1 Return-Path: <wsh@resox.2x.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 2EE4940D162
\r
6 for <notmuch@notmuchmail.org>; Sun, 31 Oct 2010 14:48:49 -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=unavailable
\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 nwxB5xWgGE5f for <notmuch@notmuchmail.org>;
\r
16 Sun, 31 Oct 2010 14:48:34 -0700 (PDT)
\r
17 Received: from smtp.nextra.cz (smtp.nextra.cz [212.65.193.3])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 6CCE040D167
\r
19 for <notmuch@notmuchmail.org>; Sun, 31 Oct 2010 14:48:02 -0700 (PDT)
\r
20 Received: from resox.2x.cz (unknown [213.29.198.144])
\r
21 by smtp.nextra.cz (Postfix) with ESMTP id 7D0B788D04;
\r
22 Sun, 31 Oct 2010 22:30:26 +0100 (CET)
\r
23 Received: from wsh by resox.2x.cz with local (Exim 4.72)
\r
24 (envelope-from <wsh@resox.2x.cz>)
\r
25 id 1PCfTk-0004wo-9I; Sun, 31 Oct 2010 22:30:16 +0100
\r
26 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
27 To: notmuch@notmuchmail.org
\r
28 Subject: [PATCH v4 3/4] Make maildir synchronization configurable
\r
29 Date: Sun, 31 Oct 2010 22:29:17 +0100
\r
30 Message-Id: <1288560558-18915-4-git-send-email-sojkam1@fel.cvut.cz>
\r
31 X-Mailer: git-send-email 1.7.1
\r
32 In-Reply-To: <87tyk3vpxd.fsf@wsheee.2x.cz>
\r
33 References: <87tyk3vpxd.fsf@wsheee.2x.cz>
\r
34 X-BeenThere: notmuch@notmuchmail.org
\r
35 X-Mailman-Version: 2.1.13
\r
37 List-Id: "Use and development of the notmuch mail system."
\r
38 <notmuch.notmuchmail.org>
\r
39 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
40 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
42 List-Post: <mailto:notmuch@notmuchmail.org>
\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
44 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
46 X-List-Received-Date: Sun, 31 Oct 2010 21:48:49 -0000
\r
48 This adds group [maildir] and key 'synchronize_flags' to the
\r
49 configuration file. Its value enables (true) or diables (false) the
\r
50 synchronization between notmuch tags and maildir flags. By default,
\r
51 the synchronization is disabled.
\r
53 lib/database-private.h | 2 +-
\r
54 lib/database.cc | 9 ++++++++
\r
55 lib/message.cc | 2 +-
\r
56 lib/notmuch.h | 6 +++++
\r
57 notmuch-client.h | 7 ++++++
\r
58 notmuch-config.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
\r
59 notmuch-new.c | 8 +++++-
\r
60 notmuch-restore.c | 2 +
\r
61 notmuch-setup.c | 10 +++++++++
\r
63 10 files changed, 93 insertions(+), 4 deletions(-)
\r
65 diff --git a/lib/database-private.h b/lib/database-private.h
\r
66 index bd72f67..dd89c63 100644
\r
67 --- a/lib/database-private.h
\r
68 +++ b/lib/database-private.h
\r
69 @@ -49,7 +49,7 @@ struct _notmuch_database {
\r
70 Xapian::QueryParser *query_parser;
\r
71 Xapian::TermGenerator *term_gen;
\r
72 Xapian::ValueRangeProcessor *value_range_processor;
\r
74 + notmuch_bool_t maildir_sync;
\r
77 /* Convert tags from Xapian internal format to notmuch format.
\r
78 diff --git a/lib/database.cc b/lib/database.cc
\r
79 index 9652013..069918a 100644
\r
80 --- a/lib/database.cc
\r
81 +++ b/lib/database.cc
\r
82 @@ -689,6 +689,8 @@ notmuch_database_open (const char *path,
\r
86 + notmuch_database_set_maildir_sync (notmuch, FALSE);
\r
90 free (notmuch_path);
\r
91 @@ -718,6 +720,13 @@ notmuch_database_close (notmuch_database_t *notmuch)
\r
92 talloc_free (notmuch);
\r
96 +notmuch_database_set_maildir_sync (notmuch_database_t *database,
\r
97 + notmuch_bool_t maildir_sync)
\r
99 + database->maildir_sync = maildir_sync;
\r
103 notmuch_database_get_path (notmuch_database_t *notmuch)
\r
105 diff --git a/lib/message.cc b/lib/message.cc
\r
106 index bb96242..80bef8e 100644
\r
107 --- a/lib/message.cc
\r
108 +++ b/lib/message.cc
\r
109 @@ -626,7 +626,7 @@ _notmuch_message_sync (notmuch_message_t *message)
\r
110 if (message->notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)
\r
113 - if (// todo_sync_enabled &&
\r
114 + if (message->notmuch->maildir_sync &&
\r
115 !notmuch_message_get_flag(message, NOTMUCH_MESSAGE_FLAG_TAGS_INVALID)) {
\r
116 status = _notmuch_message_tags_to_maildir (message);
\r
117 if (status != NOTMUCH_PRIVATE_STATUS_SUCCESS) {
\r
118 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
119 index fe01e73..41820b5 100644
\r
120 --- a/lib/notmuch.h
\r
121 +++ b/lib/notmuch.h
\r
122 @@ -176,6 +176,12 @@ notmuch_database_open (const char *path,
\r
124 notmuch_database_close (notmuch_database_t *database);
\r
126 +/* Sets whether maildir flags should be synchronized with notmuch
\r
129 +notmuch_database_set_maildir_sync (notmuch_database_t *database,
\r
130 + notmuch_bool_t maildir_sync);
\r
132 /* Return the database path of the given database.
\r
134 * The return value is a string owned by notmuch so should not be
\r
135 diff --git a/notmuch-client.h b/notmuch-client.h
\r
136 index d530578..c27d64f 100644
\r
137 --- a/notmuch-client.h
\r
138 +++ b/notmuch-client.h
\r
139 @@ -195,6 +195,13 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
\r
143 +notmuch_config_get_maildir_sync (notmuch_config_t *config);
\r
146 +notmuch_config_set_maildir_sync (notmuch_config_t *config,
\r
147 + notmuch_bool_t maildir_sync);
\r
150 debugger_is_active (void);
\r
153 diff --git a/notmuch-config.c b/notmuch-config.c
\r
154 index dcdb036..483d5c6 100644
\r
155 --- a/notmuch-config.c
\r
156 +++ b/notmuch-config.c
\r
157 @@ -61,6 +61,14 @@ static const char user_config_comment[] =
\r
158 " recipient list of replies, and will set the From address based on the\n"
\r
159 " address to which the original email was addressed.\n";
\r
161 +static const char maildir_config_comment[] =
\r
162 + " Maildir compatibility configuration\n"
\r
164 + " Here you can configure whether notmuch will synchronize its tags with\n"
\r
165 + " maildir flags."
\r
167 + "\tsynchronize_flags Valid values are true and false.\n";
\r
169 struct _notmuch_config {
\r
171 GKeyFile *key_file;
\r
172 @@ -72,8 +80,11 @@ struct _notmuch_config {
\r
173 size_t user_other_email_length;
\r
174 const char **new_tags;
\r
175 size_t new_tags_length;
\r
176 + notmuch_bool_t maildir_sync;
\r
179 +#define MAILDIR_SYNC_UNDEF ((notmuch_bool_t)-1)
\r
182 notmuch_config_destructor (notmuch_config_t *config)
\r
184 @@ -191,6 +202,7 @@ notmuch_config_open (void *ctx,
\r
185 int file_had_database_group;
\r
186 int file_had_new_group;
\r
187 int file_had_user_group;
\r
188 + int file_had_maildir_group;
\r
192 @@ -221,6 +233,7 @@ notmuch_config_open (void *ctx,
\r
193 config->user_other_email_length = 0;
\r
194 config->new_tags = NULL;
\r
195 config->new_tags_length = 0;
\r
196 + config->maildir_sync = MAILDIR_SYNC_UNDEF;
\r
198 if (! g_key_file_load_from_file (config->key_file,
\r
200 @@ -263,6 +276,7 @@ notmuch_config_open (void *ctx,
\r
202 file_had_new_group = g_key_file_has_group (config->key_file, "new");
\r
203 file_had_user_group = g_key_file_has_group (config->key_file, "user");
\r
204 + file_had_maildir_group = g_key_file_has_group (config->key_file, "maildir");
\r
207 if (notmuch_config_get_database_path (config) == NULL) {
\r
208 @@ -313,6 +327,10 @@ notmuch_config_open (void *ctx,
\r
209 notmuch_config_set_new_tags (config, tags, 2);
\r
212 + if (notmuch_config_get_maildir_sync (config) == MAILDIR_SYNC_UNDEF) {
\r
213 + notmuch_config_set_maildir_sync (config, FALSE);
\r
216 /* Whenever we know of configuration sections that don't appear in
\r
217 * the configuration file, we add some comments to help the user
\r
218 * understand what can be done. */
\r
219 @@ -340,6 +358,12 @@ notmuch_config_open (void *ctx,
\r
220 user_config_comment, NULL);
\r
223 + if (! file_had_maildir_group)
\r
225 + g_key_file_set_comment (config->key_file, "maildir", NULL,
\r
226 + maildir_config_comment, NULL);
\r
230 *is_new_ret = is_new;
\r
232 @@ -703,3 +727,28 @@ notmuch_config_command (void *ctx, int argc, char *argv[])
\r
238 +notmuch_config_get_maildir_sync (notmuch_config_t *config)
\r
240 + GError *err = NULL;
\r
241 + if (config->maildir_sync == MAILDIR_SYNC_UNDEF) {
\r
242 + config->maildir_sync =
\r
243 + g_key_file_get_boolean (config->key_file,
\r
244 + "maildir", "synchronize_flags", &err);
\r
246 + config->maildir_sync = MAILDIR_SYNC_UNDEF;
\r
247 + g_error_free (err);
\r
250 + return config->maildir_sync;
\r
254 +notmuch_config_set_maildir_sync (notmuch_config_t *config,
\r
255 + notmuch_bool_t maildir_sync)
\r
257 + g_key_file_set_boolean (config->key_file,
\r
258 + "maildir", "synchronize_flags", maildir_sync);
\r
259 + config->maildir_sync = maildir_sync;
\r
261 diff --git a/notmuch-new.c b/notmuch-new.c
\r
262 index ed3f944..273916e 100644
\r
263 --- a/notmuch-new.c
\r
264 +++ b/notmuch-new.c
\r
265 @@ -45,6 +45,7 @@ typedef struct {
\r
267 _filename_list_t *removed_files;
\r
268 _filename_list_t *removed_directories;
\r
269 + notmuch_bool_t maildir_sync;
\r
270 } add_files_state_t;
\r
272 static volatile sig_atomic_t do_add_files_print_progress = 0;
\r
273 @@ -410,11 +411,13 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
274 state->added_messages++;
\r
275 for (tag=state->new_tags; *tag != NULL; tag++)
\r
276 notmuch_message_add_tag (message, *tag);
\r
277 - notmuch_message_maildir_to_tags (message, next);
\r
278 + if (state->maildir_sync == TRUE)
\r
279 + notmuch_message_maildir_to_tags (message, next);
\r
281 /* Non-fatal issues (go on to next file) */
\r
282 case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
\r
283 - notmuch_message_maildir_to_tags (message, next);
\r
284 + if (state->maildir_sync == TRUE)
\r
285 + notmuch_message_maildir_to_tags (message, next);
\r
287 case NOTMUCH_STATUS_FILE_NOT_EMAIL:
\r
288 fprintf (stderr, "Note: Ignoring non-mail file: %s\n",
\r
289 @@ -738,6 +741,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
292 add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);
\r
293 + add_files_state.maildir_sync = notmuch_config_get_maildir_sync (config);
\r
294 db_path = notmuch_config_get_database_path (config);
\r
296 dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");
\r
297 diff --git a/notmuch-restore.c b/notmuch-restore.c
\r
298 index b0a4e1c..b5c5c48 100644
\r
299 --- a/notmuch-restore.c
\r
300 +++ b/notmuch-restore.c
\r
301 @@ -41,6 +41,8 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])
\r
302 if (notmuch == NULL)
\r
305 + notmuch_database_set_maildir_sync (notmuch,
\r
306 + notmuch_config_get_maildir_sync (config));
\r
308 input = fopen (argv[0], "r");
\r
309 if (input == NULL) {
\r
310 diff --git a/notmuch-setup.c b/notmuch-setup.c
\r
311 index c3ea937..36ce71f 100644
\r
312 --- a/notmuch-setup.c
\r
313 +++ b/notmuch-setup.c
\r
314 @@ -195,6 +195,16 @@ notmuch_setup_command (unused (void *ctx),
\r
315 g_ptr_array_free (tags, TRUE);
\r
318 + prompt ("Synchronize maildir flags with notmuch tags? %s: ",
\r
319 + notmuch_config_get_maildir_sync (config) == TRUE ? "[yes]/no" : "[no]/yes");
\r
320 + if (strlen (response) > 0) {
\r
321 + if (strcasecmp (response, "yes") == 0||
\r
322 + strcasecmp (response, "y") == 0)
\r
323 + notmuch_config_set_maildir_sync (config, TRUE);
\r
325 + notmuch_config_set_maildir_sync (config, FALSE);
\r
328 if (! notmuch_config_save (config)) {
\r
330 welcome_message_post_setup ();
\r
331 diff --git a/notmuch-tag.c b/notmuch-tag.c
\r
332 index fd54bc7..3a489a9 100644
\r
333 --- a/notmuch-tag.c
\r
334 +++ b/notmuch-tag.c
\r
335 @@ -100,6 +100,8 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))
\r
336 NOTMUCH_DATABASE_MODE_READ_WRITE);
\r
337 if (notmuch == NULL)
\r
339 + notmuch_database_set_maildir_sync (notmuch,
\r
340 + notmuch_config_get_maildir_sync (config));
\r
342 query = notmuch_query_create (notmuch, query_string);
\r
343 if (query == NULL) {
\r