]> git.cworth.org Git - notmuch/commitdiff
CLI/insert: escape envelope from
authorDavid Bremner <david@tethera.net>
Sat, 12 Feb 2022 02:47:03 +0000 (22:47 -0400)
committerDavid Bremner <david@tethera.net>
Sun, 20 Feb 2022 02:11:35 +0000 (22:11 -0400)
The idea is to do as little parsing and modification of the delivered
message as possible. Luckily the position of the "envelope header"
lets us escape it by replacing the first 5 characters of the stream
with a regular header name (with ':').

notmuch-insert.c
test/T070-insert.sh

index 37b6f3cddacc8cfe589256177e7b9151b0acf397..e44607ad45a8fdf9058f3ddf9fa3fc88acb7614e 100644 (file)
@@ -269,10 +269,13 @@ static bool
 copy_fd (int fdout, int fdin)
 {
     bool empty = true;
+    bool first = true;
+    const char *header = "X-Envelope-From: ";
 
     while (! interrupted) {
        ssize_t remain;
        char buf[4096];
+       const char *p = buf;
 
        remain = read (fdin, buf, sizeof (buf));
        if (remain == 0)
@@ -284,7 +287,17 @@ copy_fd (int fdout, int fdin)
                     strerror (errno));
            return false;
        }
-       if (! write_buf (buf, fdout, remain))
+
+       if (first && remain >= 5 && 0 == strncmp (buf, "From ", 5)) {
+           if (! write_buf (header, fdout, strlen (header)))
+               return false;
+           p += 5;
+           remain -= 5;
+       }
+
+       first = false;
+
+       if (! write_buf (p, fdout, remain))
            return false;
        empty = false;
     }
index a297fa73eb6c21a03bf64b6eae2b874ad5ebcd11..e1e3b151565d2ebc6016b7f97cf63db24e5f7382 100755 (executable)
@@ -293,7 +293,6 @@ for code in OUT_OF_MEMORY XAPIAN_EXCEPTION ; do
 done
 
 test_begin_subtest "insert converts mboxes on delivery"
-test_subtest_known_broken
 notmuch insert +unmboxed < "${TEST_DIRECTORY}"/corpora/indexing/mbox-attachment.eml
 output=$(notmuch count tag:unmboxed)
 test_expect_equal "${output}" 1