- notmuch_database_t *notmuch = NULL;
- char *mail_directory = NULL;
- int count;
- notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
-
- welcome_message ();
-
- mail_directory = prompt_user_for_mail_directory ();
-
- notmuch = notmuch_database_create (mail_directory);
- if (notmuch == NULL) {
- fprintf (stderr, "Failed to create new notmuch database at %s\n",
- mail_directory);
- ret = NOTMUCH_STATUS_FILE_ERROR;
- goto DONE;
+ char *response = NULL;
+ size_t response_size = 0;
+ notmuch_config_t *config;
+ const char **old_other_emails;
+ size_t old_other_emails_len;
+ GPtrArray *other_emails;
+ unsigned int i;
+ int is_new;
+ const char **new_tags;
+ size_t new_tags_len;
+
+#define prompt(format, ...) \
+ do { \
+ printf (format, ##__VA_ARGS__); \
+ fflush (stdout); \
+ if (getline (&response, &response_size, stdin) < 0) { \
+ printf ("Exiting.\n"); \
+ exit (1); \
+ } \
+ chomp_newline (response); \
+ } while (0)
+
+ config = notmuch_config_open (ctx, NULL, &is_new);
+
+ if (is_new)
+ welcome_message_pre_setup ();
+
+ prompt ("Your full name [%s]: ", notmuch_config_get_user_name (config));
+ if (strlen (response))
+ notmuch_config_set_user_name (config, response);
+
+ prompt ("Your primary email address [%s]: ",
+ notmuch_config_get_user_primary_email (config));
+ if (strlen (response))
+ notmuch_config_set_user_primary_email (config, response);
+
+ other_emails = g_ptr_array_new ();
+
+ old_other_emails = notmuch_config_get_user_other_email (config,
+ &old_other_emails_len);
+ for (i = 0; i < old_other_emails_len; i++) {
+ prompt ("Additional email address [%s]: ", old_other_emails[i]);
+ if (strlen (response))
+ g_ptr_array_add (other_emails, talloc_strdup (ctx, response));
+ else
+ g_ptr_array_add (other_emails, talloc_strdup (ctx,
+ old_other_emails[i]));