apple-mail-mcp 2.6.1 → 2.7.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 +22 -4
- package/build/index.js +69 -17
- package/build/services/appleMailManager.d.ts +11 -3
- package/build/services/appleMailManager.d.ts.map +1 -1
- package/build/services/appleMailManager.js +18 -5
- package/build/utils/mimeParse.d.ts.map +1 -1
- package/build/utils/mimeParse.js +14 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -186,7 +186,7 @@ Search for messages matching criteria. Searches all accounts by default.
|
|
|
186
186
|
| `isFlagged` | boolean | No | Filter by flagged status |
|
|
187
187
|
| `dateFrom` | string | No | Start date filter (e.g., "January 1, 2026") |
|
|
188
188
|
| `dateTo` | string | No | End date filter (e.g., "March 1, 2026") |
|
|
189
|
-
| `limit` | number | No | Max results (default: 50) |
|
|
189
|
+
| `limit` | number | No | Max results, 1–500 (default: 50) |
|
|
190
190
|
|
|
191
191
|
**Large mailboxes & partial results.** Apple Mail's AppleScript bridge cannot
|
|
192
192
|
search very large IMAP/Gmail mailboxes (tens of thousands of messages) before
|
|
@@ -222,6 +222,13 @@ Get the full content of a message.
|
|
|
222
222
|
|
|
223
223
|
**Returns:** Subject line and message body (plain text by default, HTML if `preferHtml` is true and HTML content is available).
|
|
224
224
|
|
|
225
|
+
> **Large messages / attachments:** reading a full message routes through
|
|
226
|
+
> `osascript`, whose captured output buffer defaults to **64 MB**. Override it
|
|
227
|
+
> with the `APPLE_MAIL_MCP_MAX_BUFFER` environment variable (in **bytes**) if you
|
|
228
|
+
> work with messages whose raw MIME (e.g. a large embedded attachment) exceeds
|
|
229
|
+
> that — a value below the message size makes the read fail with a buffer-overflow
|
|
230
|
+
> error rather than truncating ([#27](https://github.com/sweetrb/apple-mail-mcp/issues/27)).
|
|
231
|
+
|
|
225
232
|
---
|
|
226
233
|
|
|
227
234
|
#### `list-messages`
|
|
@@ -232,8 +239,8 @@ List messages in a mailbox.
|
|
|
232
239
|
|-----------|------|----------|-------------|
|
|
233
240
|
| `mailbox` | string | No | Mailbox name (omit to list from all mailboxes) |
|
|
234
241
|
| `account` | string | No | Account name |
|
|
235
|
-
| `limit` | number | No | Max messages (default: 50) |
|
|
236
|
-
| `offset` | number | No | Number of messages to skip (for pagination) |
|
|
242
|
+
| `limit` | number | No | Max messages, 1–500 (default: 50) |
|
|
243
|
+
| `offset` | number | No | Number of messages to skip, ≥ 0 (for pagination) |
|
|
237
244
|
| `from` | string | No | Filter by sender email address or name |
|
|
238
245
|
| `unreadOnly` | boolean | No | Only show unread messages |
|
|
239
246
|
|
|
@@ -682,11 +689,14 @@ Change read status of a message.
|
|
|
682
689
|
|
|
683
690
|
#### `flag-message` / `unflag-message`
|
|
684
691
|
|
|
685
|
-
Flag or unflag a message.
|
|
692
|
+
Flag or unflag a message. `flag-message` optionally takes a flag **color**; `unflag-message` removes the flag entirely (which also clears any color).
|
|
686
693
|
|
|
687
694
|
| Parameter | Type | Required | Description |
|
|
688
695
|
|-----------|------|----------|-------------|
|
|
689
696
|
| `id` | string | Yes | Message ID |
|
|
697
|
+
| `color` | string | No | (`flag-message` only) Flag color: `red`, `orange`, `yellow`, `green`, `blue`, `purple`, `gray` (`grey` accepted). Omit for Mail's default flag. |
|
|
698
|
+
|
|
699
|
+
**Flag colors** are an Apple Mail feature, applied via AppleScript as the message's `flag index` (0 red, 1 orange, 2 yellow, 3 green, 4 blue, 5 purple, 6 gray) — the same property a Mail smart mailbox can match on. For an **IMAP-routed** message id (`imap:…`) the flag is still set, but the color is **not** applied, because IMAP's `\Flagged` flag is colorless. To color a flag, use the message's AppleScript (numeric) id.
|
|
690
700
|
|
|
691
701
|
---
|
|
692
702
|
|
|
@@ -769,6 +779,7 @@ All batch operations accept an array of message IDs (max 100 per batch) and retu
|
|
|
769
779
|
| Parameter | Type | Required | Description |
|
|
770
780
|
|-----------|------|----------|-------------|
|
|
771
781
|
| `ids` | string[] | Yes | Message IDs (max 100) |
|
|
782
|
+
| `color` | string | No | (`batch-flag-messages` only) Flag color applied to AppleScript (numeric) ids — see [`flag-message`](#flag-message--unflag-message). Any `imap:` ids in the batch are flagged but not colored. |
|
|
772
783
|
|
|
773
784
|
---
|
|
774
785
|
|
|
@@ -1056,6 +1067,13 @@ AI: [calls list-messages with account="Work Exchange", mailbox="INBOX"]
|
|
|
1056
1067
|
"Your Work account has 5 unread messages..."
|
|
1057
1068
|
```
|
|
1058
1069
|
|
|
1070
|
+
To pin which account is used when a tool call omits `account`, set the
|
|
1071
|
+
`APPLE_MAIL_MCP_DEFAULT_ACCOUNT` environment variable to an account **name or
|
|
1072
|
+
email**. When unset (the default), the server falls back to Mail.app's
|
|
1073
|
+
default-send account if it is enabled, otherwise the first enabled account. A
|
|
1074
|
+
**disabled** account is never selected implicitly — this env var (an explicit,
|
|
1075
|
+
deliberate pin) is one of the few ways to target one ([#47](https://github.com/sweetrb/apple-mail-mcp/issues/47)).
|
|
1076
|
+
|
|
1059
1077
|
### Sending Emails Safely
|
|
1060
1078
|
|
|
1061
1079
|
```
|
package/build/index.js
CHANGED
|
@@ -58,6 +58,23 @@ const BATCH_IDS_SCHEMA = z
|
|
|
58
58
|
.array(MESSAGE_ID_SCHEMA)
|
|
59
59
|
.min(1, "At least one message ID is required")
|
|
60
60
|
.max(100, "Cannot process more than 100 messages in a single batch");
|
|
61
|
+
/** Apple Mail flag colors → AppleScript `flag index` palette. `grey` is an alias
|
|
62
|
+
* for `gray`. Colors are a Mail.app feature (the flag index a smart mailbox can
|
|
63
|
+
* match on); the IMAP `\Flagged` flag is colorless. */
|
|
64
|
+
const FLAG_COLOR_INDEX = {
|
|
65
|
+
red: 0,
|
|
66
|
+
orange: 1,
|
|
67
|
+
yellow: 2,
|
|
68
|
+
green: 3,
|
|
69
|
+
blue: 4,
|
|
70
|
+
purple: 5,
|
|
71
|
+
gray: 6,
|
|
72
|
+
grey: 6,
|
|
73
|
+
};
|
|
74
|
+
const FLAG_COLOR_SCHEMA = z
|
|
75
|
+
.enum(["red", "orange", "yellow", "green", "blue", "purple", "gray", "grey"])
|
|
76
|
+
.optional()
|
|
77
|
+
.describe("Optional flag color (Apple Mail palette: red, orange, yellow, green, blue, purple, gray — 'grey' accepted). Omit for Mail's default flag. Colors are applied via Mail.app (AppleScript); for an IMAP-routed message id the flag is set but the color is not applied (IMAP flags are colorless).");
|
|
61
78
|
/** Date filter strings must look like natural-language dates (e.g. "March 1, 2026").
|
|
62
79
|
* Block characters that could escape an AppleScript `date "..."` literal. */
|
|
63
80
|
const DATE_FILTER_SCHEMA = z
|
|
@@ -265,7 +282,13 @@ server.registerTool("search-messages", {
|
|
|
265
282
|
isFlagged: z.boolean().optional().describe("Filter by flagged status"),
|
|
266
283
|
dateFrom: DATE_FILTER_SCHEMA.describe("Start date filter (e.g., 'January 1, 2026')"),
|
|
267
284
|
dateTo: DATE_FILTER_SCHEMA.describe("End date filter (e.g., 'March 1, 2026')"),
|
|
268
|
-
limit: z
|
|
285
|
+
limit: z
|
|
286
|
+
.number()
|
|
287
|
+
.int()
|
|
288
|
+
.min(1)
|
|
289
|
+
.max(500)
|
|
290
|
+
.optional()
|
|
291
|
+
.describe("Maximum number of results (default: 50, max: 500)"),
|
|
269
292
|
},
|
|
270
293
|
outputSchema: LIST_OUTPUT_SCHEMA,
|
|
271
294
|
}, withErrorHandling(async ({ query, mailbox, account, limit = 50, dateFrom, dateTo, from, subject, isRead, isFlagged, }) => {
|
|
@@ -485,8 +508,19 @@ server.registerTool("list-messages", {
|
|
|
485
508
|
.optional()
|
|
486
509
|
.describe("Mailbox to list messages from. Omit to list from all mailboxes."),
|
|
487
510
|
account: z.string().optional().describe("Account to list messages from"),
|
|
488
|
-
limit: z
|
|
489
|
-
|
|
511
|
+
limit: z
|
|
512
|
+
.number()
|
|
513
|
+
.int()
|
|
514
|
+
.min(1)
|
|
515
|
+
.max(500)
|
|
516
|
+
.optional()
|
|
517
|
+
.describe("Maximum number of messages (default: 50, max: 500)"),
|
|
518
|
+
offset: z
|
|
519
|
+
.number()
|
|
520
|
+
.int()
|
|
521
|
+
.min(0)
|
|
522
|
+
.optional()
|
|
523
|
+
.describe("Number of messages to skip (for pagination)"),
|
|
490
524
|
from: z.string().optional().describe("Filter by sender email address or name"),
|
|
491
525
|
unreadOnly: z.boolean().optional().describe("Only show unread messages"),
|
|
492
526
|
},
|
|
@@ -872,20 +906,36 @@ server.registerTool("mark-as-unread", {
|
|
|
872
906
|
}), "Error marking message as unread"));
|
|
873
907
|
// --- flag-message ---
|
|
874
908
|
server.registerTool("flag-message", {
|
|
875
|
-
description: "Use when: flagging a single message (by id).\nReturns: a confirmation that the message was flagged.\nDo not use when: flagging several at once (use batch-flag-messages) or removing a flag (use unflag-message). Get the id from search-messages or list-messages first.",
|
|
909
|
+
description: "Use when: flagging a single message (by id), optionally with a color (red/orange/yellow/green/blue/purple/gray).\nReturns: a confirmation that the message was flagged (and the color, when applied).\nDo not use when: flagging several at once (use batch-flag-messages) or removing a flag (use unflag-message). Get the id from search-messages or list-messages first.\nNote: flag colors are a Mail.app feature applied via AppleScript; for an IMAP-routed id the flag is set but the color is not applied (IMAP flags are colorless).",
|
|
876
910
|
inputSchema: {
|
|
877
911
|
id: MESSAGE_ID_SCHEMA,
|
|
912
|
+
color: FLAG_COLOR_SCHEMA,
|
|
878
913
|
},
|
|
879
|
-
outputSchema: {
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
914
|
+
outputSchema: {
|
|
915
|
+
ok: z.boolean().optional(),
|
|
916
|
+
id: z.string().optional(),
|
|
917
|
+
color: z.string().optional(),
|
|
918
|
+
colorApplied: z.boolean().optional(),
|
|
919
|
+
},
|
|
920
|
+
}, withErrorHandling(({ id, color }) => {
|
|
921
|
+
const colorIndex = color ? FLAG_COLOR_INDEX[color] : undefined;
|
|
922
|
+
return routeMessage(id, {
|
|
923
|
+
imap: () => imapFlagMessage(id),
|
|
924
|
+
apple: () => mailManager.flagMessage(id, colorIndex)
|
|
925
|
+
? successResponse(color ? `Message flagged (${color})` : "Message flagged", {
|
|
926
|
+
ok: true,
|
|
927
|
+
id,
|
|
928
|
+
...(color ? { color, colorApplied: true } : {}),
|
|
929
|
+
})
|
|
930
|
+
: errorResponse(`Failed to flag message "${id}"`),
|
|
931
|
+
// IMAP path: the flag is set, but flag colors are a Mail.app-only feature.
|
|
932
|
+
ok: color
|
|
933
|
+
? `Message flagged. Note: the "${color}" color was not applied — this is an IMAP-routed message and IMAP flags are colorless.`
|
|
934
|
+
: "Message flagged",
|
|
935
|
+
fail: `Failed to flag message "${id}"`,
|
|
936
|
+
structured: color ? { ok: true, id, color, colorApplied: false } : { ok: true, id },
|
|
937
|
+
});
|
|
938
|
+
}, "Error flagging message"));
|
|
889
939
|
// --- unflag-message ---
|
|
890
940
|
server.registerTool("unflag-message", {
|
|
891
941
|
description: "Use when: removing the flag from a single message (by id).\nReturns: a confirmation that the message was unflagged.\nDo not use when: unflagging several at once (use batch-unflag-messages) or adding a flag (use flag-message). Get the id from search-messages or list-messages first.",
|
|
@@ -1030,13 +1080,15 @@ server.registerTool("batch-mark-as-unread", {
|
|
|
1030
1080
|
}, "Error batch marking messages as unread"));
|
|
1031
1081
|
// --- batch-flag-messages ---
|
|
1032
1082
|
server.registerTool("batch-flag-messages", {
|
|
1033
|
-
description: "Use when: flagging multiple messages (1–100 ids) in one call.\nReturns: counts of how many were flagged and how many failed.\nDo not use when: flagging just one (use flag-message) or removing flags (use batch-unflag-messages). Get the ids from search-messages or list-messages first.",
|
|
1083
|
+
description: "Use when: flagging multiple messages (1–100 ids) in one call, optionally with a color (red/orange/yellow/green/blue/purple/gray).\nReturns: counts of how many were flagged and how many failed.\nDo not use when: flagging just one (use flag-message) or removing flags (use batch-unflag-messages). Get the ids from search-messages or list-messages first.\nNote: flag colors are applied via Mail.app (AppleScript); any IMAP-routed ids in the batch are flagged but not colored (IMAP flags are colorless).",
|
|
1034
1084
|
inputSchema: {
|
|
1035
1085
|
ids: BATCH_IDS_SCHEMA,
|
|
1086
|
+
color: FLAG_COLOR_SCHEMA,
|
|
1036
1087
|
},
|
|
1037
1088
|
outputSchema: BATCH_COUNT_OUTPUT_SCHEMA,
|
|
1038
|
-
}, withErrorHandling(async ({ ids }) => {
|
|
1039
|
-
const
|
|
1089
|
+
}, withErrorHandling(async ({ ids, color }) => {
|
|
1090
|
+
const colorIndex = color ? FLAG_COLOR_INDEX[color] : undefined;
|
|
1091
|
+
const { success: successCount, fail: failCount } = await hybridBatchCounts(ids, (n) => mailManager.batchFlagMessages(n, colorIndex), (im) => imapBatchFlag(im));
|
|
1040
1092
|
const structured = { ok: failCount === 0, success: successCount, failed: failCount };
|
|
1041
1093
|
if (failCount === 0) {
|
|
1042
1094
|
return successResponse(`Successfully flagged ${successCount} message(s)`, structured);
|
|
@@ -381,9 +381,17 @@ export declare class AppleMailManager {
|
|
|
381
381
|
*/
|
|
382
382
|
markAsUnread(id: string): boolean;
|
|
383
383
|
/**
|
|
384
|
-
*
|
|
384
|
+
* AppleScript statement(s) to flag a message variable, optionally setting its
|
|
385
|
+
* color. `colorIndex` is Apple's flag-index palette (0 red, 1 orange,
|
|
386
|
+
* 2 yellow, 3 green, 4 blue, 5 purple, 6 gray); it is validated to 0-6 by the
|
|
387
|
+
* schema layer and is a number, so it is safe to interpolate. Omitting it
|
|
388
|
+
* applies Mail's default flag without touching the color.
|
|
385
389
|
*/
|
|
386
|
-
|
|
390
|
+
private flagOperation;
|
|
391
|
+
/**
|
|
392
|
+
* Flag a message, optionally with a color (see {@link flagOperation}).
|
|
393
|
+
*/
|
|
394
|
+
flagMessage(id: string, colorIndex?: number): boolean;
|
|
387
395
|
/**
|
|
388
396
|
* Unflag a message.
|
|
389
397
|
*/
|
|
@@ -472,7 +480,7 @@ export declare class AppleMailManager {
|
|
|
472
480
|
/**
|
|
473
481
|
* Flag multiple messages at once (single tree walk).
|
|
474
482
|
*/
|
|
475
|
-
batchFlagMessages(ids: string[]): BatchOperationResult[];
|
|
483
|
+
batchFlagMessages(ids: string[], colorIndex?: number): BatchOperationResult[];
|
|
476
484
|
/**
|
|
477
485
|
* Unflag multiple messages at once (single tree walk).
|
|
478
486
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appleMailManager.d.ts","sourceRoot":"","sources":["../../src/services/appleMailManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAUH,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,OAAO,EACP,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,SAAS,EAET,oBAAoB,EACpB,UAAU,EACV,qBAAqB,EACrB,QAAQ,EACR,QAAQ,EAGR,eAAe,EACf,OAAO,EACP,aAAa,EACb,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACb,MAAM,YAAY,CAAC;AA2DpB;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,iBAAiB,GAAG,IAAI,CAK7F;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GACd;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,iBAAiB,CAAA;CAAE,CAsCrD;AAqBD;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAKtE;AAWD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAO9F;AAED,6EAA6E;AAC7E,eAAO,MAAM,mBAAmB,mCAAmC,CAAC;AAEpE;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,OAAO,EAAE,EACnB,IAAI,GAAE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aAAa,IAAI,UAAU;CAiE5B"}
|
|
@@ -1556,10 +1556,23 @@ export class AppleMailManager {
|
|
|
1556
1556
|
return true;
|
|
1557
1557
|
}
|
|
1558
1558
|
/**
|
|
1559
|
-
*
|
|
1559
|
+
* AppleScript statement(s) to flag a message variable, optionally setting its
|
|
1560
|
+
* color. `colorIndex` is Apple's flag-index palette (0 red, 1 orange,
|
|
1561
|
+
* 2 yellow, 3 green, 4 blue, 5 purple, 6 gray); it is validated to 0-6 by the
|
|
1562
|
+
* schema layer and is a number, so it is safe to interpolate. Omitting it
|
|
1563
|
+
* applies Mail's default flag without touching the color.
|
|
1560
1564
|
*/
|
|
1561
|
-
|
|
1562
|
-
const
|
|
1565
|
+
flagOperation(varName, colorIndex) {
|
|
1566
|
+
const setFlag = `set flagged status of ${varName} to true`;
|
|
1567
|
+
return colorIndex === undefined
|
|
1568
|
+
? setFlag
|
|
1569
|
+
: `${setFlag}\n set flag index of ${varName} to ${colorIndex}`;
|
|
1570
|
+
}
|
|
1571
|
+
/**
|
|
1572
|
+
* Flag a message, optionally with a color (see {@link flagOperation}).
|
|
1573
|
+
*/
|
|
1574
|
+
flagMessage(id, colorIndex) {
|
|
1575
|
+
const script = this.findMessageScript(id, this.flagOperation("msg", colorIndex));
|
|
1563
1576
|
const result = executeAppleScript(script, { timeoutMs: 60000 });
|
|
1564
1577
|
if (!result.success || result.output.startsWith("error:")) {
|
|
1565
1578
|
console.error(`Failed to flag message: ${result.error || result.output}`);
|
|
@@ -1862,8 +1875,8 @@ export class AppleMailManager {
|
|
|
1862
1875
|
/**
|
|
1863
1876
|
* Flag multiple messages at once (single tree walk).
|
|
1864
1877
|
*/
|
|
1865
|
-
batchFlagMessages(ids) {
|
|
1866
|
-
return this.runBatchOperation(ids, "
|
|
1878
|
+
batchFlagMessages(ids, colorIndex) {
|
|
1879
|
+
return this.runBatchOperation(ids, this.flagOperation("_msg", colorIndex));
|
|
1867
1880
|
}
|
|
1868
1881
|
/**
|
|
1869
1882
|
* Unflag multiple messages at once (single tree walk).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mimeParse.d.ts","sourceRoot":"","sources":["../../src/utils/mimeParse.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,WAAW,kBAAkB;IACjC,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,oFAAoF;IACpF,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAmB,SAAQ,kBAAkB;IAC5D,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC;CACd;
|
|
1
|
+
{"version":3,"file":"mimeParse.d.ts","sourceRoot":"","sources":["../../src/utils/mimeParse.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,WAAW,kBAAkB;IACjC,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,oFAAoF;IACpF,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAmB,SAAQ,kBAAkB;IAC5D,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC;CACd;AAqMD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB,EAAE,CAyBzE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAuB7D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAuB7D;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,GACrB,kBAAkB,GAAG,IAAI,CAwB3B"}
|
package/build/utils/mimeParse.js
CHANGED
|
@@ -107,19 +107,30 @@ function splitMimeParts(source, boundary) {
|
|
|
107
107
|
}
|
|
108
108
|
return parts;
|
|
109
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Maximum nesting depth for multipart MIME traversal. Bounds recursion so a
|
|
112
|
+
* pathologically (or maliciously) deeply nested multipart tree can't blow the
|
|
113
|
+
* stack — past this depth we stop descending and treat the container as a leaf.
|
|
114
|
+
* Real mail nests only a few levels (e.g. mixed → related → alternative).
|
|
115
|
+
*/
|
|
116
|
+
const MAX_MIME_DEPTH = 20;
|
|
110
117
|
/**
|
|
111
118
|
* Walk a multipart MIME block and return all non-multipart leaf parts,
|
|
112
119
|
* descending into nested multipart/* containers (alternative, related, mixed).
|
|
120
|
+
*
|
|
121
|
+
* Descent is bounded by MAX_MIME_DEPTH; once reached, deeper multipart
|
|
122
|
+
* containers are returned as-is (as leaf parts) rather than recursed into,
|
|
123
|
+
* yielding what's parsed so far instead of overflowing the stack.
|
|
113
124
|
*/
|
|
114
|
-
function walkLeafParts(source, boundary) {
|
|
125
|
+
function walkLeafParts(source, boundary, depth = 0) {
|
|
115
126
|
const result = [];
|
|
116
127
|
const parts = splitMimeParts(source, boundary);
|
|
117
128
|
for (const part of parts) {
|
|
118
129
|
const ct = getHeader(part.headers, "Content-Type");
|
|
119
|
-
if (ct && /^multipart\//i.test(ct)) {
|
|
130
|
+
if (ct && /^multipart\//i.test(ct) && depth < MAX_MIME_DEPTH) {
|
|
120
131
|
const nestedBoundary = extractBoundary(ct);
|
|
121
132
|
if (nestedBoundary) {
|
|
122
|
-
result.push(...walkLeafParts(part.body, nestedBoundary));
|
|
133
|
+
result.push(...walkLeafParts(part.body, nestedBoundary, depth + 1));
|
|
123
134
|
continue;
|
|
124
135
|
}
|
|
125
136
|
}
|
package/package.json
CHANGED