Merge branch 'm_getfld2-meillo' into master
authorPhilipp Takacs <philipp@bureaucracy.de>
Fri, 22 Apr 2016 22:56:56 +0000 (00:56 +0200)
committerPhilipp Takacs <philipp@bureaucracy.de>
Fri, 22 Apr 2016 22:56:56 +0000 (00:56 +0200)
20 files changed:
1  2 
h/mh.h
h/prototypes.h
sbr/Makefile.in
sbr/readconfig.c
sbr/seq_read.c
uip/inc.c
uip/mhbuild.c
uip/mhl.c
uip/mhparse.c
uip/new.c
uip/pick.c
uip/rcvdist.c
uip/rcvstore.c
uip/repl.c
uip/scan.c
uip/scansbr.c
uip/slocal.c
uip/sortm.c
uip/spost.c
uip/whom.c

diff --cc h/mh.h
Simple merge
diff --cc h/prototypes.h
Simple merge
diff --cc sbr/Makefile.in
@@@ -54,10 -54,10 +54,10 @@@ SRCS = addrsbr.c ambigsw.c brkstring.
        error.c execprog.c ext_hook.c folder_addmsg.c folder_delmsgs.c  \
        folder_free.c folder_read.c  \
        folder_realloc.c gans.c getans.c getanswer.c  \
 -      getarguments.c getcpy.c \
 +      getarguments.c \
        fmt_addr.c fmt_compile.c fmt_new.c fmt_rfc2047.c  \
        fmt_scan.c lock_file.c m_atoi.c \
-       m_convert.c m_draft.c m_getfld.c m_gmprot.c  \
+       m_convert.c m_draft.c m_getfld2.c m_gmprot.c  \
        m_name.c \
        makedir.c mts.c norm_charmap.c  \
        path.c pidwait.c pidstatus.c  \
@@@ -47,27 -46,14 +46,14 @@@ readconfig(struct node **npp, FILE *ib
                return;
        }
  
-       for (state = FLD;;) {
-               switch (state = m_getfld(state, name, field, sizeof(field),
-                               ib)) {
-               case FLD:
-               case FLDPLUS:
+       for (state = FLD2;;) {
+               switch (state = m_getfld2(state, &f, ib)) {
+               case FLD2:
 -                      np = (struct node *) mh_xmalloc(sizeof(*np));
 +                      np = mh_xcalloc(1, sizeof(*np));
                        *npp = np;
                        *(npp = &np->n_next) = NULL;
-                       np->n_name = mh_xstrdup(name);
-                       if (state == FLDPLUS) {
-                               cp = mh_xstrdup(field);
-                               while (state == FLDPLUS) {
-                                       state = m_getfld(state, name, field,
-                                                       sizeof(field), ib);
-                                       cp = add(field, cp);
-                               }
-                               np->n_field = trimcpy(cp);
-                               mh_free0(&cp);
-                       } else {
-                               np->n_field = trimcpy(field);
-                       }
 -                      np->n_name = getcpy(f.name);
++                      np->n_name = mh_xstrdup(f.name);
+                       np->n_field = trimcpy(f.value);
                        np->n_context = ctx;
  
                        /*
diff --cc sbr/seq_read.c
@@@ -74,31 -74,18 +74,18 @@@ seq_public(struct msgs *mp
                return;
  
        /* Use m_getfld to scan sequence file */
-       for (state = FLD;;) {
-               switch (state = m_getfld(state, name, field, sizeof(field),
-                               fp)) {
-               case FLD:
-               case FLDPLUS:
-                       if (state == FLDPLUS) {
-                               cp = mh_xstrdup(field);
-                               while (state == FLDPLUS) {
-                                       state = m_getfld(state, name, field,
-                                                       sizeof(field), fp);
-                                       cp = add(field, cp);
-                               }
-                               seq_init(mp, mh_xstrdup(name), trimcpy(cp));
-                               mh_free0(&cp);
-                       } else {
-                               seq_init(mp, mh_xstrdup(name), trimcpy(field));
-                       }
+       for (state = FLD2;;) {
+               switch (state = m_getfld2(state, &f, fp)) {
+               case FLD2:
 -                      seq_init(mp, getcpy(f.name), trimcpy(f.value));
++                      seq_init(mp, mh_xstrdup(f.name), trimcpy(f.value));
                        continue;
  
-               case BODY:
+               case BODY2:
                        adios(EX_CONFIG, NULL, "no blank lines are permitted in %s",
                                        seqfile);
-                       /* fall */
+                       /* FALL */
  
-               case FILEEOF:
+               case FILEEOF2:
                        break;
  
                default:
diff --cc uip/inc.c
+++ b/uip/inc.c
@@@ -431,7 -444,8 +444,8 @@@ main(int argc, char **argv
                */
                break;
        }
+ giveup:;
 -      free(maildir_copy);
 +      mh_free0(&maildir_copy);
  
        if (incerr < 0) {  /* error */
                if (locked) {
diff --cc uip/mhbuild.c
@@@ -369,19 -370,8 +370,8 @@@ build_mime(char *infile
                                continue;
                        }
  
-                       /* get copies of the buffers */
-                       np = mh_xstrdup(name);
-                       vp = mh_xstrdup(buf);
-                       /* if necessary, get rest of field */
-                       while (state == FLDPLUS) {
-                               state = m_getfld(state, name, buf,
-                                               sizeof(buf), in);
-                               vp = add(buf, vp);  /* add to prev value */
-                       }
-                       /* Now add the header data to the list */
-                       add_header(ct, np, vp);
+                       /* add the header data to the list */
 -                      add_header(ct, getcpy(f.name), getcpy(f.value));
++                      add_header(ct, mh_xstrdup(f.name), mh_xstrdup(f.value));
  
                        continue;
  
        }
        ct->c_type = CT_MULTIPART;
        ct->c_subtype = MULTI_MIXED;
 -      ct->c_file = getcpy(infile);
 +      ct->c_file = mh_xstrdup(infile);
  
-       m = mh_xcalloc(1, sizeof(*m));
+       m = (struct multipart *) mh_xcalloc(1, sizeof(*m));
        ct->c_ctparams = (void *) m;
        pp = &m->mp_parts;
  
diff --cc uip/mhl.c
+++ b/uip/mhl.c
@@@ -662,32 -661,39 +660,37 @@@ mhlfile(FILE *fp, char *mname, int ofil
                                        holder.c_text = concat("(Message ",
                                                        mname, ")\n", NULL);
                                        putcomp(c1, &holder, ONECOMP);
 -                                      free(holder.c_text);
 -                                      holder.c_text = NULL;
 +                                      mh_free0(&(holder.c_text));
                                        continue;
                                }
-                               if (!mh_strcasecmp(c1->c_name, "extras")) {
-                                       for (c2 = msghd; c2; c2 = c2->c_next)
-                                               if (c2->c_flags & EXTRA)
+                               if (mh_strcasecmp(c1->c_name, "extras")==0) {
+                                       for (c2 = msghd; c2; c2 = c2->c_next) {
+                                               if (c2->c_flags & EXTRA) {
                                                        putcomp(c1, c2, TWOCOMP);
+                                               }
+                                       }
                                        continue;
                                }
-                               if (dobody && !mh_strcasecmp(c1->c_name, "body")) {
-                                       holder.c_text = mh_xcalloc(sizeof(buf), sizeof(char));
-                                       strncpy(holder.c_text, buf, sizeof(buf));
-                                       while (state == BODY) {
+                               if (dobody && mh_strcasecmp(c1->c_name, "body")==0) {
 -                                      holder.c_text = getcpy(f.value);
++                                      holder.c_text = mh_xstrdup(f.value);
+                                       while (state == BODY2) {
                                                putcomp(c1, &holder, BODYCOMP);
-                                               state = m_getfld(state, name, holder.c_text, sizeof(buf), fp);
+                                               state = m_getfld2(state, &f, fp);
+                                               free(holder.c_text);
 -                                              holder.c_text = getcpy(f.value);
++                                              holder.c_text = mh_xstrdup(f.value);
                                        }
 -                                      free(holder.c_text);
 -                                      holder.c_text = NULL;
 +                                      mh_free0(&(holder.c_text));
                                        continue;
                                }
-                               for (c2 = msghd; c2; c2 = c2->c_next)
-                                       if (!mh_strcasecmp(c2->c_name,
-                                                       c1->c_name)) {
+                               for (c2 = msghd; c2; c2 = c2->c_next) {
+                                       if (mh_strcasecmp(c2->c_name,
+                                                       c1->c_name)==0) {
                                                putcomp(c1, c2, ONECOMP);
-                                               if (!(c1->c_flags & SPLIT))
+                                               if (!(c1->c_flags & SPLIT)) {
                                                        break;
+                                               }
                                        }
+                               }
                        }
                        return;
  
diff --cc uip/mhparse.c
@@@ -248,25 -248,13 +248,13 @@@ get_content(FILE *in, char *file, int t
        ** Parse the header fields for this
        ** content into a linked list.
        */
-       for (compnum = 1, state = FLD;;) {
-               switch (state = m_getfld(state, name, buf, sizeof(buf), in)) {
-               case FLD:
-               case FLDPLUS:
+       for (compnum = 1, state = FLD2;;) {
+               switch (state = m_getfld2(state, &f, in)) {
+               case FLD2:
                        compnum++;
  
-                       /* get copies of the buffers */
-                       np = mh_xstrdup(name);
-                       vp = mh_xstrdup(buf);
-                       /* if necessary, get rest of field */
-                       while (state == FLDPLUS) {
-                               state = m_getfld(state, name, buf,
-                                               sizeof(buf), in);
-                               vp = add(buf, vp);  /* add to previous value */
-                       }
-                       /* Now add the header data to the list */
-                       add_header(ct, np, vp);
+                       /* add the header data to the list */
 -                      add_header(ct, getcpy(f.name), getcpy(f.value));
++                      add_header(ct, mh_xstrdup(f.name), mh_xstrdup(f.value));
  
                        ct->c_begin = ftell(in) + 1;
                        continue;
diff --cc uip/new.c
+++ b/uip/new.c
@@@ -107,61 -106,33 +106,33 @@@ get_msgnums(char *folder, char *sequenc
                return NULL;
        }
  
-       /* copied from seq_read.c:seq_public */
-       for (state = FLD;;) {
-               switch (state = m_getfld(state, name, field, sizeof(field),
-                               fp)) {
-               case FLD:
-               case FLDPLUS:
-                       if (state == FLDPLUS) {
-                               cp = mh_xstrdup(field);
-                               while (state == FLDPLUS) {
-                                       state = m_getfld(state, name, field,
-                                                       sizeof(field), fp);
-                                       cp = add(field, cp);
-                               }
-                               /*
-                               ** Here's where we differ from
-                               ** seq_public: if it's in a
-                               ** sequence we want, save the list
-                               ** of messages.
-                               */
-                               if (seq_in_list(name, sequences)) {
-                                       this_msgnums = trimcpy(cp);
-                                       if (msgnums == NULL) {
-                                               msgnums = this_msgnums;
-                                       } else {
-                                               old_msgnums = msgnums;
-                                               msgnums = concat(old_msgnums, " ", this_msgnums, (void *)NULL);
-                                               mh_free0(&old_msgnums);
-                                               mh_free0(&this_msgnums);
-                                       }
-                               }
-                               mh_free0(&cp);
-                       } else {
-                               /* and here */
-                               if (seq_in_list(name, sequences)) {
-                                       this_msgnums = trimcpy(field);
-                                       if (msgnums == NULL) {
-                                               msgnums = this_msgnums;
-                                       } else {
-                                               old_msgnums = msgnums;
-                                               msgnums = concat(old_msgnums, " ", this_msgnums, (void *)NULL);
-                                               mh_free0(&old_msgnums);
-                                               mh_free0(&this_msgnums);
-                                       }
+       for (state = FLD2;;) {
+               switch (state = m_getfld2(state, &f, fp)) {
+               case FLD2:
+                       /*
+                       ** if it's in a sequence we want,
+                       ** save the list of messages.
+                       */
+                       if (seq_in_list(f.name, sequences)) {
+                               this_msgnums = trimcpy(f.value);
+                               if (msgnums == NULL) {
+                                       msgnums = this_msgnums;
+                               } else {
+                                       old_msgnums = msgnums;
+                                       msgnums = concat(old_msgnums, " ",
+                                                       this_msgnums,
 -                                                      (void *)NULL);
 -                                      free(old_msgnums);
 -                                      free(this_msgnums);
++                                                      NULL);
++                                      mh_free0(&old_msgnums);
++                                      mh_free0(&this_msgnums);
                                }
                        }
                        continue;
  
-               case BODY:
-                       adios(EX_DATAERR, NULL, "no blank lines are permitted in %s",
-                                       seqfile);
-                       /* fall */
+               case BODY2:
+                       adios(EX_DATAERR, NULL, "no blank lines are permitted in %s", seqfile);
+                       /* FALL */
  
-               case FILEEOF:
+               case FILEEOF2:
                        break;
  
                default:
diff --cc uip/pick.c
@@@ -1246,32 -1247,30 +1247,27 @@@ plis
        struct tws *tw;
  
        fseek(fp, start, SEEK_SET);
-       for (state = FLD, bp = NULL;;) {
-               switch (state = m_getfld(state, name, buf, sizeof buf, fp)) {
-               case FLD:
-               case FLDPLUS:
-                       if (bp != NULL) {
+       for (state = FLD2, bp = NULL;;) {
+               switch (state = m_getfld2(state, &f, fp)) {
+               case FLD2:
+                       if (bp) {
 -                              free(bp);
 -                              bp = NULL;
 +                              mh_free0(&bp);
                        }
-                       bp = mh_xstrdup(buf);
-                       while (state == FLDPLUS) {
-                               state = m_getfld(state, name, buf,
-                                               sizeof buf, fp);
-                               bp = add(buf, bp);
-                       }
-                       if (!mh_strcasecmp(name, n->n_datef))
 -                      bp = getcpy(f.value);
++                      bp = mh_xstrdup(f.value);
+                       if (mh_strcasecmp(f.name, n->n_datef)==0) {
                                break;
+                       }
                        continue;
  
-               case BODY:
-               case FILEEOF:
-               case LENERR:
-               case FMTERR:
-                       if (state == LENERR || state == FMTERR)
-                               advise(NULL, "format error in message %d", msgnum);
-                       if (bp != NULL)
-                               mh_free0(&bp);
+               case LENERR2:
+               case FMTERR2:
+               case IOERR2:
+                       advise(NULL, "format error in message %d", msgnum);
+                       /* FALL */
+               case BODY2:
+               case FILEEOF2:
 -                      if (bp) {
 -                              free(bp);
 -                      }
++                      mh_free0(&bp);
                        return 0;
  
                default:
diff --cc uip/rcvdist.c
@@@ -192,22 -180,19 +180,19 @@@ rcvdistout(FILE *inb, char *form, char 
        if (cptr) {
                cptr->c_text = addrs;
        }
-       state = FLD;
+       state = FLD2;
        while (1) {
-               state = m_getfld(state, name, tmpbuf, SBUFSIZ, inb);
+               state = m_getfld2(state, &f, inb);
                switch (state) {
-               case FLD:
-               case FLDPLUS:
-                       if ((cptr = wantcomp[CHASH(name)])) {
+               case FLD2:
+                       if ((cptr = wantcomp[CHASH(f.name)])) {
                                do {
-                                       if (mh_strcasecmp(name, cptr->c_name)!=0) {
+                                       if (mh_strcasecmp(f.name, cptr->c_name)!=0) {
                                                continue;
                                        }
-                                       char_read += msg_count;
+                                       char_read += strlen(f.value);
                                        if (!cptr->c_text) {
-                                               cptr->c_text = tmpbuf;
-                                               *--savecomp = cptr;
-                                               tmpbuf = *nxtbuf++;
 -                                              cptr->c_text = getcpy(f.value);
++                                              cptr->c_text = mh_xstrdup(f.value);
                                        } else {
                                                cp = cptr->c_text;
                                                i = strlen(cp) - 1;
@@@ -260,16 -236,7 +236,7 @@@ finished: 
        }
        fclose(out);
  
 -      free(scanl);
 +      mh_free0(&scanl);
-       for (nxtbuf = compbuffers, i = ncomps; (cptr = *savecomp++);
-                       nxtbuf++, i--) {
-               mh_free0(&(cptr->c_text));
-       }
-       while (i-- > 0) {
-               mh_free0(nxtbuf++);
-       }
-       mh_free0(&compbuffers);
-       mh_free0(&used_buf);
  }
  
  
diff --cc uip/rcvstore.c
Simple merge
diff --cc uip/repl.c
@@@ -465,47 -441,41 +441,41 @@@ replout(FILE *inb, char *drft, struct m
                        ** temp buffer (buffer switching saves an extra
                        ** copy of the component text).
                        */
-                       if ((cptr = wantcomp[CHASH(name)]))
+                       if ((cptr = wantcomp[CHASH(f.name)])) {
                                do {
-                                       if (!mh_strcasecmp(name, cptr->c_name)) {
-                                               char_read += msg_count;
-                                               if (! cptr->c_text) {
-                                                       i = strlen(cptr->c_text = tmpbuf) - 1;
-                                                       if (tmpbuf[i] == '\n')
-                                                               tmpbuf[i] = '\0';
-                                                       *--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);
+                                       if (mh_strcasecmp(f.name, cptr->c_name)!=0) {
+                                               continue;
+                                       }
+                                       char_read += strlen(f.value);
+                                       if (!cptr->c_text) {
 -                                              cptr->c_text = getcpy(f.value);
++                                              cptr->c_text = mh_xstrdup(f.value);
+                                               i = strlen(cptr->c_text) - 1;
+                                               if (cptr->c_text[i] == '\n') {
+                                                       cptr->c_text[i] = '\0';
                                                }
-                                               while (state == FLDPLUS) {
-                                                       state = m_getfld(state, name, tmpbuf,
-                                                                                         SBUFSIZ, inb);
-                                                       cptr->c_text = add(tmpbuf, cptr->c_text);
-                                                       char_read += msg_count;
+                                       } else {
+                                               cp = cptr->c_text;
+                                               i = strlen(cp) - 1;
+                                               if (cp[i] == '\n') {
+                                                       if (cptr->c_type & CT_ADDR) {
+                                                               cp[i] = '\0';
+                                                               cp = add(",\n\t", cp);
+                                                       } else {
+                                                               cp = add("\t", cp);
+                                                       }
                                                }
-                                               break;
+                                               cptr->c_text = add(f.value, cp);
                                        }
+                                       break;
                                } while ((cptr = cptr->c_next));
-                       while (state == FLDPLUS)
-                               state = m_getfld(state, name, tmpbuf,
-                                               SBUFSIZ, inb);
+                       }
                        break;
  
-               case LENERR:
-               case FMTERR:
-               case BODY:
-               case FILEEOF:
+               case LENERR2:
+               case FMTERR2:
+               case IOERR2:
+               case BODY2:
+               case FILEEOF2:
                        goto finished;
  
                default:
@@@ -582,14 -552,7 +552,7 @@@ finished
        }
  
        /* return dynamically allocated buffers */
 -      free(scanl);
 +      mh_free0(&scanl);
-       for (nxtbuf = compbuffers, i = ncomps; (cptr = *savecomp++);
-                       nxtbuf++, i--)
-               mh_free0(&(cptr->c_text));  /* if not nxtbuf, nxtbuf already freed */
-       while ( i-- > 0)
-               mh_free0(nxtbuf++);  /* free unused nxtbufs */
-       mh_free0(&compbuffers);
-       mh_free0(&used_buf);
  }
  
  static char *buf;  /* our current working buffer */
diff --cc uip/scan.c
Simple merge
diff --cc uip/scansbr.c
@@@ -138,42 -104,39 +103,39 @@@ scan(FILE *inb, int innum, int outnum, 
                if (!(scnout = fopen(scnmsg, "w")))
                        adios(EX_IOERR, scnmsg, "unable to write");
        }
        /* scan - main loop */
-       for (compnum = 1; ;
-                       state = m_getfld(state, name, tmpbuf, SBUFSIZ, inb)) {
+       for (compnum = 1, state = FLD2; ; ) {
+               state = m_getfld2(state, &f, inb);
                switch (state) {
-               case FLD:
-               case FLDPLUS:
+               case FLD2:
                        compnum++;
                        if (incing) {
-                               FPUTS(name);
+                               FPUTS(f.name);
                                FPUTS(":");
-                               FPUTS(tmpbuf);
+                               FPUTS(f.value);
                        }
-                       /*
-                       ** if we're interested in this component, save
-                       ** a pointer to the component text, then start
-                       ** using our next free buffer as the component
-                       ** temp buffer (buffer switching saves an extra
-                       ** copy of the component text).
-                       */
-                       if (fmtstr && (cptr = wantcomp[CHASH(name)])) {
+                       if (fmtstr && (cptr = wantcomp[CHASH(f.name)])) {
+                               /*
+                               ** we're interested in this component,
+                               ** but find the right one in the hash
+                               ** collision chain ...
+                               */
                                do {
-                                       if (mh_strcasecmp(name, cptr->c_name)!=0) {
+                                       if (mh_strcasecmp(f.name, cptr->c_name)!=0) {
                                                continue;
                                        }
-                                       if (!cptr->c_text) {
-                                               cptr->c_text = tmpbuf;
-                                               cp = tmpbuf+strlen(tmpbuf)-1;
-                                               for (; cp >= tmpbuf; cp--) {
-                                                       if (isspace(*cp))
-                                                               *cp = '\0';
-                                                       else
-                                                               break;
+                                       if (cptr->c_text) {
+                                               free(cptr->c_text);
+                                               cptr->c_text = NULL;
+                                       }
 -                                      cptr->c_text = getcpy(f.value);
++                                      cptr->c_text = mh_xstrdup(f.value);
+                                       cp = cptr->c_text + strlen(cptr->c_text) - 1;
+                                       for (; cp >= cptr->c_text; cp--) {
+                                               if (isspace(*cp)) {
+                                                       *cp = '\0';
+                                               } else {
+                                                       break;
                                                }
-                                               *--savecomp = cptr;
-                                               tmpbuf = *nxtbuf++;
                                        }
                                        break;
                                } while ((cptr = cptr->c_next));
diff --cc uip/slocal.c
@@@ -756,19 -756,12 +756,12 @@@ parse(int fd
        /*
        ** Scan the headers of the message and build a lookup table.
        */
-       for (i = 0, state = FLD;;) {
-               switch (state = m_getfld(state, name, field, sizeof(field),
-                               in)) {
-               case FLD:
-               case FLDPLUS:
-                       lp = mh_xstrdup(field);
-                       while (state == FLDPLUS) {
-                               state = m_getfld(state, name, field,
-                                               sizeof(field), in);
-                               lp = add(field, lp);
-                       }
+       for (i = 0, state = FLD2;;) {
+               switch (state = m_getfld2(state, &f, in)) {
+               case FLD2:
 -                      lp = getcpy(f.value);
++                      lp = mh_xstrdup(f.value);
                        for (p = hdrs; p->p_name; p++) {
-                               if (mh_strcasecmp(p->p_name, name)!=0) {
+                               if (mh_strcasecmp(p->p_name, f.name)!=0) {
                                        if (!(p->p_flags & P_HID)) {
                                                if ((cp = p->p_value)) {
                                                        if (p->p_flags & P_ADR) {
                                }
                        }
                        if (!p->p_name && i < NVEC) {
-                               p->p_name = mh_xstrdup(name);
 -                              p->p_name = getcpy(f.name);
++                              p->p_name = mh_xstrdup(f.name);
                                p->p_value = lp;
                                p->p_flags = P_NIL;
                                p++, i++;
diff --cc uip/sortm.c
@@@ -328,49 -332,37 +329,37 @@@ get_fields(char *datesw, int msg, struc
                admonish(msgnam, "unable to read message");
                return (0);
        }
-       for (compnum = 1, state = FLD;;) {
-               switch (state = m_getfld(state, nam, buf, sizeof(buf), in)) {
-               case FLD:
-               case FLDPLUS:
-                       compnum++;
-                       if (!mh_strcasecmp(nam, datesw)) {
-                               datecomp = add(buf, datecomp);
-                               while (state == FLDPLUS) {
-                                       state = m_getfld(state, nam, buf,
-                                                       sizeof(buf), in);
-                                       datecomp = add(buf, datecomp);
-                               }
-                               if (!subjsort || subjcomp)
+       for (compnum = 1, state = FLD2;; compnum++) {
+               switch (state = m_getfld2(state, &f, in)) {
+               case FLD2:
+                       if (mh_strcasecmp(f.name, datesw)==0) {
 -                              datecomp = getcpy(f.value);
++                              datecomp = mh_xstrdup(f.value);
+                               if (!subjsort || subjcomp) {
                                        break;
-                       } else if (subjsort && !mh_strcasecmp(nam, subjsort)) {
-                               subjcomp = add(buf, subjcomp);
-                               while (state == FLDPLUS) {
-                                       state = m_getfld(state, nam, buf,
-                                                       sizeof(buf), in);
-                                       subjcomp = add(buf, subjcomp);
                                }
-                               if (datecomp)
+                       } else if (subjsort && mh_strcasecmp(f.name,
+                                       subjsort)==0) {
 -                              subjcomp = getcpy(f.value);
++                              subjcomp = mh_xstrdup(f.value);
+                               if (datecomp) {
                                        break;
-                       } else {
-                               /* just flush this guy */
-                               while (state == FLDPLUS)
-                                       state = m_getfld(state, nam, buf,
-                                                       sizeof(buf), in);
+                               }
                        }
                        continue;
  
-               case BODY:
-               case FILEEOF:
+               case BODY2:
+               case FILEEOF2:
                        break;
  
-               case LENERR:
-               case FMTERR:
-                       if (state == LENERR || state == FMTERR)
-                               admonish(NULL, "format error in message %d (header #%d)", msg, compnum);
-                       if (datecomp)
+               case LENERR2:
+               case FMTERR2:
+               case IOERR2:
+                       admonish(NULL, "format error in message %d (header #%d)", msg, compnum);
+                       if (datecomp) {
 -                              free(datecomp);
 +                              mh_free0(&datecomp);
-                       if (subjcomp)
+                       }
+                       if (subjcomp) {
 -                              free(subjcomp);
 +                              mh_free0(&subjcomp);
+                       }
                        fclose(in);
                        return (0);
  
diff --cc uip/spost.c
Simple merge
diff --cc uip/whom.c
Simple merge