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