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 PURE __attribute__((pure))
50 #define NMH_UNUSED(i) (void) i
53 #define CHECK_PRINTF(fmt, arg)
54 #define ALLOC_SIZE(...)
59 #define NMH_UNUSED(i) i
62 /* DIM gives the number of elements in the one-dimensional array a. */
63 #define DIM(a) (sizeof (a) / sizeof (*(a)))
65 /* LEN gives the strlen() of string constant s, excluding the
67 #define LEN(s) (sizeof (s) - 1)
69 /* FENDNULL fends off NULL by giving an empty string instead. */
70 #define FENDNULL(s) ((s) ? (s) : "")
73 * char array that keeps track of size in both bytes and characters
75 * Don't store return value of charstring_buffer() and use later
76 * after intervening push_back's; use charstring_buffer_copy()
79 typedef struct charstring
*charstring_t
;
81 charstring_t
charstring_create (size_t);
82 charstring_t
charstring_copy (const charstring_t
) NONNULL(1);
83 void charstring_free (charstring_t
);
84 /* Append a single-byte character: */
85 void charstring_push_back (charstring_t
, const char) NONNULL(1);
86 /* Append possibly multi-byte character(s): */
87 void charstring_push_back_chars (charstring_t
, const char [], size_t, size_t) NONNULL(1);
88 void charstring_append (charstring_t
, const charstring_t
) NONNULL(2);
89 void charstring_append_cstring (charstring_t
, const char []) NONNULL(2);
90 void charstring_clear (charstring_t
) NONNULL(1);
91 /* Don't store return value of charstring_buffer() and use later after
92 intervening push_back's; use charstring_buffer_copy() instead. */
93 const char *charstring_buffer (const charstring_t
) NONNULL(1);
94 /* User is responsible for free'ing result of buffer copy. */
95 char *charstring_buffer_copy (const charstring_t
) NONNULL(1);
96 size_t charstring_bytes (const charstring_t
) NONNULL(1) PURE
;
97 size_t charstring_chars (const charstring_t
) NONNULL(1) PURE
;
98 /* Length of the last character in the charstring. */
99 int charstring_last_char_len (const charstring_t
) NONNULL(1);
102 * user context/profile structure
105 char *n_name
; /* key */
106 char *n_field
; /* value */
107 char n_context
; /* context, not profile */
108 struct node
*n_next
; /* next entry */
114 #define AMBIGSW (-2) /* from smatch() on ambiguous switch */
115 #define UNKWNSW (-1) /* from smatch() on unknown switch */
125 /* The minchars field is apparently used like this:
127 -# : Switch can be abbreviated to # characters; switch hidden in -help.
128 0 : Switch can't be abbreviated; switch shown in -help.
129 # : Switch can be abbreviated to # characters; switch shown in -help. */
133 * If we pick this switch, return this value from smatch
140 * Macros to use when declaring struct swit arrays.
142 * These macros use a technique known as X-Macros. In your source code you
143 * use them like this:
145 * #define FOO_SWITCHES \
146 * X("switch1", 0, SWITCHSW) \
147 * X("switch2", 0, SWITCH2SW) \
148 * X("thirdswitch", 2, SWITCH3SW) \
150 * The argument to each entry in FOO_SWITCHES are the switch name (sw),
151 * the minchars field (see above) and the return value for this switch.
152 * Note that the last entry in the above definition must either omit the
153 * continuation backslash, or be followed by a blank line. In the nmh
154 * code the style is to have every line include a backslash and follow
155 * the SWITCHES macro definition by a blank line.
157 * After you define FOO_SWITCHES, you instantiate it as follows:
159 * #define X(sw, minchars, id) id,
160 * DEFINE_SWITCH_ENUM(FOO);
163 * #define X(sw, minchars, id) { sw, minchars, id },
164 * DEFINE_SWITCH_ARRAY(FOO);
167 * DEFINE_SWITCH_ENUM defines an extra enum at the end of the list called
171 #define DEFINE_SWITCH_ENUM(name) \
177 #define DEFINE_SWITCH_ARRAY(name, array) \
178 static struct swit array[] = { \
183 extern struct swit anoyes
[]; /* standard yes/no switches */
186 * general folder attributes
188 #define READONLY (1<<0) /* No write access to folder */
189 #define SEQMOD (1<<1) /* folder's sequences modified */
190 #define ALLOW_NEW (1<<2) /* allow the "new" sequence */
191 #define OTHERS (1<<3) /* folder has other files */
193 #define FBITS "\020\01READONLY\02SEQMOD\03ALLOW_NEW\04OTHERS"
196 * first free slot for user defined sequences
202 * internal messages attributes (sequences)
204 #define EXISTS (0) /* exists */
205 #define SELECTED (1) /* selected for use */
206 #define SELECT_EMPTY (2) /* "new" message */
207 #define SELECT_UNSEEN (3) /* inc/show "unseen" */
209 #define MBITS "\020\01EXISTS\02SELECTED\03NEW\04UNSEEN"
211 /* A vector of bits for tracking the sequence membership of a single
212 * message. Do not access the struct members; use vector.c.
213 * Do not move or copy this struct as it may contain a pointer to
214 * itself; use bvector_copy(). */
218 unsigned long tiny
[2]; /* Default fixed-size storage for bits. */
220 typedef struct bvector
*bvector_t
;
222 bvector_t
bvector_create (void);
223 void bvector_init(struct bvector
*bv
) NONNULL(1);
224 void bvector_copy (bvector_t
, bvector_t
) NONNULL(1, 2);
225 void bvector_free (bvector_t
) NONNULL(1);
226 void bvector_fini(struct bvector
*bv
) NONNULL(1);
227 void bvector_clear (bvector_t
, size_t) NONNULL(1);
228 void bvector_clear_all (bvector_t
) NONNULL(1);
229 void bvector_set (bvector_t
, size_t) NONNULL(1);
230 unsigned int bvector_at (bvector_t
, size_t) NONNULL(1) PURE
;
231 unsigned long bvector_first_bits (bvector_t
) NONNULL(1) PURE
;
233 typedef struct svector
*svector_t
;
235 svector_t
svector_create (size_t);
236 void svector_free (svector_t
) NONNULL(1);
237 char *svector_push_back (svector_t
, char *) NONNULL(1);
238 char *svector_at (svector_t
, size_t) NONNULL(1);
239 char **svector_find(svector_t
, const char *) NONNULL(1) PURE
;
240 char **svector_strs (svector_t
) NONNULL(1) PURE
;
241 size_t svector_size (svector_t
) NONNULL(1) PURE
;
243 typedef struct ivector
*ivector_t
;
245 ivector_t
ivector_create (size_t);
246 void ivector_free (ivector_t
) NONNULL(1);
247 int ivector_push_back (ivector_t
, int) NONNULL(1);
248 int ivector_at (ivector_t
, size_t) NONNULL(1);
249 int *ivector_atp (ivector_t
, size_t) NONNULL(1);
252 * Primary structure of folder/message information
255 int lowmsg
; /* Lowest msg number */
256 int hghmsg
; /* Highest msg number */
257 int nummsg
; /* Actual Number of msgs */
259 int lowsel
; /* Lowest selected msg number */
260 int hghsel
; /* Highest selected msg number */
261 int numsel
; /* Number of msgs selected */
263 int curmsg
; /* Number of current msg if any */
265 int msgflags
; /* Folder attributes (READONLY, etc) */
266 char *foldpath
; /* Pathname of folder */
269 * Name of sequences in this folder.
274 * bit flags for whether sequence
275 * is public (0), or private (1)
280 * These represent the lowest and highest possible
281 * message numbers we can put in the message status
282 * area, without calling folder_realloc().
288 * This is an array of bvector_t which we allocate dynamically.
289 * Each bvector_t is a set of bits flags for a particular message.
290 * These bit flags represent general attributes such as
291 * EXISTS, SELECTED, etc. as well as track if message is
292 * in a particular sequence.
295 struct bvector
*msgstats
; /* msg status */
298 * A FILE handle containing an open filehandle for the sequence file
299 * for this folder. If non-NULL, use it when the sequence file is
305 * The name of the public sequence file; required by lkfclose()
311 * Amount of space to allocate for msgstats. Allocate
312 * the array to have space for messages numbered lo to hi.
313 * Use MSGSTATNUM to load mp->num_msgstats first.
315 #define MSGSTATNUM(lo, hi) ((size_t) ((hi) - (lo) + 1))
316 #define MSGSTATSIZE(mp) ((mp)->num_msgstats * sizeof *(mp)->msgstats)
319 * macros for message and sequence manipulation
321 #define msgstat(mp,n) ((mp)->msgstats + (n) - mp->lowoff)
322 #define clear_msg_flags(mp,msgnum) bvector_clear_all (msgstat(mp, msgnum))
323 #define copy_msg_flags(mp,i,j) bvector_copy (msgstat(mp,i), msgstat(mp,j))
324 #define get_msg_flags(mp,ptr,msgnum) bvector_copy (ptr, msgstat(mp, msgnum))
325 #define set_msg_flags(mp,ptr,msgnum) bvector_copy (msgstat(mp, msgnum), ptr)
327 #define does_exist(mp,msgnum) bvector_at (msgstat(mp, msgnum), EXISTS)
328 #define unset_exists(mp,msgnum) bvector_clear (msgstat(mp, msgnum), EXISTS)
329 #define set_exists(mp,msgnum) bvector_set (msgstat(mp, msgnum), EXISTS)
331 #define is_selected(mp,msgnum) bvector_at (msgstat(mp, msgnum), SELECTED)
332 #define unset_selected(mp,msgnum) bvector_clear (msgstat(mp, msgnum), SELECTED)
333 #define set_selected(mp,msgnum) bvector_set (msgstat(mp, msgnum), SELECTED)
335 #define is_select_empty(mp,msgnum) \
336 bvector_at (msgstat(mp, msgnum), SELECT_EMPTY)
337 #define set_select_empty(mp,msgnum) \
338 bvector_set (msgstat(mp, msgnum), SELECT_EMPTY)
340 #define is_unseen(mp,msgnum) \
341 bvector_at (msgstat(mp, msgnum), SELECT_UNSEEN)
342 #define unset_unseen(mp,msgnum) \
343 bvector_clear (msgstat(mp, msgnum), SELECT_UNSEEN)
344 #define set_unseen(mp,msgnum) \
345 bvector_set (msgstat(mp, msgnum), SELECT_UNSEEN)
347 #define in_sequence(mp,seqnum,msgnum) \
348 bvector_at (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
349 #define clear_sequence(mp,seqnum,msgnum) \
350 bvector_clear (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
351 #define add_sequence(mp,seqnum,msgnum) \
352 bvector_set (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
354 #define is_seq_private(mp,seqnum) \
355 bvector_at (mp->attrstats, FFATTRSLOT + seqnum)
356 #define make_seq_public(mp,seqnum) \
357 bvector_clear (mp->attrstats, FFATTRSLOT + seqnum)
358 #define make_seq_private(mp,seqnum) \
359 bvector_set (mp->attrstats, FFATTRSLOT + seqnum)
360 #define make_all_public(mp) \
361 mp->attrstats = bvector_create(); bvector_clear_all (mp->attrstats)
364 * macros for folder attributes
366 #define clear_folder_flags(mp) ((mp)->msgflags = 0)
368 #define is_readonly(mp) ((mp)->msgflags & READONLY)
369 #define set_readonly(mp) ((mp)->msgflags |= READONLY)
371 #define other_files(mp) ((mp)->msgflags & OTHERS)
372 #define set_other_files(mp) ((mp)->msgflags |= OTHERS)
375 * m_getfld() message parsing
378 #define NAMESZ 999 /* Limit on component name size.
379 RFC 2822 limits line lengths to
380 998 characters, so a header name
381 can be at most that long.
382 m_getfld limits header names to 2
383 less than NAMESZ, which is fine,
384 because header names must be
385 followed by a colon. Add one for
388 /* Token type or error returned from m_getfld(), and its internal state
389 * for the next call. */
390 /* FLD detects the header's name is too long to fit in the fixed size
393 /* FLD reaches EOF after the header's name, or the name is followed by
394 * a linefeed rather than a colon and the body buffer isn't large enough
395 * to pretend this header line starts the body. */
397 /* The initial state, looking for headers. Returned when the header's
400 /* Another chunk of the header's value has been returned, but there's
403 /* A chunk of the email's body has been returned. */
405 /* Either the end of the input file has been reached, or the delimiter
406 * between emails has been found and the caller should
407 * m_getfld_state_reset() to reset the state to FLD for continuing
408 * through the file. */
411 typedef struct m_getfld_state
*m_getfld_state_t
;
413 #define NOUSE 0 /* draft being re-used */
415 #define TFOLDER 0 /* path() given a +folder */
416 #define TFILE 1 /* path() given a file */
417 #define TSUBCWF 2 /* path() given a @folder */
419 #define OUTPUTLINELEN 72 /* default line length for headers */
421 #define LINK "@" /* Name of link to file to which you are */
425 * credentials management
427 typedef struct nmh_creds
*nmh_creds_t
;
430 * miscellaneous macros
432 #define pidXwait(pid,cp) pidstatus (pidwait (pid, NOTOK), stdout, cp)
435 # define max(a,b) ((a) > (b) ? (a) : (b))
439 # define min(a,b) ((a) < (b) ? (a) : (b))
443 # define abs(a) ((a) > 0 ? (a) : -(a))
449 #define CTXMOD 0x01 /* context information modified */
450 #define DBITS "\020\01CTXMOD"
451 extern char ctxflags
;
453 extern char *invo_name
; /* command invocation name */
454 extern char *mypath
; /* user's $HOME */
455 extern char *defpath
; /* pathname of user's profile */
456 extern char *ctxpath
; /* pathname of user's context */
457 extern struct node
*m_defs
; /* list of profile/context entries */
460 * These standard strings are defined in config.c. They are the
461 * only system-dependent parameters in nmh, and thus by redefining
462 * their values and reloading the various modules, nmh will run
465 extern char *buildmimeproc
;
466 extern char *catproc
;
467 extern char *components
;
468 extern char *context
;
469 extern char *current
;
470 extern char *credentials_file
;
471 extern int credentials_no_perm_check
;
472 extern char *defaultfolder
;
473 extern char *digestcomps
;
474 extern char *distcomps
;
476 extern char *fileproc
;
477 extern char *foldprot
;
478 extern char *formatproc
;
479 extern char *forwcomps
;
481 extern char *incproc
;
483 extern char *mailproc
;
484 extern char *mh_defaults
;
485 extern char *mh_profile
;
487 extern char *mhlformat
;
488 extern char *mhlforward
;
489 extern char *mhlproc
;
490 extern char *mhlreply
;
491 extern char *moreproc
;
492 extern char *msgprot
;
493 extern char *nmhaccessftp
;
494 extern char *nmhaccessurl
;
495 extern char *nmhstorage
;
496 extern char *nmhcache
;
497 extern char *nmhprivcache
;
498 extern char *nsequence
;
499 extern char *packproc
;
500 extern char *postproc
;
501 extern char *pfolder
;
502 extern char *psequence
;
503 extern char *rcvdistcomps
;
504 extern char *rcvstoreproc
;
505 extern char *replcomps
;
506 extern char *replgroupcomps
;
507 extern char *rmmproc
;
508 extern char *sendproc
;
509 extern char *showmimeproc
;
510 extern char *showproc
;
511 extern char *usequence
;
512 extern char *user_agent
;
513 extern char *version_num
;
514 extern char *version_str
;
515 extern char *whatnowproc
;
516 extern char *whomproc
;
518 extern void (*done
) (int) NORETURN
;
520 #include <h/prototypes.h>