@mgcrea/mcp-apple-mail 1.3.0 → 1.3.1
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/dist/cli.js +1 -1
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/{server-CYFxflV5.js → server-Cs0iy6g6.js} +260 -12
- package/dist/server-Cs0iy6g6.js.map +1 -0
- package/package.json +2 -2
- package/dist/server-CYFxflV5.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as loadConfig, b as MAIL_SURFACE, j as BUILD_INFO, r as createServer } from "./server-
|
|
2
|
+
import { a as loadConfig, b as MAIL_SURFACE, j as BUILD_INFO, r as createServer } from "./server-Cs0iy6g6.js";
|
|
3
3
|
import { runStdioServer } from "@mgcrea/mcp-apple-core";
|
|
4
4
|
//#region src/cli.ts
|
|
5
5
|
const LOG_PREFIX = "apple-mail-mcp";
|
package/dist/index.d.ts
CHANGED
|
@@ -357,6 +357,31 @@ declare class AppleMailClient {
|
|
|
357
357
|
* answer does not change while the process lives.
|
|
358
358
|
*/
|
|
359
359
|
locate(force?: boolean): Promise<LocateResult>;
|
|
360
|
+
/**
|
|
361
|
+
* Whether the composer can be reached, and which grant is missing if not.
|
|
362
|
+
*
|
|
363
|
+
* Reported by diagnostics rather than only discovered on a failed reply.
|
|
364
|
+
* Automation-to-Mail and Full Disk Access being granted says nothing about
|
|
365
|
+
* either of these, and every read tool works without them — so the only
|
|
366
|
+
* signal used to be a `COMPOSER_NOT_FOUND` on a window that was
|
|
367
|
+
* demonstrably on screen, with no way to tell which permission was at fault.
|
|
368
|
+
*
|
|
369
|
+
* Never throws. A probe that cannot answer must not be the reason
|
|
370
|
+
* diagnostics fails, and "unknown" is an honest third state.
|
|
371
|
+
*/
|
|
372
|
+
composerAccess(): Promise<{
|
|
373
|
+
accessibility: "granted" | "denied" | "unknown";
|
|
374
|
+
systemEvents: "granted" | "denied" | "notDetermined" | "error" | "unknown";
|
|
375
|
+
/**
|
|
376
|
+
* Whether Mail's UI could actually be read, which is the only one of these
|
|
377
|
+
* three that is evidence rather than a claim. The flag above answers for an
|
|
378
|
+
* identity and has been caught disagreeing with what the same process can
|
|
379
|
+
* do; `inconclusive` is Mail with no windows open, where nothing can be
|
|
380
|
+
* concluded either way.
|
|
381
|
+
*/
|
|
382
|
+
uiRead: "granted" | "denied" | "inconclusive" | "unknown";
|
|
383
|
+
windows: (string | null)[] | null;
|
|
384
|
+
}>;
|
|
360
385
|
lanes(): Promise<LaneStatus>;
|
|
361
386
|
listMailboxes(opts: {
|
|
362
387
|
accountUuids?: string[];
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/build-info.ts","../src/client/errors.ts","../src/client/locate.ts","../src/config.ts","../src/client/mime.ts","../src/client/emlx.ts","../src/client/schema.ts","../src/client/envelope.ts","../src/client/mailbox-map.ts","../src/client/mail.ts","../src/client/ref.ts","../src/server.ts","../src/tools/index.ts"],"mappings":";;;;;cAkBa,YAAY;;;;cCWZ,6BAA6B;WACtB;EAElB,YAAY;;;;;;;;;;;;;;;;;;;;KCTF;;EAEV;;EAEA;EACA;;EAEA;EACA;EACA;EACA;EACA;;EAEA;EACA;EACA;;KAKU;;EAEV;;EAEA;;EAEA;;EAEA;;cAiBW,sBAAmB,OAAU,kBAAqB;;;;;;;;;;;;;;;cC3CzD,cAAY,EAAA;;;;;;;;;;;;;;;;;;;;;;GA8CP,EAAA,KAAA;KAEC,SAAS,EAAE,aAAa;;;;;cAMvB,aAAU,MAAS,OAAO,eAA2B;;;KCvDtD;EACV;EACA;EACA;;;;;;;;;EASA;;EAEA;;;;;;;;;;;;;;;;;;;;;KCEU;EACV,SAAS;EACT;EACA;;EAEA,cAAc;IAAe;;EAC7B;EACA;EACA;EACA;;;;KC1BU;EACV;EACA,QAAQ;EACR;IACE;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;;EAGF;EACA;EACA;;;;KChBU;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;KAGU;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;KAOU;EACV,IAAI;;EAEJ;EACA,MAAM;;cA+BK;;WAEF,MAAM;WACN;EAET,YAAY,QAAQ;EAMpB;;EASA;IAAe;IAAe;IAAa;IAAsB;;EA2CjE,OAAO,SAAS,gBAAgB;EAoFhC,MAAM,SAAS,KAAK;IAAuC;IAAe;;;EAa1E,OAAO,wBAAwB,gBAAgB;;EAmC/C,eAAe;;;;;;;;;;;;;KCpRL;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;KAGU;EACV,QAAQ;;EAER;EACA;EACA;;cAGW;;EAQX,YAAY,MAAM;EAeZ,SAAS,kBAAgB,QAAQ;;EAWjC,eAAe,iBAAiB,QAAQ;;;;;;EAmB9C,mBAAmB,SAAS,aAAa;;;;;;EAwBnC,gBAAgB,cAAc;IAAU,SAAS;IAAa;;EAepE;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/build-info.ts","../src/client/errors.ts","../src/client/locate.ts","../src/config.ts","../src/client/mime.ts","../src/client/emlx.ts","../src/client/schema.ts","../src/client/envelope.ts","../src/client/mailbox-map.ts","../src/client/mail.ts","../src/client/ref.ts","../src/server.ts","../src/tools/index.ts"],"mappings":";;;;;cAkBa,YAAY;;;;cCWZ,6BAA6B;WACtB;EAElB,YAAY;;;;;;;;;;;;;;;;;;;;KCTF;;EAEV;;EAEA;EACA;;EAEA;EACA;EACA;EACA;EACA;;EAEA;EACA;EACA;;KAKU;;EAEV;;EAEA;;EAEA;;EAEA;;cAiBW,sBAAmB,OAAU,kBAAqB;;;;;;;;;;;;;;;cC3CzD,cAAY,EAA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;;;;;;;;;;;;;EAkDI,YACJ,aACA;IAAQ;IAAc;MACrB,QAAQ;EAoBL,gBAAgB,mBAAmB;EAKnC,YAAY;IAChB;IACA;IACA;IACA;IACA;IACA;IACA;MACE;EAaE,eACJ,aACA;IACE;IACA;IACA;IACA;IACA;MAED;;;;;;;;;;;;;;;;;;;;;cC/mCQ;KAED;EACV;EACA;EACA;;cAKW,YAAS,KAAS;cAGlB,YAAS,gBAAkB;;cA2B3B,qBAAkB,MAAU,iBAAe,YAAY;;;cChDvD;cACA;KAED;EACV,QAAQ;EACR,SAAS;;EAET,YAAY;;KAGF;EACV,QAAQ;EACR,QAAQ;;;;;;;cAQG,eAAY,MAAU,wBAAsB;;;KCtB7C;;;;;EAKV;;;;;;;;;;;;cAaW,gBAAa,QAChB,WAAS,QACT,iBAAe,KAClB"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as WritesDisabledError, C as MessageNotFoundError, D as ProtocolError, E as PreconditionError, O as SchemaDriftError, S as MailNotRunningError, T as PlatformError, _ as locateEnvelopeIndex, a as loadConfig, c as decodeRef, d as assertStaticScript, f as createOsascriptRunner, g as inspectFile, h as MailboxMap, i as registerTools, j as BUILD_INFO, k as TccDeniedError, l as encodeRef, m as withBusyRetry, n as SERVER_VERSION, o as AppleMailClient, p as mapOsaError, r as createServer, s as REF_VERSION, t as SERVER_NAME, u as groupRefsByMailbox, v as AppleMailError, w as OsascriptTimeoutError, x as MailBusyError, y as IndexUnavailableError } from "./server-
|
|
1
|
+
import { A as WritesDisabledError, C as MessageNotFoundError, D as ProtocolError, E as PreconditionError, O as SchemaDriftError, S as MailNotRunningError, T as PlatformError, _ as locateEnvelopeIndex, a as loadConfig, c as decodeRef, d as assertStaticScript, f as createOsascriptRunner, g as inspectFile, h as MailboxMap, i as registerTools, j as BUILD_INFO, k as TccDeniedError, l as encodeRef, m as withBusyRetry, n as SERVER_VERSION, o as AppleMailClient, p as mapOsaError, r as createServer, s as REF_VERSION, t as SERVER_NAME, u as groupRefsByMailbox, v as AppleMailError, w as OsascriptTimeoutError, x as MailBusyError, y as IndexUnavailableError } from "./server-Cs0iy6g6.js";
|
|
2
2
|
export { AppleMailClient, AppleMailError, BUILD_INFO, IndexUnavailableError, MailBusyError, MailNotRunningError, MailboxMap, MessageNotFoundError, OsascriptTimeoutError, PlatformError, PreconditionError, ProtocolError, REF_VERSION, SERVER_NAME, SERVER_VERSION, SchemaDriftError, TccDeniedError, WritesDisabledError, assertStaticScript, createOsascriptRunner, createServer, decodeRef, encodeRef, groupRefsByMailbox, inspectFile, loadConfig, locateEnvelopeIndex, mapOsaError, registerTools, withBusyRetry };
|
|
@@ -12,8 +12,8 @@ const pkg = readPackageIdentity(new URL("../package.json", import.meta.url), {
|
|
|
12
12
|
const BUILD_INFO = {
|
|
13
13
|
name: pkg.name,
|
|
14
14
|
version: pkg.version,
|
|
15
|
-
gitCommit: "
|
|
16
|
-
gitCommitDate: "2026-08-
|
|
15
|
+
gitCommit: "312147f",
|
|
16
|
+
gitCommitDate: "2026-08-27T16:06:37+02:00"
|
|
17
17
|
};
|
|
18
18
|
//#endregion
|
|
19
19
|
//#region src/client/errors.ts
|
|
@@ -969,6 +969,10 @@ var EnvelopeIndex = class {
|
|
|
969
969
|
*/
|
|
970
970
|
const PRELUDE = `
|
|
971
971
|
ObjC.import("AppKit");
|
|
972
|
+
// For AXIsProcessTrusted, read by composerReach. AppKit does not
|
|
973
|
+
// reliably pull it in, and an unbridged symbol would throw rather than
|
|
974
|
+
// answer.
|
|
975
|
+
ObjC.import("ApplicationServices");
|
|
972
976
|
|
|
973
977
|
function isMailRunning() {
|
|
974
978
|
var apps = $.NSRunningApplication.runningApplicationsWithBundleIdentifier("com.apple.mail");
|
|
@@ -1100,6 +1104,104 @@ function composerBodySize(body) {
|
|
|
1100
1104
|
return prop(function () { return body.entireContents().length; }, -1);
|
|
1101
1105
|
}
|
|
1102
1106
|
|
|
1107
|
+
/**
|
|
1108
|
+
* Can this process actually read Mail's UI, right now?
|
|
1109
|
+
*
|
|
1110
|
+
* Asked BEFORE a composer is opened, because the alternative is what shipped:
|
|
1111
|
+
* M.reply opens a window, the accessibility read fails, and the user is left
|
|
1112
|
+
* with an empty reply window on screen and an error telling them to close it by
|
|
1113
|
+
* hand. Every retry left another one. Nothing about that failure needed the
|
|
1114
|
+
* window to exist first -- the grants it depends on can be read in one event.
|
|
1115
|
+
*
|
|
1116
|
+
* Ground truth here is the functional read, not AXIsProcessTrusted. The two
|
|
1117
|
+
* disagree: MEASURED on macOS 26.6, Cupertino.app's own process reports trusted
|
|
1118
|
+
* while an osascript grandchild of it reports the opposite, so a gate that
|
|
1119
|
+
* believed the flag alone would refuse replies on a Mac where the mechanism
|
|
1120
|
+
* works. A window list that comes back named is proof regardless of what the
|
|
1121
|
+
* flag says; the flag only breaks the tie when Mail has no windows at all.
|
|
1122
|
+
*
|
|
1123
|
+
* Returns { ok, reason, windows }. The reason separates the two grants that fail
|
|
1124
|
+
* identically once inside a composer: "systemEvents" when System Events cannot
|
|
1125
|
+
* be addressed at all, "accessibility" when it can but its UI is unreadable.
|
|
1126
|
+
*/
|
|
1127
|
+
function composerReach(SE) {
|
|
1128
|
+
try {
|
|
1129
|
+
SE.processes.name();
|
|
1130
|
+
} catch (e) {
|
|
1131
|
+
return { ok: false, reason: "systemEvents", windows: null };
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
var names;
|
|
1135
|
+
try {
|
|
1136
|
+
var proc = SE.processes.byName("Mail");
|
|
1137
|
+
names = proc.windows().map(function (w) {
|
|
1138
|
+
try { return w.name(); } catch (e2) { return null; }
|
|
1139
|
+
});
|
|
1140
|
+
} catch (e) {
|
|
1141
|
+
return { ok: false, reason: "accessibility", windows: null };
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
if (names.length) return { ok: true, reason: null, windows: names };
|
|
1145
|
+
|
|
1146
|
+
// Mail with no windows at all is legitimate -- everything closed down to the
|
|
1147
|
+
// menu bar -- so an empty list is not evidence of anything on its own, and
|
|
1148
|
+
// refusing on it would break a reply that would have worked.
|
|
1149
|
+
var trusted = false;
|
|
1150
|
+
try { trusted = $.AXIsProcessTrusted(); } catch (e) { trusted = false; }
|
|
1151
|
+
return trusted
|
|
1152
|
+
? { ok: true, reason: null, windows: names }
|
|
1153
|
+
: { ok: false, reason: "accessibility", windows: names };
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
/**
|
|
1157
|
+
* The sentence to say when a composer cannot be reached.
|
|
1158
|
+
*
|
|
1159
|
+
* Shared by the pre-flight and by the post-open failure so the two cannot drift
|
|
1160
|
+
* apart, and because the advice is identical: the reason a window is unreadable
|
|
1161
|
+
* is never anything the caller did.
|
|
1162
|
+
*/
|
|
1163
|
+
function composerGrantMessage(mode, reach) {
|
|
1164
|
+
var head =
|
|
1165
|
+
reach.reason === "systemEvents"
|
|
1166
|
+
? "Cupertino cannot address System Events at all, which is the only route into a Mail " +
|
|
1167
|
+
"composer, so the " + mode + " was not started and nothing was written."
|
|
1168
|
+
: "Cupertino cannot read Mail's windows, which is the only route into a " + mode + " " +
|
|
1169
|
+
"composer, so it was not started and nothing was written.";
|
|
1170
|
+
return (
|
|
1171
|
+
head +
|
|
1172
|
+
" Reaching a composer needs BOTH Accessibility and Automation to System Events -- the latter " +
|
|
1173
|
+
"a different grant from Automation to Mail, which is why every other tool still works. Both " +
|
|
1174
|
+
"belong to /Applications/Cupertino.app, NOT to your terminal and NOT to node: the app is the " +
|
|
1175
|
+
"process macOS holds responsible and every server inherits its identity. Accessibility is in " +
|
|
1176
|
+
"System Settings > Privacy & Security > Accessibility; Automation is under Automation. If the " +
|
|
1177
|
+
"app is already listed, toggle it off and on -- the grant goes stale when the bundle is " +
|
|
1178
|
+
"reinstalled. Then QUIT CUPERTINO AND OPEN IT AGAIN: the servers are children of the running " +
|
|
1179
|
+
"app, and a child started before the grant does not see it. Run apple_mail_diagnostics to " +
|
|
1180
|
+
"check, which reports the two grants separately and names the windows it can see."
|
|
1181
|
+
);
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
/**
|
|
1185
|
+
* Close a composer this script opened, when nothing of the user's is in it.
|
|
1186
|
+
*
|
|
1187
|
+
* Only ever called on a window put on screen moments earlier and provably not
|
|
1188
|
+
* written to. Without it every failed attempt leaves an empty reply window
|
|
1189
|
+
* behind, and the errors below had to end by asking the user to clean up after
|
|
1190
|
+
* the tool -- for a window that only exists because the tool opened it.
|
|
1191
|
+
*
|
|
1192
|
+
* It goes through Mail's own scripting interface, which is working in every
|
|
1193
|
+
* state that reaches here: what fails on this path is reading the window, not
|
|
1194
|
+
* owning it.
|
|
1195
|
+
*/
|
|
1196
|
+
function discardComposer(M, draft) {
|
|
1197
|
+
try {
|
|
1198
|
+
M.close(draft, { saving: "no" });
|
|
1199
|
+
return true;
|
|
1200
|
+
} catch (e) {
|
|
1201
|
+
return false;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1103
1205
|
/**
|
|
1104
1206
|
* Find the composer Mail just opened, by the subject Mail gave it.
|
|
1105
1207
|
*
|
|
@@ -1477,6 +1579,89 @@ const GET_MESSAGES = script(`
|
|
|
1477
1579
|
* in one mailbox costs one Apple Event, not 50.
|
|
1478
1580
|
*/
|
|
1479
1581
|
/** Set any combination of read / flagged / flagIndex / junk on a batch of ids. */
|
|
1582
|
+
/**
|
|
1583
|
+
* The two grants a composer needs, probed separately.
|
|
1584
|
+
*
|
|
1585
|
+
* `composerWindow` reaches Mail's compose window through System Events, and
|
|
1586
|
+
* that single call sits behind TWO different permissions: Automation from the
|
|
1587
|
+
* responsible process to **System Events** (a distinct TCC row from Automation
|
|
1588
|
+
* to Mail, which every other write tool uses), and **Accessibility** for the
|
|
1589
|
+
* responsible process, which is what allows reading UI elements once System
|
|
1590
|
+
* Events will talk at all.
|
|
1591
|
+
*
|
|
1592
|
+
* They have to be reported separately because the failure cannot tell them
|
|
1593
|
+
* apart. `proc.windows()` is wrapped in `prop()`, which swallows the exception
|
|
1594
|
+
* and yields `[]`, so a denied Automation and a denied Accessibility both
|
|
1595
|
+
* arrive as "no window matched" — indistinguishable from Mail genuinely not
|
|
1596
|
+
* having opened one. The old message named Accessibility outright and was read
|
|
1597
|
+
* as authoritative; it was a guess with the other two possibilities hidden.
|
|
1598
|
+
*
|
|
1599
|
+
* The identity being probed is **Cupertino.app**, not the terminal and not
|
|
1600
|
+
* node: `scripts/spike-app-tcc` measured that the app is its own responsible
|
|
1601
|
+
* process and everything beneath it inherits that. This runs under the same
|
|
1602
|
+
* identity as the composer code, so it answers for the process that will
|
|
1603
|
+
* actually be refused.
|
|
1604
|
+
*/
|
|
1605
|
+
const COMPOSER_ACCESS = `
|
|
1606
|
+
ObjC.import("ApplicationServices");
|
|
1607
|
+
function run() {
|
|
1608
|
+
// Accessibility: reading UI elements out of another process.
|
|
1609
|
+
var accessibility = $.AXIsProcessTrusted() ? "granted" : "denied";
|
|
1610
|
+
|
|
1611
|
+
// Automation -> System Events: being allowed to address it at all. Distinct
|
|
1612
|
+
// from Automation -> Mail, and prompted for separately.
|
|
1613
|
+
var systemEvents = "unknown";
|
|
1614
|
+
var detail = null;
|
|
1615
|
+
try {
|
|
1616
|
+
var SE = Application("System Events");
|
|
1617
|
+
SE.processes.name();
|
|
1618
|
+
systemEvents = "granted";
|
|
1619
|
+
} catch (e) {
|
|
1620
|
+
var msg = String(e && e.message ? e.message : e);
|
|
1621
|
+
detail = msg;
|
|
1622
|
+
// Same vocabulary as Permissions.AutomationStatus in the app: -1743 is
|
|
1623
|
+
// errAEEventNotPermitted (refused), -1744 is errAEEventWouldRequireUserConsent
|
|
1624
|
+
// (never asked). They need different advice — one is a toggle to flip, the
|
|
1625
|
+
// other is a prompt nobody has seen yet — so they are not collapsed.
|
|
1626
|
+
if (msg.indexOf("-1743") !== -1) systemEvents = "denied";
|
|
1627
|
+
else if (msg.indexOf("-1744") !== -1) systemEvents = "notDetermined";
|
|
1628
|
+
else systemEvents = "error";
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
// The functional read, which outranks both flags above.
|
|
1632
|
+
//
|
|
1633
|
+
// MEASURED, macOS 26.6: Cupertino.app's own process answers AXIsProcessTrusted
|
|
1634
|
+
// true while an osascript grandchild of it answers false, so the flag
|
|
1635
|
+
// alone cannot say whether a composer is reachable -- it is a claim about an
|
|
1636
|
+
// identity, and this is the thing itself. Naming a window of Mail's needs
|
|
1637
|
+
// exactly the grants a composer needs, and opens nothing.
|
|
1638
|
+
var uiRead = "unknown";
|
|
1639
|
+
var windows = null;
|
|
1640
|
+
try {
|
|
1641
|
+
var proc = Application("System Events").processes.byName("Mail");
|
|
1642
|
+
windows = proc.windows().map(function (w) {
|
|
1643
|
+
try { return w.name(); } catch (e) { return null; }
|
|
1644
|
+
});
|
|
1645
|
+
// No windows is not evidence: Mail closed down to the menu bar reads the
|
|
1646
|
+
// same as Mail we are blind to.
|
|
1647
|
+
uiRead = windows.length ? "granted" : "inconclusive";
|
|
1648
|
+
} catch (e) {
|
|
1649
|
+
uiRead = "denied";
|
|
1650
|
+
windows = null;
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
return JSON.stringify({
|
|
1654
|
+
ok: true,
|
|
1655
|
+
data: {
|
|
1656
|
+
accessibility: accessibility,
|
|
1657
|
+
systemEvents: systemEvents,
|
|
1658
|
+
uiRead: uiRead,
|
|
1659
|
+
windows: windows,
|
|
1660
|
+
detail: detail,
|
|
1661
|
+
},
|
|
1662
|
+
});
|
|
1663
|
+
}
|
|
1664
|
+
`;
|
|
1480
1665
|
const SET_FLAGS = script(`
|
|
1481
1666
|
var acct = findAccount(M, p.accountUuid);
|
|
1482
1667
|
if (!acct) return err("ACCOUNT_NOT_FOUND", "No account with id " + p.accountUuid);
|
|
@@ -1992,6 +2177,15 @@ const REPLY_OR_FORWARD = script(`
|
|
|
1992
2177
|
return err("MESSAGE_NOT_FOUND", "No message " + p.id + " in " + p.mailbox);
|
|
1993
2178
|
}
|
|
1994
2179
|
|
|
2180
|
+
// Asked BEFORE anything is opened, and that ordering is the fix for the
|
|
2181
|
+
// failure this tool was best known for. The two grants below fail in exactly
|
|
2182
|
+
// the state where a composer is already on screen, so the old shape left an
|
|
2183
|
+
// empty reply window behind on every attempt and told the user to close it.
|
|
2184
|
+
// Nothing about the check needs the window to exist.
|
|
2185
|
+
var SE = Application("System Events");
|
|
2186
|
+
var reach = composerReach(SE);
|
|
2187
|
+
if (!reach.ok) return err("COMPOSER_NOT_FOUND", composerGrantMessage(p.mode, reach));
|
|
2188
|
+
|
|
1995
2189
|
// The window is opened even when sending immediately: it is where the body
|
|
1996
2190
|
// has to be typed, and sending from it sends what was verified rather than
|
|
1997
2191
|
// whatever the disconnected scripting object thinks it holds.
|
|
@@ -2005,16 +2199,23 @@ const REPLY_OR_FORWARD = script(`
|
|
|
2005
2199
|
var subject = String(prop(function () { return draft.subject(); }, ""));
|
|
2006
2200
|
if (!subject) return err("COMPOSER_NOT_FOUND", "Mail did not return a composer for the " + p.mode + ".");
|
|
2007
2201
|
|
|
2008
|
-
var SE = Application("System Events");
|
|
2009
2202
|
var proc = SE.processes.byName("Mail");
|
|
2010
2203
|
var win = composerWindow(proc, subject, 8000);
|
|
2011
2204
|
if (!win) {
|
|
2205
|
+
// The pre-flight passed and this still failed, so the grants are live and
|
|
2206
|
+
// the window is the problem. Nothing has been typed yet, so the composer we
|
|
2207
|
+
// opened is ours to take back.
|
|
2208
|
+
var closedUnreadable = discardComposer(M, draft);
|
|
2012
2209
|
return err(
|
|
2013
2210
|
"COMPOSER_NOT_FOUND",
|
|
2014
2211
|
"Mail was asked to open a " + p.mode + " window for \\"" + subject + "\\" and no such window " +
|
|
2015
|
-
"
|
|
2016
|
-
"
|
|
2017
|
-
"
|
|
2212
|
+
"was readable within 8s, although Mail's other windows read fine — so this is not a " +
|
|
2213
|
+
"permission. Nothing was written. Mail may still have been opening it. The windows visible " +
|
|
2214
|
+
"at the time were: " + JSON.stringify(reach.windows) + ". " +
|
|
2215
|
+
(closedUnreadable
|
|
2216
|
+
? "The composer was closed again without saving, so a retry is safe."
|
|
2217
|
+
: "The composer could NOT be closed from here — look for an empty " + p.mode +
|
|
2218
|
+
" window in Mail and close it, or a retry leaves a second one behind.")
|
|
2018
2219
|
);
|
|
2019
2220
|
}
|
|
2020
2221
|
|
|
@@ -2029,10 +2230,14 @@ const REPLY_OR_FORWARD = script(`
|
|
|
2029
2230
|
|
|
2030
2231
|
var bodyArea = findBodyArea(win, 0);
|
|
2031
2232
|
if (!bodyArea) {
|
|
2233
|
+
var closedNoBody = discardComposer(M, draft);
|
|
2032
2234
|
return err(
|
|
2033
2235
|
"COMPOSER_NOT_FOUND",
|
|
2034
2236
|
"The " + p.mode + " window for \\"" + subject + "\\" is open, but its body cannot be reached " +
|
|
2035
|
-
"through the accessibility interface, which is the only way into it. Nothing was written."
|
|
2237
|
+
"through the accessibility interface, which is the only way into it. Nothing was written. " +
|
|
2238
|
+
(closedNoBody
|
|
2239
|
+
? "The window was closed again without saving."
|
|
2240
|
+
: "The window could NOT be closed from here and is still on screen.")
|
|
2036
2241
|
);
|
|
2037
2242
|
}
|
|
2038
2243
|
|
|
@@ -2078,12 +2283,25 @@ const REPLY_OR_FORWARD = script(`
|
|
|
2078
2283
|
|
|
2079
2284
|
if (!bodyVerified) {
|
|
2080
2285
|
restore();
|
|
2286
|
+
// Take the window back only when it is provably still empty. A paste that
|
|
2287
|
+
// landed and could not be READ is a different thing from one that never
|
|
2288
|
+
// landed, and closing that one would destroy the reply with no way to get
|
|
2289
|
+
// it back -- so it is left on screen for the user to judge.
|
|
2290
|
+
var landed = composerBodySize(bodyArea) !== sizeBefore;
|
|
2291
|
+
var closedUnverified = landed ? false : discardComposer(M, draft);
|
|
2081
2292
|
return err(
|
|
2082
2293
|
"DRAFT_BODY_NOT_SET",
|
|
2083
|
-
"The " + p.mode + " window for \\"" + subject + "\\"
|
|
2084
|
-
"body did not go in: reading the composer back does not show the text that was sent.
|
|
2085
|
-
"
|
|
2086
|
-
|
|
2294
|
+
"The " + p.mode + " window for \\"" + subject + "\\" was opened and correctly addressed, but the " +
|
|
2295
|
+
"body did not go in: reading the composer back does not show the text that was sent. It " +
|
|
2296
|
+
"MUST NOT be described to the user as ready. " +
|
|
2297
|
+
(closedUnverified
|
|
2298
|
+
? "Nothing had landed in it, so it was closed again without saving and a retry is safe."
|
|
2299
|
+
: landed
|
|
2300
|
+
? "SOMETHING DID land in it that could not be read back, so it was left open rather " +
|
|
2301
|
+
"than discarded — look at it in Mail before retrying, because a retry would paste " +
|
|
2302
|
+
"the reply in twice."
|
|
2303
|
+
: "It could NOT be closed from here — close it in Mail before retrying, or the retry " +
|
|
2304
|
+
"leaves a second draft behind.")
|
|
2087
2305
|
);
|
|
2088
2306
|
}
|
|
2089
2307
|
}
|
|
@@ -2326,6 +2544,30 @@ var AppleMailClient = class {
|
|
|
2326
2544
|
});
|
|
2327
2545
|
return this.#located;
|
|
2328
2546
|
}
|
|
2547
|
+
/**
|
|
2548
|
+
* Whether the composer can be reached, and which grant is missing if not.
|
|
2549
|
+
*
|
|
2550
|
+
* Reported by diagnostics rather than only discovered on a failed reply.
|
|
2551
|
+
* Automation-to-Mail and Full Disk Access being granted says nothing about
|
|
2552
|
+
* either of these, and every read tool works without them — so the only
|
|
2553
|
+
* signal used to be a `COMPOSER_NOT_FOUND` on a window that was
|
|
2554
|
+
* demonstrably on screen, with no way to tell which permission was at fault.
|
|
2555
|
+
*
|
|
2556
|
+
* Never throws. A probe that cannot answer must not be the reason
|
|
2557
|
+
* diagnostics fails, and "unknown" is an honest third state.
|
|
2558
|
+
*/
|
|
2559
|
+
async composerAccess() {
|
|
2560
|
+
try {
|
|
2561
|
+
return await this.runner.run(COMPOSER_ACCESS);
|
|
2562
|
+
} catch {
|
|
2563
|
+
return {
|
|
2564
|
+
accessibility: "unknown",
|
|
2565
|
+
systemEvents: "unknown",
|
|
2566
|
+
uiRead: "unknown",
|
|
2567
|
+
windows: null
|
|
2568
|
+
};
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2329
2571
|
async lanes() {
|
|
2330
2572
|
/**
|
|
2331
2573
|
* Probe twice before declaring the lane dead.
|
|
@@ -3331,6 +3573,7 @@ const buildDiagnostics = async (client, ctx) => {
|
|
|
3331
3573
|
const lanes = await client.lanes();
|
|
3332
3574
|
const located = await client.locate();
|
|
3333
3575
|
const messageFile = await client.probeMessageFile();
|
|
3576
|
+
const composer = await client.composerAccess();
|
|
3334
3577
|
let accounts = [];
|
|
3335
3578
|
let accountsError = null;
|
|
3336
3579
|
try {
|
|
@@ -3367,6 +3610,11 @@ const buildDiagnostics = async (client, ctx) => {
|
|
|
3367
3610
|
},
|
|
3368
3611
|
permissions: {
|
|
3369
3612
|
automation: lanes.applescript === "live" ? "granted" : "denied-or-mail-not-running",
|
|
3613
|
+
accessibility: composer.accessibility,
|
|
3614
|
+
automationSystemEvents: composer.systemEvents,
|
|
3615
|
+
composerUiRead: composer.uiRead,
|
|
3616
|
+
...composer.windows ? { composerWindowsSeen: composer.windows } : {},
|
|
3617
|
+
...composer.uiRead === "granted" && composer.systemEvents === "granted" ? {} : { composerNote: "Filling a Mail composer goes through System Events, which needs BOTH of the above: Automation to System Events (a different grant from Automation to Mail) and Accessibility. Until both are granted, apple_mail_reply_to_message and apple_mail_forward_message fail with COMPOSER_NOT_FOUND while every other tool works. Grant them to the Cupertino bundle that is RUNNING — not to your terminal and not to node. Automation and Full Disk Access are inherited by the servers from it; Accessibility has been measured NOT to be, so a green row is necessary and not sufficient, and `composerUiRead` above is the only line that settles it. A development build at another path does not stand in for the installed one even though they share a bundle identifier — measured. Accessibility is in System Settings > Privacy & Security > Accessibility; Automation is under Automation. If the app is already listed, toggle it off and on — the grant goes stale when the bundle is reinstalled. Then quit Cupertino and open it again: the servers are children of the running app, and a child started before the grant does not see it — which is what `accessibility: denied` beside a green Accessibility row in Cupertino's own Settings means." },
|
|
3370
3618
|
fullDiskAccess: located.readable ? "granted" : located.exists ? "denied" : "unknown (no index file found)",
|
|
3371
3619
|
...located.readable ? {} : { howToGrant: [
|
|
3372
3620
|
"System Settings > Privacy & Security > Full Disk Access",
|
|
@@ -3956,4 +4204,4 @@ const createServer = (opts) => {
|
|
|
3956
4204
|
//#endregion
|
|
3957
4205
|
export { WritesDisabledError as A, MessageNotFoundError as C, ProtocolError as D, PreconditionError as E, SchemaDriftError as O, MailNotRunningError as S, PlatformError as T, locateEnvelopeIndex as _, loadConfig as a, MAIL_SURFACE as b, decodeRef as c, assertStaticScript as d, createOsascriptRunner as f, inspectFile as g, MailboxMap as h, registerTools as i, BUILD_INFO as j, TccDeniedError as k, encodeRef as l, withBusyRetry as m, SERVER_VERSION as n, AppleMailClient as o, mapOsaError as p, createServer as r, REF_VERSION as s, SERVER_NAME as t, groupRefsByMailbox as u, AppleMailError as v, OsascriptTimeoutError as w, MailBusyError as x, IndexUnavailableError as y };
|
|
3958
4206
|
|
|
3959
|
-
//# sourceMappingURL=server-
|
|
4207
|
+
//# sourceMappingURL=server-Cs0iy6g6.js.map
|