+/**
+ * Returns the account a list of headers belongs to. It returns a
+ * *new* reference so don't forget to unref it
+ */
+static TnyAccount*
+get_account_from_header_list (TnyList *headers)
+{
+ TnyAccount *account = NULL;
+
+ if (tny_list_get_length (headers) > 0) {
+ TnyIterator *iter = tny_list_create_iterator (headers);
+ TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
+ TnyFolder *folder = tny_header_get_folder (header);
+ account = tny_folder_get_account (folder);
+ g_object_unref (folder);
+ g_object_unref (header);
+ g_object_unref (iter);
+ }
+ return account;
+}
+
+static void
+open_msgs_performer(gboolean canceled,
+ GError *err,
+ GtkWindow *parent_window,
+ TnyAccount *account,
+ gpointer user_data)
+{
+ ModestMailOperation *mail_op;
+ const gchar *proto_name;
+ gchar *error_msg;
+ ModestTransportStoreProtocol proto;
+ TnyList *not_opened_headers;
+
+ not_opened_headers = TNY_LIST (user_data);
+
+ /* Get the error message depending on the protocol */
+ proto_name = tny_account_get_proto (account);
+ if (proto_name != NULL) {
+ proto = modest_protocol_info_get_transport_store_protocol (proto_name);
+ } else {
+ proto = MODEST_PROTOCOL_STORE_MAILDIR;
+ }
+
+ /* Create the error messages */
+ if (tny_list_get_length (not_opened_headers) == 1) {
+ if (proto == MODEST_PROTOCOL_STORE_POP) {
+ error_msg = g_strdup (_("emev_ni_ui_pop3_msg_recv_error"));
+ } else if (proto == MODEST_PROTOCOL_STORE_IMAP) {
+ TnyIterator *iter = tny_list_create_iterator (not_opened_headers);
+ TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
+ error_msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"),
+ tny_header_get_subject (header));
+ g_object_unref (header);
+ g_object_unref (iter);
+ } else {
+ error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
+ }
+ } else {
+ error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
+ }
+
+ /* Create the mail operation */
+ mail_op =
+ modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
+ modest_ui_actions_get_msgs_full_error_handler,
+ error_msg, g_free);
+ modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
+ mail_op);
+
+ modest_mail_operation_get_msgs_full (mail_op,
+ not_opened_headers,
+ open_msg_cb,
+ NULL,
+ NULL);
+
+ /* Frees */
+ g_object_unref (mail_op);
+ g_object_unref (not_opened_headers);
+ g_object_unref (account);
+}
+