From fd44d68efc59bf8d3f70e70bb1df7e6885228188 Mon Sep 17 00:00:00 2001 From: Sergio Villar Senin Date: Wed, 21 Feb 2007 13:05:39 +0000 Subject: [PATCH] * Removed remember password from the store widget * Added support to use auth mechanism and security options * Initialized some variables * Fixed a bug in ModestConf * Added TLS when possible security option pmo-trunk-r844 --- src/gtk/modest-account-assistant.c | 8 +++-- src/gtk/modest-store-widget.c | 60 +++++++++++++++++++++++------------- src/gtk/modest-store-widget.h | 8 ++--- src/modest-account-mgr.c | 59 +++++++++++++++++++++++++++++++++-- src/modest-account-mgr.h | 6 +++- src/modest-conf.c | 2 +- src/modest-defs.h | 4 +-- src/modest-protocol-info.c | 6 +++- src/modest-protocol-info.h | 2 ++ src/modest-text-utils.c | 2 +- 10 files changed, 118 insertions(+), 39 deletions(-) diff --git a/src/gtk/modest-account-assistant.c b/src/gtk/modest-account-assistant.c index 38d803e..c2040e3 100644 --- a/src/gtk/modest-account-assistant.c +++ b/src/gtk/modest-account-assistant.c @@ -605,7 +605,7 @@ static void on_apply (ModestAccountAssistant *self, gpointer user_data) { ModestAccountAssistantPrivate *priv; - ModestProtocol proto; + ModestProtocol proto, security, auth; gchar *store_name, *transport_name; const gchar *account_name, *username, *servername, *path; ModestStoreWidget *store; @@ -619,6 +619,8 @@ on_apply (ModestAccountAssistant *self, gpointer user_data) username = modest_store_widget_get_username (store); servername = modest_store_widget_get_servername (store); path = modest_store_widget_get_path (store); + security = modest_store_widget_get_security (store); + auth = modest_store_widget_get_auth (store); store_name = get_new_server_account_name (priv->account_mgr, proto,username, servername); if (proto == MODEST_PROTOCOL_STORE_MAILDIR || @@ -628,7 +630,7 @@ on_apply (ModestAccountAssistant *self, gpointer user_data) g_free (uri); } else modest_account_mgr_add_server_account (priv->account_mgr, store_name, servername, - username, NULL, proto); + username, NULL, proto, security, auth); /* create server account -> transport */ transport = MODEST_TRANSPORT_WIDGET(priv->transport_widget); @@ -645,7 +647,7 @@ on_apply (ModestAccountAssistant *self, gpointer user_data) modest_account_mgr_add_server_account (priv->account_mgr, transport_name, servername, username, NULL, - proto); + proto, security, auth); /* create account */ account_name = get_account_name (self); diff --git a/src/gtk/modest-store-widget.c b/src/gtk/modest-store-widget.c index e6d38a8..d536e4a 100644 --- a/src/gtk/modest-store-widget.c +++ b/src/gtk/modest-store-widget.c @@ -51,7 +51,6 @@ struct _ModestStoreWidgetPrivate { GtkWidget *security; GtkWidget *auth; GtkWidget *chooser; - GtkWidget *remember_pwd; ModestProtocol proto; }; @@ -199,7 +198,6 @@ imap_pop_configuration (ModestStoreWidget *self) ModestPairList *protos; ModestStoreWidgetPrivate *priv; GtkWidget *label, *box, *hbox; - GtkWidget *combo; priv = MODEST_STORE_WIDGET_GET_PRIVATE(self); box = gtk_vbox_new (FALSE, 6); @@ -246,14 +244,10 @@ imap_pop_configuration (ModestStoreWidget *self) gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6); protos = modest_protocol_info_get_protocol_pair_list (MODEST_PROTOCOL_TYPE_AUTH); - combo = modest_combo_box_new (protos, g_str_equal); + priv->auth = modest_combo_box_new (protos, g_str_equal); modest_pair_list_free (protos); - gtk_box_pack_start (GTK_BOX(hbox), combo, FALSE, FALSE, 0); - priv->remember_pwd = - gtk_check_button_new_with_label (_("Remember password")); - gtk_box_pack_start (GTK_BOX(hbox),priv->remember_pwd, - FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(hbox), priv->auth, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0); @@ -304,20 +298,6 @@ modest_store_widget_new (ModestProtocol proto) return GTK_WIDGET(self); } -gboolean -modest_store_widget_get_remember_password (ModestStoreWidget *self) -{ - ModestStoreWidgetPrivate *priv; - - g_return_val_if_fail (self, FALSE); - priv = MODEST_STORE_WIDGET_GET_PRIVATE(self); - - if (GTK_IS_TOGGLE_BUTTON(priv->remember_pwd)) - return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(priv->remember_pwd)); - else - return FALSE; -} - const gchar* modest_store_widget_get_username (ModestStoreWidget *self) { @@ -372,3 +352,39 @@ modest_store_widget_get_path (ModestStoreWidget *self) else return NULL; } + +static ModestProtocol +get_protocol_from_combo (GtkWidget *combo) +{ + gchar *chosen; + + if (!combo) + return MODEST_PROTOCOL_UNKNOWN; + + chosen = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo)); + + return modest_protocol_info_get_protocol (chosen); + +} + +ModestProtocol +modest_store_widget_get_auth (ModestStoreWidget *self) +{ + ModestStoreWidgetPrivate *priv; + + g_return_val_if_fail (self, MODEST_PROTOCOL_UNKNOWN); + priv = MODEST_STORE_WIDGET_GET_PRIVATE(self); + + return get_protocol_from_combo (priv->auth); +} + +ModestProtocol +modest_store_widget_get_security (ModestStoreWidget *self) +{ + ModestStoreWidgetPrivate *priv; + + g_return_val_if_fail (self, MODEST_PROTOCOL_UNKNOWN); + priv = MODEST_STORE_WIDGET_GET_PRIVATE(self); + + return get_protocol_from_combo (priv->security); +} diff --git a/src/gtk/modest-store-widget.h b/src/gtk/modest-store-widget.h index b17d2f6..d986720 100644 --- a/src/gtk/modest-store-widget.h +++ b/src/gtk/modest-store-widget.h @@ -32,16 +32,16 @@ struct _ModestStoreWidgetClass { }; /* member functions */ -GType modest_store_widget_get_type (void) G_GNUC_CONST; +GType modest_store_widget_get_type (void) G_GNUC_CONST; -GtkWidget* modest_store_widget_new (ModestProtocol proto); +GtkWidget* modest_store_widget_new (ModestProtocol proto); -gboolean modest_store_widget_get_remember_password (ModestStoreWidget *self); const gchar* modest_store_widget_get_username (ModestStoreWidget *self); const gchar* modest_store_widget_get_servername (ModestStoreWidget *self); ModestProtocol modest_store_widget_get_proto (ModestStoreWidget *self); gchar * modest_store_widget_get_path (ModestStoreWidget *self); - +ModestProtocol modest_store_widget_get_auth (ModestStoreWidget *self); +ModestProtocol modest_store_widget_get_security (ModestStoreWidget *self); G_END_DECLS diff --git a/src/modest-account-mgr.c b/src/modest-account-mgr.c index 84e6e0f..87a81a3 100644 --- a/src/modest-account-mgr.c +++ b/src/modest-account-mgr.c @@ -307,12 +307,14 @@ gboolean modest_account_mgr_add_server_account (ModestAccountMgr * self, const gchar * name, const gchar *hostname, const gchar * username, const gchar * password, - ModestProtocol proto) + ModestProtocol proto, + ModestProtocol security, + ModestProtocol auth) { ModestAccountMgrPrivate *priv; gchar *key; ModestProtocolType proto_type; - gboolean ok; + gboolean ok = TRUE; GError *err = NULL; g_return_val_if_fail (MODEST_IS_ACCOUNT_MGR(self), FALSE); @@ -332,7 +334,6 @@ modest_account_mgr_add_server_account (ModestAccountMgr * self, g_free (key); ok = FALSE; } - g_free (key); if (!ok) goto cleanup; @@ -381,6 +382,58 @@ modest_account_mgr_add_server_account (ModestAccountMgr * self, ok = FALSE; } g_free (key); + if (!ok) + goto cleanup; + + /* auth mechanism */ + key = _modest_account_mgr_get_account_keyname (name, MODEST_ACCOUNT_AUTH_MECH, TRUE); + ok = modest_conf_set_string (priv->modest_conf, key, + modest_protocol_info_get_protocol_name (auth), &err); + if (err) { + g_printerr ("modest: failed to set %s: %s\n", key, err->message); + g_error_free (err); + ok = FALSE; + } + g_free (key); + if (!ok) + 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, "use_lsub"); + option_list = g_slist_append (option_list, "check_all"); + /* Security options */ + switch (security) { + case MODEST_PROTOCOL_SECURITY_NONE: + option_list = g_slist_append (option_list, "use_ssl=never"); + break; + case MODEST_PROTOCOL_SECURITY_SSL: + case MODEST_PROTOCOL_SECURITY_TLS: + option_list = g_slist_append (option_list, "use_ssl=always"); + break; + case MODEST_PROTOCOL_SECURITY_TLS_OP: + option_list = g_slist_append (option_list, "use_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); + } cleanup: if (!ok) { diff --git a/src/modest-account-mgr.h b/src/modest-account-mgr.h index a7385ac..6e6bff4 100644 --- a/src/modest-account-mgr.h +++ b/src/modest-account-mgr.h @@ -110,6 +110,8 @@ gboolean modest_account_mgr_add_account (ModestAccountMgr *self, * @username: the username * @password: the password * @proto: the protocol (imap, smtp, ...) used for this account + * @security: the security options, (SSL, TLS ...) used to access the server + * @auth: the authentication method (password, none ...) used to access the server * * add a server account to the configuration. * the server account with @name should not already exist @@ -121,7 +123,9 @@ gboolean modest_account_mgr_add_server_account (ModestAccountMgr *self, const gchar *hostname, const gchar *username, const gchar *password, - ModestProtocol proto); + ModestProtocol proto, + ModestProtocol security, + ModestProtocol auth); /** diff --git a/src/modest-conf.c b/src/modest-conf.c index fc25272..86a9ef1 100644 --- a/src/modest-conf.c +++ b/src/modest-conf.c @@ -316,7 +316,7 @@ modest_conf_set_list (ModestConf* self, const gchar* key, priv = MODEST_CONF_GET_PRIVATE(self); gconf_type = modest_conf_type_to_gconf_type (list_type, err); - if (err) + if (*err) return FALSE; return gconf_client_set_list (priv->gconf_client, key, gconf_type, val, err); diff --git a/src/modest-defs.h b/src/modest-defs.h index 2dda28b..01c98a7 100644 --- a/src/modest-defs.h +++ b/src/modest-defs.h @@ -89,8 +89,6 @@ #define MODEST_ACCOUNT_LEAVE_ON_SERVER "leave_on_server" /* boolean */ #define MODEST_ACCOUNT_PREFERRED_CNX "preferred_cnx" /* string */ #define MODEST_ACCOUNT_OPTIONS "options" /* list */ - - - +#define MODEST_ACCOUNT_AUTH_MECH "auth_mech" /* string */ #endif /*__MODEST_DEFS_H__*/ diff --git a/src/modest-protocol-info.c b/src/modest-protocol-info.c index 125c418..b9b966d 100644 --- a/src/modest-protocol-info.c +++ b/src/modest-protocol-info.c @@ -48,10 +48,12 @@ static const ProtocolInfo ProtocolMap[] = { { MODEST_PROTOCOL_STORE_MAILDIR, "maildir", N_("Maildir") }, { MODEST_PROTOCOL_STORE_MBOX, "mbox", N_("MBox") }, + { MODEST_PROTOCOL_SECURITY_NONE, "none", N_("None") }, { MODEST_PROTOCOL_SECURITY_SSL, "ssl", N_("SSL") }, { MODEST_PROTOCOL_SECURITY_TLS, "tls", N_("TLS") }, + { MODEST_PROTOCOL_SECURITY_TLS_OP, "tls-op", N_("TLS when possible") }, /* op stands for optional */ - { MODEST_PROTOCOL_AUTH_NONE, "none", N_("none") }, + { MODEST_PROTOCOL_AUTH_NONE, "none", N_("None") }, { MODEST_PROTOCOL_AUTH_PASSWORD, "password", N_("Password") } }; const guint PROTOCOL_MAP_SIZE = sizeof(ProtocolMap)/sizeof(ProtocolInfo); @@ -113,8 +115,10 @@ modest_protocol_info_get_protocol_type (ModestProtocol proto) case MODEST_PROTOCOL_STORE_MBOX: return MODEST_PROTOCOL_TYPE_STORE; + case MODEST_PROTOCOL_SECURITY_NONE: case MODEST_PROTOCOL_SECURITY_SSL: case MODEST_PROTOCOL_SECURITY_TLS: + case MODEST_PROTOCOL_SECURITY_TLS_OP: return MODEST_PROTOCOL_TYPE_SECURITY; case MODEST_PROTOCOL_AUTH_NONE: diff --git a/src/modest-protocol-info.h b/src/modest-protocol-info.h index d4b2a85..de963ba 100644 --- a/src/modest-protocol-info.h +++ b/src/modest-protocol-info.h @@ -47,8 +47,10 @@ typedef enum { MODEST_PROTOCOL_STORE_MAILDIR, MODEST_PROTOCOL_STORE_MBOX, + MODEST_PROTOCOL_SECURITY_NONE, MODEST_PROTOCOL_SECURITY_SSL, MODEST_PROTOCOL_SECURITY_TLS, + MODEST_PROTOCOL_SECURITY_TLS_OP, MODEST_PROTOCOL_AUTH_NONE, MODEST_PROTOCOL_AUTH_PASSWORD, diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index 578d29d..45555ce 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -791,7 +791,7 @@ gboolean modest_text_utils_validate_email_address (const gchar *email_address) { int count = 0; - const gchar *c, *domain; + const gchar *c = NULL, *domain = NULL; static gchar *rfc822_specials = "()<>@,;:\\\"[]"; /* first we validate the name portion (name@domain) */ -- 1.7.9.5