dovecot-2.2: lib-mail: message_header_encode_[bq]() now explicit...
dovecot at dovecot.org
dovecot at dovecot.org
Sun May 11 18:10:19 UTC 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/009caac530e9
changeset: 17367:009caac530e9
user: Timo Sirainen <tss at iki.fi>
date: Sun May 11 21:08:51 2014 +0300
description:
lib-mail: message_header_encode_[bq]() now explicitly takes the first line length parameter.
So this change partially reverts the previous change, because
message_header_encode() was actually internally relying on this behavior.
The explicit parameter makes it clearer.
diffstat:
src/lib-mail/message-header-encode.c | 37 ++++++++++++++++++++++--------
src/lib-mail/message-header-encode.h | 10 +++++---
src/lib-mail/test-message-header-encode.c | 6 +++-
3 files changed, 37 insertions(+), 16 deletions(-)
diffs (123 lines):
diff -r 4892a941d63b -r 009caac530e9 src/lib-mail/message-header-encode.c
--- a/src/lib-mail/message-header-encode.c Sun May 11 18:28:03 2014 +0300
+++ b/src/lib-mail/message-header-encode.c Sun May 11 21:08:51 2014 +0300
@@ -29,12 +29,20 @@
}
void message_header_encode_q(const unsigned char *input, unsigned int len,
- string_t *output)
+ string_t *output, unsigned int first_line_len)
{
unsigned int i, line_len_left;
+ line_len_left = MIME_MAX_LINE_LEN - MIME_WRAPPER_LEN;
+
+ if (first_line_len >= MIME_MAX_LINE_LEN - MIME_WRAPPER_LEN - 3) {
+ str_append(output, "\n\t");
+ line_len_left--;
+ } else {
+ line_len_left -= first_line_len;
+ }
+
str_append(output, "=?utf-8?q?");
- 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,
@@ -72,12 +80,18 @@
}
void message_header_encode_b(const unsigned char *input, unsigned int len,
- string_t *output)
+ string_t *output, unsigned int first_line_len)
{
- unsigned int line_len_left, max;
+ unsigned int line_len, line_len_left, max;
- line_len_left = MIME_MAX_LINE_LEN - MIME_WRAPPER_LEN;
+ line_len = first_line_len;
+ if (line_len >= MIME_MAX_LINE_LEN - MIME_WRAPPER_LEN) {
+ str_append(output, "\n\t");
+ line_len = 1;
+ }
+
for (;;) {
+ line_len_left = MIME_MAX_LINE_LEN - MIME_WRAPPER_LEN - line_len;
max = MAX_BASE64_DECODED_SIZE(line_len_left);
do {
max--;
@@ -105,7 +119,7 @@
break;
str_append(output, "\n\t");
- line_len_left = MIME_MAX_LINE_LEN - MIME_WRAPPER_LEN - 1;
+ line_len = 1;
}
}
@@ -155,9 +169,12 @@
/* and do it */
str_append_data(output, input, first_idx);
- if (use_q)
- message_header_encode_q(input + first_idx, enc_len, output);
- else
- message_header_encode_b(input + first_idx, enc_len, output);
+ if (use_q) {
+ message_header_encode_q(input + first_idx, enc_len,
+ output, first_idx);
+ } else {
+ message_header_encode_b(input + first_idx, enc_len,
+ output, first_idx);
+ }
str_append_data(output, input + last_idx, len - last_idx);
}
diff -r 4892a941d63b -r 009caac530e9 src/lib-mail/message-header-encode.h
--- a/src/lib-mail/message-header-encode.h Sun May 11 18:28:03 2014 +0300
+++ b/src/lib-mail/message-header-encode.h Sun May 11 21:08:51 2014 +0300
@@ -1,16 +1,18 @@
#ifndef MESSAGE_HEADER_ENCODE_H
#define MESSAGE_HEADER_ENCODE_H
-/* Encode UTF-8 input into output wherever necessary. */
+/* Encode UTF-8 input into output wherever necessary using either Q or B
+ encoding depending on which takes less space (approximately). */
void message_header_encode(const char *input, string_t *output);
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 (max 76 chars/line). */
+ The output is split into multiple lines if necessary (max 76 chars/line).
+ The first line's length is given as parameter. */
void message_header_encode_q(const unsigned char *input, unsigned int len,
- string_t *output);
+ string_t *output, unsigned int first_line_len);
void message_header_encode_b(const unsigned char *input, unsigned int len,
- string_t *output);
+ string_t *output, unsigned int first_line_len);
#endif
diff -r 4892a941d63b -r 009caac530e9 src/lib-mail/test-message-header-encode.c
--- a/src/lib-mail/test-message-header-encode.c Sun May 11 18:28:03 2014 +0300
+++ b/src/lib-mail/test-message-header-encode.c Sun May 11 21:08:51 2014 +0300
@@ -67,7 +67,8 @@
str_append_c(str, ' ');
message_header_encode_q(str_data(input) + skip,
- str_len(input) - skip, str);
+ str_len(input) - skip, str,
+ i == 0 ? 0 : i+1);
test_assert(verify_q(str_c(str), i, !skip));
}
}
@@ -153,7 +154,8 @@
str_append_c(str, ' ');
message_header_encode_b(str_data(input) + skip,
- str_len(input) - skip, str);
+ str_len(input) - skip, str,
+ i == 0 ? 0 : i+1);
test_assert(verify_b(str_c(str), i, !skip));
}
}
More information about the dovecot-cvs
mailing list