]> diplodocus.org Git - nmh/blob - h/mh.h
Run output of -replacetextplain test through uniq.
[nmh] / h / mh.h
1
2 /*
3 * mh.h -- main header file for all of nmh
4 */
5
6 #include <h/nmh.h>
7
8 /*
9 * Well-used constants
10 */
11 #define NOTOK (-1) /* syscall()s return this on error */
12 #define OK 0 /* ditto on success */
13 #define DONE 1 /* trinary logic */
14 #define ALL ""
15 #define Nbby 8 /* number of bits/byte */
16
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 */
21
22 #ifndef FALSE
23 #define FALSE 0
24 #endif
25 #ifndef TRUE
26 #define TRUE 1
27 #endif
28 typedef unsigned char boolean; /* not int so we can pack in a structure */
29
30 /* If we're using gcc then give it some information about
31 * functions that abort.
32 */
33 #if __GNUC__ > 2
34 #define NORETURN __attribute__((__noreturn__))
35 #define NMH_UNUSED(i) (void) i
36 #else
37 #define NORETURN
38 #define NMH_UNUSED(i) i
39 #endif
40
41 /*
42 * user context/profile structure
43 */
44 struct node {
45 char *n_name; /* key */
46 char *n_field; /* value */
47 char n_context; /* context, not profile */
48 struct node *n_next; /* next entry */
49 };
50
51 /*
52 * switches structure
53 */
54 #define AMBIGSW (-2) /* from smatch() on ambiguous switch */
55 #define UNKWNSW (-1) /* from smatch() on unknown switch */
56
57 struct swit {
58
59 /*
60 * Switch name
61 */
62
63 char *sw;
64
65 /* The minchars field is apparently used like this:
66
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. */
70 int minchars;
71
72 /*
73 * If we pick this switch, return this value from smatch
74 */
75
76 int swret;
77 };
78
79 /*
80 * Macros to use when declaring struct swit arrays.
81 *
82 * These macros are what known as X-Macros. In your source code you
83 * use them like this:
84 *
85 * #define FOO_SWITCHES \
86 * X("switch1", 0, SWITCHSW) \
87 * X("switch2", 0, SWITCH2SW) \
88 * X("thirdswitch", 2, SWITCH3SW) \
89 *
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.
92 *
93 * After you define FOO_SWITCHES, you instantiate it as follows:
94 *
95 * #define X(sw, minchars, id) id,
96 * DEFINE_SWITCH_ENUM(FOO);
97 * #undef X
98 *
99 * #define X(sw, minchars, id) { sw, minchars, id },
100 * DEFINE_SWITCH_ARRAY(FOO);
101 * #undef X
102 *
103 * DEFINE_SWITCH_ENUM defines an extra enum at the end of the list called
104 * LEN_FOO.
105 */
106
107 #define DEFINE_SWITCH_ENUM(name) \
108 enum { \
109 name ## _SWITCHES \
110 LEN_ ## name \
111 }
112
113 #define DEFINE_SWITCH_ARRAY(name, array) \
114 static struct swit array[] = { \
115 name ## _SWITCHES \
116 { NULL, 0, 0 } \
117 }
118
119 extern struct swit anoyes[]; /* standard yes/no switches */
120
121 #define ATTACHFORMATS 3 /* Number of send attach formats. */
122
123 /*
124 * general folder attributes
125 */
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 */
131
132 #define FBITS "\020\01READONLY\02SEQMOD\03ALLOW_NEW\04OTHERS\05MODIFIED"
133
134 /*
135 * first free slot for user defined sequences
136 * and attributes
137 */
138 #define FFATTRSLOT 5
139
140 /*
141 * internal messages attributes (sequences)
142 */
143 #define EXISTS (0) /* exists */
144 #define DELETED (1) /* deleted */
145 #define SELECTED (2) /* selected for use */
146 #define SELECT_EMPTY (3) /* "new" message */
147 #define SELECT_UNSEEN (4) /* inc/show "unseen" */
148
149 #define MBITS "\020\01EXISTS\02DELETED\03SELECTED\04NEW\05UNSEEN"
150
151 /*
152 * type for holding the sequence set of a message
153 */
154 typedef struct bvector *bvector_t;
155
156 bvector_t bvector_create (size_t /* initial size in bits, can be 0 */);
157 void bvector_copy (bvector_t, bvector_t);
158 void bvector_free (bvector_t);
159 void bvector_clear (bvector_t, size_t);
160 void bvector_clear_all (bvector_t);
161 void bvector_set (bvector_t, size_t);
162 unsigned int bvector_at (bvector_t, size_t);
163 const unsigned long *bvector_bits (bvector_t);
164 size_t bvector_maxsize (bvector_t);
165
166 struct svector;
167 typedef struct svector *svector_t;
168
169 svector_t svector_create (size_t);
170 void svector_free (svector_t);
171 char *svector_push_back (svector_t, char *);
172 char *svector_at (svector_t, size_t);
173 char **svector_strs (svector_t);
174 size_t svector_size (svector_t);
175
176 struct ivector;
177 typedef struct ivector *ivector_t;
178
179 ivector_t ivector_create (size_t);
180 void ivector_free (ivector_t);
181 int ivector_push_back (ivector_t, int);
182 int ivector_at (ivector_t, size_t);
183 int *ivector_atp (ivector_t, size_t);
184 size_t ivector_size (ivector_t);
185
186 /*
187 * Primary structure of folder/message information
188 */
189 struct msgs {
190 int lowmsg; /* Lowest msg number */
191 int hghmsg; /* Highest msg number */
192 int nummsg; /* Actual Number of msgs */
193
194 int lowsel; /* Lowest selected msg number */
195 int hghsel; /* Highest selected msg number */
196 int numsel; /* Number of msgs selected */
197
198 int curmsg; /* Number of current msg if any */
199
200 int msgflags; /* Folder attributes (READONLY, etc) */
201 char *foldpath; /* Pathname of folder */
202
203 /*
204 * Name of sequences in this folder.
205 */
206 svector_t msgattrs;
207
208 /*
209 * bit flags for whether sequence
210 * is public (0), or private (1)
211 */
212 bvector_t attrstats;
213
214 /*
215 * These represent the lowest and highest possible
216 * message numbers we can put in the message status
217 * area, without calling folder_realloc().
218 */
219 int lowoff;
220 int hghoff;
221
222 /*
223 * This is an array of bvector_t which we allocate dynamically.
224 * Each bvector_t is a set of bits flags for a particular message.
225 * These bit flags represent general attributes such as
226 * EXISTS, SELECTED, etc. as well as track if message is
227 * in a particular sequence.
228 */
229 size_t num_msgstats;
230 bvector_t *msgstats; /* msg status */
231
232 /*
233 * A FILE handle containing an open filehandle for the sequence file
234 * for this folder. If non-NULL, use it when the sequence file is
235 * written.
236 */
237 FILE *seqhandle;
238
239 /*
240 * The name of the public sequence file; required by lkfclose()
241 */
242 char *seqname;
243 };
244
245 /*
246 * Amount of space to allocate for msgstats. Allocate
247 * the array to have space for messages numbered lo to hi.
248 * Use MSGSTATNUM to load mp->num_msgstats first.
249 */
250 #define MSGSTATNUM(lo, hi) ((size_t) ((hi) - (lo) + 1))
251 #define MSGSTATSIZE(mp) ((mp)->num_msgstats * sizeof *(mp)->msgstats)
252
253 /*
254 * macros for message and sequence manipulation
255 */
256 #define msgstat(mp,n) (mp)->msgstats[(n) - mp->lowoff]
257 #define clear_msg_flags(mp,msgnum) bvector_clear_all (msgstat(mp, msgnum))
258 #define copy_msg_flags(mp,i,j) bvector_copy (msgstat(mp,i), msgstat(mp,j))
259 #define get_msg_flags(mp,ptr,msgnum) bvector_copy (ptr, msgstat(mp, msgnum))
260 #define set_msg_flags(mp,ptr,msgnum) bvector_copy (msgstat(mp, msgnum), ptr)
261
262 #define does_exist(mp,msgnum) bvector_at (msgstat(mp, msgnum), EXISTS)
263 #define unset_exists(mp,msgnum) bvector_clear (msgstat(mp, msgnum), EXISTS)
264 #define set_exists(mp,msgnum) bvector_set (msgstat(mp, msgnum), EXISTS)
265
266 #define is_selected(mp,msgnum) bvector_at (msgstat(mp, msgnum), SELECTED)
267 #define unset_selected(mp,msgnum) bvector_clear (msgstat(mp, msgnum), SELECTED)
268 #define set_selected(mp,msgnum) bvector_set (msgstat(mp, msgnum), SELECTED)
269
270 #define is_select_empty(mp,msgnum) \
271 bvector_at (msgstat(mp, msgnum), SELECT_EMPTY)
272 #define set_select_empty(mp,msgnum) \
273 bvector_set (msgstat(mp, msgnum), SELECT_EMPTY)
274
275 #define is_unseen(mp,msgnum) \
276 bvector_at (msgstat(mp, msgnum), SELECT_UNSEEN)
277 #define unset_unseen(mp,msgnum) \
278 bvector_clear (msgstat(mp, msgnum), SELECT_UNSEEN)
279 #define set_unseen(mp,msgnum) \
280 bvector_set (msgstat(mp, msgnum), SELECT_UNSEEN)
281
282 /* for msh only */
283 #define set_deleted(mp,msgnum) bvector_set (msgstat(mp, msgnum), DELETED)
284
285 #define in_sequence(mp,seqnum,msgnum) \
286 bvector_at (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
287 #define clear_sequence(mp,seqnum,msgnum) \
288 bvector_clear (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
289 #define add_sequence(mp,seqnum,msgnum) \
290 bvector_set (msgstat(mp, msgnum), FFATTRSLOT + seqnum)
291
292 #define is_seq_private(mp,seqnum) \
293 bvector_at (mp->attrstats, FFATTRSLOT + seqnum)
294 #define make_seq_public(mp,seqnum) \
295 bvector_clear (mp->attrstats, FFATTRSLOT + seqnum)
296 #define make_seq_private(mp,seqnum) \
297 bvector_set (mp->attrstats, FFATTRSLOT + seqnum)
298 #define make_all_public(mp) \
299 mp->attrstats = bvector_create(0); bvector_clear_all (mp->attrstats)
300
301 /*
302 * macros for folder attributes
303 */
304 #define clear_folder_flags(mp) ((mp)->msgflags = 0)
305
306 #define is_readonly(mp) ((mp)->msgflags & READONLY)
307 #define set_readonly(mp) ((mp)->msgflags |= READONLY)
308
309 #define other_files(mp) ((mp)->msgflags & OTHERS)
310 #define set_other_files(mp) ((mp)->msgflags |= OTHERS)
311
312 #define NULLMP ((struct msgs *) 0)
313
314 /*
315 * m_getfld() message parsing
316 */
317
318 #define NAMESZ 999 /* Limit on component name size.
319 RFC 2822 limits line lengths to
320 998 characters, so a header name
321 can be at most that long.
322 m_getfld limits header names to 2
323 less than NAMESZ, which is fine,
324 because header names must be
325 followed by a colon. Add one for
326 terminating NULL. */
327
328 #define LENERR (-2) /* Name too long error from getfld */
329 #define FMTERR (-3) /* Message Format error */
330 #define FLD 0 /* Field returned */
331 #define FLDPLUS 1 /* Field returned with more to come */
332 #define BODY 3 /* Body returned with more to come */
333 #define FILEEOF 5 /* Reached end of input file */
334
335 struct m_getfld_state;
336 typedef struct m_getfld_state *m_getfld_state_t;
337
338 /*
339 * Maildrop styles
340 */
341 #define MS_DEFAULT 0 /* default (one msg per file) */
342 #define MS_UNKNOWN 1 /* type not known yet */
343 #define MS_MBOX 2 /* Unix-style "from" lines */
344 #define MS_MMDF 3 /* string mmdlm2 */
345 #define MS_MSH 4 /* whacko msh */
346
347 #define NOUSE 0 /* draft being re-used */
348
349 #define TFOLDER 0 /* path() given a +folder */
350 #define TFILE 1 /* path() given a file */
351 #define TSUBCWF 2 /* path() given a @folder */
352
353 #define OUTPUTLINELEN 72 /* default line length for headers */
354
355 #define LINK "@" /* Name of link to file to which you are */
356 /* replying. */
357
358 #define NMH_ATTACH_HEADER "Nmh-Attachment" /* Default header for -attach */
359
360 /*
361 * credentials management
362 */
363 struct nmh_creds {
364 char *host;
365 char *user;
366 char *password;
367 };
368
369 typedef struct nmh_creds *nmh_creds_t;
370
371 /*
372 * miscellaneous macros
373 */
374 #define pidXwait(pid,cp) pidstatus (pidwait (pid, NOTOK), stdout, cp)
375
376 #ifndef max
377 # define max(a,b) ((a) > (b) ? (a) : (b))
378 #endif
379
380 #ifndef min
381 # define min(a,b) ((a) < (b) ? (a) : (b))
382 #endif
383
384 #ifndef abs
385 # define abs(a) ((a) > 0 ? (a) : -(a))
386 #endif
387
388 /*
389 * GLOBAL VARIABLES
390 */
391 #define CTXMOD 0x01 /* context information modified */
392 #define DBITS "\020\01CTXMOD"
393 extern char ctxflags;
394
395 extern char *invo_name; /* command invocation name */
396 extern char *mypath; /* user's $HOME */
397 extern char *defpath; /* pathname of user's profile */
398 extern char *ctxpath; /* pathname of user's context */
399 extern struct node *m_defs; /* list of profile/context entries */
400
401 /* What style to use for generated Message-ID and Content-ID header
402 fields. The localname style is pid.time@localname, where time is
403 in seconds. The random style replaces the localname with some
404 (pseudo)random bytes and uses microsecond-resolution time. */
405 int save_message_id_style (const char *);
406 char *message_id (time_t, int);
407
408 /*
409 * These standard strings are defined in config.c. They are the
410 * only system-dependent parameters in nmh, and thus by redefining
411 * their values and reloading the various modules, nmh will run
412 * on any system.
413 */
414 extern char *buildmimeproc;
415 extern char *catproc;
416 extern char *components;
417 extern char *context;
418 extern char *current;
419 extern char *credentials_file;
420 extern char *defaultfolder;
421 extern char *digestcomps;
422 extern char *distcomps;
423 extern char *draft;
424 extern char *fileproc;
425 extern char *foldprot;
426 extern char *formatproc;
427 extern char *forwcomps;
428 extern char *inbox;
429 extern char *incproc;
430 extern char *lproc;
431 extern char *mailproc;
432 extern char *mh_defaults;
433 extern char *mh_profile;
434 extern char *mh_seq;
435 extern char *mhlformat;
436 extern char *mhlforward;
437 extern char *mhlproc;
438 extern char *mhlreply;
439 extern char *moreproc;
440 extern char *msgprot;
441 extern char *mshproc;
442 extern char *nmhaccessftp;
443 extern char *nmhaccessurl;
444 extern char *nmhstorage;
445 extern char *nmhcache;
446 extern char *nmhprivcache;
447 extern char *nsequence;
448 extern char *packproc;
449 extern char *postproc;
450 extern char *pfolder;
451 extern char *psequence;
452 extern char *rcvdistcomps;
453 extern char *rcvstoreproc;
454 extern char *replcomps;
455 extern char *replgroupcomps;
456 extern char *rmmproc;
457 extern char *sendproc;
458 extern char *showmimeproc;
459 extern char *showproc;
460 extern char *usequence;
461 extern char *version_num;
462 extern char *version_str;
463 extern char *vmhproc;
464 extern char *whatnowproc;
465 extern char *whomproc;
466
467 extern void (*done) (int) NORETURN;
468
469 #include <h/prototypes.h>
470