Skip to content

Commit

Permalink
jmap_mail.c: NFC-normalize asText header values before encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
rsto committed Jun 3, 2024
1 parent 30086f9 commit c680294
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cassandane/tiny-tests/JMAPEmail/email_set_header_nfc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ sub test_email_set_header_nfc
to => [{
email => $nonNfcEmailAddress,
}],
'header:x-my-header' => "$nonNfcXHeaderValue",
'header:x-my-header' => $nonNfcXHeaderValue,
'header:x-my-header2:asText' => $nonNfcXHeaderValue,
mailboxIds => {
'$inbox' => JSON::true,
},
Expand All @@ -55,6 +56,8 @@ sub test_email_set_header_nfc
'header:to',
'header:x-my-header:asText',
'header:x-my-header',
'header:x-my-header2:asText',
'header:x-my-header2',
],
}, 'R2'],
]);
Expand All @@ -67,4 +70,8 @@ sub test_email_set_header_nfc
$res->[1][1]{list}[0]{'header:x-my-header:asText'});
$self->assert_str_equals(" $nonNfcXHeaderValue",
$res->[1][1]{list}[0]{'header:x-my-header'});
$self->assert_str_equals($normalizedXHeaderValue,
$res->[1][1]{list}[0]{'header:x-my-header2:asText'});
$self->assert_str_equals(" =?UTF-8?Q?0.5=C3=85?=",
$res->[1][1]{list}[0]{'header:x-my-header2'});
}
3 changes: 3 additions & 0 deletions imap/jmap_mail.c
Original file line number Diff line number Diff line change
Expand Up @@ -9200,6 +9200,8 @@ static json_t *_header_from_text(json_t *jtext,
/* Parse a Text header into raw form */
if (json_is_string(jtext)) {
const char *s = json_string_value(jtext);
char *nfc_s = charset_utf8_normalize(s);
s = nfc_s ? nfc_s : s;
char *tmp = charset_encode_mimeheader(s, strlen(s), 0);
struct buf val = BUF_INITIALIZER;
/* If text got folded, then the first line of the encoded
Expand All @@ -9208,6 +9210,7 @@ static json_t *_header_from_text(json_t *jtext,
* clients are doing this, this seems not to be an issue and
* allows us to not start the header value with a line fold. */
buf_setcstr(&val, tmp);
free(nfc_s);
free(tmp);
return _header_make(header_name, prop_name, &val, parser);
}
Expand Down

0 comments on commit c680294

Please sign in to comment.