Annotation of src/usr.bin/mail/def.h, Revision 1.14
1.14 ! deraadt 1: /* $OpenBSD: def.h,v 1.13 2003/06/25 15:13:32 millert Exp $ */
1.5 millert 2: /* $NetBSD: def.h,v 1.9 1996/12/28 07:11:00 tls Exp $ */
1.9 millert 3:
1.1 deraadt 4: /*
5: * Copyright (c) 1980, 1993
6: * The Regents of the University of California. All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
1.12 millert 16: * 3. Neither the name of the University nor the names of its contributors
1.1 deraadt 17: * may be used to endorse or promote products derived from this software
18: * without specific prior written permission.
19: *
20: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30: * SUCH DAMAGE.
31: *
1.5 millert 32: * @(#)def.h 8.4 (Berkeley) 4/20/95
1.14 ! deraadt 33: * $OpenBSD: def.h,v 1.13 2003/06/25 15:13:32 millert Exp $
1.1 deraadt 34: */
35:
36: /*
37: * Mail -- a mail program
38: *
39: * Author: Kurt Shoens (UCB) March 25, 1978
40: */
41:
1.7 millert 42: #ifndef MAIL_DEF_H
43: #define MAIL_DEF_H
44:
1.1 deraadt 45: #include <sys/stat.h>
46: #include <sys/time.h>
47:
1.5 millert 48: #include <ctype.h>
49: #include <err.h>
1.1 deraadt 50: #include <signal.h>
1.5 millert 51: #include <stdio.h>
52: #include <stdlib.h>
53: #include <string.h>
1.1 deraadt 54: #include <termios.h>
55: #include <unistd.h>
1.14 ! deraadt 56: #include <limits.h>
1.11 pjanzen 57: #include <vis.h>
1.1 deraadt 58: #include "pathnames.h"
59:
60: #define APPEND /* New mail goes to end of mailbox */
61:
62: #define ESCAPE '~' /* Default escape for sending */
63: #define NMLSIZE 1024 /* max names in a message list */
1.14 ! deraadt 64: #define PATHSIZE PATH_MAX /* Size of pathnames throughout */
1.1 deraadt 65: #define HSHSIZE 59 /* Hash size for aliases and vars */
66: #define LINESIZE BUFSIZ /* max readable line width */
67: #define STRINGSIZE ((unsigned) 128)/* Dynamic allocation units */
68: #define MAXARGC 1024 /* Maximum list of raw strings */
69: #define MAXEXP 25 /* Maximum expansion of aliases */
70:
71: #define equal(a, b) (strcmp(a,b)==0)/* A nice function to string compare */
72:
73: struct message {
74: short m_flag; /* flags, see below */
1.5 millert 75: int m_offset; /* offset in block of message */
1.4 millert 76: int m_block; /* block number of this message */
77: int m_size; /* Bytes in the message */
78: int m_lines; /* Lines in the message */
1.1 deraadt 79: };
80:
81: /*
82: * flag bits.
83: */
84: #define MUSED (1<<0) /* entry is used, but this bit isn't */
85: #define MDELETED (1<<1) /* entry has been deleted */
86: #define MSAVED (1<<2) /* entry has been saved */
87: #define MTOUCH (1<<3) /* entry has been noticed */
88: #define MPRESERVE (1<<4) /* keep entry in sys mailbox */
89: #define MMARK (1<<5) /* message is marked! */
90: #define MODIFY (1<<6) /* message has been modified */
91: #define MNEW (1<<7) /* message has never been seen */
92: #define MREAD (1<<8) /* message has been read sometime. */
93: #define MSTATUS (1<<9) /* message status has changed */
94: #define MBOX (1<<10) /* Send this to mbox, regardless */
95:
96: /*
97: * Given a file address, determine the block number it represents.
98: */
99: #define blockof(off) ((int) ((off) / 4096))
100: #define offsetof(off) ((int) ((off) % 4096))
101: #define positionof(block, offset) ((off_t)(block) * 4096 + (offset))
102:
103: /*
104: * Format of the command description table.
105: * The actual table is declared and initialized
106: * in lex.c
107: */
108: struct cmd {
109: char *c_name; /* Name of command */
1.7 millert 110: union {
1.10 millert 111: int (*c_func1)(void *);
112: int (*c_func2)(void *, void *);
1.7 millert 113: } cfunc; /* Implementor of the command */
114: #define c_func cfunc.c_func1
115: #define c_func2 cfunc.c_func2
1.1 deraadt 116: short c_argtype; /* Type of arglist (see below) */
117: short c_msgflag; /* Required flags of messages */
118: short c_msgmask; /* Relevant flags of messages */
119: };
120:
121: /* Yechh, can't initialize unions */
122: #define c_minargs c_msgflag /* Minimum argcount for RAWLIST */
123: #define c_maxargs c_msgmask /* Max argcount for RAWLIST */
124:
125: /*
126: * Argument types.
127: */
1.7 millert 128: #define MSGLIST 0x0001 /* Message list type */
129: #define STRLIST 0x0002 /* A pure string */
130: #define RAWLIST 0x0004 /* Shell string list */
131: #define NOLIST 0x0008 /* Just plain 0 */
132: #define NDMLIST 0x0010 /* Message list, no defaults */
133:
134: #define P 0x0020 /* Autoprint dot after command */
135: #define I 0x0040 /* Interactive command bit */
136: #define M 0x0080 /* Legal from send mode bit */
137: #define W 0x0100 /* Illegal when read only bit */
138: #define F 0x0200 /* Is a conditional command */
139: #define T 0x0400 /* Is a transparent command */
140: #define R 0x0800 /* Cannot be called from collect */
1.1 deraadt 141:
142: /*
143: * Oft-used mask values
144: */
145: #define MMNORM (MDELETED|MSAVED)/* Look at both save and delete bits */
146: #define MMNDEL MDELETED /* Look only at deleted bit */
147:
148: /*
149: * Structure used to return a break down of a head
150: * line (hats off to Bill Joy!)
151: */
152: struct headline {
153: char *l_from; /* The name of the sender */
154: char *l_tty; /* His tty string (if any) */
155: char *l_date; /* The entire date string */
156: };
157:
158: #define GTO 1 /* Grab To: line */
159: #define GSUBJECT 2 /* Likewise, Subject: line */
160: #define GCC 4 /* And the Cc: line */
161: #define GBCC 8 /* And also the Bcc: line */
162: #define GMASK (GTO|GSUBJECT|GCC|GBCC)
163: /* Mask of places from whence */
164:
165: #define GNL 16 /* Print blank line after */
166: #define GDEL 32 /* Entity removed from list */
167: #define GCOMMA 64 /* detract puts in commas */
168:
169: /*
170: * Structure used to pass about the current
171: * state of the user-typed message header.
172: */
173: struct header {
174: struct name *h_to; /* Dynamic "To:" string */
175: char *h_subject; /* Subject string */
176: struct name *h_cc; /* Carbon copies string */
177: struct name *h_bcc; /* Blind carbon copies */
178: struct name *h_smopts; /* Sendmail options */
179: };
180:
181: /*
182: * Structure of namelist nodes used in processing
183: * the recipients of mail and aliases and all that
184: * kind of stuff.
185: */
186: struct name {
187: struct name *n_flink; /* Forward link in list. */
188: struct name *n_blink; /* Backward list link */
189: short n_type; /* From which list it came */
190: char *n_name; /* This fella's name */
191: };
192:
193: /*
194: * Structure of a variable node. All variables are
195: * kept on a singly-linked list of these, rooted by
196: * "variables"
197: */
198:
199: struct var {
200: struct var *v_link; /* Forward link to next variable */
201: char *v_name; /* The variable's name */
202: char *v_value; /* And it's current value */
203: };
204:
205: struct group {
206: struct group *ge_link; /* Next person in this group */
207: char *ge_name; /* This person's user name */
208: };
209:
210: struct grouphead {
211: struct grouphead *g_link; /* Next grouphead in list */
212: char *g_name; /* Name of this group */
213: struct group *g_list; /* Users in group. */
214: };
215:
216: /*
217: * Structure of the hash table of ignored header fields
218: */
219: struct ignoretab {
220: int i_count; /* Number of entries */
221: struct ignore {
222: struct ignore *i_link; /* Next ignored field in bucket */
223: char *i_field; /* This ignored field */
224: } *i_head[HSHSIZE];
225: };
226:
227: /*
228: * Token values returned by the scanner used for argument lists.
229: * Also, sizes of scanner-related things.
230: */
231: #define TEOL 0 /* End of the command line */
232: #define TNUMBER 1 /* A message number */
233: #define TDASH 2 /* A simple dash */
234: #define TSTRING 3 /* A string (possibly containing -) */
235: #define TDOT 4 /* A "." */
236: #define TUP 5 /* An "^" */
237: #define TDOLLAR 6 /* A "$" */
238: #define TSTAR 7 /* A "*" */
239: #define TOPEN 8 /* An '(' */
240: #define TCLOSE 9 /* A ')' */
241: #define TPLUS 10 /* A '+' */
242: #define TERROR 11 /* A lexical error */
243:
244: #define REGDEP 2 /* Maximum regret depth. */
245: #define STRINGLEN 1024 /* Maximum length of string token */
246:
247: /*
1.9 millert 248: * Constants for conditional commands.
249: * These describe whether we should be executing stuff or not.
1.1 deraadt 250: */
251: #define CANY 0 /* Execute in send or receive mode */
252: #define CRCV 1 /* Execute in receive mode only */
253: #define CSEND 2 /* Execute in send mode only */
254:
255: /*
256: * Truncate a file to the last character written. This is
257: * useful just before closing an old file that was opened
258: * for read/write.
259: */
1.9 millert 260: #define trunc(stream) do { \
1.1 deraadt 261: (void)fflush(stream); \
262: (void)ftruncate(fileno(stream), (off_t)ftell(stream)); \
1.9 millert 263: } while(0)
1.7 millert 264:
265: #endif /* MAIL_DEF_H */