scan() was copying the mailbox to /dev/null when called for `scan -file
foo.mbox' because it used outnum being non-zero as the test of whether
to write instead of FILE pointer scnout being non-NULL. By switching,
we can avoid the opening of /dev/null that was just to give scnout a
valid value for the needless fputs(3), etc.
Add comment explaining scan()'s outnum input parameter's three
functions: -1, 0, and positive.
+/* outnum determines how the input from inb is copied. If positive then
+ * it is the number of the message to create, e.g. for inc(1), and all
+ * of the email is copied into that message, with some tweaks. If 0,
+ * e.g. `scan 42', then reading inb can dubiously stop after a whole
+ * buffer of body, even though this might not be enough to fulfill the
+ * scan format and width. Or if -1 then no copy is being created, but
+ * all of inb must be read because the next message must be found, e.g.
+ * `scan -file foo.mbox'. */
+
int
scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg,
int unseen, char *folder, long size, int noisy, charstring_t *scanl)
int
scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg,
int unseen, char *folder, long size, int noisy, charstring_t *scanl)
- if (outnum) {
- if (outnum > 0) {
- scnmsg = m_name (outnum);
- if (*scnmsg == '?') /* msg num out of range */
- return SCNNUM;
- } else {
- scnmsg = "/dev/null";
- }
- if ((scnout = fopen (scnmsg, "w")) == NULL)
- adios (scnmsg, "unable to write");
+ if (outnum > 0) {
+ scnmsg = m_name (outnum);
+ if (*scnmsg == '?') /* msg num out of range */
+ return SCNNUM;
+ if ((scnout = fopen (scnmsg, "w")) == NULL)
+ adios (scnmsg, "unable to write");
case FLD:
case FLDPLUS:
compnum++;
case FLD:
case FLDPLUS:
compnum++;
FPUTS (name);
if ( putc (':', scnout) == EOF) DIEWRERR();
FPUTS (tmpbuf);
FPUTS (name);
if ( putc (':', scnout) == EOF) DIEWRERR();
FPUTS (tmpbuf);
while (state == FLDPLUS) {
bufsz = rlwidth;
state = m_getfld (&gstate, name, tmpbuf, &bufsz, inb);
while (state == FLDPLUS) {
bufsz = rlwidth;
state = m_getfld (&gstate, name, tmpbuf, &bufsz, inb);
state = m_getfld (&gstate, name, tmpbuf + i, &bufsz, inb);
}
state = m_getfld (&gstate, name, tmpbuf + i, &bufsz, inb);
}
state = FILEEOF; /* stop now if scan cmd */
if (bodycomp && startbody == NULL)
startbody = tmpbuf;
goto finished;
}
state = FILEEOF; /* stop now if scan cmd */
if (bodycomp && startbody == NULL)
startbody = tmpbuf;
goto finished;
}
- if (putc ('\n', scnout) == EOF) DIEWRERR();
- FPUTS (tmpbuf);
+ if (scnout) {
+ if (putc ('\n', scnout) == EOF) DIEWRERR();
+ FPUTS (tmpbuf);
+ }
/*
* The previous code here used to call m_getfld() using
* pointers to the underlying output stdio buffers to
/*
* The previous code here used to call m_getfld() using
* pointers to the underlying output stdio buffers to
while (state == BODY) {
bufsz = rlwidth;
state = m_getfld (&gstate, name, tmpbuf, &bufsz, inb);
while (state == BODY) {
bufsz = rlwidth;
state = m_getfld (&gstate, name, tmpbuf, &bufsz, inb);
+ if (scnout)
+ FPUTS(tmpbuf);
fprintf (stderr, "component %d\n", compnum);
fprintf (stderr, "component %d\n", compnum);
FPUTS ("\n\nBAD MSG:\n");
FPUTS (name);
if (putc ('\n', scnout) == EOF) DIEWRERR();
FPUTS ("\n\nBAD MSG:\n");
FPUTS (name);
if (putc ('\n', scnout) == EOF) DIEWRERR();
{
dat[2] = ftell(scnout);
if (dat[2] == EOF) DIEWRERR();
{
dat[2] = ftell(scnout);
if (dat[2] == EOF) DIEWRERR();
- if (outnum && (ferror(scnout) || fclose (scnout) == EOF))
+ if (scnout && (ferror(scnout) || fclose (scnout) == EOF))
DIEWRERR();
return (state != FILEEOF ? SCNERR : encrypted ? SCNENC : SCNMSG);
DIEWRERR();
return (state != FILEEOF ? SCNERR : encrypted ? SCNENC : SCNMSG);