/* $OpenBSD: def.h,v 1.8 1996/06/08 19:48:18 christos Exp $ */1/* $NetBSD: def.h,v 1.8 1996/06/08 19:48:18 christos Exp $ */2/*3* Copyright (c) 1980, 19934* The Regents of the University of California. All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. All advertising materials mentioning features or use of this software15* must display the following acknowledgement:16* This product includes software developed by the University of17* California, Berkeley and its contributors.18* 4. Neither the name of the University nor the names of its contributors19* may be used to endorse or promote products derived from this software20* without specific prior written permission.21*22* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND23* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32* SUCH DAMAGE.33*34* @(#)def.h 8.2 (Berkeley) 3/21/9435* $NetBSD: def.h,v 1.8 1996/06/08 19:48:18 christos Exp $36*/3738/*39* Mail -- a mail program40*41* Author: Kurt Shoens (UCB) March 25, 197842*/4344#include <sys/param.h>45#include <sys/stat.h>46#include <sys/time.h>4748#include <signal.h>49#include <termios.h>50#include <unistd.h>51#include <stdlib.h>52#include <stdio.h>53#include <ctype.h>54#include <string.h>55#include "pathnames.h"5657#define APPEND /* New mail goes to end of mailbox */5859#define ESCAPE '~' /* Default escape for sending */60#define NMLSIZE 1024 /* max names in a message list */61#define PATHSIZE MAXPATHLEN /* Size of pathnames throughout */62#define HSHSIZE 59 /* Hash size for aliases and vars */63#define LINESIZE BUFSIZ /* max readable line width */64#define STRINGSIZE ((unsigned) 128)/* Dynamic allocation units */65#define MAXARGC 1024 /* Maximum list of raw strings */66#define NOSTR ((char *) 0) /* Null string pointer */67#define MAXEXP 25 /* Maximum expansion of aliases */6869#define equal(a, b) (strcmp(a,b)==0)/* A nice function to string compare */7071struct message {72short m_flag; /* flags, see below */73short m_block; /* block number of this message */74short m_offset; /* offset in block of message */75long m_size; /* Bytes in the message */76short m_lines; /* Lines in the message */77};7879/*80* flag bits.81*/8283#define MUSED (1<<0) /* entry is used, but this bit isn't */84#define MDELETED (1<<1) /* entry has been deleted */85#define MSAVED (1<<2) /* entry has been saved */86#define MTOUCH (1<<3) /* entry has been noticed */87#define MPRESERVE (1<<4) /* keep entry in sys mailbox */88#define MMARK (1<<5) /* message is marked! */89#define MODIFY (1<<6) /* message has been modified */90#define MNEW (1<<7) /* message has never been seen */91#define MREAD (1<<8) /* message has been read sometime. */92#define MSTATUS (1<<9) /* message status has changed */93#define MBOX (1<<10) /* Send this to mbox, regardless */9495/*96* Given a file address, determine the block number it represents.97*/98#define blockof(off) ((int) ((off) / 4096))99#define offsetof(off) ((int) ((off) % 4096))100#define positionof(block, offset) ((off_t)(block) * 4096 + (offset))101102/*103* Format of the command description table.104* The actual table is declared and initialized105* in lex.c106*/107struct cmd {108char *c_name; /* Name of command */109int (*c_func) __P((void *));/* Implementor of the command */110short c_argtype; /* Type of arglist (see below) */111short c_msgflag; /* Required flags of messages */112short c_msgmask; /* Relevant flags of messages */113};114115/* Yechh, can't initialize unions */116117#define c_minargs c_msgflag /* Minimum argcount for RAWLIST */118#define c_maxargs c_msgmask /* Max argcount for RAWLIST */119120/*121* Argument types.122*/123124#define MSGLIST 0 /* Message list type */125#define STRLIST 1 /* A pure string */126#define RAWLIST 2 /* Shell string list */127#define NOLIST 3 /* Just plain 0 */128#define NDMLIST 4 /* Message list, no defaults */129130#define P 040 /* Autoprint dot after command */131#define I 0100 /* Interactive command bit */132#define M 0200 /* Legal from send mode bit */133#define W 0400 /* Illegal when read only bit */134#define F 01000 /* Is a conditional command */135#define T 02000 /* Is a transparent command */136#define R 04000 /* Cannot be called from collect */137138/*139* Oft-used mask values140*/141142#define MMNORM (MDELETED|MSAVED)/* Look at both save and delete bits */143#define MMNDEL MDELETED /* Look only at deleted bit */144145/*146* Structure used to return a break down of a head147* line (hats off to Bill Joy!)148*/149150struct headline {151char *l_from; /* The name of the sender */152char *l_tty; /* His tty string (if any) */153char *l_date; /* The entire date string */154};155156#define GTO 1 /* Grab To: line */157#define GSUBJECT 2 /* Likewise, Subject: line */158#define GCC 4 /* And the Cc: line */159#define GBCC 8 /* And also the Bcc: line */160#define GMASK (GTO|GSUBJECT|GCC|GBCC)161/* Mask of places from whence */162163#define GNL 16 /* Print blank line after */164#define GDEL 32 /* Entity removed from list */165#define GCOMMA 64 /* detract puts in commas */166167/*168* Structure used to pass about the current169* state of the user-typed message header.170*/171172struct header {173struct name *h_to; /* Dynamic "To:" string */174char *h_subject; /* Subject string */175struct name *h_cc; /* Carbon copies string */176struct name *h_bcc; /* Blind carbon copies */177struct name *h_smopts; /* Sendmail options */178};179180/*181* Structure of namelist nodes used in processing182* the recipients of mail and aliases and all that183* kind of stuff.184*/185186struct name {187struct name *n_flink; /* Forward link in list. */188struct name *n_blink; /* Backward list link */189short n_type; /* From which list it came */190char *n_name; /* This fella's name */191};192193/*194* Structure of a variable node. All variables are195* kept on a singly-linked list of these, rooted by196* "variables"197*/198199struct var {200struct var *v_link; /* Forward link to next variable */201char *v_name; /* The variable's name */202char *v_value; /* And it's current value */203};204205struct group {206struct group *ge_link; /* Next person in this group */207char *ge_name; /* This person's user name */208};209210struct grouphead {211struct grouphead *g_link; /* Next grouphead in list */212char *g_name; /* Name of this group */213struct group *g_list; /* Users in group. */214};215216#define NIL ((struct name *) 0) /* The nil pointer for namelists */217#define NONE ((struct cmd *) 0) /* The nil pointer to command tab */218#define NOVAR ((struct var *) 0) /* The nil pointer to variables */219#define NOGRP ((struct grouphead *) 0)/* The nil grouphead pointer */220#define NOGE ((struct group *) 0) /* The nil group pointer */221222/*223* Structure of the hash table of ignored header fields224*/225struct ignoretab {226int i_count; /* Number of entries */227struct ignore {228struct ignore *i_link; /* Next ignored field in bucket */229char *i_field; /* This ignored field */230} *i_head[HSHSIZE];231};232233/*234* Token values returned by the scanner used for argument lists.235* Also, sizes of scanner-related things.236*/237238#define TEOL 0 /* End of the command line */239#define TNUMBER 1 /* A message number */240#define TDASH 2 /* A simple dash */241#define TSTRING 3 /* A string (possibly containing -) */242#define TDOT 4 /* A "." */243#define TUP 5 /* An "^" */244#define TDOLLAR 6 /* A "$" */245#define TSTAR 7 /* A "*" */246#define TOPEN 8 /* An '(' */247#define TCLOSE 9 /* A ')' */248#define TPLUS 10 /* A '+' */249#define TERROR 11 /* A lexical error */250251#define REGDEP 2 /* Maximum regret depth. */252#define STRINGLEN 1024 /* Maximum length of string token */253254/*255* Constants for conditional commands. These describe whether256* we should be executing stuff or not.257*/258259#define CANY 0 /* Execute in send or receive mode */260#define CRCV 1 /* Execute in receive mode only */261#define CSEND 2 /* Execute in send mode only */262263/*264* Kludges to handle the change from setexit / reset to setjmp / longjmp265*/266267#define setexit() setjmp(srbuf)268#define reset(x) longjmp(srbuf, x)269270/*271* Truncate a file to the last character written. This is272* useful just before closing an old file that was opened273* for read/write.274*/275#define trunc(stream) { \276(void)fflush(stream); \277(void)ftruncate(fileno(stream), (off_t)ftell(stream)); \278}279280281