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