-/* if (!priv->error) { */
-/* tny_header_set_flags (header, TNY_HEADER_FLAG_DELETED); */
-/* tny_header_set_flags (header, TNY_HEADER_FLAG_SEEN); */
-
-/* if (TNY_IS_CAMEL_IMAP_FOLDER (folder)) */
-/* tny_folder_sync_async(folder, FALSE, NULL, NULL, NULL); /\* FALSE --> don't expunge *\/ */
-/* /\* tny_folder_sync (folder, FALSE, &(priv->error)); /\\* FALSE --> don't expunge *\\/ *\/ */
-/* else if (TNY_IS_CAMEL_POP_FOLDER (folder)) */
-/* tny_folder_sync_async(folder, FALSE, NULL, NULL, NULL); /\* TRUE --> dont expunge *\/ */
-/* /\* tny_folder_sync (folder, TRUE, &(priv->error)); /\\* TRUE --> expunge *\\/ *\/ */
-/* else */
-/* /\* local folders *\/ */
-/* tny_folder_sync_async(folder, TRUE, NULL, NULL, NULL); /\* TRUE --> expunge *\/ */
-/* /\* tny_folder_sync (folder, TRUE, &(priv->error)); /\\* TRUE --> expunge *\\/ *\/ */
-/* } */
+ if (!priv->error) {
+ gboolean expunge, leave_on_server;
+ const gchar *account_name;
+ TnyAccount *account;
+ ModestTransportStoreProtocol account_proto;
+
+ tny_header_set_flag (header, TNY_HEADER_FLAG_DELETED);
+ tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN);
+
+ modest_mail_operation_notify_start (self);
+
+ /* Get leave on server setting */
+ account = tny_folder_get_account (folder);
+ account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (account);
+ leave_on_server =
+ modest_account_mgr_get_leave_on_server (modest_runtime_get_account_mgr (),
+ account_name);
+
+ account_proto = modest_protocol_info_get_transport_store_protocol (tny_account_get_proto (account));
+
+ if (((account_proto == MODEST_PROTOCOL_STORE_POP) && !leave_on_server) ||
+ modest_tny_folder_is_remote_folder (folder) == FALSE)
+ expunge = TRUE;
+ else
+ expunge = FALSE;
+
+ /* Sync folder */
+ tny_folder_sync_async(folder, expunge, NULL, NULL, NULL);
+
+ /* Unref */
+ g_object_unref (account);
+ }
+
+
+ /* Set status */
+ if (!priv->error)
+ priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
+ else
+ priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
+
+ /* Free */
+ g_object_unref (G_OBJECT (folder));
+
+ /* Notify about operation end */
+ modest_mail_operation_notify_end (self);
+}
+
+void
+modest_mail_operation_remove_msgs (ModestMailOperation *self,
+ TnyList *headers,
+ gboolean remove_to_trash /*ignored*/)
+{
+ TnyFolder *folder;
+ ModestMailOperationPrivate *priv;
+ TnyIterator *iter = NULL;
+ TnyHeader *header = NULL;
+ TnyList *remove_headers = NULL;
+ TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
+
+ g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
+ g_return_if_fail (TNY_IS_LIST (headers));
+
+ if (remove_to_trash)
+ g_warning ("remove to trash is not implemented");
+
+ priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
+
+ remove_headers = g_object_ref(headers);
+
+ /* Get folder from first header and sync it */
+ iter = tny_list_create_iterator (headers);
+ header = TNY_HEADER (tny_iterator_get_current (iter));
+ folder = tny_header_get_folder (header);
+
+ /* Don't remove messages that are being sent */
+ if (modest_tny_folder_is_local_folder (folder)) {
+ folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
+ }
+ if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
+ TnyTransportAccount *traccount = NULL;
+ ModestTnyAccountStore *accstore = modest_runtime_get_account_store();
+ traccount = modest_tny_account_store_get_transport_account_from_outbox_header(accstore, header);
+ if (traccount) {
+ ModestTnySendQueueStatus status;
+ ModestTnySendQueue *send_queue = modest_runtime_get_send_queue(traccount);
+ TnyIterator *iter = tny_list_create_iterator(headers);
+ g_object_unref(remove_headers);
+ remove_headers = TNY_LIST(tny_simple_list_new());
+ while (!tny_iterator_is_done(iter)) {
+ char *msg_id;
+ TnyHeader *hdr = TNY_HEADER(tny_iterator_get_current(iter));
+ msg_id = modest_tny_send_queue_get_msg_id (hdr);
+ status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
+ if (status != MODEST_TNY_SEND_QUEUE_SENDING) {
+ tny_list_append(remove_headers, G_OBJECT(hdr));
+ }
+ g_object_unref(hdr);
+ g_free(msg_id);
+ tny_iterator_next(iter);
+ }
+ g_object_unref(iter);
+ g_object_unref(traccount);
+ }
+ }
+
+ /* Get account and set it into mail_operation */
+ priv->account = modest_tny_folder_get_account (TNY_FOLDER(folder));
+ priv->op_type = MODEST_MAIL_OPERATION_TYPE_DELETE;
+ priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
+
+ /* remove message from folder */
+ modest_mail_operation_notify_start (self);
+
+ tny_folder_remove_msgs (folder, remove_headers, &(priv->error));
+ if (!priv->error) {
+ gboolean expunge, leave_on_server;
+ const gchar *account_name;
+ const gchar *proto;
+ TnyAccount *account;
+ ModestTransportStoreProtocol account_proto = MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN;
+
+ account = tny_folder_get_account (folder);
+ account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (account);
+ leave_on_server =
+ modest_account_mgr_get_leave_on_server (modest_runtime_get_account_mgr (),
+ account_name);
+
+ proto = tny_account_get_proto (account);
+ if (proto) {
+ account_proto = modest_protocol_info_get_transport_store_protocol (proto);
+ }
+
+ if (((account_proto == MODEST_PROTOCOL_STORE_POP) && !leave_on_server) ||
+ modest_tny_folder_is_remote_folder (folder) == FALSE)
+ expunge = TRUE;
+ else
+ expunge = FALSE;
+
+ /* Sync folder */
+ tny_folder_sync_async(folder, expunge, NULL, NULL, NULL);
+
+ g_object_unref (account);
+ }