From: Ralph Corderoy Date: Thu, 25 May 2017 12:53:27 +0000 (+0100) Subject: Remove support for ./.foo.map index for ./foo mailbox. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/e6c917710e4318949cb4174cabca51a8d1822dbd?ds=sidebyside Remove support for ./.foo.map index for ./foo mailbox. An MH-only index of a mailbox, mbox or MMDF format, called a map file, could be built and maintained by packf(1), rcvpack(1), and slocal(1), but since msh(1) was removed in e6917522, there hasn't been a user of the index file so stop producing it and delete all the supporting code in uip/dropsbr.c. mbx_copy() loses its `mapping' and `noisy' parameters; noisy was only used when mapping. Delete mbx_read() and mbx_size() as they have no callers without maps. --- diff --git a/h/dropsbr.h b/h/dropsbr.h index b90baa69..81b92e48 100644 --- a/h/dropsbr.h +++ b/h/dropsbr.h @@ -1,28 +1,6 @@ /* dropsbr.h -- definitions for maildrop-style files */ -/* - * A file which is formatted like a maildrop may have a corresponding map - * file which is an index to the bounds of each message. The first record - * of such an map is special, it contains: - * - * d_id = number of messages in file - * d_size = version number of map - * d_start = last message read - * d_stop = size of file - * - * Each record after that contains: - * - * d_id = BBoard-ID: of message, or similar info - * d_size = size of message in ARPA Internet octets (\n == 2 octets) - * d_start = starting position of message in file - * d_stop = stopping position of message in file - * - * Note that d_start/d_stop do NOT include the message delimiters, so - * programs using the map can simply fseek to d_start and keep reading - * until the position is at d_stop. - */ - /* * various formats for maildrop files */ @@ -30,22 +8,9 @@ #define MBOX_FORMAT 1 #define MMDF_FORMAT 2 -#define DRVRSN 3 - -struct drop { - int d_id; - int d_size; - off_t d_start; - off_t d_stop; -}; - /* * prototypes */ int mbx_open (char *, int, uid_t, gid_t, mode_t); -int mbx_read (FILE *, long, struct drop **); -int mbx_copy (char *, int, int, int, int, char *, int); -int mbx_size (int, off_t, off_t); +int mbx_copy (char *, int, int, int, char *); int mbx_close (char *, int); -int map_write (char *, int, int, long, off_t, off_t, long, int, int); -int map_chk (char *, int, struct drop *, long, int); diff --git a/man/packf.man b/man/packf.man index b96489da..4cac1d89 100644 --- a/man/packf.man +++ b/man/packf.man @@ -62,7 +62,6 @@ can be unpacked using .nf .ta \w'%nmhetcdir%/ExtraBigFileName 'u ^$HOME/.mh_profile~^The user profile -^.msgbox.map~^A binary index of the file .fi .SH "PROFILE COMPONENTS" .fc ^ ~ diff --git a/test/dist/test-dist b/test/dist/test-dist index fc6b33ce..496986f5 100755 --- a/test/dist/test-dist +++ b/test/dist/test-dist @@ -58,7 +58,7 @@ test_dist () # fakesendmail drops the message and any cc's into this mbox. mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox inc -silent -file "$mbox" - rm -f "$mbox" "$mbox.map" + rm -f "$mbox" # It's hard to calculate the exact Date: header post is going to # use, so we'll just use sed to remove the actual date so we can diff --git a/test/folder/test-packf b/test/folder/test-packf index a6c2efed..a839dc8e 100755 --- a/test/folder/test-packf +++ b/test/folder/test-packf @@ -53,7 +53,7 @@ printf 'y\n' >Mail/yes # check with no switches run_prog packf /dev/null -rm -f msgbox .msgbox.map +rm -f msgbox for i in `pick +inbox`; do diff "`mhpath +inbox $i`" "`mhpath +inbox2 $i`" done @@ -63,7 +63,7 @@ rmm +inbox2 -unlink `pick +inbox2` # check +folder run_prog packf +inbox /dev/null -rm -f msgbox .msgbox.map +rm -f msgbox for i in `pick +inbox`; do diff "`mhpath +inbox $i`" "`mhpath +inbox2 $i`" done @@ -73,7 +73,7 @@ rmm +inbox2 -unlink `pick +inbox2` # check msgs run_prog packf +inbox 1 2 3 /dev/null -rm -f msgbox .msgbox.map +rm -f msgbox for i in `pick +inbox2`; do diff "`mhpath +inbox $i`" "`mhpath +inbox2 $i`" done @@ -92,7 +92,7 @@ rmm +inbox2 -unlink `pick +inbox2` # check append to existing mbox file run_prog packf +inbox -file msgbox2 /dev/null -rm -f msgbox2 .msgbox2.map +rm -f msgbox2 for i in `pick +inbox2`; do if [ $i -le 10 ]; then diff "`mhpath +inbox $i`" "`mhpath +inbox2 $i`" @@ -107,7 +107,7 @@ rmm +inbox2 -unlink `pick +inbox2` # check -mbox run_prog packf +inbox -mbox /dev/null -rm -f msgbox .msgbox.map +rm -f msgbox for i in `pick +inbox2`; do diff "`mhpath +inbox $i`" "`mhpath +inbox2 $i`" done @@ -117,7 +117,7 @@ rmm +inbox2 -unlink `pick +inbox2` # check -mmdf run_prog packf +inbox -mmdf /dev/null -rm -f msgbox .msgbox.map +rm -f msgbox for i in `pick +inbox2`; do diff "`mhpath +inbox $i`" "`mhpath +inbox2 $i`" done @@ -127,7 +127,7 @@ rmm +inbox2 -unlink `pick +inbox2` # check append to existing mmdf file run_prog packf +inbox -mmdf /dev/null -rm -f msgbox .msgbox.map +rm -f msgbox for i in `pick +inbox2`; do if [ $i -le 10 ]; then diff "`mhpath +inbox $i`" "`mhpath +inbox2 $i`" diff --git a/test/mhbuild/test-utf8-body b/test/mhbuild/test-utf8-body index 5e1b3256..1c57f4bb 100755 --- a/test/mhbuild/test-utf8-body +++ b/test/mhbuild/test-utf8-body @@ -35,7 +35,7 @@ test_attachment () # fakesendmail drops the message and any cc's into this mbox. mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox inc -silent -file "$mbox" - rm -f "$mbox" "$mbox.map" + rm -f "$mbox" # # It's hard to calculate the exact Date: header post is going to diff --git a/test/post/test-messageid b/test/post/test-messageid index 6ca8f97e..92c72010 100755 --- a/test/post/test-messageid +++ b/test/post/test-messageid @@ -63,7 +63,7 @@ test_messageid () # fakesendmail drops the message and any cc's into this mbox. mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox inc -silent -file "$mbox" - rm -f "$mbox" "$mbox.map" + rm -f "$mbox" n=1 for expected in "$@"; do diff --git a/test/post/test-mts b/test/post/test-mts index 73b9aa11..cd0e727d 100755 --- a/test/post/test-mts +++ b/test/post/test-mts @@ -62,7 +62,7 @@ test_sendmail () # fakesendmail drops the message and any cc's into this mbox. mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox inc -silent -file "$mbox" - rm -f "$mbox" "$mbox.map" + rm -f "$mbox" n=1 for expected in "$@"; do diff --git a/test/post/test-post-aliases b/test/post/test-post-aliases index 664346df..8420aa35 100755 --- a/test/post/test-post-aliases +++ b/test/post/test-post-aliases @@ -40,7 +40,7 @@ test_alias () # fakesendmail drops the message and any cc's into this mbox. mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox inc -silent -file "$mbox" - rm -f "$mbox" "$mbox.map" + rm -f "$mbox" # It's hard to calculate the exact Date: header post is going to # use, so we'll just use sed to remove the actual date so we can easily diff --git a/test/post/test-sendfiles b/test/post/test-sendfiles index 4e2eb612..84f54bfe 100755 --- a/test/post/test-sendfiles +++ b/test/post/test-sendfiles @@ -58,7 +58,7 @@ test_sendfiles () # fakesendmail drops the message and any cc's into this mbox. mbox="$MH_TEST_DIR"/Mail/fakesendmail.mbox inc -silent -file "$mbox" - rm -f "$mbox" "$mbox.map" + rm -f "$mbox" mhlist -verbose last | sed -e 's/ *$//' -e 's/\(octet-stream\).*$/\1/' \ >"$actual" diff --git a/test/rcv/test-rcvdist b/test/rcv/test-rcvdist index 857a4edc..55c6bf30 100755 --- a/test/rcv/test-rcvdist +++ b/test/rcv/test-rcvdist @@ -67,7 +67,7 @@ test_rcvdist () # fakesendmail drops the message and any cc's into this mbox. mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox inc -silent -file "$mbox" - rm -f "$mbox" "$mbox.map" + rm -f "$mbox" # It's hard to calculate the exact Date: header post is going to # use, so we'll just use sed to remove the actual date so we can diff --git a/uip/dropsbr.c b/uip/dropsbr.c index 1fdca2e2..7c8fe246 100644 --- a/uip/dropsbr.c +++ b/uip/dropsbr.c @@ -29,7 +29,6 @@ */ static int mbx_chk_mbox (int); static int mbx_chk_mmdf (int); -static int map_open (char *, int); /* @@ -152,83 +151,18 @@ mbx_chk_mmdf (int fd) } -int -mbx_read (FILE *fp, long pos, struct drop **drops) -{ - int len, size; - long ld1, ld2; - char *bp; - char buffer[BUFSIZ]; - struct drop *cp, *dp, *ep, *pp; - - len = MAXFOLDER; - pp = mh_xcalloc(len, sizeof *pp); - - ld1 = (long) strlen (mmdlm1); - ld2 = (long) strlen (mmdlm2); - - fseek (fp, pos, SEEK_SET); - for (ep = (dp = pp) + len - 1; fgets (buffer, sizeof(buffer), fp);) { - size = 0; - if (strcmp (buffer, mmdlm1) == 0) - pos += ld1, dp->d_start = (long) pos; - else { - dp->d_start = (long)pos , pos += (long) strlen (buffer); - for (bp = buffer; *bp; bp++, size++) - if (*bp == '\n') - size++; - } - - while (fgets (buffer, sizeof(buffer), fp) != NULL) - if (strcmp (buffer, mmdlm2) == 0) - break; - else { - pos += (long) strlen (buffer); - for (bp = buffer; *bp; bp++, size++) - if (*bp == '\n') - size++; - } - - if (dp->d_start != (long) pos) { - dp->d_id = 0; - dp->d_size = (long) size; - dp->d_stop = pos; - dp++; - } - pos += ld2; - - if (dp >= ep) { - int curlen = dp - pp; - - cp = (struct drop *) mh_xrealloc ((char *) pp, - (size_t) (len += MAXFOLDER) * sizeof(*pp)); - dp = cp + curlen, ep = (pp = cp) + len - 1; - } - } - - if (dp == pp) - free(pp); - else - *drops = pp; - return (dp - pp); -} - - /* * Append message to end of file or maildrop. */ int mbx_copy (char *mailbox, int mbx_style, int md, int fd, - int mapping, char *text, int noisy) + char *text) { int i, j, size; - off_t start, stop; - long pos; char *cp, buffer[BUFSIZ + 1]; /* Space for NUL. */ FILE *fp; - pos = (long) lseek (md, (off_t) 0, SEEK_CUR); size = 0; switch (mbx_style) { @@ -237,7 +171,6 @@ mbx_copy (char *mailbox, int mbx_style, int md, int fd, j = strlen (mmdlm1); if (write (md, mmdlm1, j) != j) return NOTOK; - start = lseek (md, (off_t) 0, SEEK_CUR); if (text) { i = strlen (text); @@ -257,18 +190,11 @@ mbx_copy (char *mailbox, int mbx_style, int md, int fd, continue; if (write (md, buffer, i) != i) return NOTOK; - if (mapping) - for (cp = buffer; i-- > 0; size++) - if (*cp++ == '\n') - size++; } - stop = lseek (md, (off_t) 0, SEEK_CUR); j = strlen (mmdlm2); if (write (md, mmdlm2, j) != j) return NOTOK; - if (mapping) - map_write (mailbox, md, 0, (long) 0, start, stop, pos, size, noisy); return (i != NOTOK ? OK : NOTOK); @@ -279,7 +205,6 @@ mbx_copy (char *mailbox, int mbx_style, int md, int fd, close (j); return NOTOK; } - start = lseek (md, (off_t) 0, SEEK_CUR); /* If text is given, we add it to top of message */ if (text) { @@ -353,52 +278,20 @@ mbx_copy (char *mailbox, int mbx_style, int md, int fd, fclose (fp); return NOTOK; } - if (mapping) - for (cp = buffer; i-- > 0; size++) - if (*cp++ == '\n') - size++; } if (write (md, "\n", 1) != 1) { fclose (fp); return NOTOK; } - if (mapping) - size += 2; fclose (fp); lseek (fd, (off_t) 0, SEEK_END); - stop = lseek (md, (off_t) 0, SEEK_CUR); - if (mapping) - map_write (mailbox, md, 0, (long) 0, start, stop, pos, size, noisy); return OK; } } -int -mbx_size (int md, off_t start, off_t stop) -{ - int i, fd; - long pos; - FILE *fp; - - if ((fd = dup (md)) == NOTOK || (fp = fdopen (fd, "r")) == NULL) { - if (fd != NOTOK) - close (fd); - return NOTOK; - } - - fseek (fp, start, SEEK_SET); - for (i = 0, pos = stop - start; pos-- > 0; i++) - if (fgetc (fp) == '\n') - i++; - - fclose (fp); - return i; -} - - /* * Close and unlock file/maildrop. */ @@ -410,197 +303,3 @@ mbx_close (char *mailbox, int md) return OK; return NOTOK; } - - -/* - * This function is performed implicitly by getbbent.c: - * bb->bb_map = map_name (bb->bb_file); - */ - -static char * -map_name (char *file) -{ - char *cp, *dp; - static char buffer[BUFSIZ]; - - if ((dp = strchr(cp = r1bindex (file, '/'), '.')) == NULL) - dp = cp + strlen (cp); - if (cp == file) - snprintf (buffer, sizeof(buffer), ".%.*s%s", (int)(dp - cp), cp, ".map"); - else - snprintf (buffer, sizeof(buffer), "%.*s.%.*s%s", - (int)(cp - file), file, (int)(dp - cp), cp, ".map"); - - return buffer; -} - - -int -map_write (char *mailbox, int md, int id, long last, off_t start, - off_t stop, long pos, int size, int noisy) -{ - int i; - int clear, fd, td; - char *file; - struct drop *dp; - struct drop d1, d2, *rp; - FILE *fp; - struct stat st; - - if ((fd = map_open (file = map_name (mailbox), md)) == NOTOK) - return NOTOK; - - if ((fstat (fd, &st) == OK) && (st.st_size > 0)) - clear = 0; - else - clear = 1; - - if (!clear && map_chk (file, fd, &d1, pos, noisy)) { - (void) m_unlink (file); - mbx_close (file, fd); - if ((fd = map_open (file, md)) == NOTOK) - return NOTOK; - clear++; - } - - if (clear) { - if ((td = dup (md)) == NOTOK || (fp = fdopen (td, "r")) == NULL) { - if (noisy) - admonish (file, "unable to %s", td != NOTOK ? "fdopen" : "dup"); - if (td != NOTOK) - close (td); - mbx_close (file, fd); - return NOTOK; - } - - switch (i = mbx_read (fp, 0, &rp)) { - case NOTOK: - fclose (fp); - mbx_close (file, fd); - return NOTOK; - - case OK: - fclose (fp); - break; - - default: - d1.d_id = 0; - for (dp = rp; i-- >0; dp++) { - if (dp->d_start == start) - dp->d_id = id; - lseek (fd, (off_t) (++d1.d_id * sizeof(*dp)), SEEK_SET); - if (write (fd, (char *) dp, sizeof(*dp)) != sizeof(*dp)) { - if (noisy) - admonish (file, "write error"); - mbx_close (file, fd); - fclose (fp); - return NOTOK; - } - } - free(rp); - fclose (fp); - break; - } - } - else { - if (last == 0) - last = d1.d_start; - dp = &d2; - dp->d_id = id; - dp->d_size = (long) (size ? size : mbx_size (fd, start, stop)); - dp->d_start = start; - dp->d_stop = stop; - lseek (fd, (off_t) (++d1.d_id * sizeof(*dp)), SEEK_SET); - if (write (fd, (char *) dp, sizeof(*dp)) != sizeof(*dp)) { - if (noisy) - admonish (file, "write error"); - mbx_close (file, fd); - return NOTOK; - } - } - - dp = &d1; - dp->d_size = DRVRSN; - dp->d_start = (long) last; - dp->d_stop = lseek (md, (off_t) 0, SEEK_CUR); - - lseek (fd, (off_t) 0, SEEK_SET); - if (write (fd, (char *) dp, sizeof(*dp)) != sizeof(*dp)) { - if (noisy) - admonish (file, "write error"); - mbx_close (file, fd); - return NOTOK; - } - - mbx_close (file, fd); - - return OK; -} - - -static int -map_open (char *file, int md) -{ - mode_t mode; - struct stat st; - - mode = fstat (md, &st) != NOTOK ? (int) (st.st_mode & 0777) : m_gmprot (); - return mbx_open (file, OTHER_FORMAT, st.st_uid, st.st_gid, mode); -} - - -int -map_chk (char *file, int fd, struct drop *dp, long pos, int noisy) -{ - ssize_t count; - struct drop d, tmpd; - struct drop *dl; - - if (read (fd, (char *) &tmpd, sizeof(*dp)) != sizeof(*dp)) { -#ifdef notdef - inform("%s: missing or partial index, continuing...", file); -#endif /* notdef */ - return NOTOK; - } -#ifndef NTOHLSWAP - *dp = tmpd; /* if ntohl(n)=(n), can use struct assign */ -#else - dp->d_id = ntohl(tmpd.d_id); - dp->d_size = ntohl(tmpd.d_size); - dp->d_start = ntohl(tmpd.d_start); - dp->d_stop = ntohl(tmpd.d_stop); -#endif - - if (dp->d_size != DRVRSN) { - if (noisy) - inform("%s: version mismatch (%d != %d), continuing...", file, - dp->d_size, DRVRSN); - return NOTOK; - } - - if (dp->d_stop != pos) { - if (noisy && pos != (long) 0) - inform("%s: pointer mismatch or incomplete index (%ld!=%ld), " - "continuing...", file, dp->d_stop, (long) pos); - return NOTOK; - } - - if ((long) ((dp->d_id + 1) * sizeof(*dp)) != (long) lseek (fd, (off_t) 0, SEEK_END)) { - if (noisy) - inform("%s: corrupt index(1), continuing...", file); - return NOTOK; - } - - dl = &d; - count = strlen (mmdlm2); - lseek (fd, (off_t) (dp->d_id * sizeof(*dp)), SEEK_SET); - if (read (fd, (char *) dl, sizeof(*dl)) != sizeof(*dl) - || (ntohl(dl->d_stop) != dp->d_stop - && ntohl(dl->d_stop) + count != dp->d_stop)) { - if (noisy) - inform("%s: corrupt index(2), continuing...", file); - return NOTOK; - } - - return OK; -} diff --git a/uip/packf.c b/uip/packf.c index 6fa97b2d..2424c97c 100644 --- a/uip/packf.c +++ b/uip/packf.c @@ -28,7 +28,6 @@ DEFINE_SWITCH_ARRAY(PACKF, switches); static int md = NOTOK; static int mbx_style = MBOX_FORMAT; -static int mapping = 0; static void mbxclose_done(int) NORETURN; @@ -82,11 +81,9 @@ main (int argc, char **argv) case MBOXSW: mbx_style = MBOX_FORMAT; - mapping = 0; continue; case MMDFSW: mbx_style = MMDF_FORMAT; - mapping = 1; continue; } } @@ -155,7 +152,7 @@ main (int argc, char **argv) break; } - if (mbx_copy (file, mbx_style, md, fd, mapping, NULL, 1) == NOTOK) + if (mbx_copy (file, mbx_style, md, fd, NULL) == NOTOK) adios (file, "error writing to file"); close (fd); diff --git a/uip/rcvpack.c b/uip/rcvpack.c index 6235e5e9..18937bc2 100644 --- a/uip/rcvpack.c +++ b/uip/rcvpack.c @@ -87,7 +87,7 @@ main (int argc, char **argv) done (RCV_MBX); /* append the message */ - if (mbx_copy (file, mbx_style, md, fileno(stdin), 1, NULL, 0) == NOTOK) { + if (mbx_copy (file, mbx_style, md, fileno(stdin), NULL) == NOTOK) { mbx_close (file, md); done (RCV_MBX); } diff --git a/uip/slocal.c b/uip/slocal.c index cfbba804..f0c3aa07 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -971,7 +971,7 @@ timely (char *t1, char *t2) static int usr_file (int fd, char *mailbox, int mbx_style) { - int md, mapping; + int md; if (verbose) verbose_printf ("delivering to file \"%s\"", mailbox); @@ -979,11 +979,9 @@ usr_file (int fd, char *mailbox, int mbx_style) if (mbx_style == MBOX_FORMAT) { if (verbose) verbose_printf (" (mbox style)"); - mapping = 0; } else { if (verbose) verbose_printf (" (mmdf style)"); - mapping = 1; } /* open and lock the file */ @@ -996,7 +994,7 @@ 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 (mbx_copy (mailbox, mbx_style, md, fd, NULL) == -1) { if (verbose) adorn ("", "error writing to:"); return -1;