c03d4ec636166aa7b312bcfd79bbadaa52de7f00
[modest] / src / modest-mail-operation.h
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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.
16  *
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.
28  */
29
30 #ifndef __MODEST_MAIL_OPERATION_H__
31 #define __MODEST_MAIL_OPERATION_H__
32
33 #include <tny-transport-account.h>
34 #include <tny-folder-store.h>
35
36 G_BEGIN_DECLS
37
38 /* convenience macros */
39 #define MODEST_TYPE_MAIL_OPERATION             (modest_mail_operation_get_type())
40 #define MODEST_MAIL_OPERATION(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_MAIL_OPERATION,ModestMailOperation))
41 #define MODEST_MAIL_OPERATION_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_MAIL_OPERATION,GObject))
42 #define MODEST_IS_MAIL_OPERATION(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_MAIL_OPERATION))
43 #define MODEST_IS_MAIL_OPERATION_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_MAIL_OPERATION))
44 #define MODEST_MAIL_OPERATION_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_MAIL_OPERATION,ModestMailOperationClass))
45
46 typedef struct _ModestMailOperation      ModestMailOperation;
47 typedef struct _ModestMailOperationClass ModestMailOperationClass;
48
49 /**
50  * ModestMailOperationForwardType:
51  *
52  * How the original message will be forwarded to the recipient
53  */
54 typedef enum _ModestMailOperationForwardType {
55         MODEST_MAIL_OPERATION_FORWARD_TYPE_INLINE = 1,
56         MODEST_MAIL_OPERATION_FORWARD_TYPE_ATTACHMENT
57 } ModestMailOperationForwardType;
58
59 /**
60  * ModestMailOperationReplyType:
61  *
62  * How the original message will be forwarded to the recipient
63  */
64 typedef enum _ModestMailOperationReplyType {
65         MODEST_MAIL_OPERATION_REPLY_TYPE_CITE = 1,
66         MODEST_MAIL_OPERATION_REPLY_TYPE_QUOTE
67 } ModestMailOperationReplyType;
68
69 /**
70  * ModestMailOperationReplyMode:
71  *
72  * Who will be the recipients of the replied message
73  */
74 typedef enum _ModestMailOperationReplyMode {
75         MODEST_MAIL_OPERATION_REPLY_MODE_SENDER,
76         MODEST_MAIL_OPERATION_REPLY_MODE_LIST,
77         MODEST_MAIL_OPERATION_REPLY_MODE_ALL
78 } ModestMailOperationReplyMode;
79
80 /**
81  * ModestMailOperationStatus:
82  *
83  * The state of a mail operation
84  */
85 typedef enum _ModestMailOperationStatus {
86         MODEST_MAIL_OPERATION_STATUS_INVALID,
87         MODEST_MAIL_OPERATION_STATUS_SUCCESS,
88         MODEST_MAIL_OPERATION_STATUS_FINISHED_WITH_ERRORS,
89         MODEST_MAIL_OPERATION_STATUS_FAILED,
90         MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS,
91         MODEST_MAIL_OPERATION_STATUS_CANCELED
92 } ModestMailOperationStatus;
93
94 struct _ModestMailOperation {
95          GObject parent;
96         /* insert public members, if any */
97 };
98
99 struct _ModestMailOperationClass {
100         GObjectClass parent_class;
101
102         /* Signals */
103         void (*progress_changed) (ModestMailOperation *self, gpointer user_data);
104 };
105
106 /* member functions */
107 GType        modest_mail_operation_get_type    (void) G_GNUC_CONST;
108
109 /* typical parameter-less _new function */
110 ModestMailOperation*    modest_mail_operation_new         (void);
111
112 /* fill in other public functions, eg.: */
113
114 /**
115  * modest_mail_operation_send_mail:
116  * @self: a #ModestMailOperation
117  * @transport_account: a non-NULL #TnyTransportAccount
118  * @msg: a non-NULL #TnyMsg
119  * 
120  * Sends and already existing message using the provided
121  * #TnyTransportAccount. This operation is synchronous, so the
122  * #ModestMailOperation should not be added to any
123  * #ModestMailOperationQueue
124   **/
125 void    modest_mail_operation_send_mail       (ModestMailOperation *self,
126                                                TnyTransportAccount *transport_account,
127                                                TnyMsg* msg);
128
129 /**
130  * modest_mail_operation_send_new_mail:
131  * @self: a #ModestMailOperation
132  * @transport_account: a non-NULL #TnyTransportAccount
133  * @from: the email address of the mail sender
134  * @to: a non-NULL email address of the mail receiver
135  * @cc: a comma-separated list of email addresses where to send a carbon copy
136  * @bcc: a comma-separated list of email addresses where to send a blind carbon copy
137  * @subject: the subject of the new mail
138  * @body: the body of the new mail
139  * @attachments_list: a #GList of attachments, each attachment must be a #TnyMimePart
140  * 
141  * Sends a new mail message using the provided
142  * #TnyTransportAccount. This operation is synchronous, so the
143  * #ModestMailOperation should not be added to any
144  * #ModestMailOperationQueue
145   **/
146 void    modest_mail_operation_send_new_mail   (ModestMailOperation *self,
147                                                TnyTransportAccount *transport_account,
148                                                const gchar *from,
149                                                const gchar *to,
150                                                const gchar *cc,
151                                                const gchar *bcc,
152                                                const gchar *subject,
153                                                const gchar *body,
154                                                const GList *attachments_list);
155
156 /**
157  * modest_mail_operation_create_forward_mail:
158  * @msg: a valid #TnyMsg instance
159  * @forward_type: the type of formatting used to create the forwarded message
160  * 
161  * Creates a forwarded message from an existing one
162  * 
163  * Returns: a new #TnyMsg, or NULL in case of error
164  **/
165 TnyMsg* modest_mail_operation_create_forward_mail (TnyMsg *msg, 
166                                                    const gchar *from,
167                                                    ModestMailOperationForwardType forward_type);
168
169 /**
170  * modest_mail_operation_create_reply_mail:
171  * @msg: a valid #TnyMsg instance
172  * @reply_type: the type of formatting used to create the reply message
173  * @reply_mode: the mode of reply: to the sender only, to a mail list or to all
174  * 
175  * Creates a new message to reply to an existing one
176  * 
177  * Returns: Returns: a new #TnyMsg, or NULL in case of error
178  **/
179 TnyMsg* modest_mail_operation_create_reply_mail    (TnyMsg *msg, 
180                                                     const gchar *from,
181                                                     ModestMailOperationReplyType reply_type,
182                                                     ModestMailOperationReplyMode reply_mode);
183
184 /**
185  * modest_mail_operation_update_account:
186  * @self: a #ModestMailOperation
187  * @store_account: a #TnyStoreAccount
188  * 
189  * Asynchronously refreshes the root folders of the given store
190  * account. The caller should add the #ModestMailOperation to a
191  * #ModestMailOperationQueue and then free it. The caller will be
192  * notified by the "progress_changed" signal each time the progress of
193  * the operation changes.
194  * Example
195  * <informalexample><programlisting>
196  * queue = modest_tny_platform_factory_get_modest_mail_operation_queue_instance (fact)
197  * mail_op = modest_mail_operation_new ();
198  * g_signal_connect (G_OBJECT (mail_op), "progress_changed", G_CALLBACK(on_progress_changed), queue);
199  * if (modest_mail_operation_update_account (mail_op, account))
200  * {
201  *     modest_mail_operation_queue_add (queue, mail_op);
202  * }
203  * g_object_unref (G_OBJECT (mail_op));
204  * </programlisting></informalexample>
205  * 
206  * Returns: TRUE if the mail operation could be started, or FALSE otherwise
207  **/
208 gboolean      modest_mail_operation_update_account (ModestMailOperation *self,
209                                                     TnyStoreAccount *store_account);
210
211 /* Functions that perform store operations */
212
213 /**
214  * modest_mail_operation_create_folder:
215  * @self: a #ModestMailOperation
216  * @parent: the #TnyFolderStore which is the parent of the new folder
217  * @name: the non-NULL new name for the new folder
218  * 
219  * Creates a new folder as a children of a existing one. If the store
220  * account supports subscriptions this method also sets the new folder
221  * as subscribed. This operation is synchronous, so the
222  * #ModestMailOperation should not be added to any
223  * #ModestMailOperationQueue
224  * 
225  * Returns: a newly created #TnyFolder or NULL in case of error.
226  **/
227 TnyFolder*    modest_mail_operation_create_folder  (ModestMailOperation *self,
228                                                     TnyFolderStore *parent,
229                                                     const gchar *name);
230
231 /**
232  * modest_mail_operation_remove_folder:
233  * @self: a #ModestMailOperation
234  * @folder: a #TnyFolder
235  * @remove_to_trash: TRUE to move it to trash or FALSE to delete
236  * permanently
237  * 
238  * Removes a folder. This operation is synchronous, so the
239  * #ModestMailOperation should not be added to any
240  * #ModestMailOperationQueue
241  **/
242 void          modest_mail_operation_remove_folder  (ModestMailOperation *self,
243                                                     TnyFolder *folder,
244                                                     gboolean remove_to_trash);
245
246 /**
247  * modest_mail_operation_rename_folder:
248  * @self: a #ModestMailOperation
249  * @folder: a #TnyFolder
250  * @name: a non-NULL name without "/"
251  * 
252  * Renames a given folder with the provided new name. This operation
253  * is synchronous, so the #ModestMailOperation should not be added to
254  * any #ModestMailOperationQueue
255  **/
256 void          modest_mail_operation_rename_folder  (ModestMailOperation *self,
257                                                     TnyFolder *folder, 
258                                                     const gchar *name);
259
260 /**
261  * modest_mail_operation_xfer_folder:
262  * @self: a #ModestMailOperation
263  * @folder: a #TnyFolder
264  * @parent: the new parent of the folder as #TnyFolderStore
265  * @delete_original: wheter or not delete the original folder
266  * 
267  * Sets the given @folder as child of a provided #TnyFolderStore. This
268  * operation also transfers all the messages contained in the folder
269  * and all of his children folders with their messages as well. This
270  * operation is synchronous, so the #ModestMailOperation should not be
271  * added to any #ModestMailOperationQueue.
272  *
273  * If @delete_original is TRUE this function moves the original
274  * folder, if it is FALSE the it just copies it
275  *
276  * Returns: the newly transfered folder
277  **/
278 TnyFolder*    modest_mail_operation_xfer_folder    (ModestMailOperation *self,
279                                                     TnyFolder *folder, 
280                                                     TnyFolderStore *parent,
281                                                     gboolean delete_original);
282
283
284 /* Functions that performs msg operations */
285
286 /**
287  * modest_mail_operation_xfer_msg:
288  * @self: a #ModestMailOperation
289  * @header: the #TnyHeader of the message to move
290  * @folder: the #TnyFolder where the message will be moved
291  * @delete_original: whether or not delete the source message
292  * 
293  * Asynchronously transfers a message from its current folder to
294  * another one. The caller should add the #ModestMailOperation to a
295  * #ModestMailOperationQueue and then free it. The caller will be
296  * notified by the "progress_changed" when the operation is completed.
297  *
298  * If the @delete_original paramter is TRUE then this function moves
299  * the message between folders, otherwise it copies it.
300  * 
301  * Example
302  * <informalexample><programlisting>
303  * queue = modest_tny_platform_factory_get_modest_mail_operation_queue_instance (fact);
304  * mail_op = modest_mail_operation_new ();
305  * if (modest_mail_operation_xfer_msg (mail_op, header, folder, TRUE))
306  * {
307  *     g_signal_connect (G_OBJECT (mail_op), "progress_changed", G_CALLBACK(on_progress_changed), queue);
308  *     modest_mail_operation_queue_add (queue, mail_op);
309  * }
310  * g_object_unref (G_OBJECT (mail_op));
311  * </programlisting></informalexample>
312  *
313  * Returns: TRUE if the mail operation could be started, or FALSE otherwise
314  **/
315 gboolean      modest_mail_operation_xfer_msg       (ModestMailOperation *self,
316                                                     TnyHeader *header, 
317                                                     TnyFolder *folder,
318                                                     gboolean delete_original);
319
320 /**
321  * modest_mail_operation_remove_msg:
322  * @self: a #ModestMailOperation
323  * @header: the #TnyHeader of the message to move
324  * @remove_to_trash: TRUE to move it to trash or FALSE to delete it
325  * permanently
326  * 
327  * Deletes a message. This operation is synchronous, so the
328  * #ModestMailOperation should not be added to any
329  * #ModestMailOperationQueue
330  **/
331 void          modest_mail_operation_remove_msg     (ModestMailOperation *self,
332                                                     TnyHeader *header,
333                                                     gboolean remove_to_trash);
334
335 /* Functions to control mail operations */
336 /**
337  * modest_mail_operation_get_task_done:
338  * @self: a #ModestMailOperation
339  * 
340  * Gets the amount of work done for a given mail operation. This
341  * amount of work is an absolute value.
342  * 
343  * Returns: the amount of work completed
344  **/
345 guint     modest_mail_operation_get_task_done      (ModestMailOperation *self);
346
347 /**
348  * modest_mail_operation_get_task_total:
349  * @self: a #ModestMailOperation
350  * 
351  * Gets the total amount of work that must be done to complete a given
352  * mail operation. This amount of work is an absolute value.
353  * 
354  * Returns: the total required amount of work
355  **/
356 guint     modest_mail_operation_get_task_total     (ModestMailOperation *self);
357
358
359 /**
360  * modest_mail_operation_is_finished:
361  * @self: a #ModestMailOperation
362  * 
363  * Checks if the operation is finished. A #ModestMailOperation is
364  * finished if it's in any of the following states:
365  * MODEST_MAIL_OPERATION_STATUS_SUCCESS,
366  * MODEST_MAIL_OPERATION_STATUS_FAILED,
367  * MODEST_MAIL_OPERATION_STATUS_CANCELED or
368  * MODEST_MAIL_OPERATION_STATUS_FINISHED_WITH_ERRORS
369  * 
370  * Returns: TRUE if the operation is finished, FALSE otherwise
371  **/
372 gboolean                  modest_mail_operation_is_finished (ModestMailOperation *self);
373
374 /**
375  * modest_mail_operation_is_finished:
376  * @self: a #ModestMailOperation
377  * 
378  * Gets the current status of the given mail operation
379  *
380  * Returns: the current status or MODEST_MAIL_OPERATION_STATUS_INVALID in case of error
381  **/
382 ModestMailOperationStatus modest_mail_operation_get_status  (ModestMailOperation *self);
383
384 /**
385  * modest_mail_operation_get_error:
386  * @self: a #ModestMailOperation
387  * 
388  * Gets the error associated to the mail operation if exists
389  * 
390  * Returns: the #GError associated to the #ModestMailOperation if it
391  * exists or NULL otherwise
392  **/
393 const GError*             modest_mail_operation_get_error   (ModestMailOperation *self);
394
395 /**
396  * modest_mail_operation_cancel:
397  * @self: a #ModestMailOperation
398  *
399  * Cancels an active mail operation
400  * 
401  * Returns: TRUE if the operation was succesfully canceled, FALSE otherwise
402  **/
403 gboolean                  modest_mail_operation_cancel      (ModestMailOperation *self);
404
405 G_END_DECLS
406
407 #endif /* __MODEST_MAIL_OPERATION_H__ */
408