CLI/insert: escape envelope from

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 ':').
This commit is contained in:
David Bremner 2022-02-11 22:47:03 -04:00
parent 329bb4ddf4
commit b320d3fb59
2 changed files with 14 additions and 2 deletions

View file

@ -269,10 +269,13 @@ static bool
copy_fd (int fdout, int fdin) copy_fd (int fdout, int fdin)
{ {
bool empty = true; bool empty = true;
bool first = true;
const char *header = "X-Envelope-From: ";
while (! interrupted) { while (! interrupted) {
ssize_t remain; ssize_t remain;
char buf[4096]; char buf[4096];
const char *p = buf;
remain = read (fdin, buf, sizeof (buf)); remain = read (fdin, buf, sizeof (buf));
if (remain == 0) if (remain == 0)
@ -284,7 +287,17 @@ copy_fd (int fdout, int fdin)
strerror (errno)); strerror (errno));
return false; 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; return false;
empty = false; empty = false;
} }

View file

@ -293,7 +293,6 @@ for code in OUT_OF_MEMORY XAPIAN_EXCEPTION ; do
done done
test_begin_subtest "insert converts mboxes on delivery" test_begin_subtest "insert converts mboxes on delivery"
test_subtest_known_broken
notmuch insert +unmboxed < "${TEST_DIRECTORY}"/corpora/indexing/mbox-attachment.eml notmuch insert +unmboxed < "${TEST_DIRECTORY}"/corpora/indexing/mbox-attachment.eml
output=$(notmuch count tag:unmboxed) output=$(notmuch count tag:unmboxed)
test_expect_equal "${output}" 1 test_expect_equal "${output}" 1