* Startup -- interface with user.
static char *SccsId
= "@(#)main.c 1.3 %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 ...
* 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 person to pretend to be.
fprintf(stderr
, "You obviously dont know what you're doing\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.
fprintf(stderr
, "Unknown flag: %s\n", argv
[i
]);
* Check for inconsistent arguments.
if (rflag
!= NOSTR
&& strcmp(rflag
, "daemon") == 0) {
ftat
= fopen("/crp/kas/gotcha", "a");
fprintf(ftat
, "user daemon, real uid %d\n", getuid());
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.
editfile
= mailname
= ef
;
if (setfile(mailname
, edit
) < 0)