1 Return-Path: <jan@ryngle.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 8AD43431FC2
\r
6 for <notmuch@notmuchmail.org>; Wed, 25 Nov 2009 15:30:26 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 Received: from olra.theworths.org ([127.0.0.1])
\r
9 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
10 with ESMTP id EJqQK++v6YOu for <notmuch@notmuchmail.org>;
\r
11 Wed, 25 Nov 2009 15:30:25 -0800 (PST)
\r
12 Received: from mail-ew0-f213.google.com (mail-ew0-f213.google.com
\r
14 by olra.theworths.org (Postfix) with ESMTP id 710D3431FC0
\r
15 for <notmuch@notmuchmail.org>; Wed, 25 Nov 2009 15:30:24 -0800 (PST)
\r
16 Received: by ewy5 with SMTP id 5so257222ewy.30
\r
17 for <notmuch@notmuchmail.org>; Wed, 25 Nov 2009 15:30:23 -0800 (PST)
\r
18 Received: by 10.213.0.144 with SMTP id 16mr1690605ebb.38.1259191823446;
\r
19 Wed, 25 Nov 2009 15:30:23 -0800 (PST)
\r
20 Received: from x61s.janakj ([213.192.30.141])
\r
21 by mx.google.com with ESMTPS id 28sm333998eyg.36.2009.11.25.15.30.18
\r
22 (version=TLSv1/SSLv3 cipher=RC4-MD5);
\r
23 Wed, 25 Nov 2009 15:30:22 -0800 (PST)
\r
24 Received: by x61s.janakj (Postfix, from userid 1000)
\r
25 id AEC83440374; Thu, 26 Nov 2009 00:30:16 +0100 (CET)
\r
26 From: Jan Janak <jan@ryngle.com>
\r
27 To: notmuch@notmuchmail.org
\r
28 Date: Thu, 26 Nov 2009 00:30:13 +0100
\r
29 Message-Id: <1259191816-1982-2-git-send-email-jan@ryngle.com>
\r
30 X-Mailer: git-send-email 1.6.3.3
\r
31 In-Reply-To: <1259191816-1982-1-git-send-email-jan@ryngle.com>
\r
32 References: <1259100630-13673-1-git-send-email-jan@ryngle.com>
\r
33 <1259191816-1982-1-git-send-email-jan@ryngle.com>
\r
34 Subject: [notmuch] [PATCH 2/5] notmuch: Config option to specify tags to be
\r
35 applied by 'notmuch new'.
\r
36 X-BeenThere: notmuch@notmuchmail.org
\r
37 X-Mailman-Version: 2.1.12
\r
39 List-Id: "Use and development of the notmuch mail system."
\r
40 <notmuch.notmuchmail.org>
\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
42 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
44 List-Post: <mailto:notmuch@notmuchmail.org>
\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
47 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
48 X-List-Received-Date: Wed, 25 Nov 2009 23:30:26 -0000
\r
50 Add support for section [new] in the configuration file. This section
\r
51 is supposed to contain options for 'notmuch new'. Currently there is
\r
52 only one option called tags.
\r
54 The tags option can be used to configure a set of tags to be applied
\r
55 by 'notmuch new'. Individual tags are separated by semicolon.
\r
57 'notmuch new' is modified not to apply 'inbox' and 'unread' by default,
\r
58 but instead it obtains the set of tags to be applied from the new
\r
59 configuration file option.
\r
61 Signed-off-by: Jan Janak <jan@ryngle.com>
\r
63 This revision of the patch includes suggestions from Bart Trojanowski.
\r
65 notmuch-client.h | 3 +++
\r
66 notmuch-config.c | 43 +++++++++++++++++++++++++++++++++++++++++++
\r
67 notmuch-new.c | 19 ++++++++++++++++++-
\r
68 3 files changed, 64 insertions(+), 1 deletions(-)
\r
70 diff --git a/notmuch-client.h b/notmuch-client.h
\r
71 index c04eaeb..0fb9c19 100644
\r
72 --- a/notmuch-client.h
\r
73 +++ b/notmuch-client.h
\r
74 @@ -184,6 +184,9 @@ notmuch_config_set_user_other_email (notmuch_config_t *config,
\r
75 const char *other_email[],
\r
79 +notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length);
\r
82 debugger_is_active (void);
\r
84 diff --git a/notmuch-config.c b/notmuch-config.c
\r
85 index fc65d6b..57072ce 100644
\r
86 --- a/notmuch-config.c
\r
87 +++ b/notmuch-config.c
\r
94 static const char toplevel_config_comment[] =
\r
95 " .notmuch-config - Configuration file for the notmuch mail system\n"
\r
96 @@ -62,6 +63,9 @@ struct _notmuch_config {
\r
97 char *user_primary_email;
\r
98 char **user_other_email;
\r
99 size_t user_other_email_length;
\r
102 + size_t new_tags_length;
\r
106 @@ -199,6 +203,8 @@ notmuch_config_open (void *ctx,
\r
107 config->user_primary_email = NULL;
\r
108 config->user_other_email = NULL;
\r
109 config->user_other_email_length = 0;
\r
110 + config->new_tags = NULL;
\r
111 + config->new_tags_length = 0;
\r
113 if (! g_key_file_load_from_file (config->key_file,
\r
115 @@ -450,3 +456,40 @@ notmuch_config_set_user_other_email (notmuch_config_t *config,
\r
116 talloc_free (config->user_other_email);
\r
117 config->user_other_email = NULL;
\r
121 +notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length)
\r
125 + char *start, *end;
\r
127 + if (config->new_tags == NULL) {
\r
128 + config->new_tags_length = 0;
\r
129 + tags = g_key_file_get_string_list (config->key_file, "new", "tags",
\r
133 + config->new_tags = talloc_size (config, sizeof(char*) *
\r
135 + for (i = 0; i < len; i++) {
\r
136 + /* Remove leading and trailing white space around the tag and
\r
137 + * filter out empty tags. */
\r
139 + end = start + strlen (start) - 1;
\r
140 + while (isspace (*start)) start++;
\r
141 + while (end > start && isspace (*end)) end--;
\r
142 + if (end >= start) {
\r
143 + config->new_tags[config->new_tags_length++] =
\r
144 + talloc_strndup (config->new_tags, start,
\r
145 + end - start + 1);
\r
148 + config->new_tags[config->new_tags_length] = NULL;
\r
149 + g_strfreev (tags);
\r
153 + *length = config->new_tags_length;
\r
154 + return config->new_tags;
\r
156 diff --git a/notmuch-new.c b/notmuch-new.c
\r
157 index 9970407..af717b7 100644
\r
158 --- a/notmuch-new.c
\r
159 +++ b/notmuch-new.c
\r
162 static volatile sig_atomic_t do_add_files_print_progress = 0;
\r
164 +static notmuch_config_t *config = NULL;
\r
167 handle_sigalrm (unused (int signal))
\r
169 @@ -68,6 +70,21 @@ add_files_print_progress (add_files_state_t *state)
\r
174 +apply_tags (notmuch_message_t *message)
\r
179 + if ((tags = notmuch_config_get_new_tags (config, &count)) == NULL)
\r
182 + for (i = 0; i < count; i++) {
\r
184 + notmuch_message_add_tag (message, tags[i]);
\r
188 static int ino_cmp(const struct dirent **a, const struct dirent **b)
\r
190 return ((*a)->d_ino < (*b)->d_ino) ? -1 : 1;
\r
191 @@ -191,6 +208,7 @@ add_files_recursive (notmuch_database_t *notmuch,
\r
193 case NOTMUCH_STATUS_SUCCESS:
\r
194 state->added_messages++;
\r
195 + apply_tags (message);
\r
197 /* Non-fatal issues (go on to next file) */
\r
198 case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
\r
199 @@ -388,7 +406,6 @@ count_files (const char *path, int *count)
\r
201 notmuch_new_command (void *ctx, int argc, char *argv[])
\r
203 - notmuch_config_t *config;
\r
204 notmuch_database_t *notmuch;
\r
205 add_files_state_t add_files_state;
\r