Subject: from and Mail fixes to understand $MAIL
To: None <current-users@sun-lamp.cs.berkeley.edu>
From: Christos Zoulas <christos@deshaw.com>
List: current-users
Date: 01/03/1994 10:10:12
Here are fixes to from and mail to use the value of $MAIL (if set)
as the default mailbox like SunOS does...
christos
*** usr.bin/mail/v7.local.c.dist Sun Nov 7 05:05:57 1993
--- usr.bin/mail/v7.local.c Mon Jan 3 09:56:56 1994
***************
*** 45,50 ****
--- 45,51 ----
*/
#include "rcv.h"
+ #include <stdlib.h>
/*
* Locate the user's mailbox file (ie, the place where new, unread
***************
*** 53,59 ****
findmail(user, buf)
char *user, *buf;
{
! (void)sprintf(buf, "%s/%s", _PATH_MAILDIR, user);
}
/*
--- 54,64 ----
findmail(user, buf)
char *user, *buf;
{
! char *mbox;
! if (!(mbox = getenv("MAIL")))
! (void)sprintf(buf, "%s/%s", _PATH_MAILDIR, user);
! else
! (void)strcpy(buf, mbox);
}
/*
*** usr.bin/from/from.c.dist Sun Nov 7 05:03:27 1993
--- usr.bin/from/from.c Mon Jan 3 09:51:22 1994
***************
*** 46,51 ****
--- 46,53 ----
#include <ctype.h>
#include <pwd.h>
#include <stdio.h>
+ #include <stdlib.h>
+ #include <unistd.h>
#include <paths.h>
main(argc, argv)
***************
*** 82,101 ****
}
argv += optind;
if (!file) {
if (!(file = *argv)) {
! if (!(pwd = getpwuid(getuid()))) {
! fprintf(stderr,
! "from: no password file entry for you.\n");
! exit(1);
}
- file = pwd->pw_name;
}
! (void)sprintf(buf, "%s/%s", _PATH_MAILDIR, file);
! file = buf;
}
if (!freopen(file, "r", stdin)) {
! fprintf(stderr, "from: can't read %s.\n", file);
exit(1);
}
for (newline = 1; fgets(buf, sizeof(buf), stdin);) {
--- 84,113 ----
}
argv += optind;
+ /*
+ * We find the mailbox by:
+ * 1 -f flag
+ * 2 user
+ * 2 MAIL environment variable
+ * 3 _PATH_MAILDIR/file
+ */
if (!file) {
if (!(file = *argv)) {
! if (!(file = getenv("MAIL"))) {
! if (!(pwd = getpwuid(getuid()))) {
! (void)fprintf(stderr,
! "from: no password file entry for you.\n");
! exit(1);
! }
! (void)sprintf(file = buf, "%s/%s",
! _PATH_MAILDIR, pwd->pw_name);
}
}
! else
! (void)sprintf(file = buf, "%s/%s", _PATH_MAILDIR, file);
}
if (!freopen(file, "r", stdin)) {
! (void)fprintf(stderr, "from: can't read %s.\n", file);
exit(1);
}
for (newline = 1; fgets(buf, sizeof(buf), stdin);) {
------------------------------------------------------------------------------