@bobfrankston/rmfmail 1.2.213 → 1.2.215

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,38 @@ 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
- return unfolded.replace(/=\?([^?]+)\?([BQ])\?([^?]+)\?=/gi, (_match, charset, encoding, text) => {
7845
+ const rejoined = unfolded.replace(/(=\?[^?]+\?[BQ]\?[^?]*?)\s+\?=/gi, "$1?=");
7846
+ const decodedWords = rejoined.replace(/=\?([^?]+)\?([BQ])\?([^?]+)\?=/gi, (_match, charset, encoding, text) => {
7828
7847
  try {
7829
- const cs = charset.toLowerCase().replace(/^utf8$/, "utf-8");
7848
+ const decoder = decoderFor(charset);
7830
7849
  if (encoding.toUpperCase() === "B") {
7831
7850
  const raw = atob(text);
7832
7851
  const bytes = new Uint8Array(raw.length);
7833
7852
  for (let j = 0; j < raw.length; j++)
7834
7853
  bytes[j] = raw.charCodeAt(j);
7835
- return new TextDecoder(cs).decode(bytes);
7854
+ return decoder.decode(bytes);
7836
7855
  } else {
7837
7856
  const decoded = text.replace(/_/g, " ");
7838
7857
  const bytes = [];
@@ -7846,12 +7865,13 @@ function decodeImapString(s) {
7846
7865
  i++;
7847
7866
  }
7848
7867
  }
7849
- return new TextDecoder(cs).decode(new Uint8Array(bytes));
7868
+ return decoder.decode(new Uint8Array(bytes));
7850
7869
  }
7851
7870
  } catch {
7852
- return text;
7871
+ return encoding.toUpperCase() === "Q" ? text.replace(/_/g, " ") : text;
7853
7872
  }
7854
7873
  });
7874
+ return decodedWords.replace(/\uFEFF/g, "");
7855
7875
  }
7856
7876
  function tokenizeParenList(s) {
7857
7877
  const tokens = [];