@mgcrea/mcp-apple-mail 1.3.0 → 1.4.0
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 +26 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/{server-CYFxflV5.js → server-CGg9tIuQ.js} +274 -12
- package/dist/server-CGg9tIuQ.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-CGg9tIuQ.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,32 @@ 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 an identity can be ambiguous: one bundle id was measured
|
|
379
|
+
* holding four Accessibility entries at once, with the app's own check and
|
|
380
|
+
* its servers' checks matching different ones. `inconclusive` is Mail with
|
|
381
|
+
* no windows open, where nothing can be concluded either way.
|
|
382
|
+
*/
|
|
383
|
+
uiRead: "granted" | "denied" | "inconclusive" | "unknown";
|
|
384
|
+
windows: (string | null)[] | null;
|
|
385
|
+
}>;
|
|
360
386
|
lanes(): Promise<LaneStatus>;
|
|
361
387
|
listMailboxes(opts: {
|
|
362
388
|
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,s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;;;;;;EAuCI,cACJ,cACA,mBACC;IACD;IACA;IACA;IACA;IACA;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;cChnCQ;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-CGg9tIuQ.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: "1779320",
|
|
16
|
+
gitCommitDate: "2026-08-30T12:29:09+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,115 @@ 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 do
|
|
1117
|
+
* disagree. MEASURED, macOS 26.6: Cupertino.app's own process reported trusted
|
|
1118
|
+
* while an osascript grandchild of it reported the opposite and could not name
|
|
1119
|
+
* a single Mail window -- a green Accessibility row in System Settings beside a
|
|
1120
|
+
* reply that failed every time.
|
|
1121
|
+
*
|
|
1122
|
+
* The cause was not attribution, which was correct throughout (launchctl put
|
|
1123
|
+
* the responsible pid of the node server at the app). It was that ONE BUNDLE
|
|
1124
|
+
* IDENTIFIER CAN HOLD SEVERAL ACCESSIBILITY ENTRIES AT ONCE, one per path and
|
|
1125
|
+
* signature it has been granted at -- an installed copy, a debug build, each
|
|
1126
|
+
* earlier reinstall. tccutil reported resetting four of them for
|
|
1127
|
+
* io.mgcrea.cupertino. The app's own check matched one and the requests made on
|
|
1128
|
+
* its behalf were resolved against another.
|
|
1129
|
+
*
|
|
1130
|
+
* So the flag is a claim about an identity that may be ambiguous, and this is
|
|
1131
|
+
* the thing itself. A window list that comes back named is proof regardless of
|
|
1132
|
+
* what the flag says; the flag only breaks the tie when Mail has no windows.
|
|
1133
|
+
*
|
|
1134
|
+
* Returns { ok, reason, windows }. The reason separates the two grants that fail
|
|
1135
|
+
* identically once inside a composer: "systemEvents" when System Events cannot
|
|
1136
|
+
* be addressed at all, "accessibility" when it can but its UI is unreadable.
|
|
1137
|
+
*/
|
|
1138
|
+
function composerReach(SE) {
|
|
1139
|
+
try {
|
|
1140
|
+
SE.processes.name();
|
|
1141
|
+
} catch (e) {
|
|
1142
|
+
return { ok: false, reason: "systemEvents", windows: null };
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
var names;
|
|
1146
|
+
try {
|
|
1147
|
+
var proc = SE.processes.byName("Mail");
|
|
1148
|
+
names = proc.windows().map(function (w) {
|
|
1149
|
+
try { return w.name(); } catch (e2) { return null; }
|
|
1150
|
+
});
|
|
1151
|
+
} catch (e) {
|
|
1152
|
+
return { ok: false, reason: "accessibility", windows: null };
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
if (names.length) return { ok: true, reason: null, windows: names };
|
|
1156
|
+
|
|
1157
|
+
// Mail with no windows at all is legitimate -- everything closed down to the
|
|
1158
|
+
// menu bar -- so an empty list is not evidence of anything on its own, and
|
|
1159
|
+
// refusing on it would break a reply that would have worked.
|
|
1160
|
+
var trusted = false;
|
|
1161
|
+
try { trusted = $.AXIsProcessTrusted(); } catch (e) { trusted = false; }
|
|
1162
|
+
return trusted
|
|
1163
|
+
? { ok: true, reason: null, windows: names }
|
|
1164
|
+
: { ok: false, reason: "accessibility", windows: names };
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
/**
|
|
1168
|
+
* The sentence to say when a composer cannot be reached.
|
|
1169
|
+
*
|
|
1170
|
+
* Shared by the pre-flight and by the post-open failure so the two cannot drift
|
|
1171
|
+
* apart, and because the advice is identical: the reason a window is unreadable
|
|
1172
|
+
* is never anything the caller did.
|
|
1173
|
+
*/
|
|
1174
|
+
function composerGrantMessage(mode, reach) {
|
|
1175
|
+
var head =
|
|
1176
|
+
reach.reason === "systemEvents"
|
|
1177
|
+
? "Cupertino cannot address System Events at all, which is the only route into a Mail " +
|
|
1178
|
+
"composer, so the " + mode + " was not started and nothing was written."
|
|
1179
|
+
: "Cupertino cannot read Mail's windows, which is the only route into a " + mode + " " +
|
|
1180
|
+
"composer, so it was not started and nothing was written.";
|
|
1181
|
+
return (
|
|
1182
|
+
head +
|
|
1183
|
+
" Reaching a composer needs BOTH Accessibility and Automation to System Events -- the latter " +
|
|
1184
|
+
"a different grant from Automation to Mail, which is why every other tool still works. Both " +
|
|
1185
|
+
"belong to /Applications/Cupertino.app, NOT to your terminal and NOT to node: the app is the " +
|
|
1186
|
+
"process macOS holds responsible and every server inherits its identity. Accessibility is in " +
|
|
1187
|
+
"System Settings > Privacy & Security > Accessibility; Automation is under Automation. If the " +
|
|
1188
|
+
"app is already listed, toggle it off and on -- the grant goes stale when the bundle is " +
|
|
1189
|
+
"reinstalled. Then QUIT CUPERTINO AND OPEN IT AGAIN: the servers are children of the running " +
|
|
1190
|
+
"app, and a child started before the grant does not see it. Run apple_mail_diagnostics to " +
|
|
1191
|
+
"check, which reports the two grants separately and names the windows it can see."
|
|
1192
|
+
);
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
/**
|
|
1196
|
+
* Close a composer this script opened, when nothing of the user's is in it.
|
|
1197
|
+
*
|
|
1198
|
+
* Only ever called on a window put on screen moments earlier and provably not
|
|
1199
|
+
* written to. Without it every failed attempt leaves an empty reply window
|
|
1200
|
+
* behind, and the errors below had to end by asking the user to clean up after
|
|
1201
|
+
* the tool -- for a window that only exists because the tool opened it.
|
|
1202
|
+
*
|
|
1203
|
+
* It goes through Mail's own scripting interface, which is working in every
|
|
1204
|
+
* state that reaches here: what fails on this path is reading the window, not
|
|
1205
|
+
* owning it.
|
|
1206
|
+
*/
|
|
1207
|
+
function discardComposer(M, draft) {
|
|
1208
|
+
try {
|
|
1209
|
+
M.close(draft, { saving: "no" });
|
|
1210
|
+
return true;
|
|
1211
|
+
} catch (e) {
|
|
1212
|
+
return false;
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1103
1216
|
/**
|
|
1104
1217
|
* Find the composer Mail just opened, by the subject Mail gave it.
|
|
1105
1218
|
*
|
|
@@ -1477,6 +1590,92 @@ const GET_MESSAGES = script(`
|
|
|
1477
1590
|
* in one mailbox costs one Apple Event, not 50.
|
|
1478
1591
|
*/
|
|
1479
1592
|
/** Set any combination of read / flagged / flagIndex / junk on a batch of ids. */
|
|
1593
|
+
/**
|
|
1594
|
+
* The two grants a composer needs, probed separately.
|
|
1595
|
+
*
|
|
1596
|
+
* `composerWindow` reaches Mail's compose window through System Events, and
|
|
1597
|
+
* that single call sits behind TWO different permissions: Automation from the
|
|
1598
|
+
* responsible process to **System Events** (a distinct TCC row from Automation
|
|
1599
|
+
* to Mail, which every other write tool uses), and **Accessibility** for the
|
|
1600
|
+
* responsible process, which is what allows reading UI elements once System
|
|
1601
|
+
* Events will talk at all.
|
|
1602
|
+
*
|
|
1603
|
+
* They have to be reported separately because the failure cannot tell them
|
|
1604
|
+
* apart. `proc.windows()` is wrapped in `prop()`, which swallows the exception
|
|
1605
|
+
* and yields `[]`, so a denied Automation and a denied Accessibility both
|
|
1606
|
+
* arrive as "no window matched" — indistinguishable from Mail genuinely not
|
|
1607
|
+
* having opened one. The old message named Accessibility outright and was read
|
|
1608
|
+
* as authoritative; it was a guess with the other two possibilities hidden.
|
|
1609
|
+
*
|
|
1610
|
+
* The identity being probed is **Cupertino.app**, not the terminal and not
|
|
1611
|
+
* node: `scripts/spike-app-tcc` measured that the app is its own responsible
|
|
1612
|
+
* process and everything beneath it inherits that. This runs under the same
|
|
1613
|
+
* identity as the composer code, so it answers for the process that will
|
|
1614
|
+
* actually be refused.
|
|
1615
|
+
*/
|
|
1616
|
+
const COMPOSER_ACCESS = `
|
|
1617
|
+
ObjC.import("ApplicationServices");
|
|
1618
|
+
function run() {
|
|
1619
|
+
// Accessibility: reading UI elements out of another process.
|
|
1620
|
+
var accessibility = $.AXIsProcessTrusted() ? "granted" : "denied";
|
|
1621
|
+
|
|
1622
|
+
// Automation -> System Events: being allowed to address it at all. Distinct
|
|
1623
|
+
// from Automation -> Mail, and prompted for separately.
|
|
1624
|
+
var systemEvents = "unknown";
|
|
1625
|
+
var detail = null;
|
|
1626
|
+
try {
|
|
1627
|
+
var SE = Application("System Events");
|
|
1628
|
+
SE.processes.name();
|
|
1629
|
+
systemEvents = "granted";
|
|
1630
|
+
} catch (e) {
|
|
1631
|
+
var msg = String(e && e.message ? e.message : e);
|
|
1632
|
+
detail = msg;
|
|
1633
|
+
// Same vocabulary as Permissions.AutomationStatus in the app: -1743 is
|
|
1634
|
+
// errAEEventNotPermitted (refused), -1744 is errAEEventWouldRequireUserConsent
|
|
1635
|
+
// (never asked). They need different advice — one is a toggle to flip, the
|
|
1636
|
+
// other is a prompt nobody has seen yet — so they are not collapsed.
|
|
1637
|
+
if (msg.indexOf("-1743") !== -1) systemEvents = "denied";
|
|
1638
|
+
else if (msg.indexOf("-1744") !== -1) systemEvents = "notDetermined";
|
|
1639
|
+
else systemEvents = "error";
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
// The functional read, which outranks both flags above.
|
|
1643
|
+
//
|
|
1644
|
+
// MEASURED, macOS 26.6: Cupertino.app's own process answered
|
|
1645
|
+
// AXIsProcessTrusted true while an osascript grandchild of it answered false,
|
|
1646
|
+
// because the same bundle identifier held four separate Accessibility entries
|
|
1647
|
+
// -- one per path and signature it had been granted at -- and the two checks
|
|
1648
|
+
// matched different ones. The flag alone therefore cannot say whether a
|
|
1649
|
+
// composer is reachable: it is a claim about an identity that may be
|
|
1650
|
+
// ambiguous, and this is the thing itself. Naming a window of Mail's needs
|
|
1651
|
+
// exactly the grants a composer needs, and opens nothing.
|
|
1652
|
+
var uiRead = "unknown";
|
|
1653
|
+
var windows = null;
|
|
1654
|
+
try {
|
|
1655
|
+
var proc = Application("System Events").processes.byName("Mail");
|
|
1656
|
+
windows = proc.windows().map(function (w) {
|
|
1657
|
+
try { return w.name(); } catch (e) { return null; }
|
|
1658
|
+
});
|
|
1659
|
+
// No windows is not evidence: Mail closed down to the menu bar reads the
|
|
1660
|
+
// same as Mail we are blind to.
|
|
1661
|
+
uiRead = windows.length ? "granted" : "inconclusive";
|
|
1662
|
+
} catch (e) {
|
|
1663
|
+
uiRead = "denied";
|
|
1664
|
+
windows = null;
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
return JSON.stringify({
|
|
1668
|
+
ok: true,
|
|
1669
|
+
data: {
|
|
1670
|
+
accessibility: accessibility,
|
|
1671
|
+
systemEvents: systemEvents,
|
|
1672
|
+
uiRead: uiRead,
|
|
1673
|
+
windows: windows,
|
|
1674
|
+
detail: detail,
|
|
1675
|
+
},
|
|
1676
|
+
});
|
|
1677
|
+
}
|
|
1678
|
+
`;
|
|
1480
1679
|
const SET_FLAGS = script(`
|
|
1481
1680
|
var acct = findAccount(M, p.accountUuid);
|
|
1482
1681
|
if (!acct) return err("ACCOUNT_NOT_FOUND", "No account with id " + p.accountUuid);
|
|
@@ -1992,6 +2191,15 @@ const REPLY_OR_FORWARD = script(`
|
|
|
1992
2191
|
return err("MESSAGE_NOT_FOUND", "No message " + p.id + " in " + p.mailbox);
|
|
1993
2192
|
}
|
|
1994
2193
|
|
|
2194
|
+
// Asked BEFORE anything is opened, and that ordering is the fix for the
|
|
2195
|
+
// failure this tool was best known for. The two grants below fail in exactly
|
|
2196
|
+
// the state where a composer is already on screen, so the old shape left an
|
|
2197
|
+
// empty reply window behind on every attempt and told the user to close it.
|
|
2198
|
+
// Nothing about the check needs the window to exist.
|
|
2199
|
+
var SE = Application("System Events");
|
|
2200
|
+
var reach = composerReach(SE);
|
|
2201
|
+
if (!reach.ok) return err("COMPOSER_NOT_FOUND", composerGrantMessage(p.mode, reach));
|
|
2202
|
+
|
|
1995
2203
|
// The window is opened even when sending immediately: it is where the body
|
|
1996
2204
|
// has to be typed, and sending from it sends what was verified rather than
|
|
1997
2205
|
// whatever the disconnected scripting object thinks it holds.
|
|
@@ -2005,16 +2213,23 @@ const REPLY_OR_FORWARD = script(`
|
|
|
2005
2213
|
var subject = String(prop(function () { return draft.subject(); }, ""));
|
|
2006
2214
|
if (!subject) return err("COMPOSER_NOT_FOUND", "Mail did not return a composer for the " + p.mode + ".");
|
|
2007
2215
|
|
|
2008
|
-
var SE = Application("System Events");
|
|
2009
2216
|
var proc = SE.processes.byName("Mail");
|
|
2010
2217
|
var win = composerWindow(proc, subject, 8000);
|
|
2011
2218
|
if (!win) {
|
|
2219
|
+
// The pre-flight passed and this still failed, so the grants are live and
|
|
2220
|
+
// the window is the problem. Nothing has been typed yet, so the composer we
|
|
2221
|
+
// opened is ours to take back.
|
|
2222
|
+
var closedUnreadable = discardComposer(M, draft);
|
|
2012
2223
|
return err(
|
|
2013
2224
|
"COMPOSER_NOT_FOUND",
|
|
2014
2225
|
"Mail was asked to open a " + p.mode + " window for \\"" + subject + "\\" and no such window " +
|
|
2015
|
-
"
|
|
2016
|
-
"
|
|
2017
|
-
"
|
|
2226
|
+
"was readable within 8s, although Mail's other windows read fine — so this is not a " +
|
|
2227
|
+
"permission. Nothing was written. Mail may still have been opening it. The windows visible " +
|
|
2228
|
+
"at the time were: " + JSON.stringify(reach.windows) + ". " +
|
|
2229
|
+
(closedUnreadable
|
|
2230
|
+
? "The composer was closed again without saving, so a retry is safe."
|
|
2231
|
+
: "The composer could NOT be closed from here — look for an empty " + p.mode +
|
|
2232
|
+
" window in Mail and close it, or a retry leaves a second one behind.")
|
|
2018
2233
|
);
|
|
2019
2234
|
}
|
|
2020
2235
|
|
|
@@ -2029,10 +2244,14 @@ const REPLY_OR_FORWARD = script(`
|
|
|
2029
2244
|
|
|
2030
2245
|
var bodyArea = findBodyArea(win, 0);
|
|
2031
2246
|
if (!bodyArea) {
|
|
2247
|
+
var closedNoBody = discardComposer(M, draft);
|
|
2032
2248
|
return err(
|
|
2033
2249
|
"COMPOSER_NOT_FOUND",
|
|
2034
2250
|
"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."
|
|
2251
|
+
"through the accessibility interface, which is the only way into it. Nothing was written. " +
|
|
2252
|
+
(closedNoBody
|
|
2253
|
+
? "The window was closed again without saving."
|
|
2254
|
+
: "The window could NOT be closed from here and is still on screen.")
|
|
2036
2255
|
);
|
|
2037
2256
|
}
|
|
2038
2257
|
|
|
@@ -2078,12 +2297,25 @@ const REPLY_OR_FORWARD = script(`
|
|
|
2078
2297
|
|
|
2079
2298
|
if (!bodyVerified) {
|
|
2080
2299
|
restore();
|
|
2300
|
+
// Take the window back only when it is provably still empty. A paste that
|
|
2301
|
+
// landed and could not be READ is a different thing from one that never
|
|
2302
|
+
// landed, and closing that one would destroy the reply with no way to get
|
|
2303
|
+
// it back -- so it is left on screen for the user to judge.
|
|
2304
|
+
var landed = composerBodySize(bodyArea) !== sizeBefore;
|
|
2305
|
+
var closedUnverified = landed ? false : discardComposer(M, draft);
|
|
2081
2306
|
return err(
|
|
2082
2307
|
"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
|
-
|
|
2308
|
+
"The " + p.mode + " window for \\"" + subject + "\\" was opened and correctly addressed, but the " +
|
|
2309
|
+
"body did not go in: reading the composer back does not show the text that was sent. It " +
|
|
2310
|
+
"MUST NOT be described to the user as ready. " +
|
|
2311
|
+
(closedUnverified
|
|
2312
|
+
? "Nothing had landed in it, so it was closed again without saving and a retry is safe."
|
|
2313
|
+
: landed
|
|
2314
|
+
? "SOMETHING DID land in it that could not be read back, so it was left open rather " +
|
|
2315
|
+
"than discarded — look at it in Mail before retrying, because a retry would paste " +
|
|
2316
|
+
"the reply in twice."
|
|
2317
|
+
: "It could NOT be closed from here — close it in Mail before retrying, or the retry " +
|
|
2318
|
+
"leaves a second draft behind.")
|
|
2087
2319
|
);
|
|
2088
2320
|
}
|
|
2089
2321
|
}
|
|
@@ -2326,6 +2558,30 @@ var AppleMailClient = class {
|
|
|
2326
2558
|
});
|
|
2327
2559
|
return this.#located;
|
|
2328
2560
|
}
|
|
2561
|
+
/**
|
|
2562
|
+
* Whether the composer can be reached, and which grant is missing if not.
|
|
2563
|
+
*
|
|
2564
|
+
* Reported by diagnostics rather than only discovered on a failed reply.
|
|
2565
|
+
* Automation-to-Mail and Full Disk Access being granted says nothing about
|
|
2566
|
+
* either of these, and every read tool works without them — so the only
|
|
2567
|
+
* signal used to be a `COMPOSER_NOT_FOUND` on a window that was
|
|
2568
|
+
* demonstrably on screen, with no way to tell which permission was at fault.
|
|
2569
|
+
*
|
|
2570
|
+
* Never throws. A probe that cannot answer must not be the reason
|
|
2571
|
+
* diagnostics fails, and "unknown" is an honest third state.
|
|
2572
|
+
*/
|
|
2573
|
+
async composerAccess() {
|
|
2574
|
+
try {
|
|
2575
|
+
return await this.runner.run(COMPOSER_ACCESS);
|
|
2576
|
+
} catch {
|
|
2577
|
+
return {
|
|
2578
|
+
accessibility: "unknown",
|
|
2579
|
+
systemEvents: "unknown",
|
|
2580
|
+
uiRead: "unknown",
|
|
2581
|
+
windows: null
|
|
2582
|
+
};
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2329
2585
|
async lanes() {
|
|
2330
2586
|
/**
|
|
2331
2587
|
* Probe twice before declaring the lane dead.
|
|
@@ -3331,6 +3587,7 @@ const buildDiagnostics = async (client, ctx) => {
|
|
|
3331
3587
|
const lanes = await client.lanes();
|
|
3332
3588
|
const located = await client.locate();
|
|
3333
3589
|
const messageFile = await client.probeMessageFile();
|
|
3590
|
+
const composer = await client.composerAccess();
|
|
3334
3591
|
let accounts = [];
|
|
3335
3592
|
let accountsError = null;
|
|
3336
3593
|
try {
|
|
@@ -3367,6 +3624,11 @@ const buildDiagnostics = async (client, ctx) => {
|
|
|
3367
3624
|
},
|
|
3368
3625
|
permissions: {
|
|
3369
3626
|
automation: lanes.applescript === "live" ? "granted" : "denied-or-mail-not-running",
|
|
3627
|
+
accessibility: composer.accessibility,
|
|
3628
|
+
automationSystemEvents: composer.systemEvents,
|
|
3629
|
+
composerUiRead: composer.uiRead,
|
|
3630
|
+
...composer.windows ? { composerWindowsSeen: composer.windows } : {},
|
|
3631
|
+
...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: the app is the process macOS holds responsible, and the servers do inherit its identity. If Cupertino's own Settings shows a GREEN Accessibility row while `composerUiRead` above says denied, believe this line and not the row: one bundle identifier can hold several Accessibility entries at once, one per path and signature it has been granted at (an installed copy, a development build, each earlier reinstall), and the two checks can match different ones. The cure is to clear them all and grant once, from the bundle that is running: `tccutil reset Accessibility io.mgcrea.cupertino`, then Ask… in Cupertino's Settings — it reported resetting FOUR entries the first time this was hit. 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
3632
|
fullDiskAccess: located.readable ? "granted" : located.exists ? "denied" : "unknown (no index file found)",
|
|
3371
3633
|
...located.readable ? {} : { howToGrant: [
|
|
3372
3634
|
"System Settings > Privacy & Security > Full Disk Access",
|
|
@@ -3956,4 +4218,4 @@ const createServer = (opts) => {
|
|
|
3956
4218
|
//#endregion
|
|
3957
4219
|
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
4220
|
|
|
3959
|
-
//# sourceMappingURL=server-
|
|
4221
|
+
//# sourceMappingURL=server-CGg9tIuQ.js.map
|