@mysterycode-liwen/dsh-mail 0.0.0-stage → 1.0.1
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 -0
- package/README.md +136 -3
- package/bridge.py +1019 -0
- package/client.js +1880 -0
- package/cordis.patch.yml +8 -0
- package/docs/DETAIL.md +1 -0
- package/docs/preview.svg +21 -0
- package/icon.svg +3 -0
- package/index.js +358 -0
- package/locale/en.json +53 -0
- package/locale/zh.json +53 -0
- package/package.json +64 -6
- package/tools.js +158 -0
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# dsh-mail bundle patch: installs the mail plugin row.
|
|
2
|
+
# agentMailAccess defaults to false; the row is replaced (not deep-merged) when
|
|
3
|
+
# edited here, and the browser Settings page can toggle the volatile field live.
|
|
4
|
+
- insert:
|
|
5
|
+
- id: dsh-mail
|
|
6
|
+
name: '@mysterycode-liwen/dsh-mail'
|
|
7
|
+
config:
|
|
8
|
+
agentMailAccess: false
|
package/docs/DETAIL.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+

|
package/docs/preview.svg
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 300" width="640" height="300" role="img" aria-label="Mail panel preview">
|
|
2
|
+
<rect width="640" height="300" fill="#f4f6fb"/>
|
|
3
|
+
<rect x="24" y="24" width="592" height="252" rx="12" fill="#ffffff" stroke="#d9dfeb"/>
|
|
4
|
+
<rect x="24" y="24" width="592" height="44" rx="12" fill="#eef3fc"/>
|
|
5
|
+
<circle cx="48" cy="46" r="6" fill="#3b82f6"/>
|
|
6
|
+
<text x="64" y="51" font-family="system-ui,sans-serif" font-size="16" font-weight="600" fill="#1f2a44">Mail</text>
|
|
7
|
+
<rect x="24" y="68" width="160" height="208" fill="#fafbfe"/>
|
|
8
|
+
<rect x="40" y="84" width="128" height="30" rx="6" fill="#e6edfb"/>
|
|
9
|
+
<text x="52" y="103" font-family="system-ui,sans-serif" font-size="12" fill="#3451a3">Accounts</text>
|
|
10
|
+
<rect x="40" y="124" width="128" height="30" rx="6" fill="#ffffff" stroke="#d9dfeb"/>
|
|
11
|
+
<text x="52" y="143" font-family="system-ui,sans-serif" font-size="12" fill="#1f2a44">Inbox</text>
|
|
12
|
+
<rect x="200" y="84" width="396" height="44" rx="8" fill="#ffffff" stroke="#d9dfeb"/>
|
|
13
|
+
<text x="214" y="111" font-family="system-ui,sans-serif" font-size="13" fill="#1f2a44">Project update</text>
|
|
14
|
+
<text x="214" y="126" font-family="system-ui,sans-serif" font-size="10" fill="#7b86a0">alice@example.com · today</text>
|
|
15
|
+
<rect x="200" y="136" width="396" height="44" rx="8" fill="#ffffff" stroke="#d9dfeb"/>
|
|
16
|
+
<text x="214" y="163" font-family="system-ui,sans-serif" font-size="13" fill="#1f2a44">Re: Meeting notes</text>
|
|
17
|
+
<text x="214" y="178" font-family="system-ui,sans-serif" font-size="10" fill="#7b86a0">bob@example.com · yesterday</text>
|
|
18
|
+
<rect x="200" y="188" width="396" height="72" rx="8" fill="#f8faff" stroke="#d9dfeb"/>
|
|
19
|
+
<rect x="528" y="200" width="56" height="24" rx="6" fill="#3b82f6"/>
|
|
20
|
+
<text x="540" y="216" font-family="system-ui,sans-serif" font-size="11" fill="#ffffff">Compose</text>
|
|
21
|
+
</svg>
|
package/icon.svg
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36" width="36" height="36">
|
|
2
|
+
<path fill="#3b82f6" d="M6 9h24a3 3 0 0 1 3 3v15a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3V12a3 3 0 0 1 3-3Zm0 3.2v.3l12 8.1 12-8.1v-.3a.8.8 0 0 0-.8-.8H6.8a.8.8 0 0 0-.8.8Zm23.6 3.6L18 22.3 6.4 15.8V27a.8.8 0 0 0 .8.8h21.6a.8.8 0 0 0 .8-.8V15.8Z"/>
|
|
3
|
+
</svg>
|
package/index.js
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { existsSync } from 'node:fs';
|
|
5
|
+
|
|
6
|
+
const execFileAsync = promisify(execFile);
|
|
7
|
+
const BRIDGE_PATH = fileURLToPath(new URL('./bridge.py', import.meta.url));
|
|
8
|
+
|
|
9
|
+
export const inject = ['connection', 'credentials', 'tools'];
|
|
10
|
+
|
|
11
|
+
import { mailQueryTool } from './tools.js';
|
|
12
|
+
|
|
13
|
+
const API = '/api/dsh-mail';
|
|
14
|
+
|
|
15
|
+
function candidatePythons() {
|
|
16
|
+
return [
|
|
17
|
+
process.env.MAIL_PYTHON,
|
|
18
|
+
'C:\\Python314\\python.exe',
|
|
19
|
+
'C:\\Python313\\python.exe',
|
|
20
|
+
'C:\\Python312\\python.exe',
|
|
21
|
+
'C:\\Python311\\python.exe',
|
|
22
|
+
'C:\\Python310\\python.exe',
|
|
23
|
+
'python',
|
|
24
|
+
].filter(Boolean);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function findPython() {
|
|
28
|
+
for (const candidate of candidatePythons()) {
|
|
29
|
+
if (candidate === 'python' || existsSync(candidate)) return candidate;
|
|
30
|
+
}
|
|
31
|
+
return 'python';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function runBridge(op, extra = {}) {
|
|
35
|
+
const request = JSON.stringify({ op, ...extra });
|
|
36
|
+
const { stdout } = await execFileAsync(findPython(), [BRIDGE_PATH], {
|
|
37
|
+
env: { ...process.env, MAIL_REQUEST: request },
|
|
38
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
39
|
+
timeout: 90000,
|
|
40
|
+
});
|
|
41
|
+
const text = String(stdout).trim();
|
|
42
|
+
if (!text) return { ok: false, error: 'bridge returned empty output' };
|
|
43
|
+
try {
|
|
44
|
+
return JSON.parse(text);
|
|
45
|
+
} catch {
|
|
46
|
+
return { ok: false, error: 'bridge returned invalid JSON: ' + text.slice(0, 200) };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function accountId(seed) {
|
|
51
|
+
let h = 2166136261;
|
|
52
|
+
for (const ch of String(seed)) {
|
|
53
|
+
h ^= ch.charCodeAt(0);
|
|
54
|
+
h = Math.imul(h, 16777619) >>> 0;
|
|
55
|
+
}
|
|
56
|
+
return 'acct-' + h.toString(16).padStart(8, '0');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function recordKey(id) {
|
|
60
|
+
return 'mail/' + id;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function outboxKey(id) {
|
|
64
|
+
return 'mail-outbox/' + id;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function contactsKey(id) {
|
|
68
|
+
return 'mail-contacts/' + id;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Global plugin settings live under their own scope so listAccounts (which
|
|
72
|
+
// treats every "mail/<id>" record as an account) never picks this record up.
|
|
73
|
+
const SETTINGS_KEY = 'mail-settings/main';
|
|
74
|
+
|
|
75
|
+
async function readSettings(ctx) {
|
|
76
|
+
const data = await readData(ctx, SETTINGS_KEY, {});
|
|
77
|
+
const rawInterval = Number(data.notifyInterval);
|
|
78
|
+
return {
|
|
79
|
+
agentMailAccess: data.agentMailAccess === true,
|
|
80
|
+
// New-mail alerts are on by default. Delivery is via the desktop pet
|
|
81
|
+
// (default), a browser system notification, or both.
|
|
82
|
+
notifyEnabled: data.notifyEnabled !== false,
|
|
83
|
+
// Clamp to 15s..3600s; 60s default. Keeps IMAP polling reasonable.
|
|
84
|
+
notifyInterval: Number.isFinite(rawInterval) ? Math.min(3600, Math.max(15, Math.round(rawInterval))) : 60,
|
|
85
|
+
notifyMode: ['pet', 'system', 'both'].includes(data.notifyMode) ? data.notifyMode : 'pet',
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function writeSettings(ctx, value) {
|
|
90
|
+
const input = value && typeof value === 'object' ? value : {};
|
|
91
|
+
const rawInterval = Number(input.notifyInterval);
|
|
92
|
+
const next = {
|
|
93
|
+
agentMailAccess: input.agentMailAccess === true,
|
|
94
|
+
notifyEnabled: input.notifyEnabled !== false,
|
|
95
|
+
notifyInterval: Number.isFinite(rawInterval) ? Math.min(3600, Math.max(15, Math.round(rawInterval))) : 60,
|
|
96
|
+
notifyMode: ['pet', 'system', 'both'].includes(input.notifyMode) ? input.notifyMode : 'pet',
|
|
97
|
+
};
|
|
98
|
+
await writeData(ctx, SETTINGS_KEY, next);
|
|
99
|
+
return next;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Read a plain JSON payload record (kind 'grant') from the credential store, returning
|
|
103
|
+
// a fallback when it does not exist yet. Account-specific data lives under a
|
|
104
|
+
// key derived from the account id, so switching accounts never mixes data.
|
|
105
|
+
async function readData(ctx, key, fallback) {
|
|
106
|
+
try {
|
|
107
|
+
const record = await ctx.credentials.readRecord(key);
|
|
108
|
+
if (record && (record.kind === 'grant' || record.kind === 'data') && record.payload && typeof record.payload === 'object') {
|
|
109
|
+
return record.payload;
|
|
110
|
+
}
|
|
111
|
+
} catch {
|
|
112
|
+
// First use: the record simply does not exist.
|
|
113
|
+
}
|
|
114
|
+
return fallback;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async function writeData(ctx, key, payload) {
|
|
118
|
+
await ctx.credentials.modifyRecord(key, async () => ({ kind: 'grant', payload }));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Contacts are stored locally only (per account in the credential store);
|
|
122
|
+
// they are never written to the IMAP server.
|
|
123
|
+
function publicAccount(id, payload) {
|
|
124
|
+
return {
|
|
125
|
+
id,
|
|
126
|
+
name: payload.name || payload.username,
|
|
127
|
+
username: payload.username,
|
|
128
|
+
imapHost: payload.imapHost,
|
|
129
|
+
imapPort: payload.imapPort,
|
|
130
|
+
smtpHost: payload.smtpHost,
|
|
131
|
+
smtpPort: payload.smtpPort,
|
|
132
|
+
imapTls: payload.imapTls !== false,
|
|
133
|
+
smtpTls: payload.smtpTls !== false,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function listAccounts(ctx) {
|
|
138
|
+
const entries = await ctx.credentials.listRecords();
|
|
139
|
+
const accounts = [];
|
|
140
|
+
for (const entry of entries) {
|
|
141
|
+
const key = String(entry.key);
|
|
142
|
+
if (!key.startsWith('mail/')) continue;
|
|
143
|
+
const id = key.slice(5);
|
|
144
|
+
const record = await ctx.credentials.readRecord(key);
|
|
145
|
+
if (!record || record.kind !== 'grant' || typeof record.payload !== 'object' || record.payload === null) continue;
|
|
146
|
+
accounts.push(publicAccount(id, record.payload));
|
|
147
|
+
}
|
|
148
|
+
return accounts.sort((a, b) => String(a.name).localeCompare(String(b.name)));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function getAccountPayload(ctx, id) {
|
|
152
|
+
const record = await ctx.credentials.readRecord(recordKey(id));
|
|
153
|
+
if (!record || record.kind !== 'grant' || typeof record.payload !== 'object' || record.payload === null) {
|
|
154
|
+
throw new Error('account not found: ' + id);
|
|
155
|
+
}
|
|
156
|
+
return record.payload;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function bridgeAccount(payload) {
|
|
160
|
+
return {
|
|
161
|
+
username: payload.username,
|
|
162
|
+
authCode: payload.authCode,
|
|
163
|
+
imapHost: payload.imapHost,
|
|
164
|
+
imapPort: Number(payload.imapPort) || 993,
|
|
165
|
+
smtpHost: payload.smtpHost,
|
|
166
|
+
smtpPort: Number(payload.smtpPort) || 465,
|
|
167
|
+
imapTls: payload.imapTls !== false,
|
|
168
|
+
smtpTls: payload.smtpTls !== false,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function json(result, status = 200) {
|
|
173
|
+
return new Response(JSON.stringify(result), {
|
|
174
|
+
status,
|
|
175
|
+
headers: { 'content-type': 'application/json; charset=utf-8' },
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async function handleRequest(ctx, request) {
|
|
180
|
+
const url = new URL(request.url);
|
|
181
|
+
let body = {};
|
|
182
|
+
if (request.method === 'POST') {
|
|
183
|
+
try {
|
|
184
|
+
body = await request.json();
|
|
185
|
+
} catch {
|
|
186
|
+
return json({ ok: false, error: 'invalid JSON body' }, 400);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const op = body.op || url.searchParams.get('op');
|
|
190
|
+
try {
|
|
191
|
+
switch (op) {
|
|
192
|
+
case 'getSettings':
|
|
193
|
+
return json({ ok: true, settings: await readSettings(ctx) });
|
|
194
|
+
case 'setSettings':
|
|
195
|
+
return json({ ok: true, settings: await writeSettings(ctx, body.value) });
|
|
196
|
+
case 'listAccounts':
|
|
197
|
+
return json({ ok: true, accounts: await listAccounts(ctx) });
|
|
198
|
+
case 'saveAccount': {
|
|
199
|
+
const username = String(body.username || '').trim();
|
|
200
|
+
if (!username) return json({ ok: false, error: 'username is required' }, 400);
|
|
201
|
+
const authCode = String(body.authCode || '');
|
|
202
|
+
if (!authCode) return json({ ok: false, error: 'authCode is required' }, 400);
|
|
203
|
+
const id = body.id || accountId(username.toLowerCase());
|
|
204
|
+
const payload = {
|
|
205
|
+
name: String(body.name || username).trim(),
|
|
206
|
+
username,
|
|
207
|
+
authCode,
|
|
208
|
+
imapHost: String(body.imapHost || '').trim(),
|
|
209
|
+
imapPort: Number(body.imapPort) || 993,
|
|
210
|
+
smtpHost: String(body.smtpHost || '').trim(),
|
|
211
|
+
smtpPort: Number(body.smtpPort) || 465,
|
|
212
|
+
imapTls: body.imapTls !== false,
|
|
213
|
+
smtpTls: body.smtpTls !== false,
|
|
214
|
+
};
|
|
215
|
+
if (!payload.imapHost) return json({ ok: false, error: 'imapHost is required' }, 400);
|
|
216
|
+
if (!payload.smtpHost) return json({ ok: false, error: 'smtpHost is required' }, 400);
|
|
217
|
+
await ctx.credentials.modifyRecord(recordKey(id), async () => ({
|
|
218
|
+
kind: 'grant',
|
|
219
|
+
payload,
|
|
220
|
+
}));
|
|
221
|
+
return json({ ok: true, account: publicAccount(id, payload) });
|
|
222
|
+
}
|
|
223
|
+
case 'deleteAccount': {
|
|
224
|
+
const id = String(body.id || '');
|
|
225
|
+
if (!id) return json({ ok: false, error: 'id is required' }, 400);
|
|
226
|
+
await ctx.credentials.deleteRecord(recordKey(id));
|
|
227
|
+
return json({ ok: true });
|
|
228
|
+
}
|
|
229
|
+
case 'testAccount': {
|
|
230
|
+
const payload = await getAccountPayload(ctx, String(body.id || ''));
|
|
231
|
+
return json(await runBridge('test', { account: bridgeAccount(payload) }));
|
|
232
|
+
}
|
|
233
|
+
case 'listMessages': {
|
|
234
|
+
const payload = await getAccountPayload(ctx, String(body.id || ''));
|
|
235
|
+
return json(await runBridge('listMessages', {
|
|
236
|
+
account: bridgeAccount(payload),
|
|
237
|
+
folder: body.folder || 'INBOX',
|
|
238
|
+
limit: Number(body.limit) || 20,
|
|
239
|
+
}));
|
|
240
|
+
}
|
|
241
|
+
case 'getMessage': {
|
|
242
|
+
const payload = await getAccountPayload(ctx, String(body.id || ''));
|
|
243
|
+
return json(await runBridge('getMessage', {
|
|
244
|
+
account: bridgeAccount(payload),
|
|
245
|
+
uid: String(body.uid || ''),
|
|
246
|
+
folder: body.folder || 'INBOX',
|
|
247
|
+
}));
|
|
248
|
+
}
|
|
249
|
+
case 'sendMessage': {
|
|
250
|
+
const id = String(body.id || '');
|
|
251
|
+
const payload = await getAccountPayload(ctx, id);
|
|
252
|
+
const to = String(body.to || '').trim();
|
|
253
|
+
if (!to) return json({ ok: false, error: 'to is required' }, 400);
|
|
254
|
+
const result = await runBridge('sendMessage', {
|
|
255
|
+
account: bridgeAccount(payload),
|
|
256
|
+
to,
|
|
257
|
+
subject: String(body.subject || ''),
|
|
258
|
+
body: String(body.body || ''),
|
|
259
|
+
attachments: Array.isArray(body.attachments) ? body.attachments : [],
|
|
260
|
+
});
|
|
261
|
+
if (result.ok) {
|
|
262
|
+
// Keep a local outbox record as an instant, offline-capable mirror of
|
|
263
|
+
// the IMAP Sent folder. The outbox is per-account (key includes id).
|
|
264
|
+
try {
|
|
265
|
+
const store = await readData(ctx, outboxKey(id), { sent: [] });
|
|
266
|
+
const list = Array.isArray(store.sent) ? store.sent : [];
|
|
267
|
+
list.unshift({
|
|
268
|
+
id: String(Date.now()) + '-' + Math.random().toString(36).slice(2, 8),
|
|
269
|
+
to,
|
|
270
|
+
subject: String(body.subject || ''),
|
|
271
|
+
body: String(body.body || ''),
|
|
272
|
+
date: new Date().toISOString(),
|
|
273
|
+
});
|
|
274
|
+
await writeData(ctx, outboxKey(id), { sent: list.slice(0, 200) });
|
|
275
|
+
} catch {
|
|
276
|
+
// Local mirror must never fail an already-delivered message.
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return json(result);
|
|
280
|
+
}
|
|
281
|
+
case 'sentMessages': {
|
|
282
|
+
const id = String(body.id || '');
|
|
283
|
+
const payload = await getAccountPayload(ctx, id);
|
|
284
|
+
// Read Sent from the mail server so mails sent on other devices show up.
|
|
285
|
+
try {
|
|
286
|
+
const r = await runBridge('listSent', { account: bridgeAccount(payload), limit: 50 });
|
|
287
|
+
if (r && r.ok && Array.isArray(r.messages)) {
|
|
288
|
+
const sent = r.messages.map(m => ({
|
|
289
|
+
id: m.id || ((m.folder || '') + ':' + m.uid),
|
|
290
|
+
to: m.to || '',
|
|
291
|
+
subject: m.subject || '',
|
|
292
|
+
body: m.snippet || '',
|
|
293
|
+
date: m.date || '',
|
|
294
|
+
from: m.from || '',
|
|
295
|
+
uid: m.uid || '',
|
|
296
|
+
folder: m.folder || '',
|
|
297
|
+
}));
|
|
298
|
+
try { await writeData(ctx, outboxKey(id), { sent }); } catch {}
|
|
299
|
+
return json({ ok: true, sent });
|
|
300
|
+
}
|
|
301
|
+
} catch {
|
|
302
|
+
// Fall through to the local cache below.
|
|
303
|
+
}
|
|
304
|
+
const store = await readData(ctx, outboxKey(id), { sent: [] });
|
|
305
|
+
return json({ ok: true, sent: Array.isArray(store.sent) ? store.sent : [] });
|
|
306
|
+
}
|
|
307
|
+
case 'listContacts': {
|
|
308
|
+
const id = String(body.id || '');
|
|
309
|
+
const store = await readData(ctx, contactsKey(id), { contacts: [] });
|
|
310
|
+
return json({ ok: true, contacts: Array.isArray(store.contacts) ? store.contacts : [] });
|
|
311
|
+
}
|
|
312
|
+
case 'saveContact': {
|
|
313
|
+
const id = String(body.id || '');
|
|
314
|
+
const email = String(body.email || '').trim().toLowerCase();
|
|
315
|
+
if (!email || !email.includes('@')) return json({ ok: false, error: 'valid email is required' }, 400);
|
|
316
|
+
const emailLower = c => String(c.email || '').toLowerCase();
|
|
317
|
+
const store = await readData(ctx, contactsKey(id), { contacts: [] });
|
|
318
|
+
const list = Array.isArray(store.contacts) ? store.contacts.slice() : [];
|
|
319
|
+
const existing = list.find(c => emailLower(c) === email);
|
|
320
|
+
if (existing) existing.name = String(body.name || existing.name || '');
|
|
321
|
+
else list.push({ email, name: String(body.name || '') });
|
|
322
|
+
list.sort((a, b) => String(a.name || a.email).localeCompare(String(b.name || b.email)));
|
|
323
|
+
await writeData(ctx, contactsKey(id), { contacts: list });
|
|
324
|
+
return json({ ok: true, contacts: list });
|
|
325
|
+
}
|
|
326
|
+
case 'deleteContact': {
|
|
327
|
+
const id = String(body.id || '');
|
|
328
|
+
const email = String(body.email || '').trim().toLowerCase();
|
|
329
|
+
const store = await readData(ctx, contactsKey(id), { contacts: [] });
|
|
330
|
+
const list = (Array.isArray(store.contacts) ? store.contacts : [])
|
|
331
|
+
.filter(c => String(c.email || '').toLowerCase() !== email);
|
|
332
|
+
await writeData(ctx, contactsKey(id), { contacts: list });
|
|
333
|
+
return json({ ok: true, contacts: list });
|
|
334
|
+
}
|
|
335
|
+
default:
|
|
336
|
+
return json({ ok: false, error: 'unknown op: ' + op }, 400);
|
|
337
|
+
}
|
|
338
|
+
} catch (error) {
|
|
339
|
+
return json({ ok: false, error: error instanceof Error ? error.message : String(error) }, 500);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export function apply(ctx) {
|
|
344
|
+
ctx.effect(() => ctx.connection.fetch.register({
|
|
345
|
+
path: API,
|
|
346
|
+
methods: ['POST'],
|
|
347
|
+
requestBody: 'buffered',
|
|
348
|
+
fetch: (request) => handleRequest(ctx, request),
|
|
349
|
+
}), 'dsh-mail: fetch route');
|
|
350
|
+
|
|
351
|
+
// Read-only mailbox tool for the AI assistant. The tool itself checks the
|
|
352
|
+
// `agentMailAccess` setting on every call, so turning the switch off revokes
|
|
353
|
+
// access immediately without reloading the plugin.
|
|
354
|
+
ctx.effect(() => ctx.tools.register(mailQueryTool(
|
|
355
|
+
ctx, handleRequest,
|
|
356
|
+
async () => (await readSettings(ctx)).agentMailAccess === true
|
|
357
|
+
)), 'dsh-mail: mail_query tool');
|
|
358
|
+
}
|
package/locale/en.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Mail",
|
|
4
|
+
"description": "Send and receive email from QQ, 163, Gmail and other IMAP/SMTP accounts.",
|
|
5
|
+
"detail": "docs/DETAIL.md"
|
|
6
|
+
},
|
|
7
|
+
"ui": {
|
|
8
|
+
"label": "Mail",
|
|
9
|
+
"accounts": "Accounts",
|
|
10
|
+
"noAccounts": "No accounts yet. Add one below to get started.",
|
|
11
|
+
"addAccount": "Add account",
|
|
12
|
+
"editAccount": "Edit account",
|
|
13
|
+
"deleteAccount": "Delete",
|
|
14
|
+
"accountName": "Account name",
|
|
15
|
+
"username": "Email address",
|
|
16
|
+
"authCode": "Password / app password",
|
|
17
|
+
"imapHost": "IMAP host",
|
|
18
|
+
"imapPort": "IMAP port",
|
|
19
|
+
"smtpHost": "SMTP host",
|
|
20
|
+
"smtpPort": "SMTP port",
|
|
21
|
+
"useTls": "Use TLS/SSL",
|
|
22
|
+
"save": "Save",
|
|
23
|
+
"cancel": "Cancel",
|
|
24
|
+
"test": "Test connection",
|
|
25
|
+
"testing": "Testing...",
|
|
26
|
+
"testOk": "Connection OK",
|
|
27
|
+
"testFail": "Connection failed",
|
|
28
|
+
"inbox": "Inbox",
|
|
29
|
+
"folder": "Folder",
|
|
30
|
+
"refresh": "Refresh",
|
|
31
|
+
"loading": "Loading...",
|
|
32
|
+
"noMessages": "No messages in this folder.",
|
|
33
|
+
"compose": "Compose",
|
|
34
|
+
"to": "To",
|
|
35
|
+
"subject": "Subject",
|
|
36
|
+
"body": "Message",
|
|
37
|
+
"send": "Send",
|
|
38
|
+
"sending": "Sending...",
|
|
39
|
+
"sent": "Message sent",
|
|
40
|
+
"sendFail": "Failed to send",
|
|
41
|
+
"back": "Back to list",
|
|
42
|
+
"selectAccount": "Select an account to view its mail.",
|
|
43
|
+
"from": "From",
|
|
44
|
+
"date": "Date",
|
|
45
|
+
"passwordNote": "Stored securely in the credential vault. QQ/163 require an app password, not your login password.",
|
|
46
|
+
"presets": "Quick setup",
|
|
47
|
+
"qq": "QQ Mail",
|
|
48
|
+
"netease": "NetEase 163",
|
|
49
|
+
"gmail": "Gmail",
|
|
50
|
+
"custom": "Custom",
|
|
51
|
+
"confirmDelete": "Delete this account?"
|
|
52
|
+
}
|
|
53
|
+
}
|
package/locale/zh.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "邮件",
|
|
4
|
+
"description": "通过 QQ、163、Gmail 等 IMAP/SMTP 邮箱收发邮件。",
|
|
5
|
+
"detail": "docs/DETAIL.md"
|
|
6
|
+
},
|
|
7
|
+
"ui": {
|
|
8
|
+
"label": "邮件",
|
|
9
|
+
"accounts": "账号管理",
|
|
10
|
+
"noAccounts": "还没有账号。在下方添加一个即可开始收发邮件。",
|
|
11
|
+
"addAccount": "添加账号",
|
|
12
|
+
"editAccount": "编辑账号",
|
|
13
|
+
"deleteAccount": "删除",
|
|
14
|
+
"accountName": "账号名称",
|
|
15
|
+
"username": "邮箱地址",
|
|
16
|
+
"authCode": "密码 / 授权码",
|
|
17
|
+
"imapHost": "IMAP 服务器",
|
|
18
|
+
"imapPort": "IMAP 端口",
|
|
19
|
+
"smtpHost": "SMTP 服务器",
|
|
20
|
+
"smtpPort": "SMTP 端口",
|
|
21
|
+
"useTls": "使用 TLS/SSL",
|
|
22
|
+
"save": "保存",
|
|
23
|
+
"cancel": "取消",
|
|
24
|
+
"test": "测试连接",
|
|
25
|
+
"testing": "测试中...",
|
|
26
|
+
"testOk": "连接成功",
|
|
27
|
+
"testFail": "连接失败",
|
|
28
|
+
"inbox": "收件箱",
|
|
29
|
+
"folder": "文件夹",
|
|
30
|
+
"refresh": "刷新",
|
|
31
|
+
"loading": "加载中...",
|
|
32
|
+
"noMessages": "此文件夹中没有邮件。",
|
|
33
|
+
"compose": "写邮件",
|
|
34
|
+
"to": "收件人",
|
|
35
|
+
"subject": "主题",
|
|
36
|
+
"body": "正文",
|
|
37
|
+
"send": "发送",
|
|
38
|
+
"sending": "发送中...",
|
|
39
|
+
"sent": "邮件已发送",
|
|
40
|
+
"sendFail": "发送失败",
|
|
41
|
+
"back": "返回列表",
|
|
42
|
+
"selectAccount": "选择一个账号以查看邮件。",
|
|
43
|
+
"from": "发件人",
|
|
44
|
+
"date": "日期",
|
|
45
|
+
"passwordNote": "授权码安全保存在凭据保险箱中。QQ/163 需使用授权码而非登录密码。",
|
|
46
|
+
"presets": "快速设置",
|
|
47
|
+
"qq": "QQ 邮箱",
|
|
48
|
+
"netease": "网易 163",
|
|
49
|
+
"gmail": "Gmail",
|
|
50
|
+
"custom": "自定义",
|
|
51
|
+
"confirmDelete": "确定删除此账号吗?"
|
|
52
|
+
}
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@mysterycode-liwen/dsh-mail",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@mysterycode-liwen/dsh-mail",
|
|
3
|
+
"version": "1.0.1",
|
|
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
|
+
}
|