]> git.ipfire.org Git - people/ms/dma.git/commitdiff
deliver_local: quote "From " more liberally
authorSimon Schubert <2@0x2c.org>
Wed, 7 Dec 2011 11:39:46 +0000 (12:39 +0100)
committerSimon Schubert <2@0x2c.org>
Wed, 7 Dec 2011 11:39:46 +0000 (12:39 +0100)
It seems that when scanning for mails in mbox files, most MUAs just
look for lines beginning with "From ", and not only for "From " lines
after an empty line.  Therefore quote "From " more liberally, and also
implement the mboxro format by quoting />*From / lines that have been
quoted before.

Reported-by: Pierre Frenkiel <pierre.frenkiel@gmail.com>
dma.h
local.c
test/quote.rfc2822 [new file with mode: 0644]

diff --git a/dma.h b/dma.h
index a1e4b8c4f5a8b0c7b67b2ef01223f8874553f8e7..64ad9e6fad238344ea97a9043d43403d233e9d63 100644 (file)
--- a/dma.h
+++ b/dma.h
 #define DMA_ROOT_USER  "mail"
 #define DMA_GROUP      "mail"
 
+#ifndef MBOX_STRICT
+#define MBOX_STRICT    0
+#endif
+
 
 struct stritem {
        SLIST_ENTRY(stritem) next;
diff --git a/local.c b/local.c
index 694dd845766a02827fdecf7ac1e9c21863d1c0e3..6a6407ef86527fd83c3273e77ee039acaf888a5d 100644 (file)
--- a/local.c
+++ b/local.c
@@ -214,7 +214,17 @@ retry:
                        goto chop;
                }
 
-               if (hadnl && strncmp(line, "From ", 5) == 0) {
+               /*
+                * mboxro processing:
+                * - escape lines that start with "From " with a > sign.
+                * - be reversable by escaping lines that contain an arbitrary
+                *   number of > signs, followed by "From ", i.e. />*From / in regexp.
+                * - strict mbox processing only requires escaping after empty lines,
+                *   yet most MUAs seem to relax this requirement and will treat any
+                *   line starting with "From " as the beginning of a new mail.
+                */
+               if ((!MBOX_STRICT || hadnl) &&
+                   strncmp(&line[strspn(line, ">")], "From ", 5) == 0) {
                        const char *gt = ">";
 
                        if (write(mbox, gt, 1) != 1)
diff --git a/test/quote.rfc2822 b/test/quote.rfc2822
new file mode 100644 (file)
index 0000000..f0f52fd
--- /dev/null
@@ -0,0 +1,23 @@
+From: test <test@example.org>
+To: test <test@example.org>
+Subject: testing!
+
+From what i can see...
+
+He came along,
+from far away.
+
+The rabbit comes out
+From his rabbit hole.
+
+Fromtal nudity!
+
+> From the previous mail
+
+>From the quote
+
+From here
+From there
+>>>From everywhere.
+
+last line.