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 <camel/camel-stream-mem.h>
41 #include <glib/gi18n.h>
42 #include <modest-tny-account.h>
43 #include <modest-tny-send-queue.h>
44 #include <modest-runtime.h>
45 #include "modest-text-utils.h"
46 #include "modest-tny-msg.h"
47 #include "modest-tny-platform-factory.h"
48 #include "modest-marshal.h"
49 #include "modest-formatter.h"
50 #include "modest-error.h"
52 /* 'private'/'protected' functions */
53 static void modest_mail_operation_class_init (ModestMailOperationClass *klass);
54 static void modest_mail_operation_init (ModestMailOperation *obj);
55 static void modest_mail_operation_finalize (GObject *obj);
57 static void status_update_cb (TnyFolder *folder,
62 static void folder_refresh_cb (TnyFolder *folder,
66 static void update_folders_cb (TnyFolderStore *self,
70 static void add_attachments (TnyMsg *msg,
71 GList *attachments_list);
73 enum _ModestMailOperationSignals
75 PROGRESS_CHANGED_SIGNAL,
80 typedef struct _ModestMailOperationPrivate ModestMailOperationPrivate;
81 struct _ModestMailOperationPrivate {
84 ModestMailOperationStatus status;
88 #define MODEST_MAIL_OPERATION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
89 MODEST_TYPE_MAIL_OPERATION, \
90 ModestMailOperationPrivate))
92 #define CHECK_EXCEPTION(priv, new_status, op) if (priv->error) {\
93 priv->status = new_status;\
97 typedef struct _RefreshFolderAsyncHelper
99 ModestMailOperation *mail_op;
104 } RefreshFolderAsyncHelper;
107 static GObjectClass *parent_class = NULL;
109 static guint signals[NUM_SIGNALS] = {0};
112 modest_mail_operation_get_type (void)
114 static GType my_type = 0;
116 static const GTypeInfo my_info = {
117 sizeof(ModestMailOperationClass),
118 NULL, /* base init */
119 NULL, /* base finalize */
120 (GClassInitFunc) modest_mail_operation_class_init,
121 NULL, /* class finalize */
122 NULL, /* class data */
123 sizeof(ModestMailOperation),
125 (GInstanceInitFunc) modest_mail_operation_init,
128 my_type = g_type_register_static (G_TYPE_OBJECT,
129 "ModestMailOperation",
136 modest_mail_operation_class_init (ModestMailOperationClass *klass)
138 GObjectClass *gobject_class;
139 gobject_class = (GObjectClass*) klass;
141 parent_class = g_type_class_peek_parent (klass);
142 gobject_class->finalize = modest_mail_operation_finalize;
144 g_type_class_add_private (gobject_class, sizeof(ModestMailOperationPrivate));
147 * ModestMailOperation::progress-changed
148 * @self: the #MailOperation that emits the signal
149 * @user_data: user data set when the signal handler was connected
151 * Emitted when the progress of a mail operation changes
153 signals[PROGRESS_CHANGED_SIGNAL] =
154 g_signal_new ("progress_changed",
155 G_TYPE_FROM_CLASS (gobject_class),
157 G_STRUCT_OFFSET (ModestMailOperationClass, progress_changed),
159 g_cclosure_marshal_VOID__VOID,
164 modest_mail_operation_init (ModestMailOperation *obj)
166 ModestMailOperationPrivate *priv;
168 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(obj);
170 priv->status = MODEST_MAIL_OPERATION_STATUS_INVALID;
177 modest_mail_operation_finalize (GObject *obj)
179 ModestMailOperationPrivate *priv;
181 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(obj);
184 g_error_free (priv->error);
188 G_OBJECT_CLASS(parent_class)->finalize (obj);
192 modest_mail_operation_new (void)
194 return MODEST_MAIL_OPERATION(g_object_new(MODEST_TYPE_MAIL_OPERATION, NULL));
199 modest_mail_operation_send_mail (ModestMailOperation *self,
200 TnyTransportAccount *transport_account,
203 TnySendQueue *send_queue;
205 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
206 g_return_if_fail (TNY_IS_TRANSPORT_ACCOUNT (transport_account));
208 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
209 if (!TNY_IS_SEND_QUEUE(send_queue))
210 g_printerr ("modest: could not find send queue for account\n");
213 tny_send_queue_add (send_queue, msg, &err);
215 g_printerr ("modest: error adding msg to send queue: %s\n",
219 g_message ("modest: message added to send queue");
224 modest_mail_operation_send_new_mail (ModestMailOperation *self,
225 TnyTransportAccount *transport_account,
226 const gchar *from, const gchar *to,
227 const gchar *cc, const gchar *bcc,
228 const gchar *subject, const gchar *body,
229 const GList *attachments_list)
232 ModestMailOperationPrivate *priv = NULL;
234 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
235 g_return_if_fail (TNY_IS_TRANSPORT_ACCOUNT (transport_account));
237 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
239 /* Check parametters */
241 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
242 MODEST_MAIL_OPERATION_ERROR_MISSING_PARAMETER,
243 _("Error trying to send a mail. You need to set at least one recipient"));
247 new_msg = modest_tny_msg_new (to, from, cc, bcc, subject, body, NULL); /* FIXME: attachments */
249 g_printerr ("modest: failed to create a new msg\n");
253 modest_mail_operation_send_mail (self, transport_account, new_msg);
255 g_object_unref (G_OBJECT(new_msg));
259 add_if_attachment (gpointer data, gpointer user_data)
262 GList *attachments_list;
264 part = TNY_MIME_PART (data);
265 attachments_list = (GList *) user_data;
267 if (tny_mime_part_is_attachment (part))
268 attachments_list = g_list_prepend (attachments_list, part);
273 create_reply_forward_mail (TnyMsg *msg, const gchar *from, gboolean is_reply, guint type)
276 TnyHeader *new_header, *header;
279 ModestFormatter *formatter;
281 /* Get body from original msg. Always look for the text/plain
282 part of the message to create the reply/forwarded mail */
283 header = tny_msg_get_header (msg);
284 body = modest_tny_msg_find_body_part (msg, FALSE);
286 /* TODO: select the formatter from account prefs */
287 formatter = modest_formatter_new ("text/plain");
289 /* Format message body */
292 case MODEST_MAIL_OPERATION_REPLY_TYPE_CITE:
294 new_msg = modest_formatter_cite (formatter, body, header);
296 case MODEST_MAIL_OPERATION_REPLY_TYPE_QUOTE:
297 new_msg = modest_formatter_quote (formatter, body, header);
302 case MODEST_MAIL_OPERATION_FORWARD_TYPE_INLINE:
304 new_msg = modest_formatter_inline (formatter, body, header);
306 case MODEST_MAIL_OPERATION_FORWARD_TYPE_ATTACHMENT:
307 new_msg = modest_formatter_attach (formatter, body, header);
311 g_object_unref (G_OBJECT(formatter));
312 g_object_unref (G_OBJECT(body));
314 /* Fill the header */
315 new_header = TNY_HEADER (tny_platform_factory_new_header
316 (modest_runtime_get_platform_factory()));
317 tny_msg_set_header (new_msg, new_header);
318 tny_header_set_from (new_header, from);
319 tny_header_set_replyto (new_header, from);
321 /* Change the subject */
323 (gchar *) modest_text_utils_derived_subject (tny_header_get_subject(header),
324 (is_reply) ? _("Re:") : _("Fwd:"));
325 tny_header_set_subject (new_header, (const gchar *) new_subject);
326 g_free (new_subject);
329 g_object_unref (G_OBJECT (new_header));
330 g_object_unref (G_OBJECT (header));
336 modest_mail_operation_create_forward_mail (TnyMsg *msg,
338 ModestMailOperationForwardType forward_type)
341 TnyList *parts = NULL;
342 GList *attachments_list = NULL;
344 new_msg = create_reply_forward_mail (msg, from, FALSE, forward_type);
346 /* Add attachments */
347 parts = TNY_LIST (tny_simple_list_new());
348 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
349 tny_list_foreach (parts, add_if_attachment, attachments_list);
350 add_attachments (new_msg, attachments_list);
353 if (attachments_list)
354 g_list_free (attachments_list);
355 g_object_unref (G_OBJECT (parts));
361 modest_mail_operation_create_reply_mail (TnyMsg *msg,
363 ModestMailOperationReplyType reply_type,
364 ModestMailOperationReplyMode reply_mode)
366 TnyMsg *new_msg = NULL;
367 TnyHeader *new_header, *header;
368 const gchar* reply_to;
369 gchar *new_cc = NULL;
370 const gchar *cc = NULL, *bcc = NULL;
373 new_msg = create_reply_forward_mail (msg, from, TRUE, reply_type);
375 /* Fill the header */
376 header = tny_msg_get_header (msg);
377 new_header = tny_msg_get_header (new_msg);
378 reply_to = tny_header_get_replyto (header);
381 tny_header_set_to (new_header, reply_to);
383 tny_header_set_to (new_header, tny_header_get_from (header));
385 switch (reply_mode) {
386 case MODEST_MAIL_OPERATION_REPLY_MODE_SENDER:
387 /* Do not fill neither cc nor bcc */
389 case MODEST_MAIL_OPERATION_REPLY_MODE_LIST:
392 case MODEST_MAIL_OPERATION_REPLY_MODE_ALL:
393 /* Concatenate to, cc and bcc */
394 cc = tny_header_get_cc (header);
395 bcc = tny_header_get_bcc (header);
397 tmp = g_string_new (tny_header_get_to (header));
398 if (cc) g_string_append_printf (tmp, ",%s",cc);
399 if (bcc) g_string_append_printf (tmp, ",%s",bcc);
401 /* Remove my own address from the cc list. TODO:
402 remove also the To: of the new message, needed due
403 to the new reply_to feature */
405 modest_text_utils_remove_address ((const gchar *) tmp->str,
407 /* FIXME: remove also the mails from the new To: */
408 tny_header_set_cc (new_header, new_cc);
411 g_string_free (tmp, TRUE);
417 g_object_unref (G_OBJECT (new_header));
418 g_object_unref (G_OBJECT (header));
424 status_update_cb (TnyFolder *folder, const gchar *what, gint status, gint oftotal, gpointer user_data)
426 g_print ("%s status: %d, of total %d\n", what, status, oftotal);
430 folder_refresh_cb (TnyFolder *folder, gboolean canceled, GError **err, gpointer user_data)
432 ModestMailOperation *self = NULL;
433 ModestMailOperationPrivate *priv = NULL;
434 RefreshFolderAsyncHelper *helper;
436 helper = (RefreshFolderAsyncHelper *) user_data;
437 self = MODEST_MAIL_OPERATION (helper->mail_op);
438 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
440 if ((canceled && *err) || *err) {
441 priv->error = g_error_copy (*err);
443 } else if (canceled) {
445 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
446 MODEST_MAIL_OPERATION_ERROR_OPERATION_CANCELED,
447 _("Error trying to refresh folder %s. Operation canceled"),
448 tny_folder_get_name (folder));
453 if (priv->done == priv->total)
454 priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
455 else if ((priv->done + helper->canceled + helper->failed) == priv->total) {
456 if (helper->failed == priv->total)
457 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
458 else if (helper->failed == priv->total)
459 priv->status = MODEST_MAIL_OPERATION_STATUS_CANCELED;
461 priv->status = MODEST_MAIL_OPERATION_STATUS_FINISHED_WITH_ERRORS;
463 tny_iterator_next (helper->iter);
464 if (tny_iterator_is_done (helper->iter)) {
466 list = tny_iterator_get_list (helper->iter);
467 g_object_unref (G_OBJECT (helper->iter));
468 g_object_unref (G_OBJECT (list));
469 g_slice_free (RefreshFolderAsyncHelper, helper);
471 TnyFolder *folder = TNY_FOLDER (tny_iterator_get_current (helper->iter));
473 g_message ("modest: refreshing folder %s",
474 tny_folder_get_name (folder));
475 tny_folder_refresh_async (folder, folder_refresh_cb, status_update_cb, helper);
476 g_object_unref (G_OBJECT(folder)); // FIXME: don't unref yet
479 g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
484 update_folders_cb (TnyFolderStore *folder_store, TnyList *list, GError **err, gpointer user_data)
486 ModestMailOperation *self;
487 ModestMailOperationPrivate *priv;
488 RefreshFolderAsyncHelper *helper;
491 self = MODEST_MAIL_OPERATION (user_data);
492 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
495 priv->error = g_error_copy (*err);
496 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
500 priv->total = tny_list_get_length (list);
502 priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
504 helper = g_slice_new0 (RefreshFolderAsyncHelper);
505 helper->mail_op = self;
506 helper->iter = tny_list_create_iterator (list);
508 helper->canceled = 0;
510 /* Async refresh folders */
511 folder = TNY_FOLDER (tny_iterator_get_current (helper->iter));
513 g_message ("modest: refreshing folder %s", tny_folder_get_name (folder));
514 tny_folder_refresh_async (folder, folder_refresh_cb,
515 status_update_cb, helper);
517 //g_object_unref (G_OBJECT(folder)); /* FIXME -==> don't unref yet... */
521 modest_mail_operation_update_account (ModestMailOperation *self,
522 TnyStoreAccount *store_account)
524 ModestMailOperationPrivate *priv;
526 TnyFolderStoreQuery *query;
528 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), FALSE);
529 g_return_val_if_fail (TNY_IS_STORE_ACCOUNT(store_account), FALSE);
531 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
533 /* Get subscribed folders & refresh them */
534 folders = TNY_LIST (tny_simple_list_new ());
535 query = NULL; //tny_folder_store_query_new ();
537 /* FIXME: is this needed? */
538 tny_device_force_online (TNY_DEVICE(modest_runtime_get_device()));
540 /* FIXME: let query be NULL: do it for all */
541 //tny_folder_store_query_add_item (query, NULL, TNY_FOLDER_STORE_QUERY_OPTION_SUBSCRIBED);
542 tny_folder_store_get_folders_async (TNY_FOLDER_STORE (store_account),
543 folders, update_folders_cb, query, self);
544 //g_object_unref (query); /* FIXME */
549 ModestMailOperationStatus
550 modest_mail_operation_get_status (ModestMailOperation *self)
552 ModestMailOperationPrivate *priv;
554 g_return_val_if_fail (self, MODEST_MAIL_OPERATION_STATUS_INVALID);
555 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self),
556 MODEST_MAIL_OPERATION_STATUS_INVALID);
558 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
563 modest_mail_operation_get_error (ModestMailOperation *self)
565 ModestMailOperationPrivate *priv;
567 g_return_val_if_fail (self, NULL);
568 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), NULL);
570 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
575 modest_mail_operation_cancel (ModestMailOperation *self)
582 modest_mail_operation_get_task_done (ModestMailOperation *self)
584 ModestMailOperationPrivate *priv;
586 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), 0);
588 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
593 modest_mail_operation_get_task_total (ModestMailOperation *self)
595 ModestMailOperationPrivate *priv;
597 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), 0);
599 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
604 modest_mail_operation_is_finished (ModestMailOperation *self)
606 ModestMailOperationPrivate *priv;
607 gboolean retval = FALSE;
609 if (!MODEST_IS_MAIL_OPERATION (self)) {
610 g_warning ("%s: invalid parametter", G_GNUC_FUNCTION);
614 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
616 if (priv->status == MODEST_MAIL_OPERATION_STATUS_SUCCESS ||
617 priv->status == MODEST_MAIL_OPERATION_STATUS_FAILED ||
618 priv->status == MODEST_MAIL_OPERATION_STATUS_CANCELED ||
619 priv->status == MODEST_MAIL_OPERATION_STATUS_FINISHED_WITH_ERRORS) {
628 /* ******************************************************************* */
629 /* ************************** STORE ACTIONS ************************* */
630 /* ******************************************************************* */
634 modest_mail_operation_create_folder (ModestMailOperation *self,
635 TnyFolderStore *parent,
638 ModestMailOperationPrivate *priv;
639 TnyFolder *new_folder = NULL;
640 TnyStoreAccount *store_account;
642 g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent), NULL);
643 g_return_val_if_fail (name, NULL);
645 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
647 /* Create the folder */
648 new_folder = tny_folder_store_create_folder (parent, name, &(priv->error));
649 CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED, return NULL);
651 /* Subscribe to folder */
652 if (!tny_folder_is_subscribed (new_folder)) {
653 store_account = TNY_STORE_ACCOUNT (tny_folder_get_account (TNY_FOLDER (parent)));
654 tny_store_account_subscribe (store_account, new_folder);
655 g_object_unref (G_OBJECT (store_account));
662 modest_mail_operation_remove_folder (ModestMailOperation *self,
664 gboolean remove_to_trash)
666 TnyFolderStore *parent;
668 ModestMailOperationPrivate *priv;
670 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
671 g_return_if_fail (TNY_IS_FOLDER (folder));
673 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
675 /* Get the account */
676 account = tny_folder_get_account (folder);
678 /* Delete folder or move to trash */
679 if (remove_to_trash) {
680 TnyFolder *trash_folder, *new_folder;
681 trash_folder = modest_tny_account_get_special_folder (account,
682 TNY_FOLDER_TYPE_TRASH);
683 /* TODO: error_handling */
684 new_folder = modest_mail_operation_xfer_folder (self, folder,
685 TNY_FOLDER_STORE (trash_folder), TRUE);
686 g_object_unref (G_OBJECT (new_folder));
688 parent = tny_folder_get_folder_store (folder);
690 tny_folder_store_remove_folder (parent, folder, &(priv->error));
691 CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED, );
694 g_object_unref (G_OBJECT (parent));
696 g_object_unref (G_OBJECT (account));
700 modest_mail_operation_rename_folder (ModestMailOperation *self,
704 ModestMailOperationPrivate *priv;
706 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
707 g_return_if_fail (TNY_IS_FOLDER_STORE (folder));
708 g_return_if_fail (name);
710 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
712 /* FIXME: better error handling */
713 if (strrchr (name, '/') != NULL)
716 /* Rename. Camel handles folder subscription/unsubscription */
717 tny_folder_set_name (folder, name, &(priv->error));
718 CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED, return);
722 modest_mail_operation_xfer_folder (ModestMailOperation *self,
724 TnyFolderStore *parent,
725 gboolean delete_original)
727 ModestMailOperationPrivate *priv;
729 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), NULL);
730 g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent), NULL);
731 g_return_val_if_fail (TNY_IS_FOLDER (folder), NULL);
733 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
735 return tny_folder_copy (folder,
737 tny_folder_get_name (folder),
743 /* ******************************************************************* */
744 /* ************************** MSG ACTIONS ************************* */
745 /* ******************************************************************* */
748 modest_mail_operation_remove_msg (ModestMailOperation *self,
750 gboolean remove_to_trash)
754 g_return_if_fail (TNY_IS_HEADER (header));
756 folder = tny_header_get_folder (header);
758 /* Delete or move to trash */
759 if (remove_to_trash) {
760 TnyFolder *trash_folder;
761 TnyStoreAccount *store_account;
763 store_account = TNY_STORE_ACCOUNT (tny_folder_get_account (folder));
764 trash_folder = modest_tny_account_get_special_folder (TNY_ACCOUNT(store_account),
765 TNY_FOLDER_TYPE_TRASH);
767 modest_mail_operation_xfer_msg (self, header, trash_folder, TRUE);
768 /* g_object_unref (trash_folder); */
770 ModestMailOperationPrivate *priv;
772 /* Set status failed and set an error */
773 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
774 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
775 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
776 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
777 _("Error trying to delete a message. Trash folder not found"));
780 g_object_unref (G_OBJECT (store_account));
782 tny_folder_remove_msg (folder, header, NULL); /* FIXME */
783 tny_folder_sync(folder, TRUE, NULL); /* FIXME */
787 g_object_unref (folder);
791 transfer_msgs_cb (TnyFolder *folder, GError **err, gpointer user_data)
793 ModestMailOperationPrivate *priv;
795 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(user_data);
798 priv->error = g_error_copy (*err);
800 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
803 priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
806 g_signal_emit (G_OBJECT (user_data), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
810 modest_mail_operation_xfer_msg (ModestMailOperation *self,
813 gboolean delete_original)
815 ModestMailOperationPrivate *priv;
816 TnyFolder *src_folder;
819 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), FALSE);
820 g_return_val_if_fail (TNY_IS_HEADER (header), FALSE);
821 g_return_val_if_fail (TNY_IS_FOLDER (folder), FALSE);
823 src_folder = tny_header_get_folder (header);
824 headers = tny_simple_list_new ();
826 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
829 priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
831 tny_list_prepend (headers, G_OBJECT (header));
832 tny_folder_transfer_msgs_async (src_folder, headers, folder,
833 delete_original, transfer_msgs_cb,
837 /* FIXME: don't free 'm yet */
838 ///g_object_unref (headers);
839 ///g_object_unref (src_folder);
845 /* ******************************************************************* */
846 /* ************************* UTILIY FUNCTIONS ************************ */
847 /* ******************************************************************* */
850 add_attachments (TnyMsg *msg, GList *attachments_list)
853 TnyMimePart *attachment_part, *old_attachment;
854 const gchar *attachment_content_type;
855 const gchar *attachment_filename;
856 TnyStream *attachment_stream;
858 for (pos = (GList *)attachments_list; pos; pos = pos->next) {
860 old_attachment = pos->data;
861 attachment_filename = tny_mime_part_get_filename (old_attachment);
862 attachment_stream = tny_mime_part_get_stream (old_attachment);
863 attachment_part = tny_platform_factory_new_mime_part
864 (modest_runtime_get_platform_factory());
866 attachment_content_type = tny_mime_part_get_content_type (old_attachment);
868 tny_mime_part_construct_from_stream (attachment_part,
870 attachment_content_type);
871 tny_stream_reset (attachment_stream);
873 tny_mime_part_set_filename (attachment_part, attachment_filename);
875 tny_mime_part_add_part (TNY_MIME_PART (msg), attachment_part);
876 /* g_object_unref (attachment_part); */