notmuch_config_open will be preserved in the medium term for use by the commands that are manipulating the config file directly (config and setup) --- lib/config.cc | 5 +- notmuch-client.h | 2 +- notmuch-config.c | 157 +---------------------------------------- notmuch.c | 2 +- test/T030-config.sh | 2 +- test/T590-libconfig.sh | 12 ++-- 6 files changed, 15 insertions(+), 165 deletions(-)
diff --git a/lib/config.cc b/lib/config.cc index 03ba2731..44cbe711 100644 --- a/lib/config.cc +++ b/lib/config.cc @@ -575,7 +575,7 @@ _notmuch_config_default (notmuch_database_t *notmuch, notmuch_config_key_t key) case NOTMUCH_CONFIG_EXCLUDE_TAGS: return ""; case NOTMUCH_CONFIG_NEW_TAGS: - return "inbox;unread"; + return "unread;inbox"; case NOTMUCH_CONFIG_SYNC_MAILDIR_FLAGS: return "true"; case NOTMUCH_CONFIG_USER_NAME: @@ -592,9 +592,10 @@ _notmuch_config_default (notmuch_database_t *notmuch, notmuch_config_key_t key) else email = _get_email_from_passwd_file (notmuch); return email; + case NOTMUCH_CONFIG_NEW_IGNORE: + return ""; case NOTMUCH_CONFIG_HOOK_DIR: case NOTMUCH_CONFIG_BACKUP_DIR: - case NOTMUCH_CONFIG_NEW_IGNORE: case NOTMUCH_CONFIG_OTHER_EMAIL: return NULL; default: diff --git a/notmuch-client.h b/notmuch-client.h index db88daf8..dfdfc876 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -262,7 +262,7 @@ typedef enum { } notmuch_command_mode_t; notmuch_config_t * -notmuch_config_open (void *ctx, +notmuch_config_open (notmuch_database_t *notmuch, const char *filename, notmuch_command_mode_t config_mode); diff --git a/notmuch-config.c b/notmuch-config.c index f46e5c27..3d0959fb 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -141,69 +141,6 @@ notmuch_config_destructor (notmuch_config_t *config) return 0; } -static char * -get_name_from_passwd_file (void *ctx) -{ - long pw_buf_size; - char *pw_buf; - struct passwd passwd, *ignored; - char *name; - int e; - - pw_buf_size = sysconf (_SC_GETPW_R_SIZE_MAX); - if (pw_buf_size == -1) pw_buf_size = 64; - pw_buf = talloc_size (ctx, pw_buf_size); - - while ((e = getpwuid_r (getuid (), &passwd, pw_buf, - pw_buf_size, &ignored)) == ERANGE) { - pw_buf_size = pw_buf_size * 2; - pw_buf = talloc_zero_size (ctx, pw_buf_size); - } - - if (e == 0) { - char *comma = strchr (passwd.pw_gecos, ','); - if (comma) - name = talloc_strndup (ctx, passwd.pw_gecos, - comma - passwd.pw_gecos); - else - name = talloc_strdup (ctx, passwd.pw_gecos); - } else { - name = talloc_strdup (ctx, ""); - } - - talloc_free (pw_buf); - - return name; -} - -static char * -get_username_from_passwd_file (void *ctx) -{ - long pw_buf_size; - char *pw_buf; - struct passwd passwd, *ignored; - char *name; - int e; - - pw_buf_size = sysconf (_SC_GETPW_R_SIZE_MAX); - if (pw_buf_size == -1) pw_buf_size = 64; - pw_buf = talloc_zero_size (ctx, pw_buf_size); - - while ((e = getpwuid_r (getuid (), &passwd, pw_buf, - pw_buf_size, &ignored)) == ERANGE) { - pw_buf_size = pw_buf_size * 2; - pw_buf = talloc_zero_size (ctx, pw_buf_size); - } - - if (e == 0) - name = talloc_strdup (ctx, passwd.pw_name); - else - name = talloc_strdup (ctx, ""); - - talloc_free (pw_buf); - - return name; -} static bool get_config_from_file (notmuch_config_t *config, bool create_new) @@ -322,12 +259,10 @@ get_config_from_file (notmuch_config_t *config, bool create_new) * user in editing the file directly. */ notmuch_config_t * -notmuch_config_open (void *ctx, +notmuch_config_open (notmuch_database_t *notmuch, const char *filename, notmuch_command_mode_t config_mode) { - GError *error = NULL; - size_t tmp; char *notmuch_config_env = NULL; int file_had_database_group; int file_had_new_group; @@ -336,7 +271,7 @@ notmuch_config_open (void *ctx, int file_had_search_group; int file_had_crypto_group; - notmuch_config_t *config = talloc_zero (ctx, notmuch_config_t); + notmuch_config_t *config = talloc_zero (notmuch, notmuch_config_t); if (config == NULL) { fprintf (stderr, "Out of memory.\n"); @@ -368,15 +303,10 @@ notmuch_config_open (void *ctx, } } + /* Whenever we know of configuration sections that don't appear in * the configuration file, we add some comments to help the user * understand what can be done. - * - * It would be convenient to just add those comments now, but - * apparently g_key_file will clear any comments when keys are - * added later that create the groups. So we have to check for the - * groups now, but add the comments only after setting all of our - * values. */ file_had_database_group = g_key_file_has_group (config->key_file, "database"); @@ -386,87 +316,6 @@ notmuch_config_open (void *ctx, file_had_search_group = g_key_file_has_group (config->key_file, "search"); file_had_crypto_group = g_key_file_has_group (config->key_file, "crypto"); - if (notmuch_config_get_database_path (config) == NULL) { - char *path = getenv ("MAILDIR"); - if (path) - path = talloc_strdup (config, path); - else - path = talloc_asprintf (config, "%s/mail", - getenv ("HOME")); - notmuch_config_set_database_path (config, path); - talloc_free (path); - } - - if (notmuch_config_get_user_name (config) == NULL) { - char *name = getenv ("NAME"); - if (name) - name = talloc_strdup (config, name); - else - name = get_name_from_passwd_file (config); - notmuch_config_set_user_name (config, name); - talloc_free (name); - } - - if (notmuch_config_get_user_primary_email (config) == NULL) { - char *email = getenv ("EMAIL"); - if (email) { - notmuch_config_set_user_primary_email (config, email); - } else { - char hostname[256]; - struct hostent *hostent; - const char *domainname; - - char *username = get_username_from_passwd_file (config); - - gethostname (hostname, 256); - hostname[255] = '\0'; - - hostent = gethostbyname (hostname); - if (hostent && (domainname = strchr (hostent->h_name, '.'))) - domainname += 1; - else - domainname = "(none)"; - - email = talloc_asprintf (config, "%s@%s.%s", - username, hostname, domainname); - - notmuch_config_set_user_primary_email (config, email); - - talloc_free (username); - talloc_free (email); - } - } - - if (notmuch_config_get_new_tags (config, &tmp) == NULL) { - const char *tags[] = { "unread", "inbox" }; - notmuch_config_set_new_tags (config, tags, 2); - } - - if (notmuch_config_get_new_ignore (config, &tmp) == NULL) { - notmuch_config_set_new_ignore (config, NULL, 0); - } - - if (notmuch_config_get_search_exclude_tags (config, &tmp) == NULL) { - if (config->is_new) { - const char *tags[] = { "deleted", "spam" }; - notmuch_config_set_search_exclude_tags (config, tags, 2); - } else { - notmuch_config_set_search_exclude_tags (config, NULL, 0); - } - } - - error = NULL; - config->maildir_synchronize_flags = - g_key_file_get_boolean (config->key_file, - "maildir", "synchronize_flags", &error); - if (error) { - notmuch_config_set_maildir_synchronize_flags (config, true); - g_error_free (error); - } - - /* Whenever we know of configuration sections that don't appear in - * the configuration file, we add some comments to help the user - * understand what can be done. */ if (config->is_new) g_key_file_set_comment (config->key_file, NULL, NULL, toplevel_config_comment, NULL); diff --git a/notmuch.c b/notmuch.c index 7beeb177..093af0a5 100644 --- a/notmuch.c +++ b/notmuch.c @@ -577,7 +577,7 @@ main (int argc, char *argv[]) } if (command->mode & NOTMUCH_COMMAND_CONFIG_OPEN) { - config = notmuch_config_open (local, config_file_name, command->mode); + config = notmuch_config_open (notmuch, config_file_name, command->mode); if (! config) { ret = EXIT_FAILURE; goto DONE; diff --git a/test/T030-config.sh b/test/T030-config.sh index d974850f..9a43c1e4 100755 --- a/test/T030-config.sh +++ b/test/T030-config.sh @@ -57,7 +57,7 @@ foo.list=this;is another;list value; foo.string=this is another string value maildir.synchronize_flags=true new.ignore= -new.tags=unread;inbox; +new.tags=unread;inbox search.exclude_tags= user.name=Notmuch Test Suite user.other_email=test_suite_ot...@notmuchmail.org;test_su...@otherdomain.org diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh index cf294d04..75b47073 100755 --- a/test/T590-libconfig.sh +++ b/test/T590-libconfig.sh @@ -394,8 +394,8 @@ MAIL_DIR MAIL_DIR/.notmuch/hooks MAIL_DIR/.notmuch/backups -inbox;unread -NULL +unread;inbox + true USERNAME@FQDN NULL @@ -705,7 +705,7 @@ MAIL_DIR MAIL_DIR/.notmuch/hooks MAIL_DIR/.notmuch/backups foo;bar;fub -unread;inbox; +unread;inbox sekrit_junk true test_su...@notmuchmail.org @@ -736,8 +736,8 @@ MAIL_DIR MAIL_DIR/.notmuch/hooks MAIL_DIR/.notmuch/backups -inbox;unread -NULL +unread;inbox + true USERNAME@FQDN NULL @@ -815,7 +815,7 @@ database.path MAIL_DIR key with spaces value, with, spaces! maildir.synchronize_flags true new.ignore sekrit_junk -new.tags unread;inbox; +new.tags unread;inbox search.exclude_tags foo;bar;fub test.key1 testvalue1 test.key2 testvalue2 -- 2.30.0 _______________________________________________ notmuch mailing list -- notmuch@notmuchmail.org To unsubscribe send an email to notmuch-le...@notmuchmail.org