Decode QOutlook legacy MIME words

This commit is contained in:
Курнат Андрей
2026-06-01 08:22:01 +03:00
parent cf3d6b0b01
commit 472288badf
3 changed files with 12 additions and 14 deletions
+7 -12
View File
@@ -457,18 +457,13 @@ function optionalAddressHeaders(message: MailMessage): string[] {
}
export function decodeMimeWords(value: string): string {
return value.replace(/=\?([^?]+)\?([bqBQ])\?([^?]+)\?=/g, (_match, charset: string, encoding: string, encoded: string) => {
const normalizedCharset = charset.toLowerCase();
if (normalizedCharset !== "utf-8" && normalizedCharset !== "utf8") {
return _match;
}
if (encoding.toLowerCase() === "b") {
return decodeUtf8Bytes(base64ToBytes(encoded));
}
return decodeUtf8Bytes(quotedPrintableToBytes(encoded.replace(/_/g, " ")));
});
return value
.replace(/(=\?[^?]+\?[bqBQ]\?[^?]+\?=)\s+(?==\?[^?]+\?[bqBQ]\?[^?]+\?=)/g, "$1")
.replace(/=\?([^?]+)\?([bqBQ])\?([^?]+)\?=/g, (match, charset: string, encoding: string, encoded: string) => {
const bytes = encoding.toLowerCase() === "b" ? base64ToBytes(encoded) : quotedPrintableToBytes(encoded.replace(/_/g, " "));
const decoded = decodeBytes(bytes, charset);
return decoded || match;
});
}
export function decodeTransferBody(body: string, encoding = "", charset = "utf-8"): string {