forw,repl: Replaced internal annotate() call with invokation of anno(1).
[mmh] / uip / scansbr.c
index 9f6306d..eba09f0 100644 (file)
@@ -76,8 +76,9 @@ scan(FILE *inb, int innum, int outnum, char *fmtstr, int width, int curflg,
        char name[NAMESZ];
        char returnpath[BUFSIZ];
        char deliverydate[BUFSIZ];
-       int incing = (outnum > 0);
-       int scanfolder = (outnum == 0);
+       int incing = (outnum != SCN_MBOX && outnum != SCN_FOLD);
+       int scanfolder = (outnum == SCN_FOLD);
+       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
@@ -202,47 +204,23 @@ 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 */
+                       if (scanfolder) {
+                               /* stop here if we scan a msg in a folder */
+                               state = FILEEOF;
                                goto finished;
                        }
-                       FPUTS("\n");
-                       FPUTS(tmpbuf);
-                       /*
-                       ** performance hack: some people like to run "inc"
-                       ** on things like net.sources or large digests.
-                       ** We do a copy directly into the output buffer
-                       ** rather than going through an intermediate buffer.
-                       **
-                       ** We need the amount of data m_getfld found &
-                       ** don't want to do a strlen on the long buffer so
-                       ** there's a hack in m_getfld to save the amount
-                       ** of data it returned in the global "msg_count".
-                       */
+                       /* otherwise (mbox): snarf the body */
+                       if (incing) {
+                               FPUTS("\n");
+                               FPUTS(tmpbuf);
+                       }
 body:;
                        while (state == BODY) {
-#ifdef LINUX_STDIO
-                               if (scnout->_IO_write_ptr == scnout->_IO_write_end) {
-#elif defined(__DragonFly__)
-                               if (((struct __FILE_public *)scnout)->_w <= 0) {
-#else
-                               if (scnout->_cnt <= 0) {
-#endif
-                                       if (fflush(scnout) == EOF)
-                                               adios(scnmsg, "write error on");
+                               state = m_getfld(state, name, tmpbuf, SBUFSIZ,
+                                               inb);
+                               if (incing) {
+                                       FPUTS(tmpbuf);
                                }
-#ifdef LINUX_STDIO
-                               state = m_getfld(state, name, scnout->_IO_write_ptr, (long)scnout->_IO_write_ptr-(long)scnout->_IO_write_end , inb);
-                               scnout->_IO_write_ptr += msg_count;
-#elif defined(__DragonFly__)
-                               state = m_getfld(state, name, ((struct __FILE_public *)scnout)->_p, -(((struct __FILE_public *)scnout)->_w), inb);
-                               ((struct __FILE_public *)scnout)->_w -= msg_count;
-                               ((struct __FILE_public *)scnout)->_p += msg_count;
-#else
-                               state = m_getfld(state, name, scnout->_ptr, -(scnout->_cnt), inb);
-                               scnout->_cnt -= msg_count;
-                               scnout->_ptr += msg_count;
-#endif
                        }
                        goto finished;
 
@@ -279,6 +257,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) {