@mysterycode-liwen/dsh-mail 1.1.0 → 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/client.js CHANGED
@@ -7,12 +7,195 @@ window.__ModuleLoader__.load({
7
7
 
8
8
  const NS = 'dsh-mail';
9
9
  const API = '/api/dsh-mail';
10
+ // ---- Credential-vault bridge client (self-contained, zero deps) ----
11
+ // Enables "fill from vault" only when the credential-vault plugin is installed.
12
+ // Uninstalled -> isAvailable() false -> the feature silently hides.
13
+ /*
14
+ * vault-bridge-client.js — reusable client module for the DSH credential vault bridge
15
+ * ------------------------------------------------------------------------------
16
+ * Copy this whole file's contents into your plugin's client.js (inside
17
+ * factory(require)), or load it through your plugin's build step. ZERO deps:
18
+ * it only uses window.crypto.subtle, btoa/atob and TextEncoder/TextDecoder.
19
+ *
20
+ * WHY THIS EXISTS
21
+ * The vault keeps real secrets in its own browser localStorage. The Harness
22
+ * Host process only ever sees metadata (secrets are masked), so a plugin that
23
+ * needs a real value (e.g. a mail app password) must talk to the vault's
24
+ * browser-side bridge. This module does that.
25
+ *
26
+ * All payloads are encrypted with an ECDH (P-256) + AES-GCM session:
27
+ * 1. client.query(...) -> bridge.hello() = vault ephemeral public key + id
28
+ * 2. client generates its own ephemeral key pair, derives the shared AES key
29
+ * 3. client seals the query, vault decrypts / reads secrets / seals result
30
+ * 4. client opens the result with the same derived key.
31
+ * No plaintext and no long-lived key ever crosses the bridge. If the vault is
32
+ * not installed, isAvailable() is false and query() rejects NOT_INSTALLED —
33
+ * gate your UI on isAvailable() so the feature silently disappears.
34
+ *
35
+ * SECURITY NOTE
36
+ * The bridge is a same-document JS object. ECDH stops passive observers and
37
+ * other plugins from reading the payload, but a hostile script in the same
38
+ * document could still call the bridge as if it were your plugin. The vault
39
+ * never auto-authorises: each session is one-time use and expires in 60s.
40
+ *
41
+ * USAGE
42
+ * const vault = createVaultV1Client();
43
+ * if (vault.isAvailable()) {
44
+ * const entries = await vault.query({ category: 'account', title: 'qq' });
45
+ * const secret = vault.secretOf(entries[0]); // real password / key value
46
+ * }
47
+ *
48
+ * Node (tests): also exported via module.exports when available.
49
+ */
50
+
51
+ function createVaultV1Client(options) {
52
+ options = options || {};
53
+ var win = options.window || (typeof window !== 'undefined' ? window : null);
54
+ var BRIDGE_KEY = '@mysterycode-liwen/dsh-credential-vault/bridge/v1';
55
+
56
+ function cryptoObj() {
57
+ return (win && win.crypto) || (typeof globalThis !== 'undefined' && globalThis.crypto) || null;
58
+ }
59
+ function subtle() {
60
+ var c = cryptoObj();
61
+ return c && c.subtle ? c.subtle : null;
62
+ }
63
+ function randomFill(bytes) {
64
+ var c = cryptoObj();
65
+ if (!c || !c.getRandomValues) throw new Error('NO_CRYPTO');
66
+ c.getRandomValues(bytes);
67
+ return bytes;
68
+ }
69
+ function toB64u(bytes) {
70
+ var s = '';
71
+ for (var i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i]);
72
+ var btoaFn = options.btoa || (typeof btoa === 'function' ? btoa : (win && win.btoa));
73
+ return btoaFn(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
74
+ }
75
+ function fromB64u(str) {
76
+ var s = String(str).replace(/-/g, '+').replace(/_/g, '/');
77
+ while (s.length % 4) s += '=';
78
+ var atobFn = options.atob || (typeof atob === 'function' ? atob : (win && win.atob));
79
+ var bin = atobFn(s), out = new Uint8Array(bin.length);
80
+ for (var i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
81
+ return out;
82
+ }
83
+ function enc(str) { return new TextEncoder().encode(str); }
84
+ function dec(bytes) { return new TextDecoder().decode(bytes); }
85
+
86
+ function bridge() {
87
+ if (!win || !win[BRIDGE_KEY]) return null;
88
+ var b = win[BRIDGE_KEY];
89
+ return b && b.version === 1 && typeof b.hello === 'function' && typeof b.query === 'function' ? b : null;
90
+ }
91
+
92
+ function generatePair(s) {
93
+ return s.generateKey({ name: 'ECDH', namedCurve: 'P-256' }, true, ['deriveBits']);
94
+ }
95
+ function deriveKey(s, priv, peerJwk) {
96
+ return s.importKey('jwk', peerJwk, { name: 'ECDH', namedCurve: 'P-256' }, false, [])
97
+ .then(function (pub) { return s.deriveBits({ name: 'ECDH', public: pub }, priv, 256); })
98
+ .then(function (bits) { return s.importKey('raw', bits, { name: 'AES-GCM' }, false, ['encrypt', 'decrypt']); });
99
+ }
100
+ function seal(s, key, obj) {
101
+ var iv = randomFill(new Uint8Array(12));
102
+ return s.encrypt({ name: 'AES-GCM', iv: iv }, key, enc(JSON.stringify(obj)))
103
+ .then(function (ct) { return { iv: toB64u(iv), ciphertext: toB64u(new Uint8Array(ct)) }; });
104
+ }
105
+ function open(s, key, payload) {
106
+ if (!payload || typeof payload.iv !== 'string' || typeof payload.ciphertext !== 'string') {
107
+ return Promise.reject(new Error('BAD_CIPHERTEXT'));
108
+ }
109
+ return s.decrypt({ name: 'AES-GCM', iv: fromB64u(payload.iv) }, key, fromB64u(payload.ciphertext))
110
+ .then(function (plain) { return JSON.parse(dec(new Uint8Array(plain))); });
111
+ }
112
+
113
+ function isAvailable() { return !!bridge(); }
114
+
115
+ function query(criteria) {
116
+ criteria = criteria || {};
117
+ var b = bridge();
118
+ if (!b) return Promise.reject(new Error('NOT_INSTALLED'));
119
+ var s = subtle();
120
+ if (!s) return Promise.reject(new Error('NO_CRYPTO'));
121
+ var vaultPub, sessionId, priv, aes;
122
+ return Promise.resolve(b.hello())
123
+ .then(function (hello) {
124
+ if (!hello || !hello.sessionId || !hello.publicKeyJwk) throw new Error('BAD_HELLO');
125
+ sessionId = hello.sessionId;
126
+ vaultPub = hello.publicKeyJwk;
127
+ return generatePair(s);
128
+ })
129
+ .then(function (kp) {
130
+ priv = kp.privateKey;
131
+ return s.exportKey('jwk', kp.publicKey);
132
+ })
133
+ .then(function (pubJwk) {
134
+ return deriveKey(s, priv, vaultPub).then(function (key) {
135
+ aes = key;
136
+ return seal(s, aes, {
137
+ category: criteria.category || 'all',
138
+ title: criteria.title || '',
139
+ limit: criteria.limit || 100
140
+ }).then(function (sealed) {
141
+ return b.query({
142
+ sessionId: sessionId,
143
+ publicKeyJwk: pubJwk,
144
+ iv: sealed.iv,
145
+ ciphertext: sealed.ciphertext
146
+ });
147
+ });
148
+ });
149
+ })
150
+ .then(function (result) {
151
+ if (!result) throw new Error('NO_RESPONSE');
152
+ if (result.error) throw new Error(result.error);
153
+ return open(s, aes, result);
154
+ })
155
+ .then(function (plain) { return plain && Array.isArray(plain.entries) ? plain.entries : []; });
156
+ }
157
+
158
+ function secretOf(entry) {
159
+ if (!entry) return '';
160
+ var keys = ['password', 'keyValue', 'apiKey', 'content', 'appSecret', 'token', 'encodingAesKey', 'uploadKey'];
161
+ for (var i = 0; i < keys.length; i++) {
162
+ if (typeof entry[keys[i]] === 'string' && entry[keys[i]]) return entry[keys[i]];
163
+ }
164
+ return '';
165
+ }
166
+
167
+ return {
168
+ version: 1,
169
+ isAvailable: isAvailable,
170
+ query: query,
171
+ secretOf: secretOf,
172
+ _debug: { toB64u: toB64u, fromB64u: fromB64u, deriveKey: deriveKey, seal: seal, open: open }
173
+ };
174
+ }
175
+
10
176
 
11
177
  function escHtml(s) {
12
178
  return String(s == null ? '' : s)
13
179
  .replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
14
180
  }
15
181
 
182
+ // Best-effort plain-text extraction from a sanitized mail body, used as the
183
+ // translation source when the bridge did not supply a plain-text part.
184
+ function htmlToText(html) {
185
+ return String(html == null ? '' : html)
186
+ .replace(/<br\s*\/?>/gi, '\n')
187
+ .replace(/<\/(p|div|li|tr|h[1-6]|blockquote)>/gi, '\n')
188
+ .replace(/<[^>]*>/g, '')
189
+ .replace(/&nbsp;/gi, ' ')
190
+ .replace(/&amp;/gi, '&')
191
+ .replace(/&lt;/gi, '<')
192
+ .replace(/&gt;/gi, '>')
193
+ .replace(/&quot;/gi, '"')
194
+ .replace(/&#39;/g, "'")
195
+ .replace(/\n{3,}/g, '\n\n')
196
+ .trim();
197
+ }
198
+
16
199
  let t = (key) => key;
17
200
 
18
201
  // Map a structured bridge error ({ code, error, stage }) to a short,
@@ -89,6 +272,13 @@ window.__ModuleLoader__.load({
89
272
  custom: '自定义',
90
273
  presets: '快速设置',
91
274
  note: 'QQ / 163 需要邮箱授权码,而不是登录密码。授权码保存在凭据保险箱中。',
275
+ fillFromVault: '从保险箱选择',
276
+ vaultUnavailable: '未安装凭据保险箱插件,或保险箱中没有账号类凭据。',
277
+ vaultPickTitle: '从凭据保险箱选择授权码',
278
+ vaultPickHint: '以下是保险箱中的账号凭据,选择一个用其密码/授权码填入。',
279
+ vaultPickEmpty: '保险箱中没有可用的账号凭据。',
280
+ vaultPickError: '读取保险箱失败,请确认保险箱插件已启用。',
281
+ vaultPickLoading: '正在读取…',
92
282
  confirmDelete: '确定删除此账号吗?',
93
283
  rename: '重命名',
94
284
  renameHint: '名称只在本机显示,默认用邮箱前缀。',
@@ -187,6 +377,15 @@ window.__ModuleLoader__.load({
187
377
  notifyDiagNever: '从未',
188
378
  notifyDiagError: '最近错误',
189
379
  notifyDiagOk: '正常',
380
+ // 邮件翻译
381
+ translate: '翻译',
382
+ translating: '翻译中…',
383
+ translated: '译文',
384
+ translateShowOriginal: '查看原文',
385
+ translatedNotice: '由 DSH 翻译(机器翻译,仅供参考)',
386
+ translateFailed: '翻译失败:',
387
+ translateUnavailable: '当前环境未启用翻译服务。请在「设置 → 插件」中启用实验性翻译扩展后重试。',
388
+ translateTextLimit: '邮件内容过长,翻译失败。',
190
389
  };
191
390
  const en = {
192
391
  label: 'Mail',
@@ -231,6 +430,13 @@ window.__ModuleLoader__.load({
231
430
  custom: 'Custom',
232
431
  presets: 'Presets',
233
432
  note: 'QQ / 163 need an app password, not your login password. Stored in the credential vault.',
433
+ fillFromVault: 'Fill from vault',
434
+ vaultUnavailable: 'Credential vault plugin not installed, or no account credentials in it.',
435
+ vaultPickTitle: 'Choose app password from vault',
436
+ vaultPickHint: 'These are the account credentials in your vault. Pick one to fill its password / app code.',
437
+ vaultPickEmpty: 'No account credentials found in the vault.',
438
+ vaultPickError: 'Failed to read the vault. Make sure the vault plugin is enabled.',
439
+ vaultPickLoading: 'Reading…',
234
440
  confirmDelete: 'Delete this account?',
235
441
  rename: 'Rename',
236
442
  renameHint: 'The name is local to this machine; it defaults to the mailbox prefix.',
@@ -329,6 +535,15 @@ window.__ModuleLoader__.load({
329
535
  notifyDiagNever: 'Never',
330
536
  notifyDiagError: 'Last error',
331
537
  notifyDiagOk: 'OK',
538
+ // Mail translation
539
+ translate: 'Translate',
540
+ translating: 'Translating…',
541
+ translated: 'Translation',
542
+ translateShowOriginal: 'Show original',
543
+ translatedNotice: 'Translated by DSH (machine translation, for reference only)',
544
+ translateFailed: 'Translation failed: ',
545
+ translateUnavailable: 'Translation is not enabled in this environment. Enable the experimental translation extension under Settings → Plugins and retry.',
546
+ translateTextLimit: 'This message is too long to translate.',
332
547
  };
333
548
 
334
549
  // ---------------------------------------------------------------------
@@ -339,25 +554,25 @@ window.__ModuleLoader__.load({
339
554
  // hardcoded gray buttons the previous version had.
340
555
  // ---------------------------------------------------------------------
341
556
  const CSS = [
342
- '.dsh-mail { display:flex; flex-direction:column; height:100%; box-sizing:border-box; background:var(--dsw-alias-bg-base); color:var(--dsw-alias-label-primary); font-family:inherit; font-size:13px; line-height:1.5; }',
557
+ '.dsh-mail { display:flex; flex-direction:column; height:100%; box-sizing:border-box; background:var(--dsw-alias-bg-base); color:var(--dsw-alias-label-primary); font-family:inherit; font-size:13px; line-height:1.55; -webkit-font-smoothing:antialiased; text-rendering:optimizeLegibility; }',
343
558
  '.dsh-mail * { box-sizing:border-box; }',
344
559
  '.dsh-mail button, .dsh-mail input, .dsh-mail textarea, .dsh-mail select { font-family:inherit; }',
345
560
  '.dsh-mail-spacer { flex:1; min-width:0; }',
346
561
 
347
562
  /* top bar */
348
- '.dsh-mail-topbar { display:flex; align-items:center; gap:12px; padding:14px 18px 13px; border-bottom:1px solid var(--dsw-alias-border-l1); background:var(--dsw-alias-bg-layer-1); }',
349
- '.dsh-mail-brand { display:flex; align-items:center; gap:10px; font-size:16px; font-weight:650; letter-spacing:.2px; }',
350
- '.dsh-mail-brandmark { width:32px; height:32px; border-radius:10px; display:grid; place-items:center; background:var(--dsw-alias-brand-primary); color:var(--dsw-alias-bg-base); box-shadow:0 2px 8px rgba(0,0,0,.14); }',
351
- '.dsh-mail-brandsub { font-size:11px; color:var(--dsw-alias-label-secondary); font-weight:400; }',
563
+ '.dsh-mail-topbar { display:flex; align-items:center; gap:12px; padding:15px 20px 14px; border-bottom:1px solid var(--dsw-alias-border-l1); background:linear-gradient(180deg, color-mix(in srgb, var(--dsw-alias-brand-primary) 6%, var(--dsw-alias-bg-layer-1)), var(--dsw-alias-bg-layer-1)); }',
564
+ '.dsh-mail-brand { display:flex; align-items:center; gap:11px; font-size:16px; font-weight:700; letter-spacing:.3px; }',
565
+ '.dsh-mail-brandmark { width:34px; height:34px; border-radius:11px; display:grid; place-items:center; background:linear-gradient(135deg, color-mix(in srgb, var(--dsw-alias-brand-primary) 78%, white), var(--dsw-alias-brand-primary)); color:var(--dsw-alias-bg-base); box-shadow:0 4px 12px color-mix(in srgb, var(--dsw-alias-brand-primary) 28%, transparent), inset 0 1px 0 rgba(255,255,255,.22); }',
566
+ '.dsh-mail-brandsub { font-size:10.5px; color:var(--dsw-alias-label-secondary); font-weight:500; letter-spacing:.6px; text-transform:uppercase; }',
352
567
 
353
568
  /* buttons */
354
- '.dsh-mail-btn { display:inline-flex; align-items:center; justify-content:center; gap:6px; border:1px solid var(--dsw-alias-border-l2); border-radius:8px; padding:7px 12px; font-size:12px; font-weight:600; line-height:1.4; cursor:pointer; background:var(--dsw-alias-bg-layer-2); color:var(--dsw-alias-label-primary); transition:filter .12s, transform .06s, box-shadow .12s; white-space:nowrap; }',
355
- '.dsh-mail-btn:hover:not(:disabled) { filter:brightness(.94); }',
569
+ '.dsh-mail-btn { display:inline-flex; align-items:center; justify-content:center; gap:6px; border:1px solid var(--dsw-alias-border-l2); border-radius:9px; padding:7px 13px; font-size:12px; font-weight:600; line-height:1.4; cursor:pointer; background:var(--dsw-alias-bg-layer-2); color:var(--dsw-alias-label-primary); transition:filter .15s, transform .08s, box-shadow .15s, border-color .15s, background .15s; white-space:nowrap; }',
570
+ '.dsh-mail-btn:hover:not(:disabled) { filter:brightness(.97); border-color:var(--dsw-alias-brand-primary); box-shadow:0 2px 8px rgba(0,0,0,.08); }',
356
571
  '.dsh-mail-btn:active:not(:disabled) { transform:translateY(1px); box-shadow:inset 0 2px 5px rgba(0,0,0,.12); }',
357
572
  '.dsh-mail-btn:focus-visible { outline:2px solid var(--dsw-alias-brand-primary); outline-offset:2px; }',
358
573
  '.dsh-mail-btn:disabled { opacity:.45; cursor:not-allowed; }',
359
- '.dsh-mail-btn-primary { background:var(--dsw-alias-brand-primary); border-color:transparent; color:var(--dsw-alias-bg-base); box-shadow:0 2px 8px rgba(0,0,0,.16); }',
360
- '.dsh-mail-btn-primary:hover:not(:disabled) { filter:brightness(1.08); }',
574
+ '.dsh-mail-btn-primary { background:linear-gradient(135deg, color-mix(in srgb, var(--dsw-alias-brand-primary) 82%, white), var(--dsw-alias-brand-primary)); border-color:transparent; color:var(--dsw-alias-bg-base); box-shadow:0 3px 10px color-mix(in srgb, var(--dsw-alias-brand-primary) 32%, transparent), inset 0 1px 0 rgba(255,255,255,.2); }',
575
+ '.dsh-mail-btn-primary:hover:not(:disabled) { filter:brightness(1.06); box-shadow:0 5px 14px color-mix(in srgb, var(--dsw-alias-brand-primary) 40%, transparent); }',
361
576
  '.dsh-mail-btn-danger { color:var(--dsw-alias-state-error-primary); border-color:var(--dsw-alias-state-error-primary); background:transparent; }',
362
577
  '.dsh-mail-btn-danger:hover:not(:disabled) { filter:none; background:var(--dsw-alias-state-error-primary); color:#fff; }',
363
578
  '.dsh-mail-iconbtn { width:30px; height:30px; padding:0; border-radius:8px; }',
@@ -366,12 +581,13 @@ window.__ModuleLoader__.load({
366
581
  '.dsh-mail-refresh-err { color:var(--dsw-alias-state-error-primary); }',
367
582
 
368
583
  /* segmented navigation */
369
- '.dsh-mail-tabs { display:flex; align-items:center; gap:2px; padding:0 12px; border-bottom:1px solid var(--dsw-alias-border-l1); background:var(--dsw-alias-bg-layer-1); overflow-x:auto; }',
370
- '.dsh-mail-tab { position:relative; display:inline-flex; align-items:center; gap:7px; padding:11px 13px 12px; border:0; background:transparent; color:var(--dsw-alias-label-secondary); font-size:12px; font-weight:600; cursor:pointer; white-space:nowrap; transition:color .12s; }',
584
+ '.dsh-mail-tabs { display:flex; align-items:center; gap:4px; padding:0 14px; border-bottom:1px solid var(--dsw-alias-border-l1); background:var(--dsw-alias-bg-layer-1); overflow-x:auto; }',
585
+ '.dsh-mail-tab { position:relative; display:inline-flex; align-items:center; gap:7px; padding:12px 14px 13px; border:0; background:transparent; color:var(--dsw-alias-label-secondary); font-size:12px; font-weight:600; cursor:pointer; white-space:nowrap; transition:color .15s, transform .08s; }',
371
586
  '.dsh-mail-tab:hover { color:var(--dsw-alias-label-primary); }',
587
+ '.dsh-mail-tab:active { transform:scale(.96); }',
372
588
  '.dsh-mail-tab.is-active { color:var(--dsw-alias-brand-primary); }',
373
- '.dsh-mail-tab.is-active::after { content:""; position:absolute; left:10px; right:10px; bottom:0; height:2px; border-radius:2px 2px 0 0; background:var(--dsw-alias-brand-primary); }',
374
- '.dsh-mail-badge { display:grid; place-items:center; min-width:17px; height:17px; padding:0 5px; border-radius:9px; background:var(--dsw-alias-brand-primary); color:var(--dsw-alias-bg-base); font-size:10px; font-weight:700; }',
589
+ '.dsh-mail-tab.is-active::after { content:""; position:absolute; left:12px; right:12px; bottom:0; height:3px; border-radius:3px 3px 0 0; background:linear-gradient(90deg, color-mix(in srgb, var(--dsw-alias-brand-primary) 60%, white), var(--dsw-alias-brand-primary)); box-shadow:0 -1px 6px color-mix(in srgb, var(--dsw-alias-brand-primary) 40%, transparent); }',
590
+ '.dsh-mail-badge { display:grid; place-items:center; min-width:18px; height:18px; padding:0 5px; border-radius:9px; background:linear-gradient(135deg, color-mix(in srgb, var(--dsw-alias-brand-primary) 80%, white), var(--dsw-alias-brand-primary)); color:var(--dsw-alias-bg-base); font-size:10px; font-weight:700; box-shadow:0 2px 6px color-mix(in srgb, var(--dsw-alias-brand-primary) 30%, transparent); }',
375
591
 
376
592
  /* account chip */
377
593
  '.dsh-mail-accountbar { display:flex; align-items:center; gap:9px; padding:9px 16px; border-bottom:1px solid var(--dsw-alias-border-l1); background:var(--dsw-alias-bg-base); }',
@@ -381,35 +597,39 @@ window.__ModuleLoader__.load({
381
597
  '.dsh-mail-filterbar { display:flex; align-items:center; gap:4px; padding:7px 12px; border-bottom:1px solid var(--dsw-alias-border-l1); background:var(--dsw-alias-bg-base); }',
382
598
  '.dsh-mail-filter { display:inline-flex; align-items:center; gap:6px; padding:5px 11px; border:1px solid transparent; border-radius:8px; background:transparent; color:var(--dsw-alias-label-secondary); font-size:12px; font-weight:600; cursor:pointer; transition:background .12s,color .12s; }',
383
599
  '.dsh-mail-filter:hover { background:var(--dsw-alias-bg-layer-2); color:var(--dsw-alias-label-primary); }',
384
- '.dsh-mail-filter.is-active { background:color-mix(in srgb, var(--dsw-alias-brand-primary) 12%, transparent); color:var(--dsw-alias-brand-primary); }',
600
+ '.dsh-mail-filter.is-active { background:color-mix(in srgb, var(--dsw-alias-brand-primary) 13%, transparent); color:var(--dsw-alias-brand-primary); box-shadow:inset 0 0 0 1px color-mix(in srgb, var(--dsw-alias-brand-primary) 22%, transparent); }',
385
601
  '.dsh-mail-filtercount { display:grid; place-items:center; min-width:17px; height:17px; padding:0 5px; border-radius:9px; background:var(--dsw-alias-bg-layer-2); color:var(--dsw-alias-label-secondary); font-size:10px; font-weight:700; }',
386
602
  '.dsh-mail-filter.is-active .dsh-mail-filtercount { background:var(--dsw-alias-brand-primary); color:var(--dsw-alias-bg-base); }',
387
603
 
388
604
  /* message list */
389
- '.dsh-mail-list { flex:1; min-height:0; overflow:auto; padding:6px 8px 18px; }',
390
- '.dsh-mail-row { display:flex; align-items:flex-start; gap:11px; padding:12px 11px; border-radius:11px; border:1px solid transparent; cursor:pointer; transition:background .12s, border-color .12s; }',
391
- '.dsh-mail-row:hover { background:var(--dsw-alias-bg-layer-2); }',
392
- '.dsh-mail-row:active { transform:scale(.995); }',
393
- '.dsh-mail-avatar { width:36px; height:36px; flex:none; border-radius:50%; display:grid; place-items:center; color:#fff; font-size:14px; font-weight:700; box-shadow:inset 0 -6px 10px rgba(0,0,0,.10); }',
605
+ '.dsh-mail-list { flex:1; min-height:0; overflow:auto; padding:8px 10px 20px; }',
606
+ '.dsh-mail-list::-webkit-scrollbar, .dsh-mail-scroll::-webkit-scrollbar { width:8px; height:8px; }',
607
+ '.dsh-mail-list::-webkit-scrollbar-thumb, .dsh-mail-scroll::-webkit-scrollbar-thumb { background:color-mix(in srgb, var(--dsw-alias-label-secondary) 22%, transparent); border-radius:8px; border:2px solid transparent; background-clip:padding-box; }',
608
+ '.dsh-mail-list::-webkit-scrollbar-thumb:hover, .dsh-mail-scroll::-webkit-scrollbar-thumb:hover { background:color-mix(in srgb, var(--dsw-alias-label-secondary) 38%, transparent); background-clip:padding-box; }',
609
+ '.dsh-mail-row { display:flex; align-items:flex-start; gap:12px; padding:13px 12px; margin-bottom:3px; border-radius:12px; border:1px solid transparent; cursor:pointer; transition:background .15s, border-color .15s, transform .1s, box-shadow .15s; }',
610
+ '.dsh-mail-row:hover { background:var(--dsw-alias-bg-layer-2); border-color:var(--dsw-alias-border-l1); box-shadow:0 2px 8px rgba(0,0,0,.05); }',
611
+ '.dsh-mail-row:active { transform:scale(.992); }',
612
+ '.dsh-mail-avatar { width:38px; height:38px; flex:none; border-radius:12px; display:grid; place-items:center; color:#fff; font-size:14px; font-weight:700; box-shadow:inset 0 -6px 10px rgba(0,0,0,.10), 0 2px 6px rgba(0,0,0,.1); }',
394
613
  '.dsh-mail-rowmain { flex:1; min-width:0; }',
395
614
  '.dsh-mail-rowtop { display:flex; align-items:baseline; gap:8px; }',
396
615
  '.dsh-mail-from { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-weight:600; font-size:13px; }',
397
616
  '.dsh-mail-time { flex:none; font-size:11px; color:var(--dsw-alias-label-secondary); }',
398
617
  '.dsh-mail-subject { margin-top:2px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:12.5px; }',
399
618
  '.dsh-mail-preview { margin-top:2px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:11.5px; color:var(--dsw-alias-label-secondary); }',
400
- '.dsh-mail-row.is-unread { background:color-mix(in srgb, var(--dsw-alias-brand-primary) 7%, transparent); border-left:3px solid var(--dsw-alias-brand-primary); padding-left:8px; }',
401
- '.dsh-mail-row.is-unread .dsh-mail-from, .dsh-mail-row.is-unread .dsh-mail-subject { color:var(--dsw-alias-label-primary); font-weight:700; }',
402
- '.dsh-mail-unread { width:9px; height:9px; margin-top:7px; flex:none; border-radius:50%; background:var(--dsw-alias-brand-primary); box-shadow:0 0 0 3px color-mix(in srgb, var(--dsw-alias-brand-primary) 18%, transparent); }',
619
+ '.dsh-mail-row.is-unread { background:color-mix(in srgb, var(--dsw-alias-brand-primary) 5%, transparent); }',
620
+ '.dsh-mail-row.is-unread:hover { background:color-mix(in srgb, var(--dsw-alias-brand-primary) 9%, var(--dsw-alias-bg-layer-2)); }',
621
+ '.dsh-mail-row.is-unread .dsh-mail-from, .dsh-mail-row.is-unread .dsh-mail-subject { color:var(--dsw-alias-label-primary); font-weight:650; }',
622
+ '.dsh-mail-unread { width:7px; height:7px; margin-top:8px; flex:none; border-radius:50%; background:var(--dsw-alias-brand-primary); box-shadow:0 0 0 2px var(--dsw-alias-bg-base); }',
403
623
  '.dsh-mail-read .dsh-mail-from, .dsh-mail-read .dsh-mail-subject { color:var(--dsw-alias-label-secondary); font-weight:400; }',
404
624
 
405
625
  /* cards / forms */
406
- '.dsh-mail-card { border:1px solid var(--dsw-alias-border-l1); border-radius:12px; padding:16px; margin-bottom:12px; background:var(--dsw-alias-bg-layer-1); box-shadow:0 1px 3px rgba(0,0,0,.05); }',
407
- '.dsh-mail-cardhead { display:flex; align-items:center; gap:8px; margin-bottom:14px; font-size:14px; font-weight:650; }',
626
+ '.dsh-mail-card { border:1px solid var(--dsw-alias-border-l1); border-radius:14px; padding:18px; margin-bottom:14px; background:linear-gradient(180deg, var(--dsw-alias-bg-layer-1), var(--dsw-alias-bg-base)); box-shadow:0 2px 10px rgba(0,0,0,.05), inset 0 1px 0 rgba(255,255,255,.04); }',
627
+ '.dsh-mail-cardhead { display:flex; align-items:center; gap:9px; margin-bottom:16px; font-size:14px; font-weight:700; }',
408
628
  '.dsh-mail-grid { display:flex; gap:12px; flex-wrap:wrap; }',
409
629
  '.dsh-mail-field { display:flex; flex-direction:column; gap:5px; flex:1; min-width:160px; margin-bottom:11px; }',
410
630
  '.dsh-mail-label { font-size:11px; font-weight:600; color:var(--dsw-alias-label-secondary); }',
411
631
  '.dsh-mail-input, .dsh-mail-textarea, .dsh-mail-selectinput { width:100%; border:1px solid var(--dsw-alias-border-l2); border-radius:8px; padding:8px 10px; background:var(--dsw-alias-bg-base); color:var(--dsw-alias-label-primary); font-size:13px; transition:border-color .12s, box-shadow .12s; }',
412
- '.dsh-mail-input:focus, .dsh-mail-textarea:focus, .dsh-mail-selectinput:focus { outline:none; border-color:var(--dsw-alias-brand-primary); box-shadow:0 0 0 3px color-mix(in srgb, var(--dsw-alias-brand-primary) 18%, transparent); }',
632
+ '.dsh-mail-input:focus, .dsh-mail-textarea:focus, .dsh-mail-selectinput:focus { outline:none; border-color:var(--dsw-alias-brand-primary); box-shadow:0 0 0 3px color-mix(in srgb, var(--dsw-alias-brand-primary) 16%, transparent); background:var(--dsw-alias-bg-layer-1); }',
413
633
  '.dsh-mail-textarea { min-height:200px; resize:vertical; line-height:1.6; }',
414
634
  '.dsh-mail-hint { font-size:11.5px; color:var(--dsw-alias-label-secondary); line-height:1.6; }',
415
635
 
@@ -437,7 +657,7 @@ window.__ModuleLoader__.load({
437
657
 
438
658
  /* empty & loading */
439
659
  '.dsh-mail-empty { display:flex; flex-direction:column; align-items:center; justify-content:center; gap:10px; padding:64px 28px; text-align:center; }',
440
- '.dsh-mail-emptyicon { width:56px; height:56px; border-radius:18px; display:grid; place-items:center; background:var(--dsw-alias-bg-layer-2); color:var(--dsw-alias-label-secondary); margin-bottom:4px; }',
660
+ '.dsh-mail-emptyicon { width:60px; height:60px; border-radius:20px; display:grid; place-items:center; background:color-mix(in srgb, var(--dsw-alias-brand-primary) 10%, var(--dsw-alias-bg-layer-2)); color:var(--dsw-alias-brand-primary); margin-bottom:4px; box-shadow:inset 0 1px 0 rgba(255,255,255,.06), 0 4px 14px rgba(0,0,0,.06); }',
441
661
  '.dsh-mail-emptytitle { font-size:14px; font-weight:650; color:var(--dsw-alias-label-primary); }',
442
662
  '.dsh-mail-emptysub { font-size:12px; color:var(--dsw-alias-label-secondary); max-width:320px; line-height:1.6; }',
443
663
  '.dsh-mail-loading { display:flex; flex-direction:column; align-items:center; justify-content:center; gap:12px; padding:56px 16px; color:var(--dsw-alias-label-secondary); animation:dsh-mail-fade .25s ease-out; }',
@@ -452,15 +672,18 @@ window.__ModuleLoader__.load({
452
672
  '@media (prefers-reduced-motion: reduce) { .dsh-mail-spinner, .dsh-mail-progress::after, .dsh-mail-loading, .dsh-mail-view { animation:none; } }',
453
673
 
454
674
  /* detail */
455
- '.dsh-mail-detailhead { padding:20px 4px 14px; border-bottom:1px solid var(--dsw-alias-border-l1); margin-bottom:16px; }',
456
- '.dsh-mail-detailtitle { margin:0 0 12px; font-size:20px; font-weight:650; line-height:1.4; }',
675
+ '.dsh-mail-detailhead { padding:22px 4px 16px; border-bottom:1px solid var(--dsw-alias-border-l1); margin-bottom:18px; }',
676
+ '.dsh-mail-detailtitle { margin:0 0 12px; font-size:21px; font-weight:700; line-height:1.4; letter-spacing:.2px; }',
457
677
  '.dsh-mail-detailfrom { display:flex; align-items:center; gap:10px; }',
458
678
  '.dsh-mail-detailfrom > div:nth-child(2) { flex:1; min-width:0; }',
459
679
  // A sender already in the address book keeps the button as a quiet state
460
680
  // marker instead of an action that would overwrite the saved name.
461
681
  '.dsh-mail-btn.is-done { color:var(--dsw-alias-state-success-primary); border-color:var(--dsw-alias-state-success-primary); }',
462
682
  '.dsh-mail-detailmeta { font-size:11.5px; color:var(--dsw-alias-label-secondary); margin-top:2px; }',
463
- '.dsh-mail-mailbody { width:100%; padding:18px; border:1px solid var(--dsw-alias-border-l1); border-radius:12px; background:var(--dsw-alias-bg-layer-1); color:var(--dsw-alias-label-primary); line-height:1.75; overflow-wrap:anywhere; word-break:break-word; }',
683
+ '.dsh-mail-detailtoolbar { display:flex; align-items:center; gap:8px; flex-wrap:wrap; margin-top:12px; }',
684
+ '.dsh-mail-mailbody { width:100%; padding:20px; border:1px solid var(--dsw-alias-border-l1); border-radius:14px; background:linear-gradient(180deg, var(--dsw-alias-bg-layer-1), var(--dsw-alias-bg-base)); color:var(--dsw-alias-label-primary); line-height:1.8; overflow-wrap:anywhere; word-break:break-word; box-shadow:inset 0 1px 0 rgba(255,255,255,.04), 0 2px 8px rgba(0,0,0,.04); }',
685
+ '.dsh-mail-translated { border-color:var(--dsw-alias-brand-primary); background:color-mix(in srgb, var(--dsw-alias-brand-primary) 7%, var(--dsw-alias-bg-layer-1)); }',
686
+ '.dsh-mail-translatednotice { display:flex; align-items:center; gap:6px; margin-bottom:10px; padding-bottom:10px; border-bottom:1px dashed var(--dsw-alias-border-l2); font-size:11px; color:var(--dsw-alias-label-secondary); }',
464
687
 
465
688
  // Third-party HTML: force theme colors so hardcoded mail colors (usually
466
689
  // white bg / dark text) never clash with the dark theme. Buttons and links
@@ -472,6 +695,13 @@ window.__ModuleLoader__.load({
472
695
  '.dsh-mail-html p, .dsh-mail-html div { margin:0 0 8px; }',
473
696
  '.dsh-mail-html table { max-width:100%; border-collapse:collapse; }',
474
697
  '.dsh-mail-html blockquote { margin:8px 0; padding-left:12px; border-left:3px solid var(--dsw-alias-border-l2) !important; }',
698
+ '.dsh-mail-modal-backdrop { position:fixed; inset:0; z-index:60; background:rgba(0,0,0,.5); display:flex; align-items:center; justify-content:center; padding:20px; }',
699
+ '.dsh-mail-modal { width:100%; max-width:480px; max-height:80vh; overflow:auto; background:var(--dsw-alias-bg-layer-1); border:1px solid var(--dsw-alias-border-l2); border-radius:14px; box-shadow:0 16px 48px rgba(0,0,0,.35); }',
700
+ '.dsh-mail-modal-head { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:16px 18px; border-bottom:1px solid var(--dsw-alias-border-l1); font-weight:700; color:var(--dsw-alias-label-primary); }',
701
+ '.dsh-mail-modal-body { padding:14px 18px 18px; }',
702
+ '.dsh-mail-hint { color:var(--dsw-alias-label-secondary); font-size:12px; line-height:1.6; margin-bottom:10px; }',
703
+ '.dsh-mail-vault-opt { display:flex; flex-direction:column; align-items:flex-start; gap:2px; width:100%; text-align:left; padding:10px 12px; border:1px solid var(--dsw-alias-border-l2); border-radius:9px; background:var(--dsw-alias-bg-layer-2); color:var(--dsw-alias-label-primary); cursor:pointer; margin-top:8px; }',
704
+ '.dsh-mail-vault-opt:hover { border-color:var(--dsw-alias-brand-primary); filter:brightness(.98); }',
475
705
  ].join('\n');
476
706
 
477
707
  const PRESETS = {
@@ -565,12 +795,17 @@ window.__ModuleLoader__.load({
565
795
  };
566
796
 
567
797
  // When the background poller detects new mail it publishes the affected
568
- // account ids here so an open MailPanel can refresh its list in place.
798
+ // account ids plus the freshly seen messages, so an open MailPanel can
799
+ // merge them into its list without re-running the same IMAP query.
569
800
  // Module scope because detection happens outside React, in the poller.
570
801
  const MAIL_EVENTS = {
571
802
  listeners: new Set(),
572
803
  subscribe(fn) { this.listeners.add(fn); return () => this.listeners.delete(fn); },
573
- emit(accountIds) { for (const fn of this.listeners) { try { fn(accountIds); } catch { /* dead listener */ } } },
804
+ emit(accountIds, freshByAccount) {
805
+ for (const fn of this.listeners) {
806
+ try { fn(accountIds, freshByAccount); } catch { /* dead listener */ }
807
+ }
808
+ },
574
809
  };
575
810
 
576
811
  // A mail that arrived while DSH was restarting must not be swallowed by
@@ -741,6 +976,7 @@ window.__ModuleLoader__.load({
741
976
  if (NOTIFY.busy) return Object.assign({}, NOTIFY.diag);
742
977
  NOTIFY.busy = true;
743
978
  const changedAccounts = [];
979
+ const freshByAccount = Object.create(null);
744
980
  try {
745
981
  const mode = NOTIFY.settings.notifyMode || 'pet';
746
982
  if (mode === 'system' && notifyPermission() !== 'granted') {
@@ -762,7 +998,9 @@ window.__ModuleLoader__.load({
762
998
  NOTIFY.diag.lastCheck = Date.now();
763
999
  NOTIFY.diag.error = null;
764
1000
  const now = Date.now();
765
- for (const acc of accounts) {
1001
+ // Check every account concurrently; previously a slow IMAP session on
1002
+ // one account delayed every other account's check behind it.
1003
+ await Promise.all(accounts.map(async acc => {
766
1004
  try {
767
1005
  const mr = await fetch(API, {
768
1006
  method: 'POST', headers: { 'content-type': 'application/json' },
@@ -771,36 +1009,24 @@ window.__ModuleLoader__.load({
771
1009
  const md = await mr.json();
772
1010
  if (!md || md.ok === false || !Array.isArray(md.messages)) {
773
1011
  NOTIFY.diag.error = 'listMessages:' + (acc.name || acc.id) + ':' + (md && md.error ? md.error : 'bad-response');
774
- continue;
1012
+ return;
775
1013
  }
776
1014
  const uids = md.messages.map(m => String(m.uid));
777
1015
  const prev = NOTIFY.baselines[acc.id];
778
1016
  NOTIFY.baselines[acc.id] = uids;
1017
+ let fresh = [];
779
1018
  if (!prev) {
780
1019
  // First observation: normally seed only, but a mail that arrived
781
1020
  // during a restart (unread + recent Date header) must still alert.
782
- const recent = md.messages.filter(m =>
1021
+ fresh = md.messages.filter(m =>
783
1022
  m && m.seen === false && m.date &&
784
1023
  (now - Date.parse(m.date)) >= 0 &&
785
1024
  (now - Date.parse(m.date)) <= RECENT_MAIL_MS
786
1025
  );
787
- if (recent.length === 0) continue;
788
- const latest = recent[0] || {};
789
- const who = acc.name ? acc.name + ':' : '';
790
- const res = await deliverAlert(
791
- t('notifyTitle'),
792
- who + (latest.subject || t('noSubject')) + ' · ' + recent.length + ' ' + t('notifyBody'),
793
- { tag: 'dsh-mail-new' }
794
- );
795
- NOTIFY.diag.alerts += 1;
796
- NOTIFY.diag.lastAlert = Date.now();
797
- BADGE.add(recent.length);
798
- changedAccounts.push(acc.id);
799
- if (!res.petOk && !res.sysOk) NOTIFY.diag.error = 'deliver:' + (NOTIFY.lastError || 'no-channel');
800
- continue;
1026
+ } else {
1027
+ const prevSet = new Set(prev);
1028
+ fresh = md.messages.filter(m => !prevSet.has(String(m.uid)));
801
1029
  }
802
- const prevSet = new Set(prev);
803
- const fresh = md.messages.filter(m => !prevSet.has(String(m.uid)));
804
1030
  if (fresh.length > 0) {
805
1031
  const latest = fresh[0] || {};
806
1032
  const who = acc.name ? acc.name + ':' : '';
@@ -813,18 +1039,21 @@ window.__ModuleLoader__.load({
813
1039
  NOTIFY.diag.lastAlert = Date.now();
814
1040
  BADGE.add(fresh.length);
815
1041
  changedAccounts.push(acc.id);
1042
+ // Hand the list we already fetched to the open panel so it can
1043
+ // update in place instead of issuing a second listMessages.
1044
+ freshByAccount[acc.id] = md.messages;
816
1045
  if (!res.petOk && !res.sysOk) NOTIFY.diag.error = 'deliver:' + (NOTIFY.lastError || 'no-channel');
817
1046
  }
818
1047
  } catch (e) {
819
1048
  NOTIFY.diag.error = 'account:' + (acc.name || acc.id) + ':' + (e && e.message ? e.message : String(e));
820
1049
  }
821
- }
1050
+ }));
822
1051
  } catch (e) {
823
1052
  NOTIFY.diag.error = 'poll:' + (e && e.message ? e.message : String(e));
824
1053
  } finally {
825
1054
  NOTIFY.busy = false;
826
1055
  }
827
- if (changedAccounts.length) MAIL_EVENTS.emit(changedAccounts);
1056
+ if (changedAccounts.length) MAIL_EVENTS.emit(changedAccounts, freshByAccount);
828
1057
  return Object.assign({}, NOTIFY.diag);
829
1058
  }
830
1059
 
@@ -919,6 +1148,7 @@ window.__ModuleLoader__.load({
919
1148
  plus: 'M12 5v14M5 12h14',
920
1149
  attach: 'M20 11.5l-8.2 8.2a4.5 4.5 0 0 1-6.4-6.4l8.5-8.5a3 3 0 0 1 4.3 4.3l-8.5 8.5a1.5 1.5 0 0 1-2.2-2.2l7.8-7.8',
921
1150
  download: 'M12 4v11m0 0l-4-4m4 4l4-4M4 19h16',
1151
+ translate: 'M12.9 15L8 20l-4-5h3.1a7 7 0 0 0 1.4-4H4v-2h5.1A11 11 0 0 0 11 3h2c-.6 1.7-1.5 3.2-2.7 4.5A9 9 0 0 1 17 11h2.9l-4.3 4.3m-2-2.3c-.6-2.2-2-4-3.9-5.3A9 9 0 0 1 18 9',
922
1152
  };
923
1153
  function Ico(props) {
924
1154
  // Rendered as a React component via h(Ico, { name, size }); the first
@@ -1040,14 +1270,46 @@ window.__ModuleLoader__.load({
1040
1270
  const [inboxFilter, setInboxFilter] = usePersistent('inboxFilter', 'all');
1041
1271
  const [messages, setMessages] = usePersistent('messages', []);
1042
1272
  const [detail, setDetail] = usePersistent('detail', null);
1273
+ // Translated body for the currently open message. Kept out of PERSIST:
1274
+ // translations are disposable and never written to profile storage.
1275
+ const [translatedText, setTranslatedText] = useState(null);
1276
+ const [translating, setTranslating] = useState(false);
1043
1277
  const [busy, setBusy] = useState(false);
1044
1278
  const [loadingMessages, setLoadingMessages] = useState(false);
1045
1279
  const [loadingSent, setLoadingSent] = useState(false);
1046
1280
  const [loadingContacts, setLoadingContacts] = useState(false);
1047
1281
  const [refreshState, setRefreshState] = useState('idle'); // idle | loading | ok | error
1048
1282
  const refreshTimerRef = useRef(null);
1283
+ // In-flight dedupe must survive re-renders; a plain let would reset every
1284
+ // time React re-rendered the panel and allow duplicate IMAP sessions.
1285
+ const inflightRef = useRef({ messages: null, sent: null, contacts: null });
1049
1286
  const [flash, setFlash] = useState(null);
1050
1287
  const [form, setForm] = usePersistent('form', { preset: 'qq', name: '', username: '', authCode: '', imapHost: PRESETS.qq.imapHost, imapPort: 993, smtpHost: PRESETS.qq.smtpHost, smtpPort: 465 });
1288
+ // Credential-vault bridge (no-op if the vault plugin is not installed).
1289
+ const vaultClientRef = useRef(null);
1290
+ if (!vaultClientRef.current) vaultClientRef.current = createVaultV1Client();
1291
+ const [vaultOpen, setVaultOpen] = useState(false);
1292
+ const [vaultEntries, setVaultEntries] = useState(null);
1293
+ const [vaultBusy, setVaultBusy] = useState(false);
1294
+ async function openVaultPicker() {
1295
+ setVaultOpen(true);
1296
+ setVaultEntries(null);
1297
+ setVaultBusy(true);
1298
+ try {
1299
+ const list = await vaultClientRef.current.query({ category: 'account', limit: 100 });
1300
+ setVaultEntries(list);
1301
+ } catch (e) {
1302
+ setVaultEntries([]);
1303
+ } finally {
1304
+ setVaultBusy(false);
1305
+ }
1306
+ }
1307
+ function pickVaultSecret(entry) {
1308
+ const value = vaultClientRef.current.secretOf(entry);
1309
+ setForm(function (f) { return Object.assign({}, f, { authCode: value }); });
1310
+ setVaultOpen(false);
1311
+ notify('success', t('saved'));
1312
+ }
1051
1313
  const [compose, setCompose] = usePersistent('compose', { to: '', subject: '', body: '' });
1052
1314
  // Outgoing attachments live in React state (not PERSIST): they hold base64
1053
1315
  // file bytes, which must not be written to profile storage.
@@ -1071,15 +1333,30 @@ window.__ModuleLoader__.load({
1071
1333
  // activeId/view. New mail on the currently open account refreshes the
1072
1334
  // inbox list in place (silent, no spinner/flash).
1073
1335
  const onMailRef = useRef(() => {});
1074
- onMailRef.current = (accountIds) => {
1336
+ onMailRef.current = (accountIds, freshByAccount) => {
1075
1337
  if (!activeId || view !== 'inbox') return;
1076
1338
  if (Array.isArray(accountIds) && accountIds.length && accountIds.indexOf(activeId) === -1) return;
1339
+ // The poller already fetched this account's list to detect the new
1340
+ // mail. Merge any new UIDs straight into state/cache instead of
1341
+ // opening a second IMAP session for the same data.
1342
+ const polled = freshByAccount && freshByAccount[activeId];
1343
+ const current = cache[activeId] || messages || [];
1344
+ if (Array.isArray(polled) && current.length) {
1345
+ const seen = new Set(current.map(m => String(m.uid)));
1346
+ const added = polled.filter(m => !seen.has(String(m.uid)));
1347
+ if (added.length) {
1348
+ const merged = added.concat(current);
1349
+ setMessages(merged);
1350
+ setCache(prev => Object.assign({}, prev, { [activeId]: merged }));
1351
+ }
1352
+ return;
1353
+ }
1077
1354
  void loadMessages(false);
1078
1355
  };
1079
1356
 
1080
1357
  useEffect(() => {
1081
1358
  if (!PERSIST.accounts) refreshAccounts();
1082
- const off = MAIL_EVENTS.subscribe(ids => onMailRef.current(ids));
1359
+ const off = MAIL_EVENTS.subscribe((ids, freshByAccount) => onMailRef.current(ids, freshByAccount));
1083
1360
  return () => {
1084
1361
  off();
1085
1362
  if (refreshTimerRef.current) clearTimeout(refreshTimerRef.current);
@@ -1162,55 +1439,90 @@ window.__ModuleLoader__.load({
1162
1439
 
1163
1440
  async function loadMessages(showProgress) {
1164
1441
  if (!activeId) return false;
1442
+ // Collapse overlapping refreshes (account switch vs. new-mail event)
1443
+ // into one request per account instead of opening duplicate sessions.
1444
+ const inflight = inflightRef.current;
1445
+ if (inflight.messages && inflight.messages.id === activeId) return inflight.messages.promise;
1165
1446
  // Cache-first: if we already have this account's list, keep it visible
1166
1447
  // while the fresh list loads in the background (no blank/Loading flash).
1167
1448
  const cached = cache[activeId];
1168
1449
  if (showProgress !== false) setLoadingMessages(!(cached && cached.length));
1450
+ const id = activeId;
1451
+ const promise = (async () => {
1452
+ try {
1453
+ const data = await rpc('listMessages', { id, limit: 25 });
1454
+ const fresh = data.messages || [];
1455
+ setMessages(fresh);
1456
+ setCache(prev => Object.assign({}, prev, { [id]: fresh }));
1457
+ return true;
1458
+ } catch (e) {
1459
+ reportError(e);
1460
+ return false;
1461
+ } finally {
1462
+ setLoadingMessages(false);
1463
+ }
1464
+ })();
1465
+ inflight.messages = { id, promise };
1169
1466
  try {
1170
- const data = await rpc('listMessages', { id: activeId, limit: 25 });
1171
- const fresh = data.messages || [];
1172
- setMessages(fresh);
1173
- setCache(prev => Object.assign({}, prev, { [activeId]: fresh }));
1174
- return true;
1175
- } catch (e) {
1176
- reportError(e);
1177
- return false;
1467
+ return await promise;
1178
1468
  } finally {
1179
- setLoadingMessages(false);
1469
+ if (inflight.messages && inflight.messages.id === id) inflight.messages = null;
1180
1470
  }
1181
1471
  }
1182
1472
 
1183
1473
  async function loadSent() {
1184
1474
  if (!activeId) return false;
1475
+ const inflight = inflightRef.current;
1476
+ if (inflight.sent && inflight.sent.id === activeId) return inflight.sent.promise;
1185
1477
  setBusy(true);
1186
1478
  setLoadingSent(true);
1479
+ const id = activeId;
1480
+ const promise = (async () => {
1481
+ try {
1482
+ const data = await rpc('sentMessages', { id });
1483
+ setSent(data.sent || []);
1484
+ return true;
1485
+ } catch (e) {
1486
+ reportError(e);
1487
+ return false;
1488
+ } finally {
1489
+ setLoadingSent(false);
1490
+ setBusy(false);
1491
+ }
1492
+ })();
1493
+ inflight.sent = { id, promise };
1187
1494
  try {
1188
- const data = await rpc('sentMessages', { id: activeId });
1189
- setSent(data.sent || []);
1190
- return true;
1191
- } catch (e) {
1192
- reportError(e);
1193
- return false;
1495
+ return await promise;
1194
1496
  } finally {
1195
- setLoadingSent(false);
1196
- setBusy(false);
1497
+ if (inflight.sent && inflight.sent.id === id) inflight.sent = null;
1197
1498
  }
1198
1499
  }
1199
1500
 
1200
1501
  async function loadContacts() {
1201
1502
  if (!activeId) return false;
1503
+ const inflight = inflightRef.current;
1504
+ if (inflight.contacts && inflight.contacts.id === activeId) return inflight.contacts.promise;
1202
1505
  setBusy(true);
1203
1506
  setLoadingContacts(true);
1507
+ const id = activeId;
1508
+ const promise = (async () => {
1509
+ try {
1510
+ const data = await rpc('listContacts', { id });
1511
+ setContacts(data.contacts || []);
1512
+ return true;
1513
+ } catch (e) {
1514
+ reportError(e);
1515
+ return false;
1516
+ } finally {
1517
+ setLoadingContacts(false);
1518
+ setBusy(false);
1519
+ }
1520
+ })();
1521
+ inflight.contacts = { id, promise };
1204
1522
  try {
1205
- const data = await rpc('listContacts', { id: activeId });
1206
- setContacts(data.contacts || []);
1207
- return true;
1208
- } catch (e) {
1209
- reportError(e);
1210
- return false;
1523
+ return await promise;
1211
1524
  } finally {
1212
- setLoadingContacts(false);
1213
- setBusy(false);
1525
+ if (inflight.contacts && inflight.contacts.id === id) inflight.contacts = null;
1214
1526
  }
1215
1527
  }
1216
1528
 
@@ -1234,10 +1546,8 @@ window.__ModuleLoader__.load({
1234
1546
  setSent([]);
1235
1547
  setContacts([]);
1236
1548
  setDetail(null);
1237
- PERSIST.loadedIds = { inbox: activeId, sent: activeId, contacts: activeId };
1549
+ PERSIST.loadedIds = { inbox: activeId, sent: '', contacts: '' };
1238
1550
  loadMessages();
1239
- loadSent();
1240
- loadContacts();
1241
1551
  }
1242
1552
  }, [activeId]);
1243
1553
 
@@ -1314,6 +1624,7 @@ window.__ModuleLoader__.load({
1314
1624
  const data = await rpc('getMessage', { id: activeId, uid });
1315
1625
  const full = data.message || data;
1316
1626
  setDetail(Object.assign({}, full, { seen: true }));
1627
+ setTranslatedText(null);
1317
1628
  setView('detail');
1318
1629
  } catch (e) {
1319
1630
  reportError(e);
@@ -1322,6 +1633,36 @@ window.__ModuleLoader__.load({
1322
1633
  }
1323
1634
  }
1324
1635
 
1636
+ // Translate the currently open message through the Host's `translate`
1637
+ // op. Prefer the plain-text part; fall back to stripping tags from the
1638
+ // sanitized HTML when the mail is HTML-only.
1639
+ async function translateMessage() {
1640
+ if (!detail || translating) return;
1641
+ const source = typeof detail.body === 'string' && detail.body.trim()
1642
+ ? detail.body
1643
+ : htmlToText(detail.html);
1644
+ if (!source.trim()) {
1645
+ notify('error', t('translateFailed') + t('errGeneric'));
1646
+ return;
1647
+ }
1648
+ setTranslating(true);
1649
+ try {
1650
+ const data = await rpc('translate', { text: source, targetLanguage: 'zh-CN' });
1651
+ setTranslatedText(String(data.text || ''));
1652
+ } catch (e) {
1653
+ const code = e && e.info && e.info.code;
1654
+ if (code === 'TRANSLATION_UNAVAILABLE') {
1655
+ notify('error', t('translateUnavailable'));
1656
+ } else if (code === 'TRANSLATION_TEXT_LIMIT') {
1657
+ notify('error', t('translateTextLimit'));
1658
+ } else {
1659
+ notify('error', t('translateFailed') + (e && e.message ? e.message : t('errGeneric')));
1660
+ }
1661
+ } finally {
1662
+ setTranslating(false);
1663
+ }
1664
+ }
1665
+
1325
1666
  async function sendMail() {
1326
1667
  setBusy(true);
1327
1668
  try {
@@ -1509,6 +1850,17 @@ window.__ModuleLoader__.load({
1509
1850
  function navTo(key) {
1510
1851
  setSentDetail(null);
1511
1852
  setView(key);
1853
+ // Sent/contacts are loaded on demand (first visit after an account
1854
+ // switch), so opening the mail panel no longer waits on three IMAP
1855
+ // sessions at once. Guard with PERSIST.loadedIds to avoid refetching
1856
+ // on every tab click or remount.
1857
+ if (key === 'sent' && activeId && PERSIST.loadedIds.sent !== activeId) {
1858
+ PERSIST.loadedIds.sent = activeId;
1859
+ loadSent();
1860
+ } else if (key === 'contacts' && activeId && PERSIST.loadedIds.contacts !== activeId) {
1861
+ PERSIST.loadedIds.contacts = activeId;
1862
+ loadContacts();
1863
+ }
1512
1864
  }
1513
1865
 
1514
1866
  return h('div', { className: 'dsh-mail' },
@@ -1759,7 +2111,10 @@ window.__ModuleLoader__.load({
1759
2111
  ),
1760
2112
  h('div', { className: 'dsh-mail-field' },
1761
2113
  h('span', { className: 'dsh-mail-label' }, t('authCode')),
1762
- h('input', { className: 'dsh-mail-input', type: 'password', value: form.authCode, onChange: e => setForm(Object.assign({}, form, { authCode: e.target.value })) })
2114
+ h('input', { className: 'dsh-mail-input', type: 'password', value: form.authCode, onChange: e => setForm(Object.assign({}, form, { authCode: e.target.value })) }),
2115
+ vaultClientRef.current.isAvailable()
2116
+ ? h('button', { className: 'dsh-mail-btn', type: 'button', style: { marginTop: 8 }, onClick: openVaultPicker }, h(Ico, { name: 'accounts', size: 15 }), t('fillFromVault'))
2117
+ : null
1763
2118
  ),
1764
2119
  h('div', { className: 'dsh-mail-grid' },
1765
2120
  h('div', { className: 'dsh-mail-field' },
@@ -1786,6 +2141,30 @@ window.__ModuleLoader__.load({
1786
2141
  )
1787
2142
  ),
1788
2143
 
2144
+ /* --------------------------- VAULT PICKER ---------------------------- */
2145
+ vaultOpen && h('div', { className: 'dsh-mail-modal-backdrop', onClick: () => setVaultOpen(false) },
2146
+ h('div', { className: 'dsh-mail-modal', onClick: e => e.stopPropagation() },
2147
+ h('div', { className: 'dsh-mail-modal-head' },
2148
+ h('span', null, t('vaultPickTitle')),
2149
+ h('button', { className: 'dsh-mail-btn', onClick: () => setVaultOpen(false) }, t('cancel'))
2150
+ ),
2151
+ h('div', { className: 'dsh-mail-modal-body' },
2152
+ h('div', { className: 'dsh-mail-hint' }, t('vaultPickHint')),
2153
+ vaultBusy ? h('div', { className: 'dsh-mail-hint' }, t('vaultPickLoading'))
2154
+ : (vaultEntries && vaultEntries.length === 0) ? h('div', { className: 'dsh-mail-hint' }, t('vaultPickEmpty'))
2155
+ : (vaultEntries || []).map(entry =>
2156
+ h('button', {
2157
+ key: entry.id, type: 'button', className: 'dsh-mail-vault-opt',
2158
+ onClick: () => pickVaultSecret(entry)
2159
+ },
2160
+ h('span', { style: { fontWeight: 650 } }, entry.title || '(untitled)'),
2161
+ h('span', { className: 'dsh-mail-hint' }, entry.username || entry.provider || '')
2162
+ )
2163
+ )
2164
+ )
2165
+ )
2166
+ ),
2167
+
1789
2168
  /* ------------------------------- DETAIL ----------------------------- */
1790
2169
  view === 'detail' && h('div', { className: 'dsh-mail-view' },
1791
2170
  h('div', { className: 'dsh-mail-scroll' },
@@ -1810,18 +2189,57 @@ window.__ModuleLoader__.load({
1810
2189
  : null
1811
2190
  )
1812
2191
  ),
1813
- h('div', {
1814
- className: 'dsh-mail-mailbody',
1815
- onClick: (e) => {
1816
- const a = e.target && e.target.closest && e.target.closest('a[href]');
1817
- if (!a) return;
1818
- const href = a.getAttribute('href');
1819
- if (!href) return;
1820
- e.preventDefault();
1821
- if (window.open) window.open(href, '_blank', 'noopener,noreferrer');
2192
+ h('div', { className: 'dsh-mail-detailtoolbar' },
2193
+ h('button', {
2194
+ className: 'dsh-mail-btn',
2195
+ type: 'button',
2196
+ 'data-testid': 'translate-mail',
2197
+ onClick: () => void translateMessage(),
2198
+ disabled: translating || busy,
2199
+ title: t('translate'),
1822
2200
  },
1823
- dangerouslySetInnerHTML: { __html: detail.html || ('<div style="white-space:pre-wrap">' + escHtml(detail.body || '') + '</div>') },
1824
- }),
2201
+ h(Ico, { name: 'translate', size: 14 }),
2202
+ translating ? t('translating') : t('translate')
2203
+ ),
2204
+ translatedText !== null
2205
+ ? h('button', {
2206
+ className: 'dsh-mail-btn',
2207
+ type: 'button',
2208
+ onClick: () => setTranslatedText(null),
2209
+ title: t('translateShowOriginal'),
2210
+ }, h(Ico, { name: 'back', size: 14 }), t('translateShowOriginal'))
2211
+ : null
2212
+ ),
2213
+ translatedText !== null
2214
+ ? h('div', null,
2215
+ h('div', {
2216
+ className: 'dsh-mail-mailbody dsh-mail-translated',
2217
+ onClick: (e) => {
2218
+ const a = e.target && e.target.closest && e.target.closest('a[href]');
2219
+ if (!a) return;
2220
+ const href = a.getAttribute('href');
2221
+ if (!href) return;
2222
+ e.preventDefault();
2223
+ if (window.open) window.open(href, '_blank', 'noopener,noreferrer');
2224
+ },
2225
+ },
2226
+ h('div', { className: 'dsh-mail-translatednotice' }, h(Ico, { name: 'translate', size: 13 }), t('translatedNotice')),
2227
+ h('div', { style: { whiteSpace: 'pre-wrap' } }, translatedText || t('noMessages'))
2228
+ ),
2229
+ h('div', { style: { height: 14 } })
2230
+ )
2231
+ : h('div', {
2232
+ className: 'dsh-mail-mailbody',
2233
+ onClick: (e) => {
2234
+ const a = e.target && e.target.closest && e.target.closest('a[href]');
2235
+ if (!a) return;
2236
+ const href = a.getAttribute('href');
2237
+ if (!href) return;
2238
+ e.preventDefault();
2239
+ if (window.open) window.open(href, '_blank', 'noopener,noreferrer');
2240
+ },
2241
+ dangerouslySetInnerHTML: { __html: detail.html || ('<div style="white-space:pre-wrap">' + escHtml(detail.body || '') + '</div>') },
2242
+ }),
1825
2243
  // Attachments are fetched on demand so opening a mail stays fast.
1826
2244
  Array.isArray(detail.attachments) && detail.attachments.length > 0
1827
2245
  ? h('div', { className: 'dsh-mail-field', style: { marginTop: 14 } },
@@ -1924,6 +2342,42 @@ window.__ModuleLoader__.load({
1924
2342
  // half stores it in the credential store), so this toggle and the AI tool
1925
2343
  // share one host-owned value without depending on configForms, which is not
1926
2344
  // available on this DSH build.
2345
+ // Scoped stylesheet for the Settings-panel section. The mail panel's CSS
2346
+ // lives under .dsh-mail; the settings shell renders outside that tree, so
2347
+ // this section carries its own prefixed stylesheet (same design language:
2348
+ // soft gradients, 9/14px radii, hover/active/focus states, theme tokens).
2349
+ const SETTINGS_CSS = [
2350
+ '.dsh-mail-set { padding:4px; max-width:560px; color:var(--dsw-alias-label-primary); font-size:13px; line-height:1.55; -webkit-font-smoothing:antialiased; }',
2351
+ '.dsh-mail-set * { box-sizing:border-box; }',
2352
+ '.dsh-mail-set h2 { margin:0 0 8px; font-size:18px; font-weight:700; line-height:1.4; letter-spacing:.2px; }',
2353
+ '.dsh-mail-set h3 { margin:24px 0 8px; padding-top:18px; border-top:1px solid var(--dsw-alias-border-l1); font-size:15px; font-weight:650; line-height:1.4; }',
2354
+ '.dsh-mail-set p { margin:0 0 12px; font-size:13px; line-height:1.7; color:var(--dsw-alias-label-secondary); }',
2355
+ '.dsh-mail-set label { display:flex; align-items:center; gap:10px; cursor:pointer; font-size:14px; line-height:1.5; color:var(--dsw-alias-label-primary); }',
2356
+ '.dsh-mail-set label.dsh-mail-set-gap { margin-top:10px; }',
2357
+ '.dsh-mail-set input[type="checkbox"] { width:16px; height:16px; flex:none; accent-color:var(--dsw-alias-brand-primary); cursor:pointer; }',
2358
+ '.dsh-mail-set input[type="number"], .dsh-mail-set select { width:84px; padding:5px 8px; border:1px solid var(--dsw-alias-border-l2); border-radius:8px; background:var(--dsw-alias-bg-layer-1); color:var(--dsw-alias-label-primary); font-size:13px; font-family:inherit; transition:border-color .12s, box-shadow .12s; }',
2359
+ '.dsh-mail-set input[type="number"]:focus, .dsh-mail-set select:focus { outline:none; border-color:var(--dsw-alias-brand-primary); box-shadow:0 0 0 3px color-mix(in srgb, var(--dsw-alias-brand-primary) 16%, transparent); }',
2360
+ '.dsh-mail-set input:disabled, .dsh-mail-set select:disabled { opacity:.6; cursor:not-allowed; }',
2361
+ '.dsh-mail-set .dsh-mail-set-btn { display:inline-flex; align-items:center; justify-content:center; gap:6px; padding:6px 16px; border:1px solid var(--dsw-alias-border-l2); border-radius:9px; background:var(--dsw-alias-bg-layer-2); color:var(--dsw-alias-label-primary); font-size:13px; font-weight:600; font-family:inherit; cursor:pointer; transition:filter .15s, transform .08s, box-shadow .15s, border-color .15s; }',
2362
+ '.dsh-mail-set .dsh-mail-set-btn:hover:not(:disabled) { filter:brightness(.97); border-color:var(--dsw-alias-brand-primary); box-shadow:0 2px 8px rgba(0,0,0,.08); }',
2363
+ '.dsh-mail-set .dsh-mail-set-btn:active:not(:disabled) { transform:translateY(1px); box-shadow:inset 0 2px 5px rgba(0,0,0,.12); }',
2364
+ '.dsh-mail-set .dsh-mail-set-btn:focus-visible { outline:2px solid var(--dsw-alias-brand-primary); outline-offset:2px; }',
2365
+ '.dsh-mail-set .dsh-mail-set-btn:disabled { opacity:.5; cursor:not-allowed; }',
2366
+ '.dsh-mail-set .dsh-mail-set-btn-primary { background:linear-gradient(135deg, color-mix(in srgb, var(--dsw-alias-brand-primary) 82%, white), var(--dsw-alias-brand-primary)); border-color:transparent; color:var(--dsw-alias-bg-base); box-shadow:0 3px 10px color-mix(in srgb, var(--dsw-alias-brand-primary) 32%, transparent); }',
2367
+ '.dsh-mail-set .dsh-mail-set-btn-primary:hover:not(:disabled) { filter:brightness(1.06); box-shadow:0 5px 14px color-mix(in srgb, var(--dsw-alias-brand-primary) 40%, transparent); }',
2368
+ '.dsh-mail-set .dsh-mail-set-row { display:flex; align-items:center; gap:10px; flex-wrap:wrap; margin-top:14px; }',
2369
+ '.dsh-mail-set .dsh-mail-set-card { margin-top:14px; padding:12px; border:1px solid var(--dsw-alias-border-l1); border-radius:14px; background:linear-gradient(180deg, var(--dsw-alias-bg-layer-1), var(--dsw-alias-bg-base)); box-shadow:0 2px 10px rgba(0,0,0,.05), inset 0 1px 0 rgba(255,255,255,.04); }',
2370
+ '.dsh-mail-set .dsh-mail-set-cardhead { display:flex; align-items:center; gap:10px; flex-wrap:wrap; }',
2371
+ '.dsh-mail-set .dsh-mail-spacer { flex:1; min-width:0; }',
2372
+ '.dsh-mail-set .dsh-mail-set-meta { margin-top:6px; font-size:12px; line-height:1.7; color:var(--dsw-alias-label-secondary); }',
2373
+ '.dsh-mail-set .dsh-mail-set-meta.is-ok { color:var(--dsw-alias-state-success-primary); }',
2374
+ '.dsh-mail-set .dsh-mail-set-meta.is-error { color:var(--dsw-alias-state-error-primary); }',
2375
+ '.dsh-mail-set p.dsh-mail-set-note { margin:8px 0 0; font-size:12px; line-height:1.6; }',
2376
+ '.dsh-mail-set p.dsh-mail-set-note.is-ok { color:var(--dsw-alias-state-success-primary); }',
2377
+ '.dsh-mail-set p.dsh-mail-set-note.is-error { color:var(--dsw-alias-state-error-primary); }',
2378
+ '@media (prefers-reduced-motion: reduce) { .dsh-mail-set .dsh-mail-set-btn { transition:none; } }',
2379
+ ].join('\n');
2380
+
1927
2381
  function MailSettingsSection(props) {
1928
2382
  const tr = props && props.t ? props.t : t;
1929
2383
  const [draft, setDraft] = useState({ agentMailAccess: false, notifyEnabled: true, notifyInterval: 60, notifyMode: 'pet' });
@@ -2088,64 +2542,51 @@ window.__ModuleLoader__.load({
2088
2542
  setChecking(false);
2089
2543
  };
2090
2544
 
2091
- const field = {
2092
- display: 'flex', alignItems: 'center', gap: 10, cursor: 'pointer',
2093
- fontSize: 14, lineHeight: 1.5, color: 'var(--dsw-alias-label-primary)',
2094
- };
2095
- const hint = { margin: '6px 0 0', fontSize: 12, lineHeight: 1.6, color: 'var(--dsw-alias-label-secondary)' };
2096
- const numInput = {
2097
- width: 84, padding: '4px 8px', borderRadius: 6, fontSize: 13,
2098
- border: '1px solid var(--dsw-alias-border-l2)',
2099
- background: 'var(--dsw-alias-bg-layer-1)', color: 'var(--dsw-alias-label-primary)',
2100
- };
2101
2545
  const dirty = JSON.stringify(draft) !== JSON.stringify(stored);
2102
2546
  // In pure system-notification mode, hide all pet-related copy.
2103
2547
  const isSystemOnly = (draft.notifyMode || 'pet') === 'system';
2104
- return h('div', { style: { padding: 4, maxWidth: 560 } },
2105
- h('h2', { style: { margin: '0 0 8px', fontSize: 18, lineHeight: 1.4 } }, tr('settingsTitle')),
2548
+ return h('div', { className: 'dsh-mail-set' },
2549
+ h('style', null, SETTINGS_CSS),
2550
+ h('h2', null, tr('settingsTitle')),
2106
2551
 
2107
2552
  // AI assistant access toggle (unchanged behaviour).
2108
- h('p', { style: { margin: '0 0 12px', fontSize: 13, lineHeight: 1.7, color: 'var(--dsw-alias-label-secondary)' } }, tr('settingsDescription')),
2109
- h('label', { htmlFor: 'settings-dsh-mail-agent-access', style: field },
2553
+ h('p', null, tr('settingsDescription')),
2554
+ h('label', { htmlFor: 'settings-dsh-mail-agent-access' },
2110
2555
  h('input', {
2111
2556
  id: 'settings-dsh-mail-agent-access', type: 'checkbox',
2112
2557
  checked: draft.agentMailAccess, disabled: saving || !loaded,
2113
2558
  onChange: (e) => setDraft({ ...draft, agentMailAccess: !!(e && e.target && e.target.checked) }),
2114
- style: { width: 16, height: 16, accentColor: 'var(--dsw-alias-brand-primary)', cursor: 'pointer' },
2115
2559
  }),
2116
2560
  tr('agentMailAccessLabel')
2117
2561
  ),
2118
- h('p', { style: hint }, tr('agentMailAccessHint')),
2562
+ h('p', null, tr('agentMailAccessHint')),
2119
2563
 
2120
2564
  // New-mail notification section.
2121
- h('h3', { style: { margin: '24px 0 8px', fontSize: 15, lineHeight: 1.4 } }, tr('notifySectionTitle')),
2122
- h('p', { style: { margin: '0 0 12px', fontSize: 13, lineHeight: 1.7, color: 'var(--dsw-alias-label-secondary)' } }, tr(isSystemOnly ? 'notifySectionHintSystem' : 'notifySectionHint')),
2123
- h('label', { htmlFor: 'settings-dsh-mail-notify', style: field },
2565
+ h('h3', null, tr('notifySectionTitle')),
2566
+ h('p', null, tr(isSystemOnly ? 'notifySectionHintSystem' : 'notifySectionHint')),
2567
+ h('label', { htmlFor: 'settings-dsh-mail-notify' },
2124
2568
  h('input', {
2125
2569
  id: 'settings-dsh-mail-notify', type: 'checkbox',
2126
2570
  checked: draft.notifyEnabled, disabled: saving || !loaded,
2127
2571
  onChange: (e) => setDraft({ ...draft, notifyEnabled: !!(e && e.target && e.target.checked) }),
2128
- style: { width: 16, height: 16, accentColor: 'var(--dsw-alias-brand-primary)', cursor: 'pointer' },
2129
2572
  }),
2130
2573
  tr(isSystemOnly ? 'notifyEnabledLabelSystem' : 'notifyEnabledLabel')
2131
2574
  ),
2132
- h('label', { htmlFor: 'settings-dsh-mail-interval', style: { ...field, marginTop: 10 } },
2575
+ h('label', { htmlFor: 'settings-dsh-mail-interval', className: 'dsh-mail-set-gap' },
2133
2576
  h('span', null, tr('notifyIntervalLabel')),
2134
2577
  h('input', {
2135
2578
  id: 'settings-dsh-mail-interval', type: 'number', min: 15, max: 3600,
2136
2579
  value: draft.notifyInterval, disabled: saving || !loaded,
2137
2580
  onChange: (e) => setDraft({ ...draft, notifyInterval: Number(e && e.target && e.target.value) || 60 }),
2138
- style: numInput,
2139
2581
  })
2140
2582
  ),
2141
- h('label', { htmlFor: 'settings-dsh-mail-mode', style: { ...field, marginTop: 10 } },
2583
+ h('label', { htmlFor: 'settings-dsh-mail-mode', className: 'dsh-mail-set-gap' },
2142
2584
  h('span', null, tr('notifyMode')),
2143
2585
  h('select', {
2144
2586
  id: 'settings-dsh-mail-mode',
2145
2587
  value: draft.notifyMode || 'pet',
2146
2588
  disabled: saving || !loaded,
2147
2589
  onChange: (e) => setDraft({ ...draft, notifyMode: (e && e.target && e.target.value) || 'pet' }),
2148
- style: numInput,
2149
2590
  },
2150
2591
  h('option', { value: 'pet' }, tr('notifyModePet')),
2151
2592
  h('option', { value: 'system' }, tr('notifyModeSystem')),
@@ -2154,92 +2595,68 @@ window.__ModuleLoader__.load({
2154
2595
  ),
2155
2596
 
2156
2597
  // Permission row.
2157
- h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap', marginTop: 14 } },
2598
+ h('div', { className: 'dsh-mail-set-row' },
2158
2599
  h('button', {
2159
- type: 'button', disabled: asking || perm === 'granted' || perm === 'unsupported',
2600
+ type: 'button', className: 'dsh-mail-set-btn',
2601
+ disabled: asking || perm === 'granted' || perm === 'unsupported',
2160
2602
  onClick: () => { void requestPerm(); },
2161
- style: {
2162
- padding: '6px 16px', borderRadius: 6, border: '1px solid var(--dsw-alias-border-l2)',
2163
- background: 'var(--dsw-alias-bg-layer-1)', color: 'var(--dsw-alias-label-primary)',
2164
- fontSize: 13, cursor: asking || perm === 'granted' ? 'default' : 'pointer',
2165
- opacity: asking || perm === 'granted' ? 0.6 : 1,
2166
- },
2167
2603
  }, asking ? tr('notifyPermissionAsking') : tr('notifyPermission')),
2168
- h('span', { style: { fontSize: 12, color: 'var(--dsw-alias-label-secondary)' } },
2604
+ h('span', null,
2169
2605
  perm === 'granted' ? tr('notifyPermissionGranted')
2170
2606
  : perm === 'denied' ? tr('notifyPermissionDenied')
2171
2607
  : perm === 'unsupported' ? tr('notifyPermissionUnsupported') : ''
2172
2608
  ),
2173
2609
  h('button', {
2174
- type: 'button', disabled: asking,
2610
+ type: 'button', className: 'dsh-mail-set-btn dsh-mail-set-btn-primary',
2611
+ disabled: asking,
2175
2612
  onClick: () => { void sendTest(); },
2176
- style: {
2177
- padding: '6px 16px', borderRadius: 6, border: 'none',
2178
- background: 'var(--dsw-alias-brand-primary)', color: 'var(--dsw-alias-bg-base)',
2179
- fontSize: 13, cursor: asking ? 'default' : 'pointer',
2180
- opacity: asking ? 0.5 : 1,
2181
- },
2182
2613
  }, tr('notifyTest'))
2183
2614
  ),
2184
2615
  testMsg ? h('p', {
2185
- style: { ...hint, color: tested ? 'var(--dsw-alias-state-success-primary)' : 'var(--dsw-alias-state-error-primary)' },
2616
+ className: 'dsh-mail-set-note ' + (tested ? 'is-ok' : 'is-error'),
2186
2617
  }, testMsg) : null,
2187
2618
 
2188
2619
  // Live detection diagnostics + manual check. These make the otherwise
2189
2620
  // invisible background chain observable to the user and to us.
2190
- h('div', { style: { marginTop: 14, padding: 10, borderRadius: 6, background: 'var(--dsw-alias-bg-layer-1)', border: '1px solid var(--dsw-alias-border-l2)' } },
2191
- h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap' } },
2192
- h('strong', { style: { fontSize: 13, color: 'var(--dsw-alias-label-primary)' } }, tr('notifyDiagTitle')),
2193
- h('span', { style: { fontSize: 12, color: diag.running ? 'var(--dsw-alias-state-success-primary)' : 'var(--dsw-alias-state-error-primary)' } },
2621
+ h('div', { className: 'dsh-mail-set-card' },
2622
+ h('div', { className: 'dsh-mail-set-cardhead' },
2623
+ h('strong', null, tr('notifyDiagTitle')),
2624
+ h('span', { className: diag.running ? 'dsh-mail-set-meta is-ok' : 'dsh-mail-set-meta is-error' },
2194
2625
  diag.running ? tr('notifyDiagRunning') : tr('notifyDiagStopped')),
2195
2626
  h('span', { className: 'dsh-mail-spacer' }),
2196
2627
  h('button', {
2197
- type: 'button', disabled: checking || !loaded,
2628
+ type: 'button', className: 'dsh-mail-set-btn',
2629
+ disabled: checking || !loaded,
2198
2630
  onClick: () => { void checkNow(); },
2199
- style: {
2200
- padding: '5px 12px', borderRadius: 6, border: '1px solid var(--dsw-alias-border-l2)',
2201
- background: 'var(--dsw-alias-bg-base)', color: 'var(--dsw-alias-label-primary)',
2202
- fontSize: 12, cursor: checking || !loaded ? 'default' : 'pointer',
2203
- opacity: checking || !loaded ? 0.6 : 1,
2204
- },
2205
2631
  }, checking ? tr('notifyChecking') : tr('notifyCheckNow'))
2206
2632
  ),
2207
- h('div', { style: { marginTop: 6, fontSize: 12, lineHeight: 1.7, color: 'var(--dsw-alias-label-secondary)' } },
2633
+ h('div', { className: 'dsh-mail-set-meta' },
2208
2634
  tr('notifyDiagAccounts') + ': ' + (diag.accounts || 0) + ' · ' +
2209
2635
  tr('notifyDiagChecks') + ': ' + (diag.checks || 0) + ' · ' +
2210
2636
  tr(isSystemOnly ? 'notifyDiagAlertsSystem' : 'notifyDiagAlerts') + ': ' + (diag.alerts || 0) + ' · ' +
2211
2637
  tr('notifyDiagLastCheck') + ': ' + (diag.lastCheck ? new Date(diag.lastCheck).toLocaleString() : tr('notifyDiagNever'))
2212
2638
  ),
2213
- h('div', { style: { marginTop: 2, fontSize: 12, lineHeight: 1.7, color: diag.error ? 'var(--dsw-alias-state-error-primary)' : 'var(--dsw-alias-state-success-primary)' } },
2639
+ h('div', { className: 'dsh-mail-set-meta ' + (diag.error ? 'is-error' : 'is-ok') },
2214
2640
  tr('notifyDiagError') + ': ' + (diag.error || tr('notifyDiagOk'))
2215
2641
  ),
2216
- checkMsg ? h('p', { style: { margin: '6px 0 0', fontSize: 12, color: 'var(--dsw-alias-label-secondary)' } }, checkMsg) : null
2642
+ checkMsg ? h('p', { className: 'dsh-mail-set-note' }, checkMsg) : null
2217
2643
  ),
2218
2644
 
2219
2645
  failed
2220
- ? h('p', { style: { margin: '8px 0 0', fontSize: 12, color: 'var(--dsw-alias-state-error-primary)' } }, tr('settingsSaveFailed') + (saveError ? ' (' + saveError + ')' : ''))
2646
+ ? h('p', { className: 'dsh-mail-set-note is-error' }, tr('settingsSaveFailed') + (saveError ? ' (' + saveError + ')' : ''))
2221
2647
  : saved
2222
- ? h('p', { style: { margin: '8px 0 0', fontSize: 12, color: 'var(--dsw-alias-state-success-primary)' } }, tr('settingsSaveSuccess'))
2648
+ ? h('p', { className: 'dsh-mail-set-note is-ok' }, tr('settingsSaveSuccess'))
2223
2649
  : null,
2224
- h('div', { style: { display: 'flex', gap: 8, marginTop: 16 } },
2650
+ h('div', { className: 'dsh-mail-set-row' },
2225
2651
  h('button', {
2226
- type: 'button',
2652
+ type: 'button', className: 'dsh-mail-set-btn dsh-mail-set-btn-primary',
2227
2653
  disabled: !dirty || saving,
2228
2654
  onClick: () => { void save(); },
2229
- style: {
2230
- padding: '6px 16px', borderRadius: 6, border: 'none', cursor: dirty && !saving ? 'pointer' : 'default',
2231
- background: 'var(--dsw-alias-brand-primary)', color: 'var(--dsw-alias-bg-base)', fontSize: 13,
2232
- opacity: dirty && !saving ? 1 : 0.5,
2233
- },
2234
2655
  }, saving ? tr('settingsSaving') : tr('settingsSave')),
2235
2656
  dirty ? h('button', {
2236
- type: 'button',
2657
+ type: 'button', className: 'dsh-mail-set-btn',
2237
2658
  disabled: saving,
2238
2659
  onClick: () => setDraft(stored),
2239
- style: {
2240
- padding: '6px 16px', borderRadius: 6, border: '1px solid var(--dsw-alias-border-l2)',
2241
- background: 'transparent', color: 'var(--dsw-alias-label-primary)', fontSize: 13, cursor: 'pointer',
2242
- },
2243
2660
  }, tr('cancel')) : null
2244
2661
  )
2245
2662
  );