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