35c8b419b2e21ccbd944b6f04a66856b03067378
[mmh] / h / mh.h
1 /*
2  * mh.h -- main header file for all of nmh
3  */
4
5 #include <h/nmh.h>
6
7 /*
8  * Well-used constants
9  */
10 #define NOTOK       (-1)    /* syscall()s return this on error */
11 #define OK             0    /*  ditto on success               */
12 #define DONE           1    /* trinary logic                   */
13 #define ALL           ""
14 #define Nbby           8    /* number of bits/byte */
15
16 #define MAXARGS     1000    /* max arguments to exec                */
17 #define NFOLDERS    1000    /* max folder arguments on command line */
18 #define DMAXFOLDER     4    /* typical number of digits             */
19 #define MAXFOLDER   1000    /* message increment                    */
20
21 #ifndef FALSE
22 # define FALSE 0
23 #endif
24 #ifndef TRUE
25 # define TRUE 1
26 #endif
27 typedef unsigned char  boolean;  /* not int so we can pack in a structure */
28
29 /* If we're using gcc then give it some information about
30  * functions that abort.
31  */
32 #if __GNUC__ > 2
33 # define NORETURN __attribute__((__noreturn__))
34 #else
35 # define NORETURN
36 #endif
37
38 /*
39  * user context/profile structure
40  */
41 struct node {
42         char *n_name;         /* key                  */
43         char *n_field;        /* value                */
44         char n_context;       /* context, not profile */
45         struct node *n_next;  /* next entry           */
46 };
47
48 /*
49  * switches structure
50  */
51 #define AMBIGSW  (-2)    /* from smatch() on ambiguous switch */
52 #define UNKWNSW  (-1)    /* from smatch() on unknown switch   */
53
54 struct swit {
55         char *sw;
56         /*
57          * The minchars field is apparently used like this:
58          *
59          * -# : Switch can be abbreviated to # chars; switch hidden in -help.
60          * 0  : Switch can't be abbreviated;          switch shown in -help.
61          * #  : Switch can be abbreviated to # chars; switch shown in -help.
62          */
63         int minchars;
64 };
65
66 extern struct swit anoyes[];   /* standard yes/no switches */
67
68 #define ATTACHFORMATS 3        /* Number of send attach formats. */
69
70 /*
71  * general folder attributes
72  */
73 #define READONLY   (1<<0)    /* No write access to folder    */
74 #define SEQMOD     (1<<1)    /* folder's sequences modifed   */
75 #define ALLOW_NEW  (1<<2)    /* allow the "new" sequence     */
76 #define OTHERS     (1<<3)    /* folder has other files       */
77
78 #define FBITS  "\020\01READONLY\02SEQMOD\03ALLOW_NEW\04OTHERS"
79
80 /*
81  * type for holding the sequence set of a message
82  */
83 typedef unsigned int seqset_t;
84
85 /*
86  * Determine the number of user defined sequences we
87  * can have.  The first 5 sequence flags are for
88  * internal nmh message flags.
89  */
90 #define NUMATTRS  ((sizeof(seqset_t) * Nbby) - 5)
91
92 /*
93  * first free slot for user defined sequences
94  * and attributes
95  */
96 #define FFATTRSLOT  5
97
98 /*
99  * internal messages attributes (sequences)
100  */
101 #define EXISTS        (1<<0)    /* exists            */
102 #define DELETED       (1<<1)    /* deleted           */
103 #define SELECTED      (1<<2)    /* selected for use  */
104 #define SELECT_EMPTY  (1<<3)    /* "new" message     */
105 #define SELECT_UNSEEN (1<<4)    /* inc/show "unseen" */
106
107 #define MBITS "\020\01EXISTS\02DELETED\03SELECTED\04NEW\05UNSEEN"
108
109 /*
110  * Primary structure of folder/message information
111  */
112 struct msgs {
113         int lowmsg;        /* Lowest msg number                 */
114         int hghmsg;        /* Highest msg number                */
115         int nummsg;        /* Actual Number of msgs             */
116
117         int lowsel;        /* Lowest selected msg number        */
118         int hghsel;        /* Highest selected msg number       */
119         int numsel;        /* Number of msgs selected           */
120
121         int curmsg;        /* Number of current msg if any      */
122
123         int msgflags;      /* Folder attributes (READONLY, etc) */
124         char *foldpath;    /* Pathname of folder                */
125
126         /*
127          * Name of sequences in this folder.  We add an
128          * extra slot, so we can NULL terminate the list.
129          */
130         char *msgattrs[NUMATTRS + 1];
131
132         /*
133          * bit flags for whether sequence
134          * is public (0), or private (1)
135          */
136         seqset_t attrstats;
137
138         /*
139          * These represent the lowest and highest possible
140          * message numbers we can put in the message status
141          * area, without calling folder_realloc().
142          */
143         int    lowoff;
144         int    hghoff;
145
146         /*
147          * This is an array of seqset_t which we allocate dynamically.
148          * Each seqset_t is a set of bits flags for a particular message.
149          * These bit flags represent general attributes such as
150          * EXISTS, SELECTED, etc. as well as track if message is
151          * in a particular sequence.
152          */
153         seqset_t *msgstats;        /* msg status */
154 };
155
156 /*
157  * Amount of space to allocate for msgstats.  Allocate
158  * the array to have space for messages numbers lo to hi.
159  */
160 #define MSGSTATSIZE(mp,lo,hi) ((size_t) (((hi) - (lo) + 1) * sizeof(*(mp)->msgstats)))
161
162 /*
163  * macros for message and sequence manipulation
164  */
165 #define clear_msg_flags(mp,msgnum) ((mp)->msgstats[(msgnum) - mp->lowoff] = 0)
166 #define copy_msg_flags(mp,i,j) \
167     ((mp)->msgstats[(i) - mp->lowoff] = (mp)->msgstats[(j) - mp->lowoff])
168 #define get_msg_flags(mp,ptr,msgnum)  (*(ptr) = (mp)->msgstats[(msgnum) - mp->lowoff])
169 #define set_msg_flags(mp,ptr,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] = *(ptr))
170
171 #define does_exist(mp,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] & EXISTS)
172 #define unset_exists(mp,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~EXISTS)
173 #define set_exists(mp,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] |= EXISTS)
174
175 #define is_selected(mp,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECTED)
176 #define unset_selected(mp,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~SELECTED)
177 #define set_selected(mp,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECTED)
178
179 #define is_select_empty(mp,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECT_EMPTY)
180 #define set_select_empty(mp,msgnum) \
181     ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECT_EMPTY)
182
183 #define is_unseen(mp,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] & SELECT_UNSEEN)
184 #define unset_unseen(mp,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~SELECT_UNSEEN)
185 #define set_unseen(mp,msgnum)  ((mp)->msgstats[(msgnum) - mp->lowoff] |= SELECT_UNSEEN)
186
187
188 #define in_sequence(mp,seqnum,msgnum) \
189            ((mp)->msgstats[(msgnum) - mp->lowoff] & (1 << (FFATTRSLOT + seqnum)))
190 #define clear_sequence(mp,seqnum,msgnum) \
191            ((mp)->msgstats[(msgnum) - mp->lowoff] &= ~(1 << (FFATTRSLOT + seqnum)))
192 #define add_sequence(mp,seqnum,msgnum) \
193            ((mp)->msgstats[(msgnum) - mp->lowoff] |= (1 << (FFATTRSLOT + seqnum)))
194
195 #define is_seq_private(mp,seqnum) \
196            ((mp)->attrstats & (1 << (FFATTRSLOT + seqnum)))
197 #define make_seq_public(mp,seqnum) \
198            ((mp)->attrstats &= ~(1 << (FFATTRSLOT + seqnum)))
199 #define make_seq_private(mp,seqnum) \
200            ((mp)->attrstats |= (1 << (FFATTRSLOT + seqnum)))
201 #define make_all_public(mp) \
202            ((mp)->attrstats = 0)
203
204 /*
205  * macros for folder attributes
206  */
207 #define clear_folder_flags(mp) ((mp)->msgflags = 0)
208
209 #define is_readonly(mp)  ((mp)->msgflags & READONLY)
210 #define set_readonly(mp)  ((mp)->msgflags |= READONLY)
211
212 #define other_files(mp)  ((mp)->msgflags & OTHERS)
213 #define set_other_files(mp)  ((mp)->msgflags |= OTHERS)
214
215 #define NULLMP  ((struct msgs *) 0)
216
217 /*
218  * m_getfld() message parsing
219  */
220
221 #define NAMESZ  999        /* Limit on component name size.
222                             * RFC 2822 limits line lengths to
223                             * 998 characters, so a header name
224                             * can be at most that long.
225                             * m_getfld limits header names to 2
226                             * less than NAMESZ, which is fine,
227                             * because header names must be
228                             * followed by a colon. Add one for
229                             * terminating NULL.
230                             */
231
232 #define LENERR   (-2)      /* Name too long error from getfld  */
233 #define FMTERR   (-3)      /* Message Format error             */
234 #define FLD      0         /* Field returned                   */
235 #define FLDPLUS  1         /* Field returned with more to come */
236 #define FLDEOF   2         /* Field returned ending at eom     */
237 #define BODY     3         /* Body  returned with more to come */
238 #define BODYEOF  4         /* Body  returned ending at eom     */
239 #define FILEEOF  5         /* Reached end of input file        */
240
241 /*
242  * Maildrop styles
243  */
244 #define MS_DEFAULT  0    /* default (one msg per file) */
245 #define MS_UNKNOWN  1    /* type not known yet         */
246 #define MS_MBOX     2    /* Unix-style "from" lines    */
247 #define MS_MMDF     3    /* string mmdlm2              */
248
249 extern int msg_count;        /* m_getfld() indicators */
250 extern int msg_style;        /*  .. */
251 extern char *msg_delim;      /*  .. */
252
253 #define NOUSE    0        /* draft being re-used */
254
255 #define TFOLDER  0        /* path() given a +folder */
256 #define TFILE    1        /* path() given a file    */
257 #define TSUBCWF  2        /* path() given a @folder */
258
259 #define OUTPUTLINELEN  72    /* default line length for headers */
260
261 /*
262  * miscellaneous macros
263  */
264
265 #define pidXwait(pid,cp) pidstatus (pidwait (pid, NOTOK), stdout, cp)
266
267 #ifndef max
268 # define max(a,b) ((a) > (b) ? (a) : (b))
269 #endif
270
271 #ifndef min
272 # define min(a,b) ((a) < (b) ? (a) : (b))
273 #endif
274
275 #ifndef abs
276 # define abs(a) ((a) > 0 ? (a) : -(a))
277 #endif
278
279 /*
280  * GLOBAL VARIABLES
281  */
282 #define CTXMOD  0x01        /* context information modified */
283 #define DBITS  "\020\01CTXMOD"
284 extern char ctxflags;
285
286 extern char *invo_name;      /* command invocation name         */
287 extern char *mypath;         /* user's $HOME                    */
288 extern char *defpath;        /* pathname of user's profile      */
289 extern char *ctxpath;        /* pathname of user's context      */
290 extern struct node *m_defs;  /* list of profile/context entries */
291
292 /*
293  * These standard strings are defined in config.c.  They are the
294  * only system-dependent parameters in nmh, and thus by redefining
295  * their values and reloading the various modules, nmh will run
296  * on any system.
297  */
298 extern char *buildmimeproc;
299 extern char *backup_prefix;
300 extern char *altmsglink;
301 extern char *catproc;
302 extern char *components;
303 extern char *context;
304 extern char *current;
305 extern char *defaulteditor;
306 extern char *defaultfolder;
307 extern char *digestcomps;
308 extern char *distcomps;
309 extern char *draftfolder;
310 extern char *faceproc;
311 extern char *fileproc;
312 extern char *foldprot;
313 extern char *forwcomps;
314 extern char *inbox;
315 extern char *incproc;
316 extern char *installproc;
317 extern char *lproc;
318 extern char *mailproc;
319 extern char *mh_defaults;
320 extern char *mh_profile;
321 extern char *mh_seq;
322 extern char *mhlformat;
323 extern char *mhlforward;
324 extern char *mhlproc;
325 extern char *mhlreply;
326 extern char *moreproc;
327 extern char *msgprot;
328 extern char *nmhaccessftp;
329 extern char *nmhstorage;
330 extern char *nmhcache;
331 extern char *nmhprivcache;
332 extern char *nsequence;
333 extern char *packproc;
334 extern char *postproc;
335 extern char *pfolder;
336 extern char *psequence;
337 extern char *rcvdistcomps;
338 extern char *rcvstoreproc;
339 extern char *replcomps;
340 extern char *replgroupcomps;
341 extern char *rmfproc;
342 extern char *rmmproc;
343 extern char *sendmail;
344 extern char *sendproc;
345 extern char *showmimeproc;
346 extern char *showproc;
347 extern char *usequence;
348 extern char *version_num;
349 extern char *version_str;
350 extern char *whatnowproc;
351
352 extern void (*done) (int) NORETURN;
353
354 #include <h/prototypes.h>