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