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