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