From 4079ea967c18ad197391664ddb3247cd64057eaa Mon Sep 17 00:00:00 2001 From: "Alexey I. Froloff" Date: Wed, 10 Apr 2013 03:16:09 +0400 Subject: [PATCH] [PATCH] lib: Add a new prefix "list" to the search-terms syntax --- a8/1042fec66c3a75ee7eef8a1431de16123b9714 | 185 ++++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 a8/1042fec66c3a75ee7eef8a1431de16123b9714 diff --git a/a8/1042fec66c3a75ee7eef8a1431de16123b9714 b/a8/1042fec66c3a75ee7eef8a1431de16123b9714 new file mode 100644 index 000000000..2f953a373 --- /dev/null +++ b/a8/1042fec66c3a75ee7eef8a1431de16123b9714 @@ -0,0 +1,185 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 8ED2C431FAF + for ; Tue, 9 Apr 2013 16:16:17 -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 05zMaoi7MSL3 for ; + Tue, 9 Apr 2013 16:16:16 -0700 (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 D983C431FAE + for ; Tue, 9 Apr 2013 16:16:15 -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 79A27197; + Wed, 10 Apr 2013 03:16:18 +0400 (MSK) +Received: by fedora.raorn.name (Postfix, from userid 1000) + id 802BF1001B0; Wed, 10 Apr 2013 03:16:11 +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, 10 Apr 2013 03:16:09 +0400 +Message-Id: <1365549369-12776-1-git-send-email-raorn@raorn.name> +X-Mailer: git-send-email 1.8.1.4 +In-Reply-To: <20130409083010.GA27675@raorn.name> +References: <20130409083010.GA27675@raorn.name> +X-Mailman-Approved-At: Wed, 10 Apr 2013 00:48:50 -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: Tue, 09 Apr 2013 23:16:17 -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 + +Differences from original patch: + +The whole list ID indexed as boolean term, not split by words. +List description is not indexed at all. + +Thanks to ojwb and amdragon from irc://irc.freenode.net/notmuch + +Signed-off-by: Alexey I. Froloff +--- + lib/database.cc | 1 + + lib/index.cc | 45 ++++++++++++++++++++++++++++++++++++++++- + man/man7/notmuch-search-terms.7 | 8 ++++++++ + 3 files changed, 53 insertions(+), 1 deletion(-) + +diff --git a/lib/database.cc b/lib/database.cc +index 91d4329..6313913 100644 +--- a/lib/database.cc ++++ b/lib/database.cc +@@ -203,6 +203,7 @@ static prefix_t BOOLEAN_PREFIX_INTERNAL[] = { + }; + + static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = { ++ { "list", "XLIST"}, + { "thread", "G" }, + { "tag", "K" }, + { "is", "K" }, +diff --git a/lib/index.cc b/lib/index.cc +index a2edd6d..8b97ec3 100644 +--- a/lib/index.cc ++++ b/lib/index.cc +@@ -304,6 +304,46 @@ _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) { ++ fprintf (stderr, "Warning: Not indexing mailformed List-Id tag.\n"); ++ return; ++ } ++ ++ end_list_id = strrchr(begin_list_id, '>'); ++ if (!end_list_id || (end_list_id - begin_list_id < 2)) { ++ fprintf (stderr, "Warning: Not indexing mailformed List-Id tag.\n"); ++ 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); ++ ++ /* _notmuch_message_add_term() may return ++ * NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG here. We can't fix it, but ++ * this is not a reason to exit with error... */ ++ if (_notmuch_message_add_term (message, "list", list_id)) ++ fprintf (stderr, "Warning: Not indexing List-Id: <%s>\n", list_id); ++ ++ 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 +472,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 +540,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 + -- 2.26.2