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 */
20 * This macro is for use by scan, for example, so that platforms with
21 * a small BUFSIZ can easily allocate larger buffers.
23 #define NMH_BUFSIZ max(BUFSIZ, 8192)
31 typedef unsigned char boolean
; /* not int so we can pack in a structure */
33 /* If we're using gcc then give it some information about
34 * functions that abort.
37 #define NORETURN __attribute__((__noreturn__))
38 #define NMH_UNUSED(i) (void) i
41 #define NMH_UNUSED(i) i
44 /* DIM gives the number of elements in the one-dimensional array a. */
45 #define DIM(a) (sizeof (a) / sizeof (*(a)))
47 /* LEN gives the strlen() of string constant s, excluding the
49 #define LEN(s) (sizeof (s) - 1)
51 /* FENDNULL fends off NULL by giving an empty string instead. */
52 #define FENDNULL(s) ((s) ? (s) : "")
54 /* PLURALS gives a pointer to the string "s" when n isn't 1, and to the
55 * empty string "" when it is. Suitable for obtaining the plural `s'
56 * used for English nouns. It treats -1 as plural, as does GNU gettext.
57 * Having output vary for plurals is annoying for those writing parsers;
58 * better to phrase the output such that no test is needed, e.g.
59 * "messages found: 42". */
60 extern const char plurals
[];
61 #define PLURALS(n) (plurals + ((n) == 1))
64 * char array that keeps track of size in both bytes and characters
66 * Don't store return value of charstring_buffer() and use later
67 * after intervening push_back's; use charstring_buffer_copy()
70 typedef struct charstring
*charstring_t
;
72 charstring_t
charstring_create (size_t);
73 charstring_t
charstring_copy (const charstring_t
);
74 void charstring_free (charstring_t
);
75 /* Append a single-byte character: */
76 void charstring_push_back (charstring_t
, const char);
77 /* Append possibly multi-byte character(s): */
78 void charstring_push_back_chars (charstring_t
, const char [], size_t, size_t);
79 void charstring_append (charstring_t
, const charstring_t
);
80 void charstring_append_cstring (charstring_t
, const char []);
81 void charstring_clear (charstring_t
);
82 /* Don't store return value of charstring_buffer() and use later after
83 intervening push_back's; use charstring_buffer_copy() instead. */
84 const char *charstring_buffer (const charstring_t
);
85 /* User is responsible for free'ing result of buffer copy. */
86 char *charstring_buffer_copy (const charstring_t
);
87 size_t charstring_bytes (const charstring_t
);
88 size_t charstring_chars (const charstring_t
);
89 /* Length of the last character in the charstring. */
90 int charstring_last_char_len (const charstring_t
);
93 * user context/profile structure
96 char *n_name
; /* key */
97 char *n_field
; /* value */
98 char n_context
; /* context, not profile */
99 struct node
*n_next
; /* next entry */
105 #define AMBIGSW (-2) /* from smatch() on ambiguous switch */
106 #define UNKWNSW (-1) /* from smatch() on unknown switch */
116 /* The minchars field is apparently used like this:
118 -# : Switch can be abbreviated to # characters; switch hidden in -help.
119 0 : Switch can't be abbreviated; switch shown in -help.
120 # : Switch can be abbreviated to # characters; switch shown in -help. */
124 * If we pick this switch, return this value from smatch
131 * Macros to use when declaring struct swit arrays.
133 * These macros use a technique known as X-Macros. In your source code you
134 * use them like this:
136 * #define FOO_SWITCHES \
137 * X("switch1", 0, SWITCHSW) \
138 * X("switch2", 0, SWITCH2SW) \
139 * X("thirdswitch", 2, SWITCH3SW) \
141 * The argument to each entry in FOO_SWITCHES are the switch name (sw),
142 * the minchars field (see above) and the return value for this switch.
143 * Note that the last entry in the above definition must either omit the
144 * continuation backslash, or be followed by a blank line. In the nmh
145 * code the style is to have every line include a backslash and follow
146 * the SWITCHES macro definition by a blank line.
148 * After you define FOO_SWITCHES, you instantiate it as follows:
150 * #define X(sw, minchars, id) id,
151 * DEFINE_SWITCH_ENUM(FOO);
154 * #define X(sw, minchars, id) { sw, minchars, id },
155 * DEFINE_SWITCH_ARRAY(FOO);
158 * DEFINE_SWITCH_ENUM defines an extra enum at the end of the list called
162 #define DEFINE_SWITCH_ENUM(name) \
168 #define DEFINE_SWITCH_ARRAY(name, array) \
169 static struct swit array[] = { \
174 extern struct swit anoyes
[]; /* standard yes/no switches */
177 * general folder attributes
179 #define READONLY (1<<0) /* No write access to folder */
180 #define SEQMOD (1<<1) /* folder's sequences modified */
181 #define ALLOW_NEW (1<<2) /* allow the "new" sequence */
182 #define OTHERS (1<<3) /* folder has other files */
184 #define FBITS "\020\01READONLY\02SEQMOD\03ALLOW_NEW\04OTHERS"
187 * first free slot for user defined sequences
193 * internal messages attributes (sequences)
195 #define EXISTS (0) /* exists */
196 #define SELECTED (1) /* selected for use */
197 #define SELECT_EMPTY (2) /* "new" message */
198 #define SELECT_UNSEEN (3) /* inc/show "unseen" */
200 #define MBITS "\020\01EXISTS\02SELECTED\03NEW\04UNSEEN"
202 /* A vector of bits for tracking the sequence membership of a single
203 * message. Do not access the struct members; use vector.c.
204 * Do not move or copy this struct as it may contain a pointer to
205 * itself; use bvector_copy(). */
209 unsigned long tiny
[2]; /* Default fixed-size storage for bits. */
211 typedef struct bvector
*bvector_t
;
213 bvector_t
bvector_create (void);
214 void bvector_init(struct bvector
*bv
);
215 void bvector_copy (bvector_t
, bvector_t
);
216 void bvector_free (bvector_t
);
217 void bvector_fini(struct bvector
*bv
);
218 void bvector_clear (bvector_t
, size_t);
219 void bvector_clear_all (bvector_t
);
220 void bvector_set (bvector_t
, size_t);
221 unsigned int bvector_at (bvector_t
, size_t);
222 unsigned long bvector_first_bits (bvector_t
);
224 typedef struct svector
*svector_t
;
226 svector_t
svector_create (size_t);
227 void svector_free (svector_t
);
228 char *svector_push_back (svector_t
, char *);
229 char *svector_at (svector_t
, size_t);
230 char **svector_find(svector_t
, const char *);
231 char **svector_strs (svector_t
);
232 size_t svector_size (svector_t
);
234 typedef struct ivector
*ivector_t
;
236 ivector_t
ivector_create (size_t);
237 void ivector_free (ivector_t
);
238 int ivector_push_back (ivector_t
, int);
239 int ivector_at (ivector_t
, size_t);
240 int *ivector_atp (ivector_t
, size_t);
243 * Primary structure of folder/message information
246 int lowmsg
; /* Lowest msg number */
247 int hghmsg
; /* Highest msg number */
248 int nummsg
; /* Actual Number of msgs */
250 int lowsel
; /* Lowest selected msg number */
251 int hghsel
; /* Highest selected msg number */
252 int numsel
; /* Number of msgs selected */
254 int curmsg
; /* Number of current msg if any */
256 int msgflags
; /* Folder attributes (READONLY, etc) */
257 char *foldpath
; /* Pathname of folder */
260 * Name of sequences in this folder.
265 * bit flags for whether sequence
266 * is public (0), or private (1)
271 * These represent the lowest and highest possible
272 * message numbers we can put in the message status
273 * area, without calling folder_realloc().
279 * This is an array of bvector_t which we allocate dynamically.
280 * Each bvector_t is a set of bits flags for a particular message.
281 * These bit flags represent general attributes such as
282 * EXISTS, SELECTED, etc. as well as track if message is
283 * in a particular sequence.
286 struct bvector
*msgstats
; /* msg status */
289 * A FILE handle containing an open filehandle for the sequence file
290 * for this folder. If non-NULL, use it when the sequence file is
296 * The name of the public sequence file; required by lkfclose()
302 * Amount of space to allocate for msgstats. Allocate
303 * the array to have space for messages numbered lo to hi.
304 * Use MSGSTATNUM to load mp->num_msgstats first.
306 #define MSGSTATNUM(lo, hi) ((size_t) ((hi) - (lo) + 1))
307 #define MSGSTATSIZE(mp) ((mp)->num_msgstats * sizeof *(mp)->msgstats)
310 * macros for message and sequence manipulation
312 #define msgstat(mp,n) ((mp)->msgstats + (n) - mp->lowoff)
313 #define clear_msg_flags(mp,msgnum) bvector_clear_all (msgstat(mp, msgnum))
314 #define copy_msg_flags(mp,i,j) bvector_copy (msgstat(mp,i), msgstat(mp,j))
315 #define get_msg_flags(mp,ptr,msgnum) bvector_copy (ptr, msgstat(mp, msgnum))
316 #define set_msg_flags(mp,ptr,msgnum) bvector_copy (msgstat(mp, msgnum), ptr)
318 #define does_exist(mp,msgnum) bvector_at (msgstat(mp, msgnum), EXISTS)
319 #define unset_exists(mp,msgnum) bvector_clear (msgstat(mp, msgnum), EXISTS)
320 #define set_exists(mp,msgnum) bvector_set (msgstat(mp, msgnum), EXISTS)
322 #define is_selected(mp,msgnum) bvector_at (msgstat(mp, msgnum), SELECTED)
323 #define unset_selected(mp,msgnum) bvector_clear (msgstat(mp, msgnum), SELECTED)
324 #define set_selected(mp,msgnum) bvector_set (msgstat(mp, msgnum), SELECTED)
326 #define is_select_empty(mp,msgnum) \
327 bvector_at (msgstat(mp, msgnum), SELECT_EMPTY)
328 #define set_select_empty(mp,msgnum) \
329 bvector_set (msgstat(mp, msgnum), SELECT_EMPTY)
331 #define is_unseen(mp,msgnum) \
332 bvector_at (msgstat(mp, msgnum), SELECT_UNSEEN)
333 #define unset_unseen(mp,msgnum) \
334 bvector_clear (msgstat(mp, msgnum), SELECT_UNSEEN)
335 #define set_unseen(mp,msgnum) \
336 bvector_set (msgstat(mp, msgnum), SELECT_UNSEEN)
338 #define in_sequence(mp,seqnum,msgnum) \
339 bvector_at (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
340 #define clear_sequence(mp,seqnum,msgnum) \
341 bvector_clear (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
342 #define add_sequence(mp,seqnum,msgnum) \
343 bvector_set (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
345 #define is_seq_private(mp,seqnum) \
346 bvector_at (mp->attrstats, FFATTRSLOT + seqnum)
347 #define make_seq_public(mp,seqnum) \
348 bvector_clear (mp->attrstats, FFATTRSLOT + seqnum)
349 #define make_seq_private(mp,seqnum) \
350 bvector_set (mp->attrstats, FFATTRSLOT + seqnum)
351 #define make_all_public(mp) \
352 mp->attrstats = bvector_create(); bvector_clear_all (mp->attrstats)
355 * macros for folder attributes
357 #define clear_folder_flags(mp) ((mp)->msgflags = 0)
359 #define is_readonly(mp) ((mp)->msgflags & READONLY)
360 #define set_readonly(mp) ((mp)->msgflags |= READONLY)
362 #define other_files(mp) ((mp)->msgflags & OTHERS)
363 #define set_other_files(mp) ((mp)->msgflags |= OTHERS)
365 #define NULLMP ((struct msgs *) 0)
368 * m_getfld() message parsing
371 #define NAMESZ 999 /* Limit on component name size.
372 RFC 2822 limits line lengths to
373 998 characters, so a header name
374 can be at most that long.
375 m_getfld limits header names to 2
376 less than NAMESZ, which is fine,
377 because header names must be
378 followed by a colon. Add one for
381 #define LENERR (-2) /* Name too long error from getfld */
382 #define FMTERR (-3) /* Message Format error */
383 #define FLD 0 /* Field returned */
384 #define FLDPLUS 1 /* Field returned with more to come */
385 #define BODY 3 /* Body returned with more to come */
386 #define FILEEOF 5 /* Reached end of input file */
388 typedef struct m_getfld_state
*m_getfld_state_t
;
393 #define MS_DEFAULT 0 /* default (one msg per file) */
394 #define MS_UNKNOWN 1 /* type not known yet */
395 #define MS_MBOX 2 /* Unix-style "from" lines */
396 #define MS_MMDF 3 /* string mmdlm2 */
398 #define NOUSE 0 /* draft being re-used */
400 #define TFOLDER 0 /* path() given a +folder */
401 #define TFILE 1 /* path() given a file */
402 #define TSUBCWF 2 /* path() given a @folder */
404 #define OUTPUTLINELEN 72 /* default line length for headers */
406 #define LINK "@" /* Name of link to file to which you are */
410 * credentials management
412 typedef struct nmh_creds
*nmh_creds_t
;
415 * miscellaneous macros
417 #define pidXwait(pid,cp) pidstatus (pidwait (pid, NOTOK), stdout, cp)
420 # define max(a,b) ((a) > (b) ? (a) : (b))
424 # define min(a,b) ((a) < (b) ? (a) : (b))
428 # define abs(a) ((a) > 0 ? (a) : -(a))
434 #define CTXMOD 0x01 /* context information modified */
435 #define DBITS "\020\01CTXMOD"
436 extern char ctxflags
;
438 extern char *invo_name
; /* command invocation name */
439 extern char *mypath
; /* user's $HOME */
440 extern char *defpath
; /* pathname of user's profile */
441 extern char *ctxpath
; /* pathname of user's context */
442 extern struct node
*m_defs
; /* list of profile/context entries */
444 /* What style to use for generated Message-ID and Content-ID header
445 fields. The localname style is pid.time@localname, where time is
446 in seconds. The random style replaces the localname with some
447 (pseudo)random bytes and uses microsecond-resolution time. */
448 int save_message_id_style (const char *);
449 char *message_id (time_t, int);
452 * These standard strings are defined in config.c. They are the
453 * only system-dependent parameters in nmh, and thus by redefining
454 * their values and reloading the various modules, nmh will run
457 extern char *buildmimeproc
;
458 extern char *catproc
;
459 extern char *components
;
460 extern char *context
;
461 extern char *current
;
462 extern char *credentials_file
;
463 extern int credentials_no_perm_check
;
464 extern char *defaultfolder
;
465 extern char *digestcomps
;
466 extern char *distcomps
;
468 extern char *fileproc
;
469 extern char *foldprot
;
470 extern char *formatproc
;
471 extern char *forwcomps
;
473 extern char *incproc
;
475 extern char *mailproc
;
476 extern char *mh_defaults
;
477 extern char *mh_profile
;
479 extern char *mhlformat
;
480 extern char *mhlforward
;
481 extern char *mhlproc
;
482 extern char *mhlreply
;
483 extern char *moreproc
;
484 extern char *msgprot
;
485 extern char *nmhaccessftp
;
486 extern char *nmhaccessurl
;
487 extern char *nmhstorage
;
488 extern char *nmhcache
;
489 extern char *nmhprivcache
;
490 extern char *nsequence
;
491 extern char *packproc
;
492 extern char *postproc
;
493 extern char *pfolder
;
494 extern char *psequence
;
495 extern char *rcvdistcomps
;
496 extern char *rcvstoreproc
;
497 extern char *replcomps
;
498 extern char *replgroupcomps
;
499 extern char *rmmproc
;
500 extern char *sendproc
;
501 extern char *showmimeproc
;
502 extern char *showproc
;
503 extern char *usequence
;
504 extern char *user_agent
;
505 extern char *version_num
;
506 extern char *version_str
;
507 extern char *whatnowproc
;
508 extern char *whomproc
;
510 extern void (*done
) (int) NORETURN
;
512 #include <h/prototypes.h>