aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mail/e-mail-reader-utils.c10
-rw-r--r--mail/message-list.c60
-rw-r--r--mail/message-list.h3
3 files changed, 73 insertions, 0 deletions
diff --git a/mail/e-mail-reader-utils.c b/mail/e-mail-reader-utils.c
index 74369202ba..36e745570a 100644
--- a/mail/e-mail-reader-utils.c
+++ b/mail/e-mail-reader-utils.c
@@ -1600,6 +1600,16 @@ e_mail_reader_save_messages (EMailReader *reader)
uids = e_mail_reader_get_selected_uids (reader);
g_return_if_fail (uids != NULL && uids->len > 0);
+
+ if (uids->len > 1) {
+ GtkWidget *message_list = e_mail_reader_get_message_list (reader);
+
+ g_warn_if_fail (message_list != NULL);
+
+ if (message_list)
+ message_list_sort_uids (MESSAGE_LIST (message_list), uids);
+ }
+
message_uid = g_ptr_array_index (uids, 0);
/* XXX Either e_mail_reader_get_selected_uids()
diff --git a/mail/message-list.c b/mail/message-list.c
index dcae35ffd3..f94953f1d7 100644
--- a/mail/message-list.c
+++ b/mail/message-list.c
@@ -4251,6 +4251,66 @@ message_list_set_selected (MessageList *ml,
g_ptr_array_free (paths, TRUE);
}
+struct ml_sort_uids_data {
+ gchar *uid;
+ gint row;
+};
+
+static gint
+ml_sort_uids_cb (gconstpointer a,
+ gconstpointer b)
+{
+ struct ml_sort_uids_data * const *pdataA = a;
+ struct ml_sort_uids_data * const *pdataB = b;
+
+ return (* pdataA)->row - (* pdataB)->row;
+}
+
+void
+message_list_sort_uids (MessageList *message_list,
+ GPtrArray *uids)
+{
+ struct ml_sort_uids_data *data;
+ GPtrArray *array;
+ ETreePath path;
+ ETreeTableAdapter *adapter;
+ gint ii;
+
+ g_return_if_fail (message_list != NULL);
+ g_return_if_fail (IS_MESSAGE_LIST (message_list));
+ g_return_if_fail (uids != NULL);
+
+ if (uids->len <= 1)
+ return;
+
+ adapter = e_tree_get_table_adapter (E_TREE (message_list));
+
+ array = g_ptr_array_new_full (uids->len, g_free);
+
+ for (ii = 0; ii < uids->len; ii++) {
+ data = g_new0 (struct ml_sort_uids_data, 1);
+ data->uid = g_ptr_array_index (uids, ii);
+
+ path = g_hash_table_lookup (message_list->uid_nodemap, data->uid);
+ if (path)
+ data->row = e_tree_table_adapter_row_of_node (adapter, path);
+ else
+ data->row = ii;
+
+ g_ptr_array_add (array, data);
+ }
+
+ g_ptr_array_sort (array, ml_sort_uids_cb);
+
+ for (ii = 0; ii < uids->len; ii++) {
+ data = g_ptr_array_index (array, ii);
+
+ uids->pdata[ii] = data->uid;
+ }
+
+ g_ptr_array_free (array, TRUE);
+}
+
struct ml_count_data {
MessageList *ml;
guint count;
diff --git a/mail/message-list.h b/mail/message-list.h
index daa27f2c1a..4396291199 100644
--- a/mail/message-list.h
+++ b/mail/message-list.h
@@ -229,6 +229,9 @@ void message_list_ensure_message (MessageList *message_list,
const gchar *uid);
void message_list_save_state (MessageList *message_list);
+void message_list_sort_uids (MessageList *message_list,
+ GPtrArray *uids);
+
#define MESSAGE_LIST_LOCK(m, l) g_mutex_lock(((MessageList *)m)->l)
#define MESSAGE_LIST_UNLOCK(m, l) g_mutex_unlock(((MessageList *)m)->l)