@mgcrea/mcp-apple-mail 1.36.0 → 1.36.2
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/README.md +1 -0
- package/dist/cli.js +3 -2
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +37 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/{server-DO3YS8Ds.js → server-ynr059Dx.js} +187 -62
- package/dist/server-ynr059Dx.js.map +1 -0
- package/package.json +2 -2
- package/dist/server-DO3YS8Ds.js.map +0 -1
|
@@ -14,8 +14,8 @@ const pkg = readPackageIdentity(new URL("../package.json", import.meta.url), {
|
|
|
14
14
|
const BUILD_INFO = {
|
|
15
15
|
name: pkg.name,
|
|
16
16
|
version: pkg.version,
|
|
17
|
-
gitCommit: "
|
|
18
|
-
gitCommitDate: "2026-
|
|
17
|
+
gitCommit: "64f8fc3",
|
|
18
|
+
gitCommitDate: "2026-11-03T23:19:14+01:00"
|
|
19
19
|
};
|
|
20
20
|
//#endregion
|
|
21
21
|
//#region src/client/errors.ts
|
|
@@ -156,15 +156,30 @@ const BODY_ROLE = "AXWebArea";
|
|
|
156
156
|
* holds a deeply nested quoted message — the web area itself sits near the top.
|
|
157
157
|
*/
|
|
158
158
|
const BODY_DEPTH = 8;
|
|
159
|
+
/** The window id an edit was refused for as being on another desktop; null for any other answer. */
|
|
160
|
+
const onAnotherDesktop = (result) => result.replaced === false && result.capability === "desktop" && typeof result.windowId === "number" ? result.windowId : null;
|
|
161
|
+
/** How long an edit waits for a composer brought from another desktop to arrive. */
|
|
162
|
+
const DESKTOP_TIMEOUT_MS = 3e3;
|
|
163
|
+
/** Between asks while it arrives. */
|
|
164
|
+
const DESKTOP_POLL_MS = 150;
|
|
159
165
|
var MailAxLane = class MailAxLane {
|
|
160
166
|
#channel;
|
|
161
|
-
|
|
167
|
+
/**
|
|
168
|
+
* Whether a draft ends by bringing back the app that was in front (config's
|
|
169
|
+
* `handBackAfterDraft`). Carried here so every edit and every `release`
|
|
170
|
+
* says it, whichever path made the draft.
|
|
171
|
+
*/
|
|
172
|
+
#handBack;
|
|
173
|
+
#desktopTimeoutMs;
|
|
174
|
+
constructor(channel, opts) {
|
|
162
175
|
this.#channel = channel;
|
|
176
|
+
this.#handBack = opts.handBack ?? false;
|
|
177
|
+
this.#desktopTimeoutMs = opts.desktopTimeoutMs ?? DESKTOP_TIMEOUT_MS;
|
|
163
178
|
}
|
|
164
179
|
/** Null when this server is not hosted by Cupertino — see the note above. */
|
|
165
|
-
static open(env = process.env) {
|
|
180
|
+
static open(env = process.env, opts = {}) {
|
|
166
181
|
const channel = openAxChannel(MAIL_SURFACE, env);
|
|
167
|
-
return channel ? new MailAxLane(channel) : null;
|
|
182
|
+
return channel ? new MailAxLane(channel, opts) : null;
|
|
168
183
|
}
|
|
169
184
|
close() {
|
|
170
185
|
this.#channel.close();
|
|
@@ -179,7 +194,12 @@ var MailAxLane = class MailAxLane {
|
|
|
179
194
|
args
|
|
180
195
|
});
|
|
181
196
|
}
|
|
182
|
-
/**
|
|
197
|
+
/**
|
|
198
|
+
* Every open composer, with its handle and own text. Those on another
|
|
199
|
+
* desktop (a Space, or Mail full screen) are listed too, read where they
|
|
200
|
+
* are, with `onAnotherDesktop`: the app finds them by the window server's
|
|
201
|
+
* count, which Accessibility's own list does not reach.
|
|
202
|
+
*/
|
|
183
203
|
async composers(quoteChars) {
|
|
184
204
|
return (await this.#call("mail_composers", quoteChars === void 0 ? {} : { quoteChars })).composers ?? [];
|
|
185
205
|
}
|
|
@@ -187,9 +207,51 @@ var MailAxLane = class MailAxLane {
|
|
|
187
207
|
* Edit a composer in one verified native step. The verb's JSON comes back
|
|
188
208
|
* verbatim: a refusal is an answer, not an error. A failure of the call itself
|
|
189
209
|
* (bad arguments, Accessibility not trusted) throws, as every `#call` does.
|
|
210
|
+
*
|
|
211
|
+
* A composer on another desktop is refused by the app before anything is
|
|
212
|
+
* touched, with its `windowId`. It is then brought forward here, which
|
|
213
|
+
* switches to its desktop, and asked about again until it is on the one
|
|
214
|
+
* shown or `desktopTimeoutMs` runs out: so every path that edits a
|
|
215
|
+
* composer (compose, revise, rebuild) reaches one wherever it is.
|
|
190
216
|
*/
|
|
191
217
|
async editComposer(args) {
|
|
192
|
-
|
|
218
|
+
const edit = async () => await this.#call("mail_composer_edit", {
|
|
219
|
+
...args,
|
|
220
|
+
handBack: this.#handBack
|
|
221
|
+
});
|
|
222
|
+
let result = await edit();
|
|
223
|
+
const windowId = onAnotherDesktop(result);
|
|
224
|
+
if (windowId === null || !await this.#bringForward(windowId)) return result;
|
|
225
|
+
const deadline = Date.now() + this.#desktopTimeoutMs;
|
|
226
|
+
for (;;) {
|
|
227
|
+
result = await edit();
|
|
228
|
+
if (onAnotherDesktop(result) === null || Date.now() >= deadline) return result;
|
|
229
|
+
await new Promise((resolve) => setTimeout(resolve, DESKTOP_POLL_MS));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Bring the window `windowId` onto the desktop shown, through the app's
|
|
234
|
+
* `mail_bring_forward`, which activates Mail, raises the window and says
|
|
235
|
+
* whether it landed. False when it did not, when the person said no to
|
|
236
|
+
* being driven, and from an app that predates the verb: the edit's own
|
|
237
|
+
* refusal then stands, naming the window.
|
|
238
|
+
*/
|
|
239
|
+
async #bringForward(windowId) {
|
|
240
|
+
try {
|
|
241
|
+
return (await this.#call("mail_bring_forward", { windowId })).broughtForward === true;
|
|
242
|
+
} catch {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* End the driving session a draft opened, now rather than on the app's idle
|
|
248
|
+
* release 45 seconds later, which brought back the app the person had been
|
|
249
|
+
* in while they were reading the draft. Whether it does that is the setting.
|
|
250
|
+
* Best effort: the draft is saved whatever this answers, and the app does
|
|
251
|
+
* not end a session that also drove another application.
|
|
252
|
+
*/
|
|
253
|
+
async release() {
|
|
254
|
+
await this.#call("mail_release", { handBack: this.#handBack }).catch(() => void 0);
|
|
193
255
|
}
|
|
194
256
|
/**
|
|
195
257
|
* Can this process read Mail's windows, right now?
|
|
@@ -1644,8 +1706,12 @@ function maxQuoteLevel(el, depth) {
|
|
|
1644
1706
|
* of a composer coming forward is worth less than a window stuck at [1, 1].
|
|
1645
1707
|
*
|
|
1646
1708
|
* Failure is reported, never fatal: a quoted send still beats a lost one.
|
|
1709
|
+
*
|
|
1710
|
+
* handBack false leaves Mail in front once the window is put back: a draft
|
|
1711
|
+
* the person is about to read (the Mail setting "Return to the previous app
|
|
1712
|
+
* after a draft", off).
|
|
1647
1713
|
*/
|
|
1648
|
-
function stripCitation(windowName) {
|
|
1714
|
+
function stripCitation(windowName, handBack) {
|
|
1649
1715
|
var SE = Application("System Events");
|
|
1650
1716
|
var proc = SE.processes.byName("Mail");
|
|
1651
1717
|
|
|
@@ -1713,7 +1779,7 @@ function stripCitation(windowName) {
|
|
|
1713
1779
|
// failure path too: a strip that threw must not cost the user their composer.
|
|
1714
1780
|
unhide();
|
|
1715
1781
|
|
|
1716
|
-
if (previous && previous !== "Mail") {
|
|
1782
|
+
if (handBack !== false && previous && previous !== "Mail") {
|
|
1717
1783
|
try { SE.processes.byName(previous).frontmost = true; } catch (e) {}
|
|
1718
1784
|
}
|
|
1719
1785
|
return stripped;
|
|
@@ -2322,7 +2388,9 @@ const SEND_MESSAGE = script(`
|
|
|
2322
2388
|
|
|
2323
2389
|
pause(1.2);
|
|
2324
2390
|
var unquoted = false;
|
|
2325
|
-
try {
|
|
2391
|
+
try {
|
|
2392
|
+
unquoted = stripCitation(String(p.subject || ""), p.sendNow || p.handBack !== false);
|
|
2393
|
+
} catch (e) { unquoted = false; }
|
|
2326
2394
|
|
|
2327
2395
|
/*
|
|
2328
2396
|
* Assigning content made Mail wrap the body in a quotation that Mail itself
|
|
@@ -2589,7 +2657,7 @@ const UPDATE_DRAFT = script(`
|
|
|
2589
2657
|
|
|
2590
2658
|
pause(1.2);
|
|
2591
2659
|
var unquoted = false;
|
|
2592
|
-
try { unquoted = stripCitation(subject); } catch (e) { unquoted = false; }
|
|
2660
|
+
try { unquoted = stripCitation(subject, p.handBack !== false); } catch (e) { unquoted = false; }
|
|
2593
2661
|
|
|
2594
2662
|
/*
|
|
2595
2663
|
* Assigning content made Mail wrap the whole body in a hidden quotation, and
|
|
@@ -3119,7 +3187,8 @@ const REPLY_OR_FORWARD = script(`
|
|
|
3119
3187
|
verifiedChars: verifiedChars, subject: subject });
|
|
3120
3188
|
}
|
|
3121
3189
|
|
|
3122
|
-
|
|
3190
|
+
// A draft is left for the person to read, unless the setting asks otherwise.
|
|
3191
|
+
if (p.handBack !== false) restore();
|
|
3123
3192
|
return ok({
|
|
3124
3193
|
sent: false,
|
|
3125
3194
|
draft: true,
|
|
@@ -3388,10 +3457,11 @@ const sameHead = (a, b) => {
|
|
|
3388
3457
|
const n = Math.min(x.length, y.length, HEAD_CHARS$1);
|
|
3389
3458
|
return x.slice(0, n) === y.slice(0, n);
|
|
3390
3459
|
};
|
|
3391
|
-
/** A composer taken as the new one, with the own text it was listed with. */
|
|
3460
|
+
/** A composer taken as the new one, with the own text and the title it was listed with. */
|
|
3392
3461
|
const taken = (c) => ({
|
|
3393
3462
|
handle: c.composer,
|
|
3394
|
-
text: c.text ?? null
|
|
3463
|
+
text: c.text ?? null,
|
|
3464
|
+
subject: c.subject
|
|
3395
3465
|
});
|
|
3396
3466
|
/**
|
|
3397
3467
|
* Wait for a composer that was not there before, and return its handle.
|
|
@@ -3404,7 +3474,9 @@ const taken = (c) => ({
|
|
|
3404
3474
|
* is the one this call opened, whatever it is titled.
|
|
3405
3475
|
*
|
|
3406
3476
|
* A person can open a window by hand during the poll, and an empty composer
|
|
3407
|
-
* gives nothing to tell theirs from ours.
|
|
3477
|
+
* gives nothing to tell theirs from ours. Without a subject that holds for any
|
|
3478
|
+
* new composer they open: theirs, listed before ours, is taken, and our body
|
|
3479
|
+
* goes above its signature. Nothing of theirs is replaced, since it is new. So the candidates are every fresh
|
|
3408
3480
|
* handle, narrowed to those titled `subject` when it is given (the subject
|
|
3409
3481
|
* `OPEN_COMPOSER` returned). Exactly one candidate is returned as `{ handle }`;
|
|
3410
3482
|
* more than one is `{ ambiguous }` and nothing is picked, because filling the
|
|
@@ -3451,11 +3523,19 @@ const taken = (c) => ({
|
|
|
3451
3523
|
const awaitNewComposer = async (lane, before, timeoutMs, subject) => {
|
|
3452
3524
|
const known = new Set(before.map((c) => typeof c === "string" ? c : c.composer));
|
|
3453
3525
|
const counted = before.every((c) => typeof c !== "string");
|
|
3454
|
-
const
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3526
|
+
const under = (title) => {
|
|
3527
|
+
const same = before.filter((c) => typeof c !== "string" && c.subject === title);
|
|
3528
|
+
const held = same.map((c) => c.text);
|
|
3529
|
+
const unread = held.some((t) => typeof t !== "string");
|
|
3530
|
+
const isOld = (text) => typeof text !== "string" || unread || held.some((t) => typeof t === "string" && sameHead(t, text));
|
|
3531
|
+
return {
|
|
3532
|
+
had: same.length,
|
|
3533
|
+
unread,
|
|
3534
|
+
isOld
|
|
3535
|
+
};
|
|
3536
|
+
};
|
|
3537
|
+
const bySubject = under(subject);
|
|
3538
|
+
const { had, unread, isOld } = bySubject;
|
|
3459
3539
|
const deadline = Date.now() + timeoutMs;
|
|
3460
3540
|
let waitedOn;
|
|
3461
3541
|
for (;;) {
|
|
@@ -3464,10 +3544,12 @@ const awaitNewComposer = async (lane, before, timeoutMs, subject) => {
|
|
|
3464
3544
|
const fresh = listed.filter((c) => !known.has(c.composer));
|
|
3465
3545
|
const candidates = subject === void 0 ? fresh : fresh.filter((c) => c.subject === subject);
|
|
3466
3546
|
const only = candidates.length === 1 ? candidates[0] : void 0;
|
|
3467
|
-
if (only &&
|
|
3468
|
-
|
|
3547
|
+
if (only && subject === void 0 && !counted) return { ambiguous: [only.composer] };
|
|
3548
|
+
const lone = only && subject === void 0 ? under(only.subject) : bySubject;
|
|
3549
|
+
if (only && lone.had === 0) return taken(only);
|
|
3550
|
+
if (only && !lone.isOld(only.text)) return taken(only);
|
|
3469
3551
|
if (only) {
|
|
3470
|
-
if (!(!unread && typeof only.text !== "string") || Date.now() >= deadline) return { ambiguous: [only.composer] };
|
|
3552
|
+
if (!(!lone.unread && typeof only.text !== "string") || Date.now() >= deadline) return { ambiguous: [only.composer] };
|
|
3471
3553
|
waitedOn = [only.composer];
|
|
3472
3554
|
}
|
|
3473
3555
|
if (candidates.length > 1) {
|
|
@@ -3497,19 +3579,31 @@ const composeNatively = async (lane, runner, params, opts = {}) => {
|
|
|
3497
3579
|
const sendTimeoutMs = opts.sendTimeoutMs ?? SEND_TIMEOUT_MS;
|
|
3498
3580
|
const watch = lane.watch();
|
|
3499
3581
|
const startedAt = Date.now();
|
|
3582
|
+
if (!params.subject?.trim() && params.mode === "new") {
|
|
3583
|
+
if (params.sendNow || !params.body && !params.attachments?.length) return {
|
|
3584
|
+
ok: false,
|
|
3585
|
+
subject: params.subject ?? "",
|
|
3586
|
+
bodyVerified: null,
|
|
3587
|
+
verifiedChars: 0,
|
|
3588
|
+
sent: false,
|
|
3589
|
+
note: (params.sendNow ? "A new message with no subject cannot be sent from here: Mail asks before sending one, and its buttons are named in the Mac's language." : "A new message with no subject and nothing to fill cannot be saved from here: the only way to save it is a keystroke aimed by its title, and it has none.") + " Nothing was opened. Give it a subject, or leave out sendNow and give it a body."
|
|
3590
|
+
};
|
|
3591
|
+
}
|
|
3500
3592
|
const reach = await lane.reach();
|
|
3501
3593
|
if (!reach.ok) throw new Error(`${MailAxLane.grantMessage(params.mode)} ${MailAxLane.nothingWritten}`);
|
|
3502
3594
|
const { attachments: files = [], ...toOpen } = params;
|
|
3503
3595
|
const before = await lane.composers();
|
|
3504
3596
|
const subject = (await runner.run(OPEN_COMPOSER, toOpen)).subject;
|
|
3505
|
-
const
|
|
3597
|
+
const keyed = subject.trim() !== "";
|
|
3598
|
+
const titled = keyed ? `for "${subject}"` : "with no subject";
|
|
3599
|
+
const found = await awaitNewComposer(lane, before, composerTimeoutMs, keyed ? subject : void 0);
|
|
3506
3600
|
if (found && "ambiguous" in found) return {
|
|
3507
3601
|
ok: false,
|
|
3508
3602
|
subject,
|
|
3509
3603
|
bodyVerified: null,
|
|
3510
3604
|
verifiedChars: 0,
|
|
3511
3605
|
sent: false,
|
|
3512
|
-
note: `Mail was asked to open a ${params.mode} window
|
|
3606
|
+
note: `Mail was asked to open a ${params.mode} window ${titled}, and ` + (found.ambiguous.length === 1 ? `the one new composer under that title (${found.ambiguous[0]}) could not be told from the draft already open under it: its text reads as that draft's, or could not be read. Nothing was filled, pressed or sent, and every window is left open in Mail. Close the extra one, finish the other by hand, then retry.` : `${found.ambiguous.length} new composers${keyed ? " titled that" : ""} appeared (${found.ambiguous.join(", ")}), so this path cannot tell which one it opened. Nothing was filled, pressed or sent, and all of them are left open in Mail. Close the extra one, finish the other by hand, then retry.`) + interferenceNote(await watch.check())
|
|
3513
3607
|
};
|
|
3514
3608
|
const handle = found?.handle ?? null;
|
|
3515
3609
|
const expectHead = found?.text ? found.text : null;
|
|
@@ -3519,7 +3613,7 @@ const composeNatively = async (lane, runner, params, opts = {}) => {
|
|
|
3519
3613
|
bodyVerified: null,
|
|
3520
3614
|
verifiedChars: 0,
|
|
3521
3615
|
sent: false,
|
|
3522
|
-
note: `Mail was asked to open a ${params.mode} window
|
|
3616
|
+
note: `Mail was asked to open a ${params.mode} window ${titled} and no such window was readable within ${composerTimeoutMs / 1e3}s, ` + ((reach.windows ?? []).length > 0 ? `although Mail's other windows read fine — so this is not a permission. ` : "and no Mail window could be read at all, on any desktop. Run apple_mail_diagnostics before retrying. ") + `Nothing was written. The window may still be on screen: look for an empty ${params.mode} in Mail before retrying, because a retry would leave a second one behind. Windows visible at the time: ${JSON.stringify(reach.windows)}.` + interferenceNote(await watch.check())
|
|
3523
3617
|
};
|
|
3524
3618
|
/**
|
|
3525
3619
|
* The composer is no longer on screen, and nothing here closed it.
|
|
@@ -3531,16 +3625,21 @@ const composeNatively = async (lane, runner, params, opts = {}) => {
|
|
|
3531
3625
|
* on double-paste grounds when the real hazard was sending the mail twice.
|
|
3532
3626
|
*/
|
|
3533
3627
|
const vanished = async (knownBody = null) => {
|
|
3534
|
-
const verdict = await sentVerdict(runner, params.accountUuid, subject, startedAt)
|
|
3628
|
+
const verdict = keyed ? await sentVerdict(runner, params.accountUuid, subject, startedAt) : {
|
|
3629
|
+
sent: null,
|
|
3630
|
+
sentence: "Nothing here sends a message with no subject, so it was closed or sent by hand, and Sent cannot tell which from here: look in Drafts and in Sent before retrying."
|
|
3631
|
+
};
|
|
3535
3632
|
return {
|
|
3536
3633
|
ok: false,
|
|
3537
3634
|
subject,
|
|
3538
3635
|
bodyVerified: knownBody?.verified ?? null,
|
|
3539
3636
|
verifiedChars: knownBody?.chars ?? 0,
|
|
3540
3637
|
sent: verdict.sent,
|
|
3541
|
-
note: `The ${params.mode} window
|
|
3638
|
+
note: `The ${params.mode} window ${titled} is GONE. Nothing here closed it — this path never discards a composer — so someone using the Mac sent it or closed it while this was running. ${verdict.sentence}` + interferenceNote(await watch.check())
|
|
3542
3639
|
};
|
|
3543
3640
|
};
|
|
3641
|
+
const listedTitle = found && "handle" in found ? found.subject : void 0;
|
|
3642
|
+
const gone = () => keyed ? lane.composerGone(subject, 0) : lane.composers().then((listed) => !listed.some((c) => c.composer === handle || listedTitle !== void 0 && c.subject === listedTitle), () => false);
|
|
3544
3643
|
const body = params.body ?? "";
|
|
3545
3644
|
const filling = body !== "" || files.length > 0;
|
|
3546
3645
|
let bodyVerified = null;
|
|
@@ -3559,7 +3658,7 @@ const composeNatively = async (lane, runner, params, opts = {}) => {
|
|
|
3559
3658
|
save: !params.sendNow
|
|
3560
3659
|
});
|
|
3561
3660
|
} catch (error) {
|
|
3562
|
-
if (await
|
|
3661
|
+
if (await gone()) return vanished();
|
|
3563
3662
|
return {
|
|
3564
3663
|
ok: false,
|
|
3565
3664
|
degraded: true,
|
|
@@ -3567,11 +3666,11 @@ const composeNatively = async (lane, runner, params, opts = {}) => {
|
|
|
3567
3666
|
bodyVerified: null,
|
|
3568
3667
|
verifiedChars: 0,
|
|
3569
3668
|
sent: false,
|
|
3570
|
-
note: `The ${params.mode} window
|
|
3669
|
+
note: `The ${params.mode} window ${titled} was opened and addressed, but filling it failed: ${error instanceof Error ? error.message : String(error)} Its window is still open in Mail: finish it there, or close it without saving and retry.` + interferenceNote(await watch.check())
|
|
3571
3670
|
};
|
|
3572
3671
|
}
|
|
3573
3672
|
if (edit["replaced"] !== true) {
|
|
3574
|
-
if (await
|
|
3673
|
+
if (await gone()) return vanished();
|
|
3575
3674
|
return {
|
|
3576
3675
|
ok: false,
|
|
3577
3676
|
degraded: true,
|
|
@@ -3579,7 +3678,7 @@ const composeNatively = async (lane, runner, params, opts = {}) => {
|
|
|
3579
3678
|
bodyVerified: null,
|
|
3580
3679
|
verifiedChars: 0,
|
|
3581
3680
|
sent: false,
|
|
3582
|
-
note: `${typeof edit["reason"] === "string" ? edit["reason"] : "The edit was refused."}${typeof edit["hint"] === "string" ? ` ${edit["hint"]}` : ""} The ${params.mode} window
|
|
3681
|
+
note: `${typeof edit["reason"] === "string" ? edit["reason"] : "The edit was refused."}${typeof edit["hint"] === "string" ? ` ${edit["hint"]}` : ""} The ${params.mode} window ${titled} is still open in Mail.` + interferenceNote(await watch.check())
|
|
3583
3682
|
};
|
|
3584
3683
|
}
|
|
3585
3684
|
const text = typeof edit["text"] === "string" ? edit["text"] : "";
|
|
@@ -3593,7 +3692,7 @@ const composeNatively = async (lane, runner, params, opts = {}) => {
|
|
|
3593
3692
|
bodyVerified: false,
|
|
3594
3693
|
verifiedChars,
|
|
3595
3694
|
sent: false,
|
|
3596
|
-
note: `The ${params.mode} window
|
|
3695
|
+
note: `The ${params.mode} window ${titled} was opened and correctly addressed, but reading the composer back does not show the text that was sent. It MUST NOT be described to the user as ready. It was left open rather than discarded, and may already be saved as it stands: look at it in Mail, then fix or close it.` + interferenceNote(await watch.check())
|
|
3597
3696
|
};
|
|
3598
3697
|
}
|
|
3599
3698
|
if (!params.sendNow && edit["saved"] === false) return {
|
|
@@ -3604,22 +3703,25 @@ const composeNatively = async (lane, runner, params, opts = {}) => {
|
|
|
3604
3703
|
verifiedChars,
|
|
3605
3704
|
sent: false,
|
|
3606
3705
|
...files.length > 0 ? { attachments: files.length } : {},
|
|
3607
|
-
note: `The ${params.mode} window
|
|
3706
|
+
note: `The ${params.mode} window ${titled} was filled` + (bodyVerified ? " and its body verified" : "") + `, but it was NOT saved. Its window is still open in Mail: save it there.` + interferenceNote(await watch.check())
|
|
3608
3707
|
};
|
|
3609
3708
|
}
|
|
3610
3709
|
const known = () => bodyVerified === true ? {
|
|
3611
3710
|
verified: true,
|
|
3612
3711
|
chars: verifiedChars
|
|
3613
3712
|
} : null;
|
|
3614
|
-
if (filling && !params.sendNow)
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3713
|
+
if (filling && !params.sendNow) {
|
|
3714
|
+
await lane.release();
|
|
3715
|
+
return {
|
|
3716
|
+
ok: true,
|
|
3717
|
+
subject,
|
|
3718
|
+
bodyVerified,
|
|
3719
|
+
verifiedChars,
|
|
3720
|
+
sent: false,
|
|
3721
|
+
...files.length > 0 ? { attachments: files.length } : {},
|
|
3722
|
+
note: "Draft window is open in Mail for review."
|
|
3723
|
+
};
|
|
3724
|
+
}
|
|
3623
3725
|
let sharing;
|
|
3624
3726
|
try {
|
|
3625
3727
|
sharing = (await lane.composers()).filter((c) => c.subject === subject);
|
|
@@ -3638,7 +3740,7 @@ const composeNatively = async (lane, runner, params, opts = {}) => {
|
|
|
3638
3740
|
verifiedChars,
|
|
3639
3741
|
sent: false,
|
|
3640
3742
|
...files.length > 0 ? { attachments: files.length } : {},
|
|
3641
|
-
note: `The ${params.mode}
|
|
3743
|
+
note: `The ${params.mode} ${titled} was ${filling ? "filled" : "opened"}` + (bodyVerified ? " and its body verified" : "") + `, but it was NOT ${action}: ` + (sharing === null ? `Mail's composers could not be listed, so it is not known that the title picks out one.` : moved ? "its handle was re-bound: Mail rebuilt its window's tabs since the draft was filled, so the handle may now name another draft under this title, which the shortcut could reach." : `${sharing.length} composers in Mail carry this title, and the shortcut is aimed by title, so it could reach the wrong one.`) + ` The draft is open in Mail for review: ${params.sendNow ? "send" : "save"} it from there.` + interferenceNote(await watch.check())
|
|
3642
3744
|
};
|
|
3643
3745
|
const ref = await lane.findComposer(subject, composerTimeoutMs);
|
|
3644
3746
|
if (!ref) {
|
|
@@ -3650,7 +3752,7 @@ const composeNatively = async (lane, runner, params, opts = {}) => {
|
|
|
3650
3752
|
bodyVerified,
|
|
3651
3753
|
verifiedChars,
|
|
3652
3754
|
sent: false,
|
|
3653
|
-
note: `The ${params.mode}
|
|
3755
|
+
note: `The ${params.mode} ${titled} was composed, but its window could not be read to press anything, so it was NOT ${action}. It is open in Mail for review.` + interferenceNote(await watch.check())
|
|
3654
3756
|
};
|
|
3655
3757
|
}
|
|
3656
3758
|
let rebound = false;
|
|
@@ -3670,7 +3772,7 @@ const composeNatively = async (lane, runner, params, opts = {}) => {
|
|
|
3670
3772
|
verifiedChars,
|
|
3671
3773
|
sent: false,
|
|
3672
3774
|
...files.length > 0 ? { attachments: files.length } : {},
|
|
3673
|
-
note: `The ${params.mode}
|
|
3775
|
+
note: `The ${params.mode} ${titled} was ${filling ? "filled" : "opened"}` + (bodyVerified ? " and its body verified" : "") + `, but it was NOT ${action}: ` + (rebound ? "right before the shortcut its handle read as re-bound: Mail rebuilt its window's tabs since the draft was filled, so the handle may now name another draft under this title, which the shortcut could have reached." : "its window holds several drafts as tabs, and right before the shortcut this draft's tab was not the one shown (or could not be confirmed to be), so the shortcut could have reached another draft.") + ` Nothing was pressed. The draft is open in Mail for review: ${params.sendNow ? "send" : "save"} it from there.` + interferenceNote(await watch.check())
|
|
3674
3776
|
};
|
|
3675
3777
|
}
|
|
3676
3778
|
if (finished === "refused") return {
|
|
@@ -3679,9 +3781,10 @@ const composeNatively = async (lane, runner, params, opts = {}) => {
|
|
|
3679
3781
|
bodyVerified,
|
|
3680
3782
|
verifiedChars,
|
|
3681
3783
|
sent: false,
|
|
3682
|
-
note: `The ${params.mode}
|
|
3784
|
+
note: `The ${params.mode} ${titled} was composed, but Mail could not be brought to the front, so nothing was pressed and it was not ${action}. Its window is still open in Mail. Someone is probably using the Mac; retry once it is free, or finish it in Mail.` + interferenceNote(await watch.check())
|
|
3683
3785
|
};
|
|
3684
3786
|
const sent = params.sendNow ? await lane.composerGone(subject, sendTimeoutMs) : false;
|
|
3787
|
+
if (!params.sendNow) await lane.release();
|
|
3685
3788
|
return {
|
|
3686
3789
|
ok: params.sendNow ? sent : true,
|
|
3687
3790
|
subject,
|
|
@@ -5139,6 +5242,11 @@ const nativeOnlyRefusal = (what) => ({
|
|
|
5139
5242
|
reason: `${what} needs Cupertino's native composer, and this server was not started by Cupertino. Nothing was changed.`,
|
|
5140
5243
|
hint: "Run the Mail server from Cupertino.app, or pass a ref and a whole body to rewrite the draft the older way."
|
|
5141
5244
|
});
|
|
5245
|
+
/** A verified native edit ends the session it opened: see `MailAxLane.release`. */
|
|
5246
|
+
const released = async (lane, result) => {
|
|
5247
|
+
if (result.replaced === true) await lane.release();
|
|
5248
|
+
return result;
|
|
5249
|
+
};
|
|
5142
5250
|
var AppleMailClient = class {
|
|
5143
5251
|
config;
|
|
5144
5252
|
runner;
|
|
@@ -5171,7 +5279,7 @@ var AppleMailClient = class {
|
|
|
5171
5279
|
allowlist: opts.config.accounts,
|
|
5172
5280
|
ttlMs: opts.config.mailboxCacheTtlMs
|
|
5173
5281
|
});
|
|
5174
|
-
this.#ax = opts.ax !== void 0 ? opts.ax : MailAxLane.open();
|
|
5282
|
+
this.#ax = opts.ax !== void 0 ? opts.ax : MailAxLane.open(process.env, { handBack: opts.config.handBackAfterDraft });
|
|
5175
5283
|
}
|
|
5176
5284
|
/** Which composer lane is live, for `diagnostics` to report. */
|
|
5177
5285
|
get composerLane() {
|
|
@@ -6135,7 +6243,7 @@ var AppleMailClient = class {
|
|
|
6135
6243
|
if (target.ref === void 0) {
|
|
6136
6244
|
if (opts.subject !== void 0) throw new PreconditionError("A new subject can only be set by rebuilding a saved draft, which needs its ref. Editing a composer by handle, or the one open, leaves the subject as it is.");
|
|
6137
6245
|
if (!this.#ax) return nativeOnlyRefusal(target.composer !== void 0 ? "Editing a composer by handle" : "Editing the open composer");
|
|
6138
|
-
return this.#editComposerDirectly(this.#ax, target.composer, opts, attachments);
|
|
6246
|
+
return released(this.#ax, await this.#editComposerDirectly(this.#ax, target.composer, opts, attachments));
|
|
6139
6247
|
}
|
|
6140
6248
|
if (opts.edits !== void 0 && !this.#ax) return nativeOnlyRefusal("Editing by find and replace");
|
|
6141
6249
|
const decoded = decodeRef(target.ref);
|
|
@@ -6170,9 +6278,9 @@ var AppleMailClient = class {
|
|
|
6170
6278
|
edits: opts.edits,
|
|
6171
6279
|
attachments
|
|
6172
6280
|
});
|
|
6173
|
-
if (edited) return edited;
|
|
6281
|
+
if (edited) return released(lane, edited);
|
|
6174
6282
|
}
|
|
6175
|
-
|
|
6283
|
+
const rebuilt = await rebuildDraft({
|
|
6176
6284
|
lane,
|
|
6177
6285
|
runner: this.runner,
|
|
6178
6286
|
messageFile: async (ref) => {
|
|
@@ -6193,6 +6301,7 @@ var AppleMailClient = class {
|
|
|
6193
6301
|
subject: opts.subject,
|
|
6194
6302
|
attachments
|
|
6195
6303
|
});
|
|
6304
|
+
return released(lane, rebuilt);
|
|
6196
6305
|
}
|
|
6197
6306
|
if (opts.body === void 0) {
|
|
6198
6307
|
const gone = "none is open for this one that this server can reach: it was not started by Cupertino";
|
|
@@ -6210,7 +6319,8 @@ var AppleMailClient = class {
|
|
|
6210
6319
|
...decodedTarget,
|
|
6211
6320
|
body: opts.body,
|
|
6212
6321
|
subject: opts.subject ?? null,
|
|
6213
|
-
attachments
|
|
6322
|
+
attachments,
|
|
6323
|
+
handBack: this.config.handBackAfterDraft
|
|
6214
6324
|
}));
|
|
6215
6325
|
}
|
|
6216
6326
|
/**
|
|
@@ -6335,7 +6445,7 @@ var AppleMailClient = class {
|
|
|
6335
6445
|
});
|
|
6336
6446
|
return {
|
|
6337
6447
|
drafts,
|
|
6338
|
-
note: composers.length === 0 ? "No compose window is open in Mail." : "`composer` is the window's handle, which apple_mail_update_draft takes to edit that window directly. Recipients are the names Mail shows in the window, not addresses — read a saved draft with apple_mail_get_message for those. `savedDrafts` are the copies Mail has autosaved under the same subject, newest first: a composer opened seconds ago may have none yet, and the newest one can lag what the window shows. The window is the current text." + (composers.some((c) => c.tab === "background") ? " Mail shows these drafts as tabs of one window. A draft with `tab: \"background\"` is a tab it is not showing: its text, quote and recipients are null because reading them would mean switching tabs, which listing never does. They are read once it is the selected tab (`tab: \"selected\"`): select it in Mail and list again, or edit it with apple_mail_update_draft, which selects its tab and checks it, and once the edit is saved leaves that tab shown in place of the one that was: tell the person which draft Mail now shows." : "") + (composers.some((c) => c.rebound === true) ? " A draft with `rebound: true` is a tab whose window Mail rebuilt since its handle was given, so the handle may now name another draft under the same title: it stays reference-only until its text is proved. Edit it by a ref from `savedDrafts`, which checks its text; after that verified edit, list again and the handle edits on its own." : "") + (index ? "" : " `savedDrafts` is null because the search index cannot be read.")
|
|
6448
|
+
note: composers.length === 0 ? "No compose window is open in Mail." : "`composer` is the window's handle, which apple_mail_update_draft takes to edit that window directly. Recipients are the names Mail shows in the window, not addresses — read a saved draft with apple_mail_get_message for those. `savedDrafts` are the copies Mail has autosaved under the same subject, newest first: a composer opened seconds ago may have none yet, and the newest one can lag what the window shows. The window is the current text." + (composers.some((c) => c.tab === "background") ? " Mail shows these drafts as tabs of one window. A draft with `tab: \"background\"` is a tab it is not showing: its text, quote and recipients are null because reading them would mean switching tabs, which listing never does. They are read once it is the selected tab (`tab: \"selected\"`): select it in Mail and list again, or edit it with apple_mail_update_draft, which selects its tab and checks it, and once the edit is saved leaves that tab shown in place of the one that was: tell the person which draft Mail now shows." : "") + (composers.some((c) => c.onAnotherDesktop === true) ? " A draft with `onAnotherDesktop: true` is on a desktop that is not the one shown (another Space, or Mail in full screen): it is read where it is, and editing it with apple_mail_update_draft brings Mail forward on that desktop first, which switches the person's screen to it." : "") + (composers.some((c) => c.rebound === true) ? " A draft with `rebound: true` is a tab whose window Mail rebuilt since its handle was given, so the handle may now name another draft under the same title: it stays reference-only until its text is proved. Edit it by a ref from `savedDrafts`, which checks its text; after that verified edit, list again and the handle edits on its own." : "") + (index ? "" : " `savedDrafts` is null because the search index cannot be read.")
|
|
6339
6449
|
};
|
|
6340
6450
|
}
|
|
6341
6451
|
/** Drafts-mailbox messages carrying exactly this subject, newest first. */
|
|
@@ -6363,7 +6473,8 @@ var AppleMailClient = class {
|
|
|
6363
6473
|
async sendMessage(opts) {
|
|
6364
6474
|
const attachments = this.#resolveAttachments(opts.attachments, opts.sendNow);
|
|
6365
6475
|
const account = opts.account ? await this.mailboxes.resolveAccount(opts.account) : null;
|
|
6366
|
-
|
|
6476
|
+
const native = opts.subject.trim() !== "" || !opts.sendNow && (opts.body !== "" || attachments.length > 0);
|
|
6477
|
+
if (this.#ax && native) return composeNatively(this.#ax, this.runner, {
|
|
6367
6478
|
mode: "new",
|
|
6368
6479
|
accountUuid: account?.id ?? null,
|
|
6369
6480
|
subject: opts.subject,
|
|
@@ -6383,7 +6494,8 @@ var AppleMailClient = class {
|
|
|
6383
6494
|
subject: opts.subject,
|
|
6384
6495
|
body: opts.body,
|
|
6385
6496
|
attachments,
|
|
6386
|
-
sendNow: opts.sendNow
|
|
6497
|
+
sendNow: opts.sendNow,
|
|
6498
|
+
handBack: this.config.handBackAfterDraft
|
|
6387
6499
|
});
|
|
6388
6500
|
}
|
|
6389
6501
|
async replyOrForward(ref, opts) {
|
|
@@ -6401,7 +6513,10 @@ var AppleMailClient = class {
|
|
|
6401
6513
|
sendNow: opts.sendNow
|
|
6402
6514
|
};
|
|
6403
6515
|
if (this.#ax) return composeNatively(this.#ax, this.runner, params);
|
|
6404
|
-
return this.runner.run(REPLY_OR_FORWARD,
|
|
6516
|
+
return this.runner.run(REPLY_OR_FORWARD, {
|
|
6517
|
+
...params,
|
|
6518
|
+
handBack: this.config.handBackAfterDraft
|
|
6519
|
+
});
|
|
6405
6520
|
}
|
|
6406
6521
|
/**
|
|
6407
6522
|
* The files a compose call names, checked before Mail is asked anything.
|
|
@@ -6536,6 +6651,13 @@ const ConfigSchema = BaseConfigSchema.extend({
|
|
|
6536
6651
|
* reach a session. Off, no `events/*` method exists and nothing is declared.
|
|
6537
6652
|
*/
|
|
6538
6653
|
allowEvents: z.boolean().default(false),
|
|
6654
|
+
/**
|
|
6655
|
+
* Once a draft is written or edited, bring back the app that was in front.
|
|
6656
|
+
* Off by default: most drafts are read and sent by the person, and handing
|
|
6657
|
+
* the front back hid the window they were about to read. A send, a refusal
|
|
6658
|
+
* and a failure are not drafts left to read, and hand back as they always did.
|
|
6659
|
+
*/
|
|
6660
|
+
handBackAfterDraft: z.boolean().default(false),
|
|
6539
6661
|
mailboxCacheTtlMs: z.number().int().min(0).max(36e5).default(6e4)
|
|
6540
6662
|
}).strict();
|
|
6541
6663
|
/**
|
|
@@ -6562,6 +6684,7 @@ const loadConfig = (env = process.env) => {
|
|
|
6562
6684
|
allowFileSend: parseBool(env.APPLE_MAIL_ALLOW_FILE_SEND),
|
|
6563
6685
|
allowWatches: parseBool(env.APPLE_MAIL_ALLOW_WATCHES),
|
|
6564
6686
|
allowEvents: parseBool(env.APPLE_MAIL_ALLOW_EVENTS),
|
|
6687
|
+
handBackAfterDraft: parseBool(env.APPLE_MAIL_HAND_BACK_AFTER_DRAFT),
|
|
6565
6688
|
mailboxCacheTtlMs: parseIntOpt(env.APPLE_MAIL_MAILBOX_CACHE_TTL_MS)
|
|
6566
6689
|
};
|
|
6567
6690
|
return parseConfig(ConfigSchema, raw);
|
|
@@ -6845,7 +6968,7 @@ const buildDiagnostics = async (client, ctx) => {
|
|
|
6845
6968
|
composerAxRead: axReach.ok ? "granted" : "denied",
|
|
6846
6969
|
...axReach.windows ? { composerAxWindowsSeen: axReach.windows } : {}
|
|
6847
6970
|
} : {},
|
|
6848
|
-
...client.composerLane === "accessibility" ? { composerLaneNote: "This server is hosted by Cupertino, so a composer is driven through the app's own Accessibility driver, for a new message as for a reply or forward: the body is pasted, never assigned. Automation to System Events is NOT required for it, and `automationSystemEvents` above can be denied. The one exception is a new message with no subject,
|
|
6971
|
+
...client.composerLane === "accessibility" ? { composerLaneNote: "This server is hosted by Cupertino, so a composer is driven through the app's own Accessibility driver, for a new message as for a reply or forward: the body is pasted, never assigned. Automation to System Events is NOT required for it, and `automationSystemEvents` above can be denied. The one exception is a new message with no subject that is sent at once, or saved with no body or files: it still has its body assigned and then needs System Events to take off the quotation Mail wraps an assigned body in; without it, the result says `quoted: true` and the message is not sent." } : {},
|
|
6849
6972
|
...composer.uiRead === "granted" && composer.systemEvents === "granted" || client.composerLane === "accessibility" ? {} : { 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, and apple_mail_send_message leaves its body wrapped as a QUOTATION that recipients see — reported as `quoted: true`, and never sent that way. 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." },
|
|
6850
6973
|
fullDiskAccess: located.readable ? "granted" : located.exists ? "denied" : "unknown (no index file found)",
|
|
6851
6974
|
...located.readable ? {} : { howToGrant: [
|
|
@@ -7183,7 +7306,7 @@ const registerComposeTools = (server, client) => {
|
|
|
7183
7306
|
});
|
|
7184
7307
|
}));
|
|
7185
7308
|
server.registerTool("apple_mail_reply_to_message", {
|
|
7186
|
-
description: "Reply to a message. By default it opens a draft in Mail with the original quoted beneath your text, for the user to review. Your text goes in above the account's signature, which Mail adds and which is kept, image and all. Pass replyToAll to include every original recipient. Only pass sendNow: true (with confirm: true) when explicitly asked to send now. Success means the body was read back out of the composer window and matched, and only then may it be described to the user as ready. A failure is NOT automatically an empty draft: read the note, which says what was actually found — including that the composer was taken by someone using the Mac, in which case the reply may already have been SENT and a retry would send it twice. Filling the composer brings Mail to the front
|
|
7309
|
+
description: "Reply to a message. By default it opens a draft in Mail with the original quoted beneath your text, for the user to review. Your text goes in above the account's signature, which Mail adds and which is kept, image and all. Pass replyToAll to include every original recipient. Only pass sendNow: true (with confirm: true) when explicitly asked to send now. Success means the body was read back out of the composer window and matched, and only then may it be described to the user as ready. A failure is NOT automatically an empty draft: read the note, which says what was actually found — including that the composer was taken by someone using the Mac, in which case the reply may already have been SENT and a retry would send it twice. Filling the composer brings Mail to the front to paste, and a draft leaves it there for the person to read unless they set Mail to hand back; the clipboard is borrowed by the app and restored.",
|
|
7187
7310
|
inputSchema: z.object({
|
|
7188
7311
|
ref: messageRefArg,
|
|
7189
7312
|
body: bodyArg,
|
|
@@ -7208,7 +7331,7 @@ const registerComposeTools = (server, client) => {
|
|
|
7208
7331
|
});
|
|
7209
7332
|
}));
|
|
7210
7333
|
server.registerTool("apple_mail_forward_message", {
|
|
7211
|
-
description: "Forward a message to new recipients. By default it opens a draft in Mail for review. Only pass sendNow: true (with confirm: true) when explicitly asked to send now. When a note is given, success means it was read back out of the composer window and matched. The note goes in above the account's signature, which Mail adds and which is kept, image and all. Filling the composer brings Mail to the front
|
|
7334
|
+
description: "Forward a message to new recipients. By default it opens a draft in Mail for review. Only pass sendNow: true (with confirm: true) when explicitly asked to send now. When a note is given, success means it was read back out of the composer window and matched. The note goes in above the account's signature, which Mail adds and which is kept, image and all. Filling the composer brings Mail to the front to paste, and a draft leaves it there for the person to read unless they set Mail to hand back; the clipboard is borrowed by the app and restored.",
|
|
7212
7335
|
inputSchema: z.object({
|
|
7213
7336
|
ref: messageRefArg,
|
|
7214
7337
|
to: z.array(z.string().email()).min(1).describe("Who to forward to."),
|
|
@@ -7233,7 +7356,7 @@ const registerComposeTools = (server, client) => {
|
|
|
7233
7356
|
});
|
|
7234
7357
|
}));
|
|
7235
7358
|
server.registerTool("apple_mail_update_draft", {
|
|
7236
|
-
description: "Change an unsent draft in its open composer window in Mail: replace its text (`body`), change only some of it (`edits`), add files (`attachments`), or combine files with either — including a REPLY draft you have just written and been asked to revise or attach something to, which is the usual reason to reach for this. Name the draft one of three ways: `ref`, a saved draft's ref (apple_mail_list_open_drafts gives them under `savedDrafts`), whose window is found by its content; `composer`, a window's handle from apple_mail_list_open_drafts or a previous result, which edits that window directly; or neither, which edits the one compose window open and refuses when there are none or several, listing them. Not both ref and composer. `edits` are find-and-replace pairs applied to the text the sender wrote, never the quoted original: each `find` must match exactly once, ignoring differences in whitespace, and only the matched text is replaced, so the rest of the draft is untouched. Prefer them to `body` for a correction, because `body` replaces everything and anything you leave out is lost. Edits and body are exclusive. The edit is made in the draft's own window, so threading, earlier attachments and the quoted original all survive, no second draft appears, and the ref stays valid — though Mail may renumber a saved draft within seconds, so re-find it by subject rather than reusing a ref across turns. The app reads the window back before it reports anything, and saves only what it could verify. Mail comes to the front
|
|
7359
|
+
description: "Change an unsent draft in its open composer window in Mail: replace its text (`body`), change only some of it (`edits`), add files (`attachments`), or combine files with either — including a REPLY draft you have just written and been asked to revise or attach something to, which is the usual reason to reach for this. Name the draft one of three ways: `ref`, a saved draft's ref (apple_mail_list_open_drafts gives them under `savedDrafts`), whose window is found by its content; `composer`, a window's handle from apple_mail_list_open_drafts or a previous result, which edits that window directly; or neither, which edits the one compose window open and refuses when there are none or several, listing them. Not both ref and composer. `edits` are find-and-replace pairs applied to the text the sender wrote, never the quoted original: each `find` must match exactly once, ignoring differences in whitespace, and only the matched text is replaced, so the rest of the draft is untouched. Prefer them to `body` for a correction, because `body` replaces everything and anything you leave out is lost. Edits and body are exclusive. The edit is made in the draft's own window, so threading, earlier attachments and the quoted original all survive, no second draft appears, and the ref stays valid — though Mail may renumber a saved draft within seconds, so re-find it by subject rather than reusing a ref across turns. The app reads the window back before it reports anything, and saves only what it could verify. Mail comes to the front to paste and stays there unless the person set Mail to hand back; the clipboard is borrowed by the app and restored. When Mail shows drafts as tabs of one window, a draft in a tab it is not showing is selected for the edit, and once saved that tab is LEFT SHOWN in place of the one that was (Mail does not say when a save has landed, and switching back early could save the other draft): tell the person which draft Mail now shows. By `composer` handle, such a tab is refused when another tab has the same title, since only a `ref` lets its text be checked; so is a handle listed with `rebound: true`, whose tab Mail rebuilt since it was listed and which may now be another draft: it stays reference-only until a verified edit by `ref` proves its text. It REFUSES rather than doing damage, and returns `replaced: false` with a reason when it does: when a `find` matches zero or several places, when two windows could be the draft, when the open window holds a different message, or when the draft's own text cannot be told apart from the quote. In every refusal nothing was changed. If the draft's window is not open (a `ref` with no window for it), the draft is REBUILT: a reply is reopened as a reply to its original, so it stays in the thread, filled with the draft's own formatted text (with your edits or body) and its files, saved, and the old draft deleted only once the new one is confirmed in Drafts. It refuses, changing nothing, for a forward, a reply whose original is not in Mail's index, an edit that runs across formatting, or a window already open under the subject; and if the quote Mail writes into the new reply is not the old one, it stops with that window open, unsaved, for you to close without saving. A rebuilt draft gets a new ref. The result's `method` says which route ran. In the result `filesAdded` names the files put in, and `attachmentsAdded` counts them.",
|
|
7237
7360
|
inputSchema: z.object({
|
|
7238
7361
|
ref: messageRefArg.optional(),
|
|
7239
7362
|
composer: z.string().min(1).optional().describe("A compose window's handle (looks like mc-3), from apple_mail_list_open_drafts. Edits that window directly. Omit both ref and composer to edit the one open window. Not together with ref."),
|
|
@@ -8219,7 +8342,9 @@ const createServer = (opts) => {
|
|
|
8219
8342
|
displayName: "Mail",
|
|
8220
8343
|
era: opts.era ?? "legacy",
|
|
8221
8344
|
source: service.source,
|
|
8222
|
-
startTrigger: service.startTrigger
|
|
8345
|
+
startTrigger: service.startTrigger,
|
|
8346
|
+
...opts.logger ? { logger: opts.logger } : {},
|
|
8347
|
+
...opts.listens ? { listens: opts.listens } : {}
|
|
8223
8348
|
});
|
|
8224
8349
|
service.bind(registry);
|
|
8225
8350
|
closers.push(() => {
|
|
@@ -8288,4 +8413,4 @@ const createServer = (opts) => {
|
|
|
8288
8413
|
//#endregion
|
|
8289
8414
|
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 };
|
|
8290
8415
|
|
|
8291
|
-
//# sourceMappingURL=server-
|
|
8416
|
+
//# sourceMappingURL=server-ynr059Dx.js.map
|