]> diplodocus.org Git - nmh/blob - h/mh.h
uip/sortm.c: Remove unused variable and dlocaltimenow() call.
[nmh] / h / mh.h
1 /* mh.h -- main header file for all of nmh
2 */
3
4 #include <h/nmh.h>
5
6 /*
7 * Well-used constants
8 */
9 #define NOTOK (-1) /* syscall()s return this on error */
10 #define OK 0 /* ditto on success */
11 #define DONE 1 /* trinary logic */
12 #define ALL ""
13 #define Nbby 8 /* number of bits/byte */
14
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 */
19
20 /*
21 * This macro is for use by scan, for example, so that platforms with
22 * a small BUFSIZ can easily allocate larger buffers.
23 */
24 #define NMH_BUFSIZ (BUFSIZ>=8192 ? BUFSIZ : 8192)
25
26 #ifndef FALSE
27 #define FALSE false
28 #endif
29 #ifndef TRUE
30 #define TRUE true
31 #endif
32 typedef unsigned char boolean; /* not int so we can pack in a structure */
33
34 /* If we're using gcc then give it some information about
35 * functions that abort.
36 */
37 #if __GNUC__ > 2
38 #define NORETURN __attribute__((__noreturn__))
39 #define NMH_UNUSED(i) (void) i
40 #else
41 #define NORETURN
42 #define NMH_UNUSED(i) i
43 #endif
44
45 /* DIM gives the number of elements in the one-dimensional array a. */
46 #define DIM(a) (sizeof (a) / sizeof (*(a)))
47
48 /* LEN gives the strlen() of string constant s, excluding the
49 * terminating NUL. */
50 #define LEN(s) (sizeof (s) - 1)
51
52 /*
53 * char array that keeps track of size in both bytes and characters
54 * Usage note:
55 * Don't store return value of charstring_buffer() and use later
56 * after intervening push_back's; use charstring_buffer_copy()
57 * instead.
58 */
59 typedef struct charstring *charstring_t;
60
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);
80
81 /*
82 * user context/profile structure
83 */
84 struct node {
85 char *n_name; /* key */
86 char *n_field; /* value */
87 char n_context; /* context, not profile */
88 struct node *n_next; /* next entry */
89 };
90
91 /*
92 * switches structure
93 */
94 #define AMBIGSW (-2) /* from smatch() on ambiguous switch */
95 #define UNKWNSW (-1) /* from smatch() on unknown switch */
96
97 struct swit {
98
99 /*
100 * Switch name
101 */
102
103 char *sw;
104
105 /* The minchars field is apparently used like this:
106
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. */
110 int minchars;
111
112 /*
113 * If we pick this switch, return this value from smatch
114 */
115
116 int swret;
117 };
118
119 /*
120 * Macros to use when declaring struct swit arrays.
121 *
122 * These macros use a technique known as X-Macros. In your source code you
123 * use them like this:
124 *
125 * #define FOO_SWITCHES \
126 * X("switch1", 0, SWITCHSW) \
127 * X("switch2", 0, SWITCH2SW) \
128 * X("thirdswitch", 2, SWITCH3SW) \
129 *
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.
136 *
137 * After you define FOO_SWITCHES, you instantiate it as follows:
138 *
139 * #define X(sw, minchars, id) id,
140 * DEFINE_SWITCH_ENUM(FOO);
141 * #undef X
142 *
143 * #define X(sw, minchars, id) { sw, minchars, id },
144 * DEFINE_SWITCH_ARRAY(FOO);
145 * #undef X
146 *
147 * DEFINE_SWITCH_ENUM defines an extra enum at the end of the list called
148 * LEN_FOO.
149 */
150
151 #define DEFINE_SWITCH_ENUM(name) \
152 enum { \
153 name ## _SWITCHES \
154 LEN_ ## name \
155 }
156
157 #define DEFINE_SWITCH_ARRAY(name, array) \
158 static struct swit array[] = { \
159 name ## _SWITCHES \
160 { NULL, 0, 0 } \
161 }
162
163 extern struct swit anoyes[]; /* standard yes/no switches */
164
165 /*
166 * general folder attributes
167 */
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 */
173
174 #define FBITS "\020\01READONLY\02SEQMOD\03ALLOW_NEW\04OTHERS\05MODIFIED"
175
176 /*
177 * first free slot for user defined sequences
178 * and attributes
179 */
180 #define FFATTRSLOT 5
181
182 /*
183 * internal messages attributes (sequences)
184 */
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" */
190
191 #define MBITS "\020\01EXISTS\02DELETED\03SELECTED\04NEW\05UNSEEN"
192
193 /*
194 * type for holding the sequence set of a message
195 */
196 typedef struct bvector *bvector_t;
197
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);
207
208 typedef struct svector *svector_t;
209
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);
217
218 typedef struct ivector *ivector_t;
219
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);
226
227 /*
228 * Primary structure of folder/message information
229 */
230 struct msgs {
231 int lowmsg; /* Lowest msg number */
232 int hghmsg; /* Highest msg number */
233 int nummsg; /* Actual Number of msgs */
234
235 int lowsel; /* Lowest selected msg number */
236 int hghsel; /* Highest selected msg number */
237 int numsel; /* Number of msgs selected */
238
239 int curmsg; /* Number of current msg if any */
240
241 int msgflags; /* Folder attributes (READONLY, etc) */
242 char *foldpath; /* Pathname of folder */
243
244 /*
245 * Name of sequences in this folder.
246 */
247 svector_t msgattrs;
248
249 /*
250 * bit flags for whether sequence
251 * is public (0), or private (1)
252 */
253 bvector_t attrstats;
254
255 /*
256 * These represent the lowest and highest possible
257 * message numbers we can put in the message status
258 * area, without calling folder_realloc().
259 */
260 int lowoff;
261 int hghoff;
262
263 /*
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.
269 */
270 size_t num_msgstats;
271 bvector_t *msgstats; /* msg status */
272
273 /*
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
276 * written.
277 */
278 FILE *seqhandle;
279
280 /*
281 * The name of the public sequence file; required by lkfclose()
282 */
283 char *seqname;
284 };
285
286 /*
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.
290 */
291 #define MSGSTATNUM(lo, hi) ((size_t) ((hi) - (lo) + 1))
292 #define MSGSTATSIZE(mp) ((mp)->num_msgstats * sizeof *(mp)->msgstats)
293
294 /*
295 * macros for message and sequence manipulation
296 */
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)
302
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)
306
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)
310
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)
315
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)
322
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)
329
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)
338
339 /*
340 * macros for folder attributes
341 */
342 #define clear_folder_flags(mp) ((mp)->msgflags = 0)
343
344 #define is_readonly(mp) ((mp)->msgflags & READONLY)
345 #define set_readonly(mp) ((mp)->msgflags |= READONLY)
346
347 #define other_files(mp) ((mp)->msgflags & OTHERS)
348 #define set_other_files(mp) ((mp)->msgflags |= OTHERS)
349
350 #define NULLMP ((struct msgs *) 0)
351
352 /*
353 * m_getfld() message parsing
354 */
355
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
364 terminating NULL. */
365
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 */
372
373 struct m_getfld_state;
374 typedef struct m_getfld_state *m_getfld_state_t;
375
376 /*
377 * Maildrop styles
378 */
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 */
383
384 #define NOUSE 0 /* draft being re-used */
385
386 #define TFOLDER 0 /* path() given a +folder */
387 #define TFILE 1 /* path() given a file */
388 #define TSUBCWF 2 /* path() given a @folder */
389
390 #define OUTPUTLINELEN 72 /* default line length for headers */
391
392 #define LINK "@" /* Name of link to file to which you are */
393 /* replying. */
394
395 /*
396 * credentials management
397 */
398 struct nmh_creds;
399 typedef struct nmh_creds *nmh_creds_t;
400
401 /*
402 * miscellaneous macros
403 */
404 #define pidXwait(pid,cp) pidstatus (pidwait (pid, NOTOK), stdout, cp)
405
406 #ifndef max
407 # define max(a,b) ((a) > (b) ? (a) : (b))
408 #endif
409
410 #ifndef min
411 # define min(a,b) ((a) < (b) ? (a) : (b))
412 #endif
413
414 #ifndef abs
415 # define abs(a) ((a) > 0 ? (a) : -(a))
416 #endif
417
418 /*
419 * GLOBAL VARIABLES
420 */
421 #define CTXMOD 0x01 /* context information modified */
422 #define DBITS "\020\01CTXMOD"
423 extern char ctxflags;
424
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 */
430
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);
437
438 /*
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
442 * on any system.
443 */
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;
454 extern char *draft;
455 extern char *fileproc;
456 extern char *foldprot;
457 extern char *formatproc;
458 extern char *forwcomps;
459 extern char *inbox;
460 extern char *incproc;
461 extern char *lproc;
462 extern char *mailproc;
463 extern char *mh_defaults;
464 extern char *mh_profile;
465 extern char *mh_seq;
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;
496
497 extern void (*done) (int) NORETURN;
498
499 #include <h/prototypes.h>