* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not 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 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
static char sccsid
[] = "@(#)main.c 5.19 (Berkeley) %G%";
* Startup -- interface with user.
struct name
*to
, *cc
, *bcc
, *smopts
;
int hdrstop(), (*prevint
)();
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 save 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.
if ((ef
= expand(ef
)) == NOSTR
)
exit(1); /* error already reported */
if (setfile(ef
, edit
) < 0) {
fprintf(stderr
, "No mail for %s\n", myname
);
if (setjmp(hdrjmp
) == 0) {
if ((prevint
= signal(SIGINT
, SIG_IGN
)) != SIG_IGN
)
if (value("quiet") == NOSTR
)
printf("Mail version %s. Type ? for help.\n",
if (!edit
&& msgCount
== 0) {
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 (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)