[notmuch] [PATCH 3/4] integrate date parser
authorSebastian Spaeth <Sebastian@SSpaeth.de>
Mon, 8 Feb 2010 11:14:11 +0000 (12:14 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:36:07 +0000 (09:36 -0800)
6c/0f6e308bca4868cbf626f68f8fa41cc82f3ff2 [new file with mode: 0644]

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