Extending test-client-custom-summary to try e_book_client_get_contacts_uids()
[platform/upstream/evolution-data-server.git] / camel / camel-imapx-utils.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 #ifndef CAMEL_IMAPX_UTILS_H
25 #define CAMEL_IMAPX_UTILS_H
26
27 #include <camel/camel-store.h>
28
29 struct _CamelIMAPXStream;
30 struct _CamelFlag;
31 struct _CamelIMAPXNamespaceList;
32 struct _CamelIMAPXStore;
33
34 /* list of strings we know about that can be *quickly* tokenised */
35 typedef enum _camel_imapx_id_t {
36         IMAPX_UNKNOWN = 0,
37         IMAPX_ALERT,
38         IMAPX_APPENDUID,
39         IMAPX_BAD,
40         IMAPX_BODY,
41         IMAPX_BODYSTRUCTURE,
42         IMAPX_BYE,
43         IMAPX_CAPABILITY,
44         IMAPX_CLOSED,
45         IMAPX_COPYUID,
46         IMAPX_ENVELOPE,
47         IMAPX_EXISTS,
48         IMAPX_EXPUNGE,
49         IMAPX_FETCH,
50         IMAPX_FLAGS,
51         IMAPX_HIGHESTMODSEQ,
52         IMAPX_INTERNALDATE,
53         IMAPX_LIST,
54         IMAPX_LSUB,
55         IMAPX_MESSAGES,
56         IMAPX_MODSEQ,
57         IMAPX_NAMESPACE,
58         IMAPX_NEWNAME,
59         IMAPX_NO,
60         IMAPX_NOMODSEQ,
61         IMAPX_OK,
62         IMAPX_PARSE,
63         IMAPX_PERMANENTFLAGS,
64         IMAPX_PREAUTH,
65         IMAPX_READ_ONLY,
66         IMAPX_READ_WRITE,
67         IMAPX_RECENT,
68         IMAPX_RFC822_HEADER,
69         IMAPX_RFC822_SIZE,
70         IMAPX_RFC822_TEXT,
71         IMAPX_STATUS,
72         IMAPX_TRYCREATE,
73         IMAPX_UID,
74         IMAPX_UIDVALIDITY,
75         IMAPX_UNSEEN,
76         IMAPX_UIDNEXT,
77         IMAPX_VANISHED,
78 } camel_imapx_id_t;
79
80 #define CAMEL_IMAPX_UNTAGGED_BAD        "BAD"
81 #define CAMEL_IMAPX_UNTAGGED_BYE        "BYE"
82 #define CAMEL_IMAPX_UNTAGGED_CAPABILITY "CAPABILITY"
83 #define CAMEL_IMAPX_UNTAGGED_EXISTS     "EXISTS"
84 #define CAMEL_IMAPX_UNTAGGED_EXPUNGE    "EXPUNGE"
85 #define CAMEL_IMAPX_UNTAGGED_FETCH      "FETCH"
86 #define CAMEL_IMAPX_UNTAGGED_FLAGS      "FLAGS"
87 #define CAMEL_IMAPX_UNTAGGED_LIST       "LIST"
88 #define CAMEL_IMAPX_UNTAGGED_LSUB       "LSUB"
89 #define CAMEL_IMAPX_UNTAGGED_NAMESPACE  "NAMESPACE"
90 #define CAMEL_IMAPX_UNTAGGED_NO         "NO"
91 #define CAMEL_IMAPX_UNTAGGED_OK         "OK"
92 #define CAMEL_IMAPX_UNTAGGED_PREAUTH    "PREAUTH"
93 #define CAMEL_IMAPX_UNTAGGED_RECENT     "RECENT"
94 #define CAMEL_IMAPX_UNTAGGED_STATUS     "STATUS"
95 #define CAMEL_IMAPX_UNTAGGED_VANISHED   "VANISHED"
96
97 /* str MUST be in upper case, tokenised using gperf function */
98 camel_imapx_id_t imapx_tokenise (register const gchar *str, register guint len);
99
100 /* this flag should be part of imapfoldersummary */
101 enum {
102         CAMEL_IMAPX_MESSAGE_RECENT = (1 << 21),
103 };
104
105 /* ********************************************************************** */
106
107 GPtrArray *imapx_parse_uids (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error);
108 void imapx_parse_flags (struct _CamelIMAPXStream *stream, guint32 *flagsp, struct _CamelFlag **user_flagsp, GCancellable *cancellable, GError **error);
109 void imapx_write_flags (GString *string, guint32 flags, struct _CamelFlag *user_flags);
110 gboolean imapx_update_message_info_flags (CamelMessageInfo *info, guint32 server_flags, CamelFlag *server_user_flags, guint32 permanent_flags, CamelFolder *folder, gboolean unsolicited);
111 void imapx_set_message_info_flags_for_new_message (CamelMessageInfo *info, guint32 server_flags, CamelFlag *server_user_flags,
112                                                         CamelFolder *folder);
113 void imapx_update_store_summary (CamelFolder *folder);
114
115 /* ********************************************************************** */
116 enum {
117         IMAPX_CAPABILITY_IMAP4                  = (1 << 0),
118         IMAPX_CAPABILITY_IMAP4REV1              = (1 << 1),
119         IMAPX_CAPABILITY_STATUS                 = (1 << 2),
120         IMAPX_CAPABILITY_NAMESPACE              = (1 << 3),
121         IMAPX_CAPABILITY_UIDPLUS                = (1 << 4),
122         IMAPX_CAPABILITY_LITERALPLUS            = (1 << 5),
123         IMAPX_CAPABILITY_STARTTLS               = (1 << 6),
124         IMAPX_CAPABILITY_IDLE                   = (1 << 7),
125         IMAPX_CAPABILITY_CONDSTORE              = (1 << 8),
126         IMAPX_CAPABILITY_QRESYNC                = (1 << 9),
127         IMAPX_CAPABILITY_LIST_STATUS            = (1 << 10),
128         IMAPX_CAPABILITY_LIST_EXTENDED          = (1 << 11),
129 };
130
131 struct _capability_info {
132         guint32 capa;
133         GHashTable *auth_types;
134 };
135
136 struct _capability_info *imapx_parse_capability (struct _CamelIMAPXStream *stream, GCancellable *cancellable, GError **error);
137 void imapx_free_capability (struct _capability_info *);
138 guint32 imapx_register_capability (const gchar *capability);
139 guint32 imapx_lookup_capability (const gchar *capability);
140
141 gboolean imapx_parse_param_list (struct _CamelIMAPXStream *is, struct _camel_header_param **plist, GCancellable *cancellable, GError **error) /* IO,PARSE */;
142 struct _CamelContentDisposition *imapx_parse_ext_optional (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error) /* IO,PARSE */;
143 struct _CamelMessageContentInfo *imapx_parse_body_fields (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error) /* IO,PARSE */;
144 struct _camel_header_address *imapx_parse_address_list (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error) /* IO,PARSE */;
145 struct _CamelMessageInfo *imapx_parse_envelope (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error) /* IO, PARSE */;
146 struct _CamelMessageContentInfo *imapx_parse_body (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error) /* IO,PARSE */;
147 gchar *imapx_parse_section (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error) /* IO,PARSE */;
148 void imapx_free_body (struct _CamelMessageContentInfo *cinfo);
149
150 /* ********************************************************************** */
151 /* all the possible stuff we might get from a fetch request */
152 /* this assumes the caller/server doesn't send any one of these types twice */
153 struct _fetch_info {
154         guint32 got;            /* what we got, see below */
155         CamelStream *body;      /* BODY[.*](<.*>)? */
156         CamelStream *text;      /* RFC822.TEXT */
157         CamelStream *header;    /* RFC822.HEADER */
158         struct _CamelMessageInfo *minfo; /* ENVELOPE */
159         struct _CamelMessageContentInfo *cinfo; /* BODYSTRUCTURE,BODY */
160         guint32 size;           /* RFC822.SIZE */
161         guint32 offset;         /* start offset of a BODY[]<offset.length> request */
162         guint32 flags;          /* FLAGS */
163         guint64 modseq;         /* MODSEQ */
164         struct _CamelFlag *user_flags;
165         gchar *date;            /* INTERNALDATE */
166         gchar *section;         /* section for a BODY[section] request */
167         gchar *uid;             /* UID */
168 };
169
170 #define FETCH_BODY (1 << 0)
171 #define FETCH_TEXT (1 << 1)
172 #define FETCH_HEADER (1 << 2)
173 #define FETCH_MINFO (1 << 3)
174 #define FETCH_CINFO (1 << 4)
175 #define FETCH_SIZE (1 << 5)
176 #define FETCH_OFFSET (1 << 6)
177 #define FETCH_FLAGS (1 << 7)
178 #define FETCH_DATE (1 << 8)
179 #define FETCH_SECTION (1 << 9)
180 #define FETCH_UID (1 << 10)
181 #define FETCH_MODSEQ (1 << 11)
182
183 struct _fetch_info *imapx_parse_fetch (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error);
184 void imapx_free_fetch (struct _fetch_info *finfo);
185 void imapx_dump_fetch (struct _fetch_info *finfo);
186
187 /* ********************************************************************** */
188
189 struct _status_info {
190         camel_imapx_id_t result; /* ok/no/bad/preauth only, user_cancel - client response */
191         camel_imapx_id_t condition; /* read-only/read-write/alert/parse/trycreate/newname/permanentflags/uidvalidity/unseen/highestmodseq */
192
193         union {
194                 struct {
195                         gchar *oldname;
196                         gchar *newname;
197                 } newname;
198                 guint32 permanentflags;
199                 guint64 uidvalidity;
200                 guint32 uidnext;
201                 guint32 unseen;
202                 guint64 highestmodseq;
203                 struct {
204                         guint64 uidvalidity;
205                         guint32 uid;
206                 } appenduid;
207                 struct {
208                         guint64 uidvalidity;
209                         GPtrArray *uids;
210                         GPtrArray *copied_uids;
211                 } copyuid;
212                 struct _capability_info *cinfo;
213         } u;
214
215         gchar *text;
216 };
217
218 struct _status_info *imapx_parse_status (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error);
219 struct _status_info *imapx_copy_status (struct _status_info *sinfo);
220 void imapx_free_status (struct _status_info *sinfo);
221
222 /* ********************************************************************** */
223 /* parses the response from the status command */
224 struct _state_info {
225         gchar *name;
226         guint32 messages;
227         guint32 recent;
228         guint32 uidnext;
229         guint32 unseen;
230         guint64 uidvalidity;
231         guint64 highestmodseq;
232 };
233
234 /* use g_free to free the return value */
235 struct _state_info *imapx_parse_status_info (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error);
236
237 /* ********************************************************************** */
238
239 /* should this just return a FolderInfo?
240  * should this just return the name & flags & separator by reference? */
241 struct _list_info {
242         guint32 flags : 24;
243         gchar separator;
244         gchar *name;
245 };
246
247 struct _list_info *imapx_parse_list (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error);
248 gchar *imapx_list_get_path (struct _list_info *li);
249 void imapx_free_list (struct _list_info *linfo);
250
251 /* ********************************************************************** */
252 typedef struct _IMAPXJobQueueInfo {
253         guint queue_len;
254
255         /* list of folders for which jobs are in the queue */
256         GHashTable *folders;
257 } IMAPXJobQueueInfo;
258
259 void camel_imapx_destroy_job_queue_info (IMAPXJobQueueInfo *jinfo);
260
261 /* ********************************************************************** */
262
263 extern guchar imapx_specials[256];
264
265 #define IMAPX_TYPE_CHAR (1 << 0)
266 #define IMAPX_TYPE_TEXT_CHAR (1 << 1)
267 #define IMAPX_TYPE_QUOTED_CHAR (1 << 2)
268 #define IMAPX_TYPE_ATOM_CHAR (1 << 3)
269 #define IMAPX_TYPE_TOKEN_CHAR (1 << 4)
270 #define IMAPX_TYPE_NOTID_CHAR (1 << 5)
271
272 guchar imapx_is_mask (const gchar *p);
273
274 #define imapx_is_text_char(c) ((imapx_specials[((unsigned char)(c))&0xff] & IMAPX_TYPE_TEXT_CHAR) != 0)
275 #define imapx_is_quoted_char(c) ((imapx_specials[((unsigned char)(c))&0xff] & IMAPX_TYPE_QUOTED_CHAR) != 0)
276 #define imapx_is_atom_char(c) ((imapx_specials[((unsigned char)(c))&0xff] & IMAPX_TYPE_ATOM_CHAR) != 0)
277 #define imapx_is_token_char(c) ((imapx_specials[((unsigned char)(c))&0xff] & IMAPX_TYPE_TOKEN_CHAR) != 0)
278 #define imapx_is_notid_char(c) ((imapx_specials[((unsigned char)(c))&0xff] & IMAPX_TYPE_NOTID_CHAR) != 0)
279
280 #define imapx_is_atom(s) (imapx_is_mask(s) & IMAPX_TYPE_ATOM_CHAR)
281
282 extern gint camel_imapx_debug_flags;
283 #define CAMEL_IMAPX_DEBUG_command       (1 << 0)
284 #define CAMEL_IMAPX_DEBUG_debug         (1 << 1)
285 #define CAMEL_IMAPX_DEBUG_extra         (1 << 2)
286 #define CAMEL_IMAPX_DEBUG_io            (1 << 3)
287 #define CAMEL_IMAPX_DEBUG_token         (1 << 4)
288 #define CAMEL_IMAPX_DEBUG_parse         (1 << 5)
289 #define CAMEL_IMAPX_DEBUG_conman        (1 << 6)
290
291 /* Set this to zero to remove all debug output at build time */
292 #define CAMEL_IMAPX_DEBUG_ALL           ((1 << 7)-1)
293
294 #define camel_debug_flag(type) (camel_imapx_debug_flags & CAMEL_IMAPX_DEBUG_ALL & CAMEL_IMAPX_DEBUG_ ## type)
295 #define camel_imapx_debug(type, tagprefix, fmt, ...) do {               \
296                 if (camel_debug_flag (type))                            \
297                         printf ("[imapx:%c] " fmt, tagprefix , ##__VA_ARGS__); \
298         } while (0)
299
300 /* ********************************************************************** */
301
302 void imapx_utils_init (void);
303
304 /* chen adds from old imap provider - place it in right place */
305 gchar *imapx_path_to_physical (const gchar *prefix, const gchar *vpath);
306 gchar *imapx_concat (struct _CamelIMAPXStore *imapx_store, const gchar *prefix, const gchar *suffix);
307 gchar * imapx_get_temp_uid (void);
308
309 void camel_imapx_namespace_list_clear (struct _CamelIMAPXNamespaceList *nsl);
310 struct _CamelIMAPXNamespaceList * imapx_parse_namespace_list (struct _CamelIMAPXStream *stream, GCancellable *cancellable, GError **error);
311 struct _CamelIMAPXNamespaceList *camel_imapx_namespace_list_copy (const struct _CamelIMAPXNamespaceList *nsl);
312
313 #endif