dovecot-2.2: lib-mail: Added HEADER_FILTER_CRLF_PRESERVE flag to...

dovecot at dovecot.org dovecot at dovecot.org
Thu Mar 12 17:39:52 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/308a97126244
changeset: 18343:308a97126244
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Mar 12 19:39:03 2015 +0200
description:
lib-mail: Added HEADER_FILTER_CRLF_PRESERVE flag to istream-header-filter.

diffstat:

 src/lib-mail/istream-header-filter.c |  18 ++++++++++++------
 src/lib-mail/istream-header-filter.h |   4 +++-
 2 files changed, 15 insertions(+), 7 deletions(-)

diffs (78 lines):

diff -r 34862aea421d -r 308a97126244 src/lib-mail/istream-header-filter.c
--- a/src/lib-mail/istream-header-filter.c	Thu Mar 12 17:41:09 2015 +0200
+++ b/src/lib-mail/istream-header-filter.c	Thu Mar 12 19:39:03 2015 +0200
@@ -33,6 +33,7 @@
 	unsigned int header_parsed:1;
 	unsigned int exclude:1;
 	unsigned int crlf:1;
+	unsigned int crlf_preserve:1;
 	unsigned int hide_body:1;
 	unsigned int add_missing_eoh:1;
 	unsigned int end_body_with_lf:1;
@@ -125,9 +126,9 @@
 			     cmp_uint) != NULL;
 }
 
-static void add_eol(struct header_filter_istream *mstream)
+static void add_eol(struct header_filter_istream *mstream, bool orig_crlf)
 {
-	if (mstream->crlf)
+	if (mstream->crlf || (orig_crlf && mstream->crlf_preserve))
 		buffer_append(mstream->hdr_buf, "\r\n", 2);
 	else
 		buffer_append_c(mstream->hdr_buf, '\n');
@@ -197,7 +198,7 @@
 				continue;
 			}
 
-			add_eol(mstream);
+			add_eol(mstream, hdr->crlf_newline);
 			continue;
 		}
 
@@ -239,7 +240,7 @@
 			buffer_append(mstream->hdr_buf,
 				      hdr->value, hdr->value_len);
 			if (!hdr->no_newline)
-				add_eol(mstream);
+				add_eol(mstream, hdr->crlf_newline);
 
 			if (mstream->skip_count >= mstream->hdr_buf->used) {
 				/* we need more */
@@ -266,7 +267,7 @@
 		}
 		if (!mstream->seen_eoh && mstream->add_missing_eoh) {
 			mstream->seen_eoh = TRUE;
-			add_eol(mstream);
+			add_eol(mstream, FALSE);
 		}
 	}
 
@@ -554,7 +555,12 @@
 	mstream->callback = callback;
 	mstream->context = context;
 	mstream->exclude = (flags & HEADER_FILTER_EXCLUDE) != 0;
-	mstream->crlf = (flags & HEADER_FILTER_NO_CR) == 0;
+	if ((flags & HEADER_FILTER_CRLF_PRESERVE) != 0)
+		mstream->crlf_preserve = TRUE;
+	else if ((flags & HEADER_FILTER_NO_CR) != 0)
+		mstream->crlf = FALSE;
+	else
+		mstream->crlf = TRUE;
 	mstream->hide_body = (flags & HEADER_FILTER_HIDE_BODY) != 0;
 	mstream->add_missing_eoh = (flags & HEADER_FILTER_ADD_MISSING_EOH) != 0;
 	mstream->end_body_with_lf =
diff -r 34862aea421d -r 308a97126244 src/lib-mail/istream-header-filter.h
--- a/src/lib-mail/istream-header-filter.h	Thu Mar 12 17:41:09 2015 +0200
+++ b/src/lib-mail/istream-header-filter.h	Thu Mar 12 19:39:03 2015 +0200
@@ -16,7 +16,9 @@
 	/* If the empty "end of headers" line doesn't exist, add it. */
 	HEADER_FILTER_ADD_MISSING_EOH	= 0x10,
 	/* If body doesn't end with [CR]LF, add it/them. */
-	HEADER_FILTER_END_BODY_WITH_LF	= 0x20
+	HEADER_FILTER_END_BODY_WITH_LF	= 0x20,
+	/* Preserve the original LF or CRLF. */
+	HEADER_FILTER_CRLF_PRESERVE	= 0x40
 };
 
 struct message_header_line;


More information about the dovecot-cvs mailing list