@mysterycode-liwen/dsh-mail 1.0.1 → 1.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 +21 -21
- package/README.md +238 -136
- package/bridge.py +1257 -1019
- package/client.js +991 -174
- package/cordis.patch.yml +8 -8
- package/docs/DETAIL.md +1 -1
- package/docs/DETAIL.zh.md +1 -0
- package/docs/preview.svg +50 -20
- package/icon.svg +3 -3
- package/index.js +497 -358
- package/locale/en.json +1 -1
- package/locale/zh.json +2 -2
- package/package.json +64 -64
- package/tools.js +158 -158
package/locale/en.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Mail",
|
|
4
|
-
"description": "Send and receive email from QQ, 163, Gmail and other IMAP/SMTP accounts.",
|
|
4
|
+
"description": "Send and receive email from QQ, 163, Gmail and other IMAP/SMTP accounts, with attachments, an unread badge, read/unread filters, and new-mail alerts via a desktop pet or system notification. Credentials stay in the local vault.",
|
|
5
5
|
"detail": "docs/DETAIL.md"
|
|
6
6
|
},
|
|
7
7
|
"ui": {
|
package/locale/zh.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "邮件",
|
|
4
|
-
"description": "通过 QQ、163、Gmail 等 IMAP/SMTP
|
|
5
|
-
"detail": "docs/DETAIL.md"
|
|
4
|
+
"description": "通过 QQ、163、Gmail 等 IMAP/SMTP 邮箱收发邮件,支持附件、未读角标与已读/未读筛选、新邮件提醒(桌宠播报或系统通知),授权码保存在本机凭据保险箱。",
|
|
5
|
+
"detail": "docs/DETAIL.zh.md"
|
|
6
6
|
},
|
|
7
7
|
"ui": {
|
|
8
8
|
"label": "邮件",
|
package/package.json
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@mysterycode-liwen/dsh-mail",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"private": false,
|
|
5
|
-
"type": "module",
|
|
6
|
-
"description": "DeepSeek Harness 侧边栏邮件插件:在左侧栏收发 QQ / 163 / Gmail 等邮箱,IMAP 收信 + SMTP
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"author": "李文 <59386344+mysterycode-liwen@users.noreply.github.com>",
|
|
9
|
-
"homepage": "https://github.com/mysterycode-liwen/dsh-email#readme",
|
|
10
|
-
"keywords": [
|
|
11
|
-
"dsh-plugin",
|
|
12
|
-
"dsh",
|
|
13
|
-
"deepseek-harness",
|
|
14
|
-
"email",
|
|
15
|
-
"mail",
|
|
16
|
-
"imap",
|
|
17
|
-
"smtp",
|
|
18
|
-
"qq-mail"
|
|
19
|
-
],
|
|
20
|
-
"repository": {
|
|
21
|
-
"type": "git",
|
|
22
|
-
"url": "git+https://github.com/mysterycode-liwen/dsh-email.git"
|
|
23
|
-
},
|
|
24
|
-
"bugs": {
|
|
25
|
-
"url": "https://github.com/mysterycode-liwen/dsh-email/issues"
|
|
26
|
-
},
|
|
27
|
-
"publishConfig": {
|
|
28
|
-
"access": "public"
|
|
29
|
-
},
|
|
30
|
-
"exports": {
|
|
31
|
-
".": "./index.js",
|
|
32
|
-
"./tools": "./tools.js",
|
|
33
|
-
"./client": "./client.js",
|
|
34
|
-
"./bridge.py": "./bridge.py",
|
|
35
|
-
"./locale/*.json": "./locale/*.json",
|
|
36
|
-
"./icon": "./icon.svg"
|
|
37
|
-
},
|
|
38
|
-
"files": [
|
|
39
|
-
"index.js",
|
|
40
|
-
"tools.js",
|
|
41
|
-
"client.js",
|
|
42
|
-
"bridge.py",
|
|
43
|
-
"cordis.patch.yml",
|
|
44
|
-
"locale/*.json",
|
|
45
|
-
"docs",
|
|
46
|
-
"icon.svg",
|
|
47
|
-
"README.md",
|
|
48
|
-
"LICENSE"
|
|
49
|
-
],
|
|
50
|
-
"dsh": {
|
|
51
|
-
"bundle": {
|
|
52
|
-
"patch": "./cordis.patch.yml"
|
|
53
|
-
},
|
|
54
|
-
"client": {
|
|
55
|
-
"platform": "web",
|
|
56
|
-
"immediately": true,
|
|
57
|
-
"inject": []
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
"scripts": {
|
|
61
|
-
"check": "node scripts/check-package.mjs",
|
|
62
|
-
"prepublishOnly": "node scripts/check-package.mjs"
|
|
63
|
-
}
|
|
64
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@mysterycode-liwen/dsh-mail",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "DeepSeek Harness 侧边栏邮件插件:在左侧栏收发 QQ / 163 / Gmail 等邮箱,IMAP 收信 + SMTP 发信,支持附件、未读角标与已读/未读筛选、新邮件提醒、一键翻译邮件正文,授权码保存在本机凭据保险箱。",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "李文 <59386344+mysterycode-liwen@users.noreply.github.com>",
|
|
9
|
+
"homepage": "https://github.com/mysterycode-liwen/dsh-email#readme",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"dsh-plugin",
|
|
12
|
+
"dsh",
|
|
13
|
+
"deepseek-harness",
|
|
14
|
+
"email",
|
|
15
|
+
"mail",
|
|
16
|
+
"imap",
|
|
17
|
+
"smtp",
|
|
18
|
+
"qq-mail"
|
|
19
|
+
],
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/mysterycode-liwen/dsh-email.git"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/mysterycode-liwen/dsh-email/issues"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"exports": {
|
|
31
|
+
".": "./index.js",
|
|
32
|
+
"./tools": "./tools.js",
|
|
33
|
+
"./client": "./client.js",
|
|
34
|
+
"./bridge.py": "./bridge.py",
|
|
35
|
+
"./locale/*.json": "./locale/*.json",
|
|
36
|
+
"./icon": "./icon.svg"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"index.js",
|
|
40
|
+
"tools.js",
|
|
41
|
+
"client.js",
|
|
42
|
+
"bridge.py",
|
|
43
|
+
"cordis.patch.yml",
|
|
44
|
+
"locale/*.json",
|
|
45
|
+
"docs",
|
|
46
|
+
"icon.svg",
|
|
47
|
+
"README.md",
|
|
48
|
+
"LICENSE"
|
|
49
|
+
],
|
|
50
|
+
"dsh": {
|
|
51
|
+
"bundle": {
|
|
52
|
+
"patch": "./cordis.patch.yml"
|
|
53
|
+
},
|
|
54
|
+
"client": {
|
|
55
|
+
"platform": "web",
|
|
56
|
+
"immediately": true,
|
|
57
|
+
"inject": []
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"check": "node scripts/check-package.mjs",
|
|
62
|
+
"prepublishOnly": "node scripts/check-package.mjs"
|
|
63
|
+
}
|
|
64
|
+
}
|
package/tools.js
CHANGED
|
@@ -1,158 +1,158 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Model-facing mailbox query tool.
|
|
3
|
-
*
|
|
4
|
-
* This tool is intentionally READ-ONLY: it never sends, deletes, or changes
|
|
5
|
-
* mail, and it never exposes credentials (auth codes, passwords). Every call
|
|
6
|
-
* is gated by the `agentMailAccess` setting — when off, the tool returns an
|
|
7
|
-
* explicit "disabled" status and performs no mailbox access at all.
|
|
8
|
-
*
|
|
9
|
-
* All mailbox work is delegated to the plugin's existing request handler via a
|
|
10
|
-
* synthetic Request, so the agent and the sidebar UI share one code path.
|
|
11
|
-
*
|
|
12
|
-
* NOTE: The definition below uses raw JSON Schema directly (the subset that
|
|
13
|
-
* `ctx.tools.register` accepts). We deliberately avoid importing `defineTool`
|
|
14
|
-
* from `@deepseek-ai/dsh-tools` because that package pulls in a deep dependency
|
|
15
|
-
* chain (cordis, dsh-llm, dsh-scope, dsh-util-values, ...) that is not resolvable
|
|
16
|
-
* from a local-link plugin. `defineTool` is only a DSL-to-JSON-Schema converter;
|
|
17
|
-
* a plain ToolDefinition is registered identically.
|
|
18
|
-
*/
|
|
19
|
-
export function mailQueryTool(ctx, handleRequest, isEnabled) {
|
|
20
|
-
// Gate is asynchronous: the authoritative switch lives in the credential
|
|
21
|
-
// store (same source as the Settings UI), so we read it on every call through
|
|
22
|
-
// the provided predicate. No access is granted unless it returns true.
|
|
23
|
-
const gate = async () => (typeof isEnabled === 'function' && (await isEnabled()) === true);
|
|
24
|
-
|
|
25
|
-
function disabledValue() {
|
|
26
|
-
return {
|
|
27
|
-
status: 'disabled',
|
|
28
|
-
message: '邮箱查询未开启。请到插件设置中打开“允许 AI 助手查询邮箱内容”开关后再试。/ Mailbox query is disabled. Enable "Allow the AI assistant to query mailbox content" in the plugin settings first.',
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async function call(op, extra) {
|
|
33
|
-
const url = 'http://dsh-mail.local/api/dsh-mail?op=' + encodeURIComponent(op);
|
|
34
|
-
const request = new Request(url, {
|
|
35
|
-
method: 'POST',
|
|
36
|
-
headers: { 'content-type': 'application/json' },
|
|
37
|
-
body: JSON.stringify({ op, ...extra }),
|
|
38
|
-
});
|
|
39
|
-
const response = await handleRequest(ctx, request);
|
|
40
|
-
return response.json();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function render(_args, value) {
|
|
44
|
-
if (!value || typeof value !== 'object') {
|
|
45
|
-
return [{ type: 'text', text: String(value) }];
|
|
46
|
-
}
|
|
47
|
-
if (value.status === 'disabled' || value.status === 'error') {
|
|
48
|
-
return [{ type: 'text', text: value.message || String(value.status) }];
|
|
49
|
-
}
|
|
50
|
-
return [{ type: 'text', text: JSON.stringify(value, null, 2) }];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
name: 'mail_query',
|
|
55
|
-
description: 'Query the configured mailboxes (read-only). Requires the plugin setting "Allow the AI assistant to query mailbox content" to be enabled; otherwise returns a disabled status. Actions: list_accounts (list configured accounts; no secrets), list_messages (list recent messages in a folder), get_message (read one message by uid), sent_messages (recent sent mail). Never sends, deletes, or modifies mail and never returns passwords or authorization codes.',
|
|
56
|
-
parameters: {
|
|
57
|
-
type: 'object',
|
|
58
|
-
properties: {
|
|
59
|
-
action: {
|
|
60
|
-
type: 'string',
|
|
61
|
-
description: 'Query to run: list_accounts | list_messages | get_message | sent_messages.',
|
|
62
|
-
enum: ['list_accounts', 'list_messages', 'get_message', 'sent_messages'],
|
|
63
|
-
},
|
|
64
|
-
accountId: {
|
|
65
|
-
type: 'string',
|
|
66
|
-
description: 'Account id from list_accounts. Required for list_messages, get_message, and sent_messages.',
|
|
67
|
-
},
|
|
68
|
-
folder: {
|
|
69
|
-
type: 'string',
|
|
70
|
-
description: 'IMAP folder to read. Defaults to INBOX. Only used by list_messages and get_message.',
|
|
71
|
-
},
|
|
72
|
-
limit: {
|
|
73
|
-
type: 'integer',
|
|
74
|
-
description: 'Maximum number of messages to return (1-100). Defaults to 20. Only used by list_messages and sent_messages.',
|
|
75
|
-
},
|
|
76
|
-
uid: {
|
|
77
|
-
type: 'string',
|
|
78
|
-
description: 'Message uid to read, from list_messages. Required for get_message.',
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
required: ['action'],
|
|
82
|
-
},
|
|
83
|
-
output: {
|
|
84
|
-
schema: {
|
|
85
|
-
type: 'object',
|
|
86
|
-
properties: {
|
|
87
|
-
status: { type: 'string', description: 'disabled | error | ok' },
|
|
88
|
-
message: { type: 'string', description: 'Human-readable message when status is disabled or error.' },
|
|
89
|
-
data: { description: 'Query payload when status is ok.' },
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
render,
|
|
93
|
-
},
|
|
94
|
-
async execute(args, exec) {
|
|
95
|
-
if (!(await gate())) return disabledValue();
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
const a = args || {};
|
|
99
|
-
let data;
|
|
100
|
-
switch (a.action) {
|
|
101
|
-
case 'list_accounts': {
|
|
102
|
-
data = await call('listAccounts', {});
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
case 'list_messages': {
|
|
106
|
-
if (!a.accountId) {
|
|
107
|
-
return { status: 'error', message: 'accountId is required for list_messages.' };
|
|
108
|
-
}
|
|
109
|
-
const limit = Math.max(1, Math.min(100, Number(a.limit) || 20));
|
|
110
|
-
data = await call('listMessages', {
|
|
111
|
-
id: a.accountId,
|
|
112
|
-
folder: a.folder || 'INBOX',
|
|
113
|
-
limit,
|
|
114
|
-
});
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
case 'get_message': {
|
|
118
|
-
if (!a.accountId) {
|
|
119
|
-
return { status: 'error', message: 'accountId is required for get_message.' };
|
|
120
|
-
}
|
|
121
|
-
if (!a.uid) {
|
|
122
|
-
return { status: 'error', message: 'uid is required for get_message.' };
|
|
123
|
-
}
|
|
124
|
-
data = await call('getMessage', {
|
|
125
|
-
id: a.accountId,
|
|
126
|
-
uid: a.uid,
|
|
127
|
-
folder: a.folder || 'INBOX',
|
|
128
|
-
});
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
case 'sent_messages': {
|
|
132
|
-
if (!a.accountId) {
|
|
133
|
-
return { status: 'error', message: 'accountId is required for sent_messages.' };
|
|
134
|
-
}
|
|
135
|
-
data = await call('sentMessages', { id: a.accountId });
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
default:
|
|
139
|
-
return { status: 'error', message: 'Unknown action: ' + a.action };
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (!data || data.ok === false) {
|
|
143
|
-
const message = data && data.error ? String(data.error) : 'Mailbox query failed.';
|
|
144
|
-
return { status: 'error', message };
|
|
145
|
-
}
|
|
146
|
-
// Strip server envelope; keep only the payload the UI would receive.
|
|
147
|
-
const { ok, ...payload } = data;
|
|
148
|
-
return { status: 'ok', data: payload };
|
|
149
|
-
} catch (error) {
|
|
150
|
-
if (exec && exec.signal && exec.signal.aborted) throw error;
|
|
151
|
-
return {
|
|
152
|
-
status: 'error',
|
|
153
|
-
message: error instanceof Error ? error.message : String(error),
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
},
|
|
157
|
-
};
|
|
158
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing mailbox query tool.
|
|
3
|
+
*
|
|
4
|
+
* This tool is intentionally READ-ONLY: it never sends, deletes, or changes
|
|
5
|
+
* mail, and it never exposes credentials (auth codes, passwords). Every call
|
|
6
|
+
* is gated by the `agentMailAccess` setting — when off, the tool returns an
|
|
7
|
+
* explicit "disabled" status and performs no mailbox access at all.
|
|
8
|
+
*
|
|
9
|
+
* All mailbox work is delegated to the plugin's existing request handler via a
|
|
10
|
+
* synthetic Request, so the agent and the sidebar UI share one code path.
|
|
11
|
+
*
|
|
12
|
+
* NOTE: The definition below uses raw JSON Schema directly (the subset that
|
|
13
|
+
* `ctx.tools.register` accepts). We deliberately avoid importing `defineTool`
|
|
14
|
+
* from `@deepseek-ai/dsh-tools` because that package pulls in a deep dependency
|
|
15
|
+
* chain (cordis, dsh-llm, dsh-scope, dsh-util-values, ...) that is not resolvable
|
|
16
|
+
* from a local-link plugin. `defineTool` is only a DSL-to-JSON-Schema converter;
|
|
17
|
+
* a plain ToolDefinition is registered identically.
|
|
18
|
+
*/
|
|
19
|
+
export function mailQueryTool(ctx, handleRequest, isEnabled) {
|
|
20
|
+
// Gate is asynchronous: the authoritative switch lives in the credential
|
|
21
|
+
// store (same source as the Settings UI), so we read it on every call through
|
|
22
|
+
// the provided predicate. No access is granted unless it returns true.
|
|
23
|
+
const gate = async () => (typeof isEnabled === 'function' && (await isEnabled()) === true);
|
|
24
|
+
|
|
25
|
+
function disabledValue() {
|
|
26
|
+
return {
|
|
27
|
+
status: 'disabled',
|
|
28
|
+
message: '邮箱查询未开启。请到插件设置中打开“允许 AI 助手查询邮箱内容”开关后再试。/ Mailbox query is disabled. Enable "Allow the AI assistant to query mailbox content" in the plugin settings first.',
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function call(op, extra) {
|
|
33
|
+
const url = 'http://dsh-mail.local/api/dsh-mail?op=' + encodeURIComponent(op);
|
|
34
|
+
const request = new Request(url, {
|
|
35
|
+
method: 'POST',
|
|
36
|
+
headers: { 'content-type': 'application/json' },
|
|
37
|
+
body: JSON.stringify({ op, ...extra }),
|
|
38
|
+
});
|
|
39
|
+
const response = await handleRequest(ctx, request);
|
|
40
|
+
return response.json();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function render(_args, value) {
|
|
44
|
+
if (!value || typeof value !== 'object') {
|
|
45
|
+
return [{ type: 'text', text: String(value) }];
|
|
46
|
+
}
|
|
47
|
+
if (value.status === 'disabled' || value.status === 'error') {
|
|
48
|
+
return [{ type: 'text', text: value.message || String(value.status) }];
|
|
49
|
+
}
|
|
50
|
+
return [{ type: 'text', text: JSON.stringify(value, null, 2) }];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
name: 'mail_query',
|
|
55
|
+
description: 'Query the configured mailboxes (read-only). Requires the plugin setting "Allow the AI assistant to query mailbox content" to be enabled; otherwise returns a disabled status. Actions: list_accounts (list configured accounts; no secrets), list_messages (list recent messages in a folder), get_message (read one message by uid), sent_messages (recent sent mail). Never sends, deletes, or modifies mail and never returns passwords or authorization codes.',
|
|
56
|
+
parameters: {
|
|
57
|
+
type: 'object',
|
|
58
|
+
properties: {
|
|
59
|
+
action: {
|
|
60
|
+
type: 'string',
|
|
61
|
+
description: 'Query to run: list_accounts | list_messages | get_message | sent_messages.',
|
|
62
|
+
enum: ['list_accounts', 'list_messages', 'get_message', 'sent_messages'],
|
|
63
|
+
},
|
|
64
|
+
accountId: {
|
|
65
|
+
type: 'string',
|
|
66
|
+
description: 'Account id from list_accounts. Required for list_messages, get_message, and sent_messages.',
|
|
67
|
+
},
|
|
68
|
+
folder: {
|
|
69
|
+
type: 'string',
|
|
70
|
+
description: 'IMAP folder to read. Defaults to INBOX. Only used by list_messages and get_message.',
|
|
71
|
+
},
|
|
72
|
+
limit: {
|
|
73
|
+
type: 'integer',
|
|
74
|
+
description: 'Maximum number of messages to return (1-100). Defaults to 20. Only used by list_messages and sent_messages.',
|
|
75
|
+
},
|
|
76
|
+
uid: {
|
|
77
|
+
type: 'string',
|
|
78
|
+
description: 'Message uid to read, from list_messages. Required for get_message.',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
required: ['action'],
|
|
82
|
+
},
|
|
83
|
+
output: {
|
|
84
|
+
schema: {
|
|
85
|
+
type: 'object',
|
|
86
|
+
properties: {
|
|
87
|
+
status: { type: 'string', description: 'disabled | error | ok' },
|
|
88
|
+
message: { type: 'string', description: 'Human-readable message when status is disabled or error.' },
|
|
89
|
+
data: { description: 'Query payload when status is ok.' },
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
render,
|
|
93
|
+
},
|
|
94
|
+
async execute(args, exec) {
|
|
95
|
+
if (!(await gate())) return disabledValue();
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
const a = args || {};
|
|
99
|
+
let data;
|
|
100
|
+
switch (a.action) {
|
|
101
|
+
case 'list_accounts': {
|
|
102
|
+
data = await call('listAccounts', {});
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case 'list_messages': {
|
|
106
|
+
if (!a.accountId) {
|
|
107
|
+
return { status: 'error', message: 'accountId is required for list_messages.' };
|
|
108
|
+
}
|
|
109
|
+
const limit = Math.max(1, Math.min(100, Number(a.limit) || 20));
|
|
110
|
+
data = await call('listMessages', {
|
|
111
|
+
id: a.accountId,
|
|
112
|
+
folder: a.folder || 'INBOX',
|
|
113
|
+
limit,
|
|
114
|
+
});
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
case 'get_message': {
|
|
118
|
+
if (!a.accountId) {
|
|
119
|
+
return { status: 'error', message: 'accountId is required for get_message.' };
|
|
120
|
+
}
|
|
121
|
+
if (!a.uid) {
|
|
122
|
+
return { status: 'error', message: 'uid is required for get_message.' };
|
|
123
|
+
}
|
|
124
|
+
data = await call('getMessage', {
|
|
125
|
+
id: a.accountId,
|
|
126
|
+
uid: a.uid,
|
|
127
|
+
folder: a.folder || 'INBOX',
|
|
128
|
+
});
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
case 'sent_messages': {
|
|
132
|
+
if (!a.accountId) {
|
|
133
|
+
return { status: 'error', message: 'accountId is required for sent_messages.' };
|
|
134
|
+
}
|
|
135
|
+
data = await call('sentMessages', { id: a.accountId });
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
default:
|
|
139
|
+
return { status: 'error', message: 'Unknown action: ' + a.action };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (!data || data.ok === false) {
|
|
143
|
+
const message = data && data.error ? String(data.error) : 'Mailbox query failed.';
|
|
144
|
+
return { status: 'error', message };
|
|
145
|
+
}
|
|
146
|
+
// Strip server envelope; keep only the payload the UI would receive.
|
|
147
|
+
const { ok, ...payload } = data;
|
|
148
|
+
return { status: 'ok', data: payload };
|
|
149
|
+
} catch (error) {
|
|
150
|
+
if (exec && exec.signal && exec.signal.aborted) throw error;
|
|
151
|
+
return {
|
|
152
|
+
status: 'error',
|
|
153
|
+
message: error instanceof Error ? error.message : String(error),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
}
|