From 684ec30d81e1223a282764452f4902ed4ad1c754 Mon Sep 17 00:00:00 2001 From: markus schnalke Date: Mon, 30 Jan 2012 11:03:29 +0100 Subject: [PATCH] Rest of the MMDF-style mail drop support removal. Only Unix-style (mbox) mail drops are supported now. Their location is in `mailspool', which is reported in the configure summary now. If users like to have different locations, they can use the environment variable MAILDROP or the profile entry MailDrop to overrule the default. From mts.conf, mmdfldir and mmdflfil were removed. msgchk(1) received several cleanups. I touched sbr/m_getfld.c ... Wooohh ... --- config/Makefile.in | 6 ++- config/config.c | 5 +++ configure.ac | 1 + etc/mts.conf.in | 8 ---- h/mh.h | 2 +- h/mts.h | 20 --------- man/conflict.man8 | 2 +- man/mh-tailor.man5 | 15 ------- man/msgchk.man1 | 36 ++++++++++++---- sbr/m_getfld.c | 19 ++------- sbr/mts.c | 19 --------- uip/conflict.c | 5 +-- uip/inc.c | 2 +- uip/msgchk.c | 116 ++++++++++++++++++++++++++-------------------------- uip/slocal.c | 3 +- 15 files changed, 105 insertions(+), 154 deletions(-) diff --git a/config/Makefile.in b/config/Makefile.in index c1b16bd..da7d12a 100644 --- a/config/Makefile.in +++ b/config/Makefile.in @@ -18,13 +18,15 @@ libdir = @libdir@ etcdir = @sysconfdir@ sendmailpath = @sendmailpath@ +mailspool = @mailspool@ CC = @CC@ CFLAGS = @CFLAGS@ DEFS = @DEFS@ INCLUDES = -I.. -I$(top_srcdir) @CPPFLAGS@ -CONFIGDEFS = -DNMHBINDIR='"$(bindir)"' -DNMHETCDIR='"$(etcdir)"' -DNMHLIBDIR='"$(libdir)"' \ - -DSENDMAILPATH='"$(sendmailpath)"' +CONFIGDEFS = -DNMHBINDIR='"$(bindir)"' -DNMHETCDIR='"$(etcdir)"' \ + -DNMHLIBDIR='"$(libdir)"' -DSENDMAILPATH='"$(sendmailpath)"' \ + -DMAILSPOOL='"$(mailspool)"' COMPILE = $(CC) -c $(DEFS) $(INCLUDES) $(CFLAGS) COMPILE2 = $(CC) -c $(DEFS) $(CONFIGDEFS) $(INCLUDES) $(CFLAGS) diff --git a/config/config.c b/config/config.c index 30c9574..cdf8f5a 100644 --- a/config/config.c +++ b/config/config.c @@ -217,6 +217,11 @@ char *whatnowproc = NMHBINDIR"/whatnow"; */ char *sendmail = SENDMAILPATH; +/* +** This is the path to the system mail spool directory (e.g. `/var/mail'). +*/ +char *mailspool = MAILSPOOL; + /* ** file stuff diff --git a/configure.ac b/configure.ac index 0d3dc69..3de6bf6 100644 --- a/configure.ac +++ b/configure.ac @@ -834,6 +834,7 @@ config install path : ${nmhsysconf} man page install path : ${nmhman} sendmail path : ${sendmailpath} +mail spool : ${mailspool} file locking type : ${LOCKTYPE} address masquerading : ${masquerade} diff --git a/etc/mts.conf.in b/etc/mts.conf.in index c5fd01c..65b9d1d 100644 --- a/etc/mts.conf.in +++ b/etc/mts.conf.in @@ -8,11 +8,3 @@ # The following directive allows email address masquerading. The string # "draft_from mmailid username_extension" will allow all three types. masquerade: %masquerade% - -# Default location of mail drops. If this option is -# set, but empty, the user's home directory is used. -mmdfldir: %mailspool% - -# The name of the maildrop file in the directory where maildrops -# are kept. If this is empty, the user's login name is used. -mmdflfil: diff --git a/h/mh.h b/h/mh.h index 116abdb..ef7aa03 100644 --- a/h/mh.h +++ b/h/mh.h @@ -236,7 +236,6 @@ struct msgs { #define MS_DEFAULT 0 /* default (one msg per file) */ #define MS_UNKNOWN 1 /* type not known yet */ #define MS_MBOX 2 /* Unix-style "from" lines */ -#define MS_MMDF 3 /* string mmdlm2 */ extern int msg_count; /* m_getfld() indicators */ extern int msg_style; /* .. */ @@ -307,6 +306,7 @@ extern char *incproc; extern char *lproc; extern char *mhetcdir; extern char *mailproc; +extern char *mailspool; extern char *mh_seq; extern char *mhlformat; extern char *mhlforward; diff --git a/h/mts.h b/h/mts.h index 5ddd837..5092667 100644 --- a/h/mts.h +++ b/h/mts.h @@ -8,30 +8,10 @@ char *LocalName(void); char *SystemName(void); -/* -** Mailboxes -*/ -extern char *mmdfldir; -extern char *mmdflfil; -extern char *uucpldir; -extern char *uucplfil; - -#define MAILDIR (mmdfldir && *mmdfldir ? mmdfldir : getenv("HOME")) -#define MAILFIL (mmdflfil && *mmdflfil ? mmdflfil : getusername()) -#define UUCPDIR (uucpldir && *uucpldir ? uucpldir : getenv("HOME")) -#define UUCPFIL (uucplfil && *uucplfil ? uucplfil : getusername()) char *getusername(void); char *getfullname(void); -/* -** Separators -*/ -extern char *mmdlm1; -extern char *mmdlm2; - -#define isdlm1(s) (strcmp(s, mmdlm1) == 0) -#define isdlm2(s) (strcmp(s, mmdlm2) == 0) /* ** Read mts.conf file diff --git a/man/conflict.man8 b/man/conflict.man8 index fc2f8d7..4df7094 100644 --- a/man/conflict.man8 +++ b/man/conflict.man8 @@ -66,7 +66,7 @@ or whenever system accounting takes place. ^/etc/passwd~^List of users ^/etc/group~^List of groups ^%bindir%/mhmail~^Program to send mail -^%mailspool%/~^Directory of mail drop +^%mailspool%/~^Directory of mail drops .fi .SH "PROFILE COMPONENTS" diff --git a/man/mh-tailor.man5 b/man/mh-tailor.man5 index 8213cb7..265c3cf 100644 --- a/man/mh-tailor.man5 +++ b/man/mh-tailor.man5 @@ -31,21 +31,6 @@ will send messages by forking a local copy of .BR sendmail . .PP -.BR mmdfldir : -%mailspool% -.RS 5 -The directory where maildrops are kept. If this option is set, but empty, -the user's home directory is used. This overrides the default value -chosen at the time of compilation. -.RE -.PP -.BR mmdflfil : -.RS 5 -The name of the maildrop file in the directory where maildrops are kept. -If this is empty, the user's login name is used. This overrides the default -value (which is empty). -.RE -.PP .BR masquerade: .RS 5 This directive controls three different types of email address masquerading. diff --git a/man/msgchk.man1 b/man/msgchk.man1 index 1b9843b..1b58ee5 100644 --- a/man/msgchk.man1 +++ b/man/msgchk.man1 @@ -3,7 +3,7 @@ .\" .TH MSGCHK %manext1% "%nmhdate%" MH.6.8 [%nmhversion%] .SH NAME -msgchk \- check for messages +msgchk \- check system mail drop for messages .SH SYNOPSIS .HP 5 .na @@ -21,11 +21,12 @@ all/mail/nomail ] .SH DESCRIPTION The .B msgchk -program checks all known mail drops for mail waiting -for you. For those drops which have mail for you, +program checks your system mail drop for mail waiting +for you, or the given users. +If the requested users have mail, .B msgchk will -indicate if it believes that you have seen the mail in question before. +indicate if it believes that they have seen the mail in question before. .PP The .B \-notify @@ -67,13 +68,26 @@ switch directs .B msgchk to print out the last date mail was read, if this can be determined. +.PP +If +.I users +are given, then +.B msgchk +will only check the default system mail drops. +Otherwise, +.B msgchk +will evaluate the environment variable +.I MAILDROP +and profile component +.I MailDrop +(in this order) first and, if they are set and non-empty, +checks that mail drop instead of the system default mail drop. .SH FILES .fc ^ ~ .nf .ta \w'%etcdir%/ExtraBigFileName 'u ^$HOME/.mmh/profile~^The user profile -^%etcdir%/mts.conf~^nmh mts configuration file ^%mailspool%/$USER~^Location of mail drop .fi @@ -81,10 +95,18 @@ be determined. .fc ^ ~ .nf .ta 2.4i -.ta \w'ExtraBigProfileName 'u -None +.ta \w'ExtraBigName 'u +^MailDrop~^Supersedes the default mail drop location .fi +.SH ENVIRONMENT +.fc ^ ~ +.nf +.ta \w'ExtraBigName 'u +^MAILDROP~^Highest priority alternative mail drop location +.fi + + .SH "SEE ALSO" inc(1) diff --git a/sbr/m_getfld.c b/sbr/m_getfld.c index 8fd8364..a2dba26 100644 --- a/sbr/m_getfld.c +++ b/sbr/m_getfld.c @@ -639,15 +639,14 @@ m_unknown(FILE *iob) ** ** If the first line of the maildrop is a Unix "From " line, we ** say the style is MBOX and eat the rest of the line. Otherwise -** we say the style is MMDF and look for the delimiter string -** specified when nmh was built (or from the mts.conf file). +** abort. */ msg_style = MS_UNKNOWN; pos = ftell(iob); if (fread(text, sizeof(*text), 5, iob) == 5 - && strncmp(text, "From ", 5) == 0) { + && strncmp(text, "From ", 5) == 0) { msg_style = MS_MBOX; delimstr = "\nFrom "; #ifndef RPATHS @@ -661,11 +660,7 @@ m_unknown(FILE *iob) #endif /* RPATHS */ } else { /* not a Unix style maildrop */ - fseek(iob, pos, SEEK_SET); - if (mmdlm2 == NULL || *mmdlm2 == 0) - mmdlm2 = "\001\001\001\001\n"; - delimstr = mmdlm2; - msg_style = MS_MMDF; + adios(NULL, "No Unix style (mbox) maildrop."); } c = strlen(delimstr); fdelim = (unsigned char *) mh_xmalloc((size_t) (c + 3)); @@ -689,14 +684,6 @@ m_unknown(FILE *iob) for (cp = (char *) fdelim + 1; cp < (char *) delimend; cp++ ) pat_map[(unsigned char)*cp] = (unsigned char *) cp; - - if (msg_style == MS_MMDF) { - /* flush extra msg hdrs */ - while ((c = getc(iob)) >= 0 && eom(c, iob)) - ; - if (c >= 0) - ungetc(c, iob); - } } diff --git a/sbr/mts.c b/sbr/mts.c index a3ea0f8..2830bb7 100644 --- a/sbr/mts.c +++ b/sbr/mts.c @@ -32,25 +32,10 @@ static const char *get_mtsuserconf_pathname(void); static void mts_read_conf_file(FILE *fp); /* -** *mmdfldir and *uucpldir are the maildrop directories. If maildrops -** are kept in the user's home directory, then these should be empty -** strings. In this case, the appropriate ...lfil array should contain -** the name of the file in the user's home directory. Usually, this is -** something like ".mail". -*/ - -/* ** nmh mail transport interface customization file */ static char *mtsconf = NMHETCDIR"/mts.conf"; -char *mmdfldir = MAILSPOOL; -char *mmdflfil = ""; -char *uucpldir = "/usr/spool/mail"; -char *uucplfil = ""; - -char *mmdlm1 = "\001\001\001\001\n"; -char *mmdlm2 = "\001\001\001\001\n"; /* Cache the username and fullname of the user */ static char username[BUFSIZ]; @@ -86,10 +71,6 @@ struct bind { }; static struct bind binds[] = { - { "mmdfldir", &mmdfldir }, - { "mmdflfil", &mmdflfil }, - { "uucpldir", &uucpldir }, - { "uucplfil", &uucplfil }, { "masquerade", &masquerade }, { "maildelivery", &maildelivery }, { "everyone", &everyone }, diff --git a/uip/conflict.c b/uip/conflict.c index 4251ab2..527dd11 100644 --- a/uip/conflict.c +++ b/uip/conflict.c @@ -283,10 +283,7 @@ maildrops(void) { register int i; - if (mmdfldir && *mmdfldir) - mdrop(mmdfldir); - if (uucpldir && *uucpldir) - mdrop(uucpldir); + mdrop(mailspool); for (i = 0; dirs[i]; i++) mdrop(dirs[i]); } diff --git a/uip/inc.c b/uip/inc.c index e3199c0..f000d47 100644 --- a/uip/inc.c +++ b/uip/inc.c @@ -288,7 +288,7 @@ main(int argc, char **argv) else if ((newmail = context_find("maildrop")) && *newmail) newmail = toabsdir(newmail); else { - newmail = concat(MAILDIR, "/", MAILFIL, NULL); + newmail = concat(mailspool, "/", getusername(), NULL); } if (stat(newmail, &s1) == NOTOK || s1.st_size == 0) adios(NULL, "no mail to incorporate"); diff --git a/uip/msgchk.c b/uip/msgchk.c index 36edccb..5b75814 100644 --- a/uip/msgchk.c +++ b/uip/msgchk.c @@ -38,19 +38,16 @@ static struct swit switches[] = { #define NT_ALL (NT_MAIL | NT_NMAI) #define NONEOK 0x0 -#define UUCPOLD 0x1 -#define UUCPNEW 0x2 -#define UUCPOK (UUCPOLD | UUCPNEW) -#define MMDFOLD 0x4 -#define MMDFNEW 0x8 -#define MMDFOK (MMDFOLD | MMDFNEW) +#define MAILOLD 0x4 +#define MAILNEW 0x8 +#define MAILOK (MAILOLD | MAILNEW) /* ** static prototypes */ static int donote(char *, int); -static int checkmail(char *, char *, int, int, int); +static int checkmail(char *, int, int, int); int @@ -59,7 +56,6 @@ main(int argc, char **argv) int datesw = 1, notifysw = NT_ALL; int status = 0; int vecp = 0; - uid_t uid; char buf[BUFSIZ]; char *user, *cp; char **argp, **arguments, *vec[MAXVEC]; @@ -74,7 +70,6 @@ main(int argc, char **argv) context_read(); mts_init(invo_name); - uid = getuid(); user = getusername(); arguments = getarguments(invo_name, argc, argv, 1); @@ -125,30 +120,18 @@ main(int argc, char **argv) vec[vecp++] = cp; } - if (vecp != 0) - vec[vecp] = NULL; - - if (vecp == 0) { - char *home; - - /* Not sure this check makes sense... */ - if (!geteuid() || NULL == (home = getenv("HOME"))) { - pw = getpwnam(user); - if (pw == NULL) - adios(NULL, "unable to get information about user"); - home = pw->pw_dir; - } - status = checkmail(user, home, datesw, notifysw, 1); - } else { - for (vecp = 0; vec[vecp]; vecp++) { - if ((pw = getpwnam(vec[vecp]))) - status += checkmail(pw->pw_name, pw->pw_dir, - datesw, notifysw, 0); - else - advise(NULL, "no such user as %s", vec[vecp]); - } + if (!vecp) { + done(checkmail(user, datesw, notifysw, 1)); + return 1; } + vec[vecp] = NULL; + for (vecp = 0; vec[vecp]; vecp++) { + if ((pw = getpwnam(vec[vecp]))) + status += checkmail(pw->pw_name, datesw, notifysw, 0); + else + advise(NULL, "no such user as %s", vec[vecp]); + } done(status); return 1; } @@ -189,55 +172,72 @@ donote(char *cp, int ntflag) static int -checkmail(char *user, char *home, int datesw, int notifysw, int personal) +checkmail(char *user, int datesw, int notifysw, int personal) { int mf, status; char buffer[BUFSIZ]; struct stat st; - - snprintf(buffer, sizeof(buffer), "%s/%s", - mmdfldir[0] ? mmdfldir : home, - mmdflfil[0] ? mmdflfil : user); + char *maildrop; + + if (personal) { + /* + ** Evaluate the env var and profile only if the check is + ** for the calling user. + */ + if ((maildrop = getenv("MAILDROP")) && *maildrop) { + snprintf(buffer, sizeof buffer, "%s", + toabsdir(maildrop)); + } else if ((maildrop=context_find("maildrop")) && *maildrop) { + snprintf(buffer, sizeof buffer, "%s", + toabsdir(maildrop)); + } else { + snprintf(buffer, sizeof buffer, "%s/%s", + mailspool, user); + } + } else { + snprintf(buffer, sizeof(buffer), "%s/%s", mailspool, user); + } if (datesw) { st.st_size = 0; st.st_atime = st.st_mtime = 0; } mf = (stat(buffer, &st) == NOTOK || st.st_size == 0) ? NONEOK - : st.st_atime <= st.st_mtime ? MMDFNEW : MMDFOLD; + : st.st_atime <= st.st_mtime ? MAILNEW : MAILOLD; - if ((mf & UUCPOK) || (mf & MMDFOK)) { + if (mf & MAILOK) { if (notifysw & NT_MAIL) { - printf(personal ? "You have " : "%s has ", user); - if (mf & UUCPOK) - printf("%s old-style bell", - mf & UUCPOLD ? "old" : "new"); - if ((mf & UUCPOK) && (mf & MMDFOK)) - printf(" and "); - if (mf & MMDFOK) - printf("%s%s", mf & MMDFOLD ? "old" : "new", - mf & UUCPOK ? " Internet" : ""); + if (personal) { + printf("You have "); + } else { + printf("%s has ", user); + } + if (mf & MAILOK) + printf(mf & MAILOLD ? "old" : "new"); printf(" mail waiting"); } else { notifysw = 0; } status = 0; - } - else { - if (notifysw & NT_NMAI) - printf(personal ? "You don't %s%s" : "%s doesn't %s", - personal ? "" : user, - "have any mail waiting"); - else + } else { + if (notifysw & NT_NMAI) { + if (personal) { + printf("You don't have any mail waiting"); + } else { + printf("%s doesn't have any mail waiting", + user); + } + } else { notifysw = 0; - + } status = 1; } - if (notifysw) - if (datesw && st.st_atime) + if (notifysw) { + if (datesw && st.st_atime) { printf("; last read on %s", dtime(&st.st_atime, 1)); - if (notifysw) + } printf("\n"); + } return status; } diff --git a/uip/slocal.c b/uip/slocal.c index a81afa9..7b148e8 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -405,8 +405,7 @@ main(int argc, char **argv) if (mbox == NULL) { snprintf(mailbox, sizeof(mailbox), "%s/%s", - mmdfldir[0] ? mmdfldir : pw->pw_dir, - mmdflfil[0] ? mmdflfil : pw->pw_name); + mailspool, pw->pw_name); mbox = mailbox; } if (home == NULL) -- 1.7.10.4