xref: /csrg-svn/usr.bin/mail/def.h (revision 68818)
122474Sdist /*
262083Sbostic  * Copyright (c) 1980, 1993
362083Sbostic  *	The Regents of the University of California.  All rights reserved.
422474Sdist  *
542741Sbostic  * %sccs.include.redist.c%
633499Sbostic  *
7*68818Sdab  *	@(#)def.h	8.4 (Berkeley) 04/20/95
822474Sdist  */
91254Skas 
101254Skas /*
111254Skas  * Mail -- a mail program
121254Skas  *
131254Skas  * Author: Kurt Shoens (UCB) March 25, 1978
141254Skas  */
151254Skas 
1654505Sbostic #include <sys/param.h>
1754505Sbostic #include <sys/stat.h>
1854505Sbostic #include <sys/time.h>
1954505Sbostic 
2054505Sbostic #include <signal.h>
21*68818Sdab #include <termios.h>
2254505Sbostic #include <unistd.h>
2354505Sbostic #include <stdlib.h>
2454505Sbostic #include <stdio.h>
2554505Sbostic #include <ctype.h>
2654505Sbostic #include <string.h>
2754505Sbostic #include "pathnames.h"
2854505Sbostic 
2937870Sbostic #define	APPEND				/* New mail goes to end of mailbox */
301254Skas 
311254Skas #define	ESCAPE		'~'		/* Default escape for sending */
3225375Sserge #define	NMLSIZE		1024		/* max names in a message list */
3334968Sedward #define	PATHSIZE	MAXPATHLEN	/* Size of pathnames throughout */
3425375Sserge #define	HSHSIZE		59		/* Hash size for aliases and vars */
354128Skurt #define	LINESIZE	BUFSIZ		/* max readable line width */
361254Skas #define	STRINGSIZE	((unsigned) 128)/* Dynamic allocation units */
3725375Sserge #define	MAXARGC		1024		/* Maximum list of raw strings */
381254Skas #define	NOSTR		((char *) 0)	/* Null string pointer */
391254Skas #define	MAXEXP		25		/* Maximum expansion of aliases */
4031142Sedward 
411254Skas #define	equal(a, b)	(strcmp(a,b)==0)/* A nice function to string compare */
421254Skas 
431254Skas struct message {
441254Skas 	short	m_flag;			/* flags, see below */
451254Skas 	short	m_offset;		/* offset in block of message */
4667853Sedward 	long	m_block;		/* block number of this message */
478751Scarl 	long	m_size;			/* Bytes in the message */
4867853Sedward 	long	m_lines;		/* Lines in the message */
491254Skas };
501254Skas 
511254Skas /*
521254Skas  * flag bits.
531254Skas  */
541254Skas 
553323Skas #define	MUSED		(1<<0)		/* entry is used, but this bit isn't */
563323Skas #define	MDELETED	(1<<1)		/* entry has been deleted */
573323Skas #define	MSAVED		(1<<2)		/* entry has been saved */
583323Skas #define	MTOUCH		(1<<3)		/* entry has been noticed */
593323Skas #define	MPRESERVE	(1<<4)		/* keep entry in sys mailbox */
603323Skas #define	MMARK		(1<<5)		/* message is marked! */
613323Skas #define	MODIFY		(1<<6)		/* message has been modified */
623323Skas #define	MNEW		(1<<7)		/* message has never been seen */
633323Skas #define	MREAD		(1<<8)		/* message has been read sometime. */
643323Skas #define	MSTATUS		(1<<9)		/* message status has changed */
653323Skas #define	MBOX		(1<<10)		/* Send this to mbox, regardless */
661254Skas 
671254Skas /*
6831142Sedward  * Given a file address, determine the block number it represents.
6931142Sedward  */
7031142Sedward #define blockof(off)			((int) ((off) / 4096))
7131142Sedward #define offsetof(off)			((int) ((off) % 4096))
7231142Sedward #define positionof(block, offset)	((off_t)(block) * 4096 + (offset))
7331142Sedward 
7431142Sedward /*
751254Skas  * Format of the command description table.
761254Skas  * The actual table is declared and initialized
771254Skas  * in lex.c
781254Skas  */
791254Skas struct cmd {
801254Skas 	char	*c_name;		/* Name of command */
811254Skas 	int	(*c_func)();		/* Implementor of the command */
821254Skas 	short	c_argtype;		/* Type of arglist (see below) */
831254Skas 	short	c_msgflag;		/* Required flags of messages */
841254Skas 	short	c_msgmask;		/* Relevant flags of messages */
851254Skas };
861254Skas 
871254Skas /* Yechh, can't initialize unions */
881254Skas 
891254Skas #define	c_minargs c_msgflag		/* Minimum argcount for RAWLIST */
901254Skas #define	c_maxargs c_msgmask		/* Max argcount for RAWLIST */
911254Skas 
921254Skas /*
931254Skas  * Argument types.
941254Skas  */
951254Skas 
961254Skas #define	MSGLIST	 0		/* Message list type */
971254Skas #define	STRLIST	 1		/* A pure string */
981254Skas #define	RAWLIST	 2		/* Shell string list */
991254Skas #define	NOLIST	 3		/* Just plain 0 */
1001254Skas #define	NDMLIST	 4		/* Message list, no defaults */
1011254Skas 
1021254Skas #define	P	040		/* Autoprint dot after command */
1031254Skas #define	I	0100		/* Interactive command bit */
1044394Skurt #define	M	0200		/* Legal from send mode bit */
1051315Skas #define	W	0400		/* Illegal when read only bit */
1062064Skas #define	F	01000		/* Is a conditional command */
1071524Skas #define	T	02000		/* Is a transparent command */
1082119Skas #define	R	04000		/* Cannot be called from collect */
1091254Skas 
1101254Skas /*
1111254Skas  * Oft-used mask values
1121254Skas  */
1131254Skas 
1141254Skas #define	MMNORM		(MDELETED|MSAVED)/* Look at both save and delete bits */
1151254Skas #define	MMNDEL		MDELETED	/* Look only at deleted bit */
1161254Skas 
1171254Skas /*
1181254Skas  * Structure used to return a break down of a head
1191254Skas  * line (hats off to Bill Joy!)
1201254Skas  */
1211254Skas 
1221254Skas struct headline {
1231254Skas 	char	*l_from;	/* The name of the sender */
1241254Skas 	char	*l_tty;		/* His tty string (if any) */
1251254Skas 	char	*l_date;	/* The entire date string */
1261254Skas };
1271254Skas 
1281254Skas #define	GTO	1		/* Grab To: line */
1291254Skas #define	GSUBJECT 2		/* Likewise, Subject: line */
1301254Skas #define	GCC	4		/* And the Cc: line */
1311254Skas #define	GBCC	8		/* And also the Bcc: line */
1321254Skas #define	GMASK	(GTO|GSUBJECT|GCC|GBCC)
1331254Skas 				/* Mask of places from whence */
1341254Skas 
1351254Skas #define	GNL	16		/* Print blank line after */
1361254Skas #define	GDEL	32		/* Entity removed from list */
1371254Skas #define	GCOMMA	64		/* detract puts in commas */
1381254Skas 
1391254Skas /*
1401254Skas  * Structure used to pass about the current
1411254Skas  * state of the user-typed message header.
1421254Skas  */
1431254Skas 
1441254Skas struct header {
14534800Sedward 	struct name *h_to;		/* Dynamic "To:" string */
14634800Sedward 	char *h_subject;		/* Subject string */
14734800Sedward 	struct name *h_cc;		/* Carbon copies string */
14834800Sedward 	struct name *h_bcc;		/* Blind carbon copies */
14934800Sedward 	struct name *h_smopts;		/* Sendmail options */
1501254Skas };
1511254Skas 
1521254Skas /*
1531254Skas  * Structure of namelist nodes used in processing
1541254Skas  * the recipients of mail and aliases and all that
1551254Skas  * kind of stuff.
1561254Skas  */
1571254Skas 
1581254Skas struct name {
1591254Skas 	struct	name *n_flink;		/* Forward link in list. */
1601254Skas 	struct	name *n_blink;		/* Backward list link */
1611254Skas 	short	n_type;			/* From which list it came */
1621254Skas 	char	*n_name;		/* This fella's name */
1631254Skas };
1641254Skas 
1651254Skas /*
1661254Skas  * Structure of a variable node.  All variables are
1671254Skas  * kept on a singly-linked list of these, rooted by
1681254Skas  * "variables"
1691254Skas  */
1701254Skas 
1711254Skas struct var {
1721254Skas 	struct	var *v_link;		/* Forward link to next variable */
1731254Skas 	char	*v_name;		/* The variable's name */
1741254Skas 	char	*v_value;		/* And it's current value */
1751254Skas };
1761254Skas 
1771254Skas struct group {
1781254Skas 	struct	group *ge_link;		/* Next person in this group */
1791254Skas 	char	*ge_name;		/* This person's user name */
1801254Skas };
1811254Skas 
1821254Skas struct grouphead {
1831254Skas 	struct	grouphead *g_link;	/* Next grouphead in list */
1841254Skas 	char	*g_name;		/* Name of this group */
1851254Skas 	struct	group *g_list;		/* Users in group. */
1861254Skas };
1871254Skas 
1881254Skas #define	NIL	((struct name *) 0)	/* The nil pointer for namelists */
1891254Skas #define	NONE	((struct cmd *) 0)	/* The nil pointer to command tab */
1901254Skas #define	NOVAR	((struct var *) 0)	/* The nil pointer to variables */
1911254Skas #define	NOGRP	((struct grouphead *) 0)/* The nil grouphead pointer */
1921254Skas #define	NOGE	((struct group *) 0)	/* The nil group pointer */
1931254Skas 
1941254Skas /*
1957576Skurt  * Structure of the hash table of ignored header fields
1967576Skurt  */
19734692Sedward struct ignoretab {
19834692Sedward 	int i_count;			/* Number of entries */
19934692Sedward 	struct ignore {
20034692Sedward 		struct ignore *i_link;	/* Next ignored field in bucket */
20134692Sedward 		char *i_field;		/* This ignored field */
20234692Sedward 	} *i_head[HSHSIZE];
2037576Skurt };
2047576Skurt 
2057576Skurt /*
2061254Skas  * Token values returned by the scanner used for argument lists.
2071254Skas  * Also, sizes of scanner-related things.
2081254Skas  */
2091254Skas 
2101254Skas #define	TEOL	0			/* End of the command line */
2111254Skas #define	TNUMBER	1			/* A message number */
2121254Skas #define	TDASH	2			/* A simple dash */
2131254Skas #define	TSTRING	3			/* A string (possibly containing -) */
2141254Skas #define	TDOT	4			/* A "." */
2151254Skas #define	TUP	5			/* An "^" */
2161254Skas #define	TDOLLAR	6			/* A "$" */
2171254Skas #define	TSTAR	7			/* A "*" */
2181254Skas #define	TOPEN	8			/* An '(' */
2191254Skas #define	TCLOSE	9			/* A ')' */
2201254Skas #define TPLUS	10			/* A '+' */
22135376Sedward #define TERROR	11			/* A lexical error */
2221254Skas 
2231254Skas #define	REGDEP	2			/* Maximum regret depth. */
22425375Sserge #define	STRINGLEN	1024		/* Maximum length of string token */
2251254Skas 
2261254Skas /*
2271524Skas  * Constants for conditional commands.  These describe whether
2281524Skas  * we should be executing stuff or not.
2291524Skas  */
2301524Skas 
2311524Skas #define	CANY		0		/* Execute in send or receive mode */
2321524Skas #define	CRCV		1		/* Execute in receive mode only */
2331524Skas #define	CSEND		2		/* Execute in send mode only */
2341524Skas 
2351524Skas /*
2361254Skas  * Kludges to handle the change from setexit / reset to setjmp / longjmp
2371254Skas  */
2381254Skas 
2391254Skas #define	setexit()	setjmp(srbuf)
2401254Skas #define	reset(x)	longjmp(srbuf, x)
2411254Skas 
2421254Skas /*
24313132Ssam  * Truncate a file to the last character written. This is
24413132Ssam  * useful just before closing an old file that was opened
24513132Ssam  * for read/write.
24613132Ssam  */
24766428Sbostic #define trunc(stream) {							\
24866428Sbostic 	(void)fflush(stream); 						\
24966428Sbostic 	(void)ftruncate(fileno(stream), (long)ftell(stream));		\
25066428Sbostic }
251