From: Timo Sirainen Date: Sun, 11 May 2014 15:28:03 +0000 (+0300) Subject: lib-mail: message_header_encode() no longer tries to lookup the first line's length... X-Git-Tag: 2.2.13~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=63007f6d2a501132d5312aebb7f0d30f1d00d0bd;p=thirdparty%2Fdovecot%2Fcore.git 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. --- diff --git a/src/lib-mail/message-header-encode.c b/src/lib-mail/message-header-encode.c index 6ee3cf6ddb..06c601b0be 100644 --- a/src/lib-mail/message-header-encode.c +++ b/src/lib-mail/message-header-encode.c @@ -28,29 +28,13 @@ static bool input_idx_need_encoding(const unsigned char *input, 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_q(const unsigned char *input, unsigned int len, void message_header_encode_b(const unsigned char *input, unsigned int len, string_t *output) { - unsigned int line_len, 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; - } + unsigned int line_len_left, max; + 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 @@ void message_header_encode_b(const unsigned char *input, unsigned int len, break; str_append(output, "\n\t"); - line_len = 1; + line_len_left = MIME_MAX_LINE_LEN - MIME_WRAPPER_LEN - 1; } } diff --git a/src/lib-mail/message-header-encode.h b/src/lib-mail/message-header-encode.h index 4f3b15ca5b..640f878922 100644 --- a/src/lib-mail/message-header-encode.h +++ b/src/lib-mail/message-header-encode.h @@ -7,8 +7,7 @@ void message_header_encode_data(const unsigned char *input, unsigned int len, 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,