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