@mgcrea/mcp-apple-mail 1.24.1 → 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 CHANGED
@@ -138,14 +138,15 @@ npx @modelcontextprotocol/inspector node dist/cli.js
138
138
 
139
139
  ## Tools
140
140
 
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. |
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-DYBtv289.js";
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
@@ -67,7 +67,7 @@ declare const locateEnvelopeIndex: (opts?: LocateOptions) => LocateResult;
67
67
  * machinery without a job.
68
68
  */
69
69
  /**
70
- * `allowWrites`, `debug`, `osascriptPath`, `osascriptTimeoutMs` and `maxResults`
70
+ * `allowWrites`, `osascriptPath`, `osascriptTimeoutMs` and `maxResults`
71
71
  * come from `BaseConfigSchema` — every Apple-app server has them, with the same
72
72
  * bounds and the same defaults.
73
73
  */
@@ -75,7 +75,6 @@ declare const ConfigSchema: z.ZodObject<{
75
75
  allowWrites: z.ZodDefault<z.ZodBoolean>;
76
76
  exposePrompts: z.ZodDefault<z.ZodBoolean>;
77
77
  lazyTools: z.ZodDefault<z.ZodBoolean>;
78
- debug: z.ZodDefault<z.ZodBoolean>;
79
78
  osascriptPath: z.ZodDefault<z.ZodString>;
80
79
  osascriptTimeoutMs: z.ZodDefault<z.ZodNumber>;
81
80
  maxResults: z.ZodDefault<z.ZodNumber>;
@@ -142,6 +141,33 @@ type ComposerBody = {
142
141
  /** Whether a quoted original follows. */
143
142
  quoted: boolean;
144
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
+ };
145
171
  type ReachReport = {
146
172
  ok: boolean;
147
173
  /** `accessibility` when Mail's windows cannot be read; null when they can. */
@@ -299,6 +325,24 @@ declare class MailAxLane {
299
325
  */
300
326
  keys(ref: ComposerRef, strokes: Keystroke[], focusTimeoutMs?: number): Promise<boolean>;
301
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[]>;
302
346
  /**
303
347
  * Send the composer, or save it as a draft.
304
348
  *
@@ -952,6 +996,20 @@ declare class AppleMailClient {
952
996
  body: string;
953
997
  subject?: string | undefined;
954
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>>;
955
1013
  checkForNewMail(account?: string): Promise<unknown>;
956
1014
  sendMessage(opts: {
957
1015
  account?: string;
@@ -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;;KA2BpB;EAAgB;EAAgB;EAAc;;;;;;;;;;;;;;;;;;;;;;;KAuB9C;;EAEV;;EAEA;;EAEA;;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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":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;;;;;;;;;;;;;;;;;;EAqB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IAAU;IAAe;;;;;;;;;;EAsCvB,eACJ,aACA;IAAQ;MACP;IACD,SAAS;IACT,QAAQ;IACR;;IAEA;;EA2BI,iBACJ,aACA;IAAQ;IAAgB;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-DYBtv289.js";
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 };
@@ -1,7 +1,7 @@
1
- import { AppBusyError as MailBusyError, AppNotRunningError as MailNotRunningError, AppleAutomationError, AppleAutomationError as AppleMailError, BaseConfigSchema, IndexUnavailableError, OsascriptTimeoutError, PlatformError, PreconditionError, ProtocolError, SchemaDriftError, TccDeniedError, WritesDisabledError, assertStaticScript, confirmArg, createOsascriptRunner, describeAggregation, detectEpoch, escapeLike, fingerprintSchema, groupByArg, inspectFile, interferenceNote, limitArg, mapOsaError, openAxChannel, openReadOnly, parseBool, parseBound, parseConfig, parseIntOpt, parseList, project, promptArg, readPackageIdentity, registerSurfaceResources, registerWorkflowPrompt, requiredPromptArg, resolveLimit, selectArg, tableMap, trimmed, watchInterference, withBusyRetry, withLazyTools, wrap } from "@mgcrea/mcp-apple-core";
2
- import { closeSync, existsSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, statSync, writeFileSync } from "node:fs";
1
+ import { AppBusyError as MailBusyError, AppNotRunningError as MailNotRunningError, AppleAutomationError, AppleAutomationError as AppleMailError, BaseConfigSchema, IndexUnavailableError, OsascriptTimeoutError, PlatformError, PreconditionError, ProtocolError, SchemaDriftError, TccDeniedError, WritesDisabledError, assertStaticScript, buildBaseDiagnostics, confirmArg, createOsascriptRunner, describeAggregation, detectEpoch, escapeLike, fingerprintSchema, groupByArg, inspectFile, interferenceNote, limitArg, mapOsaError, openAxChannel, openReadOnly, parseBool, parseBound, parseConfig, parseIntOpt, parseList, project, promptArg, readPackageIdentity, registerSurfaceResources, registerWorkflowPrompt, requiredPromptArg, resolveLimit, selectArg, tableMap, trimmed, watchInterference, withBusyRetry, withLazyTools, wrap, writeConfinedFile } from "@mgcrea/mcp-apple-core";
2
+ import { closeSync, existsSync, openSync, readFileSync, readSync, readdirSync, statSync } from "node:fs";
3
3
  import { homedir } from "node:os";
4
- import { basename, dirname, join, resolve, sep } from "node:path";
4
+ import { basename, dirname, join } from "node:path";
5
5
  import { execFile } from "node:child_process";
6
6
  import { promisify } from "node:util";
7
7
  import { z } from "zod";
@@ -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: "26f4045",
18
- gitCommitDate: "2026-09-29T16:31:42+02:00"
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
- const from = starts[block];
569
- const to = starts[block + 1] ?? elements.length;
570
- lines.push(elements.slice(from, to).map((el) => el.value).filter((v) => typeof v === "string").join(""));
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: lines.join("\n"),
574
- blocks: boundary,
575
- quoted: boundary < starts.length
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
  /**
@@ -1388,7 +1525,7 @@ const extractAttachment = (emlxPath, filename, rowid) => {
1388
1525
  });
1389
1526
  if (!match) throw new PreconditionError(`No attachment named "${filename}" in this message. Use apple_mail_list_attachments to see what is there.`);
1390
1527
  const inline = partBytes(match);
1391
- if (inline.length > 0) return {
1528
+ if (hasContent(inline)) return {
1392
1529
  bytes: inline,
1393
1530
  from: "inline"
1394
1531
  };
@@ -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("(s.subject LIKE ? ESCAPE '\\' OR a.address LIKE ? ESCAPE '\\' OR a.comment LIKE ? ESCAPE '\\')");
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("s.subject LIKE ? ESCAPE '\\'");
3869
+ where.push(`${this.#subjectExpr} LIKE ? ESCAPE '\\'`);
3733
3870
  params.push(contains(filters.subject));
3734
3871
  }
3735
3872
  if (filters.sender) {
@@ -4880,7 +5017,7 @@ var AppleMailClient = class {
4880
5017
  results.push({
4881
5018
  ...base,
4882
5019
  status: "not-probed",
4883
- reason: noIndex ?? void 0
5020
+ ...noIndex ? { reason: noIndex } : {}
4884
5021
  });
4885
5022
  continue;
4886
5023
  }
@@ -4974,23 +5111,19 @@ var AppleMailClient = class {
4974
5111
  const decoded = decodeRef(ref);
4975
5112
  const located = await this.#lookupMessageFile(decoded);
4976
5113
  if (!located.found) throw new PreconditionError(`The message file was not found, so its attachments are not reachable. ${located.explain}`, { probed: located.lookup?.probed.slice(0, 3) ?? [] });
4977
- const root = resolve(this.config.attachmentDir);
4978
- const target = resolve(join(root, basename(filename)));
4979
- if (target !== join(root, basename(filename)) || !target.startsWith(root + sep)) throw new PreconditionError(`Refusing to write outside ${root}. Set APPLE_MAIL_ATTACHMENT_DIR to change the destination.`);
4980
- const { bytes, from } = extractAttachment(located.path, filename, decoded.id);
4981
- mkdirSync(root, { recursive: true });
4982
- try {
4983
- writeFileSync(target, bytes, {
4984
- mode: 384,
4985
- flag: opts.overwrite ? "w" : "wx"
4986
- });
4987
- } catch (err) {
4988
- if (err.code === "EEXIST") throw new PreconditionError(`${target} already exists; refusing to overwrite it.`);
4989
- throw err;
4990
- }
5114
+ let from = "inline";
4991
5115
  return {
4992
- path: target,
4993
- bytes: bytes.length,
5116
+ ...writeConfinedFile({
5117
+ root: this.config.attachmentDir,
5118
+ name: filename,
5119
+ bytes: () => {
5120
+ const extracted = extractAttachment(located.path, filename, decoded.id);
5121
+ from = extracted.from;
5122
+ return extracted.bytes;
5123
+ },
5124
+ overwrite: opts.overwrite ?? false,
5125
+ settingName: "APPLE_MAIL_ATTACHMENT_DIR"
5126
+ }),
4994
5127
  from
4995
5128
  };
4996
5129
  }
@@ -5178,6 +5311,62 @@ var AppleMailClient = class {
5178
5311
  subject: opts.subject ?? null
5179
5312
  }));
5180
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
+ }
5181
5370
  async checkForNewMail(account) {
5182
5371
  const resolved = account ? await this.mailboxes.resolveAccount(account) : null;
5183
5372
  return this.runner.run(CHECK_FOR_NEW_MAIL, { accountUuid: resolved?.id ?? null });
@@ -5231,7 +5420,7 @@ var AppleMailClient = class {
5231
5420
  * machinery without a job.
5232
5421
  */
5233
5422
  /**
5234
- * `allowWrites`, `debug`, `osascriptPath`, `osascriptTimeoutMs` and `maxResults`
5423
+ * `allowWrites`, `osascriptPath`, `osascriptTimeoutMs` and `maxResults`
5235
5424
  * come from `BaseConfigSchema` — every Apple-app server has them, with the same
5236
5425
  * bounds and the same defaults.
5237
5426
  */
@@ -5296,7 +5485,6 @@ const loadConfig = (env = process.env) => {
5296
5485
  allowWrites: parseBool(env.APPLE_MAIL_ALLOW_WRITES),
5297
5486
  exposePrompts: parseBool(env.APPLE_MAIL_EXPOSE_PROMPTS),
5298
5487
  lazyTools: parseBool(env.APPLE_MAIL_LAZY_TOOLS),
5299
- debug: parseBool(env.APPLE_MAIL_DEBUG),
5300
5488
  accounts: parseList(env.APPLE_MAIL_ACCOUNTS),
5301
5489
  mailRoot: trimmed(env.APPLE_MAIL_ROOT),
5302
5490
  envelopeIndexPath: trimmed(env.APPLE_MAIL_ENVELOPE_INDEX),
@@ -5349,6 +5537,10 @@ surfaces — a Mail ref means nothing to Notes or Calendar.
5349
5537
  - **A conversation** is \`apple_mail_get_thread\`, not several \`get_message\`
5350
5538
  calls.
5351
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.
5352
5544
 
5353
5545
  ## \`degraded: true\` is not an empty result
5354
5546
 
@@ -5522,14 +5714,13 @@ const buildDiagnostics = async (client, ctx) => {
5522
5714
  accountsError = err instanceof Error ? err.message : String(err);
5523
5715
  }
5524
5716
  const indexAgeSeconds = located.mtime ? Math.max(0, Math.round((Date.now() - Date.parse(located.mtime)) / 1e3)) : null;
5717
+ const base = buildBaseDiagnostics({
5718
+ build: BUILD_INFO,
5719
+ config: client.config,
5720
+ allowWrites: ctx.allowWrites
5721
+ });
5525
5722
  return {
5526
- server: {
5527
- name: BUILD_INFO.name,
5528
- version: BUILD_INFO.version,
5529
- gitCommit: BUILD_INFO.gitCommit,
5530
- node: process.version,
5531
- platform: process.platform
5532
- },
5723
+ ...base,
5533
5724
  lanes,
5534
5725
  messageFile,
5535
5726
  bodySearch: {
@@ -5574,8 +5765,7 @@ const buildDiagnostics = async (client, ctx) => {
5574
5765
  reason: located.reason
5575
5766
  },
5576
5767
  settings: {
5577
- allowWrites: ctx.allowWrites,
5578
- exposePrompts: client.config.exposePrompts,
5768
+ ...base.settings,
5579
5769
  accountAllowlist: client.config.accounts.length ? client.config.accounts : "(all accounts)",
5580
5770
  indexMode: client.config.indexMode,
5581
5771
  degradedMaxMessages: client.config.degradedMaxMessages,
@@ -5830,7 +6020,7 @@ const registerComposeTools = (server, client) => {
5830
6020
  });
5831
6021
  }));
5832
6022
  server.registerTool("apple_mail_update_draft", {
5833
- 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.",
5834
6024
  inputSchema: {
5835
6025
  ref: messageRefArg,
5836
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."),
@@ -5878,6 +6068,7 @@ const registerMessageTools = (server, client, allowWrites) => {
5878
6068
  body: message.content ?? "",
5879
6069
  note: "Body came from Mail rather than the message file, so attachment details are not " + `available. ${fallbackReason ?? ""}`.trimEnd()
5880
6070
  };
6071
+ const missing = parsed.attachments.filter((a) => !a.retrievable && a.filename).map((a) => a.filename);
5881
6072
  return {
5882
6073
  ref: message.ref,
5883
6074
  source,
@@ -5891,9 +6082,14 @@ const registerMessageTools = (server, client, allowWrites) => {
5891
6082
  truncated: parsed.truncated,
5892
6083
  body: parsed.body,
5893
6084
  attachments: parsed.attachments,
5894
- ...parsed.attachments.some((a) => !a.inline) ? { note: "Some attachments are stored outside this message file, so their sizes are unknown and apple_mail_save_attachment cannot retrieve them. Open the message in Mail to download them first." } : {}
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.` } : {}
5895
6086
  };
5896
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 })));
5897
6093
  server.registerTool("apple_mail_get_message_source", {
5898
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.",
5899
6095
  inputSchema: {
@@ -6235,4 +6431,4 @@ const createServer = (opts) => {
6235
6431
  //#endregion
6236
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 };
6237
6433
 
6238
- //# sourceMappingURL=server-DYBtv289.js.map
6434
+ //# sourceMappingURL=server-69NtCX3D.js.map