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