apple-mail-mcp 2.4.2 → 2.6.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 +35 -4
- package/build/index.js +430 -55
- package/build/services/appleMailManager.d.ts +37 -2
- package/build/services/appleMailManager.d.ts.map +1 -1
- package/build/services/appleMailManager.js +106 -10
- package/build/services/imapClient.d.ts +14 -0
- package/build/services/imapClient.d.ts.map +1 -1
- package/build/services/imapClient.js +22 -1
- package/build/services/imapMultiAccount.d.ts +124 -0
- package/build/services/imapMultiAccount.d.ts.map +1 -0
- package/build/services/imapMultiAccount.js +253 -0
- package/build/services/replyForward.d.ts +87 -0
- package/build/services/replyForward.d.ts.map +1 -0
- package/build/services/replyForward.js +150 -0
- package/build/services/smtpMailer.d.ts +43 -0
- package/build/services/smtpMailer.d.ts.map +1 -1
- package/build/services/smtpMailer.js +55 -0
- package/package.json +1 -1
|
@@ -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,WAA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,UAAU;CAiE5B"}
|
|
@@ -178,7 +178,7 @@ const UNSUPPORTED_APPLESCRIPT_OP = /AppleEvent handler failed|-10000/i;
|
|
|
178
178
|
export function describeMailboxOpError(op, raw) {
|
|
179
179
|
const trimmed = (raw || "").trim();
|
|
180
180
|
if (UNSUPPORTED_APPLESCRIPT_OP.test(trimmed)) {
|
|
181
|
-
const verb = op
|
|
181
|
+
const verb = op.charAt(0).toUpperCase() + op.slice(1);
|
|
182
182
|
return `Mail.app cannot ${op} server-side (IMAP / Gmail / Workspace / iCloud / Exchange) mailboxes via AppleScript — only local "On My Mac" mailboxes support this. ${verb} it in Mail.app directly. (Mail.app error: ${trimmed})`;
|
|
183
183
|
}
|
|
184
184
|
return trimmed || `Failed to ${op} mailbox`;
|
|
@@ -523,6 +523,77 @@ export class AppleMailManager {
|
|
|
523
523
|
this.cache.accounts = null;
|
|
524
524
|
this.cache.mailboxNames.clear();
|
|
525
525
|
}
|
|
526
|
+
/**
|
|
527
|
+
* Reads the live `enabled` flag for an account directly from Mail (bypassing
|
|
528
|
+
* the 60 s account cache) so a guard reflects an account that was enabled or
|
|
529
|
+
* disabled out-of-band. Returns true/false when known, or null when the probe
|
|
530
|
+
* is inconclusive — account not found, or the probe itself failed. Callers
|
|
531
|
+
* treat null as "can't tell, don't block".
|
|
532
|
+
*/
|
|
533
|
+
isAccountEnabled(account) {
|
|
534
|
+
const safeAccount = escapeForAppleScript(account);
|
|
535
|
+
const result = executeAppleScript(buildAppLevelScript(`
|
|
536
|
+
try
|
|
537
|
+
return (enabled of account "${safeAccount}") as text
|
|
538
|
+
on error
|
|
539
|
+
return "missing"
|
|
540
|
+
end try
|
|
541
|
+
`));
|
|
542
|
+
if (!result.success)
|
|
543
|
+
return null;
|
|
544
|
+
const out = result.output.trim();
|
|
545
|
+
if (out === "true")
|
|
546
|
+
return true;
|
|
547
|
+
if (out === "false")
|
|
548
|
+
return false;
|
|
549
|
+
return null;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Guard for AppleScript-backed structural operations (create / delete / rename
|
|
553
|
+
* mailbox). When the target account is disabled in Mail, Mail holds no live
|
|
554
|
+
* server session for it, so the operation fails inside Mail with an opaque
|
|
555
|
+
* AppleEvent -10000 — and a multi-step op like rename can leave half-built
|
|
556
|
+
* state behind (an orphaned destination mailbox). Detect the disabled account
|
|
557
|
+
* up front and refuse with an actionable message instead of attempting the
|
|
558
|
+
* doomed op.
|
|
559
|
+
*
|
|
560
|
+
* Returns an error string when the account is known-disabled, else null —
|
|
561
|
+
* including when the state can't be determined. We fail open: an inconclusive
|
|
562
|
+
* probe never blocks an otherwise-valid operation.
|
|
563
|
+
*
|
|
564
|
+
* Applies only to the AppleScript backend. Direct-IMAP accounts talk to the
|
|
565
|
+
* server independent of Mail's enabled toggle and are routed before reaching
|
|
566
|
+
* the manager.
|
|
567
|
+
*/
|
|
568
|
+
disabledAccountGuard(account) {
|
|
569
|
+
if (this.isAccountEnabled(account) === false) {
|
|
570
|
+
return `Account "${account}" is disabled in Mail, so Mail has no live connection to it — this operation would fail server-side (AppleEvent -10000) and could leave a mailbox half-changed. Enable the account (Mail ▸ Settings ▸ Accounts ▸ "Enable this account") and retry, or target an enabled account.`;
|
|
571
|
+
}
|
|
572
|
+
return null;
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Best-effort rollback for a failed rename: delete a just-created destination
|
|
576
|
+
* mailbox, but ONLY if it is empty, so any messages that did move are never
|
|
577
|
+
* destroyed. Returns true if the empty orphan was removed.
|
|
578
|
+
*/
|
|
579
|
+
deleteMailboxIfEmpty(name, account) {
|
|
580
|
+
const safeName = escapeForAppleScript(name);
|
|
581
|
+
const safeAccount = escapeForAppleScript(account);
|
|
582
|
+
const result = executeAppleScript(buildAppLevelScript(`
|
|
583
|
+
try
|
|
584
|
+
set mb to mailbox "${safeName}" of account "${safeAccount}"
|
|
585
|
+
if (count of messages of mb) is 0 then
|
|
586
|
+
delete mb
|
|
587
|
+
return "deleted"
|
|
588
|
+
else
|
|
589
|
+
return "kept"
|
|
590
|
+
end if
|
|
591
|
+
on error errMsg
|
|
592
|
+
return "error:" & errMsg
|
|
593
|
+
end try
|
|
594
|
+
`));
|
|
595
|
+
return result.success && result.output.trim() === "deleted";
|
|
596
|
+
}
|
|
526
597
|
/**
|
|
527
598
|
* Resolves the account to use for an operation when the caller omits one.
|
|
528
599
|
*
|
|
@@ -2050,6 +2121,11 @@ export class AppleMailManager {
|
|
|
2050
2121
|
*/
|
|
2051
2122
|
createMailbox(name, account) {
|
|
2052
2123
|
const targetAccount = this.resolveAccount(account);
|
|
2124
|
+
const disabled = this.disabledAccountGuard(targetAccount);
|
|
2125
|
+
if (disabled) {
|
|
2126
|
+
console.error(`Refusing to create mailbox: ${disabled}`);
|
|
2127
|
+
return { success: false, error: disabled };
|
|
2128
|
+
}
|
|
2053
2129
|
const safeName = escapeForAppleScript(name);
|
|
2054
2130
|
const safeAccount = escapeForAppleScript(targetAccount);
|
|
2055
2131
|
const script = buildAppLevelScript(`
|
|
@@ -2062,17 +2138,26 @@ export class AppleMailManager {
|
|
|
2062
2138
|
`);
|
|
2063
2139
|
const result = executeAppleScript(script);
|
|
2064
2140
|
if (!result.success || result.output.startsWith("error:")) {
|
|
2065
|
-
|
|
2066
|
-
|
|
2141
|
+
const raw = result.success
|
|
2142
|
+
? result.output.replace(/^error:/, "")
|
|
2143
|
+
: result.error || "Unknown error";
|
|
2144
|
+
const error = describeMailboxOpError("create", raw);
|
|
2145
|
+
console.error(`Failed to create mailbox: ${error}`);
|
|
2146
|
+
return { success: false, error };
|
|
2067
2147
|
}
|
|
2068
2148
|
this.invalidateCache();
|
|
2069
|
-
return true;
|
|
2149
|
+
return { success: true };
|
|
2070
2150
|
}
|
|
2071
2151
|
/**
|
|
2072
2152
|
* Delete a mailbox.
|
|
2073
2153
|
*/
|
|
2074
2154
|
deleteMailbox(name, account) {
|
|
2075
2155
|
const targetAccount = this.resolveAccount(account);
|
|
2156
|
+
const disabled = this.disabledAccountGuard(targetAccount);
|
|
2157
|
+
if (disabled) {
|
|
2158
|
+
console.error(`Refusing to delete mailbox: ${disabled}`);
|
|
2159
|
+
return { success: false, error: disabled };
|
|
2160
|
+
}
|
|
2076
2161
|
const targetMailbox = this.resolveMailbox(name, targetAccount);
|
|
2077
2162
|
const safeName = escapeForAppleScript(targetMailbox);
|
|
2078
2163
|
const safeAccount = escapeForAppleScript(targetAccount);
|
|
@@ -2101,11 +2186,15 @@ export class AppleMailManager {
|
|
|
2101
2186
|
*/
|
|
2102
2187
|
renameMailbox(oldName, newName, account) {
|
|
2103
2188
|
const targetAccount = this.resolveAccount(account);
|
|
2104
|
-
// Create the new mailbox
|
|
2105
|
-
|
|
2189
|
+
// Create the new mailbox. createMailbox runs the disabled-account guard, so
|
|
2190
|
+
// a disabled target is refused here before anything is built — no orphan can
|
|
2191
|
+
// be created. Propagate its (more specific) error rather than a generic one.
|
|
2192
|
+
const created = this.createMailbox(newName, targetAccount);
|
|
2193
|
+
if (!created.success) {
|
|
2106
2194
|
return {
|
|
2107
2195
|
success: false,
|
|
2108
|
-
error:
|
|
2196
|
+
error: created.error ??
|
|
2197
|
+
`Could not create the destination mailbox "${newName}" needed for the rename.`,
|
|
2109
2198
|
};
|
|
2110
2199
|
}
|
|
2111
2200
|
// Move all messages from old to new
|
|
@@ -2155,9 +2244,16 @@ export class AppleMailManager {
|
|
|
2155
2244
|
const raw = result.success
|
|
2156
2245
|
? result.output.replace(/^error:/, "")
|
|
2157
2246
|
: result.error || "Unknown error";
|
|
2158
|
-
//
|
|
2159
|
-
//
|
|
2160
|
-
|
|
2247
|
+
// Roll back the destination we just created so a failed rename doesn't
|
|
2248
|
+
// leave an orphan (as a partial-failure once did — the _amcp_rename_test_*
|
|
2249
|
+
// ghosts). deleteMailboxIfEmpty only removes it when empty, so any
|
|
2250
|
+
// messages that did move are never destroyed; the source is untouched
|
|
2251
|
+
// (its delete only runs after a verified-empty move).
|
|
2252
|
+
const rolledBack = this.deleteMailboxIfEmpty(resolvedNew, targetAccount);
|
|
2253
|
+
let error = describeMailboxOpError("rename", raw);
|
|
2254
|
+
error += rolledBack
|
|
2255
|
+
? ` The empty destination mailbox "${resolvedNew}" was rolled back, so no orphan was left.`
|
|
2256
|
+
: ` The destination mailbox "${resolvedNew}" was created and could not be auto-removed; delete it manually if it is an empty leftover.`;
|
|
2161
2257
|
console.error(`Failed to rename mailbox: ${error}`);
|
|
2162
2258
|
this.invalidateCache();
|
|
2163
2259
|
return { success: false, error };
|
|
@@ -139,6 +139,20 @@ export interface ImapDeps {
|
|
|
139
139
|
}
|
|
140
140
|
/** True when `account` matches any configured IMAP account (label or user). */
|
|
141
141
|
export declare function isImapAccount(account: string | undefined, env?: NodeJS.ProcessEnv): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Read-side routing gate (v2.6.0 — prefer-IMAP reads). Returns true when a read
|
|
144
|
+
* tool should go to IMAP rather than AppleScript:
|
|
145
|
+
* - IMAP is configured at all, AND
|
|
146
|
+
* - either the caller named no account (→ merge across all accounts), or the
|
|
147
|
+
* named account is itself a configured IMAP account.
|
|
148
|
+
* An explicitly-named NON-IMAP account returns false → AppleScript. When IMAP is
|
|
149
|
+
* not configured at all this is always false, so behavior is unchanged.
|
|
150
|
+
*
|
|
151
|
+
* NOTE: the 3 mailbox-WRITE ops (create/delete/rename-mailbox) deliberately keep
|
|
152
|
+
* using `isImapAccount` — they only route to IMAP for an explicitly-named IMAP
|
|
153
|
+
* account, never on an omitted account.
|
|
154
|
+
*/
|
|
155
|
+
export declare function shouldUseImap(account: string | undefined, env?: NodeJS.ProcessEnv): boolean;
|
|
142
156
|
/** Account labels of every configured IMAP account (C2), for diagnostics. */
|
|
143
157
|
export declare function listImapAccountLabels(env?: NodeJS.ProcessEnv): string[];
|
|
144
158
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imapClient.d.ts","sourceRoot":"","sources":["../../src/services/imapClient.ts"],"names":[],"mappings":"AA4BA,eAAO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nB,KAAK,SAAK,GACT,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAmElC"}
|
|
@@ -142,6 +142,22 @@ export function isImapAccount(account, env = process.env) {
|
|
|
142
142
|
return false;
|
|
143
143
|
return listImapAccountSpecs(env).some((s) => s.accountLabel === account || s.user === account);
|
|
144
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Read-side routing gate (v2.6.0 — prefer-IMAP reads). Returns true when a read
|
|
147
|
+
* tool should go to IMAP rather than AppleScript:
|
|
148
|
+
* - IMAP is configured at all, AND
|
|
149
|
+
* - either the caller named no account (→ merge across all accounts), or the
|
|
150
|
+
* named account is itself a configured IMAP account.
|
|
151
|
+
* An explicitly-named NON-IMAP account returns false → AppleScript. When IMAP is
|
|
152
|
+
* not configured at all this is always false, so behavior is unchanged.
|
|
153
|
+
*
|
|
154
|
+
* NOTE: the 3 mailbox-WRITE ops (create/delete/rename-mailbox) deliberately keep
|
|
155
|
+
* using `isImapAccount` — they only route to IMAP for an explicitly-named IMAP
|
|
156
|
+
* account, never on an omitted account.
|
|
157
|
+
*/
|
|
158
|
+
export function shouldUseImap(account, env = process.env) {
|
|
159
|
+
return (listImapAccountSpecs(env).length > 0 && (account === undefined || isImapAccount(account, env)));
|
|
160
|
+
}
|
|
145
161
|
/** Account labels of every configured IMAP account (C2), for diagnostics. */
|
|
146
162
|
export function listImapAccountLabels(env = process.env) {
|
|
147
163
|
return listImapAccountSpecs(env).map((s) => s.accountLabel);
|
|
@@ -278,6 +294,11 @@ function structuredRow(m, account, path) {
|
|
|
278
294
|
mailbox: path,
|
|
279
295
|
account,
|
|
280
296
|
hasAttachments: false,
|
|
297
|
+
// Message-ID (when the envelope carries it) is the strongest cross-/intra-
|
|
298
|
+
// backend dedup key for the multi-account merge (imapMultiAccount.ts). The
|
|
299
|
+
// AppleScript path does not expose it, so cross-backend dedup falls back to
|
|
300
|
+
// the subject|sender|date composite key.
|
|
301
|
+
...(env.messageId ? { messageId: env.messageId } : {}),
|
|
281
302
|
};
|
|
282
303
|
}
|
|
283
304
|
async function run(args, listMode, deps) {
|
|
@@ -851,7 +872,7 @@ async function imapBatch(ids, deps, op) {
|
|
|
851
872
|
errors.push(`Not an IMAP id: "${id}"`);
|
|
852
873
|
continue;
|
|
853
874
|
}
|
|
854
|
-
const key = `${ref.account}
|
|
875
|
+
const key = `${ref.account}\0${ref.path}`;
|
|
855
876
|
const g = groups.get(key) ?? { account: ref.account, path: ref.path, uids: [] };
|
|
856
877
|
g.uids.push(ref.uid);
|
|
857
878
|
groups.set(key, g);
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-account read merge (v2.6.0 — prefer-IMAP reads).
|
|
3
|
+
*
|
|
4
|
+
* v2.6.0 flips the read tools to PREFER direct IMAP whenever IMAP is configured
|
|
5
|
+
* (see `shouldUseImap` in imapClient.ts). When a read is issued with NO explicit
|
|
6
|
+
* account, results must still cover EVERY account the user has — so we:
|
|
7
|
+
*
|
|
8
|
+
* 1. fan the IMAP query out over every configured IMAP account
|
|
9
|
+
* (`resolveImapConfigs()`), and
|
|
10
|
+
* 2. ALSO run the existing AppleScript all-accounts path,
|
|
11
|
+
*
|
|
12
|
+
* then merge the two, de-duplicating any message that appears in both backends
|
|
13
|
+
* (e.g. a Gmail account that is both IMAP-configured AND visible to Mail.app's
|
|
14
|
+
* AppleScript scan) and preferring the IMAP copy (it carries the round-trippable
|
|
15
|
+
* `imap:` id that the mutation tools need).
|
|
16
|
+
*
|
|
17
|
+
* This module holds the backend-agnostic merge/dedup/sort + the per-account IMAP
|
|
18
|
+
* fan-out so the three message-list sites (search-messages, get-thread,
|
|
19
|
+
* list-messages) don't each re-implement it.
|
|
20
|
+
*
|
|
21
|
+
* @module services/imapMultiAccount
|
|
22
|
+
*/
|
|
23
|
+
import { type ImapSearchArgs, type ImapConfig, type ImapDeps } from "../services/imapClient.js";
|
|
24
|
+
import type { Account } from "../types.js";
|
|
25
|
+
/** A structured message row as emitted by either backend (permissive on keys). */
|
|
26
|
+
export type MessageRow = Record<string, unknown>;
|
|
27
|
+
/**
|
|
28
|
+
* Cross-backend dedup key for a message row.
|
|
29
|
+
*
|
|
30
|
+
* - PREFER the normalized Message-ID when present (`mid:<id>`). It's the only
|
|
31
|
+
* globally-unique identity, so two IMAP accounts that both hold the very
|
|
32
|
+
* same message (rare, but possible with multi-delivery) collapse to one.
|
|
33
|
+
* - FALL BACK to `normalizedSubject|sender|dateReceivedEpoch` when no
|
|
34
|
+
* Message-ID is available. The AppleScript backend never exposes a
|
|
35
|
+
* Message-ID, so this composite is what actually dedups the common case: a
|
|
36
|
+
* Gmail account surfaced by BOTH the IMAP fan-out and the AppleScript
|
|
37
|
+
* all-accounts scan. The IMAP and AppleScript copies of one message share
|
|
38
|
+
* the same subject, sender, and received timestamp, so they collide here.
|
|
39
|
+
*
|
|
40
|
+
* Limitation (note for live testing): the composite key assumes the two backends
|
|
41
|
+
* report the SAME received timestamp to the second. If Mail.app and the IMAP
|
|
42
|
+
* server disagree on `dateReceived` (timezone/rounding), a message could escape
|
|
43
|
+
* dedup and appear twice. Message-ID dedup (IMAP-vs-IMAP) is exact; the
|
|
44
|
+
* composite is best-effort.
|
|
45
|
+
*/
|
|
46
|
+
export declare function dedupKey(row: MessageRow): string;
|
|
47
|
+
/**
|
|
48
|
+
* Merge IMAP rows with AppleScript rows: concatenate, de-dup by {@link dedupKey}
|
|
49
|
+
* preferring the IMAP copy (IMAP rows are passed first and win on collision),
|
|
50
|
+
* sort newest-first by dateReceived, then apply `limit`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function mergeMessages(imapRows: MessageRow[], appleRows: MessageRow[], limit: number): MessageRow[];
|
|
53
|
+
/** Gmail/Workspace IMAP host? Its `[Gmail]/All Mail` virtual mailbox is Gmail-only. */
|
|
54
|
+
export declare function isGmailHost(host: string): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Fan an IMAP message query out over EVERY configured IMAP account and return
|
|
57
|
+
* the concatenated structured rows (not yet merged with AppleScript, not yet
|
|
58
|
+
* limited — the caller merges + limits). `kind` picks the underlying query so
|
|
59
|
+
* the mailbox-default and unreadOnly semantics match the single-account path.
|
|
60
|
+
*
|
|
61
|
+
* Per-account failures are swallowed (logged) so one unreachable account doesn't
|
|
62
|
+
* sink the whole read; the returned `accountsQueried`/`accountsFailed` let the
|
|
63
|
+
* caller surface partial-coverage diagnostics.
|
|
64
|
+
*/
|
|
65
|
+
export declare function fanOutImapMessages(args: ImapSearchArgs, kind: "search" | "list", deps?: Omit<ImapDeps, "config" | "account">, configs?: ImapConfig[]): Promise<{
|
|
66
|
+
rows: MessageRow[];
|
|
67
|
+
accountsQueried: string[];
|
|
68
|
+
accountsFailed: string[];
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* Per-pair matcher: does this IMAP config correspond to this Mail.app account?
|
|
72
|
+
* Compared case-insensitively, the config's `accountLabel` AND `user` against the
|
|
73
|
+
* Mail account's `name` AND `email`. An empty email can't match (avoids
|
|
74
|
+
* `"" === ""` false positives). This is the single source of truth for coverage;
|
|
75
|
+
* everything else delegates here.
|
|
76
|
+
*/
|
|
77
|
+
export declare function configMatchesAccount(config: ImapConfig, account: Account): boolean;
|
|
78
|
+
/** True when ANY config matches this Mail account (delegates to the per-pair matcher). */
|
|
79
|
+
export declare function isAccountCoveredByImap(account: Account, configs: ImapConfig[]): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Split Mail.app accounts into those covered by IMAP (counted via IMAP) and the
|
|
82
|
+
* rest (counted via AppleScript), so reads/counts skip the AppleScript scan for
|
|
83
|
+
* IMAP-covered accounts.
|
|
84
|
+
*/
|
|
85
|
+
export declare function partitionAccountsForCounts(accounts: Account[], configs: ImapConfig[]): {
|
|
86
|
+
imapCovered: Account[];
|
|
87
|
+
appleScriptOnly: Account[];
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* One unit to count for the count tools (get-unread-count / get-mail-stats),
|
|
91
|
+
* carrying exactly ONE source so every account is counted once and only once:
|
|
92
|
+
* - `{ kind: "imap", config }` — count this account via IMAP STATUS;
|
|
93
|
+
* - `{ kind: "applescript", account }`— count this Mail account via AppleScript.
|
|
94
|
+
*/
|
|
95
|
+
export type CountSource = {
|
|
96
|
+
kind: "imap";
|
|
97
|
+
config: ImapConfig;
|
|
98
|
+
label: string;
|
|
99
|
+
} | {
|
|
100
|
+
kind: "applescript";
|
|
101
|
+
account: Account;
|
|
102
|
+
label: string;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Plan the count sources so NO account is double-counted even when the coverage
|
|
106
|
+
* heuristic mis-matches (the failure mode the naive `Σimap(all configs) +
|
|
107
|
+
* Σapple(uncovered)` had: a config that fails to match its Mail account lands in
|
|
108
|
+
* BOTH sums).
|
|
109
|
+
*
|
|
110
|
+
* Account-centric: walk the Mail.app accounts; each is counted via its FIRST
|
|
111
|
+
* matching config (IMAP) or, if none matches, via AppleScript. Then any IMAP
|
|
112
|
+
* config that matched NO Mail account (configured-but-not-present-in-Mail.app) is
|
|
113
|
+
* added once as an IMAP source. A config is consumed by at most one Mail account,
|
|
114
|
+
* so two Mail accounts can't both claim the same config and inflate the total.
|
|
115
|
+
*/
|
|
116
|
+
export declare function planCountSources(accounts: Account[], configs: ImapConfig[]): CountSource[];
|
|
117
|
+
/**
|
|
118
|
+
* Render the structured message rows into the human text block the read tools
|
|
119
|
+
* emit (` - ID: … | date | subject (from: sender) [read|unread]`). Shared so the
|
|
120
|
+
* merged path matches the single-backend formatting. `showReadState` mirrors
|
|
121
|
+
* search/list (which show [read]) vs. plain list rows.
|
|
122
|
+
*/
|
|
123
|
+
export declare function formatMergedRows(rows: MessageRow[], showReadState?: boolean): string;
|
|
124
|
+
//# sourceMappingURL=imapMultiAccount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imapMultiAccount.d.ts","sourceRoot":"","sources":["../../src/services/imapMultiAccount.ts"],"names":[],"mappings":"AAAA;;;;;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