diff -Naur amavisd-milter-1.3.1.orig/amavisd-milter/amavisd-milter.h amavisd-milter-1.3.1/amavisd-milter/amavisd-milter.h
--- amavisd-milter-1.3.1.orig/amavisd-milter/amavisd-milter.h	2008-04-21 10:30:52.000000000 +0200
+++ amavisd-milter-1.3.1/amavisd-milter/amavisd-milter.h	2008-05-21 10:05:45.000000000 +0200
@@ -71,6 +71,7 @@
     size_t	mlfi_amabuf_length;	/* amavisd buffer length */
     int		mlfi_amasd;		/* amavisd socket descriptor */
     char       *mlfi_policy_bank;	/* policy bank names */
+    int		mlfi_cr_flag;		/* CR at the end of the body chunk */
 };
 
 /* Get private data from libmilter */
diff -Naur amavisd-milter-1.3.1.orig/amavisd-milter/mlfi.c amavisd-milter-1.3.1/amavisd-milter/mlfi.c
--- amavisd-milter-1.3.1.orig/amavisd-milter/mlfi.c	2008-04-21 10:30:52.000000000 +0200
+++ amavisd-milter-1.3.1/amavisd-milter/mlfi.c	2008-05-21 10:05:45.000000000 +0200
@@ -224,6 +224,9 @@
 	mlfi->mlfi_wrkdir[0] = '\0';
     }
 
+    /* Reset CRLF detection flag */
+    mlfi->mlfi_cr_flag = 0;
+
     /* Free memory */
     free(mlfi->mlfi_prev_qid);
     mlfi->mlfi_prev_qid = mlfi->mlfi_qid;
@@ -806,6 +809,7 @@
 mlfi_body(SMFICTX *ctx, unsigned char * bodyp, size_t bodylen)
 {
     struct	mlfiCtx *mlfi = MLFICTX(ctx);
+    unsigned char *b, *c;
 
     /* Check milter private data */
     if (mlfi == NULL) {
@@ -816,6 +820,41 @@
 
     logqidmsg(mlfi, LOG_DEBUG, "body chunk: %ld", (long)bodylen);
 
+    /* Check if previous chunk ends with CR */
+    if (mlfi->mlfi_cr_flag != 0) {
+	mlfi->mlfi_cr_flag = 0;
+	if (*bodyp != '\n') {
+	    (void) fprintf(mlfi->mlfi_fp, "\r");
+	    if (ferror(mlfi->mlfi_fp)) {
+		logqidmsg(mlfi, LOG_ERR, "could not write to message file "
+		    "%s: %s", mlfi->mlfi_fname, strerror(errno));
+		mlfi_setreply_tempfail(ctx);
+		return SMFIS_TEMPFAIL;
+	    }
+	}
+    }
+
+    /* Convert CRLF to LF */
+    b = c = bodyp;
+    while (c < bodyp + bodylen) {
+	if (mlfi->mlfi_cr_flag != 0) {
+	    mlfi->mlfi_cr_flag = 0;
+	    if (*c != '\n') {
+		*b++ = '\r';
+	    }
+	    *b++ = *c++;
+	} else if (*c == '\r') {
+	    mlfi->mlfi_cr_flag = 1;
+	    c++;
+	} else {
+	    *b++ = *c++;
+	}
+    }
+
+    bodylen = b - bodyp;
+    logqidmsg(mlfi, LOG_DEBUG, "after CRLF to LF conversion: %ld)",
+	(long)(bodylen));
+
     /* Write the body chunk to the message file */
     if (fwrite(bodyp, bodylen, 1, mlfi->mlfi_fp) < 1) {
 	logqidmsg(mlfi, LOG_ERR, "could not write to message file %s: %s",

