+ char *response = NULL;
+ size_t response_size = 0;
+ GPtrArray *other_emails;
+ notmuch_config_values_t *new_tags, *search_exclude_tags, *emails;
+ notmuch_conffile_t *config;
+
+#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); \
+ } while (0)
+
+ if (notmuch_minimal_options ("setup", argc, argv) < 0)
+ return EXIT_FAILURE;
+
+ config = notmuch_conffile_open (notmuch,
+ notmuch_config_path (notmuch), true);
+ if (! config)
+ return EXIT_FAILURE;
+
+ if (notmuch_conffile_is_new (config))
+ welcome_message_pre_setup ();
+
+ prompt ("Your full name [%s]: ", notmuch_config_get (notmuch, NOTMUCH_CONFIG_USER_NAME));
+ if (strlen (response))
+ notmuch_conffile_set_user_name (config, response);
+
+ prompt ("Your primary email address [%s]: ",
+ notmuch_config_get (notmuch, NOTMUCH_CONFIG_PRIMARY_EMAIL));
+ if (strlen (response))
+ notmuch_conffile_set_user_primary_email (config, response);
+
+ other_emails = g_ptr_array_new ();
+
+ 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);
+ if (strlen (response))
+ g_ptr_array_add (other_emails, talloc_strdup (config, response));
+ else
+ g_ptr_array_add (other_emails, talloc_strdup (config, email));
+ }
+
+ do {
+ prompt ("Additional email address [Press 'Enter' if none]: ");
+ if (strlen (response))
+ g_ptr_array_add (other_emails, talloc_strdup (config, response));
+ } while (strlen (response));
+ if (other_emails->len)
+ notmuch_conffile_set_user_other_email (config,
+ (const char **)
+ other_emails->pdata,
+ other_emails->len);
+ g_ptr_array_free (other_emails, true);
+
+ prompt ("Top-level directory of your email archive [%s]: ",
+ notmuch_config_get (notmuch, NOTMUCH_CONFIG_DATABASE_PATH));
+ if (strlen (response)) {
+ const char *absolute_path;
+
+ absolute_path = make_path_absolute (config, response);
+ notmuch_conffile_set_database_path (config, absolute_path);
+ }