* Startup -- interface with user.
static char *SccsId
= "@(#)main.c 2.11 %G%";
* 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 ...
int mustsend
, uflag
, hdrstop(), (*prevint
)(), f
;
* Set up a reasonable environment. We clobber the last
* element of argument list for compatibility with version 6,
* figure out whether we are being run interactively, set up
* all the temporary files, buffer standard output, and so forth.
argv
[argc
] = (char *) -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
if (argc
> 0 && **argv
== 'r')
for (i
= 1; i
< argc
; i
++) {
* If current argument is not a flag, then the
* rest of the arguments must be recipients.
* Next argument is address to be sent along
fprintf(stderr
, "Address required after -r\n");
* Next argument is temp file to write which
* articles have been read/deleted for netnews.
fprintf(stderr
, "Name required after -T\n");
if ((f
= creat(Tflag
, 0600)) < 0) {
* Next argument is person to pretend to be.
fprintf(stderr
, "Missing user name for -u\n");
strcpy(myname
, argv
[i
+1]);
* 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
, "Number required for -h\n");
fprintf(stderr
, "-h needs non-zero number\n");
* Give a subject field for sending from
fprintf(stderr
, "Subject req'd for -s\n");
* User is specifying file to "edit" with Mail,
* as opposed to reading system mailbox.
* If no argument is given after -f, we read his
* mbox file in his home directory.
* User doesn't want to source /usr/lib/Mail.rc
* Avoid initial header printing.
* Send mailer verbose flag
fprintf(stderr
, "Unknown flag: %s\n", argv
[i
]);
* Check for inconsistent arguments.
if (ef
!= NOSTR
&& argp
!= -1) {
fprintf(stderr
, "Cannot give -f and people to send to.\n");
if (mustsend
&& argp
== -1) {
fprintf(stderr
, "The flags you gave make no sense since you're not sending mail.\n");
* Ok, we are reading mail.
* Decide whether we are editing a mailbox or reading
* the system mailbox, and open up the right stuff.
ef
= (char *) calloc(1, strlen(ename
) + 1);
if (setfile(mailname
, edit
) < 0) {
fprintf(stderr
, "No mail for %s\n", myname
);
if (!edit
&& !noheader
&& value("noheader") == NOSTR
) {
if (setjmp(hdrjmp
) == 0) {
if ((prevint
= sigset(SIGINT
, SIG_IGN
)) != SIG_IGN
)
if (!edit
&& msgCount
== 0) {
sigset(SIGQUIT
, SIG_IGN
);
* Interrupt printing of the headers.