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