From 29d857f1f3a885db92ba87dc1b0d68e28af5db7a Mon Sep 17 00:00:00 2001 From: Baptiste Date: Wed, 4 Mar 2015 15:31:17 +0100 Subject: [PATCH] [PATCH] Re: Add /renew/ tag to moved/renamed/reflagged messages --- 34/3b281f0a24fcffdd6832d25300eae5842b9ef9 | 598 ++++++++++++++++++++++ 1 file changed, 598 insertions(+) create mode 100644 34/3b281f0a24fcffdd6832d25300eae5842b9ef9 diff --git a/34/3b281f0a24fcffdd6832d25300eae5842b9ef9 b/34/3b281f0a24fcffdd6832d25300eae5842b9ef9 new file mode 100644 index 000000000..826f080ea --- /dev/null +++ b/34/3b281f0a24fcffdd6832d25300eae5842b9ef9 @@ -0,0 +1,598 @@ +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 BC3AD431FAF + for ; Wed, 4 Mar 2015 06:32:41 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 2.439 +X-Spam-Level: ** +X-Spam-Status: No, score=2.439 tagged_above=-999 required=5 + tests=[DNS_FROM_AHBL_RHSBL=2.438, HTML_MESSAGE=0.001] + 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 jlZ28vrTL2jq for ; + Wed, 4 Mar 2015 06:32:35 -0800 (PST) +Received: from mx1b.lautre.net (mx1b.lautre.net [80.67.160.72]) + (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 48B23431FAE + for ; Wed, 4 Mar 2015 06:32:34 -0800 (PST) +Received: from vm_arch_64.bat.fr.eu.org (97.100.203.77.rev.sfr.net + [77.203.100.97]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + (Authenticated sender: vm_arch_64@bat.fr.eu.org) + by mx1b.lautre.net (Postfix) with ESMTPSA id 6B6B27E0D2 + for ; Wed, 4 Mar 2015 15:31:20 +0100 (CET) +Received: by vm_arch_64.bat.fr.eu.org (sSMTP sendmail emulation); + Wed, 04 Mar 2015 15:31:18 +0100 +From: Baptiste +To: notmuch@notmuchmail.org +Subject: [PATCH] Re: Add /renew/ tag to moved/renamed/reflagged messages +In-Reply-To: <87ioegq5ca.fsf@vm_arch_64.bat.fr.eu.org> +Organization: bat.fr.eu.org +References: <87ioegq5ca.fsf@vm_arch_64.bat.fr.eu.org> +User-Agent: Notmuch/0.19+67~g326e188 (http://notmuchmail.org) Emacs/25.0.50.2 + (x86_64-unknown-linux-gnu) +Date: Wed, 04 Mar 2015 15:31:17 +0100 +Message-ID: <87fv9kq1fu.fsf@vm_arch_64.bat.fr.eu.org> +MIME-Version: 1.0 +Content-Type: multipart/alternative; boundary="=-=-=" +X-Mailman-Approved-At: Wed, 04 Mar 2015 12:10:35 -0800 +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: Wed, 04 Mar 2015 14:32:42 -0000 + +--=-=-= +Content-Type: text/plain; charset=utf-8 +Content-Transfer-Encoding: quoted-printable + +Hi,=20 + +> What about another automatic tag to re-add to an existing mail when =3Dno= +tmuch new=3D detect a moved, renamed or reflagged message=C2=A0... + + +the following code sample seems to actually do the job=C2=A0=E2=80=A6 + +Best regards, + +--=20 +~~^v^~~ Baptiste + +----- + +#+BEGIN_EXAMPLE +5aa6f240a34d28ff3a8f768e399ec3c483961cb2 HEAD renew +Author: Baptiste Fouques +Date: Wed Mar 4 15:16:20 2015 +0100 + + Add /renew/ tags to moved or reflagged messages +=20=20=20=20 + (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. +=20 + Default: ``unread;inbox``. +=20 ++ **renew.tags** ++ A list of tags that will be added to all moved or re-flagged messa= +ges ++ 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); +=20 + 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); +=20 + 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 =3D 0; + config->new_tags =3D NULL; + config->new_tags_length =3D 0; ++ config->re_new_tags =3D NULL; ++ config->re_new_tags_length =3D 0; + config->new_ignore =3D NULL; + config->new_ignore_length =3D 0; + config->maildir_synchronize_flags =3D TRUE; +@@ -384,6 +388,10 @@ notmuch_config_open (void *ctx, + notmuch_config_set_new_tags (config, tags, 2); + } +=20 ++ if (notmuch_config_get_re_new_tags (config, &tmp) =3D=3D NULL) { ++ notmuch_config_set_re_new_tags (config, NULL, 0); ++ } ++ + if (notmuch_config_get_new_ignore (config, &tmp) =3D=3D 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) + } +=20 + 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, + } +=20 + 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; +=20 +@@ -274,6 +276,8 @@ add_file (notmuch_database_t *notmuch, const char *file= +name, + break; + /* Non-fatal issues (go on to next file). */ + case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: ++ for (tag =3D state->re_new_tags; *tag !=3D 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 =3D notmuch_database_begin_atomic (notmuch); + if (status) +@@ -810,7 +815,9 @@ remove_filename (notmuch_database_t *notmuch, + status =3D notmuch_database_remove_message (notmuch, path); + if (status =3D=3D NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) { + add_files_state->renamed_messages++; +- if (add_files_state->synchronize_flags =3D=3D TRUE) ++ for (tag =3D add_files_state->re_new_tags; *tag !=3D NULL; tag++) ++ notmuch_message_add_tag (message, *tag); ++ if (add_files_state->synchronize_flags =3D=3D TRUE) + notmuch_message_maildir_flags_to_tags (message); + status =3D NOTMUCH_STATUS_SUCCESS; + } else if (status =3D=3D NOTMUCH_STATUS_SUCCESS) { +@@ -948,6 +955,7 @@ notmuch_new_command (notmuch_config_t *config, int argc= +, char *argv[]) + add_files_state.verbosity =3D VERBOSITY_VERBOSE; +=20 + add_files_state.new_tags =3D notmuch_config_get_new_tags (config, &add= +_files_state.new_tags_length); ++ add_files_state.re_new_tags =3D notmuch_config_get_re_new_tags (config= +, &add_files_state.re_new_tags_length); + add_files_state.new_ignore =3D notmuch_config_get_new_ignore (config, = +&add_files_state.new_ignore_length); + add_files_state.synchronize_flags =3D notmuch_config_get_maildir_synch= +ronize_flags (config); + db_path =3D notmuch_config_get_database_path (config); +@@ -962,6 +970,17 @@ notmuch_new_command (notmuch_config_t *config, int arg= +c, char *argv[]) + return EXIT_FAILURE; + } + } ++ for (i =3D 0; i < add_files_state.re_new_tags_length; i++) { ++ const char *error_msg; ++ ++ error_msg =3D 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; ++ } ++ } ++ +=20 + if (!no_hooks) { + ret =3D 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; +=20 +@@ -192,6 +194,7 @@ notmuch_setup_command (notmuch_config_t *config, + } +=20 + new_tags =3D notmuch_config_get_new_tags (config, &new_tags_len); ++ re_new_tags =3D notmuch_config_get_re_new_tags (config, &re_new_tags_l= +en); +=20 + 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); + } +=20 ++ printf ("Tags to apply to all moved or reflagged messages (separated b= +y spaces) ["); ++ print_tag_list (re_new_tags, re_new_tags_len); ++ prompt ("]: "); ++ ++ if (strlen (response)) { ++ GPtrArray *tags =3D parse_tag_list (config, response); ++ ++ notmuch_config_set_re_new_tags (config, (const char **) tags->pdata, ++ tags->len); ++ ++ g_ptr_array_free (tags, TRUE); ++ } +=20 + search_exclude_tags =3D notmuch_config_get_search_exclude_tags (config= +, &search_exclude_tags_len); +#+END_EXAMPLE + +--=-=-= +Content-Type: multipart/related; boundary="==-=-=" + +--==-=-= +Content-Type: text/html; charset=utf-8 +Content-Transfer-Encoding: quoted-printable + +

+Hi,
+

+ +

+> What about another automatic tag to re-add to an existing mail when notmuch new detect a moved, renamed or reflagged message=C2=A0&#= +x2026;
+

+ + +

+the following code sample seems to actually do the job=C2=A0=E2=80=A6
+

+ +

+Best regards,
+

+ +

+–
+~^v^~ Baptiste
+

+ +
+ +
+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
+=20=20=20=20
+    (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.
+=20
+         Default: ``unread;inbox``.
+=20
++    **renew.tags**
++        A list of tags that will be added to all moved or re-flagged messa=
+ges
++        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);
+=20
+ 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);
+=20
+	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 =3D 0;
+     config->new_tags =3D NULL;
+     config->new_tags_length =3D 0;
++    config->re_new_tags =3D NULL;
++    config->re_new_tags_length =3D 0;
+     config->new_ignore =3D NULL;
+     config->new_ignore_length =3D 0;
+     config->maildir_synchronize_flags =3D TRUE;
+@@ -384,6 +388,10 @@ notmuch_config_open (void *ctx,
+ 	notmuch_config_set_new_tags (config, tags, 2);
+     }
+=20
++    if (notmuch_config_get_re_new_tags (config, &tmp) =3D=3D NULL) {
++	notmuch_config_set_re_new_tags (config, NULL, 0);
++    }
++
+     if (notmuch_config_get_new_ignore (config, &tmp) =3D=3D 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)
+ }
+=20
+ 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,
+ }
+=20
+ 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;
+=20
+@@ -274,6 +276,8 @@ add_file (notmuch_database_t *notmuch, const char *file=
+name,
+ 	break;
+     /* Non-fatal issues (go on to next file). */
+     case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
++	for (tag =3D state->re_new_tags; *tag !=3D 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 =3D notmuch_database_begin_atomic (notmuch);
+     if (status)
+@@ -810,7 +815,9 @@ remove_filename (notmuch_database_t *notmuch,
+     status =3D notmuch_database_remove_message (notmuch, path);
+     if (status =3D=3D NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {
+ 	add_files_state->renamed_messages++;
+-	if (add_files_state->synchronize_flags =3D=3D TRUE)
++	for (tag =3D add_files_state->re_new_tags; *tag !=3D NULL; tag++)
++	    notmuch_message_add_tag (message, *tag);
++ 	if (add_files_state->synchronize_flags =3D=3D TRUE)
+ 	    notmuch_message_maildir_flags_to_tags (message);
+ 	status =3D NOTMUCH_STATUS_SUCCESS;
+     } else if (status =3D=3D NOTMUCH_STATUS_SUCCESS) {
+@@ -948,6 +955,7 @@ notmuch_new_command (notmuch_config_t *config, int argc=
+, char *argv[])
+ 	add_files_state.verbosity =3D VERBOSITY_VERBOSE;
+=20
+     add_files_state.new_tags =3D notmuch_config_get_new_tags (config, &=
+;add_files_state.new_tags_length);
++    add_files_state.re_new_tags =3D notmuch_config_get_re_new_tags (config=
+, &add_files_state.re_new_tags_length);
+     add_files_state.new_ignore =3D notmuch_config_get_new_ignore (config, =
+&add_files_state.new_ignore_length);
+     add_files_state.synchronize_flags =3D notmuch_config_get_maildir_synch=
+ronize_flags (config);
+     db_path =3D notmuch_config_get_database_path (config);
+@@ -962,6 +970,17 @@ notmuch_new_command (notmuch_config_t *config, int arg=
+c, char *argv[])
+ 	    return EXIT_FAILURE;
+ 	}
+     }
++    for (i =3D 0; i < add_files_state.re_new_tags_length; i++) {
++	const char *error_msg;
++
++	error_msg =3D 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;
++	}
++    }
++
+=20
+     if (!no_hooks) {
+ 	ret =3D 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;
+=20
+@@ -192,6 +194,7 @@ notmuch_setup_command (notmuch_config_t *config,
+     }
+=20
+     new_tags =3D notmuch_config_get_new_tags (config, &new_tags_len);
++    re_new_tags =3D notmuch_config_get_re_new_tags (config, &re_new_ta=
+gs_len);
+=20
+     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);
+     }
+=20
++    printf ("Tags to apply to all moved or reflagged messages (separated b=
+y spaces) [");
++    print_tag_list (re_new_tags, re_new_tags_len);
++    prompt ("]: ");
++
++    if (strlen (response)) {
++	GPtrArray *tags =3D parse_tag_list (config, response);
++
++	notmuch_config_set_re_new_tags (config, (const char **) tags->pdata,
++					tags->len);
++
++	g_ptr_array_free (tags, TRUE);
++    }
+=20
+     search_exclude_tags =3D notmuch_config_get_search_exclude_tags (config=
+, &search_exclude_tags_len);
+
+ + +--==-=-=-- + +--=-=-=-- -- 2.26.2