@social-mail/social-mail-web-server 1.4.798 → 1.4.800
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/dist/server/seed/ui/seed-ui.js +1 -1
- package/dist/tests/protocols/parsers/email-parser.test.d.ts.map +1 -1
- package/dist/tests/protocols/parsers/email-parser.test.js +240 -81
- package/dist/tests/protocols/parsers/email-parser.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/wwwroot/routes/api/emails/d/get.d.ts +8 -0
- package/dist/wwwroot/routes/api/emails/d/get.d.ts.map +1 -0
- package/dist/wwwroot/routes/api/emails/d/get.js +64 -0
- package/dist/wwwroot/routes/api/emails/d/get.js.map +1 -0
- package/dist/wwwroot/routes/api/emails/unsubscribe/post.d.ts +8 -0
- package/dist/wwwroot/routes/api/emails/unsubscribe/post.d.ts.map +1 -0
- package/dist/wwwroot/routes/api/emails/unsubscribe/post.js +73 -0
- package/dist/wwwroot/routes/api/emails/unsubscribe/post.js.map +1 -0
- package/package.json +3 -2
- package/src/server/seed/ui/seed-ui.ts +1 -1
- package/src/tests/protocols/parsers/email-parser.test.ts +244 -80
- package/src/wwwroot/routes/api/emails/d/get.ts +63 -0
- package/src/wwwroot/routes/api/emails/unsubscribe/post.tsx +73 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import Inject from "@entity-access/entity-access/dist/di/di.js";
|
|
2
|
+
import Page from "@entity-access/server-pages/dist/Page.js";
|
|
3
|
+
import SocialMailContext from "../../../../../server/model/SocialMailContext.js";
|
|
4
|
+
import EmailLogService from "../../../../../server/services/email-logs/EmailLogService.js";
|
|
5
|
+
import EmailParserService from "../../../../../server/smtp/services/EmailParserService.js";
|
|
6
|
+
import { MimeNode, LineStream } from "@social-mail/shared/index.js";
|
|
7
|
+
import { Prepare } from "@entity-access/server-pages/dist/decorators/Prepare.js";
|
|
8
|
+
|
|
9
|
+
@Prepare.authorize
|
|
10
|
+
export default class extends Page {
|
|
11
|
+
|
|
12
|
+
@Inject
|
|
13
|
+
db: SocialMailContext;
|
|
14
|
+
|
|
15
|
+
@Inject
|
|
16
|
+
private els: EmailLogService;
|
|
17
|
+
|
|
18
|
+
async run() {
|
|
19
|
+
|
|
20
|
+
const [emailID] = this.childPath as any[];
|
|
21
|
+
|
|
22
|
+
const email = await this.db.emails
|
|
23
|
+
.filtered("read")
|
|
24
|
+
.where({ emailID }, (p) => (x) => x.emailID === p.emailID)
|
|
25
|
+
.include((x) => x.mimeFile)
|
|
26
|
+
.first();
|
|
27
|
+
|
|
28
|
+
const file = await this.els.load(email.mimeFile);
|
|
29
|
+
|
|
30
|
+
const root = new MimeNode();
|
|
31
|
+
|
|
32
|
+
await root.parse( new (class extends LineStream {
|
|
33
|
+
lines() {
|
|
34
|
+
return file.lines();
|
|
35
|
+
}
|
|
36
|
+
})());
|
|
37
|
+
let u = root.header("List-Unsubscribe") as string;
|
|
38
|
+
u = u.split(",").find((x) => /\<http/i.test(x)).trim();
|
|
39
|
+
|
|
40
|
+
if (u.endsWith(">")) {
|
|
41
|
+
u = u.substring(0, u.length - 1);
|
|
42
|
+
}
|
|
43
|
+
if (u.startsWith("<")) {
|
|
44
|
+
u = u.substring(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let method = "GET";
|
|
48
|
+
|
|
49
|
+
if (root.header("List-Unsubscribe-Post")) {
|
|
50
|
+
method = "POST";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const rs = await fetch(u, {
|
|
54
|
+
method
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
let failed = "";
|
|
58
|
+
let result = "";
|
|
59
|
+
|
|
60
|
+
const status = rs.status;
|
|
61
|
+
|
|
62
|
+
if (status > 399) {
|
|
63
|
+
failed = await rs.text();
|
|
64
|
+
} else {
|
|
65
|
+
result = await rs.text();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return this.json({
|
|
69
|
+
failed,
|
|
70
|
+
result
|
|
71
|
+
}, void 0, { status });
|
|
72
|
+
}
|
|
73
|
+
}
|