* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that this notice is preserved and that due credit is given
* to the University of California at 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'' without express or implied warranty.
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
static char sccsid
[] = "@(#)main.c 5.12 (Berkeley) %G%";
* Startup -- interface with user.
* Find out who the user is, copy his mail file (if exists) into
* /tmp/Rxxxxx and set up the message pointers. Then, print out the
* message headers and read user commands.
* Mail [ -i ] [ -r address ] [ -h number ] [ -f [ name ] ]
* Mail [ -i ] [ -r address ] [ -h number ] people ...
struct name
*to
, *cc
, *bcc
, *smopts
;
int mustsend
, hdrstop(), (*prevint
)(), f
;
extern int getopt(), optind
, opterr
;
* 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.
assign("interactive", "");
* 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
if (argc
> 0 && **argv
== 'r')
while ((opt
= getopt(argc
, argv
, "INT:b:c:dfh:inr:s:u:v")) != EOF
) {
* Next argument is address to be sent along
* Next argument is temp file to write which
* articles have been read/deleted for netnews.
if ((f
= creat(Tflag
, 0600)) < 0) {
* Next argument is person to pretend to be.
* User wants to ignore interrupts.
* Set the variable "ignore"
* 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.
fprintf(stderr
, "-h needs non-zero number\n");
* 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
));
* Get Blind Carbon Copy Recipient list
bcc
= cat(bcc
, nalloc(optarg
));
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
]));
smopts
= cat(smopts
, nalloc(argv
[i
]));
* Check for inconsistent arguments.
if (!to
&& (cc
|| bcc
)) {
fputs("You must also specify direct recipients of mail.\n", stderr
);
if ((ef
!= NOSTR
) && to
) {
fprintf(stderr
, "Cannot give -f and people to send to.\n");
fprintf(stderr
, "The flags you gave make no sense since you're not sending mail.\n");
mail(to
, cc
, bcc
, smopts
);
* 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 (!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)