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 568A6431FAE
\r
6 for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 14:10:36 -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 Amkgx8SNvhKo for <notmuch@notmuchmail.org>;
\r
11 Tue, 24 Nov 2009 14:10:35 -0800 (PST)
\r
12 Received: from mail-fx0-f214.google.com (mail-fx0-f214.google.com
\r
14 by olra.theworths.org (Postfix) with ESMTP id A4BA7431FBC
\r
15 for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 14:10:34 -0800 (PST)
\r
16 Received: by fxm6 with SMTP id 6so7397332fxm.0
\r
17 for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 14:10:33 -0800 (PST)
\r
18 Received: by 10.103.125.23 with SMTP id c23mr2961077mun.41.1259100633482;
\r
19 Tue, 24 Nov 2009 14:10:33 -0800 (PST)
\r
20 Received: from x61s.janakj (r2c34.net.upc.cz [62.245.66.34])
\r
21 by mx.google.com with ESMTPS id 23sm740148mun.41.2009.11.24.14.10.31
\r
22 (version=TLSv1/SSLv3 cipher=RC4-MD5);
\r
23 Tue, 24 Nov 2009 14:10:32 -0800 (PST)
\r
24 Received: by x61s.janakj (Postfix, from userid 1000)
\r
25 id B8CF7440659; Tue, 24 Nov 2009 23:10:30 +0100 (CET)
\r
26 From: Jan Janak <jan@ryngle.com>
\r
27 To: notmuch@notmuchmail.org
\r
28 Date: Tue, 24 Nov 2009 23:10:29 +0100
\r
29 Message-Id: <1259100630-13673-4-git-send-email-jan@ryngle.com>
\r
30 X-Mailer: git-send-email 1.6.3.3
\r
31 In-Reply-To: <1259100630-13673-3-git-send-email-jan@ryngle.com>
\r
32 References: <1259100630-13673-1-git-send-email-jan@ryngle.com>
\r
33 <1259100630-13673-2-git-send-email-jan@ryngle.com>
\r
34 <1259100630-13673-3-git-send-email-jan@ryngle.com>
\r
35 Subject: [notmuch] [PATCH 3/4] notmuch-setup: Copy/create the new section
\r
36 with tags for 'notmuch-new'.
\r
37 X-BeenThere: notmuch@notmuchmail.org
\r
38 X-Mailman-Version: 2.1.12
\r
40 List-Id: "Use and development of the notmuch mail system."
\r
41 <notmuch.notmuchmail.org>
\r
42 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
43 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
45 List-Post: <mailto:notmuch@notmuchmail.org>
\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
47 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
48 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
49 X-List-Received-Date: Tue, 24 Nov 2009 22:10:36 -0000
\r
51 If the user runs 'notmuch setup' and there is no configuration file yet
\r
52 then we also add the new section [new] to the configuration file and
\r
53 set the tags option as:
\r
57 This will be picked up by 'notmuch new' and all new mail added to the
\r
58 database will be tagged with the two tags as before.
\r
60 If the user already has a configuration file and runs 'notmuch setup'
\r
61 then we just copy whatever tags we find in the old configuration file
\r
62 to the new one. If there are no tags in the old configuration file then
\r
63 we assume that the user configured notmuch that way and the new config
\r
64 file would also have no tags in the section [new].
\r
66 We never ask the user interactively for the list of tags to be used by
\r
67 'notmuch new', it is assumed that beginners would want to stick to the
\r
68 defaults and advanced users can edit the configuration manually.
\r
70 Signed-off-by: Jan Janak <jan@ryngle.com>
\r
72 notmuch-client.h | 4 ++++
\r
73 notmuch-config.c | 40 ++++++++++++++++++++++++++++++++++++++++
\r
74 notmuch-setup.c | 14 ++++++++++++++
\r
75 3 files changed, 58 insertions(+), 0 deletions(-)
\r
77 diff --git a/notmuch-client.h b/notmuch-client.h
\r
78 index 0fb9c19..bb7d3d4 100644
\r
79 --- a/notmuch-client.h
\r
80 +++ b/notmuch-client.h
\r
81 @@ -187,6 +187,10 @@ notmuch_config_set_user_other_email (notmuch_config_t *config,
\r
83 notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length);
\r
86 +notmuch_config_set_new_tags (notmuch_config_t *config, const char *tags[],
\r
90 debugger_is_active (void);
\r
92 diff --git a/notmuch-config.c b/notmuch-config.c
\r
93 index 7f62a80..e884621 100644
\r
94 --- a/notmuch-config.c
\r
95 +++ b/notmuch-config.c
\r
96 @@ -54,6 +54,16 @@ static const char user_config_comment[] =
\r
97 " recipient list of replies, and will set the From address based on the\n"
\r
98 " address to which the original email was addressed.\n";
\r
100 +static const char new_config_comment[] =
\r
101 + " Configuration section for 'notmuch new'\n"
\r
103 + " The only supported value at the moment is 'tags. This option contains a\n"
\r
104 + " list of tags (separated by ';') that should be automatically applied to\n"
\r
105 + " newly added messages.\n"
\r
107 + " Note that 'notmuch new' also has a command line option which can be used\n"
\r
108 + " to add additional tags to the ones configured here.\n";
\r
110 struct _notmuch_config {
\r
112 GKeyFile *key_file;
\r
113 @@ -174,6 +184,7 @@ notmuch_config_open (void *ctx,
\r
114 GError *error = NULL;
\r
116 char *notmuch_config_env = NULL;
\r
117 + const char* def_new_tags[2] = {"inbox", "unread"};
\r
121 @@ -270,6 +281,20 @@ notmuch_config_open (void *ctx,
\r
125 + /* If we have no configuration file then we configure "inbox" and "unread"
\r
126 + * tags by default for 'notmuch new'. This ensures that the Emacs mode
\r
127 + * would still work as expected.
\r
129 + * We do not ask the user for tags to be used by 'notmuch new'. That's too
\r
130 + * much detail for beginners and others can edit the configuration file by
\r
134 + notmuch_config_set_new_tags (config, def_new_tags,
\r
135 + sizeof(def_new_tags) /
\r
136 + sizeof(const char*));
\r
139 /* When we create a new configuration file here, we add some
\r
140 * comments to help the user understand what can be done. */
\r
142 @@ -279,6 +304,8 @@ notmuch_config_open (void *ctx,
\r
143 database_config_comment, NULL);
\r
144 g_key_file_set_comment (config->key_file, "user", NULL,
\r
145 user_config_comment, NULL);
\r
146 + g_key_file_set_comment (config->key_file, "new", NULL,
\r
147 + new_config_comment, NULL);
\r
151 @@ -494,3 +521,16 @@ notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length)
\r
152 *length = config->new_tags_length;
\r
153 return config->new_tags;
\r
157 +notmuch_config_set_new_tags (notmuch_config_t *config,
\r
158 + const char *tags[],
\r
161 + g_key_file_set_string_list (config->key_file,
\r
165 + talloc_free (config->new_tags);
\r
166 + config->user_other_email = NULL;
\r
168 diff --git a/notmuch-setup.c b/notmuch-setup.c
\r
169 index d06fbf8..c1406db 100644
\r
170 --- a/notmuch-setup.c
\r
171 +++ b/notmuch-setup.c
\r
172 @@ -96,6 +96,8 @@ notmuch_setup_command (unused (void *ctx),
\r
173 notmuch_config_t *config;
\r
174 char **old_other_emails;
\r
175 size_t old_other_emails_len;
\r
177 + unsigned int new_tags_len;
\r
178 GPtrArray *other_emails;
\r
181 @@ -147,6 +149,18 @@ notmuch_setup_command (unused (void *ctx),
\r
182 other_emails->len);
\r
183 g_ptr_array_free (other_emails, TRUE);
\r
185 + /* If we already have a configuration file then we preserve the tags
\r
186 + * configured there. If the original configuration file contains no tags
\r
187 + * then we assume that the user configured it that way and add no tags.
\r
190 + new_tags = notmuch_config_get_new_tags (config, &new_tags_len);
\r
192 + notmuch_config_set_new_tags (config, (const char**)new_tags,
\r
197 prompt ("Top-level directory of your email archive [%s]: ",
\r
198 notmuch_config_get_database_path (config));
\r
199 if (strlen (response)) {
\r