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 C1D37431FD0 for ; Mon, 24 Jan 2011 09:13:10 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_NONE=-0.0001] 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 tDhe2tpUpWbz for ; Mon, 24 Jan 2011 09:13:09 -0800 (PST) Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU [18.7.68.37]) by olra.theworths.org (Postfix) with ESMTP id B88F6431FB6 for ; Mon, 24 Jan 2011 09:13:09 -0800 (PST) X-AuditID: 12074425-b7c98ae000000a04-c2-4d3db3245b8e Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) by dmz-mailsec-scanner-8.mit.edu (Symantec Brightmail Gateway) with SMTP id 2E.35.02564.423BD3D4; Mon, 24 Jan 2011 12:13:08 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id p0OHD7oI001297 for ; Mon, 24 Jan 2011 12:13:08 -0500 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p0OHD5hF015922 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 24 Jan 2011 12:13:07 -0500 (EST) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.72) (envelope-from ) id 1PhPyT-0000Gk-Ki for notmuch@notmuchmail.org; Mon, 24 Jan 2011 12:13:05 -0500 Date: Mon, 24 Jan 2011 12:13:05 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: Re: [PATCH 6/8 v2] Support maildir folder search. Message-ID: <20110124171305.GO13226@mit.edu> References: <1295165458-9573-1-git-send-email-amdragon@mit.edu> <1295165458-9573-7-git-send-email-amdragon@mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1295165458-9573-7-git-send-email-amdragon@mit.edu> User-Agent: Mutt/1.5.20 (2009-06-14) X-Brightmail-Tracker: AAAAAA== 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: Mon, 24 Jan 2011 17:13:10 -0000 This implements a folder: query prefix by constructing a wildcard query that matches all files within the specified folder, folder/new, or folder/cur. This works with hierarchical folder names, and accepts both absolute and relative paths. --- Well, that's embarrassing. I somehow lost the critical "tok->wildcard = TRUE;" line below somewhere between testing and posting this patch. This is identical to version 1 of patch 6/8 except this one addition. lib/database.cc | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 57 insertions(+), 0 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index 3af82b0..d42039c 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -582,6 +582,58 @@ transform_type_mail (_notmuch_token_t *root, unused (void *opaque)) return _notmuch_token_create_op (root, TOK_AND, mail_ast, root); } +static _notmuch_token_t * +transform_folder_one (const void *ctx, notmuch_database_t *notmuch, + const char *relpath, const char *rest) +{ + const char *db_path; + notmuch_private_status_t status; + unsigned int doc_id; + _notmuch_token_t *tok; + + /* Get the docid for (relpath + rest). */ + if (*rest) + relpath = talloc_asprintf (ctx, "%s%s", relpath, rest); + db_path = _notmuch_database_get_directory_db_path (relpath); + status = _notmuch_database_find_unique_doc_id (notmuch, "directory", + db_path, &doc_id); + if (db_path != relpath) + free ((char*) db_path); + + /* Construct a wildcard query that matches files in this directory. */ + if (status) + /* Directory doesn't exist. Perhaps this should be an error? */ + doc_id = 0; + tok = _notmuch_token_create_term (ctx, TOK_LIT, + talloc_asprintf (ctx, "%u:", doc_id)); + tok->prefix = _find_prefix ("file-direntry"); + tok->wildcard = TRUE; + return tok; +} + +static _notmuch_token_t * +transform_folder (_notmuch_token_t *root, void *opaque) +{ + if (!root) + return NULL; + if (root->type == TOK_PREFIX && strcmp (root->text, "folder") == 0) { + notmuch_database_t *notmuch = (notmuch_database_t *)opaque; + _notmuch_token_t *lit = root->left, *subs[3], *tok; + const char *relpath; + assert (lit && lit->type == TOK_LIT); + relpath = _notmuch_database_relative_path (notmuch, lit->text); + subs[0] = transform_folder_one (root, notmuch, relpath, ""); + subs[1] = transform_folder_one (root, notmuch, relpath, "/new"); + subs[2] = transform_folder_one (root, notmuch, relpath, "/cur"); + tok = _notmuch_token_create_op (root, TOK_OR, subs[1], subs[2]); + return _notmuch_token_create_op (root, TOK_OR, subs[0], tok); + } + + root->left = transform_folder (root->left, opaque); + root->right = transform_folder (root->right, opaque); + return root; +} + notmuch_database_t * notmuch_database_open (const char *path, notmuch_database_mode_t mode) @@ -690,6 +742,11 @@ notmuch_database_open (const char *path, _notmuch_qparser_add_transform (notmuch->query_parser, transform_type_mail, NULL); + + _notmuch_qparser_add_prefix (notmuch->query_parser, "folder", + TRUE, TRUE); + _notmuch_qparser_add_transform (notmuch->query_parser, + transform_folder, notmuch); } catch (const Xapian::Error &error) { fprintf (stderr, "A Xapian exception occurred opening database: %s\n", error.get_msg().c_str()); -- 1.7.2.3