Re: [PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / c0 / b7b45344b887b2d404ea49b4ddbac01dfd77de
1 Return-Path: <MarkR.Anderson@amd.com>\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 olra.theworths.org (Postfix) with ESMTP id 65F4E429E4E\r
6         for <notmuch@notmuchmail.org>; Wed, 14 Dec 2011 13:54:26 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id xW-r4LAB+r9a for <notmuch@notmuchmail.org>;\r
16         Wed, 14 Dec 2011 13:54:25 -0800 (PST)\r
17 Received: from VA3EHSOBE003.bigfish.com (va3ehsobe003.messaging.microsoft.com\r
18         [216.32.180.13]) (using TLSv1 with cipher AES128-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 63AE3429E4D\r
21         for <notmuch@notmuchmail.org>; Wed, 14 Dec 2011 13:54:25 -0800 (PST)\r
22 Received: from mail70-va3-R.bigfish.com (10.7.14.235) by\r
23         VA3EHSOBE003.bigfish.com (10.7.40.23) with Microsoft SMTP Server id\r
24         14.1.225.23; Wed, 14 Dec 2011 21:54:26 +0000\r
25 Received: from mail70-va3 (localhost [127.0.0.1])       by mail70-va3-R.bigfish.com\r
26         (Postfix) with ESMTP id 878B122037F;\r
27         Wed, 14 Dec 2011 21:54:28 +0000 (UTC)\r
28 X-SpamScore: -9\r
29 X-BigFish: VPS-9(zz1432N98dKzz1202hzz8275ch8275dhz2dh668h839h944h61h)\r
30 X-Spam-TCS-SCL: 0:0\r
31 X-Forefront-Antispam-Report: CIP:163.181.249.108; KIP:(null); UIP:(null);\r
32         IPV:NLI; H:ausb3twp01.amd.com; RD:none; EFVD:NLI\r
33 Received: from mail70-va3 (localhost.localdomain [127.0.0.1]) by mail70-va3\r
34         (MessageSwitch) id 1323899668177659_15395;\r
35         Wed, 14 Dec 2011 21:54:28 +0000 (UTC)\r
36 Received: from VA3EHSMHS023.bigfish.com (unknown [10.7.14.235]) by\r
37         mail70-va3.bigfish.com (Postfix) with ESMTP id 25059C0045;\r
38         Wed, 14 Dec 2011 21:54:28 +0000 (UTC)\r
39 Received: from ausb3twp01.amd.com (163.181.249.108) by\r
40         VA3EHSMHS023.bigfish.com (10.7.99.33) with Microsoft SMTP Server id\r
41         14.1.225.23; Wed, 14 Dec 2011 21:54:20 +0000\r
42 X-WSS-ID: 0LW7RIE-01-9C7-02\r
43 X-M-MSG: \r
44 Received: from sausexedgep02.amd.com (sausexedgep02-ext.amd.com\r
45         [163.181.249.73])       (using TLSv1 with cipher AES128-SHA (128/128\r
46         bits))  (No\r
47         client certificate requested)   by ausb3twp01.amd.com (Axway MailGate\r
48         3.8.1)\r
49         with ESMTP id 2F6141028051;     Wed, 14 Dec 2011 15:54:14 -0600 (CST)\r
50 Received: from sausexhtp02.amd.com (163.181.3.152) by sausexedgep02.amd.com\r
51         (163.181.36.59) with Microsoft SMTP Server (TLS) id 8.3.192.1;\r
52         Wed, 14 Dec 2011 15:54:29 -0600\r
53 Received: from adcvmail01.amd.com (163.181.21.78) by sausexhtp02.amd.com\r
54         (163.181.3.152) with Microsoft SMTP Server (TLS) id 8.3.213.0;\r
55         Wed, 14 Dec 2011 15:54:16 -0600\r
56 Received: from mhdc-ns01.amd.com (mhdc-ns01.amd.com [165.204.35.147])   by\r
57         adcvmail01.amd.com (8.13.8/8.13.8) with ESMTP id pBELsF31022473;\r
58         Wed, 14 Dec 2011 15:54:16 -0600\r
59 Received: from testarossa.amd.com (testarossa.amd.com [165.204.147.44]) by\r
60         mhdc-ns01.amd.com (8.13.8+Sun/8.13.8) with ESMTP id pBELsFgi024368;\r
61         Wed, 14 Dec 2011 14:54:15 -0700 (MST)\r
62 Received: (from manderso@localhost)     by testarossa.amd.com\r
63         (8.13.8/8.13.8/Submit) id pBELsABF030781;\r
64         Wed, 14 Dec 2011 14:54:10 -0700\r
65 X-Authentication-Warning: testarossa.amd.com: manderso set sender to\r
66         MarkR.Anderson@amd.com using -f\r
67 From: Mark Anderson <MarkR.Anderson@amd.com>\r
68 To: Thomas Jost <schnouki@schnouki.net>, "notmuch@notmuchmail.org"\r
69         <notmuch@notmuchmail.org>\r
70 Subject: Re: [PATCH 2/5] lib: Add a MTIME value to every mail document\r
71 In-Reply-To: <1323796305-28789-3-git-send-email-schnouki@schnouki.net>\r
72 References: <1323796305-28789-1-git-send-email-schnouki@schnouki.net>\r
73         <1323796305-28789-3-git-send-email-schnouki@schnouki.net>\r
74 User-Agent: Notmuch/0.10.2+101~g11c52d7 (http://notmuchmail.org) Emacs/23.1.1\r
75         (i686-pc-linux-gnu)\r
76 Date: Wed, 14 Dec 2011 14:54:10 -0700\r
77 Message-ID: <3wdvcpi6cql.fsf@testarossa.amd.com>\r
78 MIME-Version: 1.0\r
79 Content-Type: text/plain; charset="us-ascii"\r
80 X-OriginatorOrg: amd.com\r
81 X-BeenThere: notmuch@notmuchmail.org\r
82 X-Mailman-Version: 2.1.13\r
83 Precedence: list\r
84 List-Id: "Use and development of the notmuch mail system."\r
85         <notmuch.notmuchmail.org>\r
86 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
87         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
88 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
89 List-Post: <mailto:notmuch@notmuchmail.org>\r
90 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
91 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
92         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
93 X-List-Received-Date: Wed, 14 Dec 2011 21:54:26 -0000\r
94 \r
95 On Tue, 13 Dec 2011 11:11:42 -0600, Thomas Jost <schnouki@schnouki.net> wrote:\r
96 > This is a time_t value, similar to the message date (TIMESTAMP). It is first set\r
97 > when the message is added to the database, and is then updated every time a tag\r
98 > is added or removed. It can thus be used for doing incremental dumps of the\r
99 > database or for synchronizing it between several computers.\r
100\r
101 > This value can be read freely (with notmuch_message_get_mtime()) but for now it\r
102 > can't be set to an arbitrary value: it can only be set to "now" when updated.\r
103 > There's no specific reason for this except that I don't really see a real use\r
104 > case for setting it to an arbitrary value.\r
105 \r
106 I think it would be easier to write some testcases if the last modified\r
107 time could be touched directly.  Perhaps they aren't in the set of "must\r
108 have", but it's what comes to mind.\r
109 \r
110 -Mark\r
111 \r
112 > ---\r
113 >  lib/database.cc       |    7 ++++++-\r
114 >  lib/message.cc        |   32 ++++++++++++++++++++++++++++++++\r
115 >  lib/notmuch-private.h |    6 +++++-\r
116 >  lib/notmuch.h         |    4 ++++\r
117 >  4 files changed, 47 insertions(+), 2 deletions(-)\r
118\r
119 > diff --git a/lib/database.cc b/lib/database.cc\r
120 > index 2025189..6dc6f73 100644\r
121 > --- a/lib/database.cc\r
122 > +++ b/lib/database.cc\r
123 > @@ -81,7 +81,7 @@ typedef struct {\r
124 >   *                   STRING is the name of a file within that\r
125 >   *                   directory for this mail message.\r
126 >   *\r
127 > - *    A mail document also has four values:\r
128 > + *    A mail document also has five values:\r
129 >   *\r
130 >   *   TIMESTAMP:      The time_t value corresponding to the message's\r
131 >   *                   Date header.\r
132 > @@ -92,6 +92,9 @@ typedef struct {\r
133 >   *\r
134 >   *   SUBJECT:        The value of the "Subject" header\r
135 >   *\r
136 > + *   MTIME:          The time_t value corresponding to the last time\r
137 > + *                   a tag was added or removed on the message.\r
138 > + *\r
139 >   * In addition, terms from the content of the message are added with\r
140 >   * "from", "to", "attachment", and "subject" prefixes for use by the\r
141 >   * user in searching. Similarly, terms from the path of the mail\r
142 > @@ -1735,6 +1738,8 @@ notmuch_database_add_message (notmuch_database_t *notmuch,\r
143 >           date = notmuch_message_file_get_header (message_file, "date");\r
144 >           _notmuch_message_set_header_values (message, date, from, subject);\r
145 >  \r
146 > +            _notmuch_message_update_mtime (message);\r
147 > +\r
148 >           _notmuch_message_index_file (message, filename);\r
149 >       } else {\r
150 >           ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;\r
151 > diff --git a/lib/message.cc b/lib/message.cc\r
152 > index 0075425..0c98589 100644\r
153 > --- a/lib/message.cc\r
154 > +++ b/lib/message.cc\r
155 > @@ -830,6 +830,34 @@ _notmuch_message_set_header_values (notmuch_message_t *message,\r
156 >      message->doc.add_value (NOTMUCH_VALUE_SUBJECT, subject);\r
157 >  }\r
158 >  \r
159 > +/* Get the message mtime, i.e. when it was added or the last time a tag was\r
160 > + * added/removed. */\r
161 > +time_t\r
162 > +notmuch_message_get_mtime (notmuch_message_t *message)\r
163 > +{\r
164 > +    std::string value;\r
165 > +\r
166 > +    try {\r
167 > +     value = message->doc.get_value (NOTMUCH_VALUE_MTIME);\r
168 > +    } catch (Xapian::Error &error) {\r
169 > +     INTERNAL_ERROR ("Failed to read mtime value from document.");\r
170 > +     return 0;\r
171 > +    }\r
172 > +\r
173 > +    return Xapian::sortable_unserialise (value);\r
174 > +}\r
175 > +\r
176 > +/* Set the message mtime to "now". */\r
177 > +void\r
178 > +_notmuch_message_update_mtime (notmuch_message_t *message)\r
179 > +{\r
180 > +    time_t time_value;\r
181 > +\r
182 > +    time_value = time (NULL);\r
183 > +    message->doc.add_value (NOTMUCH_VALUE_MTIME,\r
184 > +                            Xapian::sortable_serialise (time_value));\r
185 > +}\r
186 > +\r
187 >  /* Synchronize changes made to message->doc out into the database. */\r
188 >  void\r
189 >  _notmuch_message_sync (notmuch_message_t *message)\r
190 > @@ -994,6 +1022,8 @@ notmuch_message_add_tag (notmuch_message_t *message, const char *tag)\r
191 >                       private_status);\r
192 >      }\r
193 >  \r
194 > +    _notmuch_message_update_mtime (message);\r
195 > +\r
196 >      if (! message->frozen)\r
197 >       _notmuch_message_sync (message);\r
198 >  \r
199 > @@ -1022,6 +1052,8 @@ notmuch_message_remove_tag (notmuch_message_t *message, const char *tag)\r
200 >                       private_status);\r
201 >      }\r
202 >  \r
203 > +    _notmuch_message_update_mtime (message);\r
204 > +\r
205 >      if (! message->frozen)\r
206 >       _notmuch_message_sync (message);\r
207 >  \r
208 > diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
209 > index 60a932f..9859872 100644\r
210 > --- a/lib/notmuch-private.h\r
211 > +++ b/lib/notmuch-private.h\r
212 > @@ -95,7 +95,8 @@ typedef enum {\r
213 >      NOTMUCH_VALUE_TIMESTAMP = 0,\r
214 >      NOTMUCH_VALUE_MESSAGE_ID,\r
215 >      NOTMUCH_VALUE_FROM,\r
216 > -    NOTMUCH_VALUE_SUBJECT\r
217 > +    NOTMUCH_VALUE_SUBJECT,\r
218 > +    NOTMUCH_VALUE_MTIME\r
219 >  } notmuch_value_t;\r
220 >  \r
221 >  /* Xapian (with flint backend) complains if we provide a term longer\r
222 > @@ -276,6 +277,9 @@ _notmuch_message_set_header_values (notmuch_message_t *message,\r
223 >                                   const char *from,\r
224 >                                   const char *subject);\r
225 >  void\r
226 > +_notmuch_message_update_mtime (notmuch_message_t *message);\r
227 > +\r
228 > +void\r
229 >  _notmuch_message_sync (notmuch_message_t *message);\r
230 >  \r
231 >  notmuch_status_t\r
232 > diff --git a/lib/notmuch.h b/lib/notmuch.h\r
233 > index 9f23a10..643ebce 100644\r
234 > --- a/lib/notmuch.h\r
235 > +++ b/lib/notmuch.h\r
236 > @@ -910,6 +910,10 @@ notmuch_message_set_flag (notmuch_message_t *message,\r
237 >  time_t\r
238 >  notmuch_message_get_date  (notmuch_message_t *message);\r
239 >  \r
240 > +/* Get the mtime of 'message' as a time_t value. */\r
241 > +time_t\r
242 > +notmuch_message_get_mtime (notmuch_message_t *message);\r
243 > +\r
244 >  /* Get the value of the specified header from 'message'.\r
245 >   *\r
246 >   * The value will be read from the actual message file, not from the\r
247 > -- \r
248 > 1.7.8\r
249\r
250 > _______________________________________________\r
251 > notmuch mailing list\r
252 > notmuch@notmuchmail.org\r
253 > http://notmuchmail.org/mailman/listinfo/notmuch\r
254\r
255 \r