1 Return-Path: <neil@linux.intel.com>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 6B70D431FAF
\r
6 for <notmuch@notmuchmail.org>; Mon, 16 Apr 2012 08:02:16 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-5 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_HI=-5] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id lRkV1JXFuVbB for <notmuch@notmuchmail.org>;
\r
16 Mon, 16 Apr 2012 08:02:14 -0700 (PDT)
\r
17 Received: from mga14.intel.com (mga14.intel.com [143.182.124.37])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 13585431FAE
\r
19 for <notmuch@notmuchmail.org>; Mon, 16 Apr 2012 08:02:13 -0700 (PDT)
\r
20 Received: from azsmga002.ch.intel.com ([10.2.17.35])
\r
21 by azsmga102.ch.intel.com with ESMTP; 16 Apr 2012 08:02:12 -0700
\r
23 X-IronPort-AV: E=Sophos;i="4.71,315,1320652800"; d="scan'208";a="89585162"
\r
24 Received: from unknown (HELO neilpc.ger.corp.intel.com) ([10.252.120.59])
\r
25 by AZSMGA002.ch.intel.com with ESMTP; 16 Apr 2012 08:02:01 -0700
\r
26 From: Neil Roberts <neil@linux.intel.com>
\r
27 To: notmuch@notmuchmail.org
\r
28 Subject: [PATCH] Add a new.filename_tags option
\r
29 Date: Mon, 16 Apr 2012 16:01:39 +0100
\r
30 Message-Id: <1334588499-3101-1-git-send-email-neil@linux.intel.com>
\r
31 X-Mailer: git-send-email 1.7.3.16.g9464b
\r
32 X-Mailman-Approved-At: Mon, 16 Apr 2012 08:19:42 -0700
\r
33 Cc: Neil Roberts <neil@linux.intel.com>
\r
34 X-BeenThere: notmuch@notmuchmail.org
\r
35 X-Mailman-Version: 2.1.13
\r
37 List-Id: "Use and development of the notmuch mail system."
\r
38 <notmuch.notmuchmail.org>
\r
39 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
40 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
42 List-Post: <mailto:notmuch@notmuchmail.org>
\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
44 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
46 X-List-Received-Date: Mon, 16 Apr 2012 15:02:16 -0000
\r
48 This option is similar to the existing new.tags option except that it
\r
49 is instead used when a new filename is encountered for an existing
\r
52 This can be used to do post-processing based on the filenames that a
\r
53 message has. For example, in my setup I use maildrop to filter the
\r
54 messages in to maildirs and then I have an extra script that runs to
\r
55 add the tags based on which folders maildrop put the message in. The
\r
56 script only looks at messages that have the 'inbox' tag and then
\r
57 removes the tag after processing. This works fine except sometimes I
\r
58 will get a message twice for example if I am CC'd in a message from a
\r
59 mailing list. In that case I want the message to be tagged twice, once
\r
60 to indicate it was sent directly to me and once to indicate it was
\r
61 sent to the mailing list. If one of these messages is delayed then I
\r
62 can end up processing the message once and removing the inbox tag.
\r
63 When the second message is finally received it would previously not
\r
64 get processed again so I would lose the second tag. With this patch I
\r
65 can configure it to re-add the inbox tag in this case to force it to
\r
66 reconsider the tags.
\r
68 man/man1/notmuch-config.1 | 8 ++++++++
\r
69 notmuch-client.h | 9 +++++++++
\r
70 notmuch-config.c | 34 ++++++++++++++++++++++++++++++++++
\r
71 notmuch-new.c | 7 +++++++
\r
72 4 files changed, 58 insertions(+), 0 deletions(-)
\r
74 diff --git a/man/man1/notmuch-config.1 b/man/man1/notmuch-config.1
\r
75 index 395cb9c..caf20b4 100644
\r
76 --- a/man/man1/notmuch-config.1
\r
77 +++ b/man/man1/notmuch-config.1
\r
78 @@ -74,6 +74,14 @@ A list of tags that will be added to all messages incorporated by
\r
82 +.B new.filename_tags
\r
83 +A list of tags that will be added to any message when a new filename
\r
84 +is encountered for it during
\r
91 A list of file and directory names, without path, that will not be
\r
92 searched for messages by
\r
93 diff --git a/notmuch-client.h b/notmuch-client.h
\r
94 index 19b7f01..55bcef4 100644
\r
95 --- a/notmuch-client.h
\r
96 +++ b/notmuch-client.h
\r
97 @@ -238,6 +238,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
\r
101 +notmuch_config_get_new_filename_tags (notmuch_config_t *config,
\r
105 +notmuch_config_set_new_filename_tags (notmuch_config_t *config,
\r
106 + const char *new_tags[],
\r
110 notmuch_config_get_new_ignore (notmuch_config_t *config,
\r
113 diff --git a/notmuch-config.c b/notmuch-config.c
\r
114 index e9b2750..acbc08d 100644
\r
115 --- a/notmuch-config.c
\r
116 +++ b/notmuch-config.c
\r
117 @@ -111,6 +111,8 @@ struct _notmuch_config {
\r
118 size_t user_other_email_length;
\r
119 const char **new_tags;
\r
120 size_t new_tags_length;
\r
121 + const char **new_filename_tags;
\r
122 + size_t new_filename_tags_length;
\r
123 const char **new_ignore;
\r
124 size_t new_ignore_length;
\r
125 notmuch_bool_t maildir_synchronize_flags;
\r
126 @@ -272,6 +274,8 @@ notmuch_config_open (void *ctx,
\r
127 config->user_other_email_length = 0;
\r
128 config->new_tags = NULL;
\r
129 config->new_tags_length = 0;
\r
130 + config->new_filename_tags = NULL;
\r
131 + config->new_filename_tags_length = 0;
\r
132 config->new_ignore = NULL;
\r
133 config->new_ignore_length = 0;
\r
134 config->maildir_synchronize_flags = TRUE;
\r
135 @@ -371,6 +375,10 @@ notmuch_config_open (void *ctx,
\r
136 notmuch_config_set_new_tags (config, tags, 2);
\r
139 + if (notmuch_config_get_new_filename_tags (config, &tmp) == NULL) {
\r
140 + notmuch_config_set_new_filename_tags (config, NULL, 0);
\r
143 if (notmuch_config_get_new_ignore (config, &tmp) == NULL) {
\r
144 notmuch_config_set_new_ignore (config, NULL, 0);
\r
146 @@ -624,6 +632,16 @@ notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length)
\r
150 +notmuch_config_get_new_filename_tags (notmuch_config_t *config,
\r
153 + return _config_get_list (config, "new", "filename_tags",
\r
154 + &(config->new_filename_tags),
\r
155 + &(config->new_filename_tags_length),
\r
160 notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length)
\r
162 return _config_get_list (config, "new", "ignore",
\r
163 @@ -650,6 +668,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
\r
167 +notmuch_config_set_new_filename_tags (notmuch_config_t *config,
\r
168 + const char *list[],
\r
171 + _config_set_list (config, "new", "filename_tags", list, length,
\r
172 + &(config->new_filename_tags));
\r
176 notmuch_config_set_new_ignore (notmuch_config_t *config,
\r
177 const char *list[],
\r
179 @@ -731,6 +758,13 @@ notmuch_config_command_get (void *ctx, char *item)
\r
180 tags = notmuch_config_get_new_tags (config, &length);
\r
181 for (i = 0; i < length; i++)
\r
182 printf ("%s\n", tags[i]);
\r
183 + } else if (strcmp(item, "new.filename_tags") == 0) {
\r
184 + const char **tags;
\r
185 + size_t i, length;
\r
187 + tags = notmuch_config_get_new_filename_tags (config, &length);
\r
188 + for (i = 0; i < length; i++)
\r
189 + printf ("%s\n", tags[i]);
\r
193 diff --git a/notmuch-new.c b/notmuch-new.c
\r
194 index 4f13535..4a128b7 100644
\r
195 --- a/notmuch-new.c
\r
196 +++ b/notmuch-new.c
\r
197 @@ -39,6 +39,8 @@ typedef struct {
\r
199 const char **new_tags;
\r
200 size_t new_tags_length;
\r
201 + const char **new_filename_tags;
\r
202 + size_t new_filename_tags_length;
\r
203 const char **new_ignore;
\r
204 size_t new_ignore_length;
\r
206 @@ -494,8 +496,12 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
208 /* Non-fatal issues (go on to next file) */
\r
209 case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
\r
210 + notmuch_message_freeze (message);
\r
211 + for (tag=state->new_filename_tags; *tag != NULL; tag++)
\r
212 + notmuch_message_add_tag (message, *tag);
\r
213 if (state->synchronize_flags == TRUE)
\r
214 notmuch_message_maildir_flags_to_tags (message);
\r
215 + notmuch_message_thaw (message);
\r
217 case NOTMUCH_STATUS_FILE_NOT_EMAIL:
\r
218 fprintf (stderr, "Note: Ignoring non-mail file: %s\n",
\r
219 @@ -861,6 +867,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
\r
222 add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);
\r
223 + add_files_state.new_filename_tags = notmuch_config_get_new_filename_tags (config, &add_files_state.new_filename_tags_length);
\r
224 add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length);
\r
225 add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
\r
226 db_path = notmuch_config_get_database_path (config);
\r