]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: message_header_encode() no longer tries to lookup the first line's length...
authorTimo Sirainen <tss@iki.fi>
Sun, 11 May 2014 15:28:03 +0000 (18:28 +0300)
committerTimo Sirainen <tss@iki.fi>
Sun, 11 May 2014 15:28:03 +0000 (18:28 +0300)
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.

src/lib-mail/message-header-encode.c
src/lib-mail/message-header-encode.h

index 6ee3cf6ddb663c21a9bb3ee412df6814fefdcaa4..06c601b0be57a25744d3f0d7ab9d78a9c0fe708a 100644 (file)
@@ -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;
        }
 }
 
index 4f3b15ca5bd2b3a1286dedf85b2666ebb97cd1c8..640f878922c0c2c1c64ff0f102f85f506d089e5e 100644 (file)
@@ -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,