1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright 2018 Joyent, Inc.
24 */
25
26/*
27 * Copyright (c) 1985, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Copyright (c) 2016 by Delphix. All rights reserved.
29 */
30
31/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
32/*	All Rights Reserved   */
33
34/*
35 * University Copyright- Copyright (c) 1982, 1986, 1988
36 * The Regents of the University of California
37 * All Rights Reserved
38 *
39 * University Acknowledgment- Portions of this document are derived from
40 * software developed by the University of California, Berkeley, and its
41 * contributors.
42 */
43
44#ifndef _MAILX_DEF_H
45#define	_MAILX_DEF_H
46
47#ifdef	__cplusplus
48extern "C" {
49#endif
50
51#include <sys/types.h>
52#include <signal.h>
53#include <stdio.h>
54#include <fcntl.h>
55#include <string.h>
56#include <termio.h>
57#include <setjmp.h>
58#include <time.h>
59#include <sys/stat.h>
60#include <maillock.h>
61#include <ctype.h>
62#include <errno.h>
63#ifndef preSVr4
64#include <unistd.h>
65#include <stdlib.h>
66#include <ulimit.h>
67#include <wait.h>
68#include <libcustr.h>
69#endif
70#ifdef VMUNIX
71#include <sys/wait.h>
72#endif
73#include "local.h"
74#include "uparm.h"
75
76/*
77 * mailx -- a modified version of a University of California at Berkeley
78 *	mail program
79 */
80
81#define	SENDESC		'~'		/* Default escape for sending */
82#define	NMLSIZE		1024		/* max names in a message list */
83#define	PATHSIZE	1024		/* Size of pathnames throughout */
84#define	HSHSIZE		59		/* Hash size for aliases and vars */
85#define	HDRFIELDS	3		/* Number of header fields */
86#define	LINESIZE	5120		/* max readable line width */
87#define	STRINGSIZE	((unsigned)128) /* Dynamic allocation units */
88#define	MAXARGC		1024		/* Maximum list of raw strings */
89#define	NOSTR		((char *)0)	/* Nill string pointer */
90#define	NOSTRPTR	((char **)0)	/* Nill pointer to string pointer */
91#define	NOINTPTR	((int *)0)	/* Nill pointer */
92#define	MAXEXP		25		/* Maximum expansion of aliases */
93
94/* A nice function to string compare */
95#define	equal(a, b)	(strcmp(a, b) == 0)
96
97/* Keep a list of all opened files */
98#define	fopen(s, t)	my_fopen(s, t)
99
100/* Delete closed file from the list */
101#define	fclose(s)	my_fclose(s)
102
103struct message {
104	off_t	m_offset;		/* offset in block of message */
105	long	m_size;			/* Bytes in the message */
106	long	m_lines;		/* Lines in the message */
107	long	m_clen;			/* Content-Length of the mesg   */
108	short	m_flag;			/* flags, see below */
109	char	m_text;			/* TRUE if the contents is text */
110					/* False otherwise		*/
111};
112
113typedef struct fplst {
114	FILE	*fp;
115	struct	fplst	*next;
116} NODE;
117
118/*
119 * flag bits.
120 */
121
122#define	MUSED		(1<<0)		/* entry is used, but this bit isn't */
123#define	MDELETED	(1<<1)		/* entry has been deleted */
124#define	MSAVED		(1<<2)		/* entry has been saved */
125#define	MTOUCH		(1<<3)		/* entry has been noticed */
126#define	MPRESERVE	(1<<4)		/* keep entry in sys mailbox */
127#define	MMARK		(1<<5)		/* message is marked! */
128#define	MODIFY		(1<<6)		/* message has been modified */
129#define	MNEW		(1<<7)		/* message has never been seen */
130#define	MREAD		(1<<8)		/* message has been read sometime. */
131#define	MSTATUS		(1<<9)		/* message status has changed */
132#define	MBOX		(1<<10)		/* Send this to mbox, regardless */
133#define	MBOXED		(1<<11)		/* message has been sent to mbox */
134
135#define	H_AFWDCNT	1		/* "Auto-Forward-Count:"  */
136#define	H_AFWDFROM	2		/* "Auto-Forwarded-From:" */
137#define	H_CLEN		3		/* "Content-Length:"	*/
138#define	H_CTYPE		4		/* "Content-Type:"	*/
139#define	H_DATE		5		/* "Date:"		*/
140#define	H_DEFOPTS	6		/* "Default-Options:"	*/
141#define	H_EOH		7		/* "End-of-Header:"	*/
142#define	H_FROM		8		/* "From "		*/
143#define	H_FROM1		9		/* ">From "		*/
144#define	H_FROM2		10		/* "From: "		*/
145#define	H_MTSID		11		/* "MTS-Message-ID:"	*/
146#define	H_MTYPE		12		/* "Message-Type:"	*/
147#define	H_MVERS		13		/* "Message-Version:"	*/
148#define	H_MSVC		14		/* "Message-Service:"	*/
149#define	H_RECEIVED	15		/* "Received:"		*/
150#define	H_RVERS		16		/* "Report-Version:"	*/
151#define	H_STATUS	17		/* "Status:"		*/
152#define	H_SUBJ		18		/* "Subject:"		*/
153#define	H_TO		19		/* "To:"		*/
154#define	H_TCOPY		20		/* ">To:"		*/
155#define	H_TROPTS	21		/* "Transport-Options:"   */
156#define	H_UAID		22		/* "UA-Content-ID:"	  */
157
158#define	H_DAFWDFROM	23	/* Hold A-F-F when sending Del. Notf. */
159#define	H_DTCOPY	24	/* Hold ">To:" when sending Del. Notf. */
160#define	H_DRECEIVED	25	/* Hold Rcvd: when sending Del. Notf. */
161#define	H_CONT		26	/* Continuation of previous line */
162#define	H_NAMEVALUE	27	/* unrecognized "name: value" hdr line */
163
164/*
165 * Format of the command description table.
166 * The actual table is declared and initialized
167 * in lex.c
168 */
169
170struct cmd {
171	char	*c_name;		/* Name of command */
172	int	(*c_func)(void *);	/* Implementor of the command */
173	short	c_argtype;		/* Type of arglist (see below) */
174	short	c_msgflag;		/* Required flags of messages */
175	short	c_msgmask;		/* Relevant flags of messages */
176};
177
178/* can't initialize unions */
179
180#define	c_minargs c_msgflag		/* Minimum argcount for RAWLIST */
181#define	c_maxargs c_msgmask		/* Max argcount for RAWLIST */
182
183/*
184 * Argument types.
185 */
186
187#define	MSGLIST	 0		/* Message list type */
188#define	STRLIST	 1		/* A pure string */
189#define	RAWLIST	 2		/* Shell string list */
190#define	NOLIST	 3		/* Just plain 0 */
191#define	NDMLIST	 4		/* Message list, no defaults */
192
193#define	P	040		/* Autoprint dot after command */
194#define	I	0100		/* Interactive command bit */
195#define	M	0200		/* Legal from send mode bit */
196#define	W	0400		/* Illegal when read only bit */
197#define	F	01000		/* Is a conditional command */
198#define	T	02000		/* Is a transparent command */
199#define	R	04000		/* Cannot be called from collect */
200
201/*
202 * Oft-used mask values
203 */
204
205#define	MMNORM	(MDELETED|MSAVED) /* Look at both save and delete bits */
206#define	MMNDEL	MDELETED	/* Look only at deleted bit */
207
208/*
209 * Structure used to return a break down of a head
210 * line
211 */
212
213typedef struct headline {
214	custr_t	*hl_from;	/* The name of the sender */
215	custr_t	*hl_tty;	/* Its tty string (if any) */
216	custr_t	*hl_date;	/* The entire date string */
217} headline_t;
218
219#define	GTO	1		/* Grab To: line */
220#define	GSUBJECT 2		/* Likewise, Subject: line */
221#define	GCC	4		/* And the Cc: line */
222#define	GBCC	8		/* And also the Bcc: line */
223#define	GDEFOPT	16		/* And the Default-Options: lines */
224#define	GNL	32		/* Print blank line after */
225#define	GOTHER	64		/* Other header lines */
226#define	GMASK	(GTO|GSUBJECT|GCC|GBCC|GDEFOPT|GNL|GOTHER)
227				/* Mask of all header lines */
228#define	GDEL	128		/* Entity removed from list */
229#define	GCLEN	256		/* Include Content-Length header */
230
231/*
232 * Structure used to pass about the current
233 * state of the user-typed message header.
234 */
235
236struct header {
237	char	*h_to;			/* Dynamic "To:" string */
238	char	*h_subject;		/* Subject string */
239	char	*h_cc;			/* Carbon copies string */
240	char	*h_bcc;			/* Blind carbon copies */
241	char	*h_defopt;		/* Default options */
242	char	**h_others;		/* Other header lines */
243	int	h_seq;			/* Sequence for optimization */
244};
245
246/*
247 * Structure of namelist nodes used in processing
248 * the recipients of mail and aliases and all that
249 * kind of stuff.
250 */
251
252struct name {
253	struct	name *n_flink;		/* Forward link in list. */
254	struct	name *n_blink;		/* Backward list link */
255	short	n_type;			/* From which list it came */
256	char	*n_name;		/* This fella's name */
257	char	*n_full;		/* Full name */
258};
259
260/*
261 * Structure of a variable node.  All variables are
262 * kept on a singly-linked list of these, rooted by
263 * "variables"
264 */
265
266struct var {
267	struct	var *v_link;		/* Forward link to next variable */
268	char	*v_name;		/* The variable's name */
269	char	*v_value;		/* And it's current value */
270};
271
272struct mgroup {
273	struct	mgroup *ge_link;	/* Next person in this group */
274	char	*ge_name;		/* This person's user name */
275};
276
277struct grouphead {
278	struct	grouphead *g_link;	/* Next grouphead in list */
279	char	*g_name;		/* Name of this group */
280	struct	mgroup *g_list;		/* Users in group. */
281};
282
283#define	NIL	((struct name *)0)	/* The nil pointer for namelists */
284#define	NONE	((struct cmd *)0)	/* The nil pointer to command tab */
285#define	NOVAR	((struct var *)0)	/* The nil pointer to variables */
286#define	NOGRP	((struct grouphead *)0) /* The nil grouphead pointer */
287#define	NOGE	((struct mgroup *)0)	/* The nil group pointer */
288#define	NOFP	((struct fplst *)0)	/* The nil file pointer */
289
290#define	TRUE	1
291#define	FALSE	0
292
293#define	DEADPERM	0600		/* permissions of dead.letter */
294#define	TEMPPERM	0600		/* permissions of temp files */
295#define	MBOXPERM	0600		/* permissions of ~/mbox */
296
297#ifndef	MFMODE
298#define	MFMODE		0600		/* create mode for `/var/mail' files */
299#endif
300
301/*
302 * Structure of the hash table of ignored header fields
303 */
304struct ignore {
305	struct ignore	*i_link;	/* Next ignored field in bucket */
306	char		*i_field;	/* This ignored field */
307};
308
309#ifdef preSVr4
310struct utimbuf {
311	time_t	actime;
312	time_t	modtime;
313};
314#else
315#include	<utime.h>
316#endif
317
318/*
319 * Token values returned by the scanner used for argument lists.
320 * Also, sizes of scanner-related things.
321 */
322
323#define	TEOL		0		/* End of the command line */
324#define	TNUMBER		1		/* A message number */
325#define	TDASH		2		/* A simple dash */
326#define	TSTRING		3		/* A string (possibly containing -) */
327#define	TDOT		4		/* A "." */
328#define	TUP		5		/* An "^" */
329#define	TDOLLAR		6		/* A "$" */
330#define	TSTAR		7		/* A "*" */
331#define	TOPEN		8		/* An '(' */
332#define	TCLOSE		9		/* A ')' */
333#define	TPLUS		10		/* A '+' */
334
335#define	REGDEP		2		/* Maximum regret depth. */
336#define	STRINGLEN	1024		/* Maximum length of string token */
337
338/*
339 * Constants for conditional commands.  These describe whether
340 * we should be executing stuff or not.
341 */
342
343#define	CANY		0		/* Execute in send or receive mode */
344#define	CRCV		1		/* Execute in receive mode only */
345#define	CSEND		2		/* Execute in send mode only */
346#define	CTTY		3		/* Execute if attached to a tty only */
347#define	CNOTTY		4		/* Execute if not attached to a tty */
348
349/*
350 * Flags for msend().
351 */
352
353#define	M_IGNORE	1		/* Do "ignore/retain" processing */
354#define	M_SAVING	2		/* Saving to a file/folder */
355
356/*
357 * VM/UNIX has a vfork system call which is faster than forking.  If we
358 * don't have it, fork(2) will do . . .
359 */
360
361#if !defined(VMUNIX) && defined(preSVr4)
362#define	vfork()	fork()
363#endif
364#ifndef	SIGRETRO
365#define	sigchild()
366#endif
367
368
369/*
370 * 4.2bsd signal interface help...
371 */
372#ifdef VMUNIX
373#define	sigset(s, a)	signal(s, a)
374#define	sigsys(s, a)	signal(s, a)
375#else
376#ifndef preSVr4
377/* SVr4 version of sigset() in fio.c */
378#define	sigsys(s, a)	signal(s, a)
379#define	setjmp(x)	sigsetjmp((x), 1)
380#define	longjmp		siglongjmp
381#define	jmp_buf		sigjmp_buf
382#else
383#define	OLD_BSD_SIGS
384#endif
385#endif
386
387/*
388 * Truncate a file to the last character written. This is
389 * useful just before closing an old file that was opened
390 * for read/write.
391 */
392#define	trunc(stream)	ftruncate(fileno(stream), (long)ftell(stream))
393
394/*
395 * The pointers for the string allocation routines,
396 * there are NSPACE independent areas.
397 * The first holds STRINGSIZE bytes, the next
398 * twice as much, and so on.
399 */
400
401#define	NSPACE	25			/* Total number of string spaces */
402struct strings {
403	char	*s_topFree;		/* Beginning of this area */
404	char	*s_nextFree;		/* Next alloctable place here */
405	unsigned s_nleft;		/* Number of bytes left here */
406};
407
408/* The following typedefs must be used in SVR4 */
409#ifdef preSVr4
410#ifndef sun
411typedef int gid_t;
412typedef int uid_t;
413typedef int mode_t;
414typedef int pid_t;
415#endif
416#endif
417
418#define	STSIZ	40
419#define	TMPSIZ	14
420/*
421 * Forward declarations of routine types to keep lint and cc happy.
422 */
423
424extern int		Copy(int *msgvec);
425extern FILE		*Fdopen(int fildes, char *mode);
426extern int		Followup(int *msgvec);
427extern char		*Getf(register char *s);
428extern int		More(int *msgvec);
429extern int		Respond(int *msgvec);
430extern int		Save(int *msgvec);
431extern int		Sendm(char *str);
432extern int		Sput(char str[]);
433extern int		Type(int *msgvec);
434extern void		Verhogen(void);
435extern char		*addone(char hf[], char news[]);
436extern char		*addto(char hf[], char news[]);
437extern void		alter(char name[]);
438extern int		alternates(char **namelist);
439extern void		announce(void);
440extern int		any(int ch, char *str);
441extern int		anyof(register char *s1, register char *s2);
442extern int		argcount(char **argv);
443extern void		assign(char name[], char value[]);
444extern int		blankline(const char linebuf[]);
445extern struct name	*cat(struct name *n1, struct name *n2);
446extern FILE		*collect(struct header *hp);
447extern void		commands(void);
448extern char		*copy(char *str1, char *str2);
449extern int		copycmd(char str[]);
450extern int		deassign(register char *s);
451extern int		delm(int *msgvec);
452extern struct name	*delname(register struct name *np, char name[]);
453extern int		deltype(int msgvec[]);
454extern char		*detract(register struct name *np, int ntype);
455extern int		docomma(char *s);
456extern int		dopipe(char str[]);
457extern int		dosh(char *str);
458extern int		echo(register char **argv);
459extern int		editor(int *msgvec);
460extern int		edstop(int noremove);
461extern struct name	*elide(struct name *names);
462extern int		elsecmd(void);
463extern int		endifcmd(void);
464extern int		execute(char linebuf[], int contxt);
465extern char		*expand(char *name);
466extern struct name	*extract(char line[], int arg_ntype);
467extern int		fferror(FILE *iob);
468extern int		field(char str[]);
469extern int		file(char **argv);
470extern struct grouphead	*findgroup(char name[]);
471extern void		findmail(char *name);
472extern int		first(int f, int m);
473extern void		flush(void);
474extern int		folders(char **arglist);
475extern int		followup(int *msgvec);
476extern int		from(int *msgvec);
477extern off_t		fsize(FILE *iob);
478extern int		getfold(char *name);
479extern int	gethfield(register FILE *f, char linebuf[], register long rem);
480extern int	getaline(char *line, int size, FILE *f, int *hasnulls);
481extern int	getmessage(char *buf, int *vector, int flags);
482extern int	getmsglist(char *buf, int *vector, int flags);
483extern int	getname(uid_t uid, char namebuf[]);
484extern int	getrawlist(char line[], char **argv, int argc);
485extern void	getrecf(char *buf, char *recfile,
486		    int useauthor, int sz_recfile);
487extern uid_t	getuserid(char name[]);
488extern int	grabh(register struct header *hp, int gflags, int subjtop);
489extern int	group(char **argv);
490extern void	hangup(int);
491extern int	hash(char name[]);
492extern char	*hcontents(char hfield[]);
493extern int	headerp(register char *line);
494extern int	headers(int *msgvec);
495extern int	headline_alloc(headline_t **);
496extern void	headline_free(headline_t *);
497extern void	headline_reset(headline_t *);
498extern int	help(void);
499extern char	*helppath(char *file);
500extern char	*hfield(char field[], struct message *mp,
501		    char *(*add)(char *, char *));
502extern void	holdsigs(void);
503extern int	icequal(register char *s1, register char *s2);
504extern int	ifcmd(char **argv);
505extern int	igfield(char *list[]);
506extern int	inc(void);
507extern void	inithost(void);
508extern int	isdir(char name[]);
509extern boolean_t is_headline(const char *);
510extern int	ishfield(char linebuf[], char field[]);
511extern int	ishost(char *sys, char *rest);
512extern int	isign(char *field, int saving);
513extern void	istrcpy(char *dest, int dstsize, char *src);
514extern void	lcwrite(char *fn, FILE *fi, FILE *fo, int addnl);
515extern void	load(char *name);
516extern int	loadmsg(char str[]);
517extern int	lock(FILE *fp, char *mode, int blk);
518extern void	lockmail(void);
519extern int	mail(char **people);
520extern void	mail1(struct header *hp, int use_to, char *orig_to);
521extern void	mapf(register struct name *np, char *from);
522extern int	mboxit(int msgvec[]);
523extern void	mechk(struct name *names);
524extern int	member(register char *realfield,
525		    register struct ignore **table);
526extern int	messize(int *msgvec);
527extern void	minit(void);
528extern int	more(int *msgvec);
529extern long	msend(struct message *mailp, FILE *obuf,
530		    int flag, int (*fp)(const char *, FILE *));
531extern int	my_fclose(register FILE *iop);
532extern FILE	*my_fopen(char *file, char *mode);
533extern char	*nameof(register struct message *mp);
534extern char	*netmap(char name[], char from[]);
535extern int	newfileinfo(int start);
536extern int	next(int *msgvec);
537extern int	npclose(FILE *ptr);
538extern FILE	*npopen(char *cmd, char *mode);
539extern char	*nstrcpy(char *dst, int dstsize, char *src);
540extern char	*nstrcat(char *dst, int dstsize, char *src);
541extern int	null(char *e);
542extern int	outof(struct name *names, FILE *fo);
543extern struct name	*outpre(struct name *to);
544extern void	panic(char *str);
545extern int	parse_headline(const char *, headline_t *);
546extern int	pcmdlist(void);
547extern int	pdot(void);
548extern int	preserve(int *msgvec);
549extern void	printgroup(char name[]);
550extern void	printhead(int mesg);
551extern int	puthead(struct header *hp, FILE *fo, int w, long clen);
552extern int	pversion(char *e);
553extern void	quit(int noremove);
554extern int	readline(FILE *ibuf, char *linebuf);
555extern void	receipt(struct message *mp);
556extern void	relsesigs(void);
557extern int	removefile(char name[]);
558extern int	replyall(int *msgvec);
559extern int	replysender(int *msgvec);
560extern int	respond(int *msgvec);
561extern int	retfield(char *list[]);
562extern int	rexit(int e);
563extern char	*safeexpand(char name[]);
564extern void	*salloc(unsigned size);
565extern void	*srealloc(void *optr, unsigned size);
566extern int	samebody(register char *user, register char *addr,
567		    int fuzzy);
568extern int	save(char str[]);
569extern void	savedead(int s);
570extern char	*savestr(char *str);
571extern int	schdir(char *str);
572extern int	screensize(void);
573extern int	scroll(char arg[]);
574extern int	sendm(char *str);
575extern int	set(char **arglist);
576extern void	setclen(register struct message *mp);
577extern int	setfile(char *name, int isedit);
578extern FILE	*setinput(register struct message *mp);
579extern void	setptr(register FILE *ibuf);
580extern int	shell(char *str);
581#ifndef sigchild
582extern void		sigchild(void);
583#endif
584#ifndef sigset
585extern void		(*sigset())();
586#endif
587extern char		*skin(char *name);
588extern char		*snarf(char linebuf[], int *flag, int erf);
589extern int		source(char name[]);
590extern char		*splice(char *addr, char *hdr);
591extern int		sput(char str[]);
592extern void		sreset(void);
593extern void		stop(int s);
594extern int		stouch(int msgvec[]);
595extern int		substr(char *string1, char *string2);
596extern int		swrite(char str[]);
597extern struct name	*tailof(struct name *name);
598extern void		tinit(void);
599extern int		tmail(void);
600extern int		top(int *msgvec);
601extern void		touch(int mesg);
602extern struct name	*translate(struct name *np);
603extern int		type(int *msgvec);
604extern int		undelete(int *msgvec);
605extern int		ungroup(char **argv);
606extern int		unigfield(char *list[]);
607extern void		unlockmail(void);
608extern char		**unpack(struct name *np);
609extern int		unread(int msgvec[]);
610extern int		unretfield(char *list[]);
611extern int		unset(char **arglist);
612extern int		unstack(void);
613extern char		*unuucp(char *name);
614extern struct name	*usermap(struct name *names);
615extern char		*value(char name[]);
616extern char		*vcopy(char str[]);
617extern void		vfree(register char *cp);
618extern int		visual(int *msgvec);
619extern char		*yankword(char *name, char *word, int sz, int comma);
620
621/*
622 * These functions are defined in libmail.a
623 */
624#ifdef	__cplusplus
625extern "C" {
626#endif
627extern int		delempty(mode_t, char *);
628extern char		*maildomain(void);
629extern void		touchlock(void);
630extern char		*xgetenv(char *);
631extern int		xsetenv(char *);
632#ifdef	__cplusplus
633}
634#endif
635
636/*
637 * Standard functions from the C library.
638 * These are all defined in <stdlib.h> and <wait.h> in SVr4.
639 */
640#ifdef preSVr4
641extern long		atol();
642extern char		*getcwd();
643extern char		*calloc();
644extern char		*getenv();
645extern void		exit();
646extern void		free();
647extern char		*malloc();
648extern time_t		time();
649extern long		ulimit();
650extern int		utime();
651extern int		wait();
652extern int		fputs();
653#endif
654
655#ifdef	__cplusplus
656}
657#endif
658
659#endif	/* _MAILX_DEF_H */
660