aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2012-12-14 22:28:25 +0800
committerMilan Crha <mcrha@redhat.com>2012-12-14 22:30:29 +0800
commitda874077bea944b433acab7a0e04d7c7ee01b473 (patch)
tree92f177d41aaf76127c2c35237afc0524be7154ef
parent486db3bfa7b6fa9a3742a7b610f27375375d15fc (diff)
downloadgsoc2013-evolution-da874077bea944b433acab7a0e04d7c7ee01b473.tar
gsoc2013-evolution-da874077bea944b433acab7a0e04d7c7ee01b473.tar.gz
gsoc2013-evolution-da874077bea944b433acab7a0e04d7c7ee01b473.tar.bz2
gsoc2013-evolution-da874077bea944b433acab7a0e04d7c7ee01b473.tar.lz
gsoc2013-evolution-da874077bea944b433acab7a0e04d7c7ee01b473.tar.xz
gsoc2013-evolution-da874077bea944b433acab7a0e04d7c7ee01b473.tar.zst
gsoc2013-evolution-da874077bea944b433acab7a0e04d7c7ee01b473.zip
Implement and use CamelSession::trust_prompt()
-rw-r--r--libemail-engine/e-mail-session.c130
-rw-r--r--mail/e-mail-config-auth-check.c1
-rw-r--r--mail/e-mail-ui-session.c253
-rw-r--r--mail/e-mail-ui-session.h9
4 files changed, 130 insertions, 263 deletions
diff --git a/libemail-engine/e-mail-session.c b/libemail-engine/e-mail-session.c
index 18e336a5f4..b5bf18df03 100644
--- a/libemail-engine/e-mail-session.c
+++ b/libemail-engine/e-mail-session.c
@@ -149,6 +149,7 @@ static GQueue user_message_queue = { NULL, NULL, 0 };
struct _user_message_msg {
MailMsg base;
+ EUserPrompter *prompter;
CamelSessionAlertType type;
gchar *prompt;
GSList *button_captions;
@@ -158,13 +159,29 @@ struct _user_message_msg {
guint ismain : 1;
};
-static void user_message_exec (struct _user_message_msg *m,
- GCancellable *cancellable,
- GError **error);
+static void
+user_message_exec (struct _user_message_msg *m,
+ GCancellable *cancellable,
+ GError **error);
static void
-user_message_response_free (struct _user_message_msg *m)
+user_message_response_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
+ struct _user_message_msg *m = user_data;
+ GError *local_error = NULL;
+
+ m->result = e_user_prompter_prompt_finish (E_USER_PROMPTER (source), result, &local_error);
+
+ if (local_error) {
+ g_print ("%s: Failed to prompt user: %s\n", G_STRFUNC, local_error->message);
+ g_clear_error (&local_error);
+ }
+
+ /* waiting for a response? */
+ if (m && m->button_captions)
+ e_flag_set (m->done);
/* check for pendings */
if (!g_queue_is_empty (&user_message_queue)) {
@@ -177,30 +194,32 @@ user_message_response_free (struct _user_message_msg *m)
}
}
-/* clicked, send back the reply */
-static void
-user_message_response (struct _user_message_msg *m)
-{
- /* if !allow_cancel, then we've already replied */
- if (m->button_captions) {
- m->result = TRUE; //If Accepted
- e_flag_set (m->done);
- }
-
- user_message_response_free (m);
-}
-
static void
user_message_exec (struct _user_message_msg *m,
GCancellable *cancellable,
GError **error)
{
- /* XXX This is a case where we need to be able to construct
- * custom EAlerts without a predefined XML definition. */
if (m->ismain) {
- /* Use DBUS to raise dialogs in clients and reply back.
- * For now say accept all. */
- user_message_response (m);
+ const gchar *type = "";
+
+ switch (m->type) {
+ case CAMEL_SESSION_ALERT_INFO:
+ type = "info";
+ break;
+ case CAMEL_SESSION_ALERT_WARNING:
+ type = "warning";
+ break;
+ case CAMEL_SESSION_ALERT_ERROR:
+ type = "error";
+ break;
+ }
+
+ if (!m->prompter)
+ m->prompter = e_user_prompter_new ();
+
+ e_user_prompter_prompt (m->prompter, type, "",
+ m->prompt, NULL, FALSE, m->button_captions, cancellable,
+ user_message_response_cb, m);
} else
g_queue_push_tail (&user_message_queue, mail_msg_ref (m));
}
@@ -211,6 +230,10 @@ user_message_free (struct _user_message_msg *m)
g_free (m->prompt);
g_slist_free_full (m->button_captions, g_free);
e_flag_free (m->done);
+
+ if (m->prompter)
+ g_object_unref (m->prompter);
+ m->prompter = NULL;
}
static MailMsgInfo user_message_info = {
@@ -1347,10 +1370,10 @@ static gint
mail_session_alert_user (CamelSession *session,
CamelSessionAlertType type,
const gchar *prompt,
- GSList *button_captions)
+ GSList *button_captions,
+ GCancellable *cancellable)
{
struct _user_message_msg *m;
- GCancellable *cancellable;
gint result = -1;
GSList *iter;
@@ -1367,8 +1390,6 @@ mail_session_alert_user (CamelSession *session,
if (g_slist_length (button_captions) > 1)
mail_msg_ref (m);
- cancellable = m->base.cancellable;
-
if (m->ismain)
user_message_exec (m, cancellable, &m->base.error);
else
@@ -1384,6 +1405,62 @@ mail_session_alert_user (CamelSession *session,
return result;
}
+static CamelCertTrust
+mail_session_trust_prompt (CamelSession *session,
+ const gchar *host,
+ const gchar *certificate,
+ guint32 certificate_errors,
+ const GSList *issuers,
+ GCancellable *cancellable)
+{
+ EUserPrompter *prompter;
+ ENamedParameters *parameters;
+ CamelCertTrust response;
+ gchar *errors_code;
+ const GSList *iter;
+ gint ii;
+
+ prompter = e_user_prompter_new ();
+ parameters = e_named_parameters_new ();
+ errors_code = g_strdup_printf ("%x", certificate_errors);
+
+ e_named_parameters_set (parameters, "host", host);
+ e_named_parameters_set (parameters, "certificate", certificate);
+ e_named_parameters_set (parameters, "certificate-errors", errors_code);
+
+ for (ii = 1, iter = issuers; iter; ii++, iter = iter->next) {
+ gchar *name;
+
+ if (!iter->data)
+ break;
+
+ name = g_strdup_printf ("issuer-%d", ii);
+ e_named_parameters_set (parameters, name, iter->data);
+ g_free (name);
+ }
+
+ switch (e_user_prompter_extension_prompt_sync (prompter, "ETrustPrompt::trust-prompt", parameters, NULL, cancellable, NULL)) {
+ case 0:
+ response = CAMEL_CERT_TRUST_NEVER;
+ break;
+ case 1:
+ response = CAMEL_CERT_TRUST_FULLY;
+ break;
+ case 2:
+ response = CAMEL_CERT_TRUST_TEMPORARY;
+ break;
+ default:
+ response = CAMEL_CERT_TRUST_UNKNOWN;
+ break;
+ }
+
+ g_free (errors_code);
+ e_named_parameters_free (parameters);
+ g_object_unref (prompter);
+
+ return response;
+}
+
static CamelFilterDriver *
mail_session_get_filter_driver (CamelSession *session,
const gchar *type,
@@ -1748,6 +1825,7 @@ e_mail_session_class_init (EMailSessionClass *class)
session_class->get_password = mail_session_get_password;
session_class->forget_password = mail_session_forget_password;
session_class->alert_user = mail_session_alert_user;
+ session_class->trust_prompt = mail_session_trust_prompt;
session_class->get_filter_driver = mail_session_get_filter_driver;
session_class->lookup_addressbook = mail_session_lookup_addressbook;
session_class->get_socks_proxy = mail_session_get_socks_proxy;
diff --git a/mail/e-mail-config-auth-check.c b/mail/e-mail-config-auth-check.c
index d60e95f239..d514872939 100644
--- a/mail/e-mail-config-auth-check.c
+++ b/mail/e-mail-config-auth-check.c
@@ -148,6 +148,7 @@ mail_config_auth_check_update (EMailConfigAuthCheck *auth_check)
/* to be able to answer for invalid/self-signed server certificates */
CAMEL_SESSION_GET_CLASS (session)->alert_user = e_mail_ui_session_alert_user;
+ CAMEL_SESSION_GET_CLASS (session)->trust_prompt = e_mail_ui_session_trust_prompt;
service = camel_session_add_service (
session, "fake-uid",
diff --git a/mail/e-mail-ui-session.c b/mail/e-mail-ui-session.c
index 7f80d8b6be..fcb7ced349 100644
--- a/mail/e-mail-ui-session.c
+++ b/mail/e-mail-ui-session.c
@@ -106,210 +106,6 @@ struct _SourceContext {
CamelService *service;
};
-/* Support for CamelSession.alert_user() *************************************/
-
-static gpointer user_message_dialog;
-static GQueue user_message_queue = { NULL, NULL, 0 };
-
-struct _user_message_msg {
- MailMsg base;
-
- CamelSessionAlertType type;
- gchar *prompt;
- GSList *button_captions;
- EFlag *done;
-
- gint result;
- guint ismain : 1;
-};
-
-static void user_message_exec (struct _user_message_msg *m,
- GCancellable *cancellable,
- GError **error);
-
-static void
-user_message_response_free (GtkDialog *dialog,
- gint button)
-{
- struct _user_message_msg *m = NULL;
-
- gtk_widget_destroy ((GtkWidget *) dialog);
-
- user_message_dialog = NULL;
-
- /* check for pendings */
- if (!g_queue_is_empty (&user_message_queue)) {
- GCancellable *cancellable;
-
- m = g_queue_pop_head (&user_message_queue);
- cancellable = m->base.cancellable;
- user_message_exec (m, cancellable, &m->base.error);
- mail_msg_unref (m);
- }
-}
-
-/* clicked, send back the reply */
-static void
-user_message_response (GtkDialog *dialog,
- gint button,
- struct _user_message_msg *m)
-{
- /* if !m or !button_captions, then we've already replied */
- if (m && m->button_captions) {
- m->result = button;
- e_flag_set (m->done);
- }
-
- user_message_response_free (dialog, button);
-}
-
-static void
-user_message_exec (struct _user_message_msg *m,
- GCancellable *cancellable,
- GError **error)
-{
- gboolean info_only;
- GtkWindow *parent;
- EShell *shell;
- const gchar *error_type;
- gint index;
- GSList *iter;
-
- info_only = g_slist_length (m->button_captions) <= 1;
-
- if (!m->ismain && user_message_dialog != NULL && !info_only) {
- g_queue_push_tail (&user_message_queue, mail_msg_ref (m));
- return;
- }
-
- switch (m->type) {
- case CAMEL_SESSION_ALERT_INFO:
- error_type = "system:simple-info";
- break;
- case CAMEL_SESSION_ALERT_WARNING:
- error_type = "system:simple-warning";
- break;
- case CAMEL_SESSION_ALERT_ERROR:
- error_type = "system:simple-error";
- break;
- default:
- error_type = NULL;
- g_return_if_reached ();
- }
-
- shell = e_shell_get_default ();
-
- /* try to find "mail" view to place the informational alert to */
- if (info_only) {
- GtkWindow *active_window;
- EShellWindow *shell_window;
- EShellView *shell_view;
- EShellContent *shell_content = NULL;
-
- /* check currently active window first, ... */
- active_window = e_shell_get_active_window (shell);
- if (active_window && E_IS_SHELL_WINDOW (active_window)) {
- if (E_IS_SHELL_WINDOW (active_window)) {
- shell_window = E_SHELL_WINDOW (active_window);
- shell_view = e_shell_window_peek_shell_view (shell_window, "mail");
- if (shell_view)
- shell_content = e_shell_view_get_shell_content (shell_view);
- }
- }
-
- if (!shell_content) {
- GList *list, *iter;
-
- list = gtk_application_get_windows (GTK_APPLICATION (shell));
-
- /* ...then iterate through all opened
- * windows and pick one which has it */
- for (iter = list; iter != NULL && !shell_content; iter = g_list_next (iter)) {
- if (E_IS_SHELL_WINDOW (iter->data)) {
- shell_window = iter->data;
- shell_view = e_shell_window_peek_shell_view (shell_window, "mail");
- if (shell_view)
- shell_content = e_shell_view_get_shell_content (shell_view);
- }
- }
- }
-
- /* When no shell-content found, which might not happen,
- * but just in case, process the information alert like
- * usual, through an EAlertDialog machinery. */
- if (shell_content) {
- e_alert_submit (
- E_ALERT_SINK (shell_content),
- error_type, m->prompt, NULL);
- return;
- } else if (!m->ismain && user_message_dialog != NULL) {
- g_queue_push_tail (&user_message_queue, mail_msg_ref (m));
- return;
- }
- }
-
- /* Pull in the active window from the shell to get a parent window */
- parent = e_shell_get_active_window (shell);
- user_message_dialog = e_alert_dialog_new_for_args (
- parent, error_type, m->prompt, NULL);
- g_object_set (user_message_dialog, "resizable", TRUE, NULL);
-
- if (m->button_captions) {
- GtkWidget *action_area;
- GList *children, *child;
-
- /* remove all default buttons and keep only those requested */
- action_area = gtk_dialog_get_action_area (GTK_DIALOG (user_message_dialog));
-
- children = gtk_container_get_children (GTK_CONTAINER (action_area));
- for (child = children; child != NULL; child = child->next) {
- gtk_container_remove (GTK_CONTAINER (action_area), child->data);
- }
-
- g_list_free (children);
- }
-
- for (index = 0, iter = m->button_captions; iter; index++, iter = iter->next) {
- gtk_dialog_add_button (GTK_DIALOG (user_message_dialog), iter->data, index);
- }
-
- /* XXX This is a case where we need to be able to construct
- * custom EAlerts without a predefined XML definition. */
- if (m->ismain) {
- gint response;
-
- response = gtk_dialog_run (user_message_dialog);
- user_message_response (
- user_message_dialog, response, m);
- } else {
- gpointer user_data = m;
-
- if (g_slist_length (m->button_captions) <= 1)
- user_data = NULL;
-
- g_signal_connect (
- user_message_dialog, "response",
- G_CALLBACK (user_message_response), user_data);
- gtk_widget_show (user_message_dialog);
- }
-}
-
-static void
-user_message_free (struct _user_message_msg *m)
-{
- g_free (m->prompt);
- g_slist_free_full (m->button_captions, g_free);
- e_flag_free (m->done);
-}
-
-static MailMsgInfo user_message_info = {
- sizeof (struct _user_message_msg),
- (MailMsgDescFunc) NULL,
- (MailMsgExecFunc) user_message_exec,
- (MailMsgDoneFunc) NULL,
- (MailMsgFreeFunc) user_message_free
-};
-
/* Support for CamelSession.get_filter_driver () *****************************/
static CamelFolder *
@@ -622,41 +418,27 @@ gint
e_mail_ui_session_alert_user (CamelSession *session,
CamelSessionAlertType type,
const gchar *prompt,
- GSList *button_captions)
+ GSList *button_captions,
+ GCancellable *cancellable)
{
- struct _user_message_msg *m;
- GCancellable *cancellable;
- gint result = -1;
- GSList *iter;
-
- m = mail_msg_new (&user_message_info);
- m->ismain = mail_in_main_thread ();
- m->type = type;
- m->prompt = g_strdup (prompt);
- m->done = e_flag_new ();
- m->button_captions = g_slist_copy (button_captions);
-
- for (iter = m->button_captions; iter; iter = iter->next)
- iter->data = g_strdup (iter->data);
-
- if (g_slist_length (button_captions) > 1)
- mail_msg_ref (m);
+ g_type_ensure (E_TYPE_MAIL_UI_SESSION);
- cancellable = m->base.cancellable;
-
- if (m->ismain)
- user_message_exec (m, cancellable, &m->base.error);
- else
- mail_msg_main_loop_push (m);
+ return CAMEL_SESSION_CLASS (e_mail_ui_session_parent_class)->alert_user (
+ session, type, prompt, button_captions, cancellable);
+}
- if (g_slist_length (button_captions) > 1) {
- e_flag_wait (m->done);
- result = m->result;
- mail_msg_unref (m);
- } else if (m->ismain)
- mail_msg_unref (m);
+CamelCertTrust
+e_mail_ui_session_trust_prompt (CamelSession *session,
+ const gchar *host,
+ const gchar *certificate,
+ guint32 certificate_errors,
+ const GSList *issuers,
+ GCancellable *cancellable)
+{
+ g_type_ensure (E_TYPE_MAIL_UI_SESSION);
- return result;
+ return CAMEL_SESSION_CLASS (e_mail_ui_session_parent_class)->trust_prompt (
+ session, host, certificate, certificate_errors, issuers, cancellable);
}
static CamelFilterDriver *
@@ -700,7 +482,6 @@ e_mail_ui_session_class_init (EMailUISessionClass *class)
session_class = CAMEL_SESSION_CLASS (class);
session_class->add_service = mail_ui_session_add_service;
session_class->remove_service = mail_ui_session_remove_service;
- session_class->alert_user = e_mail_ui_session_alert_user;
session_class->get_filter_driver = mail_ui_session_get_filter_driver;
mail_session_class = E_MAIL_SESSION_CLASS (class);
diff --git a/mail/e-mail-ui-session.h b/mail/e-mail-ui-session.h
index e6a65014b3..105a14adf8 100644
--- a/mail/e-mail-ui-session.h
+++ b/mail/e-mail-ui-session.h
@@ -87,7 +87,14 @@ void e_mail_ui_session_add_activity (EMailUISession *session,
gint e_mail_ui_session_alert_user (CamelSession *session,
CamelSessionAlertType type,
const gchar *prompt,
- GSList *button_captions);
+ GSList *button_captions,
+ GCancellable *cancellable);
+CamelCertTrust e_mail_ui_session_trust_prompt (CamelSession *session,
+ const gchar *host,
+ const gchar *certificate,
+ guint32 certificate_errors,
+ const GSList *issuers,
+ GCancellable *cancellable);
G_END_DECLS