@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.
- package/lib/plugin.mjs +12 -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
|
-
|
|
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 =
|
|
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}`);
|