Split camel-imapx library and merge into camel so that providers can be written on...
[platform/upstream/evolution-data-server.git] / camel / camel-imapx-server.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
4  *
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.
8  *
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.
13  *
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.
18  */
19
20 #if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
21 #error "Only <camel/camel.h> can be included directly."
22 #endif
23
24
25 #ifndef CAMEL_IMAPX_SERVER_H
26 #define CAMEL_IMAPX_SERVER_H
27
28 #include <camel/camel-session.h>
29 #include <camel/camel-store.h>
30
31 #include "camel-imapx-command.h"
32 #include "camel-imapx-stream.h"
33 #include "camel-imapx-store-summary.h"
34
35 /* Standard GObject macros */
36 #define CAMEL_TYPE_IMAPX_SERVER \
37         (camel_imapx_server_get_type ())
38 #define CAMEL_IMAPX_SERVER(obj) \
39         (G_TYPE_CHECK_INSTANCE_CAST \
40         ((obj), CAMEL_TYPE_IMAPX_SERVER, CamelIMAPXServer))
41 #define CAMEL_IMAPX_SERVER_CLASS(cls) \
42         (G_TYPE_CHECK_CLASS_CAST \
43         ((cls), CAMEL_TYPE_IMAPX_SERVER, CamelIMAPXServerClass))
44 #define CAMEL_IS_IMAPX_SERVER(obj) \
45         (G_TYPE_CHECK_INSTANCE_TYPE \
46         ((obj), CAMEL_TYPE_IMAPX_SERVER))
47 #define CAMEL_IS_IMAPX_SERVER_CLASS(cls) \
48         (G_TYPE_CHECK_CLASS_TYPE \
49         ((cls), CAMEL_TYPE_IMAPX_SERVER))
50 #define CAMEL_IMAPX_SERVER_GET_CLASS(obj) \
51         (G_TYPE_INSTANCE_GET_CLASS \
52         ((obj), CAMEL_TYPE_IMAPX_SERVER, CamelIMAPXServerClass))
53
54 #define IMAPX_MODE_READ (1 << 0)
55 #define IMAPX_MODE_WRITE (1 << 1)
56
57 G_BEGIN_DECLS
58
59 typedef struct _CamelIMAPXServer CamelIMAPXServer;
60 typedef struct _CamelIMAPXServerClass CamelIMAPXServerClass;
61
62 typedef struct _CamelIMAPXIdle CamelIMAPXIdle;
63 struct _IMAPXJobQueueInfo;
64
65 struct _CamelIMAPXServer {
66         CamelObject parent;
67
68         CamelStore *store;
69         CamelSession *session;
70
71         /* Info about the current connection */
72         CamelIMAPXStream *stream;
73         struct _capability_info *cinfo;
74         gboolean is_process_stream;
75
76         CamelIMAPXNamespaceList *nsl;
77
78         /* incoming jobs */
79         GQueue jobs;
80
81         /* in micro seconds */
82         guint job_timeout;
83
84         gchar tagprefix;
85         gint state : 4;
86
87         /* Current command/work queue.  All commands are stored in one list,
88          * all the time, so they can be cleaned up in exception cases */
89         GStaticRecMutex queue_lock;
90         CamelIMAPXCommand *literal;
91         CamelIMAPXCommandQueue *queue;
92         CamelIMAPXCommandQueue *active;
93         CamelIMAPXCommandQueue *done;
94
95         /* info on currently selected folder */
96         CamelFolder *select_folder;
97         CamelFolderChangeInfo *changes;
98         CamelFolder *select_pending;
99         guint32 permanentflags;
100         guint32 unseen;
101         guint64 uidvalidity;
102         guint64 highestmodseq;
103         guint32 uidnext;
104         guint32 exists;
105         guint32 recent;
106         guint32 mode;
107
108         /* any expunges that happened from the last command, they are
109          * processed after the command completes. */
110         GList *expunged;
111
112         GThread *parser_thread;
113         /* Protects the output stream between parser thread (which can disconnect from server) and other threads that issue
114          * commands. Input stream does not require a lock since only parser_thread can operate on it */
115         GStaticRecMutex ostream_lock;
116         /* Used for canceling operations as well as signaling parser thread to disconnnect/quit */
117         GCancellable *cancellable;
118         gboolean parser_quit;
119
120         /* Idle */
121         CamelIMAPXIdle *idle;
122         gboolean use_idle;
123
124         gboolean use_qresync;
125
126         /* used to synchronize duplicate get_message requests */
127         GCond *fetch_cond;
128         GMutex *fetch_mutex;
129         gint fetch_count;
130 };
131
132 struct _CamelIMAPXServerClass {
133         CamelObjectClass parent_class;
134
135         /* Signals */
136         void    (*select_changed)       (CamelIMAPXServer *is,
137                                          const gchar *selected_folder);
138         void    (*shutdown)             (CamelIMAPXServer *is);
139
140         gchar tagprefix;
141 };
142
143 GType           camel_imapx_server_get_type     (void);
144 CamelIMAPXServer *
145                 camel_imapx_server_new          (CamelStore *store);
146 gboolean        camel_imapx_server_connect      (CamelIMAPXServer *is,
147                                                  GCancellable *cancellable,
148                                                  GError **error);
149 gboolean        imapx_connect_to_server         (CamelIMAPXServer *is,
150                                                  GCancellable *cancellable,
151                                                  GError **error);
152 CamelAuthenticationResult
153                 camel_imapx_server_authenticate (CamelIMAPXServer *is,
154                                                  const gchar *mechanism,
155                                                  GCancellable *cancellable,
156                                                  GError **error);
157 GPtrArray *     camel_imapx_server_list         (CamelIMAPXServer *is,
158                                                  const gchar *top,
159                                                  guint32 flags,
160                                                  const gchar *ext,
161                                                  GCancellable *cancellable,
162                                                  GError **error);
163 gboolean        camel_imapx_server_refresh_info (CamelIMAPXServer *is,
164                                                  CamelFolder *folder,
165                                                  GCancellable *cancellable,
166                                                  GError **error);
167 gboolean        camel_imapx_server_sync_changes (CamelIMAPXServer *is,
168                                                  CamelFolder *folder,
169                                                  GCancellable *cancellable,
170                                                  GError **error);
171 gboolean        camel_imapx_server_expunge      (CamelIMAPXServer *is,
172                                                  CamelFolder *folder,
173                                                  GCancellable *cancellable,
174                                                  GError **error);
175 gboolean        camel_imapx_server_fetch_messages
176                                                 (CamelIMAPXServer *is,
177                                                  CamelFolder *folder,
178                                                  CamelFetchType type,
179                                                  gint limit,
180                                                  GCancellable *cancellable,
181                                                  GError **error);
182 gboolean        camel_imapx_server_noop         (CamelIMAPXServer *is,
183                                                  CamelFolder *folder,
184                                                  GCancellable *cancellable,
185                                                  GError **error);
186 CamelStream *   camel_imapx_server_get_message  (CamelIMAPXServer *is,
187                                                  CamelFolder *folder,
188                                                  const gchar *uid,
189                                                  GCancellable *cancellable,
190                                                  GError **error);
191 gboolean        camel_imapx_server_copy_message (CamelIMAPXServer *is,
192                                                  CamelFolder *source,
193                                                  CamelFolder *dest,
194                                                  GPtrArray *uids,
195                                                  gboolean delete_originals,
196                                                  GCancellable *cancellable,
197                                                  GError **error);
198 gboolean        camel_imapx_server_append_message
199                                                 (CamelIMAPXServer *is,
200                                                  CamelFolder *folder,
201                                                  CamelMimeMessage *message,
202                                                  const CamelMessageInfo *mi,
203                                                  gchar **append_uid,
204                                                  GCancellable *cancellable,
205                                                  GError **error);
206 gboolean        camel_imapx_server_sync_message (CamelIMAPXServer *is,
207                                                  CamelFolder *folder,
208                                                  const gchar *uid,
209                                                  GCancellable *cancellable,
210                                                  GError **error);
211 gboolean        camel_imapx_server_manage_subscription
212                                                 (CamelIMAPXServer *is,
213                                                  const gchar *folder_name,
214                                                  gboolean subscribe,
215                                                  GCancellable *cancellable,
216                                                  GError **error);
217 gboolean        camel_imapx_server_create_folder
218                                                 (CamelIMAPXServer *is,
219                                                  const gchar *folder_name,
220                                                  GCancellable *cancellable,
221                                                  GError **error);
222 gboolean        camel_imapx_server_delete_folder
223                                                 (CamelIMAPXServer *is,
224                                                  const gchar *folder_name,
225                                                  GCancellable *cancellable,
226                                                  GError **error);
227 gboolean        camel_imapx_server_rename_folder
228                                                 (CamelIMAPXServer *is,
229                                                  const gchar *old_name,
230                                                  const gchar *new_name,
231                                                  GCancellable *cancellable,
232                                                  GError **error);
233 struct _IMAPXJobQueueInfo *
234                 camel_imapx_server_get_job_queue_info
235                                                 (CamelIMAPXServer *is);
236
237 G_END_DECLS
238
239 #endif /* CAMEL_IMAPX_SERVER_H */