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