1 Return-Path: <sojkam1@fel.cvut.cz>
\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 90A3540CAE9
\r
6 for <notmuch@notmuchmail.org>; Tue, 11 May 2010 05:15:02 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5
\r
12 tests=[BAYES_00=-1.9] autolearn=ham
\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 Uckj7ydOAxKl for <notmuch@notmuchmail.org>;
\r
16 Tue, 11 May 2010 05:14:48 -0700 (PDT)
\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])
\r
18 by olra.theworths.org (Postfix) with ESMTP id F07E14196F5
\r
19 for <notmuch@notmuchmail.org>; Tue, 11 May 2010 05:14:35 -0700 (PDT)
\r
20 Received: from localhost (unknown [192.168.200.4])
\r
21 by max.feld.cvut.cz (Postfix) with ESMTP id CD23919F340F;
\r
22 Tue, 11 May 2010 14:14:34 +0200 (CEST)
\r
23 X-Virus-Scanned: IMAP AMAVIS
\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])
\r
25 by localhost (styx.feld.cvut.cz [192.168.200.4]) (amavisd-new,
\r
27 with ESMTP id sRDY0mxtmeOR; Tue, 11 May 2010 14:14:32 +0200 (CEST)
\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])
\r
29 by max.feld.cvut.cz (Postfix) with ESMTP id B827719F3406;
\r
30 Tue, 11 May 2010 14:14:31 +0200 (CEST)
\r
31 Received: from steelpick.2x.cz (k335-30.felk.cvut.cz [147.32.86.30])
\r
32 (Authenticated sender: sojkam1)
\r
33 by imap.feld.cvut.cz (Postfix) with ESMTPSA id A1FFFFA003;
\r
34 Tue, 11 May 2010 14:14:31 +0200 (CEST)
\r
35 Received: from wsh by steelpick.2x.cz with local (Exim 4.71)
\r
36 (envelope-from <sojkam1@fel.cvut.cz>)
\r
37 id 1OBoM3-0005sz-El; Tue, 11 May 2010 14:14:31 +0200
\r
38 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
39 To: notmuch@notmuchmail.org
\r
40 Subject: [PATCH 3/4] Make maildir synchronization configurable
\r
41 Date: Tue, 11 May 2010 14:14:20 +0200
\r
42 Message-Id: <1273580061-22580-4-git-send-email-sojkam1@fel.cvut.cz>
\r
43 X-Mailer: git-send-email 1.7.1
\r
44 In-Reply-To: <1273580061-22580-1-git-send-email-sojkam1@fel.cvut.cz>
\r
45 References: <1273580061-22580-1-git-send-email-sojkam1@fel.cvut.cz>
\r
46 X-BeenThere: notmuch@notmuchmail.org
\r
47 X-Mailman-Version: 2.1.13
\r
49 List-Id: "Use and development of the notmuch mail system."
\r
50 <notmuch.notmuchmail.org>
\r
51 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
52 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
53 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
54 List-Post: <mailto:notmuch@notmuchmail.org>
\r
55 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
56 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
57 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
58 X-List-Received-Date: Tue, 11 May 2010 12:15:02 -0000
\r
60 This adds group [maildir] and key 'sync_level' to the configuration file.
\r
61 The value of sync_level is used to control how the synchronization happens.
\r
62 The default value is no synchronization.
\r
64 lib/database-private.h | 2 +-
\r
65 lib/database.cc | 9 +++++++++
\r
66 lib/message.cc | 2 +-
\r
67 lib/notmuch.h | 19 +++++++++++++++++++
\r
68 notmuch-client.h | 7 +++++++
\r
69 notmuch-config.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
\r
70 notmuch-new.c | 8 ++++++--
\r
71 notmuch-restore.c | 2 ++
\r
72 notmuch-setup.c | 17 +++++++++++++++++
\r
73 notmuch-tag.c | 2 ++
\r
74 10 files changed, 112 insertions(+), 4 deletions(-)
\r
76 diff --git a/lib/database-private.h b/lib/database-private.h
\r
77 index 41918d7..370d779 100644
\r
78 --- a/lib/database-private.h
\r
79 +++ b/lib/database-private.h
\r
80 @@ -48,7 +48,7 @@ struct _notmuch_database {
\r
81 Xapian::QueryParser *query_parser;
\r
82 Xapian::TermGenerator *term_gen;
\r
83 Xapian::ValueRangeProcessor *value_range_processor;
\r
85 + enum notmuch_maildir_sync maildir_sync;
\r
88 /* Convert tags from Xapian internal format to notmuch format.
\r
89 diff --git a/lib/database.cc b/lib/database.cc
\r
90 index 908bbaa..bf645d0 100644
\r
91 --- a/lib/database.cc
\r
92 +++ b/lib/database.cc
\r
93 @@ -662,6 +662,8 @@ notmuch_database_open (const char *path,
\r
97 + notmuch_database_set_maildir_sync (notmuch, NOTMUCH_MAILDIR_SYNC_NONE);
\r
101 free (notmuch_path);
\r
102 @@ -691,6 +693,13 @@ notmuch_database_close (notmuch_database_t *notmuch)
\r
103 talloc_free (notmuch);
\r
107 +notmuch_database_set_maildir_sync (notmuch_database_t *database,
\r
108 + enum notmuch_maildir_sync maildir_sync)
\r
110 + database->maildir_sync = maildir_sync;
\r
114 notmuch_database_get_path (notmuch_database_t *notmuch)
\r
116 diff --git a/lib/message.cc b/lib/message.cc
\r
117 index 0de3f01..758e6fa 100644
\r
118 --- a/lib/message.cc
\r
119 +++ b/lib/message.cc
\r
120 @@ -599,7 +599,7 @@ _notmuch_message_sync (notmuch_message_t *message)
\r
121 if (message->notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)
\r
124 - if (// todo_sync_enabled &&
\r
125 + if (message->notmuch->maildir_sync == NOTMUCH_MAILDIR_SYNC_NEW_RENAMED_TAGGED &&
\r
126 !notmuch_message_get_flag(message, NOTMUCH_MESSAGE_FLAG_TAGS_INVALID)) {
\r
127 status = _notmuch_message_tags_to_maildir (message);
\r
128 if (status != NOTMUCH_PRIVATE_STATUS_SUCCESS) {
\r
129 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
130 index 408d633..34b3bcf 100644
\r
131 --- a/lib/notmuch.h
\r
132 +++ b/lib/notmuch.h
\r
133 @@ -108,6 +108,19 @@ typedef enum _notmuch_status {
\r
135 notmuch_status_to_string (notmuch_status_t status);
\r
137 +/* Level of synchronization between notmuch tags and maildir flags. */
\r
138 +enum notmuch_maildir_sync {
\r
139 + NOTMUCH_MAILDIR_SYNC_INVALID = 0,
\r
140 + /* No synchronization */
\r
141 + NOTMUCH_MAILDIR_SYNC_NONE,
\r
142 + /* Tag new messages accoring to maildir flags */
\r
143 + NOTMUCH_MAILDIR_SYNC_NEW,
\r
144 + /* The above + update tags for renamed messages */
\r
145 + NOTMUCH_MAILDIR_SYNC_NEW_RENAMED,
\r
146 + /* The above + update flags when tags are added/removed. */
\r
147 + NOTMUCH_MAILDIR_SYNC_NEW_RENAMED_TAGGED,
\r
150 /* Various opaque data types. For each notmuch_<foo>_t see the various
\r
151 * notmuch_<foo> functions below. */
\r
152 typedef struct _notmuch_database notmuch_database_t;
\r
153 @@ -176,6 +189,12 @@ notmuch_database_open (const char *path,
\r
155 notmuch_database_close (notmuch_database_t *database);
\r
157 +/* Sets the level of synchronization between maildir flags and notmuch
\r
160 +notmuch_database_set_maildir_sync (notmuch_database_t *database,
\r
161 + enum notmuch_maildir_sync maildir_sync);
\r
163 /* Return the database path of the given database.
\r
165 * The return value is a string owned by notmuch so should not be
\r
166 diff --git a/notmuch-client.h b/notmuch-client.h
\r
167 index 20be43b..50be95c 100644
\r
168 --- a/notmuch-client.h
\r
169 +++ b/notmuch-client.h
\r
170 @@ -191,6 +191,13 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
\r
171 const char *new_tags[],
\r
174 +enum notmuch_maildir_sync
\r
175 +notmuch_config_get_maildir_sync (notmuch_config_t *config);
\r
178 +notmuch_config_set_maildir_sync (notmuch_config_t *config,
\r
179 + enum notmuch_maildir_sync maildir_sync);
\r
182 debugger_is_active (void);
\r
184 diff --git a/notmuch-config.c b/notmuch-config.c
\r
185 index 58f83b0..5ac5f7b 100644
\r
186 --- a/notmuch-config.c
\r
187 +++ b/notmuch-config.c
\r
188 @@ -61,6 +61,21 @@ static const char user_config_comment[] =
\r
189 " recipient list of replies, and will set the From address based on the\n"
\r
190 " address to which the original email was addressed.\n";
\r
192 +static const char maildir_config_comment[] =
\r
193 + " Maildir compatibility configuration\n"
\r
195 + " Here you can configure whether and how will notmuch synchronize its\n"
\r
196 + " tags with maildir flags."
\r
198 + "\tsync_level Integer in the range 1 - 4 with the following meaning:\n"
\r
199 + "\t\t1 - No synchronization at all.\n"
\r
200 + "\t\t2 - 'notmuch new' tags the messages based on their maildir flags\n"
\r
201 + "\t\t only when it sees them for the first time.\n"
\r
202 + "\t\t3 - Same as 2 plus 'notmuch new' updates tags when it detects the\n"
\r
203 + "\t\t message was renamed.\n"
\r
204 + "\t\t4 - Same as 3 plus whenever message tags are changed, maildir\n"
\r
205 + "\t\t flags are updated accordingly.\n";
\r
207 struct _notmuch_config {
\r
209 GKeyFile *key_file;
\r
210 @@ -72,6 +87,7 @@ struct _notmuch_config {
\r
211 size_t user_other_email_length;
\r
212 const char **new_tags;
\r
213 size_t new_tags_length;
\r
214 + enum notmuch_maildir_sync maildir_sync;
\r
218 @@ -184,6 +200,7 @@ notmuch_config_open (void *ctx,
\r
219 int file_had_database_group;
\r
220 int file_had_new_group;
\r
221 int file_had_user_group;
\r
222 + int file_had_maildir_group;
\r
226 @@ -214,6 +231,7 @@ notmuch_config_open (void *ctx,
\r
227 config->user_other_email_length = 0;
\r
228 config->new_tags = NULL;
\r
229 config->new_tags_length = 0;
\r
230 + config->maildir_sync = NOTMUCH_MAILDIR_SYNC_INVALID;
\r
232 if (! g_key_file_load_from_file (config->key_file,
\r
234 @@ -254,6 +272,7 @@ notmuch_config_open (void *ctx,
\r
236 file_had_new_group = g_key_file_has_group (config->key_file, "new");
\r
237 file_had_user_group = g_key_file_has_group (config->key_file, "user");
\r
238 + file_had_maildir_group = g_key_file_has_group (config->key_file, "maildir");
\r
241 if (notmuch_config_get_database_path (config) == NULL) {
\r
242 @@ -304,6 +323,10 @@ notmuch_config_open (void *ctx,
\r
243 notmuch_config_set_new_tags (config, tags, 2);
\r
246 + if (notmuch_config_get_maildir_sync (config) == NOTMUCH_MAILDIR_SYNC_INVALID) {
\r
247 + notmuch_config_set_maildir_sync (config, NOTMUCH_MAILDIR_SYNC_NONE);
\r
250 /* Whenever we know of configuration sections that don't appear in
\r
251 * the configuration file, we add some comments to help the user
\r
252 * understand what can be done. */
\r
253 @@ -331,6 +354,12 @@ notmuch_config_open (void *ctx,
\r
254 user_config_comment, NULL);
\r
257 + if (! file_had_maildir_group)
\r
259 + g_key_file_set_comment (config->key_file, "maildir", NULL,
\r
260 + maildir_config_comment, NULL);
\r
264 *is_new_ret = is_new;
\r
266 @@ -553,3 +582,22 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
\r
267 config->new_tags = NULL;
\r
270 +enum notmuch_maildir_sync
\r
271 +notmuch_config_get_maildir_sync (notmuch_config_t *config)
\r
273 + if (config->maildir_sync == NOTMUCH_MAILDIR_SYNC_INVALID) {
\r
274 + config->maildir_sync =
\r
275 + g_key_file_get_integer (config->key_file,
\r
276 + "maildir", "sync_level", NULL);
\r
278 + return config->maildir_sync;
\r
282 +notmuch_config_set_maildir_sync (notmuch_config_t *config,
\r
283 + enum notmuch_maildir_sync maildir_sync)
\r
285 + g_key_file_set_integer (config->key_file,
\r
286 + "maildir", "sync_level", maildir_sync);
\r
287 + config->maildir_sync = maildir_sync;
\r
289 diff --git a/notmuch-new.c b/notmuch-new.c
\r
290 index ed3f944..40ea610 100644
\r
291 --- a/notmuch-new.c
\r
292 +++ b/notmuch-new.c
\r
293 @@ -45,6 +45,7 @@ typedef struct {
\r
295 _filename_list_t *removed_files;
\r
296 _filename_list_t *removed_directories;
\r
297 + enum notmuch_maildir_sync maildir_sync;
\r
298 } add_files_state_t;
\r
300 static volatile sig_atomic_t do_add_files_print_progress = 0;
\r
301 @@ -410,11 +411,13 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
302 state->added_messages++;
\r
303 for (tag=state->new_tags; *tag != NULL; tag++)
\r
304 notmuch_message_add_tag (message, *tag);
\r
305 - notmuch_message_maildir_to_tags (message, next);
\r
306 + if (state->maildir_sync >= NOTMUCH_MAILDIR_SYNC_NEW)
\r
307 + notmuch_message_maildir_to_tags (message, next);
\r
309 /* Non-fatal issues (go on to next file) */
\r
310 case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
\r
311 - notmuch_message_maildir_to_tags (message, next);
\r
312 + if (state->maildir_sync >= NOTMUCH_MAILDIR_SYNC_NEW_RENAMED)
\r
313 + notmuch_message_maildir_to_tags (message, next);
\r
315 case NOTMUCH_STATUS_FILE_NOT_EMAIL:
\r
316 fprintf (stderr, "Note: Ignoring non-mail file: %s\n",
\r
317 @@ -738,6 +741,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
320 add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);
\r
321 + add_files_state.maildir_sync = notmuch_config_get_maildir_sync (config);
\r
322 db_path = notmuch_config_get_database_path (config);
\r
324 dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");
\r
325 diff --git a/notmuch-restore.c b/notmuch-restore.c
\r
326 index b0a4e1c..b5c5c48 100644
\r
327 --- a/notmuch-restore.c
\r
328 +++ b/notmuch-restore.c
\r
329 @@ -41,6 +41,8 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
330 if (notmuch == NULL)
\r
333 + notmuch_database_set_maildir_sync (notmuch,
\r
334 + notmuch_config_get_maildir_sync (config));
\r
336 input = fopen (argv[0], "r");
\r
337 if (input == NULL) {
\r
338 diff --git a/notmuch-setup.c b/notmuch-setup.c
\r
339 index 955deb7..8364854 100644
\r
340 --- a/notmuch-setup.c
\r
341 +++ b/notmuch-setup.c
\r
342 @@ -195,6 +195,23 @@ notmuch_setup_command (unused (void *ctx),
\r
343 g_ptr_array_free (tags, TRUE);
\r
347 + "Notmuch can synchronize certain tags with maildir flags. You can\n"
\r
348 + "select between several levels of synchronization:\n"
\r
349 + "1 - No synchronization at all.\n"
\r
350 + "2 - 'notmuch new' tags the messages based on their maildir flags\n"
\r
351 + " only when it sees them for the first time.\n"
\r
352 + "3 - Same as 2 plus 'notmuch new' updates tags when it detects the\n"
\r
353 + " message was renamed.\n"
\r
354 + "4 - Same as 3 plus whenever message tags are changed, maildir\n"
\r
355 + " flags are updated accordingly.\n");
\r
357 + prompt ("Maildir synchronization level [%d]: ", notmuch_config_get_maildir_sync (config));
\r
358 + if (strlen (response) == 1 &&
\r
359 + response[0] >= '1' &&
\r
360 + response[0] <= '4')
\r
361 + notmuch_config_set_maildir_sync (config, atoi (response));
\r
363 if (! notmuch_config_save (config)) {
\r
365 welcome_message_post_setup ();
\r
366 diff --git a/notmuch-tag.c b/notmuch-tag.c
\r
367 index fd54bc7..3a489a9 100644
\r
368 --- a/notmuch-tag.c
\r
369 +++ b/notmuch-tag.c
\r
370 @@ -100,6 +100,8 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
371 NOTMUCH_DATABASE_MODE_READ_WRITE);
\r
372 if (notmuch == NULL)
\r
374 + notmuch_database_set_maildir_sync (notmuch,
\r
375 + notmuch_config_get_maildir_sync (config));
\r
377 query = notmuch_query_create (notmuch, query_string);
\r
378 if (query == NULL) {
\r