@zaclinley/dsh-mailharbor 0.14.0 → 0.16.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/CHANGELOG.md +36 -0
- package/README.md +36 -35
- package/README.zh.md +35 -32
- package/lib/client.js +169 -18
- package/lib/client.js.map +2 -2
- package/lib/index.js +78 -34
- package/lib/index.js.map +3 -3
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -120,7 +120,7 @@ function transportOptions(settings, credentials, security = {}) {
|
|
|
120
120
|
secure,
|
|
121
121
|
// Plain submission ports must upgrade; never send credentials in the clear.
|
|
122
122
|
requireTLS: !secure,
|
|
123
|
-
auth:
|
|
123
|
+
auth: { user: credentials.user, pass: credentials.pass ?? "" },
|
|
124
124
|
tls: { rejectUnauthorized: security.allowSelfSigned !== true, servername: settings.host },
|
|
125
125
|
connectionTimeout: 2e4,
|
|
126
126
|
greetingTimeout: 2e4,
|
|
@@ -287,7 +287,7 @@ var init_imap = __esm({
|
|
|
287
287
|
host: this.settings.host,
|
|
288
288
|
port: Number(this.settings.port),
|
|
289
289
|
secure: this.settings.secure !== false,
|
|
290
|
-
auth:
|
|
290
|
+
auth: { user: this.credentials.user, pass: this.credentials.pass ?? "" },
|
|
291
291
|
logger: false,
|
|
292
292
|
tls: { rejectUnauthorized: true },
|
|
293
293
|
connectionTimeout: this.options.connectionTimeoutMs ?? 15e3,
|
|
@@ -710,18 +710,7 @@ var DEFAULTS = {
|
|
|
710
710
|
},
|
|
711
711
|
read: { markOnOpen: true, pollSeconds: 60 },
|
|
712
712
|
render: { listLimit: 40 },
|
|
713
|
-
projects: { root: join2(homedir2(), "work", "projects") }
|
|
714
|
-
oauth: {
|
|
715
|
-
google: { clientId: "", redirectPort: 8765, scopes: ["https://mail.google.com/"] },
|
|
716
|
-
microsoft: {
|
|
717
|
-
clientId: "",
|
|
718
|
-
scopes: [
|
|
719
|
-
"offline_access",
|
|
720
|
-
"https://outlook.office.com/IMAP.AccessAsUser.All",
|
|
721
|
-
"https://outlook.office.com/SMTP.Send"
|
|
722
|
-
]
|
|
723
|
-
}
|
|
724
|
-
}
|
|
713
|
+
projects: { root: join2(homedir2(), "work", "projects") }
|
|
725
714
|
};
|
|
726
715
|
var ACCOUNT_ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
727
716
|
var EMAIL = /^[^@\s]+@[^@\s]+$/;
|
|
@@ -771,7 +760,7 @@ function normalizeAccount(input, index = 0, existing = []) {
|
|
|
771
760
|
},
|
|
772
761
|
keychainService: stringOr(input.keychainService, `dsh-mailharbor:${id}`),
|
|
773
762
|
dataDir: stringOr(input.dataDir, `accounts/${id}`),
|
|
774
|
-
auth:
|
|
763
|
+
auth: { type: "password" },
|
|
775
764
|
caldav: normalizeCaldav(input.caldav),
|
|
776
765
|
signature: stringOr(input.signature, "").slice(0, 5e3),
|
|
777
766
|
enabled: input.enabled !== false,
|
|
@@ -826,9 +815,6 @@ function loadConfig() {
|
|
|
826
815
|
const readRaw = file.read ?? {};
|
|
827
816
|
const renderRaw = file.render ?? {};
|
|
828
817
|
const projectsRaw = file.projects ?? {};
|
|
829
|
-
const oauthRaw = file.oauth ?? {};
|
|
830
|
-
const googleRaw = oauthRaw.google ?? {};
|
|
831
|
-
const microsoftRaw = oauthRaw.microsoft ?? {};
|
|
832
818
|
return {
|
|
833
819
|
dataDir: DATA_ROOT,
|
|
834
820
|
configFile: CONFIG_PATH,
|
|
@@ -853,17 +839,6 @@ function loadConfig() {
|
|
|
853
839
|
projects: {
|
|
854
840
|
root: stringOr(projectsRaw.root, DEFAULTS.projects.root)
|
|
855
841
|
},
|
|
856
|
-
oauth: {
|
|
857
|
-
google: {
|
|
858
|
-
clientId: stringOr(googleRaw.clientId, DEFAULTS.oauth.google.clientId),
|
|
859
|
-
redirectPort: intOr(googleRaw.redirectPort, DEFAULTS.oauth.google.redirectPort, 1024, 65535),
|
|
860
|
-
scopes: Array.isArray(googleRaw.scopes) ? googleRaw.scopes.filter((item) => typeof item === "string") : DEFAULTS.oauth.google.scopes
|
|
861
|
-
},
|
|
862
|
-
microsoft: {
|
|
863
|
-
clientId: stringOr(microsoftRaw.clientId, DEFAULTS.oauth.microsoft.clientId),
|
|
864
|
-
scopes: Array.isArray(microsoftRaw.scopes) ? microsoftRaw.scopes.filter((item) => typeof item === "string") : DEFAULTS.oauth.microsoft.scopes
|
|
865
|
-
}
|
|
866
|
-
},
|
|
867
842
|
revision: Date.now()
|
|
868
843
|
};
|
|
869
844
|
}
|
|
@@ -1760,7 +1735,7 @@ var BackupEngine = class {
|
|
|
1760
1735
|
host: this.runtime.imap.host,
|
|
1761
1736
|
port: Number(this.runtime.imap.port),
|
|
1762
1737
|
secure: this.runtime.imap.secure !== false,
|
|
1763
|
-
auth:
|
|
1738
|
+
auth: { user: this.credentials.user, pass: this.credentials.pass ?? "" },
|
|
1764
1739
|
logger: false,
|
|
1765
1740
|
tls: { rejectUnauthorized: true },
|
|
1766
1741
|
connectionTimeout: 2e4,
|
|
@@ -2793,7 +2768,7 @@ ${conversation.trim()}
|
|
|
2793
2768
|
}
|
|
2794
2769
|
|
|
2795
2770
|
// src/host/version.ts
|
|
2796
|
-
var VERSION = "0.
|
|
2771
|
+
var VERSION = "0.16.0";
|
|
2797
2772
|
|
|
2798
2773
|
// src/host/api.ts
|
|
2799
2774
|
init_smtp();
|
|
@@ -3007,6 +2982,78 @@ function buildRouter(runtime) {
|
|
|
3007
2982
|
}
|
|
3008
2983
|
return { ok: true, count };
|
|
3009
2984
|
});
|
|
2985
|
+
router.get("/transfer/export", () => {
|
|
2986
|
+
const config = runtime.current;
|
|
2987
|
+
return {
|
|
2988
|
+
format: "mailharbor-transfer",
|
|
2989
|
+
version: 1,
|
|
2990
|
+
exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2991
|
+
settings: {
|
|
2992
|
+
signature: config.signature,
|
|
2993
|
+
read: config.read,
|
|
2994
|
+
render: config.render,
|
|
2995
|
+
ai: {
|
|
2996
|
+
enabled: config.ai.enabled,
|
|
2997
|
+
provider: config.ai.provider,
|
|
2998
|
+
model: config.ai.model,
|
|
2999
|
+
summaryLength: config.ai.summaryLength
|
|
3000
|
+
}
|
|
3001
|
+
},
|
|
3002
|
+
accounts: config.accounts.map((account) => ({
|
|
3003
|
+
email: account.email,
|
|
3004
|
+
label: account.label,
|
|
3005
|
+
username: account.username,
|
|
3006
|
+
imap: account.imap,
|
|
3007
|
+
smtp: account.smtp,
|
|
3008
|
+
auth: account.auth,
|
|
3009
|
+
enabled: account.enabled
|
|
3010
|
+
}))
|
|
3011
|
+
};
|
|
3012
|
+
});
|
|
3013
|
+
router.post("/transfer/import", async ({ body }) => {
|
|
3014
|
+
const payload = await body();
|
|
3015
|
+
if (payload.format !== "mailharbor-transfer" || !Array.isArray(payload.accounts)) {
|
|
3016
|
+
throw new HttpError(400, "\u4E0D\u662F\u6709\u6548\u7684 MailHarbor \u914D\u7F6E\u6587\u4EF6");
|
|
3017
|
+
}
|
|
3018
|
+
const config = runtime.current;
|
|
3019
|
+
const accounts = [...config.accounts];
|
|
3020
|
+
let added = 0;
|
|
3021
|
+
for (const raw of payload.accounts) {
|
|
3022
|
+
const email = String(raw.email ?? "").trim();
|
|
3023
|
+
if (email === "" || accounts.some((account) => account.email.toLowerCase() === email.toLowerCase()))
|
|
3024
|
+
continue;
|
|
3025
|
+
try {
|
|
3026
|
+
const account = normalizeAccount(
|
|
3027
|
+
{
|
|
3028
|
+
email,
|
|
3029
|
+
label: typeof raw.label === "string" ? raw.label : void 0,
|
|
3030
|
+
username: typeof raw.username === "string" ? raw.username : void 0,
|
|
3031
|
+
imap: asObject(raw.imap),
|
|
3032
|
+
smtp: asObject(raw.smtp),
|
|
3033
|
+
...raw.auth !== void 0 ? { auth: raw.auth } : {}
|
|
3034
|
+
},
|
|
3035
|
+
accounts.length,
|
|
3036
|
+
accounts.map((account2) => account2.id)
|
|
3037
|
+
);
|
|
3038
|
+
accounts.push(account);
|
|
3039
|
+
added += 1;
|
|
3040
|
+
} catch {
|
|
3041
|
+
}
|
|
3042
|
+
}
|
|
3043
|
+
if (added > 0) saveAccounts(accounts, config.activeAccountId ?? accounts[0]?.id ?? null);
|
|
3044
|
+
const settings = asObject(payload.settings);
|
|
3045
|
+
const patch = {};
|
|
3046
|
+
if (typeof settings.signature === "string") patch.signature = settings.signature.slice(0, 5e3);
|
|
3047
|
+
const read = asObject(settings.read);
|
|
3048
|
+
if (typeof read.markOnOpen === "boolean") patch.read = { markOnOpen: read.markOnOpen };
|
|
3049
|
+
const render = asObject(settings.render);
|
|
3050
|
+
if (typeof render.listLimit === "number") patch.render = { listLimit: render.listLimit };
|
|
3051
|
+
const ai = asObject(settings.ai);
|
|
3052
|
+
if (ai.summaryLength !== void 0) patch.ai = { summaryLength: ai.summaryLength };
|
|
3053
|
+
if (Object.keys(patch).length > 0) saveSettings(patch);
|
|
3054
|
+
runtime.refresh();
|
|
3055
|
+
return { ok: true, addedAccounts: added, state: appState(runtime) };
|
|
3056
|
+
});
|
|
3010
3057
|
router.get("/messages/thread", ({ url }) => {
|
|
3011
3058
|
const { account } = accountFrom(runtime, url);
|
|
3012
3059
|
const subject = url.searchParams.get("subject") ?? "";
|
|
@@ -4986,9 +5033,6 @@ var MailHarborRuntime = class {
|
|
|
4986
5033
|
}
|
|
4987
5034
|
/** Credentials for an account, with a clear message when the user must log in. */
|
|
4988
5035
|
credentialsFor(account) {
|
|
4989
|
-
if (account.auth.type === "oauth2") {
|
|
4990
|
-
throw new Error("OAuth2 \u8D26\u53F7\u6682\u672A\u5728\u6B64\u7248\u672C\u542F\u7528\uFF0C\u8BF7\u4F7F\u7528\u5E94\u7528\u4E13\u7528\u5BC6\u7801\u767B\u5F55");
|
|
4991
|
-
}
|
|
4992
5036
|
const resolved = this.credentials.resolve(account);
|
|
4993
5037
|
if (resolved === void 0) throw new Error("\u8BF7\u5148\u767B\u5F55\u90AE\u7BB1\u8D26\u53F7");
|
|
4994
5038
|
return { user: account.username || account.email, pass: resolved.password };
|