2 * Heirloom mailx - a mail user agent derived from Berkeley Mail.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 Steffen "Daode" Nurpmeso
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
39 * Sccsid @(#)def.h 2.104 (gritter) 3/4/06
43 * Mail -- a mail program
45 * Author: Kurt Shoens (UCB) March 25, 1978
48 #if !defined (NI_MAXHOST) || (NI_MAXHOST) < 1025
50 #define NI_MAXHOST 1025
53 #define APPEND /* New mail goes to end of mailbox */
55 /* Is *C* a quoting character (for *quote-fold* compression) */
56 #define ISQUOTE(C) ((C) == '>' || (C) == '|')
58 #define ESCAPE '~' /* Default escape for sending */
61 #define MAXPATHLEN PATH_MAX
63 #define MAXPATHLEN 1024
67 #define PATHSIZE MAXPATHLEN /* Size of pathnames throughout */
69 #define HSHSIZE 59 /* Hash size for aliases and vars */
70 #define LINESIZE 2560 /* max readable line width */
71 #define STRINGSIZE ((unsigned) 128)/* Dynamic allocation units */
72 #define MAXARGC 1024 /* Maximum list of raw strings */
73 #define MAXEXP 25 /* Maximum expansion of aliases */
75 #define equal(a, b) (strcmp(a,b)==0)/* A nice function to string compare */
79 #else /* !HAVE_CATGETS */
80 #define catgets(a, b, c, d) (d)
81 #endif /* !HAVE_CATGETS */
83 typedef void (*sighandler_type
)(int);
91 MIME_NONE
, /* message is not in MIME format */
92 MIME_BIN
, /* message is in binary encoding */
93 MIME_8B
, /* message is in 8bit encoding */
94 MIME_7B
, /* message is in 7bit encoding */
95 MIME_QP
, /* message is quoted-printable */
96 MIME_B64
/* message is in base64 encoding */
100 CONV_NONE
, /* no conversion */
101 CONV_7BIT
, /* no conversion, is 7bit */
102 CONV_FROMQP
, /* convert from quoted-printable */
103 CONV_TOQP
, /* convert to quoted-printable */
104 CONV_8BIT
, /* convert to 8bit (iconv) */
105 CONV_FROMB64
, /* convert from base64 */
106 CONV_FROMB64_T
, /* convert from base64/text */
107 CONV_TOB64
, /* convert to base64 */
108 CONV_FROMHDR
, /* convert from RFC1522 format */
109 CONV_TOHDR
, /* convert to RFC1522 format */
110 CONV_TOHDR_A
/* convert addresses for header */
114 SEND_MBOX
, /* no conversion to perform */
115 SEND_RFC822
, /* no conversion, no From_ line */
116 SEND_TODISP
, /* convert to displayable form */
117 SEND_TODISP_ALL
, /* same, include all MIME parts */
118 SEND_SHOW
, /* convert to 'show' command form */
119 SEND_TOSRCH
, /* convert for IMAP SEARCH */
120 SEND_TOFLTR
, /* convert for junk mail filtering */
121 SEND_TOFILE
, /* convert for saving body to a file */
122 SEND_TOPIPE
, /* convert for pipe-content/subc. */
123 SEND_QUOTE
, /* convert for quoting */
124 SEND_QUOTE_ALL
, /* same, include all MIME parts */
125 SEND_DECRYPT
/* decrypt */
129 MIME_UNKNOWN
, /* unknown content */
130 MIME_SUBHDR
, /* inside a multipart subheader */
131 MIME_822
, /* message/rfc822 content */
132 MIME_MESSAGE
, /* other message/ content */
133 MIME_TEXT_PLAIN
, /* text/plain content */
134 MIME_TEXT_HTML
, /* text/html content */
135 MIME_TEXT
, /* other text/ content */
136 MIME_ALTERNATIVE
, /* multipart/alternative content */
137 MIME_DIGEST
, /* multipart/digest content */
138 MIME_MULTI
, /* other multipart/ content */
139 MIME_PKCS7
, /* PKCS7 content */
140 MIME_DISCARD
/* content is discarded */
144 MIME_CLEAN
= 000, /* plain RFC 2822 message */
145 MIME_HIGHBIT
= 001, /* characters >= 0200 */
146 MIME_LONGLINES
= 002, /* has lines too long for RFC 2822 */
147 MIME_CTRLCHAR
= 004, /* contains control characters */
148 MIME_HASNUL
= 010, /* contains \0 characters */
149 MIME_NOTERMNL
= 020 /* lacks a terminating newline */
153 TD_NONE
= 0, /* no display conversion */
154 TD_ISPR
= 01, /* use isprint() checks */
155 TD_ICONV
= 02, /* use iconv() */
156 TD_DELCTRL
= 04 /* delete control characters */
160 char *s
; /* the string's content */
161 size_t l
; /* the stings's length */
165 PROTO_FILE
, /* refers to a local file */
166 PROTO_POP3
, /* is a pop3 server string */
167 PROTO_IMAP
, /* is an imap server string */
168 PROTO_MAILDIR
, /* refers to a maildir folder */
169 PROTO_UNKNOWN
/* unknown protocol */
172 struct sock
{ /* data associated with a socket */
173 int s_fd
; /* file descriptor */
175 int s_use_ssl
; /* SSL is used */
176 #if defined (USE_NSS)
177 void *s_prfd
; /* NSPR file descriptor */
178 #elif defined (USE_OPENSSL)
179 void *s_ssl
; /* SSL object */
180 void *s_ctx
; /* SSL context object */
181 #endif /* SSL library specific */
183 char *s_wbuf
; /* for buffered writes */
184 int s_wbufsize
; /* allocated size of s_buf */
185 int s_wbufpos
; /* position of first empty data byte */
186 char s_rbuf
[LINESIZE
+1]; /* for buffered reads */
187 char *s_rbufptr
; /* read pointer to s_rbuf */
188 int s_rsz
; /* size of last read in s_rbuf */
189 char *s_desc
; /* description of error messages */
190 void (*s_onclose
)(void); /* execute on close */
194 struct sock mb_sock
; /* socket structure */
196 MB_NONE
= 000, /* no reply expected */
197 MB_COMD
= 001, /* command reply expected */
198 MB_MULT
= 002, /* multiline reply expected */
199 MB_PREAUTH
= 004, /* not in authenticated state */
200 MB_BYE
= 010 /* may accept a BYE state */
202 FILE *mb_itf
; /* temp file with messages, read open */
203 FILE *mb_otf
; /* same, write open */
204 char *mb_sorted
; /* sort method */
206 MB_VOID
, /* no type (e. g. connection failed) */
207 MB_FILE
, /* local file */
208 MB_POP3
, /* POP3 mailbox */
209 MB_IMAP
, /* IMAP mailbox */
210 MB_MAILDIR
, /* maildir folder */
211 MB_CACHE
/* cached mailbox */
212 } mb_type
; /* type of mailbox */
214 MB_DELE
= 01, /* may delete messages in mailbox */
215 MB_EDIT
= 02 /* may edit messages in mailbox */
217 int mb_compressed
; /* is a compressed mbox file */
218 int mb_threaded
; /* mailbox has been threaded */
221 MB_UIDPLUS
= 001 /* supports IMAP UIDPLUS */
223 unsigned long mb_uidvalidity
; /* IMAP unique identifier validity */
224 char *mb_imap_account
; /* name of current IMAP account */
225 char *mb_imap_mailbox
; /* name of current IMAP mailbox */
226 char *mb_cache_directory
; /* name of cache directory */
230 NEED_UNSPEC
, /* unspecified need, don't fetch */
231 NEED_HEADER
, /* need the header of a message */
232 NEED_BODY
/* need header and body of a message */
236 HAVE_NOTHING
= 0, /* nothing downloaded yet */
237 HAVE_HEADER
= 01, /* header is downloaded */
238 HAVE_BODY
= 02 /* entire message is downloaded */
242 * flag bits. Attention: Flags that are used in cache.c may not change.
245 MUSED
= (1<<0), /* entry is used, but this bit isn't */
246 MDELETED
= (1<<1), /* entry has been deleted */
247 MSAVED
= (1<<2), /* entry has been saved */
248 MTOUCH
= (1<<3), /* entry has been noticed */
249 MPRESERVE
= (1<<4), /* keep entry in sys mailbox */
250 MMARK
= (1<<5), /* message is marked! */
251 MODIFY
= (1<<6), /* message has been modified */
252 MNEW
= (1<<7), /* message has never been seen */
253 MREAD
= (1<<8), /* message has been read sometime. */
254 MSTATUS
= (1<<9), /* message status has changed */
255 MBOX
= (1<<10), /* Send this to mbox, regardless */
256 MNOFROM
= (1<<11), /* no From line */
257 MHIDDEN
= (1<<12), /* message is hidden to user */
258 MFULLYCACHED
= (1<<13), /* message is completely cached */
259 MBOXED
= (1<<14), /* message has been sent to mbox */
260 MUNLINKED
= (1<<15), /* message was unlinked from cache */
261 MNEWEST
= (1<<16), /* message is very new (newmail) */
262 MFLAG
= (1<<17), /* message has been flagged recently */
263 MUNFLAG
= (1<<18), /* message has been unflagged */
264 MFLAGGED
= (1<<19), /* message is `flagged' */
265 MANSWER
= (1<<20), /* message has been answered recently */
266 MUNANSWER
= (1<<21), /* message has been unanswered */
267 MANSWERED
= (1<<22), /* message is `answered' */
268 MDRAFT
= (1<<23), /* message has been drafted recently */
269 MUNDRAFT
= (1<<24), /* message has been undrafted */
270 MDRAFTED
= (1<<25), /* message is marked as `draft' */
271 MKILL
= (1<<26), /* message has been killed */
272 MOLDMARK
= (1<<27), /* messages was marked previously */
273 MJUNK
= (1<<28) /* message is classified as junk */
277 enum mflag m_flag
; /* flags */
278 enum havespec m_have
; /* downloaded parts of the part */
279 int m_block
; /* block number of this part */
280 size_t m_offset
; /* offset in block of part */
281 size_t m_size
; /* Bytes in the part */
282 size_t m_xsize
; /* Bytes in the full part */
283 long m_lines
; /* Lines in the message */
284 long m_xlines
; /* Lines in the full message */
285 time_t m_time
; /* time the message was sent */
286 char *m_from
; /* message sender */
287 struct mimepart
*m_nextpart
; /* next part at same level */
288 struct mimepart
*m_multipart
; /* parts of multipart */
289 struct mimepart
*m_parent
; /* enclosing multipart part */
290 char *m_ct_type
; /* content-type */
291 char *m_ct_type_plain
; /* content-type without specs */
292 enum mimecontent m_mimecontent
; /* same in enum */
293 char *m_charset
; /* charset */
294 char *m_ct_transfer_enc
; /* content-transfer-encoding */
295 enum mimeenc m_mimeenc
; /* same in enum */
296 char *m_partstring
; /* part level string */
297 char *m_filename
; /* attachment filename */
301 enum mflag m_flag
; /* flags */
302 enum havespec m_have
; /* downloaded parts of the message */
303 int m_block
; /* block number of this message */
304 size_t m_offset
; /* offset in block of message */
305 size_t m_size
; /* Bytes in the message */
306 size_t m_xsize
; /* Bytes in the full message */
307 long m_lines
; /* Lines in the message */
308 long m_xlines
; /* Lines in the full message */
309 time_t m_time
; /* time the message was sent */
310 time_t m_date
; /* time in the 'Date' field */
311 unsigned m_idhash
; /* hash on Message-ID for threads */
312 unsigned long m_uid
; /* IMAP unique identifier */
313 struct message
*m_child
; /* first child of this message */
314 struct message
*m_younger
; /* younger brother of this message */
315 struct message
*m_elder
; /* elder brother of this message */
316 struct message
*m_parent
; /* parent of this message */
317 unsigned m_level
; /* thread level of message */
318 long m_threadpos
; /* position in threaded display */
319 float m_score
; /* score of message */
320 char *m_maildir_file
; /* original maildir file of msg */
321 unsigned m_maildir_hash
; /* hash of file name in maildir sub */
322 int m_collapsed
; /* collapsed thread information */
326 * Given a file address, determine the block number it represents.
328 #define mailx_blockof(off) ((int) ((off) / 4096))
329 #define mailx_offsetof(off) ((int) ((off) % 4096))
330 #define mailx_positionof(block, offset) ((off_t)(block) * 4096 + (offset))
336 MSGLIST
= 0, /* Message list type */
337 STRLIST
= 1, /* A pure string */
338 RAWLIST
= 2, /* Shell string list */
339 NOLIST
= 3, /* Just plain 0 */
340 NDMLIST
= 4, /* Message list, no defaults */
341 ECHOLIST
= 5, /* Like raw list, but keep quote chars */
342 P
= 040, /* Autoprint dot after command */
343 I
= 0100, /* Interactive command bit */
344 M
= 0200, /* Legal from send mode bit */
345 W
= 0400, /* Illegal when read only bit */
346 F
= 01000, /* Is a conditional command */
347 T
= 02000, /* Is a transparent command */
348 R
= 04000, /* Cannot be called from collect */
349 A
= 010000 /* Needs an active mailbox */
353 * Oft-used mask values
356 #define MMNORM (MDELETED|MSAVED|MHIDDEN)/* Look at both save and delete bits */
357 #define MMNDEL (MDELETED|MHIDDEN) /* Look only at deleted bit */
360 * Format of the command description table.
361 * The actual table is declared and initialized
365 char *c_name
; /* Name of command */
366 int (*c_func
)(void *); /* Implementor of the command */
367 enum argtype c_argtype
; /* Type of arglist (see below) */
368 short c_msgflag
; /* Required flags of messages */
369 short c_msgmask
; /* Relevant flags of messages */
372 /* Yechh, can't initialize unions */
374 #define c_minargs c_msgflag /* Minimum argcount for RAWLIST */
375 #define c_maxargs c_msgmask /* Max argcount for RAWLIST */
378 * Structure used to return a break down of a head
379 * line (hats off to Bill Joy!)
383 char *l_from
; /* The name of the sender */
384 char *l_tty
; /* His tty string (if any) */
385 char *l_date
; /* The entire date string */
389 GTO
= 1, /* Grab To: line */
390 GSUBJECT
= 2, /* Likewise, Subject: line */
391 GCC
= 4, /* And the Cc: line */
392 GBCC
= 8, /* And also the Bcc: line */
394 GNL
= 16, /* Print blank line after */
395 GDEL
= 32, /* Entity removed from list */
396 GCOMMA
= 64, /* detract puts in commas */
397 GUA
= 128, /* User-Agent field */
398 GMIME
= 256, /* MIME 1.0 fields */
399 GMSGID
= 512, /* a Message-ID */
400 /* 1024 */ /* unused */
401 GIDENT
= 2048, /* From:, Reply-To: and Organization: field */
402 GREF
= 4096, /* References: field */
403 GDATE
= 8192, /* Date: field */
404 GFULL
= 16384, /* include full names */
405 GSKIN
= 32768, /* skin names */
406 GEXTRA
= 65536, /* extra fields */
407 GFILES
= 131072 /* include filename addresses */
410 #define GMASK (GTO|GSUBJECT|GCC|GBCC) /* Mask of places from whence */
412 #define visible(mp) (((mp)->m_flag & (MDELETED|MHIDDEN|MKILL)) == 0 || \
413 (dot == (mp) && (mp)->m_flag & MKILL))
416 * Structure used to pass about the current
417 * state of the user-typed message header.
421 struct name
*h_to
; /* Dynamic "To:" string */
422 char *h_subject
; /* Subject string */
423 struct name
*h_cc
; /* Carbon copies string */
424 struct name
*h_bcc
; /* Blind carbon copies */
425 struct name
*h_ref
; /* References */
426 struct name
*h_smopts
; /* Sendmail options */
427 struct attachment
*h_attach
; /* MIME attachments */
428 char *h_charset
; /* preferred charset */
429 struct name
*h_from
; /* overridden "From:" field */
430 struct name
*h_replyto
; /* overridden "Reply-To:" field */
431 struct name
*h_sender
; /* overridden "Sender:" field */
432 char *h_organization
; /* overridden "Organization:" field */
436 * Structure of namelist nodes used in processing
437 * the recipients of mail and aliases and all that
442 struct name
*n_flink
; /* Forward link in list. */
443 struct name
*n_blink
; /* Backward list link */
444 enum gfield n_type
; /* From which list it came */
445 char *n_name
; /* This fella's name */
446 char *n_fullname
; /* Sometimes, name including comment */
450 * Structure of a MIME attachment.
454 struct attachment
*a_flink
; /* Forward link in list. */
455 struct attachment
*a_blink
; /* Backward list link */
456 char *a_name
; /* file name */
457 char *a_content_type
; /* content type */
458 char *a_content_disposition
; /* content disposition */
459 char *a_content_id
; /* content id */
460 char *a_content_description
; /* content description */
461 char *a_charset
; /* character set */
462 int a_msgno
; /* message number */
466 * Structure of a variable node. All variables are
467 * kept on a singly-linked list of these, rooted by
472 struct var
*v_link
; /* Forward link to next variable */
473 char *v_name
; /* The variable's name */
474 char *v_value
; /* And it's current value */
478 struct group
*ge_link
; /* Next person in this group */
479 char *ge_name
; /* This person's user name */
483 struct grouphead
*g_link
; /* Next grouphead in list */
484 char *g_name
; /* Name of this group */
485 struct group
*g_list
; /* Users in group. */
489 * Structure of the hash table of ignored header fields
492 int i_count
; /* Number of entries */
494 struct ignore
*i_link
; /* Next ignored field in bucket */
495 char *i_field
; /* This ignored field */
500 * Token values returned by the scanner used for argument lists.
501 * Also, sizes of scanner-related things.
504 TEOL
= 0, /* End of the command line */
505 TNUMBER
= 1, /* A message number */
506 TDASH
= 2, /* A simple dash */
507 TSTRING
= 3, /* A string (possibly containing -) */
508 TDOT
= 4, /* A "." */
509 TUP
= 5, /* An "^" */
510 TDOLLAR
= 6, /* A "$" */
511 TSTAR
= 7, /* A "*" */
512 TOPEN
= 8, /* An '(' */
513 TCLOSE
= 9, /* A ')' */
514 TPLUS
= 10, /* A '+' */
515 TERROR
= 11, /* A lexical error */
516 TCOMMA
= 12, /* A ',' */
517 TSEMI
= 13, /* A ';' */
518 TBACK
= 14 /* A '`' */
521 #define REGDEP 2 /* Maximum regret depth. */
524 * Constants for conditional commands. These describe whether
525 * we should be executing stuff or not.
528 CANY
= 0, /* Execute in send or receive mode */
529 CRCV
= 1, /* Execute in receive mode only */
530 CSEND
= 2, /* Execute in send mode only */
531 CTERM
= 3, /* Execute only if stdin is a tty */
532 CNONTERM
= 4 /* Execute only if stdin not tty */
536 * For the 'shortcut' and 'unshortcut' functionality.
539 struct shortcut
*sh_next
; /* next shortcut in list */
540 char *sh_short
; /* shortcut string */
541 char *sh_long
; /* expanded form */
545 * Kludges to handle the change from setexit / reset to setjmp / longjmp
548 #define setexit() sigsetjmp(srbuf, 1)
549 #define reset(x) siglongjmp(srbuf, x)
552 * Locale-independent character classes.
566 extern const unsigned char class_char
[];
568 #define __ischarof(C, FLAGS) (asciichar(C) && class_char[(size_t)C] & (FLAGS))
569 #define __ischareq(C, FLAGS) (asciichar(C) && class_char[(size_t)C] == (FLAGS))
571 #define asciichar(c) ((size_t)(c) <= 0177)
572 #define alnumchar(c) __ischarof(c, C_DIGIT|C_OCTAL|C_UPPER|C_LOWER)
573 #define alphachar(c) __ischarof(c, C_UPPER|C_LOWER)
574 #define blankchar(c) __ischarof(c, C_BLANK)
575 #define blankspacechar(c) __ischarof(c, C_BLANK|C_SPACE)
576 #define cntrlchar(c) __ischareq(c, C_CNTRL)
577 #define digitchar(c) __ischarof(c, C_DIGIT|C_OCTAL)
578 #define lowerchar(c) __ischarof(c, C_LOWER)
579 #define punctchar(c) __ischarof(c, C_PUNCT)
580 #define spacechar(c) __ischarof(c, C_BLANK|C_SPACE|C_WHITE)
581 #define upperchar(c) __ischarof(c, C_UPPER)
582 #define whitechar(c) __ischarof(c, C_BLANK|C_WHITE)
583 #define octalchar(c) __ischarof(c, C_OCTAL)
585 #define upperconv(c) (lowerchar(c) ? (c)-'a'+'A' : (c))
586 #define lowerconv(c) (upperchar(c) ? (c)-'A'+'a' : (c))
588 #define fieldnamechar(c) (asciichar(c)&&(c)>040&&(c)!=0177&&(c)!=':')
591 * Truncate a file to the last character written. This is
592 * useful just before closing an old file that was opened
595 #define trunc(stream) { \
597 ftruncate(fileno(stream), (off_t)ftell(stream)); \
601 * Use either alloca() or smalloc()/free(). ac_alloc can be used to
602 * allocate space within a function. ac_free must be called when the
603 * space is no longer needed, but expands to nothing if using alloca().
606 #define ac_alloc(n) alloca(n)
607 #define ac_free(n) do {} while (0)
608 #else /* !HAVE_ALLOCA */
609 #define ac_alloc(n) smalloc(n)
610 #define ac_free(n) free(n)
611 #endif /* !HAVE_ALLOCA */
614 * glibc uses the slow thread-safe getc() even if _REENTRANT is not
615 * defined. Work around it.
619 #define getc(c) getc_unlocked(c)
621 #define putc(c, f) putc_unlocked(c, f)
623 #define putchar(c) putc_unlocked((c), stdout)
624 #endif /* __GLIBC__ */
626 #define CBAD (-15555)
628 #define smin(a, b) ((a) < (b) ? (a) : (b))
629 #define smax(a, b) ((a) < (b) ? (b) : (a))
632 * For saving the current directory and later returning.
638 #else /* !HAVE_FCHDIR */
640 char cw_wd
[PATHSIZE
];
642 #endif /* !HAVE_FCHDIR */
645 enum ssl_vrfy_level
{