apple-mail-mcp 2.17.2 → 2.17.4
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.
- package/build/index.js +65 -13
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -82817,11 +82817,36 @@ ${this.errorEmit(" ")}
|
|
|
82817
82817
|
}
|
|
82818
82818
|
const entry = this.buildSmartMailboxEntry(name, fromContains, subjectContains, bodyContains);
|
|
82819
82819
|
const temp = this.prepareSmartPlistWrite(plistPath);
|
|
82820
|
-
const
|
|
82821
|
-
|
|
82822
|
-
|
|
82823
|
-
|
|
82824
|
-
|
|
82820
|
+
const entryJson = `${temp}.entry.json`;
|
|
82821
|
+
const entryPlist = `${temp}.entry.plist`;
|
|
82822
|
+
const cleanupEntryFiles = () => {
|
|
82823
|
+
for (const f of [entryJson, entryPlist]) {
|
|
82824
|
+
try {
|
|
82825
|
+
unlinkSync(f);
|
|
82826
|
+
} catch {
|
|
82827
|
+
}
|
|
82828
|
+
}
|
|
82829
|
+
};
|
|
82830
|
+
writeFileSync3(entryJson, JSON.stringify([entry]), "utf8");
|
|
82831
|
+
const conv = spawnSync2("plutil", ["-convert", "xml1", "-o", entryPlist, entryJson], {
|
|
82832
|
+
encoding: "utf8"
|
|
82833
|
+
});
|
|
82834
|
+
if (conv.status !== 0) {
|
|
82835
|
+
cleanupEntryFiles();
|
|
82836
|
+
try {
|
|
82837
|
+
unlinkSync(temp);
|
|
82838
|
+
} catch {
|
|
82839
|
+
}
|
|
82840
|
+
return {
|
|
82841
|
+
created: false,
|
|
82842
|
+
alreadyExisted: false,
|
|
82843
|
+
error: (conv.stderr || "plutil could not encode the smart mailbox entry").trim()
|
|
82844
|
+
};
|
|
82845
|
+
}
|
|
82846
|
+
const ins = spawnSync2("/usr/libexec/PlistBuddy", ["-c", `Merge ${entryPlist} :`, temp], {
|
|
82847
|
+
encoding: "utf8"
|
|
82848
|
+
});
|
|
82849
|
+
cleanupEntryFiles();
|
|
82825
82850
|
if (ins.status !== 0) {
|
|
82826
82851
|
try {
|
|
82827
82852
|
unlinkSync(temp);
|
|
@@ -82830,7 +82855,7 @@ ${this.errorEmit(" ")}
|
|
|
82830
82855
|
return {
|
|
82831
82856
|
created: false,
|
|
82832
82857
|
alreadyExisted: false,
|
|
82833
|
-
error: (ins.stderr || "
|
|
82858
|
+
error: (ins.stderr || "PlistBuddy merge failed").trim()
|
|
82834
82859
|
};
|
|
82835
82860
|
}
|
|
82836
82861
|
if (!this.commitSmartPlist(temp, plistPath)) {
|
|
@@ -84129,8 +84154,18 @@ var defaultConnect = async (cfg) => {
|
|
|
84129
84154
|
}
|
|
84130
84155
|
return client;
|
|
84131
84156
|
};
|
|
84132
|
-
|
|
84133
|
-
|
|
84157
|
+
var SPECIAL_USE_ALIASES = {
|
|
84158
|
+
"all mail": "\\all",
|
|
84159
|
+
archive: "\\archive",
|
|
84160
|
+
drafts: "\\drafts",
|
|
84161
|
+
sent: "\\sent",
|
|
84162
|
+
"sent mail": "\\sent",
|
|
84163
|
+
trash: "\\trash",
|
|
84164
|
+
spam: "\\junk",
|
|
84165
|
+
junk: "\\junk",
|
|
84166
|
+
starred: "\\flagged"
|
|
84167
|
+
};
|
|
84168
|
+
function staticMailboxAlias(mailbox) {
|
|
84134
84169
|
const map = {
|
|
84135
84170
|
"all mail": "[Gmail]/All Mail",
|
|
84136
84171
|
"sent mail": "[Gmail]/Sent Mail",
|
|
@@ -84144,6 +84179,21 @@ function resolveMailboxPath(mailbox, _mode) {
|
|
|
84144
84179
|
};
|
|
84145
84180
|
return map[mailbox.trim().toLowerCase()] ?? mailbox;
|
|
84146
84181
|
}
|
|
84182
|
+
async function resolveMailboxPath(client, mailbox, _mode) {
|
|
84183
|
+
if (!mailbox) return "INBOX";
|
|
84184
|
+
try {
|
|
84185
|
+
const resolved = await resolveMailbox(client, mailbox);
|
|
84186
|
+
if (resolved.kind === "found") return resolved.path;
|
|
84187
|
+
const flag = SPECIAL_USE_ALIASES[mailbox.trim().toLowerCase()];
|
|
84188
|
+
if (flag) {
|
|
84189
|
+
const boxes = await client.list();
|
|
84190
|
+
const special = boxes.find((b) => b.specialUse?.toLowerCase() === flag);
|
|
84191
|
+
if (special) return special.path;
|
|
84192
|
+
}
|
|
84193
|
+
} catch {
|
|
84194
|
+
}
|
|
84195
|
+
return staticMailboxAlias(mailbox);
|
|
84196
|
+
}
|
|
84147
84197
|
function buildCriteria(a, listMode) {
|
|
84148
84198
|
const c = {};
|
|
84149
84199
|
if (a.query) c.or = [{ subject: a.query }, { from: a.query }];
|
|
@@ -84252,7 +84302,7 @@ async function run(args, listMode, deps) {
|
|
|
84252
84302
|
throw new Error(`No selectable IMAP mailboxes found for account ${cfg.accountLabel}.`);
|
|
84253
84303
|
}
|
|
84254
84304
|
} else {
|
|
84255
|
-
paths = [resolveMailboxPath(args.mailbox, listMode ? "list" : "search")];
|
|
84305
|
+
paths = [await resolveMailboxPath(client, args.mailbox, listMode ? "list" : "search")];
|
|
84256
84306
|
}
|
|
84257
84307
|
const limit = args.limit ?? 50;
|
|
84258
84308
|
const offset = args.offset ?? 0;
|
|
@@ -84328,7 +84378,9 @@ function imapUnreadCount(mailbox, deps = {}) {
|
|
|
84328
84378
|
return useClient(
|
|
84329
84379
|
deps,
|
|
84330
84380
|
async (client) => {
|
|
84331
|
-
const s = await client.status(resolveMailboxPath(mailbox, "list"), {
|
|
84381
|
+
const s = await client.status(await resolveMailboxPath(client, mailbox, "list"), {
|
|
84382
|
+
unseen: true
|
|
84383
|
+
});
|
|
84332
84384
|
return s.unseen ?? 0;
|
|
84333
84385
|
},
|
|
84334
84386
|
true
|
|
@@ -84760,7 +84812,7 @@ async function imapMoveMessageById(id, destMailbox, deps = {}) {
|
|
|
84760
84812
|
error: ambiguousMailboxError(destMailbox, dest.candidates, cfg.accountLabel)
|
|
84761
84813
|
};
|
|
84762
84814
|
}
|
|
84763
|
-
const destPath = dest.kind === "found" ? dest.path : resolveMailboxPath(destMailbox, "list");
|
|
84815
|
+
const destPath = dest.kind === "found" ? dest.path : await resolveMailboxPath(client, destMailbox, "list");
|
|
84764
84816
|
const lock = await client.getMailboxLock(ref.path);
|
|
84765
84817
|
try {
|
|
84766
84818
|
const moved = assertMutated(
|
|
@@ -84797,7 +84849,7 @@ async function resolveTrashPath(client) {
|
|
|
84797
84849
|
if (named) return named.path;
|
|
84798
84850
|
} catch {
|
|
84799
84851
|
}
|
|
84800
|
-
if (!listed) return
|
|
84852
|
+
if (!listed) return staticMailboxAlias("trash");
|
|
84801
84853
|
try {
|
|
84802
84854
|
const created = await client.mailboxCreate(FALLBACK_TRASH_PATH);
|
|
84803
84855
|
return created?.path || FALLBACK_TRASH_PATH;
|
|
@@ -85051,7 +85103,7 @@ function imapBatchMove(ids, destMailbox, deps = {}) {
|
|
|
85051
85103
|
ids,
|
|
85052
85104
|
deps,
|
|
85053
85105
|
async (c, uids) => {
|
|
85054
|
-
const dest = await findMailboxPathOrThrow(c, destMailbox) ?? resolveMailboxPath(destMailbox, "list");
|
|
85106
|
+
const dest = await findMailboxPathOrThrow(c, destMailbox) ?? await resolveMailboxPath(c, destMailbox, "list");
|
|
85055
85107
|
assertMutated(
|
|
85056
85108
|
await c.messageMove(uids, dest, { uid: true }),
|
|
85057
85109
|
`IMAP move of ${uids.length} message(s) to "${dest}"`
|
package/package.json
CHANGED