Decode QOutlook legacy MIME words
This commit is contained in:
+7
-12
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user