unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Hannu Hartikainen <hannu@hrtk.in>
To: notmuch@notmuchmail.org
Cc: Hannu Hartikainen <hannu@hrtk.in>
Subject: [PATCH v2 2/2] lib: consider all instances of Delivered-To header
Date: Fri,  2 Jul 2021 12:13:09 +0300	[thread overview]
Message-ID: <20210702091309.26970-2-hannu@hrtk.in> (raw)
In-Reply-To: <20210702091309.26970-1-hannu@hrtk.in>

When using notmuch-reply and guessing the From: address from
Delivered-To headers, I had the wrong address chosen today. This was
because the messages from the notmuch list contain these headers in this
order:

Delivered-To: hannu.hartikainen@gmail.com
...
Delivered-To: hannu@hrtk.in

In my .notmuch-config I have the following configuration:

primary_email=hannu@hrtk.in
other_email=hannu.hartikainen@gmail.com;...

Before this change, notmuch-reply would guess From: @gmail.com because
that is the first Delivered-To header present. After the change, the
primary address is chosen as I would expect.
---
 lib/message-file.c | 13 +++++++++----
 notmuch-reply.c    |  7 +++++--
 test/T220-reply.sh |  1 -
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/lib/message-file.c b/lib/message-file.c
index 647ccf3a..68f646a4 100644
--- a/lib/message-file.c
+++ b/lib/message-file.c
@@ -291,11 +291,16 @@ _notmuch_message_file_get_header (notmuch_message_file_t *message,
     if (value)
 	return value;
 
-    if (strcasecmp (header, "received") == 0) {
+    if (strcasecmp (header, "received") == 0 ||
+	strcasecmp (header, "delivered-to") == 0) {
 	/*
-	 * The Received: header is special. We concatenate all
-	 * instances of the header as we use this when analyzing the
-	 * path the mail has taken from sender to recipient.
+	 * The Received: header is special. We concatenate all instances of the
+	 * header as we use this when analyzing the path the mail has taken
+	 * from sender to recipient.
+	 *
+	 * Similarly, multiple instances of Delivered-To may be present. We
+	 * concatenate them so the one with highest priority may be picked (eg.
+	 * primary_email before other_email).
 	 */
 	decoded = _notmuch_message_file_get_combined_header (message, header);
     } else {
diff --git a/notmuch-reply.c b/notmuch-reply.c
index 08140799..ebb621e0 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -464,8 +464,8 @@ guess_from_in_received_by (notmuch_database_t *notmuch, const char *received)
  * (last Received: header added) and try to extract from them
  * indications to which email address this message was delivered.
  *
- * The Received: header is special in our get_header function and is
- * always concatenated.
+ * The Received: header is among special ones in our get_header function
+ * and is always concatenated.
  *
  * Return the address that was found, if any, and NULL otherwise.
  */
@@ -499,6 +499,9 @@ guess_from_in_received_headers (notmuch_message_t *message)
  * headers: Envelope-To, X-Original-To, and Delivered-To (searched in
  * that order).
  *
+ * The Delivered-To: header is among special ones in our get_header
+ * function and is always concatenated.
+ *
  * Return the address that was found, if any, and NULL otherwise.
  */
 static const char *
diff --git a/test/T220-reply.sh b/test/T220-reply.sh
index 9f711a04..2db36fef 100755
--- a/test/T220-reply.sh
+++ b/test/T220-reply.sh
@@ -246,7 +246,6 @@ On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
 OK"
 
 test_begin_subtest "From guessing: multiple Delivered-To"
-test_subtest_known_broken
 add_message '[from]="Sender <sender@example.com>"' \
 	    '[to]="Recipient <recipient@example.com>"' \
 	    '[subject]="From guessing"' \
-- 
2.32.0

  reply	other threads:[~2021-07-02  9:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-23 10:29 [PATCH] lib: consider all instances of Delivered-To header Hannu Hartikainen
2021-06-23 10:58 ` Michael J Gruber
2021-06-23 12:15   ` Hannu Hartikainen
2021-06-26 17:36 ` David Bremner
2021-06-28  7:11   ` Hannu Hartikainen
2021-07-02  9:13   ` [PATCH v2 1/2] reply: add test for multiple Delivered-To headers Hannu Hartikainen
2021-07-02  9:13     ` Hannu Hartikainen [this message]
2021-08-30  1:13     ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210702091309.26970-2-hannu@hrtk.in \
    --to=hannu@hrtk.in \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).