From c8da8bc79ca63dd3f4a28ba85b5816d756fe3b46 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Fri, 2 Nov 2012 23:50:53 +0100 Subject: [PATCH] Have the proper configuration loaded when initializing accounts --- src/account.c | 16 ++++++++++------ src/mailer.c | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/account.c b/src/account.c index f0c9007..c2c4dc8 100644 --- a/src/account.c +++ b/src/account.c @@ -134,7 +134,9 @@ Account * account_new(Mailer * mailer, char const * type, char const * title, account->plugin = plugin_new(LIBDIR, PACKAGE, "account", type); account->definition = (account->plugin != NULL) ? plugin_lookup(account->plugin, "account_plugin") : NULL; + /* check for errors */ if(account->type == NULL || account->plugin == NULL + || (title != NULL && account->title == NULL) || account->definition == NULL || account->definition->init == NULL || account->definition->destroy == NULL @@ -258,9 +260,9 @@ int account_config_load(Account * account, Config * config) long l; #ifdef DEBUG - fprintf(stderr, "DEBUG: account_config_load(%p)\n", (void*)config); + fprintf(stderr, "DEBUG: %s(%p)\n", __func__, (void *)config); #endif - if(p == NULL) + if(p == NULL || account->title == NULL) return 0; for(; p->name != NULL; p++) { @@ -279,7 +281,7 @@ int account_config_load(Account * account, Config * config) case ACT_UINT16: l = strtol(value, &q, 0); if(value[0] != '\0' && *q == '\0') - p->value = (void*)l; + p->value = (void *)l; break; case ACT_BOOLEAN: p->value = (strcmp(value, "yes") == 0 @@ -303,8 +305,10 @@ int account_config_save(Account * account, Config * config) char buf[6]; #ifdef DEBUG - fprintf(stderr, "DEBUG: account_config_save(%p)\n", (void*)config); + fprintf(stderr, "DEBUG: account_config_save(%p)\n", (void *)config); #endif + if(account->title == NULL) + return 0; if(config_set(config, account->title, "type", account->type) != 0) return 1; if(p == NULL) @@ -347,7 +351,7 @@ int account_config_save(Account * account, Config * config) int account_init(Account * account) { #ifdef DEBUG - fprintf(stderr, "DEBUG: %s(%p)\n", __func__, (void*)account); + fprintf(stderr, "DEBUG: %s(%p)\n", __func__, (void *)account); #endif return (account->account = account->definition->init(&account->helper)) != NULL ? 0 : -1; @@ -387,7 +391,7 @@ GtkTextBuffer * account_select_source(Account * account, Folder * folder, #ifdef DEBUG fprintf(stderr, "DEBUG: %s(\"%s\", %p)\n", __func__, - folder_get_name(folder), (void*)message); + folder_get_name(folder), (void *)message); #endif if(account->definition->get_source == NULL) return NULL; diff --git a/src/mailer.c b/src/mailer.c index a426909..6279986 100644 --- a/src/mailer.c +++ b/src/mailer.c @@ -3083,12 +3083,12 @@ static int _mailer_config_load_account(Mailer * mailer, char const * name) if((account = account_new(mailer, type, name, mailer->fo_store)) == NULL) return -mailer_error(mailer, error_get(), 1); - if(mailer_account_add(mailer, account) != 0) + if(account_config_load(account, mailer->config) != 0 + || mailer_account_add(mailer, account) != 0) { account_delete(account); return -1; } - account_config_load(account, mailer->config); return 0; }