📄 save.cpp
字号:
#include "save.h"#include "webemail.h"#include "attachments.h"#include "delete.h"#include <vector>void savefile(){ char *env; int number; passwd *info; FILE *inbox; FILE *savebox; char inboxname[400]; char saveboxname[400]; char data[500]; int count = 0; if ((env = getenv("QUERY_STRING"))==NULL) { disjavascript("?menusaved", "Mail Error", "saved mail box"); return; } number = atoi(env+5); info=getpwnam(globaluser); snprintf(inboxname, 400, MAILBOXPATH); inbox = fopen(inboxname, "r"); if (inbox == NULL) { error("savefile():ERROR while tring to read mail file"); return; } if (bothlock(inbox, 'r')!=0) { fclose(inbox); error("savefile():error while locking read mail file"); return; } snprintf(saveboxname, 400, "%s/.webmail/saved", info->pw_dir); savebox = fopen(saveboxname, "a"); if (savebox == NULL) { error("savefile():ERROR while tring to read mail file"); return; } if (bothlock(savebox, 'w')!=0) { fclose(inbox); fclose(savebox); error("savefile():error while locking read mail file"); return; } while (fgets(data, 499, inbox) != NULL) { if (strncmp(data, "From ", 5)==0) { count++; } if (count == number) { fputs(data, savebox); } } bothunlock(inbox); bothunlock(savebox); fclose(inbox); fclose(savebox); disjavascript("?menusaved", "Mail Saved", "saved mail box");}void dissaved(){ 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 end = 0; int onheader = 0; int lowercount = 0; //used so that the count is correct with hiden message. info=getpwnam(globaluser); if (info == NULL) { error("dissaved(): Can't read user data"); return; } 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\" "; cout << "link=\"#0000EF\" vlink=\"#0000EF\" alink=\"#FF0000\" "; cout << "background=/email/bg1saved.gif>"; cout << "<font size=\"+2\">Saved Mail Box</font><br>"; snprintf(filename, 400, "%s/.webmail/saved", info->pw_dir); mailstore = fopen(filename, "r"); if (mailstore == NULL) { //don't use error() here cout << "No saved mail."; return; } if (bothlock(mailstore, 'r')!=0) { cout << "Locking Error!!"; return; } cout << "<form action=\"" << EMAILPATH << "?savedmultidel\" "<<"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 (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 { cout << "<img SRC=\"/email/old.jpeg\" ALT=\"(" << WEM_Old << ")\""; cout << "BORDER=0 height=14 width=20>" << endl; cout << " <input TYPE=\"checkbox\" NAME=\"m" << emailcount << "\"> " << endl; cout << "<a href=\"" << EMAILPATH << "?showsaved=" << emailcount << "\" TARGET=_top>" << endl; escapeprint(from); cout << "</a>" << endl; if (subject != '\0') { cout << "<br> "; escapeprint(subject); cout << endl; } cout << " <a href=\"" << EMAILPATH << "?deletesaved=" << emailcount << "\" TARGET=_top>"; cout << WEM_Delete << "</a><br><br>" << endl; } from[0] = '\0'; subject[0] = '\0'; } } } cout << "<Input TYPE=submit Value=\""; cout << WEM_Delete_checked_mail << "\"></form>" << endl; cout << "<font size=\"+2\">Saved Mail Box</font><br>"; cout << WEM_E_Mail_count << ": "; if (lowercount == 1) cout << (emailcount - 1); else cout << emailcount; cout << "<br>"; cout << "<a name=bottom></a>" << endl; cout << "</body>" << endl; cout << "</html>" << endl; bothunlock(mailstore); fclose(mailstore); return;}void showsaved(){ 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]; char boundary[300]; boundary[0] = '-'; //sets up boundary boundary[1] = '-'; // " " " //attachment stuff int attachcount = 0; int dontdisplay = 0; char *attachname[100]; for (int loop = 0; loop < 100; loop++) { attachname[loop] = NULL; } if ((env = getenv("QUERY_STRING"))==NULL) { disjavascript("?menusaved", "Saved mail deleted", "menu"); return; } number = atoi(env+10); info=getpwnam(globaluser); if (info == NULL) { error("showsaved():Can't get user info"); return; } snprintf(filename, 400, "%s/.webmail/saved", info->pw_dir); mailstore = fopen(filename, "r"); if (mailstore == NULL) { error("showsaved():ERROR while tring to read mail file"); return; } if (bothlock(mailstore, 'r')!=0) { fclose(mailstore); error("showsaved():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/bg1saved.gif>" << endl; header("Saved Mail"); 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 << "</td>" << endl; cout << "<td ALIGN=RIGHT VALIGN=BOTTOM NOSAVE>" << endl; //cout << "<a href=\"" << EMAILPATH << "?save=" << number << "\">" << "Save" << "</a> "; cout << "<a href=\"" << EMAILPATH << "?deletesaved=" << 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; } 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -