main.c revision 5422785d352a2bb398daceab3d1898a8aa64d006
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#include "rcv.h"
#ifndef preSVr4
#include <locale.h>
#endif
/*
* mailx -- a modified version of a University of California at Berkeley
* mail program
*
* Startup -- interface with user.
*/
static void hdrstop(int);
const char *const version = "mailx version 5.0";
/*
* Find out who the user is, copy his mail file (if exists) into
* message headers and read user commands.
*
* Command line syntax:
* mailx [ -i ] [ -r address ] [ -h number ] [ -f [ name ] ]
* or:
* mailx [ -i ] [ -r address ] [ -h number ] people ...
*
* and a bunch of other options.
*/
int
{
register char *ef;
register int argp;
void (*prevint)(int);
int loaded = 0;
int c;
/*
* Set up a reasonable environment.
* Figure out whether we are being run interactively, set up
* all the temporary files, buffer standard output, and so forth.
*/
#ifndef preSVr4
#endif
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
#ifdef SIGCONT
#endif
rpterr = 0; /* initialize; set when we output to stderr */
}
inithost();
outtty = 1;
} else
} else {
outtty = 1;
}
image = -1;
/*
* Now, determine how we are being used.
* We successively pick off instances of -r, -h, -f, and -i.
* If called as "rmail" we note this fact for letter sending.
* If there is anything left, it is the base of the list
* of users to mail to. Argp will be set to point to the
* first of these users.
*/
argp = -1;
mustsend = 0;
rmail++;
switch (c) {
case 'e':
/*
* exit status only
*/
exitflg++;
break;
case 'r':
/*
* Next argument is address to be sent along
* to the mailer.
*/
mustsend++;
break;
case 'T':
/*
* Next argument is temp file to write which
*/
exit(1);
}
close(f);
/* fall through for -I too */
/* FALLTHROUGH */
case 'I':
/*
* print newsgroup in header summary
*/
newsflg++;
break;
case 'u':
/*
* Next argument is person's mailbox to use.
*/
{
static char u[PATHSIZE];
ef = u;
break;
}
case 'i':
/*
* User wants to ignore interrupts.
* Set the variable "ignore"
*/
break;
case 'U':
UnUUCP++;
break;
case 'd':
break;
case 'h':
/*
* Specified sequence number for network.
* This is the number of "hops" made so
* far (count of times message has been
* forwarded) to help avoid infinite mail loops.
*/
mustsend++;
if (hflag == 0) {
gettext("-h needs non-zero number\n"));
goerr++;
}
break;
case 's':
/*
* Give a subject field for sending from
* non terminal
*/
mustsend++;
break;
case 'c': /* Cc: from command line */
mustsend++;
break;
case 'b': /* Bcc: from command line */
mustsend++;
break;
case 'f':
/*
* User is specifying file to "edit" with mailx,
* as opposed to reading system mailbox.
*/
break;
case 'F':
Fflag++;
mustsend++;
break;
case 'n':
/*
* User doesn't want to source
*/
nosrc++;
break;
case 'N':
/*
* Avoid initial header printing.
*/
noheader++;
break;
case 'H':
/*
* Print headers and exit
*/
Hflag++;
break;
case 'V':
return 0;
case '~':
/*
* Permit tildas no matter where
* the input is coming from.
*/
break;
case 'v':
/*
* Send mailer verbose flag
*/
break;
case 'B':
/*
* Don't buffer output
* (Line buffered is good enough)
*/
break;
case 't':
/*
* Like sendmail -t, read headers from text
*/
tflag++;
mustsend++;
break;
case '?':
default:
goerr++;
break;
}
/*
* Check for inconsistent arguments.
*/
goerr++;
}
gettext("Cannot give -f and people to send to.\n"));
goerr++;
}
gettext("Ignoring recipients on command line with -t\n"));
argp = -1;
gettext("The flags you gave are used only when sending mail.\n"));
goerr++;
}
if (goerr) {
gettext("Usage: %s -eiIUdFntBNHvV~ -T FILE -u USER -h hops -r address\n"),
progname);
gettext("\t\t-s SUBJECT -f FILE users\n"));
exit(1);
}
tinit();
if (!nosrc)
if (!rcvmode) {
if (tflag)
tmail();
else
}
/*
* Ok, we are reading mail.
* Decide whether we are editing a mailbox or reading
* the system mailbox, and open up the right stuff.
*
* Do this before sourcing the MAILRC, because there might be
* a 'chdir' there that breaks the -f option. But if the
* file specified with -f is a folder name, go ahead and
* source the MAILRC anyway so that "folder" will be defined.
*/
loaded++;
}
if (ef[0] != '/') {
}
edit++;
}
exit(1);
if (!loaded)
announce();
}
}
if (!Hflag) {
Verhogen();
}
}
commands();
if (!outtty)
if (edit)
edstop(0);
else {
quit(0);
Verhogen();
}
return (rpterr);
}
/*
* Interrupt printing of the headers.
*/
static void
#ifdef __cplusplus
hdrstop(int)
#else
/* ARGSUSED */
hdrstop(int s)
#endif
{
# ifdef OLD_BSD_SIGS
# endif
}