[PATCH] cli/insert: do not lose the SMTP envelope

J Farkas jf.hyqohaczlksw4tx6ae at l2015aftruuq.dns007.net
Fri Jan 1 03:21:19 PST 2016


From: Janos Farkas <chexum+dev at gmail.com>
Subject: [PATCH] cli/insert: do not lose the SMTP envelope

Make sure we store the envelope sender/recipient if provided by
qmail-command(8) in $RPLINE and $DTLINE.
---

I just realised that the messages delivered directly into maildir don't have
the usual envelope addresses that qmail provides.  This is a piece of
information that's important to (at least my) troubleshooting, so I created a
patch that seems to work well, applies cleanly to master (and 0.21), and
provided a NEWS entry should it be necessary.

 NEWS             |  9 +++++++++
 notmuch-insert.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/NEWS b/NEWS
index 6681699..13d45c8 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,12 @@
+
+
+`notmuch insert` records the envelope addresses if available
+
+  If the caller provides this information as qmail-command(8) does in
+  the RPLINE and DTLINE environment variables, then notmuch insert will
+  record it in the maildir file.
+
+
 Notmuch 0.21 (2015-10-29)
 =========================
 
diff --git a/notmuch-insert.c b/notmuch-insert.c
index 5205c17..ecc0fa0 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -284,6 +284,26 @@ copy_fd (int fdout, int fdin)
 }
 
 /*
+ * Write zero (and LF) terminated string to the output fd.  It's expected to
+ * come from getenv(), so it's not checked for correctness.  NULL or empty
+ * string is ignored, successfully.
+ * Return TRUE on success, FALSE on errors.
+ */
+static notmuch_bool_t
+write_header (int fdout, const char *hdr)
+{
+    ssize_t written,to_write;
+
+    if (hdr && (to_write = strlen (hdr))) {
+        written = write (fdout, hdr, to_write);
+	if (written != to_write)
+	    return FALSE;
+    }
+
+    return TRUE;
+}
+
+/*
  * Write fdin to a new temp file in maildir/tmp, return full path to
  * the file, or NULL on errors.
  */
@@ -297,6 +317,14 @@ maildir_write_tmp (const void *ctx, int fdin, const char *maildir)
     if (fdout < 0)
 	return NULL;
 
+    /* maildir(5) suggests the message should start with a Return-Path
+     * and Delivered-To lines.  qmail-local(8) supplies these.
+     */
+    if (! write_header(fdout, getenv("RPLINE")))
+	goto FAIL;
+    if (! write_header(fdout, getenv("DTLINE")))
+	goto FAIL;
+
     if (! copy_fd (fdout, fdin))
 	goto FAIL;
 
-- 
2.6.3



More information about the notmuch mailing list