str_printfa(output, "=%02X", input[i]);
break;
default:
- if (input[i] < 32 || (input[i] & 0x80) != 0) {
+ if (input[i] < 0x20 || input[i] > 0x7e) {
line_len_left -= 2;
str_printfa(output, "=%02X", input[i]);
} else {
test_end();
}
+static void check_encoded(string_t *encoded, unsigned int test_idx)
+{
+ const unsigned char *enc = str_data(encoded), *p, *pend;
+ size_t enc_len = str_len(encoded), cur_line_len = 0;
+
+ p = enc;
+ pend = enc + enc_len;
+ while (p < pend) {
+ if (*p == '\r') {
+ p++;
+ continue;
+ }
+ if (*p == '\n') {
+ test_assert_idx(cur_line_len <= 76, test_idx);
+ cur_line_len = 0;
+ p++;
+ continue;
+ }
+ cur_line_len++;
+ test_assert_idx((*p >= 0x20 && *p <= 0x7e) || *p == '\t',
+ test_idx);
+ p++;
+ }
+
+ test_assert_idx(cur_line_len <= 76, test_idx);
+}
+
static void test_message_header_decode_encode_random(void)
{
string_t *encoded, *decoded;
/* test Q */
message_header_encode_q(buf, buflen, encoded, 0);
+ check_encoded(encoded, i);
message_header_decode_utf8(encoded->data, encoded->used,
decoded, NULL);
test_assert_idx(decoded->used == buflen &&
str_truncate(decoded, 0);
message_header_encode_b(buf, buflen, encoded, 0);
+ check_encoded(encoded, i);
message_header_decode_utf8(encoded->data, encoded->used,
decoded, NULL);
test_assert_idx(decoded->used == buflen &&