+ return result;
+}
+
+gchar*
+modest_account_mgr_get_server_account_username (ModestAccountMgr *self, const gchar* account_name)
+{
+ return modest_account_mgr_get_string (self, account_name, MODEST_ACCOUNT_USERNAME,
+ TRUE /* server account */);
+}
+
+void
+modest_account_mgr_set_server_account_username (ModestAccountMgr *self, const gchar* account_name,
+ const gchar* username)
+{
+ /* Note that this won't work properly as long as the gconf cache is broken
+ * in Maemo Bora: */
+ gchar *existing_username = modest_account_mgr_get_server_account_username(self,
+ account_name);
+
+ modest_account_mgr_set_string (self, account_name, MODEST_ACCOUNT_USERNAME,
+ username, TRUE /* server account */);
+
+ /* We don't know anything about new usernames: */
+ if (strcmp (existing_username, username) != 0)
+ modest_account_mgr_set_server_account_username_has_succeeded (self, account_name, FALSE);
+
+ g_free (existing_username);
+}
+
+gboolean
+modest_account_mgr_get_server_account_username_has_succeeded (ModestAccountMgr *self, const gchar* account_name)
+{
+ return modest_account_mgr_get_bool (self, account_name, MODEST_ACCOUNT_USERNAME_HAS_SUCCEEDED,
+ TRUE /* server account */);
+}
+
+void
+modest_account_mgr_set_server_account_username_has_succeeded (ModestAccountMgr *self,
+ const gchar* account_name,
+ gboolean succeeded)
+{
+ modest_account_mgr_set_bool (self, account_name, MODEST_ACCOUNT_USERNAME_HAS_SUCCEEDED,
+ succeeded, TRUE /* server account */);
+}
+
+gchar*
+modest_account_mgr_get_server_account_password (ModestAccountMgr *self, const gchar* account_name)
+{
+ return modest_account_mgr_get_string (self, account_name, MODEST_ACCOUNT_PASSWORD,
+ TRUE /* server account */);
+}
+
+gboolean
+modest_account_mgr_get_server_account_has_password (ModestAccountMgr *self, const gchar* account_name)
+{
+ gboolean result = FALSE;
+ gchar *password = modest_account_mgr_get_string (self, account_name, MODEST_ACCOUNT_PASSWORD,
+ TRUE /* server account */);
+ if (password && strlen (password)) {
+ result = TRUE;
+
+ /* Clean password */
+ bzero (password, strlen (password));
+ }
+
+ g_free (password);
+ return result;
+}
+
+
+gchar*
+modest_account_mgr_get_server_account_hostname (ModestAccountMgr *self,
+ const gchar* account_name)
+{
+ return modest_account_mgr_get_string (self,
+ account_name,
+ MODEST_ACCOUNT_HOSTNAME,
+ TRUE /* server account */);
+}
+
+void
+modest_account_mgr_set_server_account_hostname (ModestAccountMgr *self,
+ const gchar *server_account_name,
+ const gchar *hostname)
+{
+ modest_account_mgr_set_string (self,
+ server_account_name,
+ MODEST_ACCOUNT_HOSTNAME,
+ hostname,
+ TRUE /* server account */);
+}
+
+
+
+ModestProtocolType
+modest_account_mgr_get_server_account_secure_auth (ModestAccountMgr *self,
+ const gchar* account_name)
+{
+ ModestProtocolRegistry *protocol_registry;
+ ModestProtocolType result = MODEST_PROTOCOLS_AUTH_NONE;
+ gchar* value;
+
+ protocol_registry = modest_runtime_get_protocol_registry ();
+ value = modest_account_mgr_get_string (self, account_name, MODEST_ACCOUNT_AUTH_MECH,
+ TRUE /* server account */);
+ if (value) {
+ ModestProtocol *protocol;
+
+ protocol = modest_protocol_registry_get_protocol_by_name (protocol_registry, MODEST_PROTOCOL_REGISTRY_AUTH_PROTOCOLS, value);
+ g_free (value);
+
+ if (protocol)
+ result = modest_protocol_get_type_id (protocol);
+
+ }
+
+ return result;
+}
+
+
+void
+modest_account_mgr_set_server_account_secure_auth (ModestAccountMgr *self,
+ const gchar* account_name, ModestProtocolType secure_auth)
+{
+ const gchar* str_value;
+ ModestProtocolRegistry *protocol_registry;
+ ModestProtocol *protocol;
+
+ /* Get the conf string for the protocol: */
+ protocol_registry = modest_runtime_get_protocol_registry ();
+ protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, secure_auth);
+ str_value = modest_protocol_get_name (protocol);
+
+ /* Set it in the configuration: */
+ modest_account_mgr_set_string (self, account_name, MODEST_ACCOUNT_AUTH_MECH, str_value, TRUE);
+}
+
+ModestProtocolType
+modest_account_mgr_get_server_account_security (ModestAccountMgr *self,
+ const gchar* account_name)
+{
+ ModestProtocolType result = MODEST_PROTOCOLS_CONNECTION_NONE;
+ gchar* value;
+
+ value = modest_account_mgr_get_string (self, account_name, MODEST_ACCOUNT_SECURITY,
+ TRUE /* server account */);
+ if (value) {
+ ModestProtocolRegistry *protocol_registry;
+ ModestProtocol *protocol;
+
+ protocol_registry = modest_runtime_get_protocol_registry ();
+ protocol = modest_protocol_registry_get_protocol_by_name (protocol_registry,
+ MODEST_PROTOCOL_REGISTRY_CONNECTION_PROTOCOLS,
+ value);
+ g_free (value);
+
+ if (protocol)
+ result = modest_protocol_get_type_id (protocol);
+ }
+
+ return result;
+}
+
+void
+modest_account_mgr_set_server_account_security (ModestAccountMgr *self,
+ const gchar* account_name,
+ ModestProtocolType security)
+{
+ const gchar* str_value;
+ ModestProtocolRegistry *protocol_registry;
+ ModestProtocol *protocol;
+
+ /* Get the conf string for the protocol type: */
+ protocol_registry = modest_runtime_get_protocol_registry ();
+ protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, security);
+ str_value = modest_protocol_get_name (protocol);
+
+ /* Set it in the configuration: */
+ modest_account_mgr_set_string (self, account_name, MODEST_ACCOUNT_SECURITY, str_value, TRUE);
+}
+
+ModestServerAccountSettings *
+modest_account_mgr_load_server_settings (ModestAccountMgr *self, const gchar* name, gboolean is_transport_and_not_store)
+{
+ ModestServerAccountSettings *settings = NULL;
+ ModestProtocol *protocol;
+ ModestProtocolRegistry *registry;
+ gchar *hostname, *username, *pwd, *uri, *proto, *auth, *sec;
+
+ if (!modest_account_mgr_account_exists (self, name, TRUE)) {
+ g_warning ("%s account %s does not exist", __FUNCTION__, name);
+ return NULL;
+ }
+
+ registry = modest_runtime_get_protocol_registry ();
+ settings = modest_server_account_settings_new ();
+
+ modest_server_account_settings_set_account_name (settings, name);
+
+ proto = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_PROTO, TRUE);
+ if (proto) {
+ gchar *tag = NULL;
+ if (is_transport_and_not_store) {
+ tag = MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS;
+ } else {
+ tag = MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS;
+ }
+ protocol = modest_protocol_registry_get_protocol_by_name (registry, tag, proto);
+
+ modest_server_account_settings_set_protocol (settings,
+ modest_protocol_get_type_id (protocol));
+ g_free (proto);
+ } else {
+ goto on_error;
+ }
+
+ modest_server_account_settings_set_port (settings,
+ modest_account_mgr_get_int (self, name, MODEST_ACCOUNT_PORT, TRUE));
+
+ auth = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_AUTH_MECH, TRUE);
+ if (auth) {
+ protocol = modest_protocol_registry_get_protocol_by_name (registry, MODEST_PROTOCOL_REGISTRY_AUTH_PROTOCOLS, auth);
+ modest_server_account_settings_set_auth_protocol (settings,
+ modest_protocol_get_type_id (protocol));
+ g_free (auth);
+ } else {
+ modest_server_account_settings_set_auth_protocol (settings, MODEST_PROTOCOLS_AUTH_NONE);
+ }
+
+ sec = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_SECURITY, TRUE);
+ if (sec) {
+ protocol = modest_protocol_registry_get_protocol_by_name (registry, MODEST_PROTOCOL_REGISTRY_CONNECTION_PROTOCOLS, sec);
+ modest_server_account_settings_set_security_protocol (settings,
+ modest_protocol_get_type_id (protocol));
+ g_free (sec);
+ } else {
+ modest_server_account_settings_set_security_protocol (settings,
+ MODEST_PROTOCOLS_CONNECTION_NONE);
+ }
+
+ /* Username, password and URI. Note that the URI could include
+ the former two, so in this case there is no need to have
+ them */
+ username = modest_account_mgr_get_string (self, name,
+ MODEST_ACCOUNT_USERNAME,TRUE);
+ if (username)
+ modest_server_account_settings_set_username (settings, username);
+
+ pwd = modest_account_mgr_get_string (self, name,
+ MODEST_ACCOUNT_PASSWORD, TRUE);
+ if (pwd) {
+ modest_server_account_settings_set_password (settings, pwd);
+ g_free (pwd);
+ }
+
+ uri = modest_account_mgr_get_string (self, name,
+ MODEST_ACCOUNT_URI, TRUE);
+ if (uri)
+ modest_server_account_settings_set_uri (settings, uri);
+
+ hostname = modest_account_mgr_get_string (self, name,
+ MODEST_ACCOUNT_HOSTNAME,TRUE);
+ if (hostname)
+ modest_server_account_settings_set_hostname (settings, hostname);
+
+ if (!uri) {
+ if (!username || !hostname) {
+ g_free (username);
+ g_free (hostname);
+ goto on_error;