--- /dev/null
+Return-Path: <raorn@raorn.name>\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 8ED2C431FAF\r
+ for <notmuch@notmuchmail.org>; Tue, 9 Apr 2013 16:16:17 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 1.363\r
+X-Spam-Level: *\r
+X-Spam-Status: No, score=1.363 tagged_above=-999 required=5\r
+ tests=[RDNS_DYNAMIC=0.363, TO_NO_BRKTS_DYNIP=1] autolearn=disabled\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 05zMaoi7MSL3 for <notmuch@notmuchmail.org>;\r
+ Tue, 9 Apr 2013 16:16:16 -0700 (PDT)\r
+Received: from mail.raorn.name (c2-81-23-10-117.elastic.cloud.croc.ru\r
+ [81.23.10.117])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id D983C431FAE\r
+ for <notmuch@notmuchmail.org>; Tue, 9 Apr 2013 16:16:15 -0700 (PDT)\r
+Received: from fedora.raorn.name (fedora.raorn.name\r
+ [IPv6:2001:470:1f09:1868:d20d:70ff:fe42:f443])\r
+ by mail.raorn.name (Postfix) with ESMTP id 79A27197;\r
+ Wed, 10 Apr 2013 03:16:18 +0400 (MSK)\r
+Received: by fedora.raorn.name (Postfix, from userid 1000)\r
+ id 802BF1001B0; Wed, 10 Apr 2013 03:16:11 +0400 (MSK)\r
+From: "Alexey I. Froloff" <raorn@raorn.name>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] lib: Add a new prefix "list" to the search-terms syntax\r
+Date: Wed, 10 Apr 2013 03:16:09 +0400\r
+Message-Id: <1365549369-12776-1-git-send-email-raorn@raorn.name>\r
+X-Mailer: git-send-email 1.8.1.4\r
+In-Reply-To: <20130409083010.GA27675@raorn.name>\r
+References: <20130409083010.GA27675@raorn.name>\r
+X-Mailman-Approved-At: Wed, 10 Apr 2013 00:48:50 -0700\r
+Cc: "Alexey I. Froloff" <raorn@raorn.name>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\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: Tue, 09 Apr 2013 23:16:17 -0000\r
+\r
+From: "Alexey I. Froloff" <raorn@raorn.name>\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
+Rework of the patch by Pablo Oliveira <pablo@sifflez.org>\r
+\r
+Differences from original patch:\r
+\r
+The whole list ID indexed as boolean term, not split by words.\r
+List description is not indexed at all.\r
+\r
+Thanks to ojwb and amdragon from irc://irc.freenode.net/notmuch\r
+\r
+Signed-off-by: Alexey I. Froloff <raorn@raorn.name>\r
+---\r
+ lib/database.cc | 1 +\r
+ lib/index.cc | 45 ++++++++++++++++++++++++++++++++++++++++-\r
+ man/man7/notmuch-search-terms.7 | 8 ++++++++\r
+ 3 files changed, 53 insertions(+), 1 deletion(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 91d4329..6313913 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -203,6 +203,7 @@ static prefix_t BOOLEAN_PREFIX_INTERNAL[] = {\r
+ };\r
+ \r
+ static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {\r
++ { "list", "XLIST"},\r
+ { "thread", "G" },\r
+ { "tag", "K" },\r
+ { "is", "K" },\r
+diff --git a/lib/index.cc b/lib/index.cc\r
+index a2edd6d..8b97ec3 100644\r
+--- a/lib/index.cc\r
++++ b/lib/index.cc\r
+@@ -304,6 +304,46 @@ _index_address_list (notmuch_message_t *message,\r
+ }\r
+ }\r
+ \r
++static void\r
++_index_list_id (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
++ begin_list_id = strrchr (list_id_header, '<');\r
++ if (!begin_list_id) {\r
++ fprintf (stderr, "Warning: Not indexing mailformed List-Id tag.\n");\r
++ return;\r
++ }\r
++\r
++ end_list_id = strrchr(begin_list_id, '>');\r
++ if (!end_list_id || (end_list_id - begin_list_id < 2)) {\r
++ fprintf (stderr, "Warning: Not indexing mailformed List-Id tag.\n");\r
++ return;\r
++ }\r
++\r
++ void *local = talloc_new (message);\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
++ /* _notmuch_message_add_term() may return\r
++ * NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG here. We can't fix it, but\r
++ * this is not a reason to exit with error... */\r
++ if (_notmuch_message_add_term (message, "list", list_id))\r
++ fprintf (stderr, "Warning: Not indexing List-Id: <%s>\n", list_id);\r
++\r
++ talloc_free (local);\r
++}\r
++\r
+ /* Callback to generate terms for each mime part of a message. */\r
+ static void\r
+ _index_mime_part (notmuch_message_t *message,\r
+@@ -432,7 +472,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, *list_id;\r
+ notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;\r
+ static int initialized = 0;\r
+ char from_buf[5];\r
+@@ -500,6 +540,9 @@ mboxes is deprecated and may be removed in the future.\n", filename);\r
+ subject = g_mime_message_get_subject (mime_message);\r
+ _notmuch_message_gen_terms (message, "subject", subject);\r
+ \r
++ list_id = g_mime_object_get_header (GMIME_OBJECT (mime_message), "List-Id");\r
++ _index_list_id (message, list_id);\r
++\r
+ _index_mime_part (message, g_mime_message_get_mime_part (mime_message));\r
+ \r
+ DONE:\r
+diff --git a/man/man7/notmuch-search-terms.7 b/man/man7/notmuch-search-terms.7\r
+index eb417ba..9cae107 100644\r
+--- a/man/man7/notmuch-search-terms.7\r
++++ b/man/man7/notmuch-search-terms.7\r
+@@ -52,6 +52,8 @@ terms to match against specific portions of an email, (where\r
+ \r
+ thread:<thread-id>\r
+ \r
++ list:<list-id>\r
++\r
+ folder:<directory-path>\r
+ \r
+ date:<since>..<until>\r
+@@ -100,6 +102,12 @@ thread ID values can be seen in the first column of output from\r
+ .B "notmuch search"\r
+ \r
+ The\r
++.BR list: ,\r
++is used to match mailing list ID of an email message \- contents of the\r
++List\-Id: header without the '<', '>' delimiters or decoded list\r
++description.\r
++\r
++The\r
+ .B folder:\r
+ prefix can be used to search for email message files that are\r
+ contained within particular directories within the mail store. Only\r
+-- \r
+1.8.1.4\r
+\r