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