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>
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))
45 typedef struct _ModestMailOperation ModestMailOperation;
46 typedef struct _ModestMailOperationClass ModestMailOperationClass;
49 * ModestMailOperationForwardType:
51 * How the original message will be forwarded to the recipient
53 typedef enum _ModestMailOperationForwardType {
54 MODEST_MAIL_OPERATION_FORWARD_TYPE_INLINE = 1,
55 MODEST_MAIL_OPERATION_FORWARD_TYPE_ATTACHMENT
56 } ModestMailOperationForwardType;
59 * ModestMailOperationReplyType:
61 * How the original message will be forwarded to the recipient
63 typedef enum _ModestMailOperationReplyType {
64 MODEST_MAIL_OPERATION_REPLY_TYPE_CITE = 1,
65 MODEST_MAIL_OPERATION_REPLY_TYPE_QUOTE
66 } ModestMailOperationReplyType;
69 * ModestMailOperationReplyMode:
71 * Who will be the recipients of the replied message
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;
80 * ModestMailOperationStatus:
82 * The state of a mail operation
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;
93 struct _ModestMailOperation {
95 /* insert public members, if any */
98 struct _ModestMailOperationClass {
99 GObjectClass parent_class;
102 void (*progress_changed) (ModestMailOperation *self, gpointer user_data);
105 /* member functions */
106 GType modest_mail_operation_get_type (void) G_GNUC_CONST;
108 /* typical parameter-less _new function */
109 ModestMailOperation* modest_mail_operation_new (void);
111 /* fill in other public functions, eg.: */
114 * modest_mail_operation_send_mail:
115 * @self: a #ModestMailOperation
116 * @transport_account: a non-NULL #TnyTransportAccount
117 * @msg: a non-NULL #TnyMsg
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
124 void modest_mail_operation_send_mail (ModestMailOperation *self,
125 TnyTransportAccount *transport_account,
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
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
145 void modest_mail_operation_send_new_mail (ModestMailOperation *self,
146 TnyTransportAccount *transport_account,
151 const gchar *subject,
153 const GList *attachments_list);
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
160 * Creates a forwarded message from an existing one
162 * Returns: a new #TnyMsg, or NULL in case of error
164 TnyMsg* modest_mail_operation_create_forward_mail (TnyMsg *msg,
166 ModestMailOperationForwardType forward_type);
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
174 * Creates a new message to reply to an existing one
176 * Returns: Returns: a new #TnyMsg, or NULL in case of error
178 TnyMsg* modest_mail_operation_create_reply_mail (TnyMsg *msg,
180 ModestMailOperationReplyType reply_type,
181 ModestMailOperationReplyMode reply_mode);
184 * modest_mail_operation_update_account:
185 * @self: a #ModestMailOperation
186 * @store_account: a #TnyStoreAccount
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.
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))
200 * modest_mail_operation_queue_add (queue, mail_op);
202 * g_object_unref (G_OBJECT (mail_op));
203 * </programlisting></informalexample>
205 * Returns: TRUE if the mail operation could be started, or FALSE otherwise
207 gboolean modest_mail_operation_update_account (ModestMailOperation *self,
208 TnyStoreAccount *store_account);
210 /* Functions that perform store operations */
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
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
224 * Returns: a newly created #TnyFolder or NULL in case of error.
226 TnyFolder* modest_mail_operation_create_folder (ModestMailOperation *self,
227 TnyFolderStore *parent,
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
237 * Removes a folder. This operation is synchronous, so the
238 * #ModestMailOperation should not be added to any
239 * #ModestMailOperationQueue
241 void modest_mail_operation_remove_folder (ModestMailOperation *self,
243 gboolean remove_to_trash);
246 * modest_mail_operation_rename_folder:
247 * @self: a #ModestMailOperation
248 * @folder: a #TnyFolder
249 * @name: a non-NULL name without "/"
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
255 void modest_mail_operation_rename_folder (ModestMailOperation *self,
260 * modest_mail_operation_move_folder:
261 * @self: a #ModestMailOperation
262 * @folder: a #TnyFolder
263 * @parent: the new parent of the folder as #TnyFolderStore
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
271 void modest_mail_operation_move_folder (ModestMailOperation *self,
273 TnyFolderStore *parent);
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
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
288 void modest_mail_operation_copy_folder (ModestMailOperation *self,
290 TnyFolderStore *parent);
292 /* Functions that performs msg operations */
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
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.
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))
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);
314 * g_object_unref (G_OBJECT (mail_op));
315 * </programlisting></informalexample>
317 * Returns: TRUE if the mail operation could be started, or FALSE otherwise
319 gboolean modest_mail_operation_copy_msg (ModestMailOperation *self,
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
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.
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))
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);
343 * g_object_unref (G_OBJECT (mail_op));
344 * </programlisting></informalexample>
346 * Returns: TRUE if the mail operation could be started, or FALSE otherwise
348 gboolean modest_mail_operation_move_msg (ModestMailOperation *self,
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
359 * Deletes a message. This operation is synchronous, so the
360 * #ModestMailOperation should not be added to any
361 * #ModestMailOperationQueue
363 void modest_mail_operation_remove_msg (ModestMailOperation *self,
365 gboolean remove_to_trash);
367 /* Functions to control mail operations */
369 * modest_mail_operation_get_task_done:
370 * @self: a #ModestMailOperation
372 * Gets the amount of work done for a given mail operation. This
373 * amount of work is an absolute value.
375 * Returns: the amount of work completed
377 guint modest_mail_operation_get_task_done (ModestMailOperation *self);
380 * modest_mail_operation_get_task_total:
381 * @self: a #ModestMailOperation
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.
386 * Returns: the total required amount of work
388 guint modest_mail_operation_get_task_total (ModestMailOperation *self);
392 * modest_mail_operation_is_finished:
393 * @self: a #ModestMailOperation
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
402 * Returns: TRUE if the operation is finished, FALSE otherwise
404 gboolean modest_mail_operation_is_finished (ModestMailOperation *self);
407 * modest_mail_operation_is_finished:
408 * @self: a #ModestMailOperation
410 * Gets the current status of the given mail operation
412 * Returns: the current status or MODEST_MAIL_OPERATION_STATUS_INVALID in case of error
414 ModestMailOperationStatus modest_mail_operation_get_status (ModestMailOperation *self);
417 * modest_mail_operation_get_error:
418 * @self: a #ModestMailOperation
420 * Gets the error associated to the mail operation if exists
422 * Returns: the #GError associated to the #ModestMailOperation if it
423 * exists or NULL otherwise
425 const GError* modest_mail_operation_get_error (ModestMailOperation *self);
428 * modest_mail_operation_cancel:
429 * @self: a #ModestMailOperation
431 * Cancels an active mail operation
433 * Returns: TRUE if the operation was succesfully canceled, FALSE otherwise
435 gboolean modest_mail_operation_cancel (ModestMailOperation *self);
439 #endif /* __MODEST_MAIL_OPERATION_H__ */