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 1BB97429E2F for ; Sun, 12 Jan 2014 07:54:06 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 QGlgr1SUVk4n for ; Sun, 12 Jan 2014 07:53:57 -0800 (PST) Received: from mail-ea0-f175.google.com (mail-ea0-f175.google.com [209.85.215.175]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 6A1C9431FAE for ; Sun, 12 Jan 2014 07:53:57 -0800 (PST) Received: by mail-ea0-f175.google.com with SMTP id z10so2882467ead.34 for ; Sun, 12 Jan 2014 07:53:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:in-reply-to:references :user-agent:date:message-id:mime-version:content-type; bh=YnE7KdWNVED3swQpS8Ul+Iiya3B3J3Dp6JDMonkPnIQ=; b=ADvLS+BS9dfinVRg5YeYNEtjQ7htPn13HULAM7OLOfXlGHMOEaRRW4ZTlDjLp0T/90 YVS2scSsQ1gZkF5pveYA51+OCgiYnlf1mnk6dD7kKldO07cHUobyrPZhz/foEw7Cw1gY LNtRRA1r1hUbNF+hQxZQ6huyttlRjzRfhA4jIte2I6mpQPq/LPlFAAIpWBZslDGQXwLC Zh4jJ/5whIjqGa82Pc2IhPvocIYCrLOo0CBm73iMLTZ9qjpwlBujbtofS0ylcJ7c+sTW SoXWAMoaJpz8mEpLJnYTA5IjPOY8a3WIH3SURS4TxYbK7qfTEvTEP7Bb/lisf2/1sqxK PxGw== X-Gm-Message-State: ALoCoQk1dRvLh2HL/DfAgka3XjrFP2bPXn00uApuAHO/6JGVE5TnsvFWBXrARvsBQvOUK/sgfe8y X-Received: by 10.14.211.195 with SMTP id w43mr9925838eeo.100.1389542036266; Sun, 12 Jan 2014 07:53:56 -0800 (PST) Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi. [88.195.111.91]) by mx.google.com with ESMTPSA id v7sm32012840eel.2.2014.01.12.07.53.54 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 12 Jan 2014 07:53:55 -0800 (PST) From: Jani Nikula To: Peter Zijlstra , notmuch@notmuchmail.org Subject: Re: [PATCH] notmuch: Add "maildir:" search option In-Reply-To: <20131112155637.GA16796@laptop.programming.kicks-ass.net> References: <20131112155637.GA16796@laptop.programming.kicks-ass.net> User-Agent: Notmuch/0.17~rc2+18~g39a67a6 (http://notmuchmail.org) Emacs/24.3.1 (x86_64-pc-linux-gnu) Date: Sun, 12 Jan 2014 17:53:52 +0200 Message-ID: <8761ppurfz.fsf@nikula.org> MIME-Version: 1.0 Content-Type: text/plain 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: Sun, 12 Jan 2014 15:54:06 -0000 On Tue, 12 Nov 2013, Peter Zijlstra wrote: > 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. Hi Peter - Per some discussion on IRC about the usefulness of the current "folder:" prefix, I went ahead and sent patches to make "folder:" a boolean prefix [1]. It's not the same as your "maildir:" implementation, but I believe you could use it to achieve the things you want with that. In particular, my proposed "folder:" prefix is the literal path from maildir root, and does not make any assumptions about maildir - i.e. it requires the final cur/new too. (That can be useful for some mutt users who need the cur/new distinction.) I am not opposed to adding another prefix like "maildir:" that does make assumptions on the mail storage and transformations on the path, but I do think it would be less important with the boolean "folder:" in place. BR, Jani. [1] id:cover.1389304779.git.jani@nikula.org > > 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; > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch