From ef1e87524705b012d29d326dbd3eff2d56bf9f98 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Mon, 16 Apr 2012 16:01:39 +0100 Subject: [PATCH] [PATCH] Add a new.filename_tags option --- 9f/3c7c6798e42d07e9e3ab52a7e588a391dbaf76 | 229 ++++++++++++++++++++++ 1 file changed, 229 insertions(+) create mode 100644 9f/3c7c6798e42d07e9e3ab52a7e588a391dbaf76 diff --git a/9f/3c7c6798e42d07e9e3ab52a7e588a391dbaf76 b/9f/3c7c6798e42d07e9e3ab52a7e588a391dbaf76 new file mode 100644 index 000000000..0faeb9c2e --- /dev/null +++ b/9f/3c7c6798e42d07e9e3ab52a7e588a391dbaf76 @@ -0,0 +1,229 @@ +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 6B70D431FAF + for ; Mon, 16 Apr 2012 08:02:16 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -5 +X-Spam-Level: +X-Spam-Status: No, score=-5 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_HI=-5] 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 lRkV1JXFuVbB for ; + Mon, 16 Apr 2012 08:02:14 -0700 (PDT) +Received: from mga14.intel.com (mga14.intel.com [143.182.124.37]) + by olra.theworths.org (Postfix) with ESMTP id 13585431FAE + for ; Mon, 16 Apr 2012 08:02:13 -0700 (PDT) +Received: from azsmga002.ch.intel.com ([10.2.17.35]) + by azsmga102.ch.intel.com with ESMTP; 16 Apr 2012 08:02:12 -0700 +X-ExtLoop1: 1 +X-IronPort-AV: E=Sophos;i="4.71,315,1320652800"; d="scan'208";a="89585162" +Received: from unknown (HELO neilpc.ger.corp.intel.com) ([10.252.120.59]) + by AZSMGA002.ch.intel.com with ESMTP; 16 Apr 2012 08:02:01 -0700 +From: Neil Roberts +To: notmuch@notmuchmail.org +Subject: [PATCH] Add a new.filename_tags option +Date: Mon, 16 Apr 2012 16:01:39 +0100 +Message-Id: <1334588499-3101-1-git-send-email-neil@linux.intel.com> +X-Mailer: git-send-email 1.7.3.16.g9464b +X-Mailman-Approved-At: Mon, 16 Apr 2012 08:19:42 -0700 +Cc: Neil Roberts +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: Mon, 16 Apr 2012 15:02:16 -0000 + +This option is similar to the existing new.tags option except that it +is instead used when a new filename is encountered for an existing +message. + +This can be used to do post-processing based on the filenames that a +message has. For example, in my setup I use maildrop to filter the +messages in to maildirs and then I have an extra script that runs to +add the tags based on which folders maildrop put the message in. The +script only looks at messages that have the 'inbox' tag and then +removes the tag after processing. This works fine except sometimes I +will get a message twice for example if I am CC'd in a message from a +mailing list. In that case I want the message to be tagged twice, once +to indicate it was sent directly to me and once to indicate it was +sent to the mailing list. If one of these messages is delayed then I +can end up processing the message once and removing the inbox tag. +When the second message is finally received it would previously not +get processed again so I would lose the second tag. With this patch I +can configure it to re-add the inbox tag in this case to force it to +reconsider the tags. +--- + man/man1/notmuch-config.1 | 8 ++++++++ + notmuch-client.h | 9 +++++++++ + notmuch-config.c | 34 ++++++++++++++++++++++++++++++++++ + notmuch-new.c | 7 +++++++ + 4 files changed, 58 insertions(+), 0 deletions(-) + +diff --git a/man/man1/notmuch-config.1 b/man/man1/notmuch-config.1 +index 395cb9c..caf20b4 100644 +--- a/man/man1/notmuch-config.1 ++++ b/man/man1/notmuch-config.1 +@@ -74,6 +74,14 @@ A list of tags that will be added to all messages incorporated by + + .RS 4 + .TP 4 ++.B new.filename_tags ++A list of tags that will be added to any message when a new filename ++is encountered for it during ++.BR "notmuch new". ++.RE ++ ++.RS 4 ++.TP 4 + .B new.ignore + A list of file and directory names, without path, that will not be + searched for messages by +diff --git a/notmuch-client.h b/notmuch-client.h +index 19b7f01..55bcef4 100644 +--- a/notmuch-client.h ++++ b/notmuch-client.h +@@ -238,6 +238,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config, + size_t length); + + const char ** ++notmuch_config_get_new_filename_tags (notmuch_config_t *config, ++ size_t *length); ++ ++void ++notmuch_config_set_new_filename_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); + +diff --git a/notmuch-config.c b/notmuch-config.c +index e9b2750..acbc08d 100644 +--- a/notmuch-config.c ++++ b/notmuch-config.c +@@ -111,6 +111,8 @@ struct _notmuch_config { + size_t user_other_email_length; + const char **new_tags; + size_t new_tags_length; ++ const char **new_filename_tags; ++ size_t new_filename_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->new_filename_tags = NULL; ++ config->new_filename_tags_length = 0; + config->new_ignore = NULL; + config->new_ignore_length = 0; + config->maildir_synchronize_flags = TRUE; +@@ -371,6 +375,10 @@ notmuch_config_open (void *ctx, + notmuch_config_set_new_tags (config, tags, 2); + } + ++ if (notmuch_config_get_new_filename_tags (config, &tmp) == NULL) { ++ notmuch_config_set_new_filename_tags (config, NULL, 0); ++ } ++ + if (notmuch_config_get_new_ignore (config, &tmp) == NULL) { + notmuch_config_set_new_ignore (config, NULL, 0); + } +@@ -624,6 +632,16 @@ notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length) + } + + const char ** ++notmuch_config_get_new_filename_tags (notmuch_config_t *config, ++ size_t *length) ++{ ++ return _config_get_list (config, "new", "filename_tags", ++ &(config->new_filename_tags), ++ &(config->new_filename_tags_length), ++ length); ++} ++ ++const char ** + notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length) + { + return _config_get_list (config, "new", "ignore", +@@ -650,6 +668,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config, + } + + void ++notmuch_config_set_new_filename_tags (notmuch_config_t *config, ++ const char *list[], ++ size_t length) ++{ ++ _config_set_list (config, "new", "filename_tags", list, length, ++ &(config->new_filename_tags)); ++} ++ ++void + notmuch_config_set_new_ignore (notmuch_config_t *config, + const char *list[], + size_t length) +@@ -731,6 +758,13 @@ notmuch_config_command_get (void *ctx, 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.filename_tags") == 0) { ++ const char **tags; ++ size_t i, length; ++ ++ tags = notmuch_config_get_new_filename_tags (config, &length); ++ for (i = 0; i < length; i++) ++ printf ("%s\n", tags[i]); + } else { + char **value; + size_t i, length; +diff --git a/notmuch-new.c b/notmuch-new.c +index 4f13535..4a128b7 100644 +--- a/notmuch-new.c ++++ b/notmuch-new.c +@@ -39,6 +39,8 @@ typedef struct { + int verbose; + const char **new_tags; + size_t new_tags_length; ++ const char **new_filename_tags; ++ size_t new_filename_tags_length; + const char **new_ignore; + size_t new_ignore_length; + +@@ -494,8 +496,12 @@ add_files_recursive (notmuch_database_t *notmuch, + break; + /* Non-fatal issues (go on to next file) */ + case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: ++ notmuch_message_freeze (message); ++ for (tag=state->new_filename_tags; *tag != NULL; tag++) ++ notmuch_message_add_tag (message, *tag); + if (state->synchronize_flags == TRUE) + notmuch_message_maildir_flags_to_tags (message); ++ notmuch_message_thaw (message); + break; + case NOTMUCH_STATUS_FILE_NOT_EMAIL: + fprintf (stderr, "Note: Ignoring non-mail file: %s\n", +@@ -861,6 +867,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) + return 1; + + add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length); ++ add_files_state.new_filename_tags = notmuch_config_get_new_filename_tags (config, &add_files_state.new_filename_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); +-- +1.7.3.16.g9464b + -- 2.26.2