--- /dev/null
+Return-Path: <amdragon@mit.edu>\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 1DBC4431FBD\r
+ for <notmuch@notmuchmail.org>; Sun, 9 Mar 2014 09:16:04 -0700 (PDT)\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 4oYsUBcpegRz for <notmuch@notmuchmail.org>;\r
+ Sun, 9 Mar 2014 09:15:56 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-1.mit.edu (dmz-mailsec-scanner-1.mit.edu\r
+ [18.9.25.12])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 026E2431FBC\r
+ for <notmuch@notmuchmail.org>; Sun, 9 Mar 2014 09:15:55 -0700 (PDT)\r
+X-AuditID: 1209190c-f794a6d000000c27-86-531c93bae22b\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+ (using TLS with cipher AES256-SHA (256/256 bits))\r
+ (Client did not present a certificate)\r
+ by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 12.35.03111.AB39C135; Sun, 9 Mar 2014 12:15:54 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+ by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id s29GFqNb007502; \r
+ Sun, 9 Mar 2014 12:15:53 -0400\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+ (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s29GFntX022420\r
+ (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT);\r
+ Sun, 9 Mar 2014 12:15:51 -0400\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1WMgOD-0006mz-GU; Sun, 09 Mar 2014 12:15:49 -0400\r
+Date: Sun, 9 Mar 2014 12:15:48 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Jani Nikula <jani@nikula.org>\r
+Subject: Re: [Patch v3 04/15] lib: make folder: prefix literal\r
+Message-ID: <20140309161548.GO4709@mit.edu>\r
+References: <1394313585-28422-1-git-send-email-david@tethera.net>\r
+ <1394313585-28422-5-git-send-email-david@tethera.net>\r
+ <20140308235127.GL4709@mit.edu> <87pplv69q8.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Content-Disposition: inline\r
+In-Reply-To: <87pplv69q8.fsf@nikula.org>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFupjleLIzCtJLcpLzFFi42IRYrdT1901WSbY4NBFbosbrd2MFk3TnS2u\r
+ 35zJ7MDscev+a3aPZ6tuMXtsOfSeOYA5issmJTUnsyy1SN8ugSvjzdaH7AXnQisur3rA0sD4\r
+ 0KGLkZNDQsBEYt7eY8wQtpjEhXvr2boYuTiEBGYzSXy70w/lbGCUeHL9LCOEc4pJ4vX8o6wQ\r
+ zhJGiYtr5rGB9LMIqEjcvD8XbBabgIbEtv3LGUFsEQFFic0n94PZzAJ2Eke+d4HZwkB238sD\r
+ LCA2r4C2xPWFm6A27GSUuHRoIRNEQlDi5MwnLBDNWhI3/r0EinMA2dISy/9xgIQ5gXa9X3qF\r
+ HcQWBbphysltbBMYhWYh6Z6FpHsWQvcCRuZVjLIpuVW6uYmZOcWpybrFyYl5ealFuoZ6uZkl\r
+ eqkppZsYQcHOKcmzg/HNQaVDjAIcjEo8vB0TpIOFWBPLiitzDzFKcjApifLqA2NFiC8pP6Uy\r
+ I7E4I76oNCe1+BCjBAezkgjv7ElAOd6UxMqq1KJ8mJQ0B4uSOG/fWYlgIYH0xJLU7NTUgtQi\r
+ mKwMB4eSBC8HyFDBotT01Iq0zJwShDQTByfIcB6g4W4gNbzFBYm5xZnpEPlTjIpS4rySIFsF\r
+ QBIZpXlwvbBk9IpRHOgVYV5ZkHYeYCKD634FNJgJaHDzcSmQwSWJCCmpBkYFDz/fGbout62O\r
+ 1Gz+WnTq58oZ94Ue/SmdOJEr9mHpgo/u3M0Ben36ZxkTRB/fzLic//pwv62oc65nhHQ2Q5fC\r
+ OnHv+W8SNvQUcfvMLa3L4bs2d0XD/dnVN+ftlNh+68yMF/EyFWG+xz6cT5R133HYgC/mndGq\r
+ 67mM1trxj/OqBa8ZH1u6pEqJpTgj0VCLuag4EQB8bswzIQMAAA==\r
+Cc: notmuch@notmuchmail.org\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, 09 Mar 2014 16:16:04 -0000\r
+\r
+Quoth Jani Nikula on Mar 09 at 10:45 am:\r
+> On Sun, 09 Mar 2014, Austin Clements <amdragon@MIT.EDU> wrote:\r
+> > Quoth David Bremner on Mar 08 at 5:19 pm:\r
+> >> From: Jani Nikula <jani@nikula.org>\r
+> >> \r
+> >> In xapian terms, convert folder: prefix from probabilistic to boolean\r
+> >> prefix, matching the paths, relative form the maildir root, of the\r
+> >\r
+> > s/form/from/\r
+> >\r
+> >> message files, ignoring the maildir new and cur leaf directories.\r
+> >> \r
+> >> folder:foo matches all message files in foo, foo/new, and foo/cur.\r
+> >> \r
+> >> folder:foo/new does *not* match message files in foo/new.\r
+> >> \r
+> >> folder:"" matches all message files in the top level maildir and its\r
+> >> new and cur subdirectories.\r
+> >> \r
+> >> This change constitutes a database change: bump the database version\r
+> >> and add database upgrade support for folder: terms. The upgrade also\r
+> >> adds path: terms.\r
+> >> ---\r
+> >> lib/database.cc | 38 ++++++++++++++++++++++--\r
+> >> lib/message.cc | 80 ++++++++++++++++++++++++++++++++++++++++++++-------\r
+> >> lib/notmuch-private.h | 3 ++\r
+> >> 3 files changed, 108 insertions(+), 13 deletions(-)\r
+> >> \r
+> >> diff --git a/lib/database.cc b/lib/database.cc\r
+> >> index 93cc7f5..186e3a7 100644\r
+> >> --- a/lib/database.cc\r
+> >> +++ b/lib/database.cc\r
+> >> @@ -42,7 +42,7 @@ typedef struct {\r
+> >> const char *prefix;\r
+> >> } prefix_t;\r
+> >> \r
+> >> -#define NOTMUCH_DATABASE_VERSION 1\r
+> >> +#define NOTMUCH_DATABASE_VERSION 2\r
+> >> \r
+> >> #define STRINGIFY(s) _SUB_STRINGIFY(s)\r
+> >> #define _SUB_STRINGIFY(s) #s\r
+> >> @@ -210,6 +210,7 @@ static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {\r
+> >> { "is", "K" },\r
+> >> { "id", "Q" },\r
+> >> { "path", "P" },\r
+> >> + { "folder", "XFOLDER:" },\r
+> >\r
+> > It took me a while to figure out that the ":" here means that Xapian\r
+> > will unconditionally use a ":" after the prefix, instead of only using\r
+> > a ":" when the first letter following the prefix is upper-case ASCII.\r
+> > Maybe I was only confused by this because I simultaneously knew too\r
+> > much and not enough about Xapian, but it might be worth a comment.\r
+> > Something like,\r
+> >\r
+> > /* Without the ":", since this is a multi-letter prefix, Xapian\r
+> > * will add a colon itself if the first letter of the path is\r
+> > * upper-case ASCII. Including the ":" forces there to always be\r
+> > * a colon, which keeps our own logic simpler. */\r
+> \r
+> Do you mean "... first letter of the _prefix_ is ..."?\r
+\r
+I did mean the path. If the folder prefer were just "XFOLDER", then\r
+Xapian::QueryParser would translate the query folder:foo into the term\r
+XFOLDERfoo like you'd expect, but it would translate the query\r
+folder:Foo into the term XFOLDER:Foo. We'd have to account for this\r
+when constructing terms and (arguably) when removing terms. But\r
+"XFOLDER:" suppresses the colon-adding logic, so these two queries\r
+simply map to XFOLDER:foo and XFOLDER:Foo.\r
+\r
+> Jani.\r
+> \r
+> >\r
+> >> };\r
+> >> \r
+> >> static prefix_t PROBABILISTIC_PREFIX[]= {\r
+> >> @@ -217,7 +218,6 @@ static prefix_t PROBABILISTIC_PREFIX[]= {\r
+> >> { "to", "XTO" },\r
+> >> { "attachment", "XATTACHMENT" },\r
+> >> { "subject", "XSUBJECT"},\r
+> >> - { "folder", "XFOLDER"}\r
+> >> };\r
+> >> \r
+> >> const char *\r
+> >> @@ -1168,6 +1168,40 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
+> >> }\r
+> >> }\r
+> >> \r
+> >> + /*\r
+> >> + * Prior to version 2, the "folder:" prefix was probabilistic and\r
+> >> + * stemmed. Change it to the current boolean prefix. Add "path:"\r
+> >> + * prefixes while at it.\r
+> >> + */\r
+> >> + if (version < 2) {\r
+> >> + notmuch_query_t *query = notmuch_query_create (notmuch, "");\r
+> >\r
+> > Three space indentation and no tabs? (It looks like this was in\r
+> > Jani's v2, also. I'm guessing at some point there was a copy-paste\r
+> > from a diff with tabs converted to spaces?)\r
+> >\r
+> >> + notmuch_messages_t *messages;\r
+> >> + notmuch_message_t *message;\r
+> >> +\r
+> >> + count = 0;\r
+> >> + total = notmuch_query_count_messages (query);\r
+> >> +\r
+> >> + for (messages = notmuch_query_search_messages (query);\r
+> >> + notmuch_messages_valid (messages);\r
+> >> + notmuch_messages_move_to_next (messages)) {\r
+> >> + if (do_progress_notify) {\r
+> >> + progress_notify (closure, (double) count / total);\r
+> >> + do_progress_notify = 0;\r
+> >> + }\r
+> >> +\r
+> >> + message = notmuch_messages_get (messages);\r
+> >> +\r
+> >> + _notmuch_message_upgrade_folder (message);\r
+> >> + _notmuch_message_sync (message);\r
+> >> +\r
+> >> + notmuch_message_destroy (message);\r
+> >> +\r
+> >> + count++;\r
+> >> + }\r
+> >> +\r
+> >> + notmuch_query_destroy (query);\r
+> >> + }\r
+> >> +\r
+> >> db->set_metadata ("version", STRINGIFY (NOTMUCH_DATABASE_VERSION));\r
+> >> db->flush ();\r
+> >> \r
+> >> diff --git a/lib/message.cc b/lib/message.cc\r
+> >> index 21abe8e..31cb9f1 100644\r
+> >> --- a/lib/message.cc\r
+> >> +++ b/lib/message.cc\r
+> >> @@ -504,6 +504,56 @@ _notmuch_message_remove_terms (notmuch_message_t *message, const char *prefix)\r
+> >> }\r
+> >> }\r
+> >> \r
+> >> +/* Return true if p points at "new" or "cur". */\r
+> >> +static bool is_maildir (const char *p)\r
+> >> +{\r
+> >> + return strcmp (p, "cur") == 0 || strcmp (p, "new") == 0;\r
+> >> +}\r
+> >> +\r
+> >> +/* Add "folder:" term for directory. */\r
+> >> +static notmuch_status_t\r
+> >> +_notmuch_message_add_folder_terms (notmuch_message_t *message,\r
+> >> + const char *directory)\r
+> >> +{\r
+> >> + char *folder, *last;\r
+> >> +\r
+> >> + folder = talloc_strdup (NULL, directory);\r
+> >> + if (! folder)\r
+> >> + return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
+> >\r
+> > Same formatting problem in this chunk.\r
+> >\r
+> >> +\r
+> >> + /*\r
+> >> + * If the message file is in a leaf directory named "new" or\r
+> >> + * "cur", presume maildir and index the parent directory. Thus a\r
+> >> + * "folder:" prefix search matches messages in the specified\r
+> >> + * maildir folder, i.e. in the specified directory and its "new"\r
+> >> + * and "cur" subdirectories.\r
+> >> + *\r
+> >> + * Note that this means the "folder:" prefix can't be used for\r
+> >> + * distinguishing between message files in "new" or "cur". The\r
+> >> + * "path:" prefix needs to be used for that.\r
+> >> + *\r
+> >> + * Note the deliberate difference to _filename_is_in_maildir(). We\r
+> >> + * don't want to index different things depending on the existence\r
+> >> + * or non-existence of all maildir sibling directories "new",\r
+> >> + * "cur", and "tmp". Doing so would be surprising, and difficult\r
+> >> + * for the user to fix in case all subdirectories were not in\r
+> >> + * place during indexing.\r
+> >> + */\r
+> >> + last = strrchr (folder, '/');\r
+> >> + if (last) {\r
+> >> + if (is_maildir (last + 1))\r
+> >> + *last = '\0';\r
+> >> + } else if (is_maildir (folder)) {\r
+> >> + *folder = '\0';\r
+> >> + }\r
+> >> +\r
+> >> + _notmuch_message_add_term (message, "folder", folder);\r
+> >> +\r
+> >> + talloc_free (folder);\r
+> >> +\r
+> >> + return NOTMUCH_STATUS_SUCCESS;\r
+> >> +}\r
+> >> +\r
+> >> #define RECURSIVE_SUFFIX "/**"\r
+> >> \r
+> >> /* Add "path:" terms for directory. */\r
+> >> @@ -570,9 +620,8 @@ _notmuch_message_add_directory_terms (void *ctx, notmuch_message_t *message)\r
+> >> directory = _notmuch_database_get_directory_path (ctx,\r
+> >> message->notmuch,\r
+> >> directory_id);\r
+> >> - if (strlen (directory))\r
+> >> - _notmuch_message_gen_terms (message, "folder", directory);\r
+> >> \r
+> >> + _notmuch_message_add_folder_terms (message, directory);\r
+> >> _notmuch_message_add_path_terms (message, directory);\r
+> >> }\r
+> >> \r
+> >> @@ -610,9 +659,7 @@ _notmuch_message_add_filename (notmuch_message_t *message,\r
+> >> * notmuch_directory_get_child_files() . */\r
+> >> _notmuch_message_add_term (message, "file-direntry", direntry);\r
+> >> \r
+> >> - /* New terms allow user to search with folder: specification. */\r
+> >> - _notmuch_message_gen_terms (message, "folder", directory);\r
+> >> -\r
+> >> + _notmuch_message_add_folder_terms (message, directory);\r
+> >> _notmuch_message_add_path_terms (message, directory);\r
+> >> \r
+> >> talloc_free (local);\r
+> >> @@ -637,8 +684,6 @@ _notmuch_message_remove_filename (notmuch_message_t *message,\r
+> >> const char *filename)\r
+> >> {\r
+> >> void *local = talloc_new (message);\r
+> >> - const char *folder_prefix = _find_prefix ("folder");\r
+> >> - char *zfolder_prefix = talloc_asprintf(local, "Z%s", folder_prefix);\r
+> >> char *direntry;\r
+> >> notmuch_private_status_t private_status;\r
+> >> notmuch_status_t status;\r
+> >> @@ -659,10 +704,7 @@ _notmuch_message_remove_filename (notmuch_message_t *message,\r
+> >> /* Re-synchronize "folder:" and "path:" terms for this message. */\r
+> >> \r
+> >> /* Remove all "folder:" terms. */\r
+> >> - _notmuch_message_remove_terms (message, folder_prefix);\r
+> >> -\r
+> >> - /* Remove all "folder:" stemmed terms. */\r
+> >> - _notmuch_message_remove_terms (message, zfolder_prefix);\r
+> >> + _notmuch_message_remove_terms (message, _find_prefix ("folder"));\r
+> >> \r
+> >> /* Remove all "path:" terms. */\r
+> >> _notmuch_message_remove_terms (message, _find_prefix ("path"));\r
+> >> @@ -675,6 +717,22 @@ _notmuch_message_remove_filename (notmuch_message_t *message,\r
+> >> return status;\r
+> >> }\r
+> >> \r
+> >> +/* Upgrade the "folder:" prefix from V1 to V2. */\r
+> >> +#define FOLDER_PREFIX_V1 "XFOLDER"\r
+> >> +#define ZFOLDER_PREFIX_V1 "Z" FOLDER_PREFIX_V1\r
+> >> +void\r
+> >> +_notmuch_message_upgrade_folder (notmuch_message_t *message)\r
+> >> +{\r
+> >> + /* Remove all old "folder:" terms. */\r
+> >> + _notmuch_message_remove_terms (message, FOLDER_PREFIX_V1);\r
+> >> +\r
+> >> + /* Remove all old "folder:" stemmed terms. */\r
+> >> + _notmuch_message_remove_terms (message, ZFOLDER_PREFIX_V1);\r
+> >> +\r
+> >> + /* Add new boolean "folder:" and "path:" terms. */\r
+> >> + _notmuch_message_add_directory_terms (message, message);\r
+> >> +}\r
+> >> +\r
+> >> char *\r
+> >> _notmuch_message_talloc_copy_data (notmuch_message_t *message)\r
+> >> {\r
+> >> diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+> >> index af185c7..59eb2bc 100644\r
+> >> --- a/lib/notmuch-private.h\r
+> >> +++ b/lib/notmuch-private.h\r
+> >> @@ -263,6 +263,9 @@ _notmuch_message_gen_terms (notmuch_message_t *message,\r
+> >> void\r
+> >> _notmuch_message_upgrade_filename_storage (notmuch_message_t *message);\r
+> >> \r
+> >> +void\r
+> >> +_notmuch_message_upgrade_folder (notmuch_message_t *message);\r
+> >> +\r
+> >> notmuch_status_t\r
+> >> _notmuch_message_add_filename (notmuch_message_t *message,\r
+> >> const char *filename);\r