/* Handle the case of "notmuch" being invoked with no command * argument. For now we just call notmuch_setup_command, but we plan * to be more clever about this in the future. */ static int notmuch (void *ctx) { notmuch_config_t *config; notmuch_bool_t is_new; char *db_path; struct stat st; config = notmuch_config_open (ctx, NULL, &is_new); /* If the user has never configured notmuch, then run * notmuch_setup_command which will give a nice welcome message, * and interactively guide the user through the configuration. */ if (is_new) { notmuch_config_close (config); return notmuch_setup_command (ctx, 0, NULL); } /* Notmuch is already configured, but is there a database? */ db_path = talloc_asprintf (ctx, "%s/%s", notmuch_config_get_database_path (config), ".notmuch"); if (stat (db_path, &st)) { notmuch_config_close (config); if (errno != ENOENT) { fprintf (stderr, "Error looking for notmuch database at %s: %s\n", db_path, strerror (errno)); return 1; } printf ("Notmuch is configured, but there's not yet a database at\n\n\t%s\n\n", db_path); printf ("You probably want to run \"notmuch new\" now to create that database.\n\n" "Note that the first run of \"notmuch new\" can take a very long time\n" "and that the resulting database will use roughly the same amount of\n" "storage space as the email being indexed.\n\n"); return 0; } printf ("Notmuch is configured and appears to have a database. Excellent!\n\n" "At this point you can start exploring the functionality of notmuch by\n" "using commands such as:\n\n" "\tnotmuch search tag:inbox\n\n" "\tnotmuch search to:\"%s\"\n\n" "\tnotmuch search from:\"%s\"\n\n" "\tnotmuch search subject:\"my favorite things\"\n\n" "See \"notmuch help search\" for more details.\n\n" "You can also use \"notmuch show\" with any of the thread IDs resulting\n" "from a search. Finally, you may want to explore using a more sophisticated\n" "interface to notmuch such as the emacs interface implemented in notmuch.el\n" "or any other interface described at http://notmuchmail.org\n\n" "And don't forget to run \"notmuch new\" whenever new mail arrives.\n\n" "Have fun, and may your inbox never have much mail.\n\n", notmuch_config_get_user_name (config), notmuch_config_get_user_primary_email (config)); notmuch_config_close (config); return 0; }
static int notmuch_config_command_get (void *ctx, char *item) { notmuch_config_t *config; config = notmuch_config_open (ctx, NULL, NULL); if (config == NULL) return 1; if (strcmp(item, "database.path") == 0) { printf ("%s\n", notmuch_config_get_database_path (config)); } else if (strcmp(item, "user.name") == 0) { printf ("%s\n", notmuch_config_get_user_name (config)); } else if (strcmp(item, "user.primary_email") == 0) { printf ("%s\n", notmuch_config_get_user_primary_email (config)); } else if (strcmp(item, "user.other_email") == 0) { const char **other_email; size_t i, length; other_email = notmuch_config_get_user_other_email (config, &length); for (i = 0; i < length; i++) printf ("%s\n", other_email[i]); } else if (strcmp(item, "new.tags") == 0) { const char **tags; size_t i, length; tags = notmuch_config_get_new_tags (config, &length); for (i = 0; i < length; i++) printf ("%s\n", tags[i]); } else { char **value; size_t i, length; char *group, *key; if (_item_split (item, &group, &key)) return 1; value = g_key_file_get_string_list (config->key_file, group, key, &length, NULL); if (value == NULL) { fprintf (stderr, "Unknown configuration item: %s.%s\n", group, key); return 1; } for (i = 0; i < length; i++) printf ("%s\n", value[i]); g_strfreev (value); } notmuch_config_close (config); return 0; }
static int notmuch_config_command_list (void *ctx) { notmuch_config_t *config; char **groups; size_t g, groups_length; config = notmuch_config_open (ctx, NULL, NULL); if (config == NULL) return 1; groups = g_key_file_get_groups (config->key_file, &groups_length); if (groups == NULL) return 1; for (g = 0; g < groups_length; g++) { char **keys; size_t k, keys_length; keys = g_key_file_get_keys (config->key_file, groups[g], &keys_length, NULL); if (keys == NULL) continue; for (k = 0; k < keys_length; k++) { char *value; value = g_key_file_get_string (config->key_file, groups[g], keys[k], NULL); if (value != NULL) { printf ("%s.%s=%s\n", groups[g], keys[k], value); free (value); } } g_strfreev (keys); } g_strfreev (groups); notmuch_config_close (config); return 0; }
static int notmuch_config_command_set (void *ctx, char *item, int argc, char *argv[]) { notmuch_config_t *config; char *group, *key; int ret; if (_item_split (item, &group, &key)) return 1; config = notmuch_config_open (ctx, NULL, NULL); if (config == NULL) return 1; /* With only the name of an item, we clear it from the * configuration file. * * With a single value, we set it as a string. * * With multiple values, we set them as a string list. */ switch (argc) { case 0: g_key_file_remove_key (config->key_file, group, key, NULL); break; case 1: g_key_file_set_string (config->key_file, group, key, argv[0]); break; default: g_key_file_set_string_list (config->key_file, group, key, (const gchar **) argv, argc); break; } ret = notmuch_config_save (config); notmuch_config_close (config); return ret; }