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