1 Return-Path: <Sebastian@SSpaeth.de>
\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 3F191431FC4
\r
6 for <notmuch@notmuchmail.org>; Mon, 8 Feb 2010 03:14:19 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-1.557 tagged_above=-999 required=5 tests=[AWL=1.042,
\r
12 BAYES_00=-2.599] autolearn=ham
\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 h3gfDM+TWtQv for <notmuch@notmuchmail.org>;
\r
16 Mon, 8 Feb 2010 03:14:18 -0800 (PST)
\r
17 Received: from homiemail-a11.g.dreamhost.com (caiajhbdcaid.dreamhost.com
\r
19 by olra.theworths.org (Postfix) with ESMTP id 2EE14431FAE
\r
20 for <notmuch@notmuchmail.org>; Mon, 8 Feb 2010 03:14:18 -0800 (PST)
\r
21 Received: from localhost.localdomain (mtec-hg-docking-1-dhcp-204.ethz.ch
\r
23 by homiemail-a11.g.dreamhost.com (Postfix) with ESMTPA id 17B1B19406F;
\r
24 Mon, 8 Feb 2010 03:14:16 -0800 (PST)
\r
25 From: Sebastian Spaeth <Sebastian@SSpaeth.de>
\r
26 To: notmuch@notmuchmail.org
\r
27 Date: Mon, 8 Feb 2010 12:14:11 +0100
\r
28 Message-Id: <1265627652-25912-3-git-send-email-Sebastian@SSpaeth.de>
\r
29 X-Mailer: git-send-email 1.6.3.3
\r
30 In-Reply-To: <1265627652-25912-2-git-send-email-Sebastian@SSpaeth.de>
\r
31 References: <87fx5cjc83.fsf@SSpaeth.de>
\r
32 <1265627652-25912-1-git-send-email-Sebastian@SSpaeth.de>
\r
33 <1265627652-25912-2-git-send-email-Sebastian@SSpaeth.de>
\r
34 Subject: [notmuch] [PATCH 3/4] integrate date parser
\r
35 X-BeenThere: notmuch@notmuchmail.org
\r
36 X-Mailman-Version: 2.1.13
\r
38 List-Id: "Use and development of the notmuch mail system."
\r
39 <notmuch.notmuchmail.org>
\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
41 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
43 List-Post: <mailto:notmuch@notmuchmail.org>
\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
46 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
47 X-List-Received-Date: Mon, 08 Feb 2010 11:14:19 -0000
\r
49 Integrate and make use of the notmuch_parse_date() function in date.c that is being called by the new MaildateValueRangeProcessor in lib/database.cc
\r
50 Thanks to keithp for donating the date parser for achieving this in a nice way.
\r
52 Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
\r
54 lib/Makefile.local | 1 +
\r
55 lib/database.cc | 33 ++++++++++++++++++++++++++++++++-
\r
56 lib/notmuch.h | 17 +++++++++++++++++
\r
57 3 files changed, 50 insertions(+), 1 deletions(-)
\r
59 diff --git a/lib/Makefile.local b/lib/Makefile.local
\r
60 index 70489e1..44deaf8 100644
\r
61 --- a/lib/Makefile.local
\r
62 +++ b/lib/Makefile.local
\r
63 @@ -3,6 +3,7 @@ extra_cflags += -I$(dir)
\r
65 libnotmuch_c_srcs = \
\r
68 $(dir)/message-file.c \
\r
71 diff --git a/lib/database.cc b/lib/database.cc
\r
72 index ddda933..78cd898 100644
\r
73 --- a/lib/database.cc
\r
74 +++ b/lib/database.cc
\r
75 @@ -496,6 +496,37 @@ _notmuch_database_ensure_writable (notmuch_database_t *notmuch)
\r
76 return NOTMUCH_STATUS_SUCCESS;
\r
79 +struct MaildateValueRangeProcessor : public Xapian::ValueRangeProcessor {
\r
80 + MaildateValueRangeProcessor() {}
\r
82 + Xapian::valueno operator()(std::string &begin, std::string &end) {
\r
83 + time_t begin_first,begin_last, end_first, end_last;
\r
86 + if (begin.substr(0, 5) != "date:")
\r
87 + return Xapian::BAD_VALUENO;
\r
88 + begin.erase(0, 5);
\r
90 + retval = notmuch_parse_date(begin.c_str(), &begin_first, &begin_last, 0);
\r
92 + if (retval == NOTMUCH_STATUS_INVALID_DATE) {
\r
93 + fprintf(stderr,"Begin date failed to parse: %s",begin.c_str());
\r
94 + return Xapian::BAD_VALUENO;
\r
97 + retval = notmuch_parse_date(end.c_str(),&end_first,&end_last,begin_first);
\r
98 + if (retval == NOTMUCH_STATUS_INVALID_DATE) {
\r
99 + fprintf(stderr,"End date failed to parse: %s",end.c_str());
\r
100 + return Xapian::BAD_VALUENO;
\r
103 + begin.assign(Xapian::sortable_serialise(begin_first));
\r
104 + end.assign(Xapian::sortable_serialise(end_last));
\r
106 + return NOTMUCH_VALUE_TIMESTAMP;
\r
110 notmuch_database_t *
\r
111 notmuch_database_open (const char *path,
\r
112 notmuch_database_mode_t mode)
\r
113 @@ -572,7 +603,7 @@ notmuch_database_open (const char *path,
\r
114 notmuch->query_parser = new Xapian::QueryParser;
\r
115 notmuch->term_gen = new Xapian::TermGenerator;
\r
116 notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));
\r
117 - notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);
\r
118 + notmuch->value_range_processor = new MaildateValueRangeProcessor();
\r
120 notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);
\r
121 notmuch->query_parser->set_database (*notmuch->xapian_db);
\r
122 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
123 index 56a76d1..fa8f41a 100644
\r
124 --- a/lib/notmuch.h
\r
125 +++ b/lib/notmuch.h
\r
126 @@ -1089,6 +1089,23 @@ notmuch_filenames_advance (notmuch_filenames_t *filenames);
\r
128 notmuch_filenames_destroy (notmuch_filenames_t *filenames);
\r
131 +notmuch_parse_date(const char *text, time_t *first, time_t *last, time_t after);
\r
132 +/* Parse a string into the first and last possible timestamps.
\r
133 + * It parses the possible formats and stops if one pattern matches.
\r
134 + * Keywords: 'today','yesterday','thisweek','lastweek','thismonth',
\r
136 + * Month-day : month[-day]] (month: January, Jan, or 1)\n"
\r
137 + * ISO format: year[-month[-day]]
\r
138 + * US format : month[/day[/year]]
\r
140 + * 'after' is used to fill in bits from context if left out, e.g. a
\r
141 + * 'date:2004..01' will find from 2004-01-01 through 2004-01-31
\r
144 + * NOTMUCH_STATUS_SUCCESS
\r
145 + * NOTMUCH_STATUS_INVALID_DATE: Error parsing the date string
\r