merge with latest
[external/uw-imap-toolkit.git] / imap-2007e / c-client / mail.h
1 /* ========================================================================
2  * Copyright 1988-2008 University of Washington
3  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * 
11  * ========================================================================
12  */
13
14 /*
15  * Program:     Mailbox Access routines
16  *
17  * Author:      Mark Crispin
18  *              UW Technology
19  *              University of Washington
20  *              Seattle, WA  98195
21  *              Internet: MRC@Washington.EDU
22  *
23  * Date:        22 November 1989
24  * Last Edited: 16 December 2008
25  */
26 \f
27 /* The Version */
28
29 #define CCLIENTVERSION "2007e"
30
31 /* Build parameters */
32
33 #define CACHEINCREMENT 250      /* cache growth increments */
34 #define MAILTMPLEN 1024         /* size of a temporary buffer */
35 #define SENDBUFLEN 16385        /* size of temporary sending buffer, also
36                                  * used for SMTP commands and NETMBX generation
37                                  * buffer so shouldn't be made smaller than
38                                  * MAILTMPLEN.  Note that there's a guard byte,
39                                  * so this is actually len+1. */
40 #define MAXAUTHENTICATORS 8     /* maximum number of SASL authenticators */
41                                 /* maximum number of messages */
42 #define MAXMESSAGES (unsigned long) 1000000
43 #define MAXLOGINTRIALS 3        /* maximum number of client login attempts */
44 #define MAXWILDCARDS 10         /* maximum wildcards allowed in LIST/LSUB */
45
46
47 /* These can't be changed without changing code */
48
49 #define NUSERFLAGS 30           /* maximum number of user flags */
50 #define MAXUSERFLAG 50          /* maximum length of a user flag */
51 #define BASEYEAR 1970           /* the year time began on Unix DON'T CHANGE */
52                                 /* default for unqualified addresses */
53 #define BADHOST ".MISSING-HOST-NAME."
54                                 /* default for syntax errors in addresses */
55 #define ERRHOST ".SYNTAX-ERROR."
56
57
58 /* Coddle certain compilers' 6-character symbol limitation */
59
60 #ifdef __COMPILER_KCC__
61 #include "shortsym.h"
62 #endif
63
64
65 /* Function status code */
66
67 #define NIL 0                   /* convenient name */
68 #define T 1                     /* opposite of NIL */
69 #define LONGT (long) 1          /* long T to pacify some compilers */
70 #define VOIDT (void *) ""       /* void T ditto */
71 \f
72 /* Global and Driver Parameters */
73
74         /* 0xx: driver and authenticator flags */
75 #define ENABLE_DRIVER (long) 1
76 #define DISABLE_DRIVER (long) 2
77 #define ENABLE_AUTHENTICATOR (long) 3
78 #define DISABLE_AUTHENTICATOR (long) 4
79 #define ENABLE_DEBUG (long) 5
80 #define DISABLE_DEBUG (long) 6
81 #define HIDE_AUTHENTICATOR (long) 7
82 #define UNHIDE_AUTHENTICATOR (long) 8
83         /* 1xx: c-client globals */
84 #define GET_DRIVERS (long) 101
85 #define SET_DRIVERS (long) 102
86 #define GET_GETS (long) 103
87 #define SET_GETS (long) 104
88 #define GET_CACHE (long) 105
89 #define SET_CACHE (long) 106
90 #define GET_SMTPVERBOSE (long) 107
91 #define SET_SMTPVERBOSE (long) 108
92 #define GET_RFC822OUTPUT (long) 109
93 #define SET_RFC822OUTPUT (long) 110
94 #define GET_READPROGRESS (long) 111
95 #define SET_READPROGRESS (long) 112
96 #define GET_THREADERS (long) 113
97 #define SET_THREADERS (long) 114
98 #define GET_NAMESPACE (long) 115
99 #define SET_NAMESPACE (long) 116
100 #define GET_MAILPROXYCOPY (long) 117
101 #define SET_MAILPROXYCOPY (long) 118
102 #define GET_SERVICENAME (long) 119
103 #define SET_SERVICENAME (long) 120
104 #define GET_DRIVER (long) 121
105 #define SET_DRIVER (long) 122
106 #define GET_EXPUNGEATPING (long) 123
107 #define SET_EXPUNGEATPING (long) 124
108 #define GET_PARSEPHRASE (long) 125
109 #define SET_PARSEPHRASE (long) 126
110 #define GET_SSLDRIVER (long) 127
111 #define SET_SSLDRIVER (long) 128
112 #define GET_TRYSSLFIRST (long) 129
113 #define SET_TRYSSLFIRST (long) 130
114 #define GET_BLOCKNOTIFY (long) 131
115 #define SET_BLOCKNOTIFY (long) 132
116 #define GET_SORTRESULTS (long) 133
117 #define SET_SORTRESULTS (long) 134
118 #define GET_THREADRESULTS (long) 135
119 #define SET_THREADRESULTS (long) 136
120 #define GET_PARSELINE (long) 137
121 #define SET_PARSELINE (long) 138
122 #define GET_NEWSRCQUERY (long) 139
123 #define SET_NEWSRCQUERY (long) 140
124 #define GET_FREEENVELOPESPAREP (long) 141
125 #define SET_FREEENVELOPESPAREP (long) 142
126 #define GET_FREEELTSPAREP (long) 143
127 #define SET_FREEELTSPAREP (long) 144
128 #define GET_SSLSTART (long) 145
129 #define SET_SSLSTART (long) 146
130 #define GET_DEBUGSENSITIVE (long) 147
131 #define SET_DEBUGSENSITIVE (long) 148
132 #define GET_TCPDEBUG (long) 149
133 #define SET_TCPDEBUG (long) 150
134 #define GET_FREESTREAMSPAREP (long) 151
135 #define SET_FREESTREAMSPAREP (long) 152
136 #define GET_FREEBODYSPAREP (long) 153
137 #define SET_FREEBODYSPAREP (long) 154
138 #define GET_COPYUID (long) 155
139 #define SET_COPYUID (long) 156
140 #define GET_APPENDUID (long) 157
141 #define SET_APPENDUID (long) 158
142 #define GET_RFC822OUTPUTFULL (long) 159
143 #define SET_RFC822OUTPUTFULL (long) 160
144 #define GET_BLOCKENVINIT (long) 161
145 #define SET_BLOCKENVINIT (long) 162
146 \f
147         /* 2xx: environment */
148 #define GET_USERNAME (long) 201
149 #define SET_USERNAME (long) 202
150 #define GET_HOMEDIR (long) 203
151 #define SET_HOMEDIR (long) 204
152 #define GET_LOCALHOST (long) 205
153 #define SET_LOCALHOST (long) 206
154 #define GET_SYSINBOX (long) 207
155 #define SET_SYSINBOX (long) 208
156 #define GET_USERPROMPT (long) 209
157 #define SET_USERPROMPT (long) 210
158 #define GET_DISABLEPLAINTEXT (long) 211
159 #define SET_DISABLEPLAINTEXT (long) 212
160 #define GET_CHROOTSERVER (long) 213
161 #define SET_CHROOTSERVER (long) 214
162 #define GET_ADVERTISETHEWORLD (long) 215
163 #define SET_ADVERTISETHEWORLD (long) 216
164 #define GET_DISABLEAUTOSHAREDNS (long) 217
165 #define SET_DISABLEAUTOSHAREDNS (long) 218
166 #define GET_MAILSUBDIR 219
167 #define SET_MAILSUBDIR 220
168 #define GET_DISABLE822TZTEXT 221
169 #define SET_DISABLE822TZTEXT 222
170 #define GET_LIMITEDADVERTISE (long) 223
171 #define SET_LIMITEDADVERTISE (long) 224
172 #define GET_LOGOUTHOOK (long) 225
173 #define SET_LOGOUTHOOK (long) 226
174 #define GET_LOGOUTDATA (long) 227
175 #define SET_LOGOUTDATA (long) 228
176 #define GET_EXTERNALAUTHID (long) 229
177 #define SET_EXTERNALAUTHID (long) 230
178 #define GET_SSLCAPATH (long) 231
179 #define SET_SSLCAPATH (long) 232
180 \f
181         /* 3xx: TCP/IP */
182 #define GET_OPENTIMEOUT (long) 300
183 #define SET_OPENTIMEOUT (long) 301
184 #define GET_READTIMEOUT (long) 302
185 #define SET_READTIMEOUT (long) 303
186 #define GET_WRITETIMEOUT (long) 304
187 #define SET_WRITETIMEOUT (long) 305
188 #define GET_CLOSETIMEOUT (long) 306
189 #define SET_CLOSETIMEOUT (long) 307
190 #define GET_TIMEOUT (long) 308
191 #define SET_TIMEOUT (long) 309
192 #define GET_RSHTIMEOUT (long) 310
193 #define SET_RSHTIMEOUT (long) 311
194 #define GET_ALLOWREVERSEDNS (long) 312
195 #define SET_ALLOWREVERSEDNS (long) 313
196 #define GET_RSHCOMMAND (long) 314
197 #define SET_RSHCOMMAND (long) 315
198 #define GET_RSHPATH (long) 316
199 #define SET_RSHPATH (long) 317
200 #define GET_SSHTIMEOUT (long) 318
201 #define SET_SSHTIMEOUT (long) 319
202 #define GET_SSHCOMMAND (long) 320
203 #define SET_SSHCOMMAND (long) 321
204 #define GET_SSHPATH (long) 322
205 #define SET_SSHPATH (long) 323
206 #define GET_SSLCERTIFICATEQUERY (long) 324
207 #define SET_SSLCERTIFICATEQUERY (long) 325
208 #define GET_SSLFAILURE (long) 326
209 #define SET_SSLFAILURE (long) 327
210 #define GET_NEWSRCCANONHOST (long) 328
211 #define SET_NEWSRCCANONHOST (long) 329
212 #define GET_KINIT (long) 330
213 #define SET_KINIT (long) 331
214 #define GET_SSLCLIENTCERT (long) 332
215 #define SET_SSLCLIENTCERT (long) 333
216 #define GET_SSLCLIENTKEY (long) 334
217 #define SET_SSLCLIENTKEY (long) 335
218 #define GET_KERBEROS_CP_SVR_NAME (long) 336
219 #define SET_KERBEROS_CP_SVR_NAME (long) 337
220 \f
221         /* 4xx: network drivers */
222 #define GET_MAXLOGINTRIALS (long) 400
223 #define SET_MAXLOGINTRIALS (long) 401
224 #define GET_LOOKAHEAD (long) 402
225 #define SET_LOOKAHEAD (long) 403
226 #define GET_IMAPPORT (long) 404
227 #define SET_IMAPPORT (long) 405
228 #define GET_PREFETCH (long) 406
229 #define SET_PREFETCH (long) 407
230 #define GET_CLOSEONERROR (long) 408
231 #define SET_CLOSEONERROR (long) 409
232 #define GET_POP3PORT (long) 410
233 #define SET_POP3PORT (long) 411
234 #define GET_UIDLOOKAHEAD (long) 412
235 #define SET_UIDLOOKAHEAD (long) 413
236 #define GET_NNTPPORT (long) 414
237 #define SET_NNTPPORT (long) 415
238 #define GET_IMAPENVELOPE (long) 416
239 #define SET_IMAPENVELOPE (long) 417
240 #define GET_IMAPREFERRAL (long) 418
241 #define SET_IMAPREFERRAL (long) 419
242 #define GET_SSLIMAPPORT (long) 420
243 #define SET_SSLIMAPPORT (long) 421
244 #define GET_SSLPOPPORT (long) 422
245 #define SET_SSLPOPPORT (long) 423
246 #define GET_SSLNNTPPORT (long) 424
247 #define SET_SSLNNTPPORT (long) 425
248 #define GET_SSLSMTPPORT (long) 426
249 #define SET_SSLSMTPPORT (long) 427
250 #define GET_SMTPPORT (long) 428
251 #define SET_SMTPPORT (long) 429
252 #define GET_IMAPEXTRAHEADERS (long) 430
253 #define SET_IMAPEXTRAHEADERS (long) 431
254 #define GET_ACL (long) 432
255 #define SET_ACL (long) 433
256 #define GET_LISTRIGHTS (long) 434
257 #define SET_LISTRIGHTS (long) 435
258 #define GET_MYRIGHTS (long) 436
259 #define SET_MYRIGHTS (long) 437
260 #define GET_QUOTA (long) 438
261 #define SET_QUOTA (long) 439
262 #define GET_QUOTAROOT (long) 440
263 #define SET_QUOTAROOT (long) 441
264 #define GET_IMAPTRYSSL (long) 442
265 #define SET_IMAPTRYSSL (long) 443
266 #define GET_FETCHLOOKAHEAD (long) 444
267 #define SET_FETCHLOOKAHEAD (long) 445
268 #define GET_NNTPRANGE (long) 446
269 #define SET_NNTPRANGE (long) 447
270 #define GET_NNTPHIDEPATH (long) 448
271 #define SET_NNTPHIDEPATH (long) 449
272 #define GET_SENDCOMMAND (long) 450
273 #define SET_SENDCOMMAND (long) 451
274 #define GET_IDLETIMEOUT (long) 452
275 #define SET_IDLETIMEOUT (long) 453
276 #define GET_FETCHLOOKAHEADLIMIT (long) 454
277 #define SET_FETCHLOOKAHEADLIMIT (long) 455
278 \f
279         /* 5xx: local file drivers */
280 #define GET_MBXPROTECTION (long) 500
281 #define SET_MBXPROTECTION (long) 501
282 #define GET_DIRPROTECTION (long) 502
283 #define SET_DIRPROTECTION (long) 503
284 #define GET_LOCKPROTECTION (long) 504
285 #define SET_LOCKPROTECTION (long) 505
286 #define GET_FROMWIDGET (long) 506
287 #define SET_FROMWIDGET (long) 507
288 #define GET_NEWSACTIVE (long) 508
289 #define SET_NEWSACTIVE (long) 509
290 #define GET_NEWSSPOOL (long) 510
291 #define SET_NEWSSPOOL (long) 511
292 #define GET_NEWSRC (long) 512
293 #define SET_NEWSRC (long) 513
294 #define GET_EXTENSION (long) 514
295 #define SET_EXTENSION (long) 515
296 #define GET_DISABLEFCNTLLOCK (long) 516
297 #define SET_DISABLEFCNTLLOCK (long) 517
298 #define GET_LOCKEACCESERROR (long) 518
299 #define SET_LOCKEACCESERROR (long) 519
300 #define GET_LISTMAXLEVEL (long) 520
301 #define SET_LISTMAXLEVEL (long) 521
302 #define GET_ANONYMOUSHOME (long) 522
303 #define SET_ANONYMOUSHOME (long) 523
304 #define GET_FTPHOME (long) 524
305 #define SET_FTPHOME (long) 525
306 #define GET_PUBLICHOME (long) 526
307 #define SET_PUBLICHOME (long) 527
308 #define GET_SHAREDHOME (long) 528
309 #define SET_SHAREDHOME (long) 529
310 #define GET_MHPROFILE (long) 530
311 #define SET_MHPROFILE (long) 531
312 #define GET_MHPATH (long) 532
313 #define SET_MHPATH (long) 533
314 #define GET_ONETIMEEXPUNGEATPING (long) 534
315 #define SET_ONETIMEEXPUNGEATPING (long) 535
316 #define GET_USERHASNOLIFE (long) 536
317 #define SET_USERHASNOLIFE (long) 537
318 #define GET_FTPPROTECTION (long) 538
319 #define SET_FTPPROTECTION (long) 539
320 #define GET_PUBLICPROTECTION (long) 540
321 #define SET_PUBLICPROTECTION (long) 541
322 #define GET_SHAREDPROTECTION (long) 542
323 #define SET_SHAREDPROTECTION (long) 543
324 #define GET_LOCKTIMEOUT (long) 544
325 #define SET_LOCKTIMEOUT (long) 545
326 #define GET_NOTIMEZONES (long) 546
327 #define SET_NOTIMEZONES (long) 547
328 #define GET_HIDEDOTFILES (long) 548
329 #define SET_HIDEDOTFILES (long) 549
330 #define GET_FTPDIRPROTECTION (long) 550
331 #define SET_FTPDIRPROTECTION (long) 551
332 #define GET_PUBLICDIRPROTECTION (long) 552
333 #define SET_PUBLICDIRPROTECTION (long) 553
334 #define GET_SHAREDDIRPROTECTION (long) 554
335 #define SET_SHAREDDIRPROTECTION (long) 555
336 #define GET_TRUSTDNS (long) 556
337 #define SET_TRUSTDNS (long) 557
338 #define GET_SASLUSESPTRNAME (long) 558
339 #define SET_SASLUSESPTRNAME (long) 559
340 #define GET_NETFSSTATBUG (long) 560
341 #define SET_NETFSSTATBUG (long) 561
342 #define GET_SNARFMAILBOXNAME (long) 562
343 #define SET_SNARFMAILBOXNAME (long) 563
344 #define GET_SNARFINTERVAL (long) 564
345 #define SET_SNARFINTERVAL (long) 565
346 #define GET_SNARFPRESERVE (long) 566
347 #define SET_SNARFPRESERVE (long) 567
348 #define GET_INBOXPATH (long) 568
349 #define SET_INBOXPATH (long) 569
350 #define GET_DIRFMTTEST (long) 570
351 #define SET_DIRFMTTEST (long) 571
352 #define GET_SCANCONTENTS (long) 572
353 #define SET_SCANCONTENTS (long) 573
354 #define GET_MHALLOWINBOX (long) 574
355 #define SET_MHALLOWINBOX (long) 575
356 \f
357 /* Driver flags */
358
359 #define DR_DISABLE (long) 0x1   /* driver is disabled */
360 #define DR_LOCAL (long) 0x2     /* local file driver */
361 #define DR_MAIL (long) 0x4      /* supports mail */
362 #define DR_NEWS (long) 0x8      /* supports news */
363 #define DR_READONLY (long) 0x10 /* driver only allows readonly access */
364 #define DR_NOFAST (long) 0x20   /* "fast" data is slow (whole msg fetch) */
365 #define DR_NAMESPACE (long) 0x40/* driver has a special namespace */
366 #define DR_LOWMEM (long) 0x80   /* low amounts of memory available */
367 #define DR_LOCKING (long) 0x100 /* driver does locking */
368 #define DR_CRLF (long) 0x200    /* driver internal form uses CRLF newlines */
369 #define DR_NOSTICKY (long) 0x400/* driver does not support sticky UIDs */
370 #define DR_RECYCLE (long) 0x800 /* driver does stream recycling */
371 #define DR_XPOINT (long) 0x1000 /* needs to be checkpointed */
372                                 /* driver has no real internal date */
373 #define DR_NOINTDATE (long) 0x2000
374                                 /* driver does not announce new mail */
375 #define DR_NONEWMAIL (long) 0x4000
376                                 /* driver does not announce new mail when RO */
377 #define DR_NONEWMAILRONLY (long) 0x8000
378                                 /* driver can be halfopen */
379 #define DR_HALFOPEN (long) 0x10000
380 #define DR_DIRFMT (long) 0x20000/* driver is a directory-format */
381 #define DR_MODSEQ (long) 0x40000/* driver supports modseqs */
382
383
384 /* Cache management function codes */
385
386 #define CH_INIT (long) 10       /* initialize cache */
387 #define CH_SIZE (long) 11       /* (re-)size the cache */
388 #define CH_MAKEELT (long) 30    /* return elt, make if needed */
389 #define CH_ELT (long) 31        /* return elt if exists */
390 #define CH_SORTCACHE (long) 35  /* return sortcache entry, make if needed */
391 #define CH_FREE (long) 40       /* free space used by elt */
392                                 /* free space used by sortcache */
393 #define CH_FREESORTCACHE (long) 43
394 #define CH_EXPUNGE (long) 45    /* delete elt pointer from list */
395
396
397 /* Mailbox open options
398  * For compatibility with the past, OP_DEBUG must always be 1.
399  */
400
401 #define OP_DEBUG (long) 0x1     /* debug protocol negotiations */
402 #define OP_READONLY (long) 0x2  /* read-only open */
403 #define OP_ANONYMOUS (long) 0x4 /* anonymous open of newsgroup */
404 #define OP_SHORTCACHE (long) 0x8/* short (elt-only) caching */
405 #define OP_SILENT (long) 0x10   /* don't pass up events (internal use) */
406 #define OP_PROTOTYPE (long) 0x20/* return driver prototype */
407 #define OP_HALFOPEN (long) 0x40 /* half-open (IMAP connect but no select) */
408 #define OP_EXPUNGE (long) 0x80  /* silently expunge recycle stream */
409 #define OP_SECURE (long) 0x100  /* don't do non-secure authentication */
410 #define OP_TRYSSL (long) 0x200  /* try SSL first */
411                                 /* use multiple newsrc files */
412 #define OP_MULNEWSRC (long) 0x400
413 #define OP_NOKOD (long) 0x800   /* suppress kiss-of-death */
414 #define OP_SNIFF (long) 0x1000  /* metadata only open */
415                                 /* reserved for application use */
416
417 #define OP_FORCE_LOWER_TLS_VERSION 0x2000 /* force lower TLS version */
418 #define OP_RESERVED (unsigned long) 0xff000000
419
420
421 /* Net open options */
422
423                                 /* no error messages */
424 #define NET_SILENT ((unsigned long) 0x80000000)
425                                 /* no validation of SSL certificates */
426 #define NET_NOVALIDATECERT ((unsigned long) 0x40000000)
427                                 /* no open timeout */
428 #define NET_NOOPENTIMEOUT ((unsigned long) 0x20000000)
429                                 /* TLS not SSL */
430 #define NET_TLSCLIENT ((unsigned long) 0x10000000)
431                                 /* try SSL mode */
432 #define NET_TRYSSL ((unsigned long) 0x8000000)
433                                 /* force lower TLS version */
434 #define NET_FORCE_LOWER_TLS_VERSION ((unsigned long) 0x4000000)
435 \f
436 /* Close options */
437
438 #define CL_EXPUNGE (long) 1     /* expunge silently */
439
440
441 /* Fetch options */
442
443 #define FT_UID (long) 0x1       /* argument is a UID */
444 #define FT_PEEK (long) 0x2      /* peek at data */
445 #define FT_NOT (long) 0x4       /* NOT flag for header lines fetch */
446 #define FT_INTERNAL (long) 0x8  /* text can be internal strings */
447                                 /* IMAP prefetch text when fetching header */
448 #define FT_PREFETCHTEXT (long) 0x20
449 #define FT_NOHDRS (long) 0x40   /* suppress fetching extra headers (note that
450                                    this breaks news handling) */
451 #define FT_NEEDENV (long) 0x80  /* (internal use) include envelope */
452 #define FT_NEEDBODY (long) 0x100/* (internal use) include body structure */
453                                 /* no fetch lookahead */
454 #define FT_NOLOOKAHEAD (long) 0x200
455                                 /* (internal use) lookahead in hdr searching */
456 #define FT_SEARCHLOOKAHEAD (long) 0x400
457                                 /* stringstruct return hack */
458 #define FT_RETURNSTRINGSTRUCT (long) 0x800
459 #define FT_SELECTEDHDRS (long) 0x1000 /* g.shyamakshi@samsung.com 
460                                                                               Search selected headers - From, To,
461                                                                               cc, bcc, subject, date, priority, read reciept, message-id, retrun path*/
462
463
464 /* Flagging options */
465
466 #define ST_UID (long) 0x1       /* argument is a UID sequence */
467 #define ST_SILENT (long) 0x2    /* don't return results */
468 #define ST_SET (long) 0x4       /* set vs. clear */
469
470
471 /* Expunge options */
472
473 #define EX_UID (long) 0x1       /* argument is a UID sequence */
474
475
476 /* Copy options */
477
478 #define CP_UID (long) 0x1       /* argument is a UID sequence */
479 #define CP_MOVE (long) 0x2      /* delete from source after copying */
480                                 /* set debug in any created stream */
481 #define CP_DEBUG (long) 0x20000000
482 \f
483 /* Search/sort/thread options */
484
485 #define SE_UID (long) 0x1       /* return UID */
486 #define SE_FREE (long) 0x2      /* free search program after finished */
487 #define SE_NOPREFETCH (long) 0x4/* no search prefetching */
488 #define SO_FREE (long) 0x8      /* free sort program after finished */
489 #define SE_NOSERVER (long) 0x10 /* don't do server-based search/sort/thread */
490 #define SE_RETAIN (long) 0x20   /* retain previous search results */
491 #define SO_OVERVIEW (long) 0x40 /* use overviews in searching (NNTP only) */
492 #define SE_NEEDBODY (long) 0x80 /* include body structure in prefetch */
493 #define SE_NOHDRS (long) 0x100  /* suppress prefetching extra headers (note
494                                    that this breaks news handling) */
495 #define SE_NOLOCAL (long) 0x200 /* no local retry (IMAP only) */
496
497 #define SO_NOSERVER SE_NOSERVER /* compatibility name */
498 #define SE_SILLYOK (long) 0x400 /* allow silly searches */
499
500
501 /* Status options */
502
503 #define SA_MESSAGES (long) 0x1  /* number of messages */
504 #define SA_RECENT (long) 0x2    /* number of recent messages */
505 #define SA_UNSEEN (long) 0x4    /* number of unseen messages */
506 #define SA_UIDNEXT (long) 0x8   /* next UID to be assigned */
507                                 /* UID validity value */
508 #define SA_UIDVALIDITY (long) 0x10
509                                 /* set OP_DEBUG on any created stream */
510 #define SA_DEBUG (long) 0x10000000
511                                 /* use multiple newsrcs */
512 #define SA_MULNEWSRC (long) 0x20000000
513
514 /* Mailgets flags */
515
516 #define MG_UID (long) 0x1       /* message number is a UID */
517 #define MG_COPY (long) 0x2      /* must return copy of argument */
518 \f
519 /* SASL authenticator categories */
520
521 #define AU_SECURE (long) 0x1    /* /secure allowed */
522 #define AU_AUTHUSER (long) 0x2  /* /authuser=xxx allowed */
523                                 /* authenticator hidden */
524 #define AU_HIDE (long) 0x10000000
525                                 /* authenticator disabled */
526 #define AU_DISABLE (long) 0x20000000
527
528
529 /* Garbage collection flags */
530
531 #define GC_ELT (long) 0x1       /* message cache elements */
532 #define GC_ENV (long) 0x2       /* envelopes and bodies */
533 #define GC_TEXTS (long) 0x4     /* cached texts */
534
535
536 /* mm_log()/mm_notify() condition codes */
537
538 #define WARN (long) 1           /* mm_log warning type */
539 #define ERROR (long) 2          /* mm_log error type */
540 #define PARSE (long) 3          /* mm_log parse error type */
541 #define BYE (long) 4            /* mm_notify stream dying */
542 #define TCPDEBUG (long) 5       /* mm_log TCP debug babble */
543
544
545 /* Bits from mail_parse_flags().  Don't change these, since the header format
546  * used by tenex, mtx, and mbx corresponds to these bits.
547  */
548
549 #define fSEEN 0x1
550 #define fDELETED 0x2
551 #define fFLAGGED 0x4
552 #define fANSWERED 0x8
553 #define fOLD 0x10
554 #define fDRAFT 0x20
555
556 #define fEXPUNGED 0x8000        /* internal flag */
557 \f
558 /* Bits for mm_list() and mm_lsub() */
559
560 /* Note that (LATT_NOINFERIORS LATT_HASCHILDREN LATT_HASNOCHILDREN) and
561  * (LATT_NOSELECT LATT_MARKED LATT_UNMARKED) each have eight possible states,
562  * but only four of these are valid.  The other four are silly states which
563  * while invalid can unfortunately be expressed in the IMAP protocol.
564  */
565
566                                 /* terminal node in hierarchy */
567 #define LATT_NOINFERIORS (long) 0x1
568                                 /* name can not be selected */
569 #define LATT_NOSELECT (long) 0x2
570                                 /* changed since last accessed */
571 #define LATT_MARKED (long) 0x4
572                                 /* accessed since last changed */
573 #define LATT_UNMARKED (long) 0x8
574                                 /* name has referral to remote mailbox */
575 #define LATT_REFERRAL (long) 0x10
576                                 /* has selectable inferiors */
577 #define LATT_HASCHILDREN (long) 0x20
578                                 /* has no selectable inferiors */
579 #define LATT_HASNOCHILDREN (long) 0x40
580
581 #ifdef __FEATURE_XLIST_SUPPORT__
582
583 #define LATT_XLIST_INBOX     (long) 0x0100  /* XLIST - Inbox */
584 #define LATT_XLIST_ALL       (long) 0x0200  /* XLIST - All or AllMail */
585 #define LATT_XLIST_DRAFTS    (long) 0x0400  /* XLIST - Drafts  */
586 #define LATT_XLIST_SENT      (long) 0x0800  /* XLIST - Sent */
587 #define LATT_XLIST_JUNK      (long) 0x1000  /* XLIST - Junk or Spam */
588 #define LATT_XLIST_FLAGGED   (long) 0x2000  /* XLIST - Flagged or Starred */
589 #define LATT_XLIST_TRASH     (long) 0x4000  /* XLIST - Trash */
590 #define LATT_XLIST_ARCHIVE   (long) 0x8000  /* XLIST - Archive */
591
592 #endif /* __FEATURE_XLIST_SUPPORT__ */
593
594 #define AUTH_METHOD_NONE     0
595 #define AUTH_METHOD_DEFAULT  1
596 #define AUTH_METHOD_XOAUTH2  2
597
598 /* Sort functions */
599
600 #define SORTDATE 0              /* date */
601 #define SORTARRIVAL 1           /* arrival date */
602 #define SORTFROM 2              /* from */
603 #define SORTSUBJECT 3           /* subject */
604 #define SORTTO 4                /* to */
605 #define SORTCC 5                /* cc */
606 #define SORTSIZE 6              /* size */
607
608
609 /* imapreferral_t codes */
610
611 #define REFAUTHFAILED (long) 0  /* authentication referral -- not logged in */
612 #define REFAUTH (long) 1        /* authentication referral -- logged in */
613 #define REFSELECT (long) 2      /* select referral */
614 #define REFCREATE (long) 3
615 #define REFDELETE (long) 4
616 #define REFRENAME (long) 5
617 #define REFSUBSCRIBE (long) 6
618 #define REFUNSUBSCRIBE (long) 7
619 #define REFSTATUS (long) 8
620 #define REFCOPY (long) 9
621 #define REFAPPEND (long) 10
622
623
624 /* sendcommand_t codes */
625
626                                 /* expunge response deferred */
627 #define SC_EXPUNGEDEFERRED (long) 1
628 \f
629 /* Block notification codes */
630
631 #define BLOCK_NONE 0            /* not blocked */
632 #define BLOCK_SENSITIVE 1       /* sensitive code, disallow alarms */
633 #define BLOCK_NONSENSITIVE 2    /* non-sensitive code, allow alarms */
634 #define BLOCK_DNSLOOKUP 10      /* blocked on DNS lookup */
635 #define BLOCK_TCPOPEN 11        /* blocked on TCP open */
636 #define BLOCK_TCPREAD 12        /* blocked on TCP read */
637 #define BLOCK_TCPWRITE 13       /* blocked on TCP write */
638 #define BLOCK_TCPCLOSE 14       /* blocked on TCP close */
639 #define BLOCK_FILELOCK 20       /* blocked on file locking */
640
641
642 /* In-memory sized-text */
643
644 #define SIZEDTEXT struct mail_sizedtext
645
646 SIZEDTEXT {
647   unsigned char *data;          /* text */
648   unsigned long size;           /* size of text in octets */
649 };
650
651
652 /* String list */
653
654 #define STRINGLIST struct string_list
655
656 STRINGLIST {
657   SIZEDTEXT text;               /* string text */
658   STRINGLIST *next;
659 };
660
661
662 /* Parse results from mail_valid_net_parse */
663
664 #define NETMAXHOST 256
665 #define NETMAXUSER 65
666 #define NETMAXMBX (MAILTMPLEN/4)
667 #define NETMAXSRV 21
668 typedef struct net_mailbox {
669   char host[NETMAXHOST];        /* host name (may be canonicalized) */
670   char orighost[NETMAXHOST];    /* host name before canonicalization */
671   char user[NETMAXUSER];        /* user name */
672   char authuser[NETMAXUSER];    /* authentication user name */
673   char mailbox[NETMAXMBX];      /* mailbox name */
674   char service[NETMAXSRV];      /* service name */
675   unsigned long port;           /* TCP port number */
676   unsigned int anoflag : 1;     /* anonymous */
677   unsigned int dbgflag : 1;     /* debug flag */
678   unsigned int secflag : 1;     /* secure flag */
679   unsigned int sslflag : 1;     /* SSL driver flag */
680   unsigned int trysslflag : 1;  /* try SSL driver first flag */
681   unsigned int novalidate : 1;  /* don't validate certificates */
682   unsigned int tlsflag : 1;     /* TLS flag */
683   unsigned int notlsflag : 1;   /* do not do TLS flag */
684   unsigned int readonlyflag : 1;/* want readonly */
685   unsigned int norsh : 1;       /* don't use rsh/ssh */
686   unsigned int loser : 1;       /* server is a loser */
687   unsigned int tlssslv23 : 1;   /* force SSLv23 client method over TLS */
688   unsigned int apop; /*APOP Authentication */
689   unsigned int force_tls_v1_0 : 1; /* force TLS v1.0 */
690   unsigned int auth_method; /* Authentication method */
691 } NETMBX;
692 \f
693 /* Item in an address list */
694
695 #define ADDRESS struct mail_address
696
697 ADDRESS {
698   char *personal;               /* personal name phrase */
699   char *adl;                    /* at-domain-list source route */
700   char *mailbox;                /* mailbox name */
701   char *host;                   /* domain name of mailbox's host */
702   char *error;                  /* error in address from SMTP module */
703   struct {
704     char *type;                 /* address type (default "rfc822") */
705     char *addr;                 /* address as xtext */
706   } orcpt;
707   ADDRESS *next;                /* pointer to next address in list */
708 };
709
710
711 /* Message envelope */
712
713 typedef struct mail_envelope {
714   unsigned int incomplete : 1;  /* envelope may be incomplete */
715   unsigned int imapenvonly : 1; /* envelope only has IMAP envelope */
716   char *remail;                 /* remail header if any */
717   ADDRESS *return_path;         /* error return address */
718   unsigned char *date;          /* message composition date string */
719   ADDRESS *from;                /* originator address list */
720   ADDRESS *sender;              /* sender address list */
721   ADDRESS *reply_to;            /* reply address list */
722   char *subject;                /* message subject string */
723   ADDRESS *to;                  /* primary recipient list */
724   ADDRESS *cc;                  /* secondary recipient list */
725   ADDRESS *bcc;                 /* blind secondary recipient list */
726   char *in_reply_to;            /* replied message ID */
727   char *message_id;             /* message ID */
728   char *newsgroups;             /* USENET newsgroups */
729   char *followup_to;            /* USENET reply newsgroups */
730   char *references;             /* USENET references */
731   void *sparep;                 /* spare pointer reserved for main program */
732 } ENVELOPE;
733 \f
734 /* Primary body types */
735 /* If you change any of these you must also change body_types in rfc822.c */
736
737 #define TYPETEXT 0              /* unformatted text */
738 #define TYPEMULTIPART 1         /* multiple part */
739 #define TYPEMESSAGE 2           /* encapsulated message */
740 #define TYPEAPPLICATION 3       /* application data */
741 #define TYPEAUDIO 4             /* audio */
742 #define TYPEIMAGE 5             /* static image */
743 #define TYPEVIDEO 6             /* video */
744 #define TYPEMODEL 7             /* model */
745 #define TYPEOTHER 8             /* unknown */
746 #define TYPEMAX 15              /* maximum type code */
747
748
749 /* Body encodings */
750 /* If you change any of these you must also change body_encodings in rfc822.c
751  */
752
753 #define ENC7BIT 0               /* 7 bit SMTP semantic data */
754 #define ENC8BIT 1               /* 8 bit SMTP semantic data */
755 #define ENCBINARY 2             /* 8 bit binary data */
756 #define ENCBASE64 3             /* base-64 encoded data */
757 #define ENCQUOTEDPRINTABLE 4    /* human-readable 8-as-7 bit data */
758 #define ENCOTHER 5              /* unknown */
759 #define ENCMAX 10               /* maximum encoding code */
760
761
762 /* Body contents */
763
764 #define BODY struct mail_bodystruct
765 #define MESSAGE struct mail_body_message
766 #define PARAMETER struct mail_body_parameter
767 #define PART struct mail_body_part
768 #define PARTLIST struct mail_body_part_list /* __FEATURE_DOWNLOAD_BODY_ATTACHMENT_OPTIMIZATION__ */
769 #define PARTTEXT struct mail_body_text
770 \f
771 /* Message body text */
772
773 PARTTEXT {
774   unsigned long offset;         /* offset from body origin */
775   SIZEDTEXT text;               /* text */
776 };
777
778
779 /* Message body structure */
780
781 BODY {
782   unsigned short type;          /* body primary type */
783   unsigned short encoding;      /* body transfer encoding */
784   char *subtype;                /* subtype string */
785   PARAMETER *parameter;         /* parameter list */
786   char *id;                     /* body identifier */
787   char *description;            /* body description */
788   struct {                      /* body disposition */
789     char *type;                 /* disposition type */
790     PARAMETER *parameter;       /* disposition parameters */
791   } disposition;
792   STRINGLIST *language;         /* body language */
793   char *location;               /* body content URI */
794   PARTTEXT mime;                /* MIME header */
795   PARTTEXT contents;            /* body part contents */
796   union {                       /* different ways of accessing contents */
797     PART *part;                 /* body part list */
798     MESSAGE *msg;               /* body encapsulated message */
799   } nested;
800   struct {
801     unsigned long lines;        /* size of text in lines */
802     unsigned long bytes;        /* size of text in octets */
803   } size;
804   char *md5;                    /* MD5 checksum */
805   void *sparep;                 /* spare pointer reserved for main program */
806 };
807
808
809 /* Parameter list */
810
811 PARAMETER {
812   char *attribute;              /* parameter attribute name */
813   char *value;                  /* parameter value */
814   PARAMETER *next;              /* next parameter in list */
815 };
816
817
818 /* Multipart content list */
819
820 PART {
821   BODY body;                    /* body information for this part */
822   PART *next;                   /* next body part */
823 };
824
825 /* __FEATURE_DOWNLOAD_BODY_ATTACHMENT_OPTIMIZATION__ */
826 PARTLIST{
827   BODY *body;                   /* body information for this part */
828   PART *next;                   /* next body part */
829 };
830
831
832 /* RFC-822 Message */
833
834 MESSAGE {
835   ENVELOPE *env;                /* message envelope */
836   BODY *body;                   /* message body */
837   PARTTEXT full;                /* full message */
838   STRINGLIST *lines;            /* lines used to filter header */
839   PARTTEXT header;              /* header text */
840   PARTTEXT text;                /* body text */
841 };
842 \f
843 /* Entry in the message cache array */
844
845 typedef struct message_cache {
846   unsigned long msgno;          /* message number */
847   unsigned int lockcount : 8;   /* non-zero if multiple references */
848   unsigned long rfc822_size;    /* # of bytes of message as raw RFC822 */
849   struct {                      /* c-client internal use only */
850     unsigned long uid;          /* message unique ID */
851     unsigned long mod;          /* modseq */
852     PARTTEXT special;           /* special text pointers */
853     MESSAGE msg;                /* internal message pointers */
854     union {                     /* driver internal use */
855       unsigned long data;
856       void *ptr;
857     } spare;
858     unsigned int sequence : 1;  /* saved sequence bit */
859     unsigned int dirty : 1;     /* driver internal use */
860     unsigned int filter : 1;    /* driver internal use */
861     unsigned int ghost : 1;     /* driver internal use */
862   } private;
863                         /* internal date */
864   unsigned int day : 5;         /* day of month (1-31) */
865   unsigned int month : 4;       /* month of year (1-12) */
866   unsigned int year : 7;        /* year since BASEYEAR (expires in 127 yrs) */
867   unsigned int hours: 5;        /* hours (0-23) */
868   unsigned int minutes: 6;      /* minutes (0-59) */
869   unsigned int seconds: 6;      /* seconds (0-59) */
870   unsigned int zoccident : 1;   /* non-zero if west of UTC */
871   unsigned int zhours : 4;      /* hours from UTC (0-12) */
872   unsigned int zminutes: 6;     /* minutes (0-59) */
873                         /* system flags */
874   unsigned int seen : 1;        /* system Seen flag */
875   unsigned int deleted : 1;     /* system Deleted flag */
876   unsigned int flagged : 1;     /* system Flagged flag */
877   unsigned int answered : 1;    /* system Answered flag */
878   unsigned int draft : 1;       /* system Draft flag */
879   unsigned int recent : 1;      /* system Recent flag */
880                         /* message status */
881   unsigned int valid : 1;       /* elt has valid flags */
882   unsigned int searched : 1;    /* message was searched */
883   unsigned int sequence : 1;    /* message is in sequence */
884                         /* reserved for use by main program */
885   unsigned int spare : 1;       /* first spare bit */
886   unsigned int spare2 : 1;      /* second spare bit */
887   unsigned int spare3 : 1;      /* third spare bit */
888   unsigned int spare4 : 1;      /* fourth spare bit */
889   unsigned int spare5 : 1;      /* fifth spare bit */
890   unsigned int spare6 : 1;      /* sixth spare bit */
891   unsigned int spare7 : 1;      /* seventh spare bit */
892   unsigned int spare8 : 1;      /* eighth spare bit */
893   void *sparep;                 /* spare pointer */
894   unsigned long user_flags;     /* user-assignable flags */
895 } MESSAGECACHE;
896 \f
897 /* String structure */
898
899 #define STRINGDRIVER struct string_driver
900
901 typedef struct mailstring {
902   void *data;                   /* driver-dependent data */
903   unsigned long data1;          /* driver-dependent data */
904   unsigned long size;           /* total length of string */
905   char *chunk;                  /* base address of chunk */
906   unsigned long chunksize;      /* size of chunk */
907   unsigned long offset;         /* offset of this chunk in base */
908   char *curpos;                 /* current position in chunk */
909   unsigned long cursize;        /* number of bytes remaining in chunk */
910   STRINGDRIVER *dtb;            /* driver that handles this type of string */
911 } STRING;
912
913
914 /* Dispatch table for string driver */
915
916 STRINGDRIVER {
917                                 /* initialize string driver */
918   void (*init) (STRING *s,void *data,unsigned long size);
919                                 /* get next character in string */
920   char (*next) (STRING *s);
921                                 /* set position in string */
922   void (*setpos) (STRING *s,unsigned long i);
923 };
924
925
926 /* Stringstruct access routines */
927
928 #define INIT(s,d,data,size) ((*((s)->dtb = &d)->init) (s,data,size))
929 #define SIZE(s) ((s)->size - GETPOS (s))
930 #define CHR(s) (*(s)->curpos)
931 #define SNX(s) (--(s)->cursize ? *(s)->curpos++ : (*(s)->dtb->next) (s))
932 #define GETPOS(s) ((s)->offset + ((s)->curpos - (s)->chunk))
933 #define SETPOS(s,i) (*(s)->dtb->setpos) (s,i)
934 \f
935 /* Search program */
936
937 #define SEARCHPGM struct search_program
938 #define SEARCHHEADER struct search_header
939 #define SEARCHSET struct search_set
940 #define SEARCHOR struct search_or
941 #define SEARCHPGMLIST struct search_pgm_list
942
943
944 SEARCHHEADER {                  /* header search */
945   SIZEDTEXT line;               /* header line */
946   SIZEDTEXT text;               /* text in header */
947   SEARCHHEADER *next;           /* next in list */
948 };
949
950
951 SEARCHSET {                     /* message set */
952   unsigned long first;          /* sequence number */
953   unsigned long last;           /* last value, if a range */
954   SEARCHSET *next;              /* next in list */
955 };
956
957
958 SEARCHOR {
959   SEARCHPGM *first;             /* first program */
960   SEARCHPGM *second;            /* second program */
961   SEARCHOR *next;               /* next in list */
962 };
963
964
965 SEARCHPGMLIST {
966   SEARCHPGM *pgm;               /* search program */
967   SEARCHPGMLIST *next;          /* next in list */
968 };
969 \f
970 SEARCHPGM {                     /* search program */
971   SEARCHSET *msgno;             /* message numbers */
972   SEARCHSET *uid;               /* unique identifiers */
973   SEARCHOR *or;                 /* or'ed in programs */
974   SEARCHPGMLIST *not;           /* and'ed not program */
975   SEARCHHEADER *header;         /* list of headers */
976   STRINGLIST *bcc;              /* bcc recipients */
977   STRINGLIST *body;             /* text in message body */
978   STRINGLIST *cc;               /* cc recipients */
979   STRINGLIST *from;             /* originator */
980   STRINGLIST *keyword;          /* keywords */
981   STRINGLIST *unkeyword;        /* unkeywords */
982   STRINGLIST *subject;          /* text in subject */
983   STRINGLIST *text;             /* text in headers and body */
984   STRINGLIST *to;               /* to recipients */
985   unsigned long larger;         /* larger than this size */
986   unsigned long smaller;        /* smaller than this size */
987   unsigned long older;          /* older than this interval */
988   unsigned long younger;        /* younger than this interval */
989   unsigned short sentbefore;    /* sent before this date */
990   unsigned short senton;        /* sent on this date */
991   unsigned short sentsince;     /* sent since this date */
992   unsigned short before;        /* before this date */
993   unsigned short on;            /* on this date */
994   unsigned short since;         /* since this date */
995   unsigned int answered : 1;    /* answered messages */
996   unsigned int unanswered : 1;  /* unanswered messages */
997   unsigned int deleted : 1;     /* deleted messages */
998   unsigned int undeleted : 1;   /* undeleted messages */
999   unsigned int draft : 1;       /* message draft */
1000   unsigned int undraft : 1;     /* message undraft */
1001   unsigned int flagged : 1;     /* flagged messages */
1002   unsigned int unflagged : 1;   /* unflagged messages */
1003   unsigned int recent : 1;      /* recent messages */
1004   unsigned int old : 1;         /* old messages */
1005   unsigned int seen : 1;        /* seen messages */
1006   unsigned int unseen : 1;      /* unseen messages */
1007   /* These must be simulated in IMAP */
1008   STRINGLIST *return_path;      /* error return address */
1009   STRINGLIST *sender;           /* sender address list */
1010   STRINGLIST *reply_to;         /* reply address list */
1011   STRINGLIST *in_reply_to;      /* replied message ID */
1012   STRINGLIST *message_id;       /* message ID */
1013   STRINGLIST *newsgroups;       /* USENET newsgroups */
1014   STRINGLIST *followup_to;      /* USENET reply newsgroups */
1015   STRINGLIST *references;       /* USENET references */
1016 };
1017
1018
1019 /* Mailbox status */
1020
1021 typedef struct mbx_status {
1022   long flags;                   /* validity flags */
1023   unsigned long messages;       /* number of messages */
1024   unsigned long recent;         /* number of recent messages */
1025   unsigned long unseen;         /* number of unseen messages */
1026   unsigned long uidnext;        /* next UID to be assigned */
1027   unsigned long uidvalidity;    /* UID validity value */
1028 } MAILSTATUS;
1029 \f
1030 /* Sort program */
1031
1032 typedef void (*postsort_t) (void *sc);
1033
1034 #define SORTPGM struct sort_program
1035
1036 SORTPGM {
1037   unsigned int reverse : 1;     /* sort function is to be reversed */
1038   unsigned int abort : 1;       /* abort sorting */
1039   short function;               /* sort function */
1040   unsigned long nmsgs;          /* number of messages being sorted */
1041   struct {
1042     unsigned long cached;       /* number of messages cached so far */
1043     unsigned long sorted;       /* number of messages sorted so far */
1044     unsigned long postsorted;   /* number of postsorted messages so far */
1045   } progress;
1046   postsort_t postsort;          /* post sorter */
1047   SORTPGM *next;                /* next function */
1048 };
1049
1050
1051 /* Sort cache */
1052
1053 #define SORTCACHE struct sort_cache
1054
1055 SORTCACHE {
1056   unsigned int sorted : 1;      /* message has been sorted */
1057   unsigned int postsorted : 1;  /* message has been postsorted */
1058   unsigned int refwd : 1;       /* subject is a re or fwd */
1059   unsigned int dirty : 1;       /* has data not written to backup */
1060   SORTPGM *pgm;                 /* sort program */
1061   unsigned long num;            /* message number (sequence or UID) */
1062   unsigned long date;           /* sent date */
1063   unsigned long arrival;        /* arrival date */
1064   unsigned long size;           /* message size */
1065   char *from;                   /* from string */
1066   char *to;                     /* to string */
1067   char *cc;                     /* cc string */
1068   char *subject;                /* extracted subject string */
1069   char *message_id;             /* message-id string */
1070   char *unique;                 /* unique string, normally message-id */
1071   STRINGLIST *references;       /* references string */
1072 };
1073 \f
1074 /* ACL list */
1075
1076 #define ACLLIST struct acl_list
1077
1078 ACLLIST {
1079   char *identifier;             /* authentication identifier */
1080   char *rights;                 /* access rights */
1081   ACLLIST *next;
1082 };
1083
1084 /* Quota resource list */
1085
1086 #define QUOTALIST struct quota_list
1087
1088 QUOTALIST {
1089   char *name;                   /* resource name */
1090   unsigned long usage;          /* resource usage */
1091   unsigned long limit;          /* resource limit */
1092   QUOTALIST *next;              /* next resource */
1093 };
1094 \f
1095 /* Mail Access I/O stream */
1096
1097
1098 /* Structure for mail driver dispatch */
1099
1100 #define DRIVER struct driver    
1101
1102
1103 /* Mail I/O stream */
1104         
1105 typedef struct mail_stream {
1106   DRIVER *dtb;                  /* dispatch table for this driver */
1107   void *local;                  /* pointer to driver local data */
1108   char *mailbox;                /* mailbox name (canonicalized) */
1109   char *original_mailbox;       /* mailbox name (non-canonicalized) */
1110   unsigned short use;           /* stream use count */
1111   unsigned short sequence;      /* stream sequence */
1112   unsigned int inbox : 1;       /* stream open on an INBOX */
1113   unsigned int lock : 1;        /* stream lock flag */
1114   unsigned int debug : 1;       /* stream debug flag */
1115   unsigned int silent : 1;      /* don't pass events to main program */
1116   unsigned int rdonly : 1;      /* stream read-only flag */
1117   unsigned int anonymous : 1;   /* stream anonymous access flag */
1118   unsigned int scache : 1;      /* stream short cache flag */
1119   unsigned int halfopen : 1;    /* stream half-open flag */
1120   unsigned int secure : 1;      /* stream secure flag */
1121   unsigned int tryssl : 1;      /* stream tryssl flag */
1122   unsigned int mulnewsrc : 1;   /* stream use multiple newsrc files */
1123   unsigned int perm_seen : 1;   /* permanent Seen flag */
1124   unsigned int perm_deleted : 1;/* permanent Deleted flag */
1125   unsigned int perm_flagged : 1;/* permanent Flagged flag */
1126   unsigned int perm_answered :1;/* permanent Answered flag */
1127   unsigned int perm_draft : 1;  /* permanent Draft flag */
1128   unsigned int kwd_create : 1;  /* can create new keywords */
1129   unsigned int uid_nosticky : 1;/* UIDs are not preserved */
1130   unsigned int unhealthy : 1;   /* unhealthy protocol negotiations */
1131   unsigned int nokod : 1;       /* suppress kiss-of-death */
1132   unsigned int sniff : 1;       /* metadata only */
1133   unsigned long perm_user_flags;/* mask of permanent user flags */
1134   unsigned long gensym;         /* generated tag */
1135   unsigned long nmsgs;          /* # of associated msgs */
1136   unsigned long recent;         /* # of recent msgs */
1137   unsigned long uid_validity;   /* UID validity sequence */
1138   unsigned long uid_last;       /* last assigned UID */
1139   char *user_flags[NUSERFLAGS]; /* pointers to user flags in bit order */
1140   unsigned long cachesize;      /* size of message cache */
1141   MESSAGECACHE **cache;         /* message cache array */
1142   SORTCACHE **sc;               /* sort cache array */
1143   unsigned long msgno;          /* message number of `current' message */
1144   ENVELOPE *env;                /* scratch buffer for envelope */
1145   BODY *body;                   /* scratch buffer for body */
1146   SIZEDTEXT text;               /* scratch buffer for text */
1147   struct {
1148     char *name;                 /* mailbox name to snarf from */
1149     unsigned long time;         /* last snarf time */
1150     long options;               /* snarf open options */
1151   } snarf;
1152   struct {                      /* internal use only */
1153     struct {                    /* search temporaries */
1154       STRINGLIST *string;       /* string(s) to search */
1155       long result;              /* search result */
1156       char *text;               /* cache of fetched text */
1157     } search;
1158     STRING string;              /* stringstruct return hack */
1159   } private;
1160                         /* reserved for use by main program */
1161   void *sparep;                 /* spare pointer */
1162   unsigned int spare : 1;       /* first spare bit */
1163   unsigned int spare2 : 1;      /* second spare bit */
1164   unsigned int spare3 : 1;      /* third spare bit */
1165   unsigned int spare4 : 1;      /* fourth spare bit */
1166   unsigned int spare5 : 1;      /* fifth spare bit */
1167   unsigned int spare6 : 1;      /* sixth spare bit */
1168   unsigned int spare7 : 1;      /* seventh spare bit */
1169   unsigned int spare8 : 1;      /* eighth spare bit */
1170 } MAILSTREAM;
1171 \f
1172 /* Mail I/O stream handle */
1173
1174 typedef struct mail_stream_handle {
1175   MAILSTREAM *stream;           /* pointer to mail stream */
1176   unsigned short sequence;      /* sequence of what we expect stream to be */
1177 } MAILHANDLE;
1178
1179
1180 /* Message overview */
1181
1182 typedef struct mail_overview {
1183   char *subject;                /* message subject string */
1184   ADDRESS *from;                /* originator address list */
1185   char *date;                   /* message composition date string */
1186   char *message_id;             /* message ID */
1187   char *references;             /* USENET references */
1188   struct {                      /* may be 0 or NUL if unknown/undefined */
1189     unsigned long octets;       /* message octets (probably LF-newline form) */
1190     unsigned long lines;        /* message lines */
1191     char *xref;                 /* cross references */
1192   } optional;
1193 } OVERVIEW;
1194 \f
1195 /* Network access I/O stream */
1196
1197
1198 /* Structure for network driver dispatch */
1199
1200 #define NETDRIVER struct net_driver
1201
1202
1203 /* Network transport I/O stream */
1204
1205 typedef struct net_stream {
1206   void *stream;                 /* driver's I/O stream */
1207   NETDRIVER *dtb;               /* network driver */
1208 } NETSTREAM;
1209
1210
1211 /* Network transport driver dispatch */
1212
1213 NETDRIVER {
1214   void *(*open) (char *host,char *service,unsigned long port);
1215   void *(*aopen) (NETMBX *mb,char *service,char *usrbuf);
1216   char *(*getline) (void *stream);
1217   long (*getbuffer) (void *stream,unsigned long size,char *buffer);
1218   long (*soutr) (void *stream,char *string);
1219   long (*sout) (void *stream,char *string,unsigned long size);
1220   void (*close) (void *stream);
1221   char *(*host) (void *stream);
1222   char *(*remotehost) (void *stream);
1223   unsigned long (*port) (void *stream);
1224   char *(*localhost) (void *stream);
1225 };
1226
1227
1228 /* Mailgets data identifier */
1229
1230 typedef struct getsdata {
1231   MAILSTREAM *stream;
1232   unsigned long msgno;
1233   char *what;
1234   STRINGLIST *stl;
1235   unsigned long first;
1236   unsigned long last;
1237   long flags;
1238 } GETS_DATA;
1239
1240
1241 #define INIT_GETS(md,s,m,w,f,l) \
1242   md.stream = s, md.msgno = m, md.what = w, md.first = f, md.last = l, \
1243   md.stl = NIL, md.flags = NIL;
1244 \f
1245 /* Mail delivery I/O stream */
1246
1247 typedef struct send_stream {
1248   NETSTREAM *netstream;         /* network I/O stream */
1249   char *host;                   /* SMTP service host */
1250   char *reply;                  /* last reply string */
1251   long replycode;               /* last reply code */
1252   unsigned int debug : 1;       /* stream debug flag */
1253   unsigned int sensitive : 1;   /* sensitive data in progress */
1254   unsigned int loser : 1;       /* server is a loser */
1255   unsigned int saslcancel : 1;  /* SASL cancelled by protocol */
1256   union {                       /* protocol specific */
1257     struct {                    /* SMTP specific */
1258       unsigned int ok : 1;      /* supports ESMTP */
1259       struct {                  /* service extensions */
1260         unsigned int send : 1;  /* supports SEND */
1261         unsigned int soml : 1;  /* supports SOML */
1262         unsigned int saml : 1;  /* supports SAML */
1263         unsigned int expn : 1;  /* supports EXPN */
1264         unsigned int help : 1;  /* supports HELP */
1265         unsigned int turn : 1;  /* supports TURN */
1266         unsigned int etrn : 1;  /* supports ETRN */
1267         unsigned int starttls:1;/* supports STARTTLS */
1268         unsigned int relay : 1; /* supports relaying */
1269         unsigned int pipe : 1;  /* supports pipelining */
1270         unsigned int ensc : 1;  /* supports enhanced status codes */
1271         unsigned int bmime : 1; /* supports BINARYMIME */
1272         unsigned int chunk : 1; /* supports CHUNKING */
1273       } service;
1274       struct {                  /* 8-bit MIME transport */
1275         unsigned int ok : 1;    /* supports 8-bit MIME */
1276         unsigned int want : 1;  /* want 8-bit MIME */
1277       } eightbit;
1278       struct {                  /* delivery status notification */
1279         unsigned int ok : 1;    /* supports DSN */
1280         unsigned int want : 1;  /* want DSN */
1281         struct {                /* notification options */
1282                                 /* notify on failure */
1283           unsigned int failure : 1;
1284                                 /* notify on delay */
1285           unsigned int delay : 1;
1286                                 /* notify on success */
1287           unsigned int success : 1;
1288         } notify;
1289         unsigned int full : 1;  /* return full headers */
1290         char *envid;            /* envelope identifier as xtext */
1291       } dsn;
1292       struct {                  /* size declaration */
1293         unsigned int ok : 1;    /* supports SIZE */
1294         unsigned long limit;    /* maximum size supported */
1295       } size;
1296       struct {                  /* deliverby declaration */
1297         unsigned int ok : 1;    /* supports DELIVERBY */
1298         unsigned long minby;    /* minimum by-time */
1299       } deliverby;
1300       struct {                  /* authenticated turn */
1301         unsigned int ok : 1;    /* supports ATRN */
1302         char *domains;          /* domains */
1303       } atrn;
1304                                 /* supported SASL authenticators */
1305       unsigned int auth : MAXAUTHENTICATORS;
1306     } esmtp;
1307     struct {                    /* NNTP specific */
1308       unsigned int post : 1;    /* supports POST */
1309       struct {                  /* NNTP extensions */
1310         unsigned int ok : 1;    /* supports extensions */
1311                                 /* supports LISTGROUP */
1312         unsigned int listgroup : 1;
1313         unsigned int over : 1;  /* supports OVER */
1314         unsigned int hdr : 1;   /* supports HDR */
1315         unsigned int pat : 1;   /* supports PAT */
1316                                 /* supports STARTTLS */
1317         unsigned int starttls : 1;
1318                                 /* server has MULTIDOMAIN */
1319         unsigned int multidomain : 1;
1320                                 /* supports AUTHINFO USER */
1321         unsigned int authuser : 1;
1322                                 /* supported authenticators */
1323         unsigned int sasl : MAXAUTHENTICATORS;
1324       } ext;
1325     } nntp;
1326   } protocol;
1327 } SENDSTREAM;
1328 \f
1329 /* Jacket into external interfaces */
1330
1331 typedef long (*readfn_t) (void *stream,unsigned long size,char *buffer);
1332 typedef char *(*mailgets_t) (readfn_t f,void *stream,unsigned long size,
1333                              GETS_DATA *md);
1334 typedef char *(*readprogress_t) (GETS_DATA *md,unsigned long octets);
1335 typedef void *(*mailcache_t) (MAILSTREAM *stream,unsigned long msgno,long op);
1336 typedef long (*mailproxycopy_t) (MAILSTREAM *stream,char *sequence,
1337                                  char *mailbox,long options);
1338 typedef long (*tcptimeout_t) (long overall,long last);
1339 typedef void *(*authchallenge_t) (void *stream,unsigned long *len);
1340 typedef long (*authrespond_t) (void *stream,char *s,unsigned long size);
1341 typedef long (*authcheck_t) (void);
1342 typedef long (*authclient_t) (authchallenge_t challenger,
1343                               authrespond_t responder,char *service,NETMBX *mb,
1344                               void *s,unsigned long *trial,char *user);
1345 typedef char *(*authresponse_t) (void *challenge,unsigned long clen,
1346                                  unsigned long *rlen);
1347 typedef char *(*authserver_t) (authresponse_t responder,int argc,char *argv[]);
1348 typedef void (*smtpverbose_t) (char *buffer);
1349 typedef void (*imapenvelope_t) (MAILSTREAM *stream,unsigned long msgno,
1350                                 ENVELOPE *env);
1351 typedef char *(*imapreferral_t) (MAILSTREAM *stream,char *url,long code);
1352 typedef void (*overview_t) (MAILSTREAM *stream,unsigned long uid,OVERVIEW *ov,
1353                             unsigned long msgno);
1354 typedef unsigned long *(*sorter_t) (MAILSTREAM *stream,char *charset,
1355                                     SEARCHPGM *spg,SORTPGM *pgm,long flags);
1356 typedef void (*parseline_t) (ENVELOPE *env,char *hdr,char *data,char *host);
1357 typedef ADDRESS *(*parsephrase_t) (char *phrase,char *end,char *host);
1358 typedef void *(*blocknotify_t) (int reason,void *data);
1359 typedef long (*kinit_t) (char *host,char *reason);
1360 typedef void (*sendcommand_t) (MAILSTREAM *stream,char *cmd,long flags);
1361 typedef char *(*newsrcquery_t) (MAILSTREAM *stream,char *mulname,char *name);
1362 typedef void (*getacl_t) (MAILSTREAM *stream,char *mailbox,ACLLIST *acl);
1363 typedef void (*listrights_t) (MAILSTREAM *stream,char *mailbox,char *id,
1364                               char *alwaysrights,STRINGLIST *possiblerights);
1365 typedef void (*myrights_t) (MAILSTREAM *stream,char *mailbox,char *rights);
1366 typedef void (*quota_t) (MAILSTREAM *stream,char *qroot,QUOTALIST *qlist);
1367 typedef void (*quotaroot_t) (MAILSTREAM *stream,char *mbx,STRINGLIST *qroot);
1368 typedef void (*sortresults_t) (MAILSTREAM *stream,unsigned long *list,
1369                                unsigned long size);
1370 typedef char *(*userprompt_t) (void);
1371 typedef long (*append_t) (MAILSTREAM *stream,void *data,char **flags,
1372                           char **date,STRING **message);
1373 typedef void (*copyuid_t) (MAILSTREAM *stream,char *mailbox,
1374                            unsigned long uidvalidity,SEARCHSET *sourceset,
1375                            SEARCHSET *destset);
1376 typedef void (*appenduid_t) (char *mailbox,unsigned long uidvalidity,
1377                              SEARCHSET *set);
1378 typedef long (*dirfmttest_t) (char *name);
1379 typedef long (*scancontents_t) (char *name,char *contents,unsigned long csiz,
1380                                 unsigned long fsiz);
1381
1382 typedef void (*freeeltsparep_t) (void **sparep);
1383 typedef void (*freeenvelopesparep_t) (void **sparep);
1384 typedef void (*freebodysparep_t) (void **sparep);
1385 typedef void (*freestreamsparep_t) (void **sparep);
1386 typedef void *(*sslstart_t) (void *stream,char *host,unsigned long flags);
1387 typedef long (*sslcertificatequery_t) (char *reason,char *host,char *cert);
1388 typedef void (*sslfailure_t) (char *host,char *reason,unsigned long flags);
1389 typedef void (*logouthook_t) (void *data);
1390 typedef char *(*sslclientcert_t) (void);
1391 typedef char *(*sslclientkey_t) (void);
1392 \f
1393 /* Globals */
1394
1395 extern char *body_types[];      /* defined body type strings */
1396 extern char *body_encodings[];  /* defined body encoding strings */
1397 extern const char *days[];      /* day name strings */
1398 extern const char *months[];    /* month name strings */
1399 \f
1400 /* Threading */
1401
1402 /* Thread node */
1403
1404 #define THREADNODE struct thread_node
1405
1406 THREADNODE {
1407   unsigned long num;            /* message number */
1408   SORTCACHE *sc;                /* (internal use) sortcache entry */
1409   THREADNODE *branch;           /* branch at this point in tree */
1410   THREADNODE *next;             /* next node */
1411 };
1412
1413 typedef void (*threadresults_t) (MAILSTREAM *stream,THREADNODE *tree);
1414
1415
1416 /* Thread dispatch */
1417
1418 #define THREADER struct threader_list
1419
1420 THREADER {
1421   char *name;                   /* name of threader */
1422   THREADNODE *(*dispatch) (MAILSTREAM *stream,char *charset,SEARCHPGM *spg,
1423                            long flags,sorter_t sorter);
1424   THREADER *next;
1425 };
1426
1427
1428 /* Container for references threading */
1429
1430 typedef void ** container_t;
1431 \f
1432 /* Namespaces */
1433
1434 #define NAMESPACE struct mail_namespace
1435
1436 NAMESPACE {
1437   char *name;                   /* name of this namespace */
1438   int delimiter;                /* hierarchy delimiter */
1439   PARAMETER *param;             /* namespace parameters */
1440   NAMESPACE *next;              /* next namespace */
1441 };
1442
1443
1444 /* Authentication */
1445
1446 #define AUTHENTICATOR struct mail_authenticator
1447
1448 AUTHENTICATOR {
1449   long flags;                   /* authenticator flags */
1450   char *name;                   /* name of this authenticator */
1451   authcheck_t valid;            /* authenticator valid on this system */
1452   authclient_t client;          /* client function that supports it */
1453   authserver_t server;          /* server function that supports it */
1454   AUTHENTICATOR *next;          /* next authenticator */
1455 };
1456 \f
1457 /* Mail driver dispatch */
1458
1459 DRIVER {
1460   char *name;                   /* driver name */
1461   unsigned long flags;          /* driver flags */
1462   DRIVER *next;                 /* next driver */
1463                                 /* mailbox is valid for us */
1464   DRIVER *(*valid) (char *mailbox);
1465                                 /* manipulate driver parameters */
1466   void *(*parameters) (long function,void *value);
1467                                 /* scan mailboxes */
1468   void (*scan) (MAILSTREAM *stream,char *ref,char *pat,char *contents);
1469                                 /* list mailboxes */
1470   void (*list) (MAILSTREAM *stream,char *ref,char *pat);
1471                                 /* list subscribed mailboxes */
1472   void (*lsub) (MAILSTREAM *stream,char *ref,char *pat);
1473                                 /* subscribe to mailbox */
1474   long (*subscribe) (MAILSTREAM *stream,char *mailbox);
1475                                 /* unsubscribe from mailbox */
1476   long (*unsubscribe) (MAILSTREAM *stream,char *mailbox);
1477                                 /* create mailbox */
1478   long (*create) (MAILSTREAM *stream,char *mailbox);
1479                                 /* delete mailbox */
1480   long (*mbxdel) (MAILSTREAM *stream,char *mailbox);
1481                                 /* rename mailbox */
1482   long (*mbxren) (MAILSTREAM *stream,char *old,char *newname);
1483                                 /* status of mailbox */
1484   long (*status) (MAILSTREAM *stream,char *mbx,long flags);
1485 \f
1486                                 /* open mailbox */
1487   MAILSTREAM *(*open) (MAILSTREAM *stream);
1488                                 /* close mailbox */
1489   void (*close) (MAILSTREAM *stream,long options);
1490                                 /* fetch message "fast" attributes */
1491   void (*fast) (MAILSTREAM *stream,char *sequence,long flags);
1492                                 /* fetch message flags */
1493   void (*msgflags) (MAILSTREAM *stream,char *sequence,long flags);
1494                                 /* fetch message overview */
1495   long (*overview) (MAILSTREAM *stream,overview_t ofn);
1496                                 /* fetch message envelopes */
1497   ENVELOPE *(*structure) (MAILSTREAM *stream,unsigned long msgno,BODY **body,
1498                           long flags);
1499                                 /* return RFC-822 header */
1500   char *(*header) (MAILSTREAM *stream,unsigned long msgno,
1501                    unsigned long *length,long flags);
1502                                 /* return RFC-822 text */
1503   long (*text) (MAILSTREAM *stream,unsigned long msgno,STRING *bs,long flags);
1504                                 /* load cache */
1505   long (*msgdata) (MAILSTREAM *stream,unsigned long msgno,char *section,
1506                    unsigned long first,unsigned long last,STRINGLIST *lines,
1507                    long flags);
1508                                 /* return UID for message */
1509   unsigned long (*uid) (MAILSTREAM *stream,unsigned long msgno);
1510                                 /* return message number from UID */
1511   unsigned long (*msgno) (MAILSTREAM *stream,unsigned long uid);
1512                                 /* modify flags */
1513   void (*flag) (MAILSTREAM *stream,char *sequence,char *flag,long flags);
1514                                 /* per-message modify flags */
1515   void (*flagmsg) (MAILSTREAM *stream,MESSAGECACHE *elt);
1516                                 /* search for message based on criteria */
1517   long (*search) (MAILSTREAM *stream,char *charset,SEARCHPGM *pgm,long flags);
1518                                 /* sort messages */
1519   unsigned long *(*sort) (MAILSTREAM *stream,char *charset,SEARCHPGM *spg,
1520                           SORTPGM *pgm,long flags);
1521                                 /* thread messages */
1522   THREADNODE *(*thread) (MAILSTREAM *stream,char *type,char *charset,
1523                          SEARCHPGM *spg,long flag);
1524                                 /* ping mailbox to see if still alive */
1525   long (*ping) (MAILSTREAM *stream);
1526                                 /* check for new messages */
1527   void (*check) (MAILSTREAM *stream);
1528                                 /* expunge deleted messages */
1529   long (*expunge) (MAILSTREAM *stream,char *sequence,long options);
1530                                 /* copy messages to another mailbox */
1531   long (*copy) (MAILSTREAM *stream,char *sequence,char *mailbox,long options);
1532                                 /* append string message to mailbox */
1533   long (*append) (MAILSTREAM *stream,char *mailbox,append_t af,void *data);
1534                                 /* garbage collect stream */
1535   void (*gc) (MAILSTREAM *stream,long gcflags);
1536 };
1537
1538
1539 #include "linkage.h"
1540 \f
1541 /* Compatibility support names for old interfaces */
1542
1543 #define GET_TRYALTFIRST GET_TRYSSLFIRST
1544 #define SET_TRYALTFIRST SET_TRYSSLFIRST
1545 #define GET_IMAPTRYALT GET_IMAPTRYSSL
1546 #define SET_IMAPTRYALT SET_IMAPTRYSSL
1547 #define OP_TRYALT OP_TRYSSL
1548 #define altflag sslflag
1549
1550 #define mail_close(stream) \
1551   mail_close_full (stream,NIL)
1552 #define mail_fetchfast(stream,sequence) \
1553   mail_fetch_fast (stream,sequence,NIL)
1554 #define mail_fetchfast_full mail_fetch_fast
1555 #define mail_fetchflags(stream,sequence) \
1556   mail_fetch_flags (stream,sequence,NIL)
1557 #define mail_fetchflags_full mail_fetch_flags
1558 #ifdef __FEATURE_HEADER_OPTIMIZATION__
1559 #define mail_fetchenvelope(stream,msgno) \
1560   mail_fetch_structure (stream,msgno,NIL,NIL,0)
1561 #else
1562 #define mail_fetchenvelope(stream,msgno) \
1563   mail_fetch_structure (stream,msgno,NIL,NIL)
1564 #endif
1565 #ifdef __FEATURE_HEADER_OPTIMIZATION__
1566 #define mail_fetchstructure(stream,msgno,body) \
1567   mail_fetch_structure (stream,msgno,body,NIL,0)
1568 #else
1569 #define mail_fetchstructure(stream,msgno,body) \
1570   mail_fetch_structure (stream,msgno,body,NIL)
1571 #endif
1572 #define mail_fetchstructure_full mail_fetch_structure
1573 #define mail_fetchheader(stream,msgno) \
1574   mail_fetch_header (stream,msgno,NIL,NIL,NIL,FT_PEEK)
1575 #define mail_fetchheader_full(stream,msgno,lines,len,flags) \
1576   mail_fetch_header (stream,msgno,NIL,lines,len,FT_PEEK | (flags))
1577 #define mail_fetchtext(stream,msgno) \
1578   mail_fetch_text (stream,msgno,NIL,NIL,NIL)
1579 #define mail_fetchtext_full(stream,msgno,length,flags) \
1580   mail_fetch_text (stream,msgno,NIL,length,flags)
1581 #define mail_fetchbody(stream,msgno,section,length) \
1582   mail_fetch_body (stream,msgno,section,length,NIL)
1583 #define mail_fetchbody_full mail_fetch_body
1584 #define mail_setflag(stream,sequence,flag) \
1585   mail_flag (stream,sequence,flag,ST_SET)
1586 #define mail_setflag_full(stream,sequence,flag,flags) \
1587   mail_flag (stream,sequence,flag,ST_SET | (flags))
1588 #define mail_clearflag(stream,sequence,flag) \
1589   mail_flag (stream,sequence,flag,NIL)
1590 #define mail_clearflag_full mail_flag
1591 #define mail_search(stream,criteria) \
1592   mail_search_full (stream,NIL,mail_criteria (criteria),SE_FREE);
1593 #define mail_expunge(stream) \
1594   mail_expunge_full (stream,NIL,NIL)
1595 #define mail_copy(stream,sequence,mailbox) \
1596   mail_copy_full (stream,sequence,mailbox,NIL)
1597 #define mail_move(stream,sequence,mailbox) \
1598   mail_copy_full (stream,sequence,mailbox,CP_MOVE)
1599 #define mail_append(stream,mailbox,message) \
1600   mail_append_full (stream,mailbox,NIL,NIL,message)
1601 \f
1602 /* Interfaces for SVR4 locking brain-damage workaround */
1603
1604 /* Driver dispatching */
1605
1606 #define SAFE_DELETE(dtb,stream,mailbox) (*dtb->mbxdel) (stream,mailbox)
1607 #define SAFE_RENAME(dtb,stream,old,newname) (*dtb->mbxren) (stream,old,newname)
1608 #define SAFE_STATUS(dtb,stream,mbx,flags) (*dtb->status) (stream,mbx,flags)
1609 #define SAFE_COPY(dtb,stream,sequence,mailbox,options) \
1610   (*dtb->copy) (stream,sequence,mailbox,options)
1611 #define SAFE_APPEND(dtb,stream,mailbox,af,data) \
1612   (*dtb->append) (stream,mailbox,af,data)
1613 #define SAFE_SCAN_CONTENTS(dtb,name,contents,csiz,fsiz) \
1614   scan_contents (dtb,name,contents,csiz,fsiz)
1615
1616
1617 /* Driver callbacks */
1618
1619 #define MM_EXISTS mm_exists
1620 #define MM_EXPUNGED mm_expunged
1621 #define MM_FLAGS mm_flags
1622 #define MM_NOTIFY mm_notify
1623 #define MM_STATUS mm_status
1624 #define MM_LOG mm_log
1625 #define MM_CRITICAL mm_critical
1626 #define MM_NOCRITICAL mm_nocritical
1627 #define MM_DISKERROR mm_diskerror
1628 #define MM_FATAL mm_fatal
1629 #define MM_APPEND(af) (*af)
1630 \f
1631 /* Function prototypes */
1632
1633 void mm_searched (MAILSTREAM *stream,unsigned long number);
1634 void mm_exists (MAILSTREAM *stream,unsigned long number);
1635 void mm_expunged (MAILSTREAM *stream,unsigned long number);
1636 void mm_flags (MAILSTREAM *stream,unsigned long number);
1637 void mm_notify (MAILSTREAM *stream,char *string,long errflg);
1638 void mm_list (MAILSTREAM *stream,int delimiter,char *name,long attributes);
1639 void mm_lsub (MAILSTREAM *stream,int delimiter,char *name,long attributes);
1640 void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status);
1641 void mm_log (char *string,long errflg);
1642 void mm_dlog (char *string);
1643 void mm_login (NETMBX *mb,char *user,char *pwd,long trial);
1644 void mm_critical (MAILSTREAM *stream);
1645 void mm_nocritical (MAILSTREAM *stream);
1646 long mm_diskerror (MAILSTREAM *stream,long errcode,long serious);
1647 void mm_fatal (char *string);
1648 void *mm_cache (MAILSTREAM *stream,unsigned long msgno,long op);
1649 #ifdef __FEATURE_IMAP_ID_SUPPORT__
1650 void mm_imap_id (char **id_string);
1651 #endif /* __FEATURE_IMAP_ID_SUPPORT__ */
1652
1653 extern STRINGDRIVER mail_string;
1654 void mail_versioncheck (char *version);
1655 void mail_link (DRIVER *driver);
1656 void *mail_parameters (MAILSTREAM *stream,long function,void *value);
1657 DRIVER *mail_valid (MAILSTREAM *stream,char *mailbox,char *purpose);
1658 DRIVER *mail_valid_net (char *name,DRIVER *drv,char *host,char *mailbox);
1659 long mail_valid_net_parse (char *name,NETMBX *mb);
1660 long mail_valid_net_parse_work (char *name,NETMBX *mb,char *service);
1661 void mail_scan (MAILSTREAM *stream,char *ref,char *pat,char *contents);
1662 void mail_list (MAILSTREAM *stream,char *ref,char *pat);
1663 void mail_lsub (MAILSTREAM *stream,char *ref,char *pat);
1664 long mail_subscribe (MAILSTREAM *stream,char *mailbox);
1665 long mail_unsubscribe (MAILSTREAM *stream,char *mailbox);
1666 long mail_create (MAILSTREAM *stream,char *mailbox);
1667 long mail_delete (MAILSTREAM *stream,char *mailbox);
1668 long mail_rename (MAILSTREAM *stream,char *old,char *newname);
1669 char *mail_utf7_valid (char *mailbox);
1670 long mail_status (MAILSTREAM *stream,char *mbx,long flags);
1671 long mail_status_default (MAILSTREAM *stream,char *mbx,long flags);
1672 MAILSTREAM *mail_open (MAILSTREAM *stream,char *name,long options);
1673 MAILSTREAM *mail_open_work (DRIVER *d,MAILSTREAM *stream,char *name,
1674                             long options);
1675 MAILSTREAM *mail_close_full (MAILSTREAM *stream,long options);
1676 MAILHANDLE *mail_makehandle (MAILSTREAM *stream);
1677 void mail_free_handle (MAILHANDLE **handle);
1678 MAILSTREAM *mail_stream (MAILHANDLE *handle);
1679 \f
1680 void mail_fetch_fast (MAILSTREAM *stream,char *sequence,long flags);
1681 void mail_fetch_flags (MAILSTREAM *stream,char *sequence,long flags);
1682 void mail_fetch_overview (MAILSTREAM *stream,char *sequence,overview_t ofn);
1683 void mail_fetch_overview_sequence (MAILSTREAM *stream,char *sequence,
1684                                    overview_t ofn);
1685 void mail_fetch_overview_default (MAILSTREAM *stream,overview_t ofn);
1686 #ifdef __FEATURE_HEADER_OPTIMIZATION__
1687 ENVELOPE *mail_fetch_structure (MAILSTREAM *stream,unsigned long msgno,
1688                                 BODY **body,long flags,int iDownload);
1689 #else
1690 ENVELOPE *mail_fetch_structure (MAILSTREAM *stream,unsigned long msgno,
1691                                 BODY **body,long flags);
1692 #endif
1693 char *mail_fetch_message (MAILSTREAM *stream,unsigned long msgno,
1694                           unsigned long *len,long flags);
1695 char *mail_fetch_header (MAILSTREAM *stream,unsigned long msgno,char *section,
1696                          STRINGLIST *lines,unsigned long *len,long flags);
1697 char *mail_fetch_text (MAILSTREAM *stream,unsigned long msgno,char *section,
1698                        unsigned long *len,long flags);
1699 char *mail_fetch_mime (MAILSTREAM *stream,unsigned long msgno,char *section,
1700                        unsigned long *len,long flags);
1701 char *mail_fetch_body (MAILSTREAM *stream,unsigned long msgno,char *section,
1702                        unsigned long *len,long flags);
1703 long mail_partial_text (MAILSTREAM *stream,unsigned long msgno,char *section,
1704                         unsigned long first,unsigned long last,long flags);
1705 long mail_partial_body (MAILSTREAM *stream,unsigned long msgno,char *section,
1706                         unsigned long first,unsigned long last,long flags);
1707 char *mail_fetch_text_return (GETS_DATA *md,SIZEDTEXT *t,unsigned long *len);
1708 char *mail_fetch_string_return (GETS_DATA *md,STRING *bs,unsigned long i,
1709                                 unsigned long *len,long flags);
1710 long mail_read (void *stream,unsigned long size,char *buffer);
1711 unsigned long mail_uid (MAILSTREAM *stream,unsigned long msgno);
1712 unsigned long mail_msgno (MAILSTREAM *stream,unsigned long uid);
1713 void mail_fetchfrom (char *s,MAILSTREAM *stream,unsigned long msgno,
1714                      long length);
1715 void mail_fetchsubject (char *s,MAILSTREAM *stream,unsigned long msgno,
1716                         long length);
1717 MESSAGECACHE *mail_elt (MAILSTREAM *stream,unsigned long msgno);
1718 void mail_flag (MAILSTREAM *stream,char *sequence,char *flag,long flags);
1719 long mail_search_full (MAILSTREAM *stream,char *charset,SEARCHPGM *pgm,
1720                        long flags);
1721 long mail_search_default (MAILSTREAM *stream,char *charset,SEARCHPGM *pgm,
1722                           long flags);
1723 long mail_ping (MAILSTREAM *stream);
1724 void mail_check (MAILSTREAM *stream);
1725 long mail_expunge_full (MAILSTREAM *stream,char *sequence,long options);
1726 long mail_copy_full (MAILSTREAM *stream,char *sequence,char *mailbox,
1727                      long options);
1728 long mail_append_full (MAILSTREAM *stream,char *mailbox,char *flags,char *date,
1729                        STRING *message);
1730 long mail_append_multiple (MAILSTREAM *stream,char *mailbox,append_t af,
1731                            void *data);
1732 void mail_gc (MAILSTREAM *stream,long gcflags);
1733 void mail_gc_msg (MESSAGE *msg,long gcflags);
1734 void mail_gc_body (BODY *body);
1735 \f
1736 BODY *mail_body (MAILSTREAM *stream,unsigned long msgno,
1737                  unsigned char *section);
1738 char *mail_date (char *string,MESSAGECACHE *elt);
1739 char *mail_cdate (char *string,MESSAGECACHE *elt);
1740 long mail_parse_date (MESSAGECACHE *elt,unsigned char *string);
1741 void mail_exists (MAILSTREAM *stream,unsigned long nmsgs);
1742 void mail_recent (MAILSTREAM *stream,unsigned long recent);
1743 void mail_expunged (MAILSTREAM *stream,unsigned long msgno);
1744 void mail_lock (MAILSTREAM *stream);
1745 void mail_unlock (MAILSTREAM *stream);
1746 void mail_debug (MAILSTREAM *stream);
1747 void mail_nodebug (MAILSTREAM *stream);
1748 void mail_dlog (char *string,long flag);
1749 long mail_match_lines (STRINGLIST *lines,STRINGLIST *msglines,long flags);
1750 unsigned long mail_filter (char *text,unsigned long len,STRINGLIST *lines,
1751                            long flags);
1752 long mail_search_msg (MAILSTREAM *stream,unsigned long msgno,char *section,
1753                       SEARCHPGM *pgm);
1754 long mail_search_header_text (char *s,STRINGLIST *st);
1755 long mail_search_header (SIZEDTEXT *hdr,STRINGLIST *st);
1756 long mail_search_text (MAILSTREAM *stream,unsigned long msgno,char *section,
1757                        STRINGLIST *st,long flags);
1758 long mail_search_body (MAILSTREAM *stream,unsigned long msgno,BODY *body,
1759                        char *prefix,unsigned long section,long flags);
1760 long mail_search_string (SIZEDTEXT *s,char *charset,STRINGLIST **st);
1761 long mail_search_string_work (SIZEDTEXT *s,STRINGLIST **st);
1762 long mail_search_keyword (MAILSTREAM *stream,MESSAGECACHE *elt,STRINGLIST *st,
1763                           long flag);
1764 long mail_search_addr (ADDRESS *adr,STRINGLIST *st);
1765 char *mail_search_gets (readfn_t f,void *stream,unsigned long size,
1766                         GETS_DATA *md);
1767 SEARCHPGM *mail_criteria (char *criteria);
1768 int mail_criteria_date (unsigned short *date,char **r);
1769 int mail_criteria_string (STRINGLIST **s,char **r);
1770 unsigned short mail_shortdate (unsigned int year,unsigned int month,
1771                                unsigned int day);
1772 SEARCHSET *mail_parse_set (char *s,char **ret);
1773 SEARCHSET *mail_append_set (SEARCHSET *set,unsigned long msgno);
1774 unsigned long *mail_sort (MAILSTREAM *stream,char *charset,SEARCHPGM *spg,
1775                           SORTPGM *pgm,long flags);
1776 unsigned long *mail_sort_cache (MAILSTREAM *stream,SORTPGM *pgm,SORTCACHE **sc,
1777                                 long flags);
1778 unsigned long *mail_sort_msgs (MAILSTREAM *stream,char *charset,SEARCHPGM *spg,
1779                                SORTPGM *pgm,long flags);
1780 SORTCACHE **mail_sort_loadcache (MAILSTREAM *stream,SORTPGM *pgm);
1781 unsigned int mail_strip_subject (char *t,char **ret);
1782 char *mail_strip_subject_wsp (char *s);
1783 char *mail_strip_subject_blob (char *s);
1784 int mail_sort_compare (const void *a1,const void *a2);
1785 unsigned long mail_longdate (MESSAGECACHE *elt);
1786 THREADNODE *mail_thread (MAILSTREAM *stream,char *type,char *charset,
1787                          SEARCHPGM *spg,long flags);
1788 THREADNODE *mail_thread_msgs (MAILSTREAM *stream,char *type,char *charset,
1789                               SEARCHPGM *spg,long flags,sorter_t sorter);
1790 THREADNODE *mail_thread_orderedsubject (MAILSTREAM *stream,char *charset,
1791                                         SEARCHPGM *spg,long flags,
1792                                         sorter_t sorter);
1793 THREADNODE *mail_thread_references (MAILSTREAM *stream,char *charset,
1794                                     SEARCHPGM *spg,long flags,
1795                                     sorter_t sorter);
1796 void mail_thread_loadcache (MAILSTREAM *stream,unsigned long uid,OVERVIEW *ov,
1797                             unsigned long msgno);
1798 char *mail_thread_parse_msgid (char *s,char **ss);
1799 STRINGLIST *mail_thread_parse_references (char *s,long flag);
1800 long mail_thread_check_child (container_t mother,container_t daughter);
1801 container_t mail_thread_prune_dummy (container_t msg,container_t ane);
1802 container_t mail_thread_prune_dummy_work (container_t msg,container_t ane);
1803 THREADNODE *mail_thread_c2node (MAILSTREAM *stream,container_t con,long flags);
1804 THREADNODE *mail_thread_sort (THREADNODE *thr,THREADNODE **tc);
1805 int mail_thread_compare_date (const void *a1,const void *a2);
1806 long mail_sequence (MAILSTREAM *stream,unsigned char *sequence);
1807 long mail_uid_sequence (MAILSTREAM *stream,unsigned char *sequence);
1808 long mail_parse_flags (MAILSTREAM *stream,char *flag,unsigned long *uf);
1809 long mail_usable_network_stream (MAILSTREAM *stream,char *name);
1810 \f
1811 MESSAGECACHE *mail_new_cache_elt (unsigned long msgno);
1812 ENVELOPE *mail_newenvelope (void);
1813 ADDRESS *mail_newaddr (void);
1814 BODY *mail_newbody (void);
1815 BODY *mail_initbody (BODY *body);
1816 PARAMETER *mail_newbody_parameter (void);
1817 PART *mail_newbody_part (void);
1818 MESSAGE *mail_newmsg (void);
1819 STRINGLIST *mail_newstringlist (void);
1820 SEARCHPGM *mail_newsearchpgm (void);
1821 SEARCHHEADER *mail_newsearchheader (char *line,char *text);
1822 SEARCHSET *mail_newsearchset (void);
1823 SEARCHOR *mail_newsearchor (void);
1824 SEARCHPGMLIST *mail_newsearchpgmlist (void);
1825 SORTPGM *mail_newsortpgm (void);
1826 THREADNODE *mail_newthreadnode (SORTCACHE *sc);
1827 ACLLIST *mail_newacllist (void);
1828 QUOTALIST *mail_newquotalist (void);
1829 void mail_free_body (BODY **body);
1830 void mail_free_body_data (BODY *body);
1831 void mail_free_body_parameter (PARAMETER **parameter);
1832 void mail_free_body_part (PART **part);
1833 void mail_free_cache (MAILSTREAM *stream);
1834 void mail_free_elt (MESSAGECACHE **elt);
1835 void mail_free_envelope (ENVELOPE **env);
1836 void mail_free_address (ADDRESS **address);
1837 void mail_free_stringlist (STRINGLIST **string);
1838 void mail_free_searchpgm (SEARCHPGM **pgm);
1839 void mail_free_searchheader (SEARCHHEADER **hdr);
1840 void mail_free_searchset (SEARCHSET **set);
1841 void mail_free_searchor (SEARCHOR **orl);
1842 void mail_free_searchpgmlist (SEARCHPGMLIST **pgl);
1843 void mail_free_namespace (NAMESPACE **n);
1844 void mail_free_sortpgm (SORTPGM **pgm);
1845 void mail_free_threadnode (THREADNODE **thr);
1846 void mail_free_acllist (ACLLIST **al);
1847 void mail_free_quotalist (QUOTALIST **ql);
1848 void auth_link (AUTHENTICATOR *auth);
1849 char *mail_auth (char *mechanism,authresponse_t resp,int argc,char *argv[]);
1850 AUTHENTICATOR *mail_lookup_auth (unsigned long i);
1851 unsigned int mail_lookup_auth_name (char *mechanism,long flags);
1852 \f
1853 NETSTREAM *net_open (NETMBX *mb,NETDRIVER *dv,unsigned long port,
1854                      NETDRIVER *ssld,char *ssls,unsigned long sslp);
1855 NETSTREAM *net_open_work (NETDRIVER *dv,char *host,char *service,
1856                           unsigned long port,unsigned long portoverride,
1857                           unsigned long flags);
1858 NETSTREAM *net_aopen (NETDRIVER *dv,NETMBX *mb,char *service,char *usrbuf);
1859 char *net_getline (NETSTREAM *stream);
1860                                 /* stream must be void* for use as readfn_t */
1861 long net_getbuffer (void *stream,unsigned long size,char *buffer);
1862 long net_soutr (NETSTREAM *stream,char *string);
1863 long net_sout (NETSTREAM *stream,char *string,unsigned long size);
1864 void net_close (NETSTREAM *stream);
1865 char *net_host (NETSTREAM *stream);
1866 char *net_remotehost (NETSTREAM *stream);
1867 unsigned long net_port (NETSTREAM *stream);
1868 char *net_localhost (NETSTREAM *stream);
1869
1870 long sm_subscribe (char *mailbox);
1871 long sm_unsubscribe (char *mailbox);
1872 char *sm_read (void **sdb);
1873
1874 void ssl_onceonlyinit (void);
1875 char *ssl_start_tls (char *s);
1876 void ssl_server_init (char *server);
1877
1878
1879 /* Server I/O functions */
1880
1881 int PBIN (void);
1882 char *PSIN (char *s,int n);
1883 long PSINR (char *s,unsigned long n);
1884 int PBOUT (int c);
1885 long INWAIT (long seconds);
1886 int PSOUT (char *s);
1887 int PSOUTR (SIZEDTEXT *s);
1888 int PFLUSH (void);