@bobfrankston/iflow 1.0.44 → 1.0.45

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.
@@ -247,12 +247,26 @@ function decodeImapString(s) {
247
247
  return "";
248
248
  return s.replace(/=\?([^?]+)\?([BQ])\?([^?]+)\?=/gi, (_match, charset, encoding, text) => {
249
249
  try {
250
+ const cs = charset.toLowerCase().replace(/^utf8$/, "utf-8");
250
251
  if (encoding.toUpperCase() === "B") {
251
- return Buffer.from(text, "base64").toString("utf-8");
252
+ return Buffer.from(text, "base64").toString(cs);
252
253
  }
253
254
  else {
254
- // Quoted-printable
255
- return text.replace(/=([0-9A-F]{2})/gi, (_, hex) => String.fromCharCode(parseInt(hex, 16))).replace(/_/g, " ");
255
+ // Quoted-printable: collect bytes then decode with charset
256
+ const decoded = text.replace(/_/g, " ");
257
+ const bytes = [];
258
+ let i = 0;
259
+ while (i < decoded.length) {
260
+ if (decoded[i] === "=" && i + 2 < decoded.length) {
261
+ bytes.push(parseInt(decoded.substring(i + 1, i + 3), 16));
262
+ i += 3;
263
+ }
264
+ else {
265
+ bytes.push(decoded.charCodeAt(i));
266
+ i++;
267
+ }
268
+ }
269
+ return Buffer.from(bytes).toString(cs);
256
270
  }
257
271
  }
258
272
  catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/iflow",
3
- "version": "1.0.44",
3
+ "version": "1.0.45",
4
4
  "description": "IMAP client wrapper library",
5
5
  "main": "index.js",
6
6
  "types": "index.ts",