@mgcrea/mcp-apple-mail 1.19.1 → 1.20.1

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-B0B_aaCO.js";
2
+ import { a as loadConfig, b as MAIL_SURFACE, j as BUILD_INFO, r as createServer } from "./server-DdKWlMP9.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.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-B0B_aaCO.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-DdKWlMP9.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: "5bd33e4",
18
- gitCommitDate: "2026-09-08T16:36:51+02:00"
17
+ gitCommit: "a96dda2",
18
+ gitCommitDate: "2026-09-09T13:03:18+02:00"
19
19
  };
20
20
  //#endregion
21
21
  //#region src/client/errors.ts
@@ -667,15 +667,32 @@ const parsePart = (buf) => {
667
667
  const splitMultipart = (body, boundary) => {
668
668
  const text = body.toString("latin1");
669
669
  const marker = `--${boundary}`;
670
+ /**
671
+ * RFC 2046: a delimiter starts a line, and nothing follows it but the closing
672
+ * `--` or the end of that line. Both halves earn their keep. Without the
673
+ * first, a body that merely quotes the delimiter splits the part it sits in.
674
+ * Without the second, `--B` also matches inside `--B2`, which flattened a
675
+ * nested multipart into its parent's sibling list — harmless while only one
676
+ * part was ever read, and a doubled body the moment the parts are joined.
677
+ */
678
+ const isDelimiter = (at) => {
679
+ if (at !== 0 && text[at - 1] !== "\n") return false;
680
+ const after = text[at + marker.length];
681
+ return after === void 0 || after === "\r" || after === "\n" || after === "-";
682
+ };
683
+ const find = (from) => {
684
+ let at = text.indexOf(marker, from);
685
+ while (at !== -1 && !isDelimiter(at)) at = text.indexOf(marker, at + 1);
686
+ return at;
687
+ };
670
688
  const segments = [];
671
- let index = text.indexOf(marker);
689
+ let index = find(0);
672
690
  if (index === -1) return [];
673
691
  while (index !== -1) {
674
692
  const afterMarker = index + marker.length;
675
693
  if (text.startsWith("--", afterMarker)) break;
676
- const start = afterMarker;
677
- const next = text.indexOf(marker, start);
678
- segments.push(text.slice(start, next === -1 ? void 0 : next).replace(/^\r?\n/, ""));
694
+ const next = find(afterMarker);
695
+ segments.push(text.slice(afterMarker, next === -1 ? void 0 : next).replace(/^\r?\n/, ""));
679
696
  if (next === -1) break;
680
697
  index = next;
681
698
  }
@@ -696,37 +713,97 @@ const partBytes = (part) => {
696
713
  /** Decode one leaf part's body into text. */
697
714
  const partText = (part) => decodeCharset(partBytes(part), part.charset);
698
715
  /** Very small HTML-to-text pass: enough to read a marketing email, not a renderer. */
699
- const htmlToText = (html) => html.replaceAll(/<(script|style)[^>]*>[\s\S]*?<\/\1>/gi, "").replaceAll(/<br\s*\/?>/gi, "\n").replaceAll(/<\/(p|div|tr|h[1-6]|li)>/gi, "\n").replaceAll(/<li[^>]*>/gi, "- ").replaceAll(/<[^>]+>/g, "").replaceAll("&nbsp;", " ").replaceAll("&amp;", "&").replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&quot;", "\"").replaceAll("&#39;", "'").replaceAll(/&#(\d+);/g, (_, d) => String.fromCodePoint(Number(d))).replaceAll(/[ \t]+\n/g, "\n").replaceAll(/\n{3,}/g, "\n\n").trim();
716
+ const htmlToText = (html) => html.replaceAll(/<(script|style)[^>]*>[\s\S]*?<\/\1>/gi, "").replaceAll(/<(script|style)[^>]*>[\s\S]*$/gi, "").replaceAll(/<br\s*\/?>/gi, "\n").replaceAll(/<\/(p|div|tr|h[1-6]|li)>/gi, "\n").replaceAll(/<li[^>]*>/gi, "- ").replaceAll(/<[^>]+>/g, "").replaceAll(/<\/?[a-zA-Z][^>]*$/g, "").replaceAll("&nbsp;", " ").replaceAll("&amp;", "&").replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&quot;", "\"").replaceAll("&#39;", "'").replaceAll(/&#(\d+);/g, (_, d) => String.fromCodePoint(Number(d))).replaceAll(/[ \t]+\n/g, "\n").replaceAll(/\n{3,}/g, "\n\n").trim();
700
717
  const walk = (part, visit) => {
701
718
  visit(part);
702
719
  for (const child of part.parts) walk(child, visit);
703
720
  };
704
721
  /**
705
- * Pick the body a person would want to read: the first text/plain that is not
706
- * an attachment, else the first text/html converted to text.
722
+ * Is this part a file rather than something to read?
723
+ *
724
+ * Deliberately shared with `listAttachments`. The two used to disagree — this
725
+ * one excluded only `disposition: attachment`, that one also counted any
726
+ * non-multipart part carrying a filename — and the disagreement was harmless
727
+ * only because a single part was ever chosen as the body. Joining the parts
728
+ * made it visible, as an attached notes.txt landing in the mail it came with.
707
729
  */
708
- const bestBody = (root) => {
709
- let plain = null;
710
- let html = null;
711
- walk(root, (p) => {
712
- if (p.disposition === "attachment") return;
713
- if (!plain && p.contentType === "text/plain") plain = p;
714
- if (!html && p.contentType === "text/html") html = p;
715
- });
716
- if (plain) return {
717
- text: partText(plain).trim(),
730
+ const isAttachmentPart = (p) => p.disposition === "attachment" || p.filename !== null && !p.contentType.startsWith("multipart/");
731
+ const NOTHING = {
732
+ segments: [],
733
+ from: "none"
734
+ };
735
+ const hasText = (r) => r.segments.some((s) => s.kind === "text" && s.text.trim() !== "");
736
+ /** `[image: shot.png]` — house style is the truncation marker's: label, colon, fact. */
737
+ const markerFor = (p) => ({
738
+ kind: "marker",
739
+ text: `[${p.contentType.startsWith("image/") ? "image" : "attachment"}: ${p.filename ?? p.contentType}]`
740
+ });
741
+ /**
742
+ * Resolve one subtree to the runs a person would read, in document order.
743
+ *
744
+ * The container decides. `multipart/alternative` children are competing
745
+ * renderings of one thing, so exactly one is taken; every other multipart holds
746
+ * sequential content, so the children are spliced in order. A flat walk that
747
+ * gathered all the text parts would read the interleaved message correctly and
748
+ * emit a plain+html alternative twice.
749
+ */
750
+ const resolveBody = (part, isFile) => {
751
+ if (part.contentType.startsWith("multipart/")) {
752
+ if (part.parts.length === 0) return NOTHING;
753
+ const children = part.parts.map((child) => resolveBody(child, isFile));
754
+ if (part.contentType === "multipart/alternative") return children.find((c) => c.from === "text/plain" && hasText(c)) ?? children.find((c) => c.from === "text/html" && hasText(c)) ?? NOTHING;
755
+ const contributing = children.filter(hasText);
756
+ return {
757
+ segments: children.flatMap((c) => c.segments),
758
+ from: contributing.some((c) => c.from === "text/html") ? "text/html" : contributing.some((c) => c.from === "text/plain") ? "text/plain" : "none"
759
+ };
760
+ }
761
+ if (isFile(part)) return {
762
+ segments: [markerFor(part)],
763
+ from: "none"
764
+ };
765
+ if (part.contentType === "text/plain") return {
766
+ segments: [{
767
+ kind: "text",
768
+ text: partText(part).trim()
769
+ }],
718
770
  from: "text/plain"
719
771
  };
720
- if (html) return {
721
- text: htmlToText(partText(html)),
772
+ if (part.contentType === "text/html") return {
773
+ segments: [{
774
+ kind: "text",
775
+ text: htmlToText(partText(part))
776
+ }],
722
777
  from: "text/html"
723
778
  };
724
779
  return {
725
- text: "",
780
+ segments: [markerFor(part)],
726
781
  from: "none"
727
782
  };
728
783
  };
729
784
  /**
785
+ * The body a person would want to read: every run of it, in order.
786
+ *
787
+ * `from` reports the worst provenance of the runs that contributed, not the
788
+ * first. It is the caller's only warning that the text went through
789
+ * `htmlToText`, and a concatenation that is half derived must not claim to be
790
+ * text/plain just because its first run was.
791
+ */
792
+ const bestBody = (root) => {
793
+ const strict = resolveBody(root, isAttachmentPart);
794
+ const resolved = hasText(strict) ? strict : resolveBody(root, (p) => p.disposition === "attachment");
795
+ const kept = resolved.segments.filter((s) => s.kind === "marker" || s.text.trim() !== "");
796
+ let first = 0;
797
+ let last = kept.length;
798
+ while (first < last && kept[first].kind === "marker") first += 1;
799
+ while (last > first && kept[last - 1].kind === "marker") last -= 1;
800
+ const text = kept.slice(first, last).map((s) => s.text).join("\n\n").trim();
801
+ return {
802
+ text,
803
+ from: text === "" ? "none" : resolved.from
804
+ };
805
+ };
806
+ /**
730
807
  * Does a decoded part carry actual content?
731
808
  *
732
809
  * Stripping an attachment out to the sidecar tree leaves the part's delimiter
@@ -741,7 +818,7 @@ const hasContent = (bytes) => {
741
818
  const listAttachments = (root) => {
742
819
  const found = [];
743
820
  walk(root, (p) => {
744
- if (!(p.disposition === "attachment" || p.filename !== null && !p.contentType.startsWith("multipart/")) || p.contentType.startsWith("multipart/")) return;
821
+ if (!isAttachmentPart(p) || p.contentType.startsWith("multipart/")) return;
745
822
  const decoded = partBytes(p);
746
823
  const present = hasContent(decoded);
747
824
  found.push({
@@ -5211,4 +5288,4 @@ const createServer = (opts) => {
5211
5288
  //#endregion
5212
5289
  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 };
5213
5290
 
5214
- //# sourceMappingURL=server-B0B_aaCO.js.map
5291
+ //# sourceMappingURL=server-DdKWlMP9.js.map