1 Return-Path: <schnouki@schnouki.net>
\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 3AAAA429E25
\r
6 for <notmuch@notmuchmail.org>; Tue, 13 Dec 2011 09:12:11 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.1 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1]
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id cNxkHsTdUanm for <notmuch@notmuchmail.org>;
\r
17 Tue, 13 Dec 2011 09:12:09 -0800 (PST)
\r
18 Received: from ks3536.kimsufi.com (schnouki.net [87.98.217.222])
\r
19 by olra.theworths.org (Postfix) with ESMTP id 0C4A0429E29
\r
20 for <notmuch@notmuchmail.org>; Tue, 13 Dec 2011 09:12:09 -0800 (PST)
\r
21 Received: from thor.loria.fr (thor.loria.fr [152.81.12.250])
\r
22 by ks3536.kimsufi.com (Postfix) with ESMTPSA id 41AAF6A002A;
\r
23 Tue, 13 Dec 2011 18:12:08 +0100 (CET)
\r
24 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=schnouki.net;
\r
25 s=key-schnouki; t=1323796328;
\r
26 bh=EtHcMD+7gqtNXmtfU4FRCK6w1Rq9oohRWUpyVSw04Bs=;
\r
27 h=From:To:Subject:Date:Message-Id:In-Reply-To:References;
\r
28 b=L/kg4l4zxHSnDdZvgM1h/4rNe5e7f3RGBjadOvS6Ui8c49fZxlm6d71cQFmauApd+
\r
29 9M30B/f7nYhd4b0tFTcF1GqDj3JQN14nxaNVf5doMVX30UnclojQ8tjuENpP+0jvVW
\r
30 8JGY7xevU8Sjc4NqPUsxB/JNtRIfYrRqWxszoZlk=
\r
31 From: Thomas Jost <schnouki@schnouki.net>
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [PATCH 2/5] lib: Add a MTIME value to every mail document
\r
34 Date: Tue, 13 Dec 2011 18:11:42 +0100
\r
35 Message-Id: <1323796305-28789-3-git-send-email-schnouki@schnouki.net>
\r
36 X-Mailer: git-send-email 1.7.8
\r
37 In-Reply-To: <1323796305-28789-1-git-send-email-schnouki@schnouki.net>
\r
38 References: <1323796305-28789-1-git-send-email-schnouki@schnouki.net>
\r
39 X-BeenThere: notmuch@notmuchmail.org
\r
40 X-Mailman-Version: 2.1.13
\r
42 List-Id: "Use and development of the notmuch mail system."
\r
43 <notmuch.notmuchmail.org>
\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
47 List-Post: <mailto:notmuch@notmuchmail.org>
\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
51 X-List-Received-Date: Tue, 13 Dec 2011 17:12:11 -0000
\r
53 This is a time_t value, similar to the message date (TIMESTAMP). It is first set
\r
54 when the message is added to the database, and is then updated every time a tag
\r
55 is added or removed. It can thus be used for doing incremental dumps of the
\r
56 database or for synchronizing it between several computers.
\r
58 This value can be read freely (with notmuch_message_get_mtime()) but for now it
\r
59 can't be set to an arbitrary value: it can only be set to "now" when updated.
\r
60 There's no specific reason for this except that I don't really see a real use
\r
61 case for setting it to an arbitrary value.
\r
63 lib/database.cc | 7 ++++++-
\r
64 lib/message.cc | 32 ++++++++++++++++++++++++++++++++
\r
65 lib/notmuch-private.h | 6 +++++-
\r
66 lib/notmuch.h | 4 ++++
\r
67 4 files changed, 47 insertions(+), 2 deletions(-)
\r
69 diff --git a/lib/database.cc b/lib/database.cc
\r
70 index 2025189..6dc6f73 100644
\r
71 --- a/lib/database.cc
\r
72 +++ b/lib/database.cc
\r
73 @@ -81,7 +81,7 @@ typedef struct {
\r
74 * STRING is the name of a file within that
\r
75 * directory for this mail message.
\r
77 - * A mail document also has four values:
\r
78 + * A mail document also has five values:
\r
80 * TIMESTAMP: The time_t value corresponding to the message's
\r
82 @@ -92,6 +92,9 @@ typedef struct {
\r
84 * SUBJECT: The value of the "Subject" header
\r
86 + * MTIME: The time_t value corresponding to the last time
\r
87 + * a tag was added or removed on the message.
\r
89 * In addition, terms from the content of the message are added with
\r
90 * "from", "to", "attachment", and "subject" prefixes for use by the
\r
91 * user in searching. Similarly, terms from the path of the mail
\r
92 @@ -1735,6 +1738,8 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\r
93 date = notmuch_message_file_get_header (message_file, "date");
\r
94 _notmuch_message_set_header_values (message, date, from, subject);
\r
96 + _notmuch_message_update_mtime (message);
\r
98 _notmuch_message_index_file (message, filename);
\r
100 ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
\r
101 diff --git a/lib/message.cc b/lib/message.cc
\r
102 index 0075425..0c98589 100644
\r
103 --- a/lib/message.cc
\r
104 +++ b/lib/message.cc
\r
105 @@ -830,6 +830,34 @@ _notmuch_message_set_header_values (notmuch_message_t *message,
\r
106 message->doc.add_value (NOTMUCH_VALUE_SUBJECT, subject);
\r
109 +/* Get the message mtime, i.e. when it was added or the last time a tag was
\r
110 + * added/removed. */
\r
112 +notmuch_message_get_mtime (notmuch_message_t *message)
\r
114 + std::string value;
\r
117 + value = message->doc.get_value (NOTMUCH_VALUE_MTIME);
\r
118 + } catch (Xapian::Error &error) {
\r
119 + INTERNAL_ERROR ("Failed to read mtime value from document.");
\r
123 + return Xapian::sortable_unserialise (value);
\r
126 +/* Set the message mtime to "now". */
\r
128 +_notmuch_message_update_mtime (notmuch_message_t *message)
\r
130 + time_t time_value;
\r
132 + time_value = time (NULL);
\r
133 + message->doc.add_value (NOTMUCH_VALUE_MTIME,
\r
134 + Xapian::sortable_serialise (time_value));
\r
137 /* Synchronize changes made to message->doc out into the database. */
\r
139 _notmuch_message_sync (notmuch_message_t *message)
\r
140 @@ -994,6 +1022,8 @@ notmuch_message_add_tag (notmuch_message_t *message, const char *tag)
\r
144 + _notmuch_message_update_mtime (message);
\r
146 if (! message->frozen)
\r
147 _notmuch_message_sync (message);
\r
149 @@ -1022,6 +1052,8 @@ notmuch_message_remove_tag (notmuch_message_t *message, const char *tag)
\r
153 + _notmuch_message_update_mtime (message);
\r
155 if (! message->frozen)
\r
156 _notmuch_message_sync (message);
\r
158 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
\r
159 index 60a932f..9859872 100644
\r
160 --- a/lib/notmuch-private.h
\r
161 +++ b/lib/notmuch-private.h
\r
162 @@ -95,7 +95,8 @@ typedef enum {
\r
163 NOTMUCH_VALUE_TIMESTAMP = 0,
\r
164 NOTMUCH_VALUE_MESSAGE_ID,
\r
165 NOTMUCH_VALUE_FROM,
\r
166 - NOTMUCH_VALUE_SUBJECT
\r
167 + NOTMUCH_VALUE_SUBJECT,
\r
168 + NOTMUCH_VALUE_MTIME
\r
171 /* Xapian (with flint backend) complains if we provide a term longer
\r
172 @@ -276,6 +277,9 @@ _notmuch_message_set_header_values (notmuch_message_t *message,
\r
174 const char *subject);
\r
176 +_notmuch_message_update_mtime (notmuch_message_t *message);
\r
179 _notmuch_message_sync (notmuch_message_t *message);
\r
182 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
183 index 9f23a10..643ebce 100644
\r
184 --- a/lib/notmuch.h
\r
185 +++ b/lib/notmuch.h
\r
186 @@ -910,6 +910,10 @@ notmuch_message_set_flag (notmuch_message_t *message,
\r
188 notmuch_message_get_date (notmuch_message_t *message);
\r
190 +/* Get the mtime of 'message' as a time_t value. */
\r
192 +notmuch_message_get_mtime (notmuch_message_t *message);
\r
194 /* Get the value of the specified header from 'message'.
\r
196 * The value will be read from the actual message file, not from the
\r