From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from qmta14.emeryville.ca.mail.comcast.net (qmta14.emeryville.ca.mail.comcast.net [76.96.27.212]) by che.dreamhost.com (Postfix) with ESMTP id DB034FE9A for ; Sun, 3 Apr 2011 23:14:06 -0700 (PDT) Received: from omta02.emeryville.ca.mail.comcast.net ([76.96.30.19]) by qmta14.emeryville.ca.mail.comcast.net with comcast id THyZ1g0030QkzPwAEHz8Bc; Mon, 04 Apr 2011 05:59:09 +0000 Received: from eklbox.hsd1.mi.comcast.net. ([71.238.29.179]) by omta02.emeryville.ca.mail.comcast.net with comcast id THz71g00T3rsRL78NHz8EU; Mon, 04 Apr 2011 05:59:08 +0000 From: Karl Dahlke To: edbrowse-dev@lists.the-brannons.com Date: Mon, 4 Apr 2011 01:59:10 -0400 Message-Id: <1301896750-1588-1-git-send-email-eklhad@comcast.net> X-Mailer: git-send-email 1.7.4 Subject: [Edbrowse-dev] [PATCH] Stash the original mail in a file when it is saved as formatted. X-BeenThere: edbrowse-dev@lists.the-brannons.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Edbrowse Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Apr 2011 06:14:07 -0000 This is for that 1 time in a hundred when you wish you had the original mail, because it has hyperlinks or forms in it, or a patch, or something that is otherwise lost or mangled when rendered as finished text. --- src/fetchmail.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 53 insertions(+), 0 deletions(-) diff --git a/src/fetchmail.c b/src/fetchmail.c index 97009c5..b0f6561 100644 --- a/src/fetchmail.c +++ b/src/fetchmail.c @@ -339,6 +339,7 @@ fetchMail(int account) int exactf_l; char *exactf = 0; /* utf8 formatted */ int displine; + int stashNumber = -1; if(zapMail) delflag = true; @@ -591,6 +592,47 @@ fetchMail(int account) close(fh); fsize = exact_l; } else { + + if(mailStash) { + char *rmf; /* raw mail file */ + int rmfh; /* file handle to same */ +/* I want a fairly easy filename, in case I want to go look at the original. + * Not a 30 character message ID that I am forced to cut&paste. + * 4 or 5 digits would be nice. + * So the filename looks like /home/foo/.Trash/rawmail/36921.eml + * Note that eml is a standard suffix for a mail file. + * I pick the digits randomly. + * Please don't accumulate 100,000 emails before you empty your trash. + * It's good to have a cron job empty the trash early Sunday morning. +*/ + + k = strlen(mailStash); + rmf = allocMem(k + 12); +/* Try 20 times, then give up. */ + for(j = 0; j < 20; ++j) { + int rn = rand() % 100000; /* random number */ + sprintf(rmf, "%s/%05d.eml", mailStash, rn); + if(fileTypeByName(rmf, false)) + continue; +/* dump the original mail into the file */ + rmfh = + open(rmf, + O_WRONLY | O_TEXT | O_CREAT | O_APPEND, + 0666); + if(rmfh < 0) + break; + if(write(rmfh, exact, exact_l) < exact_l) { + close(rmfh); + unlink(rmf); + break; + } + close(rmfh); +/* written successfully, remember the stash number */ + stashNumber = rn; + break; + } + } + /* stashing the original */ fsize = 0; for(j = 1; j <= cw->dol; ++j) { char *showline = (char *)fetchLine(j, 1); @@ -600,6 +642,17 @@ fetchMail(int account) nzFree(showline); fsize += len; } /* loop over lines */ + + if(stashNumber >= 0) { + char addstash[60]; + sprintf(addstash, "\nOriginal %05d\n", + stashNumber); + k = strlen(addstash); + if(write(fh, addstash, k) < k) + goto badsave; + fsize += k; + } + close(fh); if(nattach) writeAttachments(lastMailInfo); -- 1.7.4