1 /* notmuch - Not much of an email program, (just index and search)
3 * Copyright © 2009 Carl Worth
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see http://www.gnu.org/licenses/ .
18 * Author: Carl Worth <cworth@cworth.org>
21 #include "notmuch-client.h"
24 make_path_absolute (void *ctx, const char *path)
31 cwd = getcwd (NULL, 0);
33 fprintf (stderr, "Out of memory.\n");
37 path = talloc_asprintf (ctx, "%s/%s", cwd, path);
39 fprintf (stderr, "Out of memory.\n");
47 welcome_message_pre_setup (void)
50 "Welcome to notmuch!\n\n"
52 "The goal of notmuch is to help you manage and search your collection of\n"
53 "email, and to efficiently keep up with the flow of email as it comes in.\n\n"
55 "Notmuch needs to know a few things about you such as your name and email\n"
56 "address, as well as the directory that contains your email. This is where\n"
57 "you already have mail stored and where messages will be delivered in the\n"
58 "future. This directory can contain any number of sub-directories. Regular\n"
59 "files in these directories should be individual email messages. If there\n"
60 "are other, non-email files (such as indexes maintained by other email\n"
61 "programs) then notmuch will do its best to detect those and ignore them.\n\n"
63 "If you already have your email being delivered to directories in either\n"
64 "maildir or mh format, then that's perfect. Mail storage that uses mbox\n"
65 "format, (where one mbox file contains many messages), will not work with\n"
66 "notmuch. If that's how your mail is currently stored, we recommend you\n"
67 "first convert it to maildir format with a utility such as mb2md. You can\n"
68 "continue configuring notmuch now, but be sure to complete the conversion\n"
69 "before you run \"notmuch new\" for the first time.\n\n");
73 welcome_message_post_setup (void)
76 "Notmuch is now configured, and the configuration settings are saved in\n"
77 "a file in your home directory named .notmuch-config . If you'd like to\n"
78 "change the configuration in the future, you can either edit that file\n"
79 "directly or run \"notmuch setup\". To choose an alternate configuration\n"
80 "location, set ${NOTMUCH_CONFIG}.\n\n"
82 "The next step is to run \"notmuch new\" which will create a database\n"
83 "that indexes all of your mail. Depending on the amount of mail you have\n"
84 "the initial indexing process can take a long time, so expect that.\n"
85 "Also, the resulting database will require roughly the same amount of\n"
86 "storage space as your current collection of email. So please ensure you\n"
87 "have sufficient storage space available now.\n\n");
91 print_tag_list (const char **tags, size_t tags_len)
94 for (i = 0; i < tags_len; i++) {
97 printf ("%s", tags[i]);
102 parse_tag_list (void *ctx, char *response)
104 GPtrArray *tags = g_ptr_array_new ();
105 char *tag = response;
108 while (tag && *tag) {
109 space = strchr (tag, ' ');
111 g_ptr_array_add (tags, talloc_strndup (ctx, tag, space - tag));
113 g_ptr_array_add (tags, talloc_strdup (ctx, tag));
115 while (tag && *tag == ' ')
123 notmuch_setup_command (unused (void *ctx),
124 unused (int argc), unused (char *argv[]))
126 char *response = NULL;
127 size_t response_size = 0;
128 notmuch_config_t *config;
129 const char **old_other_emails;
130 size_t old_other_emails_len;
131 GPtrArray *other_emails;
134 const char **new_tags;
137 #define prompt(format, ...) \
139 printf (format, ##__VA_ARGS__); \
141 if (getline (&response, &response_size, stdin) < 0) { \
142 printf ("Exiting.\n"); \
145 chomp_newline (response); \
148 config = notmuch_config_open (ctx, NULL, &is_new);
151 welcome_message_pre_setup ();
153 prompt ("Your full name [%s]: ", notmuch_config_get_user_name (config));
154 if (strlen (response))
155 notmuch_config_set_user_name (config, response);
157 prompt ("Your primary email address [%s]: ",
158 notmuch_config_get_user_primary_email (config));
159 if (strlen (response))
160 notmuch_config_set_user_primary_email (config, response);
162 other_emails = g_ptr_array_new ();
164 old_other_emails = notmuch_config_get_user_other_email (config,
165 &old_other_emails_len);
166 for (i = 0; i < old_other_emails_len; i++) {
167 prompt ("Additional email address [%s]: ", old_other_emails[i]);
168 if (strlen (response))
169 g_ptr_array_add (other_emails, talloc_strdup (ctx, response));
171 g_ptr_array_add (other_emails, talloc_strdup (ctx,
172 old_other_emails[i]));
176 prompt ("Additional email address [Press 'Enter' if none]: ");
177 if (strlen (response))
178 g_ptr_array_add (other_emails, talloc_strdup (ctx, response));
179 } while (strlen (response));
180 if (other_emails->len)
181 notmuch_config_set_user_other_email (config,
185 g_ptr_array_free (other_emails, TRUE);
187 prompt ("Top-level directory of your email archive [%s]: ",
188 notmuch_config_get_database_path (config));
189 if (strlen (response)) {
190 const char *absolute_path;
192 absolute_path = make_path_absolute (ctx, response);
193 notmuch_config_set_database_path (config, absolute_path);
196 new_tags = notmuch_config_get_new_tags (config, &new_tags_len);
198 printf ("Tags to apply to all new messages (separated by spaces) [");
199 print_tag_list (new_tags, new_tags_len);
202 if (strlen (response)) {
203 GPtrArray *tags = parse_tag_list (ctx, response);
205 notmuch_config_set_new_tags (config, (const char **) tags->pdata,
208 g_ptr_array_free (tags, TRUE);
212 /* Temporarily remove exclude tag support for 0.12 */
214 if (! notmuch_config_save (config)) {
216 welcome_message_post_setup ();