<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

Hi,

> What about another automatic tag to re-add to an existing mail when notmuch new detect a moved, renamed or reflagged message …

the following code sample seems to actually do the job …

Best regards,


~^v^~ Baptiste

<hr /> <pre style="color: #E6E1DC; background-color: #232323; padding: 0.5em;" class="example"> 5aa6f240a34d28ff3a8f768e399ec3c483961cb2 HEAD renew Author: Baptiste Fouques <bateast@bat.fr.eu.org> Date: Wed Mar 4 15:16:20 2015 +0100 Add /renew/ tags to moved or reflagged messages (message that are added or removed and have database dupplicated id) 5 files changed, 74 insertions(+), 1 deletion(-) doc/man1/notmuch-config.rst | 6 ++++++ notmuch-client.h | 8 ++++++++ notmuch-config.c | 25 +++++++++++++++++++++++++ notmuch-new.c | 21 ++++++++++++++++++++- notmuch-setup.c | 15 +++++++++++++++ Modified doc/man1/notmuch-config.rst diff --git a/doc/man1/notmuch-config.rst b/doc/man1/notmuch-config.rst index 2676a86..6e58d1e 100644 --- a/doc/man1/notmuch-config.rst +++ b/doc/man1/notmuch-config.rst @@ -74,6 +74,12 @@ The available configuration items are described below. Default: ``unread;inbox``. + **renew.tags** + A list of tags that will be added to all moved or re-flagged messages + by **notmuch new**. + + Default: empty list. + **new.ignore** A list of file and directory names, without path, that will not be searched for messages by **notmuch new**. All the files and Modified notmuch-client.h diff --git a/notmuch-client.h b/notmuch-client.h index 5e0d475..3bf7f7b 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -309,6 +309,14 @@ notmuch_config_set_new_tags (notmuch_config_t *config, size_t length); const char ** +notmuch_config_get_re_new_tags (notmuch_config_t *config, + size_t *length); +void +notmuch_config_set_re_new_tags (notmuch_config_t *config, + const char *new_tags[], + size_t length); + +const char ** notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length); Modified notmuch-config.c diff --git a/notmuch-config.c b/notmuch-config.c index a564bca..f7f787e 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -113,6 +113,8 @@ struct _notmuch_config { size_t user_other_email_length; const char **new_tags; size_t new_tags_length; + const char **re_new_tags; + size_t re_new_tags_length; const char **new_ignore; size_t new_ignore_length; notmuch_bool_t maildir_synchronize_flags; @@ -272,6 +274,8 @@ notmuch_config_open (void *ctx, config->user_other_email_length = 0; config->new_tags = NULL; config->new_tags_length = 0; + config->re_new_tags = NULL; + config->re_new_tags_length = 0; config->new_ignore = NULL; config->new_ignore_length = 0; config->maildir_synchronize_flags = TRUE; @@ -384,6 +388,10 @@ notmuch_config_open (void *ctx, notmuch_config_set_new_tags (config, tags, 2); } + if (notmuch_config_get_re_new_tags (config, &tmp) = NULL) { + notmuch_config_set_re_new_tags (config, NULL, 0); + } + if (notmuch_config_get_new_ignore (config, &tmp) = NULL) { notmuch_config_set_new_ignore (config, NULL, 0); } @@ -639,6 +647,14 @@ notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length) } const char ** +notmuch_config_get_re_new_tags (notmuch_config_t *config, size_t *length) +{ + return _config_get_list (config, "renew", "tags", + &(config->re_new_tags), + &(config->re_new_tags_length), length); +} + +const char ** notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length) { return _config_get_list (config, "new", "ignore", @@ -665,6 +681,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config, } void +notmuch_config_set_re_new_tags (notmuch_config_t *config, + const char *list[], + size_t length) +{ + _config_set_list (config, "renew", "tags", list, length, + &(config->re_new_tags)); +} + +void notmuch_config_set_new_ignore (notmuch_config_t *config, const char *list[], size_t length) Modified notmuch-new.c diff --git a/notmuch-new.c b/notmuch-new.c index ddf42c1..1dc7b07 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -47,6 +47,8 @@ typedef struct { notmuch_bool_t debug; const char **new_tags; size_t new_tags_length; + const char **re_new_tags; + size_t re_new_tags_length; const char **new_ignore; size_t new_ignore_length; @@ -274,6 +276,8 @@ add_file (notmuch_database_t *notmuch, const char *filename, break; /* Non-fatal issues (go on to next file). */ case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: + for (tag = state->re_new_tags; *tag != NULL; tag++) + notmuch_message_add_tag (message, *tag); if (state->synchronize_flags) notmuch_message_maildir_flags_to_tags (message); break; @@ -799,6 +803,7 @@ remove_filename (notmuch_database_t *notmuch, add_files_state_t *add_files_state) { notmuch_status_t status; + const char **tag; notmuch_message_t *message; status = notmuch_database_begin_atomic (notmuch); if (status) @@ -810,7 +815,9 @@ remove_filename (notmuch_database_t *notmuch, status = notmuch_database_remove_message (notmuch, path); if (status = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) { add_files_state->renamed_messages++; - if (add_files_state->synchronize_flags = TRUE) + for (tag = add_files_state->re_new_tags; *tag != NULL; tag++) + notmuch_message_add_tag (message, *tag); + if (add_files_state->synchronize_flags = TRUE) notmuch_message_maildir_flags_to_tags (message); status = NOTMUCH_STATUS_SUCCESS; } else if (status = NOTMUCH_STATUS_SUCCESS) { @@ -948,6 +955,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.re_new_tags = notmuch_config_get_re_new_tags (config, &add_files_state.re_new_tags_length); add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length); add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config); db_path = notmuch_config_get_database_path (config); @@ -962,6 +970,17 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) return EXIT_FAILURE; } } + for (i = 0; i < add_files_state.re_new_tags_length; i++) { + const char *error_msg; + + error_msg = illegal_tag (add_files_state.re_new_tags[i], FALSE); + if (error_msg) { + fprintf (stderr, "Error: tag '%s' in re_new.tags: %s\n", + add_files_state.re_new_tags[i], error_msg); + return EXIT_FAILURE; + } + } + if (!no_hooks) { ret = notmuch_run_hook (db_path, "pre-new"); Modified notmuch-setup.c diff --git a/notmuch-setup.c b/notmuch-setup.c index 36a6171..c00516b 100644 --- a/notmuch-setup.c +++ b/notmuch-setup.c @@ -131,6 +131,8 @@ notmuch_setup_command (notmuch_config_t *config, unsigned int i; const char **new_tags; size_t new_tags_len; + const char **re_new_tags; + size_t re_new_tags_len; const char **search_exclude_tags; size_t search_exclude_tags_len; @@ -192,6 +194,7 @@ notmuch_setup_command (notmuch_config_t *config, } new_tags = notmuch_config_get_new_tags (config, &new_tags_len); + re_new_tags = notmuch_config_get_re_new_tags (config, &re_new_tags_len); printf ("Tags to apply to all new messages (separated by spaces) ["); print_tag_list (new_tags, new_tags_len); @@ -206,6 +209,18 @@ notmuch_setup_command (notmuch_config_t *config, g_ptr_array_free (tags, TRUE); } + printf ("Tags to apply to all moved or reflagged messages (separated by spaces) ["); + print_tag_list (re_new_tags, re_new_tags_len); + prompt ("]: "); + + if (strlen (response)) { + GPtrArray *tags = parse_tag_list (config, response); + + notmuch_config_set_re_new_tags (config, (const char **) tags->pdata, + tags->len); + + g_ptr_array_free (tags, TRUE); + } search_exclude_tags = notmuch_config_get_search_exclude_tags (config, &search_exclude_tags_len); </pre>