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