X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fslocal.c;h=4e8c30d7dcf4897355463b09522777ee8b970544;hp=85bc52a0c21a277a57de0abf0de6eee42138c435;hb=39d862d5f0ba0258707ef5a74cff63243f58e425;hpb=d3ba09a465cb0e5fc9a74d0b152a7ed965f895cb diff --git a/uip/slocal.c b/uip/slocal.c index 85bc52a..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; @@ -189,7 +177,7 @@ static void glob(int); 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); @@ -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; @@ -405,8 +385,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) @@ -440,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; @@ -457,11 +431,7 @@ localmail(int fd, char *mdlvr) 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); } @@ -647,8 +617,7 @@ usr_delivery(int fd, char *delivery, int su) 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 */ @@ -659,19 +628,13 @@ usr_delivery(int fd, char *delivery, int su) 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': @@ -1059,25 +1022,18 @@ timely(char *t1, char *t2) */ 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 = mbox_open(mailbox, pw->pw_uid, pw->pw_gid, m_gmprot())) == -1) { if (verbose) adorn("", "unable to open:"); @@ -1087,15 +1043,14 @@ usr_file(int fd, char *mailbox, int mbx_style) lseek(fd, (off_t) 0, SEEK_SET); /* append message to file */ - if (mbx_copy(mailbox, mbx_style, md, fd, mapping, NULL, 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; @@ -1553,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; -}