2007-05-10 Murray Cumming <murrayc@murrayc.com>
+ * src/modest-account-mgr-helpers.c:
+ (modest_account_mgr_get_server_account_data),
+ (modest_account_mgr_free_server_account_data):
+ * src/modest-account-mgr-helpers.h:
+ * src/modest-account-mgr.c:
+ (modest_account_mgr_add_server_account):
+ * src/modest-defs.h:
+ * src/modest-tny-account.c:
+ (modest_tny_account_new_from_server_account):
+ Determine the options for tny_camel_account_add_option() here,
+ based on the settings, rather than storing them directly in gconf.
+
+2007-05-10 Murray Cumming <murrayc@murrayc.com>
+
* src/modest-tny-account-store.c: (modest_tny_account_store_alert):
Show a more friendly error dialog now that we expect (from the tinymail
documentation) to get the UNKNOWN_ALERT error. Add explanatory comments.
return modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_SIGNATURE, FALSE);
}
-
-
-#if 0 /* Not needed, but works. */
-static gint
-compare_option_strings_for_name (const gchar* a, const gchar* b)
-{
- /* printf(" debug: compare_option_strings_for_name():a=%s, b=%s\n", a, b); */
- const gchar* sep = strchr(a, '=');
- if (!sep)
- return -1;
-
- gint len = sep - a;
- if(len <= 0)
- return -1;
-
- /* Get the part of the string before the =.
- * Note that this allocation is inefficient just so we can do a strcmp. */
- gchar* name = g_malloc (len+1);
- memcpy(name, a, len);
- name[len] = 0; /* Null-termination. */
-
- /* printf(" debug: name=%s\n", name); */
-
- gint result = strcmp (name, b);
-
- g_free (name);
-
- return result;
-}
-
-gchar*
-modest_server_account_data_get_option_string (GSList* options_list, const gchar* option_name)
-{
- if (!options_list)
- return NULL;
-
- gchar *result = NULL;
- GSList* option = g_slist_find_custom(options_list, option_name, (GCompareFunc)compare_option_strings_for_name);
- if(option) {
- /* Get the value part of the key=value pair: */
- const gchar* pair = (const gchar*)option->data;
-
- const gchar* sep = strchr(pair, '=');
- if (sep) {
- gint len = sep - pair;
- if(len > 0) {
- result = g_strdup(sep+1);
-
- /* Avoid returning an empty string instead of NULL. */
- if(result && strlen(result) == 0) {
- g_free(result);
- result = NULL;
- }
- }
- }
- }
-
- return result;
-}
-
-gboolean
-modest_server_account_data_get_option_bool (GSList* options_list, const gchar* option_name)
-{
- if (!options_list)
- return FALSE;
-
- gboolean result = FALSE;
- GSList* option = g_slist_find_custom(options_list, option_name, (GCompareFunc)strcmp);
- if(option) {
- return TRUE;
- }
-
- return result;
-}
-#endif
-
gboolean modest_account_mgr_set_connection_specific_smtp (ModestAccountMgr *self,
const gchar* account_name,
/* Set it in the configuration: */
modest_account_mgr_set_string (self, account_name, MODEST_ACCOUNT_SECURITY, str_value, TRUE);
}
-
-#if 0
-gchar*
-modest_account_mgr_get_server_account_option (ModestAccountMgr *self,
- const gchar* account_name, const gchar* option_name)
-{
- GSList *option_list = modest_account_mgr_get_list (self, account_name, MODEST_ACCOUNT_OPTIONS,
- MODEST_CONF_VALUE_STRING, TRUE);
- if (!option_list)
- return NULL;
-
- gchar *result = modest_server_account_data_get_option_value (option_list, option_name);
-
- /* TODO: Should we free the items too, or just the list? */
- g_slist_free (option_list);
-
- return result;
-}
-#endif
ModestServerAccountData*
modest_account_mgr_get_server_account_data (ModestAccountMgr *self, const gchar* name)
data->last_updated = modest_account_mgr_get_int (self, name, MODEST_ACCOUNT_LAST_UPDATED,TRUE);
data->password = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_PASSWORD, TRUE);
- data->uri = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_URI,TRUE);
- data->options = modest_account_mgr_get_list (self, name, MODEST_ACCOUNT_OPTIONS,
- MODEST_CONF_VALUE_STRING, TRUE);
-
+ data->uri = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_URI,TRUE);
return data;
}
g_free (data->password);
data->password = NULL;
-
- if (data->options) {
- GSList *tmp = data->options;
- while (tmp) {
- g_free (tmp->data);
- tmp = g_slist_next (tmp);
- }
- g_slist_free (data->options);
- }
g_slice_free (ModestServerAccountData, data);
}
gint port; /* Or 0, if the default should be used. */
ModestProtocol secure_auth;
ModestProtocol security;
- GSList *options;
} ModestServerAccountData;
typedef struct {
void
modest_account_mgr_free_server_account_data (ModestAccountMgr *self,
ModestServerAccountData* data);
-
-#if 0
-/**
- * modest_account_mgr_get_account_option:
- * @self: a ModestAccountMgr instance
- * @account_name: the account name to check
- * @account_name: the option name to check
- *
- * Returns: The account option value. This must be freed with g_free().
- */
-gchar* modest_account_mgr_get_server_account_option (ModestAccountMgr *self,
- const gchar* account_name, const gchar* option_name);
-
-/**
- * modest_server_account_data_get_option_value:
- * @options_list: a ModestServerAccountData::options list.
- * @option_name: the option name to check
- *
- * Returns: The account option value. This must be freed with g_free().
- */
-gchar* modest_server_account_data_get_option_string (GSList* options_list, const gchar* option_name);
-
-/**
- * modest_server_account_data_get_option_bool:
- * @options_list: a ModestServerAccountData::options list.
- * @option_name: the option name to check
- *
- * Returns: Whether the account option is present.
- */
-gboolean modest_server_account_data_get_option_bool (GSList* options_list, const gchar* option_name);
-#endif
/**
* modest_account_mgr_get_from_string
goto cleanup;
if (proto_type == MODEST_PROTOCOL_TYPE_STORE) {
-
- GSList *option_list = NULL;
-
- /* Connection options. Some options are only valid for IMAP
- accounts but it's OK for just now since POP is still not
- supported */
- key = _modest_account_mgr_get_account_keyname (name, MODEST_ACCOUNT_OPTIONS, TRUE);
- /* Enable subscriptions and check the mails in all folders */
- option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_USE_LSUB);
- option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_CHECK_ALL);
-
- /* TODO: Remove this hack. These are hard-coded camel options to make the connection work.
- * The regular connection options (set later here) should be interpreted instead
- * because in future these camel options will not be in gconf. murrayc.
- */
- /* Security options */
- switch (security) {
- case MODEST_PROTOCOL_SECURITY_NONE:
- option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_NEVER);
- break;
- case MODEST_PROTOCOL_SECURITY_SSL:
- case MODEST_PROTOCOL_SECURITY_TLS:
- option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_ALWAYS);
- break;
- case MODEST_PROTOCOL_SECURITY_TLS_OP:
- option_list = g_slist_append (option_list, MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE);
- break;
- default:
- g_warning ("Invalid security option");
- }
- ok = modest_conf_set_list (priv->modest_conf, key,
- option_list, MODEST_CONF_VALUE_STRING, &err);
- if (err) {
- g_printerr ("modest: failed to set %s: %s\n", key, err->message);
- g_error_free (err);
- ok = FALSE;
- }
- g_slist_free (option_list);
- g_free (key);
-
-
/* Add the security settings: */
modest_server_account_set_security (self, name, security);
}
#define MODEST_ACCOUNT_LEAVE_ON_SERVER "leave_on_server" /* boolean */
#define MODEST_ACCOUNT_PREFERRED_CNX "preferred_cnx" /* string */
#define MODEST_ACCOUNT_PORT "port" /* int */
-#define MODEST_ACCOUNT_OPTIONS "options" /* list */
#define MODEST_ACCOUNT_AUTH_MECH "auth_mech" /* string */
#define MODEST_ACCOUNT_AUTH_MECH_VALUE_NONE "none"
#define MODEST_ACCOUNT_SECURITY_VALUE_NORMAL "normal"
#define MODEST_ACCOUNT_SECURITY_VALUE_SSL "ssl"
-
-/* Options keys that correspond directly to camel options.
- * These probably should not be written to user configuration,
- * because they are specific API implementation details. */
-/* Keys and values used in the text items in the options GSList: */
-#define MODEST_ACCOUNT_OPTION_SSL "use_ssl"
-#define MODEST_ACCOUNT_OPTION_SSL_NEVER "never"
-#define MODEST_ACCOUNT_OPTION_SSL_ALWAYS "always"
-#define MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE "when-possible"
-
-#define MODEST_ACCOUNT_OPTION_USE_LSUB "use_lsub"
-#define MODEST_ACCOUNT_OPTION_CHECK_ALL "check_all"
-
/* Macros for different text formats in mail editor */
#define MODEST_FILE_FORMAT_PLAIN_TEXT 0
#define MODEST_FILE_FORMAT_FORMATTED_TEXT 1
return special_folder;
}
+/* Camel options: */
+#define MODEST_ACCOUNT_OPTION_SSL "use_ssl"
+#define MODEST_ACCOUNT_OPTION_SSL_NEVER "never"
+#define MODEST_ACCOUNT_OPTION_SSL_ALWAYS "always"
+#define MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE "when-possible"
+#define MODEST_ACCOUNT_OPTION_USE_LSUB "use_lsub"
+#define MODEST_ACCOUNT_OPTION_CHECK_ALL "check_all"
/**
* modest_tny_account_new_from_server_account:
if (account_data->uri)
tny_account_set_url_string (TNY_ACCOUNT(tny_account), account_data->uri);
else {
- if (account_data->options) {
- GSList *options = account_data->options;
- while (options) {
- tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (tny_account),
- options->data);
- options = g_slist_next (options);
- }
+ const gchar* option_security = NULL;
+ switch (account_data->security) {
+ case MODEST_PROTOCOL_SECURITY_NONE:
+ option_security = MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_NEVER;
+ break;
+ case MODEST_PROTOCOL_SECURITY_SSL:
+ case MODEST_PROTOCOL_SECURITY_TLS:
+ option_security = MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_ALWAYS;;
+ break;
+ case MODEST_PROTOCOL_SECURITY_TLS_OP:
+ option_security = MODEST_ACCOUNT_OPTION_SSL "= " MODEST_ACCOUNT_OPTION_SSL_WHEN_POSSIBLE;
+ break;
+ default:
+ break;
}
+
+ if(option_security) {
+ tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (tny_account),
+ option_security);
+ }
+
+ if (account_data->proto == MODEST_PROTOCOL_TYPE_STORE) {
+ /* Connection options. Some options are only valid for IMAP
+ accounts but it's OK for just now since POP is still not
+ supported */
+ tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (tny_account),
+ MODEST_ACCOUNT_OPTION_USE_LSUB);
+ tny_camel_account_add_option (TNY_CAMEL_ACCOUNT (tny_account),
+ MODEST_ACCOUNT_OPTION_CHECK_ALL);
+ }
+
if (account_data->username)
tny_account_set_user (tny_account, account_data->username);
if (account_data->hostname)