]> Pileus Git - ~andy/fetchmail/commitdiff
Fix mimedecode last-line omission.
authorMatthias Andree <matthias.andree@gmx.de>
Fri, 17 Jun 2011 01:11:39 +0000 (03:11 +0200)
committerMatthias Andree <matthias.andree@gmx.de>
Fri, 17 Jun 2011 01:31:03 +0000 (03:31 +0200)
The mimedecode feature failed to ship the last line of the body if it
was encoded as quoted-printable and had a MIME soft line break in the
very last line.  Reported by Lars Hecking in June 2011.

Bug introduced on 1998-03-20 when the mimedecode support was added by
ESR before release 4.4.1 through code contributed by Henrik Storner,
in driver.c.

Workaround for older releases: do not use mimedecode feature.

NEWS
transact.c

diff --git a/NEWS b/NEWS
index 2394703844e2c340e49e9c8394910c7333acad32..ff68217a923f162bea9421d13d1b826f95c0bbc1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -97,6 +97,14 @@ NOTE THIS IS AN ALPHA RELEASE THAT HAS NOT BEEN THOROUGHLY TESTED!
   (Regression in 5.0.0 on 1999-03-27, as a side effect of a PGP-mimedecode fix
   attributed to Henrik Storner.)
 
+# BUG FIXES
+* The mimedecode feature failed to ship the last line of the body if it was
+  encoded as quoted-printable and had a MIME soft line break in the very last
+  line.  Reported by Lars Hecking in June 2011.
+  Bug introduced on 1998-03-20 when the mimedecode support was added by ESR
+  before release 4.4.1 through code contributed by Henrik Storner.
+  Workaround for older releases: do not use mimedecode feature.
+
 # CHANGES
 * A foreground fetchmail can now accept a few more options while another copy is
   running in the background.
index 0f0cd35378a4c4f5f053b8db9093562e899a1d52..b36c8d791a10b66aaec5c86ed37aeaa3bc05e623 100644 (file)
@@ -1341,6 +1341,28 @@ process_headers:
        return PS_SOCKET;
 }
 
+/** Convenience function factored out from readbody(): 
+ * send buffer \a buf via stuffline() and handle errors and progress.
+ * Store return value in \a *n, and return PS_IOERR for failure or
+ * PS_SUCCESS otherwise. */
+static int rb_send(struct query *ctl, char *buf, int *n)
+{
+    *n = stuffline(ctl, buf);
+
+    if (*n < 0)
+    {
+       report(stdout, GT_("error writing message text\n"));
+       release_sink(ctl);
+       return(PS_IOERR);
+    }
+    else if (want_progress())
+    {
+       fputc('*', stdout);
+       fflush(stdout);
+    }
+    return PS_SUCCESS;
+}
+
 int readbody(int sock, struct query *ctl, flag forward, int len)
 /** read and dispose of a message body presented on \a sock */
 /** \param ctl         query control record */
@@ -1427,7 +1449,7 @@ int readbody(int sock, struct query *ctl, flag forward, int len)
        /* ship out the text line */
        if (forward && (!issoftline))
        {
-           int n;
+           int n, err;
            inbufp = buf;
 
            /* guard against very long lines */
@@ -1435,22 +1457,31 @@ int readbody(int sock, struct query *ctl, flag forward, int len)
            buf[MSGBUFSIZE+2] = '\n';
            buf[MSGBUFSIZE+3] = '\0';
 
-           n = stuffline(ctl, buf);
-
-           if (n < 0)
-           {
-               report(stdout, GT_("error writing message text\n"));
-               release_sink(ctl);
-               return(PS_IOERR);
-           }
-           else if (want_progress())
-           {
-               fputc('*', stdout);
-               fflush(stdout);
-           }
+           err = rb_send(ctl, buf, &n);
+           if (err != PS_SUCCESS)
+               return err;
        }
     }
 
+    /* Flush buffer -- bug introduced by ESR on 1998-03-20 before
+     * release 4.4.1 when ESR did not sufficiently audit Henrik
+     * Storner's patch.
+     * Trouble reported in June 2011 by Lars Hecking, with
+     * text/html quoted-printable messages generated by
+     * Outlook/Exchange that got mutilated by fetchmail.
+     */
+    if (forward && issoftline)
+    {
+       int n;
+
+       /* force proper line termination */
+       inbufp[0] = '\r';
+       inbufp[1] = '\n';
+       inbufp[2] = '\0';
+
+       return rb_send(ctl, buf, &n);
+    }
+
     return(PS_SUCCESS);
 }