aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
authorChris Toshok <toshok@ximian.com>2001-10-13 06:28:04 +0800
committerChris Toshok <toshok@src.gnome.org>2001-10-13 06:28:04 +0800
commitc90ced3180e92eaa690eef03b9b709f16030fa0c (patch)
tree7d53442b4c6523570946482526844aa95e22670e /mail
parent47d5ddd05759815a8a11d4083298e1b81bf02163 (diff)
downloadgsoc2013-evolution-c90ced3180e92eaa690eef03b9b709f16030fa0c.tar
gsoc2013-evolution-c90ced3180e92eaa690eef03b9b709f16030fa0c.tar.gz
gsoc2013-evolution-c90ced3180e92eaa690eef03b9b709f16030fa0c.tar.bz2
gsoc2013-evolution-c90ced3180e92eaa690eef03b9b709f16030fa0c.tar.lz
gsoc2013-evolution-c90ced3180e92eaa690eef03b9b709f16030fa0c.tar.xz
gsoc2013-evolution-c90ced3180e92eaa690eef03b9b709f16030fa0c.tar.zst
gsoc2013-evolution-c90ced3180e92eaa690eef03b9b709f16030fa0c.zip
call e_passwords_init and e_passwords_shutdown.
2001-10-12 Chris Toshok <toshok@ximian.com> * main.c (main): call e_passwords_init and e_passwords_shutdown. * mail-session.h: add prototypes for mail_session_{get,add}_password. * mail-session.c (init): empty this out - we use e_passwords instead of a local hashtable. (get_password): use e_passwords_get_password and e_passwords_add_password. (forget_password): use e_passwords_forget_password. (mail_session_remember_password): use e_passwords_remember_password. (mail_session_forget_password): use e_passwords_forget_password. (mail_session_get_password): new function, use e_passwords_get_password. (mail_session_add_password): same, use e_passwords_add_password. (mail_session_forget_passwords): use e_passwords_forget_passwords. * mail-config.c (mail_config_write_on_exit): fix this up so it works as desired with the e_passwords stuff. svn path=/trunk/; revision=13640
Diffstat (limited to 'mail')
-rw-r--r--mail/ChangeLog23
-rw-r--r--mail/mail-config.c34
-rw-r--r--mail/mail-session.c144
-rw-r--r--mail/mail-session.h2
-rw-r--r--mail/main.c6
5 files changed, 102 insertions, 107 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 5ad3f80de2..a1e053202d 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,26 @@
+2001-10-12 Chris Toshok <toshok@ximian.com>
+
+ * main.c (main): call e_passwords_init and e_passwords_shutdown.
+
+ * mail-session.h: add prototypes for
+ mail_session_{get,add}_password.
+
+ * mail-session.c (init): empty this out - we use e_passwords
+ instead of a local hashtable.
+ (get_password): use e_passwords_get_password and
+ e_passwords_add_password.
+ (forget_password): use e_passwords_forget_password.
+ (mail_session_remember_password): use
+ e_passwords_remember_password.
+ (mail_session_forget_password): use e_passwords_forget_password.
+ (mail_session_get_password): new function, use
+ e_passwords_get_password.
+ (mail_session_add_password): same, use e_passwords_add_password.
+ (mail_session_forget_passwords): use e_passwords_forget_passwords.
+
+ * mail-config.c (mail_config_write_on_exit): fix this up so it
+ works as desired with the e_passwords stuff.
+
2001-10-12 Jeffrey Stedfast <fejj@ximian.com>
* mail-display.c (mail_error_write): Convert URLS so we can get
diff --git a/mail/mail-config.c b/mail/mail-config.c
index 5ed4886163..9e66eea531 100644
--- a/mail/mail-config.c
+++ b/mail/mail-config.c
@@ -50,6 +50,7 @@
#include <e-util/e-html-utils.h>
#include <e-util/e-url.h>
#include <e-util/e-unicode-i18n.h>
+#include <e-util/e-passwords.h>
#include "mail.h"
#include "mail-config.h"
#include "mail-mt.h"
@@ -886,19 +887,42 @@ mail_config_write_on_exit (void)
CORBA_exception_free (&ev);
/* Passwords */
- /* fixme: still depends on gnome-config */
- gnome_config_private_clean_section ("/Evolution/Passwords");
+
+ /* then we make sure the ones we want to remember are in the
+ session cache */
+ accounts = mail_config_get_accounts ();
+ for ( ; accounts; accounts = accounts->next) {
+ char *passwd;
+ account = accounts->data;
+ if (account->source->save_passwd && account->source->url) {
+ passwd = mail_session_get_password (account->source->url);
+ mail_session_forget_password (account->source->url);
+ mail_session_add_password (account->source->url, passwd);
+ g_free (passwd);
+ }
+
+ if (account->transport->save_passwd && account->transport->url) {
+ passwd = mail_session_get_password (account->transport->url);
+ mail_session_forget_password (account->transport->url);
+ mail_session_add_password (account->transport->url, passwd);
+ g_free (passwd);
+ }
+ }
+
+ /* then we clear out our component passwords */
+ e_passwords_clear_component_passwords ();
+
+ /* then we remember them */
accounts = mail_config_get_accounts ();
for ( ; accounts; accounts = accounts->next) {
account = accounts->data;
if (account->source->save_passwd && account->source->url)
mail_session_remember_password (account->source->url);
-
+
if (account->transport->save_passwd && account->transport->url)
mail_session_remember_password (account->transport->url);
}
- gnome_config_sync ();
-
+
/* now do cleanup */
mail_config_clear ();
}
diff --git a/mail/mail-session.c b/mail/mail-session.c
index 0459549ddc..643f60fc42 100644
--- a/mail/mail-session.c
+++ b/mail/mail-session.c
@@ -37,6 +37,7 @@
#include "mail-session.h"
#include "mail-tools.h"
#include "mail-mt.h"
+#include "e-util/e-passwords.h"
CamelSession *session;
@@ -50,7 +51,6 @@ CamelSession *session;
typedef struct _MailSession {
CamelSession parent_object;
- GHashTable *passwords;
gboolean interaction_enabled;
FILE *filter_logfile;
} MailSession;
@@ -76,26 +76,9 @@ static CamelFilterDriver *get_filter_driver (CamelSession *session,
CamelException *ex);
-static char *decode_base64 (char *base64);
-
static void
init (MailSession *session)
{
- char *key, *value;
- void *iter;
-
- session->passwords = g_hash_table_new (g_str_hash, g_str_equal);
-
- iter = gnome_config_private_init_iterator ("/Evolution/Passwords");
- if (iter) {
- while (gnome_config_iterator_next (iter, &key, &value)) {
- g_hash_table_insert (session->passwords,
- decode_base64 (key),
- decode_base64 (value));
- g_free (key);
- g_free (value);
- }
- }
}
static void
@@ -169,11 +152,11 @@ get_password (CamelSession *session, const char *prompt, gboolean secret,
key = make_key (service, item);
if (!key)
return NULL;
-
- ans = g_hash_table_lookup (mail_session->passwords, key);
+
+ ans = e_passwords_get_password (key);
if (ans) {
g_free (key);
- return g_strdup (ans);
+ return ans;
}
if (!mail_session->interaction_enabled ||
@@ -185,8 +168,8 @@ get_password (CamelSession *session, const char *prompt, gboolean secret,
}
if (cache)
- g_hash_table_insert (mail_session->passwords, key, g_strdup (ans));
-
+ e_passwords_add_password (key, ans);
+
return ans;
}
@@ -194,18 +177,11 @@ static void
forget_password (CamelSession *session, CamelService *service,
const char *item, CamelException *ex)
{
- MailSession *mail_session = MAIL_SESSION (session);
char *key = make_key (service, item);
- gpointer old_key, old_data;
-
- if (!g_hash_table_lookup_extended (mail_session->passwords, key,
- &old_key, &old_data))
- return;
+
+ e_passwords_forget_password (key);
- g_hash_table_remove (mail_session->passwords, key);
- memset (old_data, 0, strlen (old_data));
- g_free (old_data);
- g_free (old_key);
+ g_free (key);
}
static gboolean
@@ -393,82 +369,59 @@ get_filter_driver (CamelSession *session, const char *type, CamelException *ex)
return driver;
}
-
-static char *
-decode_base64 (char *base64)
+char *
+mail_session_get_password (const char *url_string)
{
- char *plain, *pad = "==";
- int len, out, state, save;
-
- len = strlen (base64);
- plain = g_malloc0 (len);
- state = save = 0;
- out = base64_decode_step (base64, len, plain, &state, &save);
- if (len % 4) {
- base64_decode_step (pad, 4 - len % 4, plain + out,
- &state, &save);
- }
-
- return plain;
+ CamelURL *url;
+ char *simple_url;
+ char *passwd;
+
+ url = camel_url_new (url_string, NULL);
+ simple_url = camel_url_to_string (url, CAMEL_URL_HIDE_PASSWORD | CAMEL_URL_HIDE_PARAMS);
+ camel_url_free (url);
+
+ passwd = e_passwords_get_password (simple_url);
+
+ g_free (simple_url);
+
+ return passwd;
}
-static void
-maybe_remember_password (gpointer key, gpointer password, gpointer url)
+void
+mail_session_add_password (const char *url_string,
+ const char *passwd)
{
- char *path, *key64, *pass64;
- int len, state, save;
-
- len = strlen (url);
- if (strncmp (key, url, len) != 0)
- return;
-
- len = strlen (key);
- key64 = g_malloc0 ((len + 2) * 4 / 3 + 1);
- state = save = 0;
- base64_encode_close (key, len, FALSE, key64, &state, &save);
- path = g_strdup_printf ("/Evolution/Passwords/%s", key64);
- g_free (key64);
-
- len = strlen (password);
- pass64 = g_malloc0 ((len + 2) * 4 / 3 + 1);
- state = save = 0;
- base64_encode_close (password, len, FALSE, pass64, &state, &save);
-
- gnome_config_private_set_string (path, pass64);
- g_free (path);
- g_free (pass64);
+ CamelURL *url;
+ char *simple_url;
+
+ url = camel_url_new (url_string, NULL);
+ simple_url = camel_url_to_string (url, CAMEL_URL_HIDE_PASSWORD | CAMEL_URL_HIDE_PARAMS);
+ camel_url_free (url);
+
+ e_passwords_add_password (simple_url, passwd);
+
+ g_free (simple_url);
}
void
mail_session_remember_password (const char *url_string)
{
- GHashTable *passwords = MAIL_SESSION (session)->passwords;
CamelURL *url;
char *simple_url;
- if (!passwords)
- return;
-
url = camel_url_new (url_string, NULL);
simple_url = camel_url_to_string (url, CAMEL_URL_HIDE_PASSWORD | CAMEL_URL_HIDE_PARAMS);
camel_url_free (url);
-
- g_hash_table_foreach (passwords, maybe_remember_password, simple_url);
+
+ e_passwords_remember_password (simple_url);
+
g_free (simple_url);
}
void
mail_session_forget_password (const char *key)
{
- GHashTable *passwords = MAIL_SESSION (session)->passwords;
- gpointer okey, value;
-
- if (g_hash_table_lookup_extended (passwords, key, &okey, &value)) {
- g_hash_table_remove (passwords, key);
- memset (value, 0, strlen (value));
- g_free (okey);
- g_free (value);
- }
+ e_passwords_forget_password (key);
}
void
@@ -492,22 +445,9 @@ mail_session_enable_interaction (gboolean enable)
MAIL_SESSION (session)->interaction_enabled = enable;
}
-static gboolean
-free_entry (gpointer key, gpointer value, gpointer user_data)
-{
- g_free (key);
- memset (value, 0, strlen (value));
- g_free (value);
- return TRUE;
-}
-
void
mail_session_forget_passwords (BonoboUIComponent *uih, void *user_data,
const char *path)
{
- GHashTable *passwords = MAIL_SESSION (session)->passwords;
-
- g_hash_table_foreach_remove (passwords, free_entry, NULL);
- gnome_config_private_clean_section ("/Evolution/Passwords");
- gnome_config_sync ();
+ e_passwords_forget_passwords ();
}
diff --git a/mail/mail-session.h b/mail/mail-session.h
index d23c4eaaf3..37dfe54885 100644
--- a/mail/mail-session.h
+++ b/mail/mail-session.h
@@ -38,6 +38,8 @@ char *mail_session_request_dialog (const char *prompt, gboolean secret,
const char *key, gboolean async);
gboolean mail_session_accept_dialog (const char *prompt, const char *key,
gboolean async);
+char *mail_session_get_password (const char *url);
+void mail_session_add_password (const char *url, const char *passwd);
void mail_session_forget_passwords (BonoboUIComponent *uih, void *user_data,
const char *path);
void mail_session_remember_password (const char *url);
diff --git a/mail/main.c b/mail/main.c
index dc2042f19b..af3bd93e7c 100644
--- a/mail/main.c
+++ b/mail/main.c
@@ -29,6 +29,8 @@
#include <gal/widgets/e-cursors.h>
#include <gal/widgets/e-unicode.h>
+#include "e-util/e-passwords.h"
+
#include "component-factory.h"
#include "composer/evolution-composer.h"
#include "mail.h"
@@ -125,6 +127,8 @@ main (int argc, char *argv [])
e_cursors_init ();
+ e_passwords_init ("Mail");
+
mail_config_init ();
mail_msg_init ();
@@ -146,5 +150,7 @@ main (int argc, char *argv [])
mail_config_write_on_exit ();
+ e_passwords_shutdown ();
+
return 0;
}