]>
diplodocus.org Git - nmh/blob - h/mh.h
3 * mh.h -- main header file for all of nmh
11 #define NOTOK (-1) /* syscall()s return this on error */
12 #define OK 0 /* ditto on success */
13 #define DONE 1 /* trinary logic */
15 #define Nbby 8 /* number of bits/byte */
17 #define MAXARGS 1000 /* max arguments to exec */
18 #define NFOLDERS 1000 /* max folder arguments on command line */
19 #define DMAXFOLDER 4 /* typical number of digits */
20 #define MAXFOLDER 1000 /* message increment */
28 typedef unsigned char boolean
; /* not int so we can pack in a structure */
30 /* If we're using gcc then give it some information about
31 * functions that abort.
34 #define NORETURN __attribute__((__noreturn__))
35 #define NMH_UNUSED(i) (void) i
38 #define NMH_UNUSED(i) i
42 * user context/profile structure
45 char *n_name
; /* key */
46 char *n_field
; /* value */
47 char n_context
; /* context, not profile */
48 struct node
*n_next
; /* next entry */
54 #define AMBIGSW (-2) /* from smatch() on ambiguous switch */
55 #define UNKWNSW (-1) /* from smatch() on unknown switch */
65 /* The minchars field is apparently used like this:
67 -# : Switch can be abbreviated to # characters; switch hidden in -help.
68 0 : Switch can't be abbreviated; switch shown in -help.
69 # : Switch can be abbreviated to # characters; switch shown in -help. */
73 * If we pick this switch, return this value from smatch
80 * Macros to use when declaring struct swit arrays.
82 * These macros are what known as X-Macros. In your source code you
85 * #define FOO_SWITCHES \
86 * X("switch1", 0, SWITCHSW) \
87 * X("switch2", 0, SWITCH2SW) \
88 * X("thirdswitch", 2, SWITCH3SW) \
90 * The argument to each entry in FOO_SWITCHES are the switch name (sw),
91 * the minchars field (see above) and the return value for this switch.
93 * After you define FOO_SWITCHES, you instantiate it as follows:
95 * #define X(sw, minchars, id) id,
96 * DEFINE_SWITCH_ENUM(FOO);
99 * #define X(sw, minchars, id) { sw, minchars, id },
100 * DEFINE_SWITCH_ARRAY(FOO);
103 * DEFINE_SWITCH_ENUM defines an extra enum at the end of the list called
107 #define DEFINE_SWITCH_ENUM(name) \
113 #define DEFINE_SWITCH_ARRAY(name, array) \
114 static struct swit array[] = { \
119 extern struct swit anoyes
[]; /* standard yes/no switches */
121 #define ATTACHFORMATS 3 /* Number of send attach formats. */
124 * general folder attributes
126 #define READONLY (1<<0) /* No write access to folder */
127 #define SEQMOD (1<<1) /* folder's sequences modifed */
128 #define ALLOW_NEW (1<<2) /* allow the "new" sequence */
129 #define OTHERS (1<<3) /* folder has other files */
130 #define MODIFIED (1<<4) /* msh in-core folder modified */
132 #define FBITS "\020\01READONLY\02SEQMOD\03ALLOW_NEW\04OTHERS\05MODIFIED"
135 * type for holding the sequence set of a message
137 typedef unsigned long seqset_t
;
140 * first free slot for user defined sequences
146 * Determine the number of user defined sequences we
147 * can have. The first FFATTRSLOT sequence flags are for
148 * internal nmh message flags.
150 #define NUMATTRS ((sizeof(seqset_t) * Nbby) - FFATTRSLOT)
153 * internal messages attributes (sequences)
155 #define EXISTS (1<<0) /* exists */
156 #define DELETED (1<<1) /* deleted */
157 #define SELECTED (1<<2) /* selected for use */
158 #define SELECT_EMPTY (1<<3) /* "new" message */
159 #define SELECT_UNSEEN (1<<4) /* inc/show "unseen" */
161 #define MBITS "\020\01EXISTS\02DELETED\03SELECTED\04NEW\05UNSEEN"
164 * Primary structure of folder/message information
167 int lowmsg
; /* Lowest msg number */
168 int hghmsg
; /* Highest msg number */
169 int nummsg
; /* Actual Number of msgs */
171 int lowsel
; /* Lowest selected msg number */
172 int hghsel
; /* Highest selected msg number */
173 int numsel
; /* Number of msgs selected */
175 int curmsg
; /* Number of current msg if any */
177 int msgflags
; /* Folder attributes (READONLY, etc) */
178 char *foldpath
; /* Pathname of folder */
181 * Name of sequences in this folder. We add an
182 * extra slot, so we can NULL terminate the list.
184 char *msgattrs
[NUMATTRS
+ 1];
187 * bit flags for whether sequence
188 * is public (0), or private (1)
193 * These represent the lowest and highest possible
194 * message numbers we can put in the message status
195 * area, without calling folder_realloc().
201 * This is an array of seqset_t which we allocate dynamically.
202 * Each seqset_t is a set of bits flags for a particular message.
203 * These bit flags represent general attributes such as
204 * EXISTS, SELECTED, etc. as well as track if message is
205 * in a particular sequence.
207 seqset_t
*msgstats
; /* msg status */
210 * A FILE handle containing an open filehandle for the sequence file
211 * for this folder. If non-NULL, use it when the sequence file is
217 * The name of the public sequence file; required by lkfclose()
223 * Amount of space to allocate for msgstats. Allocate
224 * the array to have space for messages numbers lo to hi.
226 #define MSGSTATSIZE(mp,lo,hi) ((size_t) (((hi) - (lo) + 1) * sizeof(*(mp)->msgstats)))
229 * macros for message and sequence manipulation
231 #define clear_msg_flags(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] = 0)
232 #define copy_msg_flags(mp,i,j) \
233 ((mp)->msgstats[(i) - mp->lowoff] = (mp)->msgstats[(j) - mp->lowoff])
234 #define get_msg_flags(mp,ptr,msgnum) (*(ptr) = (mp)->msgstats[(msgnum) - mp->lowoff])
235 #define set_msg_flags(mp,ptr,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] = *(ptr))
237 #define does_exist(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & EXISTS)
238 #define unset_exists(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~EXISTS)
239 #define set_exists(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= EXISTS)
241 #define is_selected(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECTED)
242 #define unset_selected(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~SELECTED)
243 #define set_selected(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECTED)
245 #define is_select_empty(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECT_EMPTY)
246 #define set_select_empty(mp,msgnum) \
247 ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECT_EMPTY)
249 #define is_unseen(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECT_UNSEEN)
250 #define unset_unseen(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~SELECT_UNSEEN)
251 #define set_unseen(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECT_UNSEEN)
254 #define set_deleted(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] |= DELETED)
256 #define in_sequence(mp,seqnum,msgnum) \
257 ((mp)->msgstats[(msgnum) - mp->lowoff] & ((seqset_t)1 << (FFATTRSLOT + seqnum)))
258 #define clear_sequence(mp,seqnum,msgnum) \
259 ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~((seqset_t)1 << (FFATTRSLOT + seqnum)))
260 #define add_sequence(mp,seqnum,msgnum) \
261 ((mp)->msgstats[(msgnum) - mp->lowoff] |= ((seqset_t)1 << (FFATTRSLOT + seqnum)))
263 #define is_seq_private(mp,seqnum) \
264 ((mp)->attrstats & ((seqset_t)1 << (FFATTRSLOT + seqnum)))
265 #define make_seq_public(mp,seqnum) \
266 ((mp)->attrstats &= ~((seqset_t)1 << (FFATTRSLOT + seqnum)))
267 #define make_seq_private(mp,seqnum) \
268 ((mp)->attrstats |= ((seqset_t)1 << (FFATTRSLOT + seqnum)))
269 #define make_all_public(mp) \
270 ((mp)->attrstats = 0)
273 * macros for folder attributes
275 #define clear_folder_flags(mp) ((mp)->msgflags = 0)
277 #define is_readonly(mp) ((mp)->msgflags & READONLY)
278 #define set_readonly(mp) ((mp)->msgflags |= READONLY)
280 #define other_files(mp) ((mp)->msgflags & OTHERS)
281 #define set_other_files(mp) ((mp)->msgflags |= OTHERS)
283 #define NULLMP ((struct msgs *) 0)
286 * m_getfld() message parsing
289 #define NAMESZ 999 /* Limit on component name size.
290 RFC 2822 limits line lengths to
291 998 characters, so a header name
292 can be at most that long.
293 m_getfld limits header names to 2
294 less than NAMESZ, which is fine,
295 because header names must be
296 followed by a colon. Add one for
299 #define LENERR (-2) /* Name too long error from getfld */
300 #define FMTERR (-3) /* Message Format error */
301 #define FLD 0 /* Field returned */
302 #define FLDPLUS 1 /* Field returned with more to come */
303 #define BODY 3 /* Body returned with more to come */
304 #define FILEEOF 5 /* Reached end of input file */
306 struct m_getfld_state
;
307 typedef struct m_getfld_state
*m_getfld_state_t
;
312 #define MS_DEFAULT 0 /* default (one msg per file) */
313 #define MS_UNKNOWN 1 /* type not known yet */
314 #define MS_MBOX 2 /* Unix-style "from" lines */
315 #define MS_MMDF 3 /* string mmdlm2 */
316 #define MS_MSH 4 /* whacko msh */
318 #define NOUSE 0 /* draft being re-used */
320 #define TFOLDER 0 /* path() given a +folder */
321 #define TFILE 1 /* path() given a file */
322 #define TSUBCWF 2 /* path() given a @folder */
324 #define OUTPUTLINELEN 72 /* default line length for headers */
326 #define LINK "@" /* Name of link to file to which you are */
329 #define NMH_ATTACH_HEADER "Nmh-Attachment" /* Default header for -attach */
332 * miscellaneous macros
334 #define pidXwait(pid,cp) pidstatus (pidwait (pid, NOTOK), stdout, cp)
337 # define max(a,b) ((a) > (b) ? (a) : (b))
341 # define min(a,b) ((a) < (b) ? (a) : (b))
345 # define abs(a) ((a) > 0 ? (a) : -(a))
351 #define CTXMOD 0x01 /* context information modified */
352 #define DBITS "\020\01CTXMOD"
353 extern char ctxflags
;
355 extern char *invo_name
; /* command invocation name */
356 extern char *mypath
; /* user's $HOME */
357 extern char *defpath
; /* pathname of user's profile */
358 extern char *ctxpath
; /* pathname of user's context */
359 extern struct node
*m_defs
; /* list of profile/context entries */
361 /* What style to use for generated Message-ID and Content-ID header
362 fields. The localname style is pid.time@localname, where time is
363 in seconds. The random style replaces the localname with some
364 (pseudo)random bytes and uses microsecond-resolution time. */
365 int save_message_id_style (const char *);
366 char *message_id (time_t, int);
369 * These standard strings are defined in config.c. They are the
370 * only system-dependent parameters in nmh, and thus by redefining
371 * their values and reloading the various modules, nmh will run
374 extern char *buildmimeproc
;
375 extern char *catproc
;
376 extern char *components
;
377 extern char *context
;
378 extern char *current
;
379 extern char *defaultfolder
;
380 extern char *digestcomps
;
381 extern char *distcomps
;
383 extern char *fileproc
;
384 extern char *foldprot
;
385 extern char *formatproc
;
386 extern char *forwcomps
;
388 extern char *incproc
;
390 extern char *mailproc
;
391 extern char *mh_defaults
;
392 extern char *mh_profile
;
394 extern char *mhlformat
;
395 extern char *mhlforward
;
396 extern char *mhlproc
;
397 extern char *mhlreply
;
398 extern char *moreproc
;
399 extern char *msgprot
;
400 extern char *mshproc
;
401 extern char *nmhaccessftp
;
402 extern char *nmhaccessurl
;
403 extern char *nmhstorage
;
404 extern char *nmhcache
;
405 extern char *nmhprivcache
;
406 extern char *nsequence
;
407 extern char *packproc
;
408 extern char *postproc
;
409 extern char *pfolder
;
410 extern char *psequence
;
411 extern char *rcvdistcomps
;
412 extern char *rcvstoreproc
;
413 extern char *replcomps
;
414 extern char *replgroupcomps
;
415 extern char *rmmproc
;
416 extern char *sendproc
;
417 extern char *showmimeproc
;
418 extern char *showproc
;
419 extern char *usequence
;
420 extern char *version_num
;
421 extern char *version_str
;
422 extern char *vmhproc
;
423 extern char *whatnowproc
;
424 extern char *whomproc
;
426 extern void (*done
) (int) NORETURN
;
428 #include <h/prototypes.h>