2023-11-01 11:48:19 +01:00
|
|
|
const express = require('express')
|
|
|
|
|
|
|
|
const router = new express.Router()
|
|
|
|
const {sanitizeParam} = require('express-validator/filter')
|
2023-11-01 13:04:44 +01:00
|
|
|
const config = require('../../../application/config')
|
2023-11-01 11:48:19 +01:00
|
|
|
const sanitizeAddress = sanitizeParam('address').customSanitizer(
|
|
|
|
(value, {req}) => {
|
|
|
|
return req.params.address
|
|
|
|
.replace(/[^A-Za-z0-9_.+@-]/g, '') // Remove special characters
|
|
|
|
.toLowerCase()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
router.get('^/:address([^@/]+@[^@/]+)', sanitizeAddress, (req, res, _next) => {
|
|
|
|
const mailProcessingService = req.app.get('mailProcessingService')
|
|
|
|
res.render('inbox', {
|
2023-11-01 12:33:58 +01:00
|
|
|
title: `${config.branding[0]} | ` + req.params.address,
|
2023-11-01 11:48:19 +01:00
|
|
|
address: req.params.address,
|
2023-11-01 13:21:01 +01:00
|
|
|
mailSummaries: mailProcessingService.getMailSummaries(req.params.address),
|
|
|
|
madeby: config.branding[1],
|
|
|
|
madebysite: config.branding[2]
|
2023-11-01 11:48:19 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
router.get(
|
|
|
|
'^/:address/:uid([0-9]+$)',
|
|
|
|
sanitizeAddress,
|
|
|
|
async (req, res, next) => {
|
|
|
|
try {
|
|
|
|
const mailProcessingService = req.app.get('mailProcessingService')
|
|
|
|
const mail = await mailProcessingService.getOneFullMail(
|
|
|
|
req.params.address,
|
|
|
|
req.params.uid
|
|
|
|
)
|
2023-12-24 21:06:09 +01:00
|
|
|
if (mail && !mail == "womp womp") {
|
2023-11-01 11:48:19 +01:00
|
|
|
// Emails are immutable, cache if found
|
|
|
|
res.set('Cache-Control', 'private, max-age=600')
|
|
|
|
res.render('mail', {
|
|
|
|
title: req.params.address,
|
|
|
|
address: req.params.address,
|
2023-11-01 13:21:37 +01:00
|
|
|
mail,
|
2023-11-02 06:25:22 +01:00
|
|
|
uid: req.params.uid,
|
2023-11-01 13:21:37 +01:00
|
|
|
madeby: config.branding[1],
|
|
|
|
madebysite: config.branding[2]
|
2023-11-01 11:48:19 +01:00
|
|
|
})
|
|
|
|
} else {
|
2023-12-24 21:06:09 +01:00
|
|
|
next({message: 'This mail could not be found. It either does not exist or has been deleted from our servers!', status: 404})
|
2023-11-01 11:48:19 +01:00
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error('error while fetching one email', error)
|
|
|
|
next(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-11-02 06:25:22 +01:00
|
|
|
router.get(
|
|
|
|
'^/:address/delete/:uid([0-9]+$)',
|
|
|
|
sanitizeAddress,
|
|
|
|
async (req, res, next) => {
|
|
|
|
try {
|
|
|
|
const mailProcessingService = req.app.get('mailProcessingService')
|
2023-11-02 06:27:28 +01:00
|
|
|
await mailProcessingService.deleteSpecificEmail(req.params.address, req.params.uid)
|
2023-11-03 06:11:17 +01:00
|
|
|
res.redirect(`/inbox/${req.params.address}`)
|
2023-11-02 06:25:22 +01:00
|
|
|
} catch (error) {
|
|
|
|
console.error('error while deleting email', error)
|
|
|
|
next(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-11-01 11:48:19 +01:00
|
|
|
module.exports = router
|