aboutsummaryrefslogtreecommitdiff
path: root/notmuch-insert.c
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2022-04-30 14:26:55 -0300
committerDavid Bremner <david@tethera.net>2022-04-30 14:26:55 -0300
commit97b6a43d46be19b73c2848b29184a93db06ddfe8 (patch)
tree1618e07c4b2c3514946d01dc83e92524a95aae18 /notmuch-insert.c
parent4a4ea3234e6bd056aaa4b826765c089e8c884882 (diff)
parenta9b5f8959a20bbce774dec8a65a8b207555e52bd (diff)
Merge tag 'debian/0.36-1' into debian/bullseye-backports
notmuch release 0.36-1 for unstable (sid) [dgit] [dgit distro=debian no-split --quilt=linear]
Diffstat (limited to 'notmuch-insert.c')
-rw-r--r--notmuch-insert.c48
1 files changed, 34 insertions, 14 deletions
diff --git a/notmuch-insert.c b/notmuch-insert.c
index 214d4d03..e44607ad 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -241,6 +241,26 @@ maildir_mktemp (const void *ctx, const char *maildir, bool world_readable, char
return fd;
}
+static bool
+write_buf (const char *buf, int fdout, ssize_t remain)
+{
+ const char *p = buf;
+
+ do {
+ ssize_t written = write (fdout, p, remain);
+ if (written < 0 && errno == EINTR)
+ continue;
+ if (written <= 0) {
+ fprintf (stderr, "Error: writing to temporary file: %s",
+ strerror (errno));
+ return false;
+ }
+ p += written;
+ remain -= written;
+ } while (remain > 0);
+ return true;
+}
+
/*
* Copy fdin to fdout, return true on success, and false on errors and
* empty input.
@@ -249,11 +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];
- char *p;
+ const char *p = buf;
remain = read (fdin, buf, sizeof (buf));
if (remain == 0)
@@ -266,20 +288,18 @@ copy_fd (int fdout, int fdin)
return false;
}
- p = buf;
- do {
- ssize_t written = write (fdout, p, remain);
- if (written < 0 && errno == EINTR)
- continue;
- if (written <= 0) {
- fprintf (stderr, "Error: writing to temporary file: %s",
- strerror (errno));
+ if (first && remain >= 5 && 0 == strncmp (buf, "From ", 5)) {
+ if (! write_buf (header, fdout, strlen (header)))
return false;
- }
- p += written;
- remain -= written;
- empty = false;
- } while (remain > 0);
+ p += 5;
+ remain -= 5;
+ }
+
+ first = false;
+
+ if (! write_buf (p, fdout, remain))
+ return false;
+ empty = false;
}
return (! interrupted && ! empty);