From 61dddfee00487f4ab01ed0fa4483a2209c20bb3d Mon Sep 17 00:00:00 2001 From: Peter Zijlstra Date: Tue, 12 Nov 2013 16:56:37 +0100 Subject: [PATCH] [PATCH] notmuch: Add "maildir:" search option --- 8a/7e1143d4479fea26a3ed8bba7b5e23f4263a94 | 202 ++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 8a/7e1143d4479fea26a3ed8bba7b5e23f4263a94 diff --git a/8a/7e1143d4479fea26a3ed8bba7b5e23f4263a94 b/8a/7e1143d4479fea26a3ed8bba7b5e23f4263a94 new file mode 100644 index 000000000..ebfce8e64 --- /dev/null +++ b/8a/7e1143d4479fea26a3ed8bba7b5e23f4263a94 @@ -0,0 +1,202 @@ +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 18337431FBF + for ; Tue, 12 Nov 2013 07:56:52 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -2.3 +X-Spam-Level: +X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_MED=-2.3] 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 hei5nDsg-TOx for ; + Tue, 12 Nov 2013 07:56:40 -0800 (PST) +Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 8FF09431FAF + for ; Tue, 12 Nov 2013 07:56:40 -0800 (PST) +Received: from dhcp-077-248-225-117.chello.nl ([77.248.225.117] helo=laptop) + by merlin.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) + id 1VgGKV-0002kK-CS + for notmuch@notmuchmail.org; Tue, 12 Nov 2013 15:56:39 +0000 +Received: by laptop (Postfix, from userid 1000) + id 85663103E57BE; Tue, 12 Nov 2013 16:56:37 +0100 (CET) +Date: Tue, 12 Nov 2013 16:56:37 +0100 +From: Peter Zijlstra +To: notmuch@notmuchmail.org +Subject: [PATCH] notmuch: Add "maildir:" search option +Message-ID: <20131112155637.GA16796@laptop.programming.kicks-ass.net> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +User-Agent: Mutt/1.5.21 (2012-12-30) +X-Mailman-Approved-At: Tue, 12 Nov 2013 08:02:58 -0800 +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, 12 Nov 2013 15:56:52 -0000 + +Subject: notmuch: Add "maildir:" search option + +The current "folder:" search terms are near useless when you have +recursive folders, introduce a boolean "maildir:" search term to +exactly match the maildir folder. + +Given a Maildir++ layout like: + + ~/Maildir/ + ~/Maildir/cur + ~/Maildir/new + ~/Maildir/tmp + ~/Maildir/.Sent + ~/Maildir/.Sent/cur + ~/Maildir/.Sent/new + ~/Maildir/.Sent/tmp + ~/Maildir/.INBOX.LKML + ~/Maildir/.INBOX.LKML/cur + ~/Maildir/.INBOX.LKML/new + ~/Maildir/.INBOX.LKML/tmp + ~/Maildir/.INBOX.LKML.netdev + ~/Maildir/.INBOX.LKML.netdev/cur + ~/Maildir/.INBOX.LKML.netdev/new + ~/Maildir/.INBOX.LKML.netdev/tmp + ~/Maildir/.INBOX.LKML.arch + ~/Maildir/.INBOX.LKML.arch/cur + ~/Maildir/.INBOX.LKML.arch/new + ~/Maildir/.INBOX.LKML.arch/tmp + +This patch generates the following search index: + + $ delve -a Maildir/.notmuch/xapian/ | ~/s XMAILDIR + XMAILDIR:INBOX + XMAILDIR:INBOX/LKML + XMAILDIR:INBOX/LKML/arch + XMAILDIR:INBOX/LKML/netdev + XMAILDIR:Sent + +Which allows one (me!!1) to pose queries like: + + maildir:INBOX and not tag:list + +to more easily find offlist mail (from people like my family who don't +actually send their stuff over LKML :-). + +Signed-off-by: Peter Zijlstra +--- + +XXX: now I need to go figure out how to do searches like: + + subject:PATCH/0 + +which would mandate that PATCH is the first word occurring in the +subject. I think the position index holds enough information but I +need to look into that and obviously the query parser needs work for +this. + + + lib/database.cc | 7 ++++--- + lib/message.cc | 40 ++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 44 insertions(+), 3 deletions(-) + +diff --git a/lib/database.cc b/lib/database.cc +index a021bf17253c..53aeaa68954d 100644 +--- a/lib/database.cc ++++ b/lib/database.cc +@@ -208,15 +208,16 @@ static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = { + { "thread", "G" }, + { "tag", "K" }, + { "is", "K" }, +- { "id", "Q" } ++ { "id", "Q" }, ++ { "maildir", "XMAILDIR:" }, + }; + + static prefix_t PROBABILISTIC_PREFIX[]= { + { "from", "XFROM" }, + { "to", "XTO" }, + { "attachment", "XATTACHMENT" }, +- { "subject", "XSUBJECT"}, +- { "folder", "XFOLDER"} ++ { "subject", "XSUBJECT" }, ++ { "folder", "XFOLDER" }, + }; + + const char * +diff --git a/lib/message.cc b/lib/message.cc +index 1b4637950f8e..45a727a6208f 100644 +--- a/lib/message.cc ++++ b/lib/message.cc +@@ -22,6 +22,7 @@ + #include "database-private.h" + + #include ++#include + + #include + +@@ -485,6 +486,8 @@ _notmuch_message_add_filename (notmuch_message_t *message, + notmuch_status_t status; + void *local = talloc_new (message); + char *direntry; ++ char *maildir; ++ int i; + + if (filename == NULL) + INTERNAL_ERROR ("Message filename cannot be NULL."); +@@ -507,6 +510,43 @@ _notmuch_message_add_filename (notmuch_message_t *message, + /* New terms allow user to search with folder: specification. */ + _notmuch_message_gen_terms (message, "folder", directory); + ++ /* Convert the directory into a maildir path */ ++ maildir = talloc_strdup(local, directory); ++ ++ /* Strip the maildir "cur", "new" directory entries. */ ++ i = strlen(maildir); ++ if (strncmp(maildir + i - 3, "cur", 3) == 0 || ++ strncmp(maildir + i - 3, "new", 3) == 0) { ++ maildir[i - 3] = '\0'; ++ i -= 3; ++ } ++ ++ /* Strip trailing '/' */ ++ while (maildir[i-1] == '/') { ++ maildir[i-1] = '\0'; ++ i--; ++ } ++ ++ /* Strip leading '/' */ ++ while (maildir[0] == '/') ++ maildir++; ++ ++ /* Strip leading '.' */ ++ while (maildir[0] == '.') ++ maildir++; ++ ++ /* Replace all remaining '.' with '/' */ ++ for (i = 0; maildir[i]; i++) { ++ if (maildir[i] == '.') ++ maildir[i] = '/'; ++ } ++ ++ /* If there's no string left, we're the "INBOX" */ ++ if (maildir[0] == '\0') ++ maildir = talloc_strdup(local, "INBOX"); ++ ++ _notmuch_message_add_term (message, "maildir", maildir); ++ + talloc_free (local); + + return NOTMUCH_STATUS_SUCCESS; -- 2.26.2