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