2009-11-10 21:03:05 +01:00
|
|
|
/* notmuch - Not much of an email program, (just index and search)
|
|
|
|
*
|
|
|
|
* Copyright © 2009 Carl Worth
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2016-06-02 18:26:14 +02:00
|
|
|
* along with this program. If not, see https://www.gnu.org/licenses/ .
|
2009-11-10 21:03:05 +01:00
|
|
|
*
|
|
|
|
* Author: Carl Worth <cworth@cworth.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "notmuch-client.h"
|
|
|
|
|
2009-11-12 02:01:55 +01:00
|
|
|
static const char *
|
|
|
|
make_path_absolute (void *ctx, const char *path)
|
2009-11-10 21:03:05 +01:00
|
|
|
{
|
2009-11-12 02:01:55 +01:00
|
|
|
char *cwd;
|
2009-11-10 21:03:05 +01:00
|
|
|
|
2009-11-12 02:01:55 +01:00
|
|
|
if (*path == '/')
|
|
|
|
return path;
|
2009-11-10 21:03:05 +01:00
|
|
|
|
2009-11-12 02:01:55 +01:00
|
|
|
cwd = getcwd (NULL, 0);
|
|
|
|
if (cwd == NULL) {
|
|
|
|
fprintf (stderr, "Out of memory.\n");
|
|
|
|
return NULL;
|
2009-11-10 21:03:05 +01:00
|
|
|
}
|
|
|
|
|
2009-11-12 02:01:55 +01:00
|
|
|
path = talloc_asprintf (ctx, "%s/%s", cwd, path);
|
|
|
|
if (path == NULL)
|
|
|
|
fprintf (stderr, "Out of memory.\n");
|
2009-11-10 21:03:05 +01:00
|
|
|
|
2009-11-12 02:01:55 +01:00
|
|
|
free (cwd);
|
2009-11-10 21:03:05 +01:00
|
|
|
|
2009-11-12 02:01:55 +01:00
|
|
|
return path;
|
2009-11-11 20:23:55 +01:00
|
|
|
}
|
|
|
|
|
2009-11-12 02:33:31 +01:00
|
|
|
static void
|
|
|
|
welcome_message_pre_setup (void)
|
|
|
|
{
|
|
|
|
printf (
|
2019-06-13 12:31:01 +02:00
|
|
|
"Welcome to notmuch!\n\n"
|
|
|
|
|
|
|
|
"The goal of notmuch is to help you manage and search your collection of\n"
|
|
|
|
"email, and to efficiently keep up with the flow of email as it comes in.\n\n"
|
|
|
|
|
|
|
|
"Notmuch needs to know a few things about you such as your name and email\n"
|
|
|
|
"address, as well as the directory that contains your email. This is where\n"
|
|
|
|
"you already have mail stored and where messages will be delivered in the\n"
|
|
|
|
"future. This directory can contain any number of sub-directories. Regular\n"
|
|
|
|
"files in these directories should be individual email messages. If there\n"
|
|
|
|
"are other, non-email files (such as indexes maintained by other email\n"
|
|
|
|
"programs) then notmuch will do its best to detect those and ignore them.\n\n"
|
|
|
|
|
|
|
|
"If you already have your email being delivered to directories in either\n"
|
|
|
|
"maildir or mh format, then that's perfect. Mail storage that uses mbox\n"
|
|
|
|
"format, (where one mbox file contains many messages), will not work with\n"
|
|
|
|
"notmuch. If that's how your mail is currently stored, we recommend you\n"
|
|
|
|
"first convert it to maildir format with a utility such as mb2md. You can\n"
|
|
|
|
"continue configuring notmuch now, but be sure to complete the conversion\n"
|
|
|
|
"before you run \"notmuch new\" for the first time.\n\n");
|
2009-11-12 02:33:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
welcome_message_post_setup (void)
|
|
|
|
{
|
|
|
|
printf ("\n"
|
2019-06-13 12:31:01 +02:00
|
|
|
"Notmuch is now configured, and the configuration settings are saved in\n"
|
2020-11-29 23:35:22 +01:00
|
|
|
"a file in your home directory named .notmuch-config. If you'd like to\n"
|
2019-06-13 12:31:01 +02:00
|
|
|
"change the configuration in the future, you can either edit that file\n"
|
|
|
|
"directly or run \"notmuch setup\". To choose an alternate configuration\n"
|
|
|
|
"location, set ${NOTMUCH_CONFIG}.\n\n"
|
|
|
|
|
|
|
|
"The next step is to run \"notmuch new\" which will create a database\n"
|
|
|
|
"that indexes all of your mail. Depending on the amount of mail you have\n"
|
|
|
|
"the initial indexing process can take a long time, so expect that.\n"
|
|
|
|
"Also, the resulting database will require roughly the same amount of\n"
|
|
|
|
"storage space as your current collection of email. So please ensure you\n"
|
|
|
|
"have sufficient storage space available now.\n\n");
|
2009-11-12 02:33:31 +01:00
|
|
|
}
|
|
|
|
|
2012-01-23 06:50:45 +01:00
|
|
|
static void
|
2021-02-13 18:49:32 +01:00
|
|
|
print_tag_list (notmuch_config_values_t *tags)
|
2012-01-23 06:50:45 +01:00
|
|
|
{
|
2021-02-13 18:49:32 +01:00
|
|
|
bool first = false;
|
2019-06-13 12:31:01 +02:00
|
|
|
|
2021-02-13 18:49:32 +01:00
|
|
|
for (;
|
|
|
|
notmuch_config_values_valid (tags);
|
|
|
|
notmuch_config_values_move_to_next (tags)) {
|
|
|
|
if (! first)
|
2012-01-23 06:50:45 +01:00
|
|
|
printf (" ");
|
2021-02-13 18:49:32 +01:00
|
|
|
first = false;
|
|
|
|
printf ("%s", notmuch_config_values_get (tags));
|
2012-01-23 06:50:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GPtrArray *
|
|
|
|
parse_tag_list (void *ctx, char *response)
|
|
|
|
{
|
|
|
|
GPtrArray *tags = g_ptr_array_new ();
|
|
|
|
char *tag = response;
|
|
|
|
char *space;
|
|
|
|
|
|
|
|
while (tag && *tag) {
|
|
|
|
space = strchr (tag, ' ');
|
|
|
|
if (space)
|
|
|
|
g_ptr_array_add (tags, talloc_strndup (ctx, tag, space - tag));
|
|
|
|
else
|
|
|
|
g_ptr_array_add (tags, talloc_strdup (ctx, tag));
|
|
|
|
tag = space;
|
|
|
|
while (tag && *tag == ' ')
|
|
|
|
tag++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tags;
|
|
|
|
}
|
|
|
|
|
2009-11-11 20:23:55 +01:00
|
|
|
int
|
2021-02-27 15:07:45 +01:00
|
|
|
notmuch_setup_command (notmuch_database_t *notmuch,
|
2019-05-30 21:56:14 +02:00
|
|
|
int argc, char *argv[])
|
2009-11-11 20:23:55 +01:00
|
|
|
{
|
2009-11-12 02:01:55 +01:00
|
|
|
char *response = NULL;
|
2010-10-14 20:18:19 +02:00
|
|
|
size_t response_size = 0;
|
2009-11-12 02:01:55 +01:00
|
|
|
GPtrArray *other_emails;
|
2021-02-13 18:49:32 +01:00
|
|
|
notmuch_config_values_t *new_tags, *search_exclude_tags, *emails;
|
2021-02-27 15:11:23 +01:00
|
|
|
notmuch_conffile_t *config;
|
2009-11-12 02:01:55 +01:00
|
|
|
|
2019-06-13 12:31:01 +02:00
|
|
|
#define prompt(format, ...) \
|
|
|
|
do { \
|
|
|
|
printf (format, ##__VA_ARGS__); \
|
|
|
|
fflush (stdout); \
|
|
|
|
if (getline (&response, &response_size, stdin) < 0) { \
|
|
|
|
printf ("Exiting.\n"); \
|
|
|
|
exit (EXIT_FAILURE); \
|
|
|
|
} \
|
|
|
|
chomp_newline (response); \
|
2009-11-12 02:01:55 +01:00
|
|
|
} while (0)
|
|
|
|
|
2015-04-05 22:34:55 +02:00
|
|
|
if (notmuch_minimal_options ("setup", argc, argv) < 0)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2021-02-27 15:11:23 +01:00
|
|
|
config = notmuch_conffile_open (notmuch,
|
|
|
|
notmuch_config_path (notmuch), true);
|
2021-02-27 14:22:32 +01:00
|
|
|
if (! config)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2021-02-27 15:11:23 +01:00
|
|
|
if (notmuch_conffile_is_new (config))
|
2009-11-12 02:33:31 +01:00
|
|
|
welcome_message_pre_setup ();
|
2009-11-12 02:01:55 +01:00
|
|
|
|
2021-02-13 18:49:32 +01:00
|
|
|
prompt ("Your full name [%s]: ", notmuch_config_get (notmuch, NOTMUCH_CONFIG_USER_NAME));
|
2009-11-12 02:01:55 +01:00
|
|
|
if (strlen (response))
|
2021-02-27 15:11:23 +01:00
|
|
|
notmuch_conffile_set_user_name (config, response);
|
2009-11-12 02:01:55 +01:00
|
|
|
|
|
|
|
prompt ("Your primary email address [%s]: ",
|
2021-02-13 18:49:32 +01:00
|
|
|
notmuch_config_get (notmuch, NOTMUCH_CONFIG_PRIMARY_EMAIL));
|
2009-11-12 02:01:55 +01:00
|
|
|
if (strlen (response))
|
2021-02-27 15:11:23 +01:00
|
|
|
notmuch_conffile_set_user_primary_email (config, response);
|
2009-11-12 02:01:55 +01:00
|
|
|
|
|
|
|
other_emails = g_ptr_array_new ();
|
|
|
|
|
2021-02-13 18:49:32 +01:00
|
|
|
for (emails = notmuch_config_get_values (notmuch, NOTMUCH_CONFIG_OTHER_EMAIL);
|
|
|
|
notmuch_config_values_valid (emails);
|
|
|
|
notmuch_config_values_move_to_next (emails)) {
|
|
|
|
const char *email = notmuch_config_values_get (emails);
|
|
|
|
|
|
|
|
prompt ("Additional email address [%s]: ", email);
|
2009-11-12 02:01:55 +01:00
|
|
|
if (strlen (response))
|
2013-03-03 22:55:09 +01:00
|
|
|
g_ptr_array_add (other_emails, talloc_strdup (config, response));
|
2009-11-12 02:01:55 +01:00
|
|
|
else
|
2021-02-13 18:49:32 +01:00
|
|
|
g_ptr_array_add (other_emails, talloc_strdup (config, email));
|
2009-11-10 21:03:05 +01:00
|
|
|
}
|
|
|
|
|
2009-11-12 02:01:55 +01:00
|
|
|
do {
|
|
|
|
prompt ("Additional email address [Press 'Enter' if none]: ");
|
|
|
|
if (strlen (response))
|
2013-03-03 22:55:09 +01:00
|
|
|
g_ptr_array_add (other_emails, talloc_strdup (config, response));
|
2009-11-12 02:01:55 +01:00
|
|
|
} while (strlen (response));
|
|
|
|
if (other_emails->len)
|
2021-02-27 15:11:23 +01:00
|
|
|
notmuch_conffile_set_user_other_email (config,
|
|
|
|
(const char **)
|
|
|
|
other_emails->pdata,
|
|
|
|
other_emails->len);
|
2017-10-07 10:44:04 +02:00
|
|
|
g_ptr_array_free (other_emails, true);
|
2009-11-12 02:01:55 +01:00
|
|
|
|
|
|
|
prompt ("Top-level directory of your email archive [%s]: ",
|
2021-02-13 18:49:32 +01:00
|
|
|
notmuch_config_get (notmuch, NOTMUCH_CONFIG_DATABASE_PATH));
|
2009-11-12 02:01:55 +01:00
|
|
|
if (strlen (response)) {
|
|
|
|
const char *absolute_path;
|
|
|
|
|
2013-03-03 22:55:09 +01:00
|
|
|
absolute_path = make_path_absolute (config, response);
|
2021-02-27 15:11:23 +01:00
|
|
|
notmuch_conffile_set_database_path (config, absolute_path);
|
2009-11-10 21:03:05 +01:00
|
|
|
}
|
|
|
|
|
2021-02-13 18:49:32 +01:00
|
|
|
new_tags = notmuch_config_get_values (notmuch, NOTMUCH_CONFIG_NEW_TAGS);
|
2010-04-23 19:30:40 +02:00
|
|
|
|
|
|
|
printf ("Tags to apply to all new messages (separated by spaces) [");
|
2021-02-13 18:49:32 +01:00
|
|
|
print_tag_list (new_tags);
|
2010-04-23 19:30:40 +02:00
|
|
|
prompt ("]: ");
|
|
|
|
|
|
|
|
if (strlen (response)) {
|
2013-03-03 22:55:09 +01:00
|
|
|
GPtrArray *tags = parse_tag_list (config, response);
|
2010-04-23 19:30:40 +02:00
|
|
|
|
2021-02-27 15:11:23 +01:00
|
|
|
notmuch_conffile_set_new_tags (config, (const char **) tags->pdata,
|
|
|
|
tags->len);
|
2010-04-23 19:30:40 +02:00
|
|
|
|
2017-10-07 10:44:04 +02:00
|
|
|
g_ptr_array_free (tags, true);
|
2010-04-23 19:30:40 +02:00
|
|
|
}
|
|
|
|
|
2021-02-13 18:49:32 +01:00
|
|
|
search_exclude_tags = notmuch_config_get_values (notmuch, NOTMUCH_CONFIG_EXCLUDE_TAGS);
|
2012-03-03 13:56:15 +01:00
|
|
|
|
|
|
|
printf ("Tags to exclude when searching messages (separated by spaces) [");
|
2021-02-13 18:49:32 +01:00
|
|
|
print_tag_list (search_exclude_tags);
|
2012-03-03 13:56:15 +01:00
|
|
|
prompt ("]: ");
|
|
|
|
|
|
|
|
if (strlen (response)) {
|
2013-03-03 22:55:09 +01:00
|
|
|
GPtrArray *tags = parse_tag_list (config, response);
|
2012-03-03 13:56:15 +01:00
|
|
|
|
2021-02-27 15:11:23 +01:00
|
|
|
notmuch_conffile_set_search_exclude_tags (config,
|
|
|
|
(const char **) tags->pdata,
|
|
|
|
tags->len);
|
2012-03-03 13:56:15 +01:00
|
|
|
|
2017-10-07 10:44:04 +02:00
|
|
|
g_ptr_array_free (tags, true);
|
2012-03-03 13:56:15 +01:00
|
|
|
}
|
|
|
|
|
2021-02-27 15:11:23 +01:00
|
|
|
if (notmuch_conffile_save (config))
|
2014-01-10 22:28:53 +01:00
|
|
|
return EXIT_FAILURE;
|
2012-01-23 06:40:33 +01:00
|
|
|
|
2021-02-27 14:22:32 +01:00
|
|
|
if (config)
|
2021-02-27 15:11:23 +01:00
|
|
|
notmuch_conffile_close (config);
|
2021-02-27 14:22:32 +01:00
|
|
|
|
2021-02-27 15:11:23 +01:00
|
|
|
if (notmuch_conffile_is_new (config))
|
2014-01-10 22:28:53 +01:00
|
|
|
welcome_message_post_setup ();
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
2009-11-10 21:03:05 +01:00
|
|
|
}
|