1a311032659a2a1c9325a4f3eaeaac9db0e27ade
[external/uw-imap-toolkit.git] / imap-2007e / c-client / mail.h
1 /* ========================================================================
2  * Copyright 1988-2008 University of Washington
3  *
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 #define OP_RESERVED (unsigned long) 0xff000000
417
418
419 /* Net open options */
420
421                                 /* no error messages */
422 #define NET_SILENT ((unsigned long) 0x80000000)
423                                 /* no validation of SSL certificates */
424 #define NET_NOVALIDATECERT ((unsigned long) 0x40000000)
425                                 /* no open timeout */
426 #define NET_NOOPENTIMEOUT ((unsigned long) 0x20000000)
427                                 /* TLS not SSL */
428 #define NET_TLSCLIENT ((unsigned long) 0x10000000)
429                                 /* try SSL mode */
430 #define NET_TRYSSL ((unsigned long) 0x8000000)
431 \f
432 /* Close options */
433
434 #define CL_EXPUNGE (long) 1     /* expunge silently */
435
436
437 /* Fetch options */
438
439 #define FT_UID (long) 0x1       /* argument is a UID */
440 #define FT_PEEK (long) 0x2      /* peek at data */
441 #define FT_NOT (long) 0x4       /* NOT flag for header lines fetch */
442 #define FT_INTERNAL (long) 0x8  /* text can be internal strings */
443                                 /* IMAP prefetch text when fetching header */
444 #define FT_PREFETCHTEXT (long) 0x20
445 #define FT_NOHDRS (long) 0x40   /* suppress fetching extra headers (note that
446                                    this breaks news handling) */
447 #define FT_NEEDENV (long) 0x80  /* (internal use) include envelope */
448 #define FT_NEEDBODY (long) 0x100/* (internal use) include body structure */
449                                 /* no fetch lookahead */
450 #define FT_NOLOOKAHEAD (long) 0x200
451                                 /* (internal use) lookahead in hdr searching */
452 #define FT_SEARCHLOOKAHEAD (long) 0x400
453                                 /* stringstruct return hack */
454 #define FT_RETURNSTRINGSTRUCT (long) 0x800
455 #define FT_SELECTEDHDRS (long) 0x1000 /* g.shyamakshi@samsung.com 
456                                                                               Search selected headers - From, To,
457                                                                               cc, bcc, subject, date, priority, read reciept, message-id, retrun path*/
458
459
460 /* Flagging options */
461
462 #define ST_UID (long) 0x1       /* argument is a UID sequence */
463 #define ST_SILENT (long) 0x2    /* don't return results */
464 #define ST_SET (long) 0x4       /* set vs. clear */
465
466
467 /* Expunge options */
468
469 #define EX_UID (long) 0x1       /* argument is a UID sequence */
470
471
472 /* Copy options */
473
474 #define CP_UID (long) 0x1       /* argument is a UID sequence */
475 #define CP_MOVE (long) 0x2      /* delete from source after copying */
476                                 /* set debug in any created stream */
477 #define CP_DEBUG (long) 0x20000000
478 \f
479 /* Search/sort/thread options */
480
481 #define SE_UID (long) 0x1       /* return UID */
482 #define SE_FREE (long) 0x2      /* free search program after finished */
483 #define SE_NOPREFETCH (long) 0x4/* no search prefetching */
484 #define SO_FREE (long) 0x8      /* free sort program after finished */
485 #define SE_NOSERVER (long) 0x10 /* don't do server-based search/sort/thread */
486 #define SE_RETAIN (long) 0x20   /* retain previous search results */
487 #define SO_OVERVIEW (long) 0x40 /* use overviews in searching (NNTP only) */
488 #define SE_NEEDBODY (long) 0x80 /* include body structure in prefetch */
489 #define SE_NOHDRS (long) 0x100  /* suppress prefetching extra headers (note
490                                    that this breaks news handling) */
491 #define SE_NOLOCAL (long) 0x200 /* no local retry (IMAP only) */
492
493 #define SO_NOSERVER SE_NOSERVER /* compatibility name */
494 #define SE_SILLYOK (long) 0x400 /* allow silly searches */
495
496
497 /* Status options */
498
499 #define SA_MESSAGES (long) 0x1  /* number of messages */
500 #define SA_RECENT (long) 0x2    /* number of recent messages */
501 #define SA_UNSEEN (long) 0x4    /* number of unseen messages */
502 #define SA_UIDNEXT (long) 0x8   /* next UID to be assigned */
503                                 /* UID validity value */
504 #define SA_UIDVALIDITY (long) 0x10
505                                 /* set OP_DEBUG on any created stream */
506 #define SA_DEBUG (long) 0x10000000
507                                 /* use multiple newsrcs */
508 #define SA_MULNEWSRC (long) 0x20000000
509
510 /* Mailgets flags */
511
512 #define MG_UID (long) 0x1       /* message number is a UID */
513 #define MG_COPY (long) 0x2      /* must return copy of argument */
514 \f
515 /* SASL authenticator categories */
516
517 #define AU_SECURE (long) 0x1    /* /secure allowed */
518 #define AU_AUTHUSER (long) 0x2  /* /authuser=xxx allowed */
519                                 /* authenticator hidden */
520 #define AU_HIDE (long) 0x10000000
521                                 /* authenticator disabled */
522 #define AU_DISABLE (long) 0x20000000
523
524
525 /* Garbage collection flags */
526
527 #define GC_ELT (long) 0x1       /* message cache elements */
528 #define GC_ENV (long) 0x2       /* envelopes and bodies */
529 #define GC_TEXTS (long) 0x4     /* cached texts */
530
531
532 /* mm_log()/mm_notify() condition codes */
533
534 #define WARN (long) 1           /* mm_log warning type */
535 #define ERROR (long) 2          /* mm_log error type */
536 #define PARSE (long) 3          /* mm_log parse error type */
537 #define BYE (long) 4            /* mm_notify stream dying */
538 #define TCPDEBUG (long) 5       /* mm_log TCP debug babble */
539
540
541 /* Bits from mail_parse_flags().  Don't change these, since the header format
542  * used by tenex, mtx, and mbx corresponds to these bits.
543  */
544
545 #define fSEEN 0x1
546 #define fDELETED 0x2
547 #define fFLAGGED 0x4
548 #define fANSWERED 0x8
549 #define fOLD 0x10
550 #define fDRAFT 0x20
551
552 #define fEXPUNGED 0x8000        /* internal flag */
553 \f
554 /* Bits for mm_list() and mm_lsub() */
555
556 /* Note that (LATT_NOINFERIORS LATT_HASCHILDREN LATT_HASNOCHILDREN) and
557  * (LATT_NOSELECT LATT_MARKED LATT_UNMARKED) each have eight possible states,
558  * but only four of these are valid.  The other four are silly states which
559  * while invalid can unfortunately be expressed in the IMAP protocol.
560  */
561
562                                 /* terminal node in hierarchy */
563 #define LATT_NOINFERIORS (long) 0x1
564                                 /* name can not be selected */
565 #define LATT_NOSELECT (long) 0x2
566                                 /* changed since last accessed */
567 #define LATT_MARKED (long) 0x4
568                                 /* accessed since last changed */
569 #define LATT_UNMARKED (long) 0x8
570                                 /* name has referral to remote mailbox */
571 #define LATT_REFERRAL (long) 0x10
572                                 /* has selectable inferiors */
573 #define LATT_HASCHILDREN (long) 0x20
574                                 /* has no selectable inferiors */
575 #define LATT_HASNOCHILDREN (long) 0x40
576
577
578 /* Sort functions */
579
580 #define SORTDATE 0              /* date */
581 #define SORTARRIVAL 1           /* arrival date */
582 #define SORTFROM 2              /* from */
583 #define SORTSUBJECT 3           /* subject */
584 #define SORTTO 4                /* to */
585 #define SORTCC 5                /* cc */
586 #define SORTSIZE 6              /* size */
587
588
589 /* imapreferral_t codes */
590
591 #define REFAUTHFAILED (long) 0  /* authentication referral -- not logged in */
592 #define REFAUTH (long) 1        /* authentication referral -- logged in */
593 #define REFSELECT (long) 2      /* select referral */
594 #define REFCREATE (long) 3
595 #define REFDELETE (long) 4
596 #define REFRENAME (long) 5
597 #define REFSUBSCRIBE (long) 6
598 #define REFUNSUBSCRIBE (long) 7
599 #define REFSTATUS (long) 8
600 #define REFCOPY (long) 9
601 #define REFAPPEND (long) 10
602
603
604 /* sendcommand_t codes */
605
606                                 /* expunge response deferred */
607 #define SC_EXPUNGEDEFERRED (long) 1
608 \f
609 /* Block notification codes */
610
611 #define BLOCK_NONE 0            /* not blocked */
612 #define BLOCK_SENSITIVE 1       /* sensitive code, disallow alarms */
613 #define BLOCK_NONSENSITIVE 2    /* non-sensitive code, allow alarms */
614 #define BLOCK_DNSLOOKUP 10      /* blocked on DNS lookup */
615 #define BLOCK_TCPOPEN 11        /* blocked on TCP open */
616 #define BLOCK_TCPREAD 12        /* blocked on TCP read */
617 #define BLOCK_TCPWRITE 13       /* blocked on TCP write */
618 #define BLOCK_TCPCLOSE 14       /* blocked on TCP close */
619 #define BLOCK_FILELOCK 20       /* blocked on file locking */
620
621
622 /* In-memory sized-text */
623
624 #define SIZEDTEXT struct mail_sizedtext
625
626 SIZEDTEXT {
627   unsigned char *data;          /* text */
628   unsigned long size;           /* size of text in octets */
629 };
630
631
632 /* String list */
633
634 #define STRINGLIST struct string_list
635
636 STRINGLIST {
637   SIZEDTEXT text;               /* string text */
638   STRINGLIST *next;
639 };
640
641
642 /* Parse results from mail_valid_net_parse */
643
644 #define NETMAXHOST 256
645 #define NETMAXUSER 65
646 #define NETMAXMBX (MAILTMPLEN/4)
647 #define NETMAXSRV 21
648 typedef struct net_mailbox {
649   char host[NETMAXHOST];        /* host name (may be canonicalized) */
650   char orighost[NETMAXHOST];    /* host name before canonicalization */
651   char user[NETMAXUSER];        /* user name */
652   char authuser[NETMAXUSER];    /* authentication user name */
653   char mailbox[NETMAXMBX];      /* mailbox name */
654   char service[NETMAXSRV];      /* service name */
655   unsigned long port;           /* TCP port number */
656   unsigned int anoflag : 1;     /* anonymous */
657   unsigned int dbgflag : 1;     /* debug flag */
658   unsigned int secflag : 1;     /* secure flag */
659   unsigned int sslflag : 1;     /* SSL driver flag */
660   unsigned int trysslflag : 1;  /* try SSL driver first flag */
661   unsigned int novalidate : 1;  /* don't validate certificates */
662   unsigned int tlsflag : 1;     /* TLS flag */
663   unsigned int notlsflag : 1;   /* do not do TLS flag */
664   unsigned int readonlyflag : 1;/* want readonly */
665   unsigned int norsh : 1;       /* don't use rsh/ssh */
666   unsigned int loser : 1;       /* server is a loser */
667   unsigned int tlssslv23 : 1;   /* force SSLv23 client method over TLS */
668   unsigned int apop; /*APOP Authentication - shasikala.p@siso.com*/
669 } NETMBX;
670 \f
671 /* Item in an address list */
672
673 #define ADDRESS struct mail_address
674
675 ADDRESS {
676   char *personal;               /* personal name phrase */
677   char *adl;                    /* at-domain-list source route */
678   char *mailbox;                /* mailbox name */
679   char *host;                   /* domain name of mailbox's host */
680   char *error;                  /* error in address from SMTP module */
681   struct {
682     char *type;                 /* address type (default "rfc822") */
683     char *addr;                 /* address as xtext */
684   } orcpt;
685   ADDRESS *next;                /* pointer to next address in list */
686 };
687
688
689 /* Message envelope */
690
691 typedef struct mail_envelope {
692   unsigned int incomplete : 1;  /* envelope may be incomplete */
693   unsigned int imapenvonly : 1; /* envelope only has IMAP envelope */
694   char *remail;                 /* remail header if any */
695   ADDRESS *return_path;         /* error return address */
696   unsigned char *date;          /* message composition date string */
697   ADDRESS *from;                /* originator address list */
698   ADDRESS *sender;              /* sender address list */
699   ADDRESS *reply_to;            /* reply address list */
700   char *subject;                /* message subject string */
701   ADDRESS *to;                  /* primary recipient list */
702   ADDRESS *cc;                  /* secondary recipient list */
703   ADDRESS *bcc;                 /* blind secondary recipient list */
704   char *in_reply_to;            /* replied message ID */
705   char *message_id;             /* message ID */
706   char *newsgroups;             /* USENET newsgroups */
707   char *followup_to;            /* USENET reply newsgroups */
708   char *references;             /* USENET references */
709   void *sparep;                 /* spare pointer reserved for main program */
710 } ENVELOPE;
711 \f
712 /* Primary body types */
713 /* If you change any of these you must also change body_types in rfc822.c */
714
715 #define TYPETEXT 0              /* unformatted text */
716 #define TYPEMULTIPART 1         /* multiple part */
717 #define TYPEMESSAGE 2           /* encapsulated message */
718 #define TYPEAPPLICATION 3       /* application data */
719 #define TYPEAUDIO 4             /* audio */
720 #define TYPEIMAGE 5             /* static image */
721 #define TYPEVIDEO 6             /* video */
722 #define TYPEMODEL 7             /* model */
723 #define TYPEOTHER 8             /* unknown */
724 #define TYPEMAX 15              /* maximum type code */
725
726
727 /* Body encodings */
728 /* If you change any of these you must also change body_encodings in rfc822.c
729  */
730
731 #define ENC7BIT 0               /* 7 bit SMTP semantic data */
732 #define ENC8BIT 1               /* 8 bit SMTP semantic data */
733 #define ENCBINARY 2             /* 8 bit binary data */
734 #define ENCBASE64 3             /* base-64 encoded data */
735 #define ENCQUOTEDPRINTABLE 4    /* human-readable 8-as-7 bit data */
736 #define ENCOTHER 5              /* unknown */
737 #define ENCMAX 10               /* maximum encoding code */
738
739
740 /* Body contents */
741
742 #define BODY struct mail_bodystruct
743 #define MESSAGE struct mail_body_message
744 #define PARAMETER struct mail_body_parameter
745 #define PART struct mail_body_part
746 #ifdef __DOWNLOAD_BODY_ATTACHMENT_OPTIMIZATION__
747 #define PARTLIST struct mail_body_part_list
748 #endif
749 #define PARTTEXT struct mail_body_text
750 \f
751 /* Message body text */
752
753 PARTTEXT {
754   unsigned long offset;         /* offset from body origin */
755   SIZEDTEXT text;               /* text */
756 };
757
758
759 /* Message body structure */
760
761 BODY {
762   unsigned short type;          /* body primary type */
763   unsigned short encoding;      /* body transfer encoding */
764   char *subtype;                /* subtype string */
765   PARAMETER *parameter;         /* parameter list */
766   char *id;                     /* body identifier */
767   char *description;            /* body description */
768   struct {                      /* body disposition */
769     char *type;                 /* disposition type */
770     PARAMETER *parameter;       /* disposition parameters */
771   } disposition;
772   STRINGLIST *language;         /* body language */
773   char *location;               /* body content URI */
774   PARTTEXT mime;                /* MIME header */
775   PARTTEXT contents;            /* body part contents */
776   union {                       /* different ways of accessing contents */
777     PART *part;                 /* body part list */
778     MESSAGE *msg;               /* body encapsulated message */
779   } nested;
780   struct {
781     unsigned long lines;        /* size of text in lines */
782     unsigned long bytes;        /* size of text in octets */
783   } size;
784   char *md5;                    /* MD5 checksum */
785   void *sparep;                 /* spare pointer reserved for main program */
786 };
787
788
789 /* Parameter list */
790
791 PARAMETER {
792   char *attribute;              /* parameter attribute name */
793   char *value;                  /* parameter value */
794   PARAMETER *next;              /* next parameter in list */
795 };
796
797
798 /* Multipart content list */
799
800 PART {
801   BODY body;                    /* body information for this part */
802   PART *next;                   /* next body part */
803 };
804
805 #ifdef __DOWNLOAD_BODY_ATTACHMENT_OPTIMIZATION__
806 PARTLIST{
807   BODY *body;                   /* body information for this part */
808   PART *next;                   /* next body part */
809 };
810 #endif
811
812
813 /* RFC-822 Message */
814
815 MESSAGE {
816   ENVELOPE *env;                /* message envelope */
817   BODY *body;                   /* message body */
818   PARTTEXT full;                /* full message */
819   STRINGLIST *lines;            /* lines used to filter header */
820   PARTTEXT header;              /* header text */
821   PARTTEXT text;                /* body text */
822 };
823 \f
824 /* Entry in the message cache array */
825
826 typedef struct message_cache {
827   unsigned long msgno;          /* message number */
828   unsigned int lockcount : 8;   /* non-zero if multiple references */
829   unsigned long rfc822_size;    /* # of bytes of message as raw RFC822 */
830   struct {                      /* c-client internal use only */
831     unsigned long uid;          /* message unique ID */
832     unsigned long mod;          /* modseq */
833     PARTTEXT special;           /* special text pointers */
834     MESSAGE msg;                /* internal message pointers */
835     union {                     /* driver internal use */
836       unsigned long data;
837       void *ptr;
838     } spare;
839     unsigned int sequence : 1;  /* saved sequence bit */
840     unsigned int dirty : 1;     /* driver internal use */
841     unsigned int filter : 1;    /* driver internal use */
842     unsigned int ghost : 1;     /* driver internal use */
843   } private;
844                         /* internal date */
845   unsigned int day : 5;         /* day of month (1-31) */
846   unsigned int month : 4;       /* month of year (1-12) */
847   unsigned int year : 7;        /* year since BASEYEAR (expires in 127 yrs) */
848   unsigned int hours: 5;        /* hours (0-23) */
849   unsigned int minutes: 6;      /* minutes (0-59) */
850   unsigned int seconds: 6;      /* seconds (0-59) */
851   unsigned int zoccident : 1;   /* non-zero if west of UTC */
852   unsigned int zhours : 4;      /* hours from UTC (0-12) */
853   unsigned int zminutes: 6;     /* minutes (0-59) */
854                         /* system flags */
855   unsigned int seen : 1;        /* system Seen flag */
856   unsigned int deleted : 1;     /* system Deleted flag */
857   unsigned int flagged : 1;     /* system Flagged flag */
858   unsigned int answered : 1;    /* system Answered flag */
859   unsigned int draft : 1;       /* system Draft flag */
860   unsigned int recent : 1;      /* system Recent flag */
861                         /* message status */
862   unsigned int valid : 1;       /* elt has valid flags */
863   unsigned int searched : 1;    /* message was searched */
864   unsigned int sequence : 1;    /* message is in sequence */
865                         /* reserved for use by main program */
866   unsigned int spare : 1;       /* first spare bit */
867   unsigned int spare2 : 1;      /* second spare bit */
868   unsigned int spare3 : 1;      /* third spare bit */
869   unsigned int spare4 : 1;      /* fourth spare bit */
870   unsigned int spare5 : 1;      /* fifth spare bit */
871   unsigned int spare6 : 1;      /* sixth spare bit */
872   unsigned int spare7 : 1;      /* seventh spare bit */
873   unsigned int spare8 : 1;      /* eighth spare bit */
874   void *sparep;                 /* spare pointer */
875   unsigned long user_flags;     /* user-assignable flags */
876 } MESSAGECACHE;
877 \f
878 /* String structure */
879
880 #define STRINGDRIVER struct string_driver
881
882 typedef struct mailstring {
883   void *data;                   /* driver-dependent data */
884   unsigned long data1;          /* driver-dependent data */
885   unsigned long size;           /* total length of string */
886   char *chunk;                  /* base address of chunk */
887   unsigned long chunksize;      /* size of chunk */
888   unsigned long offset;         /* offset of this chunk in base */
889   char *curpos;                 /* current position in chunk */
890   unsigned long cursize;        /* number of bytes remaining in chunk */
891   STRINGDRIVER *dtb;            /* driver that handles this type of string */
892 } STRING;
893
894
895 /* Dispatch table for string driver */
896
897 STRINGDRIVER {
898                                 /* initialize string driver */
899   void (*init) (STRING *s,void *data,unsigned long size);
900                                 /* get next character in string */
901   char (*next) (STRING *s);
902                                 /* set position in string */
903   void (*setpos) (STRING *s,unsigned long i);
904 };
905
906
907 /* Stringstruct access routines */
908
909 #define INIT(s,d,data,size) ((*((s)->dtb = &d)->init) (s,data,size))
910 #define SIZE(s) ((s)->size - GETPOS (s))
911 #define CHR(s) (*(s)->curpos)
912 #define SNX(s) (--(s)->cursize ? *(s)->curpos++ : (*(s)->dtb->next) (s))
913 #define GETPOS(s) ((s)->offset + ((s)->curpos - (s)->chunk))
914 #define SETPOS(s,i) (*(s)->dtb->setpos) (s,i)
915 \f
916 /* Search program */
917
918 #define SEARCHPGM struct search_program
919 #define SEARCHHEADER struct search_header
920 #define SEARCHSET struct search_set
921 #define SEARCHOR struct search_or
922 #define SEARCHPGMLIST struct search_pgm_list
923
924
925 SEARCHHEADER {                  /* header search */
926   SIZEDTEXT line;               /* header line */
927   SIZEDTEXT text;               /* text in header */
928   SEARCHHEADER *next;           /* next in list */
929 };
930
931
932 SEARCHSET {                     /* message set */
933   unsigned long first;          /* sequence number */
934   unsigned long last;           /* last value, if a range */
935   SEARCHSET *next;              /* next in list */
936 };
937
938
939 SEARCHOR {
940   SEARCHPGM *first;             /* first program */
941   SEARCHPGM *second;            /* second program */
942   SEARCHOR *next;               /* next in list */
943 };
944
945
946 SEARCHPGMLIST {
947   SEARCHPGM *pgm;               /* search program */
948   SEARCHPGMLIST *next;          /* next in list */
949 };
950 \f
951 SEARCHPGM {                     /* search program */
952   SEARCHSET *msgno;             /* message numbers */
953   SEARCHSET *uid;               /* unique identifiers */
954   SEARCHOR *or;                 /* or'ed in programs */
955   SEARCHPGMLIST *not;           /* and'ed not program */
956   SEARCHHEADER *header;         /* list of headers */
957   STRINGLIST *bcc;              /* bcc recipients */
958   STRINGLIST *body;             /* text in message body */
959   STRINGLIST *cc;               /* cc recipients */
960   STRINGLIST *from;             /* originator */
961   STRINGLIST *keyword;          /* keywords */
962   STRINGLIST *unkeyword;        /* unkeywords */
963   STRINGLIST *subject;          /* text in subject */
964   STRINGLIST *text;             /* text in headers and body */
965   STRINGLIST *to;               /* to recipients */
966   unsigned long larger;         /* larger than this size */
967   unsigned long smaller;        /* smaller than this size */
968   unsigned long older;          /* older than this interval */
969   unsigned long younger;        /* younger than this interval */
970   unsigned short sentbefore;    /* sent before this date */
971   unsigned short senton;        /* sent on this date */
972   unsigned short sentsince;     /* sent since this date */
973   unsigned short before;        /* before this date */
974   unsigned short on;            /* on this date */
975   unsigned short since;         /* since this date */
976   unsigned int answered : 1;    /* answered messages */
977   unsigned int unanswered : 1;  /* unanswered messages */
978   unsigned int deleted : 1;     /* deleted messages */
979   unsigned int undeleted : 1;   /* undeleted messages */
980   unsigned int draft : 1;       /* message draft */
981   unsigned int undraft : 1;     /* message undraft */
982   unsigned int flagged : 1;     /* flagged messages */
983   unsigned int unflagged : 1;   /* unflagged messages */
984   unsigned int recent : 1;      /* recent messages */
985   unsigned int old : 1;         /* old messages */
986   unsigned int seen : 1;        /* seen messages */
987   unsigned int unseen : 1;      /* unseen messages */
988   /* These must be simulated in IMAP */
989   STRINGLIST *return_path;      /* error return address */
990   STRINGLIST *sender;           /* sender address list */
991   STRINGLIST *reply_to;         /* reply address list */
992   STRINGLIST *in_reply_to;      /* replied message ID */
993   STRINGLIST *message_id;       /* message ID */
994   STRINGLIST *newsgroups;       /* USENET newsgroups */
995   STRINGLIST *followup_to;      /* USENET reply newsgroups */
996   STRINGLIST *references;       /* USENET references */
997 };
998
999
1000 /* Mailbox status */
1001
1002 typedef struct mbx_status {
1003   long flags;                   /* validity flags */
1004   unsigned long messages;       /* number of messages */
1005   unsigned long recent;         /* number of recent messages */
1006   unsigned long unseen;         /* number of unseen messages */
1007   unsigned long uidnext;        /* next UID to be assigned */
1008   unsigned long uidvalidity;    /* UID validity value */
1009 } MAILSTATUS;
1010 \f
1011 /* Sort program */
1012
1013 typedef void (*postsort_t) (void *sc);
1014
1015 #define SORTPGM struct sort_program
1016
1017 SORTPGM {
1018   unsigned int reverse : 1;     /* sort function is to be reversed */
1019   unsigned int abort : 1;       /* abort sorting */
1020   short function;               /* sort function */
1021   unsigned long nmsgs;          /* number of messages being sorted */
1022   struct {
1023     unsigned long cached;       /* number of messages cached so far */
1024     unsigned long sorted;       /* number of messages sorted so far */
1025     unsigned long postsorted;   /* number of postsorted messages so far */
1026   } progress;
1027   postsort_t postsort;          /* post sorter */
1028   SORTPGM *next;                /* next function */
1029 };
1030
1031
1032 /* Sort cache */
1033
1034 #define SORTCACHE struct sort_cache
1035
1036 SORTCACHE {
1037   unsigned int sorted : 1;      /* message has been sorted */
1038   unsigned int postsorted : 1;  /* message has been postsorted */
1039   unsigned int refwd : 1;       /* subject is a re or fwd */
1040   unsigned int dirty : 1;       /* has data not written to backup */
1041   SORTPGM *pgm;                 /* sort program */
1042   unsigned long num;            /* message number (sequence or UID) */
1043   unsigned long date;           /* sent date */
1044   unsigned long arrival;        /* arrival date */
1045   unsigned long size;           /* message size */
1046   char *from;                   /* from string */
1047   char *to;                     /* to string */
1048   char *cc;                     /* cc string */
1049   char *subject;                /* extracted subject string */
1050   char *message_id;             /* message-id string */
1051   char *unique;                 /* unique string, normally message-id */
1052   STRINGLIST *references;       /* references string */
1053 };
1054 \f
1055 /* ACL list */
1056
1057 #define ACLLIST struct acl_list
1058
1059 ACLLIST {
1060   char *identifier;             /* authentication identifier */
1061   char *rights;                 /* access rights */
1062   ACLLIST *next;
1063 };
1064
1065 /* Quota resource list */
1066
1067 #define QUOTALIST struct quota_list
1068
1069 QUOTALIST {
1070   char *name;                   /* resource name */
1071   unsigned long usage;          /* resource usage */
1072   unsigned long limit;          /* resource limit */
1073   QUOTALIST *next;              /* next resource */
1074 };
1075 \f
1076 /* Mail Access I/O stream */
1077
1078
1079 /* Structure for mail driver dispatch */
1080
1081 #define DRIVER struct driver    
1082
1083
1084 /* Mail I/O stream */
1085         
1086 typedef struct mail_stream {
1087   DRIVER *dtb;                  /* dispatch table for this driver */
1088   void *local;                  /* pointer to driver local data */
1089   char *mailbox;                /* mailbox name (canonicalized) */
1090   char *original_mailbox;       /* mailbox name (non-canonicalized) */
1091   unsigned short use;           /* stream use count */
1092   unsigned short sequence;      /* stream sequence */
1093   unsigned int inbox : 1;       /* stream open on an INBOX */
1094   unsigned int lock : 1;        /* stream lock flag */
1095   unsigned int debug : 1;       /* stream debug flag */
1096   unsigned int silent : 1;      /* don't pass events to main program */
1097   unsigned int rdonly : 1;      /* stream read-only flag */
1098   unsigned int anonymous : 1;   /* stream anonymous access flag */
1099   unsigned int scache : 1;      /* stream short cache flag */
1100   unsigned int halfopen : 1;    /* stream half-open flag */
1101   unsigned int secure : 1;      /* stream secure flag */
1102   unsigned int tryssl : 1;      /* stream tryssl flag */
1103   unsigned int mulnewsrc : 1;   /* stream use multiple newsrc files */
1104   unsigned int perm_seen : 1;   /* permanent Seen flag */
1105   unsigned int perm_deleted : 1;/* permanent Deleted flag */
1106   unsigned int perm_flagged : 1;/* permanent Flagged flag */
1107   unsigned int perm_answered :1;/* permanent Answered flag */
1108   unsigned int perm_draft : 1;  /* permanent Draft flag */
1109   unsigned int kwd_create : 1;  /* can create new keywords */
1110   unsigned int uid_nosticky : 1;/* UIDs are not preserved */
1111   unsigned int unhealthy : 1;   /* unhealthy protocol negotiations */
1112   unsigned int nokod : 1;       /* suppress kiss-of-death */
1113   unsigned int sniff : 1;       /* metadata only */
1114   unsigned long perm_user_flags;/* mask of permanent user flags */
1115   unsigned long gensym;         /* generated tag */
1116   unsigned long nmsgs;          /* # of associated msgs */
1117   unsigned long recent;         /* # of recent msgs */
1118   unsigned long uid_validity;   /* UID validity sequence */
1119   unsigned long uid_last;       /* last assigned UID */
1120   char *user_flags[NUSERFLAGS]; /* pointers to user flags in bit order */
1121   unsigned long cachesize;      /* size of message cache */
1122   MESSAGECACHE **cache;         /* message cache array */
1123   SORTCACHE **sc;               /* sort cache array */
1124   unsigned long msgno;          /* message number of `current' message */
1125   ENVELOPE *env;                /* scratch buffer for envelope */
1126   BODY *body;                   /* scratch buffer for body */
1127   SIZEDTEXT text;               /* scratch buffer for text */
1128   struct {
1129     char *name;                 /* mailbox name to snarf from */
1130     unsigned long time;         /* last snarf time */
1131     long options;               /* snarf open options */
1132   } snarf;
1133   struct {                      /* internal use only */
1134     struct {                    /* search temporaries */
1135       STRINGLIST *string;       /* string(s) to search */
1136       long result;              /* search result */
1137       char *text;               /* cache of fetched text */
1138     } search;
1139     STRING string;              /* stringstruct return hack */
1140   } private;
1141                         /* reserved for use by main program */
1142   void *sparep;                 /* spare pointer */
1143   unsigned int spare : 1;       /* first spare bit */
1144   unsigned int spare2 : 1;      /* second spare bit */
1145   unsigned int spare3 : 1;      /* third spare bit */
1146   unsigned int spare4 : 1;      /* fourth spare bit */
1147   unsigned int spare5 : 1;      /* fifth spare bit */
1148   unsigned int spare6 : 1;      /* sixth spare bit */
1149   unsigned int spare7 : 1;      /* seventh spare bit */
1150   unsigned int spare8 : 1;      /* eighth spare bit */
1151 } MAILSTREAM;
1152 \f
1153 /* Mail I/O stream handle */
1154
1155 typedef struct mail_stream_handle {
1156   MAILSTREAM *stream;           /* pointer to mail stream */
1157   unsigned short sequence;      /* sequence of what we expect stream to be */
1158 } MAILHANDLE;
1159
1160
1161 /* Message overview */
1162
1163 typedef struct mail_overview {
1164   char *subject;                /* message subject string */
1165   ADDRESS *from;                /* originator address list */
1166   char *date;                   /* message composition date string */
1167   char *message_id;             /* message ID */
1168   char *references;             /* USENET references */
1169   struct {                      /* may be 0 or NUL if unknown/undefined */
1170     unsigned long octets;       /* message octets (probably LF-newline form) */
1171     unsigned long lines;        /* message lines */
1172     char *xref;                 /* cross references */
1173   } optional;
1174 } OVERVIEW;
1175 \f
1176 /* Network access I/O stream */
1177
1178
1179 /* Structure for network driver dispatch */
1180
1181 #define NETDRIVER struct net_driver
1182
1183
1184 /* Network transport I/O stream */
1185
1186 typedef struct net_stream {
1187   void *stream;                 /* driver's I/O stream */
1188   NETDRIVER *dtb;               /* network driver */
1189 } NETSTREAM;
1190
1191
1192 /* Network transport driver dispatch */
1193
1194 NETDRIVER {
1195   void *(*open) (char *host,char *service,unsigned long port);
1196   void *(*aopen) (NETMBX *mb,char *service,char *usrbuf);
1197   char *(*getline) (void *stream);
1198   long (*getbuffer) (void *stream,unsigned long size,char *buffer);
1199   long (*soutr) (void *stream,char *string);
1200   long (*sout) (void *stream,char *string,unsigned long size);
1201   void (*close) (void *stream);
1202   char *(*host) (void *stream);
1203   char *(*remotehost) (void *stream);
1204   unsigned long (*port) (void *stream);
1205   char *(*localhost) (void *stream);
1206 };
1207
1208
1209 /* Mailgets data identifier */
1210
1211 typedef struct getsdata {
1212   MAILSTREAM *stream;
1213   unsigned long msgno;
1214   char *what;
1215   STRINGLIST *stl;
1216   unsigned long first;
1217   unsigned long last;
1218   long flags;
1219 } GETS_DATA;
1220
1221
1222 #define INIT_GETS(md,s,m,w,f,l) \
1223   md.stream = s, md.msgno = m, md.what = w, md.first = f, md.last = l, \
1224   md.stl = NIL, md.flags = NIL;
1225 \f
1226 /* Mail delivery I/O stream */
1227
1228 typedef struct send_stream {
1229   NETSTREAM *netstream;         /* network I/O stream */
1230   char *host;                   /* SMTP service host */
1231   char *reply;                  /* last reply string */
1232   long replycode;               /* last reply code */
1233   unsigned int debug : 1;       /* stream debug flag */
1234   unsigned int sensitive : 1;   /* sensitive data in progress */
1235   unsigned int loser : 1;       /* server is a loser */
1236   unsigned int saslcancel : 1;  /* SASL cancelled by protocol */
1237   union {                       /* protocol specific */
1238     struct {                    /* SMTP specific */
1239       unsigned int ok : 1;      /* supports ESMTP */
1240       struct {                  /* service extensions */
1241         unsigned int send : 1;  /* supports SEND */
1242         unsigned int soml : 1;  /* supports SOML */
1243         unsigned int saml : 1;  /* supports SAML */
1244         unsigned int expn : 1;  /* supports EXPN */
1245         unsigned int help : 1;  /* supports HELP */
1246         unsigned int turn : 1;  /* supports TURN */
1247         unsigned int etrn : 1;  /* supports ETRN */
1248         unsigned int starttls:1;/* supports STARTTLS */
1249         unsigned int relay : 1; /* supports relaying */
1250         unsigned int pipe : 1;  /* supports pipelining */
1251         unsigned int ensc : 1;  /* supports enhanced status codes */
1252         unsigned int bmime : 1; /* supports BINARYMIME */
1253         unsigned int chunk : 1; /* supports CHUNKING */
1254       } service;
1255       struct {                  /* 8-bit MIME transport */
1256         unsigned int ok : 1;    /* supports 8-bit MIME */
1257         unsigned int want : 1;  /* want 8-bit MIME */
1258       } eightbit;
1259       struct {                  /* delivery status notification */
1260         unsigned int ok : 1;    /* supports DSN */
1261         unsigned int want : 1;  /* want DSN */
1262         struct {                /* notification options */
1263                                 /* notify on failure */
1264           unsigned int failure : 1;
1265                                 /* notify on delay */
1266           unsigned int delay : 1;
1267                                 /* notify on success */
1268           unsigned int success : 1;
1269         } notify;
1270         unsigned int full : 1;  /* return full headers */
1271         char *envid;            /* envelope identifier as xtext */
1272       } dsn;
1273       struct {                  /* size declaration */
1274         unsigned int ok : 1;    /* supports SIZE */
1275         unsigned long limit;    /* maximum size supported */
1276       } size;
1277       struct {                  /* deliverby declaration */
1278         unsigned int ok : 1;    /* supports DELIVERBY */
1279         unsigned long minby;    /* minimum by-time */
1280       } deliverby;
1281       struct {                  /* authenticated turn */
1282         unsigned int ok : 1;    /* supports ATRN */
1283         char *domains;          /* domains */
1284       } atrn;
1285                                 /* supported SASL authenticators */
1286       unsigned int auth : MAXAUTHENTICATORS;
1287     } esmtp;
1288     struct {                    /* NNTP specific */
1289       unsigned int post : 1;    /* supports POST */
1290       struct {                  /* NNTP extensions */
1291         unsigned int ok : 1;    /* supports extensions */
1292                                 /* supports LISTGROUP */
1293         unsigned int listgroup : 1;
1294         unsigned int over : 1;  /* supports OVER */
1295         unsigned int hdr : 1;   /* supports HDR */
1296         unsigned int pat : 1;   /* supports PAT */
1297                                 /* supports STARTTLS */
1298         unsigned int starttls : 1;
1299                                 /* server has MULTIDOMAIN */
1300         unsigned int multidomain : 1;
1301                                 /* supports AUTHINFO USER */
1302         unsigned int authuser : 1;
1303                                 /* supported authenticators */
1304         unsigned int sasl : MAXAUTHENTICATORS;
1305       } ext;
1306     } nntp;
1307   } protocol;
1308 } SENDSTREAM;
1309 \f
1310 /* Jacket into external interfaces */
1311
1312 typedef long (*readfn_t) (void *stream,unsigned long size,char *buffer);
1313 typedef char *(*mailgets_t) (readfn_t f,void *stream,unsigned long size,
1314                              GETS_DATA *md);
1315 typedef char *(*readprogress_t) (GETS_DATA *md,unsigned long octets);
1316 typedef void *(*mailcache_t) (MAILSTREAM *stream,unsigned long msgno,long op);
1317 typedef long (*mailproxycopy_t) (MAILSTREAM *stream,char *sequence,
1318                                  char *mailbox,long options);
1319 typedef long (*tcptimeout_t) (long overall,long last);
1320 typedef void *(*authchallenge_t) (void *stream,unsigned long *len);
1321 typedef long (*authrespond_t) (void *stream,char *s,unsigned long size);
1322 typedef long (*authcheck_t) (void);
1323 typedef long (*authclient_t) (authchallenge_t challenger,
1324                               authrespond_t responder,char *service,NETMBX *mb,
1325                               void *s,unsigned long *trial,char *user);
1326 typedef char *(*authresponse_t) (void *challenge,unsigned long clen,
1327                                  unsigned long *rlen);
1328 typedef char *(*authserver_t) (authresponse_t responder,int argc,char *argv[]);
1329 typedef void (*smtpverbose_t) (char *buffer);
1330 typedef void (*imapenvelope_t) (MAILSTREAM *stream,unsigned long msgno,
1331                                 ENVELOPE *env);
1332 typedef char *(*imapreferral_t) (MAILSTREAM *stream,char *url,long code);
1333 typedef void (*overview_t) (MAILSTREAM *stream,unsigned long uid,OVERVIEW *ov,
1334                             unsigned long msgno);
1335 typedef unsigned long *(*sorter_t) (MAILSTREAM *stream,char *charset,
1336                                     SEARCHPGM *spg,SORTPGM *pgm,long flags);
1337 typedef void (*parseline_t) (ENVELOPE *env,char *hdr,char *data,char *host);
1338 typedef ADDRESS *(*parsephrase_t) (char *phrase,char *end,char *host);
1339 typedef void *(*blocknotify_t) (int reason,void *data);
1340 typedef long (*kinit_t) (char *host,char *reason);
1341 typedef void (*sendcommand_t) (MAILSTREAM *stream,char *cmd,long flags);
1342 typedef char *(*newsrcquery_t) (MAILSTREAM *stream,char *mulname,char *name);
1343 typedef void (*getacl_t) (MAILSTREAM *stream,char *mailbox,ACLLIST *acl);
1344 typedef void (*listrights_t) (MAILSTREAM *stream,char *mailbox,char *id,
1345                               char *alwaysrights,STRINGLIST *possiblerights);
1346 typedef void (*myrights_t) (MAILSTREAM *stream,char *mailbox,char *rights);
1347 typedef void (*quota_t) (MAILSTREAM *stream,char *qroot,QUOTALIST *qlist);
1348 typedef void (*quotaroot_t) (MAILSTREAM *stream,char *mbx,STRINGLIST *qroot);
1349 typedef void (*sortresults_t) (MAILSTREAM *stream,unsigned long *list,
1350                                unsigned long size);
1351 typedef char *(*userprompt_t) (void);
1352 typedef long (*append_t) (MAILSTREAM *stream,void *data,char **flags,
1353                           char **date,STRING **message);
1354 typedef void (*copyuid_t) (MAILSTREAM *stream,char *mailbox,
1355                            unsigned long uidvalidity,SEARCHSET *sourceset,
1356                            SEARCHSET *destset);
1357 typedef void (*appenduid_t) (char *mailbox,unsigned long uidvalidity,
1358                              SEARCHSET *set);
1359 typedef long (*dirfmttest_t) (char *name);
1360 typedef long (*scancontents_t) (char *name,char *contents,unsigned long csiz,
1361                                 unsigned long fsiz);
1362
1363 typedef void (*freeeltsparep_t) (void **sparep);
1364 typedef void (*freeenvelopesparep_t) (void **sparep);
1365 typedef void (*freebodysparep_t) (void **sparep);
1366 typedef void (*freestreamsparep_t) (void **sparep);
1367 typedef void *(*sslstart_t) (void *stream,char *host,unsigned long flags);
1368 typedef long (*sslcertificatequery_t) (char *reason,char *host,char *cert);
1369 typedef void (*sslfailure_t) (char *host,char *reason,unsigned long flags);
1370 typedef void (*logouthook_t) (void *data);
1371 typedef char *(*sslclientcert_t) (void);
1372 typedef char *(*sslclientkey_t) (void);
1373 \f
1374 /* Globals */
1375
1376 extern char *body_types[];      /* defined body type strings */
1377 extern char *body_encodings[];  /* defined body encoding strings */
1378 extern const char *days[];      /* day name strings */
1379 extern const char *months[];    /* month name strings */
1380 \f
1381 /* Threading */
1382
1383 /* Thread node */
1384
1385 #define THREADNODE struct thread_node
1386
1387 THREADNODE {
1388   unsigned long num;            /* message number */
1389   SORTCACHE *sc;                /* (internal use) sortcache entry */
1390   THREADNODE *branch;           /* branch at this point in tree */
1391   THREADNODE *next;             /* next node */
1392 };
1393
1394 typedef void (*threadresults_t) (MAILSTREAM *stream,THREADNODE *tree);
1395
1396
1397 /* Thread dispatch */
1398
1399 #define THREADER struct threader_list
1400
1401 THREADER {
1402   char *name;                   /* name of threader */
1403   THREADNODE *(*dispatch) (MAILSTREAM *stream,char *charset,SEARCHPGM *spg,
1404                            long flags,sorter_t sorter);
1405   THREADER *next;
1406 };
1407
1408
1409 /* Container for references threading */
1410
1411 typedef void ** container_t;
1412 \f
1413 /* Namespaces */
1414
1415 #define NAMESPACE struct mail_namespace
1416
1417 NAMESPACE {
1418   char *name;                   /* name of this namespace */
1419   int delimiter;                /* hierarchy delimiter */
1420   PARAMETER *param;             /* namespace parameters */
1421   NAMESPACE *next;              /* next namespace */
1422 };
1423
1424
1425 /* Authentication */
1426
1427 #define AUTHENTICATOR struct mail_authenticator
1428
1429 AUTHENTICATOR {
1430   long flags;                   /* authenticator flags */
1431   char *name;                   /* name of this authenticator */
1432   authcheck_t valid;            /* authenticator valid on this system */
1433   authclient_t client;          /* client function that supports it */
1434   authserver_t server;          /* server function that supports it */
1435   AUTHENTICATOR *next;          /* next authenticator */
1436 };
1437 \f
1438 /* Mail driver dispatch */
1439
1440 DRIVER {
1441   char *name;                   /* driver name */
1442   unsigned long flags;          /* driver flags */
1443   DRIVER *next;                 /* next driver */
1444                                 /* mailbox is valid for us */
1445   DRIVER *(*valid) (char *mailbox);
1446                                 /* manipulate driver parameters */
1447   void *(*parameters) (long function,void *value);
1448                                 /* scan mailboxes */
1449   void (*scan) (MAILSTREAM *stream,char *ref,char *pat,char *contents);
1450                                 /* list mailboxes */
1451   void (*list) (MAILSTREAM *stream,char *ref,char *pat);
1452                                 /* list subscribed mailboxes */
1453   void (*lsub) (MAILSTREAM *stream,char *ref,char *pat);
1454                                 /* subscribe to mailbox */
1455   long (*subscribe) (MAILSTREAM *stream,char *mailbox);
1456                                 /* unsubscribe from mailbox */
1457   long (*unsubscribe) (MAILSTREAM *stream,char *mailbox);
1458                                 /* create mailbox */
1459   long (*create) (MAILSTREAM *stream,char *mailbox);
1460                                 /* delete mailbox */
1461   long (*mbxdel) (MAILSTREAM *stream,char *mailbox);
1462                                 /* rename mailbox */
1463   long (*mbxren) (MAILSTREAM *stream,char *old,char *newname);
1464                                 /* status of mailbox */
1465   long (*status) (MAILSTREAM *stream,char *mbx,long flags);
1466 \f
1467                                 /* open mailbox */
1468   MAILSTREAM *(*open) (MAILSTREAM *stream);
1469                                 /* close mailbox */
1470   void (*close) (MAILSTREAM *stream,long options);
1471                                 /* fetch message "fast" attributes */
1472   void (*fast) (MAILSTREAM *stream,char *sequence,long flags);
1473                                 /* fetch message flags */
1474   void (*msgflags) (MAILSTREAM *stream,char *sequence,long flags);
1475                                 /* fetch message overview */
1476   long (*overview) (MAILSTREAM *stream,overview_t ofn);
1477                                 /* fetch message envelopes */
1478   ENVELOPE *(*structure) (MAILSTREAM *stream,unsigned long msgno,BODY **body,
1479                           long flags);
1480                                 /* return RFC-822 header */
1481   char *(*header) (MAILSTREAM *stream,unsigned long msgno,
1482                    unsigned long *length,long flags);
1483                                 /* return RFC-822 text */
1484   long (*text) (MAILSTREAM *stream,unsigned long msgno,STRING *bs,long flags);
1485                                 /* load cache */
1486   long (*msgdata) (MAILSTREAM *stream,unsigned long msgno,char *section,
1487                    unsigned long first,unsigned long last,STRINGLIST *lines,
1488                    long flags);
1489                                 /* return UID for message */
1490   unsigned long (*uid) (MAILSTREAM *stream,unsigned long msgno);
1491                                 /* return message number from UID */
1492   unsigned long (*msgno) (MAILSTREAM *stream,unsigned long uid);
1493                                 /* modify flags */
1494   void (*flag) (MAILSTREAM *stream,char *sequence,char *flag,long flags);
1495                                 /* per-message modify flags */
1496   void (*flagmsg) (MAILSTREAM *stream,MESSAGECACHE *elt);
1497                                 /* search for message based on criteria */
1498   long (*search) (MAILSTREAM *stream,char *charset,SEARCHPGM *pgm,long flags);
1499                                 /* sort messages */
1500   unsigned long *(*sort) (MAILSTREAM *stream,char *charset,SEARCHPGM *spg,
1501                           SORTPGM *pgm,long flags);
1502                                 /* thread messages */
1503   THREADNODE *(*thread) (MAILSTREAM *stream,char *type,char *charset,
1504                          SEARCHPGM *spg,long flag);
1505                                 /* ping mailbox to see if still alive */
1506   long (*ping) (MAILSTREAM *stream);
1507                                 /* check for new messages */
1508   void (*check) (MAILSTREAM *stream);
1509                                 /* expunge deleted messages */
1510   long (*expunge) (MAILSTREAM *stream,char *sequence,long options);
1511                                 /* copy messages to another mailbox */
1512   long (*copy) (MAILSTREAM *stream,char *sequence,char *mailbox,long options);
1513                                 /* append string message to mailbox */
1514   long (*append) (MAILSTREAM *stream,char *mailbox,append_t af,void *data);
1515                                 /* garbage collect stream */
1516   void (*gc) (MAILSTREAM *stream,long gcflags);
1517 };
1518
1519
1520 #include "linkage.h"
1521 \f
1522 /* Compatibility support names for old interfaces */
1523
1524 #define GET_TRYALTFIRST GET_TRYSSLFIRST
1525 #define SET_TRYALTFIRST SET_TRYSSLFIRST
1526 #define GET_IMAPTRYALT GET_IMAPTRYSSL
1527 #define SET_IMAPTRYALT SET_IMAPTRYSSL
1528 #define OP_TRYALT OP_TRYSSL
1529 #define altflag sslflag
1530
1531 #define mail_close(stream) \
1532   mail_close_full (stream,NIL)
1533 #define mail_fetchfast(stream,sequence) \
1534   mail_fetch_fast (stream,sequence,NIL)
1535 #define mail_fetchfast_full mail_fetch_fast
1536 #define mail_fetchflags(stream,sequence) \
1537   mail_fetch_flags (stream,sequence,NIL)
1538 #define mail_fetchflags_full mail_fetch_flags
1539 #ifdef __HEADER_OPTIMIZATION__
1540 #define mail_fetchenvelope(stream,msgno) \
1541   mail_fetch_structure (stream,msgno,NIL,NIL,0)
1542 #else
1543 #define mail_fetchenvelope(stream,msgno) \
1544   mail_fetch_structure (stream,msgno,NIL,NIL)
1545 #endif
1546 #ifdef __HEADER_OPTIMIZATION__
1547 #define mail_fetchstructure(stream,msgno,body) \
1548   mail_fetch_structure (stream,msgno,body,NIL,0)
1549 #else
1550 #define mail_fetchstructure(stream,msgno,body) \
1551   mail_fetch_structure (stream,msgno,body,NIL)
1552 #endif
1553 #define mail_fetchstructure_full mail_fetch_structure
1554 #define mail_fetchheader(stream,msgno) \
1555   mail_fetch_header (stream,msgno,NIL,NIL,NIL,FT_PEEK)
1556 #define mail_fetchheader_full(stream,msgno,lines,len,flags) \
1557   mail_fetch_header (stream,msgno,NIL,lines,len,FT_PEEK | (flags))
1558 #define mail_fetchtext(stream,msgno) \
1559   mail_fetch_text (stream,msgno,NIL,NIL,NIL)
1560 #define mail_fetchtext_full(stream,msgno,length,flags) \
1561   mail_fetch_text (stream,msgno,NIL,length,flags)
1562 #define mail_fetchbody(stream,msgno,section,length) \
1563   mail_fetch_body (stream,msgno,section,length,NIL)
1564 #define mail_fetchbody_full mail_fetch_body
1565 #define mail_setflag(stream,sequence,flag) \
1566   mail_flag (stream,sequence,flag,ST_SET)
1567 #define mail_setflag_full(stream,sequence,flag,flags) \
1568   mail_flag (stream,sequence,flag,ST_SET | (flags))
1569 #define mail_clearflag(stream,sequence,flag) \
1570   mail_flag (stream,sequence,flag,NIL)
1571 #define mail_clearflag_full mail_flag
1572 #define mail_search(stream,criteria) \
1573   mail_search_full (stream,NIL,mail_criteria (criteria),SE_FREE);
1574 #define mail_expunge(stream) \
1575   mail_expunge_full (stream,NIL,NIL)
1576 #define mail_copy(stream,sequence,mailbox) \
1577   mail_copy_full (stream,sequence,mailbox,NIL)
1578 #define mail_move(stream,sequence,mailbox) \
1579   mail_copy_full (stream,sequence,mailbox,CP_MOVE)
1580 #define mail_append(stream,mailbox,message) \
1581   mail_append_full (stream,mailbox,NIL,NIL,message)
1582 \f
1583 /* Interfaces for SVR4 locking brain-damage workaround */
1584
1585 /* Driver dispatching */
1586
1587 #define SAFE_DELETE(dtb,stream,mailbox) (*dtb->mbxdel) (stream,mailbox)
1588 #define SAFE_RENAME(dtb,stream,old,newname) (*dtb->mbxren) (stream,old,newname)
1589 #define SAFE_STATUS(dtb,stream,mbx,flags) (*dtb->status) (stream,mbx,flags)
1590 #define SAFE_COPY(dtb,stream,sequence,mailbox,options) \
1591   (*dtb->copy) (stream,sequence,mailbox,options)
1592 #define SAFE_APPEND(dtb,stream,mailbox,af,data) \
1593   (*dtb->append) (stream,mailbox,af,data)
1594 #define SAFE_SCAN_CONTENTS(dtb,name,contents,csiz,fsiz) \
1595   scan_contents (dtb,name,contents,csiz,fsiz)
1596
1597
1598 /* Driver callbacks */
1599
1600 #define MM_EXISTS mm_exists
1601 #define MM_EXPUNGED mm_expunged
1602 #define MM_FLAGS mm_flags
1603 #define MM_NOTIFY mm_notify
1604 #define MM_STATUS mm_status
1605 #define MM_LOG mm_log
1606 #define MM_CRITICAL mm_critical
1607 #define MM_NOCRITICAL mm_nocritical
1608 #define MM_DISKERROR mm_diskerror
1609 #define MM_FATAL mm_fatal
1610 #define MM_APPEND(af) (*af)
1611 \f
1612 /* Function prototypes */
1613
1614 void mm_searched (MAILSTREAM *stream,unsigned long number);
1615 void mm_exists (MAILSTREAM *stream,unsigned long number);
1616 void mm_expunged (MAILSTREAM *stream,unsigned long number);
1617 void mm_flags (MAILSTREAM *stream,unsigned long number);
1618 void mm_notify (MAILSTREAM *stream,char *string,long errflg);
1619 void mm_list (MAILSTREAM *stream,int delimiter,char *name,long attributes);
1620 void mm_lsub (MAILSTREAM *stream,int delimiter,char *name,long attributes);
1621 void mm_status (MAILSTREAM *stream,char *mailbox,MAILSTATUS *status);
1622 void mm_log (char *string,long errflg);
1623 void mm_dlog (char *string);
1624 void mm_login (NETMBX *mb,char *user,char *pwd,long trial);
1625 void mm_critical (MAILSTREAM *stream);
1626 void mm_nocritical (MAILSTREAM *stream);
1627 long mm_diskerror (MAILSTREAM *stream,long errcode,long serious);
1628 void mm_fatal (char *string);
1629 void *mm_cache (MAILSTREAM *stream,unsigned long msgno,long op);
1630
1631 extern STRINGDRIVER mail_string;
1632 void mail_versioncheck (char *version);
1633 void mail_link (DRIVER *driver);
1634 void *mail_parameters (MAILSTREAM *stream,long function,void *value);
1635 DRIVER *mail_valid (MAILSTREAM *stream,char *mailbox,char *purpose);
1636 DRIVER *mail_valid_net (char *name,DRIVER *drv,char *host,char *mailbox);
1637 long mail_valid_net_parse (char *name,NETMBX *mb);
1638 long mail_valid_net_parse_work (char *name,NETMBX *mb,char *service);
1639 void mail_scan (MAILSTREAM *stream,char *ref,char *pat,char *contents);
1640 void mail_list (MAILSTREAM *stream,char *ref,char *pat);
1641 void mail_lsub (MAILSTREAM *stream,char *ref,char *pat);
1642 long mail_subscribe (MAILSTREAM *stream,char *mailbox);
1643 long mail_unsubscribe (MAILSTREAM *stream,char *mailbox);
1644 long mail_create (MAILSTREAM *stream,char *mailbox);
1645 long mail_delete (MAILSTREAM *stream,char *mailbox);
1646 long mail_rename (MAILSTREAM *stream,char *old,char *newname);
1647 char *mail_utf7_valid (char *mailbox);
1648 long mail_status (MAILSTREAM *stream,char *mbx,long flags);
1649 long mail_status_default (MAILSTREAM *stream,char *mbx,long flags);
1650 MAILSTREAM *mail_open (MAILSTREAM *stream,char *name,long options);
1651 MAILSTREAM *mail_open_work (DRIVER *d,MAILSTREAM *stream,char *name,
1652                             long options);
1653 MAILSTREAM *mail_close_full (MAILSTREAM *stream,long options);
1654 MAILHANDLE *mail_makehandle (MAILSTREAM *stream);
1655 void mail_free_handle (MAILHANDLE **handle);
1656 MAILSTREAM *mail_stream (MAILHANDLE *handle);
1657 \f
1658 void mail_fetch_fast (MAILSTREAM *stream,char *sequence,long flags);
1659 void mail_fetch_flags (MAILSTREAM *stream,char *sequence,long flags);
1660 void mail_fetch_overview (MAILSTREAM *stream,char *sequence,overview_t ofn);
1661 void mail_fetch_overview_sequence (MAILSTREAM *stream,char *sequence,
1662                                    overview_t ofn);
1663 void mail_fetch_overview_default (MAILSTREAM *stream,overview_t ofn);
1664 #ifdef __HEADER_OPTIMIZATION__
1665 ENVELOPE *mail_fetch_structure (MAILSTREAM *stream,unsigned long msgno,
1666                                 BODY **body,long flags,int iDownload);
1667 #else
1668 ENVELOPE *mail_fetch_structure (MAILSTREAM *stream,unsigned long msgno,
1669                                 BODY **body,long flags);
1670 #endif
1671 char *mail_fetch_message (MAILSTREAM *stream,unsigned long msgno,
1672                           unsigned long *len,long flags);
1673 char *mail_fetch_header (MAILSTREAM *stream,unsigned long msgno,char *section,
1674                          STRINGLIST *lines,unsigned long *len,long flags);
1675 char *mail_fetch_text (MAILSTREAM *stream,unsigned long msgno,char *section,
1676                        unsigned long *len,long flags);
1677 char *mail_fetch_mime (MAILSTREAM *stream,unsigned long msgno,char *section,
1678                        unsigned long *len,long flags);
1679 char *mail_fetch_body (MAILSTREAM *stream,unsigned long msgno,char *section,
1680                        unsigned long *len,long flags);
1681 long mail_partial_text (MAILSTREAM *stream,unsigned long msgno,char *section,
1682                         unsigned long first,unsigned long last,long flags);
1683 long mail_partial_body (MAILSTREAM *stream,unsigned long msgno,char *section,
1684                         unsigned long first,unsigned long last,long flags);
1685 char *mail_fetch_text_return (GETS_DATA *md,SIZEDTEXT *t,unsigned long *len);
1686 char *mail_fetch_string_return (GETS_DATA *md,STRING *bs,unsigned long i,
1687                                 unsigned long *len,long flags);
1688 long mail_read (void *stream,unsigned long size,char *buffer);
1689 unsigned long mail_uid (MAILSTREAM *stream,unsigned long msgno);
1690 unsigned long mail_msgno (MAILSTREAM *stream,unsigned long uid);
1691 void mail_fetchfrom (char *s,MAILSTREAM *stream,unsigned long msgno,
1692                      long length);
1693 void mail_fetchsubject (char *s,MAILSTREAM *stream,unsigned long msgno,
1694                         long length);
1695 MESSAGECACHE *mail_elt (MAILSTREAM *stream,unsigned long msgno);
1696 void mail_flag (MAILSTREAM *stream,char *sequence,char *flag,long flags);
1697 long mail_search_full (MAILSTREAM *stream,char *charset,SEARCHPGM *pgm,
1698                        long flags);
1699 long mail_search_default (MAILSTREAM *stream,char *charset,SEARCHPGM *pgm,
1700                           long flags);
1701 long mail_ping (MAILSTREAM *stream);
1702 void mail_check (MAILSTREAM *stream);
1703 long mail_expunge_full (MAILSTREAM *stream,char *sequence,long options);
1704 long mail_copy_full (MAILSTREAM *stream,char *sequence,char *mailbox,
1705                      long options);
1706 long mail_append_full (MAILSTREAM *stream,char *mailbox,char *flags,char *date,
1707                        STRING *message);
1708 long mail_append_multiple (MAILSTREAM *stream,char *mailbox,append_t af,
1709                            void *data);
1710 void mail_gc (MAILSTREAM *stream,long gcflags);
1711 void mail_gc_msg (MESSAGE *msg,long gcflags);
1712 void mail_gc_body (BODY *body);
1713 \f
1714 BODY *mail_body (MAILSTREAM *stream,unsigned long msgno,
1715                  unsigned char *section);
1716 char *mail_date (char *string,MESSAGECACHE *elt);
1717 char *mail_cdate (char *string,MESSAGECACHE *elt);
1718 long mail_parse_date (MESSAGECACHE *elt,unsigned char *string);
1719 void mail_exists (MAILSTREAM *stream,unsigned long nmsgs);
1720 void mail_recent (MAILSTREAM *stream,unsigned long recent);
1721 void mail_expunged (MAILSTREAM *stream,unsigned long msgno);
1722 void mail_lock (MAILSTREAM *stream);
1723 void mail_unlock (MAILSTREAM *stream);
1724 void mail_debug (MAILSTREAM *stream);
1725 void mail_nodebug (MAILSTREAM *stream);
1726 void mail_dlog (char *string,long flag);
1727 long mail_match_lines (STRINGLIST *lines,STRINGLIST *msglines,long flags);
1728 unsigned long mail_filter (char *text,unsigned long len,STRINGLIST *lines,
1729                            long flags);
1730 long mail_search_msg (MAILSTREAM *stream,unsigned long msgno,char *section,
1731                       SEARCHPGM *pgm);
1732 long mail_search_header_text (char *s,STRINGLIST *st);
1733 long mail_search_header (SIZEDTEXT *hdr,STRINGLIST *st);
1734 long mail_search_text (MAILSTREAM *stream,unsigned long msgno,char *section,
1735                        STRINGLIST *st,long flags);
1736 long mail_search_body (MAILSTREAM *stream,unsigned long msgno,BODY *body,
1737                        char *prefix,unsigned long section,long flags);
1738 long mail_search_string (SIZEDTEXT *s,char *charset,STRINGLIST **st);
1739 long mail_search_string_work (SIZEDTEXT *s,STRINGLIST **st);
1740 long mail_search_keyword (MAILSTREAM *stream,MESSAGECACHE *elt,STRINGLIST *st,
1741                           long flag);
1742 long mail_search_addr (ADDRESS *adr,STRINGLIST *st);
1743 char *mail_search_gets (readfn_t f,void *stream,unsigned long size,
1744                         GETS_DATA *md);
1745 SEARCHPGM *mail_criteria (char *criteria);
1746 int mail_criteria_date (unsigned short *date,char **r);
1747 int mail_criteria_string (STRINGLIST **s,char **r);
1748 unsigned short mail_shortdate (unsigned int year,unsigned int month,
1749                                unsigned int day);
1750 SEARCHSET *mail_parse_set (char *s,char **ret);
1751 SEARCHSET *mail_append_set (SEARCHSET *set,unsigned long msgno);
1752 unsigned long *mail_sort (MAILSTREAM *stream,char *charset,SEARCHPGM *spg,
1753                           SORTPGM *pgm,long flags);
1754 unsigned long *mail_sort_cache (MAILSTREAM *stream,SORTPGM *pgm,SORTCACHE **sc,
1755                                 long flags);
1756 unsigned long *mail_sort_msgs (MAILSTREAM *stream,char *charset,SEARCHPGM *spg,
1757                                SORTPGM *pgm,long flags);
1758 SORTCACHE **mail_sort_loadcache (MAILSTREAM *stream,SORTPGM *pgm);
1759 unsigned int mail_strip_subject (char *t,char **ret);
1760 char *mail_strip_subject_wsp (char *s);
1761 char *mail_strip_subject_blob (char *s);
1762 int mail_sort_compare (const void *a1,const void *a2);
1763 unsigned long mail_longdate (MESSAGECACHE *elt);
1764 THREADNODE *mail_thread (MAILSTREAM *stream,char *type,char *charset,
1765                          SEARCHPGM *spg,long flags);
1766 THREADNODE *mail_thread_msgs (MAILSTREAM *stream,char *type,char *charset,
1767                               SEARCHPGM *spg,long flags,sorter_t sorter);
1768 THREADNODE *mail_thread_orderedsubject (MAILSTREAM *stream,char *charset,
1769                                         SEARCHPGM *spg,long flags,
1770                                         sorter_t sorter);
1771 THREADNODE *mail_thread_references (MAILSTREAM *stream,char *charset,
1772                                     SEARCHPGM *spg,long flags,
1773                                     sorter_t sorter);
1774 void mail_thread_loadcache (MAILSTREAM *stream,unsigned long uid,OVERVIEW *ov,
1775                             unsigned long msgno);
1776 char *mail_thread_parse_msgid (char *s,char **ss);
1777 STRINGLIST *mail_thread_parse_references (char *s,long flag);
1778 long mail_thread_check_child (container_t mother,container_t daughter);
1779 container_t mail_thread_prune_dummy (container_t msg,container_t ane);
1780 container_t mail_thread_prune_dummy_work (container_t msg,container_t ane);
1781 THREADNODE *mail_thread_c2node (MAILSTREAM *stream,container_t con,long flags);
1782 THREADNODE *mail_thread_sort (THREADNODE *thr,THREADNODE **tc);
1783 int mail_thread_compare_date (const void *a1,const void *a2);
1784 long mail_sequence (MAILSTREAM *stream,unsigned char *sequence);
1785 long mail_uid_sequence (MAILSTREAM *stream,unsigned char *sequence);
1786 long mail_parse_flags (MAILSTREAM *stream,char *flag,unsigned long *uf);
1787 long mail_usable_network_stream (MAILSTREAM *stream,char *name);
1788 \f
1789 MESSAGECACHE *mail_new_cache_elt (unsigned long msgno);
1790 ENVELOPE *mail_newenvelope (void);
1791 ADDRESS *mail_newaddr (void);
1792 BODY *mail_newbody (void);
1793 BODY *mail_initbody (BODY *body);
1794 PARAMETER *mail_newbody_parameter (void);
1795 PART *mail_newbody_part (void);
1796 MESSAGE *mail_newmsg (void);
1797 STRINGLIST *mail_newstringlist (void);
1798 SEARCHPGM *mail_newsearchpgm (void);
1799 SEARCHHEADER *mail_newsearchheader (char *line,char *text);
1800 SEARCHSET *mail_newsearchset (void);
1801 SEARCHOR *mail_newsearchor (void);
1802 SEARCHPGMLIST *mail_newsearchpgmlist (void);
1803 SORTPGM *mail_newsortpgm (void);
1804 THREADNODE *mail_newthreadnode (SORTCACHE *sc);
1805 ACLLIST *mail_newacllist (void);
1806 QUOTALIST *mail_newquotalist (void);
1807 void mail_free_body (BODY **body);
1808 void mail_free_body_data (BODY *body);
1809 void mail_free_body_parameter (PARAMETER **parameter);
1810 void mail_free_body_part (PART **part);
1811 void mail_free_cache (MAILSTREAM *stream);
1812 void mail_free_elt (MESSAGECACHE **elt);
1813 void mail_free_envelope (ENVELOPE **env);
1814 void mail_free_address (ADDRESS **address);
1815 void mail_free_stringlist (STRINGLIST **string);
1816 void mail_free_searchpgm (SEARCHPGM **pgm);
1817 void mail_free_searchheader (SEARCHHEADER **hdr);
1818 void mail_free_searchset (SEARCHSET **set);
1819 void mail_free_searchor (SEARCHOR **orl);
1820 void mail_free_searchpgmlist (SEARCHPGMLIST **pgl);
1821 void mail_free_namespace (NAMESPACE **n);
1822 void mail_free_sortpgm (SORTPGM **pgm);
1823 void mail_free_threadnode (THREADNODE **thr);
1824 void mail_free_acllist (ACLLIST **al);
1825 void mail_free_quotalist (QUOTALIST **ql);
1826 void auth_link (AUTHENTICATOR *auth);
1827 char *mail_auth (char *mechanism,authresponse_t resp,int argc,char *argv[]);
1828 AUTHENTICATOR *mail_lookup_auth (unsigned long i);
1829 unsigned int mail_lookup_auth_name (char *mechanism,long flags);
1830 \f
1831 NETSTREAM *net_open (NETMBX *mb,NETDRIVER *dv,unsigned long port,
1832                      NETDRIVER *ssld,char *ssls,unsigned long sslp);
1833 NETSTREAM *net_open_work (NETDRIVER *dv,char *host,char *service,
1834                           unsigned long port,unsigned long portoverride,
1835                           unsigned long flags);
1836 NETSTREAM *net_aopen (NETDRIVER *dv,NETMBX *mb,char *service,char *usrbuf);
1837 char *net_getline (NETSTREAM *stream);
1838                                 /* stream must be void* for use as readfn_t */
1839 long net_getbuffer (void *stream,unsigned long size,char *buffer);
1840 long net_soutr (NETSTREAM *stream,char *string);
1841 long net_sout (NETSTREAM *stream,char *string,unsigned long size);
1842 void net_close (NETSTREAM *stream);
1843 char *net_host (NETSTREAM *stream);
1844 char *net_remotehost (NETSTREAM *stream);
1845 unsigned long net_port (NETSTREAM *stream);
1846 char *net_localhost (NETSTREAM *stream);
1847
1848 long sm_subscribe (char *mailbox);
1849 long sm_unsubscribe (char *mailbox);
1850 char *sm_read (void **sdb);
1851
1852 void ssl_onceonlyinit (void);
1853 char *ssl_start_tls (char *s);
1854 void ssl_server_init (char *server);
1855
1856
1857 /* Server I/O functions */
1858
1859 int PBIN (void);
1860 char *PSIN (char *s,int n);
1861 long PSINR (char *s,unsigned long n);
1862 int PBOUT (int c);
1863 long INWAIT (long seconds);
1864 int PSOUT (char *s);
1865 int PSOUTR (SIZEDTEXT *s);
1866 int PFLUSH (void);