1 /* ========================================================================
2 * Copyright 1988-2007 University of Washington
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
11 * ========================================================================
15 * Program: Interactive Mail Access Protocol 4rev1 (IMAP4R1) routines
17 * Author: Mark Crispin
18 * Networks and Distributed Computing
19 * Computing & Communications
20 * University of Washington
21 * Administration Building, AG-44
23 * Internet: MRC@CAC.Washington.EDU
25 * Date: 14 October 1988
26 * Last Edited: 5 September 2007
30 /* This include file is provided for applications which need to look under
31 * the covers at the IMAP driver and in particular want to do different
32 * operations depending upon the IMAP server's protocol level and
33 * capabilities. It is NOT included in the normal c-client.h application
34 * export, and most applications do NOT need the definitions in this file.
36 * As of October 15, 2003, it is believed that:
38 * Version RFC Status Known Implementations
39 * ------- --- ------ ---------------------
40 * IMAP1 none extinct experimental TOPS-20 server
41 * IMAP2 1064 extinct old TOPS-20, SUMEX servers
42 * IMAP2 1176 rare TOPS-20, old UW servers
43 * IMAP2bis expired I-D uncommon old UW, Cyrus servers
44 * IMAP3 1203 extinct none (never implemented)
45 * IMAP4 1730 rare old UW, Cyrus, Netscape servers
46 * IMAP4rev1 2060, 3501 ubiquitous UW, Cyrus, and many others
48 * Most client implementations will only interoperate with an IMAP4rev1
49 * server. c-client based client implementations can interoperate with IMAP2,
50 * IMAP2bis, IMAP4, and IMAP4rev1 servers, but only if they are very careful.
52 * The LEVELxxx() macros in this file enable the client to determine the
53 * server protocol level and capabilities. This file also contains a few
54 * backdoor calls into the IMAP driver.
57 /* Server protocol level and capabilities */
59 typedef struct imap_cap {
60 unsigned int rfc1176 : 1; /* server is RFC-1176 IMAP2 */
61 unsigned int imap2bis : 1; /* server is IMAP2bis */
62 unsigned int imap4 : 1; /* server is IMAP4 (RFC 1730) */
63 unsigned int imap4rev1 : 1; /* server is IMAP4rev1 */
64 unsigned int acl : 1; /* server has ACL (RFC 2086) */
65 unsigned int quota : 1; /* server has QUOTA (RFC 2087) */
66 unsigned int litplus : 1; /* server has LITERAL+ (RFC 2088) */
67 unsigned int idle : 1; /* server has IDLE (RFC 2177) */
68 unsigned int mbx_ref : 1; /* server has mailbox referrals (RFC 2193) */
69 unsigned int log_ref : 1; /* server has login referrals (RFC 2221) */
70 unsigned int authanon : 1; /* server has anonymous SASL (RFC 2245) */
71 unsigned int namespace :1; /* server has NAMESPACE (RFC 2342) */
72 unsigned int uidplus : 1; /* server has UIDPLUS (RFC 2359) */
73 unsigned int starttls : 1; /* server has STARTTLS (RFC 2595) */
74 /* server disallows LOGIN command (RFC 2595) */
75 unsigned int logindisabled : 1;
76 unsigned int id : 1; /* server has ID (RFC 2971) */
77 unsigned int children : 1; /* server has CHILDREN (RFC 3348) */
78 unsigned int multiappend : 1; /* server has multi-APPEND (RFC 3502) ;*/
79 unsigned int binary : 1; /* server has BINARY (RFC 3516) */
80 unsigned int unselect : 1; /* server has UNSELECT */
81 unsigned int sasl_ir : 1; /* server has SASL-IR initial response */
82 unsigned int sort : 1; /* server has SORT */
83 unsigned int scan : 1; /* server has SCAN */
84 unsigned int urlauth : 1; /* server has URLAUTH (RFC 4467) */
85 unsigned int catenate : 1; /* server has CATENATE (RFC 4469) */
86 unsigned int condstore : 1; /* server has CONDSTORE (RFC 4551) */
87 unsigned int esearch : 1; /* server has ESEARCH (RFC 4731) */
88 unsigned int within : 1; /* server has WITHIN (RFC 5032) */
89 unsigned int extlevel; /* extension data level supported by server */
90 /* supported authenticators */
91 unsigned int auth : MAXAUTHENTICATORS;
92 THREADER *threader; /* list of threaders */
93 #ifdef __FEATURE_XLIST_SUPPORT__
94 unsigned int xlist : 1;
95 #endif /* __FEATURE_XLIST_SUPPORT__ */
96 #ifdef __FEATURE_METADATA_SUPPORT__
97 unsigned int metadata : 1;
98 #endif /* __FEATURE_METADATA_SUPPORT__ */
101 /* IMAP4rev1 level or better */
103 #define LEVELIMAP4rev1(stream) imap_cap (stream)->imap4rev1
105 #define LEVELSTATUS LEVELIMAP4rev1
108 /* IMAP4 level or better (not including RFC 1730 design mistakes) */
110 #define LEVELIMAP4(stream) (imap_cap (stream)->imap4rev1 || \
111 imap_cap (stream)->imap4)
114 /* IMAP4 RFC-1730 level */
116 #define LEVEL1730(stream) imap_cap (stream)->imap4
119 /* IMAP2bis level or better */
121 #define LEVELIMAP2bis(stream) imap_cap (stream)->imap2bis
124 /* IMAP2 RFC-1176 level or better */
126 #define LEVEL1176(stream) imap_cap (stream)->rfc1176
129 /* IMAP2 RFC-1064 or better */
131 #define LEVEL1064(stream) 1
133 /* Has ACL extension */
135 #define LEVELACL(stream) imap_cap (stream)->acl
138 /* Has QUOTA extension */
140 #define LEVELQUOTA(stream) imap_cap (stream)->quota
143 /* Has LITERALPLUS extension */
145 #define LEVELLITERALPLUS(stream) imap_cap (stream)->litplus
148 /* Has IDLE extension */
150 #define LEVELIDLE(stream) imap_cap (stream)->idle
153 /* Has mailbox referrals */
155 #define LEVELMBX_REF(stream) imap_cap (stream)->mbx_ref
158 /* Has login referrals */
160 #define LEVELLOG_REF(stream) imap_cap (stream)->log_ref
163 /* Has AUTH=ANONYMOUS extension */
165 #define LEVELANONYMOUS(stream) imap_cap (stream)->authanon
168 /* Has NAMESPACE extension */
170 #define LEVELNAMESPACE(stream) imap_cap (stream)->namespace
173 /* Has UIDPLUS extension */
175 #define LEVELUIDPLUS(stream) imap_cap (stream)->uidplus
178 /* Has STARTTLS extension */
180 #define LEVELSTARTTLS(stream) imap_cap (stream)->starttls
183 /* Has LOGINDISABLED extension */
185 #define LEVELLOGINDISABLED(stream) imap_cap (stream)->logindisabled
187 /* Has ID extension */
189 #define LEVELID(stream) imap_cap (stream)->id
192 /* Has CHILDREN extension */
194 #define LEVELCHILDREN(stream) imap_cap (stream)->children
197 /* Has MULTIAPPEND extension */
199 #define LEVELMULTIAPPEND(stream) imap_cap (stream)->multiappend
202 /* Has BINARY extension */
204 #define LEVELBINARY(stream) imap_cap (stream)->binary
207 /* Has UNSELECT extension */
209 #define LEVELUNSELECT(stream) imap_cap (stream)->unselect
212 /* Has SASL initial response extension */
214 #define LEVELSASLIR(stream) imap_cap (stream)->sasl_ir
217 /* Has SORT extension */
219 #define LEVELSORT(stream) imap_cap (stream)->sort
222 /* Has at least one THREAD extension */
224 #define LEVELTHREAD(stream) ((imap_cap (stream)->threader) ? T : NIL)
227 /* Has SCAN extension */
229 #define LEVELSCAN(stream) imap_cap (stream)->scan
232 /* Has URLAUTH extension */
234 #define LEVELURLAUTH(stream) imap_cap (stream)->urlauth
237 /* Has CATENATE extension */
239 #define LEVELCATENATE(stream) imap_cap (stream)->catenate
242 /* Has CONDSTORE extension */
244 #define LEVELCONDSTORE(stream) imap_cap (stream)->condstore
247 /* Has ESEARCH extension */
249 #define LEVELESEARCH(stream) imap_cap (stream)->esearch
252 /* Has WITHIN extension */
254 #define LEVELWITHIN(stream) imap_cap (stream)->within
257 #ifdef __FEATURE_METADATA_SUPPORT__
258 /* Has METADATA extension */
260 #define LEVELMETADATA(stream) imap_cap (stream)->metadata
261 #endif /* __FEATURE_METADATA_SUPPORT__ */
264 /* Body structure extension levels */
266 /* These are in BODYSTRUCTURE order. Note that multipart bodies do not have
267 * body-fld-md5. This is alright, since all subsequent body structure
268 * extensions are in both singlepart and multipart bodies. If that ever
269 * changes, this will have to be split.
272 #define BODYEXTMD5 1 /* body-fld-md5 */
273 #define BODYEXTDSP 2 /* body-fld-dsp */
274 #define BODYEXTLANG 3 /* body-fld-lang */
275 #define BODYEXTLOC 4 /* body-fld-loc */
278 /* Function prototypes */
280 IMAPCAP *imap_cap (MAILSTREAM *stream);
281 char *imap_host (MAILSTREAM *stream);
282 long imap_cache (MAILSTREAM *stream,unsigned long msgno,char *seg,
283 STRINGLIST *stl,SIZEDTEXT *text);
288 long imap_setacl (MAILSTREAM *stream,char *mailbox,char *id,char *rights);
289 long imap_deleteacl (MAILSTREAM *stream,char *mailbox,char *id);
290 long imap_getacl (MAILSTREAM *stream,char *mailbox);
291 long imap_listrights (MAILSTREAM *stream,char *mailbox,char *id);
292 long imap_myrights (MAILSTREAM *stream,char *mailbox);
293 long imap_setquota (MAILSTREAM *stream,char *qroot,STRINGLIST *limits);
294 long imap_getquota (MAILSTREAM *stream,char *qroot);
295 long imap_getquotaroot (MAILSTREAM *stream,char *mailbox);
297 #ifdef __FEATURE_METADATA_SUPPORT__
298 /* RFC5464 - METADATA extension */
299 char *imap_getmetadata (MAILSTREAM *stream, char *mailbox, char *entry);
300 long imap_setmetadata (MAILSTREAM *stream, char *mailbox, char *entry, char *value);
301 #endif /* __FEATURE_METADATA_SUPPORT__ */