unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 1/2] lib: Add back the synchronization of 'T' flag with deleted tag.
@ 2011-07-17  3:56 Antoine Beaupré
  2011-07-17  3:56 ` [PATCH 2/2] lib: add 'safe' setting for flags Antoine Beaupré
  2012-01-06 22:37 ` [PATCH 1/2] lib: Add back the synchronization of 'T' flag with deleted tag Jani Nikula
  0 siblings, 2 replies; 5+ messages in thread
From: Antoine Beaupré @ 2011-07-17  3:56 UTC (permalink / raw)
  To: notmuch; +Cc: Antoine Beaupré

This adds a special configuration, off by default, that allows notmuch
to synchronize the T flag again. The configuration is named
maildir_reckless_trash and quite clearly indicates that it could be
dangerous to use in the context described in commit 2c26204, which I
could actually reproduce.

In contexts where notmuch is the only mail client used, this is actually
safe to use. Besides, (T)rashed messages are not necessarily immediately
expunged from the Maildir by the client or the IMAP server.

Signed-off-by: Antoine Beaupré <anarcat@koumbit.org>
---
 lib/message.cc   |   14 +++++++++++++-
 lib/notmuch.h    |    4 ++++
 notmuch-client.h |    7 +++++++
 notmuch-config.c |   50 +++++++++++++++++++++++++++++++++++++++++++++++---
 4 files changed, 71 insertions(+), 4 deletions(-)

diff --git a/lib/message.cc b/lib/message.cc
index d993cde..f633887 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -58,7 +58,8 @@ static struct maildir_flag_tag flag2tag[] = {
     { 'F', "flagged", false},
     { 'P', "passed",  false},
     { 'R', "replied", false},
-    { 'S', "unread",  true }
+    { 'S', "unread",  true },
+    { 'T', "deleted", false},
 };
 
 /* We end up having to call the destructor explicitly because we had
@@ -993,6 +994,7 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)
     char *combined_flags = talloc_strdup (message, "");
     unsigned i;
     int seen_maildir_info = 0;
+    notmuch_bool_t reckless_trash;
 
     for (filenames = notmuch_message_get_filenames (message);
 	 notmuch_filenames_valid (filenames);
@@ -1020,7 +1022,17 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)
     if (status)
 	return status;
 
+    // TODO: this should probably be moved up in the stack to avoid
+    // opening the config file on every message (!)
+    config = notmuch_config_open (ctx, NULL, NULL);
+    if (config == NULL)
+	return 1;
+    reckless_trash = notmuch_config_get_maildir_reckless_trash (config);
+
     for (i = 0; i < ARRAY_SIZE(flag2tag); i++) {
+	if (flag2tag[i].flag == 'T' && !reckless_trash) {
+	    continue;
+	}
 	if ((strchr (combined_flags, flag2tag[i].flag) != NULL)
 	    ^ 
 	    flag2tag[i].inverse)
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 974be8d..f0c1b67 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -922,6 +922,8 @@ notmuch_message_remove_all_tags (notmuch_message_t *message);
  *	'P'	Adds the "passed" tag to the message
  *	'R'	Adds the "replied" tag to the message
  *	'S'	Removes the "unread" tag from the message
+ * 	'T'	Adds the "deleted" tag to the message and
+ *		state->reckless_trash is TRUE.
  *
  * For each flag that is not present, the opposite action (add/remove)
  * is performed for the corresponding tags.
@@ -962,6 +964,8 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message);
  *   'P' iff the message has the "passed" tag
  *   'R' iff the message has the "replied" tag
  *   'S' iff the message does not have the "unread" tag
+ *   'T' iff the message has the "trashed" tag and
+ *   state->reckless_trash is TRUE.
  *
  * Any existing flags unmentioned in the list above will be preserved
  * in the renaming.
diff --git a/notmuch-client.h b/notmuch-client.h
index 63be337..62d1e0e 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -235,6 +235,13 @@ notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,
 					      notmuch_bool_t synchronize_flags);
 
 notmuch_bool_t
+notmuch_config_get_maildir_reckless_trash (notmuch_config_t *config);
+
+void
+notmuch_config_set_maildir_reckless_trash (notmuch_config_t *config,
+					   notmuch_bool_t reckless_trash);
+
+notmuch_bool_t
 debugger_is_active (void);
 
 #endif
diff --git a/notmuch-config.c b/notmuch-config.c
index 485fa72..613fefc 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -67,9 +67,11 @@ static const char maildir_config_comment[] =
     " The following option is supported here:\n"
     "\n"
     "\tsynchronize_flags      Valid values are true and false.\n"
+    "\treckless_trash         Valid values are true and false.\n"
     "\n"
-    "\tIf true, then the following maildir flags (in message filenames)\n"
-    "\twill be synchronized with the corresponding notmuch tags:\n"
+    "\tIf synchronize_flags is true, then the following maildir flags\n"
+    "\t(in message filenames) will be synchronized with the corresponding\n"
+    "\tnotmuch tags:\n"
     "\n"
     "\t\tFlag	Tag\n"
     "\t\t----	-------\n"
@@ -78,10 +80,26 @@ static const char maildir_config_comment[] =
     "\t\tP	passed\n"
     "\t\tR	replied\n"
     "\t\tS	unread (added when 'S' flag is not present)\n"
+    "\t\tT	trashed (only if maildir_reckless_trash is enabled)\n"
     "\n"
     "\tThe \"notmuch new\" command will notice flag changes in filenames\n"
     "\tand update tags, while the \"notmuch tag\" and \"notmuch restore\"\n"
-    "\tcommands will notice tag changes and update flags in filenames\n";
+    "\tcommands will notice tag changes and update flags in filenames\n"
+    "\n"
+    "\tBy default the maildir synchronization code doesn't look at the\n"
+    "\t'trashed' (T) flag on messages. The reason for this behaviour is\n"
+    "\tit can be dangerous if another mail client is trying to delete\n"
+    "\tduplicates of a message with the same message ID.\n"
+    "\n"
+    "\tA workaround for this issue is to expunge the duplicate messages\n"
+    "\twith the other client before running notmuch new.\n"
+    "\n"
+    "\tIf you are using only notmuch to handle your emails or are never\n"
+    "\tdoing such operations, enabling reckless_trash should be safe,\n"
+    "\tbut otherwise it is safer to keep this disabled and delete mails\n"
+    "\tmanually with a shell command like:\n"
+    "\n"
+    "\tnotmuch search --format=files tag:deleted | xargs rm\n";
 
 struct _notmuch_config {
     char *filename;
@@ -95,6 +113,7 @@ struct _notmuch_config {
     const char **new_tags;
     size_t new_tags_length;
     notmuch_bool_t maildir_synchronize_flags;
+    notmuch_bool_t maildir_reckless_trash;
 };
 
 static int
@@ -251,6 +270,7 @@ notmuch_config_open (void *ctx,
     config->new_tags = NULL;
     config->new_tags_length = 0;
     config->maildir_synchronize_flags = TRUE;
+    config->maildir_reckless_trash = FALSE;
 
     if (! g_key_file_load_from_file (config->key_file,
 				     config->filename,
@@ -353,6 +373,15 @@ notmuch_config_open (void *ctx,
 	g_error_free (error);
     }
 
+    error = NULL;
+    config->maildir_reckless_trash =
+	g_key_file_get_boolean (config->key_file,
+				"maildir", "reckless_trash", &error);
+    if (error) {
+	notmuch_config_set_maildir_reckless_trash (config, FALSE);
+	g_error_free (error);
+    }
+
     /* Whenever we know of configuration sections that don't appear in
      * the configuration file, we add some comments to help the user
      * understand what can be done. */
@@ -764,3 +793,18 @@ notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,
 			    "maildir", "synchronize_flags", synchronize_flags);
     config->maildir_synchronize_flags = synchronize_flags;
 }
+
+notmuch_bool_t
+notmuch_config_get_maildir_reckless_trash (notmuch_config_t *config)
+{
+    return config->maildir_reckless_trash;
+}
+
+void
+notmuch_config_set_maildir_reckless_trash (notmuch_config_t *config,
+					   notmuch_bool_t reckless_trash)
+{
+    g_key_file_set_boolean (config->key_file,
+			    "maildir", "reckless_trash", reckless_trash);
+    config->maildir_reckless_trash = reckless_trash;
+}
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-01-17  5:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-17  3:56 [PATCH 1/2] lib: Add back the synchronization of 'T' flag with deleted tag Antoine Beaupré
2011-07-17  3:56 ` [PATCH 2/2] lib: add 'safe' setting for flags Antoine Beaupré
2012-01-06 22:45   ` Jani Nikula
2012-01-06 22:37 ` [PATCH 1/2] lib: Add back the synchronization of 'T' flag with deleted tag Jani Nikula
2012-01-17  5:12   ` Antoine Beaupré

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).