X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fslocal.c;h=4e8c30d7dcf4897355463b09522777ee8b970544;hp=7546cdd953169507c74e8c75ad4aec7565e462f6;hb=39d862d5f0ba0258707ef5a74cff63243f58e425;hpb=de448e64862babc8ea92d6ee3f61f68ba3915128 diff --git a/uip/slocal.c b/uip/slocal.c index 7546cdd..4e8c30d 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -9,7 +9,7 @@ /* ** Under sendmail, users should add the line ** -** "| /usr/local/nmh/lib/slocal" +** "| /usr/local/mmh/bin/slocal" ** ** to their $HOME/.forward file. ** @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -45,17 +44,6 @@ 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 #ifndef HAVE_GETUTENT @@ -89,23 +77,23 @@ static struct swit switches[] = { { "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; @@ -198,7 +186,6 @@ static int copy_message(int, char *, 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 *); @@ -220,7 +207,6 @@ main(int argc, char **argv) if (context_foil(NULL) == -1) done(1); - mts_init(invo_name); arguments = getarguments(invo_name, argc, argv, 0); argp = arguments; @@ -298,12 +284,6 @@ main(int argc, char **argv) verbose = 0; continue; - case SUPPRESSDUP: - suppressdup++; - continue; - case NSUPPRESSDUP: - suppressdup = 0; - continue; case DEBUGSW: debug++; continue; @@ -439,11 +419,6 @@ main(int argc, char **argv) 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; @@ -1058,7 +1033,7 @@ usr_file(int fd, char *mailbox) verbose_printf(" (mbox style)"); /* open and lock the file */ - if ((md = mbx_open(mailbox, pw->pw_uid, pw->pw_gid, + if ((md = mbox_open(mailbox, pw->pw_uid, pw->pw_gid, m_gmprot())) == -1) { if (verbose) adorn("", "unable to open:"); @@ -1068,14 +1043,14 @@ usr_file(int fd, char *mailbox) lseek(fd, (off_t) 0, SEEK_SET); /* append message to file */ - if (mbx_copy(mailbox, md, fd, verbose) == -1) { + if (mbox_copy(md, fd) == -1) { if (verbose) adorn("", "error writing to:"); return -1; } /* close and unlock file */ - if (mbx_close(mailbox, md) == NOTOK) { + if (mbox_close(mailbox, md) == NOTOK) { if (verbose) adorn("", "error closing:"); return -1; @@ -1533,108 +1508,3 @@ debug_printf(char *fmt, ...) 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; -}