RE: Reply all - issue
[notmuch-archives.git] / ba / 309e1941831f586f391865e2c8bbe74137e38f
1 Return-Path: <amthrax@drake.mit.edu>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 3EABD42D28F\r
6         for <notmuch@notmuchmail.org>; Sun, 16 Jan 2011 00:11:39 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id Tea0jO-JVXzp for <notmuch@notmuchmail.org>;\r
16         Sun, 16 Jan 2011 00:11:37 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU\r
18         [18.7.68.34])\r
19         by olra.theworths.org (Postfix) with ESMTP id B847942D29A\r
20         for <notmuch@notmuchmail.org>; Sun, 16 Jan 2011 00:11:24 -0800 (PST)\r
21 X-AuditID: 12074422-b7c3eae000000a70-4f-4d32a82c456f\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
23         by dmz-mailsec-scanner-5.mit.edu (Symantec Brightmail Gateway) with\r
24         SMTP id 48.9A.02672.C28A23D4; Sun, 16 Jan 2011 03:11:24 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id p0G8BOcR004723; \r
27         Sun, 16 Jan 2011 03:11:24 -0500\r
28 Received: from drake.mit.edu (a074.catapulsion.net [70.36.81.74])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p0G8BMwV010525\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Sun, 16 Jan 2011 03:11:23 -0500 (EST)\r
34 Received: from amthrax by drake.mit.edu with local (Exim 4.72)\r
35         (envelope-from <amthrax@drake.mit.edu>)\r
36         id 1PeNhq-0002Xd-FG; Sun, 16 Jan 2011 03:11:22 -0500\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH 6/8] Support maildir folder search.\r
40 Date: Sun, 16 Jan 2011 03:10:56 -0500\r
41 Message-Id: <1295165458-9573-7-git-send-email-amdragon@mit.edu>\r
42 X-Mailer: git-send-email 1.7.2.3\r
43 In-Reply-To: <1295165458-9573-1-git-send-email-amdragon@mit.edu>\r
44 References: <1295165458-9573-1-git-send-email-amdragon@mit.edu>\r
45 X-Brightmail-Tracker: AAAAAA==\r
46 Cc: amdragon@mit.edu\r
47 X-BeenThere: notmuch@notmuchmail.org\r
48 X-Mailman-Version: 2.1.13\r
49 Precedence: list\r
50 List-Id: "Use and development of the notmuch mail system."\r
51         <notmuch.notmuchmail.org>\r
52 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
54 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
55 List-Post: <mailto:notmuch@notmuchmail.org>\r
56 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
57 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
58         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
59 X-List-Received-Date: Sun, 16 Jan 2011 08:11:39 -0000\r
60 \r
61 This implements a folder: query prefix by constructing a wildcard\r
62 query that matches all files within the specified folder, folder/new,\r
63 or folder/cur.  This works with hierarchical folder names, and accepts\r
64 both absolute and relative paths.\r
65 ---\r
66  lib/database.cc |   56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
67  1 files changed, 56 insertions(+), 0 deletions(-)\r
68 \r
69 diff --git a/lib/database.cc b/lib/database.cc\r
70 index 3af82b0..20fd412 100644\r
71 --- a/lib/database.cc\r
72 +++ b/lib/database.cc\r
73 @@ -582,6 +582,57 @@ transform_type_mail (_notmuch_token_t *root, unused (void *opaque))\r
74      return _notmuch_token_create_op (root, TOK_AND, mail_ast, root);\r
75  }\r
76  \r
77 +static _notmuch_token_t *\r
78 +transform_folder_one (const void *ctx, notmuch_database_t *notmuch,\r
79 +                     const char *relpath, const char *rest)\r
80 +{\r
81 +    const char *db_path;\r
82 +    notmuch_private_status_t status;\r
83 +    unsigned int doc_id;\r
84 +    _notmuch_token_t *tok;\r
85 +\r
86 +    /* Get the docid for (relpath + rest). */\r
87 +    if (*rest)\r
88 +       relpath = talloc_asprintf (ctx, "%s%s", relpath, rest);\r
89 +    db_path = _notmuch_database_get_directory_db_path (relpath);\r
90 +    status = _notmuch_database_find_unique_doc_id (notmuch, "directory",\r
91 +                                                  db_path, &doc_id);\r
92 +    if (db_path != relpath)\r
93 +       free ((char*) db_path);\r
94 +\r
95 +    /* Construct a wildcard query that matches files in this directory. */\r
96 +    if (status)\r
97 +       /* Directory doesn't exist.  Perhaps this should be an error? */\r
98 +       doc_id = 0;\r
99 +    tok = _notmuch_token_create_term (ctx, TOK_LIT,\r
100 +                                     talloc_asprintf (ctx, "%u:", doc_id));\r
101 +    tok->prefix = _find_prefix ("file-direntry");\r
102 +    return tok;\r
103 +}\r
104 +\r
105 +static _notmuch_token_t *\r
106 +transform_folder (_notmuch_token_t *root, void *opaque)\r
107 +{\r
108 +    if (!root)\r
109 +       return NULL;\r
110 +    if (root->type == TOK_PREFIX && strcmp (root->text, "folder") == 0) {\r
111 +       notmuch_database_t *notmuch = (notmuch_database_t *)opaque;\r
112 +       _notmuch_token_t *lit = root->left, *subs[3], *tok;\r
113 +       const char *relpath;\r
114 +       assert (lit && lit->type == TOK_LIT);\r
115 +       relpath = _notmuch_database_relative_path (notmuch, lit->text);\r
116 +       subs[0] = transform_folder_one (root, notmuch, relpath, "");\r
117 +       subs[1] = transform_folder_one (root, notmuch, relpath, "/new");\r
118 +       subs[2] = transform_folder_one (root, notmuch, relpath, "/cur");\r
119 +       tok = _notmuch_token_create_op (root, TOK_OR, subs[1], subs[2]);\r
120 +       return _notmuch_token_create_op (root, TOK_OR, subs[0], tok);\r
121 +    }\r
122 +\r
123 +    root->left = transform_folder (root->left, opaque);\r
124 +    root->right = transform_folder (root->right, opaque);\r
125 +    return root;\r
126 +}\r
127 +\r
128  notmuch_database_t *\r
129  notmuch_database_open (const char *path,\r
130                        notmuch_database_mode_t mode)\r
131 @@ -690,6 +741,11 @@ notmuch_database_open (const char *path,\r
132  \r
133         _notmuch_qparser_add_transform (notmuch->query_parser,\r
134                                         transform_type_mail, NULL);\r
135 +\r
136 +       _notmuch_qparser_add_prefix (notmuch->query_parser, "folder",\r
137 +                                    TRUE, TRUE);\r
138 +       _notmuch_qparser_add_transform (notmuch->query_parser,\r
139 +                                       transform_folder, notmuch);\r
140      } catch (const Xapian::Error &error) {\r
141         fprintf (stderr, "A Xapian exception occurred opening database: %s\n",\r
142                  error.get_msg().c_str());\r
143 -- \r
144 1.7.2.3\r
145 \r