[PATCH v4 5/7] Introduce _notmuch_message_has_term()
[notmuch-archives.git] / 16 / 36ef3e028388a499907e13eae0fa853dae0aa0
1 Return-Path: <sojkam1@fel.cvut.cz>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id EB92E431FBD\r
6         for <notmuch@notmuchmail.org>; Mon, 26 May 2014 07:06:18 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -2.3\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id qn2HFwlTKUBV for <notmuch@notmuchmail.org>;\r
16         Mon, 26 May 2014 07:06:10 -0700 (PDT)\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
18         by olra.theworths.org (Postfix) with ESMTP id 8B123431FAF\r
19         for <notmuch@notmuchmail.org>; Mon, 26 May 2014 07:06:10 -0700 (PDT)\r
20 Received: from localhost (unknown [192.168.200.7])\r
21         by max.feld.cvut.cz (Postfix) with ESMTP id 191E319F3634\r
22         for <notmuch@notmuchmail.org>; Mon, 26 May 2014 16:06:06 +0200 (CEST)\r
23 X-Virus-Scanned: IMAP STYX AMAVIS\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])\r
25         by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new,\r
26         port 10044) with ESMTP id MGCC8KNkeYLG for <notmuch@notmuchmail.org>;\r
27         Mon, 26 May 2014 16:06:02 +0200 (CEST)\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
29         by max.feld.cvut.cz (Postfix) with ESMTP id F07CE19F362F\r
30         for <notmuch@notmuchmail.org>; Mon, 26 May 2014 16:06:01 +0200 (CEST)\r
31 Received: from wsh by steelpick.2x.cz with local (Exim 4.82)\r
32         (envelope-from <sojkam1@fel.cvut.cz>)\r
33         id 1WovXM-0008SE-1z; Mon, 26 May 2014 16:06:00 +0200\r
34 From: Michal Sojka <sojkam1@fel.cvut.cz>\r
35 To: notmuch@notmuchmail.org\r
36 Subject: [PATCH 2/2] Make parsing of References and In-Reply-To header less\r
37         error prone\r
38 Date: Mon, 26 May 2014 16:05:57 +0200\r
39 Message-Id: <1401113157-32454-3-git-send-email-sojkam1@fel.cvut.cz>\r
40 X-Mailer: git-send-email 2.0.0.rc2\r
41 In-Reply-To: <1401113157-32454-1-git-send-email-sojkam1@fel.cvut.cz>\r
42 References: <1401113157-32454-1-git-send-email-sojkam1@fel.cvut.cz>\r
43 X-BeenThere: notmuch@notmuchmail.org\r
44 X-Mailman-Version: 2.1.13\r
45 Precedence: list\r
46 List-Id: "Use and development of the notmuch mail system."\r
47         <notmuch.notmuchmail.org>\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
51 List-Post: <mailto:notmuch@notmuchmail.org>\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
54         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
55 X-List-Received-Date: Mon, 26 May 2014 14:06:19 -0000\r
56 \r
57 According to RFC2822 References and In-Reply-To headers are supposed\r
58 to contain one or more Message-IDs, however older RFC822 allowed\r
59 almost any content. When both References and In-Reply-To headers ends\r
60 with something else that a Message-ID (see e.g. [1]), the thread\r
61 structure presented by notmuch is incorrect. The reason is that\r
62 notmuch treats this case as if the email contained no "replyto"\r
63 information (see _notmuch_database_link_message_to_parents).\r
64 \r
65 This patch changes the parse_references() function to return the last\r
66 valid Message-ID encountered rather than NULL resulting from the last\r
67 hunk of text not being the Message-ID.\r
68 \r
69 [1] https://lkml.org/lkml/headers/2014/5/19/864\r
70 ---\r
71  lib/database.cc             | 15 ++++++---------\r
72  test/T510-thread-replies.sh |  1 -\r
73  2 files changed, 6 insertions(+), 10 deletions(-)\r
74 \r
75 diff --git a/lib/database.cc b/lib/database.cc\r
76 index 1efb14d..26f15fd 100644\r
77 --- a/lib/database.cc\r
78 +++ b/lib/database.cc\r
79 @@ -521,7 +521,7 @@ parse_references (void *ctx,\r
80                   GHashTable *hash,\r
81                   const char *refs)\r
82  {\r
83 -    char *ref;\r
84 +    char *ref, *last_ref = NULL;\r
85  \r
86      if (refs == NULL || *refs == '\0')\r
87         return NULL;\r
88 @@ -529,20 +529,17 @@ parse_references (void *ctx,\r
89      while (*refs) {\r
90         ref = _parse_message_id (ctx, refs, &refs);\r
91  \r
92 -       if (ref && strcmp (ref, message_id))\r
93 +       if (ref && strcmp (ref, message_id)) {\r
94             g_hash_table_insert (hash, ref, NULL);\r
95 +           last_ref = ref;\r
96 +       }\r
97      }\r
98  \r
99      /* The return value of this function is used to add a parent\r
100       * reference to the database.  We should avoid making a message\r
101 -     * its own parent, thus the following check.\r
102 +     * its own parent, thus the above check.\r
103       */\r
104 -\r
105 -    if (ref && strcmp(ref, message_id)) {\r
106 -       return ref;\r
107 -    } else {\r
108 -       return NULL;\r
109 -    }\r
110 +    return last_ref;\r
111  }\r
112  \r
113  notmuch_status_t\r
114 diff --git a/test/T510-thread-replies.sh b/test/T510-thread-replies.sh\r
115 index d818b89..1392fbe 100755\r
116 --- a/test/T510-thread-replies.sh\r
117 +++ b/test/T510-thread-replies.sh\r
118 @@ -138,7 +138,6 @@ expected=`echo "$expected" | notmuch_json_show_sanitize`\r
119  test_expect_equal_json "$output" "$expected"\r
120  \r
121  test_begin_subtest "Ignore garbage at the end of References"\r
122 -test_subtest_known_broken\r
123  add_message '[id]="foo@five.com"' \\r
124      '[subject]="five"'\r
125  add_message '[id]="bar@five.com"' \\r
126 -- \r
127 2.0.0.rc2\r
128 \r