📄 save.cpp
字号:
//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 { cout << data;} //not in attachment mode ok to dis //turns off message display if (USEATTACHMENTS && ismime) { if (onmimeheader && strncmp(data, "\n", 1) == 0) { onmimeheader = 0; } } else if (USEATTACHMENTS && !ismime) { if (strncmp(data, "begin ", 6)==0) { dontdisplay = 1; if (attachcount < 100) { attachcount++; cout << "Attached file removed from display." << endl; attachname[attachcount] = new char[500]; strncpy(attachname[attachcount], data, 499); attachname[attachcount][499] = '\0'; } } } else {} } // off header }//attach count == num } //while cout << "</textarea></form>" << endl; cout << "</td></tr></table>"; if (USEATTACHMENTS) { if (attachcount > 0) { cout << "<font size=\"+2\"><u>"; cout << WEM_Attachments << "</u></font><br>"; if (ismime) { attachcount--; //lower count because last break gets counted } for (int loop = 1; loop <= attachcount; loop++) { cout << "<a href=\"" << "./attachments/"; cout << cleanfilename(attachname[loop]+10); if (ismime) cout << "?mshowsavedattach=" << number << "x"; else cout << "?showsavedattach=" << number << "x"; cout << loop << "\">"; cout << attachname[loop]+10; cout << "</a><br>"; delete(attachname[loop]); } cout << "<br>"; } } tail(); bothunlock(mailstore); fclose(mailstore); cout << "</body></HTML>" << endl; return;}void deletesaved(){ char *env; int mailnum; char mailbox[400]; passwd *info; if ((env = getenv("QUERY_STRING"))==NULL) { disjavascript("?menusaved", "delete error", "menu"); return; } mailnum = atoi(env+12); info=getpwnam(globaluser); snprintf(mailbox, 400, "%s/.webmail/saved", info->pw_dir); deletemail(mailbox, mailnum); disjavascript("?menusaved", "Saved mail delete", "menu");}void multidelsaved(){ char data; char number[10]; vector <int> todel; int i = 0; int mark = 0; int k =0; while (1) { data = fgetc(stdin); if (data == EOF) break; if (data == '=') { mark = 0; number[k] = '\0'; k = 0; //cout << atoi(number) << endl; todel.push_back(atoi(number)); } if (mark == 1) { number[k] = data; k++; } if (data == 'm') { mark=1; k=0; } } multideletemailsaved(todel); return;}void multideletemailsaved(vector<int>& todel){ passwd *info; FILE *data; FILE *tmp; char dataname[400]; char tmpname[400]; char buf[500]; int number = 0; int emailcount = 0; int delme = 0; info=getpwnam(globaluser); snprintf(dataname, 400, "%s/.webmail/saved", info->pw_dir); snprintf(tmpname, 400, "%s/.webmail/tmp", info->pw_dir); data = fopen(dataname, "r"); if (data == NULL) { error("multideletemailsaved():Error opening data for read"); return; } if (bothlock(data, 'r')!=0) { fclose(data); error("multideletemailsaved():Error locking data for read"); return; } tmp = fopen(tmpname, "w"); if (tmp == NULL) { error("multideletemailsaved():error opening temp for write"); fclose(data); return; } if (bothlock(tmp, 'w')!=0) { fclose(data); fclose(tmp); error("multideletemailsaved():Error locking tmp for write"); return; } while (fgets(buf, 499, data) != NULL) { fputs(buf, tmp); } bothunlock(data); fclose(data); bothunlock(tmp); fclose(tmp); //rename(dataname, tmpname); sync(); data = fopen(dataname, "w"); if (data == NULL) { error("multideletemailsaved():Error opening data for write"); return; } if (bothlock(data, 'w')!=0) { fclose(data); error("multideletemailsaved():Error locking data for write"); return; } tmp = fopen(tmpname, "r"); if (tmp == NULL) { error("multideletemailsaved():error opening temp for read"); fclose(data); return; } if (bothlock(tmp, 'r')!=0) { fclose(data); fclose(tmp); error("multideletemailsaved():Error locking temp for read"); return; } while (fgets(buf, 499, tmp) != NULL) { if (strncmp(buf, "From ", 5)==0) { emailcount++; delme = 0; for (int p = 0; p<todel.size();p++) { if (emailcount == todel[p]) { delme = 1; } } } if (delme == 0) { fputs(buf, data); } } bothunlock(tmp); fclose(tmp); bothunlock(data); fclose(data); remove(tmpname); sync(); disjavascript("?dissaved#bottom", "Mail deleted", "mail list"); return;}void showsavedattach(){ char *env; char *env2; int loop = 16; int attachnum; int mailnum; char mailbox[400]; passwd *info; if ((env = getenv("QUERY_STRING"))==NULL) { disjavascript("?menusaved", "Attach display error", "menu"); return; } while (env[loop] != '\0') { if (env[loop] == 'x') { env[loop] = '\0'; env2=env+loop+1; } loop++; } attachnum = atoi(env2); mailnum = atoi(env+16); info=getpwnam(globaluser); snprintf(mailbox, 400, "%s/.webmail/saved", info->pw_dir); showattachment(mailbox, mailnum, attachnum); }void mshowsavedattach(){ char *env; char *env2; int loop = 17; int attachnum; int mailnum; char mailbox[400]; passwd *info; if ((env = getenv("QUERY_STRING"))==NULL) { disjavascript("?menusaved", "Attach display error", "menu"); return; } while (env[loop] != '\0') { if (env[loop] == 'x') { env[loop] = '\0'; env2=env+loop+1; } loop++; } attachnum = atoi(env2); mailnum = atoi(env+17); info=getpwnam(globaluser); snprintf(mailbox, 400, "%s/.webmail/saved", info->pw_dir); mshowattachment(mailbox, mailnum, attachnum);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -