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
596ccc8cbSesaxe * Common Development and Distribution License (the "License").
696ccc8cbSesaxe * 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 /*
2396ccc8cbSesaxe * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
246c83d09fSrobbin * Use is subject to license terms.
25*48bbca81SDaniel Hoffman * Copyright (c) 2016 by Delphix. All rights reserved.
267c478bd9Sstevel@tonic-gate */
277c478bd9Sstevel@tonic-gate
286c83d09fSrobbin /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
296c83d09fSrobbin /* All Rights Reserved */
306c83d09fSrobbin
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 #include "rcv.h"
427c478bd9Sstevel@tonic-gate #ifndef preSVr4
437c478bd9Sstevel@tonic-gate #include <locale.h>
447c478bd9Sstevel@tonic-gate #endif
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate /*
477c478bd9Sstevel@tonic-gate * mailx -- a modified version of a University of California at Berkeley
487c478bd9Sstevel@tonic-gate * mail program
497c478bd9Sstevel@tonic-gate *
507c478bd9Sstevel@tonic-gate * Startup -- interface with user.
517c478bd9Sstevel@tonic-gate */
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate static void hdrstop(int);
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate static jmp_buf hdrjmp;
567c478bd9Sstevel@tonic-gate
5796ccc8cbSesaxe const char *const version = "mailx version 5.0";
5896ccc8cbSesaxe
597c478bd9Sstevel@tonic-gate /*
60*48bbca81SDaniel Hoffman * Find out who the user is, copy their 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
72*48bbca81SDaniel Hoffman int
main(int argc,char ** argv)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 }
1077c478bd9Sstevel@tonic-gate myegid = getegid();
1087c478bd9Sstevel@tonic-gate myrgid = getgid();
1097c478bd9Sstevel@tonic-gate myeuid = geteuid();
1107c478bd9Sstevel@tonic-gate myruid = getuid();
1117c478bd9Sstevel@tonic-gate mypid = getpid();
1127c478bd9Sstevel@tonic-gate setgid(myrgid);
1137c478bd9Sstevel@tonic-gate setuid(myruid);
1147c478bd9Sstevel@tonic-gate inithost();
1157c478bd9Sstevel@tonic-gate intty = isatty(0);
1167c478bd9Sstevel@tonic-gate if (ioctl(1, TCGETS, &tbufs) < 0) {
1177c478bd9Sstevel@tonic-gate if (ioctl(1, TCGETA, &tbuf)==0) {
1187c478bd9Sstevel@tonic-gate outtty = 1;
1197c478bd9Sstevel@tonic-gate baud = tbuf.c_cflag & CBAUD;
1207c478bd9Sstevel@tonic-gate } else
1217c478bd9Sstevel@tonic-gate baud = B9600;
1227c478bd9Sstevel@tonic-gate } else {
1237c478bd9Sstevel@tonic-gate outtty = 1;
1247c478bd9Sstevel@tonic-gate baud = cfgetospeed(&tbufs);
1257c478bd9Sstevel@tonic-gate }
1267c478bd9Sstevel@tonic-gate image = -1;
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate * Now, determine how we are being used.
1307c478bd9Sstevel@tonic-gate * We successively pick off instances of -r, -h, -f, and -i.
1317c478bd9Sstevel@tonic-gate * If called as "rmail" we note this fact for letter sending.
1327c478bd9Sstevel@tonic-gate * If there is anything left, it is the base of the list
1337c478bd9Sstevel@tonic-gate * of users to mail to. Argp will be set to point to the
1347c478bd9Sstevel@tonic-gate * first of these users.
1357c478bd9Sstevel@tonic-gate */
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate ef = NOSTR;
1387c478bd9Sstevel@tonic-gate argp = -1;
1397c478bd9Sstevel@tonic-gate mustsend = 0;
1407c478bd9Sstevel@tonic-gate if (argc > 0 && **argv == 'r')
1417c478bd9Sstevel@tonic-gate rmail++;
1427c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "b:Bc:defFh:HiInNr:s:u:UtT:vV~")) != EOF)
1437c478bd9Sstevel@tonic-gate switch (c) {
1447c478bd9Sstevel@tonic-gate case 'e':
1457c478bd9Sstevel@tonic-gate /*
1467c478bd9Sstevel@tonic-gate * exit status only
1477c478bd9Sstevel@tonic-gate */
1487c478bd9Sstevel@tonic-gate exitflg++;
1497c478bd9Sstevel@tonic-gate break;
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate case 'r':
1527c478bd9Sstevel@tonic-gate /*
1537c478bd9Sstevel@tonic-gate * Next argument is address to be sent along
1547c478bd9Sstevel@tonic-gate * to the mailer.
1557c478bd9Sstevel@tonic-gate */
1567c478bd9Sstevel@tonic-gate mustsend++;
1577c478bd9Sstevel@tonic-gate rflag = optarg;
1587c478bd9Sstevel@tonic-gate break;
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate case 'T':
1617c478bd9Sstevel@tonic-gate /*
1627c478bd9Sstevel@tonic-gate * Next argument is temp file to write which
1637c478bd9Sstevel@tonic-gate * articles have been read/deleted for netnews.
1647c478bd9Sstevel@tonic-gate */
1657c478bd9Sstevel@tonic-gate Tflag = optarg;
1667c478bd9Sstevel@tonic-gate if ((f = creat(Tflag, TEMPPERM)) < 0) {
1677c478bd9Sstevel@tonic-gate perror(Tflag);
1687c478bd9Sstevel@tonic-gate exit(1);
1697c478bd9Sstevel@tonic-gate }
1707c478bd9Sstevel@tonic-gate close(f);
1717c478bd9Sstevel@tonic-gate /* fall through for -I too */
1727c478bd9Sstevel@tonic-gate /* FALLTHROUGH */
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate case 'I':
1757c478bd9Sstevel@tonic-gate /*
1767c478bd9Sstevel@tonic-gate * print newsgroup in header summary
1777c478bd9Sstevel@tonic-gate */
1787c478bd9Sstevel@tonic-gate newsflg++;
1797c478bd9Sstevel@tonic-gate break;
1807c478bd9Sstevel@tonic-gate
1817c478bd9Sstevel@tonic-gate case 'u':
1827c478bd9Sstevel@tonic-gate /*
1837c478bd9Sstevel@tonic-gate * Next argument is person's mailbox to use.
1847c478bd9Sstevel@tonic-gate * Treated the same as "-f /var/mail/user".
1857c478bd9Sstevel@tonic-gate */
1867c478bd9Sstevel@tonic-gate {
1877c478bd9Sstevel@tonic-gate static char u[PATHSIZE];
1887c478bd9Sstevel@tonic-gate snprintf(u, sizeof (u), "%s%s", maildir, optarg);
1897c478bd9Sstevel@tonic-gate ef = u;
1907c478bd9Sstevel@tonic-gate break;
1917c478bd9Sstevel@tonic-gate }
1927c478bd9Sstevel@tonic-gate
1937c478bd9Sstevel@tonic-gate case 'i':
1947c478bd9Sstevel@tonic-gate /*
1957c478bd9Sstevel@tonic-gate * User wants to ignore interrupts.
1967c478bd9Sstevel@tonic-gate * Set the variable "ignore"
1977c478bd9Sstevel@tonic-gate */
1987c478bd9Sstevel@tonic-gate assign("ignore", "");
1997c478bd9Sstevel@tonic-gate break;
2007c478bd9Sstevel@tonic-gate
2017c478bd9Sstevel@tonic-gate case 'U':
2027c478bd9Sstevel@tonic-gate UnUUCP++;
2037c478bd9Sstevel@tonic-gate break;
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate case 'd':
2067c478bd9Sstevel@tonic-gate assign("debug", "");
2077c478bd9Sstevel@tonic-gate break;
2087c478bd9Sstevel@tonic-gate
2097c478bd9Sstevel@tonic-gate case 'h':
2107c478bd9Sstevel@tonic-gate /*
2117c478bd9Sstevel@tonic-gate * Specified sequence number for network.
2127c478bd9Sstevel@tonic-gate * This is the number of "hops" made so
2137c478bd9Sstevel@tonic-gate * far (count of times message has been
2147c478bd9Sstevel@tonic-gate * forwarded) to help avoid infinite mail loops.
2157c478bd9Sstevel@tonic-gate */
2167c478bd9Sstevel@tonic-gate mustsend++;
2177c478bd9Sstevel@tonic-gate hflag = atoi(optarg);
2187c478bd9Sstevel@tonic-gate if (hflag == 0) {
2197c478bd9Sstevel@tonic-gate fprintf(stderr,
2207c478bd9Sstevel@tonic-gate gettext("-h needs non-zero number\n"));
2217c478bd9Sstevel@tonic-gate goerr++;
2227c478bd9Sstevel@tonic-gate }
2237c478bd9Sstevel@tonic-gate break;
2247c478bd9Sstevel@tonic-gate
2257c478bd9Sstevel@tonic-gate case 's':
2267c478bd9Sstevel@tonic-gate /*
2277c478bd9Sstevel@tonic-gate * Give a subject field for sending from
2287c478bd9Sstevel@tonic-gate * non terminal
2297c478bd9Sstevel@tonic-gate */
2307c478bd9Sstevel@tonic-gate mustsend++;
2317c478bd9Sstevel@tonic-gate sflag = optarg;
2327c478bd9Sstevel@tonic-gate break;
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate case 'c': /* Cc: from command line */
2357c478bd9Sstevel@tonic-gate mustsend++;
2367c478bd9Sstevel@tonic-gate cflag = optarg;
2377c478bd9Sstevel@tonic-gate break;
2387c478bd9Sstevel@tonic-gate
2397c478bd9Sstevel@tonic-gate case 'b': /* Bcc: from command line */
2407c478bd9Sstevel@tonic-gate mustsend++;
2417c478bd9Sstevel@tonic-gate bflag = optarg;
2427c478bd9Sstevel@tonic-gate break;
2437c478bd9Sstevel@tonic-gate
2447c478bd9Sstevel@tonic-gate case 'f':
2457c478bd9Sstevel@tonic-gate /*
2467c478bd9Sstevel@tonic-gate * User is specifying file to "edit" with mailx,
2477c478bd9Sstevel@tonic-gate * as opposed to reading system mailbox.
248*48bbca81SDaniel Hoffman * If no argument is given after -f, we read their
249*48bbca81SDaniel Hoffman * $MBOX file or mbox in their home directory.
2507c478bd9Sstevel@tonic-gate */
2517c478bd9Sstevel@tonic-gate ef = (argc == optind || *argv[optind] == '-')
2527c478bd9Sstevel@tonic-gate ? "" : argv[optind++];
2537c478bd9Sstevel@tonic-gate if (*ef && *ef != '/' && *ef != '+')
2547c478bd9Sstevel@tonic-gate cwd = getcwd(NOSTR, PATHSIZE);
2557c478bd9Sstevel@tonic-gate break;
2567c478bd9Sstevel@tonic-gate
2577c478bd9Sstevel@tonic-gate case 'F':
2587c478bd9Sstevel@tonic-gate Fflag++;
2597c478bd9Sstevel@tonic-gate mustsend++;
2607c478bd9Sstevel@tonic-gate break;
2617c478bd9Sstevel@tonic-gate
2627c478bd9Sstevel@tonic-gate case 'n':
2637c478bd9Sstevel@tonic-gate /*
2647c478bd9Sstevel@tonic-gate * User doesn't want to source
2657c478bd9Sstevel@tonic-gate * /etc/mail/mailx.rc
2667c478bd9Sstevel@tonic-gate */
2677c478bd9Sstevel@tonic-gate nosrc++;
2687c478bd9Sstevel@tonic-gate break;
2697c478bd9Sstevel@tonic-gate
2707c478bd9Sstevel@tonic-gate case 'N':
2717c478bd9Sstevel@tonic-gate /*
2727c478bd9Sstevel@tonic-gate * Avoid initial header printing.
2737c478bd9Sstevel@tonic-gate */
2747c478bd9Sstevel@tonic-gate noheader++;
2757c478bd9Sstevel@tonic-gate break;
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate case 'H':
2787c478bd9Sstevel@tonic-gate /*
2797c478bd9Sstevel@tonic-gate * Print headers and exit
2807c478bd9Sstevel@tonic-gate */
2817c478bd9Sstevel@tonic-gate Hflag++;
2827c478bd9Sstevel@tonic-gate break;
2837c478bd9Sstevel@tonic-gate
2847c478bd9Sstevel@tonic-gate case 'V':
2857c478bd9Sstevel@tonic-gate puts(version);
2867c478bd9Sstevel@tonic-gate return 0;
2877c478bd9Sstevel@tonic-gate
2887c478bd9Sstevel@tonic-gate case '~':
2897c478bd9Sstevel@tonic-gate /*
2907c478bd9Sstevel@tonic-gate * Permit tildas no matter where
2917c478bd9Sstevel@tonic-gate * the input is coming from.
2927c478bd9Sstevel@tonic-gate */
2937c478bd9Sstevel@tonic-gate assign("escapeok", "");
2947c478bd9Sstevel@tonic-gate break;
2957c478bd9Sstevel@tonic-gate
2967c478bd9Sstevel@tonic-gate case 'v':
2977c478bd9Sstevel@tonic-gate /*
2987c478bd9Sstevel@tonic-gate * Send mailer verbose flag
2997c478bd9Sstevel@tonic-gate */
3007c478bd9Sstevel@tonic-gate assign("verbose", "");
3017c478bd9Sstevel@tonic-gate break;
3027c478bd9Sstevel@tonic-gate
3037c478bd9Sstevel@tonic-gate case 'B':
3047c478bd9Sstevel@tonic-gate /*
3057c478bd9Sstevel@tonic-gate * Don't buffer output
3067c478bd9Sstevel@tonic-gate * (Line buffered is good enough)
3077c478bd9Sstevel@tonic-gate */
3087c478bd9Sstevel@tonic-gate setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
3097c478bd9Sstevel@tonic-gate setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
3107c478bd9Sstevel@tonic-gate break;
3117c478bd9Sstevel@tonic-gate
3127c478bd9Sstevel@tonic-gate case 't':
3137c478bd9Sstevel@tonic-gate /*
3147c478bd9Sstevel@tonic-gate * Like sendmail -t, read headers from text
3157c478bd9Sstevel@tonic-gate */
3167c478bd9Sstevel@tonic-gate tflag++;
3177c478bd9Sstevel@tonic-gate mustsend++;
3187c478bd9Sstevel@tonic-gate break;
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate case '?':
3217c478bd9Sstevel@tonic-gate default:
3227c478bd9Sstevel@tonic-gate goerr++;
3237c478bd9Sstevel@tonic-gate break;
3247c478bd9Sstevel@tonic-gate }
3257c478bd9Sstevel@tonic-gate
3267c478bd9Sstevel@tonic-gate if (optind != argc)
3277c478bd9Sstevel@tonic-gate argp = optind;
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate /*
3307c478bd9Sstevel@tonic-gate * Check for inconsistent arguments.
3317c478bd9Sstevel@tonic-gate */
3327c478bd9Sstevel@tonic-gate
3337c478bd9Sstevel@tonic-gate if (newsflg && ef==NOSTR) {
3347c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("Need -f with -I flag\n"));
3357c478bd9Sstevel@tonic-gate goerr++;
3367c478bd9Sstevel@tonic-gate }
3377c478bd9Sstevel@tonic-gate if (ef != NOSTR && argp != -1) {
3387c478bd9Sstevel@tonic-gate fprintf(stderr,
3397c478bd9Sstevel@tonic-gate gettext("Cannot give -f and people to send to.\n"));
3407c478bd9Sstevel@tonic-gate goerr++;
3417c478bd9Sstevel@tonic-gate }
3427c478bd9Sstevel@tonic-gate if (exitflg && (mustsend || argp != -1))
3437c478bd9Sstevel@tonic-gate exit(1); /* nonsense flags involving -e simply exit */
3447c478bd9Sstevel@tonic-gate if (tflag && argp != -1) {
3457c478bd9Sstevel@tonic-gate fprintf(stderr,
3467c478bd9Sstevel@tonic-gate gettext("Ignoring recipients on command line with -t\n"));
3477c478bd9Sstevel@tonic-gate argp = -1;
3487c478bd9Sstevel@tonic-gate } else if (!tflag && mustsend && argp == -1) {
3497c478bd9Sstevel@tonic-gate fprintf(stderr,
3507c478bd9Sstevel@tonic-gate gettext("The flags you gave are used only when sending mail.\n"));
3517c478bd9Sstevel@tonic-gate goerr++;
3527c478bd9Sstevel@tonic-gate }
3537c478bd9Sstevel@tonic-gate if (goerr) {
3547c478bd9Sstevel@tonic-gate fprintf(stderr,
3557c478bd9Sstevel@tonic-gate gettext("Usage: %s -eiIUdFntBNHvV~ -T FILE -u USER -h hops -r address\n"),
3567c478bd9Sstevel@tonic-gate progname);
3577c478bd9Sstevel@tonic-gate fprintf(stderr,
3587c478bd9Sstevel@tonic-gate gettext("\t\t-s SUBJECT -f FILE users\n"));
3597c478bd9Sstevel@tonic-gate exit(1);
3607c478bd9Sstevel@tonic-gate }
3617c478bd9Sstevel@tonic-gate tinit();
3627c478bd9Sstevel@tonic-gate input = stdin;
3637c478bd9Sstevel@tonic-gate rcvmode = !tflag && argp == -1;
3647c478bd9Sstevel@tonic-gate if (!nosrc)
3657c478bd9Sstevel@tonic-gate load(MASTER);
3667c478bd9Sstevel@tonic-gate
3677c478bd9Sstevel@tonic-gate if (!rcvmode) {
3687c478bd9Sstevel@tonic-gate load(Getf("MAILRC"));
3697c478bd9Sstevel@tonic-gate if (tflag)
3707c478bd9Sstevel@tonic-gate tmail();
3717c478bd9Sstevel@tonic-gate else
3727c478bd9Sstevel@tonic-gate mail(&argv[argp]);
3737c478bd9Sstevel@tonic-gate exit(senderr ? senderr : rpterr);
3747c478bd9Sstevel@tonic-gate }
3757c478bd9Sstevel@tonic-gate
3767c478bd9Sstevel@tonic-gate /*
3777c478bd9Sstevel@tonic-gate * Ok, we are reading mail.
3787c478bd9Sstevel@tonic-gate * Decide whether we are editing a mailbox or reading
3797c478bd9Sstevel@tonic-gate * the system mailbox, and open up the right stuff.
3807c478bd9Sstevel@tonic-gate *
3817c478bd9Sstevel@tonic-gate * Do this before sourcing the MAILRC, because there might be
3827c478bd9Sstevel@tonic-gate * a 'chdir' there that breaks the -f option. But if the
3837c478bd9Sstevel@tonic-gate * file specified with -f is a folder name, go ahead and
3847c478bd9Sstevel@tonic-gate * source the MAILRC anyway so that "folder" will be defined.
3857c478bd9Sstevel@tonic-gate */
3867c478bd9Sstevel@tonic-gate
3877c478bd9Sstevel@tonic-gate nstrcpy(origname, PATHSIZE, mailname);
3887c478bd9Sstevel@tonic-gate editfile = mailname;
3897c478bd9Sstevel@tonic-gate
3907c478bd9Sstevel@tonic-gate if (ef != NOSTR) {
3917c478bd9Sstevel@tonic-gate if (ef == NOSTR || *ef == '\0' || *ef == '+') {
3927c478bd9Sstevel@tonic-gate load(Getf("MAILRC"));
3937c478bd9Sstevel@tonic-gate loaded++;
3947c478bd9Sstevel@tonic-gate }
3957c478bd9Sstevel@tonic-gate ef = *ef ? safeexpand(ef) : Getf("MBOX");
3967c478bd9Sstevel@tonic-gate nstrcpy(origname, PATHSIZE, ef);
3977c478bd9Sstevel@tonic-gate if (ef[0] != '/') {
3987c478bd9Sstevel@tonic-gate if (cwd == NOSTR)
3997c478bd9Sstevel@tonic-gate cwd = getcwd(NOSTR, PATHSIZE);
4007c478bd9Sstevel@tonic-gate nstrcat(cwd, PATHSIZE, "/");
4017c478bd9Sstevel@tonic-gate nstrcat(cwd, PATHSIZE, ef);
4027c478bd9Sstevel@tonic-gate ef = cwd;
4037c478bd9Sstevel@tonic-gate }
4047c478bd9Sstevel@tonic-gate editfile = ef;
4057c478bd9Sstevel@tonic-gate edit++;
4067c478bd9Sstevel@tonic-gate }
4077c478bd9Sstevel@tonic-gate
4087c478bd9Sstevel@tonic-gate if (setfile(editfile, edit) < 0)
4097c478bd9Sstevel@tonic-gate exit(1);
4107c478bd9Sstevel@tonic-gate
4117c478bd9Sstevel@tonic-gate if (!loaded)
4127c478bd9Sstevel@tonic-gate load(Getf("MAILRC"));
4137c478bd9Sstevel@tonic-gate if (msgCount > 0 && !noheader && value("header") != NOSTR) {
4147c478bd9Sstevel@tonic-gate if (setjmp(hdrjmp) == 0) {
4157c478bd9Sstevel@tonic-gate if ((prevint = sigset(SIGINT, SIG_IGN)) != SIG_IGN)
4167c478bd9Sstevel@tonic-gate sigset(SIGINT, hdrstop);
4177c478bd9Sstevel@tonic-gate announce();
4187c478bd9Sstevel@tonic-gate fflush(stdout);
4197c478bd9Sstevel@tonic-gate sigset(SIGINT, prevint);
4207c478bd9Sstevel@tonic-gate }
4217c478bd9Sstevel@tonic-gate }
4227c478bd9Sstevel@tonic-gate if (Hflag || (!edit && msgCount == 0)) {
4237c478bd9Sstevel@tonic-gate if (!Hflag) {
4247c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("No mail for %s\n"), myname);
4257c478bd9Sstevel@tonic-gate Verhogen();
4267c478bd9Sstevel@tonic-gate }
4277c478bd9Sstevel@tonic-gate fflush(stdout);
4287c478bd9Sstevel@tonic-gate exit(rpterr);
4297c478bd9Sstevel@tonic-gate }
4307c478bd9Sstevel@tonic-gate commands();
4317c478bd9Sstevel@tonic-gate sigset(SIGHUP, SIG_IGN);
4327c478bd9Sstevel@tonic-gate sigset(SIGINT, SIG_IGN);
4337c478bd9Sstevel@tonic-gate sigset(SIGQUIT, SIG_IGN);
4347c478bd9Sstevel@tonic-gate if (!outtty)
4357c478bd9Sstevel@tonic-gate sigset(SIGPIPE, SIG_IGN);
4367c478bd9Sstevel@tonic-gate if (edit)
4377c478bd9Sstevel@tonic-gate edstop(0);
4387c478bd9Sstevel@tonic-gate else {
4397c478bd9Sstevel@tonic-gate quit(0);
4407c478bd9Sstevel@tonic-gate Verhogen();
4417c478bd9Sstevel@tonic-gate }
4426c83d09fSrobbin return (rpterr);
4437c478bd9Sstevel@tonic-gate }
4447c478bd9Sstevel@tonic-gate
4457c478bd9Sstevel@tonic-gate /*
4467c478bd9Sstevel@tonic-gate * Interrupt printing of the headers.
4477c478bd9Sstevel@tonic-gate */
448*48bbca81SDaniel Hoffman static void
4497c478bd9Sstevel@tonic-gate #ifdef __cplusplus
hdrstop(int)4507c478bd9Sstevel@tonic-gate hdrstop(int)
4517c478bd9Sstevel@tonic-gate #else
4527c478bd9Sstevel@tonic-gate /* ARGSUSED */
4537c478bd9Sstevel@tonic-gate hdrstop(int s)
4547c478bd9Sstevel@tonic-gate #endif
4557c478bd9Sstevel@tonic-gate {
4567c478bd9Sstevel@tonic-gate
4577c478bd9Sstevel@tonic-gate fflush(stdout);
4587c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("\nInterrupt\n"));
4597c478bd9Sstevel@tonic-gate # ifdef OLD_BSD_SIGS
4607c478bd9Sstevel@tonic-gate sigrelse(SIGINT);
4617c478bd9Sstevel@tonic-gate # endif
4627c478bd9Sstevel@tonic-gate longjmp(hdrjmp, 1);
4637c478bd9Sstevel@tonic-gate }
464