dsh-email 0.14.1 → 0.14.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.14.4(2026-09-29)
4
+
5
+ - 修复:SMTP 发送改为**每次发送独占连接**,取消(AbortSignal)时只销毁本次连接的 socket 并立即拒绝,不再影响同账号的其它发送,也不会在取消后仍把邮件发出去。
6
+ - 修复:OAuth2 令牌刷新与取消的竞态——取消后即使令牌刷新成功也不再继续发送。
7
+ - 测试:修正 TLS fixture 的两处握手缺陷(STARTTLS 明文阶段未发送 220;取消用例把 greeting 压住导致走不到 TLS 升级),TLS 与取消回归现可稳定通过(285 项)。
8
+ ## 0.14.3(2026-09-28)
9
+
10
+ - 兼容验证更新到 Harness 0.2.0-rc.1:282 项邮件测试与 18 插件共同加载检查通过。
11
+ - 运行时代码未变;同步中英文兼容性声明。
12
+
13
+ ## 0.14.2(2026-09-28)
14
+
15
+ - 修复 [#17](https://github.com/STARDUSTLC666/dsh-email/issues/17):空主机配合未修改的表单默认端口/TLS 不再覆盖服务商预设;Outlook 恢复 587/STARTTLS。旧设置转换和 Harness 0.1.7 已迁移配置共用归一化规则,保留自定义主机、非默认组合和不含占位 host 的显式端口覆盖。
16
+ - 感谢 [SenkjM 的 PR #18](https://github.com/STARDUSTLC666/dsh-email/pull/18) 提供复现与修复方向。本次补齐新版运行时路径并避免误删明确的端口设置;282 项邮件测试通过。配置和界面验证不代表真实 SMTP 投递已验证。
17
+
3
18
  ## 0.14.1(2026-09-27)
4
19
 
5
20
  - 未补全的账号和服务器预设会显示未保存提示;避免草稿丢失和错误的“已保存”状态。测试连接只校验所选账号,错误直接指向设置页中的对应字段。
package/README.en.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # dsh-email
2
2
 
3
- ## 0.14.1 update (2026-09-27)
3
+ ## 0.14.2 update (2026-09-28)
4
4
 
5
- Incomplete account and server-preset drafts display an unsaved status and are protected against accidental navigation. Connection tests validate the selected account independently and identify the relevant settings field.
5
+ Fixes saved blank-host defaults overriding Outlook's 587/STARTTLS preset, including legacy settings migrated to Harness 0.1.7. Explicit custom hosts, ports and TLS choices remain effective. Thanks to [SenkjM for the reproduction and proposed fix in #17 / #18](https://github.com/STARDUSTLC666/dsh-email/pull/18).
6
6
 
7
- Validation host: Harness 0.1.7-rc.2 built from official sources, retaining the local tool-scheduler fix. Build and automated checks pass; interactive coverage and external-service limits are recorded in this release round.
7
+ Validation host: Harness `0.2.0-rc.1` built from official sources (commit `407e65c8`) with Node `24.16.0` on 2026-09-28. All 282 plugin tests pass in an isolated environment; all 18 plugins mount together in one host registering 10 tools, with tool schemas and health-check contracts passing. No live ports or external services were exercised in this round.
8
8
 
9
9
  ![npm](https://img.shields.io/npm/v/dsh-email) ![downloads](https://img.shields.io/npm/dm/dsh-email) ![license](https://img.shields.io/github/license/STARDUSTLC666/dsh-email) ![stars](https://img.shields.io/github/stars/STARDUSTLC666/dsh-email?style=social)
10
10
 
@@ -53,11 +53,7 @@ Example:
53
53
  - **0.10.8 and earlier**: see [CHANGELOG.md](CHANGELOG.md).
54
54
  ## Compatibility
55
55
 
56
- The current baseline is official-source Harness **0.1.7-alpha.2** (2026-09-23, with a local `Symbol.for` tool-scheduler fix). All 18 plugins load together. Legacy migration, editing and automatic saving in the real Web UI, refresh, revision conflicts and restart persistence have been checked with isolated fixture accounts. No live mailbox connection or sending was exercised in this round.
57
-
58
- 2026-09-21: the current release package was installed through the official CLI in an isolated profile and co-loaded with the other two most-downloaded plugins on source-built Harness `0.1.6-alpha.2`. All 18 plugin tools registered; calendar/email configuration checks, PPT theme listing and 17-row table generation passed. The host is based on the official alpha.2 release plus the tool-scheduler `Symbol.for` fix (`93badd88`). This run did not connect to live mail or calendar services.
59
-
60
- Co-load verification was performed on 2026-09-16 with official source builds of Harness `0.1.5-rc.2` and `0.1.6-alpha.1`: all 18 components load alongside ModLens, with passing tool schemas, skill registration and offline read-only calls.
56
+ The current baseline is official-source Harness **0.2.0-rc.1** (2026-09-28, with a local `Symbol.for` tool-scheduler fix). All 18 plugins load together. Settings coverage includes legacy migration, real Web UI editing and automatic saving, refresh, revision conflicts and restart persistence with isolated fixture accounts. No live mailbox connection or sending was exercised in this round.
61
57
 
62
58
  **0.11.0 co-load verification (2026-09-18, locally built Harness `0.1.5-rc.2`, `web` profile)**: the plugin mounted without errors; the settings route answered GET with 200 and no `raw` field in the response; a `text/plain` POST was refused with **415**, proving the same-origin guard holds in the real host; under a `application/json` POST the card projection was correct, and an account pinning `authKind: password` reported both `authKindDeclared` and `authKind` as `password`; the panel actually rendered account cards, the eight provider presets with localized labels, the three-way authentication selector, the application (client) ID field with its hint, the missing-ID warning banner (so `--dsw-alias-state-warn-primary` is genuinely defined in the real host) and the Sign in with Microsoft button; the browser console was clean; save worked end to end, and afterwards `accountsYaml` was restored to empty with the original account intact. Offline tests: 231 green. **Still not done**: an end-to-end OAuth2 run against a real Outlook tenant (the device-code flow needs a human to authorize in a browser) and real sending; the `clientId` paths are covered only against a fake authority. Uses the `cordis.patch.yml` + `dsh.bundle.patch` bundle model. Node requirements are 22.19 or later within 22.x, or 24 or later. Live external-service workflows require separate configuration and validation.
63
59
 
package/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  # dsh-email
4
4
 
5
- ## 0.14.1 更新(2026-09-27)
5
+ ## 0.14.2 更新(2026-09-28)
6
6
 
7
- 未补全的账号和服务器预设会显示未保存提示;避免草稿丢失和错误的“已保存”状态。测试连接只校验所选账号,错误直接指向设置页中的对应字段。
7
+ 修复保存过的空服务器默认值覆盖 Outlook 预设的问题:恢复 `587 / STARTTLS`,并覆盖 Harness 0.1.7 的旧配置迁移路径。明确设置的自定义主机、端口和 TLS 仍然生效。感谢 [SenkjM 在 #17 / #18 提供复现和修复方向](https://github.com/STARDUSTLC666/dsh-email/pull/18)。
8
8
 
9
- 验证宿主:官方源码构建的 Harness 0.1.7-rc.2(保留本地工具调度器修复)。构建与自动测试通过;实际操作和外部服务限制见本轮验收记录。
9
+ 验证宿主:官方源码构建的 Harness `0.2.0-rc.1`(commit `407e65c8`)+ Node `24.16.0`(2026-09-28)。282 项插件测试在隔离环境全部通过;同一个宿主里 18 个插件共同加载,注册 10 个工具,工具 schema 与健康检查契约通过。本轮未启用真实端口与外部服务。
10
10
 
11
11
  > **让 agent 协助处理邮件**:收发、搜索、回复转发、附件、邮件整理与新邮件提醒,支持八种常见邮箱服务预设。
12
12
 
@@ -61,16 +61,10 @@ IMAP/SMTP email tools for DeepSeek Harness, with replies, forwarding, mailbox or
61
61
  - **0.10.8 及更早**:见 [CHANGELOG.md](CHANGELOG.md)。
62
62
  ## 兼容性
63
63
 
64
- 当前验证基线为官方源码构建的 Harness **0.1.7-alpha.2**(2026-09-23,含本地工具调度器 `Symbol.for` 修复)。18 个插件共同加载;邮件设置已通过旧配置迁移、真实网页编辑与自动保存、刷新恢复、修订冲突和重启持久化检查。本轮使用隔离测试账号,未连接真实邮箱或发送邮件。
65
-
66
- 2026-09-21:当前发布包经官方 CLI 安装到隔离 profile,在源码构建的 Harness `0.1.6-alpha.2` 上与另外两个下载量前三插件共同加载,18 个插件工具注册正常;日历/邮件配置自检、PPT 主题查询和 17 行表格生成通过。测试本体基于官方 alpha.2 发布提交,另含工具调度器 `Symbol.for` 修复(`93badd88`)。本轮未连接真实邮箱或日历服务。
67
-
68
- 2026-09-16 曾在官方源码构建的 Harness `0.1.5-rc.2` 和 `0.1.6-alpha.1` 上完成同载验证:18 个组件与 ModLens 同载,工具 schema、技能注册及离线只读调用检查通过。
64
+ 当前验证基线为官方源码构建的 Harness **0.2.0-rc.1**(2026-09-28,含本地工具调度器 `Symbol.for` 修复)。18 个插件共同加载;邮件设置覆盖旧配置迁移、真实网页编辑与自动保存、刷新恢复、修订冲突和重启持久化检查。本轮使用隔离测试账号,未连接真实邮箱或发送邮件。
69
65
 
70
66
  **0.11.0 的同载验证(2026-09-18,本地构建的 Harness `0.1.5-rc.2`,`web` profile)**:插件挂载无报错;设置路由 GET 返回 200 且响应中已无 `raw` 字段;用 `text/plain` 发 POST 被 **415** 拒绝(同源守卫在真实宿主下生效);`application/json` 的 POST 下卡片投影正确,账号钉住 `authKind: password` 后 `authKindDeclared` 与 `authKind` 均为 `password`;设置面板实际渲染出账号卡片、8 个服务商预设的中文下拉、「认证方式」三态选择器、「应用(客户端)ID」输入格与提示、未填 ID 时的警示条(说明 `--dsw-alias-state-warn-primary` 在真实宿主下确有定义)与「登录 Microsoft 账号」按钮;浏览器控制台无报错;save 全链路可用,验证结束后已把 `accountsYaml` 还原为空、原有账号恢复。离线测试 231 项全绿。**仍未做**:真实 Outlook 租户的 OAuth2 端到端(设备码流程要真人在浏览器完成授权)与真实发信未测,`clientId` 相关路径目前只有假 authority 的用例覆盖。采用 `cordis.patch.yml` + `dsh.bundle.patch` 组合包模型。Node 要求为 22.19 及以上的 22.x,或 24 及以上。外部服务的实际业务操作需按各组件配置单独验证。
71
67
 
72
- 2026-09-10,npm `dsh-email@0.10.6` 曾通过真实 QQ 邮箱目录、列表、读取和搜索,以及设置页“测试连接”“保存并应用”检查;授权码留空时能继续使用 `DSH_EMAIL_PASSWORD`。独立 SMTP 登录认证也已通过。此次复验未连接真实邮箱,未发送、修改或删除邮件。
73
-
74
68
  遵循官方[插件打包与安装要求](https://github.com/deepseek-ai/deepseek-harness/blob/master/docs/user/develop/basic/publish.md):ESM 入口、预构建 `lib/`、`dsh.bundle.patch` 和 `cordis.patch.yml` 配置层;显式注入所需服务,提供 JSON Schema 参数、规范化输出和渲染函数,运行时不导入宿主内部服务;配置声明使用官方 `@deepseek-ai/schemastery` 公共包。使用 Node 22.19 及以上的 22.x 或 Node 24 及以上版本;Harness 仍在快速迭代,上述版本是实测基线。
75
69
 
76
70
  ## 安装
package/lib/config.d.ts CHANGED
@@ -56,6 +56,18 @@ export interface SmtpConfig {
56
56
  port?: number;
57
57
  secure?: boolean;
58
58
  }
59
+ /** Legacy form placeholders; an untouched blank-host endpoint delegates to its provider. */
60
+ export declare const ENDPOINT_DEFAULTS: {
61
+ readonly imap: {
62
+ readonly port: 993;
63
+ readonly secure: true;
64
+ };
65
+ readonly smtp: {
66
+ readonly port: 465;
67
+ readonly secure: true;
68
+ };
69
+ };
70
+ export declare function normalizeSettingsEndpoint<T extends SmtpConfig>(value: T, kind: keyof typeof ENDPOINT_DEFAULTS): Omit<T, 'host' | 'port' | 'secure'> & SmtpConfig;
59
71
  /** One mailbox account. Top-level shorthand fields act as shared defaults. */
60
72
  export interface AccountConfig {
61
73
  /** Built-in provider name, or a custom serverPresets name. */
package/lib/config.js CHANGED
@@ -34,6 +34,24 @@ export const OUTLOOK_IMAP_HOST = 'outlook.office365.com';
34
34
  * them, so such a release asks every built-in account to log in one more time.
35
35
  */
36
36
  export const OUTLOOK_OAUTH2_CLIENT_ID = '15dcd5aa-00dd-487f-82d7-1d2b2c299e14';
37
+ /** Legacy form placeholders; an untouched blank-host endpoint delegates to its provider. */
38
+ export const ENDPOINT_DEFAULTS = {
39
+ imap: { port: 993, secure: true }, smtp: { port: 465, secure: true },
40
+ };
41
+ export function normalizeSettingsEndpoint(value, kind) {
42
+ if (typeof value.host !== 'string' || value.host.trim() !== '')
43
+ return value;
44
+ const normalized = { ...value };
45
+ delete normalized.host;
46
+ const defaults = ENDPOINT_DEFAULTS[kind];
47
+ // A changed port or TLS choice is intentional; preserve that whole combination.
48
+ if ((value.port === undefined || value.port === defaults.port)
49
+ && (value.secure === undefined || value.secure === defaults.secure)) {
50
+ delete normalized.port;
51
+ delete normalized.secure;
52
+ }
53
+ return normalized;
54
+ }
37
55
  export const PROVIDER_PRESETS = {
38
56
  qq: { imap: { host: 'imap.qq.com', port: 993, secure: true }, smtp: { host: 'smtp.qq.com', port: 465, secure: true } },
39
57
  '163': { imap: { host: 'imap.163.com', port: 993, secure: true }, smtp: { host: 'smtp.163.com', port: 465, secure: true } },
@@ -340,17 +358,21 @@ function resolveAccount(name, common, acc, allowEnvPassword, providers, known) {
340
358
  const authUser = (acc.authUser ?? common.authUser ?? '').trim() || user;
341
359
  const authPassword = (acc.authPassword ?? common.authPassword) || password;
342
360
  const senderName = (acc.senderName ?? common.senderName ?? '').trim();
361
+ const accountImap = acc.imap && normalizeSettingsEndpoint(acc.imap, 'imap');
362
+ const sharedImap = common.imap && normalizeSettingsEndpoint(common.imap, 'imap');
363
+ const accountSmtp = acc.smtp && normalizeSettingsEndpoint(acc.smtp, 'smtp');
364
+ const sharedSmtp = common.smtp && normalizeSettingsEndpoint(common.smtp, 'smtp');
343
365
  const imap = {
344
- host: acc.imap?.host ?? common.imap?.host ?? preset?.imap.host,
345
- port: acc.imap?.port ?? common.imap?.port ?? preset?.imap.port,
346
- secure: acc.imap?.secure ?? common.imap?.secure ?? preset?.imap.secure,
347
- connectionTimeoutMs: acc.imap?.connectionTimeoutMs ?? common.imap?.connectionTimeoutMs,
348
- socketTimeoutMs: acc.imap?.socketTimeoutMs ?? common.imap?.socketTimeoutMs,
366
+ host: accountImap?.host ?? sharedImap?.host ?? preset?.imap.host,
367
+ port: accountImap?.port ?? sharedImap?.port ?? preset?.imap.port,
368
+ secure: accountImap?.secure ?? sharedImap?.secure ?? preset?.imap.secure,
369
+ connectionTimeoutMs: accountImap?.connectionTimeoutMs ?? sharedImap?.connectionTimeoutMs,
370
+ socketTimeoutMs: accountImap?.socketTimeoutMs ?? sharedImap?.socketTimeoutMs,
349
371
  };
350
372
  const smtp = {
351
- host: acc.smtp?.host ?? common.smtp?.host ?? preset?.smtp.host,
352
- port: acc.smtp?.port ?? common.smtp?.port ?? preset?.smtp.port,
353
- secure: acc.smtp?.secure ?? common.smtp?.secure ?? preset?.smtp.secure,
373
+ host: accountSmtp?.host ?? sharedSmtp?.host ?? preset?.smtp.host,
374
+ port: accountSmtp?.port ?? sharedSmtp?.port ?? preset?.smtp.port,
375
+ secure: accountSmtp?.secure ?? sharedSmtp?.secure ?? preset?.smtp.secure,
354
376
  };
355
377
  const problems = [];
356
378
  if (user === '')
@@ -108,8 +108,7 @@ export declare function extractMessageIds(source: Buffer): {
108
108
  */
109
109
  export declare function buildReplyMessage(original: OriginalDigest, mode: EmailReplyMode, selfAddress: string | readonly string[], text: string, forwardTo?: string): BuiltReply;
110
110
  /**
111
- * One mailbox pool for the whole plugin: pooled IMAP connections per
112
- * account plus pooled SMTP transporters, with idle sweep and error eviction.
111
+ * One mailbox pool for the whole plugin: pooled IMAP connections per account.
113
112
  */
114
113
  export declare class EmailPool {
115
114
  private readonly settings;
@@ -155,14 +154,13 @@ export declare class EmailPool {
155
154
  startIdleSweep(): void;
156
155
  dispose(): void;
157
156
  /**
158
- * A pooled transporter for one account. The token is captured when the
159
- * transporter is built; an OAuth2 token that turns out to be stale is
160
- * re-minted in sendMail, which rebuilds the transporter.
157
+ * Create an unpooled sender with its own socket. The socket callback exposes
158
+ * only the public SMTP transport hook to the cancellation owner.
161
159
  */
162
160
  private transporter;
163
- private dropTransporter;
164
161
  /**
165
- * Send through the pooled transporter while making cancellation close it.
162
+ * Give each send its own SMTP connection so cancellation can close that
163
+ * operation without closing another send for the same account.
166
164
  *
167
165
  * An OAuth2 transporter carries a token that was minted when it was built,
168
166
  * so a rejection is retried once against a freshly built one (and a fresh
@@ -1,5 +1,6 @@
1
1
  import { ImapFlow } from 'imapflow';
2
2
  import nodemailer from 'nodemailer';
3
+ import { createConnection } from 'node:net';
3
4
  import { mkdir, stat, writeFile } from 'node:fs/promises';
4
5
  import { join } from 'node:path';
5
6
  import { getFreshAccessToken, OAuth2Error } from './oauth2.js';
@@ -293,8 +294,7 @@ const READ_CACHE_TTL_MS = 10 * 60 * 1000;
293
294
  /** Folder names change rarely; a short TTL keeps email_folders off the wire. */
294
295
  const FOLDER_CACHE_TTL_MS = 60 * 1000;
295
296
  /**
296
- * One mailbox pool for the whole plugin: pooled IMAP connections per
297
- * account plus pooled SMTP transporters, with idle sweep and error eviction.
297
+ * One mailbox pool for the whole plugin: pooled IMAP connections per account.
298
298
  */
299
299
  export class EmailPool {
300
300
  settings;
@@ -566,41 +566,64 @@ export class EmailPool {
566
566
  this.idleTimer = undefined;
567
567
  for (const name of [...this.imaps.keys()])
568
568
  void this.evictImap(name);
569
- for (const transporter of this.smtps.values())
569
+ for (const [transporter, socket] of this.smtps) {
570
+ socket?.destroy();
570
571
  transporter.close();
572
+ }
571
573
  this.smtps.clear();
572
574
  }
573
575
  /**
574
- * A pooled transporter for one account. The token is captured when the
575
- * transporter is built; an OAuth2 token that turns out to be stale is
576
- * re-minted in sendMail, which rebuilds the transporter.
576
+ * Create an unpooled sender with its own socket. The socket callback exposes
577
+ * only the public SMTP transport hook to the cancellation owner.
577
578
  */
578
- transporter(name, cfg, accessToken) {
579
- let t = this.smtps.get(name);
580
- if (t === undefined) {
581
- t = nodemailer.createTransport({
582
- pool: true,
583
- host: cfg.smtp.host,
584
- port: cfg.smtp.port,
585
- secure: cfg.smtp.secure,
586
- auth: smtpAuthOf(cfg, accessToken),
587
- connectionTimeout: 30000,
588
- greetingTimeout: 10000,
589
- socketTimeout: 60000,
590
- maxConnections: 2,
591
- maxMessages: 50,
592
- });
593
- this.smtps.set(name, t);
594
- }
595
- return t;
596
- }
597
- dropTransporter(name, transporter) {
598
- if (this.smtps.get(name) === transporter)
599
- this.smtps.delete(name);
600
- transporter.close();
579
+ transporter(name, cfg, accessToken, signal, onSocket) {
580
+ const transporter = nodemailer.createTransport({
581
+ host: cfg.smtp.host,
582
+ port: cfg.smtp.port,
583
+ secure: cfg.smtp.secure,
584
+ auth: smtpAuthOf(cfg, accessToken),
585
+ connectionTimeout: 30000,
586
+ greetingTimeout: 10000,
587
+ socketTimeout: 60000,
588
+ getSocket: (options, callback) => {
589
+ const socket = createConnection({ host: options.host ?? cfg.smtp.host, port: options.port ?? cfg.smtp.port });
590
+ onSocket(socket);
591
+ let settled = false;
592
+ const finish = (error, socketOptions) => {
593
+ if (settled)
594
+ return;
595
+ settled = true;
596
+ clearTimeout(timer);
597
+ socket.removeListener('connect', onConnect);
598
+ socket.removeListener('error', onError);
599
+ signal?.removeEventListener('abort', onAbort);
600
+ if (error !== null)
601
+ socket.destroy();
602
+ callback(error, socketOptions);
603
+ };
604
+ const onConnect = () => {
605
+ if (signal?.aborted === true) {
606
+ finish(signal.reason instanceof Error ? signal.reason : new Error('SMTP connection aborted'));
607
+ }
608
+ else
609
+ finish(null, { connection: socket });
610
+ };
611
+ const onError = (error) => finish(error);
612
+ const onAbort = () => finish(signal?.reason instanceof Error ? signal.reason : new Error('SMTP connection aborted'));
613
+ const timer = setTimeout(() => finish(new Error('SMTP connection timeout')), 30000);
614
+ socket.once('connect', onConnect);
615
+ socket.once('error', onError);
616
+ signal?.addEventListener('abort', onAbort, { once: true });
617
+ if (signal?.aborted === true)
618
+ onAbort();
619
+ },
620
+ });
621
+ this.smtps.set(transporter, undefined);
622
+ return transporter;
601
623
  }
602
624
  /**
603
- * Send through the pooled transporter while making cancellation close it.
625
+ * Give each send its own SMTP connection so cancellation can close that
626
+ * operation without closing another send for the same account.
604
627
  *
605
628
  * An OAuth2 transporter carries a token that was minted when it was built,
606
629
  * so a rejection is retried once against a freshly built one (and a fresh
@@ -610,44 +633,78 @@ export class EmailPool {
610
633
  async sendMail(name, cfg, message, signal) {
611
634
  signal?.throwIfAborted();
612
635
  const attempt = async (forceToken) => {
613
- const token = cfg.authKind === 'oauth2' ? await getFreshAccessToken(name, cfg, { force: forceToken }) : undefined;
614
- const transporter = this.transporter(name, cfg, token);
615
- const onAbort = () => {
616
- this.dropTransporter(name, transporter);
617
- };
618
- signal?.addEventListener('abort', onAbort, { once: true });
636
+ let token;
637
+ if (cfg.authKind === 'oauth2') {
638
+ const refreshing = getFreshAccessToken(name, cfg, { force: forceToken });
639
+ if (signal === undefined)
640
+ token = await refreshing;
641
+ else {
642
+ let onAbort;
643
+ const aborted = new Promise((_resolve, reject) => {
644
+ onAbort = () => reject(signal.reason ?? new DOMException('The operation was aborted', 'AbortError'));
645
+ signal.addEventListener('abort', onAbort, { once: true });
646
+ if (signal.aborted)
647
+ onAbort();
648
+ });
649
+ try {
650
+ token = await Promise.race([refreshing, aborted]);
651
+ }
652
+ finally {
653
+ if (onAbort !== undefined)
654
+ signal.removeEventListener('abort', onAbort);
655
+ }
656
+ }
657
+ }
658
+ signal?.throwIfAborted();
659
+ let smtpSocket;
660
+ const transporter = this.transporter(name, cfg, token, signal, socket => {
661
+ smtpSocket = socket;
662
+ this.smtps.set(transporter, socket);
663
+ });
664
+ let onAbort;
665
+ const aborted = signal === undefined ? undefined : new Promise((_resolve, reject) => {
666
+ onAbort = () => {
667
+ smtpSocket?.destroy();
668
+ transporter.close();
669
+ reject(new MailError('SMTP发送已取消;服务器是否已接收邮件无法确认,请先检查邮箱再决定是否重发'));
670
+ };
671
+ signal.addEventListener('abort', onAbort, { once: true });
672
+ });
619
673
  try {
620
- const info = await transporter.sendMail(message);
621
- signal?.throwIfAborted();
674
+ const sending = transporter.sendMail(message);
675
+ const info = aborted === undefined ? await sending : await Promise.race([sending, aborted]);
622
676
  return info;
623
677
  }
624
678
  finally {
625
- signal?.removeEventListener('abort', onAbort);
679
+ if (onAbort !== undefined)
680
+ signal?.removeEventListener('abort', onAbort);
681
+ smtpSocket?.destroy();
682
+ transporter.close();
683
+ this.smtps.delete(transporter);
626
684
  }
627
685
  };
628
686
  try {
629
687
  return await attempt(false);
630
688
  }
631
689
  catch (error) {
632
- signal?.throwIfAborted();
690
+ if (signal?.aborted === true)
691
+ throw error;
633
692
  if (cfg.authKind !== 'oauth2')
634
693
  throw error;
635
- // A pooled connection that already authenticated can fail for reasons no
694
+ // A connection that already authenticated can fail for reasons no
636
695
  // token can fix (a rejected recipient, a full mailbox). Only a credential
637
696
  // rejection is worth a second, freshly-tokened attempt — and a token
638
697
  // store that refused outright is reported as itself.
639
698
  if (!looksLikeAuthFailure(error))
640
699
  throw this.oauth2ErrorOf(error);
641
- // The cached transporter holds the old token: it has to go, or the retry
642
- // would reuse the very credential that was just refused.
643
- const stale = this.smtps.get(name);
644
- if (stale !== undefined)
645
- this.dropTransporter(name, stale);
700
+ // A fresh transporter is created for the retry so it cannot reuse the
701
+ // credential that was just refused.
646
702
  try {
647
703
  return await attempt(true);
648
704
  }
649
705
  catch (retryError) {
650
- signal?.throwIfAborted();
706
+ if (signal !== undefined && Boolean(signal.aborted))
707
+ throw retryError;
651
708
  throw this.oauth2ErrorOf(retryError);
652
709
  }
653
710
  }
package/lib/settings.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import z from 'schemastery';
2
- import { PROVIDER_NAMES } from './config.js';
2
+ import { ENDPOINT_DEFAULTS, normalizeSettingsEndpoint, PROVIDER_NAMES } from './config.js';
3
3
  /** Settings-document namespace this plugin owns (editable from the Web settings page). */
4
4
  export const SETTINGS_NAMESPACE = 'dsh-email';
5
5
  /**
@@ -22,13 +22,13 @@ export const EmailSettingsSchema = z.object({
22
22
  serverPresets: z.string().default(''),
23
23
  imap: z.object({
24
24
  host: z.string().default(''),
25
- port: z.number().default(993),
26
- secure: z.boolean().default(true),
25
+ port: z.number().default(ENDPOINT_DEFAULTS.imap.port),
26
+ secure: z.boolean().default(ENDPOINT_DEFAULTS.imap.secure),
27
27
  }),
28
28
  smtp: z.object({
29
29
  host: z.string().default(''),
30
- port: z.number().default(465),
31
- secure: z.boolean().default(true),
30
+ port: z.number().default(ENDPOINT_DEFAULTS.smtp.port),
31
+ secure: z.boolean().default(ENDPOINT_DEFAULTS.smtp.secure),
32
32
  }),
33
33
  });
34
34
  /** Project the row config (cordis.patch.yml) into the settings-schema base shape. */
@@ -45,15 +45,15 @@ export function toSettingsBase(config) {
45
45
  ...(config.imap !== undefined ? {
46
46
  imap: {
47
47
  host: config.imap.host ?? '',
48
- port: config.imap.port ?? 993,
49
- secure: config.imap.secure ?? true,
48
+ port: config.imap.port ?? ENDPOINT_DEFAULTS.imap.port,
49
+ secure: config.imap.secure ?? ENDPOINT_DEFAULTS.imap.secure,
50
50
  },
51
51
  } : {}),
52
52
  ...(config.smtp !== undefined ? {
53
53
  smtp: {
54
54
  host: config.smtp.host ?? '',
55
- port: config.smtp.port ?? 465,
56
- secure: config.smtp.secure ?? true,
55
+ port: config.smtp.port ?? ENDPOINT_DEFAULTS.smtp.port,
56
+ secure: config.smtp.secure ?? ENDPOINT_DEFAULTS.smtp.secure,
57
57
  },
58
58
  } : {}),
59
59
  };
@@ -131,7 +131,9 @@ export function toEmailConfig(value, user) {
131
131
  // serverPresets is intentionally NOT projected: it is UI-side metadata that
132
132
  // resolution never reads, and projecting it would put it into the resolved
133
133
  // fingerprint, so saving a preset would dispose every live IMAP connection.
134
- const imapValue = draft.imap;
134
+ // Only a persisted blank host signals a placeholder. A schema-added blank
135
+ // host must not erase an explicit port-only override from the raw document.
136
+ const imapValue = user?.imap?.host !== undefined && draft.imap ? normalizeSettingsEndpoint(draft.imap, 'imap') : draft.imap;
135
137
  const imapKeys = user === null ? imapValue : user?.imap;
136
138
  if (isSet(imapKeys) && isSet(imapValue)) {
137
139
  const imap = {};
@@ -145,7 +147,7 @@ export function toEmailConfig(value, user) {
145
147
  imap.secure = imapValue.secure;
146
148
  out.imap = imap;
147
149
  }
148
- const smtpValue = draft.smtp;
150
+ const smtpValue = user?.smtp?.host !== undefined && draft.smtp ? normalizeSettingsEndpoint(draft.smtp, 'smtp') : draft.smtp;
149
151
  const smtpKeys = user === null ? smtpValue : user?.smtp;
150
152
  if (isSet(smtpKeys) && isSet(smtpValue)) {
151
153
  const smtp = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-email",
3
- "version": "0.14.1",
3
+ "version": "0.14.4",
4
4
  "description": "DSH 邮件插件:IMAP/SMTP 收发搜索、回复转发、附件与整理,多账号卡片设置页、Outlook OAuth2 登录与发信审批。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",