scansbr: Fixed scan and inc.
[mmh] / uip / scansbr.c
index 9f6306d..299027a 100644 (file)
@@ -78,6 +78,7 @@ scan(FILE *inb, int innum, int outnum, char *fmtstr, int width, int curflg,
        char deliverydate[BUFSIZ];
        int incing = (outnum > 0);
        int scanfolder = (outnum == 0);
+       long fpos;
 
        /* first-time only initialization */
        if (!scanl) {
@@ -122,6 +123,7 @@ scan(FILE *inb, int innum, int outnum, char *fmtstr, int width, int curflg,
        dat[0] = innum ? innum : outnum;
        dat[1] = curflg;
        dat[4] = unseen;
+       fpos = ftell(inb);
 
        /*
        ** Get the first field.  If the message is non-empty
@@ -203,7 +205,16 @@ scan(FILE *inb, int innum, int outnum, char *fmtstr, int width, int curflg,
                case BODY:
                        compnum = -1;
                        if (!incing) {
-                               state = FILEEOF; /* stop here if scan cmd */
+                               /* stop here if scan cmd */
+                               if (scanfolder) {
+                                       state = FILEEOF;
+                                       goto finished;
+                               }
+                               /* for mboxes: snarf the body */
+                               while (state == BODY) {
+                                       state = m_getfld(state, name, tmpbuf,
+                                                       SBUFSIZ, inb);
+                               }
                                goto finished;
                        }
                        FPUTS("\n");
@@ -279,6 +290,10 @@ finished:
        if (incing) {
                if ((dat[2] = ftell(scnout)) == EOF)
                        adios(scnmsg, "write error on");
+       } else if (!scanfolder) {
+               if ((dat[2] = ftell(inb)) == EOF)
+                       adios(scnmsg, "write error on");
+               dat[2] -= fpos;
        }
 
        if ((datecomp && !datecomp->c_text) || scanfolder) {