[evolution] Bug #693254 - Mail reply uses wrong "From:" account



commit 853abba1d383c27733c0fca23aaae165c30eea54
Author: Milan Crha <mcrha redhat com>
Date:   Tue Mar 5 14:14:31 2013 +0100

    Bug #693254 - Mail reply uses wrong "From:" account

 libemail-engine/e-mail-utils.c |   45 +++++++++++++++++-----
 libemail-engine/e-mail-utils.h |   16 ++++++++
 mail/em-composer-utils.c       |   82 ++++++++++++++++++++++++++++++++++++++--
 3 files changed, 129 insertions(+), 14 deletions(-)
---
diff --git a/libemail-engine/e-mail-utils.c b/libemail-engine/e-mail-utils.c
index cc5ef73..7b406ec 100644
--- a/libemail-engine/e-mail-utils.c
+++ b/libemail-engine/e-mail-utils.c
@@ -484,10 +484,12 @@ mail_account_in_recipients (ESourceRegistry *registry,
 }
 
 ESource *
-em_utils_guess_mail_account_with_recipients (ESourceRegistry *registry,
-                                             CamelMimeMessage *message,
-                                             CamelFolder *folder,
-                                             const gchar *message_uid)
+em_utils_guess_mail_account_with_recipients_and_sort (ESourceRegistry *registry,
+                                                     CamelMimeMessage *message,
+                                                     CamelFolder *folder,
+                                                     const gchar *message_uid,
+                                                     EMailUtilsSourtSourcesFunc sort_func,
+                                                     gpointer sort_func_data)
 {
        ESource *source = NULL;
        GHashTable *recipients;
@@ -552,6 +554,9 @@ second_preference:
        extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
        list = e_source_registry_list_sources (registry, extension_name);
 
+       if (sort_func)
+               sort_func (&list, sort_func_data);
+
        for (iter = list; iter != NULL; iter = g_list_next (iter)) {
                ESource *temp = E_SOURCE (iter->data);
 
@@ -578,10 +583,12 @@ exit:
 }
 
 ESource *
-em_utils_guess_mail_identity_with_recipients (ESourceRegistry *registry,
-                                              CamelMimeMessage *message,
-                                              CamelFolder *folder,
-                                              const gchar *message_uid)
+em_utils_guess_mail_identity_with_recipients_and_sort (ESourceRegistry *registry,
+                                                      CamelMimeMessage *message,
+                                                      CamelFolder *folder,
+                                                      const gchar *message_uid,
+                                                      EMailUtilsSourtSourcesFunc sort_func,
+                                                      gpointer sort_func_data)
 {
        ESource *source;
        ESourceExtension *extension;
@@ -591,8 +598,8 @@ em_utils_guess_mail_identity_with_recipients (ESourceRegistry *registry,
        g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
        g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), NULL);
 
-       source = em_utils_guess_mail_account_with_recipients (
-               registry, message, folder, message_uid);
+       source = em_utils_guess_mail_account_with_recipients_and_sort (
+               registry, message, folder, message_uid, sort_func, sort_func_data);
 
        if (source == NULL)
                return NULL;
@@ -619,6 +626,24 @@ em_utils_guess_mail_identity_with_recipients (ESourceRegistry *registry,
 }
 
 ESource *
+em_utils_guess_mail_account_with_recipients (ESourceRegistry *registry,
+                                             CamelMimeMessage *message,
+                                             CamelFolder *folder,
+                                             const gchar *message_uid)
+{
+       return em_utils_guess_mail_account_with_recipients_and_sort (registry, message, folder, message_uid, 
NULL, NULL);
+}
+
+ESource *
+em_utils_guess_mail_identity_with_recipients (ESourceRegistry *registry,
+                                              CamelMimeMessage *message,
+                                              CamelFolder *folder,
+                                              const gchar *message_uid)
+{
+       return em_utils_guess_mail_identity_with_recipients_and_sort (registry, message, folder, message_uid, 
NULL, NULL);
+}
+
+ESource *
 em_utils_ref_mail_identity_for_store (ESourceRegistry *registry,
                                       CamelStore *store)
 {
diff --git a/libemail-engine/e-mail-utils.h b/libemail-engine/e-mail-utils.h
index 87bf337..b9201d9 100644
--- a/libemail-engine/e-mail-utils.h
+++ b/libemail-engine/e-mail-utils.h
@@ -25,6 +25,8 @@
 #include <camel/camel.h>
 #include <libedataserver/libedataserver.h>
 
+typedef void (* EMailUtilsSourtSourcesFunc) (GList **psources, gpointer user_data);
+
 gboolean       em_utils_folder_is_drafts       (ESourceRegistry *registry,
                                                 CamelFolder *folder);
 gboolean       em_utils_folder_is_templates    (ESourceRegistry *registry,
@@ -51,6 +53,20 @@ ESource *    em_utils_guess_mail_identity_with_recipients
                                                 CamelMimeMessage *message,
                                                 CamelFolder *folder,
                                                 const gchar *message_uid);
+ESource *      em_utils_guess_mail_account_with_recipients_and_sort
+                                               (ESourceRegistry *registry,
+                                                CamelMimeMessage *message,
+                                                CamelFolder *folder,
+                                                const gchar *message_uid,
+                                                EMailUtilsSourtSourcesFunc sort_func,
+                                                gpointer sort_func_data);
+ESource *      em_utils_guess_mail_identity_with_recipients_and_sort
+                                               (ESourceRegistry *registry,
+                                                CamelMimeMessage *message,
+                                                CamelFolder *folder,
+                                                const gchar *message_uid,
+                                                EMailUtilsSourtSourcesFunc sort_func,
+                                                gpointer sort_func_data);
 ESource *      em_utils_ref_mail_identity_for_store
                                                (ESourceRegistry *registry,
                                                 CamelStore *store);
diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c
index 9962101..d52d04c 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -50,6 +50,7 @@
 #include <composer/e-composer-post-header.h>
 
 #include "e-mail-printer.h"
+#include "e-mail-ui-session.h"
 #include "em-utils.h"
 #include "em-composer-utils.h"
 #include "em-folder-selector.h"
@@ -1965,6 +1966,79 @@ em_utils_forward_messages (EMailReader *reader,
        }
 }
 
+static gint
+compare_sources_with_uids_order_cb (gconstpointer a,
+                                   gconstpointer b,
+                                   gpointer user_data)
+{
+       ESource *asource = (ESource *) a;
+       ESource *bsource = (ESource *) b;
+       GHashTable *uids_order = user_data;
+       gint aindex, bindex;
+
+       aindex = GPOINTER_TO_INT (g_hash_table_lookup (uids_order, e_source_get_uid (asource)));
+       bindex = GPOINTER_TO_INT (g_hash_table_lookup (uids_order, e_source_get_uid (bsource)));
+
+       if (aindex <= 0)
+               aindex = g_hash_table_size (uids_order);
+       if (bindex <= 0)
+               bindex = g_hash_table_size (uids_order);
+
+       return aindex - bindex;
+}
+
+static void
+sort_sources_by_ui (GList **psources,
+                   gpointer user_data)
+{
+       EShell *shell = user_data;
+       EShellBackend *shell_backend;
+       EMailSession *mail_session;
+       EMailAccountStore *account_store;
+       GtkTreeModel *model;
+       GtkTreeIter iter;
+       GHashTable *uids_order;
+       gint index = 0;
+
+       g_return_if_fail (psources != NULL);
+       g_return_if_fail (E_IS_SHELL (shell));
+
+       /* nothing to sort */
+       if (!*psources || !g_list_next (*psources))
+               return;
+
+       shell_backend = e_shell_get_backend_by_name (shell, "mail");
+       g_return_if_fail (shell_backend != NULL);
+
+       mail_session = e_mail_backend_get_session (E_MAIL_BACKEND (shell_backend));
+       g_return_if_fail (mail_session != NULL);
+
+       account_store = e_mail_ui_session_get_account_store (E_MAIL_UI_SESSION (mail_session));
+       g_return_if_fail (account_store != NULL);
+
+       model = GTK_TREE_MODEL (account_store);
+       if (!gtk_tree_model_get_iter_first (model, &iter))
+               return;
+
+       uids_order = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+
+       do {
+               CamelService *service = NULL;
+
+               gtk_tree_model_get (model, &iter, E_MAIL_ACCOUNT_STORE_COLUMN_SERVICE, &service, -1);
+
+               if (service) {
+                       index++;
+                       g_hash_table_insert (uids_order, g_strdup (camel_service_get_uid (service)), 
GINT_TO_POINTER (index));
+                       g_object_unref (service);
+               }
+       } while (gtk_tree_model_iter_next (model, &iter));
+
+       *psources = g_list_sort_with_data (*psources, compare_sources_with_uids_order_cb, uids_order);
+
+       g_hash_table_destroy (uids_order);
+}
+
 /* Redirecting messages... */
 
 static EMsgComposer *
@@ -1994,8 +2068,8 @@ redirect_get_composer (EShell *shell,
        registry = e_shell_get_registry (shell);
 
        /* This returns a new ESource reference. */
-       source = em_utils_guess_mail_identity_with_recipients (
-               registry, message, NULL, NULL);
+       source = em_utils_guess_mail_identity_with_recipients_and_sort (
+               registry, message, NULL, NULL, sort_sources_by_ui, shell);
 
        if (source != NULL) {
                identity_uid = e_source_dup_uid (source);
@@ -2932,8 +3006,8 @@ em_utils_reply_to_message (EShell *shell,
        registry = e_shell_get_registry (shell);
 
        /* This returns a new ESource reference. */
-       source = em_utils_guess_mail_identity_with_recipients (
-               registry, message, folder, message_uid);
+       source = em_utils_guess_mail_identity_with_recipients_and_sort (
+               registry, message, folder, message_uid, sort_sources_by_ui, shell);
        if (source != NULL) {
                identity_uid = e_source_dup_uid (source);
                g_object_unref (source);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]