[PATCH v4 3/4] Make maildir synchronization configurable
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 31 Oct 2010 21:29:17 +0000 (22:29 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:37:20 +0000 (09:37 -0800)
aa/9ccbcd6c7f746c341c3026bc38396159733571 [new file with mode: 0644]

diff --git a/aa/9ccbcd6c7f746c341c3026bc38396159733571 b/aa/9ccbcd6c7f746c341c3026bc38396159733571
new file mode 100644 (file)
index 0000000..977d92b
--- /dev/null
@@ -0,0 +1,346 @@
+Return-Path: <wsh@resox.2x.cz>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 2EE4940D162\r
+       for <notmuch@notmuchmail.org>; Sun, 31 Oct 2010 14:48:49 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.9\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
+       tests=[BAYES_00=-1.9] autolearn=unavailable\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id nwxB5xWgGE5f for <notmuch@notmuchmail.org>;\r
+       Sun, 31 Oct 2010 14:48:34 -0700 (PDT)\r
+Received: from smtp.nextra.cz (smtp.nextra.cz [212.65.193.3])\r
+       by olra.theworths.org (Postfix) with ESMTP id 6CCE040D167\r
+       for <notmuch@notmuchmail.org>; Sun, 31 Oct 2010 14:48:02 -0700 (PDT)\r
+Received: from resox.2x.cz (unknown [213.29.198.144])\r
+       by smtp.nextra.cz (Postfix) with ESMTP id 7D0B788D04;\r
+       Sun, 31 Oct 2010 22:30:26 +0100 (CET)\r
+Received: from wsh by resox.2x.cz with local (Exim 4.72)\r
+       (envelope-from <wsh@resox.2x.cz>)\r
+       id 1PCfTk-0004wo-9I; Sun, 31 Oct 2010 22:30:16 +0100\r
+From: Michal Sojka <sojkam1@fel.cvut.cz>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v4 3/4] Make maildir synchronization configurable\r
+Date: Sun, 31 Oct 2010 22:29:17 +0100\r
+Message-Id: <1288560558-18915-4-git-send-email-sojkam1@fel.cvut.cz>\r
+X-Mailer: git-send-email 1.7.1\r
+In-Reply-To: <87tyk3vpxd.fsf@wsheee.2x.cz>\r
+References: <87tyk3vpxd.fsf@wsheee.2x.cz>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 31 Oct 2010 21:48:49 -0000\r
+\r
+This adds group [maildir] and key 'synchronize_flags' to the\r
+configuration file. Its value enables (true) or diables (false) the\r
+synchronization between notmuch tags and maildir flags. By default,\r
+the synchronization is disabled.\r
+---\r
+ lib/database-private.h |    2 +-\r
+ lib/database.cc        |    9 ++++++++\r
+ lib/message.cc         |    2 +-\r
+ lib/notmuch.h          |    6 +++++\r
+ notmuch-client.h       |    7 ++++++\r
+ notmuch-config.c       |   49 ++++++++++++++++++++++++++++++++++++++++++++++++\r
+ notmuch-new.c          |    8 +++++-\r
+ notmuch-restore.c      |    2 +\r
+ notmuch-setup.c        |   10 +++++++++\r
+ notmuch-tag.c          |    2 +\r
+ 10 files changed, 93 insertions(+), 4 deletions(-)\r
+\r
+diff --git a/lib/database-private.h b/lib/database-private.h\r
+index bd72f67..dd89c63 100644\r
+--- a/lib/database-private.h\r
++++ b/lib/database-private.h\r
+@@ -49,7 +49,7 @@ struct _notmuch_database {\r
+     Xapian::QueryParser *query_parser;\r
+     Xapian::TermGenerator *term_gen;\r
+     Xapian::ValueRangeProcessor *value_range_processor;\r
+-\r
++    notmuch_bool_t maildir_sync;\r
+ };\r
\r
+ /* Convert tags from Xapian internal format to notmuch format.\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 9652013..069918a 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -689,6 +689,8 @@ notmuch_database_open (const char *path,\r
+       notmuch = NULL;\r
+     }\r
\r
++    notmuch_database_set_maildir_sync (notmuch, FALSE);\r
++\r
+   DONE:\r
+     if (notmuch_path)\r
+       free (notmuch_path);\r
+@@ -718,6 +720,13 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
+     talloc_free (notmuch);\r
+ }\r
\r
++void\r
++notmuch_database_set_maildir_sync (notmuch_database_t *database,\r
++                                 notmuch_bool_t maildir_sync)\r
++{\r
++    database->maildir_sync = maildir_sync;\r
++}\r
++\r
+ const char *\r
+ notmuch_database_get_path (notmuch_database_t *notmuch)\r
+ {\r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index bb96242..80bef8e 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -626,7 +626,7 @@ _notmuch_message_sync (notmuch_message_t *message)\r
+     if (message->notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)\r
+       return;\r
\r
+-    if (// todo_sync_enabled &&\r
++    if (message->notmuch->maildir_sync &&\r
+       !notmuch_message_get_flag(message, NOTMUCH_MESSAGE_FLAG_TAGS_INVALID)) {\r
+       status = _notmuch_message_tags_to_maildir (message);\r
+       if (status != NOTMUCH_PRIVATE_STATUS_SUCCESS) {\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index fe01e73..41820b5 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -176,6 +176,12 @@ notmuch_database_open (const char *path,\r
+ void\r
+ notmuch_database_close (notmuch_database_t *database);\r
\r
++/* Sets whether maildir flags should be synchronized with notmuch\r
++ * tags. */\r
++void\r
++notmuch_database_set_maildir_sync (notmuch_database_t *database,\r
++                                 notmuch_bool_t maildir_sync);\r
++\r
+ /* Return the database path of the given database.\r
+  *\r
+  * The return value is a string owned by notmuch so should not be\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index d530578..c27d64f 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -195,6 +195,13 @@ notmuch_config_set_new_tags (notmuch_config_t *config,\r
+                            size_t length);\r
\r
+ notmuch_bool_t\r
++notmuch_config_get_maildir_sync (notmuch_config_t *config);\r
++\r
++void\r
++notmuch_config_set_maildir_sync (notmuch_config_t *config,\r
++                               notmuch_bool_t maildir_sync);\r
++\r
++notmuch_bool_t\r
+ debugger_is_active (void);\r
\r
+ #endif\r
+diff --git a/notmuch-config.c b/notmuch-config.c\r
+index dcdb036..483d5c6 100644\r
+--- a/notmuch-config.c\r
++++ b/notmuch-config.c\r
+@@ -61,6 +61,14 @@ static const char user_config_comment[] =\r
+     " recipient list of replies, and will set the From address based on the\n"\r
+     " address to which the original email was addressed.\n";\r
\r
++static const char maildir_config_comment[] =\r
++    " Maildir compatibility configuration\n"\r
++    "\n"\r
++    " Here you can configure whether notmuch will synchronize its tags with\n"\r
++    " maildir flags."\r
++    "\n"\r
++    "\tsynchronize_flags      Valid values are true and false.\n";\r
++\r
+ struct _notmuch_config {\r
+     char *filename;\r
+     GKeyFile *key_file;\r
+@@ -72,8 +80,11 @@ struct _notmuch_config {\r
+     size_t user_other_email_length;\r
+     const char **new_tags;\r
+     size_t new_tags_length;\r
++    notmuch_bool_t maildir_sync;\r
+ };\r
\r
++#define MAILDIR_SYNC_UNDEF ((notmuch_bool_t)-1)\r
++\r
+ static int\r
+ notmuch_config_destructor (notmuch_config_t *config)\r
+ {\r
+@@ -191,6 +202,7 @@ notmuch_config_open (void *ctx,\r
+     int file_had_database_group;\r
+     int file_had_new_group;\r
+     int file_had_user_group;\r
++    int file_had_maildir_group;\r
\r
+     if (is_new_ret)\r
+       *is_new_ret = 0;\r
+@@ -221,6 +233,7 @@ notmuch_config_open (void *ctx,\r
+     config->user_other_email_length = 0;\r
+     config->new_tags = NULL;\r
+     config->new_tags_length = 0;\r
++    config->maildir_sync = MAILDIR_SYNC_UNDEF;\r
\r
+     if (! g_key_file_load_from_file (config->key_file,\r
+                                    config->filename,\r
+@@ -263,6 +276,7 @@ notmuch_config_open (void *ctx,\r
+                                                   "database");\r
+     file_had_new_group = g_key_file_has_group (config->key_file, "new");\r
+     file_had_user_group = g_key_file_has_group (config->key_file, "user");\r
++    file_had_maildir_group = g_key_file_has_group (config->key_file, "maildir");\r
\r
\r
+     if (notmuch_config_get_database_path (config) == NULL) {\r
+@@ -313,6 +327,10 @@ notmuch_config_open (void *ctx,\r
+       notmuch_config_set_new_tags (config, tags, 2);\r
+     }\r
\r
++    if (notmuch_config_get_maildir_sync (config) == MAILDIR_SYNC_UNDEF) {\r
++      notmuch_config_set_maildir_sync (config, FALSE);\r
++    }\r
++\r
+     /* Whenever we know of configuration sections that don't appear in\r
+      * the configuration file, we add some comments to help the user\r
+      * understand what can be done. */\r
+@@ -340,6 +358,12 @@ notmuch_config_open (void *ctx,\r
+                               user_config_comment, NULL);\r
+     }\r
\r
++    if (! file_had_maildir_group)\r
++    {\r
++      g_key_file_set_comment (config->key_file, "maildir", NULL,\r
++                              maildir_config_comment, NULL);\r
++    }\r
++\r
+     if (is_new_ret)\r
+       *is_new_ret = is_new;\r
\r
+@@ -703,3 +727,28 @@ notmuch_config_command (void *ctx, int argc, char *argv[])\r
+            argv[0]);\r
+     return 1;\r
+ }\r
++\r
++notmuch_bool_t\r
++notmuch_config_get_maildir_sync (notmuch_config_t *config)\r
++{\r
++    GError *err = NULL;\r
++    if (config->maildir_sync == MAILDIR_SYNC_UNDEF) {\r
++      config->maildir_sync =\r
++          g_key_file_get_boolean (config->key_file,\r
++                                  "maildir", "synchronize_flags", &err);\r
++      if (err) {\r
++          config->maildir_sync = MAILDIR_SYNC_UNDEF;\r
++          g_error_free (err);\r
++      }\r
++    }\r
++    return config->maildir_sync;\r
++}\r
++\r
++void\r
++notmuch_config_set_maildir_sync (notmuch_config_t *config,\r
++                               notmuch_bool_t maildir_sync)\r
++{\r
++    g_key_file_set_boolean (config->key_file,\r
++                          "maildir", "synchronize_flags", maildir_sync);\r
++    config->maildir_sync = maildir_sync;\r
++}\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index ed3f944..273916e 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -45,6 +45,7 @@ typedef struct {\r
\r
+     _filename_list_t *removed_files;\r
+     _filename_list_t *removed_directories;\r
++    notmuch_bool_t maildir_sync;\r
+ } add_files_state_t;\r
\r
+ static volatile sig_atomic_t do_add_files_print_progress = 0;\r
+@@ -410,11 +411,13 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+           state->added_messages++;\r
+           for (tag=state->new_tags; *tag != NULL; tag++)\r
+               notmuch_message_add_tag (message, *tag);\r
+-          notmuch_message_maildir_to_tags (message, next);\r
++          if (state->maildir_sync == TRUE)\r
++              notmuch_message_maildir_to_tags (message, next);\r
+           break;\r
+       /* Non-fatal issues (go on to next file) */\r
+       case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:\r
+-          notmuch_message_maildir_to_tags (message, next);\r
++          if (state->maildir_sync == TRUE)\r
++              notmuch_message_maildir_to_tags (message, next);\r
+           break;\r
+       case NOTMUCH_STATUS_FILE_NOT_EMAIL:\r
+           fprintf (stderr, "Note: Ignoring non-mail file: %s\n",\r
+@@ -738,6 +741,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
+       return 1;\r
\r
+     add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);\r
++    add_files_state.maildir_sync = notmuch_config_get_maildir_sync (config);\r
+     db_path = notmuch_config_get_database_path (config);\r
\r
+     dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch");\r
+diff --git a/notmuch-restore.c b/notmuch-restore.c\r
+index b0a4e1c..b5c5c48 100644\r
+--- a/notmuch-restore.c\r
++++ b/notmuch-restore.c\r
+@@ -41,6 +41,8 @@ notmuch_restore_command (unused (void *ctx), int argc, char *argv[])\r
+     if (notmuch == NULL)\r
+       return 1;\r
\r
++    notmuch_database_set_maildir_sync (notmuch,\r
++                                     notmuch_config_get_maildir_sync (config));\r
+     if (argc) {\r
+       input = fopen (argv[0], "r");\r
+       if (input == NULL) {\r
+diff --git a/notmuch-setup.c b/notmuch-setup.c\r
+index c3ea937..36ce71f 100644\r
+--- a/notmuch-setup.c\r
++++ b/notmuch-setup.c\r
+@@ -195,6 +195,16 @@ notmuch_setup_command (unused (void *ctx),\r
+       g_ptr_array_free (tags, TRUE);\r
+     }\r
\r
++    prompt ("Synchronize maildir flags with notmuch tags? %s: ",\r
++          notmuch_config_get_maildir_sync (config) == TRUE ? "[yes]/no" : "[no]/yes");\r
++    if (strlen (response) > 0) {\r
++      if (strcasecmp (response, "yes") == 0||\r
++          strcasecmp (response, "y") == 0)\r
++          notmuch_config_set_maildir_sync (config, TRUE);\r
++      else\r
++          notmuch_config_set_maildir_sync (config, FALSE);\r
++    }\r
++\r
+     if (! notmuch_config_save (config)) {\r
+       if (is_new)\r
+         welcome_message_post_setup ();\r
+diff --git a/notmuch-tag.c b/notmuch-tag.c\r
+index fd54bc7..3a489a9 100644\r
+--- a/notmuch-tag.c\r
++++ b/notmuch-tag.c\r
+@@ -100,6 +100,8 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+                                    NOTMUCH_DATABASE_MODE_READ_WRITE);\r
+     if (notmuch == NULL)\r
+       return 1;\r
++    notmuch_database_set_maildir_sync (notmuch,\r
++                                     notmuch_config_get_maildir_sync (config));\r
\r
+     query = notmuch_query_create (notmuch, query_string);\r
+     if (query == NULL) {\r
+-- \r
+1.7.1\r
+\r