1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "modest-mail-operation.h"
31 /* include other impl specific header files */
34 #include <tny-mime-part.h>
35 #include <tny-store-account.h>
36 #include <tny-folder-store.h>
37 #include <tny-folder-store-query.h>
38 #include <tny-camel-stream.h>
39 #include <tny-simple-list.h>
40 #include <tny-send-queue.h>
41 #include <camel/camel-stream-mem.h>
42 #include <glib/gi18n.h>
43 #include <modest-tny-account.h>
44 #include <modest-tny-send-queue.h>
45 #include <modest-runtime.h>
46 #include "modest-text-utils.h"
47 #include "modest-tny-msg.h"
48 #include "modest-tny-platform-factory.h"
49 #include "modest-marshal.h"
50 #include "modest-formatter.h"
51 #include "modest-error.h"
53 /* 'private'/'protected' functions */
54 static void modest_mail_operation_class_init (ModestMailOperationClass *klass);
55 static void modest_mail_operation_init (ModestMailOperation *obj);
56 static void modest_mail_operation_finalize (GObject *obj);
58 static void status_update_cb (TnyFolder *folder,
63 static void folder_refresh_cb (TnyFolder *folder,
67 static void update_folders_cb (TnyFolderStore *self,
71 static void add_attachments (TnyMsg *msg,
72 GList *attachments_list);
74 enum _ModestMailOperationSignals
76 PROGRESS_CHANGED_SIGNAL,
81 typedef struct _ModestMailOperationPrivate ModestMailOperationPrivate;
82 struct _ModestMailOperationPrivate {
85 ModestMailOperationStatus status;
89 #define MODEST_MAIL_OPERATION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
90 MODEST_TYPE_MAIL_OPERATION, \
91 ModestMailOperationPrivate))
93 #define CHECK_EXCEPTION(priv, new_status, op) if (priv->error) {\
94 priv->status = new_status;\
98 typedef struct _RefreshFolderAsyncHelper
100 ModestMailOperation *mail_op;
105 } RefreshFolderAsyncHelper;
108 static GObjectClass *parent_class = NULL;
110 static guint signals[NUM_SIGNALS] = {0};
113 modest_mail_operation_get_type (void)
115 static GType my_type = 0;
117 static const GTypeInfo my_info = {
118 sizeof(ModestMailOperationClass),
119 NULL, /* base init */
120 NULL, /* base finalize */
121 (GClassInitFunc) modest_mail_operation_class_init,
122 NULL, /* class finalize */
123 NULL, /* class data */
124 sizeof(ModestMailOperation),
126 (GInstanceInitFunc) modest_mail_operation_init,
129 my_type = g_type_register_static (G_TYPE_OBJECT,
130 "ModestMailOperation",
137 modest_mail_operation_class_init (ModestMailOperationClass *klass)
139 GObjectClass *gobject_class;
140 gobject_class = (GObjectClass*) klass;
142 parent_class = g_type_class_peek_parent (klass);
143 gobject_class->finalize = modest_mail_operation_finalize;
145 g_type_class_add_private (gobject_class, sizeof(ModestMailOperationPrivate));
148 * ModestMailOperation::progress-changed
149 * @self: the #MailOperation that emits the signal
150 * @user_data: user data set when the signal handler was connected
152 * Emitted when the progress of a mail operation changes
154 signals[PROGRESS_CHANGED_SIGNAL] =
155 g_signal_new ("progress_changed",
156 G_TYPE_FROM_CLASS (gobject_class),
158 G_STRUCT_OFFSET (ModestMailOperationClass, progress_changed),
160 g_cclosure_marshal_VOID__VOID,
165 modest_mail_operation_init (ModestMailOperation *obj)
167 ModestMailOperationPrivate *priv;
169 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(obj);
171 priv->status = MODEST_MAIL_OPERATION_STATUS_INVALID;
178 modest_mail_operation_finalize (GObject *obj)
180 ModestMailOperationPrivate *priv;
182 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(obj);
185 g_error_free (priv->error);
189 G_OBJECT_CLASS(parent_class)->finalize (obj);
193 modest_mail_operation_new (void)
195 return MODEST_MAIL_OPERATION(g_object_new(MODEST_TYPE_MAIL_OPERATION, NULL));
200 modest_mail_operation_send_mail (ModestMailOperation *self,
201 TnyTransportAccount *transport_account,
204 TnySendQueue *send_queue;
206 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
207 g_return_if_fail (TNY_IS_TRANSPORT_ACCOUNT (transport_account));
209 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
210 if (!TNY_IS_SEND_QUEUE(send_queue))
211 g_printerr ("modest: could not find send queue for account\n");
214 tny_send_queue_add (send_queue, msg, &err);
216 g_printerr ("modest: error adding msg to send queue: %s\n",
220 g_message ("modest: message added to send queue");
225 modest_mail_operation_send_new_mail (ModestMailOperation *self,
226 TnyTransportAccount *transport_account,
227 const gchar *from, const gchar *to,
228 const gchar *cc, const gchar *bcc,
229 const gchar *subject, const gchar *body,
230 const GList *attachments_list)
233 ModestMailOperationPrivate *priv = NULL;
235 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
236 g_return_if_fail (TNY_IS_TRANSPORT_ACCOUNT (transport_account));
238 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
240 /* Check parametters */
242 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
243 MODEST_MAIL_OPERATION_ERROR_MISSING_PARAMETER,
244 _("Error trying to send a mail. You need to set at least one recipient"));
248 new_msg = modest_tny_msg_new (to, from, cc, bcc, subject, body, NULL); /* FIXME: attachments */
250 g_printerr ("modest: failed to create a new msg\n");
254 modest_mail_operation_send_mail (self, transport_account, new_msg);
256 g_object_unref (G_OBJECT(new_msg));
260 add_if_attachment (gpointer data, gpointer user_data)
263 GList *attachments_list;
265 part = TNY_MIME_PART (data);
266 attachments_list = (GList *) user_data;
268 if (tny_mime_part_is_attachment (part))
269 attachments_list = g_list_prepend (attachments_list, part);
274 create_reply_forward_mail (TnyMsg *msg, const gchar *from, gboolean is_reply, guint type)
277 TnyHeader *new_header, *header;
280 ModestFormatter *formatter;
282 /* Get body from original msg. Always look for the text/plain
283 part of the message to create the reply/forwarded mail */
284 header = tny_msg_get_header (msg);
285 body = modest_tny_msg_find_body_part (msg, FALSE);
287 /* TODO: select the formatter from account prefs */
288 formatter = modest_formatter_new ("text/plain");
290 /* Format message body */
293 case MODEST_MAIL_OPERATION_REPLY_TYPE_CITE:
295 new_msg = modest_formatter_cite (formatter, body, header);
297 case MODEST_MAIL_OPERATION_REPLY_TYPE_QUOTE:
298 new_msg = modest_formatter_quote (formatter, body, header);
303 case MODEST_MAIL_OPERATION_FORWARD_TYPE_INLINE:
305 new_msg = modest_formatter_inline (formatter, body, header);
307 case MODEST_MAIL_OPERATION_FORWARD_TYPE_ATTACHMENT:
308 new_msg = modest_formatter_attach (formatter, body, header);
312 g_object_unref (G_OBJECT(formatter));
313 g_object_unref (G_OBJECT(body));
315 /* Fill the header */
316 new_header = tny_msg_get_header (new_msg);
317 tny_header_set_from (new_header, from);
318 tny_header_set_replyto (new_header, from);
320 /* Change the subject */
322 (gchar *) modest_text_utils_derived_subject (tny_header_get_subject(header),
323 (is_reply) ? _("Re:") : _("Fwd:"));
324 tny_header_set_subject (new_header, (const gchar *) new_subject);
325 g_free (new_subject);
328 g_object_unref (G_OBJECT (new_header));
329 g_object_unref (G_OBJECT (header));
335 modest_mail_operation_create_forward_mail (TnyMsg *msg,
337 ModestMailOperationForwardType forward_type)
340 TnyList *parts = NULL;
341 GList *attachments_list = NULL;
343 new_msg = create_reply_forward_mail (msg, from, FALSE, forward_type);
345 /* Add attachments */
346 parts = TNY_LIST (tny_simple_list_new());
347 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
348 tny_list_foreach (parts, add_if_attachment, attachments_list);
349 add_attachments (new_msg, attachments_list);
352 if (attachments_list)
353 g_list_free (attachments_list);
354 g_object_unref (G_OBJECT (parts));
360 modest_mail_operation_create_reply_mail (TnyMsg *msg,
362 ModestMailOperationReplyType reply_type,
363 ModestMailOperationReplyMode reply_mode)
365 TnyMsg *new_msg = NULL;
366 TnyHeader *new_header, *header;
367 const gchar* reply_to;
368 gchar *new_cc = NULL;
369 const gchar *cc = NULL, *bcc = NULL;
372 new_msg = create_reply_forward_mail (msg, from, TRUE, reply_type);
374 /* Fill the header */
375 header = tny_msg_get_header (msg);
376 new_header = tny_msg_get_header (new_msg);
377 reply_to = tny_header_get_replyto (header);
380 tny_header_set_to (new_header, reply_to);
382 tny_header_set_to (new_header, tny_header_get_from (header));
384 switch (reply_mode) {
385 case MODEST_MAIL_OPERATION_REPLY_MODE_SENDER:
386 /* Do not fill neither cc nor bcc */
388 case MODEST_MAIL_OPERATION_REPLY_MODE_LIST:
391 case MODEST_MAIL_OPERATION_REPLY_MODE_ALL:
392 /* Concatenate to, cc and bcc */
393 cc = tny_header_get_cc (header);
394 bcc = tny_header_get_bcc (header);
396 tmp = g_string_new (tny_header_get_to (header));
397 if (cc) g_string_append_printf (tmp, ",%s",cc);
398 if (bcc) g_string_append_printf (tmp, ",%s",bcc);
400 /* Remove my own address from the cc list. TODO:
401 remove also the To: of the new message, needed due
402 to the new reply_to feature */
404 modest_text_utils_remove_address ((const gchar *) tmp->str,
406 /* FIXME: remove also the mails from the new To: */
407 tny_header_set_cc (new_header, new_cc);
410 g_string_free (tmp, TRUE);
416 g_object_unref (G_OBJECT (new_header));
417 g_object_unref (G_OBJECT (header));
423 status_update_cb (TnyFolder *folder, const gchar *what, gint status, gint oftotal, gpointer user_data)
425 g_print ("%s status: %d, of total %d\n", what, status, oftotal);
429 folder_refresh_cb (TnyFolder *folder, gboolean canceled, GError **err, gpointer user_data)
431 ModestMailOperation *self = NULL;
432 ModestMailOperationPrivate *priv = NULL;
433 RefreshFolderAsyncHelper *helper;
435 helper = (RefreshFolderAsyncHelper *) user_data;
436 self = MODEST_MAIL_OPERATION (helper->mail_op);
437 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
439 if ((canceled && *err) || *err) {
440 priv->error = g_error_copy (*err);
442 } else if (canceled) {
444 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
445 MODEST_MAIL_OPERATION_ERROR_OPERATION_CANCELED,
446 _("Error trying to refresh folder %s. Operation canceled"),
447 tny_folder_get_name (folder));
452 if (priv->done == priv->total)
453 priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
454 else if ((priv->done + helper->canceled + helper->failed) == priv->total) {
455 if (helper->failed == priv->total)
456 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
457 else if (helper->failed == priv->total)
458 priv->status = MODEST_MAIL_OPERATION_STATUS_CANCELED;
460 priv->status = MODEST_MAIL_OPERATION_STATUS_FINISHED_WITH_ERRORS;
462 tny_iterator_next (helper->iter);
463 if (tny_iterator_is_done (helper->iter)) {
465 list = tny_iterator_get_list (helper->iter);
466 g_object_unref (G_OBJECT (helper->iter));
467 g_object_unref (G_OBJECT (list));
468 g_slice_free (RefreshFolderAsyncHelper, helper);
470 TnyFolder *folder = TNY_FOLDER (tny_iterator_get_current (helper->iter));
472 g_message ("modest: refreshing folder %s",
473 tny_folder_get_name (folder));
474 tny_folder_refresh_async (folder, folder_refresh_cb, status_update_cb, helper);
475 g_object_unref (G_OBJECT(folder)); // FIXME: don't unref yet
478 g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
483 update_folders_cb (TnyFolderStore *folder_store, TnyList *list, GError **err, gpointer user_data)
485 ModestMailOperation *self;
486 ModestMailOperationPrivate *priv;
487 RefreshFolderAsyncHelper *helper;
490 self = MODEST_MAIL_OPERATION (user_data);
491 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
494 priv->error = g_error_copy (*err);
495 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
499 priv->total = tny_list_get_length (list);
501 priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
503 helper = g_slice_new0 (RefreshFolderAsyncHelper);
504 helper->mail_op = self;
505 helper->iter = tny_list_create_iterator (list);
507 helper->canceled = 0;
509 /* Async refresh folders */
510 folder = TNY_FOLDER (tny_iterator_get_current (helper->iter));
512 g_message ("modest: refreshing folder %s", tny_folder_get_name (folder));
513 tny_folder_refresh_async (folder, folder_refresh_cb,
514 status_update_cb, helper);
516 //g_object_unref (G_OBJECT(folder)); /* FIXME -==> don't unref yet... */
520 modest_mail_operation_update_account (ModestMailOperation *self,
521 TnyStoreAccount *store_account)
523 ModestMailOperationPrivate *priv;
525 TnyFolderStoreQuery *query;
527 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), FALSE);
528 g_return_val_if_fail (TNY_IS_STORE_ACCOUNT(store_account), FALSE);
530 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
532 /* Get subscribed folders & refresh them */
533 folders = TNY_LIST (tny_simple_list_new ());
534 query = NULL; //tny_folder_store_query_new ();
536 /* FIXME: is this needed? */
537 // tny_device_force_online (TNY_DEVICE(modest_runtime_get_device()));
539 /* FIXME: let query be NULL: do it for all */
540 //tny_folder_store_query_add_item (query, NULL, TNY_FOLDER_STORE_QUERY_OPTION_SUBSCRIBED);
541 tny_folder_store_get_folders_async (TNY_FOLDER_STORE (store_account),
542 folders, update_folders_cb, query, self);
543 //g_object_unref (query); /* FIXME */
548 ModestMailOperationStatus
549 modest_mail_operation_get_status (ModestMailOperation *self)
551 ModestMailOperationPrivate *priv;
553 g_return_val_if_fail (self, MODEST_MAIL_OPERATION_STATUS_INVALID);
554 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self),
555 MODEST_MAIL_OPERATION_STATUS_INVALID);
557 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
562 modest_mail_operation_get_error (ModestMailOperation *self)
564 ModestMailOperationPrivate *priv;
566 g_return_val_if_fail (self, NULL);
567 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), NULL);
569 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
574 modest_mail_operation_cancel (ModestMailOperation *self)
581 modest_mail_operation_get_task_done (ModestMailOperation *self)
583 ModestMailOperationPrivate *priv;
585 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), 0);
587 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
592 modest_mail_operation_get_task_total (ModestMailOperation *self)
594 ModestMailOperationPrivate *priv;
596 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), 0);
598 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
603 modest_mail_operation_is_finished (ModestMailOperation *self)
605 ModestMailOperationPrivate *priv;
606 gboolean retval = FALSE;
608 if (!MODEST_IS_MAIL_OPERATION (self)) {
609 g_warning ("%s: invalid parametter", G_GNUC_FUNCTION);
613 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
615 if (priv->status == MODEST_MAIL_OPERATION_STATUS_SUCCESS ||
616 priv->status == MODEST_MAIL_OPERATION_STATUS_FAILED ||
617 priv->status == MODEST_MAIL_OPERATION_STATUS_CANCELED ||
618 priv->status == MODEST_MAIL_OPERATION_STATUS_FINISHED_WITH_ERRORS) {
627 /* ******************************************************************* */
628 /* ************************** STORE ACTIONS ************************* */
629 /* ******************************************************************* */
633 modest_mail_operation_create_folder (ModestMailOperation *self,
634 TnyFolderStore *parent,
637 ModestMailOperationPrivate *priv;
638 TnyFolder *new_folder = NULL;
639 //TnyStoreAccount *store_account;
641 g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent), NULL);
642 g_return_val_if_fail (name, NULL);
644 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
646 /* Create the folder */
647 new_folder = tny_folder_store_create_folder (parent, name, &(priv->error));
648 CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED, return NULL);
650 /* /\* Subscribe to folder *\/ */
651 /* if (!tny_folder_is_subscribed (new_folder)) { */
652 /* store_account = TNY_STORE_ACCOUNT (tny_folder_get_account (TNY_FOLDER (parent))); */
653 /* tny_store_account_subscribe (store_account, new_folder); */
654 /* g_object_unref (G_OBJECT (store_account)); */
661 modest_mail_operation_remove_folder (ModestMailOperation *self,
663 gboolean remove_to_trash)
665 TnyFolderStore *parent;
667 ModestMailOperationPrivate *priv;
669 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
670 g_return_if_fail (TNY_IS_FOLDER (folder));
672 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
674 /* Get the account */
675 account = tny_folder_get_account (folder);
677 /* Delete folder or move to trash */
678 if (remove_to_trash) {
679 TnyFolder *trash_folder, *new_folder;
680 trash_folder = modest_tny_account_get_special_folder (account,
681 TNY_FOLDER_TYPE_TRASH);
682 /* TODO: error_handling */
683 new_folder = modest_mail_operation_xfer_folder (self, folder,
684 TNY_FOLDER_STORE (trash_folder), TRUE);
685 g_object_unref (G_OBJECT (new_folder));
687 parent = tny_folder_get_folder_store (folder);
689 tny_folder_store_remove_folder (parent, folder, &(priv->error));
690 CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED, );
693 g_object_unref (G_OBJECT (parent));
695 g_object_unref (G_OBJECT (account));
699 modest_mail_operation_rename_folder (ModestMailOperation *self,
703 ModestMailOperationPrivate *priv;
705 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
706 g_return_if_fail (TNY_IS_FOLDER_STORE (folder));
707 g_return_if_fail (name);
709 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
711 /* FIXME: better error handling */
712 if (strrchr (name, '/') != NULL)
715 /* Rename. Camel handles folder subscription/unsubscription */
716 tny_folder_set_name (folder, name, &(priv->error));
717 CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED, return);
721 modest_mail_operation_xfer_folder (ModestMailOperation *self,
723 TnyFolderStore *parent,
724 gboolean delete_original)
726 ModestMailOperationPrivate *priv;
728 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), NULL);
729 g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent), NULL);
730 g_return_val_if_fail (TNY_IS_FOLDER (folder), NULL);
732 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
734 return tny_folder_copy (folder,
736 tny_folder_get_name (folder),
742 /* ******************************************************************* */
743 /* ************************** MSG ACTIONS ************************* */
744 /* ******************************************************************* */
747 modest_mail_operation_remove_msg (ModestMailOperation *self,
749 gboolean remove_to_trash)
753 g_return_if_fail (TNY_IS_HEADER (header));
755 folder = tny_header_get_folder (header);
757 /* Delete or move to trash */
758 if (remove_to_trash) {
759 TnyFolder *trash_folder;
760 TnyStoreAccount *store_account;
762 store_account = TNY_STORE_ACCOUNT (tny_folder_get_account (folder));
763 trash_folder = modest_tny_account_get_special_folder (TNY_ACCOUNT(store_account),
764 TNY_FOLDER_TYPE_TRASH);
766 modest_mail_operation_xfer_msg (self, header, trash_folder, TRUE);
767 /* g_object_unref (trash_folder); */
769 ModestMailOperationPrivate *priv;
771 /* Set status failed and set an error */
772 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
773 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
774 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
775 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
776 _("Error trying to delete a message. Trash folder not found"));
779 g_object_unref (G_OBJECT (store_account));
781 tny_folder_remove_msg (folder, header, NULL); /* FIXME */
782 tny_folder_sync(folder, TRUE, NULL); /* FIXME */
786 g_object_unref (folder);
790 transfer_msgs_cb (TnyFolder *folder, GError **err, gpointer user_data)
792 ModestMailOperationPrivate *priv;
794 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(user_data);
797 priv->error = g_error_copy (*err);
799 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
802 priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
805 g_signal_emit (G_OBJECT (user_data), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
809 modest_mail_operation_xfer_msg (ModestMailOperation *self,
812 gboolean delete_original)
814 ModestMailOperationPrivate *priv;
815 TnyFolder *src_folder;
818 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), FALSE);
819 g_return_val_if_fail (TNY_IS_HEADER (header), FALSE);
820 g_return_val_if_fail (TNY_IS_FOLDER (folder), FALSE);
822 src_folder = tny_header_get_folder (header);
823 headers = tny_simple_list_new ();
825 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
828 priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
830 tny_list_prepend (headers, G_OBJECT (header));
831 tny_folder_transfer_msgs_async (src_folder, headers, folder,
832 delete_original, transfer_msgs_cb,
836 /* FIXME: don't free 'm yet */
837 ///g_object_unref (headers);
838 ///g_object_unref (src_folder);
844 /* ******************************************************************* */
845 /* ************************* UTILIY FUNCTIONS ************************ */
846 /* ******************************************************************* */
849 add_attachments (TnyMsg *msg, GList *attachments_list)
852 TnyMimePart *attachment_part, *old_attachment;
853 const gchar *attachment_content_type;
854 const gchar *attachment_filename;
855 TnyStream *attachment_stream;
857 for (pos = (GList *)attachments_list; pos; pos = pos->next) {
859 old_attachment = pos->data;
860 attachment_filename = tny_mime_part_get_filename (old_attachment);
861 attachment_stream = tny_mime_part_get_stream (old_attachment);
862 attachment_part = tny_platform_factory_new_mime_part
863 (modest_runtime_get_platform_factory());
865 attachment_content_type = tny_mime_part_get_content_type (old_attachment);
867 tny_mime_part_construct_from_stream (attachment_part,
869 attachment_content_type);
870 tny_stream_reset (attachment_stream);
872 tny_mime_part_set_filename (attachment_part, attachment_filename);
874 tny_mime_part_add_part (TNY_MIME_PART (msg), attachment_part);
875 /* g_object_unref (attachment_part); */