Re: [PATCH 0/4] Allow specifying alternate names for addresses in other_email
[notmuch-archives.git] / a8 / 1042fec66c3a75ee7eef8a1431de16123b9714
1 Return-Path: <raorn@raorn.name>\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 8ED2C431FAF\r
6         for <notmuch@notmuchmail.org>; Tue,  9 Apr 2013 16:16:17 -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: 1.363\r
10 X-Spam-Level: *\r
11 X-Spam-Status: No, score=1.363 tagged_above=-999 required=5\r
12         tests=[RDNS_DYNAMIC=0.363, TO_NO_BRKTS_DYNIP=1] 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 05zMaoi7MSL3 for <notmuch@notmuchmail.org>;\r
16         Tue,  9 Apr 2013 16:16:16 -0700 (PDT)\r
17 Received: from mail.raorn.name (c2-81-23-10-117.elastic.cloud.croc.ru\r
18         [81.23.10.117])\r
19         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id D983C431FAE\r
22         for <notmuch@notmuchmail.org>; Tue,  9 Apr 2013 16:16:15 -0700 (PDT)\r
23 Received: from fedora.raorn.name (fedora.raorn.name\r
24         [IPv6:2001:470:1f09:1868:d20d:70ff:fe42:f443])\r
25         by mail.raorn.name (Postfix) with ESMTP id 79A27197;\r
26         Wed, 10 Apr 2013 03:16:18 +0400 (MSK)\r
27 Received: by fedora.raorn.name (Postfix, from userid 1000)\r
28         id 802BF1001B0; Wed, 10 Apr 2013 03:16:11 +0400 (MSK)\r
29 From: "Alexey I. Froloff" <raorn@raorn.name>\r
30 To: notmuch@notmuchmail.org\r
31 Subject: [PATCH] lib: Add a new prefix "list" to the search-terms syntax\r
32 Date: Wed, 10 Apr 2013 03:16:09 +0400\r
33 Message-Id: <1365549369-12776-1-git-send-email-raorn@raorn.name>\r
34 X-Mailer: git-send-email 1.8.1.4\r
35 In-Reply-To: <20130409083010.GA27675@raorn.name>\r
36 References: <20130409083010.GA27675@raorn.name>\r
37 X-Mailman-Approved-At: Wed, 10 Apr 2013 00:48:50 -0700\r
38 Cc: "Alexey I. Froloff" <raorn@raorn.name>\r
39 X-BeenThere: notmuch@notmuchmail.org\r
40 X-Mailman-Version: 2.1.13\r
41 Precedence: list\r
42 List-Id: "Use and development of the notmuch mail system."\r
43         <notmuch.notmuchmail.org>\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
45         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
47 List-Post: <mailto:notmuch@notmuchmail.org>\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
50         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
51 X-List-Received-Date: Tue, 09 Apr 2013 23:16:17 -0000\r
52 \r
53 From: "Alexey I. Froloff" <raorn@raorn.name>\r
54 \r
55 Add support for indexing and searching the message's List-Id header.\r
56 This is useful when matching all the messages belonging to a particular\r
57 mailing list.\r
58 \r
59 Rework of the patch by Pablo Oliveira <pablo@sifflez.org>\r
60 \r
61 Differences from original patch:\r
62 \r
63 The whole list ID indexed as boolean term, not split by words.\r
64 List description is not indexed at all.\r
65 \r
66 Thanks to ojwb and amdragon from irc://irc.freenode.net/notmuch\r
67 \r
68 Signed-off-by: Alexey I. Froloff <raorn@raorn.name>\r
69 ---\r
70  lib/database.cc                 |  1 +\r
71  lib/index.cc                    | 45 ++++++++++++++++++++++++++++++++++++++++-\r
72  man/man7/notmuch-search-terms.7 |  8 ++++++++\r
73  3 files changed, 53 insertions(+), 1 deletion(-)\r
74 \r
75 diff --git a/lib/database.cc b/lib/database.cc\r
76 index 91d4329..6313913 100644\r
77 --- a/lib/database.cc\r
78 +++ b/lib/database.cc\r
79 @@ -203,6 +203,7 @@ static prefix_t BOOLEAN_PREFIX_INTERNAL[] = {\r
80  };\r
81  \r
82  static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {\r
83 +    { "list",                  "XLIST"},\r
84      { "thread",                        "G" },\r
85      { "tag",                   "K" },\r
86      { "is",                    "K" },\r
87 diff --git a/lib/index.cc b/lib/index.cc\r
88 index a2edd6d..8b97ec3 100644\r
89 --- a/lib/index.cc\r
90 +++ b/lib/index.cc\r
91 @@ -304,6 +304,46 @@ _index_address_list (notmuch_message_t *message,\r
92      }\r
93  }\r
94  \r
95 +static void\r
96 +_index_list_id (notmuch_message_t *message,\r
97 +               const char *list_id_header)\r
98 +{\r
99 +    const char *begin_list_id, *end_list_id;\r
100 +\r
101 +    if (list_id_header == NULL)\r
102 +       return;\r
103 +\r
104 +    /* RFC2919 says that the list-id is found at the end of the header\r
105 +     * and enclosed between angle brackets. If we cannot find a\r
106 +     * matching pair of brackets containing at least one character,\r
107 +     * we ignore the list id header. */\r
108 +    begin_list_id = strrchr (list_id_header, '<');\r
109 +    if (!begin_list_id) {\r
110 +       fprintf (stderr, "Warning: Not indexing mailformed List-Id tag.\n");\r
111 +       return;\r
112 +    }\r
113 +\r
114 +    end_list_id = strrchr(begin_list_id, '>');\r
115 +    if (!end_list_id || (end_list_id - begin_list_id < 2)) {\r
116 +       fprintf (stderr, "Warning: Not indexing mailformed List-Id tag.\n");\r
117 +       return;\r
118 +    }\r
119 +\r
120 +    void *local = talloc_new (message);\r
121 +\r
122 +    /* We extract the list id between the angle brackets */\r
123 +    const char *list_id = talloc_strndup (local, begin_list_id + 1,\r
124 +                                         end_list_id - begin_list_id - 1);\r
125 +\r
126 +    /* _notmuch_message_add_term() may return\r
127 +     * NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG here.  We can't fix it, but\r
128 +     * this is not a reason to exit with error... */\r
129 +    if (_notmuch_message_add_term (message, "list", list_id))\r
130 +       fprintf (stderr, "Warning: Not indexing List-Id: <%s>\n", list_id);\r
131 +\r
132 +    talloc_free (local);\r
133 +}\r
134 +\r
135  /* Callback to generate terms for each mime part of a message. */\r
136  static void\r
137  _index_mime_part (notmuch_message_t *message,\r
138 @@ -432,7 +472,7 @@ _notmuch_message_index_file (notmuch_message_t *message,\r
139      GMimeMessage *mime_message = NULL;\r
140      InternetAddressList *addresses;\r
141      FILE *file = NULL;\r
142 -    const char *from, *subject;\r
143 +    const char *from, *subject, *list_id;\r
144      notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;\r
145      static int initialized = 0;\r
146      char from_buf[5];\r
147 @@ -500,6 +540,9 @@ mboxes is deprecated and may be removed in the future.\n", filename);\r
148      subject = g_mime_message_get_subject (mime_message);\r
149      _notmuch_message_gen_terms (message, "subject", subject);\r
150  \r
151 +    list_id = g_mime_object_get_header (GMIME_OBJECT (mime_message), "List-Id");\r
152 +    _index_list_id (message, list_id);\r
153 +\r
154      _index_mime_part (message, g_mime_message_get_mime_part (mime_message));\r
155  \r
156    DONE:\r
157 diff --git a/man/man7/notmuch-search-terms.7 b/man/man7/notmuch-search-terms.7\r
158 index eb417ba..9cae107 100644\r
159 --- a/man/man7/notmuch-search-terms.7\r
160 +++ b/man/man7/notmuch-search-terms.7\r
161 @@ -52,6 +52,8 @@ terms to match against specific portions of an email, (where\r
162  \r
163         thread:<thread-id>\r
164  \r
165 +       list:<list-id>\r
166 +\r
167         folder:<directory-path>\r
168  \r
169         date:<since>..<until>\r
170 @@ -100,6 +102,12 @@ thread ID values can be seen in the first column of output from\r
171  .B "notmuch search"\r
172  \r
173  The\r
174 +.BR list: ,\r
175 +is used to match mailing list ID of an email message \- contents of the\r
176 +List\-Id: header without the '<', '>' delimiters or decoded list\r
177 +description.\r
178 +\r
179 +The\r
180  .B folder:\r
181  prefix can be used to search for email message files that are\r
182  contained within particular directories within the mail store. Only\r
183 -- \r
184 1.8.1.4\r
185 \r