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 3F191431FC4 for ; Mon, 8 Feb 2010 03:14:19 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.557 X-Spam-Level: X-Spam-Status: No, score=-1.557 tagged_above=-999 required=5 tests=[AWL=1.042, BAYES_00=-2.599] autolearn=ham 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 h3gfDM+TWtQv for ; Mon, 8 Feb 2010 03:14:18 -0800 (PST) Received: from homiemail-a11.g.dreamhost.com (caiajhbdcaid.dreamhost.com [208.97.132.83]) by olra.theworths.org (Postfix) with ESMTP id 2EE14431FAE for ; Mon, 8 Feb 2010 03:14:18 -0800 (PST) Received: from localhost.localdomain (mtec-hg-docking-1-dhcp-204.ethz.ch [129.132.133.204]) by homiemail-a11.g.dreamhost.com (Postfix) with ESMTPA id 17B1B19406F; Mon, 8 Feb 2010 03:14:16 -0800 (PST) From: Sebastian Spaeth To: notmuch@notmuchmail.org Date: Mon, 8 Feb 2010 12:14:11 +0100 Message-Id: <1265627652-25912-3-git-send-email-Sebastian@SSpaeth.de> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1265627652-25912-2-git-send-email-Sebastian@SSpaeth.de> References: <87fx5cjc83.fsf@SSpaeth.de> <1265627652-25912-1-git-send-email-Sebastian@SSpaeth.de> <1265627652-25912-2-git-send-email-Sebastian@SSpaeth.de> Subject: [notmuch] [PATCH 3/4] integrate date parser 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, 08 Feb 2010 11:14:19 -0000 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 Thanks to keithp for donating the date parser for achieving this in a nice way. Signed-off-by: Sebastian Spaeth --- lib/Makefile.local | 1 + lib/database.cc | 33 ++++++++++++++++++++++++++++++++- lib/notmuch.h | 17 +++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletions(-) diff --git a/lib/Makefile.local b/lib/Makefile.local index 70489e1..44deaf8 100644 --- a/lib/Makefile.local +++ b/lib/Makefile.local @@ -3,6 +3,7 @@ extra_cflags += -I$(dir) libnotmuch_c_srcs = \ $(dir)/libsha1.c \ + $(dir)/date.c \ $(dir)/message-file.c \ $(dir)/messages.c \ $(dir)/sha1.c \ diff --git a/lib/database.cc b/lib/database.cc index ddda933..78cd898 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -496,6 +496,37 @@ _notmuch_database_ensure_writable (notmuch_database_t *notmuch) return NOTMUCH_STATUS_SUCCESS; } +struct MaildateValueRangeProcessor : public Xapian::ValueRangeProcessor { + MaildateValueRangeProcessor() {} + + Xapian::valueno operator()(std::string &begin, std::string &end) { + time_t begin_first,begin_last, end_first, end_last; + int retval; + + if (begin.substr(0, 5) != "date:") + return Xapian::BAD_VALUENO; + begin.erase(0, 5); + + retval = notmuch_parse_date(begin.c_str(), &begin_first, &begin_last, 0); + + if (retval == NOTMUCH_STATUS_INVALID_DATE) { + fprintf(stderr,"Begin date failed to parse: %s",begin.c_str()); + return Xapian::BAD_VALUENO; + } + + retval = notmuch_parse_date(end.c_str(),&end_first,&end_last,begin_first); + if (retval == NOTMUCH_STATUS_INVALID_DATE) { + fprintf(stderr,"End date failed to parse: %s",end.c_str()); + return Xapian::BAD_VALUENO; + } + + begin.assign(Xapian::sortable_serialise(begin_first)); + end.assign(Xapian::sortable_serialise(end_last)); + + return NOTMUCH_VALUE_TIMESTAMP; + } +}; + notmuch_database_t * notmuch_database_open (const char *path, notmuch_database_mode_t mode) @@ -572,7 +603,7 @@ notmuch_database_open (const char *path, notmuch->query_parser = new Xapian::QueryParser; notmuch->term_gen = new Xapian::TermGenerator; notmuch->term_gen->set_stemmer (Xapian::Stem ("english")); - notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP); + notmuch->value_range_processor = new MaildateValueRangeProcessor(); notmuch->query_parser->set_default_op (Xapian::Query::OP_AND); notmuch->query_parser->set_database (*notmuch->xapian_db); diff --git a/lib/notmuch.h b/lib/notmuch.h index 56a76d1..fa8f41a 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -1089,6 +1089,23 @@ notmuch_filenames_advance (notmuch_filenames_t *filenames); void notmuch_filenames_destroy (notmuch_filenames_t *filenames); +notmuch_status_t +notmuch_parse_date(const char *text, time_t *first, time_t *last, time_t after); +/* Parse a string into the first and last possible timestamps. + * It parses the possible formats and stops if one pattern matches. + * Keywords: 'today','yesterday','thisweek','lastweek','thismonth', + * 'lastmonth' + * Month-day : month[-day]] (month: January, Jan, or 1)\n" + * ISO format: year[-month[-day]] + * US format : month[/day[/year]] + * + * 'after' is used to fill in bits from context if left out, e.g. a + * 'date:2004..01' will find from 2004-01-01 through 2004-01-31 + * + * Return values: + * NOTMUCH_STATUS_SUCCESS + * NOTMUCH_STATUS_INVALID_DATE: Error parsing the date string + */ NOTMUCH_END_DECLS #endif -- 1.6.3.3