--- /dev/null
+Return-Path: <anarcat@angela.anarcat.ath.cx>\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 028C9431FD0\r
+ for <notmuch@notmuchmail.org>; Sat, 16 Jul 2011 20:56:25 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ autolearn=disabled\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 dK-4lcfR21AJ for <notmuch@notmuchmail.org>;\r
+ Sat, 16 Jul 2011 20:56:24 -0700 (PDT)\r
+Received: from bureau.koumbit.net (homere.koumbit.net [209.44.112.81])\r
+ (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id A0948431FB6\r
+ for <notmuch@notmuchmail.org>; Sat, 16 Jul 2011 20:56:24 -0700 (PDT)\r
+Received: from localhost (H144.C72.B0.tor.eicat.ca [72.0.72.144])\r
+ (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by bureau.koumbit.net (Postfix) with ESMTPSA id A51F1E80EF7;\r
+ Sat, 16 Jul 2011 23:56:23 -0400 (EDT)\r
+Received: by localhost (Postfix, from userid 1000)\r
+ id 6E4006305; Sat, 16 Jul 2011 23:56:25 -0400 (EDT)\r
+From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= <anarcat@koumbit.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/2] lib: Add back the synchronization of 'T' flag with\r
+ deleted tag.\r
+Date: Sat, 16 Jul 2011 23:56:12 -0400\r
+Message-Id: <1310874973-28437-1-git-send-email-anarcat@koumbit.org>\r
+X-Mailer: git-send-email 1.7.2.5\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=UTF-8\r
+Content-Transfer-Encoding: 8bit\r
+Cc: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= <anarcat@koumbit.org>\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, 17 Jul 2011 03:56:26 -0000\r
+\r
+This adds a special configuration, off by default, that allows notmuch\r
+to synchronize the T flag again. The configuration is named\r
+maildir_reckless_trash and quite clearly indicates that it could be\r
+dangerous to use in the context described in commit 2c26204, which I\r
+could actually reproduce.\r
+\r
+In contexts where notmuch is the only mail client used, this is actually\r
+safe to use. Besides, (T)rashed messages are not necessarily immediately\r
+expunged from the Maildir by the client or the IMAP server.\r
+\r
+Signed-off-by: Antoine Beaupré <anarcat@koumbit.org>\r
+---\r
+ lib/message.cc | 14 +++++++++++++-\r
+ lib/notmuch.h | 4 ++++\r
+ notmuch-client.h | 7 +++++++\r
+ notmuch-config.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++---\r
+ 4 files changed, 71 insertions(+), 4 deletions(-)\r
+\r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index d993cde..f633887 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -58,7 +58,8 @@ static struct maildir_flag_tag flag2tag[] = {\r
+ { 'F', "flagged", false},\r
+ { 'P', "passed", false},\r
+ { 'R', "replied", false},\r
+- { 'S', "unread", true }\r
++ { 'S', "unread", true },\r
++ { 'T', "deleted", false},\r
+ };\r
+ \r
+ /* We end up having to call the destructor explicitly because we had\r
+@@ -993,6 +994,7 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)\r
+ char *combined_flags = talloc_strdup (message, "");\r
+ unsigned i;\r
+ int seen_maildir_info = 0;\r
++ notmuch_bool_t reckless_trash;\r
+ \r
+ for (filenames = notmuch_message_get_filenames (message);\r
+ notmuch_filenames_valid (filenames);\r
+@@ -1020,7 +1022,17 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)\r
+ if (status)\r
+ return status;\r
+ \r
++ // TODO: this should probably be moved up in the stack to avoid\r
++ // opening the config file on every message (!)\r
++ config = notmuch_config_open (ctx, NULL, NULL);\r
++ if (config == NULL)\r
++ return 1;\r
++ reckless_trash = notmuch_config_get_maildir_reckless_trash (config);\r
++\r
+ for (i = 0; i < ARRAY_SIZE(flag2tag); i++) {\r
++ if (flag2tag[i].flag == 'T' && !reckless_trash) {\r
++ continue;\r
++ }\r
+ if ((strchr (combined_flags, flag2tag[i].flag) != NULL)\r
+ ^ \r
+ flag2tag[i].inverse)\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 974be8d..f0c1b67 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -922,6 +922,8 @@ notmuch_message_remove_all_tags (notmuch_message_t *message);\r
+ * 'P' Adds the "passed" tag to the message\r
+ * 'R' Adds the "replied" tag to the message\r
+ * 'S' Removes the "unread" tag from the message\r
++ * 'T' Adds the "deleted" tag to the message and\r
++ * state->reckless_trash is TRUE.\r
+ *\r
+ * For each flag that is not present, the opposite action (add/remove)\r
+ * is performed for the corresponding tags.\r
+@@ -962,6 +964,8 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message);\r
+ * 'P' iff the message has the "passed" tag\r
+ * 'R' iff the message has the "replied" tag\r
+ * 'S' iff the message does not have the "unread" tag\r
++ * 'T' iff the message has the "trashed" tag and\r
++ * state->reckless_trash is TRUE.\r
+ *\r
+ * Any existing flags unmentioned in the list above will be preserved\r
+ * in the renaming.\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index 63be337..62d1e0e 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -235,6 +235,13 @@ notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,\r
+ notmuch_bool_t synchronize_flags);\r
+ \r
+ notmuch_bool_t\r
++notmuch_config_get_maildir_reckless_trash (notmuch_config_t *config);\r
++\r
++void\r
++notmuch_config_set_maildir_reckless_trash (notmuch_config_t *config,\r
++ notmuch_bool_t reckless_trash);\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 485fa72..613fefc 100644\r
+--- a/notmuch-config.c\r
++++ b/notmuch-config.c\r
+@@ -67,9 +67,11 @@ static const char maildir_config_comment[] =\r
+ " The following option is supported here:\n"\r
+ "\n"\r
+ "\tsynchronize_flags Valid values are true and false.\n"\r
++ "\treckless_trash Valid values are true and false.\n"\r
+ "\n"\r
+- "\tIf true, then the following maildir flags (in message filenames)\n"\r
+- "\twill be synchronized with the corresponding notmuch tags:\n"\r
++ "\tIf synchronize_flags is true, then the following maildir flags\n"\r
++ "\t(in message filenames) will be synchronized with the corresponding\n"\r
++ "\tnotmuch tags:\n"\r
+ "\n"\r
+ "\t\tFlag Tag\n"\r
+ "\t\t---- -------\n"\r
+@@ -78,10 +80,26 @@ static const char maildir_config_comment[] =\r
+ "\t\tP passed\n"\r
+ "\t\tR replied\n"\r
+ "\t\tS unread (added when 'S' flag is not present)\n"\r
++ "\t\tT trashed (only if maildir_reckless_trash is enabled)\n"\r
+ "\n"\r
+ "\tThe \"notmuch new\" command will notice flag changes in filenames\n"\r
+ "\tand update tags, while the \"notmuch tag\" and \"notmuch restore\"\n"\r
+- "\tcommands will notice tag changes and update flags in filenames\n";\r
++ "\tcommands will notice tag changes and update flags in filenames\n"\r
++ "\n"\r
++ "\tBy default the maildir synchronization code doesn't look at the\n"\r
++ "\t'trashed' (T) flag on messages. The reason for this behaviour is\n"\r
++ "\tit can be dangerous if another mail client is trying to delete\n"\r
++ "\tduplicates of a message with the same message ID.\n"\r
++ "\n"\r
++ "\tA workaround for this issue is to expunge the duplicate messages\n"\r
++ "\twith the other client before running notmuch new.\n"\r
++ "\n"\r
++ "\tIf you are using only notmuch to handle your emails or are never\n"\r
++ "\tdoing such operations, enabling reckless_trash should be safe,\n"\r
++ "\tbut otherwise it is safer to keep this disabled and delete mails\n"\r
++ "\tmanually with a shell command like:\n"\r
++ "\n"\r
++ "\tnotmuch search --format=files tag:deleted | xargs rm\n";\r
+ \r
+ struct _notmuch_config {\r
+ char *filename;\r
+@@ -95,6 +113,7 @@ struct _notmuch_config {\r
+ const char **new_tags;\r
+ size_t new_tags_length;\r
+ notmuch_bool_t maildir_synchronize_flags;\r
++ notmuch_bool_t maildir_reckless_trash;\r
+ };\r
+ \r
+ static int\r
+@@ -251,6 +270,7 @@ notmuch_config_open (void *ctx,\r
+ config->new_tags = NULL;\r
+ config->new_tags_length = 0;\r
+ config->maildir_synchronize_flags = TRUE;\r
++ config->maildir_reckless_trash = FALSE;\r
+ \r
+ if (! g_key_file_load_from_file (config->key_file,\r
+ config->filename,\r
+@@ -353,6 +373,15 @@ notmuch_config_open (void *ctx,\r
+ g_error_free (error);\r
+ }\r
+ \r
++ error = NULL;\r
++ config->maildir_reckless_trash =\r
++ g_key_file_get_boolean (config->key_file,\r
++ "maildir", "reckless_trash", &error);\r
++ if (error) {\r
++ notmuch_config_set_maildir_reckless_trash (config, FALSE);\r
++ g_error_free (error);\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
+@@ -764,3 +793,18 @@ notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,\r
+ "maildir", "synchronize_flags", synchronize_flags);\r
+ config->maildir_synchronize_flags = synchronize_flags;\r
+ }\r
++\r
++notmuch_bool_t\r
++notmuch_config_get_maildir_reckless_trash (notmuch_config_t *config)\r
++{\r
++ return config->maildir_reckless_trash;\r
++}\r
++\r
++void\r
++notmuch_config_set_maildir_reckless_trash (notmuch_config_t *config,\r
++ notmuch_bool_t reckless_trash)\r
++{\r
++ g_key_file_set_boolean (config->key_file,\r
++ "maildir", "reckless_trash", reckless_trash);\r
++ config->maildir_reckless_trash = reckless_trash;\r
++}\r
+-- \r
+1.7.2.5\r
+\r