Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 028C9431FD0 for ; Sat, 16 Jul 2011 20:56:25 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dK-4lcfR21AJ for ; Sat, 16 Jul 2011 20:56:24 -0700 (PDT) Received: from bureau.koumbit.net (homere.koumbit.net [209.44.112.81]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id A0948431FB6 for ; Sat, 16 Jul 2011 20:56:24 -0700 (PDT) Received: from localhost (H144.C72.B0.tor.eicat.ca [72.0.72.144]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by bureau.koumbit.net (Postfix) with ESMTPSA id A51F1E80EF7; Sat, 16 Jul 2011 23:56:23 -0400 (EDT) Received: by localhost (Postfix, from userid 1000) id 6E4006305; Sat, 16 Jul 2011 23:56:25 -0400 (EDT) From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= To: notmuch@notmuchmail.org Subject: [PATCH 1/2] lib: Add back the synchronization of 'T' flag with deleted tag. Date: Sat, 16 Jul 2011 23:56:12 -0400 Message-Id: <1310874973-28437-1-git-send-email-anarcat@koumbit.org> X-Mailer: git-send-email 1.7.2.5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Jul 2011 03:56:26 -0000 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é --- 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