+
+ModestProtocol
+modest_server_account_data_get_option_secure_auth (ModestServerAccountData *account_data)
+{
+ ModestProtocol result = MODEST_PROTOCOL_AUTH_NONE;
+ gchar* value = modest_server_account_data_get_option_value (account_data->options,
+ MODEST_ACCOUNT_OPTION_SECURE_AUTH);
+ if (value) {
+ if (strcmp(value, MODEST_ACCOUNT_OPTION_SECURE_AUTH_VALUE_NONE) == 0)
+ result = MODEST_PROTOCOL_AUTH_NONE;
+ else if (strcmp(value, MODEST_ACCOUNT_OPTION_SECURE_AUTH_VALUE_PASSWORD) == 0)
+ result = MODEST_PROTOCOL_AUTH_PASSWORD;
+ else if (strcmp(value, MODEST_ACCOUNT_OPTION_SECURE_AUTH_VALUE_CRAMMD5) == 0)
+ result = MODEST_PROTOCOL_AUTH_CRAMMD5;
+
+ g_free (value);
+ }
+
+ return result;
+}
+
+void
+modest_server_account_set_option_secure_auth (ModestAccountMgr *self,
+ const gchar* account_name, ModestProtocol secure_auth)
+{
+ GSList *options_list = modest_account_mgr_get_list (self, account_name, MODEST_ACCOUNT_OPTIONS,
+ MODEST_CONF_VALUE_STRING, TRUE);
+ if(options_list) {
+ /* Remove the item if it exists already: */
+ GSList* option = NULL;
+ do {
+ option = g_slist_find_custom(options_list, MODEST_ACCOUNT_OPTION_SECURE_AUTH, (GCompareFunc)compare_option_strings_for_name);
+ if(option)
+ options_list = g_slist_remove (options_list, option->data);
+ } while (option);
+ }
+
+ /* Add the new item to the list: */
+ const gchar* str_value = NULL;
+ if (secure_auth == MODEST_PROTOCOL_AUTH_NONE)
+ str_value = MODEST_ACCOUNT_OPTION_SECURE_AUTH_VALUE_NONE;
+ else if (secure_auth == MODEST_PROTOCOL_AUTH_PASSWORD)
+ str_value = MODEST_ACCOUNT_OPTION_SECURE_AUTH_VALUE_PASSWORD;
+ else if (secure_auth == MODEST_PROTOCOL_AUTH_CRAMMD5)
+ str_value = MODEST_ACCOUNT_OPTION_SECURE_AUTH_VALUE_CRAMMD5;
+
+ if (str_value) {
+ gchar* pair = g_strdup_printf(MODEST_ACCOUNT_OPTION_SECURE_AUTH "=%s", str_value);
+ options_list = g_slist_append(options_list, pair);
+ }
+
+ /* Set it in the configuration: */
+ modest_account_mgr_set_list (self, account_name, MODEST_ACCOUNT_OPTIONS, options_list,
+ MODEST_CONF_VALUE_STRING, TRUE);
+
+ /* TODO: Should we free the items too, or just the list? */
+ g_slist_free (options_list);
+}
+
+ModestProtocol
+modest_server_account_data_get_option_security (ModestServerAccountData *account_data)
+{
+ ModestProtocol result = MODEST_PROTOCOL_SECURITY_NONE;
+ gchar* value = modest_server_account_data_get_option_value (account_data->options,
+ MODEST_ACCOUNT_OPTION_SECURITY);
+ if (value) {
+ if (strcmp(value, MODEST_ACCOUNT_OPTION_SECURITY_VALUE_NONE) == 0)
+ result = MODEST_PROTOCOL_SECURITY_NONE;
+ else if (strcmp(value, MODEST_ACCOUNT_OPTION_SECURITY_VALUE_NORMAL) == 0)
+ result = MODEST_PROTOCOL_SECURITY_TLS;
+ else if (strcmp(value, MODEST_ACCOUNT_OPTION_SECURITY_VALUE_SSL) == 0)
+ result = MODEST_PROTOCOL_SECURITY_SSL;
+
+ g_free (value);
+ }
+
+ return result;
+}
+
+void
+modest_server_account_set_option_security (ModestAccountMgr *self,
+ const gchar* account_name, ModestProtocol security)
+{
+ GSList *options_list = modest_account_mgr_get_list (self, account_name, MODEST_ACCOUNT_OPTIONS,
+ MODEST_CONF_VALUE_STRING, TRUE);
+
+ if(options_list) {
+ /* Remove the item if it exists already: */
+ GSList* option = NULL;
+ do {
+ g_slist_find_custom(options_list, MODEST_ACCOUNT_OPTION_SECURITY, (GCompareFunc)compare_option_strings_for_name);
+ if(option)
+ options_list = g_slist_remove (options_list, option->data);
+ } while(option);
+ }
+
+ /* Add the new item to the list: */
+ const gchar* str_value = NULL;
+ if (security == MODEST_PROTOCOL_SECURITY_NONE)
+ str_value = MODEST_ACCOUNT_OPTION_SECURITY_VALUE_NONE;
+ else if (security == MODEST_PROTOCOL_SECURITY_TLS)
+ str_value = MODEST_ACCOUNT_OPTION_SECURITY_VALUE_NORMAL;
+ else if (security == MODEST_PROTOCOL_SECURITY_SSL)
+ str_value = MODEST_ACCOUNT_OPTION_SECURITY_VALUE_SSL;
+
+ if (str_value) {
+ gchar* pair = g_strdup_printf(MODEST_ACCOUNT_OPTION_SECURITY "=%s", str_value);
+ options_list = g_slist_append(options_list, pair);
+ }
+
+ /* Set it in the configuration: */
+ modest_account_mgr_set_list (self, account_name, MODEST_ACCOUNT_OPTIONS, options_list,
+ MODEST_CONF_VALUE_STRING, TRUE);
+
+ /* TODO: Should we free the items too, or just the list? */
+ g_slist_free (options_list);
+}