Whitespace cleanups.
[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 /* str MUST be in upper case, tokenised using gperf function */
81 camel_imapx_id_t imapx_tokenise (register const gchar *str, register guint len);
82
83 /* this flag should be part of imapfoldersummary */
84 enum {
85         CAMEL_IMAPX_MESSAGE_RECENT = (1 << 21),
86 };
87
88 /* ********************************************************************** */
89
90 GPtrArray *imapx_parse_uids (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error);
91 void imapx_parse_flags (struct _CamelIMAPXStream *stream, guint32 *flagsp, struct _CamelFlag **user_flagsp, GCancellable *cancellable, GError **error);
92 void imapx_write_flags (GString *string, guint32 flags, struct _CamelFlag *user_flags);
93 gboolean imapx_update_message_info_flags (CamelMessageInfo *info, guint32 server_flags, CamelFlag *server_user_flags, guint32 permanent_flags, CamelFolder *folder, gboolean unsolicited);
94 void imapx_set_message_info_flags_for_new_message (CamelMessageInfo *info, guint32 server_flags, CamelFlag *server_user_flags,
95                                                         CamelFolder *folder);
96 void imapx_update_store_summary (CamelFolder *folder);
97
98 /* ********************************************************************** */
99 enum {
100         IMAPX_CAPABILITY_IMAP4                  = (1 << 0),
101         IMAPX_CAPABILITY_IMAP4REV1              = (1 << 1),
102         IMAPX_CAPABILITY_STATUS                 = (1 << 2),
103         IMAPX_CAPABILITY_NAMESPACE              = (1 << 3),
104         IMAPX_CAPABILITY_UIDPLUS                = (1 << 4),
105         IMAPX_CAPABILITY_LITERALPLUS            = (1 << 5),
106         IMAPX_CAPABILITY_STARTTLS               = (1 << 6),
107         IMAPX_CAPABILITY_IDLE                   = (1 << 7),
108         IMAPX_CAPABILITY_CONDSTORE              = (1 << 8),
109         IMAPX_CAPABILITY_QRESYNC                = (1 << 9),
110         IMAPX_CAPABILITY_LIST_STATUS            = (1 << 10),
111         IMAPX_CAPABILITY_LIST_EXTENDED          = (1 << 11),
112 };
113
114 struct _capability_info {
115         guint32 capa;
116         GHashTable *auth_types;
117 };
118
119 struct _capability_info *imapx_parse_capability (struct _CamelIMAPXStream *stream, GCancellable *cancellable, GError **error);
120 void imapx_free_capability (struct _capability_info *);
121
122 gboolean imapx_parse_param_list (struct _CamelIMAPXStream *is, struct _camel_header_param **plist, GCancellable *cancellable, GError **error) /* IO,PARSE */;
123 struct _CamelContentDisposition *imapx_parse_ext_optional (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error) /* IO,PARSE */;
124 struct _CamelMessageContentInfo *imapx_parse_body_fields (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error) /* IO,PARSE */;
125 struct _camel_header_address *imapx_parse_address_list (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error) /* IO,PARSE */;
126 struct _CamelMessageInfo *imapx_parse_envelope (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error) /* IO, PARSE */;
127 struct _CamelMessageContentInfo *imapx_parse_body (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error) /* IO,PARSE */;
128 gchar *imapx_parse_section (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error) /* IO,PARSE */;
129 void imapx_free_body (struct _CamelMessageContentInfo *cinfo);
130
131 /* ********************************************************************** */
132 /* all the possible stuff we might get from a fetch request */
133 /* this assumes the caller/server doesn't send any one of these types twice */
134 struct _fetch_info {
135         guint32 got;            /* what we got, see below */
136         CamelStream *body;      /* BODY[.*](<.*>)? */
137         CamelStream *text;      /* RFC822.TEXT */
138         CamelStream *header;    /* RFC822.HEADER */
139         struct _CamelMessageInfo *minfo; /* ENVELOPE */
140         struct _CamelMessageContentInfo *cinfo; /* BODYSTRUCTURE,BODY */
141         guint32 size;           /* RFC822.SIZE */
142         guint32 offset;         /* start offset of a BODY[]<offset.length> request */
143         guint32 flags;          /* FLAGS */
144         guint64 modseq;         /* MODSEQ */
145         struct _CamelFlag *user_flags;
146         gchar *date;            /* INTERNALDATE */
147         gchar *section;         /* section for a BODY[section] request */
148         gchar *uid;             /* UID */
149 };
150
151 #define FETCH_BODY (1 << 0)
152 #define FETCH_TEXT (1 << 1)
153 #define FETCH_HEADER (1 << 2)
154 #define FETCH_MINFO (1 << 3)
155 #define FETCH_CINFO (1 << 4)
156 #define FETCH_SIZE (1 << 5)
157 #define FETCH_OFFSET (1 << 6)
158 #define FETCH_FLAGS (1 << 7)
159 #define FETCH_DATE (1 << 8)
160 #define FETCH_SECTION (1 << 9)
161 #define FETCH_UID (1 << 10)
162 #define FETCH_MODSEQ (1 << 11)
163
164 struct _fetch_info *imapx_parse_fetch (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error);
165 void imapx_free_fetch (struct _fetch_info *finfo);
166 void imapx_dump_fetch (struct _fetch_info *finfo);
167
168 /* ********************************************************************** */
169
170 struct _status_info {
171         camel_imapx_id_t result; /* ok/no/bad/preauth only, user_cancel - client response */
172         camel_imapx_id_t condition; /* read-only/read-write/alert/parse/trycreate/newname/permanentflags/uidvalidity/unseen/highestmodseq */
173
174         union {
175                 struct {
176                         gchar *oldname;
177                         gchar *newname;
178                 } newname;
179                 guint32 permanentflags;
180                 guint64 uidvalidity;
181                 guint32 uidnext;
182                 guint32 unseen;
183                 guint64 highestmodseq;
184                 struct {
185                         guint64 uidvalidity;
186                         guint32 uid;
187                 } appenduid;
188                 struct {
189                         guint64 uidvalidity;
190                         GPtrArray *uids;
191                         GPtrArray *copied_uids;
192                 } copyuid;
193                 struct _capability_info *cinfo;
194         } u;
195
196         gchar *text;
197 };
198
199 struct _status_info *imapx_parse_status (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error);
200 struct _status_info *imapx_copy_status (struct _status_info *sinfo);
201 void imapx_free_status (struct _status_info *sinfo);
202
203 /* ********************************************************************** */
204 /* parses the response from the status command */
205 struct _state_info {
206         gchar *name;
207         guint32 messages;
208         guint32 recent;
209         guint32 uidnext;
210         guint32 unseen;
211         guint64 uidvalidity;
212         guint64 highestmodseq;
213 };
214
215 /* use g_free to free the return value */
216 struct _state_info *imapx_parse_status_info (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error);
217
218 /* ********************************************************************** */
219
220 /* should this just return a FolderInfo?
221  * should this just return the name & flags & separator by reference? */
222 struct _list_info {
223         guint32 flags : 24;
224         gchar separator;
225         gchar *name;
226 };
227
228 struct _list_info *imapx_parse_list (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error);
229 gchar *imapx_list_get_path (struct _list_info *li);
230 void imapx_free_list (struct _list_info *linfo);
231
232 /* ********************************************************************** */
233 typedef struct _IMAPXJobQueueInfo {
234         guint queue_len;
235
236         /* list of folders for which jobs are in the queue */
237         GHashTable *folders;
238 } IMAPXJobQueueInfo;
239
240 void camel_imapx_destroy_job_queue_info (IMAPXJobQueueInfo *jinfo);
241
242 /* ********************************************************************** */
243
244 extern guchar imapx_specials[256];
245
246 #define IMAPX_TYPE_CHAR (1 << 0)
247 #define IMAPX_TYPE_TEXT_CHAR (1 << 1)
248 #define IMAPX_TYPE_QUOTED_CHAR (1 << 2)
249 #define IMAPX_TYPE_ATOM_CHAR (1 << 3)
250 #define IMAPX_TYPE_TOKEN_CHAR (1 << 4)
251 #define IMAPX_TYPE_NOTID_CHAR (1 << 5)
252
253 guchar imapx_is_mask (const gchar *p);
254
255 #define imapx_is_text_char(c) ((imapx_specials[((unsigned char)(c))&0xff] & IMAPX_TYPE_TEXT_CHAR) != 0)
256 #define imapx_is_quoted_char(c) ((imapx_specials[((unsigned char)(c))&0xff] & IMAPX_TYPE_QUOTED_CHAR) != 0)
257 #define imapx_is_atom_char(c) ((imapx_specials[((unsigned char)(c))&0xff] & IMAPX_TYPE_ATOM_CHAR) != 0)
258 #define imapx_is_token_char(c) ((imapx_specials[((unsigned char)(c))&0xff] & IMAPX_TYPE_TOKEN_CHAR) != 0)
259 #define imapx_is_notid_char(c) ((imapx_specials[((unsigned char)(c))&0xff] & IMAPX_TYPE_NOTID_CHAR) != 0)
260
261 #define imapx_is_atom(s) (imapx_is_mask(s) & IMAPX_TYPE_ATOM_CHAR)
262
263 extern gint camel_imapx_debug_flags;
264 #define CAMEL_IMAPX_DEBUG_command       (1 << 0)
265 #define CAMEL_IMAPX_DEBUG_debug         (1 << 1)
266 #define CAMEL_IMAPX_DEBUG_extra         (1 << 2)
267 #define CAMEL_IMAPX_DEBUG_io            (1 << 3)
268 #define CAMEL_IMAPX_DEBUG_token         (1 << 4)
269 #define CAMEL_IMAPX_DEBUG_parse         (1 << 5)
270 #define CAMEL_IMAPX_DEBUG_conman        (1 << 6)
271
272 /* Set this to zero to remove all debug output at build time */
273 #define CAMEL_IMAPX_DEBUG_ALL           ((1 << 7)-1)
274
275 #define camel_debug_flag(type) (camel_imapx_debug_flags & CAMEL_IMAPX_DEBUG_ALL & CAMEL_IMAPX_DEBUG_ ## type)
276 #define camel_imapx_debug(type, tagprefix, fmt, ...) do {               \
277                 if (camel_debug_flag (type))                            \
278                         printf ("[imapx:%c] " fmt, tagprefix , ##__VA_ARGS__); \
279         } while (0)
280
281 /* ********************************************************************** */
282
283 void imapx_utils_init (void);
284
285 /* chen adds from old imap provider - place it in right place */
286 gchar *imapx_path_to_physical (const gchar *prefix, const gchar *vpath);
287 gchar *imapx_concat (struct _CamelIMAPXStore *imapx_store, const gchar *prefix, const gchar *suffix);
288 gchar * imapx_get_temp_uid (void);
289
290 void camel_imapx_namespace_list_clear (struct _CamelIMAPXNamespaceList *nsl);
291 struct _CamelIMAPXNamespaceList * imapx_parse_namespace_list (struct _CamelIMAPXStream *stream, GCancellable *cancellable, GError **error);
292 struct _CamelIMAPXNamespaceList *camel_imapx_namespace_list_copy (const struct _CamelIMAPXNamespaceList *nsl);
293
294 #endif