[PATCH] cli/insert: do not lose the SMTP envelope
Jani Nikula
jani at nikula.org
Sun Jan 3 08:04:39 PST 2016
On Fri, 01 Jan 2016, J Farkas <jf.hyqohaczlksw4tx6ae at l2015aftruuq.dns007.net> wrote:
> 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.
I'd be more interested in seeing some tests for this...
>
> 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.
We usually refer to message files. Perhaps you should also mention what
the RPLINE and DTLINE variables should contain.
> +
> +
> 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;
> + }
It's not an error for write() to return prematurely with written <
to_write. Please see the write(2) man page and the copy_fd()
implementation in this file.
BR,
Jani.
> +
> + 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 at notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch
More information about the notmuch
mailing list