[PATCH 8/8] Support before: and after: date search with sane date syntax.
authorAustin Clements <amdragon@MIT.EDU>
Sun, 16 Jan 2011 08:10:58 +0000 (03:10 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:37:43 +0000 (09:37 -0800)
2f/9e29e5f22c268a1e88f3f05d078a4b323fea6f [new file with mode: 0644]

diff --git a/2f/9e29e5f22c268a1e88f3f05d078a4b323fea6f b/2f/9e29e5f22c268a1e88f3f05d078a4b323fea6f
new file mode 100644 (file)
index 0000000..3afebe3
--- /dev/null
@@ -0,0 +1,140 @@
+Return-Path: <amthrax@drake.mit.edu>\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 A65BA429E2F\r
+       for <notmuch@notmuchmail.org>; Sun, 16 Jan 2011 00:11:40 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled\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 PRQ56k3oj6TA for <notmuch@notmuchmail.org>;\r
+       Sun, 16 Jan 2011 00:11:39 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU\r
+       [18.7.68.36])\r
+       by olra.theworths.org (Postfix) with ESMTP id F0BF442D29F\r
+       for <notmuch@notmuchmail.org>; Sun, 16 Jan 2011 00:11:26 -0800 (PST)\r
+X-AuditID: 12074424-b7b0bae000000a05-e1-4d32a82eb16a\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+       by dmz-mailsec-scanner-7.mit.edu (Symantec Brightmail Gateway) with\r
+       SMTP id CD.6D.02565.E28A23D4; Sun, 16 Jan 2011 03:11:26 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id p0G8BP0S013772; \r
+       Sun, 16 Jan 2011 03:11:25 -0500\r
+Received: from drake.mit.edu (a074.catapulsion.net [70.36.81.74])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p0G8BNVE010531\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sun, 16 Jan 2011 03:11:25 -0500 (EST)\r
+Received: from amthrax by drake.mit.edu with local (Exim 4.72)\r
+       (envelope-from <amthrax@drake.mit.edu>)\r
+       id 1PeNhr-0002Xj-L4; Sun, 16 Jan 2011 03:11:23 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 8/8] Support before: and after: date search with sane date\r
+       syntax.\r
+Date: Sun, 16 Jan 2011 03:10:58 -0500\r
+Message-Id: <1295165458-9573-9-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.2.3\r
+In-Reply-To: <1295165458-9573-1-git-send-email-amdragon@mit.edu>\r
+References: <1295165458-9573-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker: AAAAAA==\r
+Cc: amdragon@mit.edu\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: Sun, 16 Jan 2011 08:11:41 -0000\r
+\r
+Gmail-compatible date search operators, where the date must be\r
+specified as yyyy/mm/dd.  This is just a start; it would be great to\r
+support fancier date syntax and, in particular, relative date\r
+specifications.\r
+---\r
+ lib/database.cc |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ 1 files changed, 50 insertions(+), 0 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 20fd412..cb02220 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -633,6 +633,49 @@ transform_folder (_notmuch_token_t *root, void *opaque)\r
+     return root;\r
+ }\r
\r
++static _notmuch_token_t *\r
++transform_date (_notmuch_token_t *root, void *opaque)\r
++{\r
++    if (!root)\r
++      return NULL;\r
++    if (root->type == TOK_PREFIX) {\r
++      int after = (strcmp (root->text, "after") == 0);\r
++      int before = (strcmp (root->text, "before") == 0);\r
++      if (after || before) {\r
++          _notmuch_token_t *tok = root->left;\r
++          struct tm t;\r
++          time_t time_value;\r
++          char *end, *serialzed;\r
++\r
++          /* Parse the date */\r
++          assert (tok && tok->type == TOK_LIT);\r
++          memset(&t, 0, sizeof(t));\r
++          end = strptime (tok->text, "%Y/%m/%d", &t);\r
++          time_value = mktime(&t);\r
++          if (!end || *end || time_value == -1) {\r
++              char *msg = talloc_asprintf (root, "Invalid date \"%s\"",\r
++                                           tok->text);\r
++              return _notmuch_token_create_term (root, TOK_ERROR, msg);\r
++          }\r
++\r
++          /* Construct the date query */\r
++          tok = _notmuch_token_create_term (root, TOK_RANGE, NULL);\r
++          tok->valueno = NOTMUCH_VALUE_TIMESTAMP;\r
++          serialzed = talloc_strdup\r
++              (tok, Xapian::sortable_serialise (time_value).c_str ());\r
++          if (after)\r
++              tok->rangeBegin = serialzed;\r
++          else\r
++              tok->rangeEnd = serialzed;\r
++          return tok;\r
++      }\r
++    }\r
++\r
++    root->left = transform_date (root->left, opaque);\r
++    root->right = transform_date (root->right, opaque);\r
++    return root;\r
++}\r
++\r
+ notmuch_database_t *\r
+ notmuch_database_open (const char *path,\r
+                      notmuch_database_mode_t mode)\r
+@@ -746,6 +789,13 @@ notmuch_database_open (const char *path,\r
+                                    TRUE, TRUE);\r
+       _notmuch_qparser_add_transform (notmuch->query_parser,\r
+                                       transform_folder, notmuch);\r
++\r
++      _notmuch_qparser_add_prefix (notmuch->query_parser, "after",\r
++                                   TRUE, TRUE);\r
++      _notmuch_qparser_add_prefix (notmuch->query_parser, "before",\r
++                                   TRUE, TRUE);\r
++      _notmuch_qparser_add_transform (notmuch->query_parser,\r
++                                      transform_date, NULL);\r
+     } catch (const Xapian::Error &error) {\r
+       fprintf (stderr, "A Xapian exception occurred opening database: %s\n",\r
+                error.get_msg().c_str());\r
+-- \r
+1.7.2.3\r
+\r