@puwenhui/dsh-email 0.2.4 → 0.2.5

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.
Files changed (2) hide show
  1. package/lib/plugin.mjs +12 -2
  2. package/package.json +1 -1
package/lib/plugin.mjs CHANGED
@@ -10,6 +10,12 @@ function loadLocal() {
10
10
  }
11
11
  return {};
12
12
  }
13
+ // 用户数据根(宿主规范:$DSH_HOME,缺省 ~/.dsh):相对路径的索引库与附件都落在 storages/dsh-email/,
14
+ // 与包安装目录解耦——升级/重装插件不丢数据
15
+ var dshHome = process.env.DSH_HOME && process.env.DSH_HOME.trim() !== '' ? process.env.DSH_HOME : path.join(process.env.USERPROFILE ?? process.env.HOME ?? '.', '.dsh');
16
+ function resolveDataPath(rel) {
17
+ return path.isAbsolute(rel) ? rel : path.join(dshHome, 'storages', 'dsh-email', rel);
18
+ }
13
19
  function resolveConfig(overrides = {}) {
14
20
  const env = process.env;
15
21
  const local = loadLocal();
@@ -109,7 +115,11 @@ CREATE TABLE IF NOT EXISTS sync_state(
109
115
  var Store = class {
110
116
  db;
111
117
  constructor(dbPath) {
112
- const resolved = dbPath === ":memory:" ? ":memory:" : path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", dbPath);
118
+ let resolved;
119
+ if (dbPath === ':memory:') resolved = ':memory:';
120
+ else if (path.isAbsolute(dbPath)) resolved = dbPath;
121
+ else resolved = resolveDataPath(dbPath);
122
+ if (resolved !== ':memory:') fs.mkdirSync(path.dirname(resolved), { recursive: true });
113
123
  this.db = new DatabaseSync(resolved);
114
124
  this.db.exec("PRAGMA journal_mode=WAL; PRAGMA foreign_keys=ON;");
115
125
  this.db.exec(SCHEMA);
@@ -768,7 +778,7 @@ var EmailService = class {
768
778
  const list = parsed.attachments ?? [];
769
779
  const hit = list.find((a) => String(a.partId ?? "") === att.part_id) ?? list[0];
770
780
  if (!hit?.content) throw new Error("附件内容解析失败");
771
- const dir = path.resolve(fileURLToPath(new URL(".", import.meta.url)), "..", saveDirOverride || this.cfg.attachmentDir);
781
+ const dir = resolveDataPath(saveDirOverride || this.cfg.attachmentDir);
772
782
  fs.mkdirSync(dir, { recursive: true });
773
783
  const safe = String(hit.filename || att.filename || `attachment-${id}`).replace(/[\\/:*?"<>|]/g, "_");
774
784
  const file = path.join(dir, `${att.mailbox}-${att.uid}-${safe}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@puwenhui/dsh-email",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "DSH 邮件助手插件:IMAP 同步 + 全文索引 + 会话归并 + 10 个模型工具 + 设置配置卡 + 重要新邮件桌面提醒",
5
5
  "repository": {
6
6
  "type": "git",