[evolution/gnome-3-6] Bug #693254 - Mail reply uses wrong "From:" account
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/gnome-3-6] Bug #693254 - Mail reply uses wrong "From:" account
- Date: Tue, 5 Mar 2013 13:15:32 +0000 (UTC)
commit 0f04843c8b25e06d5cbed20e5173fe61fa10dde2
Author: Milan Crha <mcrha redhat com>
Date: Tue Mar 5 14:15:10 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 52c5fb3..ef99074 100644
--- a/libemail-engine/e-mail-utils.c
+++ b/libemail-engine/e-mail-utils.c
@@ -1104,10 +1104,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;
@@ -1176,6 +1178,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);
@@ -1202,10 +1207,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;
@@ -1215,8 +1222,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;
@@ -1243,6 +1250,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 e7521d6..9f6477f 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,
@@ -59,6 +61,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 8c463b9..9015d05 100644
--- a/mail/em-composer-utils.c
+++ b/mail/em-composer-utils.c
@@ -53,6 +53,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"
@@ -1926,6 +1927,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 *
@@ -1955,8 +2029,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);
@@ -2893,8 +2967,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]