@mgcrea/mcp-apple-mail 1.37.0 → 1.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js 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-D5S4dzq6.js";
2
+ import { a as loadConfig, b as MAIL_SURFACE, j as BUILD_INFO, r as createServer } from "./server-D-UcpTRv.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
@@ -193,6 +193,14 @@ type EditComposerArgs = {
193
193
  attachments?: string[];
194
194
  save?: boolean;
195
195
  expectHead?: string;
196
+ /**
197
+ * With `expectHead`: the head is the draft's whole stored text (up to its
198
+ * cap), so below 120 characters the window must hold exactly that text, not
199
+ * merely begin it. Sent for a draft that is not a reply, whose stored text is
200
+ * its own; a reply's runs on into its quote, which the window lists apart. An
201
+ * app that predates it ignores it and checks the prefix.
202
+ */
203
+ expectWhole?: boolean;
196
204
  };
197
205
  type ReachReport = {
198
206
  ok: boolean;
@@ -662,6 +670,14 @@ declare class MailboxMap {
662
670
  * `[Gmail]/`-stripped, then final path segment, then case-insensitive.
663
671
  */
664
672
  resolveMailboxName(account: MailAccount, wanted: string): string;
673
+ /**
674
+ * `resolveMailboxName` for a name a caller asked for, with `resolveAccount`'s
675
+ * second chance: the account came out of a list that can be stale by design,
676
+ * so a name it lacks earns one fresh read before it is refused. A mailbox
677
+ * created in Mail, or synced from another device, since that list was taken
678
+ * is then found on the first call rather than the one after.
679
+ */
680
+ resolveMailbox(account: MailAccount, wanted: string): Promise<string>;
665
681
  /**
666
682
  * Map an Envelope Index `mailboxes.url` onto a scriptable account + mailbox.
667
683
  * The URL host is the account UUID (verified against live Mail), so this join
@@ -1017,7 +1033,7 @@ declare class AppleMailClient {
1017
1033
  * without their attachments is most older mail, Mail is asked to download
1018
1034
  * the attachment (see `#fetchFromMail`).
1019
1035
  */
1020
- saveAttachment(ref: string, filename: string, opts?: {
1036
+ saveAttachment(ref: string, requested: string, opts?: {
1021
1037
  overwrite?: boolean;
1022
1038
  }): Promise<{
1023
1039
  path: 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/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/client/watch.ts","../src/tools/watch.ts","../src/server.ts","../src/tools/index.ts"],"mappings":";;;;;cAkBa,YAAY;;;;cCeZ,6BAA6B;WACtB;EAElB,YAAY;;;;;;;;;;;;;;;;;;;;KCbF;;EAEV;;EAEA;EACA;;EAEA;EACA;EACA;EACA;EACA;;EAEA;EACA;EACA;;KAKU;;EAEV;;EAEA;;EAEA;;EAEA;;cAiBW,sBAAmB,OAAU,kBAAqB;;;;;;;;;;;;;;;cC3CzD,cAAY,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GAyFP,EAAA,KAAA;KAEC,SAAS,EAAE,aAAa;;;;;cAMvB,aAAU,MAAS,OAAO,eAA2B;;;KCxCtD;EAAgB;EAAgB;EAAc;;;KAG9C;;;;;;;;;EASV;;;;;;;;;;;EAWA;;EAEA;;;;;;;;EAQA;;EAEA;;EAEA;;EAEA;EACA;EACA;;EAEA;;EAEA;EACA;;;;;;EAMA;;EAEA;;EAEA;;;;;;EAMA;;EAEA;;KAGU;EACV;EACA;;;;;;;EAOA;EACA;EACA;IAAU;IAAc;;EACxB;EACA;EACA;;KAGU;EACV;;EAEA;EACA;;KAiBU;EACV;EACA;;cAGW;;UAUJ;;SAOA,KACL,MAAK,OAAO,YACZ,OAAM,oBACL;EAKH;;EAKA,SAAS;;;;;;;EAcH,UAAU,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AAa,QAChB,WAAS,QACT,iBAAe,KAClB"}
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/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/client/watch.ts","../src/tools/watch.ts","../src/server.ts","../src/tools/index.ts"],"mappings":";;;;;cAkBa,YAAY;;;;cCeZ,6BAA6B;WACtB;EAElB,YAAY;;;;;;;;;;;;;;;;;;;;KCbF;;EAEV;;EAEA;EACA;;EAEA;EACA;EACA;EACA;EACA;;EAEA;EACA;EACA;;KAKU;;EAEV;;EAEA;;EAEA;;EAEA;;cAiBW,sBAAmB,OAAU,kBAAqB;;;;;;;;;;;;;;;cC3CzD,cAAY,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GAyFP,EAAA,KAAA;KAEC,SAAS,EAAE,aAAa;;;;;cAMvB,aAAU,MAAS,OAAO,eAA2B;;;KCxCtD;EAAgB;EAAgB;EAAc;;;KAG9C;;;;;;;;;EASV;;;;;;;;;;;EAWA;;EAEA;;;;;;;;EAQA;;EAEA;;EAEA;;EAEA;EACA;EACA;;EAEA;;EAEA;EACA;;;;;;EAMA;;EAEA;;EAEA;;;;;;EAMA;;EAEA;;KAGU;EACV;EACA;;;;;;;EAOA;EACA;EACA;IAAU;IAAc;;EACxB;EACA;EACA;;;;;;;;EAQA;;KAGU;EACV;;EAEA;EACA;;KAiBU;EACV;EACA;;cAGW;;UAUJ;;SAOA,KACL,MAAK,OAAO,YACZ,OAAM,oBACL;EAKH;;EAKA,SAAS;;;;;;;EAcH,UAAU,sBAAsB,QAAQ;;;;;;;;;;;;EAmBxC,aAAa,MAAM,mBAAmB,QAAQ;;;;;;;;EA0C9C,WAAW;;;;;;;;;;;;;;;;;;EAqBX,SAAS,QAAQ;;;;;;;;;;;;;;;SA2BhB,aAAa;;kB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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-D5S4dzq6.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-D-UcpTRv.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: "9f3ce2c",
18
- gitCommitDate: "2026-11-06T12:19:38+01:00"
17
+ gitCommit: "45c3a7e",
18
+ gitCommitDate: "2026-11-10T15:30:40+01:00"
19
19
  };
20
20
  //#endregion
21
21
  //#region src/client/errors.ts
@@ -586,6 +586,14 @@ const headerFilename = (disposition, contentType) => {
586
586
  return null;
587
587
  };
588
588
  /**
589
+ * Whether two spellings name the same attachment.
590
+ *
591
+ * The message file, the sidecar tree on disk and Mail can each hold an accented
592
+ * name in NFC or NFD, so a byte comparison sends a name the list tools gave out
593
+ * back as "no attachment named". Mail's own download script compares NFC too.
594
+ */
595
+ const sameAttachmentName = (a, b) => a.normalize("NFC") === b.normalize("NFC");
596
+ /**
589
597
  * The RFC 2231 form, including the numbered continuations long names use.
590
598
  *
591
599
  * A continuation is only percent-decoded when its own segment is starred —
@@ -604,6 +612,7 @@ const extendedParam = (value, param) => {
604
612
  });
605
613
  if (segments.length === 0) return null;
606
614
  segments.sort((a, b) => a.index - b.index);
615
+ if (segments.every((s) => !s.encoded)) return decodeEncodedWords(segments.map((s) => s.text).join(""));
607
616
  let charset = null;
608
617
  let out = "";
609
618
  for (const [position, segment] of segments.entries()) {
@@ -1148,10 +1157,16 @@ const walkParts = (part, visit) => {
1148
1157
  const extractAttachment = (emlxPath, filename, rowid) => {
1149
1158
  const root = parsePart(splitEmlx(readFileSync(emlxPath)));
1150
1159
  let match = null;
1160
+ const names = [];
1151
1161
  walkParts(root, (p) => {
1152
- if (!match && p.filename === filename) match = p;
1162
+ if (p.filename === null) return;
1163
+ names.push(p.filename);
1164
+ if (!match && sameAttachmentName(p.filename, filename)) match = p;
1153
1165
  });
1154
- if (!match) throw new PreconditionError$1(`No attachment named "${filename}" in this message. Use apple_mail_list_attachments to see what is there.`);
1166
+ if (!match) {
1167
+ const listed = names.length > 0 ? `It lists: ${names.join(", ")}.` : "It lists none.";
1168
+ throw new PreconditionError$1(`No attachment named "${filename}" in this message. ${listed}`);
1169
+ }
1155
1170
  const inline = partBytes(match);
1156
1171
  if (hasContent(inline)) return {
1157
1172
  bytes: inline,
@@ -1194,7 +1209,7 @@ const findNamedFile = (root, filename, depth) => {
1194
1209
  if (depth > 4) return null;
1195
1210
  for (const entry of safeReaddir(root)) {
1196
1211
  const full = join(root, entry);
1197
- if (entry === filename) return full;
1212
+ if (sameAttachmentName(entry, filename)) return full;
1198
1213
  try {
1199
1214
  if (statSync(full).isDirectory()) {
1200
1215
  const hit = findNamedFile(full, filename, depth + 1);
@@ -2426,6 +2441,23 @@ const SEND_MESSAGE = script(`
2426
2441
  }
2427
2442
 
2428
2443
  if (p.sendNow) {
2444
+ // Read back right before the send, after everything that touched the
2445
+ // window: a file Mail took without throwing and never attached would
2446
+ // otherwise go out missing. A count Mail will not give is not a shortfall.
2447
+ var wanted = (p.attachments || []).length;
2448
+ var held = wanted ? prop(function () { return msg.content.attachments.length; }, null) : 0;
2449
+ if (held !== null && held < wanted) {
2450
+ return ok({
2451
+ sent: false, draft: true, degraded: true, capability: "attachments",
2452
+ subjectLength: String(p.subject || "").length,
2453
+ recipientCount: (p.to || []).length + (p.cc || []).length + (p.bcc || []).length,
2454
+ attachments: held, attachmentsRequested: wanted,
2455
+ note:
2456
+ "Mail holds " + held + " of the " + wanted + " files asked for, so the message was " +
2457
+ "NOT sent. It is open in Mail as a draft: attach the missing files there and send " +
2458
+ "it, or close it without saving and try again."
2459
+ });
2460
+ }
2429
2461
  msg.send();
2430
2462
  return ok({ sent: true, unquoted: unquoted, subjectLength: String(p.subject || "").length,
2431
2463
  recipientCount: (p.to || []).length + (p.cc || []).length + (p.bcc || []).length,
@@ -2596,10 +2628,11 @@ const UPDATE_DRAFT = script(`
2596
2628
  "those are written by Mail's own reply command, which needs the original message. " +
2597
2629
  "Recreating it would produce a draft that looks right and starts a NEW thread.",
2598
2630
  hint:
2599
- "This draft's composer window is NOT open in Mail — if it were, the body would have been " +
2600
- "edited in place and this refusal would not have happened. Either reopen the draft in " +
2601
- "Mail and edit it there, or delete it and start again with apple_mail_reply_to_message, " +
2602
- "which threads correctly and leaves the composer open for further revisions."
2631
+ "Editing a reply in its open composer window takes the Mail server run from " +
2632
+ "Cupertino.app, and this one is not, so no window was looked for. Run it from " +
2633
+ "Cupertino.app, or edit the draft in Mail directly, or delete it and start again with " +
2634
+ "apple_mail_reply_to_message, which threads correctly and leaves the composer open for " +
2635
+ "further revisions."
2603
2636
  });
2604
2637
  }
2605
2638
  if (attachments > 0) {
@@ -3193,7 +3226,7 @@ const REPLY_OR_FORWARD = script(`
3193
3226
  );
3194
3227
  }
3195
3228
  return ok({ sent: true, mode: p.mode, bodyVerified: bodyVerified,
3196
- verifiedChars: verifiedChars, subject: subject });
3229
+ verifiedChars: verifiedChars, subject: subject, attachments: attached.count });
3197
3230
  }
3198
3231
 
3199
3232
  // A draft is left for the person to read, unless the setting asks otherwise.
@@ -3205,6 +3238,7 @@ const REPLY_OR_FORWARD = script(`
3205
3238
  subject: subject,
3206
3239
  bodyVerified: bodyVerified,
3207
3240
  verifiedChars: verifiedChars,
3241
+ attachments: attached.count,
3208
3242
  note: bodyVerified
3209
3243
  ? "Draft window is open in Mail for review; its body was read back out of the window and matches."
3210
3244
  : "Draft window is open in Mail for review."
@@ -4424,6 +4458,23 @@ var MailboxMap = class {
4424
4458
  throw new PreconditionError$1(`No mailbox "${wanted}" in account "${account.name}". Available: ${account.mailboxes.join(", ")}.`);
4425
4459
  }
4426
4460
  /**
4461
+ * `resolveMailboxName` for a name a caller asked for, with `resolveAccount`'s
4462
+ * second chance: the account came out of a list that can be stale by design,
4463
+ * so a name it lacks earns one fresh read before it is refused. A mailbox
4464
+ * created in Mail, or synced from another device, since that list was taken
4465
+ * is then found on the first call rather than the one after.
4466
+ */
4467
+ async resolveMailbox(account, wanted) {
4468
+ try {
4469
+ return this.resolveMailboxName(account, wanted);
4470
+ } catch (error) {
4471
+ if (!(error instanceof PreconditionError$1)) throw error;
4472
+ const fresh = (await this.accounts(true)).find((a) => a.id === account.id);
4473
+ if (!fresh) throw error;
4474
+ return this.resolveMailboxName(fresh, wanted);
4475
+ }
4476
+ }
4477
+ /**
4427
4478
  * Map an Envelope Index `mailboxes.url` onto a scriptable account + mailbox.
4428
4479
  * The URL host is the account UUID (verified against live Mail), so this join
4429
4480
  * is exact rather than a heuristic on display names.
@@ -4585,13 +4636,46 @@ const NAMED = {
4585
4636
  apos: "'",
4586
4637
  nbsp: "\xA0"
4587
4638
  };
4588
- const decodeEntities = (raw) => raw.replaceAll(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (whole, name) => {
4639
+ const decodeEntity = (whole, name) => {
4589
4640
  if (name[0] === "#") {
4590
4641
  const code = name[1] === "x" || name[1] === "X" ? Number.parseInt(name.slice(2), 16) : Number.parseInt(name.slice(1), 10);
4591
4642
  return Number.isFinite(code) && code > 0 && code <= 1114111 ? String.fromCodePoint(code) : whole;
4592
4643
  }
4593
4644
  return NAMED[name.toLowerCase()] ?? whole;
4594
- });
4645
+ };
4646
+ /**
4647
+ * A run's text with its entities decoded, and where each of its UTF-16 units came from in the
4648
+ * run, so an edit can be spliced into the source and the rest of the run kept as it was.
4649
+ */
4650
+ const decodeEntities = (raw) => {
4651
+ let text = "";
4652
+ const at = [];
4653
+ let cursor = 0;
4654
+ const copy = (end) => {
4655
+ for (; cursor < end; cursor += 1) {
4656
+ text += raw[cursor];
4657
+ at.push(cursor);
4658
+ }
4659
+ };
4660
+ for (const entity of raw.matchAll(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi)) {
4661
+ const whole = entity[0];
4662
+ const decoded = decodeEntity(whole, entity[1]);
4663
+ copy(entity.index);
4664
+ if (decoded === whole) {
4665
+ copy(entity.index + whole.length);
4666
+ continue;
4667
+ }
4668
+ for (let unit = 0; unit < decoded.length; unit += 1) at.push(entity.index);
4669
+ text += decoded;
4670
+ cursor = entity.index + whole.length;
4671
+ }
4672
+ copy(raw.length);
4673
+ at.push(raw.length);
4674
+ return {
4675
+ text,
4676
+ at
4677
+ };
4678
+ };
4595
4679
  const encodeText = (text) => text.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\xA0", "&nbsp;");
4596
4680
  /**
4597
4681
  * A replacement's text as HTML: encoded, and each line break it carries a
@@ -4612,7 +4696,7 @@ const tokenize = (html) => {
4612
4696
  if (text) tokens.push({
4613
4697
  kind: "text",
4614
4698
  raw: text,
4615
- text: decodeEntities(text)
4699
+ ...decodeEntities(text)
4616
4700
  });
4617
4701
  text = "";
4618
4702
  };
@@ -4704,15 +4788,15 @@ const applyHtmlEdits = (edits, html) => {
4704
4788
  });
4705
4789
  }
4706
4790
  const edited = /* @__PURE__ */ new Map();
4707
- for (const at of new Set(placed.map((p) => p.token))) {
4708
- const text = tokens[at].text;
4709
- let encoded = "";
4791
+ for (const index of new Set(placed.map((p) => p.token))) {
4792
+ const { raw, at } = tokens[index];
4793
+ let spliced = "";
4710
4794
  let cursor = 0;
4711
- for (const p of placed.filter((q) => q.token === at).toSorted((a, b) => a.start - b.start)) {
4712
- encoded += encodeText(text.slice(cursor, p.start)) + encodeReplacement(p.replace);
4795
+ for (const p of placed.filter((q) => q.token === index).toSorted((a, b) => a.start - b.start)) {
4796
+ spliced += raw.slice(at[cursor], at[p.start]) + encodeReplacement(p.replace);
4713
4797
  cursor = p.end;
4714
4798
  }
4715
- edited.set(at, encoded + encodeText(text.slice(cursor)));
4799
+ edited.set(index, spliced + raw.slice(at[cursor]));
4716
4800
  }
4717
4801
  const out = tokens.map((token, at) => edited.get(at) ?? token.raw).join("");
4718
4802
  return {
@@ -5056,6 +5140,7 @@ const rebuildDraft = async (deps, target, opts) => {
5056
5140
  const found = await awaitNewComposer(lane, before, deps.composerTimeoutMs ?? COMPOSER_TIMEOUT_MS, opened.subject);
5057
5141
  if (found === null || "ambiguous" in found) return refuse("composer", found === null ? `Mail was asked to open a ${kind} for "${opened.subject}", and no new window under that title was readable in time. Nothing was filled. The original draft was not changed.` : `Mail was asked to open a ${kind} for "${opened.subject}", and ` + (found.ambiguous.length === 1 ? `the one new window under that title (${found.ambiguous[0]}) could not be told from the composer already open under it. ` : `${found.ambiguous.length} new windows under that title appeared (${found.ambiguous.join(", ")}), so which one is it cannot be told. `) + "Nothing was filled. The original draft was not changed.", `Look for an empty ${kind} window in Mail and close it without saving.`);
5058
5142
  handle = found.handle;
5143
+ if (squash(opened.subject) !== squash(subject)) return refuse("subject", `Mail did not take the subject: it was given "${subject}" and the new ${kind} holds "${opened.subject}". Nothing was filled. ${leftOpen(handle)}`, closeIt, { composer: handle });
5059
5144
  const wanted = recipients;
5060
5145
  const got = opened.recipients;
5061
5146
  if (!got || !sameAddresses(got.to, wanted.to) || !sameAddresses(got.cc, wanted.cc) || !sameAddresses(got.bcc, wanted.bcc)) return refuse("recipients", `Mail did not take the draft's recipients: it was given ${JSON.stringify(wanted)} and holds ${JSON.stringify(got ?? null)}. Nothing was filled. ${leftOpen(handle)}`, closeIt, { composer: handle });
@@ -5201,8 +5286,11 @@ const groupRefsByMailbox = (refs) => {
5201
5286
  *
5202
5287
  * * The window is matched to the draft by CONTENT, not only by subject. Two
5203
5288
  * replies in one thread carry the same title.
5204
- * * The first 120 characters of the stored text go along as `expectHead`, so
5205
- * the app checks the same thing again against the window it actually edits.
5289
+ * * The stored text's opening goes along as `expectHead`, so the app checks
5290
+ * the same thing again against the window it actually edits: the first 120
5291
+ * characters for a reply, and for any other draft its stored text whole (up
5292
+ * to 400 characters) with `expectWhole`, since below the cap its window must
5293
+ * hold exactly that text.
5206
5294
  * * Every refusal the app makes is returned exactly as it answered.
5207
5295
  */
5208
5296
  /**
@@ -5239,12 +5327,13 @@ const refuse = (capability, facts, reason, hint, extra = {}) => ({
5239
5327
  * the other is what an accessibility client sees a WebKit view display — and
5240
5328
  * they agree on the words while disagreeing about every line break.
5241
5329
  */
5242
- const sameDraft = (stored, shown) => {
5330
+ const sameDraft = (stored, shown, whole) => {
5243
5331
  const a = squash(stored.replaceAll(FILE_CHAR, ""));
5244
5332
  const b = squash(shown.replaceAll(FILE_CHAR, ""));
5245
5333
  if (a.length === 0 || b.length === 0) return a.length === b.length;
5246
5334
  const chars = Math.min(a.length, b.length, IDENTITY_CHARS);
5247
- return a.slice(0, chars) === b.slice(0, chars);
5335
+ if (a.slice(0, chars) !== b.slice(0, chars)) return false;
5336
+ return !whole || chars === IDENTITY_CHARS || a.length === b.length;
5248
5337
  };
5249
5338
  /** A composer whose text the listing could not read: a background tab, or a body not loaded. */
5250
5339
  const isHidden = (c) => c.tab === "background" || c.text === null;
@@ -5264,7 +5353,7 @@ const reviseDraftInPlace = async (lane, facts, opts) => {
5264
5353
  if (sameSubject.length === 0) return null;
5265
5354
  const hidden = sameSubject.filter(isHidden);
5266
5355
  const read = sameSubject.filter((c) => !isHidden(c));
5267
- const matches = read.filter((c) => sameDraft(facts.contentHead, c.text ?? ""));
5356
+ const matches = read.filter((c) => sameDraft(facts.contentHead, c.text ?? "", !facts.isReply));
5268
5357
  if (matches.length === 0 && hidden.length === 0) return refuse("identity", facts, `A composer titled "${facts.subject}" is open, but what it holds is not what this draft holds — most likely a different message under the same subject, such as another reply in the thread. Rewriting it would destroy text belonging to something else, so nothing was touched.`, "Check which windows are open in Mail, or edit the draft there directly.", {
5269
5358
  composerText: (read[0]?.text ?? "").slice(0, 200),
5270
5359
  draftText: facts.contentHead.slice(0, 200)
@@ -5277,13 +5366,17 @@ const reviseDraftInPlace = async (lane, facts, opts) => {
5277
5366
  handle = (matches[0] ?? hidden[0]).composer;
5278
5367
  }
5279
5368
  const files = opts.attachments ?? [];
5280
- const head = facts.contentHead.slice(0, IDENTITY_CHARS);
5369
+ const whole = !facts.isReply;
5370
+ const head = whole ? facts.contentHead : facts.contentHead.slice(0, IDENTITY_CHARS);
5281
5371
  const answer = await lane.editComposer({
5282
5372
  composer: handle,
5283
5373
  ...opts.edits !== void 0 ? { edits: opts.edits } : {},
5284
5374
  ...opts.body !== void 0 ? { body: opts.body } : {},
5285
5375
  ...files.length > 0 ? { attachments: files } : {},
5286
- ...matched || head.length > 0 ? { expectHead: head } : {}
5376
+ ...matched || head.length > 0 ? {
5377
+ expectHead: head,
5378
+ ...whole ? { expectWhole: true } : {}
5379
+ } : {}
5287
5380
  });
5288
5381
  if (answer.replaced !== true) return answer;
5289
5382
  return {
@@ -5555,7 +5648,7 @@ var AppleMailClient = class {
5555
5648
  * Events otherwise, which measured 8.4 s for twenty and is capped.
5556
5649
  */
5557
5650
  async listMessages(account, mailbox, limit) {
5558
- const name = this.mailboxes.resolveMailboxName(account, mailbox);
5651
+ const name = await this.mailboxes.resolveMailbox(account, mailbox);
5559
5652
  const scope = await this.#indexScope(account, name);
5560
5653
  if ("reason" in scope) return {
5561
5654
  ...await this.listRecent(account, name, limit),
@@ -5567,7 +5660,17 @@ var AppleMailClient = class {
5567
5660
  mailboxRowids: scope.rowids,
5568
5661
  limit,
5569
5662
  offset: 0
5570
- }).map((r) => this.#rowToSummary(r, lookup)).filter((m) => m !== null);
5663
+ }).map((r) => {
5664
+ const summary = this.#rowToSummary(r, lookup);
5665
+ return summary ? {
5666
+ ...summary,
5667
+ ref: encodeRef({
5668
+ accountUuid: account.id,
5669
+ mailbox: name,
5670
+ id: r.rowid
5671
+ })
5672
+ } : null;
5673
+ }).filter((m) => m !== null);
5571
5674
  const { total } = scope.index.count({ mailboxRowids: scope.rowids });
5572
5675
  return {
5573
5676
  mailbox: name,
@@ -5582,7 +5685,7 @@ var AppleMailClient = class {
5582
5685
  * that figure is the cached badge value and the Apple Event cost 0.77 s.
5583
5686
  */
5584
5687
  async countMessages(account, mailbox) {
5585
- const name = this.mailboxes.resolveMailboxName(account, mailbox);
5688
+ const name = await this.mailboxes.resolveMailbox(account, mailbox);
5586
5689
  const scope = await this.#indexScope(account, name);
5587
5690
  if ("reason" in scope) {
5588
5691
  const counts = await this.countMailbox(account, name);
@@ -5713,7 +5816,7 @@ var AppleMailClient = class {
5713
5816
  if (!opts.account && !opts.mailbox) return void 0;
5714
5817
  const lookup = await this.mailboxLookup();
5715
5818
  const account = opts.account ? await this.mailboxes.resolveAccount(opts.account) : null;
5716
- const wanted = opts.mailbox ? account ? this.mailboxes.resolveMailboxName(account, opts.mailbox) : opts.mailbox : null;
5819
+ const wanted = opts.mailbox ? account ? await this.mailboxes.resolveMailbox(account, opts.mailbox) : opts.mailbox : null;
5717
5820
  const rowids = [];
5718
5821
  for (const [rowid, entry] of lookup) {
5719
5822
  if (account && entry.accountUuid !== account.id) continue;
@@ -5930,6 +6033,17 @@ var AppleMailClient = class {
5930
6033
  source: "emlx"
5931
6034
  };
5932
6035
  }
6036
+ /**
6037
+ * The mailbox the index says a ref's row lives in, when it is in the ref's
6038
+ * account, or null: no index, no such row, or a mailbox the account list
6039
+ * cannot name.
6040
+ */
6041
+ async #rowMailbox(ref) {
6042
+ const row = (await this.index())?.byRowid(ref.id);
6043
+ if (!row?.mailboxUrl) return null;
6044
+ const where = await this.mailboxes.resolveIndexUrl(row.mailboxUrl);
6045
+ return where && where.account.id === ref.accountUuid ? where.mailbox : null;
6046
+ }
5933
6047
  /** A ref's envelope fields from the index, keeping the ref the caller passed. */
5934
6048
  async #indexSummary(ref) {
5935
6049
  const row = (await this.index())?.byRowid(ref.id);
@@ -5996,6 +6110,19 @@ var AppleMailClient = class {
5996
6110
  path: lookup.path,
5997
6111
  partial: lookup.partial
5998
6112
  };
6113
+ const home = await this.#rowMailbox(ref);
6114
+ if (home !== null && home !== ref.mailbox) try {
6115
+ const there = lookupEmlx({
6116
+ accountDirectory: account.directory,
6117
+ mailbox: home,
6118
+ rowid: ref.id
6119
+ });
6120
+ if (there.found) return {
6121
+ found: true,
6122
+ path: there.path,
6123
+ partial: there.partial
6124
+ };
6125
+ } catch {}
5999
6126
  return {
6000
6127
  found: false,
6001
6128
  lookup,
@@ -6155,7 +6282,8 @@ var AppleMailClient = class {
6155
6282
  * without their attachments is most older mail, Mail is asked to download
6156
6283
  * the attachment (see `#fetchFromMail`).
6157
6284
  */
6158
- async saveAttachment(ref, filename, opts = {}) {
6285
+ async saveAttachment(ref, requested, opts = {}) {
6286
+ const filename = decodeEncodedWords(requested);
6159
6287
  const decoded = decodeRef(ref);
6160
6288
  const located = await this.#lookupMessageFile(decoded);
6161
6289
  if (!located.found) throw new PreconditionError$1(`The message file was not found, so its attachments are not reachable. ${located.explain}`, { probed: located.lookup?.probed.slice(0, 3) ?? [] });
@@ -7927,8 +8055,10 @@ var MailArrivalSource = class {
7927
8055
  * While set, `since` stops before the first row whose mailbox is not among
7928
8056
  * `knownMailboxes`, so the cursor stays below a row the lookup cannot judge
7929
8057
  * yet. The watch service sets it around a tick, refreshes when `takeHeld()`
7930
- * says it stopped, and ticks again; a read never sees it set. The events
7931
- * service keeps it set, and refreshes before the next poll or tick.
8058
+ * says it stopped, and ticks again; it sets it around a read too, and drops
8059
+ * what the read held, so the cursor a client gets never passes such a row.
8060
+ * The events service keeps it set, and refreshes before the next poll or
8061
+ * tick.
7932
8062
  */
7933
8063
  holdNewMailboxes = false;
7934
8064
  constructor(opts) {
@@ -8048,8 +8178,9 @@ const isMailRunning = async (run = defaultRun) => {
8048
8178
  * that writes a new `Envelope Index` and renames it over the old one leaves that
8049
8179
  * connection reading the deleted file: nothing new arrives there and nothing
8050
8180
  * errors. So the service records the file's inode when it opens it, compares on
8051
- * every trigger, and reopens before the tick when it changed. The registry then
8052
- * sees the renumbered head below its mark and resets without notifying. The
8181
+ * every trigger, and reopens before the tick when it changed, then restarts the
8182
+ * registry at the new file's head, so nothing it already holds is reported,
8183
+ * whether its renumbered head is below the old mark or past it. The
8053
8184
  * mailbox rowids may be renumbered too, so the lookup is rebuilt from the new
8054
8185
  * file's `mailboxes` table with the accounts already in hand.
8055
8186
  *
@@ -8144,10 +8275,23 @@ var MailWatchService = class {
8144
8275
  get #loaded() {
8145
8276
  return this.#accounts !== void 0;
8146
8277
  }
8278
+ /** True while `onTrigger` ticks, so `source.since` can tell a tick from a read. */
8279
+ #ticking = false;
8147
8280
  /** What `createWatches` is given. Delegates to the source `ensure()` builds. */
8148
8281
  source = {
8149
8282
  head: () => this.#ready().head(),
8150
- since: (after, limit) => this.#loaded ? this.#ready().since(after, limit) : []
8283
+ since: (after, limit) => {
8284
+ if (!this.#loaded) return [];
8285
+ const inner = this.#ready();
8286
+ if (this.#ticking || this.#events) return inner.since(after, limit);
8287
+ inner.holdNewMailboxes = true;
8288
+ try {
8289
+ return inner.since(after, limit);
8290
+ } finally {
8291
+ inner.holdNewMailboxes = false;
8292
+ inner.takeHeld();
8293
+ }
8294
+ }
8151
8295
  };
8152
8296
  constructor(opts) {
8153
8297
  this.#client = opts.client;
@@ -8260,6 +8404,7 @@ var MailWatchService = class {
8260
8404
  try {
8261
8405
  this.#open(this.#path);
8262
8406
  this.#reopenFailing = false;
8407
+ this.#registry?.restart();
8263
8408
  } catch (err) {
8264
8409
  if (!this.#reopenFailing) this.#logger?.warn?.("watch: the Envelope Index was replaced and could not be reopened", err);
8265
8410
  this.#reopenFailing = true;
@@ -8335,14 +8480,23 @@ var MailWatchService = class {
8335
8480
  if (this.#ready().head() > (this.#registry?.mark ?? 0) && this.#stale() && !await this.#refreshSoftly() && !this.#loaded) return;
8336
8481
  const inner = this.#ready();
8337
8482
  inner.holdNewMailboxes = true;
8483
+ this.#ticking = true;
8338
8484
  try {
8339
8485
  tick();
8340
8486
  } finally {
8341
8487
  inner.holdNewMailboxes = false;
8488
+ this.#ticking = false;
8489
+ }
8490
+ const held = inner.takeHeld();
8491
+ if (held === null) return;
8492
+ this.#heldThrough.set(held.mailbox, Math.max(held.rowid, this.#heldThrough.get(held.mailbox) ?? 0));
8493
+ if (!await this.#refreshSoftly()) this.#rebuild();
8494
+ this.#ticking = true;
8495
+ try {
8496
+ tick();
8497
+ } finally {
8498
+ this.#ticking = false;
8342
8499
  }
8343
- if (inner.takeHeld() === null) return;
8344
- await this.#refreshSoftly();
8345
- tick();
8346
8500
  }
8347
8501
  /**
8348
8502
  * What the file trigger runs. `onTrigger` is async and the trigger's own
@@ -8596,4 +8750,4 @@ const createServer = (opts) => {
8596
8750
  //#endregion
8597
8751
  export { WritesDisabledError as A, MessageNotFoundError as C, ProtocolError as D, PreconditionError$1 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 };
8598
8752
 
8599
- //# sourceMappingURL=server-D5S4dzq6.js.map
8753
+ //# sourceMappingURL=server-D-UcpTRv.js.map