On Fri, Jan 01 2016, J Farkas <jf.hyqohaczlksw4tx6ae@l2015aftruuq.dns007.net> wrote: > From: Janos Farkas <chexum+dev@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. > --- Probably good feature, but like http://www.qmail.org/man/man8/qmail-command.html says: qmail-local supplies several useful environment variables to command. WARNING: These environment variables are not quoted. They may contain special characters. They are under the control of a possibly malicious remote user. Should we check that the contents of RPLINE and DTLINE are well-formed before writing these to the mail files ? Tomi > 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 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > https://notmuchmail.org/mailman/listinfo/notmuch