From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 5F6F6431FAF for ; Wed, 3 Apr 2013 06:52:39 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 1.363 X-Spam-Level: * X-Spam-Status: No, score=1.363 tagged_above=-999 required=5 tests=[RDNS_DYNAMIC=0.363, TO_NO_BRKTS_DYNIP=1] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uf-S1i2bJx7s for ; Wed, 3 Apr 2013 06:52:35 -0700 (PDT) X-Greylist: delayed 374 seconds by postgrey-1.32 at olra; Wed, 03 Apr 2013 06:52:35 PDT Received: from mail.raorn.name (c2-81-23-10-117.elastic.cloud.croc.ru [81.23.10.117]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 737F8431FAE for ; Wed, 3 Apr 2013 06:52:35 -0700 (PDT) Received: from fedora.raorn.name (fedora.raorn.name [IPv6:2001:470:1f09:1868:d20d:70ff:fe42:f443]) by mail.raorn.name (Postfix) with ESMTP id 5BC19197; Wed, 3 Apr 2013 17:46:21 +0400 (MSK) Received: by fedora.raorn.name (Postfix, from userid 1000) id C7FCB1002B4; Wed, 3 Apr 2013 17:46:15 +0400 (MSK) From: "Alexey I. Froloff" To: notmuch@notmuchmail.org Subject: [PATCH] lib: Add a new prefix "list" to the search-terms syntax Date: Wed, 3 Apr 2013 17:46:03 +0400 Message-Id: <1364996763-19718-1-git-send-email-raorn@raorn.name> X-Mailer: git-send-email 1.8.1.4 X-Mailman-Approved-At: Wed, 03 Apr 2013 07:02:40 -0700 Cc: "Alexey I. Froloff" X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Apr 2013 13:52:39 -0000 From: "Alexey I. Froloff" Add support for indexing and searching the message's List-Id header. This is useful when matching all the messages belonging to a particular mailing list. Rework of the patch by Pablo Oliveira Cc: Pablo Oliveira Signed-off-by: Alexey I. Froloff --- lib/database.cc | 1 + lib/index.cc | 48 ++++++++++++++++++++++++++++++++++++++++- man/man7/notmuch-search-terms.7 | 8 +++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/lib/database.cc b/lib/database.cc index 91d4329..9311505 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -214,6 +214,7 @@ static prefix_t PROBABILISTIC_PREFIX[]= { { "to", "XTO" }, { "attachment", "XATTACHMENT" }, { "subject", "XSUBJECT"}, + { "list", "XLIST"}, { "folder", "XFOLDER"} }; diff --git a/lib/index.cc b/lib/index.cc index a2edd6d..d79bd95 100644 --- a/lib/index.cc +++ b/lib/index.cc @@ -304,6 +304,49 @@ _index_address_list (notmuch_message_t *message, } } +static void +_index_list_id (notmuch_message_t *message, + const char *list_id_header) +{ + const char *begin_list_id, *end_list_id; + + if (list_id_header == NULL) + return; + + /* RFC2919 says that the list-id is found at the end of the header + * and enclosed between angle brackets. If we cannot find a + * matching pair of brackets containing at least one character, + * we ignore the list id header. */ + begin_list_id = strrchr (list_id_header, '<'); + if (!begin_list_id) + return; + + end_list_id = strrchr(begin_list_id, '>'); + if (!end_list_id || (end_list_id - begin_list_id < 2)) + return; + + void *local = talloc_new (message); + + /* We extract the list id between the angle brackets */ + const char *list_id = talloc_strndup(local, begin_list_id + 1, + end_list_id - begin_list_id - 1); + + /* All the text before is the description of the list */ + const char *description = talloc_strndup(local, list_id_header, + begin_list_id - list_id_header); + + /* Description may be RFC2047 encoded */ + char *decoded_desc = g_mime_utils_header_decode_phrase(description); + + _notmuch_message_gen_terms(message, "list", list_id); + + if (decoded_desc) + _notmuch_message_gen_terms(message, "list", decoded_desc); + + free(decoded_desc); + talloc_free (local); +} + /* Callback to generate terms for each mime part of a message. */ static void _index_mime_part (notmuch_message_t *message, @@ -432,7 +475,7 @@ _notmuch_message_index_file (notmuch_message_t *message, GMimeMessage *mime_message = NULL; InternetAddressList *addresses; FILE *file = NULL; - const char *from, *subject; + const char *from, *subject, *list_id; notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS; static int initialized = 0; char from_buf[5]; @@ -500,6 +543,9 @@ mboxes is deprecated and may be removed in the future.\n", filename); subject = g_mime_message_get_subject (mime_message); _notmuch_message_gen_terms (message, "subject", subject); + list_id = g_mime_object_get_header (GMIME_OBJECT (mime_message), "List-Id"); + _index_list_id (message, list_id); + _index_mime_part (message, g_mime_message_get_mime_part (mime_message)); DONE: diff --git a/man/man7/notmuch-search-terms.7 b/man/man7/notmuch-search-terms.7 index eb417ba..9cae107 100644 --- a/man/man7/notmuch-search-terms.7 +++ b/man/man7/notmuch-search-terms.7 @@ -52,6 +52,8 @@ terms to match against specific portions of an email, (where thread: + list: + folder: date:.. @@ -100,6 +102,12 @@ thread ID values can be seen in the first column of output from .B "notmuch search" The +.BR list: , +is used to match mailing list ID of an email message \- contents of the +List\-Id: header without the '<', '>' delimiters or decoded list +description. + +The .B folder: prefix can be used to search for email message files that are contained within particular directories within the mail store. Only -- 1.8.1.4