From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id CC5D76DE023A for ; Fri, 6 Jul 2018 07:09:12 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WN1u5yHcG7ea for ; Fri, 6 Jul 2018 07:09:11 -0700 (PDT) X-Greylist: delayed 306 seconds by postgrey-1.36 at arlo; Fri, 06 Jul 2018 07:09:11 PDT Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.135]) by arlo.cworth.org (Postfix) with ESMTPS id 2F0FA6DE021C for ; Fri, 6 Jul 2018 07:09:10 -0700 (PDT) Received: from localhost ([130.75.46.4]) by mrelayeu.kundenserver.de (mreue001 [212.227.15.167]) with ESMTPSA (Nemesis) id 0LkGC3-1g7l1P25pj-00cNua; Fri, 06 Jul 2018 16:04:00 +0200 From: Michael J Gruber To: notmuch@notmuchmail.org Subject: [PATCH] introduce new.rename_tags for renamed (moved) messages Date: Fri, 6 Jul 2018 16:04:00 +0200 Message-Id: X-Mailer: git-send-email 2.18.0.226.g7b49cad896 X-Provags-ID: V03:K1:RNqIDOgP+CIzvI9liq/NkmlA3IvEsZVjnFu4ZCjZgwzBfnI8LQF jfno/Va3Trmz74IMa2+VfaYzsqVDvivZm2jwZLJtZLDHuKknAi5PCZggeqO/elFuVVnZp8e 6jcXzRJb+zQpTnAOB6vZtX7BcMH77IkHO0cq2pvvkNr88mPHdWghYhe8N9BLSvtchQY8i6K BmUm7UxMueF/opBErMM4g== X-UI-Out-Filterresults: notjunk:1;V01:K0:4OM718Idqlw=:hWSO5MNWmuHXdv+CDHsreD Kug9RMbHVXLwfXijQk+ayKnN3JknQZ/ijrOH3doBG68GpbknRbTQevmnmCmceLwFzNV3KYhJS u9BXokypBIw8O5uqH4zQ3ylwgL0hBF4H9M8Vm7mlBeamCXFg4ksB3nNxdGD9urb8DhBtgK5sI vRs2aD/YIflmxLBxjprcx7oRwR5tZntUgonkU+v0P+GLpawVjwhC05ogtkalaIvVQvgFTV1PL GAsIcEYNJiUugsbPCeTrjb9HShlbPjdsXL0jHDXdZywwn8Wk0RarDMCTq9F80criiWObCELHJ kLsN5MyugacwXOZgAVUmchS2m8oDvZXA6FSdL1Zt8KvvTly97xpLHJJ9YvqE7G3igWg8fr04q KAxgaUVKafcUC+y9Ja7GynbxVcMTB5n7KCZbfhQ6Pws9oU32FkUjMy8VZY/dhGgqaACBCKI70 Oe2L/HZzTDTAEquiP6yUmEP0zxAWzzXfE+YW4nuQOz4S/OP4ZShpcrb7IdN9cRAGKlpmkROca Phex7eiERRvAf7PmJ1yqI0S+zrEMcf0Kxjv9nW2hKTJf/i2diIK/16e1n+KLJYcVA8yj6LshL ZCG1/tXmYU3sXbGPLSyUltrB8heBCPGFzu6hMrAGJcNN9uZse7tuj5n3gwzz2hTVE9TrDqMEU q7esSaBl4ibxiwxly2O5mhiXyS95VYSxgU5KHAL0wZahtz0ekKlswsffKRTAgoj6lFhY= X-Mailman-Approved-At: Sun, 08 Jul 2018 11:46:48 -0700 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.26 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: Fri, 06 Jul 2018 14:09:12 -0000 IMAP clients (such as webmail) use folders to mark messages as junk etc., some even to mark messages as trash ("move to trash"). Such a change is reported by notmuch as a rename; the message is not tagged with new.tags since it is not new, so that there is no way to act upon a rename. Introduce new.rename_tags (default: not set) which are added by `notmuch new` to renamed messages. This allows to act upon renames, e.g. to keep the IMAP folder structure in sync with tags with a tool like `afew` or homecooked scripts simply by filtering for this tag in the same ways as one would filter for new messages using new.tags. Signed-off-by: Michael J Gruber --- NEWS | 11 +++++++++++ doc/man1/notmuch-config.rst | 6 ++++++ notmuch-client.h | 8 ++++++++ notmuch-config.c | 26 ++++++++++++++++++++++++++ notmuch-new.c | 23 +++++++++++++++++++++++ 5 files changed, 74 insertions(+) diff --git a/NEWS b/NEWS index 240d594b..e3b75e74 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,14 @@ +Notmuch 0.28 (UNRELEASED) +========================= + +New command-line features +------------------------- + +User-configurable tags for renamed messages + + A new "new.rename_tags" option is available in the configuration file to + determine which tags are applied to renamed (moved) messages. + Notmuch 0.27 (2018-06-13) ========================= diff --git a/doc/man1/notmuch-config.rst b/doc/man1/notmuch-config.rst index 89909808..9e4198a1 100644 --- a/doc/man1/notmuch-config.rst +++ b/doc/man1/notmuch-config.rst @@ -77,6 +77,12 @@ The available configuration items are described below. Default: ``unread;inbox``. +**new.rename_tags** + A list of tags that will be added to all messages which + **notmuch new** identifies as renamed (moved). + + Default: not set. + **new.ignore** A list to specify files and directories that will not be searched for messages by **notmuch new**. Each entry in the list is either: diff --git a/notmuch-client.h b/notmuch-client.h index 6c84ecc0..5e1e6b66 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -316,6 +316,14 @@ notmuch_config_set_new_tags (notmuch_config_t *config, const char *new_tags[], size_t length); +const char ** +notmuch_config_get_rename_tags (notmuch_config_t *config, + size_t *length); +void +notmuch_config_set_rename_tags (notmuch_config_t *config, + const char *rename_tags[], + size_t length); + const char ** notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length); diff --git a/notmuch-config.c b/notmuch-config.c index e1b16609..02f7d247 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -132,6 +132,8 @@ struct _notmuch_config { size_t user_other_email_length; const char **new_tags; size_t new_tags_length; + const char **rename_tags; + size_t rename_tags_length; const char **new_ignore; size_t new_ignore_length; bool maildir_synchronize_flags; @@ -712,6 +714,14 @@ notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length) &(config->new_tags_length), length); } +const char ** +notmuch_config_get_rename_tags (notmuch_config_t *config, size_t *length) +{ + return _config_get_list (config, "new", "rename_tags", + &(config->rename_tags), + &(config->rename_tags_length), length); +} + const char ** notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length) { @@ -738,6 +748,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config, &(config->new_tags)); } +void +notmuch_config_set_rename_tags (notmuch_config_t *config, + const char *list[], + size_t length) +{ + _config_set_list (config, "new", "rename_tags", list, length, + &(config->rename_tags)); +} + void notmuch_config_set_new_ignore (notmuch_config_t *config, const char *list[], @@ -867,6 +886,13 @@ notmuch_config_command_get (notmuch_config_t *config, char *item) tags = notmuch_config_get_new_tags (config, &length); for (i = 0; i < length; i++) printf ("%s\n", tags[i]); + } else if (strcmp(item, "new.rename_tags") == 0) { + const char **tags; + size_t i, length; + + tags = notmuch_config_get_rename_tags (config, &length); + for (i = 0; i < length; i++) + printf ("%s\n", tags[i]); } else if (STRNCMP_LITERAL (item, BUILT_WITH_PREFIX) == 0) { printf ("%s\n", notmuch_built_with (item + strlen (BUILT_WITH_PREFIX)) ? "true" : "false"); diff --git a/notmuch-new.c b/notmuch-new.c index 6a54a1a1..e6d3dc82 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -50,6 +50,8 @@ typedef struct { bool full_scan; const char **new_tags; size_t new_tags_length; + const char **rename_tags; + size_t rename_tags_length; const char **ignore_verbatim; size_t ignore_verbatim_length; regex_t *ignore_regex; @@ -948,9 +950,18 @@ remove_filename (notmuch_database_t *notmuch, status = notmuch_database_remove_message (notmuch, path); if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) { + const char **tag; add_files_state->renamed_messages++; + notmuch_message_freeze (message); + + for (tag = add_files_state->rename_tags; tag != NULL && *tag != NULL; tag++) { + notmuch_message_add_tag (message, *tag); + } + + if (add_files_state->synchronize_flags == true) notmuch_message_maildir_flags_to_tags (message); + notmuch_message_thaw (message); status = NOTMUCH_STATUS_SUCCESS; } else if (status == NOTMUCH_STATUS_SUCCESS) { add_files_state->removed_messages++; @@ -1095,6 +1106,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) add_files_state.verbosity = VERBOSITY_VERBOSE; add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length); + add_files_state.rename_tags = notmuch_config_get_rename_tags (config, &add_files_state.rename_tags_length); add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config); db_path = notmuch_config_get_database_path (config); add_files_state.db_path = db_path; @@ -1113,6 +1125,17 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) } } + for (i = 0; i < add_files_state.rename_tags_length; i++) { + const char *error_msg; + + error_msg = illegal_tag (add_files_state.rename_tags[i], false); + if (error_msg) { + fprintf (stderr, "Error: tag '%s' in rename.tags: %s\n", + add_files_state.rename_tags[i], error_msg); + return EXIT_FAILURE; + } + } + if (hooks) { ret = notmuch_run_hook (db_path, "pre-new"); if (ret) -- 2.18.0.226.g7b49cad896