Add more PRIxy macros, start using them..
[s-mailx.git] / nail.h
blob0f34e9b39ca387c57bc7368050bb6f728c2a8faf
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 + 0 > 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 /* Number of Not-Yet-Dead calls that are remembered */
132 #if defined HAVE_DEBUG || defined HAVE_DEVEL || defined HAVE_NYD2
133 # ifdef HAVE_NYD2
134 # define NYD_CALLS_MAX (25 * 99)
135 # elif defined HAVE_DEVEL
136 # define NYD_CALLS_MAX (25 * 66)
137 # else
138 # define NYD_CALLS_MAX (25 * 33)
139 # endif
140 #endif
142 #define APPEND /* New mail goes to end of mailbox */
143 #define CBAD (-15555)
144 #define ESCAPE '~' /* Default escape for sending */
145 #define FIO_STACK_SIZE 20 /* Maximum recursion for sourcing */
146 #define HIST_SIZE 242 /* tty.c: history list default size */
147 #define HSHSIZE 23 /* Hash prime TODO make dynamic, obsolete */
148 #define MAXARGC 1024 /* Maximum list of raw strings */
149 #define MAXEXP 25 /* Maximum expansion of aliases */
150 #define PROMPT_BUFFER_SIZE 80 /* getprompt() bufsize (> 3!) */
152 #define ACCOUNT_NULL "null" /* Name of "null" account */
153 #define MAILRC "~/.mailrc"
154 #define NETRC "~/.netrc"
155 #define TMPDIR_FALLBACK "/tmp"
157 /* Some environment variables for pipe hooks */
158 #define AGENT_USER "NAIL_USER"
159 #define AGENT_USER_ENC "NAIL_USER_ENC"
160 #define AGENT_HOST "NAIL_HOST"
161 #define AGENT_HOST_PORT "NAIL_HOST_PORT"
163 #undef COLOUR
164 #ifdef HAVE_COLOUR
165 # define COLOUR(X) X
166 #else
167 # define COLOUR(X)
168 #endif
169 #define COLOUR_MSGINFO "fg=green"
170 #define COLOUR_PARTINFO "fg=brown"
171 #define COLOUR_FROM_ "fg=brown"
172 #define COLOUR_HEADER "fg=red"
173 #define COLOUR_UHEADER "ft=bold,fg=red"
174 #define COLOUR_TERMS \
175 "cons25,linux,rxvt,rxvt-unicode,screen,sun,vt100,vt220,wsvt25,xterm"
176 #define COLOUR_USER_HEADERS "from,subject"
178 #define FROM_DATEBUF 64 /* Size of RFC 4155 From_ line date */
179 #define DATE_DAYSYEAR 365L
180 #define DATE_SECSMIN 60L
181 #define DATE_MINSHOUR 60L
182 #define DATE_HOURSDAY 24L
183 #define DATE_SECSDAY (DATE_SECSMIN * DATE_MINSHOUR * DATE_HOURSDAY)
185 /* *indentprefix* default as of POSIX */
186 #define INDENT_DEFAULT "\t"
188 /* Default *encoding* as enum conversion below */
189 #define MIME_DEFAULT_ENCODING CONV_TOQP
191 /* Maximum allowed line length in a mail before QP folding is necessary), and
192 * the real limit we go for */
193 #define MIME_LINELEN_MAX 998 /* Plus CRLF */
194 #define MIME_LINELEN_LIMIT (MIME_LINELEN_MAX - 48)
196 /* Ditto, SHOULD */
197 #define MIME_LINELEN_NORM 78 /* Plus CRLF */
199 /* And in headers which contain an encoded word according to RFC 2047 there is
200 * yet another limit */
201 #define MIME_LINELEN_HEADER_WITH_ENCODED_WORD_MAX 76
203 /* Locations of mime.types(5) */
204 #define MIME_TYPES_USR "~/.mime.types"
205 #define MIME_TYPES_SYS "/etc/mime.types"
207 /* Fallback MIME charsets, if *charset-7bit* and *charset-8bit* or not set */
208 #define CHARSET_7BIT "US-ASCII"
209 #ifdef HAVE_ICONV
210 # define CHARSET_8BIT "UTF-8"
211 # define CHARSET_8BIT_OKEY charset_8bit
212 #else
213 # define CHARSET_8BIT "ISO-8859-1"
214 # define CHARSET_8BIT_OKEY ttycharset
215 #endif
217 /* Some environment variables for pipe hooks */
218 #define PIPEHOOK_FILENAME "NAIL_FILENAME"
219 #define PIPEHOOK_FILENAME_GENERATED "NAIL_FILENAME_GENERATED"
220 #define PIPEHOOK_CONTENT "NAIL_CONTENT"
221 #define PIPEHOOK_CONTENT_EVIDENCE "NAIL_CONTENT_EVIDENCE"
223 /* Is *W* a quoting (ASCII only) character? */
224 #define ISQUOTE(W) \
225 ((W) == L'>' || (W) == L'|' || (W) == L'}' || (W) == L':')
227 /* Maximum number of quote characters (not bytes!) that'll be used on
228 * follow lines when compressing leading quote characters */
229 #define QUOTE_MAX 42
231 /* How much spaces should a <tab> count when *quote-fold*ing? (power-of-two!) */
232 #define QUOTE_TAB_SPACES 8
234 /* Maximum size of a message that is passed through to the spam system */
235 #define SPAM_MAXSIZE 420000
237 /* String dope: dynamic buffer size, and size of the single builtin one that's
238 * used first; note that these value include the size of the structure */
239 #define SBUFFER_SIZE 0x18000u
240 #define SBUFFER_BUILTIN 0x2000u
242 /* These come from the configuration (named Xxy to not clash with sh(1)..) */
243 #ifndef XSHELL
244 # define XSHELL "/bin/sh"
245 #endif
246 #ifndef XLISTER
247 # define XLISTER "ls"
248 #endif
249 #ifndef XPAGER
250 # define XPAGER "more"
251 #endif
254 * CC support, generic macros etc.
257 #ifdef __clang__
258 # define CC_CLANG 1
259 # define PREREQ_CLANG(X,Y) \
260 (__clang_major__ + 0 > (X) || \
261 (__clang_major__ + 0 == (X) && __clang_minor__ + 0 >= (Y)))
262 # define __EXTEN __extension__
263 #elif defined __GNUC__
264 # define CC_GCC 1
265 # define PREREQ_GCC(X,Y) \
266 (__GNUC__ + 0 > (X) || (__GNUC__ + 0 == (X) && __GNUC_MINOR__ + 0 >= (Y)))
267 # define __EXTEN __extension__
268 #endif
270 #ifndef CC_CLANG
271 # define CC_CLANG 0
272 # define PREREQ_CLANG(X,Y) 0
273 #endif
274 #ifndef CC_GCC
275 # define CC_GCC 0
276 # define PREREQ_GCC(X,Y) 0
277 #endif
278 #ifndef __EXTEN
279 # define __EXTEN
280 #endif
282 /* Suppress some technical warnings via #pragma's unless developing.
283 * XXX Wild guesses: clang(1) 1.7 and (OpenBSD) gcc(1) 4.2.1 don't work */
284 #if !defined HAVE_DEBUG && !defined HAVE_DEVEL
285 # if PREREQ_CLANG(3, 4)
286 # pragma clang diagnostic ignored "-Wunused-result"
287 # pragma clang diagnostic ignored "-Wformat"
288 # elif PREREQ_GCC(4, 7)
289 # pragma GCC diagnostic ignored "-Wunused-result"
290 # pragma GCC diagnostic ignored "-Wformat"
291 # endif
292 #endif
294 /* For injection macros like DBG(), NATCH_CHAR() */
295 #define COMMA ,
297 #define EMPTY_FILE(F) typedef int CONCAT(avoid_empty_file__, F);
299 /* Pointer to size_t */
300 #define PTR2SIZE(X) ((size_t)(uintptr_t)(X))
302 /* Pointer comparison (types from below) */
303 #define PTRCMP(A,C,B) ((uintptr_t)(A) C (uintptr_t)(B))
305 /* Ditto, compare (maybe mixed-signed) integers cases to T bits, unsigned;
306 * Note: doesn't sign-extend correctly, that's still up to the caller */
307 #define UICMP(T,A,C,B) ((ui ## T ## _t)(A) C (ui ## T ## _t)(B))
309 /* Members in constant array */
310 #ifndef NELEM
311 # define NELEM(A) (sizeof(A) / sizeof(A[0]))
312 #endif
314 /* sizeof() for member fields */
315 #define SIZEOF_FIELD(T,F) sizeof(((T *)NULL)->F)
317 /* Casts-away (*NOT* cast-away) */
318 #define UNUSED(X) ((void)(X))
319 #define UNCONST(P) ((void*)(uintptr_t)(void const*)(P))
320 #define UNVOLATILE(P) ((void*)(uintptr_t)(void volatile*)(P))
321 #define UNXXX(T,C,P) ((T)(uintptr_t)(C)(P))
323 /* __STDC_VERSION__ is ISO C99, so also use __STDC__, which should work */
324 #if defined __STDC__ || defined __STDC_VERSION__ /*|| defined __cplusplus*/
325 # define STRING(X) #X
326 # define XSTRING(X) STRING(X)
327 # define CONCAT(S1,S2) _CONCAT(S1, S2)
328 # define _CONCAT(S1,S2) S1 ## S2
329 #else
330 # define STRING(X) "X"
331 # define XSTRING STRING
332 # define CONCAT(S1,S2) S1/**/S2
333 #endif
335 #if defined __STDC_VERSION__ && __STDC_VERSION__ + 0 >= 199901L
336 /* Variable size arrays and structure fields */
337 # define VFIELD_SIZE(X)
338 # define VFIELD_SIZEOF(T,F) (0)
339 /* Inline functions */
340 # define HAVE_INLINE
341 # define INLINE inline
342 # define SINLINE static inline
343 #else
344 # define VFIELD_SIZE(X) (X)
345 # define VFIELD_SIZEOF(T,F) SIZEOF_FIELD(T, F)
346 # if CC_CLANG || PREREQ_GCC(2, 9)
347 # define INLINE static __inline
348 # define SINLINE static __inline
349 # else
350 # define INLINE
351 # define SINLINE static
352 # endif
353 #endif
355 #undef __FUN__
356 #if defined __STDC_VERSION__ && __STDC_VERSION__ + 0 >= 199901L
357 # define __FUN__ __func__
358 #elif CC_CLANG || PREREQ_GCC(3, 4)
359 # define __FUN__ __FUNCTION__
360 #else
361 # define __FUN__ uagent /* Something that is not a literal */
362 #endif
364 #if defined __predict_true && defined __predict_false
365 # define LIKELY(X) __predict_true(X)
366 # define UNLIKELY(X) __predict_false(X)
367 #elif CC_CLANG || PREREQ_GCC(2, 96)
368 # define LIKELY(X) __builtin_expect(X, 1)
369 # define UNLIKELY(X) __builtin_expect(X, 0)
370 #else
371 # define LIKELY(X) (X)
372 # define UNLIKELY(X) (X)
373 #endif
375 #undef HAVE_NATCH_CHAR
376 #undef NATCH_CHAR
377 #if defined HAVE_SETLOCALE && defined HAVE_C90AMEND1 && defined HAVE_WCWIDTH
378 # define HAVE_NATCH_CHAR
379 # define NATCH_CHAR(X) X
380 #else
381 # define NATCH_CHAR(X)
382 #endif
384 /* Compile-Time-Assert */
385 #define CTA(TEST) _CTA_1(TEST, __LINE__)
386 #define _CTA_1(TEST,L) _CTA_2(TEST, L)
387 #define _CTA_2(TEST,L) \
388 typedef char COMPILE_TIME_ASSERT_failed_at_line_ ## L[(TEST) ? 1 : -1]
390 #undef ISPOW2
391 #define ISPOW2(X) ((((X) - 1) & (X)) == 0)
392 #undef MIN
393 #define MIN(A, B) ((A) < (B) ? (A) : (B))
394 #undef MAX
395 #define MAX(A, B) ((A) < (B) ? (B) : (A))
396 #undef ABS
397 #define ABS(A) ((A) < 0 ? -(A) : (A))
399 #undef DBG
400 #undef NDBG
401 #ifndef HAVE_DEBUG
402 # undef assert
403 # define assert(X) UNUSED(0)
404 # define DBG(X)
405 # define NDBG(X) X
406 #else
407 # define DBG(X) X
408 # define NDBG(X)
409 #endif
411 /* Translation (init in main.c) */
412 #undef _
413 #undef N_
414 #undef V_
415 #define _(S) (S)
416 #define N_(S) (S)
417 #define V_(S) (S)
420 * Types
423 #ifdef UINT8_MAX
424 # define UI8_MAX UINT8_MAX
425 # define SI8_MIN INT8_MIN
426 # define SI8_MAX INT8_MAX
427 typedef uint8_t ui8_t;
428 typedef int8_t si8_t;
429 #elif UCHAR_MAX != 255
430 # error UCHAR_MAX must be 255
431 #else
432 # define UI8_MAX UCHAR_MAX
433 # define SI8_MIN CHAR_MIN
434 # define SI8_MAX CHAR_MAX
435 typedef unsigned char ui8_t;
436 typedef signed char si8_t;
437 #endif
439 #if !defined PRIu8 || !defined PRId8
440 # undef PRIu8
441 # undef PRId8
442 # define PRIu8 "hhu"
443 # define PRId8 "hhd"
444 #endif
446 #ifdef UINT16_MAX
447 # define UI16_MAX UINT16_MAX
448 # define SI16_MIN INT16_MIN
449 # define SI16_MAX INT16_MAX
450 typedef uint16_t ui16_t;
451 typedef int16_t si16_t;
452 #elif USHRT_MAX != 0xFFFFu
453 # error USHRT_MAX must be 0xFFFF
454 #else
455 # define UI16_MAX USHRT_MAX
456 # define SI16_MIN SHRT_MIN
457 # define SI16_MAX SHRT_MAX
458 typedef unsigned short ui16_t;
459 typedef signed short si16_t;
460 #endif
462 #if !defined PRIu16 || !defined PRId16
463 # undef PRIu16
464 # undef PRId16
465 # if UI16_MAX == UINT_MAX
466 # define PRIu16 "u"
467 # define PRId16 "d"
468 # else
469 # define PRIu16 "hu"
470 # define PRId16 "hd"
471 # endif
472 #endif
474 #ifdef UINT32_MAX
475 # define UI32_MAX UINT32_MAX
476 # define SI32_MIN INT32_MIN
477 # define SI32_MAX INT32_MAX
478 typedef uint32_t ui32_t;
479 typedef int32_t si32_t;
480 #elif ULONG_MAX == 0xFFFFFFFFu
481 # define UI32_MAX ULONG_MAX
482 # define SI32_MIN LONG_MIN
483 # define SI32_MAX LONG_MAX
484 typedef unsigned long int ui32_t;
485 typedef signed long int si32_t;
486 #elif UINT_MAX != 0xFFFFFFFFu
487 # error UINT_MAX must be 0xFFFFFFFF
488 #else
489 # define UI32_MAX UINT_MAX
490 # define SI32_MIN INT_MIN
491 # define SI32_MAX INT_MAX
492 typedef unsigned int ui32_t;
493 typedef signed int si32_t;
494 #endif
496 #if !defined PRIu32 || !defined PRId32
497 # undef PRIu32
498 # undef PRId32
499 # if UI32_MAX == ULONG_MAX
500 # define PRIu32 "lu"
501 # define PRId32 "ld"
502 # else
503 # define PRIu32 "u"
504 # define PRId32 "d"
505 # endif
506 #endif
508 #ifdef UINT64_MAX
509 # define UI64_MAX UINT64_MAX
510 # define SI64_MIN INT64_MIN
511 # define SI64_MAX INT64_MAX
512 typedef uint64_t ui64_t;
513 typedef int64_t si64_t;
514 #elif ULONG_MAX <= 0xFFFFFFFFu
515 # if !defined ULLONG_MAX || (ULLONG_MAX >> 31) < 0xFFFFFFFFu
516 # error We need a 64 bit integer
517 # else
518 # define UI64_MAX ULLONG_MAX
519 # define SI64_MIN LLONG_MIN
520 # define SI64_MAX LLONG_MAX
521 __EXTEN typedef unsigned long long ui64_t;
522 __EXTEN typedef signed long long si64_t;
523 # endif
524 #else
525 # define UI64_MAX ULONG_MAX
526 # define SI64_MIN LONG_MIN
527 # define SI64_MAX LONG_MAX
528 typedef unsigned long ui64_t;
529 typedef signed long si64_t;
530 #endif
532 #if !defined PRIu64 || !defined PRId64 || !defined PRIX64
533 # undef PRIu64
534 # undef PRId64
535 # undef PRIX64
536 # if defined ULLONG_MAX && UI64_MAX == ULLONG_MAX
537 # define PRIu64 "llu"
538 # define PRId64 "lld"
539 # define PRIX64 "llX"
540 # else
541 # define PRIu64 "lu"
542 # define PRId64 "ld"
543 # define PRIX64 "lX"
544 # endif
545 #endif
547 /* (So that we can use UICMP() for size_t comparison, too) */
548 typedef size_t uiz_t;
549 typedef ssize_t siz_t;
551 #undef PRIuZ
552 #undef PRIdZ
553 #if defined __STDC_VERSION__ && __STDC_VERSION__ + 0 >= 199901L
554 # define PRIuZ "zu"
555 # define PRIdZ "zd"
556 # define PRIxZ_FMT_CTA() CTA(1 == 1)
557 #elif defined SIZE_MAX
558 # if SIZE_MAX == UI64_MAX
559 # define PRIuZ PRIu64
560 # define PRIdZ PRId64
561 # define PRIxZ_FMT_CTA() CTA(sizeof(size_t) == sizeof(ui64_t))
562 # elif SIZE_MAX == UI32_MAX
563 # define PRIuZ PRIu32
564 # define PRIdZ PRId32
565 # define PRIxZ_FMT_CTA() CTA(sizeof(size_t) == sizeof(ui32_t))
566 # endif
567 #endif
568 #ifndef PRIuZ
569 # define PRIuZ "lu"
570 # define PRIdZ "ld"
571 # define PRIxZ_FMT_CTA() CTA(sizeof(size_t) == sizeof(unsigned long))
572 #endif
574 #ifndef UINTPTR_MAX
575 # ifdef SIZE_MAX
576 # define uintptr_t size_t
577 # define UINTPTR_MAX SIZE_MAX
578 # else
579 # define uintptr_t unsigned long
580 # define UINTPTR_MAX ULONG_MAX
581 # endif
582 #endif
584 #if !defined PRIuPTR || !defined PRIXPTR
585 # undef PRIuPTR
586 # undef PRIXPTR
587 # if UINTPTR_MAX == ULONG_MAX
588 # define PRIuPTR "lu"
589 # define PRIXPTR "lX"
590 # else
591 # define PRIuPTR "u"
592 # define PRIXPTR "X"
593 # endif
594 #endif
596 enum {FAL0, TRU1};
597 typedef si8_t bool_t;
599 /* Add shorter aliases for "normal" integers */
600 typedef unsigned long ul_i;
601 typedef unsigned int ui_i;
602 typedef unsigned short us_i;
603 typedef unsigned char uc_i;
605 typedef signed long sl_i;
606 typedef signed int si_i;
607 typedef signed short ss_i;
608 typedef signed char sc_i;
610 typedef void ( *sighandler_type)(int);
612 enum user_options {
613 OPT_NONE,
614 OPT_DEBUG = 1u<< 0, /* -d / *debug* */
615 OPT_VERB = 1u<< 1, /* -v / *verbose* */
616 OPT_VERBVERB = 1u<<19, /* .. even more verbosity */
617 OPT_EXISTONLY = 1u<< 2, /* -e */
618 OPT_HEADERSONLY = 1u<< 3, /* -H */
619 OPT_HEADERLIST = 1u<< 4, /* -L */
620 OPT_NOSRC = 1u<< 5, /* -n */
621 OPT_E_FLAG = 1u<< 6, /* -E / *skipemptybody* */
622 OPT_F_FLAG = 1u<< 7, /* -F */
623 OPT_N_FLAG = 1u<< 8, /* -N / *header* */
624 OPT_R_FLAG = 1u<< 9, /* -R */
625 OPT_r_FLAG = 1u<<10, /* -r (plus option_r_arg) */
626 OPT_t_FLAG = 1u<<11, /* -t */
627 OPT_u_FLAG = 1u<<12, /* -u / $USER and pw->pw_uid != getuid(2) */
628 OPT_TILDE_FLAG = 1u<<13, /* -~ */
629 OPT_BATCH_FLAG = 1u<<14, /* -# */
631 OPT_SENDMODE = 1u<<15, /* Usage case forces send mode */
632 OPT_INTERACTIVE = 1u<<16, /* isatty(0) */
633 OPT_TTYIN = OPT_INTERACTIVE,
634 OPT_TTYOUT = 1u<<17,
635 OPT_UNICODE = 1u<<18, /* We're in an UTF-8 environment */
637 /* Some easy-access shortcuts */
638 OPT_D_V = OPT_DEBUG | OPT_VERB,
639 OPT_D_VV = OPT_DEBUG | OPT_VERBVERB
641 #define IS_TTY_SESSION() \
642 ((options & (OPT_TTYIN | OPT_TTYOUT)) == (OPT_TTYIN | OPT_TTYOUT))
644 enum exit_status {
645 EXIT_OK = EXIT_SUCCESS,
646 EXIT_ERR = EXIT_FAILURE,
647 EXIT_USE = 2,
648 EXIT_COLL_ABORT = 1<<1, /* Message collection was aborted */
649 EXIT_SEND_ERROR = 1<<2 /* Unspecified send error occurred */
652 enum fedit_mode {
653 FEDIT_NONE = 0,
654 FEDIT_SYSBOX = 1<<0, /* %: prefix */
655 FEDIT_RDONLY = 1<<1, /* Readonly (per-box, OPT_R_FLAG is global) */
656 FEDIT_NEWMAIL = 1<<2 /* `newmail' operation TODO OBSOLETE THIS! */
659 enum fexp_mode {
660 FEXP_FULL, /* Full expansion */
661 FEXP_LOCAL = 1<<0, /* Result must be local file/maildir */
662 FEXP_SHELL = 1<<1, /* No folder %,#,&,+ stuff, yet sh(1) */
663 FEXP_NSHORTCUT = 1<<2, /* Don't expand shortcuts */
664 FEXP_SILENT = 1<<3, /* Don't print but only return errors */
665 FEXP_MULTIOK = 1<<4 /* Expansion to many entries is ok */
668 enum flock_type {
669 FLOCK_READ,
670 FLOCK_WRITE,
671 FLOCK_UNLOCK
674 /* <0 means "stop" unless *prompt* extensions are enabled. */
675 enum prompt_exp {
676 PROMPT_STOP = -1, /* \c */
677 /* *prompt* extensions: \$, \@ etc. */
678 PROMPT_DOLLAR = -2,
679 PROMPT_AT = -3
682 enum colourspec {
683 COLOURSPEC_MSGINFO,
684 COLOURSPEC_PARTINFO,
685 COLOURSPEC_FROM_,
686 COLOURSPEC_HEADER,
687 COLOURSPEC_UHEADER,
688 COLOURSPEC_RESET
691 enum okay {
692 STOP = 0,
693 OKAY = 1
696 enum mimeenc {
697 MIME_NONE, /* message is not in MIME format */
698 MIME_BIN, /* message is in binary encoding */
699 MIME_8B, /* message is in 8bit encoding */
700 MIME_7B, /* message is in 7bit encoding */
701 MIME_QP, /* message is quoted-printable */
702 MIME_B64 /* message is in base64 encoding */
705 enum mime_counter_evidence {
706 MIMECE_NONE,
707 MIMECE_USR_OVWR = 1<<1
710 enum conversion {
711 CONV_NONE, /* no conversion */
712 CONV_7BIT, /* no conversion, is 7bit */
713 CONV_FROMQP, /* convert from quoted-printable */
714 CONV_TOQP, /* convert to quoted-printable */
715 CONV_8BIT, /* convert to 8bit (iconv) */
716 CONV_FROMB64, /* convert from base64 */
717 CONV_FROMB64_T, /* convert from base64/text */
718 CONV_TOB64, /* convert to base64 */
719 CONV_FROMHDR, /* convert from RFC1522 format */
720 CONV_TOHDR, /* convert to RFC1522 format */
721 CONV_TOHDR_A /* convert addresses for header */
724 enum sendaction {
725 SEND_MBOX, /* no conversion to perform */
726 SEND_RFC822, /* no conversion, no From_ line */
727 SEND_TODISP, /* convert to displayable form */
728 SEND_TODISP_ALL, /* same, include all MIME parts */
729 SEND_SHOW, /* convert to 'show' command form */
730 SEND_TOSRCH, /* convert for IMAP SEARCH */
731 SEND_TOFILE, /* convert for saving body to a file */
732 SEND_TOPIPE, /* convert for pipe-content/subc. */
733 SEND_QUOTE, /* convert for quoting */
734 SEND_QUOTE_ALL, /* same, include all MIME parts */
735 SEND_DECRYPT /* decrypt */
738 enum mimecontent {
739 MIME_UNKNOWN, /* unknown content */
740 MIME_SUBHDR, /* inside a multipart subheader */
741 MIME_822, /* message/rfc822 content */
742 MIME_MESSAGE, /* other message/ content */
743 MIME_TEXT_PLAIN, /* text/plain content */
744 MIME_TEXT_HTML, /* text/html content */
745 MIME_TEXT, /* other text/ content */
746 MIME_ALTERNATIVE, /* multipart/alternative content */
747 MIME_DIGEST, /* multipart/digest content */
748 MIME_MULTI, /* other multipart/ content */
749 MIME_PKCS7, /* PKCS7 content */
750 MIME_DISCARD /* content is discarded */
753 /* Content-Transfer-Encodings as defined in RFC 2045:
754 * - Quoted-Printable, section 6.7
755 * - Base64, section 6.8 */
756 #define QP_LINESIZE (4 * 19) /* Max. compliant QP linesize */
758 #define B64_LINESIZE (4 * 19) /* Max. compliant Base64 linesize */
759 #define B64_ENCODE_INPUT_PER_LINE 57 /* Max. input for Base64 encode/line */
761 /* xxx QP came later, maybe rewrite all to use mimecte_flags directly? */
762 enum __mimecte_flags {
763 MIMECTE_NONE,
764 MIMECTE_SALLOC = 1<<0, /* Use salloc(), not srealloc().. */
765 /* ..result .s,.l point to user buffer of *_LINESIZE+[+[+]] bytes instead */
766 MIMECTE_BUF = 1<<1,
767 MIMECTE_CRLF = 1<<2, /* (encode) Append "\r\n" to lines */
768 MIMECTE_LF = 1<<3, /* (encode) Append "\n" to lines */
769 /* (encode) If one of _CRLF/_LF is set, honour *_LINESIZE+[+[+]] and
770 * inject the desired line-ending whenever a linewrap is desired */
771 MIMECTE_MULTILINE = 1<<4,
772 /* (encode) Quote with header rules, do not generate soft NL breaks? */
773 MIMECTE_ISHEAD = 1<<5
776 enum qpflags {
777 QP_NONE = MIMECTE_NONE,
778 QP_SALLOC = MIMECTE_SALLOC,
779 QP_BUF = MIMECTE_BUF,
780 QP_ISHEAD = MIMECTE_ISHEAD
783 enum b64flags {
784 B64_NONE = MIMECTE_NONE,
785 B64_SALLOC = MIMECTE_SALLOC,
786 B64_BUF = MIMECTE_BUF,
787 B64_CRLF = MIMECTE_CRLF,
788 B64_LF = MIMECTE_LF,
789 B64_MULTILINE = MIMECTE_MULTILINE
792 enum oflags {
793 OF_RDONLY = 1<<0,
794 OF_WRONLY = 1<<1,
795 OF_RDWR = 1<<2,
796 OF_APPEND = 1<<3,
797 OF_CREATE = 1<<4,
798 OF_TRUNC = 1<<5,
799 OF_EXCL = 1<<6,
800 OF_CLOEXEC = 1<<7,
801 OF_UNLINK = 1<<8, /* Only for Ftmp(): unlink(2) after creation */
802 OF_HOLDSIGS = 1<<9, /* Mutual with OF_UNLINK - await Ftmp_free() */
803 OF_REGISTER = 1<<10 /* Register file in our file table */
806 enum tdflags {
807 TD_NONE, /* no display conversion */
808 TD_ISPR = 1<<0, /* use isprint() checks */
809 TD_ICONV = 1<<1, /* use iconv() */
810 TD_DELCTRL = 1<<2, /* delete control characters */
813 * NOTE: _TD_EOF and _TD_BUFCOPY may be ORd with enum conversion and
814 * enum sendaction, and may thus NOT clash with their bit range!
816 _TD_EOF = 1<<14, /* EOF seen, last round! */
817 _TD_BUFCOPY = 1<<15 /* Buffer may be constant, copy it */
820 enum protocol {
821 PROTO_FILE, /* refers to a local file */
822 PROTO_POP3, /* is a pop3 server string */
823 PROTO_IMAP, /* is an imap server string */
824 PROTO_MAILDIR, /* refers to a maildir folder */
825 PROTO_UNKNOWN /* unknown protocol */
828 enum cproto {
829 CPROTO_SMTP,
830 CPROTO_POP3,
831 CPROTO_IMAP
834 enum authtype {
835 AUTHTYPE_NONE = 1<<0,
836 AUTHTYPE_PLAIN = 1<<1, /* POP3: APOP is covered by this */
837 AUTHTYPE_LOGIN = 1<<2,
838 AUTHTYPE_CRAM_MD5 = 1<<3,
839 AUTHTYPE_GSSAPI = 1<<4
842 #ifdef HAVE_SSL
843 enum ssl_verify_level {
844 SSL_VERIFY_IGNORE,
845 SSL_VERIFY_WARN,
846 SSL_VERIFY_ASK,
847 SSL_VERIFY_STRICT
849 #endif
851 /* A large enum with all the binary and value options a.k.a their keys.
852 * Only the constant keys are in here, to be looked up via ok_[bv]look(),
853 * ok_[bv]set() and ok_[bv]clear().
854 * Note: see the comments in accmacvar.c before changing *anything* in here! */
855 enum okeys {
856 /* Option keys for binary options */
857 ok_b_add_file_recipients,
858 ok_b_allnet,
859 ok_b_append,
860 ok_b_ask,
861 ok_b_askatend,
862 ok_b_askattach,
863 ok_b_askbcc,
864 ok_b_askcc,
865 ok_b_asksign,
866 ok_b_asksub,
867 ok_b_attachment_ask_content_description,
868 ok_b_attachment_ask_content_disposition,
869 ok_b_attachment_ask_content_id,
870 ok_b_attachment_ask_content_type,
871 ok_b_autocollapse,
872 ok_b_autoprint,
873 ok_b_autothread,
874 ok_b_bang,
875 ok_b_batch_exit_on_error,
876 ok_b_bsdannounce,
877 ok_b_bsdcompat,
878 ok_b_bsdflags,
879 ok_b_bsdheadline,
880 ok_b_bsdmsgs,
881 ok_b_bsdorder,
882 ok_b_bsdset,
883 ok_b_colour_disable,
884 ok_b_colour_pager,
885 ok_b_debug, /* {special=1} */
886 ok_b_disconnected,
887 ok_b_disposition_notification_send,
888 ok_b_dot,
889 ok_b_editalong,
890 ok_b_editheaders,
891 ok_b_emptybox,
892 ok_b_emptystart,
893 ok_b_flipr,
894 ok_b_forward_as_attachment,
895 ok_b_fullnames,
896 ok_b_header, /* {special=1} */
897 ok_b_history_gabby,
898 ok_b_history_gabby_persist,
899 ok_b_hold,
900 ok_b_idna_disable,
901 ok_b_ignore,
902 ok_b_ignoreeof,
903 ok_b_imap_use_starttls,
904 ok_b_keep,
905 ok_b_keep_content_length,
906 ok_b_keepsave,
907 ok_b_line_editor_disable,
908 ok_b_markanswered,
909 ok_b_message_id_disable,
910 ok_b_metoo,
911 ok_b_mime_allow_text_controls,
912 ok_b_netrc_lookup,
913 ok_b_outfolder,
914 ok_b_page,
915 ok_b_piperaw,
916 ok_b_pop3_bulk_load,
917 ok_b_pop3_no_apop,
918 ok_b_pop3_use_starttls,
919 ok_b_print_all_chars,
920 ok_b_print_alternatives,
921 ok_b_quiet,
922 ok_b_quote_as_attachment,
923 ok_b_recipients_in_cc,
924 ok_b_record_resent,
925 ok_b_reply_in_same_charset,
926 ok_b_Replyall,
927 ok_b_rfc822_body_from_, /* {name=rfc822-body-from_} */
928 ok_b_save,
929 ok_b_searchheaders,
930 ok_b_sendcharsets_else_ttycharset,
931 ok_b_sendwait,
932 ok_b_showlast,
933 ok_b_showname,
934 ok_b_showto,
935 ok_b_skipemptybody, /* {special=1} */
936 ok_b_smime_force_encryption,
937 ok_b_smime_no_default_ca,
938 ok_b_smime_sign,
939 ok_b_smtp_use_starttls,
940 ok_b_ssl_no_default_ca,
941 ok_b_ssl_v2_allow,
942 ok_b_v15_compat,
943 ok_b_verbose, /* {special=1} */
944 ok_b_writebackedited,
946 /* Option keys for values options */
947 ok_v_agent_shell_lookup,
948 ok_v_attrlist,
949 ok_v_autobcc,
950 ok_v_autocc,
951 ok_v_autosort,
952 ok_v_charset_7bit,
953 ok_v_charset_8bit,
954 ok_v_cmd,
955 ok_v_colour_from_, /* {name=colour-from_} */
956 ok_v_colour_header,
957 ok_v_colour_msginfo,
958 ok_v_colour_partinfo,
959 ok_v_colour_terms,
960 ok_v_colour_uheader,
961 ok_v_colour_user_headers,
962 ok_v_crt,
963 ok_v_datefield,
964 ok_v_datefield_markout_older,
965 ok_v_DEAD,
966 ok_v_EDITOR,
967 ok_v_encoding,
968 ok_v_escape,
969 ok_v_folder, /* {special=1} */
970 ok_v_folder_hook,
971 ok_v_from,
972 ok_v_fwdheading,
973 ok_v_headline,
974 ok_v_headline_bidi,
975 ok_v_hostname,
976 ok_v_imap_auth,
977 ok_v_imap_cache,
978 ok_v_imap_keepalive,
979 ok_v_imap_list_depth,
980 ok_v_indentprefix,
981 ok_v_line_editor_cursor_right, /* {special=1} */
982 ok_v_LISTER,
983 ok_v_MAIL,
984 ok_v_MBOX,
985 ok_v_mime_counter_evidence,
986 /* TODO v15-compat: mimetypes-load-control -> mimetypes-load / mimetypes */
987 ok_v_mimetypes_load_control,
988 ok_v_NAIL_EXTRA_RC, /* {name=NAIL_EXTRA_RC} */
989 /* TODO v15-compat: NAIL_HEAD -> message-head? */
990 ok_v_NAIL_HEAD, /* {name=NAIL_HEAD} */
991 /* TODO v15-compat: NAIL_HISTFILE -> history-file */
992 ok_v_NAIL_HISTFILE, /* {name=NAIL_HISTFILE} */
993 /* TODO v15-compat: NAIL_HISTSIZE -> history-size{,limit} */
994 ok_v_NAIL_HISTSIZE, /* {name=NAIL_HISTSIZE} */
995 /* TODO v15-compat: NAIL_TAIL -> message-tail? */
996 ok_v_NAIL_TAIL, /* {name=NAIL_TAIL} */
997 ok_v_newfolders,
998 ok_v_newmail,
999 ok_v_ORGANIZATION,
1000 ok_v_PAGER,
1001 ok_v_password,
1002 /* TODO pop3_auth is yet a dummy to enable easier impl. of ccred_lookup()! */
1003 ok_v_pop3_auth,
1004 ok_v_pop3_keepalive,
1005 ok_v_prompt,
1006 ok_v_quote,
1007 ok_v_quote_fold,
1008 ok_v_record,
1009 ok_v_reply_strings,
1010 ok_v_replyto,
1011 ok_v_screen,
1012 ok_v_sendcharsets,
1013 ok_v_sender,
1014 ok_v_sendmail,
1015 ok_v_sendmail_arguments,
1016 ok_v_sendmail_progname,
1017 ok_v_SHELL,
1018 ok_v_Sign,
1019 ok_v_sign,
1020 ok_v_signature,
1021 ok_v_smime_ca_dir,
1022 ok_v_smime_ca_file,
1023 ok_v_smime_crl_dir,
1024 ok_v_smime_crl_file,
1025 ok_v_smime_sign_cert,
1026 ok_v_smime_sign_include_certs,
1027 ok_v_smtp,
1028 /* TODO v15-compat: smtp-auth: drop */
1029 ok_v_smtp_auth,
1030 ok_v_smtp_auth_password,
1031 ok_v_smtp_auth_user,
1032 ok_v_smtp_hostname,
1033 ok_v_spam_command,
1034 ok_v_spam_host,
1035 ok_v_spam_maxsize,
1036 ok_v_spam_port,
1037 ok_v_spam_socket,
1038 ok_v_spam_user,
1039 ok_v_ssl_ca_dir,
1040 ok_v_ssl_ca_file,
1041 ok_v_ssl_cert,
1042 ok_v_ssl_cipher_list,
1043 ok_v_ssl_crl_dir,
1044 ok_v_ssl_crl_file,
1045 ok_v_ssl_key,
1046 ok_v_ssl_method,
1047 ok_v_ssl_rand_egd,
1048 ok_v_ssl_rand_file,
1049 ok_v_ssl_verify,
1050 ok_v_stealthmua,
1051 ok_v_toplines,
1052 ok_v_ttycharset,
1053 ok_v_user,
1054 ok_v_VISUAL
1057 enum okey_xlook_mode {
1058 OXM_PLAIN = 1<<0, /* Plain key always tested */
1059 OXM_H_P = 1<<1, /* Check PLAIN-.url_h_p */
1060 OXM_U_H_P = 1<<2, /* Check PLAIN-.url_u_h_p */
1061 OXM_ALL = 0x7
1064 /* Locale-independent character classes */
1065 enum {
1066 C_CNTRL = 0000,
1067 C_BLANK = 0001,
1068 C_WHITE = 0002,
1069 C_SPACE = 0004,
1070 C_PUNCT = 0010,
1071 C_OCTAL = 0020,
1072 C_DIGIT = 0040,
1073 C_UPPER = 0100,
1074 C_LOWER = 0200
1077 struct str {
1078 char *s; /* the string's content */
1079 size_t l; /* the stings's length */
1082 struct colour_table {
1083 /* Plus a copy of *colour-user-headers* */
1084 struct str ct_csinfo[COLOURSPEC_RESET+1 + 1];
1087 struct bidi_info {
1088 struct str bi_start; /* Start of (possibly) bidirectional text */
1089 struct str bi_end; /* End of ... */
1090 size_t bi_pad; /* No of visual columns to reserve for BIDI pad */
1093 struct url {
1094 char const *url_input; /* Input as given (really) */
1095 enum cproto url_cproto; /* Communication protocol as given */
1096 bool_t url_needs_tls; /* Wether the protocol uses SSL/TLS */
1097 bool_t url_had_user; /* Wether .url_user was part of the URL */
1098 ui16_t url_portno; /* atoi .url_port or default, host endian */
1099 char const *url_port; /* Port (if given) or NULL */
1100 char url_proto[14]; /* Communication protocol as 'xy\0//' */
1101 ui8_t url_proto_len; /* Length of .url_proto ('\0' index) */
1102 ui8_t url_proto_xlen; /* .. if '\0' is replaced with ':' */
1103 struct str url_user; /* User, exactly as given / looked up */
1104 struct str url_user_enc; /* User, urlxenc()oded */
1105 struct str url_pass; /* Pass (urlxdec()oded) or NULL */
1106 struct str url_host; /* Service hostname */
1107 struct str url_path; /* CPROTO_IMAP: path suffix or NULL */
1108 /* TODO: url_get_component(url *, enum COMPONENT, str *store) */
1109 struct str url_h_p; /* .url_host[:.url_port] */
1110 /* .url_user@.url_host
1111 * Note: for CPROTO_SMTP this may resolve HOST via *smtp-hostname* (->
1112 * *hostname*)! (And may later be overwritten according to *from*!) */
1113 struct str url_u_h;
1114 struct str url_u_h_p; /* .url_user@.url_host[:.url_port] */
1115 struct str url_eu_h_p; /* .url_user_enc@.url_host[:.url_port] */
1116 char const *url_p_u_h_p; /* .url_proto://.url_u_h_p */
1117 char const *url_p_eu_h_p; /* .url_proto://.url_eu_h_p */
1118 char const *url_p_eu_h_p_p; /* .url_proto://.url_eu_h_p[/.url_path] */
1121 struct ccred {
1122 enum cproto cc_cproto; /* Communication protocol */
1123 enum authtype cc_authtype; /* Desired authentication */
1124 char const *cc_auth; /* Authentication type as string */
1125 struct str cc_user; /* User (urlxdec()oded) or NULL */
1126 struct str cc_pass; /* Password (urlxdec()oded) or NULL */
1129 struct time_current {
1130 time_t tc_time;
1131 struct tm tc_gm;
1132 struct tm tc_local;
1133 char tc_ctime[32];
1136 struct quoteflt {
1137 FILE *qf_os; /* Output stream */
1138 char const *qf_pfix;
1139 ui32_t qf_pfix_len; /* Length of prefix: 0: bypass */
1140 ui32_t qf_qfold_min; /* Simple way: wrote prefix? */
1141 #ifdef HAVE_QUOTE_FOLD
1142 ui32_t qf_qfold_max; /* Otherwise: line lengths */
1143 ui8_t qf_state; /* *quote-fold* state machine */
1144 bool_t qf_brk_isws; /* Breakpoint is at WS */
1145 ui8_t __dummy[2];
1146 ui32_t qf_wscnt; /* Whitespace count */
1147 ui32_t qf_brkl; /* Breakpoint */
1148 ui32_t qf_brkw; /* Visual width, breakpoint */
1149 ui32_t qf_datw; /* Current visual output line width */
1150 struct str qf_dat; /* Current visual output line */
1151 struct str qf_currq; /* Current quote, compressed */
1152 mbstate_t qf_mbps[2];
1153 #endif
1156 struct search_expr {
1157 char const *ss_where; /* to search for the expression (not always used) */
1158 char const *ss_sexpr; /* String search expression; NULL: use .ss_reexpr */
1159 #ifdef HAVE_REGEX
1160 regex_t ss_reexpr;
1161 #endif
1164 struct eval_ctx {
1165 struct str ev_line; /* The terminated data to evaluate */
1166 ui32_t ev_line_size; /* May be used to store line memory size */
1167 bool_t ev_is_recursive; /* Evaluation in evaluation? (collect ~:) */
1168 ui8_t __dummy[3];
1169 bool_t ev_add_history; /* Enter (final) command in history? */
1170 char const *ev_new_content; /* History: reenter line, start with this */
1173 struct termios_state {
1174 struct termios ts_tios;
1175 char *ts_linebuf;
1176 size_t ts_linesize;
1177 bool_t ts_needs_reset;
1180 #define termios_state_reset() \
1181 do {\
1182 if (termios_state.ts_needs_reset) {\
1183 tcsetattr(0, TCSADRAIN, &termios_state.ts_tios);\
1184 termios_state.ts_needs_reset = FAL0;\
1186 } while (0)
1188 struct sock { /* data associated with a socket */
1189 int s_fd; /* file descriptor */
1190 #ifdef HAVE_SSL
1191 int s_use_ssl; /* SSL is used */
1192 # ifdef HAVE_OPENSSL
1193 void *s_ssl; /* SSL object */
1194 void *s_ctx; /* SSL context object */
1195 # endif
1196 #endif
1197 char *s_wbuf; /* for buffered writes */
1198 int s_wbufsize; /* allocated size of s_buf */
1199 int s_wbufpos; /* position of first empty data byte */
1200 char *s_rbufptr; /* read pointer to s_rbuf */
1201 int s_rsz; /* size of last read in s_rbuf */
1202 char const *s_desc; /* description of error messages */
1203 void (*s_onclose)(void); /* execute on close */
1204 char s_rbuf[LINESIZE + 1]; /* for buffered reads */
1207 struct sockconn {
1208 struct url sc_url;
1209 struct ccred sc_cred;
1210 struct sock sc_sock;
1213 struct mailbox {
1214 enum {
1215 MB_NONE = 000, /* no reply expected */
1216 MB_COMD = 001, /* command reply expected */
1217 MB_MULT = 002, /* multiline reply expected */
1218 MB_PREAUTH = 004, /* not in authenticated state */
1219 MB_BYE = 010 /* may accept a BYE state */
1220 } mb_active;
1221 FILE *mb_itf; /* temp file with messages, read open */
1222 FILE *mb_otf; /* same, write open */
1223 char *mb_sorted; /* sort method */
1224 enum {
1225 MB_VOID, /* no type (e. g. connection failed) */
1226 MB_FILE, /* local file */
1227 MB_POP3, /* POP3 mailbox */
1228 MB_IMAP, /* IMAP mailbox */
1229 MB_MAILDIR, /* maildir folder */
1230 MB_CACHE /* cached mailbox */
1231 } mb_type; /* type of mailbox */
1232 enum {
1233 MB_DELE = 01, /* may delete messages in mailbox */
1234 MB_EDIT = 02 /* may edit messages in mailbox */
1235 } mb_perm;
1236 int mb_compressed; /* is a compressed mbox file */
1237 int mb_threaded; /* mailbox has been threaded */
1238 #ifdef HAVE_IMAP
1239 enum mbflags {
1240 MB_NOFLAGS = 000,
1241 MB_UIDPLUS = 001 /* supports IMAP UIDPLUS */
1242 } mb_flags;
1243 unsigned long mb_uidvalidity; /* IMAP unique identifier validity */
1244 char *mb_imap_account; /* name of current IMAP account */
1245 char *mb_imap_pass; /* xxx v15-compat URL workaround */
1246 char *mb_imap_mailbox; /* name of current IMAP mailbox */
1247 char *mb_cache_directory; /* name of cache directory */
1248 #endif
1249 struct sock mb_sock; /* socket structure */
1252 enum needspec {
1253 NEED_UNSPEC, /* unspecified need, don't fetch */
1254 NEED_HEADER, /* need the header of a message */
1255 NEED_BODY /* need header and body of a message */
1258 enum havespec {
1259 HAVE_NOTHING, /* nothing downloaded yet */
1260 HAVE_HEADER = 01, /* header is downloaded */
1261 HAVE_BODY = 02 /* entire message is downloaded */
1264 /* flag bits. Attention: Flags that are used in cache.c may not change */
1265 enum mflag {
1266 MUSED = (1<< 0), /* entry is used, but this bit isn't */
1267 MDELETED = (1<< 1), /* entry has been deleted */
1268 MSAVED = (1<< 2), /* entry has been saved */
1269 MTOUCH = (1<< 3), /* entry has been noticed */
1270 MPRESERVE = (1<< 4), /* keep entry in sys mailbox */
1271 MMARK = (1<< 5), /* message is marked! */
1272 MODIFY = (1<< 6), /* message has been modified */
1273 MNEW = (1<< 7), /* message has never been seen */
1274 MREAD = (1<< 8), /* message has been read sometime. */
1275 MSTATUS = (1<< 9), /* message status has changed */
1276 MBOX = (1<<10), /* Send this to mbox, regardless */
1277 MNOFROM = (1<<11), /* no From line */
1278 MHIDDEN = (1<<12), /* message is hidden to user */
1279 MFULLYCACHED = (1<<13), /* message is completely cached */
1280 MBOXED = (1<<14), /* message has been sent to mbox */
1281 MUNLINKED = (1<<15), /* message was unlinked from cache */
1282 MNEWEST = (1<<16), /* message is very new (newmail) */
1283 MFLAG = (1<<17), /* message has been flagged recently */
1284 MUNFLAG = (1<<18), /* message has been unflagged */
1285 MFLAGGED = (1<<19), /* message is `flagged' */
1286 MANSWER = (1<<20), /* message has been answered recently */
1287 MUNANSWER = (1<<21), /* message has been unanswered */
1288 MANSWERED = (1<<22), /* message is `answered' */
1289 MDRAFT = (1<<23), /* message has been drafted recently */
1290 MUNDRAFT = (1<<24), /* message has been undrafted */
1291 MDRAFTED = (1<<25), /* message is marked as `draft' */
1292 MOLDMARK = (1<<26), /* messages was marked previously */
1293 MSPAM = (1<<27) /* message is classified as spam */
1295 #define MMNORM (MDELETED | MSAVED | MHIDDEN)
1296 #define MMNDEL (MDELETED | MHIDDEN)
1298 #define visible(mp) (((mp)->m_flag & MMNDEL) == 0)
1300 struct mimepart {
1301 enum mflag m_flag; /* flags */
1302 enum havespec m_have; /* downloaded parts of the part */
1303 #ifdef HAVE_SPAM
1304 ui32_t m_spamscore; /* Spam score as int, 24:8 bits */
1305 #endif
1306 int m_block; /* block number of this part */
1307 size_t m_offset; /* offset in block of part */
1308 size_t m_size; /* Bytes in the part */
1309 size_t m_xsize; /* Bytes in the full part */
1310 long m_lines; /* Lines in the message */
1311 long m_xlines; /* Lines in the full message */
1312 time_t m_time; /* time the message was sent */
1313 char const *m_from; /* message sender */
1314 struct mimepart *m_nextpart; /* next part at same level */
1315 struct mimepart *m_multipart; /* parts of multipart */
1316 struct mimepart *m_parent; /* enclosing multipart part */
1317 char *m_ct_type; /* content-type */
1318 char *m_ct_type_plain; /* content-type without specs */
1319 char *m_ct_type_usr_ovwr; /* Forcefully overwritten one */
1320 enum mimecontent m_mimecontent; /* same in enum */
1321 char const *m_charset; /* charset */
1322 char *m_ct_transfer_enc; /* content-transfer-encoding */
1323 enum mimeenc m_mimeenc; /* same in enum */
1324 char *m_partstring; /* part level string */
1325 char *m_filename; /* attachment filename */
1328 struct message {
1329 enum mflag m_flag; /* flags */
1330 enum havespec m_have; /* downloaded parts of the message */
1331 #ifdef HAVE_SPAM
1332 ui32_t m_spamscore; /* Spam score as int, 24:8 bits */
1333 #endif
1334 int m_block; /* block number of this message */
1335 size_t m_offset; /* offset in block of message */
1336 size_t m_size; /* Bytes in the message */
1337 size_t m_xsize; /* Bytes in the full message */
1338 long m_lines; /* Lines in the message */
1339 long m_xlines; /* Lines in the full message */
1340 time_t m_time; /* time the message was sent */
1341 time_t m_date; /* time in the 'Date' field */
1342 unsigned m_idhash; /* hash on Message-ID for threads */
1343 struct message *m_child; /* first child of this message */
1344 struct message *m_younger; /* younger brother of this message */
1345 struct message *m_elder; /* elder brother of this message */
1346 struct message *m_parent; /* parent of this message */
1347 unsigned m_level; /* thread level of message */
1348 long m_threadpos; /* position in threaded display */
1349 #ifdef HAVE_IMAP
1350 unsigned long m_uid; /* IMAP unique identifier */
1351 #endif
1352 char *m_maildir_file; /* original maildir file of msg */
1353 ui32_t m_maildir_hash; /* hash of file name in maildir sub */
1354 int m_collapsed; /* collapsed thread information */
1357 /* Given a file address, determine the block number it represents */
1358 #define mailx_blockof(off) ((int) ((off) / 4096))
1359 #define mailx_offsetof(off) ((int) ((off) % 4096))
1360 #define mailx_positionof(block, offset) ((off_t)(block) * 4096 + (offset))
1362 /* Argument types */
1363 enum argtype {
1364 ARG_MSGLIST = 0, /* Message list type */
1365 ARG_STRLIST = 1, /* A pure string */
1366 ARG_RAWLIST = 2, /* Shell string list */
1367 ARG_NOLIST = 3, /* Just plain 0 */
1368 ARG_NDMLIST = 4, /* Message list, no defaults */
1369 ARG_ECHOLIST = 5, /* Like raw list, but keep quote chars */
1370 ARG_ARGMASK = 7, /* Mask of the above */
1372 ARG_A = 1u<< 4, /* Needs an active mailbox */
1373 ARG_F = 1u<< 5, /* Is a conditional command */
1374 ARG_H = 1u<< 6, /* Never place in history */
1375 ARG_I = 1u<< 7, /* Interactive command bit */
1376 ARG_M = 1u<< 8, /* Legal from send mode bit */
1377 ARG_P = 1u<< 9, /* Autoprint dot after command */
1378 ARG_R = 1u<<10, /* Cannot be called from collect / recursion */
1379 ARG_T = 1u<<11, /* Is a transparent command */
1380 ARG_V = 1u<<12, /* Places data in temporary_arg_v_store */
1381 ARG_W = 1u<<13 /* Invalid when read only bit */
1384 enum gfield {
1385 GTO = 1, /* Grab To: line */
1386 GSUBJECT = 2, /* Likewise, Subject: line */
1387 GCC = 4, /* And the Cc: line */
1388 GBCC = 8, /* And also the Bcc: line */
1390 GNL = 16, /* Print blank line after */
1391 GDEL = 32, /* Entity removed from list */
1392 GCOMMA = 64, /* detract puts in commas */
1393 GUA = 128, /* User-Agent field */
1394 GMIME = 256, /* MIME 1.0 fields */
1395 GMSGID = 512, /* a Message-ID */
1396 /* 1024 */
1397 GIDENT = 2048, /* From:, Reply-To: and Organization: field */
1398 GREF = 4096, /* References: field */
1399 GDATE = 8192, /* Date: field */
1400 GFULL = 16384, /* include full names */
1401 GSKIN = 32768, /* skin names */
1402 GEXTRA = 65536, /* extra fields */
1403 GFILES = 131072 /* include filename addresses */
1405 #define GMASK (GTO | GSUBJECT | GCC | GBCC)
1407 /* Structure used to pass about the current state of a message (header) */
1408 struct header {
1409 struct name *h_to; /* Dynamic "To:" string */
1410 char *h_subject; /* Subject string */
1411 struct name *h_cc; /* Carbon copies string */
1412 struct name *h_bcc; /* Blind carbon copies */
1413 struct name *h_ref; /* References */
1414 struct attachment *h_attach; /* MIME attachments */
1415 char *h_charset; /* preferred charset */
1416 struct name *h_from; /* overridden "From:" field */
1417 struct name *h_replyto; /* overridden "Reply-To:" field */
1418 struct name *h_sender; /* overridden "Sender:" field */
1419 char *h_organization; /* overridden "Organization:" field */
1422 /* Handling of namelist nodes used in processing the recipients of mail and
1423 * aliases, inspection of mail-addresses and all that kind of stuff */
1424 enum nameflags {
1425 NAME_NAME_SALLOC = 1<< 0, /* .n_name is doped */
1426 NAME_FULLNAME_SALLOC = 1<< 1, /* .n_fullname is doped */
1427 NAME_SKINNED = 1<< 2, /* Is actually skin()ned */
1428 NAME_IDNA = 1<< 3, /* IDNA was applied */
1429 NAME_ADDRSPEC_CHECKED = 1<< 4, /* Address has been .. and */
1430 NAME_ADDRSPEC_ISFILE = 1<< 5, /* ..is a file path */
1431 NAME_ADDRSPEC_ISPIPE = 1<< 6, /* ..is a command for piping */
1432 NAME_ADDRSPEC_ISFILEORPIPE = NAME_ADDRSPEC_ISFILE | NAME_ADDRSPEC_ISPIPE,
1433 NAME_ADDRSPEC_ERR_EMPTY = 1<< 7, /* An empty string (or NULL) */
1434 NAME_ADDRSPEC_ERR_ATSEQ = 1<< 8, /* Weird @ sequence */
1435 NAME_ADDRSPEC_ERR_CHAR = 1<< 9, /* Invalid character */
1436 NAME_ADDRSPEC_ERR_IDNA = 1<<10, /* IDNA convertion failed */
1437 NAME_ADDRSPEC_INVALID = NAME_ADDRSPEC_ERR_EMPTY |
1438 NAME_ADDRSPEC_ERR_ATSEQ | NAME_ADDRSPEC_ERR_CHAR |
1439 NAME_ADDRSPEC_ERR_IDNA,
1441 _NAME_SHIFTWC = 11,
1442 _NAME_MAXWC = 0xFFFFF,
1443 _NAME_MASKWC = _NAME_MAXWC << _NAME_SHIFTWC
1446 /* In the !_ERR_EMPTY case, the failing character can be queried */
1447 #define NAME_ADDRSPEC_ERR_GETWC(F) \
1448 ((((unsigned int)(F) & _NAME_MASKWC) >> _NAME_SHIFTWC) & _NAME_MAXWC)
1449 #define NAME_ADDRSPEC_ERR_SET(F, E, WC) \
1450 do {\
1451 (F) = ((F) & ~(NAME_ADDRSPEC_INVALID | _NAME_MASKWC)) |\
1452 (E) | (((unsigned int)(WC) & _NAME_MAXWC) << _NAME_SHIFTWC);\
1453 } while (0)
1455 struct name {
1456 struct name *n_flink; /* Forward link in list. */
1457 struct name *n_blink; /* Backward list link */
1458 enum gfield n_type; /* From which list it came */
1459 enum nameflags n_flags; /* enum nameflags */
1460 char *n_name; /* This fella's name */
1461 char *n_fullname; /* Sometimes, name including comment */
1464 struct addrguts {
1465 char const *ag_input; /* Input string as given */
1466 size_t ag_ilen; /* strlen() of input */
1467 size_t ag_iaddr_start; /* Start of *addr-spec* in .ag_input */
1468 size_t ag_iaddr_aend; /* ..and one past its end */
1469 char *ag_skinned; /* Output (alloced if !=.ag_input) */
1470 size_t ag_slen; /* strlen() of .ag_skinned */
1471 size_t ag_sdom_start; /* Start of domain in .ag_skinned, */
1472 enum nameflags ag_n_flags; /* enum nameflags of .ag_skinned */
1475 /* MIME attachments */
1476 enum attach_conv {
1477 AC_DEFAULT, /* _get_lc() -> _iter_*() */
1478 AC_FIX_OUTCS, /* _get_lc() -> "charset=" .a_charset */
1479 AC_FIX_INCS, /* "charset=".a_input_charset (nocnv) */
1480 AC_TMPFILE /* attachment.a_tmpf is converted */
1483 struct attachment {
1484 struct attachment *a_flink; /* Forward link in list. */
1485 struct attachment *a_blink; /* Backward list link */
1486 char const *a_name; /* file name */
1487 char const *a_content_type; /* content type */
1488 char const *a_content_disposition; /* content disposition */
1489 char const *a_content_id; /* content id */
1490 char const *a_content_description; /* content description */
1491 char const *a_input_charset; /* Interpretation depends on .a_conv */
1492 char const *a_charset; /* ... */
1493 FILE *a_tmpf; /* If AC_TMPFILE */
1494 enum attach_conv a_conv; /* User chosen conversion */
1495 int a_msgno; /* message number */
1498 struct sendbundle {
1499 struct header *sb_hp;
1500 struct name *sb_to;
1501 FILE *sb_input;
1502 struct str sb_signer; /* USER@HOST for signing+ */
1503 struct url sb_url;
1504 struct ccred sb_ccred;
1507 struct group {
1508 struct group *ge_link; /* Next person in this group */
1509 char *ge_name; /* This person's user name */
1512 struct grouphead {
1513 struct grouphead *g_link; /* Next grouphead in list */
1514 char *g_name; /* Name of this group */
1515 struct group *g_list; /* Users in group. */
1518 /* Structure of the hash table of ignored header fields */
1519 struct ignoretab {
1520 int i_count; /* Number of entries */
1521 struct ignore {
1522 struct ignore *i_link; /* Next ignored field in bucket */
1523 char *i_field; /* This ignored field */
1524 } *i_head[HSHSIZE];
1527 /* For the 'shortcut' and 'unshortcut' functionality */
1528 struct shortcut {
1529 struct shortcut *sh_next; /* next shortcut in list */
1530 char *sh_short; /* shortcut string */
1531 char *sh_long; /* expanded form */
1534 /* For saving the current directory and later returning */
1535 struct cw {
1536 #ifdef HAVE_FCHDIR
1537 int cw_fd;
1538 #else
1539 char cw_wd[PATH_MAX];
1540 #endif
1544 * Global variable declarations
1546 * These become instantiated in main.c.
1549 #undef VL
1550 #ifdef _MAIN_SOURCE
1551 # ifndef HAVE_AMALGAMATION
1552 # define VL
1553 # else
1554 # define VL static
1555 # endif
1556 #else
1557 # define VL extern
1558 #endif
1560 VL gid_t effectivegid; /* Saved from when we started up */
1561 VL gid_t realgid; /* Saved from when we started up */
1563 VL int mb_cur_max; /* Value of MB_CUR_MAX */
1564 VL int realscreenheight; /* The real screen height */
1565 VL int scrnwidth; /* Screen width, or best guess */
1566 VL int scrnheight; /* Screen height/guess (4 header) */
1567 VL int enc_has_state; /* Encoding has shift states */
1569 VL char **altnames; /* List of alternate names of user */
1570 VL char const *homedir; /* Path name of home directory */
1571 VL char const *myname; /* My login name */
1572 VL char const *progname; /* Our name */
1573 VL char const *tempdir; /* The temporary directory */
1575 VL int exit_status; /* Exit status */
1576 VL int options; /* Bits of enum user_options */
1577 VL char *option_r_arg; /* Argument to -r option */
1578 VL char const **smopts; /* sendmail(1) opts from commline */
1579 VL size_t smopts_count; /* Entries in smopts */
1581 /* TODO Join as many of these state machine bits into a single carrier! */
1582 VL int inhook; /* Currently executing a hook */
1583 VL bool_t exec_last_comm_error; /* Last execute() command failed */
1584 VL bool_t edit; /* Indicates editing a file */
1585 VL bool_t did_print_dot; /* Current message has been printed */
1586 VL bool_t list_saw_numbers; /* Last *LIST saw numerics */
1587 VL bool_t msglist_is_single; /* Last NDMLIST/MSGLIST chose 1 msg */
1588 VL bool_t loading; /* Loading user definitions */
1589 VL bool_t sourcing; /* Currently reading variant file */
1590 VL bool_t sawcom; /* Set after first command */
1591 VL bool_t starting; /* Still in startup code */
1592 VL bool_t var_clear_allow_undefined; /* v?ok_[bv]clear(): no complain */
1593 VL int noreset; /* String resets suspended */
1595 /* XXX stylish sorting */
1596 VL int msgCount; /* Count of messages read in */
1597 VL struct mailbox mb; /* Current mailbox */
1598 VL int image; /* File descriptor for msg image */
1599 VL char mailname[PATH_MAX]; /* Name of current file TODO URL/object*/
1600 VL char displayname[80 - 40]; /* Prettyfied for display TODO URL/obj*/
1601 VL char prevfile[PATH_MAX]; /* Name of previous file TODO URL/obj */
1602 VL char const *account_name; /* Current account name or NULL */
1603 VL off_t mailsize; /* Size of system mailbox */
1604 VL struct message *dot; /* Pointer to current message */
1605 VL struct message *prevdot; /* Previous current message */
1606 VL struct message *message; /* The actual message structure */
1607 VL struct message *threadroot; /* first threaded message */
1608 VL int imap_created_mailbox; /* hack to get feedback from imap */
1610 VL struct grouphead *groups[HSHSIZE]; /* Pointer to active groups */
1611 VL struct ignoretab ignore[2]; /* ignored and retained fields
1612 * 0 is ignore, 1 is retain */
1613 VL struct ignoretab saveignore[2]; /* ignored and retained fields
1614 * on save to folder */
1615 VL struct ignoretab allignore[2]; /* special, ignore all headers */
1616 VL struct ignoretab fwdignore[2]; /* fields to ignore for forwarding */
1617 VL struct shortcut *shortcuts; /* list of shortcuts */
1619 VL struct time_current time_current; /* time(3); send: mail1() XXXcarrier */
1620 VL struct termios_state termios_state; /* getpassword(); see commands().. */
1622 #ifdef HAVE_COLOUR
1623 VL struct colour_table *colour_table;
1624 #endif
1626 #ifdef HAVE_SSL
1627 VL enum ssl_verify_level ssl_verify_level; /* SSL verification level */
1628 #endif
1630 #ifdef HAVE_ICONV
1631 VL iconv_t iconvd;
1632 #endif
1634 VL sigjmp_buf srbuf;
1635 VL int interrupts;
1636 VL sighandler_type dflpipe;
1637 VL sighandler_type handlerstacktop;
1638 #define handlerpush(f) (savedtop = handlerstacktop, handlerstacktop = (f))
1639 #define handlerpop() (handlerstacktop = savedtop)
1641 /* TODO Temporary hacks unless the codebase doesn't jump and uses pass-by-value
1642 * TODO carrier structs instead of locals */
1643 VL char *temporary_arg_v_store;
1644 VL void *temporary_localopts_store;
1645 /* TODO temporary storage to overcome which_protocol() mess (for PROTO_FILE) */
1646 VL char const *temporary_protocol_ext;
1648 /* The remaining variables need initialization */
1650 #ifndef HAVE_AMALGAMATION
1651 VL char const month_names[12 + 1][4];
1652 VL char const weekday_names[7 + 1][4];
1654 VL char const uagent[]; /* User agent */
1655 VL char const version[]; /* The version string */
1656 VL char const features[]; /* The "feature string" */
1658 VL uc_i const class_char[];
1659 #endif
1662 * Finally, let's include the function prototypes XXX embed
1665 #include "nailfuns.h"
1667 /* s-it-mode */