scansbr: Fixed scan and inc.
authormarkus schnalke <meillo@marmaro.de>
Thu, 22 Mar 2012 20:07:50 +0000 (21:07 +0100)
committermarkus schnalke <meillo@marmaro.de>
Thu, 22 Mar 2012 20:07:50 +0000 (21:07 +0100)
Writing to /dev/null had it's sense, as for scanning mboxes, the message size
had been determined this way and the file pointer had been pushed forward.
This is now done using the input file pointer instead of the output fp.

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) {