87 lines
2.7 KiB
JavaScript
87 lines
2.7 KiB
JavaScript
|
import express from "express";
|
||
|
const app = express();
|
||
|
|
||
|
import formidable from "formidable";
|
||
|
import fs from "node:fs";
|
||
|
|
||
|
import cookieParser from 'cookie-parser';
|
||
|
|
||
|
app.use(cookieParser());
|
||
|
|
||
|
app.post('/sendgrid/ingress', (req, res) => {
|
||
|
const form = formidable({});
|
||
|
|
||
|
form.parse(req, (err, fields, files) => {
|
||
|
var message = "";
|
||
|
if ( fields.email ) {
|
||
|
if ( typeof fields.email === "string") {
|
||
|
message = fields.email;
|
||
|
} else {
|
||
|
message = fields.email.join("");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fs.writeFileSync(`messages/${new Date().toISOString()}.eml`, message);
|
||
|
fs.writeFileSync(`messages/${new Date().toISOString()}.json`, JSON.stringify(fields));
|
||
|
res.status(204);
|
||
|
res.end();
|
||
|
})
|
||
|
});
|
||
|
|
||
|
app.post('/mail/login', (req, res) => {
|
||
|
// TODO: Actual proper login stuffs.
|
||
|
res.cookie("authenticated", "true", {maxAge: 86_400_000});
|
||
|
res.redirect("/static/jmapjs");
|
||
|
})
|
||
|
|
||
|
// JMAP implementation.
|
||
|
|
||
|
app.all("/.well-known/jmap", (req, res) => {
|
||
|
res.redirect("/jmap/session");
|
||
|
});
|
||
|
|
||
|
// https://jmap.io/spec-core.html#the-jmap-session-resource
|
||
|
// TODO: Authenticated
|
||
|
app.get("/jmap/session", (req, res) => {
|
||
|
if ( req.cookies.authenticated == "true" )
|
||
|
res.json({
|
||
|
"capabilities": {
|
||
|
"urn:ietf:params:jmap:core": {
|
||
|
"maxSizeUpload": 50000000,
|
||
|
"maxConcurrentUpload": 8,
|
||
|
"maxSizeRequest": 10000000,
|
||
|
"maxConcurrentRequests": 8,
|
||
|
"maxCallsInRequest": 32,
|
||
|
"maxObjectsInGet": 256,
|
||
|
"maxObjectsInSet": 128,
|
||
|
"collationAlgorithms": [
|
||
|
"i;ascii-numeric",
|
||
|
"i;ascii-casemap",
|
||
|
"i;unicode-casemap"
|
||
|
]
|
||
|
},
|
||
|
},
|
||
|
"accounts": {
|
||
|
"andrew@andrewpietila.com": {
|
||
|
"name": "andrew@andrewpietila.com",
|
||
|
isPersonal: true,
|
||
|
isReadOnly: false,
|
||
|
accountCapabilities: {}
|
||
|
}
|
||
|
},
|
||
|
"primaryAccounts": {
|
||
|
},
|
||
|
"username": "andrew@andrewpietila.com",
|
||
|
"apiUrl": "https://andrewpietila.com/api/jmap/api/",
|
||
|
"downloadUrl": "https://andrewpietila.com/api/jmap/download/{accountId}/{blobId}/{name}?accept={type}",
|
||
|
"uploadUrl": "https://andrewpietila.com/api/jmap/upload/{accountId}/",
|
||
|
"eventSourceUrl": "https://andrewpietila.com/api/jmap/eventsource/?types={types}&closeafter={closeafter}&ping={ping}",
|
||
|
"state": "75128aab4b1b"
|
||
|
});
|
||
|
else {
|
||
|
res.status(404);
|
||
|
res.end();
|
||
|
}
|
||
|
})
|
||
|
|
||
|
app.listen(8080);
|