⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inbox.cpp

📁 一个国外学生做的基于Web浏览器的email程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include "inbox.h"#include "webemail.h"#include "attachments.h"#include "delete.h"#include <vector>//list contents of mail boxvoid disinbox(){	passwd *info;	FILE *mailstore;	char filename[400];	char data[500];	int emailcount = 0;	char from[101];	char subject[101];	from[0] = '\0';	subject[0] = '\0';	int isold = 0;	int isreplied = 0;	int end = 0;	int onheader = 0;	int lowercount = 0;  //used so that the count is correct with hiden message.	//fetchmail	char poppath[400];	FILE *popfile;	info=getpwnam(globaluser);	if (info == NULL)	{		error("readmail(): Can't read user data");		return;	}	snprintf(filename, 400, MAILBOXPATH);	cout << "Content-type: text/HTML" << endl;	cout << "Pragma: no-cache" << endl << endl;	cout << "<html>" << endl;	cout << "<head>" << endl;	cout << "<title>Web E-Mail</title>" << endl;	cout << "<META HTTP-EQUIV=\"expires\" content=\"0\">" << endl;	cout << "</head>" << endl;	cout << "<body text=\"#000000\" bgcolor=\"#FFFFFF\" link=\"#0000FF\" vlink=\"#0000FF\" alink=\"#FF0000\" background=/email/bg1.gif>" << endl;	mailstore = fopen(filename, "r");	if (mailstore == NULL)	{		//don't use error() here		cout << "No mail.";		return;	}	if (bothlock(mailstore, 'r')!=0)	{		cout << "Locking Error!!";		return;	}	cout << "<form action=\"" << EMAILPATH << "?multidel\" " << "method=\"post\">";  	while (end == 0)	{		if (fgets(data, 499, mailstore) == NULL)		{			end = 1;		}		if (data[0] == '\n' || data[0] == '\r')		{			onheader=0;		}		if (strncasecmp(data, "From: ", 6)==0 && onheader)		{			strncpy(from, data, 99);			from[100]='\0';					}		if (strncasecmp(data, "Subject: ", 9)==0 && onheader)		{			strncpy(subject, data, 99);			subject[100]='\0';		}		if (strncasecmp(data, "Status: ", 8)==0 && onheader)		{			if (strncasecmp(data+8, "R", 1)==0)				isold = 1;		}		if (strncasecmp(data, "X-Status: ", 10)==0 && onheader)		{			if (strncasecmp(data+10, "A", 1)==0)				isreplied = 1;		}		if (strncmp(data, "From ", 5)==0 || end == 1)		{			onheader = 1;			if (from[0] != '\0')			{				emailcount++;				if (emailcount == 1 && 				strncasecmp(from, "From: Mail System Internal Data", 31) == 0)				{					lowercount = 1;				}				else				{					if (isold == 1 && isreplied == 1)					{						cout << "<img SRC=\"/email/replied.jpeg\" ALT=\"(" << "Replied" << ")\""; 						cout << "BORDER=0 height=14 width=20>" << endl;									}					else if (isold == 1)					{						cout << "<img SRC=\"/email/old.jpeg\" ALT=\"(" << WEM_Old << ")\""; 						cout << "BORDER=0 height=14 width=20>" << endl;									}					else 					{						cout << "<img SRC=\"/email/new.jpeg\" ALT=\"(" << WEM_New << ")\"";						cout << "BORDER=0 height=14 width=20>" << endl;					}					cout << "&nbsp;<input TYPE=\"checkbox\" NAME=\"m" << emailcount << "\">&nbsp;" << endl;					cout << "<a href=\"" << EMAILPATH << "?read=" << emailcount << "\" TARGET=_top>" << endl;	 				escapeprint(from);					cout << "</a>" << endl;					if (subject != '\0')					{						cout << "<br>&nbsp;&nbsp;";						escapeprint(subject);						cout << endl;					}					cout << "&nbsp;&nbsp;<a href=\"" << EMAILPATH << "?delete=" << emailcount << "\" TARGET=_top>";					cout << WEM_Delete << "</a><br><br>" << endl;				}				from[0] = '\0';				subject[0] = '\0';				isold = 0;				isreplied = 0;			}		}	}	cout << "<Input TYPE=submit Value=\"";	cout << WEM_Delete_checked_mail << "\"></form>" << endl;	if (USEEXTERNMAIL)	{		snprintf(poppath, 400, "%s/.fetchmailrc",info->pw_dir);		popfile = fopen(poppath, "r");		if (popfile != NULL)		{			cout << "<a href=\"" << EMAILPATH << "?popcheck\">";			cout << WEM_Check_external;			cout << "</a><br>";			fclose(popfile);		}	}	cout << WEM_E_Mail_count << ": ";	if (lowercount == 1)		cout << (emailcount - 1);	else		cout << emailcount;	cout << "<br>";	if (USEQUOTAS)	{		/*  More File Size Stuff   --Jon*/		struct stat MBOXSIZE;		double jtest = 0.0;		stat(filename, &MBOXSIZE);		jtest=MBOXSIZE.st_size;		if (jtest > MAX_MBOX_SIZE)		{			cout << "<hr width=\"100%\">";			cout << "<font color=red size=8>Alert:  </font><font				color=blue>Your Mailbox Has reached it's Maximum Size.				<br>While your Mailbox will continue to function,				It is highly Suggested that you delete any old				messages to prevent an administrator from removing				messages that you may need.  Thanks for your Help.				</font><p><br>";		}		/* End File Size Stuff */	}	cout << "<a name=bottom></a>" << endl;	bothunlock(mailstore);	fclose(mailstore);	cout << "</body></html>" << endl;	return;}//read actual message//this one needs to replace sent and saved boxesvoid showinbox(){	char *env;	int number; 	//email to read	passwd *info;	FILE *mailstore;	char filename[400];	char data[500];	int count = 0;	int offofheader = 0; //mail header	int extenddata = 0; //multi line headers	int domarkold = 1;	int ismime = 0; //looks for mime header, only turns on for 1.0	int onmimeheader = 0;	char answer[500]; //stores found answer from boundary	char boundary[300];	boundary[0] = '-'; //sets up boundary	boundary[1] = '-'; // "   "     "	//receite stuff	char receiptaddress[400];	int sendreceipt = 0;	int gotsubject = 0;	char subject[400];	//attachment stuff	int attachcount = 0;	int dontdisplay = 0;	char *attachname[100];	for (int loop = 0; loop < 100; loop++)	{		attachname[loop] = NULL;	}	//get mail number	if ((env = getenv("QUERY_STRING"))==NULL)	{		menu();		return;	}	number = atoi(env+5);		info=getpwnam(globaluser);	if (info == NULL)	{		error("showinbox():Can't get user info");		return;	}	snprintf(filename, 400, MAILBOXPATH);	mailstore = fopen(filename, "r");	if (mailstore == NULL)	{		error("showinbox():ERROR while tring to read mail file");		return;	}		if (bothlock(mailstore, 'r')!=0)	{		fclose(mailstore);		error("showinbox():Error while locking mail file.");		return;	}	cout << "content-type: text/HTML" << endl;	cout << "Pragma: No-Cache" << endl << endl;	cout << "<html><head>" << endl;	cout << "<title>Web E-Mail</title>" << endl;	cout << "<META HTTP-EQUIV=\"expires\" content=\"0\">" << endl;	cout << "</head>" << endl;	cout << "<body text=\"#000000\" bgcolor=\"#FFFFFF\" ";	cout << "link=\"#0000EF\" vlink=\"#0000EF\" alink=\"#FF0000\" background=/email/bg1.gif>" << endl;		header(WEM_Read);	cout << "<table CELLSPACING=0 CELLPADDING=0 NOSAVE >" << endl;	cout << "<tr NOSAVE><td NOSAVE>" << endl;	cout << "<table CELLSPACING=0 CELLPADDING=0 WIDTH=\"100%\" NOSAVE >" << endl;	cout << "<tr NOSAVE><td ALIGN=LEFT VALIGN=BOTTOM NOSAVE>" << endl;	cout << "<a href=\"" << EMAILPATH << "?addname=" << number << "\">" << WEM_Add_address << "</a>&nbsp;&nbsp;"; 	cout << "<a href=\"" << EMAILPATH << "?reply=" << number << "\">" << WEM_Reply << "</a>&nbsp;&nbsp;";	cout << "<a href=\"" << EMAILPATH << "?forward=" << number << "\">" << WEM_Forward << "</a><br>";	cout << "<a href=\"" << EMAILPATH << "?viewhtml=" << number << "\">" << WEM_HTML_View << "</a>&nbsp;&nbsp;";	cout << "<a href=\"" << EMAILPATH << "?viewprint=" << number << "\">" << "Printable view" << "</a>&nbsp;&nbsp;";	cout << "</td>" << endl;	cout << "<td ALIGN=RIGHT VALIGN=BOTTOM NOSAVE>" << endl;	cout << "<a href=\"" << EMAILPATH << "?save=" << number << "\">" << "Save" << "</a>&nbsp;&nbsp;";	cout << "<a href=\"" << EMAILPATH << "?delete=" << number << "\">" << WEM_Delete << "</a>";	cout << "</td></tr></table></td></tr>" << endl;	cout << "<tr NOSAVE><td NOSAVE>" << endl;	cout << "<form><textarea wrap=virtual cols=80 rows=20>" << endl;	//display message	while (fgets(data, 499, mailstore) != NULL)	{		if (strncmp(data, "From ", 5)==0)		{			count++;		}		if (count == number)		{			//tries to prevent js attacks			distroytag(data, "</textarea");			if (data[0] == '\n')				offofheader = 1; 			if (offofheader == 0) //in header			{				if (strncasecmp(data,"From: ", 6)==0 ||				strncasecmp(data, "To: ", 4) == 0 ||				strncasecmp(data, "Date: ", 6)==0 ||				strncasecmp(data, "cc: ", 4)==0 ||				strncasecmp(data, "Reply-To: ", 10)==0)				{					extenddata = 1;					cout << data;				}				else if (strncasecmp(data, "Subject: ",9)==0)				{					extenddata = 1;					cout << data;					gotsubject = 1;					strncpy(subject, data, 399);					subject[399] = '\0';				}				else if (strncasecmp(data, "Return-Receipt-To:",18)==0)				{					extenddata = 1;					cout << data;					sendreceipt = 1;					strncpy(receiptaddress, data, 399);					receiptaddress[399] =  '\0';				} 				else if (strncasecmp(data, "Status: R", 9) ==0)				{					domarkold=0;				}				else if (strncasecmp(data, "MIME-Version: 1.0",17)==0)				{					cout << data;					ismime=1;				}				else if (finddata(data, "boundary=", answer) != NULL)				{					int o = 0;					if (answer[0] == '"')						o++; //checks for" 					strncpy(boundary+2, answer+o, 300);					for (o = 0; o<299; o++)					{ 								if (boundary[o] == '\n' ||	 					boundary[o] == '"' || 							boundary[o] == '\r' || 							boundary[o] == '\0') 							{ 										boundary[o] = '\0';	 						break; 				 			} 									}  				} 				else if (extenddata == 1 && 				strncasecmp(data, "        ",8)==0)				{					cout << data;				}				else //turn off extenddata				{					extenddata = 0;				}			}			else //out of header			{				//turns on message display.				if (USEATTACHMENTS && ismime)				{					if (strncmp(data, boundary,strlen(boundary))==0) 					{						onmimeheader = 1;						dontdisplay = 0;						//default on, in case there is no						// content-type						if (attachcount < 100)						{							attachcount++;							attachname[attachcount] = new char[500]; 										//strncpy(attachname[attachcount], data, 499); 								snprintf(attachname[attachcount],499, "          mime attachment %d", attachcount);							attachname[attachcount][499] = '\0';  						}		 			}					if (onmimeheader && (					finddata(data, "filename=", answer) != NULL))					{						//is this safe???						//has memory been defined already???						strncpy(attachname[attachcount], "          ", 499);						strncpy(attachname[attachcount]+10, answer, 489);					}					if (onmimeheader && (					strncasecmp(data, "Content-Type: text/plain",24)==0 ||					strncasecmp(data, "Content-Type: message/delivery-status",37)==0					))					{						//turn on display, or 						//really leave on						dontdisplay = 0; 					}					else if (onmimeheader &&					strncasecmp(data, "Content-Type: ", 14) == 0)					{						//unknown type, turn off display						dontdisplay = 1;					}					else {}				}				else if (USEATTACHMENTS && !ismime)				{				  	if (strncasecmp(data, "end", 3) ==0)						dontdisplay = 0;				}				else {}				//displays message				if (USEATTACHMENTS && 				dontdisplay == 0 && onmimeheader == 0)				{	cout << data;} //ok to display				else if (USEATTACHMENTS)				{} //not ok to display				else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -