From cc9f629675bd930e66a798e06e890710da905605 Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Mon, 19 Nov 2012 12:22:26 -0500 Subject: [PATCH 01/16] Remove unused variable. --- uip/rcvdist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uip/rcvdist.c b/uip/rcvdist.c index 702dc9aa..d189e8ed 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -171,7 +171,7 @@ rcvdistout (FILE *inb, char *form, char *addrs) register int char_read = 0, format_len, i, state; register char **ap; char *cp, *scanl, name[NAMESZ], tmpbuf[SBUFSIZ]; - register struct comp *cptr, **savecomp; + register struct comp *cptr; FILE *out; if (!(out = fopen (drft, "w"))) -- 2.56.1 From 096cb902c659b224590c2989020d437721d8e9e5 Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Mon, 19 Nov 2012 12:23:16 -0500 Subject: [PATCH 02/16] Change API a bit. Rename fmt_addcomp() to fmt_addcomptext(). Create new function fmt_addcompentry(). --- h/fmt_scan.h | 21 +++++++++++++++++++- sbr/fmt_compile.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++- uip/mhlsbr.c | 2 +- uip/rcvdist.c | 2 +- 4 files changed, 70 insertions(+), 4 deletions(-) diff --git a/h/fmt_scan.h b/h/fmt_scan.h index 466a9b5d..a2bff891 100644 --- a/h/fmt_scan.h +++ b/h/fmt_scan.h @@ -172,6 +172,25 @@ void fmt_free (struct format *fmt, int reset); struct comp *fmt_findcomp(char *component); +/* + * Search for a component structure in the component hash table. + * + * Identical to fmd_findcomp(), but is case-INSENSITIVE. + */ + +struct comp *fmt_findcasecmp(char *component); + +/* + * Add a component entry to the component hash table + * + * component - The name of the component to add to the hash table. + * + * If the component is already in the hash table, this function will do + * nothing. Returns 1 if a component was added, 0 if it already existed. + */ + +int fmt_addcompentry(char *component); + /* * Add a string to a component hash table entry. Arguments are: * @@ -198,7 +217,7 @@ struct comp *fmt_findcomp(char *component); * in the component hash table, this function will return -1. */ -int fmt_addcomp(char *component, char *text); +int fmt_addcomptext(char *component, char *text); /* * Append to an existing component. Arguments are: diff --git a/sbr/fmt_compile.c b/sbr/fmt_compile.c index 65831958..148d35c7 100644 --- a/sbr/fmt_compile.c +++ b/sbr/fmt_compile.c @@ -872,6 +872,53 @@ fmt_findcomp(char *component) return cm; } +/* + * Like fmt_findcomp, but case-insensitive. + */ + +struct comp * +fmt_findcasecmp(char *component) +{ + struct comp *cm; + + for (cm = wantcomp[CHASH(component)]; cm; cm = cm->c_next) + if (mh_strcasecmp(component, cm->c_name) == 0) + break; + + return cm; +} + +/* + * Add an entry to the component hash table + * + * Returns true if the component was added, 0 if it already existed. + * + */ + +int +fmt_addcompentry(char *component) +{ + struct comp *cm; + int i; + + FINDCOMP(cm, component); + + if (cm) + return 0; + + NEWCOMP(cm, component); + + /* + * ncomp is really meant for fmt_compile() and this function is + * meant to be used outside of it. So decrement it just to be safe + * (internal callers should be using NEWCOMP()). + */ + + ncomp--; + + return 1; +} + /* * Add a string to a component hash table entry. * @@ -880,7 +927,7 @@ fmt_findcomp(char *component) */ int -fmt_addcomp(char *component, char *text) +fmt_addcomptext(char *component, char *text) { int i, found = 0, bucket = CHASH(component); struct comp *cptr = wantcomp[bucket]; diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index 53b61f98..2d101d11 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -1018,7 +1018,7 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec) switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) { case FLD: case FLDPLUS: - bucket = fmt_addcomp(name, buf); + bucket = fmt_addcomptext(name, buf); for (ip = ignores; *ip; ip++) if (!mh_strcasecmp (name, *ip)) { while (state == FLDPLUS) { diff --git a/uip/rcvdist.c b/uip/rcvdist.c index d189e8ed..d3f36caa 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -196,7 +196,7 @@ rcvdistout (FILE *inb, char *form, char *addrs) switch (state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb)) { case FLD: case FLDPLUS: - i = fmt_addcomp(name, tmpbuf); + i = fmt_addcomptext(name, tmpbuf); if (i != -1) { char_read += msg_count; while (state == FLDPLUS) { -- 2.56.1 From a814e2957bf53b2ecef28593f325cd082122ba52 Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Mon, 19 Nov 2012 13:47:46 -0500 Subject: [PATCH 03/16] Change fmt_findcasecmp() to fmt_findcasecomp(). The new name is more consistent. --- h/fmt_scan.h | 2 +- sbr/fmt_compile.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/h/fmt_scan.h b/h/fmt_scan.h index a2bff891..8de6f23d 100644 --- a/h/fmt_scan.h +++ b/h/fmt_scan.h @@ -178,7 +178,7 @@ struct comp *fmt_findcomp(char *component); * Identical to fmd_findcomp(), but is case-INSENSITIVE. */ -struct comp *fmt_findcasecmp(char *component); +struct comp *fmt_findcasecomp(char *component); /* * Add a component entry to the component hash table diff --git a/sbr/fmt_compile.c b/sbr/fmt_compile.c index 148d35c7..57bf5167 100644 --- a/sbr/fmt_compile.c +++ b/sbr/fmt_compile.c @@ -877,7 +877,7 @@ fmt_findcomp(char *component) */ struct comp * -fmt_findcasecmp(char *component) +fmt_findcasecomp(char *component) { struct comp *cm; -- 2.56.1 From ef15ffef47e7fc7d5716ce1c2ebccef17ed6e10e Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Mon, 19 Nov 2012 13:48:16 -0500 Subject: [PATCH 04/16] Convert scan() to the new world format API. --- uip/scansbr.c | 81 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 29 deletions(-) diff --git a/uip/scansbr.c b/uip/scansbr.c index 480cab5b..d1868451 100644 --- a/uip/scansbr.c +++ b/uip/scansbr.c @@ -93,24 +93,52 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, umask(~m_gmprot()); /* Compile format string */ - ncomps = fmt_compile (nfs, &fmt) + 1; + ncomps = fmt_compile (nfs, &fmt, 1) + 1; - FINDCOMP(bodycomp, "body"); - FINDCOMP(datecomp, "date"); - FINDCOMP(cptr, "folder"); + bodycomp = fmt_findcomp("body"); + datecomp = fmt_findcomp("date"); + cptr = fmt_findcomp("folder"); if (cptr && folder) - cptr->c_text = folder; - FINDCOMP(cptr, "encrypted"); - if (!cptr) - if ((cptr = (struct comp *) calloc (1, sizeof(*cptr)))) { - cptr->c_name = "encrypted"; - cptr->c_next = wantcomp[i = CHASH (cptr->c_name)]; - wantcomp[i] = cptr; + cptr->c_text = getcpy(folder); + if (fmt_addcompentry("encrypted")) { ncomps++; } - FINDCOMP (cptr, "dtimenow"); + cptr = fmt_findcomp("dtimenow"); if (cptr) cptr->c_text = getcpy(dtimenow (0)); + + /* + * In other programs I got rid of this complicated buffer switching, + * but since scan reads lots of messages at once and this complicated + * memory management, I decided to keep it; otherwise there was + * the potential for a lot of malloc() and free()s, and I could + * see the malloc() pool really getting fragmented. Maybe it + * wouldn't be an issue in practice; perhaps this will get + * revisited someday. + * + * So, some notes for what's going on: + * + * nxtbuf is an array of pointers that contains malloc()'d buffers + * to hold our component text. used_buf is an array of struct comp + * pointers that holds pointers to component structures we found while + * processing a message. + * + * We read in the message with m_getfld(), using "tmpbuf" as our + * input buffer. tmpbuf is set at the start of message processing + * to the first buffer in our buffer pool (nxtbuf). + * + * Every time we find a component we care about, we set that component's + * text buffer to the current value of tmpbuf, and then switch tmpbuf + * to the next buffer in our pool. We also add that component to + * our used_buf pool. + * + * When we're done, we go back and zero out all of the component + * text buffer pointers that we saved in used_buf. + * + * Note that this means c_text memory is NOT owned by the fmt_module + * and it's our responsibility to free it. + */ + nxtbuf = compbuffers = (char **) calloc((size_t) ncomps, sizeof(char *)); if (nxtbuf == NULL) adios (NULL, "unable to allocate component buffers"); @@ -176,23 +204,18 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, * buffer as the component temp buffer (buffer switching * saves an extra copy of the component text). */ - if ((cptr = wantcomp[CHASH(name)])) { - do { - if (!mh_strcasecmp(name, cptr->c_name)) { - if (! cptr->c_text) { - cptr->c_text = tmpbuf; - for (cp = tmpbuf + strlen (tmpbuf) - 1; + if ((cptr = fmt_findcasecomp(name))) { + if (! cptr->c_text) { + cptr->c_text = tmpbuf; + for (cp = tmpbuf + strlen (tmpbuf) - 1; cp >= tmpbuf; cp--) - if (isspace (*cp)) - *cp = 0; - else - break; - *--savecomp = cptr; - tmpbuf = *nxtbuf++; - } - break; - } - } while ((cptr = cptr->c_next)); + if (isspace (*cp)) + *cp = 0; + else + break; + *--savecomp = cptr; + tmpbuf = *nxtbuf++; + } } while (state == FLDPLUS) { @@ -335,7 +358,7 @@ finished: if (noisy) fputs (scanl, stdout); - FINDCOMP (cptr, "encrypted"); + cptr = fmt_findcomp ("encrypted"); encrypted = cptr && cptr->c_text; /* return dynamically allocated buffers to pool */ -- 2.56.1 From 8366f135cfca005564388adb63d5c7a87c7634ea Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Mon, 19 Nov 2012 14:18:55 -0500 Subject: [PATCH 05/16] Whoops, with the new world order we need to make sure we allocate memory for all strings in format instructions. --- sbr/fmt_compile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbr/fmt_compile.c b/sbr/fmt_compile.c index 57bf5167..3a6202d4 100644 --- a/sbr/fmt_compile.c +++ b/sbr/fmt_compile.c @@ -264,7 +264,7 @@ static struct ftable functable[] = { } while (0) #define LV(type, value) do { NEW(type,0,0); fp->f_value = (value); } while (0) -#define LS(type, str) do { NEW(type,0,0); fp->f_text = (str); fp->f_flags |= FF_STRALLOC; } while (0) +#define LS(type, str) do { NEW(type,0,0); fp->f_text = getcpy(str); fp->f_flags |= FF_STRALLOC; } while (0) #define PUTCOMP(comp) do { NEW(FT_COMP,0,0); ADDC(comp); } while (0) #define PUTLIT(str) do { NEW(FT_LIT,0,0); fp->f_text = getcpy(str); fp->f_flags |= FF_STRALLOC; } while (0) -- 2.56.1 From 93228ecdb0d9fdbe3bcf579bda4d3339ebf9f717 Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Mon, 19 Nov 2012 14:19:30 -0500 Subject: [PATCH 06/16] Support for the new world format API for comp and forw. --- uip/comp.c | 12 ++++---- uip/forwsbr.c | 77 +++++++++++++++++++++------------------------------ 2 files changed, 37 insertions(+), 52 deletions(-) diff --git a/uip/comp.c b/uip/comp.c index f7a8f8f5..65b213ae 100644 --- a/uip/comp.c +++ b/uip/comp.c @@ -294,34 +294,34 @@ main (int argc, char **argv) cp = new_fs(form, NULL, NULL); format_len = strlen(cp); - fmt_compile(cp, &fmt); + fmt_compile(cp, &fmt, 1); /* * Set up any components that were fed to us on the command line */ if (from) { - FINDCOMP(cptr, "from"); + cptr = fmt_findcomp("from"); if (cptr) cptr->c_text = from; } if (to) { - FINDCOMP(cptr, "to"); + cptr = fmt_findcomp("to"); if (cptr) cptr->c_text = to; } if (cc) { - FINDCOMP(cptr, "cc"); + cptr = fmt_findcomp("cc"); if (cptr) cptr->c_text = cc; } if (fcc) { - FINDCOMP(cptr, "fcc"); + cptr = fmt_findcomp("fcc"); if (cptr) cptr->c_text = fcc; } if (subject) { - FINDCOMP(cptr, "subject"); + cptr = fmt_findcomp("subject"); if (cptr) cptr->c_text = subject; } diff --git a/uip/forwsbr.c b/uip/forwsbr.c index 9abf20de..355adff2 100644 --- a/uip/forwsbr.c +++ b/uip/forwsbr.c @@ -67,14 +67,14 @@ build_form (char *form, char *digest, int *dat, char *from, char *to, fmtsize = strlen (nfs) + 256; /* Compile format string */ - (void) fmt_compile (nfs, &fmt); + (void) fmt_compile (nfs, &fmt, 1); /* * Mark any components tagged as address components */ for (ap = addrcomps; *ap; ap++) { - FINDCOMP (cptr, *ap); + cptr = fmt_findcomp (*ap); if (cptr) cptr->c_type |= CT_ADDR; } @@ -96,35 +96,17 @@ build_form (char *form, char *digest, int *dat, char *from, char *to, * a copy. We don't do all of that weird buffer switching * that replout does. */ - if ((cptr = wantcomp[CHASH(name)])) - do { - if (mh_strcasecmp(name, cptr->c_name) == 0) { - char_read += msg_count; - if (! cptr->c_text) { - cptr->c_text = strdup(msgbuf); - } else { - i = strlen(cptr->c_text) - 1; - if (cptr->c_text[i] == '\n') { - if (cptr->c_type & CT_ADDR) { - cptr->c_text[i] = '\0'; - cptr->c_text = add(",\n\t", - cptr->c_text); - } else { - cptr->c_text = add ("\t", cptr->c_text); - } - } - cptr->c_text = add(msgbuf, cptr->c_text); - } - while (state == FLDPLUS) { - state = m_getfld(state, name, msgbuf, - sizeof(msgbuf), tmp); - cptr->c_text = add(msgbuf, cptr->c_text); - char_read += msg_count; - } - break; - } - } while ((cptr = cptr->c_next)); + i = fmt_addcomptext(name, msgbuf); + if (i != -1) { + char_read += msg_count; + while (state == FLDPLUS) { + state = m_getfld(state, name, msgbuf, + sizeof(msgbuf), tmp); + fmt_appendcomp(i, name, msgbuf); + char_read += msg_count; + } + } while (state == FLDPLUS) state = m_getfld(state, name, msgbuf, sizeof(msgbuf), tmp); break; @@ -143,44 +125,49 @@ build_form (char *form, char *digest, int *dat, char *from, char *to, /* * Override any components just in case they were included in the * input message. Also include command-line components given here + * + * With the memory rework I've changed things so we always get copies + * of these strings; I don't like the idea that the caller of this + * function has to know to pass in already-allocated memory (and that + * it will be free()'d by us). */ finished: - FINDCOMP (cptr, "digest"); + cptr = fmt_findcomp ("digest"); if (cptr) { COMPFREE(cptr); - cptr->c_text = digest; + cptr->c_text = getcpy(digest); } - FINDCOMP (cptr, "nmh-date"); + cptr = fmt_findcomp ("nmh-date"); if (cptr) { COMPFREE(cptr); cptr->c_text = getcpy(dtimenow (0)); } - FINDCOMP (cptr, "nmh-from"); + cptr = fmt_findcomp ("nmh-from"); if (cptr) { COMPFREE(cptr); - cptr->c_text = from; + cptr->c_text = getcpy(from); } - FINDCOMP (cptr, "nmh-to"); + cptr = fmt_findcomp ("nmh-to"); if (cptr) { COMPFREE(cptr); - cptr->c_text = to; + cptr->c_text = getcpy(to); } - FINDCOMP (cptr, "nmh-cc"); + cptr = fmt_findcomp ("nmh-cc"); if (cptr) { COMPFREE(cptr); - cptr->c_text = cc; + cptr->c_text = getcpy(cc); } - FINDCOMP (cptr, "nmh-subject"); + cptr = fmt_findcomp ("nmh-subject"); if (cptr) { COMPFREE(cptr); - cptr->c_text = subject; + cptr->c_text = getcpy(subject); } - FINDCOMP (cptr, "fcc"); + cptr = fmt_findcomp ("fcc"); if (cptr) { COMPFREE(cptr); - cptr->c_text = fcc; + cptr->c_text = getcpy(fcc); } cp = m_mktemp2(NULL, invo_name, NULL, &tmp); @@ -203,9 +190,7 @@ finished: * Free any component buffers that we allocated */ - for (i = 0; i < (sizeof(wantcomp) / sizeof(struct comp)); i++) - for (cptr = wantcomp[i]; cptr != NULL; cptr = cptr->c_next) - COMPFREE(cptr); + fmt_free(fmt, 1); return in; } -- 2.56.1 From babc387dc837745618b56c5330cb7002cd60b612 Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Mon, 19 Nov 2012 14:37:14 -0500 Subject: [PATCH 07/16] Convert repl to the new world format API. --- uip/replsbr.c | 103 ++++++++++++++++---------------------------------- 1 file changed, 32 insertions(+), 71 deletions(-) diff --git a/uip/replsbr.c b/uip/replsbr.c index f6ccd352..3dbc3031 100644 --- a/uip/replsbr.c +++ b/uip/replsbr.c @@ -36,14 +36,6 @@ static int nodupcheck = 0; /* If set, no check for duplicates */ */ #define SBUFSIZ 256 -static struct format *fmt; - -static int ncomps = 0; /* # of interesting components */ -static char **compbuffers = NULL; /* buffers for component text */ -static struct comp **used_buf = NULL; /* stack for comp that use buffers */ - -static int dat[5]; /* aux. data for format routine */ - static char *addrcomps[] = { "from", "sender", @@ -73,13 +65,14 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen, { register int state, i; register struct comp *cptr; - register char *tmpbuf; - register char **nxtbuf; + char tmpbuf[SBUFSIZ]; + struct format *fmt; register char **ap; - register struct comp **savecomp; int char_read = 0, format_len, mask; char name[NAMESZ], *scanl; unsigned char *cp; + static int dat[5]; /* aux. data for format routine */ + FILE *out; NMH_UNUSED (msg); @@ -94,50 +87,41 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen, format_len = strlen (cp); /* compile format string */ - ncomps = fmt_compile (cp, &fmt) + 1; - - if (!(nxtbuf = compbuffers = (char **) - calloc((size_t) ncomps, sizeof(char *)))) - adios (NULL, "unable to allocate component buffers"); - if (!(savecomp = used_buf = (struct comp **) - calloc((size_t) (ncomps+1), sizeof(struct comp *)))) - adios (NULL, "unable to allocate component buffer stack"); - savecomp += ncomps + 1; - *--savecomp = NULL; /* point at zero'd end minus 1 */ - - for (i = ncomps; i--; ) - *nxtbuf++ = mh_xmalloc(SBUFSIZ); - - nxtbuf = compbuffers; /* point at start */ - tmpbuf = *nxtbuf++; + fmt_compile (cp, &fmt, 1); for (ap = addrcomps; *ap; ap++) { - FINDCOMP (cptr, *ap); + cptr = fmt_findcomp (*ap); if (cptr) cptr->c_type |= CT_ADDR; } /* * ignore any components killed by command line switches + * + * This prevents the component from being found via fmt_findcomp(), + * which makes sure no text gets added to it when the message is processed. + * + * getcpy(NULL) returns a malloc'd zero-length string, so it can safely + * be free()'d later. */ if (!ccto) { - FINDCOMP (cptr, "to"); + cptr = fmt_findcomp ("to"); if (cptr) - cptr->c_name = ""; + cptr->c_name = getcpy(NULL); } if (!cccc) { - FINDCOMP (cptr, "cc"); + cptr = fmt_findcomp("cc"); if (cptr) - cptr->c_name = ""; + cptr->c_name = getcpy(NULL); } /* set up the "fcc" pseudo-component */ if (fcc) { - FINDCOMP (cptr, "fcc"); + cptr = fmt_findcomp ("fcc"); if (cptr) cptr->c_text = getcpy (fcc); } if ((cp = getenv("USER"))) { - FINDCOMP (cptr, "user"); + cptr = fmt_findcomp ("user"); if (cptr) cptr->c_text = getcpy(cp); } @@ -148,7 +132,7 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen, * pick any interesting stuff out of msg "inb" */ for (state = FLD;;) { - state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb); + state = m_getfld (state, name, tmpbuf, sizeof(tmpbuf), inb); switch (state) { case FLD: case FLDPLUS: @@ -158,35 +142,17 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen, * buffer as the component temp buffer (buffer switching * saves an extra copy of the component text). */ - if ((cptr = wantcomp[CHASH(name)])) - do { - if (!mh_strcasecmp(name, cptr->c_name)) { - char_read += msg_count; - if (! cptr->c_text) { - cptr->c_text = tmpbuf; - *--savecomp = cptr; - tmpbuf = *nxtbuf++; - } else { - i = strlen (cp = cptr->c_text) - 1; - if (cp[i] == '\n') { - if (cptr->c_type & CT_ADDR) { - cp[i] = '\0'; - cp = add (",\n\t", cp); - } else { - cp = add ("\t", cp); - } - } - cptr->c_text = add (tmpbuf, cp); - } - while (state == FLDPLUS) { - state = m_getfld (state, name, tmpbuf, - SBUFSIZ, inb); - cptr->c_text = add (tmpbuf, cptr->c_text); - char_read += msg_count; - } - break; - } - } while ((cptr = cptr->c_next)); + + i = fmt_addcomptext(name, tmpbuf); + if (i != -1) { + char_read += msg_count; + while (state == FLDPLUS) { + state = m_getfld(state, name, tmpbuf, + sizeof(tmpbuf), inb); + fmt_appendcomp(i, name, tmpbuf); + char_read += msg_count; + } + } while (state == FLDPLUS) state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb); @@ -211,7 +177,7 @@ finished: /* * if there's a "Subject" component, strip any "Re:"s off it */ - FINDCOMP (cptr, "subject") + cptr = fmt_findcomp ("subject"); if (cptr && (cp = cptr->c_text)) { register char *sp = cp; @@ -266,12 +232,7 @@ finished: /* return dynamically allocated buffers */ free (scanl); - for (nxtbuf = compbuffers, i = ncomps; (cptr = *savecomp++); nxtbuf++, i--) - free (cptr->c_text); /* if not nxtbuf, nxtbuf already freed */ - while ( i-- > 0) - free (*nxtbuf++); /* free unused nxtbufs */ - free ((char *) compbuffers); - free ((char *) used_buf); + fmt_free(fmt, 1); } static char *buf; /* our current working buffer */ -- 2.56.1 From c616181932ec412f09430dba5a90dbf37ef79ba8 Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Mon, 19 Nov 2012 15:29:01 -0500 Subject: [PATCH 08/16] Make sure we strip off a newline from components we want to display (we were stripping off a newline from the wrong copy of the component). --- uip/mhlsbr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index 2d101d11..45d99b03 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -1168,7 +1168,7 @@ mcomp_format (struct mcomp *c1, struct mcomp *c2) if (!(c1->c_flags & ADDRFMT)) { if (c1->c_c_text) - c1->c_c_text->c_text = getcpy (ap); + c1->c_c_text->c_text = ap; if ((cp = strrchr(ap, '\n'))) /* drop ending newline */ if (!cp[1]) *cp = 0; @@ -1177,7 +1177,7 @@ mcomp_format (struct mcomp *c1, struct mcomp *c2) /* Don't need to append a newline, dctime() already did */ c2->c_text = getcpy (buffer); - free (ap); + /* ap is now owned by the component struct, so do NOT free it here */ return; } -- 2.56.1 From b5f46f4ba364af010a7ef5afb20b667fcbe9b136 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Tue, 20 Nov 2012 00:47:24 +0100 Subject: [PATCH 09/16] Yozo TODA: fix for mhshow-charset- directives in .mh_profile being broken --- h/mhparse.h | 4 +--- uip/mhbuildsbr.c | 3 +-- uip/mhparse.c | 16 +++------------- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/h/mhparse.h b/h/mhparse.h index 48f221fc..5a5a2199 100644 --- a/h/mhparse.h +++ b/h/mhparse.h @@ -162,10 +162,8 @@ struct Content { #define TEXT_ENRICHED 0x03 /* Flags for character sets */ -#define CHARSET_UNKNOWN 0x00 +#define CHARSET_SPECIFIED 0x00 #define CHARSET_UNSPECIFIED 0x01 /* only needed when building drafts */ -#define CHARSET_USASCII 0x01 -#define CHARSET_LATIN 0x02 /* Structure for text content */ struct text { diff --git a/uip/mhbuildsbr.c b/uip/mhbuildsbr.c index 0ebdaba6..6a7443e9 100644 --- a/uip/mhbuildsbr.c +++ b/uip/mhbuildsbr.c @@ -1358,12 +1358,11 @@ scan_content (CT ct) continue; if (contains8bit) { - t->tx_charset = CHARSET_UNKNOWN; *ap = concat ("charset=", write_charset_8bit(), NULL); } else { - t->tx_charset = CHARSET_USASCII; *ap = add ("charset=us-ascii", NULL); } + t->tx_charset = CHARSET_SPECIFIED; cp = strchr(*ap++, '='); *ap = NULL; diff --git a/uip/mhparse.c b/uip/mhparse.c index 25bbad75..8cfa8998 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -46,11 +46,7 @@ struct k2v SubText[] = { { NULL, TEXT_UNKNOWN } /* this one must be last! */ }; -struct k2v Charset[] = { - { "us-ascii", CHARSET_USASCII }, - { "iso-8859-1", CHARSET_LATIN }, - { NULL, CHARSET_UNKNOWN } /* this one must be last! */ -}; +/* Charset[] removed -- yozo. Mon Oct 8 01:03:41 JST 2012 */ /* * Structures for MULTIPART messages @@ -1077,14 +1073,8 @@ InitText (CT ct) /* check if content specified a character set */ if (*ap) { - /* match character set or set to CHARSET_UNKNOWN */ - for (kv = Charset; kv->kv_key; kv++) { - if (!mh_strcasecmp (*ep, kv->kv_key)) { - chset = *ep; - break; - } - } - t->tx_charset = kv->kv_value; + chset = *ep; + t->tx_charset = CHARSET_SPECIFIED; } else { t->tx_charset = CHARSET_UNSPECIFIED; } -- 2.56.1 From a97c3e637eaf2e2f4ecd8cb93b11795afb980988 Mon Sep 17 00:00:00 2001 From: David Levine Date: Mon, 19 Nov 2012 19:19:59 -0600 Subject: [PATCH 10/16] Fixed a couple of signed-unsigned comparisons. --- sbr/fmt_compile.c | 2 +- uip/forwsbr.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sbr/fmt_compile.c b/sbr/fmt_compile.c index 3a6202d4..01473342 100644 --- a/sbr/fmt_compile.c +++ b/sbr/fmt_compile.c @@ -981,7 +981,7 @@ fmt_appendcomp(int bucket, char *component, char *text) static void free_comptable(void) { - int i; + unsigned int i; struct comp *cm, *cm2; for (i = 0; i < sizeof(wantcomp)/sizeof(wantcomp[0]); i++) { diff --git a/uip/forwsbr.c b/uip/forwsbr.c index 355adff2..86255857 100644 --- a/uip/forwsbr.c +++ b/uip/forwsbr.c @@ -47,7 +47,7 @@ build_form (char *form, char *digest, int *dat, char *from, char *to, { int in; int fmtsize, state, char_read = 0; - unsigned i; + int i; register char *nfs; char *line, tmpfil[BUFSIZ], name[NAMESZ], **ap; FILE *tmp; -- 2.56.1 From b15f35a73878825d1824a710982d6769ece9b6cb Mon Sep 17 00:00:00 2001 From: David Levine Date: Fri, 23 Nov 2012 09:25:15 -0600 Subject: [PATCH 11/16] Added Message-Id to messages in test suite. --- test/anno/test-anno | 2 +- test/common.sh.in | 1 + test/dist/test-dist | 16 ++++++++++++++++ test/mhbuild/test-forw | 4 ++++ test/rcv/test-rcvdist | 2 ++ test/repl/test-repl | 8 ++++++++ 6 files changed, 32 insertions(+), 1 deletion(-) diff --git a/test/anno/test-anno b/test/anno/test-anno index e96c6062..bdf93287 100755 --- a/test/anno/test-anno +++ b/test/anno/test-anno @@ -122,7 +122,7 @@ check "$expected" "$actual" rm "${MH_TEST_DIR}/Mail/draft" # check -append -sed -e '4a\ +sed -e '5a\ Nmh-test:' "${MH_TEST_DIR}/Mail/inbox/1" >"$expected" anno 1 -component Nmh-test -append sed -e 's/^Nmh-test:.*/Nmh-test:/' "${MH_TEST_DIR}/Mail/inbox/1" >"$actual" diff --git a/test/common.sh.in b/test/common.sh.in index a25409b8..dd68f774 100644 --- a/test/common.sh.in +++ b/test/common.sh.in @@ -207,6 +207,7 @@ EOF From: Test$i To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: $i@test.nmh Subject: Testing message $i This is message number $i diff --git a/test/dist/test-dist b/test/dist/test-dist index 769406cb..c96ed1af 100755 --- a/test/dist/test-dist +++ b/test/dist/test-dist @@ -95,6 +95,7 @@ cat >"$expected" < To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 1@test.nmh Subject: Testing message 1 Resent-From: ${localmbox} Resent-To: somebody@example.com @@ -112,6 +113,7 @@ cat >"$expected" < To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 1@test.nmh Subject: Testing message 1 Resent-From: ${localmbox} Resent-To: somebody@example.com @@ -132,6 +134,7 @@ cat >"$expected" < To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 1@test.nmh Subject: Testing message 1 Resent-From: me@example.com Resent-To: you@example.com @@ -149,6 +152,7 @@ cat >"$expected" < To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 2@test.nmh Subject: Testing message 2 Resent-From: ${localmbox} Resent-To: somebody@example.com @@ -165,6 +169,7 @@ Resent: somebody@example.com From: Test2 To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 2@test.nmh Subject: Testing message 2 This is message number 2 @@ -194,6 +199,7 @@ cat >"$expected" < To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 1@test.nmh Subject: Testing message 1 Resent-From: ${localmbox} Resent-To: somebody@example.com @@ -208,6 +214,7 @@ cat >"$expected" < To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 1@test.nmh Subject: Testing message 1 This is message number 1 @@ -225,6 +232,7 @@ if [ $hard_links_supported -eq 1 ]; then From: Test8 To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 8@test.nmh Subject: Testing message 8 Resent-From: ${localmbox} Resent-To: somebody@example.com @@ -244,6 +252,7 @@ EOF From: Test8 To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 8@test.nmh Subject: Testing message 8 Resent-From: ${localmbox} Resent-To: somebody@example.com @@ -260,6 +269,7 @@ cat >"$expected" < To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 3@test.nmh Subject: Testing message 3 Resent-From: ${localmbox} Resent-To: somebody@example.com @@ -275,6 +285,7 @@ cat >"$expected" < To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 3@test.nmh Subject: Testing message 3 Resent-From: ${localmbox} Resent-To: somebody@example.com @@ -291,6 +302,7 @@ cat >"$expected" < To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 3@test.nmh Subject: Testing message 3 Resent-From: ${localmbox} Resent-To: somebody@example.com @@ -311,6 +323,7 @@ cat >"$expected" < To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 1@test.nmh Subject: Testing message 1 Resent-From: me@example.com Resent-To: somebody@example.com @@ -326,6 +339,7 @@ cat >"$expected" < To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 1@test.nmh Subject: Testing message 1 Resent-From: ${localmbox} Resent-To: somebody@example.com @@ -342,6 +356,7 @@ cat >"$expected" < To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 1@test.nmh Subject: Testing message 1 Resent-From: ${localmbox} Resent-To: somebody@example.com @@ -357,6 +372,7 @@ cat >"$expected" < To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 1@test.nmh Subject: Testing message 1 Resent-From: ${localmbox} Resent-To: somebody@example.com diff --git a/test/mhbuild/test-forw b/test/mhbuild/test-forw index 21677380..7326b51f 100755 --- a/test/mhbuild/test-forw +++ b/test/mhbuild/test-forw @@ -47,6 +47,7 @@ Content-Type: message/rfc822 From: Test1 To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 1@test.nmh Subject: Testing message 1 This is message number 1 @@ -57,6 +58,7 @@ Content-Type: message/rfc822 From: Test2 To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 2@test.nmh Subject: Testing message 2 This is message number 2 @@ -84,6 +86,7 @@ Content-Description: forwarded messages From: Test1 To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 1@test.nmh Subject: Testing message 1 This is message number 1 @@ -93,6 +96,7 @@ This is message number 1 From: Test2 To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 2@test.nmh Subject: Testing message 2 This is message number 2 diff --git a/test/rcv/test-rcvdist b/test/rcv/test-rcvdist index 8dea84dd..311cdc9c 100755 --- a/test/rcv/test-rcvdist +++ b/test/rcv/test-rcvdist @@ -80,6 +80,7 @@ cat > "$expected" < To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 1@test.nmh Subject: Testing message 1 Resent-From: `${MH_LIB_DIR}/ap -format '%(localmbox)' 0` Resent-To: recipient@example.com @@ -95,6 +96,7 @@ cat > "$expected" < To: Some User Date: Fri, 29 Sep 2006 00:00:00 +Message-Id: 2@test.nmh Subject: Testing message 2 Resent-To: recipient@example.com Resent-From: Some User diff --git a/test/repl/test-repl b/test/repl/test-repl index 0b5b4839..29383f96 100755 --- a/test/repl/test-repl +++ b/test/repl/test-repl @@ -81,6 +81,8 @@ To: Test1 cc: mymailbox@localhost Fcc: +outbox Subject: Re: Testing message 1 +In-reply-to: 1@test.nmh +References: 1@test.nmh Comments: In-reply-to Test1 message dated "Fri, 29 Sep 2006 00:00:00." -------- @@ -96,6 +98,8 @@ To: Test1 cc: Fcc: +outbox Subject: Re: Testing message 1 +In-reply-to: 1@test.nmh +References: 1@test.nmh Comments: In-reply-to Test1 message dated "Fri, 29 Sep 2006 00:00:00." -------- @@ -114,6 +118,8 @@ To: Test1 cc: mymailbox@localhost Fcc: +outbox Subject: Re: Testing message 1 +In-reply-to: 1@test.nmh +References: 1@test.nmh Comments: In-reply-to Test1 message dated "Fri, 29 Sep 2006 00:00:00." -------- @@ -131,6 +137,8 @@ To: Test1 cc: Fcc: +outbox Subject: Re: Testing message 1 +In-reply-to: 1@test.nmh +References: 1@test.nmh Comments: In-reply-to Test1 message dated "Fri, 29 Sep 2006 00:00:00." -------- -- 2.56.1 From a47dfadde7d7df81cd47856379957866ae88986b Mon Sep 17 00:00:00 2001 From: David Levine Date: Fri, 23 Nov 2012 09:26:21 -0600 Subject: [PATCH 12/16] slocal used to support two different formats for three of its arguments: [address info sender] [-addr address] [-info data] [-sender sender] But it hasn't properly supported the first form since at least April 1999. So, I removed that first form from the man page and the broken support from the code. Score another for the test suite! --- man/slocal.man | 5 ++--- uip/slocal.c | 19 +++---------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/man/slocal.man b/man/slocal.man index d0b24e4c..10851e40 100644 --- a/man/slocal.man +++ b/man/slocal.man @@ -1,4 +1,4 @@ -.TH SLOCAL %manext1% "November 9, 2012" "%nmhversion%" +.TH SLOCAL %manext1% "November 23, 2012" "%nmhversion%" .\" .\" %nmhwarning% .\" @@ -8,7 +8,6 @@ slocal \- asynchronously filter and deliver new mail .HP 5 .na .B %libdir%/slocal -[address\ info\ sender] .RB [ \-addr .IR address ] .RB [ \-info @@ -59,7 +58,7 @@ Under .BR sendmail , the sender will obtained from the UUCP \*(lqFrom:\*(rq line, if present. The user may override these -values with command line arguments, or arguments to the +values with the .B \-addr and .B \-sender diff --git a/uip/slocal.c b/uip/slocal.c index 80620a7a..a7283bf8 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -222,8 +222,7 @@ main (int argc, char **argv) adios (NULL, "-%s unknown", cp); case HELPSW: - snprintf (buf, sizeof(buf), - "%s [switches] [address info sender]", invo_name); + snprintf (buf, sizeof(buf), "%s [switches]", invo_name); print_help (buf, switches, 0); done (0); case VERSIONSW: @@ -284,20 +283,8 @@ main (int argc, char **argv) debug++; continue; } - } - - switch (argp - (argv + 1)) { - case 1: - addr = cp; - break; - - case 2: - info = cp; - break; - - case 3: - sender = cp; - break; + } else { + adios (NULL, "only switch arguments are supported"); } } -- 2.56.1 From eba408368603a3afe170ef61a334c3a479ea5a29 Mon Sep 17 00:00:00 2001 From: David Levine Date: Fri, 23 Nov 2012 09:27:44 -0600 Subject: [PATCH 13/16] Added test-slocal. --- Makefile.am | 1 + test/slocal/test-slocal | 195 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100755 test/slocal/test-slocal diff --git a/Makefile.am b/Makefile.am index e6a6256b..40bae41e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -75,6 +75,7 @@ TESTS = test/ali/test-ali test/anno/test-anno \ test/repl/test-multicomp test/repl/test-repl \ test/scan/test-scan test/scan/test-scan-multibyte \ test/sequences/test-flist test/sequences/test-mark \ + test/slocal/test-slocal \ test/whatnow/test-attach-detach test/whatnow/test-cd \ test/whatnow/test-ls test/whom/test-whom \ test/cleanup ## The "cleanup" test should always be last. diff --git a/test/slocal/test-slocal b/test/slocal/test-slocal new file mode 100755 index 00000000..eafe3139 --- /dev/null +++ b/test/slocal/test-slocal @@ -0,0 +1,195 @@ +#!/bin/sh +###################################################### +# +# Test slocal +# +###################################################### + +set -e + +if test -z "$MH_OBJ_DIR"; then + srcdir=`dirname $0`/../.. + MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR +fi + +. "$MH_OBJ_DIR/test/common.sh" + +setup_test + +# Use proper program, maybe not the first one on PATH. +slocal="$MH_LIB_DIR"/slocal + +expected="$MH_TEST_DIR"/$$.expected +actual="$MH_TEST_DIR"/$$.actual +actual2="$MH_TEST_DIR"/$$.actual2 +md="$MH_TEST_DIR"/Mail/maildelivery + +# check -help +cat >"$expected" <"$actual" 2>&1 +check "$expected" "$actual" + +# check -version +case `$slocal -vers` in + slocal\ --*) ;; + * ) printf '%s: slocal -vers generated unexpected output\n' "$0" >&2 + failed=`expr ${failed:-0} + 1`;; +esac + +# check unknown switch +run_test "$slocal -nonexistent" 'slocal: -nonexistent unknown' + +# check non-switch argument +run_test "$slocal nonexistent" 'slocal: only switch arguments are supported' + +# check basic operation +# Can't use rcvstore because slocal wipes out the environment. +# So, it would put the message in the user's inbox, not the +# test inbox. slocal also freopens stdout and stderr to +# /dev/null, so we can't view them to verify simulated delivery. +cat >$md <"$actual2" 2>&1 +run_test "grep ^retrieving $actual2" 'retrieving message from stdin' + +# check -verbose +$slocal -verbose -maildelivery $md <"$MH_TEST_DIR"/Mail/inbox/1 >"$actual2" 2>&1 +run_test "grep ^delivering $actual2" 'delivering to pipe "tee", success.' + +# check -noverbose +$slocal -verbose -noverbose -maildelivery $md <"$MH_TEST_DIR"/Mail/inbox/1 \ + >"$actual2" 2>&1 +run_test "grep ^delivering $actual2" '' +rm -f "$actual2" + +# check match of From +cat >$md <$md <$md <$md <$md <$md <$md <$md <$md <$md < Date: Fri, 23 Nov 2012 19:58:34 -0500 Subject: [PATCH 14/16] Document the -port switch to inc. Also, fix the -port switch to inc so it actually works. --- man/inc.man | 7 ++++++- uip/inc.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/man/inc.man b/man/inc.man index 4c471fcb..5156db87 100644 --- a/man/inc.man +++ b/man/inc.man @@ -25,6 +25,8 @@ inc \- incorporate new mail .IR columns ] .RB [ \-host .IR hostname ] +.RB [ \-port +.IR portname/number ] .RB [ \-user .IR username ] .RB [ \-pack @@ -198,7 +200,10 @@ will query this POP service host for mail to incorporate. If is set and .B \-host is specified as well, the commandline switch will override -the environment variable. +the environment variable. The +.B \-port +switch specifies the port name or number used to connect to the POP +server. If unspecified the default is \*(lqpop3\*(rq. .PP The default is for .B inc diff --git a/uip/inc.c b/uip/inc.c index 72c79b70..12da6ba1 100644 --- a/uip/inc.c +++ b/uip/inc.c @@ -335,7 +335,7 @@ main (int argc, char **argv) continue; case PORTSW: - if (!(host = *argp++) || *port == '-') + if (!(port = *argp++) || *port == '-') adios (NULL, "missing argument to %s", argp[-2]); continue; -- 2.56.1 From 2ffe7ca30b85d542d02f74c39785319bcb6ad005 Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Fri, 23 Nov 2012 19:59:37 -0500 Subject: [PATCH 15/16] Document changes to inc. --- docs/pending-release-notes | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/pending-release-notes b/docs/pending-release-notes index fc7728b2..2f5efdba 100644 --- a/docs/pending-release-notes +++ b/docs/pending-release-notes @@ -29,6 +29,8 @@ NEW FEATURES - $PAGER overrides the compiled-in default pager command. - Added etc/scan.highlighted format file, as an example of how to highlight/colorize the output of scan(1). +- inc(1) now supports a -port switch to specify the port used by the + POP server. ---------------------------- -- 2.56.1 From 39a6bb2ad6c87e55d25115eb7d8e9a4043fec2e1 Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Fri, 23 Nov 2012 20:54:28 -0500 Subject: [PATCH 16/16] Fix the race condition with fakesmtp so it works without needing retries. --- test/fakesmtp.c | 32 ++++++++++++++++++++++++++++++- test/mhmail/test-mhmail | 36 ++++++++--------------------------- test/post/test-post-common.sh | 24 +++-------------------- 3 files changed, 42 insertions(+), 50 deletions(-) diff --git a/test/fakesmtp.c b/test/fakesmtp.c index 05be6dea..fbfe0442 100644 --- a/test/fakesmtp.c +++ b/test/fakesmtp.c @@ -34,6 +34,7 @@ main(int argc, char *argv[]) struct addrinfo hints, *res; int rc, l, conn, on, datamode; FILE *f, *pid; + pid_t child; fd_set readfd; struct stat st; struct timeval tv; @@ -118,6 +119,32 @@ main(int argc, char *argv[]) exit(1); } + /* + * Now we fork() and print out the process ID of our child + * for scripts to use. Once we do that, then exit. + */ + + child = fork(); + + switch (child) { + case -1: + fprintf(stderr, "Unable to fork child: %s\n", strerror(errno)); + exit(1); + break; + case 0: + /* + * Close stdin & stdout, otherwise people can + * think we're still doing stuff. For now leave stderr + * open. + */ + fclose(stdin); + fclose(stdout); + break; + default: + printf("%ld\n", (long) child); + exit(0); + } + /* * Now that our socket & files are set up, wait 30 seconds for * a connection. If there isn't one, then exit. @@ -202,6 +229,8 @@ main(int argc, char *argv[]) */ if (strcmp(line, "QUIT") == 0) { + fclose(f); + f = NULL; putsmtp(conn, "221 Later alligator!"); close(conn); break; @@ -213,7 +242,8 @@ main(int argc, char *argv[]) } } - fclose(f); + if (f) + fclose(f); exit(0); } diff --git a/test/mhmail/test-mhmail b/test/mhmail/test-mhmail index fa905866..37452073 100755 --- a/test/mhmail/test-mhmail +++ b/test/mhmail/test-mhmail @@ -21,36 +21,16 @@ fi # $4 contains the message body. test_mhmail () { - "${MH_OBJ_DIR}/test/fakesmtp" "$actual" $localport & - pid="$!" - - # The server doesn't always come up fast enough, so sleep and - # retry a few times if it fails... - status=1 - for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do - if [ $3 = '|' ]; then - if printf '%s' "$4" | mhmail recipient@example.com $2 \ - -server 127.0.0.1 -port $localport; then - status=0 - break - fi - else - if mhmail recipient@example.com $2 -body "$4" \ - -server 127.0.0.1 -port $localport; then - status=0 - break - fi - fi - sleep 2 - done - if [ $status -ne 0 ]; then - printf '%s: mhmail failed, was fakesmtp given enough time to start?\n' \ - "$0" >&2 - exit 1 + pid=`"${MH_OBJ_DIR}/test/fakesmtp" "$actual" $localport` + + if [ $3 = '|' ]; then + printf '%s' "$4" | mhmail recipient@example.com $2 \ + -server 127.0.0.1 -port $localport + else + mhmail recipient@example.com $2 -body "$4" \ + -server 127.0.0.1 -port $localport fi - wait ${pid} - # # 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-post-common.sh b/test/post/test-post-common.sh index 4535ff89..3b1a3d0b 100755 --- a/test/post/test-post-common.sh +++ b/test/post/test-post-common.sh @@ -26,27 +26,9 @@ echo "clientname: nosuchhost.example.com" >> ${MHMTSCONF} # $3: optional switches for send test_post () -{ "${MH_OBJ_DIR}/test/fakesmtp" "$1" $localport & - pid="$!" - - # The server doesn't always come up fast enough, so sleep and - # retry a few times if it fails... - status=1 - for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do - if send -draft -server 127.0.0.1 -port $localport $3 - then - status=0 - break - fi - sleep 2 - done - if [ $status -ne 0 ]; then - printf '%s: send failed, was fakesmtp given enough time to start?\n' \ - "$0" >&2 - exit 1 - fi - - wait ${pid} +{ pid=`"${MH_OBJ_DIR}/test/fakesmtp" "$1" $localport` + + send -draft -server 127.0.0.1 -port $localport $3 || exit 1 # # It's hard to calculate the exact Date: header post is going to -- 2.56.1