📄 attachments.cpp.old
字号:
#include "attachments.h"void showattachment(char mailfile[], int mailnum, int attachnum){ FILE * mailbox; char data[500]; int count = 0; int attachcount = 0; char header[500]; int attachfound = 0; passwd *info; mailbox = fopen(mailfile, "r"); if (mailbox == NULL) { error("showattachment():can't open data for read."); return; } if (bothlock(mailbox, 'r')!=0) { fclose(mailbox); error("showattachment():Error locking mailstore"); return; } info=getpwnam(globaluser); while (fgets(data, 500, mailbox) != NULL) { if (strncmp(data, "From ", 5)==0) { count++; if (count > mailnum) break; } if (count == mailnum) //email found { if (strncmp(data, "begin ", 6)==0) { attachcount++; } if (attachcount == attachnum) { snprintf(header, 500, "content-type: %s\n\n", guessmime(data)); attachfound = 1; char uudecodepath[500]; char attachpath[500]; FILE *uuout; char rdata; //attach data snprintf(uudecodepath, 500, "/usr/bin/uudecode -o %s/.webmail/uutmp", info->pw_dir); uuout = popen(uudecodepath, "w"); if (uuout == NULL) { error("showattachment(): Error opening or piping to uudecode"); return; } do { fputs(data, uuout); if (strncmp(data, "end", 3)==0) { attachcount++; //need to end break; } } while (fgets(data, 500, mailbox) !=NULL); pclose(uuout); snprintf(attachpath, 500,"%s/.webmail/uutmp", info->pw_dir); uuout = fopen(attachpath, "r"); if (uuout == NULL) { error("showattachment(): Error opening attachment"); return; } if (bothlock(uuout, 'r')!=0) { fclose(uuout); error("showattachment():Error locking tmpstore"); return; } cout << header; while (fread(&rdata, 1, 1, uuout)>0) { cout << rdata; } bothunlock(uuout); fclose(uuout); remove(attachpath); } } } bothunlock(mailbox); fclose(mailbox); if (attachfound == 0) { error("showattachment(): No attachment found"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -