]> git.notmuchmail.org Git - notmuch/commitdiff
lib: consider all instances of Delivered-To header
authorHannu Hartikainen <hannu@hrtk.in>
Fri, 2 Jul 2021 09:13:09 +0000 (12:13 +0300)
committerDavid Bremner <david@tethera.net>
Mon, 30 Aug 2021 01:10:08 +0000 (18:10 -0700)
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
notmuch-reply.c
test/T220-reply.sh

index 647ccf3abedaaf52f95bcc44e9a3199de8d4b42d..68f646a4e56d878459d37a665ca0298621e0c1d9 100644 (file)
@@ -291,11 +291,16 @@ _notmuch_message_file_get_header (notmuch_message_file_t *message,
     if (value)
        return value;
 
     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 {
         */
        decoded = _notmuch_message_file_get_combined_header (message, header);
     } else {
index 08140799e2b965967ac2496883d091b1fb3a3032..ebb621e08670e6e799416b5ddf74aa932e40144a 100644 (file)
@@ -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.
  *
  * (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.
  */
  *
  * 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).
  *
  * 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 *
  * Return the address that was found, if any, and NULL otherwise.
  */
 static const char *
index 9f711a04c0251735163450a6d34fcdf3f5eb917a..2db36fef1b26d8e7a2f57c114bd582c1e0c76322 100755 (executable)
@@ -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"
 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"' \
 add_message '[from]="Sender <sender@example.com>"' \
            '[to]="Recipient <recipient@example.com>"' \
            '[subject]="From guessing"' \