1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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.
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.
30 #ifndef __MODEST_MAIL_OPERATION_H__
31 #define __MODEST_MAIL_OPERATION_H__
33 #include <tny-transport-account.h>
34 #include <tny-folder-store.h>
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))
46 typedef struct _ModestMailOperation ModestMailOperation;
47 typedef struct _ModestMailOperationClass ModestMailOperationClass;
50 * ModestMailOperationStatus:
52 * The state of a mail operation
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;
63 struct _ModestMailOperation {
65 /* insert public members, if any */
68 struct _ModestMailOperationClass {
69 GObjectClass parent_class;
72 void (*progress_changed) (ModestMailOperation *self, gpointer user_data);
75 /* member functions */
76 GType modest_mail_operation_get_type (void) G_GNUC_CONST;
78 /* typical parameter-less _new function */
79 ModestMailOperation* modest_mail_operation_new (void);
81 /* fill in other public functions, eg.: */
84 * modest_mail_operation_send_mail:
85 * @self: a #ModestMailOperation
86 * @transport_account: a non-NULL #TnyTransportAccount
87 * @msg: a non-NULL #TnyMsg
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
94 void modest_mail_operation_send_mail (ModestMailOperation *self,
95 TnyTransportAccount *transport_account,
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
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
115 void modest_mail_operation_send_new_mail (ModestMailOperation *self,
116 TnyTransportAccount *transport_account,
121 const gchar *subject,
123 const GList *attachments_list);
126 * modest_mail_operation_update_account:
127 * @self: a #ModestMailOperation
128 * @store_account: a #TnyStoreAccount
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.
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))
142 * modest_mail_operation_queue_add (queue, mail_op);
144 * g_object_unref (G_OBJECT (mail_op));
145 * </programlisting></informalexample>
147 * Returns: TRUE if the mail operation could be started, or FALSE otherwise
149 gboolean modest_mail_operation_update_account (ModestMailOperation *self,
150 TnyStoreAccount *store_account);
152 /* Functions that perform store operations */
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
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
166 * Returns: a newly created #TnyFolder or NULL in case of error.
168 TnyFolder* modest_mail_operation_create_folder (ModestMailOperation *self,
169 TnyFolderStore *parent,
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
179 * Removes a folder. This operation is synchronous, so the
180 * #ModestMailOperation should not be added to any
181 * #ModestMailOperationQueue
183 void modest_mail_operation_remove_folder (ModestMailOperation *self,
185 gboolean remove_to_trash);
188 * modest_mail_operation_rename_folder:
189 * @self: a #ModestMailOperation
190 * @folder: a #TnyFolder
191 * @name: a non-NULL name without "/"
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
197 void modest_mail_operation_rename_folder (ModestMailOperation *self,
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
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.
214 * If @delete_original is TRUE this function moves the original
215 * folder, if it is FALSE the it just copies it
217 * Returns: the newly transfered folder
219 TnyFolder* modest_mail_operation_xfer_folder (ModestMailOperation *self,
221 TnyFolderStore *parent,
222 gboolean delete_original);
225 /* Functions that performs msg operations */
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
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.
239 * If the @delete_original paramter is TRUE then this function moves
240 * the message between folders, otherwise it copies it.
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))
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);
251 * g_object_unref (G_OBJECT (mail_op));
252 * </programlisting></informalexample>
254 * Returns: TRUE if the mail operation could be started, or FALSE otherwise
256 gboolean modest_mail_operation_xfer_msg (ModestMailOperation *self,
259 gboolean delete_original);
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
268 * Deletes a message. This operation is synchronous, so the
269 * #ModestMailOperation should not be added to any
270 * #ModestMailOperationQueue
272 void modest_mail_operation_remove_msg (ModestMailOperation *self,
274 gboolean remove_to_trash);
276 /* Functions to control mail operations */
278 * modest_mail_operation_get_task_done:
279 * @self: a #ModestMailOperation
281 * Gets the amount of work done for a given mail operation. This
282 * amount of work is an absolute value.
284 * Returns: the amount of work completed
286 guint modest_mail_operation_get_task_done (ModestMailOperation *self);
289 * modest_mail_operation_get_task_total:
290 * @self: a #ModestMailOperation
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.
295 * Returns: the total required amount of work
297 guint modest_mail_operation_get_task_total (ModestMailOperation *self);
301 * modest_mail_operation_is_finished:
302 * @self: a #ModestMailOperation
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
311 * Returns: TRUE if the operation is finished, FALSE otherwise
313 gboolean modest_mail_operation_is_finished (ModestMailOperation *self);
316 * modest_mail_operation_is_finished:
317 * @self: a #ModestMailOperation
319 * Gets the current status of the given mail operation
321 * Returns: the current status or MODEST_MAIL_OPERATION_STATUS_INVALID in case of error
323 ModestMailOperationStatus modest_mail_operation_get_status (ModestMailOperation *self);
326 * modest_mail_operation_get_error:
327 * @self: a #ModestMailOperation
329 * Gets the error associated to the mail operation if exists
331 * Returns: the #GError associated to the #ModestMailOperation if it
332 * exists or NULL otherwise
334 const GError* modest_mail_operation_get_error (ModestMailOperation *self);
337 * modest_mail_operation_cancel:
338 * @self: a #ModestMailOperation
340 * Cancels an active mail operation
342 * Returns: TRUE if the operation was succesfully canceled, FALSE otherwise
344 gboolean modest_mail_operation_cancel (ModestMailOperation *self);
348 #endif /* __MODEST_MAIL_OPERATION_H__ */