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 /* trinary 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 (BUFSIZ>=8192 ? 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)
52 * char array that keeps track of size in both bytes and characters
54 * Don't store return value of charstring_buffer() and use later
55 * after intervening push_back's; use charstring_buffer_copy()
58 typedef struct charstring
*charstring_t
;
60 charstring_t
charstring_create (size_t);
61 charstring_t
charstring_copy (const charstring_t
);
62 void charstring_free (charstring_t
);
63 /* Append a single-byte character: */
64 void charstring_push_back (charstring_t
, const char);
65 /* Append possibly multi-byte character(s): */
66 void charstring_push_back_chars (charstring_t
, const char [], size_t, size_t);
67 void charstring_append (charstring_t
, const charstring_t
);
68 void charstring_append_cstring (charstring_t
, const char []);
69 void charstring_clear (charstring_t
);
70 /* Don't store return value of charstring_buffer() and use later after
71 intervening push_back's; use charstring_buffer_copy() instead. */
72 const char *charstring_buffer (const charstring_t
);
73 /* User is responsible for free'ing result of buffer copy. */
74 char *charstring_buffer_copy (const charstring_t
);
75 size_t charstring_bytes (const charstring_t
);
76 size_t charstring_chars (const charstring_t
);
77 /* Length of the last character in the charstring. */
78 int charstring_last_char_len (const charstring_t
);
81 * user context/profile structure
84 char *n_name
; /* key */
85 char *n_field
; /* value */
86 char n_context
; /* context, not profile */
87 struct node
*n_next
; /* next entry */
93 #define AMBIGSW (-2) /* from smatch() on ambiguous switch */
94 #define UNKWNSW (-1) /* from smatch() on unknown switch */
104 /* The minchars field is apparently used like this:
106 -# : Switch can be abbreviated to # characters; switch hidden in -help.
107 0 : Switch can't be abbreviated; switch shown in -help.
108 # : Switch can be abbreviated to # characters; switch shown in -help. */
112 * If we pick this switch, return this value from smatch
119 * Macros to use when declaring struct swit arrays.
121 * These macros use a technique known as X-Macros. In your source code you
122 * use them like this:
124 * #define FOO_SWITCHES \
125 * X("switch1", 0, SWITCHSW) \
126 * X("switch2", 0, SWITCH2SW) \
127 * X("thirdswitch", 2, SWITCH3SW) \
129 * The argument to each entry in FOO_SWITCHES are the switch name (sw),
130 * the minchars field (see above) and the return value for this switch.
131 * Note that the last entry in the above definition must either omit the
132 * continuation backslash, or be followed by a blank line. In the nmh
133 * code the style is to have every line include a backslash and follow
134 * the SWITCHES macro definition by a blank line.
136 * After you define FOO_SWITCHES, you instantiate it as follows:
138 * #define X(sw, minchars, id) id,
139 * DEFINE_SWITCH_ENUM(FOO);
142 * #define X(sw, minchars, id) { sw, minchars, id },
143 * DEFINE_SWITCH_ARRAY(FOO);
146 * DEFINE_SWITCH_ENUM defines an extra enum at the end of the list called
150 #define DEFINE_SWITCH_ENUM(name) \
156 #define DEFINE_SWITCH_ARRAY(name, array) \
157 static struct swit array[] = { \
162 extern struct swit anoyes
[]; /* standard yes/no switches */
165 * general folder attributes
167 #define READONLY (1<<0) /* No write access to folder */
168 #define SEQMOD (1<<1) /* folder's sequences modified */
169 #define ALLOW_NEW (1<<2) /* allow the "new" sequence */
170 #define OTHERS (1<<3) /* folder has other files */
172 #define FBITS "\020\01READONLY\02SEQMOD\03ALLOW_NEW\04OTHERS"
175 * first free slot for user defined sequences
181 * internal messages attributes (sequences)
183 #define EXISTS (0) /* exists */
184 #define SELECTED (1) /* selected for use */
185 #define SELECT_EMPTY (2) /* "new" message */
186 #define SELECT_UNSEEN (3) /* inc/show "unseen" */
188 #define MBITS "\020\01EXISTS\02SELECTED\03NEW\04UNSEEN"
191 * type for holding the sequence set of a message
193 typedef struct bvector
*bvector_t
;
195 bvector_t
bvector_create (size_t /* initial size in bits, can be 0 */);
196 void bvector_copy (bvector_t
, bvector_t
);
197 void bvector_free (bvector_t
);
198 void bvector_clear (bvector_t
, size_t);
199 void bvector_clear_all (bvector_t
);
200 void bvector_set (bvector_t
, size_t);
201 unsigned int bvector_at (bvector_t
, size_t);
202 unsigned long bvector_first_bits (bvector_t
);
204 typedef struct svector
*svector_t
;
206 svector_t
svector_create (size_t);
207 void svector_free (svector_t
);
208 char *svector_push_back (svector_t
, char *);
209 char *svector_at (svector_t
, size_t);
210 char **svector_find(svector_t
, const char *);
211 char **svector_strs (svector_t
);
212 size_t svector_size (svector_t
);
214 typedef struct ivector
*ivector_t
;
216 ivector_t
ivector_create (size_t);
217 void ivector_free (ivector_t
);
218 int ivector_push_back (ivector_t
, int);
219 int ivector_at (ivector_t
, size_t);
220 int *ivector_atp (ivector_t
, size_t);
223 * Primary structure of folder/message information
226 int lowmsg
; /* Lowest msg number */
227 int hghmsg
; /* Highest msg number */
228 int nummsg
; /* Actual Number of msgs */
230 int lowsel
; /* Lowest selected msg number */
231 int hghsel
; /* Highest selected msg number */
232 int numsel
; /* Number of msgs selected */
234 int curmsg
; /* Number of current msg if any */
236 int msgflags
; /* Folder attributes (READONLY, etc) */
237 char *foldpath
; /* Pathname of folder */
240 * Name of sequences in this folder.
245 * bit flags for whether sequence
246 * is public (0), or private (1)
251 * These represent the lowest and highest possible
252 * message numbers we can put in the message status
253 * area, without calling folder_realloc().
259 * This is an array of bvector_t which we allocate dynamically.
260 * Each bvector_t is a set of bits flags for a particular message.
261 * These bit flags represent general attributes such as
262 * EXISTS, SELECTED, etc. as well as track if message is
263 * in a particular sequence.
266 bvector_t
*msgstats
; /* msg status */
269 * A FILE handle containing an open filehandle for the sequence file
270 * for this folder. If non-NULL, use it when the sequence file is
276 * The name of the public sequence file; required by lkfclose()
282 * Amount of space to allocate for msgstats. Allocate
283 * the array to have space for messages numbered lo to hi.
284 * Use MSGSTATNUM to load mp->num_msgstats first.
286 #define MSGSTATNUM(lo, hi) ((size_t) ((hi) - (lo) + 1))
287 #define MSGSTATSIZE(mp) ((mp)->num_msgstats * sizeof *(mp)->msgstats)
290 * macros for message and sequence manipulation
292 #define msgstat(mp,n) (mp)->msgstats[(n) - mp->lowoff]
293 #define clear_msg_flags(mp,msgnum) bvector_clear_all (msgstat(mp, msgnum))
294 #define copy_msg_flags(mp,i,j) bvector_copy (msgstat(mp,i), msgstat(mp,j))
295 #define get_msg_flags(mp,ptr,msgnum) bvector_copy (ptr, msgstat(mp, msgnum))
296 #define set_msg_flags(mp,ptr,msgnum) bvector_copy (msgstat(mp, msgnum), ptr)
298 #define does_exist(mp,msgnum) bvector_at (msgstat(mp, msgnum), EXISTS)
299 #define unset_exists(mp,msgnum) bvector_clear (msgstat(mp, msgnum), EXISTS)
300 #define set_exists(mp,msgnum) bvector_set (msgstat(mp, msgnum), EXISTS)
302 #define is_selected(mp,msgnum) bvector_at (msgstat(mp, msgnum), SELECTED)
303 #define unset_selected(mp,msgnum) bvector_clear (msgstat(mp, msgnum), SELECTED)
304 #define set_selected(mp,msgnum) bvector_set (msgstat(mp, msgnum), SELECTED)
306 #define is_select_empty(mp,msgnum) \
307 bvector_at (msgstat(mp, msgnum), SELECT_EMPTY)
308 #define set_select_empty(mp,msgnum) \
309 bvector_set (msgstat(mp, msgnum), SELECT_EMPTY)
311 #define is_unseen(mp,msgnum) \
312 bvector_at (msgstat(mp, msgnum), SELECT_UNSEEN)
313 #define unset_unseen(mp,msgnum) \
314 bvector_clear (msgstat(mp, msgnum), SELECT_UNSEEN)
315 #define set_unseen(mp,msgnum) \
316 bvector_set (msgstat(mp, msgnum), SELECT_UNSEEN)
318 #define in_sequence(mp,seqnum,msgnum) \
319 bvector_at (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
320 #define clear_sequence(mp,seqnum,msgnum) \
321 bvector_clear (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
322 #define add_sequence(mp,seqnum,msgnum) \
323 bvector_set (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
325 #define is_seq_private(mp,seqnum) \
326 bvector_at (mp->attrstats, FFATTRSLOT + seqnum)
327 #define make_seq_public(mp,seqnum) \
328 bvector_clear (mp->attrstats, FFATTRSLOT + seqnum)
329 #define make_seq_private(mp,seqnum) \
330 bvector_set (mp->attrstats, FFATTRSLOT + seqnum)
331 #define make_all_public(mp) \
332 mp->attrstats = bvector_create(0); bvector_clear_all (mp->attrstats)
335 * macros for folder attributes
337 #define clear_folder_flags(mp) ((mp)->msgflags = 0)
339 #define is_readonly(mp) ((mp)->msgflags & READONLY)
340 #define set_readonly(mp) ((mp)->msgflags |= READONLY)
342 #define other_files(mp) ((mp)->msgflags & OTHERS)
343 #define set_other_files(mp) ((mp)->msgflags |= OTHERS)
345 #define NULLMP ((struct msgs *) 0)
348 * m_getfld() message parsing
351 #define NAMESZ 999 /* Limit on component name size.
352 RFC 2822 limits line lengths to
353 998 characters, so a header name
354 can be at most that long.
355 m_getfld limits header names to 2
356 less than NAMESZ, which is fine,
357 because header names must be
358 followed by a colon. Add one for
361 #define LENERR (-2) /* Name too long error from getfld */
362 #define FMTERR (-3) /* Message Format error */
363 #define FLD 0 /* Field returned */
364 #define FLDPLUS 1 /* Field returned with more to come */
365 #define BODY 3 /* Body returned with more to come */
366 #define FILEEOF 5 /* Reached end of input file */
368 typedef struct m_getfld_state
*m_getfld_state_t
;
373 #define MS_DEFAULT 0 /* default (one msg per file) */
374 #define MS_UNKNOWN 1 /* type not known yet */
375 #define MS_MBOX 2 /* Unix-style "from" lines */
376 #define MS_MMDF 3 /* string mmdlm2 */
378 #define NOUSE 0 /* draft being re-used */
380 #define TFOLDER 0 /* path() given a +folder */
381 #define TFILE 1 /* path() given a file */
382 #define TSUBCWF 2 /* path() given a @folder */
384 #define OUTPUTLINELEN 72 /* default line length for headers */
386 #define LINK "@" /* Name of link to file to which you are */
390 * credentials management
392 typedef struct nmh_creds
*nmh_creds_t
;
395 * miscellaneous macros
397 #define pidXwait(pid,cp) pidstatus (pidwait (pid, NOTOK), stdout, cp)
400 # define max(a,b) ((a) > (b) ? (a) : (b))
404 # define min(a,b) ((a) < (b) ? (a) : (b))
408 # define abs(a) ((a) > 0 ? (a) : -(a))
414 #define CTXMOD 0x01 /* context information modified */
415 #define DBITS "\020\01CTXMOD"
416 extern char ctxflags
;
418 extern char *invo_name
; /* command invocation name */
419 extern char *mypath
; /* user's $HOME */
420 extern char *defpath
; /* pathname of user's profile */
421 extern char *ctxpath
; /* pathname of user's context */
422 extern struct node
*m_defs
; /* list of profile/context entries */
424 /* What style to use for generated Message-ID and Content-ID header
425 fields. The localname style is pid.time@localname, where time is
426 in seconds. The random style replaces the localname with some
427 (pseudo)random bytes and uses microsecond-resolution time. */
428 int save_message_id_style (const char *);
429 char *message_id (time_t, int);
432 * These standard strings are defined in config.c. They are the
433 * only system-dependent parameters in nmh, and thus by redefining
434 * their values and reloading the various modules, nmh will run
437 extern char *buildmimeproc
;
438 extern char *catproc
;
439 extern char *components
;
440 extern char *context
;
441 extern char *current
;
442 extern char *credentials_file
;
443 extern int credentials_no_perm_check
;
444 extern char *defaultfolder
;
445 extern char *digestcomps
;
446 extern char *distcomps
;
448 extern char *fileproc
;
449 extern char *foldprot
;
450 extern char *formatproc
;
451 extern char *forwcomps
;
453 extern char *incproc
;
455 extern char *mailproc
;
456 extern char *mh_defaults
;
457 extern char *mh_profile
;
459 extern char *mhlformat
;
460 extern char *mhlforward
;
461 extern char *mhlproc
;
462 extern char *mhlreply
;
463 extern char *moreproc
;
464 extern char *msgprot
;
465 extern char *nmhaccessftp
;
466 extern char *nmhaccessurl
;
467 extern char *nmhstorage
;
468 extern char *nmhcache
;
469 extern char *nmhprivcache
;
470 extern char *nsequence
;
471 extern char *packproc
;
472 extern char *postproc
;
473 extern char *pfolder
;
474 extern char *psequence
;
475 extern char *rcvdistcomps
;
476 extern char *rcvstoreproc
;
477 extern char *replcomps
;
478 extern char *replgroupcomps
;
479 extern char *rmmproc
;
480 extern char *sendproc
;
481 extern char *showmimeproc
;
482 extern char *showproc
;
483 extern char *usequence
;
484 extern char *user_agent
;
485 extern char *version_num
;
486 extern char *version_str
;
487 extern char *whatnowproc
;
488 extern char *whomproc
;
490 extern void (*done
) (int) NORETURN
;
492 #include <h/prototypes.h>