@bobfrankston/rmfmail 1.2.213 → 1.2.214
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -7820,19 +7820,37 @@ function unquote(s) {
|
|
|
7820
7820
|
return s.slice(1, -1).replace(/\\(.)/g, "$1");
|
|
7821
7821
|
return s;
|
|
7822
7822
|
}
|
|
7823
|
+
function decoderFor(label) {
|
|
7824
|
+
const raw = label.trim().toLowerCase();
|
|
7825
|
+
const candidates = [raw];
|
|
7826
|
+
const noLang = raw.split("*")[0];
|
|
7827
|
+
if (noLang !== raw)
|
|
7828
|
+
candidates.push(noLang);
|
|
7829
|
+
const locale = noLang.match(/^[a-z]{1,8}(?:_[a-z0-9]{1,8})?\.(.+)$/);
|
|
7830
|
+
if (locale)
|
|
7831
|
+
candidates.push(locale[1]);
|
|
7832
|
+
candidates.push(noLang.replace(/^utf[_]?8$/, "utf-8"));
|
|
7833
|
+
for (const cs of candidates) {
|
|
7834
|
+
try {
|
|
7835
|
+
return new TextDecoder(cs);
|
|
7836
|
+
} catch {
|
|
7837
|
+
}
|
|
7838
|
+
}
|
|
7839
|
+
return new TextDecoder("utf-8");
|
|
7840
|
+
}
|
|
7823
7841
|
function decodeImapString(s) {
|
|
7824
7842
|
if (!s)
|
|
7825
7843
|
return "";
|
|
7826
7844
|
const unfolded = s.replace(/\?=\s+=\?/g, "?==?");
|
|
7827
7845
|
return unfolded.replace(/=\?([^?]+)\?([BQ])\?([^?]+)\?=/gi, (_match, charset, encoding, text) => {
|
|
7828
7846
|
try {
|
|
7829
|
-
const
|
|
7847
|
+
const decoder = decoderFor(charset);
|
|
7830
7848
|
if (encoding.toUpperCase() === "B") {
|
|
7831
7849
|
const raw = atob(text);
|
|
7832
7850
|
const bytes = new Uint8Array(raw.length);
|
|
7833
7851
|
for (let j = 0; j < raw.length; j++)
|
|
7834
7852
|
bytes[j] = raw.charCodeAt(j);
|
|
7835
|
-
return
|
|
7853
|
+
return decoder.decode(bytes);
|
|
7836
7854
|
} else {
|
|
7837
7855
|
const decoded = text.replace(/_/g, " ");
|
|
7838
7856
|
const bytes = [];
|
|
@@ -7846,10 +7864,10 @@ function decodeImapString(s) {
|
|
|
7846
7864
|
i++;
|
|
7847
7865
|
}
|
|
7848
7866
|
}
|
|
7849
|
-
return
|
|
7867
|
+
return decoder.decode(new Uint8Array(bytes));
|
|
7850
7868
|
}
|
|
7851
7869
|
} catch {
|
|
7852
|
-
return text;
|
|
7870
|
+
return encoding.toUpperCase() === "Q" ? text.replace(/_/g, " ") : text;
|
|
7853
7871
|
}
|
|
7854
7872
|
});
|
|
7855
7873
|
}
|