fix: MIME Decoding corrupts non-ASCII characters in Base64-encoded words (#2291)

This commit is contained in:
Willi Ballenthin 2026-06-20 11:41:53 +02:00 committed by GitHub
parent 8105e3eb07
commit 64fc664479
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 1 deletions

View File

@ -87,7 +87,7 @@ class MIMEDecoding extends Operation {
end = cur + j + "?=".length;
if (encoding.toLowerCase() === "b") {
text = fromBase64(text);
text = fromBase64(text, undefined, "byteArray");
} else if (encoding.toLowerCase() === "q") {
text = this.parseQEncodedWord(text);
} else {

View File

@ -75,6 +75,39 @@ TestRegister.addTests([
}
]
},
{
name: "UTF-8 Base64 non-ASCII",
input: "Subject: =?UTF-8?B?Y2Fmw6k=?=",
expectedOutput: "Subject: café",
recipeConfig: [
{
"op": "MIME Decoding",
"args": []
}
]
},
{
name: "UTF-8 Base64 multibyte CJK",
input: "Subject: =?UTF-8?B?5pel5pys6Kqe?=",
expectedOutput: "Subject: 日本語",
recipeConfig: [
{
"op": "MIME Decoding",
"args": []
}
]
},
{
name: "UTF-8 Base64 ASCII-only",
input: "Subject: =?UTF-8?B?aGVsbG8=?=",
expectedOutput: "Subject: hello",
recipeConfig: [
{
"op": "MIME Decoding",
"args": []
}
]
},
{
name: "ISO Decoding",
input: "From: =?US-ASCII?Q?Keith_Moore?= <moore@cs.utk.edu>\nTo: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <keld@dkuug.dk>\nCC: =?ISO-8859-1?Q?Andr=E9?= Pirard <PIRARD@vm1.ulg.ac.be>\nSubject: =?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=\n=?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=",