--- /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 5F6F6431FAF\r
+ for <notmuch@notmuchmail.org>; Wed, 3 Apr 2013 06:52:39 -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 uf-S1i2bJx7s for <notmuch@notmuchmail.org>;\r
+ Wed, 3 Apr 2013 06:52:35 -0700 (PDT)\r
+X-Greylist: delayed 374 seconds by postgrey-1.32 at olra;\r
+ Wed, 03 Apr 2013 06:52:35 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 737F8431FAE\r
+ for <notmuch@notmuchmail.org>; Wed, 3 Apr 2013 06:52:35 -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 5BC19197;\r
+ Wed, 3 Apr 2013 17:46:21 +0400 (MSK)\r
+Received: by fedora.raorn.name (Postfix, from userid 1000)\r
+ id C7FCB1002B4; Wed, 3 Apr 2013 17:46:15 +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, 3 Apr 2013 17:46:03 +0400\r
+Message-Id: <1364996763-19718-1-git-send-email-raorn@raorn.name>\r
+X-Mailer: git-send-email 1.8.1.4\r
+X-Mailman-Approved-At: Wed, 03 Apr 2013 07:02:40 -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: Wed, 03 Apr 2013 13:52:39 -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
+Cc: Pablo Oliveira <pablo@sifflez.org>\r
+Signed-off-by: Alexey I. Froloff <raorn@raorn.name>\r
+---\r
+ lib/database.cc | 1 +\r
+ lib/index.cc | 48 ++++++++++++++++++++++++++++++++++++++++-\r
+ man/man7/notmuch-search-terms.7 | 8 +++++++\r
+ 3 files changed, 56 insertions(+), 1 deletion(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 91d4329..9311505 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -214,6 +214,7 @@ static prefix_t PROBABILISTIC_PREFIX[]= {\r
+ { "to", "XTO" },\r
+ { "attachment", "XATTACHMENT" },\r
+ { "subject", "XSUBJECT"},\r
++ { "list", "XLIST"},\r
+ { "folder", "XFOLDER"}\r
+ };\r
+ \r
+diff --git a/lib/index.cc b/lib/index.cc\r
+index a2edd6d..d79bd95 100644\r
+--- a/lib/index.cc\r
++++ b/lib/index.cc\r
+@@ -304,6 +304,49 @@ _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
++ 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 (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
++ /* 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, "list", list_id);\r
++\r
++ if (decoded_desc)\r
++ _notmuch_message_gen_terms(message, "list", decoded_desc);\r
++\r
++ free(decoded_desc);\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 +475,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 +543,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