- 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;
+ notmuch_config_t *config;
+ char **old_other_emails;
+ size_t old_other_emails_len;
+ GPtrArray *other_emails;
+ unsigned int i;
+
+#define prompt(format, ...) \
+ do { \
+ printf (format, ##__VA_ARGS__); \
+ fflush (stdout); \
+ getline (&response, &response_size, stdin); \
+ chomp_newline (response); \
+ } while (0)
+
+ config = notmuch_config_open (ctx, NULL);
+
+ 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]));