4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
46 * mailx -- a modified version of a University of California at Berkeley
49 * Startup -- interface with user.
52 static void hdrstop(int);
54 static jmp_buf hdrjmp
;
56 const char *const version
= "mailx version 5.0";
59 * Find out who the user is, copy his mail file (if exists) into
60 * /tmp/Rxxxxx and set up the message pointers. Then, print out the
61 * message headers and read user commands.
63 * Command line syntax:
64 * mailx [ -i ] [ -r address ] [ -h number ] [ -f [ name ] ]
66 * mailx [ -i ] [ -r address ] [ -h number ] people ...
68 * and a bunch of other options.
72 main(int argc
, char **argv
)
76 int mustsend
, f
, goerr
= 0;
85 * Set up a reasonable environment.
86 * Figure out whether we are being run interactively, set up
87 * all the temporary files, buffer standard output, and so forth.
91 (void)setlocale(LC_ALL
, "");
93 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
94 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
96 (void) textdomain(TEXT_DOMAIN
);
99 sigset(SIGCONT
, SIG_DFL
);
101 rpterr
= 0; /* initialize; set when we output to stderr */
103 if (progname
[strlen(progname
) - 1] != 'x') {
104 assign("bsdcompat", "");
115 if (ioctl(1, TCGETS
, &tbufs
) < 0) {
116 if (ioctl(1, TCGETA
, &tbuf
)==0) {
118 baud
= tbuf
.c_cflag
& CBAUD
;
123 baud
= cfgetospeed(&tbufs
);
128 * Now, determine how we are being used.
129 * We successively pick off instances of -r, -h, -f, and -i.
130 * If called as "rmail" we note this fact for letter sending.
131 * If there is anything left, it is the base of the list
132 * of users to mail to. Argp will be set to point to the
133 * first of these users.
139 if (argc
> 0 && **argv
== 'r')
141 while ((c
= getopt(argc
, argv
, "b:Bc:defFh:HiInNr:s:u:UtT:vV~")) != EOF
)
152 * Next argument is address to be sent along
161 * Next argument is temp file to write which
162 * articles have been read/deleted for netnews.
165 if ((f
= creat(Tflag
, TEMPPERM
)) < 0) {
170 /* fall through for -I too */
175 * print newsgroup in header summary
182 * Next argument is person's mailbox to use.
183 * Treated the same as "-f /var/mail/user".
186 static char u
[PATHSIZE
];
187 snprintf(u
, sizeof (u
), "%s%s", maildir
, optarg
);
194 * User wants to ignore interrupts.
195 * Set the variable "ignore"
197 assign("ignore", "");
210 * Specified sequence number for network.
211 * This is the number of "hops" made so
212 * far (count of times message has been
213 * forwarded) to help avoid infinite mail loops.
216 hflag
= atoi(optarg
);
219 gettext("-h needs non-zero number\n"));
226 * Give a subject field for sending from
233 case 'c': /* Cc: from command line */
238 case 'b': /* Bcc: from command line */
245 * User is specifying file to "edit" with mailx,
246 * as opposed to reading system mailbox.
247 * If no argument is given after -f, we read his/her
248 * $MBOX file or mbox in his/her home directory.
250 ef
= (argc
== optind
|| *argv
[optind
] == '-')
251 ? "" : argv
[optind
++];
252 if (*ef
&& *ef
!= '/' && *ef
!= '+')
253 cwd
= getcwd(NOSTR
, PATHSIZE
);
263 * User doesn't want to source
271 * Avoid initial header printing.
278 * Print headers and exit
289 * Permit tildas no matter where
290 * the input is coming from.
292 assign("escapeok", "");
297 * Send mailer verbose flag
299 assign("verbose", "");
304 * Don't buffer output
305 * (Line buffered is good enough)
307 setvbuf(stdout
, NULL
, _IOLBF
, BUFSIZ
);
308 setvbuf(stderr
, NULL
, _IOLBF
, BUFSIZ
);
313 * Like sendmail -t, read headers from text
329 * Check for inconsistent arguments.
332 if (newsflg
&& ef
==NOSTR
) {
333 fprintf(stderr
, gettext("Need -f with -I flag\n"));
336 if (ef
!= NOSTR
&& argp
!= -1) {
338 gettext("Cannot give -f and people to send to.\n"));
341 if (exitflg
&& (mustsend
|| argp
!= -1))
342 exit(1); /* nonsense flags involving -e simply exit */
343 if (tflag
&& argp
!= -1) {
345 gettext("Ignoring recipients on command line with -t\n"));
347 } else if (!tflag
&& mustsend
&& argp
== -1) {
349 gettext("The flags you gave are used only when sending mail.\n"));
354 gettext("Usage: %s -eiIUdFntBNHvV~ -T FILE -u USER -h hops -r address\n"),
357 gettext("\t\t-s SUBJECT -f FILE users\n"));
362 rcvmode
= !tflag
&& argp
== -1;
367 load(Getf("MAILRC"));
372 exit(senderr
? senderr
: rpterr
);
376 * Ok, we are reading mail.
377 * Decide whether we are editing a mailbox or reading
378 * the system mailbox, and open up the right stuff.
380 * Do this before sourcing the MAILRC, because there might be
381 * a 'chdir' there that breaks the -f option. But if the
382 * file specified with -f is a folder name, go ahead and
383 * source the MAILRC anyway so that "folder" will be defined.
386 nstrcpy(origname
, PATHSIZE
, mailname
);
390 if (ef
== NOSTR
|| *ef
== '\0' || *ef
== '+') {
391 load(Getf("MAILRC"));
394 ef
= *ef
? safeexpand(ef
) : Getf("MBOX");
395 nstrcpy(origname
, PATHSIZE
, ef
);
398 cwd
= getcwd(NOSTR
, PATHSIZE
);
399 nstrcat(cwd
, PATHSIZE
, "/");
400 nstrcat(cwd
, PATHSIZE
, ef
);
407 if (setfile(editfile
, edit
) < 0)
411 load(Getf("MAILRC"));
412 if (msgCount
> 0 && !noheader
&& value("header") != NOSTR
) {
413 if (setjmp(hdrjmp
) == 0) {
414 if ((prevint
= sigset(SIGINT
, SIG_IGN
)) != SIG_IGN
)
415 sigset(SIGINT
, hdrstop
);
418 sigset(SIGINT
, prevint
);
421 if (Hflag
|| (!edit
&& msgCount
== 0)) {
423 fprintf(stderr
, gettext("No mail for %s\n"), myname
);
430 sigset(SIGHUP
, SIG_IGN
);
431 sigset(SIGINT
, SIG_IGN
);
432 sigset(SIGQUIT
, SIG_IGN
);
434 sigset(SIGPIPE
, SIG_IGN
);
445 * Interrupt printing of the headers.
457 fprintf(stderr
, gettext("\nInterrupt\n"));