Commit 853abba1 authored by Milan Crha's avatar Milan Crha
Browse files

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

parent 642eaed1
...@@ -484,10 +484,12 @@ mail_account_in_recipients (ESourceRegistry *registry, ...@@ -484,10 +484,12 @@ mail_account_in_recipients (ESourceRegistry *registry,
} }
ESource * ESource *
em_utils_guess_mail_account_with_recipients (ESourceRegistry *registry, em_utils_guess_mail_account_with_recipients_and_sort (ESourceRegistry *registry,
CamelMimeMessage *message, CamelMimeMessage *message,
CamelFolder *folder, CamelFolder *folder,
const gchar *message_uid) const gchar *message_uid,
EMailUtilsSourtSourcesFunc sort_func,
gpointer sort_func_data)
{ {
ESource *source = NULL; ESource *source = NULL;
GHashTable *recipients; GHashTable *recipients;
...@@ -552,6 +554,9 @@ second_preference: ...@@ -552,6 +554,9 @@ second_preference:
extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT; extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
list = e_source_registry_list_sources (registry, extension_name); 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)) { for (iter = list; iter != NULL; iter = g_list_next (iter)) {
ESource *temp = E_SOURCE (iter->data); ESource *temp = E_SOURCE (iter->data);
...@@ -578,10 +583,12 @@ exit: ...@@ -578,10 +583,12 @@ exit:
} }
ESource * ESource *
em_utils_guess_mail_identity_with_recipients (ESourceRegistry *registry, em_utils_guess_mail_identity_with_recipients_and_sort (ESourceRegistry *registry,
CamelMimeMessage *message, CamelMimeMessage *message,
CamelFolder *folder, CamelFolder *folder,
const gchar *message_uid) const gchar *message_uid,
EMailUtilsSourtSourcesFunc sort_func,
gpointer sort_func_data)
{ {
ESource *source; ESource *source;
ESourceExtension *extension; ESourceExtension *extension;
...@@ -591,8 +598,8 @@ em_utils_guess_mail_identity_with_recipients (ESourceRegistry *registry, ...@@ -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 (E_IS_SOURCE_REGISTRY (registry), NULL);
g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), NULL); g_return_val_if_fail (CAMEL_IS_MIME_MESSAGE (message), NULL);
source = em_utils_guess_mail_account_with_recipients ( source = em_utils_guess_mail_account_with_recipients_and_sort (
registry, message, folder, message_uid); registry, message, folder, message_uid, sort_func, sort_func_data);
if (source == NULL) if (source == NULL)
return NULL; return NULL;
...@@ -618,6 +625,24 @@ em_utils_guess_mail_identity_with_recipients (ESourceRegistry *registry, ...@@ -618,6 +625,24 @@ em_utils_guess_mail_identity_with_recipients (ESourceRegistry *registry,
return source; return source;
} }
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 * ESource *
em_utils_ref_mail_identity_for_store (ESourceRegistry *registry, em_utils_ref_mail_identity_for_store (ESourceRegistry *registry,
CamelStore *store) CamelStore *store)
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include <camel/camel.h> #include <camel/camel.h>
#include <libedataserver/libedataserver.h> #include <libedataserver/libedataserver.h>
typedef void (* EMailUtilsSourtSourcesFunc) (GList **psources, gpointer user_data);
gboolean em_utils_folder_is_drafts (ESourceRegistry *registry, gboolean em_utils_folder_is_drafts (ESourceRegistry *registry,
CamelFolder *folder); CamelFolder *folder);
gboolean em_utils_folder_is_templates (ESourceRegistry *registry, gboolean em_utils_folder_is_templates (ESourceRegistry *registry,
...@@ -51,6 +53,20 @@ ESource * em_utils_guess_mail_identity_with_recipients ...@@ -51,6 +53,20 @@ ESource * em_utils_guess_mail_identity_with_recipients
CamelMimeMessage *message, CamelMimeMessage *message,
CamelFolder *folder, CamelFolder *folder,
const gchar *message_uid); 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 ESource * em_utils_ref_mail_identity_for_store
(ESourceRegistry *registry, (ESourceRegistry *registry,
CamelStore *store); CamelStore *store);
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#include <composer/e-composer-post-header.h> #include <composer/e-composer-post-header.h>
#include "e-mail-printer.h" #include "e-mail-printer.h"
#include "e-mail-ui-session.h"
#include "em-utils.h" #include "em-utils.h"
#include "em-composer-utils.h" #include "em-composer-utils.h"
#include "em-folder-selector.h" #include "em-folder-selector.h"
...@@ -1965,6 +1966,79 @@ em_utils_forward_messages (EMailReader *reader, ...@@ -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... */ /* Redirecting messages... */
static EMsgComposer * static EMsgComposer *
...@@ -1994,8 +2068,8 @@ redirect_get_composer (EShell *shell, ...@@ -1994,8 +2068,8 @@ redirect_get_composer (EShell *shell,
registry = e_shell_get_registry (shell); registry = e_shell_get_registry (shell);
/* This returns a new ESource reference. */ /* This returns a new ESource reference. */
source = em_utils_guess_mail_identity_with_recipients ( source = em_utils_guess_mail_identity_with_recipients_and_sort (
registry, message, NULL, NULL); registry, message, NULL, NULL, sort_sources_by_ui, shell);
if (source != NULL) { if (source != NULL) {
identity_uid = e_source_dup_uid (source); identity_uid = e_source_dup_uid (source);
...@@ -2932,8 +3006,8 @@ em_utils_reply_to_message (EShell *shell, ...@@ -2932,8 +3006,8 @@ em_utils_reply_to_message (EShell *shell,
registry = e_shell_get_registry (shell); registry = e_shell_get_registry (shell);
/* This returns a new ESource reference. */ /* This returns a new ESource reference. */
source = em_utils_guess_mail_identity_with_recipients ( source = em_utils_guess_mail_identity_with_recipients_and_sort (
registry, message, folder, message_uid); registry, message, folder, message_uid, sort_sources_by_ui, shell);
if (source != NULL) { if (source != NULL) {
identity_uid = e_source_dup_uid (source); identity_uid = e_source_dup_uid (source);
g_object_unref (source); g_object_unref (source);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment