Merge branch 'topic/mdn'
[s-mailx.git] / nail.h
blob90da5fddd3dbcacb4d9982ddd0bf9cf16f299099
1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ Header inclusion, macros, constants, types and the global var declarations.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 - 2014 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
6 */
7 /*
8 * Copyright (c) 1980, 1993
9 * The Regents of the University of California. All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
41 * Mail -- a mail program
43 * Author: Kurt Shoens (UCB) March 25, 1978
46 #include "config.h"
48 #include <sys/stat.h>
49 #include <sys/types.h>
51 #include <errno.h>
52 #include <limits.h>
53 #include <setjmp.h>
54 #include <signal.h>
55 #include <stdarg.h>
56 #include <stdio.h>
57 #include <stdlib.h>
58 #include <string.h>
59 #include <termios.h>
60 #include <time.h>
61 #include <unistd.h>
63 #if defined __STDC_VERSION__ && __STDC_VERSION__ + 0 >= 199901L
64 # include <stdint.h>
65 #else
66 # include <inttypes.h>
67 #endif
69 #ifdef HAVE_C90AMEND1
70 # include <wchar.h>
71 # include <wctype.h>
72 #endif
73 #ifdef HAVE_DEBUG
74 # include <assert.h>
75 #endif
76 #ifdef HAVE_ICONV
77 # include <iconv.h>
78 #endif
79 #ifdef HAVE_REGEX
80 # include <regex.h>
81 #endif
83 #ifdef HAVE_OPENSSL_MD5
84 # include <openssl/md5.h>
85 #endif
88 * Constants, some nail-specific macros
91 #if !defined NI_MAXHOST || NI_MAXHOST < 1025
92 # undef NI_MAXHOST
93 # define NI_MAXHOST 1025
94 #endif
96 /* TODO PATH_MAX: fixed-size buffer is always wrong (think NFS) */
97 #ifndef PATH_MAX
98 # ifdef MAXPATHLEN
99 # define PATH_MAX MAXPATHLEN
100 # else
101 # define PATH_MAX 1024 /* _XOPEN_PATH_MAX POSIX 2008/Cor 1-2013 */
102 # endif
103 #endif
105 #ifndef STDIN_FILENO
106 # define STDIN_FILENO 0
107 #endif
108 #ifndef STDOUT_FILENO
109 # define STDOUT_FILENO 1
110 #endif
111 #ifndef STDERR_FILENO
112 # define STDERR_FILENO 2
113 #endif
115 #ifdef NSIG_MAX
116 # undef NSIG
117 # define NSIG NSIG_MAX
118 #elif !defined NSIG
119 # define NSIG ((sizeof(sigset_t) * 8) - 1)
120 #endif
122 /* */
124 #if BUFSIZ > 2560 /* TODO simply use BUFSIZ? */
125 # define LINESIZE BUFSIZ /* max readable line width */
126 #else
127 # define LINESIZE 2560
128 #endif
129 #define BUFFER_SIZE (BUFSIZ >= (1u << 13) ? BUFSIZ : (1u << 14))
131 #define CBAD (-15555)
132 #define APPEND /* New mail goes to end of mailbox */
133 #define ESCAPE '~' /* Default escape for sending */
134 #define FIO_STACK_SIZE 20 /* Maximum recursion for sourcing */
135 #define HIST_SIZE 242 /* tty.c: history list default size */
136 #define HSHSIZE 23 /* Hash prime (aliases, vars, macros) */
137 #define MAXARGC 1024 /* Maximum list of raw strings */
138 #define MAXEXP 25 /* Maximum expansion of aliases */
139 #define NYD_CALLS_MAX 1000 /* Number of NYD calls that are remembered */
140 #define PROMPT_BUFFER_SIZE 80 /* getprompt() bufsize (> 3!) */
142 #define ACCOUNT_NULL "null" /* Name of "null" account */
143 #define MAILRC "~/.mailrc"
144 #define NETRC "~/.netrc"
145 #define TMPDIR_FALLBACK "/tmp"
147 #undef COLOUR
148 #ifdef HAVE_COLOUR
149 # define COLOUR(X) X
150 #else
151 # define COLOUR(X)
152 #endif
153 #define COLOUR_MSGINFO "fg=green"
154 #define COLOUR_PARTINFO "fg=brown"
155 #define COLOUR_FROM_ "fg=brown"
156 #define COLOUR_HEADER "fg=red"
157 #define COLOUR_UHEADER "ft=bold,fg=red"
158 #define COLOUR_TERMS \
159 "cons25,linux,rxvt,rxvt-unicode,screen,sun,vt100,vt220,wsvt25,xterm"
160 #define COLOUR_USER_HEADERS "from,subject"
162 #define FROM_DATEBUF 64 /* Size of RFC 4155 From_ line date */
163 #define DATE_DAYSYEAR 365L
164 #define DATE_SECSMIN 60L
165 #define DATE_MINSHOUR 60L
166 #define DATE_HOURSDAY 24L
167 #define DATE_SECSDAY (DATE_SECSMIN * DATE_MINSHOUR * DATE_HOURSDAY)
169 /* *indentprefix* default as of POSIX */
170 #define INDENT_DEFAULT "\t"
172 /* Default *encoding* as enum conversion below */
173 #define MIME_DEFAULT_ENCODING CONV_TOQP
175 /* Maximum allowed line length in a mail before QP folding is necessary), and
176 * the real limit we go for */
177 #define MIME_LINELEN_MAX 1000
178 #define MIME_LINELEN_LIMIT (MIME_LINELEN_MAX - 50)
180 /* Locations of mime.types(5) */
181 #define MIME_TYPES_USR "~/.mime.types"
182 #define MIME_TYPES_SYS "/etc/mime.types"
184 /* Fallback MIME charsets, if *charset-7bit* and *charset-8bit* or not set */
185 #define CHARSET_7BIT "US-ASCII"
186 #ifdef HAVE_ICONV
187 # define CHARSET_8BIT "UTF-8"
188 # define CHARSET_8BIT_OKEY charset_8bit
189 #else
190 # define CHARSET_8BIT "ISO-8859-1"
191 # define CHARSET_8BIT_OKEY ttycharset
192 #endif
194 /* Is *W* a quoting (ASCII only) character? */
195 #define ISQUOTE(W) \
196 ((W) == L'>' || (W) == L'|' || (W) == L'}' || (W) == L':')
198 /* Maximum number of quote characters (not bytes!) that'll be used on
199 * follow lines when compressing leading quote characters */
200 #define QUOTE_MAX 42
202 /* How much spaces should a <tab> count when *quote-fold*ing? (power-of-two!) */
203 #define QUOTE_TAB_SPACES 8
205 /* Maximum size of a message that is passed through to the spam system */
206 #define SPAM_MAXSIZE 420000
208 /* String dope: dynamic buffer size, and size of the single builtin one that's
209 * used first */
210 #define SBUFFER_SIZE 0x18000u
211 #define SBUFFER_BUILTIN 0x2000u
213 /* These come from the configuration (named Xxy to not clash with sh(1)..) */
214 #ifndef XSHELL
215 # define XSHELL "/bin/sh"
216 #endif
217 #ifndef XLISTER
218 # define XLISTER "ls"
219 #endif
220 #ifndef XPAGER
221 # define XPAGER "more"
222 #endif
225 * CC support, generic macros etc.
228 #undef __PREREQ
229 #if defined __GNUC__ || defined __clang__
230 # define __EXTEN __extension__
231 # ifdef __GNUC__
232 # define __PREREQ(X,Y) \
233 (__GNUC__ > (X) || (__GNUC__ == (X) && __GNUC_MINOR__ >= (Y)))
234 # else
235 # define __PREREQ(X,Y) 1
236 # endif
237 #else
238 # define __EXTEN
239 # define __PREREQ(X,Y) 0
240 #endif
242 /* For injection macros like DBG(), NATCH_CHAR() */
243 #define COMMA ,
245 #define EMPTY_FILE(F) typedef int CONCAT(avoid_empty_file__, F);
247 /* Pointer to size_t */
248 #define PTR2SIZE(X) ((size_t)(uintptr_t)(X))
250 /* Pointer comparison (types from below) */
251 #define PTRCMP(A,C,B) ((uintptr_t)(A) C (uintptr_t)(B))
253 /* Ditto, compare (maybe mixed-signed) integers cases to T bits, unsigned;
254 * Note: doesn't sign-extend correctly, that's still up to the caller */
255 #define UICMP(T,A,C,B) ((ui ## T ## _t)(A) C (ui ## T ## _t)(B))
257 /* Members in constant array */
258 #ifndef NELEM
259 # define NELEM(A) (sizeof(A) / sizeof(A[0]))
260 #endif
262 /* sizeof() for member fields */
263 #define SIZEOF_FIELD(T,F) sizeof(((T *)NULL)->F)
265 /* Casts-away (*NOT* cast-away) */
266 #define UNUSED(X) ((void)(X))
267 #define UNCONST(P) ((void*)(uintptr_t)(void const*)(P))
268 #define UNVOLATILE(P) ((void*)(uintptr_t)(void volatile*)(P))
269 #define UNXXX(T,C,P) ((T)(uintptr_t)(C)(P))
271 /* __STDC_VERSION__ is ISO C99, so also use __STDC__, which should work */
272 #if defined __STDC__ || defined __STDC_VERSION__ /*|| defined __cplusplus*/
273 # define STRING(X) #X
274 # define XSTRING(X) STRING(X)
275 # define CONCAT(S1,S2) _CONCAT(S1, S2)
276 # define _CONCAT(S1,S2) S1 ## S2
277 #else
278 # define STRING(X) "X"
279 # define XSTRING STRING
280 # define CONCAT(S1,S2) S1/**/S2
281 #endif
283 #if defined __STDC_VERSION__ && __STDC_VERSION__ + 0 >= 199901L
284 /* Variable size arrays and structure fields */
285 # define VFIELD_SIZE(X)
286 # define VFIELD_SIZEOF(T,F) (0)
287 /* Inline functions */
288 # define HAVE_INLINE
289 # define INLINE inline
290 # define SINLINE static inline
291 #else
292 # define VFIELD_SIZE(X) (X)
293 # define VFIELD_SIZEOF(T,F) SIZEOF_FIELD(T, F)
294 # if __PREREQ(2, 9)
295 # define INLINE static __inline
296 # define SINLINE static __inline
297 # else
298 # define INLINE
299 # define SINLINE static
300 # endif
301 #endif
303 #undef __FUN__
304 #if defined __STDC_VERSION__ && __STDC_VERSION__ + 0 >= 199901L
305 # define __FUN__ __func__
306 #elif __PREREQ(3, 4)
307 # define __FUN__ __FUNCTION__
308 #else
309 # define __FUN__ uagent /* Something that is not a literal */
310 #endif
312 #if defined __predict_true && defined __predict_false
313 # define LIKELY(X) __predict_true(X)
314 # define UNLIKELY(X) __predict_false(X)
315 #elif __PREREQ(2, 96)
316 # define LIKELY(X) __builtin_expect(X, 1)
317 # define UNLIKELY(X) __builtin_expect(X, 0)
318 #else
319 # define LIKELY(X) (X)
320 # define UNLIKELY(X) (X)
321 #endif
323 #undef HAVE_NATCH_CHAR
324 #undef NATCH_CHAR
325 #if defined HAVE_SETLOCALE && defined HAVE_C90AMEND1 && defined HAVE_WCWIDTH
326 # define HAVE_NATCH_CHAR
327 # define NATCH_CHAR(X) X
328 #else
329 # define NATCH_CHAR(X)
330 #endif
332 /* Compile-Time-Assert */
333 #define CTA(TEST) _CTA_1(TEST, __LINE__)
334 #define _CTA_1(TEST,L) _CTA_2(TEST, L)
335 #define _CTA_2(TEST,L) \
336 typedef char COMPILE_TIME_ASSERT_failed_at_line_ ## L[(TEST) ? 1 : -1]
338 #undef ISPOW2
339 #define ISPOW2(X) ((((X) - 1) & (X)) == 0)
340 #undef MIN
341 #define MIN(A, B) ((A) < (B) ? (A) : (B))
342 #undef MAX
343 #define MAX(A, B) ((A) < (B) ? (B) : (A))
344 #undef ABS
345 #define ABS(A) ((A) < 0 ? -(A) : (A))
347 #undef DBG
348 #undef NDBG
349 #ifndef HAVE_DEBUG
350 # undef assert
351 # define assert(X) UNUSED(0)
352 # define DBG(X)
353 # define NDBG(X) X
354 #else
355 # define DBG(X) X
356 # define NDBG(X)
357 #endif
359 /* Translation (init in main.c) */
360 #undef tr
361 #undef _
362 #undef N_
363 #undef V_
364 #ifdef HAVE_CATGETS
365 # define CATSET 1
366 # define tr(c,d) catgets(catd, CATSET, c, d)
367 #else
368 # define tr(c,d) (d)
369 #endif
370 #define _(S) (S)
371 #define N_(S) (S)
372 #define V_(S) (S)
375 * Types
378 typedef unsigned long ul_it;
379 typedef unsigned int ui_it;
380 typedef unsigned short us_it;
381 typedef unsigned char uc_it;
383 typedef signed long sl_it;
384 typedef signed int si_it;
385 typedef signed short ss_it;
386 typedef signed char sc_it;
388 #ifdef UINT8_MAX
389 # define UI8_MAX UINT8_MAX
390 # define SI8_MIN INT8_MIN
391 # define SI8_MAX INT8_MAX
392 typedef uint8_t ui8_t;
393 typedef int8_t si8_t;
394 #elif UCHAR_MAX != 255
395 # error UCHAR_MAX must be 255
396 #else
397 # define UI8_MAX UCHAR_MAX
398 # define SI8_MIN CHAR_MIN
399 # define SI8_MAX CHAR_MAX
400 typedef unsigned char ui8_t;
401 typedef signed char si8_t;
402 #endif
404 #ifdef UINT16_MAX
405 # define UI16_MAX UINT16_MAX
406 # define SI16_MIN INT16_MIN
407 # define SI16_MAX INT16_MAX
408 typedef uint16_t ui16_t;
409 typedef int16_t si16_t;
410 #elif USHRT_MAX != 0xFFFFu
411 # error USHRT_MAX must be 0xFFFF
412 #else
413 # define UI16_MAX USHRT_MAX
414 # define SI16_MIN SHRT_MIN
415 # define SI16_MAX SHRT_MAX
416 typedef unsigned short ui16_t;
417 typedef signed short si16_t;
418 #endif
420 #ifdef UINT32_MAX
421 # define UI32_MAX UINT32_MAX
422 # define SI32_MIN INT32_MIN
423 # define SI32_MAX INT32_MAX
424 typedef uint32_t ui32_t;
425 typedef int32_t si32_t;
426 #elif ULONG_MAX == 0xFFFFFFFFu
427 # define UI32_MAX ULONG_MAX
428 # define SI32_MIN LONG_MIN
429 # define SI32_MAX LONG_MAX
430 typedef unsigned long int ui32_t;
431 typedef signed long int si32_t;
432 #elif UINT_MAX != 0xFFFFFFFFu
433 # error UINT_MAX must be 0xFFFFFFFF
434 #else
435 # define UI32_MAX UINT_MAX
436 # define SI32_MIN INT_MIN
437 # define SI32_MAX INT_MAX
438 typedef unsigned int ui32_t;
439 typedef signed int si32_t;
440 #endif
442 #ifdef UINT64_MAX
443 # define UI64_MAX UINT64_MAX
444 # define SI64_MIN INT64_MIN
445 # define SI64_MAX INT64_MAX
446 typedef uint64_t ui64_t;
447 #elif ULONG_MAX <= 0xFFFFFFFFu
448 # if !defined ULLONG_MAX || ULLONG_MAX != 0xFFFFFFFFFFFFFFFFu
449 # error We need a 64 bit integer
450 # else
451 # define UI64_MAX ULLONG_MAX
452 # define SI64_MIN LLONG_MIN
453 # define SI64_MAX LLONG_MAX
454 __EXTEN typedef unsigned long long ui64_t;
455 __EXTEN typedef signed long long si64_t;
456 # endif
457 #else
458 # define UI64_MAX ULONG_MAX
459 # define SI64_MIN LONG_MIN
460 # define SI64_MAX LONG_MAX
461 typedef unsigned long ui64_t;
462 typedef signed long si64_t;
463 #endif
465 /* (So that we can use UICMP() for size_t comparison, too) */
466 typedef size_t uiz_t;
467 typedef ssize_t siz_t;
469 #ifndef UINTPTR_MAX
470 # ifdef SIZE_MAX
471 # define uintptr_t size_t
472 # define UINTPTR_MAX SIZE_MAX
473 # else
474 # define uintptr_t unsigned long
475 # define UINTPTR_MAX ULONG_MAX
476 # endif
477 #endif
479 /* XXX Note we don't really deal with that the right way in that we pass size_t
480 * XXX arguments without casting; should do, because above we assert UINT_MAX
481 * XXX is indeed ui32_t -- CTAsserted in main.c */
482 #if defined __STDC_VERSION__ && __STDC_VERSION__ + 0 >= 199901L
483 # define ZFMT "zu"
484 # define __ZFMT_CTA() CTA(1 == 1)
485 #elif defined SIZE_MAX && SIZE_MAX == 0xFFFFFFFFu && ULONG_MAX != UINT_MAX
486 # define ZFMT "u"
487 # define __ZFMT_CTA() CTA(sizeof(size_t) == sizeof(unsigned int))
488 #endif
489 #ifndef ZFMT
490 # define ZFMT "lu"
491 # define __ZFMT_CTA() CTA(sizeof(size_t) == sizeof(unsigned long))
492 #endif
494 enum {FAL0, TRU1};
495 typedef si8_t bool_t;
497 typedef void ( *sighandler_type)(int);
499 enum user_options {
500 OPT_NONE,
501 OPT_DEBUG = 1u<< 0, /* -d / *debug* */
502 OPT_VERB = 1u<< 1, /* -v / *verbose* */
503 OPT_VERBVERB = 1u<<19, /* .. even more verbosity */
504 OPT_EXISTONLY = 1u<< 2, /* -e */
505 OPT_HEADERSONLY = 1u<< 3, /* -H */
506 OPT_HEADERLIST = 1u<< 4, /* -L */
507 OPT_NOSRC = 1u<< 5, /* -n */
508 OPT_E_FLAG = 1u<< 6, /* -E / *skipemptybody* */
509 OPT_F_FLAG = 1u<< 7, /* -F */
510 OPT_N_FLAG = 1u<< 8, /* -N / *header* */
511 OPT_R_FLAG = 1u<< 9, /* -R */
512 OPT_r_FLAG = 1u<<10, /* -r (plus option_r_arg) */
513 OPT_t_FLAG = 1u<<11, /* -t */
514 OPT_u_FLAG = 1u<<12, /* -u given, or USER != getpwnam(3) */
515 OPT_TILDE_FLAG = 1u<<13, /* -~ */
516 OPT_BATCH_FLAG = 1u<<14, /* -# */
518 OPT_SENDMODE = 1u<<15, /* Usage case forces send mode */
519 OPT_INTERACTIVE = 1u<<16, /* isatty(0) */
520 OPT_TTYIN = OPT_INTERACTIVE,
521 OPT_TTYOUT = 1u<<17,
522 OPT_UNICODE = 1u<<18, /* We're in an UTF-8 environment */
524 /* Some easy-access shortcuts */
525 OPT_D_V = OPT_DEBUG | OPT_VERB,
526 OPT_D_VV = OPT_DEBUG | OPT_VERBVERB
528 #define IS_TTY_SESSION() \
529 ((options & (OPT_TTYIN | OPT_TTYOUT)) == (OPT_TTYIN | OPT_TTYOUT))
531 enum exit_status {
532 EXIT_OK = EXIT_SUCCESS,
533 EXIT_ERR = EXIT_FAILURE,
534 EXIT_USE = 2,
535 EXIT_COLL_ABORT = 1<<1, /* Message collection was aborted */
536 EXIT_SEND_ERROR = 1<<2 /* Unspecified send error occurred */
539 enum fexp_mode {
540 FEXP_FULL, /* Full expansion */
541 FEXP_LOCAL = 1<<0, /* Result must be local file/maildir */
542 FEXP_SHELL = 1<<1, /* No folder %,#,&,+ stuff, yet sh(1) */
543 FEXP_NSHORTCUT = 1<<2, /* Don't expand shortcuts */
544 FEXP_SILENT = 1<<3, /* Don't print but only return errors */
545 FEXP_MULTIOK = 1<<4 /* Expansion to many entries is ok */
548 enum flock_type {
549 FLOCK_READ,
550 FLOCK_WRITE,
551 FLOCK_UNLOCK
554 /* <0 means "stop" unless *prompt* extensions are enabled. */
555 enum prompt_exp {
556 PROMPT_STOP = -1, /* \c */
557 /* *prompt* extensions: \$, \@ etc. */
558 PROMPT_DOLLAR = -2,
559 PROMPT_AT = -3
562 enum colourspec {
563 COLOURSPEC_MSGINFO,
564 COLOURSPEC_PARTINFO,
565 COLOURSPEC_FROM_,
566 COLOURSPEC_HEADER,
567 COLOURSPEC_UHEADER,
568 COLOURSPEC_RESET
571 enum okay {
572 STOP = 0,
573 OKAY = 1
576 enum mimeenc {
577 MIME_NONE, /* message is not in MIME format */
578 MIME_BIN, /* message is in binary encoding */
579 MIME_8B, /* message is in 8bit encoding */
580 MIME_7B, /* message is in 7bit encoding */
581 MIME_QP, /* message is quoted-printable */
582 MIME_B64 /* message is in base64 encoding */
585 enum conversion {
586 CONV_NONE, /* no conversion */
587 CONV_7BIT, /* no conversion, is 7bit */
588 CONV_FROMQP, /* convert from quoted-printable */
589 CONV_TOQP, /* convert to quoted-printable */
590 CONV_8BIT, /* convert to 8bit (iconv) */
591 CONV_FROMB64, /* convert from base64 */
592 CONV_FROMB64_T, /* convert from base64/text */
593 CONV_TOB64, /* convert to base64 */
594 CONV_FROMHDR, /* convert from RFC1522 format */
595 CONV_TOHDR, /* convert to RFC1522 format */
596 CONV_TOHDR_A /* convert addresses for header */
599 enum sendaction {
600 SEND_MBOX, /* no conversion to perform */
601 SEND_RFC822, /* no conversion, no From_ line */
602 SEND_TODISP, /* convert to displayable form */
603 SEND_TODISP_ALL, /* same, include all MIME parts */
604 SEND_SHOW, /* convert to 'show' command form */
605 SEND_TOSRCH, /* convert for IMAP SEARCH */
606 SEND_TOFLTR, /* convert for spam mail filtering */
607 SEND_TOFILE, /* convert for saving body to a file */
608 SEND_TOPIPE, /* convert for pipe-content/subc. */
609 SEND_QUOTE, /* convert for quoting */
610 SEND_QUOTE_ALL, /* same, include all MIME parts */
611 SEND_DECRYPT /* decrypt */
614 enum mimecontent {
615 MIME_UNKNOWN, /* unknown content */
616 MIME_SUBHDR, /* inside a multipart subheader */
617 MIME_822, /* message/rfc822 content */
618 MIME_MESSAGE, /* other message/ content */
619 MIME_TEXT_PLAIN, /* text/plain content */
620 MIME_TEXT_HTML, /* text/html content */
621 MIME_TEXT, /* other text/ content */
622 MIME_ALTERNATIVE, /* multipart/alternative content */
623 MIME_DIGEST, /* multipart/digest content */
624 MIME_MULTI, /* other multipart/ content */
625 MIME_PKCS7, /* PKCS7 content */
626 MIME_DISCARD /* content is discarded */
629 /* Content-Transfer-Encodings as defined in RFC 2045:
630 * - Quoted-Printable, section 6.7
631 * - Base64, section 6.8 */
632 #define QP_LINESIZE (4 * 19) /* Max. compliant QP linesize */
634 #define B64_LINESIZE (4 * 19) /* Max. compliant Base64 linesize */
635 #define B64_ENCODE_INPUT_PER_LINE 57 /* Max. input for Base64 encode/line */
637 /* xxx QP came later, maybe rewrite all to use mimecte_flags directly? */
638 enum __mimecte_flags {
639 MIMECTE_NONE,
640 MIMECTE_SALLOC = 1<<0, /* Use salloc(), not srealloc().. */
641 /* ..result .s,.l point to user buffer of *_LINESIZE+[+[+]] bytes instead */
642 MIMECTE_BUF = 1<<1,
643 MIMECTE_CRLF = 1<<2, /* (encode) Append "\r\n" to lines */
644 MIMECTE_LF = 1<<3, /* (encode) Append "\n" to lines */
645 /* (encode) If one of _CRLF/_LF is set, honour *_LINESIZE+[+[+]] and
646 * inject the desired line-ending whenever a linewrap is desired */
647 MIMECTE_MULTILINE = 1<<4,
648 /* (encode) Quote with header rules, do not generate soft NL breaks? */
649 MIMECTE_ISHEAD = 1<<5
652 enum qpflags {
653 QP_NONE = MIMECTE_NONE,
654 QP_SALLOC = MIMECTE_SALLOC,
655 QP_BUF = MIMECTE_BUF,
656 QP_ISHEAD = MIMECTE_ISHEAD
659 enum b64flags {
660 B64_NONE = MIMECTE_NONE,
661 B64_SALLOC = MIMECTE_SALLOC,
662 B64_BUF = MIMECTE_BUF,
663 B64_CRLF = MIMECTE_CRLF,
664 B64_LF = MIMECTE_LF,
665 B64_MULTILINE = MIMECTE_MULTILINE
668 enum oflags {
669 OF_RDONLY = 1<<0,
670 OF_WRONLY = 1<<1,
671 OF_RDWR = 1<<2,
672 OF_APPEND = 1<<3,
673 OF_CREATE = 1<<4,
674 OF_TRUNC = 1<<5,
675 OF_EXCL = 1<<6,
676 OF_CLOEXEC = 1<<7,
677 OF_UNLINK = 1<<8, /* Only for Ftmp(): unlink(2) after creation */
678 OF_HOLDSIGS = 1<<9, /* Mutual with OF_UNLINK - await Ftmp_free() */
679 OF_REGISTER = 1<<10 /* Register file in our file table */
682 enum tdflags {
683 TD_NONE, /* no display conversion */
684 TD_ISPR = 1<<0, /* use isprint() checks */
685 TD_ICONV = 1<<1, /* use iconv() */
686 TD_DELCTRL = 1<<2, /* delete control characters */
689 * NOTE: _TD_EOF and _TD_BUFCOPY may be ORd with enum conversion and
690 * enum sendaction, and may thus NOT clash with their bit range!
692 _TD_EOF = 1<<14, /* EOF seen, last round! */
693 _TD_BUFCOPY = 1<<15 /* Buffer may be constant, copy it */
696 enum protocol {
697 PROTO_FILE, /* refers to a local file */
698 PROTO_POP3, /* is a pop3 server string */
699 PROTO_IMAP, /* is an imap server string */
700 PROTO_MAILDIR, /* refers to a maildir folder */
701 PROTO_UNKNOWN /* unknown protocol */
704 enum cproto {
705 CPROTO_SMTP,
706 CPROTO_POP3,
707 CPROTO_IMAP
710 enum authtype {
711 AUTHTYPE_NONE = 1<<0,
712 AUTHTYPE_PLAIN = 1<<1, /* POP3: APOP is covered by this */
713 AUTHTYPE_LOGIN = 1<<2,
714 AUTHTYPE_CRAM_MD5 = 1<<3,
715 AUTHTYPE_GSSAPI = 1<<4
718 #ifdef HAVE_SSL
719 enum ssl_verify_level {
720 SSL_VERIFY_IGNORE,
721 SSL_VERIFY_WARN,
722 SSL_VERIFY_ASK,
723 SSL_VERIFY_STRICT
725 #endif
727 /* A large enum with all the binary and value options a.k.a their keys.
728 * Only the constant keys are in here, to be looked up via ok_[bv]look(),
729 * ok_[bv]set() and ok_[bv]clear().
730 * Note: see the comments in accmacvar.c before changing *anything* in here! */
731 enum okeys {
732 /* Option keys for binary options */
733 ok_b_add_file_recipients,
734 ok_b_allnet,
735 ok_b_append,
736 ok_b_ask,
737 ok_b_askatend,
738 ok_b_askattach,
739 ok_b_askbcc,
740 ok_b_askcc,
741 ok_b_asksign,
742 ok_b_asksub,
743 ok_b_attachment_ask_content_description,
744 ok_b_attachment_ask_content_disposition,
745 ok_b_attachment_ask_content_id,
746 ok_b_attachment_ask_content_type,
747 ok_b_autocollapse,
748 ok_b_autoprint,
749 ok_b_autothread,
750 ok_b_bang,
751 ok_b_batch_exit_on_error,
752 ok_b_bsdannounce,
753 ok_b_bsdcompat,
754 ok_b_bsdflags,
755 ok_b_bsdheadline,
756 ok_b_bsdmsgs,
757 ok_b_bsdorder,
758 ok_b_bsdset,
759 ok_b_colour_disable,
760 ok_b_colour_pager,
761 ok_b_debug, /* {special=1} */
762 ok_b_disconnected,
763 ok_b_disposition_notification_send,
764 ok_b_dot,
765 ok_b_editalong,
766 ok_b_editheaders,
767 ok_b_emptybox,
768 ok_b_emptystart,
769 ok_b_flipr,
770 ok_b_forward_as_attachment,
771 ok_b_fullnames,
772 ok_b_header, /* {special=1} */
773 ok_b_history_gabby,
774 ok_b_history_gabby_persist,
775 ok_b_hold,
776 ok_b_idna_disable,
777 ok_b_ignore,
778 ok_b_ignoreeof,
779 ok_b_imap_use_starttls,
780 ok_b_keep,
781 ok_b_keep_content_length,
782 ok_b_keepsave,
783 ok_b_line_editor_disable,
784 ok_b_markanswered,
785 ok_b_message_id_disable,
786 ok_b_metoo,
787 ok_b_mime_allow_text_controls,
788 ok_b_mime_counter_evidence,
789 ok_b_netrc_lookup,
790 ok_b_outfolder,
791 ok_b_page,
792 ok_b_piperaw,
793 ok_b_pop3_bulk_load,
794 ok_b_pop3_no_apop,
795 ok_b_pop3_use_starttls,
796 ok_b_print_all_chars,
797 ok_b_print_alternatives,
798 ok_b_quiet,
799 ok_b_quote_as_attachment,
800 ok_b_recipients_in_cc,
801 ok_b_record_resent,
802 ok_b_reply_in_same_charset,
803 ok_b_Replyall,
804 ok_b_rfc822_body_from_, /* {name=rfc822-body-from_} */
805 ok_b_save,
806 ok_b_searchheaders,
807 ok_b_sendcharsets_else_ttycharset,
808 ok_b_sendwait,
809 ok_b_showlast,
810 ok_b_showname,
811 ok_b_showto,
812 ok_b_skipemptybody, /* {special=1} */
813 ok_b_smime_force_encryption,
814 ok_b_smime_no_default_ca,
815 ok_b_smime_sign,
816 ok_b_smtp_use_starttls,
817 ok_b_ssl_no_default_ca,
818 ok_b_ssl_v2_allow,
819 ok_b_v15_compat,
820 ok_b_verbose, /* {special=1} */
821 ok_b_writebackedited,
823 /* Option keys for values options */
824 ok_v_attrlist,
825 ok_v_autobcc,
826 ok_v_autocc,
827 ok_v_autosort,
828 ok_v_charset_7bit,
829 ok_v_charset_8bit,
830 ok_v_cmd,
831 ok_v_colour_from_, /* {name=colour-from_} */
832 ok_v_colour_header,
833 ok_v_colour_msginfo,
834 ok_v_colour_partinfo,
835 ok_v_colour_terms,
836 ok_v_colour_uheader,
837 ok_v_colour_user_headers,
838 ok_v_crt,
839 ok_v_datefield,
840 ok_v_datefield_markout_older,
841 ok_v_DEAD,
842 ok_v_EDITOR,
843 ok_v_encoding,
844 ok_v_escape,
845 ok_v_folder, /* {special=1} */
846 ok_v_folder_hook,
847 ok_v_from,
848 ok_v_fwdheading,
849 ok_v_headline,
850 ok_v_headline_bidi,
851 ok_v_hostname,
852 ok_v_imap_auth,
853 ok_v_imap_cache,
854 ok_v_imap_keepalive,
855 ok_v_imap_list_depth,
856 ok_v_indentprefix,
857 ok_v_line_editor_cursor_right, /* {special=1} */
858 ok_v_LISTER,
859 ok_v_MAIL,
860 ok_v_MBOX,
861 /* TODO v15-compat: mimetypes-load-control -> mimetypes-load / mimetypes */
862 ok_v_mimetypes_load_control,
863 ok_v_NAIL_EXTRA_RC, /* {name=NAIL_EXTRA_RC} */
864 /* TODO v15-compat: NAIL_HEAD -> message-head? */
865 ok_v_NAIL_HEAD, /* {name=NAIL_HEAD} */
866 /* TODO v15-compat: NAIL_HISTFILE -> history-file */
867 ok_v_NAIL_HISTFILE, /* {name=NAIL_HISTFILE} */
868 /* TODO v15-compat: NAIL_HISTSIZE -> history-size{,limit} */
869 ok_v_NAIL_HISTSIZE, /* {name=NAIL_HISTSIZE} */
870 /* TODO v15-compat: NAIL_TAIL -> message-tail? */
871 ok_v_NAIL_TAIL, /* {name=NAIL_TAIL} */
872 ok_v_newfolders,
873 ok_v_newmail,
874 ok_v_ORGANIZATION,
875 ok_v_PAGER,
876 ok_v_pop3_keepalive,
877 ok_v_prompt,
878 ok_v_quote,
879 ok_v_quote_fold,
880 ok_v_record,
881 ok_v_replyto,
882 ok_v_screen,
883 ok_v_sendcharsets,
884 ok_v_sender,
885 ok_v_sendmail,
886 ok_v_sendmail_arguments,
887 ok_v_sendmail_progname,
888 ok_v_SHELL,
889 ok_v_Sign,
890 ok_v_sign,
891 ok_v_signature,
892 ok_v_smime_ca_dir,
893 ok_v_smime_ca_file,
894 ok_v_smime_crl_dir,
895 ok_v_smime_crl_file,
896 ok_v_smime_sign_cert,
897 ok_v_smime_sign_include_certs,
898 ok_v_smtp,
899 /* TODO v15-compat: smtp-auth: drop */
900 ok_v_smtp_auth,
901 ok_v_smtp_auth_password,
902 ok_v_smtp_auth_user,
903 ok_v_smtp_hostname,
904 ok_v_spam_command,
905 ok_v_spam_host,
906 ok_v_spam_maxsize,
907 ok_v_spam_port,
908 ok_v_spam_socket,
909 ok_v_spam_user,
910 ok_v_ssl_ca_dir,
911 ok_v_ssl_ca_file,
912 ok_v_ssl_cert,
913 ok_v_ssl_cipher_list,
914 ok_v_ssl_crl_dir,
915 ok_v_ssl_crl_file,
916 ok_v_ssl_key,
917 ok_v_ssl_method,
918 ok_v_ssl_rand_egd,
919 ok_v_ssl_rand_file,
920 ok_v_ssl_verify,
921 ok_v_stealthmua,
922 ok_v_toplines,
923 ok_v_ttycharset,
924 ok_v_user,
925 ok_v_VISUAL
928 enum okey_xlook_mode {
929 OXM_PLAIN = 1<<0, /* Plain key always tested */
930 OXM_H_P = 1<<1, /* Check PLAIN-.url_h_p */
931 OXM_U_H_P = 1<<2, /* Check PLAIN-.url_u_h_p */
932 OXM_ALL = 0x7
935 /* Locale-independent character classes */
936 enum {
937 C_CNTRL = 0000,
938 C_BLANK = 0001,
939 C_WHITE = 0002,
940 C_SPACE = 0004,
941 C_PUNCT = 0010,
942 C_OCTAL = 0020,
943 C_DIGIT = 0040,
944 C_UPPER = 0100,
945 C_LOWER = 0200
948 struct str {
949 char *s; /* the string's content */
950 size_t l; /* the stings's length */
953 struct colour_table {
954 /* Plus a copy of *colour-user-headers* */
955 struct str ct_csinfo[COLOURSPEC_RESET+1 + 1];
958 struct bidi_info {
959 struct str bi_start; /* Start of (possibly) bidirectional text */
960 struct str bi_end; /* End of ... */
961 size_t bi_pad; /* No of visual columns to reserve for BIDI pad */
964 struct url {
965 char const *url_input; /* Input as given (really) */
966 enum cproto url_cproto; /* Communication protocol as given */
967 bool_t url_needs_tls; /* Wether the protocol uses SSL/TLS */
968 bool_t url_had_user; /* Wether .url_user was part of the URL */
969 ui16_t url_portno; /* atoi .url_port or default, host endian */
970 char const *url_port; /* Port (if given) or NULL */
971 char url_proto[14]; /* Communication protocol as 'xy\0//' */
972 ui8_t url_proto_len; /* Length of .url_proto ('\0' index) */
973 ui8_t url_proto_xlen; /* .. if '\0' is replaced with ':' */
974 struct str url_user; /* User, exactly as given / looked up */
975 struct str url_user_enc; /* User, urlxenc()oded */
976 struct str url_pass; /* Pass (urlxdec()oded) or NULL */
977 struct str url_host; /* Service hostname */
978 struct str url_path; /* CPROTO_IMAP: path suffix or NULL */
979 /* TODO: url_get_component(url *, enum COMPONENT, str *store) */
980 struct str url_h_p; /* .url_host[:.url_port] */
981 /* .url_user@.url_host
982 * Note: for CPROTO_SMTP this may resolve HOST via *smtp-hostname* (->
983 * *hostname*)! (And may later be overwritten according to *from*!) */
984 struct str url_u_h;
985 struct str url_u_h_p; /* .url_user@.url_host[:.url_port] */
986 struct str url_eu_h_p; /* .url_user_enc@.url_host[:.url_port] */
987 char const *url_p_u_h_p; /* .url_proto://.url_u_h_p */
988 char const *url_p_eu_h_p; /* .url_proto://.url_eu_h_p */
989 char const *url_p_eu_h_p_p; /* .url_proto://.url_eu_h_p[/.url_path] */
992 struct ccred {
993 enum cproto cc_cproto; /* Communication protocol */
994 enum authtype cc_authtype; /* Desired authentication */
995 char const *cc_auth; /* Authentication type as string */
996 struct str cc_user; /* User (urlxdec()oded) or NULL */
997 struct str cc_pass; /* Password (urlxdec()oded) or NULL */
1000 struct time_current {
1001 time_t tc_time;
1002 struct tm tc_gm;
1003 struct tm tc_local;
1004 char tc_ctime[32];
1007 struct quoteflt {
1008 FILE *qf_os; /* Output stream */
1009 char const *qf_pfix;
1010 ui32_t qf_pfix_len; /* Length of prefix: 0: bypass */
1011 ui32_t qf_qfold_min; /* Simple way: wrote prefix? */
1012 #ifdef HAVE_QUOTE_FOLD
1013 ui32_t qf_qfold_max; /* Otherwise: line lengths */
1014 ui8_t qf_state; /* *quote-fold* state machine */
1015 bool_t qf_brk_isws; /* Breakpoint is at WS */
1016 ui8_t __dummy[2];
1017 ui32_t qf_wscnt; /* Whitespace count */
1018 ui32_t qf_brkl; /* Breakpoint */
1019 ui32_t qf_brkw; /* Visual width, breakpoint */
1020 ui32_t qf_datw; /* Current visual output line width */
1021 struct str qf_dat; /* Current visual output line */
1022 struct str qf_currq; /* Current quote, compressed */
1023 mbstate_t qf_mbps[2];
1024 #endif
1027 struct search_expr {
1028 char const *ss_where; /* to search for the expression (not always used) */
1029 char const *ss_sexpr; /* String search expression; NULL: use .ss_reexpr */
1030 #ifdef HAVE_REGEX
1031 regex_t ss_reexpr;
1032 #endif
1035 struct eval_ctx {
1036 struct str ev_line; /* The terminated data to evaluate */
1037 ui32_t ev_line_size; /* May be used to store line memory size */
1038 bool_t ev_is_recursive; /* Evaluation in evaluation? (collect ~:) */
1039 ui8_t __dummy[3];
1040 bool_t ev_add_history; /* Enter (final) command in history? */
1041 char const *ev_new_content; /* History: reenter line, start with this */
1044 struct termios_state {
1045 struct termios ts_tios;
1046 char *ts_linebuf;
1047 size_t ts_linesize;
1048 bool_t ts_needs_reset;
1051 #define termios_state_reset() \
1052 do {\
1053 if (termios_state.ts_needs_reset) {\
1054 tcsetattr(0, TCSADRAIN, &termios_state.ts_tios);\
1055 termios_state.ts_needs_reset = FAL0;\
1057 } while (0)
1059 struct sock { /* data associated with a socket */
1060 int s_fd; /* file descriptor */
1061 #ifdef HAVE_SSL
1062 int s_use_ssl; /* SSL is used */
1063 # ifdef HAVE_OPENSSL
1064 void *s_ssl; /* SSL object */
1065 void *s_ctx; /* SSL context object */
1066 # endif
1067 #endif
1068 char *s_wbuf; /* for buffered writes */
1069 int s_wbufsize; /* allocated size of s_buf */
1070 int s_wbufpos; /* position of first empty data byte */
1071 char *s_rbufptr; /* read pointer to s_rbuf */
1072 int s_rsz; /* size of last read in s_rbuf */
1073 char const *s_desc; /* description of error messages */
1074 void (*s_onclose)(void); /* execute on close */
1075 char s_rbuf[LINESIZE + 1]; /* for buffered reads */
1078 struct sockconn {
1079 struct url sc_url;
1080 struct ccred sc_cred;
1081 struct sock sc_sock;
1084 struct mailbox {
1085 enum {
1086 MB_NONE = 000, /* no reply expected */
1087 MB_COMD = 001, /* command reply expected */
1088 MB_MULT = 002, /* multiline reply expected */
1089 MB_PREAUTH = 004, /* not in authenticated state */
1090 MB_BYE = 010 /* may accept a BYE state */
1091 } mb_active;
1092 FILE *mb_itf; /* temp file with messages, read open */
1093 FILE *mb_otf; /* same, write open */
1094 char *mb_sorted; /* sort method */
1095 enum {
1096 MB_VOID, /* no type (e. g. connection failed) */
1097 MB_FILE, /* local file */
1098 MB_POP3, /* POP3 mailbox */
1099 MB_IMAP, /* IMAP mailbox */
1100 MB_MAILDIR, /* maildir folder */
1101 MB_CACHE /* cached mailbox */
1102 } mb_type; /* type of mailbox */
1103 enum {
1104 MB_DELE = 01, /* may delete messages in mailbox */
1105 MB_EDIT = 02 /* may edit messages in mailbox */
1106 } mb_perm;
1107 int mb_compressed; /* is a compressed mbox file */
1108 int mb_threaded; /* mailbox has been threaded */
1109 #ifdef HAVE_IMAP
1110 enum mbflags {
1111 MB_NOFLAGS = 000,
1112 MB_UIDPLUS = 001 /* supports IMAP UIDPLUS */
1113 } mb_flags;
1114 unsigned long mb_uidvalidity; /* IMAP unique identifier validity */
1115 char *mb_imap_account; /* name of current IMAP account */
1116 char *mb_imap_pass; /* xxx v15-compat URL workaround */
1117 char *mb_imap_mailbox; /* name of current IMAP mailbox */
1118 char *mb_cache_directory; /* name of cache directory */
1119 #endif
1120 struct sock mb_sock; /* socket structure */
1123 enum needspec {
1124 NEED_UNSPEC, /* unspecified need, don't fetch */
1125 NEED_HEADER, /* need the header of a message */
1126 NEED_BODY /* need header and body of a message */
1129 enum havespec {
1130 HAVE_NOTHING, /* nothing downloaded yet */
1131 HAVE_HEADER = 01, /* header is downloaded */
1132 HAVE_BODY = 02 /* entire message is downloaded */
1135 /* flag bits. Attention: Flags that are used in cache.c may not change */
1136 enum mflag {
1137 MUSED = (1<< 0), /* entry is used, but this bit isn't */
1138 MDELETED = (1<< 1), /* entry has been deleted */
1139 MSAVED = (1<< 2), /* entry has been saved */
1140 MTOUCH = (1<< 3), /* entry has been noticed */
1141 MPRESERVE = (1<< 4), /* keep entry in sys mailbox */
1142 MMARK = (1<< 5), /* message is marked! */
1143 MODIFY = (1<< 6), /* message has been modified */
1144 MNEW = (1<< 7), /* message has never been seen */
1145 MREAD = (1<< 8), /* message has been read sometime. */
1146 MSTATUS = (1<< 9), /* message status has changed */
1147 MBOX = (1<<10), /* Send this to mbox, regardless */
1148 MNOFROM = (1<<11), /* no From line */
1149 MHIDDEN = (1<<12), /* message is hidden to user */
1150 MFULLYCACHED = (1<<13), /* message is completely cached */
1151 MBOXED = (1<<14), /* message has been sent to mbox */
1152 MUNLINKED = (1<<15), /* message was unlinked from cache */
1153 MNEWEST = (1<<16), /* message is very new (newmail) */
1154 MFLAG = (1<<17), /* message has been flagged recently */
1155 MUNFLAG = (1<<18), /* message has been unflagged */
1156 MFLAGGED = (1<<19), /* message is `flagged' */
1157 MANSWER = (1<<20), /* message has been answered recently */
1158 MUNANSWER = (1<<21), /* message has been unanswered */
1159 MANSWERED = (1<<22), /* message is `answered' */
1160 MDRAFT = (1<<23), /* message has been drafted recently */
1161 MUNDRAFT = (1<<24), /* message has been undrafted */
1162 MDRAFTED = (1<<25), /* message is marked as `draft' */
1163 MOLDMARK = (1<<26), /* messages was marked previously */
1164 MSPAM = (1<<27) /* message is classified as spam */
1166 #define MMNORM (MDELETED | MSAVED | MHIDDEN)
1167 #define MMNDEL (MDELETED | MHIDDEN)
1169 #define visible(mp) (((mp)->m_flag & MMNDEL) == 0)
1171 struct mimepart {
1172 enum mflag m_flag; /* flags */
1173 enum havespec m_have; /* downloaded parts of the part */
1174 #ifdef HAVE_SPAM
1175 ui32_t m_spamscore; /* Spam score as int, 24:8 bits */
1176 #endif
1177 int m_block; /* block number of this part */
1178 size_t m_offset; /* offset in block of part */
1179 size_t m_size; /* Bytes in the part */
1180 size_t m_xsize; /* Bytes in the full part */
1181 long m_lines; /* Lines in the message */
1182 long m_xlines; /* Lines in the full message */
1183 time_t m_time; /* time the message was sent */
1184 char const *m_from; /* message sender */
1185 struct mimepart *m_nextpart; /* next part at same level */
1186 struct mimepart *m_multipart; /* parts of multipart */
1187 struct mimepart *m_parent; /* enclosing multipart part */
1188 char *m_ct_type; /* content-type */
1189 char *m_ct_type_plain; /* content-type without specs */
1190 enum mimecontent m_mimecontent; /* same in enum */
1191 char const *m_charset; /* charset */
1192 char *m_ct_transfer_enc; /* content-transfer-encoding */
1193 enum mimeenc m_mimeenc; /* same in enum */
1194 char *m_partstring; /* part level string */
1195 char *m_filename; /* attachment filename */
1198 struct message {
1199 enum mflag m_flag; /* flags */
1200 enum havespec m_have; /* downloaded parts of the message */
1201 #ifdef HAVE_SPAM
1202 ui32_t m_spamscore; /* Spam score as int, 24:8 bits */
1203 #endif
1204 int m_block; /* block number of this message */
1205 size_t m_offset; /* offset in block of message */
1206 size_t m_size; /* Bytes in the message */
1207 size_t m_xsize; /* Bytes in the full message */
1208 long m_lines; /* Lines in the message */
1209 long m_xlines; /* Lines in the full message */
1210 time_t m_time; /* time the message was sent */
1211 time_t m_date; /* time in the 'Date' field */
1212 unsigned m_idhash; /* hash on Message-ID for threads */
1213 struct message *m_child; /* first child of this message */
1214 struct message *m_younger; /* younger brother of this message */
1215 struct message *m_elder; /* elder brother of this message */
1216 struct message *m_parent; /* parent of this message */
1217 unsigned m_level; /* thread level of message */
1218 long m_threadpos; /* position in threaded display */
1219 #ifdef HAVE_IMAP
1220 unsigned long m_uid; /* IMAP unique identifier */
1221 #endif
1222 char *m_maildir_file; /* original maildir file of msg */
1223 ui32_t m_maildir_hash; /* hash of file name in maildir sub */
1224 int m_collapsed; /* collapsed thread information */
1227 /* Given a file address, determine the block number it represents */
1228 #define mailx_blockof(off) ((int) ((off) / 4096))
1229 #define mailx_offsetof(off) ((int) ((off) % 4096))
1230 #define mailx_positionof(block, offset) ((off_t)(block) * 4096 + (offset))
1232 /* Argument types */
1233 enum argtype {
1234 ARG_MSGLIST = 0, /* Message list type */
1235 ARG_STRLIST = 1, /* A pure string */
1236 ARG_RAWLIST = 2, /* Shell string list */
1237 ARG_NOLIST = 3, /* Just plain 0 */
1238 ARG_NDMLIST = 4, /* Message list, no defaults */
1239 ARG_ECHOLIST = 5, /* Like raw list, but keep quote chars */
1240 ARG_ARGMASK = 7, /* Mask of the above */
1242 ARG_A = 1u<< 4, /* Needs an active mailbox */
1243 ARG_F = 1u<< 5, /* Is a conditional command */
1244 ARG_H = 1u<< 6, /* Never place in history */
1245 ARG_I = 1u<< 7, /* Interactive command bit */
1246 ARG_M = 1u<< 8, /* Legal from send mode bit */
1247 ARG_P = 1u<< 9, /* Autoprint dot after command */
1248 ARG_R = 1u<<10, /* Cannot be called from collect / recursion */
1249 ARG_T = 1u<<11, /* Is a transparent command */
1250 ARG_V = 1u<<12, /* Places data in temporary_arg_v_store */
1251 ARG_W = 1u<<13 /* Invalid when read only bit */
1254 enum gfield {
1255 GTO = 1, /* Grab To: line */
1256 GSUBJECT = 2, /* Likewise, Subject: line */
1257 GCC = 4, /* And the Cc: line */
1258 GBCC = 8, /* And also the Bcc: line */
1260 GNL = 16, /* Print blank line after */
1261 GDEL = 32, /* Entity removed from list */
1262 GCOMMA = 64, /* detract puts in commas */
1263 GUA = 128, /* User-Agent field */
1264 GMIME = 256, /* MIME 1.0 fields */
1265 GMSGID = 512, /* a Message-ID */
1266 /* 1024 */
1267 GIDENT = 2048, /* From:, Reply-To: and Organization: field */
1268 GREF = 4096, /* References: field */
1269 GDATE = 8192, /* Date: field */
1270 GFULL = 16384, /* include full names */
1271 GSKIN = 32768, /* skin names */
1272 GEXTRA = 65536, /* extra fields */
1273 GFILES = 131072 /* include filename addresses */
1275 #define GMASK (GTO | GSUBJECT | GCC | GBCC)
1277 /* Structure used to pass about the current state of a message (header) */
1278 struct header {
1279 struct name *h_to; /* Dynamic "To:" string */
1280 char *h_subject; /* Subject string */
1281 struct name *h_cc; /* Carbon copies string */
1282 struct name *h_bcc; /* Blind carbon copies */
1283 struct name *h_ref; /* References */
1284 struct attachment *h_attach; /* MIME attachments */
1285 char *h_charset; /* preferred charset */
1286 struct name *h_from; /* overridden "From:" field */
1287 struct name *h_replyto; /* overridden "Reply-To:" field */
1288 struct name *h_sender; /* overridden "Sender:" field */
1289 char *h_organization; /* overridden "Organization:" field */
1292 /* Handling of namelist nodes used in processing the recipients of mail and
1293 * aliases, inspection of mail-addresses and all that kind of stuff */
1294 enum nameflags {
1295 NAME_NAME_SALLOC = 1<< 0, /* .n_name is doped */
1296 NAME_FULLNAME_SALLOC = 1<< 1, /* .n_fullname is doped */
1297 NAME_SKINNED = 1<< 2, /* Is actually skin()ned */
1298 NAME_IDNA = 1<< 3, /* IDNA was applied */
1299 NAME_ADDRSPEC_CHECKED = 1<< 4, /* Address has been .. and */
1300 NAME_ADDRSPEC_ISFILE = 1<< 5, /* ..is a file path */
1301 NAME_ADDRSPEC_ISPIPE = 1<< 6, /* ..is a command for piping */
1302 NAME_ADDRSPEC_ISFILEORPIPE = NAME_ADDRSPEC_ISFILE | NAME_ADDRSPEC_ISPIPE,
1303 NAME_ADDRSPEC_ERR_EMPTY = 1<< 7, /* An empty string (or NULL) */
1304 NAME_ADDRSPEC_ERR_ATSEQ = 1<< 8, /* Weird @ sequence */
1305 NAME_ADDRSPEC_ERR_CHAR = 1<< 9, /* Invalid character */
1306 NAME_ADDRSPEC_ERR_IDNA = 1<<10, /* IDNA convertion failed */
1307 NAME_ADDRSPEC_INVALID = NAME_ADDRSPEC_ERR_EMPTY |
1308 NAME_ADDRSPEC_ERR_ATSEQ | NAME_ADDRSPEC_ERR_CHAR |
1309 NAME_ADDRSPEC_ERR_IDNA,
1311 _NAME_SHIFTWC = 11,
1312 _NAME_MAXWC = 0xFFFFF,
1313 _NAME_MASKWC = _NAME_MAXWC << _NAME_SHIFTWC
1316 /* In the !_ERR_EMPTY case, the failing character can be queried */
1317 #define NAME_ADDRSPEC_ERR_GETWC(F) \
1318 ((((unsigned int)(F) & _NAME_MASKWC) >> _NAME_SHIFTWC) & _NAME_MAXWC)
1319 #define NAME_ADDRSPEC_ERR_SET(F, E, WC) \
1320 do {\
1321 (F) = ((F) & ~(NAME_ADDRSPEC_INVALID | _NAME_MASKWC)) |\
1322 (E) | (((unsigned int)(WC) & _NAME_MAXWC) << _NAME_SHIFTWC);\
1323 } while (0)
1325 struct name {
1326 struct name *n_flink; /* Forward link in list. */
1327 struct name *n_blink; /* Backward list link */
1328 enum gfield n_type; /* From which list it came */
1329 enum nameflags n_flags; /* enum nameflags */
1330 char *n_name; /* This fella's name */
1331 char *n_fullname; /* Sometimes, name including comment */
1334 struct addrguts {
1335 char const *ag_input; /* Input string as given */
1336 size_t ag_ilen; /* strlen() of input */
1337 size_t ag_iaddr_start; /* Start of *addr-spec* in .ag_input */
1338 size_t ag_iaddr_aend; /* ..and one past its end */
1339 char *ag_skinned; /* Output (alloced if !=.ag_input) */
1340 size_t ag_slen; /* strlen() of .ag_skinned */
1341 size_t ag_sdom_start; /* Start of domain in .ag_skinned, */
1342 enum nameflags ag_n_flags; /* enum nameflags of .ag_skinned */
1345 /* MIME attachments */
1346 enum attach_conv {
1347 AC_DEFAULT, /* _get_lc() -> _iter_*() */
1348 AC_FIX_OUTCS, /* _get_lc() -> "charset=" .a_charset */
1349 AC_FIX_INCS, /* "charset=".a_input_charset (nocnv) */
1350 AC_TMPFILE /* attachment.a_tmpf is converted */
1353 struct attachment {
1354 struct attachment *a_flink; /* Forward link in list. */
1355 struct attachment *a_blink; /* Backward list link */
1356 char const *a_name; /* file name */
1357 char const *a_content_type; /* content type */
1358 char const *a_content_disposition; /* content disposition */
1359 char const *a_content_id; /* content id */
1360 char const *a_content_description; /* content description */
1361 char const *a_input_charset; /* Interpretation depends on .a_conv */
1362 char const *a_charset; /* ... */
1363 FILE *a_tmpf; /* If AC_TMPFILE */
1364 enum attach_conv a_conv; /* User chosen conversion */
1365 int a_msgno; /* message number */
1368 struct sendbundle {
1369 struct header *sb_hp;
1370 struct name *sb_to;
1371 FILE *sb_input;
1372 struct str sb_signer; /* USER@HOST for signing+ */
1373 struct url sb_url;
1374 struct ccred sb_ccred;
1377 struct group {
1378 struct group *ge_link; /* Next person in this group */
1379 char *ge_name; /* This person's user name */
1382 struct grouphead {
1383 struct grouphead *g_link; /* Next grouphead in list */
1384 char *g_name; /* Name of this group */
1385 struct group *g_list; /* Users in group. */
1388 /* Structure of the hash table of ignored header fields */
1389 struct ignoretab {
1390 int i_count; /* Number of entries */
1391 struct ignore {
1392 struct ignore *i_link; /* Next ignored field in bucket */
1393 char *i_field; /* This ignored field */
1394 } *i_head[HSHSIZE];
1397 /* For the 'shortcut' and 'unshortcut' functionality */
1398 struct shortcut {
1399 struct shortcut *sh_next; /* next shortcut in list */
1400 char *sh_short; /* shortcut string */
1401 char *sh_long; /* expanded form */
1404 /* For saving the current directory and later returning */
1405 struct cw {
1406 #ifdef HAVE_FCHDIR
1407 int cw_fd;
1408 #else
1409 char cw_wd[PATH_MAX];
1410 #endif
1414 * Global variable declarations
1416 * These become instantiated in main.c.
1419 #undef VL
1420 #ifdef _MAIN_SOURCE
1421 # ifndef HAVE_AMALGAMATION
1422 # define VL
1423 # else
1424 # define VL static
1425 # endif
1426 #else
1427 # define VL extern
1428 #endif
1430 VL gid_t effectivegid; /* Saved from when we started up */
1431 VL gid_t realgid; /* Saved from when we started up */
1433 VL int mb_cur_max; /* Value of MB_CUR_MAX */
1434 VL int realscreenheight; /* The real screen height */
1435 VL int scrnwidth; /* Screen width, or best guess */
1436 VL int scrnheight; /* Screen height/guess (4 header) */
1437 VL int enc_has_state; /* Encoding has shift states */
1439 VL char **altnames; /* List of alternate names of user */
1440 VL char const *homedir; /* Path name of home directory */
1441 VL char const *myname; /* My login name */
1442 VL char const *progname; /* Our name */
1443 VL char const *tempdir; /* The temporary directory */
1445 VL int exit_status; /* Exit status */
1446 VL int options; /* Bits of enum user_options */
1447 VL char *option_r_arg; /* Argument to -r option */
1448 VL char const **smopts; /* sendmail(1) opts from commline */
1449 VL size_t smopts_count; /* Entries in smopts */
1451 /* TODO Join as many of these state machine bits into a single carrier! */
1452 VL int inhook; /* Currently executing a hook */
1453 VL bool_t exec_last_comm_error; /* Last execute() command failed */
1454 VL bool_t edit; /* Indicates editing a file */
1455 VL bool_t did_print_dot; /* Current message has been printed */
1456 VL bool_t list_saw_numbers; /* Last *LIST saw numerics */
1457 VL bool_t msglist_is_single; /* Last NDMLIST/MSGLIST chose 1 msg */
1458 VL bool_t loading; /* Loading user definitions */
1459 VL bool_t sourcing; /* Currently reading variant file */
1460 VL bool_t sawcom; /* Set after first command */
1461 VL bool_t starting; /* Still in startup code */
1462 VL bool_t var_clear_allow_undefined; /* v?ok_[bv]clear(): no complain */
1463 VL int noreset; /* String resets suspended */
1465 /* XXX stylish sorting */
1466 VL int msgCount; /* Count of messages read in */
1467 VL struct mailbox mb; /* Current mailbox */
1468 VL int image; /* File descriptor for msg image */
1469 VL char mailname[PATH_MAX]; /* Name of current file TODO URL/object*/
1470 VL char displayname[80 - 40]; /* Prettyfied for display TODO URL/obj*/
1471 VL char prevfile[PATH_MAX]; /* Name of previous file TODO URL/obj */
1472 VL char const *account_name; /* Current account name or NULL */
1473 VL off_t mailsize; /* Size of system mailbox */
1474 VL struct message *dot; /* Pointer to current message */
1475 VL struct message *prevdot; /* Previous current message */
1476 VL struct message *message; /* The actual message structure */
1477 VL struct message *threadroot; /* first threaded message */
1478 VL int imap_created_mailbox; /* hack to get feedback from imap */
1480 VL struct grouphead *groups[HSHSIZE]; /* Pointer to active groups */
1481 VL struct ignoretab ignore[2]; /* ignored and retained fields
1482 * 0 is ignore, 1 is retain */
1483 VL struct ignoretab saveignore[2]; /* ignored and retained fields
1484 * on save to folder */
1485 VL struct ignoretab allignore[2]; /* special, ignore all headers */
1486 VL struct ignoretab fwdignore[2]; /* fields to ignore for forwarding */
1487 VL struct shortcut *shortcuts; /* list of shortcuts */
1489 VL struct time_current time_current; /* time(3); send: mail1() XXXcarrier */
1490 VL struct termios_state termios_state; /* getpassword(); see commands().. */
1492 #ifdef HAVE_COLOUR
1493 VL struct colour_table *colour_table;
1494 #endif
1496 #ifdef HAVE_SSL
1497 VL enum ssl_verify_level ssl_verify_level; /* SSL verification level */
1498 #endif
1500 #ifdef HAVE_ICONV
1501 VL iconv_t iconvd;
1502 #endif
1504 #ifdef HAVE_CATGETS
1505 VL nl_catd catd;
1506 #endif
1508 VL sigjmp_buf srbuf;
1509 VL int interrupts;
1510 VL sighandler_type dflpipe;
1511 VL sighandler_type handlerstacktop;
1512 #define handlerpush(f) (savedtop = handlerstacktop, handlerstacktop = (f))
1513 #define handlerpop() (handlerstacktop = savedtop)
1515 /* TODO Temporary hacks unless the codebase doesn't jump and uses pass-by-value
1516 * TODO carrier structs instead of locals */
1517 VL char *temporary_arg_v_store;
1518 VL void *temporary_localopts_store;
1520 /* The remaining variables need initialization */
1522 #ifndef HAVE_AMALGAMATION
1523 VL char const month_names[12 + 1][4];
1524 VL char const weekday_names[7 + 1][4];
1526 VL char const uagent[]; /* User agent */
1527 VL char const version[]; /* The version string */
1528 VL char const features[]; /* The "feature string" */
1530 VL uc_it const class_char[];
1531 #endif
1534 * Finally, let's include the function prototypes XXX embed
1537 #include "nailfuns.h"
1539 /* vim:set fenc=utf-8:s-it-mode */