@zaclinley/dsh-mailharbor 0.16.0 → 0.16.1
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 +13 -0
- package/README.md +17 -17
- package/lib/client.js +129 -34
- package/lib/client.js.map +3 -3
- package/lib/index.js +28 -5
- package/lib/index.js.map +2 -2
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -2768,7 +2768,7 @@ ${conversation.trim()}
|
|
|
2768
2768
|
}
|
|
2769
2769
|
|
|
2770
2770
|
// src/host/version.ts
|
|
2771
|
-
var VERSION = "0.16.
|
|
2771
|
+
var VERSION = "0.16.1";
|
|
2772
2772
|
|
|
2773
2773
|
// src/host/api.ts
|
|
2774
2774
|
init_smtp();
|
|
@@ -3107,14 +3107,26 @@ function buildRouter(runtime) {
|
|
|
3107
3107
|
const part = Number(url.searchParams.get("part") ?? 0);
|
|
3108
3108
|
const provider = runtime.provider(account);
|
|
3109
3109
|
const file2 = await provider.attachment(mailbox, uid, part);
|
|
3110
|
-
writeAttachment(
|
|
3110
|
+
writeAttachment(
|
|
3111
|
+
res,
|
|
3112
|
+
file2.filename,
|
|
3113
|
+
file2.contentType,
|
|
3114
|
+
Buffer.from(file2.dataBase64, "base64"),
|
|
3115
|
+
canPreviewInline(file2.contentType) && url.searchParams.get("inline") === "1"
|
|
3116
|
+
);
|
|
3111
3117
|
return void 0;
|
|
3112
3118
|
}
|
|
3113
3119
|
const emailId = Number(url.searchParams.get("emailId") ?? 0);
|
|
3114
3120
|
const attachmentId = Number(url.searchParams.get("attachmentId") ?? 0);
|
|
3115
3121
|
const file = runtime.database(account).attachment(emailId, attachmentId);
|
|
3116
3122
|
if (file === void 0) throw new HttpError(404, "\u9644\u4EF6\u4E0D\u5B58\u5728");
|
|
3117
|
-
writeAttachment(
|
|
3123
|
+
writeAttachment(
|
|
3124
|
+
res,
|
|
3125
|
+
file.filename,
|
|
3126
|
+
file.contentType,
|
|
3127
|
+
Buffer.from(file.data),
|
|
3128
|
+
canPreviewInline(file.contentType) && url.searchParams.get("inline") === "1"
|
|
3129
|
+
);
|
|
3118
3130
|
return void 0;
|
|
3119
3131
|
});
|
|
3120
3132
|
router.get("/drafts", ({ url }) => {
|
|
@@ -3998,13 +4010,24 @@ async function listServer(runtime, account, mailbox, query, limit, offset = 0) {
|
|
|
3998
4010
|
);
|
|
3999
4011
|
return { items, total: result.total };
|
|
4000
4012
|
}
|
|
4001
|
-
function
|
|
4013
|
+
function canPreviewInline(contentType) {
|
|
4014
|
+
const type = contentType.toLowerCase();
|
|
4015
|
+
return type.startsWith("image/") && type !== "image/svg+xml" || type === "application/pdf" || type === "text/plain" || type === "text/csv" || type === "text/markdown" || type === "application/json";
|
|
4016
|
+
}
|
|
4017
|
+
function writeAttachment(res, filename, contentType, data, inline = false) {
|
|
4002
4018
|
res.statusCode = 200;
|
|
4003
4019
|
res.setHeader("content-type", contentType);
|
|
4004
4020
|
res.setHeader("content-length", String(data.length));
|
|
4005
|
-
res.setHeader(
|
|
4021
|
+
res.setHeader(
|
|
4022
|
+
"content-disposition",
|
|
4023
|
+
`${inline ? "inline" : "attachment"}; filename*=UTF-8''${encodeURIComponent(filename)}`
|
|
4024
|
+
);
|
|
4006
4025
|
res.setHeader("cache-control", "no-store");
|
|
4007
4026
|
res.setHeader("x-content-type-options", "nosniff");
|
|
4027
|
+
res.setHeader(
|
|
4028
|
+
"content-security-policy",
|
|
4029
|
+
"sandbox; default-src 'none'; img-src 'self' data:; style-src 'unsafe-inline'"
|
|
4030
|
+
);
|
|
4008
4031
|
res.end(data);
|
|
4009
4032
|
}
|
|
4010
4033
|
function asObject(value) {
|