Blame SOURCES/fetchmail-6.3.24-data-loss.patch

820307
From 21ac960a3e648cd53c155bd2b724f72f0164416f Mon Sep 17 00:00:00 2001
820307
From: Matthias Andree <matthias.andree@gmx.de>
820307
Date: Fri, 17 Jun 2011 03:11:39 +0200
820307
Subject: [PATCH] Fix mimedecode last-line omission.
820307
820307
The mimedecode feature failed to ship the last line of the body if it
820307
was encoded as quoted-printable and had a MIME soft line break in the
820307
very last line.  Reported by Lars Hecking in June 2011.
820307
820307
Bug introduced on 1998-03-20 when the mimedecode support was added by
820307
ESR before release 4.4.1 through code contributed by Henrik Storner,
820307
in driver.c.
820307
820307
Workaround for older releases: do not use mimedecode feature.
820307
---
820307
 NEWS       |    8 ++++++++
820307
 transact.c |   59 +++++++++++++++++++++++++++++++++++++++++++++--------------
820307
 2 files changed, 53 insertions(+), 14 deletions(-)
820307
820307
diff --git a/NEWS b/NEWS
820307
index 26709e4..ac9bc42 100644
820307
--- a/NEWS
820307
+++ b/NEWS
820307
@@ -156,6 +156,14 @@ fetchmail-6.3.23 (released 2012-12-10, 26106 LoC):
820307
 * Clean up logfile vs. syslog handling, and in case logfile overrides
820307
   syslog, send a message to the latter stating where logging goes.
820307
 
820307
+# BUG FIXES
820307
+* The mimedecode feature failed to ship the last line of the body if it was
820307
+  encoded as quoted-printable and had a MIME soft line break in the very last
820307
+  line.  Reported by Lars Hecking in June 2011.
820307
+  Bug introduced on 1998-03-20 when the mimedecode support was added by ESR
820307
+  before release 4.4.1 through code contributed by Henrik Storner.
820307
+  Workaround for older releases: do not use mimedecode feature.
820307
+
820307
 # CHANGES
820307
 * The build process can now be made a bit more silent and concise through
820307
   ./configure --enable-silent-rules, or by adding "V=0" to the make command.
820307
diff --git a/transact.c b/transact.c
820307
index ec8013a..5449e56 100644
820307
--- a/transact.c
820307
+++ b/transact.c
820307
@@ -1383,6 +1383,28 @@ process_headers:
820307
 	return PS_SOCKET;
820307
 }
820307
 
820307
+/** Convenience function factored out from readbody(): 
820307
+ * send buffer \a buf via stuffline() and handle errors and progress.
820307
+ * Store return value in \a *n, and return PS_IOERR for failure or
820307
+ * PS_SUCCESS otherwise. */
820307
+static int rb_send(struct query *ctl, char *buf, int *n)
820307
+{
820307
+    *n = stuffline(ctl, buf);
820307
+
820307
+    if (*n < 0)
820307
+    {
820307
+	report(stdout, GT_("error writing message text\n"));
820307
+	release_sink(ctl);
820307
+	return(PS_IOERR);
820307
+    }
820307
+    else if (want_progress())
820307
+    {
820307
+	fputc('*', stdout);
820307
+	fflush(stdout);
820307
+    }
820307
+    return PS_SUCCESS;
820307
+}
820307
+
820307
 int readbody(int sock, struct query *ctl, flag forward, int len)
820307
 /** read and dispose of a message body presented on \a sock */
820307
 /** \param ctl		query control record */
820307
@@ -1478,7 +1500,7 @@ int readbody(int sock, struct query *ctl, flag forward, int len)
820307
 	/* ship out the text line */
820307
 	if (forward && (!issoftline))
820307
 	{
820307
-	    int	n;
820307
+	    int	n, err;
820307
 	    inbufp = buf;
820307
 
820307
 	    /* guard against very long lines */
820307
@@ -1486,22 +1508,31 @@ int readbody(int sock, struct query *ctl, flag forward, int len)
820307
 	    buf[MSGBUFSIZE+2] = '\n';
820307
 	    buf[MSGBUFSIZE+3] = '\0';
820307
 
820307
-	    n = stuffline(ctl, buf);
820307
-
820307
-	    if (n < 0)
820307
-	    {
820307
-		report(stdout, GT_("error writing message text\n"));
820307
-		release_sink(ctl);
820307
-		return(PS_IOERR);
820307
-	    }
820307
-	    else if (want_progress())
820307
-	    {
820307
-		fputc('*', stdout);
820307
-		fflush(stdout);
820307
-	    }
820307
+	    err = rb_send(ctl, buf, &n);
820307
+	    if (err != PS_SUCCESS)
820307
+		return err;
820307
 	}
820307
     }
820307
 
820307
+    /* Flush buffer -- bug introduced by ESR on 1998-03-20 before
820307
+     * release 4.4.1 when ESR did not sufficiently audit Henrik
820307
+     * Storner's patch.
820307
+     * Trouble reported in June 2011 by Lars Hecking, with
820307
+     * text/html quoted-printable messages generated by
820307
+     * Outlook/Exchange that got mutilated by fetchmail.
820307
+     */
820307
+    if (forward && issoftline)
820307
+    {
820307
+	int n;
820307
+
820307
+	/* force proper line termination */
820307
+	inbufp[0] = '\r';
820307
+	inbufp[1] = '\n';
820307
+	inbufp[2] = '\0';
820307
+
820307
+	return rb_send(ctl, buf, &n);
820307
+    }
820307
+
820307
     return(PS_SUCCESS);
820307
 }
820307
 
820307
-- 
820307
1.7.1
820307