[PATCH 8/9] cli: optionally restore message properties from dump file
[notmuch-archives.git] / 2f / 2b15294141dcb2852e7b94ebd5839b1ab3db3a
1 Return-Path: <jani@nikula.org>\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 arlo.cworth.org (Postfix) with ESMTP id 2CA0B6DE17FD\r
6  for <notmuch@notmuchmail.org>; Sat, 15 Aug 2015 04:25:48 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.248\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.248 tagged_above=-999 required=5 tests=[AWL=0.472,\r
12   RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01]\r
13  autolearn=disabled\r
14 Received: from arlo.cworth.org ([127.0.0.1])\r
15  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
16  with ESMTP id oiJMmBN0Od3U for <notmuch@notmuchmail.org>;\r
17  Sat, 15 Aug 2015 04:25:46 -0700 (PDT)\r
18 Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com\r
19  [209.85.212.169])\r
20  by arlo.cworth.org (Postfix) with ESMTPS id F08716DE021E\r
21  for <notmuch@notmuchmail.org>; Sat, 15 Aug 2015 04:25:45 -0700 (PDT)\r
22 Received: by wibhh20 with SMTP id hh20so42720009wib.0\r
23  for <notmuch@notmuchmail.org>; Sat, 15 Aug 2015 04:25:44 -0700 (PDT)\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
25  d=1e100.net; s=20130820;\r
26  h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to\r
27  :references:mime-version:content-type:content-transfer-encoding;\r
28  bh=kO1xVViJfzx+unxR58RtuAtdQC/HNZotS0xPe8oCbrc=;\r
29  b=YMqq2iM1ijS2g3QZMSUJynAcoveZAJyHuLrmJaOLVo0/LMoArZ3IRPBddu+SzBZAK9\r
30  IsE9e2EEOQ3SRcPrf3q2y/XO7ACPplokwp/sY1PanZZugsOI5Itk0SkxTWGLh+joTw2T\r
31  f5F2KORwMtrJf36JXYMfV+klzM+Uy8XT4eGxpPAlXPDTE/l3yz/njxDko1PPLdSJiiN9\r
32  LRpMxDc03OacE3msADtXIo8w4XbvBt+Qpa2JrvMd8uXUVdm4CZgSy/pxv2h+Czc0S3+O\r
33  ctf03ZK4YsVVo6JesuCPp/rXTmJHfOBgd97cXGmqyibnitHioWj2Ww7kHU4Jd79GSrzf\r
34  n9AA==\r
35 X-Gm-Message-State:\r
36  ALoCoQm08GaHFou1AT5fOvsMz+ymbYAE9wq2GN1xZyg85fSB8Gf2qKMfw7K7uS0/852e2DdIkbMG\r
37 X-Received: by 10.194.117.5 with SMTP id ka5mr8984258wjb.50.1439637944265;\r
38  Sat, 15 Aug 2015 04:25:44 -0700 (PDT)\r
39 Received: from localhost (mobile-access-bcee4f-131.dhcp.inet.fi.\r
40  [188.238.79.131])\r
41  by smtp.gmail.com with ESMTPSA id gm20sm12517871wjc.17.2015.08.15.04.25.43\r
42  (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
43  Sat, 15 Aug 2015 04:25:43 -0700 (PDT)\r
44 From: Jani Nikula <jani@nikula.org>\r
45 To: David Bremner <david@tethera.net>, Jani Nikula <jani@nikula.org>,\r
46  notmuch@notmuchmail.org\r
47 Subject: [PATCH] lib: add support for date:<expr>..! to mean\r
48  date:<expr>..<expr>\r
49 Date: Sat, 15 Aug 2015 14:25:47 +0300\r
50 Message-Id: <1439637947-12147-1-git-send-email-jani@nikula.org>\r
51 X-Mailer: git-send-email 2.1.4\r
52 In-Reply-To: <87k2vegsda.fsf@maritornes.cs.unb.ca>\r
53 References: <87k2vegsda.fsf@maritornes.cs.unb.ca>\r
54 MIME-Version: 1.0\r
55 Content-Type: text/plain; charset=UTF-8\r
56 Content-Transfer-Encoding: 8bit\r
57 X-BeenThere: notmuch@notmuchmail.org\r
58 X-Mailman-Version: 2.1.18\r
59 Precedence: list\r
60 List-Id: "Use and development of the notmuch mail system."\r
61  <notmuch.notmuchmail.org>\r
62 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
63  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
64 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
65 List-Post: <mailto:notmuch@notmuchmail.org>\r
66 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
67 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
68  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
69 X-List-Received-Date: Sat, 15 Aug 2015 11:25:48 -0000\r
70 \r
71 It doesn't seem likely we can support simple date:<expr> expanding to\r
72 date:<expr>..<expr> any time soon. (This can be done with a future\r
73 version of Xapian, or with a custom query query parser.) In the mean\r
74 time, provide shorthand date:<expr>..! to mean the same. This is\r
75 useful, as the expansion takes place before interpetation, and we can\r
76 use, for example, date:yesterday..! to match from beginning of\r
77 yesterday to end of yesterday.\r
78 \r
79 Idea from Mark Walters <markwalters1009@gmail.com>.\r
80 ---\r
81  doc/man7/notmuch-search-terms.rst | 12 +++++++-----\r
82  lib/parse-time-vrp.cc             |  5 +++++\r
83  test/T500-search-date.sh          |  4 ++++\r
84  3 files changed, 16 insertions(+), 5 deletions(-)\r
85 \r
86 diff --git a/doc/man7/notmuch-search-terms.rst b/doc/man7/notmuch-search-terms.rst\r
87 index 1d27ac1e6de5..3b35a32b7d23 100644\r
88 --- a/doc/man7/notmuch-search-terms.rst\r
89 +++ b/doc/man7/notmuch-search-terms.rst\r
90 @@ -270,6 +270,13 @@ In this case, <since> is taken as the earliest time it could describe\r
91  could describe (the end of yesterday). Similarly, date:january..february\r
92  matches from the beginning of January to the end of February.\r
93  \r
94 +date:<expr>..! can be used as a shorthand for date:<expr>..<expr>. The\r
95 +expansion takes place before interpretation, and thus, for example,\r
96 +date:monday..! matches from the beginning of Monday until the end of\r
97 +Monday. (Note that entering date:<expr> without "..", for example\r
98 +date:yesterday, won't work, as it's not interpreted as a range\r
99 +expression at all. Again, use date:yesterday..!)\r
100 +\r
101  Currently, we do not support spaces in range expressions. You can\r
102  replace the spaces with '\_', or (in most cases) '-', or (in some cases)\r
103  leave the spaces out altogether. Examples in this man page use spaces\r
104 @@ -280,11 +287,6 @@ to specify date:..<until> or date:<since>.. to not limit the start or\r
105  end time, respectively. Pre-1.2.1 Xapian does not report an error on\r
106  open ended ranges, but it does not work as expected either.\r
107  \r
108 -Entering date:expr without ".." (for example date:yesterday) won't work,\r
109 -as it's not interpreted as a range expression at all. You can achieve\r
110 -the expected result by duplicating the expr both sides of ".." (for\r
111 -example date:yesterday..yesterday).\r
112 -\r
113  Relative date and time\r
114  ----------------------\r
115  \r
116 diff --git a/lib/parse-time-vrp.cc b/lib/parse-time-vrp.cc\r
117 index 33f07db3410e..03804cf50fa8 100644\r
118 --- a/lib/parse-time-vrp.cc\r
119 +++ b/lib/parse-time-vrp.cc\r
120 @@ -31,6 +31,7 @@ Xapian::valueno\r
121  ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end)\r
122  {\r
123      time_t t, now;\r
124 +    std::string b;\r
125  \r
126      /* Require date: prefix in start of the range... */\r
127      if (STRNCMP_LITERAL (begin.c_str (), PREFIX))\r
128 @@ -38,6 +39,7 @@ ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end)\r
129  \r
130      /* ...and remove it. */\r
131      begin.erase (0, sizeof (PREFIX) - 1);\r
132 +    b = begin;\r
133  \r
134      /* Use the same 'now' for begin and end. */\r
135      if (time (&now) == (time_t) -1)\r
136 @@ -51,6 +53,9 @@ ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end)\r
137      }\r
138  \r
139      if (!end.empty ()) {\r
140 +       if (end == "!" && ! b.empty ())\r
141 +           end = b;\r
142 +\r
143         if (parse_time_string (end.c_str (), &t, &now, PARSE_TIME_ROUND_UP_INCLUSIVE))\r
144             return Xapian::BAD_VALUENO;\r
145  \r
146 diff --git a/test/T500-search-date.sh b/test/T500-search-date.sh\r
147 index b28496b78e2e..f5cea421d785 100755\r
148 --- a/test/T500-search-date.sh\r
149 +++ b/test/T500-search-date.sh\r
150 @@ -8,6 +8,10 @@ test_begin_subtest "Absolute date range"\r
151  output=$(notmuch search date:2010-12-16..12/16/2010 | notmuch_search_sanitize)\r
152  test_expect_equal "$output" "thread:XXX   2010-12-16 [1/1] Olivier Berger; Essai accentuĂ© (inbox unread)"\r
153  \r
154 +test_begin_subtest "Absolute date range with 'same' operator"\r
155 +output=$(notmuch search date:2010-12-16..! | notmuch_search_sanitize)\r
156 +test_expect_equal "$output" "thread:XXX   2010-12-16 [1/1] Olivier Berger; Essai accentuĂ© (inbox unread)"\r
157 +\r
158  test_begin_subtest "Absolute time range with TZ"\r
159  notmuch search date:18-Nov-2009_02:19:26-0800..2009-11-18_04:49:52-06:00 | notmuch_search_sanitize > OUTPUT\r
160  cat <<EOF >EXPECTED\r
161 -- \r
162 2.1.4\r
163 \r