diff options
author | Michal Sojka <sojkam1@fel.cvut.cz> | 2014-05-26 16:05:57 +0200 |
---|---|---|
committer | David Bremner <david@tethera.net> | 2014-08-16 17:45:16 -0700 |
commit | 028c56061e820211f5757a49bf4da30198b29e29 (patch) | |
tree | d9e35460b71fef0535ae727745eb50e12864e6dd /lib/database.cc | |
parent | 61993923b4b2e8c9871cc60681e91896c55e169c (diff) |
Make parsing of References and In-Reply-To header less error prone
According to RFC2822 References and In-Reply-To headers are supposed
to contain one or more Message-IDs, however older RFC822 allowed
almost any content. When both References and In-Reply-To headers ends
with something else that a Message-ID (see e.g. [1]), the thread
structure presented by notmuch is incorrect. The reason is that
notmuch treats this case as if the email contained no "replyto"
information (see _notmuch_database_link_message_to_parents).
This patch changes the parse_references() function to return the last
valid Message-ID encountered rather than NULL resulting from the last
hunk of text not being the Message-ID.
[1] https://lkml.org/lkml/headers/2014/5/19/864
Diffstat (limited to 'lib/database.cc')
-rw-r--r-- | lib/database.cc | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/lib/database.cc b/lib/database.cc index c7602906..9c0952a4 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -524,7 +524,7 @@ parse_references (void *ctx, GHashTable *hash, const char *refs) { - char *ref; + char *ref, *last_ref = NULL; if (refs == NULL || *refs == '\0') return NULL; @@ -532,20 +532,17 @@ parse_references (void *ctx, while (*refs) { ref = _parse_message_id (ctx, refs, &refs); - if (ref && strcmp (ref, message_id)) + if (ref && strcmp (ref, message_id)) { g_hash_table_insert (hash, ref, NULL); + last_ref = ref; + } } /* The return value of this function is used to add a parent * reference to the database. We should avoid making a message - * its own parent, thus the following check. + * its own parent, thus the above check. */ - - if (ref && strcmp(ref, message_id)) { - return ref; - } else { - return NULL; - } + return last_ref; } notmuch_status_t |