@bobfrankston/iflow-direct 0.1.7 → 0.1.8

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.
Files changed (2) hide show
  1. package/imap-compat.js +35 -14
  2. package/package.json +1 -1
package/imap-compat.js CHANGED
@@ -73,24 +73,45 @@ export class CompatImapClient {
73
73
  }
74
74
  /** Detect special folders from folder list */
75
75
  getSpecialFolders(folders) {
76
+ // Match IMAP special-use flags (RFC 6154) first, then fall back to exact
77
+ // LEAF NAME match. Do NOT use substring matches on the full path —
78
+ // "Drafts.Older" used to get tagged as the Drafts folder because of a
79
+ // lower.includes("draft") test, which made it impossible to rename or
80
+ // delete the subfolder.
76
81
  const result = {};
82
+ const leafName = (f) => {
83
+ const delim = f.delimiter || ".";
84
+ return (f.path.split(delim).pop() || f.path).toLowerCase();
85
+ };
77
86
  for (const f of folders) {
78
- const lower = f.path.toLowerCase();
87
+ const name = leafName(f);
79
88
  const flags = f.flags.map(fl => fl.toLowerCase());
80
- if (flags.includes("\\inbox") || lower === "inbox")
81
- result.inbox = f.path;
82
- else if (flags.includes("\\sent") || lower === "sent" || lower.includes("sent"))
83
- result.sent = f.path;
84
- else if (flags.includes("\\trash") || lower === "trash" || lower.includes("trash"))
85
- result.trash = f.path;
86
- else if (flags.includes("\\drafts") || lower === "drafts" || lower.includes("draft"))
87
- result.drafts = f.path;
88
- else if (flags.includes("\\junk") || flags.includes("\\spam") || lower === "spam" || lower === "junk") {
89
- result.junk = f.path;
90
- result.spam = f.path;
89
+ if (flags.includes("\\inbox") || name === "inbox") {
90
+ if (!result.inbox)
91
+ result.inbox = f.path;
92
+ }
93
+ else if (flags.includes("\\sent") || name === "sent" || name === "sent items" || name === "sent mail") {
94
+ if (!result.sent)
95
+ result.sent = f.path;
96
+ }
97
+ else if (flags.includes("\\trash") || name === "trash" || name === "deleted items" || name === "deleted") {
98
+ if (!result.trash)
99
+ result.trash = f.path;
100
+ }
101
+ else if (flags.includes("\\drafts") || name === "drafts" || name === "draft") {
102
+ if (!result.drafts)
103
+ result.drafts = f.path;
104
+ }
105
+ else if (flags.includes("\\junk") || flags.includes("\\spam") || name === "spam" || name === "junk" || name === "junk email" || name === "junk e-mail") {
106
+ if (!result.junk)
107
+ result.junk = f.path;
108
+ if (!result.spam)
109
+ result.spam = f.path;
110
+ }
111
+ else if (flags.includes("\\archive") || name === "archive" || name === "archives") {
112
+ if (!result.archive)
113
+ result.archive = f.path;
91
114
  }
92
- else if (flags.includes("\\archive") || lower === "archive")
93
- result.archive = f.path;
94
115
  }
95
116
  return result;
96
117
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/iflow-direct",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Direct IMAP client — transport-agnostic, no Node.js dependencies, browser-ready",
5
5
  "main": "index.js",
6
6
  "types": "index.ts",