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",
223 modest_mail_operation_send_new_mail (ModestMailOperation *self,
224 TnyTransportAccount *transport_account,
225 const gchar *from, const gchar *to,
226 const gchar *cc, const gchar *bcc,
227 const gchar *subject, const gchar *body,
228 const GList *attachments_list)
231 ModestMailOperationPrivate *priv = NULL;
233 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
234 g_return_if_fail (TNY_IS_TRANSPORT_ACCOUNT (transport_account));
236 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
238 /* Check parametters */
240 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
241 MODEST_MAIL_OPERATION_ERROR_MISSING_PARAMETER,
242 _("Error trying to send a mail. You need to set at least one recipient"));
246 new_msg = modest_tny_msg_new (to, from, cc, bcc, subject, body, NULL); /* FIXME: attachments */
248 g_printerr ("modest: failed to create a new msg\n");
252 modest_mail_operation_send_mail (self, transport_account, new_msg);
254 g_object_unref (G_OBJECT(new_msg));
258 add_if_attachment (gpointer data, gpointer user_data)
261 GList *attachments_list;
263 part = TNY_MIME_PART (data);
264 attachments_list = (GList *) user_data;
266 if (tny_mime_part_is_attachment (part))
267 attachments_list = g_list_prepend (attachments_list, part);
272 create_reply_forward_mail (TnyMsg *msg, const gchar *from, gboolean is_reply, guint type)
275 TnyHeader *new_header, *header;
278 ModestFormatter *formatter;
280 /* Get body from original msg. Always look for the text/plain
281 part of the message to create the reply/forwarded mail */
282 header = tny_msg_get_header (msg);
283 body = modest_tny_msg_find_body_part (msg, FALSE);
285 /* TODO: select the formatter from account prefs */
286 formatter = modest_formatter_new ("text/plain");
288 /* Format message body */
291 case MODEST_MAIL_OPERATION_REPLY_TYPE_CITE:
293 new_msg = modest_formatter_cite (formatter, body, header);
295 case MODEST_MAIL_OPERATION_REPLY_TYPE_QUOTE:
296 new_msg = modest_formatter_quote (formatter, body, header);
301 case MODEST_MAIL_OPERATION_FORWARD_TYPE_INLINE:
303 new_msg = modest_formatter_inline (formatter, body, header);
305 case MODEST_MAIL_OPERATION_FORWARD_TYPE_ATTACHMENT:
306 new_msg = modest_formatter_attach (formatter, body, header);
310 g_object_unref (G_OBJECT(formatter));
311 g_object_unref (G_OBJECT(body));
313 /* Fill the header */
314 new_header = TNY_HEADER (tny_platform_factory_new_header
315 (modest_runtime_get_platform_factory()));
316 tny_msg_set_header (new_msg, new_header);
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));
471 tny_folder_refresh_async (folder, folder_refresh_cb,
474 g_object_unref (G_OBJECT(folder));
476 g_signal_emit (G_OBJECT (self), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
481 update_folders_cb (TnyFolderStore *folder_store, TnyList *list, GError **err, gpointer user_data)
483 ModestMailOperation *self;
484 ModestMailOperationPrivate *priv;
485 RefreshFolderAsyncHelper *helper;
488 self = MODEST_MAIL_OPERATION (user_data);
489 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
492 priv->error = g_error_copy (*err);
493 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
497 priv->total = tny_list_get_length (list);
499 priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
501 helper = g_slice_new0 (RefreshFolderAsyncHelper);
502 helper->mail_op = self;
503 helper->iter = tny_list_create_iterator (list);
505 helper->canceled = 0;
507 /* Async refresh folders */
508 folder = TNY_FOLDER (tny_iterator_get_current (helper->iter));
509 tny_folder_refresh_async (folder, folder_refresh_cb,
510 status_update_cb, helper);
511 g_object_unref (G_OBJECT(folder));
515 modest_mail_operation_update_account (ModestMailOperation *self,
516 TnyStoreAccount *store_account)
518 ModestMailOperationPrivate *priv;
520 TnyFolderStoreQuery *query;
522 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), FALSE);
523 g_return_val_if_fail (TNY_IS_STORE_ACCOUNT(store_account), FALSE);
525 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
527 /* Get subscribed folders & refresh them */
528 folders = TNY_LIST (tny_simple_list_new ());
529 query = tny_folder_store_query_new ();
530 tny_folder_store_query_add_item (query, NULL, TNY_FOLDER_STORE_QUERY_OPTION_SUBSCRIBED);
531 tny_folder_store_get_folders_async (TNY_FOLDER_STORE (store_account),
532 folders, update_folders_cb, query, self);
533 g_object_unref (query);
538 ModestMailOperationStatus
539 modest_mail_operation_get_status (ModestMailOperation *self)
541 ModestMailOperationPrivate *priv;
543 g_return_val_if_fail (self, MODEST_MAIL_OPERATION_STATUS_INVALID);
544 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self),
545 MODEST_MAIL_OPERATION_STATUS_INVALID);
547 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
552 modest_mail_operation_get_error (ModestMailOperation *self)
554 ModestMailOperationPrivate *priv;
556 g_return_val_if_fail (self, NULL);
557 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), NULL);
559 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
564 modest_mail_operation_cancel (ModestMailOperation *self)
571 modest_mail_operation_get_task_done (ModestMailOperation *self)
573 ModestMailOperationPrivate *priv;
575 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), 0);
577 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
582 modest_mail_operation_get_task_total (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_is_finished (ModestMailOperation *self)
595 ModestMailOperationPrivate *priv;
596 gboolean retval = FALSE;
598 if (!MODEST_IS_MAIL_OPERATION (self)) {
599 g_warning ("%s: invalid parametter", G_GNUC_FUNCTION);
603 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
605 if (priv->status == MODEST_MAIL_OPERATION_STATUS_SUCCESS ||
606 priv->status == MODEST_MAIL_OPERATION_STATUS_FAILED ||
607 priv->status == MODEST_MAIL_OPERATION_STATUS_CANCELED ||
608 priv->status == MODEST_MAIL_OPERATION_STATUS_FINISHED_WITH_ERRORS) {
617 /* ******************************************************************* */
618 /* ************************** STORE ACTIONS ************************* */
619 /* ******************************************************************* */
623 modest_mail_operation_create_folder (ModestMailOperation *self,
624 TnyFolderStore *parent,
627 ModestMailOperationPrivate *priv;
628 TnyFolder *new_folder = NULL;
629 TnyStoreAccount *store_account;
631 g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent), NULL);
632 g_return_val_if_fail (name, NULL);
634 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
636 /* Create the folder */
637 new_folder = tny_folder_store_create_folder (parent, name, &(priv->error));
638 CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED, return NULL);
640 /* Subscribe to folder */
641 if (!tny_folder_is_subscribed (new_folder)) {
642 store_account = TNY_STORE_ACCOUNT (tny_folder_get_account (TNY_FOLDER (parent)));
643 tny_store_account_subscribe (store_account, new_folder);
644 g_object_unref (G_OBJECT (store_account));
651 modest_mail_operation_remove_folder (ModestMailOperation *self,
653 gboolean remove_to_trash)
655 TnyFolderStore *parent;
657 ModestMailOperationPrivate *priv;
659 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
660 g_return_if_fail (TNY_IS_FOLDER (folder));
662 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
664 /* Get the account */
665 account = tny_folder_get_account (folder);
667 /* Delete folder or move to trash */
668 if (remove_to_trash) {
669 TnyFolder *trash_folder, *new_folder;
670 trash_folder = modest_tny_account_get_special_folder (account,
671 TNY_FOLDER_TYPE_TRASH);
672 /* TODO: error_handling */
673 new_folder = modest_mail_operation_xfer_folder (self, folder,
674 TNY_FOLDER_STORE (trash_folder), TRUE);
675 g_object_unref (G_OBJECT (new_folder));
677 parent = tny_folder_get_folder_store (folder);
679 tny_folder_store_remove_folder (parent, folder, &(priv->error));
680 CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED, );
682 if (parent) g_object_unref (G_OBJECT (parent));
684 g_object_unref (G_OBJECT (account));
688 modest_mail_operation_rename_folder (ModestMailOperation *self,
692 ModestMailOperationPrivate *priv;
694 g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
695 g_return_if_fail (TNY_IS_FOLDER_STORE (folder));
696 g_return_if_fail (name);
698 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
700 /* FIXME: better error handling */
701 if (strrchr (name, '/') != NULL)
704 /* Rename. Camel handles folder subscription/unsubscription */
705 tny_folder_set_name (folder, name, &(priv->error));
706 CHECK_EXCEPTION (priv, MODEST_MAIL_OPERATION_STATUS_FAILED, return);
710 modest_mail_operation_xfer_folder (ModestMailOperation *self,
712 TnyFolderStore *parent,
713 gboolean delete_original)
715 ModestMailOperationPrivate *priv;
717 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), NULL);
718 g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent), NULL);
719 g_return_val_if_fail (TNY_IS_FOLDER (folder), NULL);
721 priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self);
723 return tny_folder_copy (folder,
725 tny_folder_get_name (folder),
731 /* ******************************************************************* */
732 /* ************************** MSG ACTIONS ************************* */
733 /* ******************************************************************* */
736 modest_mail_operation_remove_msg (ModestMailOperation *self,
738 gboolean remove_to_trash)
742 g_return_if_fail (TNY_IS_HEADER (header));
744 folder = tny_header_get_folder (header);
746 /* Delete or move to trash */
747 if (remove_to_trash) {
748 TnyFolder *trash_folder;
749 TnyStoreAccount *store_account;
751 store_account = TNY_STORE_ACCOUNT (tny_folder_get_account (folder));
752 trash_folder = modest_tny_account_get_special_folder (TNY_ACCOUNT(store_account),
753 TNY_FOLDER_TYPE_TRASH);
755 modest_mail_operation_xfer_msg (self, header, trash_folder, TRUE);
756 /* g_object_unref (trash_folder); */
758 ModestMailOperationPrivate *priv;
760 /* Set status failed and set an error */
761 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
762 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
763 g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
764 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
765 _("Error trying to delete a message. Trash folder not found"));
768 g_object_unref (G_OBJECT (store_account));
770 tny_folder_remove_msg (folder, header, NULL); /* FIXME */
771 tny_folder_sync(folder, TRUE, NULL); /* FIXME */
775 g_object_unref (folder);
779 transfer_msgs_cb (TnyFolder *folder, GError **err, gpointer user_data)
781 ModestMailOperationPrivate *priv;
783 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(user_data);
786 priv->error = g_error_copy (*err);
788 priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED;
791 priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
794 g_signal_emit (G_OBJECT (user_data), signals[PROGRESS_CHANGED_SIGNAL], 0, NULL);
798 modest_mail_operation_xfer_msg (ModestMailOperation *self,
801 gboolean delete_original)
803 ModestMailOperationPrivate *priv;
804 TnyFolder *src_folder;
807 g_return_val_if_fail (MODEST_IS_MAIL_OPERATION (self), FALSE);
808 g_return_val_if_fail (TNY_IS_HEADER (header), FALSE);
809 g_return_val_if_fail (TNY_IS_FOLDER (folder), FALSE);
811 src_folder = tny_header_get_folder (header);
812 headers = tny_simple_list_new ();
814 priv = MODEST_MAIL_OPERATION_GET_PRIVATE(self);
817 priv->status = MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS;
819 tny_list_prepend (headers, G_OBJECT (header));
820 tny_folder_transfer_msgs_async (src_folder, headers, folder,
821 delete_original, transfer_msgs_cb, self);
824 g_object_unref (headers);
825 g_object_unref (src_folder);
831 /* ******************************************************************* */
832 /* ************************* UTILIY FUNCTIONS ************************ */
833 /* ******************************************************************* */
836 add_attachments (TnyMsg *msg, GList *attachments_list)
839 TnyMimePart *attachment_part, *old_attachment;
840 const gchar *attachment_content_type;
841 const gchar *attachment_filename;
842 TnyStream *attachment_stream;
844 for (pos = (GList *)attachments_list; pos; pos = pos->next) {
846 old_attachment = pos->data;
847 attachment_filename = tny_mime_part_get_filename (old_attachment);
848 attachment_stream = tny_mime_part_get_stream (old_attachment);
849 attachment_part = tny_platform_factory_new_mime_part
850 (modest_runtime_get_platform_factory());
852 attachment_content_type = tny_mime_part_get_content_type (old_attachment);
854 tny_mime_part_construct_from_stream (attachment_part,
856 attachment_content_type);
857 tny_stream_reset (attachment_stream);
859 tny_mime_part_set_filename (attachment_part, attachment_filename);
861 tny_mime_part_add_part (TNY_MIME_PART (msg), attachment_part);
862 /* g_object_unref (attachment_part); */