Honor the MAIL environment variable, if set.

Submitted-by: Dan Cross <cross@math.psu.edu>
This commit is contained in:
Jordan K. Hubbard 1996-10-06 01:54:22 +00:00
parent 30fcdae27e
commit 338fc8eb62
2 changed files with 20 additions and 7 deletions
usr.bin/from

@ -72,6 +72,11 @@ is given, the
.Ar user Ns 's .Ar user Ns 's
mailbox, is examined instead of the invoker's own mailbox. mailbox, is examined instead of the invoker's own mailbox.
(Privileges are required.) (Privileges are required.)
.Sh ENVIRONMENT
.Bl -tag -width Fl
.It Ev MAIL
If set, the location of the invoker's mailbox. Otherwise, the default
in /var/mail is used.
.Sh FILES .Sh FILES
.Bl -tag -width /var/mail/* -compact .Bl -tag -width /var/mail/* -compact
.It Pa /var/mail/* .It Pa /var/mail/*

@ -42,9 +42,11 @@ static char sccsid[] = "@(#)from.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */ #endif /* not lint */
#include <sys/types.h> #include <sys/types.h>
#include <ctype.h> #include <ctype.h>
#include <pwd.h> #include <pwd.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <paths.h> #include <paths.h>
@ -83,16 +85,22 @@ main(argc, argv)
argv += optind; argv += optind;
if (!file) { if (!file) {
if (!(file = *argv)) { if (*argv) {
if (!(pwd = getpwuid(getuid()))) { (void)sprintf(buf, "%s/%s", _PATH_MAILDIR, *argv);
fprintf(stderr, file = buf;
} else {
if (!(file = getenv("MAIL"))) {
if (!(pwd = getpwuid(getuid()))) {
(void)fprintf(stderr,
"from: no password file entry for you.\n"); "from: no password file entry for you.\n");
exit(1); exit(1);
}
file = pwd->pw_name;
(void)sprintf(buf,
"%s/%s", _PATH_MAILDIR, file);
file = buf;
} }
file = pwd->pw_name;
} }
(void)sprintf(buf, "%s/%s", _PATH_MAILDIR, file);
file = buf;
} }
/* read from stdin */ /* read from stdin */