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 A65BA429E2F
\r
6 for <notmuch@notmuchmail.org>; Sun, 16 Jan 2011 00:11:40 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\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 PRQ56k3oj6TA for <notmuch@notmuchmail.org>;
\r
16 Sun, 16 Jan 2011 00:11:39 -0800 (PST)
\r
17 Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id F0BF442D29F
\r
20 for <notmuch@notmuchmail.org>; Sun, 16 Jan 2011 00:11:26 -0800 (PST)
\r
21 X-AuditID: 12074424-b7b0bae000000a05-e1-4d32a82eb16a
\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])
\r
23 by dmz-mailsec-scanner-7.mit.edu (Symantec Brightmail Gateway) with
\r
24 SMTP id CD.6D.02565.E28A23D4; Sun, 16 Jan 2011 03:11:26 -0500 (EST)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id p0G8BP0S013772;
\r
27 Sun, 16 Jan 2011 03:11:25 -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 p0G8BNVE010531
\r
32 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
33 Sun, 16 Jan 2011 03:11:25 -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 1PeNhr-0002Xj-L4; Sun, 16 Jan 2011 03:11:23 -0500
\r
37 From: Austin Clements <amdragon@MIT.EDU>
\r
38 To: notmuch@notmuchmail.org
\r
39 Subject: [PATCH 8/8] Support before: and after: date search with sane date
\r
41 Date: Sun, 16 Jan 2011 03:10:58 -0500
\r
42 Message-Id: <1295165458-9573-9-git-send-email-amdragon@mit.edu>
\r
43 X-Mailer: git-send-email 1.7.2.3
\r
44 In-Reply-To: <1295165458-9573-1-git-send-email-amdragon@mit.edu>
\r
45 References: <1295165458-9573-1-git-send-email-amdragon@mit.edu>
\r
46 X-Brightmail-Tracker: AAAAAA==
\r
47 Cc: amdragon@mit.edu
\r
48 X-BeenThere: notmuch@notmuchmail.org
\r
49 X-Mailman-Version: 2.1.13
\r
51 List-Id: "Use and development of the notmuch mail system."
\r
52 <notmuch.notmuchmail.org>
\r
53 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
54 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
55 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
56 List-Post: <mailto:notmuch@notmuchmail.org>
\r
57 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
58 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
59 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
60 X-List-Received-Date: Sun, 16 Jan 2011 08:11:41 -0000
\r
62 Gmail-compatible date search operators, where the date must be
\r
63 specified as yyyy/mm/dd. This is just a start; it would be great to
\r
64 support fancier date syntax and, in particular, relative date
\r
67 lib/database.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
\r
68 1 files changed, 50 insertions(+), 0 deletions(-)
\r
70 diff --git a/lib/database.cc b/lib/database.cc
\r
71 index 20fd412..cb02220 100644
\r
72 --- a/lib/database.cc
\r
73 +++ b/lib/database.cc
\r
74 @@ -633,6 +633,49 @@ transform_folder (_notmuch_token_t *root, void *opaque)
\r
78 +static _notmuch_token_t *
\r
79 +transform_date (_notmuch_token_t *root, void *opaque)
\r
83 + if (root->type == TOK_PREFIX) {
\r
84 + int after = (strcmp (root->text, "after") == 0);
\r
85 + int before = (strcmp (root->text, "before") == 0);
\r
86 + if (after || before) {
\r
87 + _notmuch_token_t *tok = root->left;
\r
89 + time_t time_value;
\r
90 + char *end, *serialzed;
\r
92 + /* Parse the date */
\r
93 + assert (tok && tok->type == TOK_LIT);
\r
94 + memset(&t, 0, sizeof(t));
\r
95 + end = strptime (tok->text, "%Y/%m/%d", &t);
\r
96 + time_value = mktime(&t);
\r
97 + if (!end || *end || time_value == -1) {
\r
98 + char *msg = talloc_asprintf (root, "Invalid date \"%s\"",
\r
100 + return _notmuch_token_create_term (root, TOK_ERROR, msg);
\r
103 + /* Construct the date query */
\r
104 + tok = _notmuch_token_create_term (root, TOK_RANGE, NULL);
\r
105 + tok->valueno = NOTMUCH_VALUE_TIMESTAMP;
\r
106 + serialzed = talloc_strdup
\r
107 + (tok, Xapian::sortable_serialise (time_value).c_str ());
\r
109 + tok->rangeBegin = serialzed;
\r
111 + tok->rangeEnd = serialzed;
\r
116 + root->left = transform_date (root->left, opaque);
\r
117 + root->right = transform_date (root->right, opaque);
\r
121 notmuch_database_t *
\r
122 notmuch_database_open (const char *path,
\r
123 notmuch_database_mode_t mode)
\r
124 @@ -746,6 +789,13 @@ notmuch_database_open (const char *path,
\r
126 _notmuch_qparser_add_transform (notmuch->query_parser,
\r
127 transform_folder, notmuch);
\r
129 + _notmuch_qparser_add_prefix (notmuch->query_parser, "after",
\r
131 + _notmuch_qparser_add_prefix (notmuch->query_parser, "before",
\r
133 + _notmuch_qparser_add_transform (notmuch->query_parser,
\r
134 + transform_date, NULL);
\r
135 } catch (const Xapian::Error &error) {
\r
136 fprintf (stderr, "A Xapian exception occurred opening database: %s\n",
\r
137 error.get_msg().c_str());
\r