@mgcrea/mcp-apple-mail 1.16.0 → 1.17.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 +15 -31
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +21 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/{server-D7Aj2CJS.js → server-D62cuBVz.js} +185 -21
- package/dist/server-D62cuBVz.js.map +1 -0
- package/package.json +2 -2
- package/dist/server-D7Aj2CJS.js.map +0 -1
package/README.md
CHANGED
|
@@ -51,7 +51,7 @@ _reader_ that needs permission, not Mail.
|
|
|
51
51
|
**Automation** is granted to the app that launches the server (Terminal, iTerm, VS Code, Claude…).
|
|
52
52
|
macOS prompts for it on the first Apple Event, so usually you just click Allow.
|
|
53
53
|
|
|
54
|
-
**Full Disk Access** is the awkward one
|
|
54
|
+
**Full Disk Access** is the awkward one.
|
|
55
55
|
|
|
56
56
|
### Why you should not just grant it to your editor
|
|
57
57
|
|
|
@@ -70,43 +70,27 @@ defeats `APPLE_MAIL_ACCOUNTS`, which exists to bound exactly this.
|
|
|
70
70
|
You cannot avoid it by granting the permission to `.mcp.json` (it is data, not code) or to `node`
|
|
71
71
|
(it is not the responsible process, and it is shared by every node program on the machine).
|
|
72
72
|
|
|
73
|
-
###
|
|
73
|
+
### What to do instead
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
Install [**Cupertino.app**](https://cupertino.mgcrea.io), the signed menu bar app this package is
|
|
76
|
+
developed in. It holds one Full Disk Access grant and serves this server beneath it, so the
|
|
77
|
+
permission belongs to a notarized binary rather than to your editor:
|
|
78
78
|
|
|
79
79
|
```bash
|
|
80
|
-
|
|
81
|
-
./scripts/install-wrapper.sh
|
|
80
|
+
brew install --cask mgcrea/tap/cupertino
|
|
82
81
|
```
|
|
83
82
|
|
|
84
|
-
|
|
83
|
+
Measured: Full Disk Access and Automation granted to a signed `.app` are inherited two levels deep
|
|
84
|
+
by the processes it spawns, so a `node` grandchild reads the Envelope Index and `tccd` resolves a
|
|
85
|
+
grandchild `osascript` to the app rather than to whatever launched it.
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
"command": "/Users/YOU/Library/Application Support/apple-mail-mcp/bin/apple-mail-mcp",
|
|
91
|
-
"env": { "APPLE_MAIL_ALLOW_WRITES": "1" }
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
Verified on macOS 26.6: the launcher reads Mail's index while plain `node` in the same shell stays
|
|
98
|
-
denied, so the grant really is scoped. `apple_mail_diagnostics` will confirm it.
|
|
99
|
-
|
|
100
|
-
Three things worth knowing:
|
|
87
|
+
Earlier versions of this package described a small compiled launcher that made itself its own
|
|
88
|
+
responsible process through a private API. It is no longer built or shipped — there is nothing left
|
|
89
|
+
to escape — though `native/launcher.c` stays in the repository as the clearest statement of the
|
|
90
|
+
problem.
|
|
101
91
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
told would let any local process read your whole disk using a permission you granted for mail.
|
|
105
|
-
- **Install it once, outside the repo.** macOS ties the grant to a file path, so a launcher living in
|
|
106
|
-
`node_modules` or an `npx` cache would silently lose its permission on the next version bump.
|
|
107
|
-
- **`responsibility_spawnattrs_setdisclaim` is a private API.** It has been stable since 10.14, and
|
|
108
|
-
if it ever disappears the launcher says so on stderr and starts the server anyway — you lose the
|
|
109
|
-
search and body lanes, not the server. The fallback is granting Full Disk Access to the host app.
|
|
92
|
+
If you would rather not install the app, granting Full Disk Access to your editor does work. Read
|
|
93
|
+
the paragraph above about what that grant actually covers before you do.
|
|
110
94
|
|
|
111
95
|
Restart your MCP host after granting. `apple_mail_diagnostics` reports which permission is missing
|
|
112
96
|
and what it is blocking.
|
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-D62cuBVz.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
|
@@ -198,8 +198,20 @@ declare class MailAxLane {
|
|
|
198
198
|
* keystroke goes wherever the focus actually is. Both are needed, and the
|
|
199
199
|
* focus is read back because an element can report itself focusable and not
|
|
200
200
|
* take it.
|
|
201
|
+
*
|
|
202
|
+
* **What "read back" has to mean here, learned the hard way.** Mail's composer
|
|
203
|
+
* web area answers `AXFocused: false` while holding the keyboard — measured
|
|
204
|
+
* over 1.2 s without ever flipping, with a command-V landing in it the whole
|
|
205
|
+
* time. `apple_desktop_focus` used to return that flag, so this guard refused
|
|
206
|
+
* to press command-V and every native reply came back "Nothing landed in it"
|
|
207
|
+
* for a body that would have gone in. The driver now answers from the
|
|
208
|
+
* APPLICATION's `AXFocusedUIElement`, which is what the window server routes
|
|
209
|
+
* keystrokes by and so cannot disagree with where one will land.
|
|
210
|
+
*
|
|
211
|
+
* The guard itself stays. Posting command-V without knowing where the focus is
|
|
212
|
+
* types into whatever happens to be in front, and that is the user's window.
|
|
201
213
|
*/
|
|
202
|
-
paste(ref: ComposerRef): Promise<boolean>;
|
|
214
|
+
paste(ref: ComposerRef, focusTimeoutMs?: number): Promise<boolean>;
|
|
203
215
|
/**
|
|
204
216
|
* Send the composer, or save it as a draft.
|
|
205
217
|
*
|
|
@@ -398,7 +410,14 @@ declare class EnvelopeIndex {
|
|
|
398
410
|
* real top-N unless you already knew to doubt it.
|
|
399
411
|
*/
|
|
400
412
|
groupBy(filters: Omit<SearchFilters, "offset">, field: GroupField): GroupResult;
|
|
401
|
-
|
|
413
|
+
/**
|
|
414
|
+
* Narrowed to the one filter this actually applies.
|
|
415
|
+
*
|
|
416
|
+
* It used to take the whole filter set, which promised a query/sender/date
|
|
417
|
+
* scope it silently dropped. No caller passed one, so the lie was free —
|
|
418
|
+
* until somebody added a caller that did.
|
|
419
|
+
*/
|
|
420
|
+
count(filters: Pick<SearchFilters, "mailboxRowids">): {
|
|
402
421
|
total: number;
|
|
403
422
|
unread: number;
|
|
404
423
|
};
|
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/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;;;
|
|
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/server.ts","../src/tools/index.ts"],"mappings":";;;;;cAkBa,YAAY;;;;cCWZ,6BAA6B;WACtB;EAElB,YAAY;;;;;;;;;;;;;;;;;;;;KCTF;;EAEV;;EA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AAS,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-D62cuBVz.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,4 +1,4 @@
|
|
|
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, parseConfig, parseIntOpt, parseList, project, promptArg, readPackageIdentity, registerSurfaceResources, registerWorkflowPrompt, requiredPromptArg, resolveLimit, selectArg, tableMap, trimmed, watchInterference, withBusyRetry, withLazyTools, wrap } from "@mgcrea/mcp-apple-core";
|
|
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
2
|
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import { basename, dirname, join, resolve, sep } from "node:path";
|
|
@@ -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-09-
|
|
17
|
+
gitCommit: "d05a45c",
|
|
18
|
+
gitCommitDate: "2026-09-07T16:21:19+02:00"
|
|
19
19
|
};
|
|
20
20
|
//#endregion
|
|
21
21
|
//#region src/client/errors.ts
|
|
@@ -154,6 +154,31 @@ const BODY_ROLE = "AXWebArea";
|
|
|
154
154
|
* holds a deeply nested quoted message — the web area itself sits near the top.
|
|
155
155
|
*/
|
|
156
156
|
const BODY_DEPTH = 8;
|
|
157
|
+
/**
|
|
158
|
+
* How long to keep asking the composer's body to take the focus.
|
|
159
|
+
*
|
|
160
|
+
* **Readable is not ready, and the gap is not zero.** `findComposer` returns as
|
|
161
|
+
* soon as the window and its web area can be READ; the body cannot take the
|
|
162
|
+
* keyboard for about another 140 ms after that. Measured over three fresh
|
|
163
|
+
* composers, driving the real driver:
|
|
164
|
+
*
|
|
165
|
+
* web area readable at 395 ms focus -> false at 421 ms, true at 560 ms
|
|
166
|
+
* web area readable at 637 ms focus -> false at 671 ms, true at 812 ms
|
|
167
|
+
* web area readable at 640 ms focus -> false at 665 ms, true at 805 ms
|
|
168
|
+
*
|
|
169
|
+
* The first attempt failed on every trial. Without a poll here that is a
|
|
170
|
+
* coin-flip resting on how long the surrounding round trips happen to take —
|
|
171
|
+
* `compose.ts` retries the whole paste once, for an unrelated reason, and that
|
|
172
|
+
* retry was silently carrying this.
|
|
173
|
+
*
|
|
174
|
+
* Which is `docs/desktop.md`'s most expensive lesson arriving in a new place:
|
|
175
|
+
* *the control must be polled for, not waited for*. It was written about a
|
|
176
|
+
* window's chrome appearing before its content; this is the same shape one level
|
|
177
|
+
* down, where the content is there and the focus is not.
|
|
178
|
+
*/
|
|
179
|
+
const FOCUS_TIMEOUT_MS = 2e3;
|
|
180
|
+
/** Between focus attempts. Each one is a round trip, so this is not a spin. */
|
|
181
|
+
const FOCUS_POLL_MS = 100;
|
|
157
182
|
var MailAxLane = class MailAxLane {
|
|
158
183
|
#channel;
|
|
159
184
|
constructor(channel) {
|
|
@@ -322,11 +347,28 @@ var MailAxLane = class MailAxLane {
|
|
|
322
347
|
* keystroke goes wherever the focus actually is. Both are needed, and the
|
|
323
348
|
* focus is read back because an element can report itself focusable and not
|
|
324
349
|
* take it.
|
|
350
|
+
*
|
|
351
|
+
* **What "read back" has to mean here, learned the hard way.** Mail's composer
|
|
352
|
+
* web area answers `AXFocused: false` while holding the keyboard — measured
|
|
353
|
+
* over 1.2 s without ever flipping, with a command-V landing in it the whole
|
|
354
|
+
* time. `apple_desktop_focus` used to return that flag, so this guard refused
|
|
355
|
+
* to press command-V and every native reply came back "Nothing landed in it"
|
|
356
|
+
* for a body that would have gone in. The driver now answers from the
|
|
357
|
+
* APPLICATION's `AXFocusedUIElement`, which is what the window server routes
|
|
358
|
+
* keystrokes by and so cannot disagree with where one will land.
|
|
359
|
+
*
|
|
360
|
+
* The guard itself stays. Posting command-V without knowing where the focus is
|
|
361
|
+
* types into whatever happens to be in front, and that is the user's window.
|
|
325
362
|
*/
|
|
326
|
-
async paste(ref) {
|
|
363
|
+
async paste(ref, focusTimeoutMs = FOCUS_TIMEOUT_MS) {
|
|
327
364
|
await this.#call("raise_window", { handle: ref.window });
|
|
328
365
|
await this.activate();
|
|
329
|
-
|
|
366
|
+
const deadline = Date.now() + focusTimeoutMs;
|
|
367
|
+
for (;;) {
|
|
368
|
+
if ((await this.#call("focus", { handle: ref.body })).focused === true) break;
|
|
369
|
+
if (Date.now() >= deadline) return false;
|
|
370
|
+
await new Promise((resolve) => setTimeout(resolve, FOCUS_POLL_MS));
|
|
371
|
+
}
|
|
330
372
|
await this.#call("key", {
|
|
331
373
|
key: "v",
|
|
332
374
|
modifiers: ["command"]
|
|
@@ -511,6 +553,90 @@ const headerParam = (value, param) => {
|
|
|
511
553
|
const match = new RegExp(`${param}\\s*=\\s*"([^"]*)"|${param}\\s*=\\s*([^;\\s]+)`, "i").exec(value);
|
|
512
554
|
return match ? match[1] ?? match[2] ?? null : null;
|
|
513
555
|
};
|
|
556
|
+
/**
|
|
557
|
+
* The filename a part actually carries, through both ways of spelling one.
|
|
558
|
+
*
|
|
559
|
+
* `headerParam` reads `filename="x"` and nothing else, which is fine for
|
|
560
|
+
* `charset` and `boundary` — both plain ASCII tokens by definition — and wrong
|
|
561
|
+
* for a filename, because a filename is the one parameter that routinely is not
|
|
562
|
+
* ASCII. Two encodings exist for it and mail uses both:
|
|
563
|
+
*
|
|
564
|
+
* RFC 2231 `filename*=UTF-8''r%C3%A9sum%C3%A9.pdf`
|
|
565
|
+
* also split across `filename*0*=`, `filename*1*=` for long names
|
|
566
|
+
* RFC 2047 `name="=?utf-8?Q?r=C3=A9sum=C3=A9=2Epdf?="`
|
|
567
|
+
*
|
|
568
|
+
* Neither was handled. The first returned null, so an attachment with an
|
|
569
|
+
* accented name was reported as having no filename at all — which
|
|
570
|
+
* `list_attachments` shows as unretrievable and `save_attachment` cannot write.
|
|
571
|
+
* The second came back verbatim, so saving it wrote a file literally named
|
|
572
|
+
* `=?utf-8?Q?...?=` on disk.
|
|
573
|
+
*
|
|
574
|
+
* RFC 2231 is tried first because it is the one designed for this; the RFC 2047
|
|
575
|
+
* form in a parameter is technically not allowed and is nonetheless everywhere.
|
|
576
|
+
*/
|
|
577
|
+
const headerFilename = (disposition, contentType) => {
|
|
578
|
+
for (const [value, param] of [[disposition, "filename"], [contentType, "name"]]) {
|
|
579
|
+
if (!value) continue;
|
|
580
|
+
const extended = extendedParam(value, param);
|
|
581
|
+
if (extended !== null) return extended;
|
|
582
|
+
const plain = headerParam(value, param);
|
|
583
|
+
if (plain !== null) return decodeEncodedWords(plain);
|
|
584
|
+
}
|
|
585
|
+
return null;
|
|
586
|
+
};
|
|
587
|
+
/**
|
|
588
|
+
* The RFC 2231 form, including the numbered continuations long names use.
|
|
589
|
+
*
|
|
590
|
+
* A continuation is only percent-decoded when its own segment is starred —
|
|
591
|
+
* `filename*1=` is literal text and `filename*1*=` is encoded, and treating the
|
|
592
|
+
* two alike turns a legitimate `%` in a filename into mojibake.
|
|
593
|
+
*/
|
|
594
|
+
const extendedParam = (value, param) => {
|
|
595
|
+
const single = new RegExp(`${param}\\*\\s*=\\s*(?:"([^"]*)"|([^;\\s]+))`, "i").exec(value);
|
|
596
|
+
if (single) return decodeExtended(single[1] ?? single[2] ?? "", true);
|
|
597
|
+
const segments = [];
|
|
598
|
+
const pattern = new RegExp(`${param}\\*(\\d+)(\\*)?\\s*=\\s*(?:"([^"]*)"|([^;\\s]+))`, "gi");
|
|
599
|
+
for (const match of value.matchAll(pattern)) segments.push({
|
|
600
|
+
index: Number(match[1]),
|
|
601
|
+
text: match[3] ?? match[4] ?? "",
|
|
602
|
+
encoded: match[2] === "*"
|
|
603
|
+
});
|
|
604
|
+
if (segments.length === 0) return null;
|
|
605
|
+
segments.sort((a, b) => a.index - b.index);
|
|
606
|
+
let charset = null;
|
|
607
|
+
let out = "";
|
|
608
|
+
for (const [position, segment] of segments.entries()) {
|
|
609
|
+
if (!segment.encoded) {
|
|
610
|
+
out += segment.text;
|
|
611
|
+
continue;
|
|
612
|
+
}
|
|
613
|
+
if (position === 0) {
|
|
614
|
+
const parts = segment.text.split("'");
|
|
615
|
+
if (parts.length >= 3) {
|
|
616
|
+
charset = parts[0] || null;
|
|
617
|
+
out += percentDecode(parts.slice(2).join("'"), charset);
|
|
618
|
+
continue;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
out += percentDecode(segment.text, charset);
|
|
622
|
+
}
|
|
623
|
+
return out;
|
|
624
|
+
};
|
|
625
|
+
const decodeExtended = (raw, hasCharsetPrefix) => {
|
|
626
|
+
if (!hasCharsetPrefix) return percentDecode(raw, null);
|
|
627
|
+
const parts = raw.split("'");
|
|
628
|
+
if (parts.length < 3) return percentDecode(raw, null);
|
|
629
|
+
return percentDecode(parts.slice(2).join("'"), parts[0] || null);
|
|
630
|
+
};
|
|
631
|
+
/** Percent-decoded as BYTES, then read in the charset the header named. */
|
|
632
|
+
const percentDecode = (raw, charset) => {
|
|
633
|
+
const bytes = [];
|
|
634
|
+
for (let i = 0; i < raw.length; i += 1) if (raw[i] === "%" && /^[0-9a-f]{2}$/i.test(raw.slice(i + 1, i + 3))) {
|
|
635
|
+
bytes.push(Number.parseInt(raw.slice(i + 1, i + 3), 16));
|
|
636
|
+
i += 2;
|
|
637
|
+
} else bytes.push(raw.charCodeAt(i) & 255);
|
|
638
|
+
return decodeCharset(Buffer.from(bytes), charset);
|
|
639
|
+
};
|
|
514
640
|
const HEADER_BODY_SPLIT = /\r?\n\r?\n/;
|
|
515
641
|
const parsePart = (buf) => {
|
|
516
642
|
const text = buf.toString("latin1");
|
|
@@ -527,7 +653,7 @@ const parsePart = (buf) => {
|
|
|
527
653
|
charset: headerParam(contentTypeRaw, "charset"),
|
|
528
654
|
encoding: headerValue(headers, "content-transfer-encoding")?.trim().toLowerCase() ?? null,
|
|
529
655
|
disposition: dispositionRaw?.split(";")[0]?.trim().toLowerCase() ?? null,
|
|
530
|
-
filename:
|
|
656
|
+
filename: headerFilename(dispositionRaw, contentTypeRaw),
|
|
531
657
|
contentId: headerValue(headers, "content-id")?.replaceAll(/[<>]/g, "") ?? null,
|
|
532
658
|
raw: Buffer.from(text.slice(bodyStart), "latin1"),
|
|
533
659
|
parts: []
|
|
@@ -2519,12 +2645,12 @@ const withClipboard = async (clipboard, text, body) => {
|
|
|
2519
2645
|
} catch {}
|
|
2520
2646
|
}
|
|
2521
2647
|
};
|
|
2522
|
-
const paste = async (lane, clipboard, ref, text) => {
|
|
2648
|
+
const paste = async (lane, clipboard, ref, text, focusTimeoutMs) => {
|
|
2523
2649
|
const expected = text.length > VERIFY_CHARS ? text.slice(0, VERIFY_CHARS) : text;
|
|
2524
2650
|
const sizeBefore = await lane.bodySize(ref.body);
|
|
2525
2651
|
return withClipboard(clipboard, text, async () => {
|
|
2526
2652
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
2527
|
-
if (await lane.paste(ref)) {
|
|
2653
|
+
if (await lane.paste(ref, focusTimeoutMs)) {
|
|
2528
2654
|
const after = await lane.bodyText(ref.body);
|
|
2529
2655
|
if (after !== null && containsText(after, expected)) return {
|
|
2530
2656
|
verified: true,
|
|
@@ -2559,7 +2685,7 @@ const replyOrForwardNatively = async (lane, runner, params, opts = {}) => {
|
|
|
2559
2685
|
let bodyVerified = null;
|
|
2560
2686
|
let verifiedChars = 0;
|
|
2561
2687
|
if (params.body) {
|
|
2562
|
-
const result = await paste(lane, clipboard, ref, params.body);
|
|
2688
|
+
const result = await paste(lane, clipboard, ref, params.body, opts.focusTimeoutMs);
|
|
2563
2689
|
bodyVerified = result.verified;
|
|
2564
2690
|
verifiedChars = result.verified ? Math.min(params.body.length, VERIFY_CHARS) : 0;
|
|
2565
2691
|
if (!result.verified) return {
|
|
@@ -2709,7 +2835,8 @@ var EnvelopeIndex = class EnvelopeIndex {
|
|
|
2709
2835
|
* as 0 rows against 51,128 real messages.
|
|
2710
2836
|
*/
|
|
2711
2837
|
#mailboxPredicate(rowids, params) {
|
|
2712
|
-
if (
|
|
2838
|
+
if (rowids === void 0) return "1=1";
|
|
2839
|
+
if (rowids.length === 0) return "1=0";
|
|
2713
2840
|
const placeholders = rowids.map(() => "?").join(",");
|
|
2714
2841
|
if (!this.caps.has.labels) {
|
|
2715
2842
|
params.push(...rowids);
|
|
@@ -2722,8 +2849,17 @@ var EnvelopeIndex = class EnvelopeIndex {
|
|
|
2722
2849
|
if (value === null || !Number.isFinite(value)) return null;
|
|
2723
2850
|
return (/* @__PURE__ */ new Date((value + this.caps.epochOffset) * 1e3)).toISOString();
|
|
2724
2851
|
}
|
|
2725
|
-
|
|
2726
|
-
|
|
2852
|
+
/**
|
|
2853
|
+
* A resolved instant to this store's own units.
|
|
2854
|
+
*
|
|
2855
|
+
* Takes a Date rather than a string, which is the whole point: it used to do
|
|
2856
|
+
* `Date.parse(iso)`, and `Date.parse("last week")` is NaN. node:sqlite binds
|
|
2857
|
+
* NaN as NULL, `date_received >= NULL` matches nothing, and the caller got
|
|
2858
|
+
* zero results with no error. Parsing now happens once, in core's grammar,
|
|
2859
|
+
* which refuses what it cannot read.
|
|
2860
|
+
*/
|
|
2861
|
+
#toEpoch(when) {
|
|
2862
|
+
return Math.floor(when.getTime() / 1e3) - this.caps.epochOffset;
|
|
2727
2863
|
}
|
|
2728
2864
|
/**
|
|
2729
2865
|
* The WHERE half of a filtered read, appending its bind values to `params`.
|
|
@@ -2760,11 +2896,11 @@ var EnvelopeIndex = class EnvelopeIndex {
|
|
|
2760
2896
|
if (filters.hasAttachment && this.caps.has.attachments) where.push("EXISTS (SELECT 1 FROM attachments at WHERE at.message = m.ROWID)");
|
|
2761
2897
|
if (filters.dateFrom) {
|
|
2762
2898
|
where.push("m.date_received >= ?");
|
|
2763
|
-
params.push(this.#toEpoch(filters.dateFrom));
|
|
2899
|
+
params.push(this.#toEpoch(parseBound("dateFrom", filters.dateFrom, "start")));
|
|
2764
2900
|
}
|
|
2765
2901
|
if (filters.dateTo) {
|
|
2766
|
-
where.push("m.date_received
|
|
2767
|
-
params.push(this.#toEpoch(filters.dateTo));
|
|
2902
|
+
where.push("m.date_received < ?");
|
|
2903
|
+
params.push(this.#toEpoch(parseBound("dateTo", filters.dateTo, "end")));
|
|
2768
2904
|
}
|
|
2769
2905
|
return where.join(" AND ");
|
|
2770
2906
|
}
|
|
@@ -2835,9 +2971,18 @@ var EnvelopeIndex = class EnvelopeIndex {
|
|
|
2835
2971
|
};
|
|
2836
2972
|
}
|
|
2837
2973
|
}
|
|
2838
|
-
/**
|
|
2974
|
+
/**
|
|
2975
|
+
* `date_received` is epoch-with-offset, so shift it before formatting.
|
|
2976
|
+
*
|
|
2977
|
+
* `'localtime'`, matching Messages' buckets and — since the shared grammar
|
|
2978
|
+
* landed — matching the bounds. A day bucket is a CALENDAR day, and a person
|
|
2979
|
+
* asking "how much mail per day" means their own days. In UTC a message that
|
|
2980
|
+
* arrived at 23:30 local counted against tomorrow, so a bare `dateTo` naming
|
|
2981
|
+
* a local day could return rows the grouping then filed under the day after
|
|
2982
|
+
* the one that was asked for.
|
|
2983
|
+
*/
|
|
2839
2984
|
#dateBucket(format) {
|
|
2840
|
-
return `strftime('${format}', datetime(m.date_received + ${this.caps.epochOffset}, 'unixepoch'))`;
|
|
2985
|
+
return `strftime('${format}', datetime(m.date_received + ${this.caps.epochOffset}, 'unixepoch', 'localtime'))`;
|
|
2841
2986
|
}
|
|
2842
2987
|
/**
|
|
2843
2988
|
* Count matches per group, over every match rather than a page of them.
|
|
@@ -2869,6 +3014,13 @@ var EnvelopeIndex = class EnvelopeIndex {
|
|
|
2869
3014
|
totalGroups: totals.totalGroups ?? 0
|
|
2870
3015
|
};
|
|
2871
3016
|
}
|
|
3017
|
+
/**
|
|
3018
|
+
* Narrowed to the one filter this actually applies.
|
|
3019
|
+
*
|
|
3020
|
+
* It used to take the whole filter set, which promised a query/sender/date
|
|
3021
|
+
* scope it silently dropped. No caller passed one, so the lie was free —
|
|
3022
|
+
* until somebody added a caller that did.
|
|
3023
|
+
*/
|
|
2872
3024
|
count(filters) {
|
|
2873
3025
|
const params = [];
|
|
2874
3026
|
const predicate = this.#mailboxPredicate(filters.mailboxRowids, params);
|
|
@@ -3420,6 +3572,11 @@ var AppleMailClient = class {
|
|
|
3420
3572
|
if (wanted && entry.mailbox.toLowerCase() !== wanted.toLowerCase()) continue;
|
|
3421
3573
|
rowids.push(rowid);
|
|
3422
3574
|
}
|
|
3575
|
+
if (rowids.length === 0) {
|
|
3576
|
+
const known = [...lookup.values()].filter((e) => !account || e.accountUuid === account.id).map((e) => e.mailbox);
|
|
3577
|
+
const unique = [...new Set(known)].toSorted();
|
|
3578
|
+
throw new PreconditionError(`No mailbox matching ${JSON.stringify(opts.mailbox ?? "")}${account ? ` in account ${JSON.stringify(account.name)}` : ""} is present in Mail's search index.` + (unique.length ? ` Indexed there: ${unique.slice(0, 20).join(", ")}.` : " That account has no indexed mailboxes at all."));
|
|
3579
|
+
}
|
|
3423
3580
|
return rowids;
|
|
3424
3581
|
}
|
|
3425
3582
|
/**
|
|
@@ -3824,13 +3981,20 @@ var AppleMailClient = class {
|
|
|
3824
3981
|
const decoded = decodeRef(ref);
|
|
3825
3982
|
const located = await this.#lookupMessageFile(decoded);
|
|
3826
3983
|
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) ?? [] });
|
|
3827
|
-
const { bytes, from } = extractAttachment(located.path, filename, decoded.id);
|
|
3828
3984
|
const root = resolve(this.config.attachmentDir);
|
|
3829
3985
|
const target = resolve(join(root, basename(filename)));
|
|
3830
3986
|
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.`);
|
|
3831
|
-
|
|
3987
|
+
const { bytes, from } = extractAttachment(located.path, filename, decoded.id);
|
|
3832
3988
|
mkdirSync(root, { recursive: true });
|
|
3833
|
-
|
|
3989
|
+
try {
|
|
3990
|
+
writeFileSync(target, bytes, {
|
|
3991
|
+
mode: 384,
|
|
3992
|
+
flag: opts.overwrite ? "w" : "wx"
|
|
3993
|
+
});
|
|
3994
|
+
} catch (err) {
|
|
3995
|
+
if (err.code === "EEXIST") throw new PreconditionError(`${target} already exists; refusing to overwrite it.`);
|
|
3996
|
+
throw err;
|
|
3997
|
+
}
|
|
3834
3998
|
return {
|
|
3835
3999
|
path: target,
|
|
3836
4000
|
bytes: bytes.length,
|
|
@@ -5047,4 +5211,4 @@ const createServer = (opts) => {
|
|
|
5047
5211
|
//#endregion
|
|
5048
5212
|
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 };
|
|
5049
5213
|
|
|
5050
|
-
//# sourceMappingURL=server-
|
|
5214
|
+
//# sourceMappingURL=server-D62cuBVz.js.map
|