/*
** Under sendmail, users should add the line
**
-** "| /usr/local/nmh/lib/slocal"
+** "| /usr/local/mmh/bin/slocal"
**
** to their $HOME/.forward file.
**
#include <h/rcvmail.h>
#include <h/signals.h>
#include <h/tws.h>
-#include <h/mts.h>
#include <h/utils.h>
#include <pwd.h>
extern int initgroups(char*, int);
#endif
-/*
-** This define is needed for Berkeley db v2 and above to
-** make the header file expose the 'historical' ndbm APIs.
-** We define it unconditionally because this is simple and
-** harmless.
-*/
-#define DB_DBM_HSEARCH 1
-#ifdef NDBM_HEADER
-#include NDBM_HEADER
-#endif
-
#include <utmp.h>
#ifndef HAVE_GETUTENT
{ "verbose", 0 },
#define NVERBSW 9
{ "noverbose", 0 },
-#define SUPPRESSDUP 10
- { "suppressdup", 0 },
-#define NSUPPRESSDUP 11
- { "nosuppressdup", 0 },
-#define DEBUGSW 12
+#define DEBUGSW 10
{ "debug", 0 },
-#define VERSIONSW 13
+#define VERSIONSW 11
{ "version", 0 },
-#define HELPSW 14
+#define HELPSW 12
{ "help", 0 },
{ NULL, 0 }
};
+
+/* global maildelivery file */
+char *maildelivery = NMHETCDIR"/maildelivery";
+
+
static int globbed = 0; /* have we built "vars" table yet? */
static int parsed = 0; /* have we built header field table yet */
static int utmped = 0; /* have we scanned umtp(x) file yet */
-static int suppressdup = 0; /* are we suppressing duplicate messages? */
static int verbose = 0;
static int debug = 0;
static struct pair *lookup(struct pair *, char *);
static int logged_in(void);
static int timely(char *, char *);
-static int usr_file(int, char *, int);
+static int usr_file(int, char *);
static int usr_pipe(int, char *, char *, char **, int);
static int usr_folder(int, char *);
static RETSIGTYPE alrmser(int);
static void verbose_printf(char *fmt, ...);
static void adorn(char *, char *, ...);
static void debug_printf(char *fmt, ...);
-static int suppress_duplicates(int, char *);
static char *trim(char *);
if (context_foil(NULL) == -1)
done(1);
- mts_init(invo_name);
arguments = getarguments(invo_name, argc, argv, 0);
argp = arguments;
verbose = 0;
continue;
- case SUPPRESSDUP:
- suppressdup++;
- continue;
- case NSUPPRESSDUP:
- suppressdup = 0;
- continue;
case DEBUGSW:
debug++;
continue;
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)
static int
localmail(int fd, char *mdlvr)
{
- /* check if this message is a duplicate */
- if (suppressdup && suppress_duplicates(fd, mdlvr ?
- mdlvr : ".maildelivery") == DONE)
- return 0;
-
/* delivery according to personal Maildelivery file */
if (usr_delivery(fd, mdlvr ? mdlvr : ".maildelivery", 0) != -1)
return 0;
verbose_printf("(delivering to standard mail spool)\n");
/* last resort - deliver to standard mail spool */
-#ifdef SLOCAL_MBOX
- return usr_file(fd, mbox, MBOX_FORMAT);
-#else
- return usr_file(fd, mbox, MMDF_FORMAT);
-#endif
+ return usr_file(fd, mbox);
}
case 'f':
/* mbox format */
if (!mh_strcasecmp(action, "file")) {
- status = usr_file(fd, string,
- MBOX_FORMAT);
+ status = usr_file(fd, string);
break;
}
/* deliver to nmh folder */
break;
case 'm':
- /* mmdf format */
- if (!mh_strcasecmp(action, "mmdf")) {
- status = usr_file(fd, string,
- MMDF_FORMAT);
- break;
- }
/* mbox format */
- else if (mh_strcasecmp(action, "mbox"))
+ if (mh_strcasecmp(action, "mbox"))
continue; /* else fall */
case '>':
/* mbox format */
- status = usr_file(fd, string, MBOX_FORMAT);
+ status = usr_file(fd, string);
break;
case 'd':
*/
static int
-usr_file(int fd, char *mailbox, int mbx_style)
+usr_file(int fd, char *mailbox)
{
- int md, mapping;
+ int md;
if (verbose)
verbose_printf("delivering to file \"%s\"", mailbox);
- if (mbx_style == MBOX_FORMAT) {
- if (verbose)
- verbose_printf(" (mbox style)");
- mapping = 0;
- } else {
- if (verbose)
- verbose_printf(" (mmdf style)");
- mapping = 1;
- }
+ if (verbose)
+ verbose_printf(" (mbox style)");
/* open and lock the file */
- if ((md = mbx_open(mailbox, mbx_style, pw->pw_uid, pw->pw_gid,
+ if ((md = mbx_open(mailbox, pw->pw_uid, pw->pw_gid,
m_gmprot())) == -1) {
if (verbose)
adorn("", "unable to open:");
lseek(fd, (off_t) 0, SEEK_SET);
/* append message to file */
- if (mbx_copy(mailbox, mbx_style, md, fd, mapping, NULL, verbose)
- == -1) {
+ if (mbx_copy(mailbox, md, fd, verbose) == -1) {
if (verbose)
adorn("", "error writing to:");
return -1;
while (fgets(buffer, sizeof(buffer), qfp)) {
if (first) {
first = 0;
- if (!strncmp(buffer, "From ", i)) {
+ if (strncmp(buffer, "From ", i)==0) {
#ifdef RPATHS
char *fp, *cp, *hp, *ep;
#endif
vfprintf(stderr, fmt, ap);
va_end(ap);
}
-
-
-/*
-** Check ndbm/db file(s) to see if the Message-Id of this
-** message matches the Message-Id of a previous message,
-** so we can discard it. If it doesn't match, we add the
-** Message-Id of this message to the ndbm/db file.
-*/
-static int
-suppress_duplicates(int fd, char *file)
-{
- int fd1, lockfd, state, result;
- char *cp, buf[BUFSIZ], name[NAMESZ];
- datum key, value;
- DBM *db;
- FILE *in;
-
- if ((fd1 = dup(fd)) == -1)
- return -1;
- if (!(in = fdopen(fd1, "r"))) {
- close(fd1);
- return -1;
- }
- rewind(in);
-
- for (state = FLD;;) {
- state = m_getfld(state, name, buf, sizeof(buf), in);
- switch (state) {
- case FLD:
- case FLDPLUS:
- case FLDEOF:
- /* Search for the message ID */
- if (mh_strcasecmp(name, "Message-ID")) {
- while (state == FLDPLUS)
- state = m_getfld(state, name, buf,
- sizeof(buf), in);
- continue;
- }
-
- cp = getcpy(buf);
- while (state == FLDPLUS) {
- state = m_getfld(state, name, buf,
- sizeof(buf), in);
- cp = add(buf, cp);
- }
- key.dptr = trimcpy(cp);
- key.dsize = strlen(key.dptr) + 1;
- free(cp);
- cp = key.dptr;
-
- if (!(db = dbm_open(file, O_RDWR | O_CREAT, 0600))) {
- advise(file, "unable to perform dbm_open on");
- free(cp);
- fclose(in);
- return -1;
- }
- /*
- ** Since it is difficult to portable lock a ndbm
- ** file, we will open and lock the Maildelivery
- ** file instead. This will fail if your Maildelivery
- ** file doesn't exist.
- */
- if ((lockfd = lkopen(file, O_RDWR, 0)) == -1) {
- advise(file, "unable to perform file locking on");
- free(cp);
- fclose(in);
- return -1;
- }
- value = dbm_fetch(db, key);
- if (value.dptr) {
- if (verbose)
- verbose_printf("Message-ID: %s\n already received on %s", cp, value.dptr);
- result = DONE;
- } else {
- value.dptr = ddate + sizeof("Delivery-Date:");
- value.dsize = strlen(value.dptr) + 1;
- if (dbm_store(db, key, value, DBM_INSERT))
- advise(file, "possibly corrupt file");
- result = 0;
- }
-
- dbm_close(db);
- lkclose(lockfd, file);
- free(cp);
- fclose(in);
- return result;
- break;
-
- case BODY:
- case BODYEOF:
- case FILEEOF:
- break;
-
- case LENERR:
- case FMTERR:
- default:
- break;
- }
-
- break;
- }
-
- fclose(in);
- return 0;
-}