environment variable isn't set.
The HOME environment variable defines in which directory the Maildir will
be found. If HOME is set to ``/home/charlie'', ``/home/charlie/Maildir''
will be where delivery is attempted to. If this variable is not set,
-delivery will fail.
+B<mdeliver> will fall back to using getpwuid(3).
=back
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
+#include <pwd.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
{
char *home;
char newfn[LEN_FILENAME];
+ struct passwd *pwd;
struct stat st;
if (argv[1] && argv[1][0] == '-' && argv[1][1] == 'v') {
}
if ((home = getenv("HOME")) == NULL) {
- errx("HOME is not set.");
+ if ((pwd = getpwuid(geteuid())) != NULL) {
+ home = pwd->pw_dir;
+ } else {
+ errx("HOME is not set and getpwuid() failed.");
+ }
}
if (chdir(home) != 0) {