1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU Lesser General Public
7 * License as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
21 #error "Only <camel/camel.h> can be included directly."
24 #ifndef CAMEL_IMAPX_SERVER_H
25 #define CAMEL_IMAPX_SERVER_H
27 #include <camel/camel-session.h>
28 #include <camel/camel-store.h>
30 #include "camel-imapx-command.h"
31 #include "camel-imapx-stream.h"
32 #include "camel-imapx-store-summary.h"
34 /* Standard GObject macros */
35 #define CAMEL_TYPE_IMAPX_SERVER \
36 (camel_imapx_server_get_type ())
37 #define CAMEL_IMAPX_SERVER(obj) \
38 (G_TYPE_CHECK_INSTANCE_CAST \
39 ((obj), CAMEL_TYPE_IMAPX_SERVER, CamelIMAPXServer))
40 #define CAMEL_IMAPX_SERVER_CLASS(cls) \
41 (G_TYPE_CHECK_CLASS_CAST \
42 ((cls), CAMEL_TYPE_IMAPX_SERVER, CamelIMAPXServerClass))
43 #define CAMEL_IS_IMAPX_SERVER(obj) \
44 (G_TYPE_CHECK_INSTANCE_TYPE \
45 ((obj), CAMEL_TYPE_IMAPX_SERVER))
46 #define CAMEL_IS_IMAPX_SERVER_CLASS(cls) \
47 (G_TYPE_CHECK_CLASS_TYPE \
48 ((cls), CAMEL_TYPE_IMAPX_SERVER))
49 #define CAMEL_IMAPX_SERVER_GET_CLASS(obj) \
50 (G_TYPE_INSTANCE_GET_CLASS \
51 ((obj), CAMEL_TYPE_IMAPX_SERVER, CamelIMAPXServerClass))
53 #define IMAPX_MODE_READ (1 << 0)
54 #define IMAPX_MODE_WRITE (1 << 1)
58 /* Avoid a circular reference. */
59 struct _CamelIMAPXStore;
60 struct _CamelIMAPXSettings;
62 typedef struct _CamelIMAPXServer CamelIMAPXServer;
63 typedef struct _CamelIMAPXServerClass CamelIMAPXServerClass;
64 typedef struct _CamelIMAPXServerPrivate CamelIMAPXServerPrivate;
66 typedef struct _CamelIMAPXIdle CamelIMAPXIdle;
67 struct _IMAPXJobQueueInfo;
69 /* untagged response handling */
71 (*CamelIMAPXUntaggedRespHandler)
72 (CamelIMAPXServer *server,
73 CamelIMAPXStream *stream,
74 GCancellable *cancellable,
78 * CamelIMAPXUntaggedRespHandlerDesc:
79 * @untagged_response: a string representation of the IMAP
80 * untagged response code. Must be
81 * all-uppercase with underscores allowed
83 * @handler: an untagged response handler function for #CamelIMAPXServer
84 * @next_response: the IMAP untagged code to call a registered
85 * handler for directly after successfully
86 * running @handler. If not NULL, @skip_stream_when_done
87 * for the current handler has no effect
88 * @skip_stream_when_done: whether or not to skip the current IMAP
89 * untagged response in the #CamelIMAPXStream.
90 * Set to TRUE if your handler does not eat
91 * the stream up to the next response token
93 * IMAP untagged response handler function descriptor. Use in conjunction
94 * with camel_imapx_server_register_untagged_handler() to register a new
95 * handler function for a given untagged response code
99 typedef struct _CamelIMAPXUntaggedRespHandlerDesc CamelIMAPXUntaggedRespHandlerDesc;
100 struct _CamelIMAPXUntaggedRespHandlerDesc {
101 const gchar *untagged_response;
102 const CamelIMAPXUntaggedRespHandler handler;
103 const gchar *next_response;
104 gboolean skip_stream_when_done;
107 struct _CamelIMAPXServer {
109 CamelIMAPXServerPrivate *priv;
111 /* Info about the current connection */
112 struct _capability_info *cinfo;
113 gboolean is_process_stream;
115 CamelIMAPXNamespaceList *nsl;
120 /* in micro seconds */
126 /* Current command/work queue. All commands are stored in one list,
127 * all the time, so they can be cleaned up in exception cases */
128 GRecMutex queue_lock;
129 CamelIMAPXCommand *literal;
130 CamelIMAPXCommandQueue *queue;
131 CamelIMAPXCommandQueue *active;
132 CamelIMAPXCommandQueue *done;
134 /* info on currently selected folder */
135 CamelFolder *select_folder;
136 CamelFolderChangeInfo *changes;
137 CamelFolder *select_pending;
138 guint32 permanentflags;
141 guint64 highestmodseq;
147 /* any expunges that happened from the last command, they are
148 * processed after the command completes. */
151 GThread *parser_thread;
152 /* Used for canceling operations as well as signaling parser thread to disconnnect/quit */
153 GCancellable *cancellable;
154 gboolean parser_quit;
157 CamelIMAPXIdle *idle;
160 gboolean use_qresync;
162 /* used to synchronize duplicate get_message requests */
168 struct _CamelIMAPXServerClass {
169 CamelObjectClass parent_class;
172 void (*select_changed) (CamelIMAPXServer *is,
173 const gchar *selected_folder);
174 void (*shutdown) (CamelIMAPXServer *is);
179 GType camel_imapx_server_get_type (void);
181 camel_imapx_server_new (struct _CamelIMAPXStore *store);
182 struct _CamelIMAPXStore *
183 camel_imapx_server_ref_store (CamelIMAPXServer *is);
184 struct _CamelIMAPXSettings *
185 camel_imapx_server_ref_settings (CamelIMAPXServer *is);
187 camel_imapx_server_ref_stream (CamelIMAPXServer *is);
188 gboolean camel_imapx_server_connect (CamelIMAPXServer *is,
189 GCancellable *cancellable,
191 gboolean imapx_connect_to_server (CamelIMAPXServer *is,
192 GCancellable *cancellable,
194 CamelAuthenticationResult
195 camel_imapx_server_authenticate (CamelIMAPXServer *is,
196 const gchar *mechanism,
197 GCancellable *cancellable,
199 GPtrArray * camel_imapx_server_list (CamelIMAPXServer *is,
203 GCancellable *cancellable,
205 gboolean camel_imapx_server_refresh_info (CamelIMAPXServer *is,
207 GCancellable *cancellable,
209 gboolean camel_imapx_server_sync_changes (CamelIMAPXServer *is,
211 GCancellable *cancellable,
213 gboolean camel_imapx_server_expunge (CamelIMAPXServer *is,
215 GCancellable *cancellable,
217 gboolean camel_imapx_server_fetch_messages
218 (CamelIMAPXServer *is,
222 GCancellable *cancellable,
224 gboolean camel_imapx_server_noop (CamelIMAPXServer *is,
226 GCancellable *cancellable,
228 CamelStream * camel_imapx_server_get_message (CamelIMAPXServer *is,
231 GCancellable *cancellable,
233 gboolean camel_imapx_server_copy_message (CamelIMAPXServer *is,
237 gboolean delete_originals,
238 GCancellable *cancellable,
240 gboolean camel_imapx_server_append_message
241 (CamelIMAPXServer *is,
243 CamelMimeMessage *message,
244 const CamelMessageInfo *mi,
246 GCancellable *cancellable,
248 gboolean camel_imapx_server_sync_message (CamelIMAPXServer *is,
251 GCancellable *cancellable,
253 gboolean camel_imapx_server_manage_subscription
254 (CamelIMAPXServer *is,
255 const gchar *folder_name,
257 GCancellable *cancellable,
259 gboolean camel_imapx_server_create_folder
260 (CamelIMAPXServer *is,
261 const gchar *folder_name,
262 GCancellable *cancellable,
264 gboolean camel_imapx_server_delete_folder
265 (CamelIMAPXServer *is,
266 const gchar *folder_name,
267 GCancellable *cancellable,
269 gboolean camel_imapx_server_rename_folder
270 (CamelIMAPXServer *is,
271 const gchar *old_name,
272 const gchar *new_name,
273 GCancellable *cancellable,
275 struct _IMAPXJobQueueInfo *
276 camel_imapx_server_get_job_queue_info
277 (CamelIMAPXServer *is);
278 const CamelIMAPXUntaggedRespHandlerDesc *
279 camel_imapx_server_register_untagged_handler
280 (CamelIMAPXServer *is,
281 const gchar *untagged_response,
282 const CamelIMAPXUntaggedRespHandlerDesc *desc);
283 gboolean camel_imapx_server_command_run (CamelIMAPXServer *is,
284 CamelIMAPXCommand *ic,
285 GCancellable *cancellable,
290 #endif /* CAMEL_IMAPX_SERVER_H */