Public
Script
October 23, 2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { fetch } from "https://esm.town/v/std/fetch";
export const etherealExtractor = async function (
req: express.Request,
res: express.Response,
) {
try {
const { default: qp } = await import("npm:quoted-printable");
let email_id;
switch (req.method) {
case "GET": {
email_id = req.query.email_id;
break;
}
case "POST": {
email_id = req.body.email_id;
}
}
if (!email_id)
return res.status(400).send({ message: "email_id is required" });
const sourceUrl = `https://ethereal.email/message/${email_id}/message.eml`;
const resource = await fetch(sourceUrl);
const eml = await resource.text();
const headerEndsAt = eml.search(/\n\s+\n/);
return res.status(200).type("text").send(qp.decode(eml.slice(headerEndsAt)))
.end();
}
catch (e) {
res.status(500).json({
message: e.message,
});
}
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023