@mgcrea/mcp-apple-mail 1.25.0 → 1.26.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/README.md +9 -8
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +59 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/{server-Chflrnvi.js → server-69NtCX3D.js} +215 -13
- package/dist/server-69NtCX3D.js.map +1 -0
- package/package.json +2 -2
- package/dist/server-Chflrnvi.js.map +0 -1
package/README.md
CHANGED
|
@@ -138,14 +138,15 @@ npx @modelcontextprotocol/inspector node dist/cli.js
|
|
|
138
138
|
|
|
139
139
|
## Tools
|
|
140
140
|
|
|
141
|
-
| Tool
|
|
142
|
-
|
|
|
143
|
-
| `apple_mail_diagnostics`
|
|
144
|
-
| `apple_mail_list_accounts`
|
|
145
|
-
| `apple_mail_list_mailboxes`
|
|
146
|
-
| `apple_mail_list_messages`
|
|
147
|
-
| `apple_mail_search_messages`
|
|
148
|
-
| `apple_mail_count_messages`
|
|
141
|
+
| Tool | Does |
|
|
142
|
+
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
143
|
+
| `apple_mail_diagnostics` | What the server can currently do and why. **Call this first when anything looks wrong** — it names the exact System Settings pane to open. |
|
|
144
|
+
| `apple_mail_list_accounts` | Accounts with UUIDs, addresses and mailbox names. Start here. |
|
|
145
|
+
| `apple_mail_list_mailboxes` | Mailboxes, optionally with counts (~0.3 s each). |
|
|
146
|
+
| `apple_mail_list_messages` | Newest N of one mailbox, with a `ref` per message. |
|
|
147
|
+
| `apple_mail_search_messages` | Any combination of filters. `body` searches message text — see [Body search](#body-search). |
|
|
148
|
+
| `apple_mail_count_messages` | Totals and unread, labelled by source. |
|
|
149
|
+
| `apple_mail_list_open_drafts` | The drafts open in Mail right now, own text apart from the quote — for "review my draft". |
|
|
149
150
|
|
|
150
151
|
Every message carries an opaque `ref` (`m1:<accountUuid>/<mailbox>#<id>`) which the read and action
|
|
151
152
|
tools take. It is versioned and carries its mailbox, so a row id can never be applied to the wrong
|
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-69NtCX3D.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
|
@@ -141,6 +141,33 @@ type ComposerBody = {
|
|
|
141
141
|
/** Whether a quoted original follows. */
|
|
142
142
|
quoted: boolean;
|
|
143
143
|
};
|
|
144
|
+
/**
|
|
145
|
+
* One compose window as a person would read it, for reviewing what they wrote.
|
|
146
|
+
*
|
|
147
|
+
* Recipients are display names, never addresses — see `TOKEN_CHAR`. A name
|
|
148
|
+
* still being typed, not yet turned into a token, is returned as typed.
|
|
149
|
+
*/
|
|
150
|
+
type OpenComposer = {
|
|
151
|
+
subject: string;
|
|
152
|
+
/** The window Mail considers main — the one in front, when Mail is. */
|
|
153
|
+
main: boolean;
|
|
154
|
+
/** The account picker's value, `Name – address`. */
|
|
155
|
+
from: string | null;
|
|
156
|
+
to: string[];
|
|
157
|
+
cc: string[];
|
|
158
|
+
/** Null when the Bcc field is not shown, which is not the same as empty. */
|
|
159
|
+
bcc: string[] | null;
|
|
160
|
+
/**
|
|
161
|
+
* What the sender wrote. When `quoted` is null the boundary could not be
|
|
162
|
+
* found, and this is the readable text of the whole body instead.
|
|
163
|
+
*/
|
|
164
|
+
text: string | null;
|
|
165
|
+
/** Whether a quoted original follows; null when that could not be established. */
|
|
166
|
+
quoted: boolean | null;
|
|
167
|
+
/** The opening of the quoted original, up to the requested length. */
|
|
168
|
+
quote: string | null;
|
|
169
|
+
quoteTruncated: boolean;
|
|
170
|
+
};
|
|
144
171
|
type ReachReport = {
|
|
145
172
|
ok: boolean;
|
|
146
173
|
/** `accessibility` when Mail's windows cannot be read; null when they can. */
|
|
@@ -298,6 +325,24 @@ declare class MailAxLane {
|
|
|
298
325
|
*/
|
|
299
326
|
keys(ref: ComposerRef, strokes: Keystroke[], focusTimeoutMs?: number): Promise<boolean>;
|
|
300
327
|
composerBody(body: string): Promise<ComposerBody | null>;
|
|
328
|
+
/**
|
|
329
|
+
* Every compose window open in Mail, read the way a person reviewing it would.
|
|
330
|
+
*
|
|
331
|
+
* **Why this reads windows rather than asking Mail.** `outgoing messages` —
|
|
332
|
+
* the scripting class for a composer — came back EMPTY with a reply composer
|
|
333
|
+
* on screen that the person had opened by hand (measured 2026-10-06, macOS
|
|
334
|
+
* 27.0). It lists only the composers a script made. The window is the one
|
|
335
|
+
* place every draft being written can be seen.
|
|
336
|
+
*
|
|
337
|
+
* A composer is recognised by its subject FIELD, not its title: the title is
|
|
338
|
+
* the subject, so it cannot tell a composer from a viewer showing a message
|
|
339
|
+
* with the same one. The shallow walk that finds the field is cheap on Mail's
|
|
340
|
+
* main window, which is the one with thousands of rows under it.
|
|
341
|
+
*
|
|
342
|
+
* Pure reads. Nothing is raised, focused or typed, so it can run while
|
|
343
|
+
* someone is using the Mac.
|
|
344
|
+
*/
|
|
345
|
+
listComposers(quoteChars?: number): Promise<OpenComposer[]>;
|
|
301
346
|
/**
|
|
302
347
|
* Send the composer, or save it as a draft.
|
|
303
348
|
*
|
|
@@ -951,6 +996,20 @@ declare class AppleMailClient {
|
|
|
951
996
|
body: string;
|
|
952
997
|
subject?: string | undefined;
|
|
953
998
|
}): Promise<Record<string, unknown>>;
|
|
999
|
+
/**
|
|
1000
|
+
* The drafts being written right now: every compose window open in Mail.
|
|
1001
|
+
*
|
|
1002
|
+
* Read from the windows, because nothing else sees them all — see
|
|
1003
|
+
* `MailAxLane.listComposers`. Each one is paired with the saved copies Mail
|
|
1004
|
+
* has autosaved under the same subject in a Drafts mailbox, which is where
|
|
1005
|
+
* the recipients' ADDRESSES are (the window only shows names) and what
|
|
1006
|
+
* `updateDraft` takes. The pairing is by subject, so it is offered as
|
|
1007
|
+
* candidates rather than asserted; `updateDraft` matches content before it
|
|
1008
|
+
* touches anything, so a wrong candidate is refused rather than edited.
|
|
1009
|
+
*/
|
|
1010
|
+
listOpenDrafts(opts?: {
|
|
1011
|
+
quoteChars?: number | undefined;
|
|
1012
|
+
}): Promise<Record<string, unknown>>;
|
|
954
1013
|
checkForNewMail(account?: string): Promise<unknown>;
|
|
955
1014
|
sendMessage(opts: {
|
|
956
1015
|
account?: 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/ax.ts","../src/client/compose.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;;;;KC+B7D;EAAc;EAAa;;
|
|
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/ax.ts","../src/client/compose.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;;;;KC+B7D;EAAc;EAAa;;KAyDpB;EAAgB;EAAgB;EAAc;;;;;;;;;;;;;;;;;;;;;;;KAuB9C;;EAEV;;EAEA;;EAEA;;;;;;;;KASU;EACV;;EAEA;;EAEA;EACA;EACA;;EAEA;;;;;EAKA;;EAEA;;EAEA;EACA;;KAGU;EACV;;EAEA;EACA;;cAGW;;UAGJ;;SAKA,KAAK,MAAK,OAAO,aAA2B;EAKnD;;EAKA,SAAS;;;;;;;;;;;;;;;;;;EAyBH,SAAS,QAAQ;;;;;;;;;SAqBhB,aAAa;;;;;;;;;;;;;;;;;EA0Bd,aAAa,iBAAiB,oBAAoB,QAAQ;;;;;;;;;;;;;;EA8B1D,cAAc,kBAAkB,QAAQ;;EAyBxC,YAAY;;;;;;;;;;;;;EAgBZ,SAAS,eAAe;;;;;;;;;;;;;;;;;;;;;;;EAsCxB,SAAS,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwCxB,MAAM,KAAK,aAAa,0BAAoC;;;;;;;;;;;;;;;;;;EAqB5D,KACJ,KAAK,aACL,SAAS,aACT,0BACC;EAyEG,aAAa,eAAe,QAAQ;;;;;;;;;;;;;;;;;;EAsFpC,cAAc,sBAA2B,QAAQ;;;;;;;;;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MACvB;IACD;IACA;IACA;IACA;IACA;;;;;;;;;;;;;;;EA2HI,oBAAoB;IAEtB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;;;;;;;;;EA8HE,eACJ,aACA,kBACA;IAAQ;MACP;IAAU;IAAc;IAAe;;;EAsCpC,SACJ,gBACA;IAAS;IAAgB;IAAmB;IAAoB;MAC/D;IAAU;IAAiB;IAAgB;;EA6BxC,aACJ,gBACA;IAAQ;IAA4B;MACnC;IAAU;IAAe;IAAgB;IAAqB;;EAqD3D,eAAe,iBAAiB;IACpC;IACA;IACA;IACA;;;;;;;;;;;;;;EAuCI,cACJ,cACA,mBACC;IACD;IACA;IACA;IACA;IACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoEI,YACJ,aACA;IAAQ;IAAc;MACrB,QAAQ;;;;;;;;;;;;EAiDL,eACJ;IAAQ;MACP,QAAQ;EAsEL,gBAAgB,mBAAmB;EAKnC,YAAY;IAChB;IACA;IACA;IACA;IACA;IACA;IACA;MACE;EAaE,eACJ,aACA;IACE;IACA;IACA;IACA;IACA;MAED;;;;;;;;;;;;;;;;;;;;;cCz4CQ;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;;;KCrB7C;;;;;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-69NtCX3D.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 };
|
|
@@ -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-10-
|
|
17
|
+
gitCommit: "8802834",
|
|
18
|
+
gitCommitDate: "2026-10-06T12:47:35+02:00"
|
|
19
19
|
};
|
|
20
20
|
//#endregion
|
|
21
21
|
//#region src/client/errors.ts
|
|
@@ -207,6 +207,33 @@ const QUOTE_READ_PAUSE_MS = 120;
|
|
|
207
207
|
* the number of lines in somebody's draft.
|
|
208
208
|
*/
|
|
209
209
|
const KEY_BURST = 20;
|
|
210
|
+
/**
|
|
211
|
+
* The composer's header fields, by the identifiers Mail gives them.
|
|
212
|
+
*
|
|
213
|
+
* Identifiers rather than labels, because the labels are localised — a French
|
|
214
|
+
* Mail says "À :" — and the identifiers are not. `popup_from` is the account
|
|
215
|
+
* picker, whose value reads `Name – address`.
|
|
216
|
+
*/
|
|
217
|
+
const SUBJECT_FIELD = "Mail.subjectField";
|
|
218
|
+
const FROM_FIELD = "popup_from";
|
|
219
|
+
const RECIPIENT_FIELDS = {
|
|
220
|
+
to: "Mail.toField",
|
|
221
|
+
cc: "Mail.ccField",
|
|
222
|
+
bcc: "Mail.bccField"
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* What a recipient field holds in place of each recipient.
|
|
226
|
+
*
|
|
227
|
+
* MEASURED, macOS 27.0: a field holding one token reads `AXValue` "" —
|
|
228
|
+
* the object replacement character — and the token itself is a child
|
|
229
|
+
* `AXTextField` with subrole `AXTextAttachment` whose value is the DISPLAY NAME.
|
|
230
|
+
* No attribute on it carries the address: AXDescription, AXHelp, AXTitle,
|
|
231
|
+
* AXValueDescription and AXIdentifier all read null.
|
|
232
|
+
*/
|
|
233
|
+
const TOKEN_CHAR = "";
|
|
234
|
+
const TOKEN_SUBROLE = "AXTextAttachment";
|
|
235
|
+
/** How much of the quoted original to return by default. */
|
|
236
|
+
const QUOTE_CHARS = 2e3;
|
|
210
237
|
var MailAxLane = class MailAxLane {
|
|
211
238
|
#channel;
|
|
212
239
|
constructor(channel) {
|
|
@@ -535,6 +562,14 @@ var MailAxLane = class MailAxLane {
|
|
|
535
562
|
return null;
|
|
536
563
|
}
|
|
537
564
|
async composerBody(body) {
|
|
565
|
+
const split = await this.#split(body);
|
|
566
|
+
return split ? split.own : null;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* The body read once, split at the quote: the sender's own text, and the
|
|
570
|
+
* blocks from the boundary down. Null exactly when `composerBody` is.
|
|
571
|
+
*/
|
|
572
|
+
async #split(body) {
|
|
538
573
|
let tree;
|
|
539
574
|
try {
|
|
540
575
|
tree = await this.#call("expand", {
|
|
@@ -563,16 +598,118 @@ var MailAxLane = class MailAxLane {
|
|
|
563
598
|
if (truncated || starts.length > BLOCK_SCAN_MAX) return null;
|
|
564
599
|
boundary = starts.length;
|
|
565
600
|
}
|
|
601
|
+
const blockText = (block) => elements.slice(starts[block], starts[block + 1] ?? elements.length).map((el) => el.value).filter((v) => typeof v === "string").join("");
|
|
566
602
|
const lines = [];
|
|
567
|
-
for (let block = 0; block < boundary; block += 1)
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
603
|
+
for (let block = 0; block < boundary; block += 1) lines.push(blockText(block));
|
|
604
|
+
const quoteBlocks = [];
|
|
605
|
+
for (let block = boundary; block < starts.length; block += 1) quoteBlocks.push(blockText(block));
|
|
606
|
+
return {
|
|
607
|
+
own: {
|
|
608
|
+
text: lines.join("\n"),
|
|
609
|
+
blocks: boundary,
|
|
610
|
+
quoted: boundary < starts.length
|
|
611
|
+
},
|
|
612
|
+
tree,
|
|
613
|
+
quoteBlocks
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Every compose window open in Mail, read the way a person reviewing it would.
|
|
618
|
+
*
|
|
619
|
+
* **Why this reads windows rather than asking Mail.** `outgoing messages` —
|
|
620
|
+
* the scripting class for a composer — came back EMPTY with a reply composer
|
|
621
|
+
* on screen that the person had opened by hand (measured 2026-10-06, macOS
|
|
622
|
+
* 27.0). It lists only the composers a script made. The window is the one
|
|
623
|
+
* place every draft being written can be seen.
|
|
624
|
+
*
|
|
625
|
+
* A composer is recognised by its subject FIELD, not its title: the title is
|
|
626
|
+
* the subject, so it cannot tell a composer from a viewer showing a message
|
|
627
|
+
* with the same one. The shallow walk that finds the field is cheap on Mail's
|
|
628
|
+
* main window, which is the one with thousands of rows under it.
|
|
629
|
+
*
|
|
630
|
+
* Pure reads. Nothing is raised, focused or typed, so it can run while
|
|
631
|
+
* someone is using the Mac.
|
|
632
|
+
*/
|
|
633
|
+
async listComposers(quoteChars = QUOTE_CHARS) {
|
|
634
|
+
const listed = await this.#call("list_windows", {
|
|
635
|
+
bundleId: MAIL_BUNDLE,
|
|
636
|
+
includeTitles: true
|
|
637
|
+
});
|
|
638
|
+
const found = [];
|
|
639
|
+
for (const win of listed.windows ?? []) {
|
|
640
|
+
const header = await this.#call("ui_tree", {
|
|
641
|
+
bundleId: MAIL_BUNDLE,
|
|
642
|
+
window: win.index,
|
|
643
|
+
detail: "labelled",
|
|
644
|
+
maxDepth: 1
|
|
645
|
+
});
|
|
646
|
+
const fields = new Map((header.elements ?? []).flatMap((el) => el.id ? [[el.id, el]] : []));
|
|
647
|
+
const subject = fields.get(SUBJECT_FIELD);
|
|
648
|
+
if (!subject) continue;
|
|
649
|
+
const body = await this.#bodyOf(win.index);
|
|
650
|
+
const reading = body ? await this.#readBody(body, quoteChars) : null;
|
|
651
|
+
const bccField = fields.get(RECIPIENT_FIELDS.bcc);
|
|
652
|
+
found.push({
|
|
653
|
+
subject: subject.value ?? win.title ?? "",
|
|
654
|
+
main: win.main === true,
|
|
655
|
+
from: fields.get(FROM_FIELD)?.value ?? null,
|
|
656
|
+
to: await this.#recipients(fields.get(RECIPIENT_FIELDS.to)),
|
|
657
|
+
cc: await this.#recipients(fields.get(RECIPIENT_FIELDS.cc)),
|
|
658
|
+
bcc: bccField ? await this.#recipients(bccField) : null,
|
|
659
|
+
...reading ?? {
|
|
660
|
+
text: null,
|
|
661
|
+
quoted: null,
|
|
662
|
+
quote: null,
|
|
663
|
+
quoteTruncated: false
|
|
664
|
+
}
|
|
665
|
+
});
|
|
571
666
|
}
|
|
667
|
+
return found;
|
|
668
|
+
}
|
|
669
|
+
/** The names in one recipient field: its tokens, then anything still being typed. */
|
|
670
|
+
async #recipients(field) {
|
|
671
|
+
if (!field) return [];
|
|
672
|
+
const typed = (field.value ?? "").split(TOKEN_CHAR).map((s) => s.trim());
|
|
673
|
+
const names = [];
|
|
674
|
+
if ((field.value ?? "").includes(TOKEN_CHAR)) try {
|
|
675
|
+
const tokens = await this.#call("expand", {
|
|
676
|
+
handle: field.handle,
|
|
677
|
+
detail: "all",
|
|
678
|
+
maxDepth: 2
|
|
679
|
+
});
|
|
680
|
+
for (const el of tokens.elements ?? []) if (el.subrole === TOKEN_SUBROLE && el.value?.trim()) names.push(el.value.trim());
|
|
681
|
+
} catch {}
|
|
682
|
+
return [...names, ...typed.filter((s) => s !== "")];
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* The body for a reader: own text, and the opening of the quote.
|
|
686
|
+
*
|
|
687
|
+
* When the quote boundary cannot be found the whole readable body is returned
|
|
688
|
+
* with `quoted: null` rather than nothing — a reviewer is not about to replace
|
|
689
|
+
* anything, so a body it cannot split is still worth reading, as long as it is
|
|
690
|
+
* labelled as unsplit.
|
|
691
|
+
*/
|
|
692
|
+
async #readBody(body, quoteChars) {
|
|
693
|
+
const split = await this.#split(body);
|
|
694
|
+
if (!split) return {
|
|
695
|
+
text: await this.bodyText(body),
|
|
696
|
+
quoted: null,
|
|
697
|
+
quote: null,
|
|
698
|
+
quoteTruncated: false
|
|
699
|
+
};
|
|
700
|
+
if (!split.own.quoted) return {
|
|
701
|
+
text: split.own.text,
|
|
702
|
+
quoted: false,
|
|
703
|
+
quote: null,
|
|
704
|
+
quoteTruncated: false
|
|
705
|
+
};
|
|
706
|
+
const whole = split.quoteBlocks.join("\n");
|
|
707
|
+
const treeCut = split.tree.truncated !== void 0 || (split.tree.matched ?? 0) > (split.tree.elements ?? []).length;
|
|
572
708
|
return {
|
|
573
|
-
text:
|
|
574
|
-
|
|
575
|
-
|
|
709
|
+
text: split.own.text,
|
|
710
|
+
quoted: true,
|
|
711
|
+
quote: whole.slice(0, quoteChars),
|
|
712
|
+
quoteTruncated: whole.length > quoteChars || treeCut
|
|
576
713
|
};
|
|
577
714
|
}
|
|
578
715
|
/**
|
|
@@ -3725,11 +3862,11 @@ var EnvelopeIndex = class EnvelopeIndex {
|
|
|
3725
3862
|
const where = ["m.deleted = 0"];
|
|
3726
3863
|
where.push(this.#mailboxPredicate(filters.mailboxRowids, params));
|
|
3727
3864
|
if (filters.query) {
|
|
3728
|
-
where.push(
|
|
3865
|
+
where.push(`(${this.#subjectExpr} LIKE ? ESCAPE '\\' OR a.address LIKE ? ESCAPE '\\' OR a.comment LIKE ? ESCAPE '\\')`);
|
|
3729
3866
|
params.push(contains(filters.query), contains(filters.query), contains(filters.query));
|
|
3730
3867
|
}
|
|
3731
3868
|
if (filters.subject) {
|
|
3732
|
-
where.push(
|
|
3869
|
+
where.push(`${this.#subjectExpr} LIKE ? ESCAPE '\\'`);
|
|
3733
3870
|
params.push(contains(filters.subject));
|
|
3734
3871
|
}
|
|
3735
3872
|
if (filters.sender) {
|
|
@@ -5174,6 +5311,62 @@ var AppleMailClient = class {
|
|
|
5174
5311
|
subject: opts.subject ?? null
|
|
5175
5312
|
}));
|
|
5176
5313
|
}
|
|
5314
|
+
/**
|
|
5315
|
+
* The drafts being written right now: every compose window open in Mail.
|
|
5316
|
+
*
|
|
5317
|
+
* Read from the windows, because nothing else sees them all — see
|
|
5318
|
+
* `MailAxLane.listComposers`. Each one is paired with the saved copies Mail
|
|
5319
|
+
* has autosaved under the same subject in a Drafts mailbox, which is where
|
|
5320
|
+
* the recipients' ADDRESSES are (the window only shows names) and what
|
|
5321
|
+
* `updateDraft` takes. The pairing is by subject, so it is offered as
|
|
5322
|
+
* candidates rather than asserted; `updateDraft` matches content before it
|
|
5323
|
+
* touches anything, so a wrong candidate is refused rather than edited.
|
|
5324
|
+
*/
|
|
5325
|
+
async listOpenDrafts(opts = {}) {
|
|
5326
|
+
if (!this.#ax) return {
|
|
5327
|
+
degraded: true,
|
|
5328
|
+
capability: "accessibility",
|
|
5329
|
+
drafts: [],
|
|
5330
|
+
reason: "Open compose windows can only be read through Cupertino's Accessibility lane, and this server was not started by Cupertino. Nothing was read, so this does NOT mean no draft is open.",
|
|
5331
|
+
hint: "Run the Mail server from Cupertino.app to use this tool."
|
|
5332
|
+
};
|
|
5333
|
+
if (!(await this.#ax.reach()).ok) return {
|
|
5334
|
+
degraded: true,
|
|
5335
|
+
capability: "accessibility",
|
|
5336
|
+
drafts: [],
|
|
5337
|
+
reason: "Mail's windows could not be read, so nothing was checked — this does NOT mean no draft is open.",
|
|
5338
|
+
hint: "Grant Accessibility to Cupertino.app in System Settings > Privacy & Security > Accessibility, then run apple_mail_diagnostics."
|
|
5339
|
+
};
|
|
5340
|
+
const composers = await this.#ax.listComposers(opts.quoteChars);
|
|
5341
|
+
const index = composers.length > 0 ? await this.index() : null;
|
|
5342
|
+
const drafts = [];
|
|
5343
|
+
for (const composer of composers) drafts.push({
|
|
5344
|
+
...composer,
|
|
5345
|
+
savedDrafts: index ? await this.#savedDrafts(composer.subject) : null
|
|
5346
|
+
});
|
|
5347
|
+
return {
|
|
5348
|
+
drafts,
|
|
5349
|
+
note: composers.length === 0 ? "No compose window is open in Mail." : "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." + (index ? "" : " `savedDrafts` is null because the search index cannot be read.")
|
|
5350
|
+
};
|
|
5351
|
+
}
|
|
5352
|
+
/** Drafts-mailbox messages carrying exactly this subject, newest first. */
|
|
5353
|
+
async #savedDrafts(subject) {
|
|
5354
|
+
if (!subject) return [];
|
|
5355
|
+
try {
|
|
5356
|
+
return ((await this.searchMessages({
|
|
5357
|
+
subject,
|
|
5358
|
+
mailbox: "Drafts",
|
|
5359
|
+
limit: 10,
|
|
5360
|
+
offset: 0
|
|
5361
|
+
}))?.messages ?? []).filter((m) => m.subject === subject).map((m) => ({
|
|
5362
|
+
ref: m.ref,
|
|
5363
|
+
saved: m.dateSent ?? m.dateReceived
|
|
5364
|
+
}));
|
|
5365
|
+
} catch (err) {
|
|
5366
|
+
this.#logger?.debug?.("listOpenDrafts: could not search Drafts", err);
|
|
5367
|
+
return [];
|
|
5368
|
+
}
|
|
5369
|
+
}
|
|
5177
5370
|
async checkForNewMail(account) {
|
|
5178
5371
|
const resolved = account ? await this.mailboxes.resolveAccount(account) : null;
|
|
5179
5372
|
return this.runner.run(CHECK_FOR_NEW_MAIL, { accountUuid: resolved?.id ?? null });
|
|
@@ -5344,6 +5537,10 @@ surfaces — a Mail ref means nothing to Notes or Calendar.
|
|
|
5344
5537
|
- **A conversation** is \`apple_mail_get_thread\`, not several \`get_message\`
|
|
5345
5538
|
calls.
|
|
5346
5539
|
- **Counts** are \`apple_mail_count_messages\`. Do not count by paging a search.
|
|
5540
|
+
- **"My draft", unnamed** — the one the user is writing — is
|
|
5541
|
+
\`apple_mail_list_open_drafts\`. It reads the compose windows themselves, so it
|
|
5542
|
+
sees a draft no search would find yet, and it keeps the user's own words apart
|
|
5543
|
+
from the message they quote.
|
|
5347
5544
|
|
|
5348
5545
|
## \`degraded: true\` is not an empty result
|
|
5349
5546
|
|
|
@@ -5823,7 +6020,7 @@ const registerComposeTools = (server, client) => {
|
|
|
5823
6020
|
});
|
|
5824
6021
|
}));
|
|
5825
6022
|
server.registerTool("apple_mail_update_draft", {
|
|
5826
|
-
description: "Replace the body of an unsent draft — including a REPLY draft you have just written and been asked to revise, which is the usual reason to reach for this. It takes one of two routes and the result says which in `method`. `inPlace`: the draft's own composer window is still open in Mail, so the body is edited in that window. Nothing is recreated, so threading, attachments and the quoted original all survive, no second draft appears, and your 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. `recreate`: no composer is open, so a new draft is composed with the same recipients and the old one deleted once the replacement is confirmed present; the ref you passed in is DEAD afterwards and the result carries the new one. It REFUSES rather than doing damage, and returns `replaced: false` with a reason when it does. Editing in place refuses when two composers share the subject, when the open window turns out to hold a different message, or when the draft's own text cannot be selected exactly — it will not risk swallowing the quoted original. Recreating refuses on a reply or forward draft, because In-Reply-To is set by Mail's reply command and a recreated one would silently start a new thread; on a draft carrying attachments, because their bytes are not available as files to re-attach; and on anything not in the Drafts mailbox, because deleting a sent or received message and writing a lookalike is not editing. In every refusal the original is untouched. If a recreated replacement cannot be confirmed the original is KEPT and you are told there are now two — never assume a clean swap without reading `replaced`. Editing in place brings Mail to the front for a moment and borrows the clipboard, both of which are put back.",
|
|
6023
|
+
description: "Replace the body of an unsent draft — including a REPLY draft you have just written and been asked to revise, which is the usual reason to reach for this. For a draft the user has open, apple_mail_list_open_drafts gives its ref under `savedDrafts`. It takes one of two routes and the result says which in `method`. `inPlace`: the draft's own composer window is still open in Mail, so the body is edited in that window. Nothing is recreated, so threading, attachments and the quoted original all survive, no second draft appears, and your 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. `recreate`: no composer is open, so a new draft is composed with the same recipients and the old one deleted once the replacement is confirmed present; the ref you passed in is DEAD afterwards and the result carries the new one. It REFUSES rather than doing damage, and returns `replaced: false` with a reason when it does. Editing in place refuses when two composers share the subject, when the open window turns out to hold a different message, or when the draft's own text cannot be selected exactly — it will not risk swallowing the quoted original. Recreating refuses on a reply or forward draft, because In-Reply-To is set by Mail's reply command and a recreated one would silently start a new thread; on a draft carrying attachments, because their bytes are not available as files to re-attach; and on anything not in the Drafts mailbox, because deleting a sent or received message and writing a lookalike is not editing. In every refusal the original is untouched. If a recreated replacement cannot be confirmed the original is KEPT and you are told there are now two — never assume a clean swap without reading `replaced`. Editing in place brings Mail to the front for a moment and borrows the clipboard, both of which are put back.",
|
|
5827
6024
|
inputSchema: {
|
|
5828
6025
|
ref: messageRefArg,
|
|
5829
6026
|
body: z.string().min(1).describe("The complete new body. This REPLACES the draft's text rather than appending to it, so include everything that should remain — read the draft first with apple_mail_get_message if you are editing rather than rewriting."),
|
|
@@ -5888,6 +6085,11 @@ const registerMessageTools = (server, client, allowWrites) => {
|
|
|
5888
6085
|
...missing.length > 0 ? { note: `Not downloaded by Mail yet: ${missing.join(", ")}. Its bytes are not on disk, so apple_mail_save_attachment cannot retrieve it. Open the message in Mail to download it first.` } : {}
|
|
5889
6086
|
};
|
|
5890
6087
|
}));
|
|
6088
|
+
server.registerTool("apple_mail_list_open_drafts", {
|
|
6089
|
+
description: "Read the drafts the user has open in Mail right now — every compose window, with its subject, From, the recipients' names as shown, the text they wrote separated from the quoted message below it, and the opening of that quote. Reach for this when the user says 'review my draft', 'check this email before I send it' or 'what do you think of my reply' without naming a message: the draft in front of them may never have been saved where a search finds it, and the window is the current text either way. `main: true` marks the window in front. Each draft carries `savedDrafts`, the refs Mail autosaved under the same subject: read one with apple_mail_get_message for recipient ADDRESSES, or pass it to apple_mail_update_draft to rewrite the body in place. Read-only: nothing is focused, typed or brought to the front. `degraded: true` means the windows could not be read, which is NOT the same as no draft being open.",
|
|
6090
|
+
inputSchema: { quoteChars: z.number().int().min(0).max(2e4).optional().describe("How much of the quoted original to return per draft. Default 2000; 0 for none.") },
|
|
6091
|
+
annotations: { readOnlyHint: true }
|
|
6092
|
+
}, async ({ quoteChars }) => wrap(async () => client.listOpenDrafts({ quoteChars })));
|
|
5891
6093
|
server.registerTool("apple_mail_get_message_source", {
|
|
5892
6094
|
description: "Get the raw RFC 5322 source of a message — every header and the undecoded body. Use this for header forensics (Received chains, SPF/DKIM/DMARC results, List-Unsubscribe), not for reading mail: apple_mail_get_message gives you the readable version without the noise. Capped and pageable via offset.",
|
|
5893
6095
|
inputSchema: {
|
|
@@ -6229,4 +6431,4 @@ const createServer = (opts) => {
|
|
|
6229
6431
|
//#endregion
|
|
6230
6432
|
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 };
|
|
6231
6433
|
|
|
6232
|
-
//# sourceMappingURL=server-
|
|
6434
|
+
//# sourceMappingURL=server-69NtCX3D.js.map
|