dovecot-2.2: lib-mail: message_header_encode() no longer tries t...

dovecot at dovecot.org dovecot at dovecot.org
Sun May 11 15:28:58 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/4892a941d63b
changeset: 17366:4892a941d63b
user:      Timo Sirainen <tss at iki.fi>
date:      Sun May 11 18:28:03 2014 +0300
description:
lib-mail: message_header_encode() no longer tries to lookup the first line's length from output string.
This function is used only by Pigeonhole, which only uses it for empty
output strings, so it's not useful there. Also that behavior is somewhat
unexpected and confusing.

diffstat:

 src/lib-mail/message-header-encode.c |  32 +++++---------------------------
 src/lib-mail/message-header-encode.h |   3 +--
 2 files changed, 6 insertions(+), 29 deletions(-)

diffs (76 lines):

diff -r f557dada0649 -r 4892a941d63b src/lib-mail/message-header-encode.c
--- a/src/lib-mail/message-header-encode.c	Thu May 08 18:07:30 2014 +0300
+++ b/src/lib-mail/message-header-encode.c	Sun May 11 18:28:03 2014 +0300
@@ -28,29 +28,13 @@
 	return FALSE;
 }
 
-static unsigned int str_last_line_len(string_t *str)
-{
-	const unsigned char *data = str_data(str);
-	unsigned int i = str_len(str);
-
-	while (i > 0 && data[i-1] != '\n')
-		i--;
-	return str_len(str) - i;
-}
-
 void message_header_encode_q(const unsigned char *input, unsigned int len,
 			     string_t *output)
 {
-	unsigned int i, line_len, line_len_left;
-
-	line_len = str_last_line_len(output);
-	if (line_len >= MIME_MAX_LINE_LEN - MIME_WRAPPER_LEN - 3) {
-		str_append(output, "\n\t");
-		line_len = 1;
-	}
+	unsigned int i, line_len_left;
 
 	str_append(output, "=?utf-8?q?");
-	line_len_left = MIME_MAX_LINE_LEN - MIME_WRAPPER_LEN - line_len;
+	line_len_left = MIME_MAX_LINE_LEN - MIME_WRAPPER_LEN;
 	for (i = 0; i < len; i++) {
 		if (line_len_left < 3) {
 			/* if we're not at the beginning of a character,
@@ -90,16 +74,10 @@
 void message_header_encode_b(const unsigned char *input, unsigned int len,
 			     string_t *output)
 {
-	unsigned int line_len, line_len_left, max;
+	unsigned int line_len_left, max;
 
-	line_len = str_last_line_len(output);
-	if (line_len >= MIME_MAX_LINE_LEN - MIME_WRAPPER_LEN) {
-		str_append(output, "\n\t");
-		line_len = 1;
-	}
-
+	line_len_left = MIME_MAX_LINE_LEN - MIME_WRAPPER_LEN;
 	for (;;) {
-		line_len_left = MIME_MAX_LINE_LEN - MIME_WRAPPER_LEN - line_len;
 		max = MAX_BASE64_DECODED_SIZE(line_len_left);
 		do {
 			max--;
@@ -127,7 +105,7 @@
 			break;
 
 		str_append(output, "\n\t");
-		line_len = 1;
+		line_len_left = MIME_MAX_LINE_LEN - MIME_WRAPPER_LEN - 1;
 	}
 }
 
diff -r f557dada0649 -r 4892a941d63b src/lib-mail/message-header-encode.h
--- a/src/lib-mail/message-header-encode.h	Thu May 08 18:07:30 2014 +0300
+++ b/src/lib-mail/message-header-encode.h	Sun May 11 18:28:03 2014 +0300
@@ -7,8 +7,7 @@
 				string_t *output);
 
 /* Encode the whole UTF-8 input using "Q" or "B" encoding into output.
-   The output is split into multiple lines if necessary. The first line length
-   is looked up from the output string. */
+   The output is split into multiple lines if necessary (max 76 chars/line). */
 void message_header_encode_q(const unsigned char *input, unsigned int len,
 			     string_t *output);
 void message_header_encode_b(const unsigned char *input, unsigned int len,


More information about the dovecot-cvs mailing list