Avoid "cannot canonicalize" maildir warning..
[s-mailx.git] / nail.h
blobba959cd5fd2f67add214bf21b0e46ffe584fc90e
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_DEBUG
70 # include <assert.h>
71 #endif
72 #ifdef HAVE_ICONV
73 # include <iconv.h>
74 #endif
75 #ifdef HAVE_C90AMEND1
76 # include <wchar.h>
77 # include <wctype.h>
78 #endif
81 * Constants, some nail-specific macros
84 #if !defined NI_MAXHOST || NI_MAXHOST < 1025
85 # undef NI_MAXHOST
86 # define NI_MAXHOST 1025
87 #endif
89 #ifndef MAXPATHLEN
90 # ifdef PATH_MAX
91 # define MAXPATHLEN PATH_MAX
92 # else
93 # define MAXPATHLEN 1024
94 # endif
95 #elif defined PATH_MAX && MAXPATHLEN < PATH_MAX
96 # undef MAXPATHLEN
97 # define MAXPATHLEN PATH_MAX
98 #endif
100 #ifndef STDIN_FILENO
101 # define STDIN_FILENO 0
102 #endif
103 #ifndef STDOUT_FILENO
104 # define STDOUT_FILENO 1
105 #endif
106 #ifndef STDERR_FILENO
107 # define STDERR_FILENO 2
108 #endif
110 #ifdef NSIG_MAX
111 # undef NSIG
112 # define NSIG NSIG_MAX
113 #elif !defined NSIG
114 # define NSIG ((sizeof(sigset_t) * 8) - 1)
115 #endif
117 /* */
119 #if BUFSIZ > 2560 /* TODO simply use BUFSIZ? */
120 # define LINESIZE BUFSIZ /* max readable line width */
121 #else
122 # define LINESIZE 2560
123 #endif
124 #define BUFFER_SIZE (BUFSIZ >= (1u << 13) ? BUFSIZ : (1u << 14))
126 #define CBAD (-15555)
127 #define APPEND /* New mail goes to end of mailbox */
128 #define ESCAPE '~' /* Default escape for sending */
129 #define HIST_SIZE 242 /* tty.c: history list default size */
130 #define HSHSIZE 23 /* Hash prime (aliases, vars, macros) */
131 #define MAXARGC 1024 /* Maximum list of raw strings */
132 #define MAXEXP 25 /* Maximum expansion of aliases */
133 #define PROMPT_BUFFER_SIZE 80 /* getprompt() bufsize (> 3!) */
135 #define ACCOUNT_NULL "null" /* Name of "null" account */
136 #define MAILRC "~/.mailrc"
137 #define TMPDIR_FALLBACK "/tmp"
139 #define COLOUR_MSGINFO "fg=green"
140 #define COLOUR_PARTINFO "fg=brown"
141 #define COLOUR_FROM_ "fg=brown"
142 #define COLOUR_HEADER "fg=red"
143 #define COLOUR_UHEADER "ft=bold,fg=red"
144 #define COLOUR_PAGERS "less"
145 #define COLOUR_TERMS \
146 "cons25,linux,rxvt,rxvt-unicode,screen,sun,"\
147 "vt100,vt220,wsvt25,xterm,xterm-color"
148 #define COLOUR_USER_HEADERS "from,subject"
150 #define FROM_DATEBUF 64 /* Size of RFC 4155 From_ line date */
151 #define DATE_DAYSYEAR 365L
152 #define DATE_SECSMIN 60L
153 #define DATE_MINSHOUR 60L
154 #define DATE_HOURSDAY 24L
155 #define DATE_SECSDAY (DATE_SECSMIN * DATE_MINSHOUR * DATE_HOURSDAY)
157 /* Default *encoding* as enum conversion below */
158 #define MIME_DEFAULT_ENCODING CONV_TOQP
160 /* Maximum allowed line length in a mail before QP folding is necessary), and
161 * the real limit we go for */
162 #define MIME_LINELEN_MAX 1000
163 #define MIME_LINELEN_LIMIT (MIME_LINELEN_MAX - 50)
165 /* Locations of mime.types(5) */
166 #define MIME_TYPES_USR "~/.mime.types"
167 #define MIME_TYPES_SYS "/etc/mime.types"
169 /* Fallback MIME charsets, if *charset-7bit* and *charset-8bit* or not set */
170 #define CHARSET_7BIT "US-ASCII"
171 #ifdef HAVE_ICONV
172 # define CHARSET_8BIT "UTF-8"
173 # define CHARSET_8BIT_OKEY charset_8bit
174 #else
175 # define CHARSET_8BIT "ISO-8859-1"
176 # define CHARSET_8BIT_OKEY ttycharset
177 #endif
179 /* Is *W* a quoting (ASCII only) character? */
180 #define ISQUOTE(W) \
181 ((W) == L'>' || (W) == L'|' || (W) == L'}' || (W) == L':')
183 /* Maximum number of quote characters (not bytes!) that'll be used on
184 * follow lines when compressing leading quote characters */
185 #define QUOTE_MAX 42
187 /* How much spaces should a <tab> count when *quote-fold*ing? (power-of-two!) */
188 #define QUOTE_TAB_SPACES 8
190 /* Maximum size of a message that is passed through to the spam system */
191 #define SPAM_MAXSIZE 420000
193 /* String dope: dynamic buffer size, and size of the single builtin one that's
194 * used first */
195 #define SBUFFER_SIZE 0x18000u
196 #define SBUFFER_BUILTIN 0x2000u
198 /* These come from the configuration (named Xxy to not clash with sh(1)..) */
199 #ifndef XSHELL
200 # define XSHELL "/bin/sh"
201 #endif
202 #ifndef XLISTER
203 # define XLISTER "ls"
204 #endif
205 #ifndef XPAGER
206 # define XPAGER "more"
207 #endif
210 * CC support, generic macros etc.
213 #undef __PREREQ
214 #if defined __GNUC__ || defined __clang__
215 # define __EXTEN __extension__
216 # ifdef __GNUC__
217 # define __PREREQ(X,Y) \
218 (__GNUC__ > (X) || (__GNUC__ == (X) && __GNUC_MINOR__ >= (Y)))
219 # else
220 # define __PREREQ(X,Y) 1
221 # endif
222 #else
223 # define __EXTEN
224 # define __PREREQ(X,Y) 0
225 #endif
227 #define EMPTY_FILE(F) typedef int CONCAT(avoid_empty_file__, F);
229 /* Pointer to size_t */
230 #define PTR2SIZE(X) ((size_t)(uintptr_t)(X))
232 /* Pointer comparison (types from below) */
233 #define PTRCMP(A,C,B) ((uintptr_t)(A) C (uintptr_t)(B))
235 /* Ditto, compare (maybe mixed-signed) integers cases to T bits, unsigned;
236 * Note: doesn't sign-extend correctly, that's still up to the caller */
237 #define UICMP(T,A,C,B) ((ui ## T ## _t)(A) C (ui ## T ## _t)(B))
239 /* Members in constant array */
240 #ifndef NELEM
241 # define NELEM(A) (sizeof(A) / sizeof(A[0]))
242 #endif
244 /* sizeof() for member fields */
245 #define SIZEOF_FIELD(T,F) sizeof(((T *)NULL)->F)
247 /* Casts-away (*NOT* cast-away) */
248 #define UNUSED(X) ((void)(X))
249 #define UNCONST(P) ((void*)(uintptr_t)(void const*)(P))
250 #define UNVOLATILE(P) ((void*)(uintptr_t)(void volatile*)(P))
251 #define UNXXX(T,C,P) ((T)(uintptr_t)(C)(P))
253 /* __STDC_VERSION__ is ISO C99, so also use __STDC__, which should work */
254 #if defined __STDC__ || defined __STDC_VERSION__ /*|| defined __cplusplus*/
255 # define STRING(X) #X
256 # define XSTRING(X) STRING(X)
257 # define CONCAT(S1,S2) _CONCAT(S1, S2)
258 # define _CONCAT(S1,S2) S1 ## S2
259 #else
260 # define STRING(X) "X"
261 # define XSTRING STRING
262 # define CONCAT(S1,S2) S1/**/S2
263 #endif
265 #if defined __STDC_VERSION__ && __STDC_VERSION__ + 0 >= 199901L
266 /* Variable size arrays and structure fields */
267 # define VFIELD_SIZE(X)
268 # define VFIELD_SIZEOF(T,F) (0)
269 /* Inline functions */
270 # define HAVE_INLINE
271 # define INLINE inline
272 # define SINLINE static inline
273 #else
274 # define VFIELD_SIZE(X) (X)
275 # define VFIELD_SIZEOF(T,F) SIZEOF_FIELD(T, F)
276 # if __PREREQ(2, 9)
277 # define INLINE static __inline
278 # define SINLINE static __inline
279 # else
280 # define INLINE
281 # define SINLINE static
282 # endif
283 #endif
285 #if defined __predict_true && defined __predict_false
286 # define LIKELY(X) __predict_true(X)
287 # define UNLIKELY(X) __predict_false(X)
288 #elif __PREREQ(2, 96)
289 # define LIKELY(X) __builtin_expect(X, 1)
290 # define UNLIKELY(X) __builtin_expect(X, 0)
291 #else
292 # define LIKELY(X) (X)
293 # define UNLIKELY(X) (X)
294 #endif
296 /* Compile-Time-Assert */
297 #define CTA(TEST) _CTA_1(TEST, __LINE__)
298 #define _CTA_1(TEST,L) _CTA_2(TEST, L)
299 #define _CTA_2(TEST,L) \
300 typedef char COMPILE_TIME_ASSERT_failed_at_line_ ## L[(TEST) ? 1 : -1]
302 #undef ISPOW2
303 #define ISPOW2(X) ((((X) - 1) & (X)) == 0)
304 #undef MIN
305 #define MIN(A, B) ((A) < (B) ? (A) : (B))
306 #undef MAX
307 #define MAX(A, B) ((A) < (B) ? (B) : (A))
308 #undef ABS
309 #define ABS(A) ((A) < 0 ? -(A) : (A))
311 #undef DBG
312 #undef NDBG
313 #ifndef HAVE_DEBUG
314 # undef assert
315 # define assert(X) UNUSED(0)
316 # define DBG(X)
317 # define NDBG(X) X
318 #else
319 # define DBG(X) X
320 # define NDBG(X)
321 #endif
323 /* Translation (init in main.c) */
324 #undef tr
325 #ifdef HAVE_CATGETS
326 # define CATSET 1
327 # define tr(c,d) catgets(catd, CATSET, c, d)
328 #else
329 # define tr(c,d) (d)
330 #endif
333 * Types
336 /* TODO convert all integer types to the new [su]i(8|16|32|64)_t */
337 typedef unsigned long ul_it;
338 typedef unsigned int ui_it;
339 typedef unsigned short us_it;
340 typedef unsigned char uc_it;
342 typedef signed long sl_it;
343 typedef signed int si_it;
344 typedef signed short ss_it;
345 typedef signed char sc_it;
347 #ifdef UINT8_MAX
348 # define UI8_MAX UINT8_MAX
349 # define SI8_MIN INT8_MIN
350 # define SI8_MAX INT8_MAX
351 typedef uint8_t ui8_t;
352 typedef int8_t si8_t;
353 #elif UCHAR_MAX != 255
354 # error UCHAR_MAX must be 255
355 #else
356 # define UI8_MAX UCHAR_MAX
357 # define SI8_MIN CHAR_MIN
358 # define SI8_MAX CHAR_MAX
359 typedef unsigned char ui8_t;
360 typedef signed char si8_t;
361 #endif
363 #ifdef UINT16_MAX
364 # define UI16_MAX UINT16_MAX
365 # define SI16_MIN INT16_MIN
366 # define SI16_MAX INT16_MAX
367 typedef uint16_t ui16_t;
368 typedef int16_t si16_t;
369 #elif USHRT_MAX != 0xFFFFu
370 # error USHRT_MAX must be 0xFFFF
371 #else
372 # define UI16_MAX USHRT_MAX
373 # define SI16_MIN SHRT_MIN
374 # define SI16_MAX SHRT_MAX
375 typedef unsigned short ui16_t;
376 typedef signed short si16_t;
377 #endif
379 #ifdef UINT32_MAX
380 # define UI32_MAX UINT32_MAX
381 # define SI32_MIN INT32_MIN
382 # define SI32_MAX INT32_MAX
383 typedef uint32_t ui32_t;
384 typedef int32_t si32_t;
385 #elif ULONG_MAX == 0xFFFFFFFFu
386 # define UI32_MAX ULONG_MAX
387 # define SI32_MIN LONG_MIN
388 # define SI32_MAX LONG_MAX
389 typedef unsigned long int ui32_t;
390 typedef signed long int si32_t;
391 #elif UINT_MAX != 0xFFFFFFFFu
392 # error UINT_MAX must be 0xFFFFFFFF
393 #else
394 # define UI32_MAX UINT_MAX
395 # define SI32_MIN INT_MIN
396 # define SI32_MAX INT_MAX
397 typedef unsigned int ui32_t;
398 typedef signed int si32_t;
399 #endif
401 #ifdef UINT64_MAX
402 # define UI64_MAX UINT64_MAX
403 # define SI64_MIN INT64_MIN
404 # define SI64_MAX INT64_MAX
405 typedef uint64_t ui64_t;
406 #elif ULONG_MAX <= 0xFFFFFFFFu
407 # if !defined ULLONG_MAX || ULLONG_MAX != 0xFFFFFFFFFFFFFFFFu
408 # error We need a 64 bit integer
409 # else
410 # define UI64_MAX ULLONG_MAX
411 # define SI64_MIN LLONG_MIN
412 # define SI64_MAX LLONG_MAX
413 __EXTEN typedef unsigned long long ui64_t;
414 __EXTEN typedef signed long long si64_t;
415 # endif
416 #else
417 # define UI64_MAX ULONG_MAX
418 # define SI64_MIN LONG_MIN
419 # define SI64_MAX LONG_MAX
420 typedef unsigned long ui64_t;
421 typedef signed long si64_t;
422 #endif
424 /* (So that we can use UICMP() for size_t comparison, too) */
425 typedef size_t uiz_t;
426 /*typedef ssize_t siz_t;*/
428 #ifndef UINTPTR_MAX
429 # ifdef SIZE_MAX
430 # define uintptr_t size_t
431 # define UINTPTR_MAX SIZE_MAX
432 # else
433 # define uintptr_t unsigned long
434 # define UINTPTR_MAX ULONG_MAX
435 # endif
436 #endif
438 /* XXX Note we don't really deal with that the right way in that we pass size_t
439 * XXX arguments without casting; should do, because above we assert UINT_MAX
440 * XXX is indeed ui32_t */
441 #if defined __STDC_VERSION__ && __STDC_VERSION__ + 0 >= 199901L
442 # define ZFMT "zu"
443 #elif defined SIZE_MAX && SIZE_MAX == 0xFFFFFFFFu && ULONG_MAX != UINT_MAX
444 # define ZFMT "u"
445 #endif
446 #ifndef ZFMT
447 # define ZFMT "lu"
448 #endif
450 typedef enum {FAL0, TRU1} bool_t;
452 typedef void ( *sighandler_type)(int);
454 enum user_options {
455 OPT_NONE,
456 OPT_DEBUG = 1u<< 0, /* -d / *debug* */
457 OPT_VERBOSE = 1u<< 1, /* -v / *verbose* */
458 OPT_EXISTONLY = 1u<< 2, /* -e */
459 OPT_HEADERSONLY = 1u<< 3, /* -H */
460 OPT_NOSRC = 1u<< 4, /* -n */
461 OPT_E_FLAG = 1u<< 5, /* -E / *skipemptybody* */
462 OPT_F_FLAG = 1u<< 6, /* -F */
463 OPT_N_FLAG = 1u<< 7, /* -N / *header* */
464 OPT_R_FLAG = 1u<< 8, /* -R */
465 OPT_r_FLAG = 1u<< 9, /* -r (plus option_r_arg) */
466 OPT_t_FLAG = 1u<<10, /* -t */
467 OPT_u_FLAG = 1u<<11, /* -u given, or USER != getpwnam(3) */
468 OPT_TILDE_FLAG = 1u<<12, /* -~ */
469 OPT_BATCH_FLAG = 1u<<13, /* -# */
471 OPT_SENDMODE = 1u<<14, /* Usage case forces send mode */
472 OPT_INTERACTIVE = 1u<<15, /* isatty(0) */
473 OPT_TTYIN = OPT_INTERACTIVE,
474 OPT_TTYOUT = 1u<<16
476 #define IS_TTY_SESSION() \
477 ((options & (OPT_TTYIN | OPT_TTYOUT)) == (OPT_TTYIN | OPT_TTYOUT))
479 enum exit_status {
480 EXIT_OK = EXIT_SUCCESS,
481 EXIT_ERR = EXIT_FAILURE,
482 EXIT_COLL_ABORT = 1<<1, /* Message collection was aborted */
483 EXIT_SEND_ERROR = 1<<2 /* Unspecified send error occurred */
486 enum fexp_mode {
487 FEXP_FULL, /* Full expansion */
488 FEXP_LOCAL = 1<<0, /* Result must be local file/maildir */
489 FEXP_SHELL = 1<<1, /* No folder %,#,&,+ stuff, yet sh(1) */
490 FEXP_NSHORTCUT = 1<<2, /* Don't expand shortcuts */
491 FEXP_SILENT = 1<<3, /* Don't print but only return errors */
492 FEXP_MULTIOK = 1<<4 /* Expansion to many entries is ok */
495 /* <0 means "stop" unless *prompt* extensions are enabled. */
496 enum prompt_exp {
497 PROMPT_STOP = -1, /* \c */
498 /* *prompt* extensions: \$, \@ etc. */
499 PROMPT_DOLLAR = -2,
500 PROMPT_AT = -3
503 enum colourspec {
504 COLOURSPEC_MSGINFO,
505 COLOURSPEC_PARTINFO,
506 COLOURSPEC_FROM_,
507 COLOURSPEC_HEADER,
508 COLOURSPEC_UHEADER,
509 COLOURSPEC_RESET
512 enum okay {
513 STOP = 0,
514 OKAY = 1
517 enum mimeenc {
518 MIME_NONE, /* message is not in MIME format */
519 MIME_BIN, /* message is in binary encoding */
520 MIME_8B, /* message is in 8bit encoding */
521 MIME_7B, /* message is in 7bit encoding */
522 MIME_QP, /* message is quoted-printable */
523 MIME_B64 /* message is in base64 encoding */
526 enum conversion {
527 CONV_NONE, /* no conversion */
528 CONV_7BIT, /* no conversion, is 7bit */
529 CONV_FROMQP, /* convert from quoted-printable */
530 CONV_TOQP, /* convert to quoted-printable */
531 CONV_8BIT, /* convert to 8bit (iconv) */
532 CONV_FROMB64, /* convert from base64 */
533 CONV_FROMB64_T, /* convert from base64/text */
534 CONV_TOB64, /* convert to base64 */
535 CONV_FROMHDR, /* convert from RFC1522 format */
536 CONV_TOHDR, /* convert to RFC1522 format */
537 CONV_TOHDR_A /* convert addresses for header */
540 enum sendaction {
541 SEND_MBOX, /* no conversion to perform */
542 SEND_RFC822, /* no conversion, no From_ line */
543 SEND_TODISP, /* convert to displayable form */
544 SEND_TODISP_ALL, /* same, include all MIME parts */
545 SEND_SHOW, /* convert to 'show' command form */
546 SEND_TOSRCH, /* convert for IMAP SEARCH */
547 SEND_TOFLTR, /* convert for spam mail filtering */
548 SEND_TOFILE, /* convert for saving body to a file */
549 SEND_TOPIPE, /* convert for pipe-content/subc. */
550 SEND_QUOTE, /* convert for quoting */
551 SEND_QUOTE_ALL, /* same, include all MIME parts */
552 SEND_DECRYPT /* decrypt */
555 enum mimecontent {
556 MIME_UNKNOWN, /* unknown content */
557 MIME_SUBHDR, /* inside a multipart subheader */
558 MIME_822, /* message/rfc822 content */
559 MIME_MESSAGE, /* other message/ content */
560 MIME_TEXT_PLAIN, /* text/plain content */
561 MIME_TEXT_HTML, /* text/html content */
562 MIME_TEXT, /* other text/ content */
563 MIME_ALTERNATIVE, /* multipart/alternative content */
564 MIME_DIGEST, /* multipart/digest content */
565 MIME_MULTI, /* other multipart/ content */
566 MIME_PKCS7, /* PKCS7 content */
567 MIME_DISCARD /* content is discarded */
570 enum tdflags {
571 TD_NONE, /* no display conversion */
572 TD_ISPR = 1<<0, /* use isprint() checks */
573 TD_ICONV = 1<<1, /* use iconv() */
574 TD_DELCTRL = 1<<2, /* delete control characters */
577 * NOTE: _TD_EOF and _TD_BUFCOPY may be ORd with enum conversion and
578 * enum sendaction, and may thus NOT clash with their bit range!
580 _TD_EOF = 1<<14, /* EOF seen, last round! */
581 _TD_BUFCOPY = 1<<15 /* Buffer may be constant, copy it */
584 enum protocol {
585 PROTO_FILE, /* refers to a local file */
586 PROTO_POP3, /* is a pop3 server string */
587 PROTO_IMAP, /* is an imap server string */
588 PROTO_MAILDIR, /* refers to a maildir folder */
589 PROTO_UNKNOWN /* unknown protocol */
592 #ifdef HAVE_SSL
593 enum ssl_vrfy_level {
594 VRFY_IGNORE,
595 VRFY_WARN,
596 VRFY_ASK,
597 VRFY_STRICT
599 #endif
601 /* A large enum with all the binary and value options a.k.a their keys.
602 * Only the constant keys are in here, to be looked up via ok_[bv]look(),
603 * ok_[bv]set() and ok_[bv]clear().
604 * Note: see the comments in acmava.c before changing *anything* in here! */
605 enum okeys {
606 /* Option keys for binary options */
607 ok_b_add_file_recipients,
608 ok_b_allnet,
609 ok_b_append,
610 ok_b_ask,
611 ok_b_askatend,
612 ok_b_askattach,
613 ok_b_askbcc,
614 ok_b_askcc,
615 ok_b_asksign,
616 ok_b_asksub,
617 ok_b_attachment_ask_content_description,
618 ok_b_attachment_ask_content_disposition,
619 ok_b_attachment_ask_content_id,
620 ok_b_attachment_ask_content_type,
621 ok_b_autocollapse,
622 ok_b_autoprint,
623 ok_b_autothread,
624 ok_b_bang,
625 ok_b_batch_exit_on_error,
626 ok_b_bsdannounce,
627 ok_b_bsdcompat,
628 ok_b_bsdflags,
629 ok_b_bsdheadline,
630 ok_b_bsdmsgs,
631 ok_b_bsdorder,
632 ok_b_bsdset,
633 ok_b_colour_disable,
634 ok_b_debug, /* {special=1} */
635 ok_b_disconnected,
636 ok_b_dot,
637 ok_b_editalong,
638 ok_b_editheaders,
639 ok_b_emptybox,
640 ok_b_emptystart,
641 ok_b_flipr,
642 ok_b_forward_as_attachment,
643 ok_b_fullnames,
644 ok_b_header, /* {special=1} */
645 ok_b_hold,
646 ok_b_idna_disable,
647 ok_b_ignore,
648 ok_b_ignoreeof,
649 ok_b_imap_use_starttls,
650 ok_b_keep,
651 ok_b_keep_content_length,
652 ok_b_keepsave,
653 ok_b_line_editor_disable,
654 ok_b_markanswered,
655 ok_b_message_id_disable,
656 ok_b_metoo,
657 ok_b_mime_allow_text_controls,
658 ok_b_mime_counter_evidence,
659 ok_b_outfolder,
660 ok_b_page,
661 ok_b_piperaw,
662 ok_b_pop3_bulk_load,
663 ok_b_pop3_no_apop,
664 ok_b_pop3_use_starttls,
665 ok_b_print_all_chars,
666 ok_b_print_alternatives,
667 ok_b_quiet,
668 ok_b_quote_as_attachment,
669 ok_b_recipients_in_cc,
670 ok_b_record_resent,
671 ok_b_reply_in_same_charset,
672 ok_b_Replyall,
673 ok_b_rfc822_body_from_, /* {name=rfc822-body-from_} */
674 ok_b_save,
675 ok_b_searchheaders,
676 ok_b_sendcharsets_else_ttycharset,
677 ok_b_sendwait,
678 ok_b_showlast,
679 ok_b_showname,
680 ok_b_showto,
681 ok_b_skipemptybody, /* {special=1} */
682 ok_b_smime_force_encryption,
683 ok_b_smime_no_default_ca,
684 ok_b_smime_sign,
685 ok_b_smtp_use_starttls,
686 ok_b_ssl_no_default_ca,
687 ok_b_ssl_v2_allow,
688 ok_b_writebackedited,
689 ok_b_verbose, /* {special=1} */
691 /* Option keys for values options */
692 ok_v_attrlist,
693 ok_v_autobcc,
694 ok_v_autocc,
695 /* XXX autoinc is the same as *newmail*, unite!! */
696 ok_v_autoinc,
697 ok_v_autosort,
698 ok_v_charset_7bit,
699 ok_v_charset_8bit,
700 ok_v_cmd,
701 ok_v_colour_pagers,
702 ok_v_colour_from_, /* {name=colour-from_} */
703 ok_v_colour_header,
704 ok_v_colour_msginfo,
705 ok_v_colour_partinfo,
706 ok_v_colour_terms,
707 ok_v_colour_uheader,
708 ok_v_colour_user_headers,
709 ok_v_crt,
710 ok_v_datefield,
711 ok_v_datefield_markout_older,
712 ok_v_DEAD,
713 ok_v_EDITOR,
714 ok_v_encoding,
715 ok_v_escape,
716 ok_v_folder, /* {special=1} */
717 ok_v_folder_hook,
718 ok_v_from,
719 ok_v_fwdheading,
720 ok_v_headline,
721 ok_v_hostname,
722 ok_v_imap_auth,
723 ok_v_imap_cache,
724 ok_v_imap_keepalive,
725 ok_v_imap_list_depth,
726 ok_v_indentprefix,
727 ok_v_line_editor_cursor_right, /* {special=1} */
728 ok_v_LISTER,
729 ok_v_MAIL,
730 ok_v_MBOX,
731 ok_v_mimetypes_load_control,
732 ok_v_NAIL_EXTRA_RC, /* {name=NAIL_EXTRA_RC} */
733 ok_v_NAIL_HEAD, /* {name=NAIL_HEAD} */
734 ok_v_NAIL_HISTFILE, /* {name=NAIL_HISTFILE} */
735 ok_v_NAIL_HISTSIZE, /* {name=NAIL_HISTSIZE} */
736 ok_v_NAIL_TAIL, /* {name=NAIL_TAIL} */
737 ok_v_newfolders,
738 ok_v_newmail,
739 ok_v_ORGANIZATION,
740 ok_v_PAGER,
741 ok_v_pop3_keepalive,
742 ok_v_prompt,
743 ok_v_quote,
744 ok_v_quote_fold,
745 ok_v_record,
746 ok_v_replyto,
747 ok_v_screen,
748 ok_v_sendcharsets,
749 ok_v_sender,
750 ok_v_sendmail,
751 ok_v_sendmail_progname,
752 ok_v_SHELL,
753 ok_v_Sign,
754 ok_v_sign,
755 ok_v_signature,
756 ok_v_smime_ca_dir,
757 ok_v_smime_ca_file,
758 ok_v_smime_crl_dir,
759 ok_v_smime_crl_file,
760 ok_v_smime_sign_cert,
761 ok_v_smime_sign_include_certs,
762 ok_v_smtp,
763 ok_v_smtp_auth,
764 ok_v_smtp_auth_password,
765 ok_v_smtp_auth_user,
766 ok_v_spam_command,
767 ok_v_spam_host,
768 ok_v_spam_maxsize,
769 ok_v_spam_port,
770 ok_v_spam_socket,
771 ok_v_spam_user,
772 ok_v_ssl_ca_dir,
773 ok_v_ssl_ca_file,
774 ok_v_ssl_cert,
775 ok_v_ssl_cipher_list,
776 ok_v_ssl_crl_dir,
777 ok_v_ssl_crl_file,
778 ok_v_ssl_key,
779 ok_v_ssl_method,
780 ok_v_ssl_rand_egd,
781 ok_v_ssl_rand_file,
782 ok_v_ssl_verify,
783 ok_v_stealthmua,
784 ok_v_toplines,
785 ok_v_ttycharset,
786 ok_v_VISUAL
789 struct str {
790 char *s; /* the string's content */
791 size_t l; /* the stings's length */
794 struct colour_table {
795 /* Plus a copy of *colour-user-headers* */
796 struct str ct_csinfo[COLOURSPEC_RESET+1 + 1];
799 struct time_current {
800 time_t tc_time;
801 struct tm tc_gm;
802 struct tm tc_local;
803 char tc_ctime[32];
806 struct quoteflt {
807 FILE *qf_os; /* Output stream */
808 char const *qf_pfix;
809 ui_it qf_pfix_len; /* Length of prefix: 0: bypass */
810 ui_it qf_qfold_min; /* Simple way: wrote prefix? */
811 #ifdef HAVE_QUOTE_FOLD
812 ui_it qf_qfold_max; /* Otherwise: line lengths */
813 uc_it qf_state; /* *quote-fold* state machine */
814 bool_t qf_brk_isws; /* Breakpoint is at WS */
815 uc_it __dummy[2];
816 ui_it qf_wscnt; /* Whitespace count */
817 ui_it qf_brkl; /* Breakpoint */
818 ui_it qf_brkw; /* Visual width, breakpoint */
819 ui_it qf_datw; /* Current visual output line width */
820 struct str qf_dat; /* Current visual output line */
821 struct str qf_currq; /* Current quote, compressed */
822 mbstate_t qf_mbps[2];
823 #endif
826 struct eval_ctx {
827 struct str ev_line;
828 bool_t ev_is_recursive; /* Evaluation in evaluation? (collect ~:) */
829 ui8_t __dummy[6];
830 bool_t ev_add_history; /* Enter (final) command in history? */
831 char const *ev_new_content; /* History: reenter line, start with this */
834 struct termios_state {
835 struct termios ts_tios;
836 char *ts_linebuf;
837 size_t ts_linesize;
838 bool_t ts_needs_reset;
841 #define termios_state_reset() \
842 do {\
843 if (termios_state.ts_needs_reset) {\
844 tcsetattr(0, TCSADRAIN, &termios_state.ts_tios);\
845 termios_state.ts_needs_reset = FAL0;\
847 } while (0)
849 struct sock { /* data associated with a socket */
850 int s_fd; /* file descriptor */
851 #ifdef HAVE_SSL
852 int s_use_ssl; /* SSL is used */
853 # ifdef HAVE_OPENSSL
854 void *s_ssl; /* SSL object */
855 void *s_ctx; /* SSL context object */
856 # endif
857 #endif
858 char *s_wbuf; /* for buffered writes */
859 int s_wbufsize; /* allocated size of s_buf */
860 int s_wbufpos; /* position of first empty data byte */
861 char *s_rbufptr; /* read pointer to s_rbuf */
862 int s_rsz; /* size of last read in s_rbuf */
863 char const *s_desc; /* description of error messages */
864 void (*s_onclose)(void); /* execute on close */
865 char s_rbuf[LINESIZE + 1]; /* for buffered reads */
868 struct mailbox {
869 enum {
870 MB_NONE = 000, /* no reply expected */
871 MB_COMD = 001, /* command reply expected */
872 MB_MULT = 002, /* multiline reply expected */
873 MB_PREAUTH = 004, /* not in authenticated state */
874 MB_BYE = 010 /* may accept a BYE state */
875 } mb_active;
876 FILE *mb_itf; /* temp file with messages, read open */
877 FILE *mb_otf; /* same, write open */
878 char *mb_sorted; /* sort method */
879 enum {
880 MB_VOID, /* no type (e. g. connection failed) */
881 MB_FILE, /* local file */
882 MB_POP3, /* POP3 mailbox */
883 MB_IMAP, /* IMAP mailbox */
884 MB_MAILDIR, /* maildir folder */
885 MB_CACHE /* cached mailbox */
886 } mb_type; /* type of mailbox */
887 enum {
888 MB_DELE = 01, /* may delete messages in mailbox */
889 MB_EDIT = 02 /* may edit messages in mailbox */
890 } mb_perm;
891 int mb_compressed; /* is a compressed mbox file */
892 int mb_threaded; /* mailbox has been threaded */
893 #ifdef HAVE_IMAP
894 enum mbflags {
895 MB_NOFLAGS = 000,
896 MB_UIDPLUS = 001 /* supports IMAP UIDPLUS */
897 } mb_flags;
898 unsigned long mb_uidvalidity; /* IMAP unique identifier validity */
899 char *mb_imap_account; /* name of current IMAP account */
900 char *mb_imap_mailbox; /* name of current IMAP mailbox */
901 char *mb_cache_directory; /* name of cache directory */
902 #endif
903 struct sock mb_sock; /* socket structure */
906 enum needspec {
907 NEED_UNSPEC, /* unspecified need, don't fetch */
908 NEED_HEADER, /* need the header of a message */
909 NEED_BODY /* need header and body of a message */
912 enum havespec {
913 HAVE_NOTHING, /* nothing downloaded yet */
914 HAVE_HEADER = 01, /* header is downloaded */
915 HAVE_BODY = 02 /* entire message is downloaded */
918 /* flag bits. Attention: Flags that are used in cache.c may not change */
919 enum mflag {
920 MUSED = (1<< 0), /* entry is used, but this bit isn't */
921 MDELETED = (1<< 1), /* entry has been deleted */
922 MSAVED = (1<< 2), /* entry has been saved */
923 MTOUCH = (1<< 3), /* entry has been noticed */
924 MPRESERVE = (1<< 4), /* keep entry in sys mailbox */
925 MMARK = (1<< 5), /* message is marked! */
926 MODIFY = (1<< 6), /* message has been modified */
927 MNEW = (1<< 7), /* message has never been seen */
928 MREAD = (1<< 8), /* message has been read sometime. */
929 MSTATUS = (1<< 9), /* message status has changed */
930 MBOX = (1<<10), /* Send this to mbox, regardless */
931 MNOFROM = (1<<11), /* no From line */
932 MHIDDEN = (1<<12), /* message is hidden to user */
933 MFULLYCACHED = (1<<13), /* message is completely cached */
934 MBOXED = (1<<14), /* message has been sent to mbox */
935 MUNLINKED = (1<<15), /* message was unlinked from cache */
936 MNEWEST = (1<<16), /* message is very new (newmail) */
937 MFLAG = (1<<17), /* message has been flagged recently */
938 MUNFLAG = (1<<18), /* message has been unflagged */
939 MFLAGGED = (1<<19), /* message is `flagged' */
940 MANSWER = (1<<20), /* message has been answered recently */
941 MUNANSWER = (1<<21), /* message has been unanswered */
942 MANSWERED = (1<<22), /* message is `answered' */
943 MDRAFT = (1<<23), /* message has been drafted recently */
944 MUNDRAFT = (1<<24), /* message has been undrafted */
945 MDRAFTED = (1<<25), /* message is marked as `draft' */
946 MOLDMARK = (1<<26), /* messages was marked previously */
947 MSPAM = (1<<27) /* message is classified as spam */
949 #define MMNORM (MDELETED | MSAVED | MHIDDEN)
950 #define MMNDEL (MDELETED | MHIDDEN)
952 #define visible(mp) (((mp)->m_flag & MMNDEL) == 0)
954 struct mimepart {
955 enum mflag m_flag; /* flags */
956 enum havespec m_have; /* downloaded parts of the part */
957 #ifdef HAVE_SPAM
958 ui_it m_spamscore; /* Spam score as int, 24:8 bits */
959 #endif
960 int m_block; /* block number of this part */
961 size_t m_offset; /* offset in block of part */
962 size_t m_size; /* Bytes in the part */
963 size_t m_xsize; /* Bytes in the full part */
964 long m_lines; /* Lines in the message */
965 long m_xlines; /* Lines in the full message */
966 time_t m_time; /* time the message was sent */
967 char const *m_from; /* message sender */
968 struct mimepart *m_nextpart; /* next part at same level */
969 struct mimepart *m_multipart; /* parts of multipart */
970 struct mimepart *m_parent; /* enclosing multipart part */
971 char *m_ct_type; /* content-type */
972 char *m_ct_type_plain; /* content-type without specs */
973 enum mimecontent m_mimecontent; /* same in enum */
974 char const *m_charset; /* charset */
975 char *m_ct_transfer_enc; /* content-transfer-encoding */
976 enum mimeenc m_mimeenc; /* same in enum */
977 char *m_partstring; /* part level string */
978 char *m_filename; /* attachment filename */
981 struct message {
982 enum mflag m_flag; /* flags */
983 enum havespec m_have; /* downloaded parts of the message */
984 #ifdef HAVE_SPAM
985 ui_it m_spamscore; /* Spam score as int, 24:8 bits */
986 #endif
987 int m_block; /* block number of this message */
988 size_t m_offset; /* offset in block of message */
989 size_t m_size; /* Bytes in the message */
990 size_t m_xsize; /* Bytes in the full message */
991 long m_lines; /* Lines in the message */
992 long m_xlines; /* Lines in the full message */
993 time_t m_time; /* time the message was sent */
994 time_t m_date; /* time in the 'Date' field */
995 unsigned m_idhash; /* hash on Message-ID for threads */
996 struct message *m_child; /* first child of this message */
997 struct message *m_younger; /* younger brother of this message */
998 struct message *m_elder; /* elder brother of this message */
999 struct message *m_parent; /* parent of this message */
1000 unsigned m_level; /* thread level of message */
1001 long m_threadpos; /* position in threaded display */
1002 #ifdef HAVE_IMAP
1003 unsigned long m_uid; /* IMAP unique identifier */
1004 #endif
1005 char *m_maildir_file; /* original maildir file of msg */
1006 unsigned m_maildir_hash; /* hash of file name in maildir sub */
1007 int m_collapsed; /* collapsed thread information */
1010 /* Given a file address, determine the block number it represents */
1011 #define mailx_blockof(off) ((int) ((off) / 4096))
1012 #define mailx_offsetof(off) ((int) ((off) % 4096))
1013 #define mailx_positionof(block, offset) ((off_t)(block) * 4096 + (offset))
1015 /* Argument types */
1016 enum argtype {
1017 ARG_MSGLIST = 0, /* Message list type */
1018 ARG_STRLIST = 1, /* A pure string */
1019 ARG_RAWLIST = 2, /* Shell string list */
1020 ARG_NOLIST = 3, /* Just plain 0 */
1021 ARG_NDMLIST = 4, /* Message list, no defaults */
1022 ARG_ECHOLIST = 5, /* Like raw list, but keep quote chars */
1023 ARG_ARGMASK = 7, /* Mask of the above */
1025 ARG_A = 1u<< 4, /* Needs an active mailbox */
1026 ARG_F = 1u<< 5, /* Is a conditional command */
1027 ARG_H = 1u<< 6, /* Never place in history */
1028 ARG_I = 1u<< 7, /* Interactive command bit */
1029 ARG_M = 1u<< 8, /* Legal from send mode bit */
1030 ARG_P = 1u<< 9, /* Autoprint dot after command */
1031 ARG_R = 1u<<10, /* Cannot be called from collect / recursion */
1032 ARG_T = 1u<<11, /* Is a transparent command */
1033 ARG_V = 1u<<12, /* Places data in temporary_arg_v_store */
1034 ARG_W = 1u<<13 /* Illegal when read only bit */
1037 enum gfield {
1038 GTO = 1, /* Grab To: line */
1039 GSUBJECT = 2, /* Likewise, Subject: line */
1040 GCC = 4, /* And the Cc: line */
1041 GBCC = 8, /* And also the Bcc: line */
1043 GNL = 16, /* Print blank line after */
1044 GDEL = 32, /* Entity removed from list */
1045 GCOMMA = 64, /* detract puts in commas */
1046 GUA = 128, /* User-Agent field */
1047 GMIME = 256, /* MIME 1.0 fields */
1048 GMSGID = 512, /* a Message-ID */
1049 /* 1024 */
1050 GIDENT = 2048, /* From:, Reply-To: and Organization: field */
1051 GREF = 4096, /* References: field */
1052 GDATE = 8192, /* Date: field */
1053 GFULL = 16384, /* include full names */
1054 GSKIN = 32768, /* skin names */
1055 GEXTRA = 65536, /* extra fields */
1056 GFILES = 131072 /* include filename addresses */
1058 #define GMASK (GTO | GSUBJECT | GCC | GBCC)
1060 /* Structure used to pass about the current state of a message (header) */
1061 struct header {
1062 struct name *h_to; /* Dynamic "To:" string */
1063 char *h_subject; /* Subject string */
1064 struct name *h_cc; /* Carbon copies string */
1065 struct name *h_bcc; /* Blind carbon copies */
1066 struct name *h_ref; /* References */
1067 struct attachment *h_attach; /* MIME attachments */
1068 char *h_charset; /* preferred charset */
1069 struct name *h_from; /* overridden "From:" field */
1070 struct name *h_replyto; /* overridden "Reply-To:" field */
1071 struct name *h_sender; /* overridden "Sender:" field */
1072 char *h_organization; /* overridden "Organization:" field */
1075 /* Handling of namelist nodes used in processing the recipients of mail and
1076 * aliases, inspection of mail-addresses and all that kind of stuff */
1077 enum nameflags {
1078 NAME_NAME_SALLOC = 1<< 0, /* .n_name is doped */
1079 NAME_FULLNAME_SALLOC = 1<< 1, /* .n_fullname is doped */
1080 NAME_SKINNED = 1<< 2, /* Is actually skin()ned */
1081 NAME_IDNA = 1<< 3, /* IDNA was applied */
1082 NAME_ADDRSPEC_CHECKED = 1<< 4, /* Address has been .. and */
1083 NAME_ADDRSPEC_ISFILE = 1<< 5, /* ..is a file path */
1084 NAME_ADDRSPEC_ISPIPE = 1<< 6, /* ..is a command for piping */
1085 NAME_ADDRSPEC_ISFILEORPIPE = NAME_ADDRSPEC_ISFILE | NAME_ADDRSPEC_ISPIPE,
1086 NAME_ADDRSPEC_ERR_EMPTY = 1<< 7, /* An empty string (or NULL) */
1087 NAME_ADDRSPEC_ERR_ATSEQ = 1<< 8, /* Weird @ sequence */
1088 NAME_ADDRSPEC_ERR_CHAR = 1<< 9, /* Invalid character */
1089 NAME_ADDRSPEC_ERR_IDNA = 1<<10, /* IDNA convertion failed */
1090 NAME_ADDRSPEC_INVALID = NAME_ADDRSPEC_ERR_EMPTY |
1091 NAME_ADDRSPEC_ERR_ATSEQ | NAME_ADDRSPEC_ERR_CHAR |
1092 NAME_ADDRSPEC_ERR_IDNA,
1094 _NAME_SHIFTWC = 11,
1095 _NAME_MAXWC = 0xFFFFF,
1096 _NAME_MASKWC = _NAME_MAXWC << _NAME_SHIFTWC
1099 /* In the !_ERR_EMPTY case, the failing character can be queried */
1100 #define NAME_ADDRSPEC_ERR_GETWC(F) \
1101 ((((unsigned int)(F) & _NAME_MASKWC) >> _NAME_SHIFTWC) & _NAME_MAXWC)
1102 #define NAME_ADDRSPEC_ERR_SET(F, E, WC) \
1103 do {\
1104 (F) = ((F) & ~(NAME_ADDRSPEC_INVALID | _NAME_MASKWC)) |\
1105 (E) | (((unsigned int)(WC) & _NAME_MAXWC) << _NAME_SHIFTWC);\
1106 } while (0)
1108 struct name {
1109 struct name *n_flink; /* Forward link in list. */
1110 struct name *n_blink; /* Backward list link */
1111 enum gfield n_type; /* From which list it came */
1112 enum nameflags n_flags; /* enum nameflags */
1113 char *n_name; /* This fella's name */
1114 char *n_fullname; /* Sometimes, name including comment */
1117 struct addrguts {
1118 char const *ag_input; /* Input string as given */
1119 size_t ag_ilen; /* strlen() of input */
1120 size_t ag_iaddr_start; /* Start of *addr-spec* in .ag_input */
1121 size_t ag_iaddr_aend; /* ..and one past its end */
1122 char *ag_skinned; /* Output (alloced if !=.ag_input) */
1123 size_t ag_slen; /* strlen() of .ag_skinned */
1124 size_t ag_sdom_start; /* Start of domain in .ag_skinned, */
1125 enum nameflags ag_n_flags; /* enum nameflags of .ag_skinned */
1128 /* MIME attachments */
1129 enum attach_conv {
1130 AC_DEFAULT, /* _get_lc() -> _iter_*() */
1131 AC_FIX_OUTCS, /* _get_lc() -> "charset=" .a_charset */
1132 AC_FIX_INCS, /* "charset=".a_input_charset (nocnv) */
1133 AC_TMPFILE /* attachment.a_tmpf is converted */
1136 struct attachment {
1137 struct attachment *a_flink; /* Forward link in list. */
1138 struct attachment *a_blink; /* Backward list link */
1139 char const *a_name; /* file name */
1140 char const *a_content_type; /* content type */
1141 char const *a_content_disposition; /* content disposition */
1142 char const *a_content_id; /* content id */
1143 char const *a_content_description; /* content description */
1144 char const *a_input_charset; /* Interpretation depends on .a_conv */
1145 char const *a_charset; /* ... */
1146 FILE *a_tmpf; /* If AC_TMPFILE */
1147 enum attach_conv a_conv; /* User chosen conversion */
1148 int a_msgno; /* message number */
1151 struct group {
1152 struct group *ge_link; /* Next person in this group */
1153 char *ge_name; /* This person's user name */
1156 struct grouphead {
1157 struct grouphead *g_link; /* Next grouphead in list */
1158 char *g_name; /* Name of this group */
1159 struct group *g_list; /* Users in group. */
1162 /* Structure of the hash table of ignored header fields */
1163 struct ignoretab {
1164 int i_count; /* Number of entries */
1165 struct ignore {
1166 struct ignore *i_link; /* Next ignored field in bucket */
1167 char *i_field; /* This ignored field */
1168 } *i_head[HSHSIZE];
1171 /* Token values returned by the scanner used for argument lists.
1172 * Also, sizes of scanner-related things */
1173 enum ltoken {
1174 TEOL = 0, /* End of the command line */
1175 TNUMBER = 1, /* A message number */
1176 TDASH = 2, /* A simple dash */
1177 TSTRING = 3, /* A string (possibly containing -) */
1178 TDOT = 4, /* A "." */
1179 TUP = 5, /* An "^" */
1180 TDOLLAR = 6, /* A "$" */
1181 TSTAR = 7, /* A "*" */
1182 TOPEN = 8, /* An '(' */
1183 TCLOSE = 9, /* A ')' */
1184 TPLUS = 10, /* A '+' */
1185 TERROR = 11, /* A lexical error */
1186 TCOMMA = 12, /* A ',' */
1187 TSEMI = 13, /* A ';' */
1188 TBACK = 14 /* A '`' */
1191 #define REGDEP 2 /* Maximum regret depth. */
1193 /* Constants for conditional commands. These describe whether we should be
1194 * executing stuff or not */
1195 enum condition {
1196 COND_ANY = 0, /* Execute in send or receive mode */
1197 COND_RCV = 1, /* Execute in receive mode only */
1198 COND_SEND = 2, /* Execute in send mode only */
1199 COND_TERM = 3, /* Execute only if stdin is a tty */
1200 COND_NOTERM = 4, /* Execute only if stdin not tty */
1201 COND_EXEC = 5, /* Do execute this block */
1202 COND_NOEXEC = 6 /* Don't execute this block */
1205 /* For the 'shortcut' and 'unshortcut' functionality */
1206 struct shortcut {
1207 struct shortcut *sh_next; /* next shortcut in list */
1208 char *sh_short; /* shortcut string */
1209 char *sh_long; /* expanded form */
1212 /* Kludges to handle the change from setexit / reset to setjmp / longjmp */
1213 #define setexit() (void)sigsetjmp(srbuf, 1)
1214 #define reset(x) siglongjmp(srbuf, x)
1216 /* Content-Transfer-Encodings as defined in RFC 2045:
1217 * - Quoted-Printable, section 6.7
1218 * - Base64, section 6.8 */
1220 #define QP_LINESIZE (4 * 19) /* Max. compliant QP linesize */
1222 #define B64_LINESIZE (4 * 19) /* Max. compliant Base64 linesize */
1223 #define B64_ENCODE_INPUT_PER_LINE 57 /* Max. input for Base64 encode/line */
1225 /* xxx QP came later, maybe rewrite all to use mimecte_flags directly? */
1226 enum __mimecte_flags {
1227 MIMECTE_NONE,
1228 MIMECTE_SALLOC = 1<<0, /* Use salloc(), not srealloc().. */
1229 /* ..result .s,.l point to user buffer of *_LINESIZE+[+[+]] bytes instead */
1230 MIMECTE_BUF = 1<<1,
1231 MIMECTE_CRLF = 1<<2, /* (encode) Append "\r\n" to lines */
1232 MIMECTE_LF = 1<<3, /* (encode) Append "\n" to lines */
1233 /* (encode) If one of _CRLF/_LF is set, honour *_LINESIZE+[+[+]] and
1234 * inject the desired line-ending whenever a linewrap is desired */
1235 MIMECTE_MULTILINE = 1<<4,
1236 /* (encode) Quote with header rules, do not generate soft NL breaks? */
1237 MIMECTE_ISHEAD = 1<<5
1240 enum qpflags {
1241 QP_NONE = MIMECTE_NONE,
1242 QP_SALLOC = MIMECTE_SALLOC,
1243 QP_BUF = MIMECTE_BUF,
1244 QP_ISHEAD = MIMECTE_ISHEAD
1247 enum b64flags {
1248 B64_NONE = MIMECTE_NONE,
1249 B64_SALLOC = MIMECTE_SALLOC,
1250 B64_BUF = MIMECTE_BUF,
1251 B64_CRLF = MIMECTE_CRLF,
1252 B64_LF = MIMECTE_LF,
1253 B64_MULTILINE = MIMECTE_MULTILINE
1256 /* Locale-independent character classes */
1257 enum {
1258 C_CNTRL = 0000,
1259 C_BLANK = 0001,
1260 C_WHITE = 0002,
1261 C_SPACE = 0004,
1262 C_PUNCT = 0010,
1263 C_OCTAL = 0020,
1264 C_DIGIT = 0040,
1265 C_UPPER = 0100,
1266 C_LOWER = 0200
1269 #define __ischarof(C, FLAGS) \
1270 (asciichar(C) && (class_char[(uc_it)(C)] & (FLAGS)) != 0)
1272 #define asciichar(c) ((uc_it)(c) <= 0177)
1273 #define alnumchar(c) __ischarof(c, C_DIGIT | C_OCTAL | C_UPPER | C_LOWER)
1274 #define alphachar(c) __ischarof(c, C_UPPER | C_LOWER)
1275 #define blankchar(c) __ischarof(c, C_BLANK)
1276 #define blankspacechar(c) __ischarof(c, C_BLANK | C_SPACE)
1277 #define cntrlchar(c) __ischarof(c, C_CNTRL)
1278 #define digitchar(c) __ischarof(c, C_DIGIT | C_OCTAL)
1279 #define lowerchar(c) __ischarof(c, C_LOWER)
1280 #define punctchar(c) __ischarof(c, C_PUNCT)
1281 #define spacechar(c) __ischarof(c, C_BLANK | C_SPACE | C_WHITE)
1282 #define upperchar(c) __ischarof(c, C_UPPER)
1283 #define whitechar(c) __ischarof(c, C_BLANK | C_WHITE)
1284 #define octalchar(c) __ischarof(c, C_OCTAL)
1286 #define upperconv(c) (lowerchar(c) ? (char)((uc_it)(c) - 'a' + 'A') : (c))
1287 #define lowerconv(c) (upperchar(c) ? (char)((uc_it)(c) - 'A' + 'a') : (c))
1288 /* RFC 822, 3.2. */
1289 #define fieldnamechar(c) \
1290 (asciichar(c) && (c) > 040 && (c) != 0177 && (c) != ':')
1292 /* Try to use alloca() for some function-local buffers and data, fall back to
1293 * smalloc()/free() if not available */
1294 #ifdef HAVE_ALLOCA
1295 # define ac_alloc(n) HAVE_ALLOCA(n)
1296 # define ac_free(n) do {UNUSED(n);} while (0)
1297 #else
1298 # define ac_alloc(n) smalloc(n)
1299 # define ac_free(n) free(n)
1300 #endif
1302 /* Single-threaded, use unlocked I/O */
1303 #ifdef HAVE_PUTC_UNLOCKED
1304 # undef getc
1305 # define getc(c) getc_unlocked(c)
1306 # undef putc
1307 # define putc(c, f) putc_unlocked(c, f)
1308 # undef putchar
1309 # define putchar(c) putc_unlocked((c), stdout)
1310 #endif
1312 /* Truncate a file to the last character written. This is useful just before
1313 * closing an old file that was opened for read/write */
1314 #define ftrunc(stream) \
1315 do {\
1316 off_t off;\
1317 fflush(stream);\
1318 off = ftell(stream);\
1319 if (off >= 0)\
1320 ftruncate(fileno(stream), off);\
1321 } while (0)
1323 /* fflush() and rewind() */
1324 #define fflush_rewind(stream) \
1325 do {\
1326 fflush(stream);\
1327 rewind(stream);\
1328 } while (0)
1330 /* For saving the current directory and later returning */
1331 struct cw {
1332 #ifdef HAVE_FCHDIR
1333 int cw_fd;
1334 #else
1335 char cw_wd[MAXPATHLEN];
1336 #endif
1340 * Global variable declarations
1342 * These become instantiated in main.c.
1345 #undef VL
1346 #ifdef _MAIN_SOURCE
1347 # ifndef HAVE_AMALGAMATION
1348 # define VL
1349 # else
1350 # define VL static
1351 # endif
1352 #else
1353 # define VL extern
1354 #endif
1356 VL gid_t effectivegid; /* Saved from when we started up */
1357 VL gid_t realgid; /* Saved from when we started up */
1359 VL int mb_cur_max; /* Value of MB_CUR_MAX */
1360 VL int realscreenheight; /* The real screen height */
1361 VL int scrnwidth; /* Screen width, or best guess */
1362 VL int scrnheight; /* Screen height/guess (4 header) */
1363 VL int utf8; /* Locale uses UTF-8 encoding */
1364 VL int enc_has_state; /* Encoding has shift states */
1366 VL char **altnames; /* List of alternate names of user */
1367 VL char const *homedir; /* Path name of home directory */
1368 VL char const *myname; /* My login name */
1369 VL char const *progname; /* Our name */
1370 VL char const *tempdir; /* The temporary directory */
1372 VL int exit_status; /* Exit status */
1373 VL int options; /* Bits of enum user_options */
1374 VL char *option_r_arg; /* Argument to -r option */
1375 VL char const **smopts; /* sendmail(1) opts from commline */
1376 VL size_t smopts_count; /* Entries in smopts */
1378 /* TODO Join as many of these state machine bits into a single carrier! */
1379 VL int inhook; /* Currently executing a hook */
1380 VL bool_t exec_last_comm_error; /* Last execute() command failed */
1381 VL bool_t edit; /* Indicates editing a file */
1382 VL bool_t did_print_dot; /* Current message has been printed */
1383 VL bool_t list_saw_numbers; /* Last *LIST saw numerics */
1384 VL bool_t msglist_is_single; /* Last NDMLIST/MSGLIST chose 1 msg */
1385 VL bool_t loading; /* Loading user definitions */
1386 VL bool_t sourcing; /* Currently reading variant file */
1387 VL bool_t sawcom; /* Set after first command */
1388 VL bool_t starting; /* Still in startup code */
1389 VL bool_t var_clear_allow_undefined; /* v?ok_[bv]clear(): no complain */
1390 VL int noreset; /* String resets suspended */
1392 /* XXX stylish sorting */
1393 VL int msgCount; /* Count of messages read in */
1394 VL enum condition cond_state; /* State of conditional exc. */
1395 VL struct mailbox mb; /* Current mailbox */
1396 VL int image; /* File descriptor for msg image */
1397 VL char mailname[MAXPATHLEN]; /* Name of current file */
1398 VL char displayname[80 - 40]; /* Prettyfied for display */
1399 VL char prevfile[MAXPATHLEN]; /* Name of previous file */
1400 VL char const *account_name; /* Current account name or NULL */
1401 VL off_t mailsize; /* Size of system mailbox */
1402 VL struct message *dot; /* Pointer to current message */
1403 VL struct message *prevdot; /* Previous current message */
1404 VL struct message *message; /* The actual message structure */
1405 VL struct message *threadroot; /* first threaded message */
1406 VL int imap_created_mailbox; /* hack to get feedback from imap */
1407 VL int msgspace; /* Number of allocated struct m */
1409 VL struct grouphead *groups[HSHSIZE]; /* Pointer to active groups */
1410 VL struct ignoretab ignore[2]; /* ignored and retained fields
1411 * 0 is ignore, 1 is retain */
1412 VL struct ignoretab saveignore[2]; /* ignored and retained fields
1413 * on save to folder */
1414 VL struct ignoretab allignore[2]; /* special, ignore all headers */
1415 VL struct ignoretab fwdignore[2]; /* fields to ignore for forwarding */
1416 VL struct shortcut *shortcuts; /* list of shortcuts */
1418 VL struct time_current time_current; /* time(3); send: mail1() XXXcarrier */
1419 VL struct termios_state termios_state; /* getpassword(); see commands().. */
1421 #ifdef HAVE_COLOUR
1422 VL struct colour_table *colour_table;
1423 #endif
1425 #ifdef HAVE_SSL
1426 VL enum ssl_vrfy_level ssl_vrfy_level; /* SSL verification level */
1427 #endif
1429 #ifdef HAVE_ICONV
1430 VL iconv_t iconvd;
1431 #endif
1433 #ifdef HAVE_CATGETS
1434 VL nl_catd catd;
1435 #endif
1437 VL sigjmp_buf srbuf;
1438 VL int interrupts;
1439 VL sighandler_type dflpipe;
1440 VL sighandler_type handlerstacktop;
1441 #define handlerpush(f) (savedtop = handlerstacktop, handlerstacktop = (f))
1442 #define handlerpop() (handlerstacktop = savedtop)
1444 VL char *temporary_arg_v_store;
1446 /* The remaining variables need initialization */
1448 #ifndef HAVE_AMALGAMATION
1449 VL char const month_names[12 + 1][4];
1450 VL char const weekday_names[7 + 1][4];
1452 VL char const uagent[]; /* User agent */
1453 VL char const version[]; /* The version string */
1454 VL char const features[]; /* The "feature string" */
1456 VL uc_it const class_char[];
1457 #endif
1460 * Finally, let's include the function prototypes XXX embed
1463 #include "extern.h"
1465 /* vim:set fenc=utf-8:s-it-mode */