xref: /netbsd-src/usr.bin/mail/def.h (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /*	$NetBSD: def.h,v 1.16 2003/08/07 11:14:37 agc Exp $	*/
2 /*
3  * Copyright (c) 1980, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the University nor the names of its contributors
15  *    may be used to endorse or promote products derived from this software
16  *    without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  *	@(#)def.h	8.4 (Berkeley) 4/20/95
31  *	$NetBSD: def.h,v 1.16 2003/08/07 11:14:37 agc Exp $
32  */
33 
34 /*
35  * Mail -- a mail program
36  *
37  * Author: Kurt Shoens (UCB) March 25, 1978
38  */
39 
40 #include <sys/types.h>
41 #include <sys/file.h>
42 #include <sys/ioctl.h>
43 #include <sys/stat.h>
44 #include <sys/param.h>
45 #include <sys/time.h>
46 #include <sys/wait.h>
47 
48 #include <ctype.h>
49 #include <err.h>
50 #include <errno.h>
51 #include <fcntl.h>
52 #include <paths.h>
53 #include <pwd.h>
54 #include <signal.h>
55 #include <stdio.h>
56 #include <stdlib.h>
57 #include <string.h>
58 #include <termios.h>
59 #include <time.h>
60 #include <unistd.h>
61 #include "pathnames.h"
62 
63 #define	APPEND				/* New mail goes to end of mailbox */
64 
65 #define	ESCAPE		'~'		/* Default escape for sending */
66 #define	NMLSIZE		1024		/* max names in a message list */
67 #define	PATHSIZE	MAXPATHLEN	/* Size of pathnames throughout */
68 #define	HSHSIZE		59		/* Hash size for aliases and vars */
69 #define	LINESIZE	BUFSIZ		/* max readable line width */
70 #define	STRINGSIZE	((unsigned) 128)/* Dynamic allocation units */
71 #define	MAXARGC		1024		/* Maximum list of raw strings */
72 #define	MAXEXP		25		/* Maximum expansion of aliases */
73 
74 #define	equal(a, b)	(strcmp(a,b)==0)/* A nice function to string compare */
75 
76 struct message {
77 	short	m_flag;			/* flags, see below */
78 	long	m_block;		/* block number of this message */
79 	short	m_offset;		/* offset in block of message */
80 	long	m_size;			/* Bytes in the message */
81 	long	m_lines;		/* Lines in the message */
82 	long	m_blines;		/* Body (non-header) lines */
83 };
84 
85 /*
86  * flag bits.
87  */
88 
89 #define	MUSED		(1<<0)		/* entry is used, but this bit isn't */
90 #define	MDELETED	(1<<1)		/* entry has been deleted */
91 #define	MSAVED		(1<<2)		/* entry has been saved */
92 #define	MTOUCH		(1<<3)		/* entry has been noticed */
93 #define	MPRESERVE	(1<<4)		/* keep entry in sys mailbox */
94 #define	MMARK		(1<<5)		/* message is marked! */
95 #define	MODIFY		(1<<6)		/* message has been modified */
96 #define	MNEW		(1<<7)		/* message has never been seen */
97 #define	MREAD		(1<<8)		/* message has been read sometime. */
98 #define	MSTATUS		(1<<9)		/* message status has changed */
99 #define	MBOX		(1<<10)		/* Send this to mbox, regardless */
100 
101 /*
102  * Given a file address, determine the block number it represents.
103  */
104 #define blockof(off)			((int) ((off) / 4096))
105 #define offsetof(off)			((int) ((off) % 4096))
106 #define positionof(block, offset)	((off_t)(block) * 4096 + (offset))
107 
108 /*
109  * Format of the command description table.
110  * The actual table is declared and initialized
111  * in lex.c
112  */
113 struct cmd {
114 	char	*c_name;		/* Name of command */
115 	int	(*c_func)(void *);	/* Implementor of the command */
116 	short	c_argtype;		/* Type of arglist (see below) */
117 	short	c_msgflag;		/* Required flags of messages */
118 	short	c_msgmask;		/* Relevant flags of messages */
119 };
120 
121 /* Yechh, can't initialize unions */
122 
123 #define	c_minargs c_msgflag		/* Minimum argcount for RAWLIST */
124 #define	c_maxargs c_msgmask		/* Max argcount for RAWLIST */
125 
126 /*
127  * Argument types.
128  */
129 
130 #define	MSGLIST	 0		/* Message list type */
131 #define	STRLIST	 1		/* A pure string */
132 #define	RAWLIST	 2		/* Shell string list */
133 #define	NOLIST	 3		/* Just plain 0 */
134 #define	NDMLIST	 4		/* Message list, no defaults */
135 
136 #define	P	040		/* Autoprint dot after command */
137 #define	I	0100		/* Interactive command bit */
138 #define	M	0200		/* Legal from send mode bit */
139 #define	W	0400		/* Illegal when read only bit */
140 #define	F	01000		/* Is a conditional command */
141 #define	T	02000		/* Is a transparent command */
142 #define	R	04000		/* Cannot be called from collect */
143 
144 /*
145  * Oft-used mask values
146  */
147 
148 #define	MMNORM		(MDELETED|MSAVED)/* Look at both save and delete bits */
149 #define	MMNDEL		MDELETED	/* Look only at deleted bit */
150 
151 /*
152  * Structure used to return a break down of a head
153  * line (hats off to Bill Joy!)
154  */
155 
156 struct headline {
157 	char	*l_from;	/* The name of the sender */
158 	char	*l_tty;		/* His tty string (if any) */
159 	char	*l_date;	/* The entire date string */
160 };
161 
162 #define	GTO	1		/* Grab To: line */
163 #define	GSUBJECT 2		/* Likewise, Subject: line */
164 #define	GCC	4		/* And the Cc: line */
165 #define	GBCC	8		/* And also the Bcc: line */
166 #define	GMASK	(GTO|GSUBJECT|GCC|GBCC)
167 				/* Mask of places from whence */
168 
169 #define	GNL	16		/* Print blank line after */
170 #define	GDEL	32		/* Entity removed from list */
171 #define	GCOMMA	64		/* detract puts in commas */
172 
173 /*
174  * Structure used to pass about the current
175  * state of the user-typed message header.
176  */
177 
178 struct header {
179 	struct name *h_to;		/* Dynamic "To:" string */
180 	char *h_subject;		/* Subject string */
181 	struct name *h_cc;		/* Carbon copies string */
182 	struct name *h_bcc;		/* Blind carbon copies */
183 	struct name *h_smopts;		/* Sendmail options */
184 };
185 
186 /*
187  * Structure of namelist nodes used in processing
188  * the recipients of mail and aliases and all that
189  * kind of stuff.
190  */
191 
192 struct name {
193 	struct	name *n_flink;		/* Forward link in list. */
194 	struct	name *n_blink;		/* Backward list link */
195 	short	n_type;			/* From which list it came */
196 	char	*n_name;		/* This fella's name */
197 };
198 
199 /*
200  * Structure of a variable node.  All variables are
201  * kept on a singly-linked list of these, rooted by
202  * "variables"
203  */
204 
205 struct var {
206 	struct	var *v_link;		/* Forward link to next variable */
207 	char	*v_name;		/* The variable's name */
208 	char	*v_value;		/* And it's current value */
209 };
210 
211 struct group {
212 	struct	group *ge_link;		/* Next person in this group */
213 	char	*ge_name;		/* This person's user name */
214 };
215 
216 struct grouphead {
217 	struct	grouphead *g_link;	/* Next grouphead in list */
218 	char	*g_name;		/* Name of this group */
219 	struct	group *g_list;		/* Users in group. */
220 };
221 
222 /*
223  * Structure of the hash table of ignored header fields
224  */
225 struct ignoretab {
226 	int i_count;			/* Number of entries */
227 	struct ignore {
228 		struct ignore *i_link;	/* Next ignored field in bucket */
229 		char *i_field;		/* This ignored field */
230 	} *i_head[HSHSIZE];
231 };
232 
233 /*
234  * Token values returned by the scanner used for argument lists.
235  * Also, sizes of scanner-related things.
236  */
237 
238 #define	TEOL	0			/* End of the command line */
239 #define	TNUMBER	1			/* A message number */
240 #define	TDASH	2			/* A simple dash */
241 #define	TSTRING	3			/* A string (possibly containing -) */
242 #define	TDOT	4			/* A "." */
243 #define	TUP	5			/* An "^" */
244 #define	TDOLLAR	6			/* A "$" */
245 #define	TSTAR	7			/* A "*" */
246 #define	TOPEN	8			/* An '(' */
247 #define	TCLOSE	9			/* A ')' */
248 #define TPLUS	10			/* A '+' */
249 #define TERROR	11			/* A lexical error */
250 
251 #define	REGDEP	2			/* Maximum regret depth. */
252 #define	STRINGLEN	1024		/* Maximum length of string token */
253 
254 /*
255  * Constants for conditional commands.  These describe whether
256  * we should be executing stuff or not.
257  */
258 
259 #define	CANY		0		/* Execute in send or receive mode */
260 #define	CRCV		1		/* Execute in receive mode only */
261 #define	CSEND		2		/* Execute in send mode only */
262 
263 /*
264  * Kludges to handle the change from setexit / reset to setjmp / longjmp
265  */
266 
267 #define	setexit()	setjmp(srbuf)
268 #define	reset(x)	longjmp(srbuf, x)
269 
270 /*
271  * Truncate a file to the last character written. This is
272  * useful just before closing an old file that was opened
273  * for read/write.
274  */
275 #define trunc(stream) {							\
276 	(void)fflush(stream); 						\
277 	(void)ftruncate(fileno(stream), (off_t)ftell(stream));		\
278 }
279