xref: /titanic_51/usr/src/cmd/mailx/main.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate /*
27*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1998 by Sun Microsystems, Inc.
28*7c478bd9Sstevel@tonic-gate  * All rights reserved.
29*7c478bd9Sstevel@tonic-gate  */
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate /*
32*7c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
33*7c478bd9Sstevel@tonic-gate  * The Regents of the University of California
34*7c478bd9Sstevel@tonic-gate  * All Rights Reserved
35*7c478bd9Sstevel@tonic-gate  *
36*7c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
37*7c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
38*7c478bd9Sstevel@tonic-gate  * contributors.
39*7c478bd9Sstevel@tonic-gate  */
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #include "rcv.h"
44*7c478bd9Sstevel@tonic-gate #ifndef preSVr4
45*7c478bd9Sstevel@tonic-gate #include <locale.h>
46*7c478bd9Sstevel@tonic-gate #endif
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate /*
49*7c478bd9Sstevel@tonic-gate  * mailx -- a modified version of a University of California at Berkeley
50*7c478bd9Sstevel@tonic-gate  *	mail program
51*7c478bd9Sstevel@tonic-gate  *
52*7c478bd9Sstevel@tonic-gate  * Startup -- interface with user.
53*7c478bd9Sstevel@tonic-gate  */
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate static void		hdrstop(int);
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate static jmp_buf	hdrjmp;
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate /*
60*7c478bd9Sstevel@tonic-gate  * Find out who the user is, copy his mail file (if exists) into
61*7c478bd9Sstevel@tonic-gate  * /tmp/Rxxxxx and set up the message pointers.  Then, print out the
62*7c478bd9Sstevel@tonic-gate  * message headers and read user commands.
63*7c478bd9Sstevel@tonic-gate  *
64*7c478bd9Sstevel@tonic-gate  * Command line syntax:
65*7c478bd9Sstevel@tonic-gate  *	mailx [ -i ] [ -r address ] [ -h number ] [ -f [ name ] ]
66*7c478bd9Sstevel@tonic-gate  * or:
67*7c478bd9Sstevel@tonic-gate  *	mailx [ -i ] [ -r address ] [ -h number ] people ...
68*7c478bd9Sstevel@tonic-gate  *
69*7c478bd9Sstevel@tonic-gate  * and a bunch of other options.
70*7c478bd9Sstevel@tonic-gate  */
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate int
73*7c478bd9Sstevel@tonic-gate main(int argc, char **argv)
74*7c478bd9Sstevel@tonic-gate {
75*7c478bd9Sstevel@tonic-gate 	register char *ef;
76*7c478bd9Sstevel@tonic-gate 	register int argp;
77*7c478bd9Sstevel@tonic-gate 	int mustsend, f, goerr = 0;
78*7c478bd9Sstevel@tonic-gate 	void (*prevint)(int);
79*7c478bd9Sstevel@tonic-gate 	int loaded = 0;
80*7c478bd9Sstevel@tonic-gate 	struct termio tbuf;
81*7c478bd9Sstevel@tonic-gate 	struct termios tbufs;
82*7c478bd9Sstevel@tonic-gate 	int c;
83*7c478bd9Sstevel@tonic-gate 	char *cwd, *mf;
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate 	/*
86*7c478bd9Sstevel@tonic-gate 	 * Set up a reasonable environment.
87*7c478bd9Sstevel@tonic-gate 	 * Figure out whether we are being run interactively, set up
88*7c478bd9Sstevel@tonic-gate 	 * all the temporary files, buffer standard output, and so forth.
89*7c478bd9Sstevel@tonic-gate 	 */
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate #ifndef preSVr4
92*7c478bd9Sstevel@tonic-gate 	(void)setlocale(LC_ALL, "");
93*7c478bd9Sstevel@tonic-gate #endif
94*7c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
95*7c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"	/* Use this only if it weren't */
96*7c478bd9Sstevel@tonic-gate #endif
97*7c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate #ifdef SIGCONT
100*7c478bd9Sstevel@tonic-gate 	sigset(SIGCONT, SIG_DFL);
101*7c478bd9Sstevel@tonic-gate #endif
102*7c478bd9Sstevel@tonic-gate 	rpterr = 0;	/* initialize; set when we output to stderr */
103*7c478bd9Sstevel@tonic-gate 	progname = argv[0];
104*7c478bd9Sstevel@tonic-gate 	if (progname[strlen(progname) - 1] != 'x') {
105*7c478bd9Sstevel@tonic-gate 		assign("bsdcompat", "");
106*7c478bd9Sstevel@tonic-gate 		assign("escapeok", "");		/* XXX */
107*7c478bd9Sstevel@tonic-gate 	}
108*7c478bd9Sstevel@tonic-gate 	myegid = getegid();
109*7c478bd9Sstevel@tonic-gate 	myrgid = getgid();
110*7c478bd9Sstevel@tonic-gate 	myeuid = geteuid();
111*7c478bd9Sstevel@tonic-gate 	myruid = getuid();
112*7c478bd9Sstevel@tonic-gate 	mypid = getpid();
113*7c478bd9Sstevel@tonic-gate 	setgid(myrgid);
114*7c478bd9Sstevel@tonic-gate 	setuid(myruid);
115*7c478bd9Sstevel@tonic-gate 	inithost();
116*7c478bd9Sstevel@tonic-gate 	intty = isatty(0);
117*7c478bd9Sstevel@tonic-gate 	if (ioctl(1, TCGETS, &tbufs) < 0) {
118*7c478bd9Sstevel@tonic-gate 		if (ioctl(1, TCGETA, &tbuf)==0) {
119*7c478bd9Sstevel@tonic-gate 			outtty = 1;
120*7c478bd9Sstevel@tonic-gate 			baud = tbuf.c_cflag & CBAUD;
121*7c478bd9Sstevel@tonic-gate 		} else
122*7c478bd9Sstevel@tonic-gate 			baud = B9600;
123*7c478bd9Sstevel@tonic-gate 	} else {
124*7c478bd9Sstevel@tonic-gate 		outtty = 1;
125*7c478bd9Sstevel@tonic-gate 		baud = cfgetospeed(&tbufs);
126*7c478bd9Sstevel@tonic-gate 	}
127*7c478bd9Sstevel@tonic-gate 	image = -1;
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate 	/*
130*7c478bd9Sstevel@tonic-gate 	 * Now, determine how we are being used.
131*7c478bd9Sstevel@tonic-gate 	 * We successively pick off instances of -r, -h, -f, and -i.
132*7c478bd9Sstevel@tonic-gate 	 * If called as "rmail" we note this fact for letter sending.
133*7c478bd9Sstevel@tonic-gate 	 * If there is anything left, it is the base of the list
134*7c478bd9Sstevel@tonic-gate 	 * of users to mail to.  Argp will be set to point to the
135*7c478bd9Sstevel@tonic-gate 	 * first of these users.
136*7c478bd9Sstevel@tonic-gate 	 */
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate 	ef = NOSTR;
139*7c478bd9Sstevel@tonic-gate 	argp = -1;
140*7c478bd9Sstevel@tonic-gate 	mustsend = 0;
141*7c478bd9Sstevel@tonic-gate 	if (argc > 0 && **argv == 'r')
142*7c478bd9Sstevel@tonic-gate 		rmail++;
143*7c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "b:Bc:defFh:HiInNr:s:u:UtT:vV~")) != EOF)
144*7c478bd9Sstevel@tonic-gate 		switch (c) {
145*7c478bd9Sstevel@tonic-gate 		case 'e':
146*7c478bd9Sstevel@tonic-gate 			/*
147*7c478bd9Sstevel@tonic-gate 			 * exit status only
148*7c478bd9Sstevel@tonic-gate 			 */
149*7c478bd9Sstevel@tonic-gate 			exitflg++;
150*7c478bd9Sstevel@tonic-gate 			break;
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate 		case 'r':
153*7c478bd9Sstevel@tonic-gate 			/*
154*7c478bd9Sstevel@tonic-gate 			 * Next argument is address to be sent along
155*7c478bd9Sstevel@tonic-gate 			 * to the mailer.
156*7c478bd9Sstevel@tonic-gate 			 */
157*7c478bd9Sstevel@tonic-gate 			mustsend++;
158*7c478bd9Sstevel@tonic-gate 			rflag = optarg;
159*7c478bd9Sstevel@tonic-gate 			break;
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate 		case 'T':
162*7c478bd9Sstevel@tonic-gate 			/*
163*7c478bd9Sstevel@tonic-gate 			 * Next argument is temp file to write which
164*7c478bd9Sstevel@tonic-gate 			 * articles have been read/deleted for netnews.
165*7c478bd9Sstevel@tonic-gate 			 */
166*7c478bd9Sstevel@tonic-gate 			Tflag = optarg;
167*7c478bd9Sstevel@tonic-gate 			if ((f = creat(Tflag, TEMPPERM)) < 0) {
168*7c478bd9Sstevel@tonic-gate 				perror(Tflag);
169*7c478bd9Sstevel@tonic-gate 				exit(1);
170*7c478bd9Sstevel@tonic-gate 			}
171*7c478bd9Sstevel@tonic-gate 			close(f);
172*7c478bd9Sstevel@tonic-gate 			/* fall through for -I too */
173*7c478bd9Sstevel@tonic-gate 			/* FALLTHROUGH */
174*7c478bd9Sstevel@tonic-gate 
175*7c478bd9Sstevel@tonic-gate 		case 'I':
176*7c478bd9Sstevel@tonic-gate 			/*
177*7c478bd9Sstevel@tonic-gate 			 * print newsgroup in header summary
178*7c478bd9Sstevel@tonic-gate 			 */
179*7c478bd9Sstevel@tonic-gate 			newsflg++;
180*7c478bd9Sstevel@tonic-gate 			break;
181*7c478bd9Sstevel@tonic-gate 
182*7c478bd9Sstevel@tonic-gate 		case 'u':
183*7c478bd9Sstevel@tonic-gate 			/*
184*7c478bd9Sstevel@tonic-gate 			 * Next argument is person's mailbox to use.
185*7c478bd9Sstevel@tonic-gate 			 * Treated the same as "-f /var/mail/user".
186*7c478bd9Sstevel@tonic-gate 			 */
187*7c478bd9Sstevel@tonic-gate 			{
188*7c478bd9Sstevel@tonic-gate 			static char u[PATHSIZE];
189*7c478bd9Sstevel@tonic-gate 			snprintf(u, sizeof (u), "%s%s", maildir, optarg);
190*7c478bd9Sstevel@tonic-gate 			ef = u;
191*7c478bd9Sstevel@tonic-gate 			break;
192*7c478bd9Sstevel@tonic-gate 			}
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate 		case 'i':
195*7c478bd9Sstevel@tonic-gate 			/*
196*7c478bd9Sstevel@tonic-gate 			 * User wants to ignore interrupts.
197*7c478bd9Sstevel@tonic-gate 			 * Set the variable "ignore"
198*7c478bd9Sstevel@tonic-gate 			 */
199*7c478bd9Sstevel@tonic-gate 			assign("ignore", "");
200*7c478bd9Sstevel@tonic-gate 			break;
201*7c478bd9Sstevel@tonic-gate 
202*7c478bd9Sstevel@tonic-gate 		case 'U':
203*7c478bd9Sstevel@tonic-gate 			UnUUCP++;
204*7c478bd9Sstevel@tonic-gate 			break;
205*7c478bd9Sstevel@tonic-gate 
206*7c478bd9Sstevel@tonic-gate 		case 'd':
207*7c478bd9Sstevel@tonic-gate 			assign("debug", "");
208*7c478bd9Sstevel@tonic-gate 			break;
209*7c478bd9Sstevel@tonic-gate 
210*7c478bd9Sstevel@tonic-gate 		case 'h':
211*7c478bd9Sstevel@tonic-gate 			/*
212*7c478bd9Sstevel@tonic-gate 			 * Specified sequence number for network.
213*7c478bd9Sstevel@tonic-gate 			 * This is the number of "hops" made so
214*7c478bd9Sstevel@tonic-gate 			 * far (count of times message has been
215*7c478bd9Sstevel@tonic-gate 			 * forwarded) to help avoid infinite mail loops.
216*7c478bd9Sstevel@tonic-gate 			 */
217*7c478bd9Sstevel@tonic-gate 			mustsend++;
218*7c478bd9Sstevel@tonic-gate 			hflag = atoi(optarg);
219*7c478bd9Sstevel@tonic-gate 			if (hflag == 0) {
220*7c478bd9Sstevel@tonic-gate 				fprintf(stderr,
221*7c478bd9Sstevel@tonic-gate 				    gettext("-h needs non-zero number\n"));
222*7c478bd9Sstevel@tonic-gate 				goerr++;
223*7c478bd9Sstevel@tonic-gate 			}
224*7c478bd9Sstevel@tonic-gate 			break;
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate 		case 's':
227*7c478bd9Sstevel@tonic-gate 			/*
228*7c478bd9Sstevel@tonic-gate 			 * Give a subject field for sending from
229*7c478bd9Sstevel@tonic-gate 			 * non terminal
230*7c478bd9Sstevel@tonic-gate 			 */
231*7c478bd9Sstevel@tonic-gate 			mustsend++;
232*7c478bd9Sstevel@tonic-gate 			sflag = optarg;
233*7c478bd9Sstevel@tonic-gate 			break;
234*7c478bd9Sstevel@tonic-gate 
235*7c478bd9Sstevel@tonic-gate 		case 'c':	/* Cc: from command line */
236*7c478bd9Sstevel@tonic-gate 			mustsend++;
237*7c478bd9Sstevel@tonic-gate 			cflag = optarg;
238*7c478bd9Sstevel@tonic-gate 			break;
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate 		case 'b':	/* Bcc: from command line */
241*7c478bd9Sstevel@tonic-gate 			mustsend++;
242*7c478bd9Sstevel@tonic-gate 			bflag = optarg;
243*7c478bd9Sstevel@tonic-gate 			break;
244*7c478bd9Sstevel@tonic-gate 
245*7c478bd9Sstevel@tonic-gate 		case 'f':
246*7c478bd9Sstevel@tonic-gate 			/*
247*7c478bd9Sstevel@tonic-gate 			 * User is specifying file to "edit" with mailx,
248*7c478bd9Sstevel@tonic-gate 			 * as opposed to reading system mailbox.
249*7c478bd9Sstevel@tonic-gate 			 * If no argument is given after -f, we read his/her
250*7c478bd9Sstevel@tonic-gate 			 * $MBOX file or mbox in his/her home directory.
251*7c478bd9Sstevel@tonic-gate 			 */
252*7c478bd9Sstevel@tonic-gate 			ef = (argc == optind || *argv[optind] == '-')
253*7c478bd9Sstevel@tonic-gate 				? "" : argv[optind++];
254*7c478bd9Sstevel@tonic-gate 			if (*ef && *ef != '/' && *ef != '+')
255*7c478bd9Sstevel@tonic-gate 				cwd = getcwd(NOSTR, PATHSIZE);
256*7c478bd9Sstevel@tonic-gate 			break;
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate 		case 'F':
259*7c478bd9Sstevel@tonic-gate 			Fflag++;
260*7c478bd9Sstevel@tonic-gate 			mustsend++;
261*7c478bd9Sstevel@tonic-gate 			break;
262*7c478bd9Sstevel@tonic-gate 
263*7c478bd9Sstevel@tonic-gate 		case 'n':
264*7c478bd9Sstevel@tonic-gate 			/*
265*7c478bd9Sstevel@tonic-gate 			 * User doesn't want to source
266*7c478bd9Sstevel@tonic-gate 			 *	/etc/mail/mailx.rc
267*7c478bd9Sstevel@tonic-gate 			 */
268*7c478bd9Sstevel@tonic-gate 			nosrc++;
269*7c478bd9Sstevel@tonic-gate 			break;
270*7c478bd9Sstevel@tonic-gate 
271*7c478bd9Sstevel@tonic-gate 		case 'N':
272*7c478bd9Sstevel@tonic-gate 			/*
273*7c478bd9Sstevel@tonic-gate 			 * Avoid initial header printing.
274*7c478bd9Sstevel@tonic-gate 			 */
275*7c478bd9Sstevel@tonic-gate 			noheader++;
276*7c478bd9Sstevel@tonic-gate 			break;
277*7c478bd9Sstevel@tonic-gate 
278*7c478bd9Sstevel@tonic-gate 		case 'H':
279*7c478bd9Sstevel@tonic-gate 			/*
280*7c478bd9Sstevel@tonic-gate 			 * Print headers and exit
281*7c478bd9Sstevel@tonic-gate 			 */
282*7c478bd9Sstevel@tonic-gate 			Hflag++;
283*7c478bd9Sstevel@tonic-gate 			break;
284*7c478bd9Sstevel@tonic-gate 
285*7c478bd9Sstevel@tonic-gate 		case 'V':
286*7c478bd9Sstevel@tonic-gate 			puts(version);
287*7c478bd9Sstevel@tonic-gate 			return 0;
288*7c478bd9Sstevel@tonic-gate 
289*7c478bd9Sstevel@tonic-gate 		case '~':
290*7c478bd9Sstevel@tonic-gate 			/*
291*7c478bd9Sstevel@tonic-gate 			 * Permit tildas no matter where
292*7c478bd9Sstevel@tonic-gate 			 * the input is coming from.
293*7c478bd9Sstevel@tonic-gate 			 */
294*7c478bd9Sstevel@tonic-gate 			assign("escapeok", "");
295*7c478bd9Sstevel@tonic-gate 			break;
296*7c478bd9Sstevel@tonic-gate 
297*7c478bd9Sstevel@tonic-gate 		case 'v':
298*7c478bd9Sstevel@tonic-gate 			/*
299*7c478bd9Sstevel@tonic-gate 			 * Send mailer verbose flag
300*7c478bd9Sstevel@tonic-gate 			 */
301*7c478bd9Sstevel@tonic-gate 			assign("verbose", "");
302*7c478bd9Sstevel@tonic-gate 			break;
303*7c478bd9Sstevel@tonic-gate 
304*7c478bd9Sstevel@tonic-gate 		case 'B':
305*7c478bd9Sstevel@tonic-gate 			/*
306*7c478bd9Sstevel@tonic-gate 			 * Don't buffer output
307*7c478bd9Sstevel@tonic-gate 			 * (Line buffered is good enough)
308*7c478bd9Sstevel@tonic-gate 			 */
309*7c478bd9Sstevel@tonic-gate 			setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
310*7c478bd9Sstevel@tonic-gate 			setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
311*7c478bd9Sstevel@tonic-gate 			break;
312*7c478bd9Sstevel@tonic-gate 
313*7c478bd9Sstevel@tonic-gate 		case 't':
314*7c478bd9Sstevel@tonic-gate 			/*
315*7c478bd9Sstevel@tonic-gate 			 * Like sendmail -t, read headers from text
316*7c478bd9Sstevel@tonic-gate 			 */
317*7c478bd9Sstevel@tonic-gate 			tflag++;
318*7c478bd9Sstevel@tonic-gate 			mustsend++;
319*7c478bd9Sstevel@tonic-gate 			break;
320*7c478bd9Sstevel@tonic-gate 
321*7c478bd9Sstevel@tonic-gate 		case '?':
322*7c478bd9Sstevel@tonic-gate 		default:
323*7c478bd9Sstevel@tonic-gate 			goerr++;
324*7c478bd9Sstevel@tonic-gate 			break;
325*7c478bd9Sstevel@tonic-gate 		}
326*7c478bd9Sstevel@tonic-gate 
327*7c478bd9Sstevel@tonic-gate 	if (optind != argc)
328*7c478bd9Sstevel@tonic-gate 		argp = optind;
329*7c478bd9Sstevel@tonic-gate 
330*7c478bd9Sstevel@tonic-gate 	/*
331*7c478bd9Sstevel@tonic-gate 	 * Check for inconsistent arguments.
332*7c478bd9Sstevel@tonic-gate 	 */
333*7c478bd9Sstevel@tonic-gate 
334*7c478bd9Sstevel@tonic-gate 	if (newsflg && ef==NOSTR) {
335*7c478bd9Sstevel@tonic-gate 		fprintf(stderr, gettext("Need -f with -I flag\n"));
336*7c478bd9Sstevel@tonic-gate 		goerr++;
337*7c478bd9Sstevel@tonic-gate 	}
338*7c478bd9Sstevel@tonic-gate 	if (ef != NOSTR && argp != -1) {
339*7c478bd9Sstevel@tonic-gate 		fprintf(stderr,
340*7c478bd9Sstevel@tonic-gate 		    gettext("Cannot give -f and people to send to.\n"));
341*7c478bd9Sstevel@tonic-gate 		goerr++;
342*7c478bd9Sstevel@tonic-gate 	}
343*7c478bd9Sstevel@tonic-gate 	if (exitflg && (mustsend || argp != -1))
344*7c478bd9Sstevel@tonic-gate 		exit(1);	/* nonsense flags involving -e simply exit */
345*7c478bd9Sstevel@tonic-gate 	if (tflag && argp != -1) {
346*7c478bd9Sstevel@tonic-gate 		fprintf(stderr,
347*7c478bd9Sstevel@tonic-gate 		    gettext("Ignoring recipients on command line with -t\n"));
348*7c478bd9Sstevel@tonic-gate 		argp = -1;
349*7c478bd9Sstevel@tonic-gate 	} else if (!tflag && mustsend && argp == -1) {
350*7c478bd9Sstevel@tonic-gate 		fprintf(stderr,
351*7c478bd9Sstevel@tonic-gate 	    gettext("The flags you gave are used only when sending mail.\n"));
352*7c478bd9Sstevel@tonic-gate 		goerr++;
353*7c478bd9Sstevel@tonic-gate 	}
354*7c478bd9Sstevel@tonic-gate 	if (goerr) {
355*7c478bd9Sstevel@tonic-gate 		fprintf(stderr,
356*7c478bd9Sstevel@tonic-gate gettext("Usage: %s -eiIUdFntBNHvV~ -T FILE -u USER -h hops -r address\n"),
357*7c478bd9Sstevel@tonic-gate 		    progname);
358*7c478bd9Sstevel@tonic-gate 		fprintf(stderr,
359*7c478bd9Sstevel@tonic-gate 		    gettext("\t\t-s SUBJECT -f FILE users\n"));
360*7c478bd9Sstevel@tonic-gate 		exit(1);
361*7c478bd9Sstevel@tonic-gate 	}
362*7c478bd9Sstevel@tonic-gate 	tinit();
363*7c478bd9Sstevel@tonic-gate 	input = stdin;
364*7c478bd9Sstevel@tonic-gate 	rcvmode = !tflag && argp == -1;
365*7c478bd9Sstevel@tonic-gate 	if (!nosrc)
366*7c478bd9Sstevel@tonic-gate 		load(MASTER);
367*7c478bd9Sstevel@tonic-gate 
368*7c478bd9Sstevel@tonic-gate 	if (!rcvmode) {
369*7c478bd9Sstevel@tonic-gate 		load(Getf("MAILRC"));
370*7c478bd9Sstevel@tonic-gate 		if (tflag)
371*7c478bd9Sstevel@tonic-gate 			tmail();
372*7c478bd9Sstevel@tonic-gate 		else
373*7c478bd9Sstevel@tonic-gate 			mail(&argv[argp]);
374*7c478bd9Sstevel@tonic-gate 		exit(senderr ? senderr : rpterr);
375*7c478bd9Sstevel@tonic-gate 	}
376*7c478bd9Sstevel@tonic-gate 
377*7c478bd9Sstevel@tonic-gate 	/*
378*7c478bd9Sstevel@tonic-gate 	 * Ok, we are reading mail.
379*7c478bd9Sstevel@tonic-gate 	 * Decide whether we are editing a mailbox or reading
380*7c478bd9Sstevel@tonic-gate 	 * the system mailbox, and open up the right stuff.
381*7c478bd9Sstevel@tonic-gate 	 *
382*7c478bd9Sstevel@tonic-gate 	 * Do this before sourcing the MAILRC, because there might be
383*7c478bd9Sstevel@tonic-gate 	 * a 'chdir' there that breaks the -f option.  But if the
384*7c478bd9Sstevel@tonic-gate 	 * file specified with -f is a folder name, go ahead and
385*7c478bd9Sstevel@tonic-gate 	 * source the MAILRC anyway so that "folder" will be defined.
386*7c478bd9Sstevel@tonic-gate 	 */
387*7c478bd9Sstevel@tonic-gate 
388*7c478bd9Sstevel@tonic-gate 	nstrcpy(origname, PATHSIZE, mailname);
389*7c478bd9Sstevel@tonic-gate 	editfile = mailname;
390*7c478bd9Sstevel@tonic-gate 
391*7c478bd9Sstevel@tonic-gate 	if (ef != NOSTR) {
392*7c478bd9Sstevel@tonic-gate 		if (ef == NOSTR || *ef == '\0' || *ef == '+') {
393*7c478bd9Sstevel@tonic-gate 			load(Getf("MAILRC"));
394*7c478bd9Sstevel@tonic-gate 			loaded++;
395*7c478bd9Sstevel@tonic-gate 		}
396*7c478bd9Sstevel@tonic-gate 		ef = *ef ? safeexpand(ef) : Getf("MBOX");
397*7c478bd9Sstevel@tonic-gate 		nstrcpy(origname, PATHSIZE, ef);
398*7c478bd9Sstevel@tonic-gate 		if (ef[0] != '/') {
399*7c478bd9Sstevel@tonic-gate 			if (cwd == NOSTR)
400*7c478bd9Sstevel@tonic-gate 				cwd = getcwd(NOSTR, PATHSIZE);
401*7c478bd9Sstevel@tonic-gate 			nstrcat(cwd, PATHSIZE, "/");
402*7c478bd9Sstevel@tonic-gate 			nstrcat(cwd, PATHSIZE, ef);
403*7c478bd9Sstevel@tonic-gate 			ef = cwd;
404*7c478bd9Sstevel@tonic-gate 		}
405*7c478bd9Sstevel@tonic-gate 		editfile = ef;
406*7c478bd9Sstevel@tonic-gate 		edit++;
407*7c478bd9Sstevel@tonic-gate 	}
408*7c478bd9Sstevel@tonic-gate 
409*7c478bd9Sstevel@tonic-gate 	if (setfile(editfile, edit) < 0)
410*7c478bd9Sstevel@tonic-gate 		exit(1);
411*7c478bd9Sstevel@tonic-gate 
412*7c478bd9Sstevel@tonic-gate 	if (!loaded)
413*7c478bd9Sstevel@tonic-gate 		load(Getf("MAILRC"));
414*7c478bd9Sstevel@tonic-gate 	if (msgCount > 0 && !noheader && value("header") != NOSTR) {
415*7c478bd9Sstevel@tonic-gate 		if (setjmp(hdrjmp) == 0) {
416*7c478bd9Sstevel@tonic-gate 			if ((prevint = sigset(SIGINT, SIG_IGN)) != SIG_IGN)
417*7c478bd9Sstevel@tonic-gate 				sigset(SIGINT, hdrstop);
418*7c478bd9Sstevel@tonic-gate 			announce();
419*7c478bd9Sstevel@tonic-gate 			fflush(stdout);
420*7c478bd9Sstevel@tonic-gate 			sigset(SIGINT, prevint);
421*7c478bd9Sstevel@tonic-gate 		}
422*7c478bd9Sstevel@tonic-gate 	}
423*7c478bd9Sstevel@tonic-gate 	if (Hflag || (!edit && msgCount == 0)) {
424*7c478bd9Sstevel@tonic-gate 		if (!Hflag) {
425*7c478bd9Sstevel@tonic-gate 			fprintf(stderr, gettext("No mail for %s\n"), myname);
426*7c478bd9Sstevel@tonic-gate 			Verhogen();
427*7c478bd9Sstevel@tonic-gate 		}
428*7c478bd9Sstevel@tonic-gate 		fflush(stdout);
429*7c478bd9Sstevel@tonic-gate 		exit(rpterr);
430*7c478bd9Sstevel@tonic-gate 	}
431*7c478bd9Sstevel@tonic-gate 	commands();
432*7c478bd9Sstevel@tonic-gate 	sigset(SIGHUP, SIG_IGN);
433*7c478bd9Sstevel@tonic-gate 	sigset(SIGINT, SIG_IGN);
434*7c478bd9Sstevel@tonic-gate 	sigset(SIGQUIT, SIG_IGN);
435*7c478bd9Sstevel@tonic-gate 	if (!outtty)
436*7c478bd9Sstevel@tonic-gate 		sigset(SIGPIPE, SIG_IGN);
437*7c478bd9Sstevel@tonic-gate 	if (edit)
438*7c478bd9Sstevel@tonic-gate 		edstop(0);
439*7c478bd9Sstevel@tonic-gate 	else {
440*7c478bd9Sstevel@tonic-gate 		quit(0);
441*7c478bd9Sstevel@tonic-gate 		Verhogen();
442*7c478bd9Sstevel@tonic-gate 	}
443*7c478bd9Sstevel@tonic-gate 	exit(rpterr);
444*7c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
445*7c478bd9Sstevel@tonic-gate }
446*7c478bd9Sstevel@tonic-gate 
447*7c478bd9Sstevel@tonic-gate /*
448*7c478bd9Sstevel@tonic-gate  * Interrupt printing of the headers.
449*7c478bd9Sstevel@tonic-gate  */
450*7c478bd9Sstevel@tonic-gate static void
451*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
452*7c478bd9Sstevel@tonic-gate hdrstop(int)
453*7c478bd9Sstevel@tonic-gate #else
454*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
455*7c478bd9Sstevel@tonic-gate hdrstop(int s)
456*7c478bd9Sstevel@tonic-gate #endif
457*7c478bd9Sstevel@tonic-gate {
458*7c478bd9Sstevel@tonic-gate 
459*7c478bd9Sstevel@tonic-gate 	fflush(stdout);
460*7c478bd9Sstevel@tonic-gate 	fprintf(stderr, gettext("\nInterrupt\n"));
461*7c478bd9Sstevel@tonic-gate # ifdef OLD_BSD_SIGS
462*7c478bd9Sstevel@tonic-gate 	sigrelse(SIGINT);
463*7c478bd9Sstevel@tonic-gate # endif
464*7c478bd9Sstevel@tonic-gate 	longjmp(hdrjmp, 1);
465*7c478bd9Sstevel@tonic-gate }
466