--- /dev/null
+Return-Path: <jani@nikula.org>\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 1BB97429E2F\r
+ for <notmuch@notmuchmail.org>; Sun, 12 Jan 2014 07:54:06 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 QGlgr1SUVk4n for <notmuch@notmuchmail.org>;\r
+ Sun, 12 Jan 2014 07:53:57 -0800 (PST)\r
+Received: from mail-ea0-f175.google.com (mail-ea0-f175.google.com\r
+ [209.85.215.175]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 6A1C9431FAE\r
+ for <notmuch@notmuchmail.org>; Sun, 12 Jan 2014 07:53:57 -0800 (PST)\r
+Received: by mail-ea0-f175.google.com with SMTP id z10so2882467ead.34\r
+ for <notmuch@notmuchmail.org>; Sun, 12 Jan 2014 07:53:56 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:subject:in-reply-to:references\r
+ :user-agent:date:message-id:mime-version:content-type;\r
+ bh=YnE7KdWNVED3swQpS8Ul+Iiya3B3J3Dp6JDMonkPnIQ=;\r
+ b=ADvLS+BS9dfinVRg5YeYNEtjQ7htPn13HULAM7OLOfXlGHMOEaRRW4ZTlDjLp0T/90\r
+ YVS2scSsQ1gZkF5pveYA51+OCgiYnlf1mnk6dD7kKldO07cHUobyrPZhz/foEw7Cw1gY\r
+ LNtRRA1r1hUbNF+hQxZQ6huyttlRjzRfhA4jIte2I6mpQPq/LPlFAAIpWBZslDGQXwLC\r
+ Zh4jJ/5whIjqGa82Pc2IhPvocIYCrLOo0CBm73iMLTZ9qjpwlBujbtofS0ylcJ7c+sTW\r
+ SoXWAMoaJpz8mEpLJnYTA5IjPOY8a3WIH3SURS4TxYbK7qfTEvTEP7Bb/lisf2/1sqxK\r
+ PxGw==\r
+X-Gm-Message-State:\r
+ ALoCoQk1dRvLh2HL/DfAgka3XjrFP2bPXn00uApuAHO/6JGVE5TnsvFWBXrARvsBQvOUK/sgfe8y\r
+X-Received: by 10.14.211.195 with SMTP id w43mr9925838eeo.100.1389542036266;\r
+ Sun, 12 Jan 2014 07:53:56 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.\r
+ [88.195.111.91])\r
+ by mx.google.com with ESMTPSA id v7sm32012840eel.2.2014.01.12.07.53.54\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Sun, 12 Jan 2014 07:53:55 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Peter Zijlstra <peterz@infradead.org>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH] notmuch: Add "maildir:" search option\r
+In-Reply-To: <20131112155637.GA16796@laptop.programming.kicks-ass.net>\r
+References: <20131112155637.GA16796@laptop.programming.kicks-ass.net>\r
+User-Agent: Notmuch/0.17~rc2+18~g39a67a6 (http://notmuchmail.org) Emacs/24.3.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Sun, 12 Jan 2014 17:53:52 +0200\r
+Message-ID: <8761ppurfz.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\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: Sun, 12 Jan 2014 15:54:06 -0000\r
+\r
+On Tue, 12 Nov 2013, Peter Zijlstra <peterz@infradead.org> wrote:\r
+> Subject: notmuch: Add "maildir:" search option\r
+>\r
+> The current "folder:" search terms are near useless when you have\r
+> recursive folders, introduce a boolean "maildir:" search term to\r
+> exactly match the maildir folder.\r
+\r
+Hi Peter -\r
+\r
+Per some discussion on IRC about the usefulness of the current "folder:"\r
+prefix, I went ahead and sent patches to make "folder:" a boolean prefix\r
+[1]. It's not the same as your "maildir:" implementation, but I believe\r
+you could use it to achieve the things you want with that. In\r
+particular, my proposed "folder:" prefix is the literal path from\r
+maildir root, and does not make any assumptions about maildir - i.e. it\r
+requires the final cur/new too. (That can be useful for some mutt users\r
+who need the cur/new distinction.)\r
+\r
+I am not opposed to adding another prefix like "maildir:" that does make\r
+assumptions on the mail storage and transformations on the path, but I\r
+do think it would be less important with the boolean "folder:" in place.\r
+\r
+BR,\r
+Jani.\r
+\r
+\r
+[1] id:cover.1389304779.git.jani@nikula.org\r
+\r
+\r
+\r
+>\r
+> Given a Maildir++ layout like:\r
+>\r
+> ~/Maildir/\r
+> ~/Maildir/cur\r
+> ~/Maildir/new\r
+> ~/Maildir/tmp\r
+> ~/Maildir/.Sent\r
+> ~/Maildir/.Sent/cur\r
+> ~/Maildir/.Sent/new\r
+> ~/Maildir/.Sent/tmp\r
+> ~/Maildir/.INBOX.LKML\r
+> ~/Maildir/.INBOX.LKML/cur\r
+> ~/Maildir/.INBOX.LKML/new\r
+> ~/Maildir/.INBOX.LKML/tmp\r
+> ~/Maildir/.INBOX.LKML.netdev\r
+> ~/Maildir/.INBOX.LKML.netdev/cur\r
+> ~/Maildir/.INBOX.LKML.netdev/new\r
+> ~/Maildir/.INBOX.LKML.netdev/tmp\r
+> ~/Maildir/.INBOX.LKML.arch\r
+> ~/Maildir/.INBOX.LKML.arch/cur\r
+> ~/Maildir/.INBOX.LKML.arch/new\r
+> ~/Maildir/.INBOX.LKML.arch/tmp\r
+>\r
+> This patch generates the following search index:\r
+>\r
+> $ delve -a Maildir/.notmuch/xapian/ | ~/s XMAILDIR\r
+> XMAILDIR:INBOX\r
+> XMAILDIR:INBOX/LKML\r
+> XMAILDIR:INBOX/LKML/arch\r
+> XMAILDIR:INBOX/LKML/netdev\r
+> XMAILDIR:Sent\r
+>\r
+> Which allows one (me!!1) to pose queries like:\r
+>\r
+> maildir:INBOX and not tag:list\r
+>\r
+> to more easily find offlist mail (from people like my family who don't\r
+> actually send their stuff over LKML :-).\r
+>\r
+> Signed-off-by: Peter Zijlstra <peterz@infradead.org>\r
+> ---\r
+>\r
+> XXX: now I need to go figure out how to do searches like:\r
+>\r
+> subject:PATCH/0\r
+>\r
+> which would mandate that PATCH is the first word occurring in the\r
+> subject. I think the position index holds enough information but I\r
+> need to look into that and obviously the query parser needs work for\r
+> this.\r
+>\r
+>\r
+> lib/database.cc | 7 ++++---\r
+> lib/message.cc | 40 ++++++++++++++++++++++++++++++++++++++++\r
+> 2 files changed, 44 insertions(+), 3 deletions(-)\r
+>\r
+> diff --git a/lib/database.cc b/lib/database.cc\r
+> index a021bf17253c..53aeaa68954d 100644\r
+> --- a/lib/database.cc\r
+> +++ b/lib/database.cc\r
+> @@ -208,15 +208,16 @@ static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {\r
+> { "thread", "G" },\r
+> { "tag", "K" },\r
+> { "is", "K" },\r
+> - { "id", "Q" }\r
+> + { "id", "Q" },\r
+> + { "maildir", "XMAILDIR:" },\r
+> };\r
+> \r
+> static prefix_t PROBABILISTIC_PREFIX[]= {\r
+> { "from", "XFROM" },\r
+> { "to", "XTO" },\r
+> { "attachment", "XATTACHMENT" },\r
+> - { "subject", "XSUBJECT"},\r
+> - { "folder", "XFOLDER"}\r
+> + { "subject", "XSUBJECT" },\r
+> + { "folder", "XFOLDER" },\r
+> };\r
+> \r
+> const char *\r
+> diff --git a/lib/message.cc b/lib/message.cc\r
+> index 1b4637950f8e..45a727a6208f 100644\r
+> --- a/lib/message.cc\r
+> +++ b/lib/message.cc\r
+> @@ -22,6 +22,7 @@\r
+> #include "database-private.h"\r
+> \r
+> #include <stdint.h>\r
+> +#include <string.h>\r
+> \r
+> #include <gmime/gmime.h>\r
+> \r
+> @@ -485,6 +486,8 @@ _notmuch_message_add_filename (notmuch_message_t *message,\r
+> notmuch_status_t status;\r
+> void *local = talloc_new (message);\r
+> char *direntry;\r
+> + char *maildir;\r
+> + int i;\r
+> \r
+> if (filename == NULL)\r
+> INTERNAL_ERROR ("Message filename cannot be NULL.");\r
+> @@ -507,6 +510,43 @@ _notmuch_message_add_filename (notmuch_message_t *message,\r
+> /* New terms allow user to search with folder: specification. */\r
+> _notmuch_message_gen_terms (message, "folder", directory);\r
+> \r
+> + /* Convert the directory into a maildir path */\r
+> + maildir = talloc_strdup(local, directory);\r
+> +\r
+> + /* Strip the maildir "cur", "new" directory entries. */\r
+> + i = strlen(maildir);\r
+> + if (strncmp(maildir + i - 3, "cur", 3) == 0 ||\r
+> + strncmp(maildir + i - 3, "new", 3) == 0) {\r
+> + maildir[i - 3] = '\0';\r
+> + i -= 3;\r
+> + }\r
+> +\r
+> + /* Strip trailing '/' */\r
+> + while (maildir[i-1] == '/') {\r
+> + maildir[i-1] = '\0';\r
+> + i--;\r
+> + }\r
+> +\r
+> + /* Strip leading '/' */\r
+> + while (maildir[0] == '/')\r
+> + maildir++;\r
+> +\r
+> + /* Strip leading '.' */\r
+> + while (maildir[0] == '.')\r
+> + maildir++;\r
+> +\r
+> + /* Replace all remaining '.' with '/' */\r
+> + for (i = 0; maildir[i]; i++) {\r
+> + if (maildir[i] == '.')\r
+> + maildir[i] = '/';\r
+> + }\r
+> +\r
+> + /* If there's no string left, we're the "INBOX" */\r
+> + if (maildir[0] == '\0')\r
+> + maildir = talloc_strdup(local, "INBOX");\r
+> +\r
+> + _notmuch_message_add_term (message, "maildir", maildir);\r
+> +\r
+> talloc_free (local);\r
+> \r
+> return NOTMUCH_STATUS_SUCCESS;\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r