diff options
Diffstat (limited to 'mail/mail-session.c')
-rw-r--r-- | mail/mail-session.c | 325 |
1 files changed, 163 insertions, 162 deletions
diff --git a/mail/mail-session.c b/mail/mail-session.c index 4b524abdc0..5a46ee76b2 100644 --- a/mail/mail-session.c +++ b/mail/mail-session.c @@ -148,22 +148,22 @@ make_key (CamelService *service, const char *item) /* ********************************************************************** */ -static GtkDialog *password_dialogue = NULL; +static GtkDialog *password_dialog = NULL; static EDList password_list = E_DLIST_INITIALISER(password_list); struct _pass_msg { struct _mail_msg msg; - + CamelSession *session; const char *prompt; gboolean secret; CamelService *service; const char *item; CamelException *ex; - + char *service_url; char *key; - + MailConfigService *config_service; GtkWidget *check; GtkWidget *entry; @@ -174,17 +174,17 @@ struct _pass_msg { static void do_get_pass(struct _mail_msg *mm); static void -pass_response(GtkDialog *dialogue, int button, void *data) +pass_response (GtkDialog *dialog, int button, void *data) { struct _pass_msg *m = data; - - switch(button) { + + switch (button) { case GTK_RESPONSE_OK: { gboolean cache, remember; - m->result = g_strdup(gtk_entry_get_text((GtkEntry *)m->entry)); - remember = cache = m->check?gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (m->check)):FALSE; - + m->result = g_strdup (gtk_entry_get_text ((GtkEntry *) m->entry)); + remember = cache = m->check ? gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (m->check)) : FALSE; + if (m->service_url) { if (m->service) { mail_config_service_set_save_passwd (m->config_service, cache); @@ -209,35 +209,35 @@ pass_response(GtkDialog *dialogue, int button, void *data) } break; } default: - camel_exception_set(m->ex, CAMEL_EXCEPTION_USER_CANCEL, _("User canceled operation.")); + camel_exception_set (m->ex, CAMEL_EXCEPTION_USER_CANCEL, _("User canceled operation.")); break; } - - gtk_widget_destroy((GtkWidget *)dialogue); - - password_dialogue = NULL; - e_msgport_reply((EMsg *)m); - - if ((m = (struct _pass_msg *)e_dlist_remhead(&password_list))) - do_get_pass((struct _mail_msg *)m); + + gtk_widget_destroy ((GtkWidget *) dialog); + + password_dialog = NULL; + e_msgport_reply ((EMsg *)m); + + if ((m = (struct _pass_msg *) e_dlist_remhead (&password_list))) + do_get_pass ((struct _mail_msg *) m); } static void -request_password(struct _pass_msg *m) +request_password (struct _pass_msg *m) { - char *title; const MailConfigAccount *mca = NULL; - - /* If we already have a password_dialogue up, save this request till later */ - if (!m->ismain && password_dialogue) { - e_dlist_addtail(&password_list, (EDListNode *)m); + char *title; + + /* If we already have a password_dialog up, save this request till later */ + if (!m->ismain && password_dialog) { + e_dlist_addtail (&password_list, (EDListNode *)m); return; } - + if (m->service_url) { - if ( (mca = mail_config_get_account_by_source_url(m->service_url)) ) + if ((mca = mail_config_get_account_by_source_url (m->service_url))) m->config_service = mca->source; - else if ( (mca = mail_config_get_account_by_transport_url (m->service_url)) ) + else if ((mca = mail_config_get_account_by_transport_url (m->service_url))) m->config_service = mca->transport; } @@ -245,29 +245,31 @@ request_password(struct _pass_msg *m) title = g_strdup_printf (_("Enter Password for %s"), mca->name); else title = g_strdup (_("Enter Password")); - - password_dialogue = (GtkDialog *)gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, "%s", m->prompt); - g_signal_connect(password_dialogue, "response", G_CALLBACK(pass_response), m); - gtk_window_set_title (GTK_WINDOW (password_dialogue), title); + + password_dialog = (GtkDialog *) gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_QUESTION, + GTK_BUTTONS_OK_CANCEL, "%s", m->prompt); + + g_signal_connect (password_dialog, "response", G_CALLBACK (pass_response), m); + gtk_window_set_title (GTK_WINDOW (password_dialog), title); g_free (title); - - m->entry = gtk_entry_new(); - gtk_entry_set_visibility((GtkEntry *)m->entry, !m->secret); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (password_dialogue)->vbox), m->entry, TRUE, FALSE, 0); - gtk_widget_show(m->entry); - + + m->entry = gtk_entry_new (); + gtk_entry_set_visibility ((GtkEntry *) m->entry, !m->secret); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (password_dialog)->vbox), m->entry, TRUE, FALSE, 0); + gtk_widget_show (m->entry); + if (m->service_url == NULL || m->service != NULL) { - m->check = gtk_check_button_new_with_mnemonic(m->service_url? _("_Remember this password") : - _("_Remember this password for the remainder of this session")); + m->check = gtk_check_button_new_with_mnemonic (m->service_url? _("_Remember this password") : + _("_Remember this password for the remainder of this session")); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (m->check), m->config_service->save_passwd); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (password_dialogue)->vbox), m->check, TRUE, FALSE, 0); - gtk_widget_show(m->check); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (password_dialog)->vbox), m->check, TRUE, FALSE, 0); + gtk_widget_show (m->check); } - + if (m->ismain) - gtk_dialog_run(password_dialogue); + gtk_dialog_run (password_dialog); else - gtk_widget_show((GtkWidget *)password_dialogue); + gtk_widget_show ((GtkWidget *) password_dialog); } static void @@ -350,7 +352,7 @@ get_password (CamelSession *session, const char *prompt, gboolean secret, CamelS ret = m->result; mail_msg_free(m); e_msgport_destroy(pass_reply); - + return ret; } @@ -358,7 +360,7 @@ static void main_forget_password (CamelSession *session, CamelService *service, const char *item, CamelException *ex) { char *key = make_key (service, item); - + e_passwords_forget_password ("Mail", key); g_free (key); @@ -373,7 +375,7 @@ forget_password (CamelSession *session, CamelService *service, const char *item, /* ********************************************************************** */ -static GtkDialog *message_dialogue; +static GtkDialog *message_dialog; static EDList message_list = E_DLIST_INITIALISER(password_list); struct _user_message_msg { @@ -391,19 +393,18 @@ static void do_user_message (struct _mail_msg *mm); /* clicked, send back the reply */ static void -user_message_response(GtkDialog *gd, int button, struct _user_message_msg *m) +user_message_response (GtkDialog *dialog, int button, struct _user_message_msg *m) { - gtk_widget_destroy((GtkWidget *)gd); - g_object_unref(gd); - - message_dialogue = NULL; - + gtk_widget_destroy ((GtkWidget *) dialog); + + message_dialog = NULL; + /* if !allow_cancel, then we've already replied */ if (m->allow_cancel) { m->result = button == GTK_RESPONSE_OK; e_msgport_reply((EMsg *)m); } - + /* check for pendings */ if ((m = (struct _user_message_msg *)e_dlist_remhead(&message_list))) do_user_message((struct _mail_msg *)m); @@ -414,12 +415,12 @@ do_user_message (struct _mail_msg *mm) { struct _user_message_msg *m = (struct _user_message_msg *)mm; GtkMessageType msg_type; - - if (!m->ismain && message_dialogue != NULL) { - e_dlist_addtail(&message_list, (EDListNode *)m); + + if (!m->ismain && message_dialog != NULL) { + e_dlist_addtail (&message_list, (EDListNode *)m); return; } - + switch (m->type) { case CAMEL_SESSION_ALERT_INFO: msg_type = GTK_MESSAGE_INFO; @@ -433,25 +434,25 @@ do_user_message (struct _mail_msg *mm) default: msg_type = GTK_MESSAGE_INFO; } - - message_dialogue = (GtkDialog *)gtk_message_dialog_new( + + message_dialog = (GtkDialog *) gtk_message_dialog_new ( NULL, 0, msg_type, - m->allow_cancel?GTK_BUTTONS_OK_CANCEL:GTK_BUTTONS_OK, + m->allow_cancel ? GTK_BUTTONS_OK_CANCEL : GTK_BUTTONS_OK, m->prompt); - gtk_dialog_set_default_response(message_dialogue, m->allow_cancel?GTK_RESPONSE_CANCEL:GTK_RESPONSE_OK); - g_object_set(message_dialogue, "allow_shrink", TRUE, "allow_grow", TRUE, NULL); - + gtk_dialog_set_default_response (message_dialog, m->allow_cancel ? GTK_RESPONSE_CANCEL : GTK_RESPONSE_OK); + g_object_set ((GObject *) message_dialog, "allow_shrink", TRUE, "allow_grow", TRUE, NULL); + /* We only need to wait for the result if we allow cancel otherwise show but send result back instantly */ if (m->allow_cancel) { - g_signal_connect(message_dialogue, "response", G_CALLBACK(user_message_response), m); + g_signal_connect (message_dialog, "response", G_CALLBACK (user_message_response), m); if (m->ismain) - gtk_dialog_run(message_dialogue); + gtk_dialog_run (message_dialog); else - gtk_widget_show((GtkWidget *)message_dialogue); + gtk_widget_show ((GtkWidget *) message_dialog); } else { - gtk_widget_show((GtkWidget *)message_dialogue); + gtk_widget_show ((GtkWidget *) message_dialog); m->result = TRUE; - e_msgport_reply((EMsg *)m); + e_msgport_reply ((EMsg *)m); } } @@ -562,31 +563,31 @@ timeout_timeout (struct _mail_msg *mm) } static void -timeout_done(struct _mail_msg *mm) +timeout_done (struct _mail_msg *mm) { - struct _timeout_msg *m = (struct _timeout_msg *)mm; - MailSession *ms = (MailSession *)m->session; + struct _timeout_msg *m = (struct _timeout_msg *) mm; + MailSession *ms = (MailSession *) m->session; struct _timeout_data *td; - + if (!m->result) { MAIL_SESSION_LOCK(ms, lock); - td = find_timeout(&ms->timeouts, m->id); + td = find_timeout (&ms->timeouts, m->id); if (td) { - e_dlist_remove((EDListNode *)td); + e_dlist_remove ((EDListNode *) td); if (td->timeout_id) - gtk_timeout_remove(td->timeout_id); - g_free(td); + gtk_timeout_remove (td->timeout_id); + g_free (td); } MAIL_SESSION_UNLOCK(ms, lock); } } static void -timeout_free(struct _mail_msg *mm) +timeout_free (struct _mail_msg *mm) { struct _timeout_msg *m = (struct _timeout_msg *)mm; - - camel_object_unref((CamelObject *)m->session); + + camel_object_unref (m->session); } static struct _mail_msg_op timeout_op = { @@ -601,63 +602,63 @@ camel_timeout (gpointer data) { struct _timeout_data *td = data; struct _timeout_msg *m; - + /* stop if we are removed pending */ if (td->removed) return FALSE; - m = mail_msg_new(&timeout_op, NULL, sizeof (*m)); - + m = mail_msg_new (&timeout_op, NULL, sizeof (*m)); + m->session = td->session; - camel_object_ref((CamelObject *)td->session); + camel_object_ref (td->session); m->id = td->id; - e_thread_put(mail_thread_queued, (EMsg *)m); + e_thread_put (mail_thread_queued, (EMsg *)m); return TRUE; } static void -main_register_timeout(CamelSession *session, void *event_data, void *data) +main_register_timeout (CamelSession *session, void *event_data, void *data) { MailSession *ms = (MailSession *)session; unsigned int handle = (unsigned int)event_data; struct _timeout_data *td; - + MAIL_SESSION_LOCK(session, lock); - td = find_timeout(&ms->timeouts, handle); + td = find_timeout (&ms->timeouts, handle); if (td) { if (td->removed) { - e_dlist_remove((EDListNode *)td); + e_dlist_remove ((EDListNode *) td); if (td->timeout_id) - gtk_timeout_remove(td->timeout_id); - g_free(td); + gtk_timeout_remove (td->timeout_id); + g_free (td); } else { - td->timeout_id = gtk_timeout_add(td->interval, camel_timeout, td); + td->timeout_id = gtk_timeout_add (td->interval, camel_timeout, td); } } MAIL_SESSION_UNLOCK(session, lock); - - camel_object_unref((CamelObject *)ms); + + camel_object_unref (ms); } static guint register_timeout (CamelSession *session, guint32 interval, CamelTimeoutCallback cb, gpointer camel_data) { struct _timeout_data *td; - MailSession *ms = (MailSession *)session; + MailSession *ms = (MailSession *) session; guint ret; - + MAIL_SESSION_LOCK(session, lock); - + ret = ms->timeout_id; - ms->timeout_id ++; - + ms->timeout_id++; + /* just debugging, the timeout code now ignores excessive events anyway */ if (interval < 100) - g_warning("Timeout requested %d is small, may cause performance problems", interval); - - td = g_malloc(sizeof(*td)); + g_warning ("Timeout requested %d is small, may cause performance problems", interval); + + td = g_malloc (sizeof (*td)); td->cb = cb; td->camel_data = camel_data; td->interval = interval; @@ -665,34 +666,35 @@ register_timeout (CamelSession *session, guint32 interval, CamelTimeoutCallback td->session = session; td->removed = FALSE; td->busy = FALSE; - e_dlist_addhead(&ms->timeouts, (EDListNode *)td); - + e_dlist_addhead (&ms->timeouts, (EDListNode *) td); + MAIL_SESSION_UNLOCK(session, lock); - - camel_object_ref(ms); - mail_async_event_emit(ms->async, MAIL_ASYNC_GUI, (MailAsyncFunc)main_register_timeout, (CamelObject *)session, (void *)ret, NULL); + + camel_object_ref (ms); + mail_async_event_emit (ms->async, MAIL_ASYNC_GUI, (MailAsyncFunc) main_register_timeout, + (CamelObject *) session, (void *) ret, NULL); return ret; } static void -main_remove_timeout(CamelSession *session, void *event_data, void *data) +main_remove_timeout (CamelSession *session, void *event_data, void *data) { - MailSession *ms = (MailSession *)session; - unsigned int handle = (unsigned int)event_data; + MailSession *ms = (MailSession *) session; + unsigned int handle = (unsigned int) event_data; struct _timeout_data *td; - + MAIL_SESSION_LOCK(session, lock); - td = find_timeout(&ms->timeouts, handle); + td = find_timeout (&ms->timeouts, handle); if (td) { - e_dlist_remove((EDListNode *)td); + e_dlist_remove ((EDListNode *) td); if (td->timeout_id) - gtk_timeout_remove(td->timeout_id); - g_free(td); + gtk_timeout_remove (td->timeout_id); + g_free (td); } MAIL_SESSION_UNLOCK(session, lock); - - camel_object_unref((CamelObject *)ms); + + camel_object_unref (ms); } static gboolean @@ -701,21 +703,21 @@ remove_timeout (CamelSession *session, guint handle) MailSession *ms = (MailSession *)session; struct _timeout_data *td; int remove = FALSE; - + MAIL_SESSION_LOCK(session, lock); - td = find_timeout(&ms->timeouts, handle); + td = find_timeout (&ms->timeouts, handle); if (td && !td->removed) { td->removed = TRUE; remove = TRUE; } MAIL_SESSION_UNLOCK(session, lock); - + if (remove) { - camel_object_ref(ms); - mail_async_event_emit(ms->async, MAIL_ASYNC_GUI, - (MailAsyncFunc)main_remove_timeout, (CamelObject *)session, (void *)handle, NULL); + camel_object_ref (ms); + mail_async_event_emit (ms->async, MAIL_ASYNC_GUI, (MailAsyncFunc) main_remove_timeout, + (CamelObject *) session, (void *) handle, NULL); } else - g_warning("Removing a timeout i dont know about (or twice): %d", handle); + g_warning ("Removing a timeout i dont know about (or twice): %d", handle); return TRUE; } @@ -752,7 +754,7 @@ main_get_filter_driver (CamelSession *session, const char *type, CamelException user = g_strdup_printf ("%s/filters.xml", evolution_dir); system = EVOLUTION_DATADIR "/evolution/filtertypes.xml"; - fc = (RuleContext *)filter_context_new (); + fc = (RuleContext *) filter_context_new (); rule_context_load (fc, system, user); g_free (user); @@ -760,7 +762,7 @@ main_get_filter_driver (CamelSession *session, const char *type, CamelException camel_filter_driver_set_folder_func (driver, get_folder, NULL); if (mail_config_get_filter_log ()) { - MailSession *ms = (MailSession *)session; + MailSession *ms = (MailSession *) session; if (ms->filter_logfile == NULL) { const char *filename; @@ -813,16 +815,15 @@ main_get_filter_driver (CamelSession *session, const char *type, CamelException g_string_truncate (faction, 0); filter_rule_build_code (rule, fsearch); - filter_filter_build_action ((FilterFilter *)rule, faction); + filter_filter_build_action ((FilterFilter *) rule, faction); - camel_filter_driver_add_rule (driver, rule->name, - fsearch->str, faction->str); + camel_filter_driver_add_rule (driver, rule->name, fsearch->str, faction->str); } g_string_free (fsearch, TRUE); g_string_free (faction, TRUE); - g_object_unref(fc); + g_object_unref (fc); return driver; } @@ -830,8 +831,8 @@ main_get_filter_driver (CamelSession *session, const char *type, CamelException static CamelFilterDriver * get_filter_driver (CamelSession *session, const char *type, CamelException *ex) { - return (CamelFilterDriver *)mail_call_main(MAIL_CALL_p_ppp, (MailMainFunc)main_get_filter_driver, - session, type, ex); + return (CamelFilterDriver *) mail_call_main (MAIL_CALL_p_ppp, (MailMainFunc) main_get_filter_driver, + session, type, ex); } char * @@ -840,15 +841,15 @@ mail_session_get_password (const char *url_string) 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 ("Mail", simple_url); - + g_free (simple_url); - + return passwd; } @@ -858,13 +859,13 @@ mail_session_add_password (const char *url_string, { 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); } @@ -877,9 +878,9 @@ mail_session_remember_password (const char *url_string) 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_remember_password ("Mail", simple_url); - + g_free (simple_url); } @@ -901,10 +902,10 @@ mail_session_init (void) camel_dir = g_strdup_printf ("%s/mail", evolution_dir); camel_session_construct (session, camel_dir); - + /* The shell will tell us to go online. */ - camel_session_set_online ((CamelSession *)session, FALSE); - + camel_session_set_online ((CamelSession *) session, FALSE); + g_free (camel_dir); } @@ -922,31 +923,31 @@ mail_session_set_interactive (gboolean interactive) if (!interactive) { struct _pass_msg *pm; struct _user_message_msg *um; - - d(printf("Gone non-interactive, checking for outstanding interactive tasks\n")); - + + d(printf ("Gone non-interactive, checking for outstanding interactive tasks\n")); + /* clear out pending password requests */ - while ((pm = (struct _pass_msg *)e_dlist_remhead(&password_list))) { - d(printf("Flushing password request : %s\n", pm->prompt)); - e_msgport_reply((EMsg *)pm); + while ((pm = (struct _pass_msg *) e_dlist_remhead (&password_list))) { + d(printf ("Flushing password request : %s\n", pm->prompt)); + e_msgport_reply ((EMsg *) pm); } - + /* destroy the current */ - if (password_dialogue) { - d(printf("Destroying password dialogue\n")); - gtk_object_destroy((GtkObject *)password_dialogue); + if (password_dialog) { + d(printf ("Destroying password dialogue\n")); + gtk_widget_destroy ((GtkWidget *) password_dialog); } - + /* same for pending user messages */ - while ((um = (struct _user_message_msg *)e_dlist_remhead(&message_list))) { - d(printf("Flusing message request: %s\n", um->prompt)); - e_msgport_reply((EMsg *)um); + while ((um = (struct _user_message_msg *) e_dlist_remhead (&message_list))) { + d(printf ("Flusing message request: %s\n", um->prompt)); + e_msgport_reply((EMsg *) um); } - + /* and the current */ - if (message_dialogue) { + if (message_dialog) { d(printf("Destroying message dialogue\n")); - gtk_object_destroy((GtkObject *)message_dialogue); + gtk_widget_destroy ((GtkWidget *) message_dialog); } } } |