Move #include from h/mh.h to source files
[mmh] / h / mh.h
1 /*
2 ** mh.h -- main header file for all of nmh
3 */
4
5 #include <config.h>
6
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10
11
12 /*
13 ** Well-used constants
14 */
15 #define NOTOK       (-1)    /* syscall()s return this on error */
16 #define OK             0    /*  ditto on success               */
17 #define DONE           1    /* trinary logic                   */
18 #define ALL           ""
19 #define Nbby           8    /* number of bits/byte */
20
21 #define MAXARGS     1000    /* max arguments to exec                */
22 #define NFOLDERS    1000    /* max folder arguments on command line */
23 #define DMAXFOLDER     4    /* typical number of digits             */
24 #define MAXFOLDER   1000    /* message increment                    */
25
26 #ifndef FALSE
27 # define FALSE 0
28 #endif
29 #ifndef TRUE
30 # define TRUE 1
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 #else
40 # define NORETURN
41 #endif
42
43 /*
44 ** we should be getting this value from pathconf(_PC_PATH_MAX)
45 */
46 #ifndef PATH_MAX
47 # ifdef MAXPATHLEN
48 #  define PATH_MAX MAXPATHLEN
49 # else
50    /* so we will just pick something */
51 #  define PATH_MAX 1024
52 # endif
53 #endif
54
55 /*
56 ** we should be getting this value from sysconf(_SC_OPEN_MAX)
57 */
58 #ifndef OPEN_MAX
59 # ifdef NOFILE
60 #  define OPEN_MAX NOFILE
61 # else
62    /* so we will just pick something */
63 #  define OPEN_MAX 64
64 # endif
65 #endif
66
67 /*
68 ** user context/profile structure
69 */
70 struct node {
71         char *n_name;         /* key                  */
72         char *n_field;        /* value                */
73         char n_context;       /* context, not profile */
74         struct node *n_next;  /* next entry           */
75 };
76
77 /*
78 ** switches structure
79 */
80 #define AMBIGSW  (-2)    /* from smatch() on ambiguous switch */
81 #define UNKWNSW  (-1)    /* from smatch() on unknown switch   */
82
83 struct swit {
84         char *sw;
85         /*
86         ** The minchars field is apparently used like this:
87         **
88         ** -# : Switch can be abbreviated to # chars; switch hidden in -help.
89         ** 0  : Switch can't be abbreviated;          switch shown in -help.
90         ** #  : Switch can be abbreviated to # chars; switch shown in -help.
91         */
92         int minchars;
93 };
94
95 extern struct swit anoyes[];   /* standard yes/no switches */
96
97 /*
98 ** general folder attributes
99 */
100 #define READONLY      (1<<0)    /* No write access to folder    */
101 #define SEQMOD        (1<<1)    /* folder's sequences modifed   */
102 #define ALLOW_BEYOND  (1<<2)    /* allow the beyond sequence    */
103 #define OTHERS        (1<<3)    /* folder has other files       */
104
105 #define FBITS  "\020\01READONLY\02SEQMOD\03ALLOW_BEYOND\04OTHERS"
106
107 /*
108 ** type for holding the sequence set of a message
109 */
110 typedef unsigned int seqset_t;
111
112 /*
113 ** internal messages attributes (sequences)
114 */
115 #define EXISTS        (1<<0)    /* exists            */
116 #define SELECTED      (1<<1)    /* selected for use  */
117 #define SELECT_UNSEEN (1<<2)    /* inc/show "unseen" */
118
119 #define MBITS "\020\01EXISTS\02SELECTED\03UNSEEN"
120
121 /*
122 ** first free slot for user-defined sequences
123 */
124 #define FFATTRSLOT  3
125
126 /*
127 ** Determine the number of user defined sequences we
128 ** can have.  The first few sequence flags are for
129 ** internal nmh message flags.
130 */
131 #define NUMATTRS  ((sizeof(seqset_t) * Nbby) - FFATTRSLOT)
132
133 /*
134 ** Primary structure of folder/message information
135 */
136 struct msgs {
137         int lowmsg;        /* Lowest msg number                 */
138         int hghmsg;        /* Highest msg number                */
139         int nummsg;        /* Actual Number of msgs             */
140
141         int lowsel;        /* Lowest selected msg number        */
142         int hghsel;        /* Highest selected msg number       */
143         int numsel;        /* Number of msgs selected           */
144
145         int curmsg;        /* Number of current msg if any      */
146
147         int msgflags;      /* Folder attributes (READONLY, etc) */
148         char *foldpath;    /* Pathname of folder                */
149
150         /*
151         ** Name of sequences in this folder.  We add an
152         ** extra slot, so we can NULL terminate the list.
153         */
154         char *msgattrs[NUMATTRS + 1];
155
156         /*
157         ** bit flags for whether sequence
158         ** is public (0), or private (1)
159         */
160         seqset_t attrstats;
161
162         /*
163         ** These represent the lowest and highest possible
164         ** message numbers we can put in the message status
165         ** area, without calling folder_realloc().
166         */
167         int    lowoff;
168         int    hghoff;
169
170         /*
171         ** This is an array of seqset_t which we allocate dynamically.
172         ** Each seqset_t is a set of bits flags for a particular message.
173         ** These bit flags represent general attributes such as
174         ** EXISTS, SELECTED, etc. as well as track if message is
175         ** in a particular sequence.
176         */
177         seqset_t *msgstats;        /* msg status */
178 };
179
180 /*
181 ** Amount of space to allocate for msgstats.  Allocate
182 ** the array to have space for messages numbers lo to hi.
183 */
184 #define MSGSTATSIZE(mp,lo,hi) ((size_t) (((hi) - (lo) + 1) * sizeof(*(mp)->msgstats)))
185
186 #define NULLMP  ((struct msgs *) 0)
187
188 /*
189 ** m_getfld() message parsing
190 */
191
192 #define NAMESZ  999        /*
193                            ** Limit on component name size.
194                            ** RFC 2822 limits line lengths to
195                            ** 998 characters, so a header name
196                            ** can be at most that long.
197                            ** m_getfld limits header names to 2
198                            ** less than NAMESZ, which is fine,
199                            ** because header names must be
200                            ** followed by a colon. Add one for
201                            ** terminating NULL.
202                            */
203
204 #define LENERR   (-2)      /* Name too long error from getfld  */
205 #define FMTERR   (-3)      /* Message Format error             */
206 #define FLD      0         /* Field returned                   */
207 #define FLDPLUS  1         /* Field returned with more to come */
208 #define FLDEOF   2         /* Field returned ending at eom     */
209 #define BODY     3         /* Body  returned with more to come */
210 #define BODYEOF  4         /* Body  returned ending at eom     */
211 #define FILEEOF  5         /* Reached end of input file        */
212
213 extern int msg_count;        /* m_getfld() indicators (That's a hack!) */
214
215 #define NOUSE    0        /* draft being re-used */
216
217 #define OUTPUTLINELEN  72    /* default line length for headers */
218
219 /*
220 ** miscellaneous macros
221 */
222
223 #ifndef max
224 # define max(a,b) ((a) > (b) ? (a) : (b))
225 #endif
226
227 #ifndef min
228 # define min(a,b) ((a) < (b) ? (a) : (b))
229 #endif
230
231 /*
232 ** GLOBAL VARIABLES
233 */
234 #define CTXMOD  0x01        /* context information modified */
235 #define DBITS  "\020\01CTXMOD"
236 extern char ctxflags;
237
238 extern char *invo_name;      /* command invocation name         */
239 extern char *mypath;         /* user's $HOME                    */
240 extern char *mmhdir;
241 extern char *mmhpath;
242 extern char *defpath;        /* pathname of user's profile      */
243 extern char *ctxpath;        /* pathname of user's context      */
244 extern struct node *m_defs;  /* list of profile/context entries */
245 extern char *mailstore;      /* name of mail storage directory  */
246
247 /*
248 ** These standard strings are defined in config.c.  They are the
249 ** only system-dependent parameters in nmh, and thus by redefining
250 ** their values and reloading the various modules, nmh will run
251 ** on any system.
252 */
253 extern char *attach_hdr;
254 extern char *sign_hdr;
255 extern char *enc_hdr;
256 extern char *components;
257 extern char *context;
258 extern char *curfolder;
259 extern char *defaulteditor;
260 extern char *defaultpager;
261 extern char *defaultfolder;
262 extern char *digestcomps;
263 extern char *distcomps;
264 extern char *draftfolder;
265 extern char *foldprot;
266 extern char *forwcomps;
267 extern char *inbox;
268 extern char *listproc;
269 extern char *mhetcdir;
270 extern char *mailspool;
271 extern char *mh_seq;
272 extern char *mhlformat;
273 extern char *mhlreply;
274 extern char *mimetypequery;
275 extern char *mimetypequeryproc;
276 extern char *msgprot;
277 extern char *nmhstorage;
278 extern char *nsequence;
279 extern char *profile;
280 extern char *psequence;
281 extern char *rcvdistcomps;
282 extern char *replcomps;
283 extern char *replgroupcomps;
284 extern char *sendmail;
285 extern char *seq_all;
286 extern char *seq_beyond;
287 extern char *seq_cur;
288 extern char *seq_first;
289 extern char *seq_last;
290 extern char *seq_next;
291 extern char *seq_prev;
292 extern char *seq_unseen;
293 extern char *seq_neg;
294 extern char *trashfolder;
295 extern char *usequence;
296 extern char *version_num;
297 extern char *version_str;
298 extern char *whatnowproc;
299
300 #include <h/prototypes.h>