1 /* mh.h -- main header file for all of nmh
9 #define NOTOK (-1) /* syscall()s return this on error */
10 #define OK 0 /* ditto on success */
11 #define DONE 1 /* ternary logic */
14 #define MAXARGS 1000 /* max arguments to exec */
15 #define NFOLDERS 1000 /* max folder arguments on command line */
16 #define DMAXFOLDER 4 /* typical number of digits */
17 #define MAXFOLDER 1000 /* message increment */
19 /* non-zero exit(3) values indicating the number of errors need to be
20 * capped else they interfere with the shell's use of high seven-bit
21 * values, and the shell's mapping of signals onto top-bit-set values.
22 * Plus, every so often the eight-bit value will wrap to zero, wrongly
23 * indicating success. */
27 * This macro is for use by scan, for example, so that platforms with
28 * a small BUFSIZ can easily allocate larger buffers.
30 #define NMH_BUFSIZ max(BUFSIZ, 8192)
38 typedef unsigned char boolean
; /* not int so we can pack in a structure */
40 /* If we're using gcc then tell it extra information so it can do more
41 * compile-time checks. */
43 #define NORETURN __attribute__((__noreturn__))
44 #define CHECK_PRINTF(fmt, arg) __attribute__((format(printf, fmt, arg)))
45 #define ALLOC_SIZE(...) __attribute__((alloc_size(__VA_ARGS__)))
46 #define CONST __attribute__((const))
47 #define MALLOC __attribute__((malloc))
48 #define NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
49 #define NMH_UNUSED(i) (void) i
52 #define CHECK_PRINTF(fmt, arg)
53 #define ALLOC_SIZE(...)
57 #define NMH_UNUSED(i) i
60 /* DIM gives the number of elements in the one-dimensional array a. */
61 #define DIM(a) (sizeof (a) / sizeof (*(a)))
63 /* LEN gives the strlen() of string constant s, excluding the
65 #define LEN(s) (sizeof (s) - 1)
67 /* FENDNULL fends off NULL by giving an empty string instead. */
68 #define FENDNULL(s) ((s) ? (s) : "")
71 * char array that keeps track of size in both bytes and characters
73 * Don't store return value of charstring_buffer() and use later
74 * after intervening push_back's; use charstring_buffer_copy()
77 typedef struct charstring
*charstring_t
;
79 charstring_t
charstring_create (size_t);
80 charstring_t
charstring_copy (const charstring_t
) NONNULL(1);
81 void charstring_free (charstring_t
);
82 /* Append a single-byte character: */
83 void charstring_push_back (charstring_t
, const char) NONNULL(1);
84 /* Append possibly multi-byte character(s): */
85 void charstring_push_back_chars (charstring_t
, const char [], size_t, size_t) NONNULL(1);
86 void charstring_append (charstring_t
, const charstring_t
) NONNULL(2);
87 void charstring_append_cstring (charstring_t
, const char []) NONNULL(2);
88 void charstring_clear (charstring_t
) NONNULL(1);
89 /* Don't store return value of charstring_buffer() and use later after
90 intervening push_back's; use charstring_buffer_copy() instead. */
91 const char *charstring_buffer (const charstring_t
) NONNULL(1);
92 /* User is responsible for free'ing result of buffer copy. */
93 char *charstring_buffer_copy (const charstring_t
) NONNULL(1);
94 size_t charstring_bytes (const charstring_t
) NONNULL(1);
95 size_t charstring_chars (const charstring_t
) NONNULL(1);
96 /* Length of the last character in the charstring. */
97 int charstring_last_char_len (const charstring_t
) NONNULL(1);
100 * user context/profile structure
103 char *n_name
; /* key */
104 char *n_field
; /* value */
105 char n_context
; /* context, not profile */
106 struct node
*n_next
; /* next entry */
112 #define AMBIGSW (-2) /* from smatch() on ambiguous switch */
113 #define UNKWNSW (-1) /* from smatch() on unknown switch */
123 /* The minchars field is apparently used like this:
125 -# : Switch can be abbreviated to # characters; switch hidden in -help.
126 0 : Switch can't be abbreviated; switch shown in -help.
127 # : Switch can be abbreviated to # characters; switch shown in -help. */
131 * If we pick this switch, return this value from smatch
138 * Macros to use when declaring struct swit arrays.
140 * These macros use a technique known as X-Macros. In your source code you
141 * use them like this:
143 * #define FOO_SWITCHES \
144 * X("switch1", 0, SWITCHSW) \
145 * X("switch2", 0, SWITCH2SW) \
146 * X("thirdswitch", 2, SWITCH3SW) \
148 * The argument to each entry in FOO_SWITCHES are the switch name (sw),
149 * the minchars field (see above) and the return value for this switch.
150 * Note that the last entry in the above definition must either omit the
151 * continuation backslash, or be followed by a blank line. In the nmh
152 * code the style is to have every line include a backslash and follow
153 * the SWITCHES macro definition by a blank line.
155 * After you define FOO_SWITCHES, you instantiate it as follows:
157 * #define X(sw, minchars, id) id,
158 * DEFINE_SWITCH_ENUM(FOO);
161 * #define X(sw, minchars, id) { sw, minchars, id },
162 * DEFINE_SWITCH_ARRAY(FOO);
165 * DEFINE_SWITCH_ENUM defines an extra enum at the end of the list called
169 #define DEFINE_SWITCH_ENUM(name) \
175 #define DEFINE_SWITCH_ARRAY(name, array) \
176 static struct swit array[] = { \
181 extern struct swit anoyes
[]; /* standard yes/no switches */
184 * general folder attributes
186 #define READONLY (1<<0) /* No write access to folder */
187 #define SEQMOD (1<<1) /* folder's sequences modified */
188 #define ALLOW_NEW (1<<2) /* allow the "new" sequence */
189 #define OTHERS (1<<3) /* folder has other files */
191 #define FBITS "\020\01READONLY\02SEQMOD\03ALLOW_NEW\04OTHERS"
194 * first free slot for user defined sequences
200 * internal messages attributes (sequences)
202 #define EXISTS (0) /* exists */
203 #define SELECTED (1) /* selected for use */
204 #define SELECT_EMPTY (2) /* "new" message */
205 #define SELECT_UNSEEN (3) /* inc/show "unseen" */
207 #define MBITS "\020\01EXISTS\02SELECTED\03NEW\04UNSEEN"
209 /* A vector of bits for tracking the sequence membership of a single
210 * message. Do not access the struct members; use vector.c.
211 * Do not move or copy this struct as it may contain a pointer to
212 * itself; use bvector_copy(). */
216 unsigned long tiny
[2]; /* Default fixed-size storage for bits. */
218 typedef struct bvector
*bvector_t
;
220 bvector_t
bvector_create (void);
221 void bvector_init(struct bvector
*bv
) NONNULL(1);
222 void bvector_copy (bvector_t
, bvector_t
) NONNULL(1, 2);
223 void bvector_free (bvector_t
) NONNULL(1);
224 void bvector_fini(struct bvector
*bv
) NONNULL(1);
225 void bvector_clear (bvector_t
, size_t) NONNULL(1);
226 void bvector_clear_all (bvector_t
) NONNULL(1);
227 void bvector_set (bvector_t
, size_t) NONNULL(1);
228 unsigned int bvector_at (bvector_t
, size_t) NONNULL(1);
229 unsigned long bvector_first_bits (bvector_t
) NONNULL(1);
231 typedef struct svector
*svector_t
;
233 svector_t
svector_create (size_t);
234 void svector_free (svector_t
) NONNULL(1);
235 char *svector_push_back (svector_t
, char *) NONNULL(1);
236 char *svector_at (svector_t
, size_t) NONNULL(1);
237 char **svector_find(svector_t
, const char *) NONNULL(1);
238 char **svector_strs (svector_t
) NONNULL(1);
239 size_t svector_size (svector_t
) NONNULL(1);
241 typedef struct ivector
*ivector_t
;
243 ivector_t
ivector_create (size_t);
244 void ivector_free (ivector_t
) NONNULL(1);
245 int ivector_push_back (ivector_t
, int) NONNULL(1);
246 int ivector_at (ivector_t
, size_t) NONNULL(1);
247 int *ivector_atp (ivector_t
, size_t) NONNULL(1);
250 * Primary structure of folder/message information
253 int lowmsg
; /* Lowest msg number */
254 int hghmsg
; /* Highest msg number */
255 int nummsg
; /* Actual Number of msgs */
257 int lowsel
; /* Lowest selected msg number */
258 int hghsel
; /* Highest selected msg number */
259 int numsel
; /* Number of msgs selected */
261 int curmsg
; /* Number of current msg if any */
263 int msgflags
; /* Folder attributes (READONLY, etc) */
264 char *foldpath
; /* Pathname of folder */
267 * Name of sequences in this folder.
272 * bit flags for whether sequence
273 * is public (0), or private (1)
278 * These represent the lowest and highest possible
279 * message numbers we can put in the message status
280 * area, without calling folder_realloc().
286 * This is an array of bvector_t which we allocate dynamically.
287 * Each bvector_t is a set of bits flags for a particular message.
288 * These bit flags represent general attributes such as
289 * EXISTS, SELECTED, etc. as well as track if message is
290 * in a particular sequence.
293 struct bvector
*msgstats
; /* msg status */
296 * A FILE handle containing an open filehandle for the sequence file
297 * for this folder. If non-NULL, use it when the sequence file is
303 * The name of the public sequence file; required by lkfclose()
309 * Amount of space to allocate for msgstats. Allocate
310 * the array to have space for messages numbered lo to hi.
311 * Use MSGSTATNUM to load mp->num_msgstats first.
313 #define MSGSTATNUM(lo, hi) ((size_t) ((hi) - (lo) + 1))
314 #define MSGSTATSIZE(mp) ((mp)->num_msgstats * sizeof *(mp)->msgstats)
317 * macros for message and sequence manipulation
319 #define msgstat(mp,n) ((mp)->msgstats + (n) - mp->lowoff)
320 #define clear_msg_flags(mp,msgnum) bvector_clear_all (msgstat(mp, msgnum))
321 #define copy_msg_flags(mp,i,j) bvector_copy (msgstat(mp,i), msgstat(mp,j))
322 #define get_msg_flags(mp,ptr,msgnum) bvector_copy (ptr, msgstat(mp, msgnum))
323 #define set_msg_flags(mp,ptr,msgnum) bvector_copy (msgstat(mp, msgnum), ptr)
325 #define does_exist(mp,msgnum) bvector_at (msgstat(mp, msgnum), EXISTS)
326 #define unset_exists(mp,msgnum) bvector_clear (msgstat(mp, msgnum), EXISTS)
327 #define set_exists(mp,msgnum) bvector_set (msgstat(mp, msgnum), EXISTS)
329 #define is_selected(mp,msgnum) bvector_at (msgstat(mp, msgnum), SELECTED)
330 #define unset_selected(mp,msgnum) bvector_clear (msgstat(mp, msgnum), SELECTED)
331 #define set_selected(mp,msgnum) bvector_set (msgstat(mp, msgnum), SELECTED)
333 #define is_select_empty(mp,msgnum) \
334 bvector_at (msgstat(mp, msgnum), SELECT_EMPTY)
335 #define set_select_empty(mp,msgnum) \
336 bvector_set (msgstat(mp, msgnum), SELECT_EMPTY)
338 #define is_unseen(mp,msgnum) \
339 bvector_at (msgstat(mp, msgnum), SELECT_UNSEEN)
340 #define unset_unseen(mp,msgnum) \
341 bvector_clear (msgstat(mp, msgnum), SELECT_UNSEEN)
342 #define set_unseen(mp,msgnum) \
343 bvector_set (msgstat(mp, msgnum), SELECT_UNSEEN)
345 #define in_sequence(mp,seqnum,msgnum) \
346 bvector_at (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
347 #define clear_sequence(mp,seqnum,msgnum) \
348 bvector_clear (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
349 #define add_sequence(mp,seqnum,msgnum) \
350 bvector_set (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
352 #define is_seq_private(mp,seqnum) \
353 bvector_at (mp->attrstats, FFATTRSLOT + seqnum)
354 #define make_seq_public(mp,seqnum) \
355 bvector_clear (mp->attrstats, FFATTRSLOT + seqnum)
356 #define make_seq_private(mp,seqnum) \
357 bvector_set (mp->attrstats, FFATTRSLOT + seqnum)
358 #define make_all_public(mp) \
359 mp->attrstats = bvector_create(); bvector_clear_all (mp->attrstats)
362 * macros for folder attributes
364 #define clear_folder_flags(mp) ((mp)->msgflags = 0)
366 #define is_readonly(mp) ((mp)->msgflags & READONLY)
367 #define set_readonly(mp) ((mp)->msgflags |= READONLY)
369 #define other_files(mp) ((mp)->msgflags & OTHERS)
370 #define set_other_files(mp) ((mp)->msgflags |= OTHERS)
373 * m_getfld() message parsing
376 #define NAMESZ 999 /* Limit on component name size.
377 RFC 2822 limits line lengths to
378 998 characters, so a header name
379 can be at most that long.
380 m_getfld limits header names to 2
381 less than NAMESZ, which is fine,
382 because header names must be
383 followed by a colon. Add one for
386 /* Token type or error returned from m_getfld(), and its internal state
387 * for the next call. */
388 /* FLD detects the header's name is too long to fit in the fixed size
391 /* FLD reaches EOF after the header's name, or the name is followed by
392 * a linefeed rather than a colon and the body buffer isn't large enough
393 * to pretend this header line starts the body. */
395 /* The initial state, looking for headers. Returned when the header's
398 /* Another chunk of the header's value has been returned, but there's
401 /* A chunk of the email's body has been returned. */
403 /* Either the end of the input file has been reached, or the delimiter
404 * between emails has been found and the caller should
405 * m_getfld_state_reset() to reset the state to FLD for continuing
406 * through the file. */
409 typedef struct m_getfld_state
*m_getfld_state_t
;
411 #define NOUSE 0 /* draft being re-used */
413 #define TFOLDER 0 /* path() given a +folder */
414 #define TFILE 1 /* path() given a file */
415 #define TSUBCWF 2 /* path() given a @folder */
417 #define OUTPUTLINELEN 72 /* default line length for headers */
419 #define LINK "@" /* Name of link to file to which you are */
423 * credentials management
425 typedef struct nmh_creds
*nmh_creds_t
;
428 * miscellaneous macros
430 #define pidXwait(pid,cp) pidstatus (pidwait (pid, NOTOK), stdout, cp)
433 # define max(a,b) ((a) > (b) ? (a) : (b))
437 # define min(a,b) ((a) < (b) ? (a) : (b))
441 # define abs(a) ((a) > 0 ? (a) : -(a))
447 #define CTXMOD 0x01 /* context information modified */
448 #define DBITS "\020\01CTXMOD"
449 extern char ctxflags
;
451 extern char *invo_name
; /* command invocation name */
452 extern char *mypath
; /* user's $HOME */
453 extern char *defpath
; /* pathname of user's profile */
454 extern char *ctxpath
; /* pathname of user's context */
455 extern struct node
*m_defs
; /* list of profile/context entries */
458 * These standard strings are defined in config.c. They are the
459 * only system-dependent parameters in nmh, and thus by redefining
460 * their values and reloading the various modules, nmh will run
463 extern char *buildmimeproc
;
464 extern char *catproc
;
465 extern char *components
;
466 extern char *context
;
467 extern char *current
;
468 extern char *credentials_file
;
469 extern int credentials_no_perm_check
;
470 extern char *defaultfolder
;
471 extern char *digestcomps
;
472 extern char *distcomps
;
474 extern char *fileproc
;
475 extern char *foldprot
;
476 extern char *formatproc
;
477 extern char *forwcomps
;
479 extern char *incproc
;
481 extern char *mailproc
;
482 extern char *mh_defaults
;
483 extern char *mh_profile
;
485 extern char *mhlformat
;
486 extern char *mhlforward
;
487 extern char *mhlproc
;
488 extern char *mhlreply
;
489 extern char *moreproc
;
490 extern char *msgprot
;
491 extern char *nmhaccessftp
;
492 extern char *nmhaccessurl
;
493 extern char *nmhstorage
;
494 extern char *nmhcache
;
495 extern char *nmhprivcache
;
496 extern char *nsequence
;
497 extern char *packproc
;
498 extern char *postproc
;
499 extern char *pfolder
;
500 extern char *psequence
;
501 extern char *rcvdistcomps
;
502 extern char *rcvstoreproc
;
503 extern char *replcomps
;
504 extern char *replgroupcomps
;
505 extern char *rmmproc
;
506 extern char *sendproc
;
507 extern char *showmimeproc
;
508 extern char *showproc
;
509 extern char *usequence
;
510 extern char *user_agent
;
511 extern char *version_num
;
512 extern char *version_str
;
513 extern char *whatnowproc
;
514 extern char *whomproc
;
516 extern void (*done
) (int) NORETURN
;
518 #include <h/prototypes.h>