Home | History | Annotate | Line # | Download | only in mail
def.h revision 1.20
      1  1.20  christos /*	$NetBSD: def.h,v 1.20 2006/10/21 21:37:20 christos Exp $	*/
      2   1.1       cgd /*
      3   1.6   deraadt  * Copyright (c) 1980, 1993
      4   1.6   deraadt  *	The Regents of the University of California.  All rights reserved.
      5   1.1       cgd  *
      6   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      7   1.1       cgd  * modification, are permitted provided that the following conditions
      8   1.1       cgd  * are met:
      9   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     10   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     11   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     13   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     14  1.16       agc  * 3. Neither the name of the University nor the names of its contributors
     15   1.1       cgd  *    may be used to endorse or promote products derived from this software
     16   1.1       cgd  *    without specific prior written permission.
     17   1.1       cgd  *
     18   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     19   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     20   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     21   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     22   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     24   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     26   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28   1.1       cgd  * SUCH DAMAGE.
     29   1.1       cgd  *
     30   1.9       tls  *	@(#)def.h	8.4 (Berkeley) 4/20/95
     31  1.20  christos  *	$NetBSD: def.h,v 1.20 2006/10/21 21:37:20 christos Exp $
     32   1.1       cgd  */
     33   1.1       cgd 
     34   1.1       cgd /*
     35   1.1       cgd  * Mail -- a mail program
     36   1.1       cgd  *
     37   1.1       cgd  * Author: Kurt Shoens (UCB) March 25, 1978
     38   1.1       cgd  */
     39   1.1       cgd 
     40  1.10     lukem #include <sys/types.h>
     41  1.10     lukem #include <sys/file.h>
     42  1.10     lukem #include <sys/ioctl.h>
     43  1.10     lukem #include <sys/stat.h>
     44   1.6   deraadt #include <sys/param.h>
     45   1.6   deraadt #include <sys/time.h>
     46  1.10     lukem #include <sys/wait.h>
     47   1.6   deraadt 
     48  1.10     lukem #include <ctype.h>
     49  1.10     lukem #include <err.h>
     50  1.10     lukem #include <errno.h>
     51  1.10     lukem #include <fcntl.h>
     52  1.10     lukem #include <paths.h>
     53  1.10     lukem #include <pwd.h>
     54   1.6   deraadt #include <signal.h>
     55  1.10     lukem #include <stdio.h>
     56  1.10     lukem #include <stdlib.h>
     57  1.10     lukem #include <string.h>
     58   1.7   mycroft #include <termios.h>
     59  1.11    kleink #include <time.h>
     60   1.6   deraadt #include <unistd.h>
     61   1.6   deraadt #include "pathnames.h"
     62   1.6   deraadt 
     63   1.1       cgd #define	APPEND				/* New mail goes to end of mailbox */
     64   1.1       cgd 
     65   1.1       cgd #define	ESCAPE		'~'		/* Default escape for sending */
     66   1.1       cgd #define	NMLSIZE		1024		/* max names in a message list */
     67   1.1       cgd #define	PATHSIZE	MAXPATHLEN	/* Size of pathnames throughout */
     68   1.1       cgd #define	HSHSIZE		59		/* Hash size for aliases and vars */
     69   1.1       cgd #define	LINESIZE	BUFSIZ		/* max readable line width */
     70   1.1       cgd #define	STRINGSIZE	((unsigned) 128)/* Dynamic allocation units */
     71   1.1       cgd #define	MAXARGC		1024		/* Maximum list of raw strings */
     72   1.1       cgd #define	MAXEXP		25		/* Maximum expansion of aliases */
     73   1.1       cgd 
     74   1.1       cgd #define	equal(a, b)	(strcmp(a,b)==0)/* A nice function to string compare */
     75   1.1       cgd 
     76  1.20  christos #define readline mail_readline
     77  1.20  christos 
     78   1.1       cgd struct message {
     79   1.1       cgd 	short	m_flag;			/* flags, see below */
     80  1.18  christos 	short	m_offset;		/* offset in block of message */
     81   1.9       tls 	long	m_block;		/* block number of this message */
     82   1.9       tls 	long	m_lines;		/* Lines in the message */
     83  1.18  christos 	off_t	m_size;			/* Bytes in the message */
     84  1.15      ross 	long	m_blines;		/* Body (non-header) lines */
     85   1.1       cgd };
     86  1.20  christos typedef struct mime_info mime_info_t;	/* phantom structure only to attach.c */
     87   1.1       cgd 
     88   1.1       cgd /*
     89   1.1       cgd  * flag bits.
     90   1.1       cgd  */
     91   1.1       cgd 
     92   1.1       cgd #define	MUSED		(1<<0)		/* entry is used, but this bit isn't */
     93   1.1       cgd #define	MDELETED	(1<<1)		/* entry has been deleted */
     94   1.1       cgd #define	MSAVED		(1<<2)		/* entry has been saved */
     95   1.1       cgd #define	MTOUCH		(1<<3)		/* entry has been noticed */
     96   1.1       cgd #define	MPRESERVE	(1<<4)		/* keep entry in sys mailbox */
     97   1.1       cgd #define	MMARK		(1<<5)		/* message is marked! */
     98   1.1       cgd #define	MODIFY		(1<<6)		/* message has been modified */
     99   1.1       cgd #define	MNEW		(1<<7)		/* message has never been seen */
    100   1.1       cgd #define	MREAD		(1<<8)		/* message has been read sometime. */
    101   1.1       cgd #define	MSTATUS		(1<<9)		/* message status has changed */
    102   1.1       cgd #define	MBOX		(1<<10)		/* Send this to mbox, regardless */
    103   1.1       cgd 
    104   1.1       cgd /*
    105   1.1       cgd  * Given a file address, determine the block number it represents.
    106   1.1       cgd  */
    107   1.1       cgd #define blockof(off)			((int) ((off) / 4096))
    108   1.1       cgd #define offsetof(off)			((int) ((off) % 4096))
    109   1.1       cgd #define positionof(block, offset)	((off_t)(block) * 4096 + (offset))
    110   1.1       cgd 
    111   1.1       cgd /*
    112   1.1       cgd  * Format of the command description table.
    113   1.1       cgd  * The actual table is declared and initialized
    114   1.1       cgd  * in lex.c
    115   1.1       cgd  */
    116   1.1       cgd struct cmd {
    117  1.17  christos 	const char *c_name;		/* Name of command */
    118  1.12       wiz 	int	(*c_func)(void *);	/* Implementor of the command */
    119  1.20  christos #ifdef USE_EDITLINE
    120  1.19  christos 	const char *c_complete;		/* String describing completion */
    121  1.19  christos #endif
    122   1.1       cgd 	short	c_argtype;		/* Type of arglist (see below) */
    123   1.1       cgd 	short	c_msgflag;		/* Required flags of messages */
    124   1.1       cgd 	short	c_msgmask;		/* Relevant flags of messages */
    125   1.1       cgd };
    126   1.1       cgd 
    127   1.1       cgd /* Yechh, can't initialize unions */
    128   1.1       cgd 
    129   1.1       cgd #define	c_minargs c_msgflag		/* Minimum argcount for RAWLIST */
    130   1.1       cgd #define	c_maxargs c_msgmask		/* Max argcount for RAWLIST */
    131   1.1       cgd 
    132   1.1       cgd /*
    133   1.1       cgd  * Argument types.
    134   1.1       cgd  */
    135   1.1       cgd 
    136   1.1       cgd #define	MSGLIST	 0		/* Message list type */
    137   1.1       cgd #define	STRLIST	 1		/* A pure string */
    138   1.1       cgd #define	RAWLIST	 2		/* Shell string list */
    139   1.1       cgd #define	NOLIST	 3		/* Just plain 0 */
    140   1.1       cgd #define	NDMLIST	 4		/* Message list, no defaults */
    141   1.1       cgd 
    142   1.1       cgd #define	P	040		/* Autoprint dot after command */
    143   1.1       cgd #define	I	0100		/* Interactive command bit */
    144   1.1       cgd #define	M	0200		/* Legal from send mode bit */
    145   1.1       cgd #define	W	0400		/* Illegal when read only bit */
    146   1.1       cgd #define	F	01000		/* Is a conditional command */
    147   1.1       cgd #define	T	02000		/* Is a transparent command */
    148   1.1       cgd #define	R	04000		/* Cannot be called from collect */
    149   1.1       cgd 
    150   1.1       cgd /*
    151   1.1       cgd  * Oft-used mask values
    152   1.1       cgd  */
    153   1.1       cgd 
    154   1.1       cgd #define	MMNORM		(MDELETED|MSAVED)/* Look at both save and delete bits */
    155   1.1       cgd #define	MMNDEL		MDELETED	/* Look only at deleted bit */
    156   1.1       cgd 
    157   1.1       cgd /*
    158   1.1       cgd  * Structure used to return a break down of a head
    159   1.1       cgd  * line (hats off to Bill Joy!)
    160   1.1       cgd  */
    161   1.1       cgd 
    162   1.1       cgd struct headline {
    163   1.1       cgd 	char	*l_from;	/* The name of the sender */
    164   1.1       cgd 	char	*l_tty;		/* His tty string (if any) */
    165   1.1       cgd 	char	*l_date;	/* The entire date string */
    166   1.1       cgd };
    167   1.1       cgd 
    168  1.19  christos #define	GTO	 0x001		/* Grab To: line */
    169  1.19  christos #define	GSUBJECT 0x002		/* Likewise, Subject: line */
    170  1.19  christos #define	GCC	 0x004		/* And the Cc: line */
    171  1.19  christos #define	GBCC	 0x008		/* And also the Bcc: line */
    172  1.19  christos #define GSMOPTS  0x010		/* Grab the sendmail options */
    173  1.20  christos #ifdef MIME_SUPPORT
    174  1.20  christos #define GMIME    0x020		/* mime flag */
    175  1.20  christos #endif
    176  1.19  christos #define	GMASK	(GTO|GSUBJECT|GCC|GBCC|GSMOPTS)
    177   1.1       cgd 				/* Mask of places from whence */
    178   1.1       cgd 
    179  1.19  christos #define	GNL	 0x100		/* Print blank line after */
    180  1.19  christos #define	GDEL	 0x200		/* Entity removed from list */
    181  1.19  christos #define	GCOMMA	 0x400		/* detract puts in commas */
    182   1.1       cgd 
    183  1.20  christos #ifdef MIME_SUPPORT
    184  1.20  christos /*
    185  1.20  christos  * Structure of MIME content.
    186  1.20  christos  */
    187  1.20  christos struct Content {
    188  1.20  christos 	const char *C_type;		/* content type */
    189  1.20  christos 	const char *C_encoding;		/* content transfer encoding */
    190  1.20  christos 	const char *C_disposition;	/* content disposition */
    191  1.20  christos 	const char *C_description;	/* content description */
    192  1.20  christos 	const char *C_id;		/* content id */
    193  1.20  christos };
    194  1.20  christos /* Header strings corresponding to the above Content fields. */
    195  1.20  christos #define MIME_HDR_TYPE		"Content-Type"
    196  1.20  christos #define MIME_HDR_ENCODING	"Content-Transfer-Encoding"
    197  1.20  christos #define MIME_HDR_DISPOSITION	"Content-Disposition"
    198  1.20  christos #define MIME_HDR_ID		"Content-ID"
    199  1.20  christos #define MIME_HDR_DESCRIPTION	"Content-Description"
    200  1.20  christos #define MIME_HDR_VERSION	"MIME-Version"
    201  1.20  christos /* the value of the MIME-Version field */
    202  1.20  christos #define MIME_VERSION		"1.0"
    203  1.20  christos 
    204  1.20  christos typedef enum {
    205  1.20  christos 	ATTACH_INVALID = 0,	/* do not use! */
    206  1.20  christos 	ATTACH_FNAME = 1,
    207  1.20  christos 	ATTACH_MSG = 2,
    208  1.20  christos 	ATTACH_FILENO = 3
    209  1.20  christos } attach_t;
    210  1.20  christos 
    211  1.20  christos /*
    212  1.20  christos  * Structure of a MIME attachment.
    213  1.20  christos  */
    214  1.20  christos struct attachment {
    215  1.20  christos 	struct attachment *a_flink;	/* Forward link in list. */
    216  1.20  christos 	struct attachment *a_blink;	/* Backward list link */
    217  1.20  christos 
    218  1.20  christos 	attach_t a_type;		/* attachment type */
    219  1.20  christos #if 1
    220  1.20  christos 	union {
    221  1.20  christos 		char *u_name;		/* file name */
    222  1.20  christos 		struct message *u_msg;	/* message */
    223  1.20  christos 		int u_fileno;		/* file number */
    224  1.20  christos 	} a_u;
    225  1.20  christos 
    226  1.20  christos 	#define a_name		a_u.u_name
    227  1.20  christos 	#define a_msg		a_u.u_msg
    228  1.20  christos 	#define a_fileno	a_u.u_fileno
    229  1.20  christos #else
    230  1.20  christos 	char *a_name;			/* file name */
    231  1.20  christos 	struct message *a_msg;		/* message */
    232  1.20  christos 	int a_fileno;			/* file number */
    233  1.20  christos #endif
    234  1.20  christos 
    235  1.20  christos 	struct Content a_Content;	/* MIME content strings */
    236  1.20  christos };
    237  1.20  christos #endif /* MIME_SUPPORT */
    238  1.20  christos 
    239   1.1       cgd /*
    240   1.1       cgd  * Structure used to pass about the current
    241   1.1       cgd  * state of the user-typed message header.
    242   1.1       cgd  */
    243   1.1       cgd 
    244   1.1       cgd struct header {
    245   1.1       cgd 	struct name *h_to;		/* Dynamic "To:" string */
    246   1.1       cgd 	char *h_subject;		/* Subject string */
    247   1.1       cgd 	struct name *h_cc;		/* Carbon copies string */
    248   1.1       cgd 	struct name *h_bcc;		/* Blind carbon copies */
    249   1.1       cgd 	struct name *h_smopts;		/* Sendmail options */
    250  1.20  christos #ifdef MIME_SUPPORT
    251  1.20  christos 	char *h_mime_boundary;		/* MIME multipart boundary string */
    252  1.20  christos 	struct Content h_Content;	/* MIME content for message */
    253  1.20  christos 	struct attachment *h_attach;	/* MIME attachments */
    254  1.20  christos #endif
    255   1.1       cgd };
    256   1.1       cgd 
    257   1.1       cgd /*
    258   1.1       cgd  * Structure of namelist nodes used in processing
    259   1.1       cgd  * the recipients of mail and aliases and all that
    260   1.1       cgd  * kind of stuff.
    261   1.1       cgd  */
    262   1.1       cgd 
    263   1.1       cgd struct name {
    264   1.1       cgd 	struct	name *n_flink;		/* Forward link in list. */
    265   1.1       cgd 	struct	name *n_blink;		/* Backward list link */
    266   1.1       cgd 	short	n_type;			/* From which list it came */
    267   1.1       cgd 	char	*n_name;		/* This fella's name */
    268   1.1       cgd };
    269   1.1       cgd 
    270   1.1       cgd /*
    271   1.1       cgd  * Structure of a variable node.  All variables are
    272   1.1       cgd  * kept on a singly-linked list of these, rooted by
    273   1.1       cgd  * "variables"
    274   1.1       cgd  */
    275   1.1       cgd 
    276   1.1       cgd struct var {
    277   1.1       cgd 	struct	var *v_link;		/* Forward link to next variable */
    278   1.1       cgd 	char	*v_name;		/* The variable's name */
    279   1.1       cgd 	char	*v_value;		/* And it's current value */
    280   1.1       cgd };
    281   1.1       cgd 
    282   1.1       cgd struct group {
    283   1.1       cgd 	struct	group *ge_link;		/* Next person in this group */
    284   1.1       cgd 	char	*ge_name;		/* This person's user name */
    285   1.1       cgd };
    286   1.1       cgd 
    287   1.1       cgd struct grouphead {
    288   1.1       cgd 	struct	grouphead *g_link;	/* Next grouphead in list */
    289   1.1       cgd 	char	*g_name;		/* Name of this group */
    290   1.1       cgd 	struct	group *g_list;		/* Users in group. */
    291   1.1       cgd };
    292   1.1       cgd 
    293   1.1       cgd /*
    294   1.1       cgd  * Structure of the hash table of ignored header fields
    295   1.1       cgd  */
    296   1.1       cgd struct ignoretab {
    297  1.18  christos 	size_t i_count;			/* Number of entries */
    298   1.1       cgd 	struct ignore {
    299   1.1       cgd 		struct ignore *i_link;	/* Next ignored field in bucket */
    300   1.1       cgd 		char *i_field;		/* This ignored field */
    301   1.1       cgd 	} *i_head[HSHSIZE];
    302   1.1       cgd };
    303   1.1       cgd 
    304   1.1       cgd /*
    305   1.1       cgd  * Token values returned by the scanner used for argument lists.
    306   1.1       cgd  * Also, sizes of scanner-related things.
    307   1.1       cgd  */
    308   1.1       cgd 
    309   1.1       cgd #define	TEOL	0			/* End of the command line */
    310   1.1       cgd #define	TNUMBER	1			/* A message number */
    311   1.1       cgd #define	TDASH	2			/* A simple dash */
    312   1.1       cgd #define	TSTRING	3			/* A string (possibly containing -) */
    313   1.1       cgd #define	TDOT	4			/* A "." */
    314   1.1       cgd #define	TUP	5			/* An "^" */
    315   1.1       cgd #define	TDOLLAR	6			/* A "$" */
    316   1.1       cgd #define	TSTAR	7			/* A "*" */
    317   1.1       cgd #define	TOPEN	8			/* An '(' */
    318   1.1       cgd #define	TCLOSE	9			/* A ')' */
    319   1.1       cgd #define TPLUS	10			/* A '+' */
    320   1.1       cgd #define TERROR	11			/* A lexical error */
    321   1.1       cgd 
    322   1.1       cgd #define	REGDEP	2			/* Maximum regret depth. */
    323   1.1       cgd #define	STRINGLEN	1024		/* Maximum length of string token */
    324   1.1       cgd 
    325   1.1       cgd /*
    326   1.1       cgd  * Constants for conditional commands.  These describe whether
    327   1.1       cgd  * we should be executing stuff or not.
    328   1.1       cgd  */
    329   1.1       cgd 
    330   1.1       cgd #define	CANY		0		/* Execute in send or receive mode */
    331   1.1       cgd #define	CRCV		1		/* Execute in receive mode only */
    332   1.1       cgd #define	CSEND		2		/* Execute in send mode only */
    333   1.1       cgd 
    334   1.1       cgd /*
    335   1.1       cgd  * Kludges to handle the change from setexit / reset to setjmp / longjmp
    336   1.1       cgd  */
    337   1.1       cgd 
    338  1.18  christos #define	setexit()	(void)setjmp(srbuf)
    339   1.1       cgd #define	reset(x)	longjmp(srbuf, x)
    340   1.1       cgd 
    341   1.1       cgd /*
    342   1.1       cgd  * Truncate a file to the last character written. This is
    343   1.1       cgd  * useful just before closing an old file that was opened
    344   1.1       cgd  * for read/write.
    345   1.1       cgd  */
    346   1.6   deraadt #define trunc(stream) {							\
    347   1.6   deraadt 	(void)fflush(stream); 						\
    348   1.6   deraadt 	(void)ftruncate(fileno(stream), (off_t)ftell(stream));		\
    349   1.4       cgd }
    350  1.20  christos 
    351  1.20  christos /*
    352  1.20  christos  * Make this static inline available everywhere.
    353  1.20  christos  */
    354  1.20  christos static inline char*
    355  1.20  christos skip_white(char *cp)
    356  1.20  christos {
    357  1.20  christos 	while (isblank((unsigned char)*cp))
    358  1.20  christos 		cp++;
    359  1.20  christos 	return cp;
    360  1.20  christos }
    361