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 * 4. Neither the name of the University nor the names of its contributors 141590Srgrimes * may be used to endorse or promote products derived from this software 151590Srgrimes * without specific prior written permission. 161590Srgrimes * 171590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201590Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271590Srgrimes * SUCH DAMAGE. 281590Srgrimes * 2988150Smikeh * @(#)def.h 8.4 (Berkeley) 4/20/95 3067496Sphk * 3167496Sphk * $FreeBSD$ 321590Srgrimes */ 331590Srgrimes 341590Srgrimes/* 351590Srgrimes * Mail -- a mail program 361590Srgrimes * 371590Srgrimes * Author: Kurt Shoens (UCB) March 25, 1978 381590Srgrimes */ 391590Srgrimes 401590Srgrimes#include <sys/param.h> 411590Srgrimes#include <sys/stat.h> 421590Srgrimes 4377274Smikeh#include <ctype.h> 4477274Smikeh#include <err.h> 4577274Smikeh#include <paths.h> 461590Srgrimes#include <signal.h> 4777274Smikeh#include <stdio.h> 4877274Smikeh#include <stdlib.h> 4977274Smikeh#include <string.h> 5017678Speter#include <termios.h> 5177274Smikeh#include <time.h> 521590Srgrimes#include <unistd.h> 5377274Smikeh 541590Srgrimes#include "pathnames.h" 551590Srgrimes 561590Srgrimes#define APPEND /* New mail goes to end of mailbox */ 571590Srgrimes 581590Srgrimes#define ESCAPE '~' /* Default escape for sending */ 591590Srgrimes#define NMLSIZE 1024 /* max names in a message list */ 601590Srgrimes#define PATHSIZE MAXPATHLEN /* Size of pathnames throughout */ 611590Srgrimes#define HSHSIZE 59 /* Hash size for aliases and vars */ 621590Srgrimes#define LINESIZE BUFSIZ /* max readable line width */ 6377274Smikeh#define STRINGSIZE ((unsigned)128) /* Dynamic allocation units */ 641590Srgrimes#define MAXARGC 1024 /* Maximum list of raw strings */ 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_offset; /* offset in block of message */ 728387Sache long m_block; /* block number of this message */ 731590Srgrimes long m_size; /* Bytes in the message */ 748387Sache long 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 */ 9677274Smikeh#define blockof(off) ((int)((off) / 4096)) 9777274Smikeh#define boffsetof(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 { 10677274Smikeh const 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 */ 15832189Sjoerg#define GREPLYTO 0x10 /* And the Reply-To: line */ 15932189Sjoerg#define GINREPLYTO 0x20 /* The In-Reply-To: line */ 16032189Sjoerg#define GMASK (GTO|GSUBJECT|GCC|GBCC|GREPLYTO|GINREPLYTO) 1611590Srgrimes /* Mask of places from whence */ 1621590Srgrimes 16332189Sjoerg#define GNL 0x40 /* Print blank line after */ 16432189Sjoerg#define GDEL 0x80 /* Entity removed from list */ 16532189Sjoerg#define GCOMMA 0x100 /* detract puts in commas */ 1661590Srgrimes 1671590Srgrimes/* 1681590Srgrimes * Structure used to pass about the current 1691590Srgrimes * state of the user-typed message header. 1701590Srgrimes */ 1711590Srgrimes 1721590Srgrimesstruct header { 17377274Smikeh struct name *h_bcc; /* Blind carbon copies */ 17477274Smikeh struct name *h_cc; /* Carbon copies string */ 17577274Smikeh struct name *h_smopts; /* Sendmail options */ 17677274Smikeh struct name *h_to; /* Dynamic "To:" string */ 17777274Smikeh char *h_inreplyto; /* Reference */ 17877274Smikeh char *h_replyto; /* Reply address */ 17977274Smikeh char *h_subject; /* Subject string */ 1801590Srgrimes}; 1811590Srgrimes 1821590Srgrimes/* 1831590Srgrimes * Structure of namelist nodes used in processing 1841590Srgrimes * the recipients of mail and aliases and all that 1851590Srgrimes * kind of stuff. 1861590Srgrimes */ 1871590Srgrimes 1881590Srgrimesstruct name { 1891590Srgrimes struct name *n_flink; /* Forward link in list. */ 1901590Srgrimes struct name *n_blink; /* Backward list link */ 1911590Srgrimes short n_type; /* From which list it came */ 1921590Srgrimes char *n_name; /* This fella's name */ 1931590Srgrimes}; 1941590Srgrimes 1951590Srgrimes/* 1961590Srgrimes * Structure of a variable node. All variables are 1971590Srgrimes * kept on a singly-linked list of these, rooted by 1981590Srgrimes * "variables" 1991590Srgrimes */ 2001590Srgrimes 2011590Srgrimesstruct var { 2021590Srgrimes struct var *v_link; /* Forward link to next variable */ 2031590Srgrimes char *v_name; /* The variable's name */ 2041590Srgrimes char *v_value; /* And it's current value */ 2051590Srgrimes}; 2061590Srgrimes 2071590Srgrimesstruct group { 2081590Srgrimes struct group *ge_link; /* Next person in this group */ 2091590Srgrimes char *ge_name; /* This person's user name */ 2101590Srgrimes}; 2111590Srgrimes 2121590Srgrimesstruct grouphead { 2131590Srgrimes struct grouphead *g_link; /* Next grouphead in list */ 2141590Srgrimes char *g_name; /* Name of this group */ 2151590Srgrimes struct group *g_list; /* Users in group. */ 2161590Srgrimes}; 2171590Srgrimes 2181590Srgrimes/* 2191590Srgrimes * Structure of the hash table of ignored header fields 2201590Srgrimes */ 2211590Srgrimesstruct ignoretab { 22277274Smikeh int i_count; /* Number of entries */ 22377274Smikeh struct ignore { 22477274Smikeh struct ignore *i_link; /* Next ignored field in bucket */ 22577274Smikeh char *i_field; /* This ignored field */ 2261590Srgrimes } *i_head[HSHSIZE]; 2271590Srgrimes}; 2281590Srgrimes 2291590Srgrimes/* 2301590Srgrimes * Token values returned by the scanner used for argument lists. 2311590Srgrimes * Also, sizes of scanner-related things. 2321590Srgrimes */ 2331590Srgrimes 2341590Srgrimes#define TEOL 0 /* End of the command line */ 2351590Srgrimes#define TNUMBER 1 /* A message number */ 2361590Srgrimes#define TDASH 2 /* A simple dash */ 2371590Srgrimes#define TSTRING 3 /* A string (possibly containing -) */ 2381590Srgrimes#define TDOT 4 /* A "." */ 2391590Srgrimes#define TUP 5 /* An "^" */ 2401590Srgrimes#define TDOLLAR 6 /* A "$" */ 2411590Srgrimes#define TSTAR 7 /* A "*" */ 2421590Srgrimes#define TOPEN 8 /* An '(' */ 2431590Srgrimes#define TCLOSE 9 /* A ')' */ 2441590Srgrimes#define TPLUS 10 /* A '+' */ 2451590Srgrimes#define TERROR 11 /* A lexical error */ 2461590Srgrimes 2471590Srgrimes#define REGDEP 2 /* Maximum regret depth. */ 2481590Srgrimes#define STRINGLEN 1024 /* Maximum length of string token */ 2491590Srgrimes 2501590Srgrimes/* 2511590Srgrimes * Constants for conditional commands. These describe whether 2521590Srgrimes * we should be executing stuff or not. 2531590Srgrimes */ 2541590Srgrimes 2551590Srgrimes#define CANY 0 /* Execute in send or receive mode */ 2561590Srgrimes#define CRCV 1 /* Execute in receive mode only */ 2571590Srgrimes#define CSEND 2 /* Execute in send mode only */ 2581590Srgrimes 2591590Srgrimes/* 2601590Srgrimes * Kludges to handle the change from setexit / reset to setjmp / longjmp 2611590Srgrimes */ 2621590Srgrimes 2631590Srgrimes#define setexit() setjmp(srbuf) 2641590Srgrimes#define reset(x) longjmp(srbuf, x) 2651590Srgrimes 2661590Srgrimes/* 2671590Srgrimes * Truncate a file to the last character written. This is 2681590Srgrimes * useful just before closing an old file that was opened 2691590Srgrimes * for read/write. 2701590Srgrimes */ 2711590Srgrimes#define trunc(stream) { \ 2721590Srgrimes (void)fflush(stream); \ 27377274Smikeh (void)ftruncate(fileno(stream), (off_t)ftell(stream)); \ 2741590Srgrimes} 275