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