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_UTILS_H
25 #define CAMEL_IMAPX_UTILS_H
27 #include <camel/camel-store.h>
29 struct _CamelIMAPXStream;
31 struct _CamelIMAPXNamespaceList;
32 struct _CamelIMAPXStore;
34 /* list of strings we know about that can be *quickly* tokenised */
35 typedef enum _camel_imapx_id_t {
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"
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);
100 /* this flag should be part of imapfoldersummary */
102 CAMEL_IMAPX_MESSAGE_RECENT = (1 << 21),
105 /* ********************************************************************** */
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);
115 /* ********************************************************************** */
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),
131 struct _capability_info {
133 GHashTable *auth_types;
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);
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);
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 */
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 */
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)
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);
187 /* ********************************************************************** */
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 */
198 guint32 permanentflags;
202 guint64 highestmodseq;
210 GPtrArray *copied_uids;
212 struct _capability_info *cinfo;
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);
222 /* ********************************************************************** */
223 /* parses the response from the status command */
231 guint64 highestmodseq;
234 /* use g_free to free the return value */
235 struct _state_info *imapx_parse_status_info (struct _CamelIMAPXStream *is, GCancellable *cancellable, GError **error);
237 /* ********************************************************************** */
239 /* should this just return a FolderInfo?
240 * should this just return the name & flags & separator by reference? */
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);
251 /* ********************************************************************** */
252 typedef struct _IMAPXJobQueueInfo {
255 /* list of folders for which jobs are in the queue */
259 void camel_imapx_destroy_job_queue_info (IMAPXJobQueueInfo *jinfo);
261 /* ********************************************************************** */
263 extern guchar imapx_specials[256];
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)
272 guchar imapx_is_mask (const gchar *p);
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)
280 #define imapx_is_atom(s) (imapx_is_mask(s) & IMAPX_TYPE_ATOM_CHAR)
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)
291 /* Set this to zero to remove all debug output at build time */
292 #define CAMEL_IMAPX_DEBUG_ALL ((1 << 7)-1)
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__); \
300 /* ********************************************************************** */
302 void imapx_utils_init (void);
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);
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);