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