@diskd-ai/email-mcp 0.3.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/LICENSE +155 -0
- package/README.md +820 -0
- package/dist/cli/account-commands.d.ts +10 -0
- package/dist/cli/account-commands.d.ts.map +1 -0
- package/dist/cli/account-commands.js +703 -0
- package/dist/cli/account-commands.js.map +1 -0
- package/dist/cli/config-commands.d.ts +9 -0
- package/dist/cli/config-commands.d.ts.map +1 -0
- package/dist/cli/config-commands.js +156 -0
- package/dist/cli/config-commands.js.map +1 -0
- package/dist/cli/guard.d.ts +11 -0
- package/dist/cli/guard.d.ts.map +1 -0
- package/dist/cli/guard.js +18 -0
- package/dist/cli/guard.js.map +1 -0
- package/dist/cli/install-commands.d.ts +12 -0
- package/dist/cli/install-commands.d.ts.map +1 -0
- package/dist/cli/install-commands.js +320 -0
- package/dist/cli/install-commands.js.map +1 -0
- package/dist/cli/notify.d.ts +8 -0
- package/dist/cli/notify.d.ts.map +1 -0
- package/dist/cli/notify.js +143 -0
- package/dist/cli/notify.js.map +1 -0
- package/dist/cli/providers.d.ts +13 -0
- package/dist/cli/providers.d.ts.map +1 -0
- package/dist/cli/providers.js +180 -0
- package/dist/cli/providers.js.map +1 -0
- package/dist/cli/scheduler.d.ts +8 -0
- package/dist/cli/scheduler.d.ts.map +1 -0
- package/dist/cli/scheduler.js +268 -0
- package/dist/cli/scheduler.js.map +1 -0
- package/dist/cli/setup.d.ts +12 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js +15 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/cli/test.d.ts +7 -0
- package/dist/cli/test.d.ts.map +1 -0
- package/dist/cli/test.js +67 -0
- package/dist/cli/test.js.map +1 -0
- package/dist/config/loader.d.ts +34 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +339 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/schema.d.ts +351 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +165 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/config/xdg.d.ts +27 -0
- package/dist/config/xdg.d.ts.map +1 -0
- package/dist/config/xdg.js +30 -0
- package/dist/config/xdg.js.map +1 -0
- package/dist/connections/manager.d.ts +42 -0
- package/dist/connections/manager.d.ts.map +1 -0
- package/dist/connections/manager.js +266 -0
- package/dist/connections/manager.js.map +1 -0
- package/dist/connections/types.d.ts +13 -0
- package/dist/connections/types.d.ts.map +1 -0
- package/dist/connections/types.js +2 -0
- package/dist/connections/types.js.map +1 -0
- package/dist/logging.d.ts +46 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +63 -0
- package/dist/logging.js.map +1 -0
- package/dist/main.d.ts +13 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +206 -0
- package/dist/main.js.map +1 -0
- package/dist/prompts/actions.prompt.d.ts +9 -0
- package/dist/prompts/actions.prompt.d.ts.map +1 -0
- package/dist/prompts/actions.prompt.js +64 -0
- package/dist/prompts/actions.prompt.js.map +1 -0
- package/dist/prompts/calendar.prompt.d.ts +9 -0
- package/dist/prompts/calendar.prompt.d.ts.map +1 -0
- package/dist/prompts/calendar.prompt.js +55 -0
- package/dist/prompts/calendar.prompt.js.map +1 -0
- package/dist/prompts/cleanup.prompt.d.ts +9 -0
- package/dist/prompts/cleanup.prompt.d.ts.map +1 -0
- package/dist/prompts/cleanup.prompt.js +78 -0
- package/dist/prompts/cleanup.prompt.js.map +1 -0
- package/dist/prompts/compose.prompt.d.ts +8 -0
- package/dist/prompts/compose.prompt.d.ts.map +1 -0
- package/dist/prompts/compose.prompt.js +116 -0
- package/dist/prompts/compose.prompt.js.map +1 -0
- package/dist/prompts/register.d.ts +8 -0
- package/dist/prompts/register.d.ts.map +1 -0
- package/dist/prompts/register.js +20 -0
- package/dist/prompts/register.js.map +1 -0
- package/dist/prompts/thread.prompt.d.ts +9 -0
- package/dist/prompts/thread.prompt.d.ts.map +1 -0
- package/dist/prompts/thread.prompt.js +58 -0
- package/dist/prompts/thread.prompt.js.map +1 -0
- package/dist/prompts/triage.prompt.d.ts +9 -0
- package/dist/prompts/triage.prompt.d.ts.map +1 -0
- package/dist/prompts/triage.prompt.js +64 -0
- package/dist/prompts/triage.prompt.js.map +1 -0
- package/dist/resources/accounts.resource.d.ts +9 -0
- package/dist/resources/accounts.resource.d.ts.map +1 -0
- package/dist/resources/accounts.resource.js +26 -0
- package/dist/resources/accounts.resource.js.map +1 -0
- package/dist/resources/mailboxes.resource.d.ts +10 -0
- package/dist/resources/mailboxes.resource.d.ts.map +1 -0
- package/dist/resources/mailboxes.resource.js +33 -0
- package/dist/resources/mailboxes.resource.js.map +1 -0
- package/dist/resources/register.d.ts +12 -0
- package/dist/resources/register.d.ts.map +1 -0
- package/dist/resources/register.js +20 -0
- package/dist/resources/register.js.map +1 -0
- package/dist/resources/scheduled.resource.d.ts +9 -0
- package/dist/resources/scheduled.resource.d.ts.map +1 -0
- package/dist/resources/scheduled.resource.js +31 -0
- package/dist/resources/scheduled.resource.js.map +1 -0
- package/dist/resources/stats.resource.d.ts +10 -0
- package/dist/resources/stats.resource.d.ts.map +1 -0
- package/dist/resources/stats.resource.js +45 -0
- package/dist/resources/stats.resource.js.map +1 -0
- package/dist/resources/templates.resource.d.ts +9 -0
- package/dist/resources/templates.resource.d.ts.map +1 -0
- package/dist/resources/templates.resource.js +34 -0
- package/dist/resources/templates.resource.js.map +1 -0
- package/dist/resources/unread.resource.d.ts +11 -0
- package/dist/resources/unread.resource.d.ts.map +1 -0
- package/dist/resources/unread.resource.js +46 -0
- package/dist/resources/unread.resource.js.map +1 -0
- package/dist/safety/audit.d.ts +17 -0
- package/dist/safety/audit.d.ts.map +1 -0
- package/dist/safety/audit.js +50 -0
- package/dist/safety/audit.js.map +1 -0
- package/dist/safety/rate-limiter.d.ts +22 -0
- package/dist/safety/rate-limiter.d.ts.map +1 -0
- package/dist/safety/rate-limiter.js +52 -0
- package/dist/safety/rate-limiter.js.map +1 -0
- package/dist/safety/validation.d.ts +44 -0
- package/dist/safety/validation.d.ts.map +1 -0
- package/dist/safety/validation.js +113 -0
- package/dist/safety/validation.js.map +1 -0
- package/dist/server.d.ts +10 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +25 -0
- package/dist/server.js.map +1 -0
- package/dist/services/calendar.service.d.ts +22 -0
- package/dist/services/calendar.service.d.ts.map +1 -0
- package/dist/services/calendar.service.js +115 -0
- package/dist/services/calendar.service.js.map +1 -0
- package/dist/services/event-bus.d.ts +28 -0
- package/dist/services/event-bus.d.ts.map +1 -0
- package/dist/services/event-bus.js +16 -0
- package/dist/services/event-bus.js.map +1 -0
- package/dist/services/hooks.service.d.ts +77 -0
- package/dist/services/hooks.service.d.ts.map +1 -0
- package/dist/services/hooks.service.js +498 -0
- package/dist/services/hooks.service.js.map +1 -0
- package/dist/services/imap.service.d.ts +133 -0
- package/dist/services/imap.service.d.ts.map +1 -0
- package/dist/services/imap.service.js +1393 -0
- package/dist/services/imap.service.js.map +1 -0
- package/dist/services/label-strategy.d.ts +20 -0
- package/dist/services/label-strategy.d.ts.map +1 -0
- package/dist/services/label-strategy.js +237 -0
- package/dist/services/label-strategy.js.map +1 -0
- package/dist/services/local-calendar.service.d.ts +126 -0
- package/dist/services/local-calendar.service.d.ts.map +1 -0
- package/dist/services/local-calendar.service.js +428 -0
- package/dist/services/local-calendar.service.js.map +1 -0
- package/dist/services/notifier.service.d.ts +69 -0
- package/dist/services/notifier.service.d.ts.map +1 -0
- package/dist/services/notifier.service.js +319 -0
- package/dist/services/notifier.service.js.map +1 -0
- package/dist/services/oauth.service.d.ts +47 -0
- package/dist/services/oauth.service.d.ts.map +1 -0
- package/dist/services/oauth.service.js +140 -0
- package/dist/services/oauth.service.js.map +1 -0
- package/dist/services/presets.d.ts +36 -0
- package/dist/services/presets.d.ts.map +1 -0
- package/dist/services/presets.js +173 -0
- package/dist/services/presets.js.map +1 -0
- package/dist/services/reminders.service.d.ts +63 -0
- package/dist/services/reminders.service.d.ts.map +1 -0
- package/dist/services/reminders.service.js +281 -0
- package/dist/services/reminders.service.js.map +1 -0
- package/dist/services/scheduler.service.d.ts +42 -0
- package/dist/services/scheduler.service.d.ts.map +1 -0
- package/dist/services/scheduler.service.js +260 -0
- package/dist/services/scheduler.service.js.map +1 -0
- package/dist/services/smtp.service.d.ts +40 -0
- package/dist/services/smtp.service.d.ts.map +1 -0
- package/dist/services/smtp.service.js +151 -0
- package/dist/services/smtp.service.js.map +1 -0
- package/dist/services/template.service.d.ts +33 -0
- package/dist/services/template.service.d.ts.map +1 -0
- package/dist/services/template.service.js +123 -0
- package/dist/services/template.service.js.map +1 -0
- package/dist/services/watcher.service.d.ts +36 -0
- package/dist/services/watcher.service.d.ts.map +1 -0
- package/dist/services/watcher.service.js +241 -0
- package/dist/services/watcher.service.js.map +1 -0
- package/dist/tools/accounts.tool.d.ts +7 -0
- package/dist/tools/accounts.tool.d.ts.map +1 -0
- package/dist/tools/accounts.tool.js +29 -0
- package/dist/tools/accounts.tool.js.map +1 -0
- package/dist/tools/analytics.tool.d.ts +9 -0
- package/dist/tools/analytics.tool.d.ts.map +1 -0
- package/dist/tools/analytics.tool.js +27 -0
- package/dist/tools/analytics.tool.js.map +1 -0
- package/dist/tools/attachments.tool.d.ts +7 -0
- package/dist/tools/attachments.tool.d.ts.map +1 -0
- package/dist/tools/attachments.tool.js +45 -0
- package/dist/tools/attachments.tool.js.map +1 -0
- package/dist/tools/bulk.tool.d.ts +7 -0
- package/dist/tools/bulk.tool.d.ts.map +1 -0
- package/dist/tools/bulk.tool.js +75 -0
- package/dist/tools/bulk.tool.js.map +1 -0
- package/dist/tools/calendar.tool.d.ts +19 -0
- package/dist/tools/calendar.tool.d.ts.map +1 -0
- package/dist/tools/calendar.tool.js +538 -0
- package/dist/tools/calendar.tool.js.map +1 -0
- package/dist/tools/contacts.tool.d.ts +7 -0
- package/dist/tools/contacts.tool.d.ts.map +1 -0
- package/dist/tools/contacts.tool.js +44 -0
- package/dist/tools/contacts.tool.js.map +1 -0
- package/dist/tools/drafts.tool.d.ts +8 -0
- package/dist/tools/drafts.tool.d.ts.map +1 -0
- package/dist/tools/drafts.tool.js +92 -0
- package/dist/tools/drafts.tool.js.map +1 -0
- package/dist/tools/emails.tool.d.ts +7 -0
- package/dist/tools/emails.tool.d.ts.map +1 -0
- package/dist/tools/emails.tool.js +400 -0
- package/dist/tools/emails.tool.js.map +1 -0
- package/dist/tools/folders.tool.d.ts +7 -0
- package/dist/tools/folders.tool.d.ts.map +1 -0
- package/dist/tools/folders.tool.js +111 -0
- package/dist/tools/folders.tool.js.map +1 -0
- package/dist/tools/health.tool.d.ts +10 -0
- package/dist/tools/health.tool.d.ts.map +1 -0
- package/dist/tools/health.tool.js +78 -0
- package/dist/tools/health.tool.js.map +1 -0
- package/dist/tools/label.tool.d.ts +11 -0
- package/dist/tools/label.tool.d.ts.map +1 -0
- package/dist/tools/label.tool.js +165 -0
- package/dist/tools/label.tool.js.map +1 -0
- package/dist/tools/locate.tool.d.ts +11 -0
- package/dist/tools/locate.tool.d.ts.map +1 -0
- package/dist/tools/locate.tool.js +59 -0
- package/dist/tools/locate.tool.js.map +1 -0
- package/dist/tools/mailboxes.tool.d.ts +7 -0
- package/dist/tools/mailboxes.tool.d.ts.map +1 -0
- package/dist/tools/mailboxes.tool.js +38 -0
- package/dist/tools/mailboxes.tool.js.map +1 -0
- package/dist/tools/manage.tool.d.ts +7 -0
- package/dist/tools/manage.tool.d.ts.map +1 -0
- package/dist/tools/manage.tool.js +125 -0
- package/dist/tools/manage.tool.js.map +1 -0
- package/dist/tools/register.d.ts +20 -0
- package/dist/tools/register.d.ts.map +1 -0
- package/dist/tools/register.js +53 -0
- package/dist/tools/register.js.map +1 -0
- package/dist/tools/scheduler.tool.d.ts +9 -0
- package/dist/tools/scheduler.tool.d.ts.map +1 -0
- package/dist/tools/scheduler.tool.js +104 -0
- package/dist/tools/scheduler.tool.js.map +1 -0
- package/dist/tools/send.tool.d.ts +7 -0
- package/dist/tools/send.tool.d.ts.map +1 -0
- package/dist/tools/send.tool.js +123 -0
- package/dist/tools/send.tool.js.map +1 -0
- package/dist/tools/templates.tool.d.ts +12 -0
- package/dist/tools/templates.tool.d.ts.map +1 -0
- package/dist/tools/templates.tool.js +140 -0
- package/dist/tools/templates.tool.js.map +1 -0
- package/dist/tools/thread.tool.d.ts +10 -0
- package/dist/tools/thread.tool.d.ts.map +1 -0
- package/dist/tools/thread.tool.js +146 -0
- package/dist/tools/thread.tool.js.map +1 -0
- package/dist/tools/watcher.tool.d.ts +9 -0
- package/dist/tools/watcher.tool.d.ts.map +1 -0
- package/dist/tools/watcher.tool.js +282 -0
- package/dist/tools/watcher.tool.js.map +1 -0
- package/dist/types/index.d.ts +271 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/calendar-notes.d.ts +31 -0
- package/dist/utils/calendar-notes.d.ts.map +1 -0
- package/dist/utils/calendar-notes.js +99 -0
- package/dist/utils/calendar-notes.js.map +1 -0
- package/dist/utils/calendar-state.d.ts +27 -0
- package/dist/utils/calendar-state.d.ts.map +1 -0
- package/dist/utils/calendar-state.js +85 -0
- package/dist/utils/calendar-state.js.map +1 -0
- package/dist/utils/conference-details.d.ts +12 -0
- package/dist/utils/conference-details.d.ts.map +1 -0
- package/dist/utils/conference-details.js +71 -0
- package/dist/utils/conference-details.js.map +1 -0
- package/dist/utils/meeting-url.d.ts +10 -0
- package/dist/utils/meeting-url.d.ts.map +1 -0
- package/dist/utils/meeting-url.js +30 -0
- package/dist/utils/meeting-url.js.map +1 -0
- package/package.json +108 -0
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Hooks Service — intelligent email triage via MCP sampling.
|
|
3
|
+
*
|
|
4
|
+
* Listens for new email events on the event bus and:
|
|
5
|
+
* - Matches static rules FIRST (fast, free, deterministic)
|
|
6
|
+
* - Falls through to AI triage via `sampling/createMessage` if no rule matched
|
|
7
|
+
* - Uses preset system prompts + custom instructions for AI triage
|
|
8
|
+
* - Auto-applies labels and flags based on AI response
|
|
9
|
+
* - Falls back to logging if sampling is unavailable
|
|
10
|
+
*/
|
|
11
|
+
import { mcpLog } from '../logging.js';
|
|
12
|
+
import eventBus from './event-bus.js';
|
|
13
|
+
import LocalCalendarService from './local-calendar.service.js';
|
|
14
|
+
import NotifierService from './notifier.service.js';
|
|
15
|
+
import { buildSystemPrompt } from './presets.js';
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// Pattern matching helpers
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
/** Convert a glob-like pattern (with `*` wildcards and `|` OR) to a RegExp. */
|
|
20
|
+
function globToRegex(pattern) {
|
|
21
|
+
const parts = pattern
|
|
22
|
+
.split('|')
|
|
23
|
+
.map((p) => p.trim())
|
|
24
|
+
.filter(Boolean);
|
|
25
|
+
const regexParts = parts.map((part) => {
|
|
26
|
+
const escaped = part.replace(/[.+?^${}()[\]\\]/g, '\\$&');
|
|
27
|
+
return escaped.replace(/\*/g, '.*');
|
|
28
|
+
});
|
|
29
|
+
return new RegExp(`^(?:${regexParts.join('|')})$`, 'i');
|
|
30
|
+
}
|
|
31
|
+
/** Test whether a value matches a glob pattern (case-insensitive). */
|
|
32
|
+
function matchesPattern(pattern, value) {
|
|
33
|
+
try {
|
|
34
|
+
return globToRegex(pattern).test(value);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
// HooksService
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
export default class HooksService {
|
|
44
|
+
config;
|
|
45
|
+
imapService;
|
|
46
|
+
lowLevelServer = null;
|
|
47
|
+
samplingSupported = false;
|
|
48
|
+
pendingEmails = [];
|
|
49
|
+
batchTimer = null;
|
|
50
|
+
rateCounter = 0;
|
|
51
|
+
rateResetTimer = null;
|
|
52
|
+
resolvedSystemPrompt;
|
|
53
|
+
notifier;
|
|
54
|
+
localCalendar;
|
|
55
|
+
static MAX_SAMPLING_PER_MIN = 10;
|
|
56
|
+
constructor(config, imapService) {
|
|
57
|
+
this.config = config;
|
|
58
|
+
this.imapService = imapService;
|
|
59
|
+
this.notifier = new NotifierService(config.alerts);
|
|
60
|
+
this.localCalendar = new LocalCalendarService();
|
|
61
|
+
this.resolvedSystemPrompt = buildSystemPrompt(config.preset, {
|
|
62
|
+
customInstructions: config.customInstructions,
|
|
63
|
+
systemPrompt: config.systemPrompt,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/** Returns the NotifierService instance for direct tool access. */
|
|
67
|
+
getNotifier() {
|
|
68
|
+
return this.notifier;
|
|
69
|
+
}
|
|
70
|
+
/** Returns the current hooks configuration. */
|
|
71
|
+
getHooksConfig() {
|
|
72
|
+
return this.config;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Start listening for email events.
|
|
76
|
+
* Call after MCP server is connected so we can access the low-level server.
|
|
77
|
+
*/
|
|
78
|
+
start(lowLevelServer, clientCapabilities) {
|
|
79
|
+
this.lowLevelServer = lowLevelServer;
|
|
80
|
+
this.samplingSupported = clientCapabilities.sampling === true;
|
|
81
|
+
if (this.config.onNewEmail === 'none')
|
|
82
|
+
return;
|
|
83
|
+
eventBus.on('email:new', (event) => {
|
|
84
|
+
this.onNewEmail(event);
|
|
85
|
+
});
|
|
86
|
+
// Rate limit reset every 60s
|
|
87
|
+
this.rateResetTimer = setInterval(() => {
|
|
88
|
+
this.rateCounter = 0;
|
|
89
|
+
}, 60_000);
|
|
90
|
+
const ruleCount = this.config.rules.length;
|
|
91
|
+
mcpLog('info', 'hooks', `Hooks active: mode=${this.config.onNewEmail}, preset=${this.config.preset}, ` +
|
|
92
|
+
`rules=${ruleCount}, sampling=${this.samplingSupported ? 'yes' : 'no'}`).catch(() => { });
|
|
93
|
+
}
|
|
94
|
+
stop() {
|
|
95
|
+
if (this.batchTimer) {
|
|
96
|
+
clearTimeout(this.batchTimer);
|
|
97
|
+
this.batchTimer = null;
|
|
98
|
+
}
|
|
99
|
+
this.pendingEmails = [];
|
|
100
|
+
if (this.rateResetTimer) {
|
|
101
|
+
clearInterval(this.rateResetTimer);
|
|
102
|
+
this.rateResetTimer = null;
|
|
103
|
+
}
|
|
104
|
+
this.notifier.stop();
|
|
105
|
+
eventBus.removeAllListeners('email:new');
|
|
106
|
+
}
|
|
107
|
+
// -------------------------------------------------------------------------
|
|
108
|
+
// Event handling + batching
|
|
109
|
+
// -------------------------------------------------------------------------
|
|
110
|
+
onNewEmail(event) {
|
|
111
|
+
const items = event.emails.map((meta) => ({
|
|
112
|
+
account: event.account,
|
|
113
|
+
mailbox: event.mailbox,
|
|
114
|
+
meta,
|
|
115
|
+
}));
|
|
116
|
+
this.pendingEmails.push(...items);
|
|
117
|
+
this.batchTimer ??= setTimeout(() => {
|
|
118
|
+
this.flushBatch().catch(() => { });
|
|
119
|
+
}, this.config.batchDelay * 1000);
|
|
120
|
+
}
|
|
121
|
+
async flushBatch() {
|
|
122
|
+
this.batchTimer = null;
|
|
123
|
+
const batch = [...this.pendingEmails];
|
|
124
|
+
this.pendingEmails = [];
|
|
125
|
+
if (batch.length === 0)
|
|
126
|
+
return;
|
|
127
|
+
await this.sendResourceUpdates(batch);
|
|
128
|
+
// Partition: static-rule-matched vs needs-AI-triage
|
|
129
|
+
const ruleMatched = [];
|
|
130
|
+
const needsTriage = [];
|
|
131
|
+
batch.forEach((email) => {
|
|
132
|
+
const outcome = HooksService.matchStaticRules(email, this.config.rules);
|
|
133
|
+
if (outcome.matched) {
|
|
134
|
+
ruleMatched.push({ email, rule: outcome.rule });
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
needsTriage.push(email);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
// Apply static rule actions
|
|
141
|
+
if (ruleMatched.length > 0) {
|
|
142
|
+
const ruleOps = ruleMatched.map(async ({ email, rule }) => this.applyStaticRule(email, rule));
|
|
143
|
+
await Promise.allSettled(ruleOps);
|
|
144
|
+
}
|
|
145
|
+
// AI triage for remaining emails
|
|
146
|
+
if (needsTriage.length > 0) {
|
|
147
|
+
if (this.config.onNewEmail === 'triage' && this.samplingSupported) {
|
|
148
|
+
await this.triageBatch(needsTriage);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
await this.notifyBatch(needsTriage);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// -------------------------------------------------------------------------
|
|
156
|
+
// Static rule matching
|
|
157
|
+
// -------------------------------------------------------------------------
|
|
158
|
+
static matchStaticRules(email, rules) {
|
|
159
|
+
const matched = rules.find((rule) => HooksService.emailMatchesRule(email, rule));
|
|
160
|
+
return matched ? { matched: true, rule: matched } : { matched: false };
|
|
161
|
+
}
|
|
162
|
+
static emailMatchesRule(email, rule) {
|
|
163
|
+
const { match } = rule;
|
|
164
|
+
const fromAddr = email.meta.from.address;
|
|
165
|
+
const fromFull = email.meta.from.name ? `${email.meta.from.name} <${fromAddr}>` : fromAddr;
|
|
166
|
+
const toAddrs = email.meta.to.map((t) => t.address).join(', ');
|
|
167
|
+
const { subject } = email.meta;
|
|
168
|
+
// All specified match conditions must pass (AND logic)
|
|
169
|
+
if (match.from &&
|
|
170
|
+
!matchesPattern(match.from, fromAddr) &&
|
|
171
|
+
!matchesPattern(match.from, fromFull)) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
if (match.to && !matchesPattern(match.to, toAddrs)) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
if (match.subject && !matchesPattern(match.subject, subject)) {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
// At least one match condition must be specified
|
|
181
|
+
return Boolean(match.from ?? match.to ?? match.subject);
|
|
182
|
+
}
|
|
183
|
+
async applyStaticRule(email, rule) {
|
|
184
|
+
const { actions } = rule;
|
|
185
|
+
// Apply labels
|
|
186
|
+
if (actions.labels?.length) {
|
|
187
|
+
const labelOps = actions.labels.map(async (label) => {
|
|
188
|
+
try {
|
|
189
|
+
await this.imapService.addLabel(email.account, email.meta.id, email.mailbox, label);
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
await mcpLog('warning', 'hooks', `Could not add label "${label}" to email ${email.meta.id}`);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
await Promise.allSettled(labelOps);
|
|
196
|
+
}
|
|
197
|
+
// Apply flag
|
|
198
|
+
if (actions.flag) {
|
|
199
|
+
try {
|
|
200
|
+
await this.imapService.setFlags(email.account, email.mailbox, email.meta.id, 'flag');
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
await mcpLog('warning', 'hooks', `Could not flag email ${email.meta.id}`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// Mark read
|
|
207
|
+
if (actions.markRead) {
|
|
208
|
+
try {
|
|
209
|
+
await this.imapService.setFlags(email.account, email.mailbox, email.meta.id, 'read');
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
await mcpLog('warning', 'hooks', `Could not mark email ${email.meta.id} as read`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// Send alert via notifier (rule with alert=true forces desktop notification)
|
|
216
|
+
const payload = {
|
|
217
|
+
account: email.account,
|
|
218
|
+
sender: email.meta.from,
|
|
219
|
+
subject: email.meta.subject,
|
|
220
|
+
priority: actions.flag ? 'high' : 'normal',
|
|
221
|
+
labels: actions.labels,
|
|
222
|
+
ruleName: rule.name,
|
|
223
|
+
uid: email.meta.id,
|
|
224
|
+
folder: email.mailbox,
|
|
225
|
+
hasAttachments: email.meta.hasAttachments,
|
|
226
|
+
};
|
|
227
|
+
await this.notifier.alert(payload, actions.alert === true);
|
|
228
|
+
// Add to calendar if rule requests it or global auto_calendar is on
|
|
229
|
+
if (actions.addToCalendar ?? this.config.autoCalendar) {
|
|
230
|
+
const { isCalendarProcessed, markCalendarProcessed } = await import('../utils/calendar-state.js');
|
|
231
|
+
const already = await isCalendarProcessed(email.account, email.meta.id);
|
|
232
|
+
if (!already) {
|
|
233
|
+
await this.applyCalendarAction(email);
|
|
234
|
+
await markCalendarProcessed(email.account, email.meta.id, 'event', email.meta.subject);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
await mcpLog('info', 'hooks', `Calendar: skipping auto-add for ${email.meta.id} (already processed once)`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// -------------------------------------------------------------------------
|
|
242
|
+
// Resource subscription notifications
|
|
243
|
+
// -------------------------------------------------------------------------
|
|
244
|
+
async sendResourceUpdates(emails) {
|
|
245
|
+
if (!this.lowLevelServer)
|
|
246
|
+
return;
|
|
247
|
+
const accounts = [...new Set(emails.map((e) => e.account))];
|
|
248
|
+
const srv = this.lowLevelServer;
|
|
249
|
+
const ops = accounts.flatMap((account) => [
|
|
250
|
+
srv.sendResourceUpdated({ uri: `email://${account}/unread` }).catch(() => { }),
|
|
251
|
+
srv.sendResourceUpdated({ uri: `email://${account}/mailboxes` }).catch(() => { }),
|
|
252
|
+
]);
|
|
253
|
+
await Promise.allSettled(ops);
|
|
254
|
+
}
|
|
255
|
+
// -------------------------------------------------------------------------
|
|
256
|
+
// Notify mode (alerts-aware fallback)
|
|
257
|
+
// -------------------------------------------------------------------------
|
|
258
|
+
async notifyBatch(emails) {
|
|
259
|
+
const ops = emails.map(async (e) => {
|
|
260
|
+
const payload = {
|
|
261
|
+
account: e.account,
|
|
262
|
+
sender: e.meta.from,
|
|
263
|
+
subject: e.meta.subject,
|
|
264
|
+
priority: 'normal',
|
|
265
|
+
uid: e.meta.id,
|
|
266
|
+
folder: e.mailbox,
|
|
267
|
+
hasAttachments: e.meta.hasAttachments,
|
|
268
|
+
};
|
|
269
|
+
return this.notifier.alert(payload);
|
|
270
|
+
});
|
|
271
|
+
await Promise.allSettled(ops);
|
|
272
|
+
}
|
|
273
|
+
// -------------------------------------------------------------------------
|
|
274
|
+
// Triage mode (AI sampling with preset prompts)
|
|
275
|
+
// -------------------------------------------------------------------------
|
|
276
|
+
async triageBatch(emails) {
|
|
277
|
+
if (this.rateCounter >= HooksService.MAX_SAMPLING_PER_MIN) {
|
|
278
|
+
await mcpLog('warning', 'hooks', 'Sampling rate limit reached — falling back to notify');
|
|
279
|
+
await this.notifyBatch(emails);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
// Skip AI for notification-only preset
|
|
283
|
+
if (this.config.preset === 'notification-only' || !this.resolvedSystemPrompt) {
|
|
284
|
+
await this.notifyBatch(emails);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
this.rateCounter += 1;
|
|
288
|
+
const emailSummaries = emails.map((e, i) => HooksService.formatEmailSummary(e, i)).join('\n\n');
|
|
289
|
+
const userPrompt = `Analyze these ${emails.length} new email(s):\n\n${emailSummaries}`;
|
|
290
|
+
try {
|
|
291
|
+
const srv = this.lowLevelServer;
|
|
292
|
+
if (!srv)
|
|
293
|
+
throw new Error('Server not available');
|
|
294
|
+
const result = await srv.createMessage({
|
|
295
|
+
messages: [{ role: 'user', content: { type: 'text', text: userPrompt } }],
|
|
296
|
+
systemPrompt: this.resolvedSystemPrompt,
|
|
297
|
+
maxTokens: 1000,
|
|
298
|
+
modelPreferences: {
|
|
299
|
+
hints: [{ name: 'fast' }],
|
|
300
|
+
speedPriority: 0.8,
|
|
301
|
+
intelligencePriority: 0.5,
|
|
302
|
+
},
|
|
303
|
+
});
|
|
304
|
+
const text = result.model && result.content?.type === 'text' ? result.content.text : '';
|
|
305
|
+
const triageResults = HooksService.parseTriageResponse(text, emails.length);
|
|
306
|
+
await this.applyTriageResults(emails, triageResults);
|
|
307
|
+
}
|
|
308
|
+
catch (err) {
|
|
309
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
310
|
+
await mcpLog('warning', 'hooks', `Sampling failed: ${errMsg} — falling back to notify`);
|
|
311
|
+
await this.notifyBatch(emails);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
static formatEmailSummary(e, index) {
|
|
315
|
+
const flagIcons = [
|
|
316
|
+
e.meta.flagged ? '⭐' : '',
|
|
317
|
+
e.meta.seen ? '👁️' : '🆕',
|
|
318
|
+
e.meta.hasAttachments ? '📎' : '',
|
|
319
|
+
].join('');
|
|
320
|
+
return (`[${index + 1}] From: ${e.meta.from.name ?? e.meta.from.address}\n` +
|
|
321
|
+
` Subject: ${e.meta.subject}\n` +
|
|
322
|
+
` Date: ${e.meta.date}\n` +
|
|
323
|
+
` Flags: ${flagIcons}`);
|
|
324
|
+
}
|
|
325
|
+
// -------------------------------------------------------------------------
|
|
326
|
+
// Triage application
|
|
327
|
+
// -------------------------------------------------------------------------
|
|
328
|
+
async applyTriageResults(emails, results) {
|
|
329
|
+
const ops = emails.map(async (email, i) => this.applySingleTriage(email, results[i] ?? {}));
|
|
330
|
+
await Promise.allSettled(ops);
|
|
331
|
+
}
|
|
332
|
+
async applySingleTriage(email, triage) {
|
|
333
|
+
// Auto-label
|
|
334
|
+
if (this.config.autoLabel && triage.labels?.length) {
|
|
335
|
+
const labelOps = triage.labels.map(async (label) => {
|
|
336
|
+
try {
|
|
337
|
+
await this.imapService.addLabel(email.account, email.meta.id, email.mailbox, label);
|
|
338
|
+
}
|
|
339
|
+
catch {
|
|
340
|
+
await mcpLog('warning', 'hooks', `Could not add label "${label}" to email ${email.meta.id}`);
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
await Promise.allSettled(labelOps);
|
|
344
|
+
}
|
|
345
|
+
// Auto-flag
|
|
346
|
+
if (this.config.autoFlag && triage.flag) {
|
|
347
|
+
try {
|
|
348
|
+
await this.imapService.setFlags(email.account, email.mailbox, email.meta.id, 'flag');
|
|
349
|
+
}
|
|
350
|
+
catch {
|
|
351
|
+
await mcpLog('warning', 'hooks', `Could not flag email ${email.meta.id}`);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
// Route through notifier for urgency-based alerts
|
|
355
|
+
const priority = triage.priority ?? 'normal';
|
|
356
|
+
const payload = {
|
|
357
|
+
account: email.account,
|
|
358
|
+
sender: email.meta.from,
|
|
359
|
+
subject: email.meta.subject,
|
|
360
|
+
priority,
|
|
361
|
+
labels: triage.labels,
|
|
362
|
+
uid: email.meta.id,
|
|
363
|
+
folder: email.mailbox,
|
|
364
|
+
hasAttachments: email.meta.hasAttachments,
|
|
365
|
+
};
|
|
366
|
+
await this.notifier.alert(payload);
|
|
367
|
+
if (triage.action) {
|
|
368
|
+
await mcpLog('info', 'hooks', ` Action: ${triage.action}`);
|
|
369
|
+
}
|
|
370
|
+
// Add to calendar if AI triage requested it or global auto_calendar is on
|
|
371
|
+
if (triage.addToCalendar ?? this.config.autoCalendar) {
|
|
372
|
+
const { isCalendarProcessed, markCalendarProcessed } = await import('../utils/calendar-state.js');
|
|
373
|
+
const already = await isCalendarProcessed(email.account, email.meta.id);
|
|
374
|
+
if (!already) {
|
|
375
|
+
await this.applyCalendarAction(email);
|
|
376
|
+
await markCalendarProcessed(email.account, email.meta.id, 'event', email.meta.subject);
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
await mcpLog('info', 'hooks', `Calendar: skipping auto-add for ${email.meta.id} (already processed once — instruct AI to add again)`);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
// -------------------------------------------------------------------------
|
|
384
|
+
// Calendar auto-add helper
|
|
385
|
+
// -------------------------------------------------------------------------
|
|
386
|
+
async applyCalendarAction(email) {
|
|
387
|
+
const { buildCalendarNotes } = await import('../utils/calendar-notes.js');
|
|
388
|
+
const { extractConferenceDetails } = await import('../utils/conference-details.js');
|
|
389
|
+
const { extractMeetingUrl } = await import('../utils/meeting-url.js');
|
|
390
|
+
const { CALENDAR_ATTACHMENTS_DIR } = await import('../config/xdg.js');
|
|
391
|
+
const path = await import('node:path');
|
|
392
|
+
try {
|
|
393
|
+
const full = await this.imapService.getEmail(email.account, email.meta.id, email.mailbox);
|
|
394
|
+
const bodyText = full.bodyText ?? '';
|
|
395
|
+
const bodyHtml = full.bodyHtml ?? '';
|
|
396
|
+
const combined = `${bodyText}\n${bodyHtml}`;
|
|
397
|
+
// Try ICS extraction
|
|
398
|
+
let start = new Date(full.date);
|
|
399
|
+
let end = new Date(start.getTime() + 60 * 60 * 1000);
|
|
400
|
+
let location;
|
|
401
|
+
let icsUid;
|
|
402
|
+
try {
|
|
403
|
+
const { default: CalSvc } = await import('./calendar.service.js');
|
|
404
|
+
const calSvc = new CalSvc();
|
|
405
|
+
const icsContents = await this.imapService.getCalendarParts(email.account, email.mailbox, email.meta.id);
|
|
406
|
+
if (icsContents.length > 0) {
|
|
407
|
+
const events = calSvc.extractFromParts(icsContents);
|
|
408
|
+
if (events.length > 0) {
|
|
409
|
+
start = new Date(events[0].start);
|
|
410
|
+
end = new Date(events[0].end);
|
|
411
|
+
location = events[0].location;
|
|
412
|
+
icsUid = events[0].uid;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
catch {
|
|
417
|
+
// ICS extraction is best-effort
|
|
418
|
+
}
|
|
419
|
+
const meetingUrl = extractMeetingUrl(combined);
|
|
420
|
+
const conference = extractConferenceDetails(bodyText !== '' ? bodyText : bodyHtml);
|
|
421
|
+
// Save attachments
|
|
422
|
+
let savedAttachments = [];
|
|
423
|
+
if (full.attachments.length > 0) {
|
|
424
|
+
const destDir = path.join(CALENDAR_ATTACHMENTS_DIR, `${email.account}-${email.meta.id}`.replace(/[^a-zA-Z0-9-_]/g, '_'));
|
|
425
|
+
savedAttachments = await this.imapService.saveEmailAttachments(email.account, email.meta.id, email.mailbox, destDir);
|
|
426
|
+
}
|
|
427
|
+
const notes = buildCalendarNotes({
|
|
428
|
+
emailFrom: full.from.name ? `${full.from.name} <${full.from.address}>` : full.from.address,
|
|
429
|
+
emailSubject: full.subject,
|
|
430
|
+
emailDate: new Date(full.date).toLocaleString(),
|
|
431
|
+
meetingUrl: meetingUrl?.url,
|
|
432
|
+
meetingUrlLabel: meetingUrl?.label,
|
|
433
|
+
dialIn: conference?.dialIn,
|
|
434
|
+
meetingId: conference?.meetingId,
|
|
435
|
+
passcode: conference?.passcode,
|
|
436
|
+
conferenceProvider: conference?.provider,
|
|
437
|
+
bodyExcerpt: bodyText !== '' ? bodyText : bodyHtml,
|
|
438
|
+
savedAttachments,
|
|
439
|
+
});
|
|
440
|
+
const result = await this.localCalendar.addEvent({
|
|
441
|
+
title: full.subject,
|
|
442
|
+
start,
|
|
443
|
+
end,
|
|
444
|
+
location,
|
|
445
|
+
notes,
|
|
446
|
+
url: meetingUrl?.url,
|
|
447
|
+
urlLabel: meetingUrl?.label,
|
|
448
|
+
alarmMinutes: this.config.calendarAlarmMinutes ?? 15,
|
|
449
|
+
savedAttachments,
|
|
450
|
+
dialIn: conference?.dialIn,
|
|
451
|
+
meetingId: conference?.meetingId,
|
|
452
|
+
passcode: conference?.passcode,
|
|
453
|
+
icsUid,
|
|
454
|
+
}, this.config.calendarName !== '' ? this.config.calendarName : undefined, { confirm: this.config.calendarConfirm !== false });
|
|
455
|
+
await mcpLog('info', 'hooks', `Calendar: ${result.message}`);
|
|
456
|
+
}
|
|
457
|
+
catch (err) {
|
|
458
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
459
|
+
await mcpLog('warning', 'hooks', `Calendar auto-add failed: ${msg}`);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
// -------------------------------------------------------------------------
|
|
463
|
+
// Response parsing
|
|
464
|
+
// -------------------------------------------------------------------------
|
|
465
|
+
static parseTriageResponse(text, expectedCount) {
|
|
466
|
+
try {
|
|
467
|
+
const cleaned = text.replace(/```(?:json)?\n?/g, '').trim();
|
|
468
|
+
const parsed = JSON.parse(cleaned);
|
|
469
|
+
if (Array.isArray(parsed)) {
|
|
470
|
+
return parsed.slice(0, expectedCount).map(HooksService.sanitizeTriageResult);
|
|
471
|
+
}
|
|
472
|
+
if (typeof parsed === 'object' && parsed !== null) {
|
|
473
|
+
return [HooksService.sanitizeTriageResult(parsed)];
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
catch {
|
|
477
|
+
// Parse failure — return empty results
|
|
478
|
+
}
|
|
479
|
+
return Array.from({ length: expectedCount }, () => ({}));
|
|
480
|
+
}
|
|
481
|
+
static sanitizeTriageResult(raw) {
|
|
482
|
+
if (typeof raw !== 'object' || raw === null)
|
|
483
|
+
return {};
|
|
484
|
+
const obj = raw;
|
|
485
|
+
return {
|
|
486
|
+
priority: ['urgent', 'high', 'normal', 'low'].includes(obj.priority)
|
|
487
|
+
? obj.priority
|
|
488
|
+
: undefined,
|
|
489
|
+
labels: Array.isArray(obj.labels)
|
|
490
|
+
? obj.labels.filter((l) => typeof l === 'string').slice(0, 5)
|
|
491
|
+
: undefined,
|
|
492
|
+
flag: typeof obj.flag === 'boolean' ? obj.flag : undefined,
|
|
493
|
+
action: typeof obj.action === 'string' ? obj.action.slice(0, 200) : undefined,
|
|
494
|
+
addToCalendar: typeof obj.add_to_calendar === 'boolean' ? obj.add_to_calendar : undefined,
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
//# sourceMappingURL=hooks.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.service.js","sourceRoot":"","sources":["../../src/services/hooks.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAGvC,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAEtC,OAAO,oBAAoB,MAAM,6BAA6B,CAAC;AAE/D,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AA+BjD,8EAA8E;AAC9E,2BAA2B;AAC3B,8EAA8E;AAE9E,+E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CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS;YAC7E,aAAa,EAAE,OAAO,GAAG,CAAC,eAAe,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS;SAC1F,CAAC;IACJ,CAAC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IMAP service — pure business logic for email read operations.
|
|
3
|
+
*
|
|
4
|
+
* No MCP dependency — fully unit-testable.
|
|
5
|
+
*/
|
|
6
|
+
import type { IConnectionManager } from '../connections/types.js';
|
|
7
|
+
import type { BulkResult, Contact, Email, EmailAddress, EmailMeta, EmailStats, LabelInfo, Mailbox, PaginatedResult, QuotaInfo } from '../types/index.js';
|
|
8
|
+
export default class ImapService {
|
|
9
|
+
private connections;
|
|
10
|
+
private labelStrategies;
|
|
11
|
+
private labelStrategyPending;
|
|
12
|
+
constructor(connections: IConnectionManager);
|
|
13
|
+
private getLabelStrategy;
|
|
14
|
+
listMailboxes(accountName: string): Promise<Mailbox[]>;
|
|
15
|
+
listEmails(accountName: string, options?: {
|
|
16
|
+
mailbox?: string;
|
|
17
|
+
page?: number;
|
|
18
|
+
pageSize?: number;
|
|
19
|
+
since?: string;
|
|
20
|
+
before?: string;
|
|
21
|
+
from?: string;
|
|
22
|
+
subject?: string;
|
|
23
|
+
seen?: boolean;
|
|
24
|
+
flagged?: boolean;
|
|
25
|
+
hasAttachment?: boolean;
|
|
26
|
+
answered?: boolean;
|
|
27
|
+
}): Promise<PaginatedResult<EmailMeta>>;
|
|
28
|
+
getEmail(accountName: string, emailId: string, mailbox?: string): Promise<Email>;
|
|
29
|
+
getEmailFlags(accountName: string, emailId: string, mailbox?: string): Promise<{
|
|
30
|
+
seen: boolean;
|
|
31
|
+
flagged: boolean;
|
|
32
|
+
answered: boolean;
|
|
33
|
+
labels: string[];
|
|
34
|
+
subject: string;
|
|
35
|
+
from: string;
|
|
36
|
+
date: string;
|
|
37
|
+
}>;
|
|
38
|
+
searchEmails(accountName: string, query: string, options?: {
|
|
39
|
+
mailbox?: string;
|
|
40
|
+
page?: number;
|
|
41
|
+
pageSize?: number;
|
|
42
|
+
to?: string;
|
|
43
|
+
hasAttachment?: boolean;
|
|
44
|
+
largerThan?: number;
|
|
45
|
+
smallerThan?: number;
|
|
46
|
+
answered?: boolean;
|
|
47
|
+
}): Promise<PaginatedResult<EmailMeta>>;
|
|
48
|
+
listLabels(accountName: string): Promise<LabelInfo[]>;
|
|
49
|
+
addLabel(accountName: string, emailId: string, mailbox: string, label: string): Promise<void>;
|
|
50
|
+
removeLabel(accountName: string, emailId: string, mailbox: string, label: string): Promise<void>;
|
|
51
|
+
createLabel(accountName: string, name: string): Promise<void>;
|
|
52
|
+
deleteLabel(accountName: string, name: string): Promise<void>;
|
|
53
|
+
private static readonly VIRTUAL_SPECIAL_USE;
|
|
54
|
+
private static assertRealMailbox;
|
|
55
|
+
findEmailFolder(accountName: string, emailId: string, sourceMailbox: string): Promise<{
|
|
56
|
+
folders: string[];
|
|
57
|
+
messageId?: string;
|
|
58
|
+
}>;
|
|
59
|
+
moveEmail(accountName: string, emailId: string, sourceMailbox: string, destinationMailbox: string): Promise<void>;
|
|
60
|
+
deleteEmail(accountName: string, emailId: string, mailbox?: string, permanent?: boolean): Promise<void>;
|
|
61
|
+
setFlags(accountName: string, emailId: string, mailbox: string, action: 'read' | 'unread' | 'flag' | 'unflag'): Promise<void>;
|
|
62
|
+
bulkSetFlags(accountName: string, ids: number[], mailbox: string, action: 'mark_read' | 'mark_unread' | 'flag' | 'unflag'): Promise<BulkResult>;
|
|
63
|
+
bulkMove(accountName: string, ids: number[], mailbox: string, destination: string): Promise<BulkResult>;
|
|
64
|
+
bulkDelete(accountName: string, ids: number[], mailbox: string, permanent?: boolean): Promise<BulkResult>;
|
|
65
|
+
saveDraft(accountName: string, options: {
|
|
66
|
+
to: string[];
|
|
67
|
+
subject: string;
|
|
68
|
+
body: string;
|
|
69
|
+
cc?: string[];
|
|
70
|
+
bcc?: string[];
|
|
71
|
+
html?: boolean;
|
|
72
|
+
inReplyTo?: string;
|
|
73
|
+
}): Promise<{
|
|
74
|
+
id: number;
|
|
75
|
+
mailbox: string;
|
|
76
|
+
}>;
|
|
77
|
+
/**
|
|
78
|
+
* Fetch a draft message for sending.
|
|
79
|
+
* Returns the parsed draft with recipients and content.
|
|
80
|
+
*/
|
|
81
|
+
fetchDraft(accountName: string, emailId: number, mailbox?: string): Promise<{
|
|
82
|
+
email: Email;
|
|
83
|
+
mailbox: string;
|
|
84
|
+
}>;
|
|
85
|
+
/** Delete a draft after it has been sent. */
|
|
86
|
+
deleteDraft(accountName: string, emailId: number, mailbox: string): Promise<void>;
|
|
87
|
+
createMailbox(accountName: string, folderPath: string): Promise<void>;
|
|
88
|
+
renameMailbox(accountName: string, folderPath: string, newPath: string): Promise<void>;
|
|
89
|
+
deleteMailbox(accountName: string, folderPath: string): Promise<void>;
|
|
90
|
+
downloadAttachment(accountName: string, emailId: string, mailbox: string, filename: string, maxSizeBytes?: number): Promise<{
|
|
91
|
+
filename: string;
|
|
92
|
+
mimeType: string;
|
|
93
|
+
size: number;
|
|
94
|
+
contentBase64: string;
|
|
95
|
+
}>;
|
|
96
|
+
/**
|
|
97
|
+
* Download and save all non-ICS attachments from an email to a local directory.
|
|
98
|
+
* Returns metadata including the saved file paths and file:// URLs.
|
|
99
|
+
*
|
|
100
|
+
* Attachments larger than maxSizeBytes (default 25 MB) are skipped.
|
|
101
|
+
*/
|
|
102
|
+
saveEmailAttachments(accountName: string, emailId: string, mailbox: string, destDir: string, maxSizeBytes?: number): Promise<{
|
|
103
|
+
filename: string;
|
|
104
|
+
localPath: string;
|
|
105
|
+
fileUrl: string;
|
|
106
|
+
mimeType: string;
|
|
107
|
+
size: number;
|
|
108
|
+
}[]>;
|
|
109
|
+
/**
|
|
110
|
+
* Reconstruct an email thread by following References / In-Reply-To chains.
|
|
111
|
+
* Searches by Message-ID header for each reference and returns messages in
|
|
112
|
+
* chronological order. Caps at MAX_THREAD_MESSAGES to prevent runaway chains.
|
|
113
|
+
*/
|
|
114
|
+
getThread(accountName: string, messageId: string, mailbox?: string): Promise<{
|
|
115
|
+
threadId: string;
|
|
116
|
+
messages: Email[];
|
|
117
|
+
participants: EmailAddress[];
|
|
118
|
+
messageCount: number;
|
|
119
|
+
}>;
|
|
120
|
+
extractContacts(accountName: string, options?: {
|
|
121
|
+
mailbox?: string;
|
|
122
|
+
limit?: number;
|
|
123
|
+
}): Promise<Contact[]>;
|
|
124
|
+
getEmailStats(accountName: string, mailbox: string, period: 'day' | 'week' | 'month'): Promise<EmailStats>;
|
|
125
|
+
getQuota(accountName: string): Promise<QuotaInfo | null>;
|
|
126
|
+
getCapabilities(accountName: string): Promise<string[]>;
|
|
127
|
+
getCalendarParts(accountName: string, mailbox: string, emailId: string): Promise<string[]>;
|
|
128
|
+
/**
|
|
129
|
+
* Recursively find body parts with text/calendar content type.
|
|
130
|
+
*/
|
|
131
|
+
private findCalendarParts;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=imap.service.d.ts.map
|