xref: /minix/usr.bin/mail/def.h (revision fb9c64b2)
1 /*	$NetBSD: def.h,v 1.28 2014/10/18 08:33:30 snj Exp $	*/
2 /*
3  * Copyright (c) 1980, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the University nor the names of its contributors
15  *    may be used to endorse or promote products derived from this software
16  *    without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  *	@(#)def.h	8.4 (Berkeley) 4/20/95
31  *	$NetBSD: def.h,v 1.28 2014/10/18 08:33:30 snj Exp $
32  */
33 
34 /*
35  * Mail -- a mail program
36  *
37  * Author: Kurt Shoens (UCB) March 25, 1978
38  */
39 
40 #ifndef __DEF_H__
41 #define __DEF_H__
42 
43 #include <sys/types.h>
44 #include <sys/file.h>
45 #include <sys/ioctl.h>
46 #include <sys/stat.h>
47 #include <sys/param.h>
48 #include <sys/time.h>
49 #include <sys/wait.h>
50 
51 #include <ctype.h>
52 #include <err.h>
53 #include <errno.h>
54 #include <fcntl.h>
55 #include <paths.h>
56 #include <pwd.h>
57 #include <setjmp.h>
58 #include <signal.h>
59 #include <stdio.h>
60 #include <stdlib.h>
61 #include <string.h>
62 #include <termios.h>
63 #include <time.h>
64 #include <unistd.h>
65 #include <vis.h>
66 
67 #include "pathnames.h"
68 
69 #define	APPEND				/* New mail goes to end of mailbox */
70 
71 #define COMMENT_CHAR	'#'		/* Comment character when sourcing */
72 #define	ESCAPE		'~'		/* Default escape for sending */
73 #define	NMLSIZE		1024		/* max names in a message list */
74 #define	PATHSIZE	MAXPATHLEN	/* Size of pathnames throughout */
75 #define	HSHSIZE		59		/* Hash size for aliases and vars */
76 #define	LINESIZE	BUFSIZ		/* max readable line width */
77 #define	MAXARGC		1024		/* Maximum list of raw strings */
78 #define	MAXEXP		25		/* Maximum expansion of aliases */
79 
80 #define PUBLIC			/* make it easy to find the entry points */
81 
82 /*
83  * User environment variable names.
84  * See complete.h, mime.h, and thread.h for names specific to those modules.
85  */
86 #define	ENAME_INDENT_POSTSCRIPT	"indentpostscript"
87 #define	ENAME_INDENT_PREAMBLE	"indentpreamble"
88 #define ENAME_APPEND		"append"
89 #define ENAME_ASK		"ask"
90 #define ENAME_ASKBCC		"askbcc"
91 #define ENAME_ASKCC		"askcc"
92 #define ENAME_ASKSUB		"asksub"
93 #define ENAME_AUTOINC		"autoinc"
94 #define ENAME_AUTOPRINT		"autoprint"
95 #define ENAME_CRT		"crt"
96 #define ENAME_DEAD		"DEAD"
97 #define ENAME_DEBUG		"debug"
98 #define ENAME_DONTSENDEMPTY	"dontsendempty"
99 #define ENAME_DOT		"dot"
100 #define ENAME_EDITOR		"EDITOR"
101 #define ENAME_ENABLE_PIPES	"enable-pipes"
102 #define ENAME_ESCAPE		"escape"
103 #define ENAME_FOLDER		"folder"
104 #define ENAME_HEADER_FORMAT	"header-format"
105 #define ENAME_HOLD		"hold"
106 #define ENAME_IGNORE		"ignore"
107 #define ENAME_IGNOREEOF		"ignoreeof"
108 #define ENAME_INDENTPREFIX	"indentprefix"
109 #define ENAME_INTERACTIVE	"interactive"
110 #define ENAME_KEEP		"keep"
111 #define ENAME_KEEPSAVE		"keepsave"
112 #define ENAME_LISTER		"LISTER"
113 #define ENAME_MBOX		"MBOX"
114 #define ENAME_METOO		"metoo"
115 #define ENAME_NOHEADER		"noheader"
116 #define ENAME_NOSAVE		"nosave"
117 #define ENAME_PAGE_ALSO		"page-also"
118 #define ENAME_PAGER		"PAGER"
119 #define ENAME_PAGER_OFF		"pager-off"
120 #define ENAME_PROMPT		"prompt"
121 #define ENAME_QUIET		"quiet"
122 #define ENAME_RECORD		"record"
123 #define ENAME_REGEX_SEARCH	"regex-search"
124 #define ENAME_REPLYALL		"Replyall"
125 #define ENAME_REPLYASRECIPIENT	"ReplyAsRecipient"
126 #define ENAME_SCREEN		"screen"
127 #define ENAME_SCREENHEIGHT	"screenheight"
128 #define ENAME_SCREENWIDTH	"screenwidth"
129 #define ENAME_SEARCHHEADERS	"searchheaders"
130 #define ENAME_SENDMAIL		"sendmail"
131 #define ENAME_SHELL		"SHELL"
132 #define ENAME_SHOW_RCPT		"show-rcpt"
133 #define ENAME_SMOPTS_VERIFY	"smopts-verify"
134 #define ENAME_TOPLINES		"toplines"
135 #define ENAME_VERBOSE		"verbose"
136 #define ENAME_VISUAL		"VISUAL"
137 
138 #define	equal(a, b)	(strcmp(a,b)==0)/* A nice function to string compare */
139 
140 struct message {
141 	short	m_flag;			/* flags, see below */
142 	short	m_offset;		/* offset in block of message */
143 	long	m_block;		/* block number of this message */
144 	long	m_lines;		/* Lines in the message */
145 	off_t	m_size;			/* Bytes in the message */
146 	long	m_blines;		/* Body (non-header) lines */
147 
148 	/*
149 	 * threading fields
150 	 */
151 	int		m_index;	/* message index in this thread */
152 	int		m_depth;	/* depth in thread */
153 	struct message *m_flink;	/* link to next message */
154 	struct message *m_blink;	/* link to previous message */
155 	struct message *m_clink;	/* link to child of this message */
156 	struct message *m_plink;	/* link to parent of thread */
157 };
158 typedef struct mime_info mime_info_t;	/* phantom structure only to attach.c */
159 
160 /*
161  * flag bits.
162  */
163 
164 #define	MUSED		(1<<0)		/* entry is used, but this bit isn't */
165 #define	MDELETED	(1<<1)		/* entry has been deleted */
166 #define	MSAVED		(1<<2)		/* entry has been saved */
167 #define	MTOUCH		(1<<3)		/* entry has been noticed */
168 #define	MPRESERVE	(1<<4)		/* keep entry in sys mailbox */
169 #define	MMARK		(1<<5)		/* message is marked! */
170 #define	MMODIFY		(1<<6)		/* message has been modified */
171 #define	MNEW		(1<<7)		/* message has never been seen */
172 #define	MREAD		(1<<8)		/* message has been read sometime. */
173 #define	MSTATUS		(1<<9)		/* message status has changed */
174 #define	MBOX		(1<<10)		/* Send this to mbox, regardless */
175 #define MTAGGED		(1<<11)		/* message has been tagged */
176 
177 /*
178  * Given a file address, determine the block number it represents.
179  */
180 #define blockof(off)			((int) ((off) / 4096))
181 #define blkoffsetof(off)		((int) ((off) % 4096))
182 #define positionof(block, offset)	((off_t)(block) * 4096 + (offset))
183 
184 /*
185  * Format of the command description table.
186  * The actual table is declared and initialized
187  * in lex.c
188  */
189 struct cmd {
190 	const char *c_name;		/* Name of command */
191 	int	(*c_func)(void *);	/* Implementor of the command */
192 	int	c_pipe;			/* Pipe output through the pager */
193 # define C_PIPE_PAGER	1		/* enable use of pager */
194 # define C_PIPE_CRT	2		/* use the pager if CRT is defined */
195 # define C_PIPE_SHELL	4		/* enable shell pipes */
196 #ifdef USE_EDITLINE
197 	const char *c_complete;		/* String describing completion */
198 #endif
199 	short	c_argtype;		/* Type of arglist (see below) */
200 	short	c_msgflag;		/* Required flags of messages */
201 	short	c_msgmask;		/* Relevant flags of messages */
202 };
203 
204 /* Yechh, can't initialize unions */
205 
206 #define	c_minargs c_msgflag		/* Minimum argcount for RAWLIST */
207 #define	c_maxargs c_msgmask		/* Max argcount for RAWLIST */
208 
209 /*
210  * Argument types.
211  */
212 
213 #define	MSGLIST	 0		/* Message list type */
214 #define	STRLIST	 1		/* A pure string */
215 #define	RAWLIST	 2		/* Shell string list */
216 #define	NOLIST	 3		/* Just plain 0 */
217 #define	NDMLIST	 4		/* Message list, no defaults */
218 
219 #define	P	0x010		/* Autoprint dot after command */
220 #define	I	0x020		/* Interactive command bit */
221 #define	M	0x040		/* Legal from send mode bit */
222 #define	W	0x080		/* Illegal when read only bit */
223 #define	F	0x100		/* Is a conditional command */
224 #define	T	0x200		/* Is a transparent command */
225 #define	R	0x400		/* Cannot be called from collect */
226 #define ARGTYPE_MASK	~(P|I|M|W|F|T|R)
227 
228 /*
229  * Oft-used mask values
230  */
231 
232 #define	MMNORM		(MDELETED|MSAVED)/* Look at both save and delete bits */
233 #define	MMNDEL		MDELETED	/* Look only at deleted bit */
234 
235 /*
236  * Structure used to return a break down of a head
237  * line (hats off to Bill Joy!)
238  */
239 
240 struct headline {
241 	char	*l_from;	/* The name of the sender */
242 	char	*l_tty;		/* His tty string (if any) */
243 	char	*l_date;	/* The entire date string */
244 };
245 
246 #define	GTO	 0x001		/* Grab To: line */
247 #define	GSUBJECT 0x002		/* Likewise, Subject: line */
248 #define	GCC	 0x004		/* And the Cc: line */
249 #define	GBCC	 0x008		/* And also the Bcc: line */
250 #define GSMOPTS  0x010		/* Grab the sendmail options */
251 #define GMISC	 0x020		/* miscellaneous extra fields for sending */
252 #ifdef MIME_SUPPORT
253 #define GMIME    0x040		/* mime flag */
254 #endif
255 #define	GMASK	(GTO | GSUBJECT | GCC | GBCC | GSMOPTS)
256 				/* Mask of places from whence */
257 
258 #define	GNL	 0x100		/* Print blank line after */
259 #define	GDEL	 0x200		/* Entity removed from list */
260 #define	GCOMMA	 0x400		/* detract puts in commas */
261 
262 #ifdef MIME_SUPPORT
263 /*
264  * Structure of MIME content.
265  */
266 struct Content {
267 	const char *C_type;		/* content type */
268 	const char *C_encoding;		/* content transfer encoding */
269 	const char *C_disposition;	/* content disposition */
270 	const char *C_description;	/* content description */
271 	const char *C_id;		/* content id */
272 };
273 /* Header strings corresponding to the above Content fields. */
274 #define MIME_HDR_TYPE		"Content-Type"
275 #define MIME_HDR_ENCODING	"Content-Transfer-Encoding"
276 #define MIME_HDR_DISPOSITION	"Content-Disposition"
277 #define MIME_HDR_ID		"Content-ID"
278 #define MIME_HDR_DESCRIPTION	"Content-Description"
279 #define MIME_HDR_VERSION	"MIME-Version"
280 /* the value of the MIME-Version field */
281 #define MIME_VERSION		"1.0"
282 
283 typedef enum {
284 	ATTACH_INVALID = 0,	/* do not use! */
285 	ATTACH_FNAME = 1,
286 	ATTACH_MSG = 2,
287 	ATTACH_FILENO = 3
288 } attach_t;
289 
290 /*
291  * Structure of a MIME attachment.
292  */
293 struct attachment {
294 	struct attachment *a_flink;	/* Forward link in list. */
295 	struct attachment *a_blink;	/* Backward list link */
296 
297 	attach_t a_type;		/* attachment type */
298 #if 1
299 	union {
300 		char *u_name;		/* file name */
301 		struct message *u_msg;	/* message */
302 		int u_fileno;		/* file number */
303 	} a_u;
304 
305 	#define a_name		a_u.u_name
306 	#define a_msg		a_u.u_msg
307 	#define a_fileno	a_u.u_fileno
308 #else
309 	char *a_name;			/* file name */
310 	struct message *a_msg;		/* message */
311 	int a_fileno;			/* file number */
312 #endif
313 
314 	struct Content a_Content;	/* MIME content strings */
315 };
316 #endif /* MIME_SUPPORT */
317 
318 /*
319  * Structure used to pass about the current
320  * state of the user-typed message header.
321  */
322 
323 struct header {
324 	struct name	*h_to;		/* Dynamic "To:" string */
325 	char		*h_subject;	/* Subject string */
326 	struct name	*h_cc;		/* Carbon copies string */
327 	struct name	*h_bcc;		/* Blind carbon copies */
328 	struct name	*h_smopts;	/* Sendmail options */
329 	char		*h_in_reply_to;	/* In-Reply-To: field */
330 	struct name	*h_references;	/* References: field */
331 	struct name	*h_extra;	/* extra header fields */
332 #ifdef MIME_SUPPORT
333 	char *h_mime_boundary;		/* MIME multipart boundary string */
334 	struct Content h_Content;	/* MIME content for message */
335 	struct attachment *h_attach;	/* MIME attachments */
336 #endif
337 };
338 
339 /*
340  * Structure of namelist nodes used in processing
341  * the recipients of mail and aliases and all that
342  * kind of stuff.
343  */
344 
345 struct name {
346 	struct	name *n_flink;		/* Forward link in list. */
347 	struct	name *n_blink;		/* Backward list link */
348 	short	n_type;			/* From which list it came */
349 	char	*n_name;		/* This fella's name */
350 };
351 
352 /*
353  * Structure of a variable node.  All variables are
354  * kept on a singly-linked list of these, rooted by
355  * "variables"
356  */
357 
358 struct var {
359 	struct	var *v_link;		/* Forward link to next variable */
360 	char	*v_name;		/* The variable's name */
361 	char	*v_value;		/* And its current value */
362 };
363 
364 struct group {
365 	struct	group *ge_link;		/* Next person in this group */
366 	char	*ge_name;		/* This person's user name */
367 };
368 
369 struct grouphead {
370 	struct	grouphead *g_link;	/* Next grouphead in list */
371 	char	*g_name;		/* Name of this group */
372 	struct	group *g_list;		/* Users in group. */
373 };
374 
375 struct smopts_s {
376 	struct smopts_s *s_link;	/* Link to next smopts_s in list */
377 	char *s_name;			/* Name of this smopts_s */
378 	struct name *s_smopts;		/* sendmail options name list */
379 };
380 
381 /*
382  * Structure of the hash table of ignored header fields
383  */
384 struct ignoretab {
385 	size_t i_count;			/* Number of entries */
386 	struct ignore {
387 		struct ignore *i_link;	/* Next ignored field in bucket */
388 		char *i_field;		/* This ignored field */
389 	} *i_head[HSHSIZE];
390 };
391 
392 /*
393  * Constants for conditional commands.  These control whether we
394  * should be executing commands or not.
395  */
396 struct cond_stack_s {
397 	struct cond_stack_s *c_next;
398 	int c_cond;
399 };
400 #define	CNONE		0x00		/* Execute everything */
401 #define	CSKIP		0x01		/* Do not execute commands */
402 #define	CIF		0x02		/* Inside if/endif block */
403 #define	CELSE		0x04		/* The last conditional was else */
404 #define	CIGN		0x08		/* Conditional in a skipped block */
405 
406 enum mailmode_e {
407 	mm_receiving,			/* receiving mail mode */
408 	mm_sending,			/* sending mail mode */
409 	mm_hdrsonly			/* headers only mode */
410 };
411 
412 /*
413  * Truncate a file to the last character written. This is
414  * useful just before closing an old file that was opened
415  * for read/write.
416  */
417 #define trunc(stream) {							\
418 	(void)fflush(stream); 						\
419 	(void)ftruncate(fileno(stream), (off_t)ftell(stream));		\
420 }
421 
422 /*
423  * White Space (WSP) as specified in see RFC 2822.
424  *
425  * NOTE: Use this in place of isblank() so it is inline.  Also, unlike
426  * the table implemented ctype(3) routines, this does not have input
427  * range issues caused by sign extensions.
428  *
429  * See mime_header.h for the related is_FWS().
430  */
431 static inline int
432 is_WSP(int c)
433 {
434 	return c == ' ' || c == '\t';
435 }
436 
437 static inline char *
438 skip_WSP(const char *cp)
439 {
440 	while (is_WSP(*cp))
441 		cp++;
442 	return __UNCONST(cp);
443 }
444 
445 static inline char *
446 skip_space(char *p)
447 {
448 	while (isspace((unsigned char)*p))
449 		p++;
450 	return p;
451 }
452 
453 /*
454  * strip trailing white space
455  */
456 static inline char *
457 strip_WSP(char *line)
458 {
459 	char *cp;
460 
461 	cp = line + strlen(line) - 1;
462 	while (cp >= line && is_WSP(*cp))
463 		cp--;
464 	*++cp = '\0';
465 	return cp;
466 }
467 
468 #endif /* __DEF_H__ */
469