dovecot-2.1: lib-storage: External mail attachment parsing didn'...

dovecot at dovecot.org dovecot at dovecot.org
Fri Jun 29 08:05:13 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.1/rev/6b08977c4b75
changeset: 14584:6b08977c4b75
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jun 29 08:05:08 2012 +0300
description:
lib-storage: External mail attachment parsing didn't handle CRLF linefeeds correctly.
This simply meant that if mail_save_crlf=yes was used, base64-encoded
attachments weren't saved base64-decoded.

diffstat:

 src/lib-storage/index/index-attachment.c |  44 +++++++++++++++++--------------
 1 files changed, 24 insertions(+), 20 deletions(-)

diffs (68 lines):

diff -r 3efbc4a8219b -r 6b08977c4b75 src/lib-storage/index/index-attachment.c
--- a/src/lib-storage/index/index-attachment.c	Fri Jun 29 06:14:51 2012 +0300
+++ b/src/lib-storage/index/index-attachment.c	Fri Jun 29 08:05:08 2012 +0300
@@ -448,6 +448,28 @@
 }
 
 static int
+index_attachment_base64_decode_lf(struct mail_save_attachment_part *part)
+{
+	part->base64_state = BASE64_STATE_0;
+	if (part->cur_base64_blocks < part->base64_line_blocks) {
+		/* last line */
+		part->base64_state = BASE64_STATE_EOM;
+		return 0;
+	} else if (part->base64_line_blocks == 0) {
+		/* first line */
+		if (part->cur_base64_blocks == 0)
+			return -1;
+		part->base64_line_blocks = part->cur_base64_blocks;
+	} else if (part->cur_base64_blocks == part->base64_line_blocks) {
+		/* line is ok */
+	} else {
+		return -1;
+	}
+	part->cur_base64_blocks = 0;
+	return 1;
+}
+
+static int
 index_attachment_try_base64_decode_char(struct mail_save_attachment_part *part,
 					size_t pos, char chr)
 {
@@ -458,25 +480,7 @@
 		else if (chr == '\r')
 			part->base64_state = BASE64_STATE_CR;
 		else if (chr == '\n') {
-			part->base64_state = BASE64_STATE_0;
-			if (part->cur_base64_blocks <
-			    part->base64_line_blocks) {
-				/* last line */
-				part->base64_state = BASE64_STATE_EOM;
-				return 0;
-			} else if (part->base64_line_blocks == 0) {
-				/* first line */
-				if (part->cur_base64_blocks == 0)
-					return -1;
-				part->base64_line_blocks =
-					part->cur_base64_blocks;
-			} else if (part->cur_base64_blocks ==
-				   part->base64_line_blocks) {
-				/* line is ok */
-			} else {
-				return -1;
-			}
-			part->cur_base64_blocks = 0;
+			return index_attachment_base64_decode_lf(part);
 		} else {
 			return -1;
 		}
@@ -511,7 +515,7 @@
 		if (chr != '\n')
 			return -1;
 		part->base64_have_crlf = TRUE;
-		break;
+		return index_attachment_base64_decode_lf(part);
 	case BASE64_STATE_EOB:
 		if (chr != '=')
 			return -1;


More information about the dovecot-cvs mailing list