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 */
13 #define Nbby 8 /* number of bits/byte */
15 #define MAXARGS 1000 /* max arguments to exec */
16 #define NFOLDERS 1000 /* max folder arguments on command line */
17 #define DMAXFOLDER 4 /* typical number of digits */
18 #define MAXFOLDER 1000 /* message increment */
21 * This macro is for use by scan, for example, so that platforms with
22 * a small BUFSIZ can easily allocate larger buffers.
24 #define NMH_BUFSIZ (BUFSIZ>=8192 ? BUFSIZ : 8192)
32 typedef unsigned char boolean
; /* not int so we can pack in a structure */
34 /* If we're using gcc then give it some information about
35 * functions that abort.
38 #define NORETURN __attribute__((__noreturn__))
39 #define NMH_UNUSED(i) (void) i
42 #define NMH_UNUSED(i) i
45 /* DIM gives the number of elements in the one-dimensional array a. */
46 #define DIM(a) (sizeof (a) / sizeof (*(a)))
48 /* LEN gives the strlen() of string constant s, excluding the
50 #define LEN(s) (sizeof (s) - 1)
53 * char array that keeps track of size in both bytes and characters
55 * Don't store return value of charstring_buffer() and use later
56 * after intervening push_back's; use charstring_buffer_copy()
59 typedef struct charstring
*charstring_t
;
61 charstring_t
charstring_create (size_t);
62 charstring_t
charstring_copy (const charstring_t
);
63 void charstring_free (charstring_t
);
64 /* Append a single-byte character: */
65 void charstring_push_back (charstring_t
, const char);
66 /* Append possibly multi-byte character(s): */
67 void charstring_push_back_chars (charstring_t
, const char [], size_t, size_t);
68 void charstring_append (charstring_t
, const charstring_t
);
69 void charstring_append_cstring (charstring_t
, const char []);
70 void charstring_clear (charstring_t
);
71 /* Don't store return value of charstring_buffer() and use later after
72 intervening push_back's; use charstring_buffer_copy() instead. */
73 const char *charstring_buffer (const charstring_t
);
74 /* User is responsible for free'ing result of buffer copy. */
75 char *charstring_buffer_copy (const charstring_t
);
76 size_t charstring_bytes (const charstring_t
);
77 size_t charstring_chars (const charstring_t
);
78 /* Length of the last character in the charstring. */
79 int charstring_last_char_len (const charstring_t
);
82 * user context/profile structure
85 char *n_name
; /* key */
86 char *n_field
; /* value */
87 char n_context
; /* context, not profile */
88 struct node
*n_next
; /* next entry */
94 #define AMBIGSW (-2) /* from smatch() on ambiguous switch */
95 #define UNKWNSW (-1) /* from smatch() on unknown switch */
105 /* The minchars field is apparently used like this:
107 -# : Switch can be abbreviated to # characters; switch hidden in -help.
108 0 : Switch can't be abbreviated; switch shown in -help.
109 # : Switch can be abbreviated to # characters; switch shown in -help. */
113 * If we pick this switch, return this value from smatch
120 * Macros to use when declaring struct swit arrays.
122 * These macros use a technique known as X-Macros. In your source code you
123 * use them like this:
125 * #define FOO_SWITCHES \
126 * X("switch1", 0, SWITCHSW) \
127 * X("switch2", 0, SWITCH2SW) \
128 * X("thirdswitch", 2, SWITCH3SW) \
130 * The argument to each entry in FOO_SWITCHES are the switch name (sw),
131 * the minchars field (see above) and the return value for this switch.
132 * Note that the last entry in the above definition must either omit the
133 * continuation backslash, or be followed by a blank line. In the nmh
134 * code the style is to have every line include a backslash and follow
135 * the SWITCHES macro definition by a blank line.
137 * After you define FOO_SWITCHES, you instantiate it as follows:
139 * #define X(sw, minchars, id) id,
140 * DEFINE_SWITCH_ENUM(FOO);
143 * #define X(sw, minchars, id) { sw, minchars, id },
144 * DEFINE_SWITCH_ARRAY(FOO);
147 * DEFINE_SWITCH_ENUM defines an extra enum at the end of the list called
151 #define DEFINE_SWITCH_ENUM(name) \
157 #define DEFINE_SWITCH_ARRAY(name, array) \
158 static struct swit array[] = { \
163 extern struct swit anoyes
[]; /* standard yes/no switches */
166 * general folder attributes
168 #define READONLY (1<<0) /* No write access to folder */
169 #define SEQMOD (1<<1) /* folder's sequences modified */
170 #define ALLOW_NEW (1<<2) /* allow the "new" sequence */
171 #define OTHERS (1<<3) /* folder has other files */
172 #define MODIFIED (1<<4) /* msh in-core folder modified */
174 #define FBITS "\020\01READONLY\02SEQMOD\03ALLOW_NEW\04OTHERS\05MODIFIED"
177 * first free slot for user defined sequences
183 * internal messages attributes (sequences)
185 #define EXISTS (0) /* exists */
186 #define DELETED (1) /* deleted */
187 #define SELECTED (2) /* selected for use */
188 #define SELECT_EMPTY (3) /* "new" message */
189 #define SELECT_UNSEEN (4) /* inc/show "unseen" */
191 #define MBITS "\020\01EXISTS\02DELETED\03SELECTED\04NEW\05UNSEEN"
194 * type for holding the sequence set of a message
196 typedef struct bvector
*bvector_t
;
198 bvector_t
bvector_create (size_t /* initial size in bits, can be 0 */);
199 void bvector_copy (bvector_t
, bvector_t
);
200 void bvector_free (bvector_t
);
201 void bvector_clear (bvector_t
, size_t);
202 void bvector_clear_all (bvector_t
);
203 void bvector_set (bvector_t
, size_t);
204 unsigned int bvector_at (bvector_t
, size_t);
205 const unsigned long *bvector_bits (bvector_t
);
206 size_t bvector_maxsize (bvector_t
);
208 typedef struct svector
*svector_t
;
210 svector_t
svector_create (size_t);
211 void svector_free (svector_t
);
212 char *svector_push_back (svector_t
, char *);
213 char *svector_at (svector_t
, size_t);
214 char **svector_find(svector_t
, const char *);
215 char **svector_strs (svector_t
);
216 size_t svector_size (svector_t
);
218 typedef struct ivector
*ivector_t
;
220 ivector_t
ivector_create (size_t);
221 void ivector_free (ivector_t
);
222 int ivector_push_back (ivector_t
, int);
223 int ivector_at (ivector_t
, size_t);
224 int *ivector_atp (ivector_t
, size_t);
225 size_t ivector_size (ivector_t
);
228 * Primary structure of folder/message information
231 int lowmsg
; /* Lowest msg number */
232 int hghmsg
; /* Highest msg number */
233 int nummsg
; /* Actual Number of msgs */
235 int lowsel
; /* Lowest selected msg number */
236 int hghsel
; /* Highest selected msg number */
237 int numsel
; /* Number of msgs selected */
239 int curmsg
; /* Number of current msg if any */
241 int msgflags
; /* Folder attributes (READONLY, etc) */
242 char *foldpath
; /* Pathname of folder */
245 * Name of sequences in this folder.
250 * bit flags for whether sequence
251 * is public (0), or private (1)
256 * These represent the lowest and highest possible
257 * message numbers we can put in the message status
258 * area, without calling folder_realloc().
264 * This is an array of bvector_t which we allocate dynamically.
265 * Each bvector_t is a set of bits flags for a particular message.
266 * These bit flags represent general attributes such as
267 * EXISTS, SELECTED, etc. as well as track if message is
268 * in a particular sequence.
271 bvector_t
*msgstats
; /* msg status */
274 * A FILE handle containing an open filehandle for the sequence file
275 * for this folder. If non-NULL, use it when the sequence file is
281 * The name of the public sequence file; required by lkfclose()
287 * Amount of space to allocate for msgstats. Allocate
288 * the array to have space for messages numbered lo to hi.
289 * Use MSGSTATNUM to load mp->num_msgstats first.
291 #define MSGSTATNUM(lo, hi) ((size_t) ((hi) - (lo) + 1))
292 #define MSGSTATSIZE(mp) ((mp)->num_msgstats * sizeof *(mp)->msgstats)
295 * macros for message and sequence manipulation
297 #define msgstat(mp,n) (mp)->msgstats[(n) - mp->lowoff]
298 #define clear_msg_flags(mp,msgnum) bvector_clear_all (msgstat(mp, msgnum))
299 #define copy_msg_flags(mp,i,j) bvector_copy (msgstat(mp,i), msgstat(mp,j))
300 #define get_msg_flags(mp,ptr,msgnum) bvector_copy (ptr, msgstat(mp, msgnum))
301 #define set_msg_flags(mp,ptr,msgnum) bvector_copy (msgstat(mp, msgnum), ptr)
303 #define does_exist(mp,msgnum) bvector_at (msgstat(mp, msgnum), EXISTS)
304 #define unset_exists(mp,msgnum) bvector_clear (msgstat(mp, msgnum), EXISTS)
305 #define set_exists(mp,msgnum) bvector_set (msgstat(mp, msgnum), EXISTS)
307 #define is_selected(mp,msgnum) bvector_at (msgstat(mp, msgnum), SELECTED)
308 #define unset_selected(mp,msgnum) bvector_clear (msgstat(mp, msgnum), SELECTED)
309 #define set_selected(mp,msgnum) bvector_set (msgstat(mp, msgnum), SELECTED)
311 #define is_select_empty(mp,msgnum) \
312 bvector_at (msgstat(mp, msgnum), SELECT_EMPTY)
313 #define set_select_empty(mp,msgnum) \
314 bvector_set (msgstat(mp, msgnum), SELECT_EMPTY)
316 #define is_unseen(mp,msgnum) \
317 bvector_at (msgstat(mp, msgnum), SELECT_UNSEEN)
318 #define unset_unseen(mp,msgnum) \
319 bvector_clear (msgstat(mp, msgnum), SELECT_UNSEEN)
320 #define set_unseen(mp,msgnum) \
321 bvector_set (msgstat(mp, msgnum), SELECT_UNSEEN)
323 #define in_sequence(mp,seqnum,msgnum) \
324 bvector_at (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
325 #define clear_sequence(mp,seqnum,msgnum) \
326 bvector_clear (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
327 #define add_sequence(mp,seqnum,msgnum) \
328 bvector_set (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
330 #define is_seq_private(mp,seqnum) \
331 bvector_at (mp->attrstats, FFATTRSLOT + seqnum)
332 #define make_seq_public(mp,seqnum) \
333 bvector_clear (mp->attrstats, FFATTRSLOT + seqnum)
334 #define make_seq_private(mp,seqnum) \
335 bvector_set (mp->attrstats, FFATTRSLOT + seqnum)
336 #define make_all_public(mp) \
337 mp->attrstats = bvector_create(0); bvector_clear_all (mp->attrstats)
340 * macros for folder attributes
342 #define clear_folder_flags(mp) ((mp)->msgflags = 0)
344 #define is_readonly(mp) ((mp)->msgflags & READONLY)
345 #define set_readonly(mp) ((mp)->msgflags |= READONLY)
347 #define other_files(mp) ((mp)->msgflags & OTHERS)
348 #define set_other_files(mp) ((mp)->msgflags |= OTHERS)
350 #define NULLMP ((struct msgs *) 0)
353 * m_getfld() message parsing
356 #define NAMESZ 999 /* Limit on component name size.
357 RFC 2822 limits line lengths to
358 998 characters, so a header name
359 can be at most that long.
360 m_getfld limits header names to 2
361 less than NAMESZ, which is fine,
362 because header names must be
363 followed by a colon. Add one for
366 #define LENERR (-2) /* Name too long error from getfld */
367 #define FMTERR (-3) /* Message Format error */
368 #define FLD 0 /* Field returned */
369 #define FLDPLUS 1 /* Field returned with more to come */
370 #define BODY 3 /* Body returned with more to come */
371 #define FILEEOF 5 /* Reached end of input file */
373 struct m_getfld_state
;
374 typedef struct m_getfld_state
*m_getfld_state_t
;
379 #define MS_DEFAULT 0 /* default (one msg per file) */
380 #define MS_UNKNOWN 1 /* type not known yet */
381 #define MS_MBOX 2 /* Unix-style "from" lines */
382 #define MS_MMDF 3 /* string mmdlm2 */
384 #define NOUSE 0 /* draft being re-used */
386 #define TFOLDER 0 /* path() given a +folder */
387 #define TFILE 1 /* path() given a file */
388 #define TSUBCWF 2 /* path() given a @folder */
390 #define OUTPUTLINELEN 72 /* default line length for headers */
392 #define LINK "@" /* Name of link to file to which you are */
396 * credentials management
399 typedef struct nmh_creds
*nmh_creds_t
;
402 * miscellaneous macros
404 #define pidXwait(pid,cp) pidstatus (pidwait (pid, NOTOK), stdout, cp)
407 # define max(a,b) ((a) > (b) ? (a) : (b))
411 # define min(a,b) ((a) < (b) ? (a) : (b))
415 # define abs(a) ((a) > 0 ? (a) : -(a))
421 #define CTXMOD 0x01 /* context information modified */
422 #define DBITS "\020\01CTXMOD"
423 extern char ctxflags
;
425 extern char *invo_name
; /* command invocation name */
426 extern char *mypath
; /* user's $HOME */
427 extern char *defpath
; /* pathname of user's profile */
428 extern char *ctxpath
; /* pathname of user's context */
429 extern struct node
*m_defs
; /* list of profile/context entries */
431 /* What style to use for generated Message-ID and Content-ID header
432 fields. The localname style is pid.time@localname, where time is
433 in seconds. The random style replaces the localname with some
434 (pseudo)random bytes and uses microsecond-resolution time. */
435 int save_message_id_style (const char *);
436 char *message_id (time_t, int);
439 * These standard strings are defined in config.c. They are the
440 * only system-dependent parameters in nmh, and thus by redefining
441 * their values and reloading the various modules, nmh will run
444 extern char *buildmimeproc
;
445 extern char *catproc
;
446 extern char *components
;
447 extern char *context
;
448 extern char *current
;
449 extern char *credentials_file
;
450 extern int credentials_no_perm_check
;
451 extern char *defaultfolder
;
452 extern char *digestcomps
;
453 extern char *distcomps
;
455 extern char *fileproc
;
456 extern char *foldprot
;
457 extern char *formatproc
;
458 extern char *forwcomps
;
460 extern char *incproc
;
462 extern char *mailproc
;
463 extern char *mh_defaults
;
464 extern char *mh_profile
;
466 extern char *mhlformat
;
467 extern char *mhlforward
;
468 extern char *mhlproc
;
469 extern char *mhlreply
;
470 extern char *moreproc
;
471 extern char *msgprot
;
472 extern char *nmhaccessftp
;
473 extern char *nmhaccessurl
;
474 extern char *nmhstorage
;
475 extern char *nmhcache
;
476 extern char *nmhprivcache
;
477 extern char *nsequence
;
478 extern char *packproc
;
479 extern char *postproc
;
480 extern char *pfolder
;
481 extern char *psequence
;
482 extern char *rcvdistcomps
;
483 extern char *rcvstoreproc
;
484 extern char *replcomps
;
485 extern char *replgroupcomps
;
486 extern char *rmmproc
;
487 extern char *sendproc
;
488 extern char *showmimeproc
;
489 extern char *showproc
;
490 extern char *usequence
;
491 extern char *user_agent
;
492 extern char *version_num
;
493 extern char *version_str
;
494 extern char *whatnowproc
;
495 extern char *whomproc
;
497 extern void (*done
) (int) NORETURN
;
499 #include <h/prototypes.h>