1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ Constants, types etc.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 - 2013 Steffen "Daode" Nurpmeso <sdaoden@users.sf.net>.
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
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
41 * Mail -- a mail program
43 * Author: Kurt Shoens (UCB) March 25, 1978
46 #if ! defined NI_MAXHOST || NI_MAXHOST < 1025
48 # define NI_MAXHOST 1025
51 #define APPEND /* New mail goes to end of mailbox */
55 # define MAXPATHLEN PATH_MAX
57 # define MAXPATHLEN 1024
60 #if BUFSIZ > 2560 /* TODO simply use BUFSIZ? */
61 # define LINESIZE BUFSIZ /* max readable line width */
63 # define LINESIZE 2560
67 # define STDIN_FILENO 0
70 # define STDOUT_FILENO 1
73 # define STDERR_FILENO 2
76 #define MAXARGC 1024 /* Maximum list of raw strings */
77 #define MAXEXP 25 /* Maximum expansion of aliases */
78 #define HSHSIZE 23 /* Hash size aliases, vars, macros */
80 #define FROM_DATEBUF 64 /* Size of RFC 4155 From_ line date */
81 #define DATE_DAYSYEAR 365L
82 #define DATE_SECSMIN 60L
83 #define DATE_MINSHOUR 60L
84 #define DATE_HOURSDAY 24L
85 #define DATE_SECSDAY (DATE_SECSMIN * DATE_MINSHOUR * DATE_HOURSDAY)
87 #define ESCAPE '~' /* Default escape for sending */
91 #define SHELL "/bin/sh"
96 * Funs, CC support etc.
99 /* Members in constant array */
100 #define ARRAY_COUNT(A) (sizeof(A) / sizeof(A[0]))
102 /* sizeof() for member fields */
103 #define SIZEOF_FIELD(T,F) sizeof(((T *)NULL)->F)
105 /* Casts-away (*NOT* cast-away) */
106 #define UNCONST(P) ((void*)(unsigned long)(void const*)(P))
107 #define UNVOLATILE(P) ((void*)(unsigned long)(void volatile*)(P))
109 /* __STDC_VERSION__ is ISO C99, so also use __STDC__, which should work */
110 #if defined __STDC__ || defined __STDC_VERSION__ /*|| defined __cplusplus*/
111 # define STRING(X) #X
112 # define XSTRING(X) STRING(X)
113 # define CONCAT(S1,S2) _CONCAT(S1, S2)
114 # define _CONCAT(S1,S2) S1 ## S2
116 # define STRING(X) "X"
117 # define XSTRING STRING
118 # define CONCAT(S1,S2) S1/**/S2
121 #if defined __STDC_VERSION__ && __STDC_VERSION__ + 0 >= 199901L
122 /* Variable size arrays and structure fields */
123 # define VFIELD_SIZE(X)
124 # define VFIELD_SIZEOF(T,F) (0)
125 /* Inline functions */
127 # define INLINE inline
128 # define SINLINE static inline
130 # define VFIELD_SIZE(X) (X)
131 # define VFIELD_SIZEOF(T,F) SIZEOF_FIELD(T, F)
133 # define SINLINE static
137 #define ISPOW2(X) ((((X) - 1) & (X)) == 0)
139 #define MIN(A, B) ((A) < (B) ? (A) : (B))
141 #define MAX(A, B) ((A) < (B) ? (B) : (A))
143 #define ABS(A) ((A) < 0 ? -(A) : (A))
145 #define smin(a, b) ((a) < (b) ? (a) : (b)) /* TODO OBSOLETE */
146 #define smax(a, b) ((a) < (b) ? (b) : (a)) /* TODO OBSOLETE */
148 /* Compile-Time-Assert */
149 #define CTA(TEST) _CTA_1(TEST, __LINE__)
150 #define _CTA_1(TEST,L) _CTA_2(TEST, L)
151 #define _CTA_2(TEST,L) \
152 typedef char COMPILE_TIME_ASSERT_failed_at_line_ ## L[(TEST) ? 1 : -1]
155 * Line editor (tty.c)
158 /* The default size in entries of the history list */
159 #define HIST_SIZE 242
165 /* Is *C* a quoting character (for *quote-fold* compression) */
166 #define ISQUOTE(C) ((C) == '>' || (C) == '|' || (C) == '}')
168 /* Locations of mime.types(5) */
169 #define MIME_TYPES_USR "~/.mime.types"
170 #define MIME_TYPES_SYS "/etc/mime.types"
172 /* Default *encoding* as enum conversion below */
173 #define MIME_DEFAULT_ENCODING CONV_TOQP
175 /* Maximum allowed line length in a mail before QP folding is necessary), and
176 * the real limit we go for */
177 #define MIME_LINELEN_MAX 1000
178 #define MIME_LINELEN_LIMIT (MIME_LINELEN_MAX - 50)
180 /* Fallback charsets, if *charset-7bit* and *charset-8bit* or not set, resp. */
181 #define CHARSET_7BIT "US-ASCII"
183 # define CHARSET_8BIT "UTF-8"
184 # define CHARSET_8BIT_VAR "charset-8bit"
186 # define CHARSET_8BIT "ISO-8859-1"
187 # define CHARSET_8BIT_VAR "ttycharset"
191 * Auto-reclaimed string storage (strings.c)
194 /* Dynamic buffer size, and size of the single builtin one that's used first */
195 #define SBUFFER_SIZE 0x18000u
196 #define SBUFFER_BUILTIN 0x2000u
198 /* Huge allocation if GT; those are never cached but will be auto freed */
199 #define SHUGE_CUTLIMIT LINESIZE
202 * Translation (init in main.c) TODO convert all catgets() that remain to tr()
207 # define tr(c,d) catgets(catd, CATSET, c, d)
209 # define catgets(a,b,c,d) (d)
217 typedef unsigned long ul_it
;
218 typedef unsigned int ui_it
;
219 typedef unsigned short us_it
;
220 typedef unsigned char uc_it
;
222 typedef signed long sl_it
;
223 typedef signed int si_it
;
224 typedef signed short ss_it
;
225 typedef signed char sc_it
;
227 typedef enum {FAL0
, TRU1
} bool_t
;
229 typedef void ( *sighandler_type
)(int);
233 OPT_DEBUG
= 1<< 0, /* -d / *debug* */
234 OPT_VERBOSE
= 1<< 1, /* -v / *verbose* */
235 OPT_EXISTONLY
= 1<< 2, /* -e */
236 OPT_HEADERSONLY
= 1<< 3, /* -H */
237 OPT_NOSRC
= 1<< 4, /* -n */
238 OPT_E_FLAG
= 1<< 5, /* -E / *skipemptybody* */
239 OPT_F_FLAG
= 1<< 6, /* -F */
240 OPT_N_FLAG
= 1<< 7, /* -N / *header* */
241 OPT_R_FLAG
= 1<< 8, /* -R */
242 OPT_r_FLAG
= 1<< 9, /* -r (plus option_r_arg) */
243 OPT_t_FLAG
= 1<<10, /* -t */
244 OPT_TILDE_FLAG
= 1<<11, /* -~ */
245 OPT_BATCH_FLAG
= 1<<12, /* -# */
247 OPT_SENDMODE
= 1<<13, /* Usage case forces send mode */
248 OPT_INTERACTIVE
= 1<<14, /* isatty(0) */
249 OPT_TTYIN
= OPT_INTERACTIVE
,
252 #define IS_TTY_SESSION() \
253 ((options & (OPT_TTYIN | OPT_TTYOUT)) == (OPT_TTYIN | OPT_TTYOUT))
256 EXIT_OK
= EXIT_SUCCESS
,
257 EXIT_ERR
= EXIT_FAILURE
,
258 EXIT_COLL_ABORT
= 1<<1, /* Message collection was aborted */
259 EXIT_SEND_ERROR
= 1<<2 /* Unspecified send error occurred */
263 FEXP_FULL
, /* Full expansion */
264 FEXP_LOCAL
= 1<<0, /* Result must be local file/maildir */
265 FEXP_SHELL
= 1<<1, /* No folder %,#,&,+ stuff, yet sh(1) */
266 FEXP_NSHORTCUT
= 1<<2, /* Don't expand shortcuts */
267 FEXP_SILENT
= 1<<3, /* Don't print but only return errors */
268 FEXP_MULTIOK
= 1<<4 /* Expansion to many entries is ok */
273 LNED_LF_ESC
= 1<<0, /* LF can be backslash escaped */
274 LNED_HIST_ADD
= 1<<1 /* Add completed line to history */
283 MIME_NONE
, /* message is not in MIME format */
284 MIME_BIN
, /* message is in binary encoding */
285 MIME_8B
, /* message is in 8bit encoding */
286 MIME_7B
, /* message is in 7bit encoding */
287 MIME_QP
, /* message is quoted-printable */
288 MIME_B64
/* message is in base64 encoding */
292 CONV_NONE
, /* no conversion */
293 CONV_7BIT
, /* no conversion, is 7bit */
294 CONV_FROMQP
, /* convert from quoted-printable */
295 CONV_TOQP
, /* convert to quoted-printable */
296 CONV_8BIT
, /* convert to 8bit (iconv) */
297 CONV_FROMB64
, /* convert from base64 */
298 CONV_FROMB64_T
, /* convert from base64/text */
299 CONV_TOB64
, /* convert to base64 */
300 CONV_FROMHDR
, /* convert from RFC1522 format */
301 CONV_TOHDR
, /* convert to RFC1522 format */
302 CONV_TOHDR_A
/* convert addresses for header */
306 SEND_MBOX
, /* no conversion to perform */
307 SEND_RFC822
, /* no conversion, no From_ line */
308 SEND_TODISP
, /* convert to displayable form */
309 SEND_TODISP_ALL
, /* same, include all MIME parts */
310 SEND_SHOW
, /* convert to 'show' command form */
311 SEND_TOSRCH
, /* convert for IMAP SEARCH */
312 SEND_TOFLTR
, /* convert for junk mail filtering */
313 SEND_TOFILE
, /* convert for saving body to a file */
314 SEND_TOPIPE
, /* convert for pipe-content/subc. */
315 SEND_QUOTE
, /* convert for quoting */
316 SEND_QUOTE_ALL
, /* same, include all MIME parts */
317 SEND_DECRYPT
/* decrypt */
321 MIME_UNKNOWN
, /* unknown content */
322 MIME_SUBHDR
, /* inside a multipart subheader */
323 MIME_822
, /* message/rfc822 content */
324 MIME_MESSAGE
, /* other message/ content */
325 MIME_TEXT_PLAIN
, /* text/plain content */
326 MIME_TEXT_HTML
, /* text/html content */
327 MIME_TEXT
, /* other text/ content */
328 MIME_ALTERNATIVE
, /* multipart/alternative content */
329 MIME_DIGEST
, /* multipart/digest content */
330 MIME_MULTI
, /* other multipart/ content */
331 MIME_PKCS7
, /* PKCS7 content */
332 MIME_DISCARD
/* content is discarded */
336 TD_NONE
= 0, /* no display conversion */
337 TD_ISPR
= 1<<0, /* use isprint() checks */
338 TD_ICONV
= 1<<1, /* use iconv() */
339 TD_DELCTRL
= 1<<2, /* delete control characters */
342 * NOTE: _TD_EOF and _TD_BUFCOPY may be ORd with enum conversion and
343 * enum sendaction, and may thus NOT clash with their bit range!
345 _TD_EOF
= 1<<14,/* EOF seen, last round! */
346 _TD_BUFCOPY
= 1<<15 /* Buffer may be constant, copy it */
350 PROTO_FILE
, /* refers to a local file */
351 PROTO_POP3
, /* is a pop3 server string */
352 PROTO_IMAP
, /* is an imap server string */
353 PROTO_MAILDIR
, /* refers to a maildir folder */
354 PROTO_UNKNOWN
/* unknown protocol */
358 enum ssl_vrfy_level
{
367 char *s
; /* the string's content */
368 size_t l
; /* the stings's length */
371 struct time_current
{
378 struct termios_state
{
379 struct termios ts_tios
;
382 bool_t ts_needs_reset
;
385 #define termios_state_reset() \
387 if (termios_state.ts_needs_reset) {\
388 tcsetattr(0, TCSADRAIN, &termios_state.ts_tios);\
389 termios_state.ts_needs_reset = FAL0;\
393 struct sock
{ /* data associated with a socket */
394 int s_fd
; /* file descriptor */
396 int s_use_ssl
; /* SSL is used */
398 void *s_ssl
; /* SSL object */
399 void *s_ctx
; /* SSL context object */
402 char *s_wbuf
; /* for buffered writes */
403 int s_wbufsize
; /* allocated size of s_buf */
404 int s_wbufpos
; /* position of first empty data byte */
405 char *s_rbufptr
; /* read pointer to s_rbuf */
406 int s_rsz
; /* size of last read in s_rbuf */
407 char const *s_desc
; /* description of error messages */
408 void (*s_onclose
)(void); /* execute on close */
409 char s_rbuf
[LINESIZE
+ 1]; /* for buffered reads */
414 MB_NONE
= 000, /* no reply expected */
415 MB_COMD
= 001, /* command reply expected */
416 MB_MULT
= 002, /* multiline reply expected */
417 MB_PREAUTH
= 004, /* not in authenticated state */
418 MB_BYE
= 010 /* may accept a BYE state */
420 FILE *mb_itf
; /* temp file with messages, read open */
421 FILE *mb_otf
; /* same, write open */
422 char *mb_sorted
; /* sort method */
424 MB_VOID
, /* no type (e. g. connection failed) */
425 MB_FILE
, /* local file */
426 MB_POP3
, /* POP3 mailbox */
427 MB_IMAP
, /* IMAP mailbox */
428 MB_MAILDIR
, /* maildir folder */
429 MB_CACHE
/* cached mailbox */
430 } mb_type
; /* type of mailbox */
432 MB_DELE
= 01, /* may delete messages in mailbox */
433 MB_EDIT
= 02 /* may edit messages in mailbox */
435 int mb_compressed
; /* is a compressed mbox file */
436 int mb_threaded
; /* mailbox has been threaded */
440 MB_UIDPLUS
= 001 /* supports IMAP UIDPLUS */
442 unsigned long mb_uidvalidity
; /* IMAP unique identifier validity */
443 char *mb_imap_account
; /* name of current IMAP account */
444 char *mb_imap_mailbox
; /* name of current IMAP mailbox */
445 char *mb_cache_directory
; /* name of cache directory */
447 struct sock mb_sock
; /* socket structure */
451 NEED_UNSPEC
, /* unspecified need, don't fetch */
452 NEED_HEADER
, /* need the header of a message */
453 NEED_BODY
/* need header and body of a message */
457 HAVE_NOTHING
= 0, /* nothing downloaded yet */
458 HAVE_HEADER
= 01, /* header is downloaded */
459 HAVE_BODY
= 02 /* entire message is downloaded */
463 * flag bits. Attention: Flags that are used in cache.c may not change.
466 MUSED
= (1<<0), /* entry is used, but this bit isn't */
467 MDELETED
= (1<<1), /* entry has been deleted */
468 MSAVED
= (1<<2), /* entry has been saved */
469 MTOUCH
= (1<<3), /* entry has been noticed */
470 MPRESERVE
= (1<<4), /* keep entry in sys mailbox */
471 MMARK
= (1<<5), /* message is marked! */
472 MODIFY
= (1<<6), /* message has been modified */
473 MNEW
= (1<<7), /* message has never been seen */
474 MREAD
= (1<<8), /* message has been read sometime. */
475 MSTATUS
= (1<<9), /* message status has changed */
476 MBOX
= (1<<10), /* Send this to mbox, regardless */
477 MNOFROM
= (1<<11), /* no From line */
478 MHIDDEN
= (1<<12), /* message is hidden to user */
479 MFULLYCACHED
= (1<<13), /* message is completely cached */
480 MBOXED
= (1<<14), /* message has been sent to mbox */
481 MUNLINKED
= (1<<15), /* message was unlinked from cache */
482 MNEWEST
= (1<<16), /* message is very new (newmail) */
483 MFLAG
= (1<<17), /* message has been flagged recently */
484 MUNFLAG
= (1<<18), /* message has been unflagged */
485 MFLAGGED
= (1<<19), /* message is `flagged' */
486 MANSWER
= (1<<20), /* message has been answered recently */
487 MUNANSWER
= (1<<21), /* message has been unanswered */
488 MANSWERED
= (1<<22), /* message is `answered' */
489 MDRAFT
= (1<<23), /* message has been drafted recently */
490 MUNDRAFT
= (1<<24), /* message has been undrafted */
491 MDRAFTED
= (1<<25), /* message is marked as `draft' */
492 MKILL
= (1<<26), /* message has been killed */
493 MOLDMARK
= (1<<27), /* messages was marked previously */
494 MJUNK
= (1<<28) /* message is classified as junk */
498 enum mflag m_flag
; /* flags */
499 enum havespec m_have
; /* downloaded parts of the part */
500 int m_block
; /* block number of this part */
501 size_t m_offset
; /* offset in block of part */
502 size_t m_size
; /* Bytes in the part */
503 size_t m_xsize
; /* Bytes in the full part */
504 long m_lines
; /* Lines in the message */
505 long m_xlines
; /* Lines in the full message */
506 time_t m_time
; /* time the message was sent */
507 char const *m_from
; /* message sender */
508 struct mimepart
*m_nextpart
; /* next part at same level */
509 struct mimepart
*m_multipart
; /* parts of multipart */
510 struct mimepart
*m_parent
; /* enclosing multipart part */
511 char *m_ct_type
; /* content-type */
512 char *m_ct_type_plain
; /* content-type without specs */
513 enum mimecontent m_mimecontent
; /* same in enum */
514 char const *m_charset
; /* charset */
515 char *m_ct_transfer_enc
; /* content-transfer-encoding */
516 enum mimeenc m_mimeenc
; /* same in enum */
517 char *m_partstring
; /* part level string */
518 char *m_filename
; /* attachment filename */
522 enum mflag m_flag
; /* flags */
523 enum havespec m_have
; /* downloaded parts of the message */
524 int m_block
; /* block number of this message */
525 size_t m_offset
; /* offset in block of message */
526 size_t m_size
; /* Bytes in the message */
527 size_t m_xsize
; /* Bytes in the full message */
528 long m_lines
; /* Lines in the message */
529 long m_xlines
; /* Lines in the full message */
530 time_t m_time
; /* time the message was sent */
531 time_t m_date
; /* time in the 'Date' field */
532 unsigned m_idhash
; /* hash on Message-ID for threads */
533 struct message
*m_child
; /* first child of this message */
534 struct message
*m_younger
; /* younger brother of this message */
535 struct message
*m_elder
; /* elder brother of this message */
536 struct message
*m_parent
; /* parent of this message */
537 unsigned m_level
; /* thread level of message */
538 long m_threadpos
; /* position in threaded display */
540 float m_score
; /* score of message */
543 unsigned long m_uid
; /* IMAP unique identifier */
545 char *m_maildir_file
; /* original maildir file of msg */
546 unsigned m_maildir_hash
; /* hash of file name in maildir sub */
547 int m_collapsed
; /* collapsed thread information */
551 * Given a file address, determine the block number it represents.
553 #define mailx_blockof(off) ((int) ((off) / 4096))
554 #define mailx_offsetof(off) ((int) ((off) % 4096))
555 #define mailx_positionof(block, offset) ((off_t)(block) * 4096 + (offset))
561 MSGLIST
= 0, /* Message list type */
562 STRLIST
= 1, /* A pure string */
563 RAWLIST
= 2, /* Shell string list */
564 NOLIST
= 3, /* Just plain 0 */
565 NDMLIST
= 4, /* Message list, no defaults */
566 ECHOLIST
= 5, /* Like raw list, but keep quote chars */
567 P
= 040, /* Autoprint dot after command */
568 I
= 0100, /* Interactive command bit */
569 M
= 0200, /* Legal from send mode bit */
570 W
= 0400, /* Illegal when read only bit */
571 F
= 01000, /* Is a conditional command */
572 T
= 02000, /* Is a transparent command */
573 R
= 04000, /* Cannot be called from collect */
574 A
= 010000 /* Needs an active mailbox */
578 * Oft-used mask values
580 #define MMNORM (MDELETED|MSAVED|MHIDDEN) /* Look at save *and* delete bits */
581 #define MMNDEL (MDELETED|MHIDDEN) /* Look only at deleted bit */
584 * Format of the command description table.
585 * The actual table is declared and initialized
589 char const *c_name
; /* Name of command */
590 int (*c_func
)(void *); /* Implementor of command */
591 enum argtype c_argtype
; /* Arglist type (see below) */
592 short c_msgflag
; /* Required flags of msgs*/
593 short c_msgmask
; /* Relevant flags of msgs */
594 #ifdef USE_DOCSTRINGS
595 int c_docid
; /* Translation id of .c_doc */
596 char const *c_doc
; /* One line doc for command */
600 /* Yechh, can't initialize unions */
602 #define c_minargs c_msgflag /* Minimum argcount for RAWLIST */
603 #define c_maxargs c_msgmask /* Max argcount for RAWLIST */
606 GTO
= 1, /* Grab To: line */
607 GSUBJECT
= 2, /* Likewise, Subject: line */
608 GCC
= 4, /* And the Cc: line */
609 GBCC
= 8, /* And also the Bcc: line */
611 GNL
= 16, /* Print blank line after */
612 GDEL
= 32, /* Entity removed from list */
613 GCOMMA
= 64, /* detract puts in commas */
614 GUA
= 128, /* User-Agent field */
615 GMIME
= 256, /* MIME 1.0 fields */
616 GMSGID
= 512, /* a Message-ID */
617 /* 1024 */ /* unused */
618 GIDENT
= 2048, /* From:, Reply-To: and Organization: field */
619 GREF
= 4096, /* References: field */
620 GDATE
= 8192, /* Date: field */
621 GFULL
= 16384, /* include full names */
622 GSKIN
= 32768, /* skin names */
623 GEXTRA
= 65536, /* extra fields */
624 GFILES
= 131072 /* include filename addresses */
627 #define GMASK (GTO|GSUBJECT|GCC|GBCC) /* Mask of places from whence */
629 #define visible(mp) (((mp)->m_flag & (MDELETED|MHIDDEN|MKILL)) == 0 || \
630 (dot == (mp) && (mp)->m_flag & MKILL))
633 * Structure used to pass about the current state of a message (header).
636 struct name
*h_to
; /* Dynamic "To:" string */
637 char *h_subject
; /* Subject string */
638 struct name
*h_cc
; /* Carbon copies string */
639 struct name
*h_bcc
; /* Blind carbon copies */
640 struct name
*h_ref
; /* References */
641 struct attachment
*h_attach
; /* MIME attachments */
642 char *h_charset
; /* preferred charset */
643 struct name
*h_from
; /* overridden "From:" field */
644 struct name
*h_replyto
; /* overridden "Reply-To:" field */
645 struct name
*h_sender
; /* overridden "Sender:" field */
646 char *h_organization
; /* overridden "Organization:" field */
650 * Handling of namelist nodes used in processing the recipients of mail and
651 * aliases, inspection of mail-addresses and all that kind of stuff.
655 NAME_NAME_SALLOC
= 1<< 0, /* .n_name is doped */
656 NAME_FULLNAME_SALLOC
= 1<< 1, /* .n_fullname is doped */
657 NAME_SKINNED
= 1<< 2, /* Is actually skin()ned */
658 NAME_IDNA
= 1<< 3, /* IDNA was applied */
659 NAME_ADDRSPEC_CHECKED
= 1<< 4, /* Address has been .. and */
660 NAME_ADDRSPEC_ISFILE
= 1<< 5, /* ..is a file path */
661 NAME_ADDRSPEC_ISPIPE
= 1<< 6, /* ..is a command for piping */
662 NAME_ADDRSPEC_ISFILEORPIPE
= NAME_ADDRSPEC_ISFILE
|
663 NAME_ADDRSPEC_ISPIPE
,
664 NAME_ADDRSPEC_ERR_EMPTY
= 1<< 7, /* An empty string (or NULL) */
665 NAME_ADDRSPEC_ERR_ATSEQ
= 1<< 8, /* Weird @ sequence */
666 NAME_ADDRSPEC_ERR_CHAR
= 1<< 9, /* Invalid character */
667 NAME_ADDRSPEC_ERR_IDNA
= 1<<10, /* IDNA convertion failed */
668 NAME_ADDRSPEC_INVALID
= NAME_ADDRSPEC_ERR_EMPTY
|
669 NAME_ADDRSPEC_ERR_ATSEQ
|
670 NAME_ADDRSPEC_ERR_CHAR
|
671 NAME_ADDRSPEC_ERR_IDNA
,
674 _NAME_MAXWC
= 0xFFFFF,
675 _NAME_MASKWC
= _NAME_MAXWC
<< _NAME_SHIFTWC
678 /* In the !_ERR_EMPTY case, the failing character can be queried */
679 #define NAME_ADDRSPEC_ERR_GETWC(F) \
680 ((((unsigned int)(F) & _NAME_MASKWC) >> _NAME_SHIFTWC) & _NAME_MAXWC)
681 #define NAME_ADDRSPEC_ERR_SET(F, E, WC) \
682 do (F) = ((F) & ~(NAME_ADDRSPEC_INVALID | _NAME_MASKWC)) | \
683 (E) | (((unsigned int)(WC) & _NAME_MAXWC) << _NAME_SHIFTWC); \
687 struct name
*n_flink
; /* Forward link in list. */
688 struct name
*n_blink
; /* Backward list link */
689 enum gfield n_type
; /* From which list it came */
690 enum nameflags n_flags
; /* enum nameflags */
691 char *n_name
; /* This fella's name */
692 char *n_fullname
; /* Sometimes, name including comment */
696 char const *ag_input
; /* Input string as given */
697 size_t ag_ilen
; /* strlen() of input */
698 size_t ag_iaddr_start
; /* Start of *addr-spec* in .ag_input */
699 size_t ag_iaddr_aend
; /* ..and one past its end */
700 char *ag_skinned
; /* Output (alloced if !=.ag_input) */
701 size_t ag_slen
; /* strlen() of .ag_skinned */
702 size_t ag_sdom_start
; /* Start of domain in .ag_skinned, */
703 enum nameflags ag_n_flags
; /* enum nameflags of .ag_skinned */
711 AC_DEFAULT
, /* _get_lc() -> _iter_*() */
712 AC_FIX_OUTCS
, /* _get_lc() -> "charset=" .a_charset */
713 AC_FIX_INCS
, /* "charset=".a_input_charset (nocnv) */
714 AC_TMPFILE
/* attachment.a_tmpf is converted */
718 struct attachment
*a_flink
; /* Forward link in list. */
719 struct attachment
*a_blink
; /* Backward list link */
720 char const *a_name
; /* file name */
721 char const *a_content_type
; /* content type */
722 char const *a_content_disposition
; /* content disposition */
723 char const *a_content_id
; /* content id */
724 char const *a_content_description
; /* content description */
725 char const *a_input_charset
; /* Interpretation depends on .a_conv */
726 char const *a_charset
; /* ... */
727 FILE *a_tmpf
; /* If AC_TMPFILE */
728 enum attach_conv a_conv
; /* User chosen conversion */
729 int a_msgno
; /* message number */
733 * Structure of a variable node. All variables are
734 * kept on a singly-linked list of these, rooted by
738 struct var
*v_link
; /* Forward link to next variable */
739 char *v_name
; /* The variable's name */
740 char *v_value
; /* And it's current value */
744 struct group
*ge_link
; /* Next person in this group */
745 char *ge_name
; /* This person's user name */
749 struct grouphead
*g_link
; /* Next grouphead in list */
750 char *g_name
; /* Name of this group */
751 struct group
*g_list
; /* Users in group. */
755 * Structure of the hash table of ignored header fields
758 int i_count
; /* Number of entries */
760 struct ignore
*i_link
; /* Next ignored field in bucket */
761 char *i_field
; /* This ignored field */
766 * Token values returned by the scanner used for argument lists.
767 * Also, sizes of scanner-related things.
770 TEOL
= 0, /* End of the command line */
771 TNUMBER
= 1, /* A message number */
772 TDASH
= 2, /* A simple dash */
773 TSTRING
= 3, /* A string (possibly containing -) */
774 TDOT
= 4, /* A "." */
775 TUP
= 5, /* An "^" */
776 TDOLLAR
= 6, /* A "$" */
777 TSTAR
= 7, /* A "*" */
778 TOPEN
= 8, /* An '(' */
779 TCLOSE
= 9, /* A ')' */
780 TPLUS
= 10, /* A '+' */
781 TERROR
= 11, /* A lexical error */
782 TCOMMA
= 12, /* A ',' */
783 TSEMI
= 13, /* A ';' */
784 TBACK
= 14 /* A '`' */
787 #define REGDEP 2 /* Maximum regret depth. */
790 * Constants for conditional commands. These describe whether
791 * we should be executing stuff or not.
794 CANY
= 0, /* Execute in send or receive mode */
795 CRCV
= 1, /* Execute in receive mode only */
796 CSEND
= 2, /* Execute in send mode only */
797 CTERM
= 3, /* Execute only if stdin is a tty */
798 CNONTERM
= 4 /* Execute only if stdin not tty */
802 * For the 'shortcut' and 'unshortcut' functionality.
805 struct shortcut
*sh_next
; /* next shortcut in list */
806 char *sh_short
; /* shortcut string */
807 char *sh_long
; /* expanded form */
811 * Kludges to handle the change from setexit / reset to setjmp / longjmp
813 #define setexit() (void)sigsetjmp(srbuf, 1)
814 #define reset(x) siglongjmp(srbuf, x)
817 * Content-Transfer-Encodings as defined in RFC 2045:
818 * - Quoted-Printable, section 6.7
819 * - Base64, section 6.8
822 #define QP_LINESIZE (4 * 19 +1) /* Max. compliant QP linesize (+1) */
824 #define B64_LINESIZE (4 * 19 +1) /* Max. compl. Base64 linesize (+1) */
825 #define B64_ENCODE_INPUT_PER_LINE 57 /* Max. input for Base64 encode/line */
827 /* xxx QP came later, maybe rewrite all to use mimecte_flags directly? */
828 enum __mimecte_flags
{
830 MIMECTE_SALLOC
= 1<<0, /* Use salloc(), not srealloc().. */
831 /* ..result .s,.l point to user buffer of *_LINESIZE+ bytes instead */
833 MIMECTE_CRLF
= 1<<2, /* (encode) Append "\r\n" to lines */
834 MIMECTE_LF
= 1<<3, /* (encode) Append "\n" to lines */
835 /* (encode) If one of _CRLF/_LF is set, honour *_LINESIZE and
836 * inject the desired line-ending whenever a linewrap is desired */
837 MIMECTE_MULTILINE
= 1<<4,
838 /* (encode) Quote with header rules, do not generate soft NL breaks? */
839 MIMECTE_ISHEAD
= 1<<5
843 QP_NONE
= MIMECTE_NONE
,
844 QP_SALLOC
= MIMECTE_SALLOC
,
845 QP_BUF
= MIMECTE_BUF
,
846 QP_ISHEAD
= MIMECTE_ISHEAD
850 B64_NONE
= MIMECTE_NONE
,
851 B64_SALLOC
= MIMECTE_SALLOC
,
852 B64_BUF
= MIMECTE_BUF
,
853 B64_CRLF
= MIMECTE_CRLF
,
855 B64_MULTILINE
= MIMECTE_MULTILINE
859 * Locale-independent character classes.
874 extern uc_it
const class_char
[];
876 #define __ischarof(C, FLAGS) \
877 (asciichar(C) && (class_char[(uc_it)(C)] & (FLAGS)) != 0)
879 #define asciichar(c) ((uc_it)(c) <= 0177)
880 #define alnumchar(c) __ischarof(c, C_DIGIT|C_OCTAL|C_UPPER|C_LOWER)
881 #define alphachar(c) __ischarof(c, C_UPPER|C_LOWER)
882 #define blankchar(c) __ischarof(c, C_BLANK)
883 #define blankspacechar(c) __ischarof(c, C_BLANK|C_SPACE)
884 #define cntrlchar(c) __ischarof(c, C_CNTRL)
885 #define digitchar(c) __ischarof(c, C_DIGIT|C_OCTAL)
886 #define lowerchar(c) __ischarof(c, C_LOWER)
887 #define punctchar(c) __ischarof(c, C_PUNCT)
888 #define spacechar(c) __ischarof(c, C_BLANK|C_SPACE|C_WHITE)
889 #define upperchar(c) __ischarof(c, C_UPPER)
890 #define whitechar(c) __ischarof(c, C_BLANK|C_WHITE)
891 #define octalchar(c) __ischarof(c, C_OCTAL)
893 #define upperconv(c) (lowerchar(c) ? (char)((uc_it)(c) - 'a' + 'A') : (c))
894 #define lowerconv(c) (upperchar(c) ? (char)((uc_it)(c) - 'A' + 'a') : (c))
896 #define fieldnamechar(c) \
897 (asciichar(c) && (c) > 040 && (c) != 0177 && (c) != ':')
900 * Try to use alloca() for some function-local buffers and data,
901 * fall back to smalloc()/free() if not available.
904 # define ac_alloc(n) HAVE_ALLOCA(n)
905 # define ac_free(n) do {} while (0)
907 # define ac_alloc(n) smalloc(n)
908 # define ac_free(n) free(n)
912 * Single-threaded, use unlocked I/O.
914 #ifdef HAVE_PUTC_UNLOCKED
916 # define getc(c) getc_unlocked(c)
918 # define putc(c, f) putc_unlocked(c, f)
920 # define putchar(c) putc_unlocked((c), stdout)
924 * Truncate a file to the last character written. This is
925 * useful just before closing an old file that was opened
928 #define ftrunc(stream) do {\
931 off = ftell(stream);\
933 ftruncate(fileno(stream), off);\
937 * fflush() and rewind()
939 #define fflush_rewind(stream) do { \
945 * For saving the current directory and later returning.
951 char cw_wd
[PATHSIZE
];