[RFC PATCH 3/3] WIP: escape envelope from

Subject: [RFC PATCH 3/3] WIP: escape envelope from

Date: Fri, 11 Feb 2022 22:55:03 -0400

To: notmuch@notmuchmail.org

Cc:

From: David Bremner


This needs duplicate code elimination.
---
 notmuch-insert.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/notmuch-insert.c b/notmuch-insert.c
index 214d4d03..dfeb6322 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -249,6 +249,8 @@ 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;
@@ -267,6 +269,23 @@ copy_fd (int fdout, int fdin)
 	}
 
 	p = buf;
+
+	if (first && remain >= 5 && 0 == strncmp (buf, "From ", 5)) {
+	    ssize_t written = write (fdout, header, strlen(header));
+	    if (written < 0 && errno == EINTR)
+		continue;
+	    if (written <= 0) {
+		fprintf (stderr, "Error: writing to temporary file: %s",
+			 strerror (errno));
+		return false;
+	    }
+
+	    p += 5;
+	    remain -= 5;
+	    empty = false;
+	}
+
+	first=false;
 	do {
 	    ssize_t written = write (fdout, p, remain);
 	    if (written < 0 && errno == EINTR)
-- 
2.34.1

_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: