[PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / 98 / 671de1eeeec75669b596818bc10b42a954d570
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 5F6F6431FAF\r
6         for <notmuch@notmuchmail.org>; Wed,  3 Apr 2013 06:52:39 -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 uf-S1i2bJx7s for <notmuch@notmuchmail.org>;\r
16         Wed,  3 Apr 2013 06:52:35 -0700 (PDT)\r
17 X-Greylist: delayed 374 seconds by postgrey-1.32 at olra;\r
18         Wed, 03 Apr 2013 06:52:35 PDT\r
19 Received: from mail.raorn.name (c2-81-23-10-117.elastic.cloud.croc.ru\r
20         [81.23.10.117])\r
21         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
22         (No client certificate requested)\r
23         by olra.theworths.org (Postfix) with ESMTPS id 737F8431FAE\r
24         for <notmuch@notmuchmail.org>; Wed,  3 Apr 2013 06:52:35 -0700 (PDT)\r
25 Received: from fedora.raorn.name (fedora.raorn.name\r
26         [IPv6:2001:470:1f09:1868:d20d:70ff:fe42:f443])\r
27         by mail.raorn.name (Postfix) with ESMTP id 5BC19197;\r
28         Wed,  3 Apr 2013 17:46:21 +0400 (MSK)\r
29 Received: by fedora.raorn.name (Postfix, from userid 1000)\r
30         id C7FCB1002B4; Wed,  3 Apr 2013 17:46:15 +0400 (MSK)\r
31 From: "Alexey I. Froloff" <raorn@raorn.name>\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [PATCH] lib: Add a new prefix "list" to the search-terms syntax\r
34 Date: Wed,  3 Apr 2013 17:46:03 +0400\r
35 Message-Id: <1364996763-19718-1-git-send-email-raorn@raorn.name>\r
36 X-Mailer: git-send-email 1.8.1.4\r
37 X-Mailman-Approved-At: Wed, 03 Apr 2013 07:02:40 -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: Wed, 03 Apr 2013 13:52:39 -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 Cc: Pablo Oliveira <pablo@sifflez.org>\r
62 Signed-off-by: Alexey I. Froloff <raorn@raorn.name>\r
63 ---\r
64  lib/database.cc                 |  1 +\r
65  lib/index.cc                    | 48 ++++++++++++++++++++++++++++++++++++++++-\r
66  man/man7/notmuch-search-terms.7 |  8 +++++++\r
67  3 files changed, 56 insertions(+), 1 deletion(-)\r
68 \r
69 diff --git a/lib/database.cc b/lib/database.cc\r
70 index 91d4329..9311505 100644\r
71 --- a/lib/database.cc\r
72 +++ b/lib/database.cc\r
73 @@ -214,6 +214,7 @@ static prefix_t PROBABILISTIC_PREFIX[]= {\r
74      { "to",                    "XTO" },\r
75      { "attachment",            "XATTACHMENT" },\r
76      { "subject",               "XSUBJECT"},\r
77 +    { "list",                  "XLIST"},\r
78      { "folder",                        "XFOLDER"}\r
79  };\r
80  \r
81 diff --git a/lib/index.cc b/lib/index.cc\r
82 index a2edd6d..d79bd95 100644\r
83 --- a/lib/index.cc\r
84 +++ b/lib/index.cc\r
85 @@ -304,6 +304,49 @@ _index_address_list (notmuch_message_t *message,\r
86      }\r
87  }\r
88  \r
89 +static void\r
90 +_index_list_id (notmuch_message_t *message,\r
91 +               const char *list_id_header)\r
92 +{\r
93 +    const char *begin_list_id, *end_list_id;\r
94 +\r
95 +    if (list_id_header == NULL)\r
96 +       return;\r
97 +\r
98 +    /* RFC2919 says that the list-id is found at the end of the header\r
99 +     * and enclosed between angle brackets. If we cannot find a\r
100 +     * matching pair of brackets containing at least one character,\r
101 +     * we ignore the list id header. */\r
102 +    begin_list_id = strrchr (list_id_header, '<');\r
103 +    if (!begin_list_id)\r
104 +       return;\r
105 +\r
106 +    end_list_id = strrchr(begin_list_id, '>');\r
107 +    if (!end_list_id || (end_list_id - begin_list_id < 2))\r
108 +       return;\r
109 +\r
110 +    void *local = talloc_new (message);\r
111 +\r
112 +    /* We extract the list id between the angle brackets */\r
113 +    const char *list_id = talloc_strndup(local, begin_list_id + 1,\r
114 +                                        end_list_id - begin_list_id - 1);\r
115 +\r
116 +    /* All the text before is the description of the list */\r
117 +    const char *description = talloc_strndup(local, list_id_header,\r
118 +                                            begin_list_id - list_id_header);\r
119 +\r
120 +    /* Description may be RFC2047 encoded */\r
121 +    char *decoded_desc = g_mime_utils_header_decode_phrase(description);\r
122 +\r
123 +    _notmuch_message_gen_terms(message, "list", list_id);\r
124 +\r
125 +    if (decoded_desc)\r
126 +       _notmuch_message_gen_terms(message, "list", decoded_desc);\r
127 +\r
128 +    free(decoded_desc);\r
129 +    talloc_free (local);\r
130 +}\r
131 +\r
132  /* Callback to generate terms for each mime part of a message. */\r
133  static void\r
134  _index_mime_part (notmuch_message_t *message,\r
135 @@ -432,7 +475,7 @@ _notmuch_message_index_file (notmuch_message_t *message,\r
136      GMimeMessage *mime_message = NULL;\r
137      InternetAddressList *addresses;\r
138      FILE *file = NULL;\r
139 -    const char *from, *subject;\r
140 +    const char *from, *subject, *list_id;\r
141      notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;\r
142      static int initialized = 0;\r
143      char from_buf[5];\r
144 @@ -500,6 +543,9 @@ mboxes is deprecated and may be removed in the future.\n", filename);\r
145      subject = g_mime_message_get_subject (mime_message);\r
146      _notmuch_message_gen_terms (message, "subject", subject);\r
147  \r
148 +    list_id = g_mime_object_get_header (GMIME_OBJECT (mime_message), "List-Id");\r
149 +    _index_list_id (message, list_id);\r
150 +\r
151      _index_mime_part (message, g_mime_message_get_mime_part (mime_message));\r
152  \r
153    DONE:\r
154 diff --git a/man/man7/notmuch-search-terms.7 b/man/man7/notmuch-search-terms.7\r
155 index eb417ba..9cae107 100644\r
156 --- a/man/man7/notmuch-search-terms.7\r
157 +++ b/man/man7/notmuch-search-terms.7\r
158 @@ -52,6 +52,8 @@ terms to match against specific portions of an email, (where\r
159  \r
160         thread:<thread-id>\r
161  \r
162 +       list:<list-id>\r
163 +\r
164         folder:<directory-path>\r
165  \r
166         date:<since>..<until>\r
167 @@ -100,6 +102,12 @@ thread ID values can be seen in the first column of output from\r
168  .B "notmuch search"\r
169  \r
170  The\r
171 +.BR list: ,\r
172 +is used to match mailing list ID of an email message \- contents of the\r
173 +List\-Id: header without the '<', '>' delimiters or decoded list\r
174 +description.\r
175 +\r
176 +The\r
177  .B folder:\r
178  prefix can be used to search for email message files that are\r
179  contained within particular directories within the mail store. Only\r
180 -- \r
181 1.8.1.4\r
182 \r