xref: /original-bsd/usr.bin/mail/def.h (revision eeb6993a)
1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)def.h	5.21 (Berkeley) 06/01/90
8  */
9 
10 #include <sys/param.h>		/* includes <sys/types.h> */
11 #include <sys/signal.h>
12 #include <stdio.h>
13 #include <sgtty.h>
14 #include <ctype.h>
15 #include <string.h>
16 #include "pathnames.h"
17 
18 /*
19  * Mail -- a mail program
20  *
21  * Author: Kurt Shoens (UCB) March 25, 1978
22  */
23 
24 #define	APPEND				/* New mail goes to end of mailbox */
25 
26 #define	ESCAPE		'~'		/* Default escape for sending */
27 #define	NMLSIZE		1024		/* max names in a message list */
28 #define	PATHSIZE	MAXPATHLEN	/* Size of pathnames throughout */
29 #define	HSHSIZE		59		/* Hash size for aliases and vars */
30 #define	LINESIZE	BUFSIZ		/* max readable line width */
31 #define	STRINGSIZE	((unsigned) 128)/* Dynamic allocation units */
32 #define	MAXARGC		1024		/* Maximum list of raw strings */
33 #define	NOSTR		((char *) 0)	/* Null string pointer */
34 #define	MAXEXP		25		/* Maximum expansion of aliases */
35 
36 #define	equal(a, b)	(strcmp(a,b)==0)/* A nice function to string compare */
37 
38 struct message {
39 	short	m_flag;			/* flags, see below */
40 	short	m_block;		/* block number of this message */
41 	short	m_offset;		/* offset in block of message */
42 	long	m_size;			/* Bytes in the message */
43 	short	m_lines;		/* Lines in the message */
44 };
45 
46 /*
47  * flag bits.
48  */
49 
50 #define	MUSED		(1<<0)		/* entry is used, but this bit isn't */
51 #define	MDELETED	(1<<1)		/* entry has been deleted */
52 #define	MSAVED		(1<<2)		/* entry has been saved */
53 #define	MTOUCH		(1<<3)		/* entry has been noticed */
54 #define	MPRESERVE	(1<<4)		/* keep entry in sys mailbox */
55 #define	MMARK		(1<<5)		/* message is marked! */
56 #define	MODIFY		(1<<6)		/* message has been modified */
57 #define	MNEW		(1<<7)		/* message has never been seen */
58 #define	MREAD		(1<<8)		/* message has been read sometime. */
59 #define	MSTATUS		(1<<9)		/* message status has changed */
60 #define	MBOX		(1<<10)		/* Send this to mbox, regardless */
61 
62 /*
63  * Given a file address, determine the block number it represents.
64  */
65 #define blockof(off)			((int) ((off) / 4096))
66 #define offsetof(off)			((int) ((off) % 4096))
67 #define positionof(block, offset)	((off_t)(block) * 4096 + (offset))
68 
69 /*
70  * Format of the command description table.
71  * The actual table is declared and initialized
72  * in lex.c
73  */
74 
75 struct cmd {
76 	char	*c_name;		/* Name of command */
77 	int	(*c_func)();		/* Implementor of the command */
78 	short	c_argtype;		/* Type of arglist (see below) */
79 	short	c_msgflag;		/* Required flags of messages */
80 	short	c_msgmask;		/* Relevant flags of messages */
81 };
82 
83 /* Yechh, can't initialize unions */
84 
85 #define	c_minargs c_msgflag		/* Minimum argcount for RAWLIST */
86 #define	c_maxargs c_msgmask		/* Max argcount for RAWLIST */
87 
88 /*
89  * Argument types.
90  */
91 
92 #define	MSGLIST	 0		/* Message list type */
93 #define	STRLIST	 1		/* A pure string */
94 #define	RAWLIST	 2		/* Shell string list */
95 #define	NOLIST	 3		/* Just plain 0 */
96 #define	NDMLIST	 4		/* Message list, no defaults */
97 
98 #define	P	040		/* Autoprint dot after command */
99 #define	I	0100		/* Interactive command bit */
100 #define	M	0200		/* Legal from send mode bit */
101 #define	W	0400		/* Illegal when read only bit */
102 #define	F	01000		/* Is a conditional command */
103 #define	T	02000		/* Is a transparent command */
104 #define	R	04000		/* Cannot be called from collect */
105 
106 /*
107  * Oft-used mask values
108  */
109 
110 #define	MMNORM		(MDELETED|MSAVED)/* Look at both save and delete bits */
111 #define	MMNDEL		MDELETED	/* Look only at deleted bit */
112 
113 /*
114  * Structure used to return a break down of a head
115  * line (hats off to Bill Joy!)
116  */
117 
118 struct headline {
119 	char	*l_from;	/* The name of the sender */
120 	char	*l_tty;		/* His tty string (if any) */
121 	char	*l_date;	/* The entire date string */
122 };
123 
124 #define	GTO	1		/* Grab To: line */
125 #define	GSUBJECT 2		/* Likewise, Subject: line */
126 #define	GCC	4		/* And the Cc: line */
127 #define	GBCC	8		/* And also the Bcc: line */
128 #define	GMASK	(GTO|GSUBJECT|GCC|GBCC)
129 				/* Mask of places from whence */
130 
131 #define	GNL	16		/* Print blank line after */
132 #define	GDEL	32		/* Entity removed from list */
133 #define	GCOMMA	64		/* detract puts in commas */
134 
135 /*
136  * Structure used to pass about the current
137  * state of the user-typed message header.
138  */
139 
140 struct header {
141 	struct name *h_to;		/* Dynamic "To:" string */
142 	char *h_subject;		/* Subject string */
143 	struct name *h_cc;		/* Carbon copies string */
144 	struct name *h_bcc;		/* Blind carbon copies */
145 	struct name *h_smopts;		/* Sendmail options */
146 };
147 
148 /*
149  * Structure of namelist nodes used in processing
150  * the recipients of mail and aliases and all that
151  * kind of stuff.
152  */
153 
154 struct name {
155 	struct	name *n_flink;		/* Forward link in list. */
156 	struct	name *n_blink;		/* Backward list link */
157 	short	n_type;			/* From which list it came */
158 	char	*n_name;		/* This fella's name */
159 };
160 
161 /*
162  * Structure of a variable node.  All variables are
163  * kept on a singly-linked list of these, rooted by
164  * "variables"
165  */
166 
167 struct var {
168 	struct	var *v_link;		/* Forward link to next variable */
169 	char	*v_name;		/* The variable's name */
170 	char	*v_value;		/* And it's current value */
171 };
172 
173 struct group {
174 	struct	group *ge_link;		/* Next person in this group */
175 	char	*ge_name;		/* This person's user name */
176 };
177 
178 struct grouphead {
179 	struct	grouphead *g_link;	/* Next grouphead in list */
180 	char	*g_name;		/* Name of this group */
181 	struct	group *g_list;		/* Users in group. */
182 };
183 
184 #define	NIL	((struct name *) 0)	/* The nil pointer for namelists */
185 #define	NONE	((struct cmd *) 0)	/* The nil pointer to command tab */
186 #define	NOVAR	((struct var *) 0)	/* The nil pointer to variables */
187 #define	NOGRP	((struct grouphead *) 0)/* The nil grouphead pointer */
188 #define	NOGE	((struct group *) 0)	/* The nil group pointer */
189 
190 /*
191  * Structure of the hash table of ignored header fields
192  */
193 struct ignoretab {
194 	int i_count;			/* Number of entries */
195 	struct ignore {
196 		struct ignore *i_link;	/* Next ignored field in bucket */
197 		char *i_field;		/* This ignored field */
198 	} *i_head[HSHSIZE];
199 };
200 
201 /*
202  * Token values returned by the scanner used for argument lists.
203  * Also, sizes of scanner-related things.
204  */
205 
206 #define	TEOL	0			/* End of the command line */
207 #define	TNUMBER	1			/* A message number */
208 #define	TDASH	2			/* A simple dash */
209 #define	TSTRING	3			/* A string (possibly containing -) */
210 #define	TDOT	4			/* A "." */
211 #define	TUP	5			/* An "^" */
212 #define	TDOLLAR	6			/* A "$" */
213 #define	TSTAR	7			/* A "*" */
214 #define	TOPEN	8			/* An '(' */
215 #define	TCLOSE	9			/* A ')' */
216 #define TPLUS	10			/* A '+' */
217 #define TERROR	11			/* A lexical error */
218 
219 #define	REGDEP	2			/* Maximum regret depth. */
220 #define	STRINGLEN	1024		/* Maximum length of string token */
221 
222 /*
223  * Constants for conditional commands.  These describe whether
224  * we should be executing stuff or not.
225  */
226 
227 #define	CANY		0		/* Execute in send or receive mode */
228 #define	CRCV		1		/* Execute in receive mode only */
229 #define	CSEND		2		/* Execute in send mode only */
230 
231 /*
232  * Kludges to handle the change from setexit / reset to setjmp / longjmp
233  */
234 
235 #define	setexit()	setjmp(srbuf)
236 #define	reset(x)	longjmp(srbuf, x)
237 
238 /*
239  * Truncate a file to the last character written. This is
240  * useful just before closing an old file that was opened
241  * for read/write.
242  */
243 #define trunc(stream)	ftruncate(fileno(stream), (long) ftell(stream))
244 
245 /*
246  * Forward declarations of routine types to keep lint and cc happy.
247  */
248 
249 FILE	*Fdopen();
250 FILE	*Popen();
251 FILE	*collect();
252 FILE	*infix();
253 FILE	*run_editor();
254 FILE	*setinput();
255 char	**unpack();
256 char	*calloc();
257 char	*copy();
258 char	*copyin();
259 char	*detract();
260 char	*expand();
261 char	*getdeadletter();
262 char	*gets();
263 char	*hfield();
264 char	*name1();
265 char	*nameof();
266 char	*nextword();
267 char	*getenv();
268 char	*getname();
269 char	*fgets();
270 char	*ishfield();
271 char	*malloc();
272 char	*mktemp();
273 char	*readtty();
274 char	*reedit();
275 char	*salloc();
276 char	*savestr();
277 char	*skin();
278 char	*snarf();
279 char	*username();
280 char	*value();
281 char	*vcopy();
282 char	*yankword();
283 off_t	fsize();
284 uid_t	getuid();
285 struct	cmd	*lex();
286 struct	grouphead	*findgroup();
287 struct	name	*nalloc();
288 struct	name	*cat();
289 struct	name	*delname();
290 struct	name	*elide();
291 struct	name	*extract();
292 struct	name	*gexpand();
293 struct	name	*outof();
294 struct	name	*put();
295 struct	name	*usermap();
296 struct	var	*lookup();
297