[notmuch] [PATCH] lib: Add a new prefix "listid" to the search-terms syntax.
authorPablo Oliveira <pablo@sifflez.org>
Sun, 27 Dec 2009 02:06:37 +0000 (03:06 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:35:56 +0000 (09:35 -0800)
ab/edc63b5d98b7f141afc8f2ef503c2a99a17050 [new file with mode: 0644]

diff --git a/ab/edc63b5d98b7f141afc8f2ef503c2a99a17050 b/ab/edc63b5d98b7f141afc8f2ef503c2a99a17050
new file mode 100644 (file)
index 0000000..ac56e75
--- /dev/null
@@ -0,0 +1,187 @@
+Return-Path: <pablo.oliveira@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 54C3B431FBC\r
+       for <notmuch@notmuchmail.org>; Sat, 26 Dec 2009 18:06:45 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 67-2HzCtVahI for <notmuch@notmuchmail.org>;\r
+       Sat, 26 Dec 2009 18:06:44 -0800 (PST)\r
+Received: from ey-out-1920.google.com (ey-out-1920.google.com [74.125.78.148])\r
+       by olra.theworths.org (Postfix) with ESMTP id 2FC75431FAE\r
+       for <notmuch@notmuchmail.org>; Sat, 26 Dec 2009 18:06:44 -0800 (PST)\r
+Received: by ey-out-1920.google.com with SMTP id 3so2896446eyh.6\r
+       for <notmuch@notmuchmail.org>; Sat, 26 Dec 2009 18:06:43 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+       h=domainkey-signature:received:received:sender:from:to:subject:date\r
+       :message-id:mime-version:content-type;\r
+       bh=h9mmZSc14flcTatym49RRjEy0s/KcdI7YnTElViS+BQ=;\r
+       b=tIbvvJrVwsCogH0n/fvzqjfcgMla0aGgPQLWGeogzg+DqQXT2KUEATOMaKQRTt+dvT\r
+       aPIPNye0KPFBR9n2/1kvPUpunfHsUoSaFdlDTTgJFqQ51gr8ZkhfzSsVGMXXpybhFRYc\r
+       78K4mRQ9tFa49Ar90uWDpe5LJUArurZeIPGg4=\r
+DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma;\r
+       h=sender:from:to:subject:date:message-id:mime-version:content-type;\r
+       b=LY23gJuEFLWWA0DDThmS+BEkWbx2X22QfmLhGujTOs2bJu4h6m9K+jPR+6CuvT4Rsv\r
+       4R6gan82TWB5+gqWLNPKj22QCuMAzPmkuWlxhu+IQbHeIBgb+u/aU1QbA7GL2EXHkId0\r
+       8p/enI3htpTNaS8a6nmbZPSV6psXD2NXD3rQc=\r
+Received: by 10.213.102.66 with SMTP id f2mr4559047ebo.12.1261879603088;\r
+       Sat, 26 Dec 2009 18:06:43 -0800 (PST)\r
+Received: from ecaz (80.174.89.24.dyn.user.ono.com [80.174.89.24])\r
+       by mx.google.com with ESMTPS id 15sm7270537ewy.12.2009.12.26.18.06.40\r
+       (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
+       Sat, 26 Dec 2009 18:06:42 -0800 (PST)\r
+Sender: Pablo Oliveira <pablo.oliveira@gmail.com>\r
+From: Pablo Oliveira <pablo@sifflez.org>\r
+To: notmuch@notmuchmail.org\r
+Date: Sun, 27 Dec 2009 03:06:37 +0100\r
+Message-ID: <87ws09i30y.fsf@sifflez.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Subject: [notmuch] [PATCH] lib: Add a new prefix "listid" to the\r
+       search-terms syntax.\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.12\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 27 Dec 2009 02:06:45 -0000\r
+\r
+\r
+Add support for indexing and searching the message's List-ID header.\r
+This is useful when matching all the messages belonging to a particular\r
+mailing list.\r
+\r
+Signed-off-by: Pablo Oliveira <pablo@sifflez.org>\r
+---\r
+ lib/database.cc |    3 ++-\r
+ lib/index.cc    |   49 ++++++++++++++++++++++++++++++++++++++++++++++++-\r
+ notmuch.1       |    2 ++\r
+ notmuch.c       |    1 +\r
+ 4 files changed, 53 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index b6c4d07..f5d695c 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -124,7 +124,8 @@ prefix_t PROBABILISTIC_PREFIX[]= {\r
+     { "from", "XFROM" },\r
+     { "to", "XTO" },\r
+     { "attachment", "XATTACHMENT" },\r
+-    { "subject", "XSUBJECT"}\r
++    { "subject", "XSUBJECT"},\r
++    { "listid", "XLISTID"}\r
+ };\r
\r
+ int\r
+diff --git a/lib/index.cc b/lib/index.cc\r
+index 125fa6c..b27a1dc 100644\r
+--- a/lib/index.cc\r
++++ b/lib/index.cc\r
+@@ -254,6 +254,50 @@ _index_mime_part (notmuch_message_t *message,\r
+     free (body);\r
+ }\r
\r
++static void\r
++_index_listid (notmuch_message_t *message,\r
++               const char *list_id_header)\r
++{\r
++    const char *begin_list_id, *end_list_id;\r
++\r
++    if (list_id_header == NULL)\r
++      return;\r
++\r
++    /* RFC2919 says that the list-id is found at the end of the header\r
++     * and enclosed between angle brackets. If we cannot find a\r
++     * matching pair of brackets containing at least one character,\r
++     * we ignore the list id header. */\r
++\r
++    begin_list_id = strrchr (list_id_header, '<');\r
++    if (!begin_list_id)\r
++      return;\r
++\r
++    end_list_id = strrchr(begin_list_id, '>');\r
++    if (!end_list_id || (end_list_id - begin_list_id < 2))\r
++      return;\r
++\r
++    void *local = talloc_new (NULL);\r
++\r
++    /* We extract the list id between the angle brackets */\r
++    const char *list_id = talloc_strndup(local, begin_list_id + 1,\r
++                                       end_list_id - begin_list_id - 1);\r
++\r
++    /* All the text before is the description of the list */\r
++    const char *description = talloc_strndup(local, list_id_header,\r
++                                           begin_list_id - list_id_header);\r
++\r
++    /* Description may be RFC2047 encoded */\r
++    char *decoded_desc = g_mime_utils_header_decode_phrase(description);\r
++\r
++    _notmuch_message_gen_terms(message, "listid", list_id);\r
++\r
++    if (decoded_desc)\r
++      _notmuch_message_gen_terms(message, "listid", decoded_desc);\r
++\r
++    free(decoded_desc);\r
++    talloc_free (local);\r
++}\r
++\r
+ notmuch_status_t\r
+ _notmuch_message_index_file (notmuch_message_t *message,\r
+                            const char *filename)\r
+@@ -263,7 +307,7 @@ _notmuch_message_index_file (notmuch_message_t *message,\r
+     GMimeMessage *mime_message = NULL;\r
+     InternetAddressList *addresses;\r
+     FILE *file = NULL;\r
+-    const char *from, *subject;\r
++    const char *from, *subject, *listid;\r
+     notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;\r
+     static int initialized = 0;\r
\r
+@@ -298,6 +342,9 @@ _notmuch_message_index_file (notmuch_message_t *message,\r
+     subject = skip_re_in_subject (subject);\r
+     _notmuch_message_gen_terms (message, "subject", subject);\r
\r
++    listid = g_mime_object_get_header (GMIME_OBJECT(mime_message), "List-Id");\r
++    _index_listid (message, listid);\r
++\r
+     _index_mime_part (message, g_mime_message_get_mime_part (mime_message));\r
\r
+   DONE:\r
+diff --git a/notmuch.1 b/notmuch.1\r
+index 369ecba..2be7056 100644\r
+--- a/notmuch.1\r
++++ b/notmuch.1\r
+@@ -362,6 +362,8 @@ terms to match against specific portions of an email, (where\r
\r
+       thread:<thread-id>\r
\r
++      listid:<list-id>\r
++\r
+ The\r
+ .B from:\r
+ prefix is used to match the name or address of the sender of an email\r
+diff --git a/notmuch.c b/notmuch.c\r
+index 2ac8a59..cc9233b 100644\r
+--- a/notmuch.c\r
++++ b/notmuch.c\r
+@@ -55,6 +55,7 @@ static const char search_terms_help[] =\r
+     "\t\t\ttag:<tag>\n"\r
+     "\t\t\tid:<message-id>\n"\r
+     "\t\t\tthread:<thread-id>\n"\r
++    "\t\t\tlistid:<list-id>\n"\r
+     "\n"\r
+     "\t\tThe from: prefix is used to match the name or address of\n"\r
+     "\t\tthe sender of an email message.\n"\r
+-- \r
+1.6.3.3\r
+\r
+\r