From 2b1d1fdc36a85c3cd3b18cd1d24ef36e35d36504 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Tue, 9 Jan 2001 17:21:34 +0000 Subject: New function to set the password for a given url. 2001-01-09 Jeffrey Stedfast * session.c (mail_session_set_password): New function to set the password for a given url. * mail-config-druid.c (druid_finish): Don't save the password in the source url, instead insert it into the save-password hash. (mail_config_druid_get_source_url): Check to make sure the authmech isn't "", if it is then don't set the authmech. * mail-account-editor.c (apply_changes): Don't save the password in the source url, instead insert it into the save-password hash. Also check to make sure we don't set an empty string as the authmech for the source or transport. * mail-accounts.c (mail_default): After reloading the accounts, reselect the previously selected account. (mail_delete): Same. * mail-config-druid.c (druid_cancel): Fixed segfault bug. svn path=/trunk/; revision=7319 --- mail/ChangeLog | 21 +++++++++++++++++++++ mail/mail-account-editor.c | 22 ++++++++++++++++------ mail/mail-accounts.c | 17 +++++++++++------ mail/mail-config-druid.c | 28 +++++++++++++++++++--------- mail/mail-session.h | 2 ++ mail/session.c | 6 ++++++ 6 files changed, 75 insertions(+), 21 deletions(-) diff --git a/mail/ChangeLog b/mail/ChangeLog index b11ba47303..e678e18cb8 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,24 @@ +2001-01-09 Jeffrey Stedfast + + * session.c (mail_session_set_password): New function to set the + password for a given url. + + * mail-config-druid.c (druid_finish): Don't save the password in + the source url, instead insert it into the save-password hash. + (mail_config_druid_get_source_url): Check to make sure the + authmech isn't "", if it is then don't set the authmech. + + * mail-account-editor.c (apply_changes): Don't save the password + in the source url, instead insert it into the save-password + hash. Also check to make sure we don't set an empty string as the + authmech for the source or transport. + + * mail-accounts.c (mail_default): After reloading the accounts, + reselect the previously selected account. + (mail_delete): Same. + + * mail-config-druid.c (druid_cancel): Fixed segfault bug. + 2001-01-09 Radek Doulik * mail-format.c (write_headers): remove

diff --git a/mail/mail-account-editor.c b/mail/mail-account-editor.c index a17fc389ad..89ad447b46 100644 --- a/mail/mail-account-editor.c +++ b/mail/mail-account-editor.c @@ -21,13 +21,12 @@ */ #include "mail-account-editor.h" +#include "mail-session.h" #include #include #include #include -extern CamelSession *session; - static void mail_account_editor_class_init (MailAccountEditorClass *class); static void mail_account_editor_init (MailAccountEditor *editor); static void mail_account_editor_finalise (GtkObject *obj); @@ -108,7 +107,7 @@ static gboolean apply_changes (MailAccountEditor *editor) { MailConfigAccount *account; - char *host, *pport; + char *host, *pport, *auth; CamelURL *url; int port; @@ -144,7 +143,8 @@ apply_changes (MailAccountEditor *editor) url->passwd = g_strdup (gtk_entry_get_text (editor->source_passwd)); g_free (url->authmech); - url->authmech = g_strdup (gtk_object_get_data (GTK_OBJECT (editor), "source_authmech")); + auth = gtk_object_get_data (GTK_OBJECT (editor), "source_authmech"); + url->authmech = auth && *auth ? g_strdup (auth) : NULL; g_free (url->host); host = g_strdup (gtk_entry_get_text (editor->source_host)); @@ -167,16 +167,26 @@ apply_changes (MailAccountEditor *editor) return FALSE; } + if (account->source->save_passwd) { + char *string; + + string = camel_url_to_string (url, FALSE); + mail_session_set_password (string, url->passwd); + mail_session_remember_password (string); + g_free (string); + } + /* now that we know this url works, set it */ g_free (account->source->url); - account->source->url = camel_url_to_string (url, account->source->save_passwd); + account->source->url = camel_url_to_string (url, FALSE); camel_url_free (url); /* transport */ url = camel_url_new (account->transport->url, NULL); g_free (url->authmech); - url->authmech = g_strdup (gtk_object_get_data (GTK_OBJECT (editor), "transport_authmech")); + auth = gtk_object_get_data (GTK_OBJECT (editor), "transport_authmech"); + url->authmech = auth && *auth ? g_strdup (auth) : NULL; g_free (url->host); host = g_strdup (gtk_entry_get_text (editor->transport_host)); diff --git a/mail/mail-accounts.c b/mail/mail-accounts.c index 9d0fd7090c..f48e33120d 100644 --- a/mail/mail-accounts.c +++ b/mail/mail-accounts.c @@ -209,19 +209,20 @@ mail_delete (GtkButton *button, gpointer data) MailConfigAccount *account; if (dialog->accounts_row >= 0) { - int row, len; + int sel, row, len; - account = gtk_clist_get_row_data (dialog->mail_accounts, dialog->accounts_row); + sel = dialog->accounts_row; + + account = gtk_clist_get_row_data (dialog->mail_accounts, sel); g_slist_remove ((GSList *) dialog->accounts, account); account_destroy (account); mail_config_write (); - gtk_clist_remove (dialog->mail_accounts, dialog->accounts_row); + gtk_clist_remove (dialog->mail_accounts, sel); len = g_slist_length ((GSList *) dialog->accounts); if (len > 0) { - row = dialog->accounts_row; - row = row >= len ? len - 1 : row; + row = sel >= len ? len - 1 : sel; gtk_clist_select_row (dialog->mail_accounts, row, 0); } else { dialog->accounts_row = -1; @@ -239,10 +240,14 @@ mail_default (GtkButton *button, gpointer data) const MailConfigAccount *account; if (dialog->accounts_row >= 0) { - account = gtk_clist_get_row_data (dialog->mail_accounts, dialog->accounts_row); + int row; + + row = dialog->accounts_row; + account = gtk_clist_get_row_data (dialog->mail_accounts, row); mail_config_set_default_account (account); mail_config_write (); load_accounts (dialog); + gtk_clist_select_row (dialog->mail_accounts, row, 0); } } diff --git a/mail/mail-config-druid.c b/mail/mail-config-druid.c index 14126cdbde..f59ede3869 100644 --- a/mail/mail-config-druid.c +++ b/mail/mail-config-druid.c @@ -28,14 +28,13 @@ #include "mail-config.h" #include "mail-ops.h" #include "mail.h" +#include "mail-session.h" #include #include #include #define d(x) x -extern CamelSession *session; - GtkWidget *mail_config_create_html (const char *name, const char *str1, const char *str2, int int1, int int2); @@ -178,12 +177,12 @@ mail_config_create_html (const char *name, const char *str1, const char *str2, } static void -druid_cancel (GnomeDruidPage *page, gpointer arg1, gpointer user_data) +druid_cancel (GnomeDruid *druid, gpointer user_data) { /* Cancel the setup of the account */ - MailConfigDruid *druid = user_data; + MailConfigDruid *config = user_data; - gtk_widget_destroy (GTK_WIDGET (druid)); + gtk_widget_destroy (GTK_WIDGET (config)); } static void @@ -195,7 +194,9 @@ druid_finish (GnomeDruidPage *page, gpointer arg1, gpointer user_data) MailConfigIdentity *id; MailConfigService *source; MailConfigService *transport; + CamelURL *url; GSList *mini; + char *str; account = g_new0 (MailConfigAccount, 1); account->name = mail_config_druid_get_account_name (druid); @@ -211,9 +212,17 @@ druid_finish (GnomeDruidPage *page, gpointer arg1, gpointer user_data) /* construct the source */ source = g_new0 (MailConfigService, 1); - source->url = mail_config_druid_get_source_url (druid); source->keep_on_server = mail_config_druid_get_keep_mail_on_server (druid); source->save_passwd = mail_config_druid_get_save_password (druid); + str = mail_config_druid_get_source_url (druid); + url = camel_url_new (str, NULL); + g_free (str); + source->url = camel_url_to_string (url, FALSE); + if (source->save_passwd && url->passwd) { + mail_session_set_password (source->url, url->passwd); + mail_session_remember_password (source->url); + } + camel_url_free (url); /* construct the transport */ transport = g_new0 (MailConfigService, 1); @@ -226,7 +235,7 @@ druid_finish (GnomeDruidPage *page, gpointer arg1, gpointer user_data) mail_config_add_account (account); mail_config_write (); - mini = g_slist_append (NULL, account->source); + mini = g_slist_prepend (NULL, account->source); mail_load_storages (druid->shell, mini); g_slist_free (mini); @@ -924,7 +933,7 @@ mail_config_druid_get_sigfile (MailConfigDruid *druid) char * mail_config_druid_get_source_url (MailConfigDruid *druid) { - char *source_url, *host, *pport; + char *source_url, *host, *pport, *auth; const CamelProvider *provider; CamelURL *url; int port = 0; @@ -936,7 +945,8 @@ mail_config_druid_get_source_url (MailConfigDruid *druid) url = g_new0 (CamelURL, 1); url->protocol = g_strdup (provider->protocol); url->user = g_strdup (gtk_entry_get_text (druid->incoming_username)); - url->authmech = g_strdup (gtk_object_get_data (GTK_OBJECT (druid), "source_authmech")); + auth = gtk_object_get_data (GTK_OBJECT (druid), "source_authmech"); + url->authmech = auth && *auth ? g_strdup (auth) : NULL; url->passwd = g_strdup (gtk_entry_get_text (druid->password)); host = g_strdup (gtk_entry_get_text (druid->incoming_hostname)); if (host && (pport = strchr (host, ':'))) { diff --git a/mail/mail-session.h b/mail/mail-session.h index 18d54c8573..a2ce0b1a10 100644 --- a/mail/mail-session.h +++ b/mail/mail-session.h @@ -40,6 +40,8 @@ void mail_session_forget_passwords (BonoboUIComponent *uih, void *user_data, const char *path); void mail_session_remember_password (const char *url); +void mail_session_set_password (const char *url, const char *password); + extern CamelSession *session; #ifdef __cplusplus diff --git a/mail/session.c b/mail/session.c index 6fd85712e4..b35116d904 100644 --- a/mail/session.c +++ b/mail/session.c @@ -289,3 +289,9 @@ mail_session_forget_passwords (BonoboUIComponent *uih, void *user_data, gnome_config_private_clean_section ("/Evolution/Passwords"); gnome_config_sync (); } + +void +mail_session_set_password (const char *url, const char *password) +{ + g_hash_table_insert (passwords, url, g_strdup (password)); +} -- cgit