* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted provided
* that: (1) source distributions retain this entire copyright notice and
* comment, and (2) distributions including binaries display the following
* acknowledgement: ``This product includes software developed by the
* University of California, Berkeley and its contributors'' in the
* documentation or other materials provided with the distribution and in
* all advertising materials mentioning features or use of this software.
* Neither the name of the University nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
static char sccsid
[] = "@(#)main.c 5.27 (Berkeley) 6/25/90";
* Startup -- interface with user.
struct name
*to
, *cc
, *bcc
, *smopts
;
extern int getopt(), optind
, opterr
;
* Set up a reasonable environment.
* Figure out whether we are being run interactively,
* start the SIGCHLD catcher, and so forth.
(void) signal(SIGCHLD
, sigchild
);
assign("interactive", "");
* Now, determine how we are being used.
* We successively pick off - flags.
* 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
while ((i
= getopt(argc
, argv
, "INT:b:c:dfins:u:v")) != EOF
) {
* Next argument is temp file to write which
* articles have been read/deleted for netnews.
if ((i
= creat(Tflag
, 0600)) < 0) {
* Next argument is person to pretend to be.
* User wants to ignore interrupts.
* Set the variable "ignore"
* Give a subject field for sending from
* User is specifying file to "edit" with Mail,
* as opposed to reading system mailbox.
* If no argument is given after -f, we read his
* getopt() can't handle optional arguments, so here
* is an ugly hack to get around it.
if ((argv
[optind
]) && (argv
[optind
][0] != '-'))
* User doesn't want to source /usr/lib/Mail.rc
* Avoid initial header printing.
* Send mailer verbose flag
assign("interactive", "");
* Get Carbon Copy Recipient list
cc
= cat(cc
, nalloc(optarg
, GCC
));
* Get Blind Carbon Copy Recipient list
bcc
= cat(bcc
, nalloc(optarg
, GBCC
));
Usage: mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...\n\
[- sendmail-options ...]\n\
mail [-iInNv] -f [name]\n\
mail [-iInNv] [-u user]\n",
for (i
= optind
; (argv
[i
]) && (*argv
[i
] != '-'); i
++)
to
= cat(to
, nalloc(argv
[i
], GTO
));
smopts
= cat(smopts
, nalloc(argv
[i
], 0));
* Check for inconsistent arguments.
if (to
== NIL
&& (subject
!= NOSTR
|| cc
!= NIL
|| bcc
!= NIL
)) {
fputs("You must specify direct recipients with -s, -c, or -b.\n", stderr
);
if (ef
!= NOSTR
&& to
!= NIL
) {
fprintf(stderr
, "Cannot give -f and people to send to.\n");
* Expand returns a savestr, but load only uses the file name
* for fopen, so it's safe to do this.
load(expand("~/.mailrc"));
mail(to
, cc
, bcc
, smopts
, subject
);
* Ok, we are reading mail.
* Decide whether we are editing a mailbox or reading
* the system mailbox, and open up the right stuff.
exit(1); /* error already reported */
if (setjmp(hdrjmp
) == 0) {
if ((prevint
= signal(SIGINT
, SIG_IGN
)) != SIG_IGN
)
if (value("quiet") == NOSTR
)
printf("Mail version %s. Type ? for help.\n",
signal(SIGQUIT
, SIG_IGN
);
* Interrupt printing of the headers.
fprintf(stderr
, "\nInterrupt\n");
* Compute what the screen size for printing headers should be.
* We use the following algorithm for the height:
* If baud rate < 1200, use 9
* If baud rate = 1200, use 14
* If baud rate > 1200, use 24 or ws_row
* Width is either 80 or ws_col;
if (ioctl(1, TIOCGWINSZ
, (char *) &ws
) < 0)
ws
.ws_col
= ws
.ws_row
= 0;
if (ioctl(1, TIOCGETP
, &tbuf
) < 0)
if (tbuf
.sg_ospeed
< B1200
)
else if (tbuf
.sg_ospeed
== B1200
)
screenheight
= ws
.ws_row
;
if ((realscreenheight
= ws
.ws_row
) == 0)
if ((screenwidth
= ws
.ws_col
) == 0)