6b8f4a97a2ec7a21a45ebefc10b31f6953853d6a
[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 /*
69 ** general folder attributes
70 */
71 #define READONLY      (1<<0)    /* No write access to folder    */
72 #define SEQMOD        (1<<1)    /* folder's sequences modifed   */
73 #define ALLOW_BEYOND  (1<<2)    /* allow the beyond sequence    */
74 #define OTHERS        (1<<3)    /* folder has other files       */
75
76 #define FBITS  "\020\01READONLY\02SEQMOD\03ALLOW_BEYOND\04OTHERS"
77
78 /*
79 ** type for holding the sequence set of a message
80 */
81 typedef unsigned int seqset_t;
82
83 /*
84 ** internal messages attributes (sequences)
85 */
86 #define EXISTS        (1<<0)    /* exists            */
87 #define SELECTED      (1<<1)    /* selected for use  */
88 #define SELECT_UNSEEN (1<<2)    /* inc/show "unseen" */
89
90 #define MBITS "\020\01EXISTS\02SELECTED\03UNSEEN"
91
92 /*
93 ** first free slot for user-defined sequences
94 */
95 #define FFATTRSLOT  3
96
97 /*
98 ** Determine the number of user defined sequences we
99 ** can have.  The first few sequence flags are for
100 ** internal nmh message flags.
101 */
102 #define NUMATTRS  ((sizeof(seqset_t) * Nbby) - FFATTRSLOT)
103
104 /*
105 ** Primary structure of folder/message information
106 */
107 struct msgs {
108         int lowmsg;        /* Lowest msg number                 */
109         int hghmsg;        /* Highest msg number                */
110         int nummsg;        /* Actual Number of msgs             */
111
112         int lowsel;        /* Lowest selected msg number        */
113         int hghsel;        /* Highest selected msg number       */
114         int numsel;        /* Number of msgs selected           */
115
116         int curmsg;        /* Number of current msg if any      */
117
118         int msgflags;      /* Folder attributes (READONLY, etc) */
119         char *foldpath;    /* Pathname of folder                */
120
121         /*
122         ** Name of sequences in this folder.  We add an
123         ** extra slot, so we can NULL terminate the list.
124         */
125         char *msgattrs[NUMATTRS + 1];
126
127         /*
128         ** bit flags for whether sequence
129         ** is public (0), or private (1)
130         */
131         seqset_t attrstats;
132
133         /*
134         ** These represent the lowest and highest possible
135         ** message numbers we can put in the message status
136         ** area, without calling folder_realloc().
137         */
138         int    lowoff;
139         int    hghoff;
140
141         /*
142         ** This is an array of seqset_t which we allocate dynamically.
143         ** Each seqset_t is a set of bits flags for a particular message.
144         ** These bit flags represent general attributes such as
145         ** EXISTS, SELECTED, etc. as well as track if message is
146         ** in a particular sequence.
147         */
148         seqset_t *msgstats;        /* msg status */
149 };
150
151 /*
152 ** Amount of space to allocate for msgstats.  Allocate
153 ** the array to have space for messages numbers lo to hi.
154 */
155 #define MSGSTATSIZE(mp,lo,hi) ((size_t) (((hi) - (lo) + 1) * sizeof(*(mp)->msgstats)))
156
157 #define NULLMP  ((struct msgs *) 0)
158
159 /*
160 ** m_getfld() message parsing
161 */
162
163 #define NAMESZ  999        /*
164                            ** Limit on component name size.
165                            ** RFC 2822 limits line lengths to
166                            ** 998 characters, so a header name
167                            ** can be at most that long.
168                            ** m_getfld limits header names to 2
169                            ** less than NAMESZ, which is fine,
170                            ** because header names must be
171                            ** followed by a colon. Add one for
172                            ** terminating NULL.
173                            */
174
175 #define LENERR   (-2)      /* Name too long error from getfld  */
176 #define FMTERR   (-3)      /* Message Format error             */
177 #define FLD      0         /* Field returned                   */
178 #define FLDPLUS  1         /* Field returned with more to come */
179 #define FLDEOF   2         /* Field returned ending at eom     */
180 #define BODY     3         /* Body  returned with more to come */
181 #define BODYEOF  4         /* Body  returned ending at eom     */
182 #define FILEEOF  5         /* Reached end of input file        */
183
184 extern int msg_count;        /* m_getfld() indicators (That's a hack!) */
185
186 #define NOUSE    0        /* draft being re-used */
187
188 #define OUTPUTLINELEN  72    /* default line length for headers */
189
190 /*
191 ** miscellaneous macros
192 */
193
194 #ifndef max
195 # define max(a,b) ((a) > (b) ? (a) : (b))
196 #endif
197
198 #ifndef min
199 # define min(a,b) ((a) < (b) ? (a) : (b))
200 #endif
201
202 /*
203 ** GLOBAL VARIABLES
204 */
205 #define CTXMOD  0x01        /* context information modified */
206 #define DBITS  "\020\01CTXMOD"
207 extern char ctxflags;
208
209 extern char *invo_name;      /* command invocation name         */
210 extern char *mypath;         /* user's $HOME                    */
211 extern char *mmhdir;
212 extern char *mmhpath;
213 extern char *defpath;        /* pathname of user's profile      */
214 extern char *ctxpath;        /* pathname of user's context      */
215 extern struct node *m_defs;  /* list of profile/context entries */
216 extern char *mailstore;      /* name of mail storage directory  */
217
218 /*
219 ** These standard strings are defined in config.c.  They are the
220 ** only system-dependent parameters in nmh, and thus by redefining
221 ** their values and reloading the various modules, nmh will run
222 ** on any system.
223 */
224 extern char *attach_hdr;
225 extern char *sign_hdr;
226 extern char *enc_hdr;
227 extern char *components;
228 extern char *context;
229 extern char *curfolder;
230 extern char *defaulteditor;
231 extern char *defaultpager;
232 extern char *defaultfolder;
233 extern char *digestcomps;
234 extern char *distcomps;
235 extern char *draftfolder;
236 extern char *foldprot;
237 extern char *forwcomps;
238 extern char *inbox;
239 extern char *listproc;
240 extern char *mhetcdir;
241 extern char *mailspool;
242 extern char *mh_seq;
243 extern char *mhlformat;
244 extern char *mhlreply;
245 extern char *mimetypequery;
246 extern char *mimetypequeryproc;
247 extern char *msgprot;
248 extern char *nmhstorage;
249 extern char *nsequence;
250 extern char *profile;
251 extern char *psequence;
252 extern char *rcvdistcomps;
253 extern char *replcomps;
254 extern char *replgroupcomps;
255 extern char *sendmail;
256 extern char *seq_all;
257 extern char *seq_beyond;
258 extern char *seq_cur;
259 extern char *seq_first;
260 extern char *seq_last;
261 extern char *seq_next;
262 extern char *seq_prev;
263 extern char *seq_unseen;
264 extern char *seq_neg;
265 extern char *trashfolder;
266 extern char *usequence;
267 extern char *version_num;
268 extern char *version_str;
269 extern char *whatnowproc;
270
271 #include <h/prototypes.h>