[PATCH v2 14/14] cli/reply: only pass gmime message to add recipients to reply message
[notmuch-archives.git] / b1 / b039415a8bb3a1bbbebcb75b1d89fb6e055f5e
1 Return-Path: <bremner@tesseract.cs.unb.ca>\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 E820E6DE035A\r
6  for <notmuch@notmuchmail.org>; Sat, 26 Mar 2016 11:23:32 -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.02\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.02 tagged_above=-999 required=5 tests=[AWL=-0.021,\r
12   HEADER_FROM_DIFFERENT_DOMAINS=0.001] autolearn=disabled\r
13 Received: from arlo.cworth.org ([127.0.0.1])\r
14  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
15  with ESMTP id gsVEucqSAscb for <notmuch@notmuchmail.org>;\r
16  Sat, 26 Mar 2016 11:23:25 -0700 (PDT)\r
17 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
18  by arlo.cworth.org (Postfix) with ESMTPS id 5F1056DE02C1\r
19  for <notmuch@notmuchmail.org>; Sat, 26 Mar 2016 11:23:17 -0700 (PDT)\r
20 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
21  (envelope-from <bremner@tesseract.cs.unb.ca>)\r
22  id 1ajsTS-0000ug-OZ; Sat, 26 Mar 2016 13:58:10 -0400\r
23 Received: (nullmailer pid 8808 invoked by uid 1000);\r
24  Sat, 26 Mar 2016 17:57:27 -0000\r
25 From: David Bremner <david@tethera.net>\r
26 To: notmuch@notmuchmail.org\r
27 Subject: [Patch v2 03/13] lib: optionally support single argument date:\r
28  queries\r
29 Date: Sat, 26 Mar 2016 14:57:13 -0300\r
30 Message-Id: <1459015043-8460-4-git-send-email-david@tethera.net>\r
31 X-Mailer: git-send-email 2.6.4\r
32 In-Reply-To: <1459015043-8460-1-git-send-email-david@tethera.net>\r
33 References: <1459015043-8460-1-git-send-email-david@tethera.net>\r
34 MIME-Version: 1.0\r
35 Content-Type: text/plain; charset=UTF-8\r
36 Content-Transfer-Encoding: 8bit\r
37 X-BeenThere: notmuch@notmuchmail.org\r
38 X-Mailman-Version: 2.1.20\r
39 Precedence: list\r
40 List-Id: "Use and development of the notmuch mail system."\r
41  <notmuch.notmuchmail.org>\r
42 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
43  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
45 List-Post: <mailto:notmuch@notmuchmail.org>\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
47 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
48  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
49 X-List-Received-Date: Sat, 26 Mar 2016 18:23:33 -0000\r
50 \r
51 This relies on the FieldProcessor API, which is only present in xapian\r
52 >= 1.3.\r
53 ---\r
54  doc/man7/notmuch-search-terms.rst | 22 +++++++++++++++++++---\r
55  lib/database-private.h            |  3 +++\r
56  lib/database.cc                   |  6 ++++++\r
57  lib/parse-time-vrp.cc             | 21 +++++++++++++++++++++\r
58  lib/parse-time-vrp.h              |  5 +++++\r
59  test/T500-search-date.sh          |  6 ++++++\r
60  6 files changed, 60 insertions(+), 3 deletions(-)\r
61 \r
62 diff --git a/doc/man7/notmuch-search-terms.rst b/doc/man7/notmuch-search-terms.rst\r
63 index 2fbc16d..29e8b03 100644\r
64 --- a/doc/man7/notmuch-search-terms.rst\r
65 +++ b/doc/man7/notmuch-search-terms.rst\r
66 @@ -281,9 +281,10 @@ matches from the beginning of January to the end of February.\r
67  date:<expr>..! can be used as a shorthand for date:<expr>..<expr>. The\r
68  expansion takes place before interpretation, and thus, for example,\r
69  date:monday..! matches from the beginning of Monday until the end of\r
70 -Monday. (Note that entering date:<expr> without "..", for example\r
71 -date:yesterday, won't work, as it's not interpreted as a range\r
72 -expression at all. Again, use date:yesterday..!)\r
73 +Monday.\r
74 +With **Xapian Field Processor** support (see below), non-range\r
75 +date queries such as date:yesterday will work, but otherwise\r
76 +will give unexpected results; if in doubt use date:yesterday..!\r
77  \r
78  Currently, we do not support spaces in range expressions. You can\r
79  replace the spaces with '\_', or (in most cases) '-', or (in some cases)\r
80 @@ -370,6 +371,21 @@ Time zones\r
81  \r
82  Some time zone codes, e.g. UTC, EET.\r
83  \r
84 +XAPIAN FIELD PROCESSORS\r
85 +=======================\r
86 +\r
87 +Certain optional features of the notmuch query processor rely on the\r
88 +presence of the Xapian field processor API. You can determine if your\r
89 +notmuch was built against a sufficiently recent version of Xapian by running\r
90 +\r
91 +::\r
92 +\r
93 +  % notmuch config get options.field_processor\r
94 +\r
95 +Currently the following features require field processor support:\r
96 +\r
97 +- non-range date queries, e.g. "date:today"\r
98 +\r
99  SEE ALSO\r
100  ========\r
101  \r
102 diff --git a/lib/database-private.h b/lib/database-private.h\r
103 index 3fb10f7..e1962f4 100644\r
104 --- a/lib/database-private.h\r
105 +++ b/lib/database-private.h\r
106 @@ -176,6 +176,9 @@ struct _notmuch_database {\r
107      Xapian::TermGenerator *term_gen;\r
108      Xapian::ValueRangeProcessor *value_range_processor;\r
109      Xapian::ValueRangeProcessor *date_range_processor;\r
110 +#if HAVE_XAPIAN_FIELD_PROCESSOR\r
111 +    Xapian::FieldProcessor *date_field_processor;\r
112 +#endif\r
113      Xapian::ValueRangeProcessor *last_mod_range_processor;\r
114  };\r
115  \r
116 diff --git a/lib/database.cc b/lib/database.cc\r
117 index 3b342f1..0e3c90c 100644\r
118 --- a/lib/database.cc\r
119 +++ b/lib/database.cc\r
120 @@ -1000,6 +1000,12 @@ notmuch_database_open_verbose (const char *path,\r
121         notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));\r
122         notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);\r
123         notmuch->date_range_processor = new ParseTimeValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP);\r
124 +#if HAVE_XAPIAN_FIELD_PROCESSOR\r
125 +       /* This currently relies on the query parser to pass anything\r
126 +        * with a .. to the range processor */\r
127 +       notmuch->date_field_processor = new DateFieldProcessor();\r
128 +       notmuch->query_parser->add_boolean_prefix("date", notmuch->date_field_processor);\r
129 +#endif\r
130         notmuch->last_mod_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_LAST_MOD, "lastmod:");\r
131  \r
132         notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);\r
133 diff --git a/lib/parse-time-vrp.cc b/lib/parse-time-vrp.cc\r
134 index 03804cf..b15b77c 100644\r
135 --- a/lib/parse-time-vrp.cc\r
136 +++ b/lib/parse-time-vrp.cc\r
137 @@ -64,3 +64,24 @@ ParseTimeValueRangeProcessor::operator() (std::string &begin, std::string &end)\r
138  \r
139      return valno;\r
140  }\r
141 +\r
142 +#if HAVE_XAPIAN_FIELD_PROCESSOR\r
143 +/* XXX TODO: is throwing an exception the right thing to do here? */\r
144 +Xapian::Query DateFieldProcessor::operator()(const std::string & str) {\r
145 +    time_t from, to, now;\r
146 +\r
147 +    /* Use the same 'now' for begin and end. */\r
148 +    if (time (&now) == (time_t) -1)\r
149 +       throw Xapian::QueryParserError("Unable to get current time");\r
150 +\r
151 +    if (parse_time_string (str.c_str (), &from, &now, PARSE_TIME_ROUND_DOWN))\r
152 +       throw Xapian::QueryParserError ("Didn't understand date specification '" + str + "'");\r
153 +\r
154 +    if (parse_time_string (str.c_str (), &to, &now, PARSE_TIME_ROUND_UP_INCLUSIVE))\r
155 +       throw Xapian::QueryParserError ("Didn't understand date specification '" + str + "'");\r
156 +\r
157 +    return Xapian::Query(Xapian::Query::OP_AND,\r
158 +                        Xapian::Query(Xapian::Query::OP_VALUE_GE, 0, Xapian::sortable_serialise ((double) from)),\r
159 +                        Xapian::Query(Xapian::Query::OP_VALUE_LE, 0, Xapian::sortable_serialise ((double) to)));\r
160 +}\r
161 +#endif\r
162 diff --git a/lib/parse-time-vrp.h b/lib/parse-time-vrp.h\r
163 index 094c4f8..3bd12bf 100644\r
164 --- a/lib/parse-time-vrp.h\r
165 +++ b/lib/parse-time-vrp.h\r
166 @@ -37,4 +37,9 @@ public:\r
167      Xapian::valueno operator() (std::string &begin, std::string &end);\r
168  };\r
169  \r
170 +#if HAVE_XAPIAN_FIELD_PROCESSOR\r
171 +class DateFieldProcessor : public Xapian::FieldProcessor {\r
172 +    Xapian::Query operator()(const std::string & str);\r
173 +};\r
174 +#endif\r
175  #endif /* NOTMUCH_PARSE_TIME_VRP_H */\r
176 diff --git a/test/T500-search-date.sh b/test/T500-search-date.sh\r
177 index f5cea42..198a2e6 100755\r
178 --- a/test/T500-search-date.sh\r
179 +++ b/test/T500-search-date.sh\r
180 @@ -12,6 +12,12 @@ test_begin_subtest "Absolute date range with 'same' operator"\r
181  output=$(notmuch search date:2010-12-16..! | notmuch_search_sanitize)\r
182  test_expect_equal "$output" "thread:XXX   2010-12-16 [1/1] Olivier Berger; Essai accentuĂ© (inbox unread)"\r
183  \r
184 +if [ "${NOTMUCH_HAVE_XAPIAN_FIELD_PROCESSOR}" = "1" ]; then\r
185 +    test_begin_subtest "Absolute date field"\r
186 +    output=$(notmuch search date:2010-12-16 | notmuch_search_sanitize)\r
187 +    test_expect_equal "$output" "thread:XXX   2010-12-16 [1/1] Olivier Berger; Essai accentuĂ© (inbox unread)"\r
188 +fi\r
189 +\r
190  test_begin_subtest "Absolute time range with TZ"\r
191  notmuch search date:18-Nov-2009_02:19:26-0800..2009-11-18_04:49:52-06:00 | notmuch_search_sanitize > OUTPUT\r
192  cat <<EOF >EXPECTED\r
193 -- \r
194 2.6.4\r
195 \r