edbrowse-dev - development list for edbrowse
 help / color / mirror / Atom feed
From: Karl Dahlke <eklhad@comcast.net>
To: edbrowse-dev@lists.the-brannons.com
Subject: [Edbrowse-dev] [PATCH] Stash the original mail in a file when it is saved as formatted.
Date: Mon,  4 Apr 2011 01:59:10 -0400	[thread overview]
Message-ID: <1301896750-1588-1-git-send-email-eklhad@comcast.net> (raw)

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


             reply	other threads:[~2011-04-04  6:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-04  5:59 Karl Dahlke [this message]
2011-04-04 11:23 ` Christopher Brannon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1301896750-1588-1-git-send-email-eklhad@comcast.net \
    --to=eklhad@comcast.net \
    --cc=edbrowse-dev@lists.the-brannons.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).