xref: /titanic_44/usr/src/cmd/mailx/main.c (revision 6c83d09f819e9de7126c8539546eca2e276df44a)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate 
237c478bd9Sstevel@tonic-gate /*
24*6c83d09fSrobbin  * Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
25*6c83d09fSrobbin  * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
28*6c83d09fSrobbin /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
29*6c83d09fSrobbin /*	  All Rights Reserved  	*/
30*6c83d09fSrobbin 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
337c478bd9Sstevel@tonic-gate  * The Regents of the University of California
347c478bd9Sstevel@tonic-gate  * All Rights Reserved
357c478bd9Sstevel@tonic-gate  *
367c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
377c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
387c478bd9Sstevel@tonic-gate  * contributors.
397c478bd9Sstevel@tonic-gate  */
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #include "rcv.h"
447c478bd9Sstevel@tonic-gate #ifndef preSVr4
457c478bd9Sstevel@tonic-gate #include <locale.h>
467c478bd9Sstevel@tonic-gate #endif
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate /*
497c478bd9Sstevel@tonic-gate  * mailx -- a modified version of a University of California at Berkeley
507c478bd9Sstevel@tonic-gate  *	mail program
517c478bd9Sstevel@tonic-gate  *
527c478bd9Sstevel@tonic-gate  * Startup -- interface with user.
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate static void		hdrstop(int);
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate static jmp_buf	hdrjmp;
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate /*
607c478bd9Sstevel@tonic-gate  * Find out who the user is, copy his mail file (if exists) into
617c478bd9Sstevel@tonic-gate  * /tmp/Rxxxxx and set up the message pointers.  Then, print out the
627c478bd9Sstevel@tonic-gate  * message headers and read user commands.
637c478bd9Sstevel@tonic-gate  *
647c478bd9Sstevel@tonic-gate  * Command line syntax:
657c478bd9Sstevel@tonic-gate  *	mailx [ -i ] [ -r address ] [ -h number ] [ -f [ name ] ]
667c478bd9Sstevel@tonic-gate  * or:
677c478bd9Sstevel@tonic-gate  *	mailx [ -i ] [ -r address ] [ -h number ] people ...
687c478bd9Sstevel@tonic-gate  *
697c478bd9Sstevel@tonic-gate  * and a bunch of other options.
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate int
737c478bd9Sstevel@tonic-gate main(int argc, char **argv)
747c478bd9Sstevel@tonic-gate {
757c478bd9Sstevel@tonic-gate 	register char *ef;
767c478bd9Sstevel@tonic-gate 	register int argp;
777c478bd9Sstevel@tonic-gate 	int mustsend, f, goerr = 0;
787c478bd9Sstevel@tonic-gate 	void (*prevint)(int);
797c478bd9Sstevel@tonic-gate 	int loaded = 0;
807c478bd9Sstevel@tonic-gate 	struct termio tbuf;
817c478bd9Sstevel@tonic-gate 	struct termios tbufs;
827c478bd9Sstevel@tonic-gate 	int c;
837c478bd9Sstevel@tonic-gate 	char *cwd, *mf;
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 	/*
867c478bd9Sstevel@tonic-gate 	 * Set up a reasonable environment.
877c478bd9Sstevel@tonic-gate 	 * Figure out whether we are being run interactively, set up
887c478bd9Sstevel@tonic-gate 	 * all the temporary files, buffer standard output, and so forth.
897c478bd9Sstevel@tonic-gate 	 */
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate #ifndef preSVr4
927c478bd9Sstevel@tonic-gate 	(void)setlocale(LC_ALL, "");
937c478bd9Sstevel@tonic-gate #endif
947c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
957c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"	/* Use this only if it weren't */
967c478bd9Sstevel@tonic-gate #endif
977c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate #ifdef SIGCONT
1007c478bd9Sstevel@tonic-gate 	sigset(SIGCONT, SIG_DFL);
1017c478bd9Sstevel@tonic-gate #endif
1027c478bd9Sstevel@tonic-gate 	rpterr = 0;	/* initialize; set when we output to stderr */
1037c478bd9Sstevel@tonic-gate 	progname = argv[0];
1047c478bd9Sstevel@tonic-gate 	if (progname[strlen(progname) - 1] != 'x') {
1057c478bd9Sstevel@tonic-gate 		assign("bsdcompat", "");
1067c478bd9Sstevel@tonic-gate 		assign("escapeok", "");		/* XXX */
1077c478bd9Sstevel@tonic-gate 	}
1087c478bd9Sstevel@tonic-gate 	myegid = getegid();
1097c478bd9Sstevel@tonic-gate 	myrgid = getgid();
1107c478bd9Sstevel@tonic-gate 	myeuid = geteuid();
1117c478bd9Sstevel@tonic-gate 	myruid = getuid();
1127c478bd9Sstevel@tonic-gate 	mypid = getpid();
1137c478bd9Sstevel@tonic-gate 	setgid(myrgid);
1147c478bd9Sstevel@tonic-gate 	setuid(myruid);
1157c478bd9Sstevel@tonic-gate 	inithost();
1167c478bd9Sstevel@tonic-gate 	intty = isatty(0);
1177c478bd9Sstevel@tonic-gate 	if (ioctl(1, TCGETS, &tbufs) < 0) {
1187c478bd9Sstevel@tonic-gate 		if (ioctl(1, TCGETA, &tbuf)==0) {
1197c478bd9Sstevel@tonic-gate 			outtty = 1;
1207c478bd9Sstevel@tonic-gate 			baud = tbuf.c_cflag & CBAUD;
1217c478bd9Sstevel@tonic-gate 		} else
1227c478bd9Sstevel@tonic-gate 			baud = B9600;
1237c478bd9Sstevel@tonic-gate 	} else {
1247c478bd9Sstevel@tonic-gate 		outtty = 1;
1257c478bd9Sstevel@tonic-gate 		baud = cfgetospeed(&tbufs);
1267c478bd9Sstevel@tonic-gate 	}
1277c478bd9Sstevel@tonic-gate 	image = -1;
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 	/*
1307c478bd9Sstevel@tonic-gate 	 * Now, determine how we are being used.
1317c478bd9Sstevel@tonic-gate 	 * We successively pick off instances of -r, -h, -f, and -i.
1327c478bd9Sstevel@tonic-gate 	 * If called as "rmail" we note this fact for letter sending.
1337c478bd9Sstevel@tonic-gate 	 * If there is anything left, it is the base of the list
1347c478bd9Sstevel@tonic-gate 	 * of users to mail to.  Argp will be set to point to the
1357c478bd9Sstevel@tonic-gate 	 * first of these users.
1367c478bd9Sstevel@tonic-gate 	 */
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 	ef = NOSTR;
1397c478bd9Sstevel@tonic-gate 	argp = -1;
1407c478bd9Sstevel@tonic-gate 	mustsend = 0;
1417c478bd9Sstevel@tonic-gate 	if (argc > 0 && **argv == 'r')
1427c478bd9Sstevel@tonic-gate 		rmail++;
1437c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "b:Bc:defFh:HiInNr:s:u:UtT:vV~")) != EOF)
1447c478bd9Sstevel@tonic-gate 		switch (c) {
1457c478bd9Sstevel@tonic-gate 		case 'e':
1467c478bd9Sstevel@tonic-gate 			/*
1477c478bd9Sstevel@tonic-gate 			 * exit status only
1487c478bd9Sstevel@tonic-gate 			 */
1497c478bd9Sstevel@tonic-gate 			exitflg++;
1507c478bd9Sstevel@tonic-gate 			break;
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 		case 'r':
1537c478bd9Sstevel@tonic-gate 			/*
1547c478bd9Sstevel@tonic-gate 			 * Next argument is address to be sent along
1557c478bd9Sstevel@tonic-gate 			 * to the mailer.
1567c478bd9Sstevel@tonic-gate 			 */
1577c478bd9Sstevel@tonic-gate 			mustsend++;
1587c478bd9Sstevel@tonic-gate 			rflag = optarg;
1597c478bd9Sstevel@tonic-gate 			break;
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 		case 'T':
1627c478bd9Sstevel@tonic-gate 			/*
1637c478bd9Sstevel@tonic-gate 			 * Next argument is temp file to write which
1647c478bd9Sstevel@tonic-gate 			 * articles have been read/deleted for netnews.
1657c478bd9Sstevel@tonic-gate 			 */
1667c478bd9Sstevel@tonic-gate 			Tflag = optarg;
1677c478bd9Sstevel@tonic-gate 			if ((f = creat(Tflag, TEMPPERM)) < 0) {
1687c478bd9Sstevel@tonic-gate 				perror(Tflag);
1697c478bd9Sstevel@tonic-gate 				exit(1);
1707c478bd9Sstevel@tonic-gate 			}
1717c478bd9Sstevel@tonic-gate 			close(f);
1727c478bd9Sstevel@tonic-gate 			/* fall through for -I too */
1737c478bd9Sstevel@tonic-gate 			/* FALLTHROUGH */
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 		case 'I':
1767c478bd9Sstevel@tonic-gate 			/*
1777c478bd9Sstevel@tonic-gate 			 * print newsgroup in header summary
1787c478bd9Sstevel@tonic-gate 			 */
1797c478bd9Sstevel@tonic-gate 			newsflg++;
1807c478bd9Sstevel@tonic-gate 			break;
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate 		case 'u':
1837c478bd9Sstevel@tonic-gate 			/*
1847c478bd9Sstevel@tonic-gate 			 * Next argument is person's mailbox to use.
1857c478bd9Sstevel@tonic-gate 			 * Treated the same as "-f /var/mail/user".
1867c478bd9Sstevel@tonic-gate 			 */
1877c478bd9Sstevel@tonic-gate 			{
1887c478bd9Sstevel@tonic-gate 			static char u[PATHSIZE];
1897c478bd9Sstevel@tonic-gate 			snprintf(u, sizeof (u), "%s%s", maildir, optarg);
1907c478bd9Sstevel@tonic-gate 			ef = u;
1917c478bd9Sstevel@tonic-gate 			break;
1927c478bd9Sstevel@tonic-gate 			}
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 		case 'i':
1957c478bd9Sstevel@tonic-gate 			/*
1967c478bd9Sstevel@tonic-gate 			 * User wants to ignore interrupts.
1977c478bd9Sstevel@tonic-gate 			 * Set the variable "ignore"
1987c478bd9Sstevel@tonic-gate 			 */
1997c478bd9Sstevel@tonic-gate 			assign("ignore", "");
2007c478bd9Sstevel@tonic-gate 			break;
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 		case 'U':
2037c478bd9Sstevel@tonic-gate 			UnUUCP++;
2047c478bd9Sstevel@tonic-gate 			break;
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 		case 'd':
2077c478bd9Sstevel@tonic-gate 			assign("debug", "");
2087c478bd9Sstevel@tonic-gate 			break;
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 		case 'h':
2117c478bd9Sstevel@tonic-gate 			/*
2127c478bd9Sstevel@tonic-gate 			 * Specified sequence number for network.
2137c478bd9Sstevel@tonic-gate 			 * This is the number of "hops" made so
2147c478bd9Sstevel@tonic-gate 			 * far (count of times message has been
2157c478bd9Sstevel@tonic-gate 			 * forwarded) to help avoid infinite mail loops.
2167c478bd9Sstevel@tonic-gate 			 */
2177c478bd9Sstevel@tonic-gate 			mustsend++;
2187c478bd9Sstevel@tonic-gate 			hflag = atoi(optarg);
2197c478bd9Sstevel@tonic-gate 			if (hflag == 0) {
2207c478bd9Sstevel@tonic-gate 				fprintf(stderr,
2217c478bd9Sstevel@tonic-gate 				    gettext("-h needs non-zero number\n"));
2227c478bd9Sstevel@tonic-gate 				goerr++;
2237c478bd9Sstevel@tonic-gate 			}
2247c478bd9Sstevel@tonic-gate 			break;
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate 		case 's':
2277c478bd9Sstevel@tonic-gate 			/*
2287c478bd9Sstevel@tonic-gate 			 * Give a subject field for sending from
2297c478bd9Sstevel@tonic-gate 			 * non terminal
2307c478bd9Sstevel@tonic-gate 			 */
2317c478bd9Sstevel@tonic-gate 			mustsend++;
2327c478bd9Sstevel@tonic-gate 			sflag = optarg;
2337c478bd9Sstevel@tonic-gate 			break;
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate 		case 'c':	/* Cc: from command line */
2367c478bd9Sstevel@tonic-gate 			mustsend++;
2377c478bd9Sstevel@tonic-gate 			cflag = optarg;
2387c478bd9Sstevel@tonic-gate 			break;
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate 		case 'b':	/* Bcc: from command line */
2417c478bd9Sstevel@tonic-gate 			mustsend++;
2427c478bd9Sstevel@tonic-gate 			bflag = optarg;
2437c478bd9Sstevel@tonic-gate 			break;
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 		case 'f':
2467c478bd9Sstevel@tonic-gate 			/*
2477c478bd9Sstevel@tonic-gate 			 * User is specifying file to "edit" with mailx,
2487c478bd9Sstevel@tonic-gate 			 * as opposed to reading system mailbox.
2497c478bd9Sstevel@tonic-gate 			 * If no argument is given after -f, we read his/her
2507c478bd9Sstevel@tonic-gate 			 * $MBOX file or mbox in his/her home directory.
2517c478bd9Sstevel@tonic-gate 			 */
2527c478bd9Sstevel@tonic-gate 			ef = (argc == optind || *argv[optind] == '-')
2537c478bd9Sstevel@tonic-gate 				? "" : argv[optind++];
2547c478bd9Sstevel@tonic-gate 			if (*ef && *ef != '/' && *ef != '+')
2557c478bd9Sstevel@tonic-gate 				cwd = getcwd(NOSTR, PATHSIZE);
2567c478bd9Sstevel@tonic-gate 			break;
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate 		case 'F':
2597c478bd9Sstevel@tonic-gate 			Fflag++;
2607c478bd9Sstevel@tonic-gate 			mustsend++;
2617c478bd9Sstevel@tonic-gate 			break;
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate 		case 'n':
2647c478bd9Sstevel@tonic-gate 			/*
2657c478bd9Sstevel@tonic-gate 			 * User doesn't want to source
2667c478bd9Sstevel@tonic-gate 			 *	/etc/mail/mailx.rc
2677c478bd9Sstevel@tonic-gate 			 */
2687c478bd9Sstevel@tonic-gate 			nosrc++;
2697c478bd9Sstevel@tonic-gate 			break;
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate 		case 'N':
2727c478bd9Sstevel@tonic-gate 			/*
2737c478bd9Sstevel@tonic-gate 			 * Avoid initial header printing.
2747c478bd9Sstevel@tonic-gate 			 */
2757c478bd9Sstevel@tonic-gate 			noheader++;
2767c478bd9Sstevel@tonic-gate 			break;
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 		case 'H':
2797c478bd9Sstevel@tonic-gate 			/*
2807c478bd9Sstevel@tonic-gate 			 * Print headers and exit
2817c478bd9Sstevel@tonic-gate 			 */
2827c478bd9Sstevel@tonic-gate 			Hflag++;
2837c478bd9Sstevel@tonic-gate 			break;
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate 		case 'V':
2867c478bd9Sstevel@tonic-gate 			puts(version);
2877c478bd9Sstevel@tonic-gate 			return 0;
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate 		case '~':
2907c478bd9Sstevel@tonic-gate 			/*
2917c478bd9Sstevel@tonic-gate 			 * Permit tildas no matter where
2927c478bd9Sstevel@tonic-gate 			 * the input is coming from.
2937c478bd9Sstevel@tonic-gate 			 */
2947c478bd9Sstevel@tonic-gate 			assign("escapeok", "");
2957c478bd9Sstevel@tonic-gate 			break;
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate 		case 'v':
2987c478bd9Sstevel@tonic-gate 			/*
2997c478bd9Sstevel@tonic-gate 			 * Send mailer verbose flag
3007c478bd9Sstevel@tonic-gate 			 */
3017c478bd9Sstevel@tonic-gate 			assign("verbose", "");
3027c478bd9Sstevel@tonic-gate 			break;
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 		case 'B':
3057c478bd9Sstevel@tonic-gate 			/*
3067c478bd9Sstevel@tonic-gate 			 * Don't buffer output
3077c478bd9Sstevel@tonic-gate 			 * (Line buffered is good enough)
3087c478bd9Sstevel@tonic-gate 			 */
3097c478bd9Sstevel@tonic-gate 			setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
3107c478bd9Sstevel@tonic-gate 			setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
3117c478bd9Sstevel@tonic-gate 			break;
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate 		case 't':
3147c478bd9Sstevel@tonic-gate 			/*
3157c478bd9Sstevel@tonic-gate 			 * Like sendmail -t, read headers from text
3167c478bd9Sstevel@tonic-gate 			 */
3177c478bd9Sstevel@tonic-gate 			tflag++;
3187c478bd9Sstevel@tonic-gate 			mustsend++;
3197c478bd9Sstevel@tonic-gate 			break;
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate 		case '?':
3227c478bd9Sstevel@tonic-gate 		default:
3237c478bd9Sstevel@tonic-gate 			goerr++;
3247c478bd9Sstevel@tonic-gate 			break;
3257c478bd9Sstevel@tonic-gate 		}
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate 	if (optind != argc)
3287c478bd9Sstevel@tonic-gate 		argp = optind;
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate 	/*
3317c478bd9Sstevel@tonic-gate 	 * Check for inconsistent arguments.
3327c478bd9Sstevel@tonic-gate 	 */
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate 	if (newsflg && ef==NOSTR) {
3357c478bd9Sstevel@tonic-gate 		fprintf(stderr, gettext("Need -f with -I flag\n"));
3367c478bd9Sstevel@tonic-gate 		goerr++;
3377c478bd9Sstevel@tonic-gate 	}
3387c478bd9Sstevel@tonic-gate 	if (ef != NOSTR && argp != -1) {
3397c478bd9Sstevel@tonic-gate 		fprintf(stderr,
3407c478bd9Sstevel@tonic-gate 		    gettext("Cannot give -f and people to send to.\n"));
3417c478bd9Sstevel@tonic-gate 		goerr++;
3427c478bd9Sstevel@tonic-gate 	}
3437c478bd9Sstevel@tonic-gate 	if (exitflg && (mustsend || argp != -1))
3447c478bd9Sstevel@tonic-gate 		exit(1);	/* nonsense flags involving -e simply exit */
3457c478bd9Sstevel@tonic-gate 	if (tflag && argp != -1) {
3467c478bd9Sstevel@tonic-gate 		fprintf(stderr,
3477c478bd9Sstevel@tonic-gate 		    gettext("Ignoring recipients on command line with -t\n"));
3487c478bd9Sstevel@tonic-gate 		argp = -1;
3497c478bd9Sstevel@tonic-gate 	} else if (!tflag && mustsend && argp == -1) {
3507c478bd9Sstevel@tonic-gate 		fprintf(stderr,
3517c478bd9Sstevel@tonic-gate 	    gettext("The flags you gave are used only when sending mail.\n"));
3527c478bd9Sstevel@tonic-gate 		goerr++;
3537c478bd9Sstevel@tonic-gate 	}
3547c478bd9Sstevel@tonic-gate 	if (goerr) {
3557c478bd9Sstevel@tonic-gate 		fprintf(stderr,
3567c478bd9Sstevel@tonic-gate gettext("Usage: %s -eiIUdFntBNHvV~ -T FILE -u USER -h hops -r address\n"),
3577c478bd9Sstevel@tonic-gate 		    progname);
3587c478bd9Sstevel@tonic-gate 		fprintf(stderr,
3597c478bd9Sstevel@tonic-gate 		    gettext("\t\t-s SUBJECT -f FILE users\n"));
3607c478bd9Sstevel@tonic-gate 		exit(1);
3617c478bd9Sstevel@tonic-gate 	}
3627c478bd9Sstevel@tonic-gate 	tinit();
3637c478bd9Sstevel@tonic-gate 	input = stdin;
3647c478bd9Sstevel@tonic-gate 	rcvmode = !tflag && argp == -1;
3657c478bd9Sstevel@tonic-gate 	if (!nosrc)
3667c478bd9Sstevel@tonic-gate 		load(MASTER);
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate 	if (!rcvmode) {
3697c478bd9Sstevel@tonic-gate 		load(Getf("MAILRC"));
3707c478bd9Sstevel@tonic-gate 		if (tflag)
3717c478bd9Sstevel@tonic-gate 			tmail();
3727c478bd9Sstevel@tonic-gate 		else
3737c478bd9Sstevel@tonic-gate 			mail(&argv[argp]);
3747c478bd9Sstevel@tonic-gate 		exit(senderr ? senderr : rpterr);
3757c478bd9Sstevel@tonic-gate 	}
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate 	/*
3787c478bd9Sstevel@tonic-gate 	 * Ok, we are reading mail.
3797c478bd9Sstevel@tonic-gate 	 * Decide whether we are editing a mailbox or reading
3807c478bd9Sstevel@tonic-gate 	 * the system mailbox, and open up the right stuff.
3817c478bd9Sstevel@tonic-gate 	 *
3827c478bd9Sstevel@tonic-gate 	 * Do this before sourcing the MAILRC, because there might be
3837c478bd9Sstevel@tonic-gate 	 * a 'chdir' there that breaks the -f option.  But if the
3847c478bd9Sstevel@tonic-gate 	 * file specified with -f is a folder name, go ahead and
3857c478bd9Sstevel@tonic-gate 	 * source the MAILRC anyway so that "folder" will be defined.
3867c478bd9Sstevel@tonic-gate 	 */
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate 	nstrcpy(origname, PATHSIZE, mailname);
3897c478bd9Sstevel@tonic-gate 	editfile = mailname;
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate 	if (ef != NOSTR) {
3927c478bd9Sstevel@tonic-gate 		if (ef == NOSTR || *ef == '\0' || *ef == '+') {
3937c478bd9Sstevel@tonic-gate 			load(Getf("MAILRC"));
3947c478bd9Sstevel@tonic-gate 			loaded++;
3957c478bd9Sstevel@tonic-gate 		}
3967c478bd9Sstevel@tonic-gate 		ef = *ef ? safeexpand(ef) : Getf("MBOX");
3977c478bd9Sstevel@tonic-gate 		nstrcpy(origname, PATHSIZE, ef);
3987c478bd9Sstevel@tonic-gate 		if (ef[0] != '/') {
3997c478bd9Sstevel@tonic-gate 			if (cwd == NOSTR)
4007c478bd9Sstevel@tonic-gate 				cwd = getcwd(NOSTR, PATHSIZE);
4017c478bd9Sstevel@tonic-gate 			nstrcat(cwd, PATHSIZE, "/");
4027c478bd9Sstevel@tonic-gate 			nstrcat(cwd, PATHSIZE, ef);
4037c478bd9Sstevel@tonic-gate 			ef = cwd;
4047c478bd9Sstevel@tonic-gate 		}
4057c478bd9Sstevel@tonic-gate 		editfile = ef;
4067c478bd9Sstevel@tonic-gate 		edit++;
4077c478bd9Sstevel@tonic-gate 	}
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate 	if (setfile(editfile, edit) < 0)
4107c478bd9Sstevel@tonic-gate 		exit(1);
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate 	if (!loaded)
4137c478bd9Sstevel@tonic-gate 		load(Getf("MAILRC"));
4147c478bd9Sstevel@tonic-gate 	if (msgCount > 0 && !noheader && value("header") != NOSTR) {
4157c478bd9Sstevel@tonic-gate 		if (setjmp(hdrjmp) == 0) {
4167c478bd9Sstevel@tonic-gate 			if ((prevint = sigset(SIGINT, SIG_IGN)) != SIG_IGN)
4177c478bd9Sstevel@tonic-gate 				sigset(SIGINT, hdrstop);
4187c478bd9Sstevel@tonic-gate 			announce();
4197c478bd9Sstevel@tonic-gate 			fflush(stdout);
4207c478bd9Sstevel@tonic-gate 			sigset(SIGINT, prevint);
4217c478bd9Sstevel@tonic-gate 		}
4227c478bd9Sstevel@tonic-gate 	}
4237c478bd9Sstevel@tonic-gate 	if (Hflag || (!edit && msgCount == 0)) {
4247c478bd9Sstevel@tonic-gate 		if (!Hflag) {
4257c478bd9Sstevel@tonic-gate 			fprintf(stderr, gettext("No mail for %s\n"), myname);
4267c478bd9Sstevel@tonic-gate 			Verhogen();
4277c478bd9Sstevel@tonic-gate 		}
4287c478bd9Sstevel@tonic-gate 		fflush(stdout);
4297c478bd9Sstevel@tonic-gate 		exit(rpterr);
4307c478bd9Sstevel@tonic-gate 	}
4317c478bd9Sstevel@tonic-gate 	commands();
4327c478bd9Sstevel@tonic-gate 	sigset(SIGHUP, SIG_IGN);
4337c478bd9Sstevel@tonic-gate 	sigset(SIGINT, SIG_IGN);
4347c478bd9Sstevel@tonic-gate 	sigset(SIGQUIT, SIG_IGN);
4357c478bd9Sstevel@tonic-gate 	if (!outtty)
4367c478bd9Sstevel@tonic-gate 		sigset(SIGPIPE, SIG_IGN);
4377c478bd9Sstevel@tonic-gate 	if (edit)
4387c478bd9Sstevel@tonic-gate 		edstop(0);
4397c478bd9Sstevel@tonic-gate 	else {
4407c478bd9Sstevel@tonic-gate 		quit(0);
4417c478bd9Sstevel@tonic-gate 		Verhogen();
4427c478bd9Sstevel@tonic-gate 	}
443*6c83d09fSrobbin 	return (rpterr);
4447c478bd9Sstevel@tonic-gate }
4457c478bd9Sstevel@tonic-gate 
4467c478bd9Sstevel@tonic-gate /*
4477c478bd9Sstevel@tonic-gate  * Interrupt printing of the headers.
4487c478bd9Sstevel@tonic-gate  */
4497c478bd9Sstevel@tonic-gate static void
4507c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4517c478bd9Sstevel@tonic-gate hdrstop(int)
4527c478bd9Sstevel@tonic-gate #else
4537c478bd9Sstevel@tonic-gate /* ARGSUSED */
4547c478bd9Sstevel@tonic-gate hdrstop(int s)
4557c478bd9Sstevel@tonic-gate #endif
4567c478bd9Sstevel@tonic-gate {
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 	fflush(stdout);
4597c478bd9Sstevel@tonic-gate 	fprintf(stderr, gettext("\nInterrupt\n"));
4607c478bd9Sstevel@tonic-gate # ifdef OLD_BSD_SIGS
4617c478bd9Sstevel@tonic-gate 	sigrelse(SIGINT);
4627c478bd9Sstevel@tonic-gate # endif
4637c478bd9Sstevel@tonic-gate 	longjmp(hdrjmp, 1);
4647c478bd9Sstevel@tonic-gate }
465