def.h revision 1590
11590Srgrimes/*
21590Srgrimes * Copyright (c) 1980, 1993
31590Srgrimes *	The Regents of the University of California.  All rights reserved.
41590Srgrimes *
51590Srgrimes * Redistribution and use in source and binary forms, with or without
61590Srgrimes * modification, are permitted provided that the following conditions
71590Srgrimes * are met:
81590Srgrimes * 1. Redistributions of source code must retain the above copyright
91590Srgrimes *    notice, this list of conditions and the following disclaimer.
101590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111590Srgrimes *    notice, this list of conditions and the following disclaimer in the
121590Srgrimes *    documentation and/or other materials provided with the distribution.
131590Srgrimes * 3. All advertising materials mentioning features or use of this software
141590Srgrimes *    must display the following acknowledgement:
151590Srgrimes *	This product includes software developed by the University of
161590Srgrimes *	California, Berkeley and its contributors.
171590Srgrimes * 4. Neither the name of the University nor the names of its contributors
181590Srgrimes *    may be used to endorse or promote products derived from this software
191590Srgrimes *    without specific prior written permission.
201590Srgrimes *
211590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241590Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311590Srgrimes * SUCH DAMAGE.
321590Srgrimes *
331590Srgrimes *	@(#)def.h	8.2 (Berkeley) 3/21/94
341590Srgrimes */
351590Srgrimes
361590Srgrimes/*
371590Srgrimes * Mail -- a mail program
381590Srgrimes *
391590Srgrimes * Author: Kurt Shoens (UCB) March 25, 1978
401590Srgrimes */
411590Srgrimes
421590Srgrimes#include <sys/param.h>
431590Srgrimes#include <sys/stat.h>
441590Srgrimes#include <sys/time.h>
451590Srgrimes
461590Srgrimes#include <signal.h>
471590Srgrimes#include <sgtty.h>
481590Srgrimes#include <unistd.h>
491590Srgrimes#include <stdlib.h>
501590Srgrimes#include <stdio.h>
511590Srgrimes#include <ctype.h>
521590Srgrimes#include <string.h>
531590Srgrimes#include "pathnames.h"
541590Srgrimes
551590Srgrimes#define	APPEND				/* New mail goes to end of mailbox */
561590Srgrimes
571590Srgrimes#define	ESCAPE		'~'		/* Default escape for sending */
581590Srgrimes#define	NMLSIZE		1024		/* max names in a message list */
591590Srgrimes#define	PATHSIZE	MAXPATHLEN	/* Size of pathnames throughout */
601590Srgrimes#define	HSHSIZE		59		/* Hash size for aliases and vars */
611590Srgrimes#define	LINESIZE	BUFSIZ		/* max readable line width */
621590Srgrimes#define	STRINGSIZE	((unsigned) 128)/* Dynamic allocation units */
631590Srgrimes#define	MAXARGC		1024		/* Maximum list of raw strings */
641590Srgrimes#define	NOSTR		((char *) 0)	/* Null string pointer */
651590Srgrimes#define	MAXEXP		25		/* Maximum expansion of aliases */
661590Srgrimes
671590Srgrimes#define	equal(a, b)	(strcmp(a,b)==0)/* A nice function to string compare */
681590Srgrimes
691590Srgrimesstruct message {
701590Srgrimes	short	m_flag;			/* flags, see below */
711590Srgrimes	short	m_block;		/* block number of this message */
721590Srgrimes	short	m_offset;		/* offset in block of message */
731590Srgrimes	long	m_size;			/* Bytes in the message */
741590Srgrimes	short	m_lines;		/* Lines in the message */
751590Srgrimes};
761590Srgrimes
771590Srgrimes/*
781590Srgrimes * flag bits.
791590Srgrimes */
801590Srgrimes
811590Srgrimes#define	MUSED		(1<<0)		/* entry is used, but this bit isn't */
821590Srgrimes#define	MDELETED	(1<<1)		/* entry has been deleted */
831590Srgrimes#define	MSAVED		(1<<2)		/* entry has been saved */
841590Srgrimes#define	MTOUCH		(1<<3)		/* entry has been noticed */
851590Srgrimes#define	MPRESERVE	(1<<4)		/* keep entry in sys mailbox */
861590Srgrimes#define	MMARK		(1<<5)		/* message is marked! */
871590Srgrimes#define	MODIFY		(1<<6)		/* message has been modified */
881590Srgrimes#define	MNEW		(1<<7)		/* message has never been seen */
891590Srgrimes#define	MREAD		(1<<8)		/* message has been read sometime. */
901590Srgrimes#define	MSTATUS		(1<<9)		/* message status has changed */
911590Srgrimes#define	MBOX		(1<<10)		/* Send this to mbox, regardless */
921590Srgrimes
931590Srgrimes/*
941590Srgrimes * Given a file address, determine the block number it represents.
951590Srgrimes */
961590Srgrimes#define blockof(off)			((int) ((off) / 4096))
971590Srgrimes#define offsetof(off)			((int) ((off) % 4096))
981590Srgrimes#define positionof(block, offset)	((off_t)(block) * 4096 + (offset))
991590Srgrimes
1001590Srgrimes/*
1011590Srgrimes * Format of the command description table.
1021590Srgrimes * The actual table is declared and initialized
1031590Srgrimes * in lex.c
1041590Srgrimes */
1051590Srgrimesstruct cmd {
1061590Srgrimes	char	*c_name;		/* Name of command */
1071590Srgrimes	int	(*c_func)();		/* Implementor of the command */
1081590Srgrimes	short	c_argtype;		/* Type of arglist (see below) */
1091590Srgrimes	short	c_msgflag;		/* Required flags of messages */
1101590Srgrimes	short	c_msgmask;		/* Relevant flags of messages */
1111590Srgrimes};
1121590Srgrimes
1131590Srgrimes/* Yechh, can't initialize unions */
1141590Srgrimes
1151590Srgrimes#define	c_minargs c_msgflag		/* Minimum argcount for RAWLIST */
1161590Srgrimes#define	c_maxargs c_msgmask		/* Max argcount for RAWLIST */
1171590Srgrimes
1181590Srgrimes/*
1191590Srgrimes * Argument types.
1201590Srgrimes */
1211590Srgrimes
1221590Srgrimes#define	MSGLIST	 0		/* Message list type */
1231590Srgrimes#define	STRLIST	 1		/* A pure string */
1241590Srgrimes#define	RAWLIST	 2		/* Shell string list */
1251590Srgrimes#define	NOLIST	 3		/* Just plain 0 */
1261590Srgrimes#define	NDMLIST	 4		/* Message list, no defaults */
1271590Srgrimes
1281590Srgrimes#define	P	040		/* Autoprint dot after command */
1291590Srgrimes#define	I	0100		/* Interactive command bit */
1301590Srgrimes#define	M	0200		/* Legal from send mode bit */
1311590Srgrimes#define	W	0400		/* Illegal when read only bit */
1321590Srgrimes#define	F	01000		/* Is a conditional command */
1331590Srgrimes#define	T	02000		/* Is a transparent command */
1341590Srgrimes#define	R	04000		/* Cannot be called from collect */
1351590Srgrimes
1361590Srgrimes/*
1371590Srgrimes * Oft-used mask values
1381590Srgrimes */
1391590Srgrimes
1401590Srgrimes#define	MMNORM		(MDELETED|MSAVED)/* Look at both save and delete bits */
1411590Srgrimes#define	MMNDEL		MDELETED	/* Look only at deleted bit */
1421590Srgrimes
1431590Srgrimes/*
1441590Srgrimes * Structure used to return a break down of a head
1451590Srgrimes * line (hats off to Bill Joy!)
1461590Srgrimes */
1471590Srgrimes
1481590Srgrimesstruct headline {
1491590Srgrimes	char	*l_from;	/* The name of the sender */
1501590Srgrimes	char	*l_tty;		/* His tty string (if any) */
1511590Srgrimes	char	*l_date;	/* The entire date string */
1521590Srgrimes};
1531590Srgrimes
1541590Srgrimes#define	GTO	1		/* Grab To: line */
1551590Srgrimes#define	GSUBJECT 2		/* Likewise, Subject: line */
1561590Srgrimes#define	GCC	4		/* And the Cc: line */
1571590Srgrimes#define	GBCC	8		/* And also the Bcc: line */
1581590Srgrimes#define	GMASK	(GTO|GSUBJECT|GCC|GBCC)
1591590Srgrimes				/* Mask of places from whence */
1601590Srgrimes
1611590Srgrimes#define	GNL	16		/* Print blank line after */
1621590Srgrimes#define	GDEL	32		/* Entity removed from list */
1631590Srgrimes#define	GCOMMA	64		/* detract puts in commas */
1641590Srgrimes
1651590Srgrimes/*
1661590Srgrimes * Structure used to pass about the current
1671590Srgrimes * state of the user-typed message header.
1681590Srgrimes */
1691590Srgrimes
1701590Srgrimesstruct header {
1711590Srgrimes	struct name *h_to;		/* Dynamic "To:" string */
1721590Srgrimes	char *h_subject;		/* Subject string */
1731590Srgrimes	struct name *h_cc;		/* Carbon copies string */
1741590Srgrimes	struct name *h_bcc;		/* Blind carbon copies */
1751590Srgrimes	struct name *h_smopts;		/* Sendmail options */
1761590Srgrimes};
1771590Srgrimes
1781590Srgrimes/*
1791590Srgrimes * Structure of namelist nodes used in processing
1801590Srgrimes * the recipients of mail and aliases and all that
1811590Srgrimes * kind of stuff.
1821590Srgrimes */
1831590Srgrimes
1841590Srgrimesstruct name {
1851590Srgrimes	struct	name *n_flink;		/* Forward link in list. */
1861590Srgrimes	struct	name *n_blink;		/* Backward list link */
1871590Srgrimes	short	n_type;			/* From which list it came */
1881590Srgrimes	char	*n_name;		/* This fella's name */
1891590Srgrimes};
1901590Srgrimes
1911590Srgrimes/*
1921590Srgrimes * Structure of a variable node.  All variables are
1931590Srgrimes * kept on a singly-linked list of these, rooted by
1941590Srgrimes * "variables"
1951590Srgrimes */
1961590Srgrimes
1971590Srgrimesstruct var {
1981590Srgrimes	struct	var *v_link;		/* Forward link to next variable */
1991590Srgrimes	char	*v_name;		/* The variable's name */
2001590Srgrimes	char	*v_value;		/* And it's current value */
2011590Srgrimes};
2021590Srgrimes
2031590Srgrimesstruct group {
2041590Srgrimes	struct	group *ge_link;		/* Next person in this group */
2051590Srgrimes	char	*ge_name;		/* This person's user name */
2061590Srgrimes};
2071590Srgrimes
2081590Srgrimesstruct grouphead {
2091590Srgrimes	struct	grouphead *g_link;	/* Next grouphead in list */
2101590Srgrimes	char	*g_name;		/* Name of this group */
2111590Srgrimes	struct	group *g_list;		/* Users in group. */
2121590Srgrimes};
2131590Srgrimes
2141590Srgrimes#define	NIL	((struct name *) 0)	/* The nil pointer for namelists */
2151590Srgrimes#define	NONE	((struct cmd *) 0)	/* The nil pointer to command tab */
2161590Srgrimes#define	NOVAR	((struct var *) 0)	/* The nil pointer to variables */
2171590Srgrimes#define	NOGRP	((struct grouphead *) 0)/* The nil grouphead pointer */
2181590Srgrimes#define	NOGE	((struct group *) 0)	/* The nil group pointer */
2191590Srgrimes
2201590Srgrimes/*
2211590Srgrimes * Structure of the hash table of ignored header fields
2221590Srgrimes */
2231590Srgrimesstruct ignoretab {
2241590Srgrimes	int i_count;			/* Number of entries */
2251590Srgrimes	struct ignore {
2261590Srgrimes		struct ignore *i_link;	/* Next ignored field in bucket */
2271590Srgrimes		char *i_field;		/* This ignored field */
2281590Srgrimes	} *i_head[HSHSIZE];
2291590Srgrimes};
2301590Srgrimes
2311590Srgrimes/*
2321590Srgrimes * Token values returned by the scanner used for argument lists.
2331590Srgrimes * Also, sizes of scanner-related things.
2341590Srgrimes */
2351590Srgrimes
2361590Srgrimes#define	TEOL	0			/* End of the command line */
2371590Srgrimes#define	TNUMBER	1			/* A message number */
2381590Srgrimes#define	TDASH	2			/* A simple dash */
2391590Srgrimes#define	TSTRING	3			/* A string (possibly containing -) */
2401590Srgrimes#define	TDOT	4			/* A "." */
2411590Srgrimes#define	TUP	5			/* An "^" */
2421590Srgrimes#define	TDOLLAR	6			/* A "$" */
2431590Srgrimes#define	TSTAR	7			/* A "*" */
2441590Srgrimes#define	TOPEN	8			/* An '(' */
2451590Srgrimes#define	TCLOSE	9			/* A ')' */
2461590Srgrimes#define TPLUS	10			/* A '+' */
2471590Srgrimes#define TERROR	11			/* A lexical error */
2481590Srgrimes
2491590Srgrimes#define	REGDEP	2			/* Maximum regret depth. */
2501590Srgrimes#define	STRINGLEN	1024		/* Maximum length of string token */
2511590Srgrimes
2521590Srgrimes/*
2531590Srgrimes * Constants for conditional commands.  These describe whether
2541590Srgrimes * we should be executing stuff or not.
2551590Srgrimes */
2561590Srgrimes
2571590Srgrimes#define	CANY		0		/* Execute in send or receive mode */
2581590Srgrimes#define	CRCV		1		/* Execute in receive mode only */
2591590Srgrimes#define	CSEND		2		/* Execute in send mode only */
2601590Srgrimes
2611590Srgrimes/*
2621590Srgrimes * Kludges to handle the change from setexit / reset to setjmp / longjmp
2631590Srgrimes */
2641590Srgrimes
2651590Srgrimes#define	setexit()	setjmp(srbuf)
2661590Srgrimes#define	reset(x)	longjmp(srbuf, x)
2671590Srgrimes
2681590Srgrimes/*
2691590Srgrimes * Truncate a file to the last character written. This is
2701590Srgrimes * useful just before closing an old file that was opened
2711590Srgrimes * for read/write.
2721590Srgrimes */
2731590Srgrimes#define trunc(stream) {							\
2741590Srgrimes	(void)fflush(stream); 						\
2751590Srgrimes	(void)ftruncate(fileno(stream), (long)ftell(stream));		\
2761590Srgrimes}
277