Add delete button

pull/1/head
ClaraCrazy 2023-11-02 06:25:22 +01:00
parent b2c51c186d
commit 1865a08c87
7 changed files with 39 additions and 4 deletions

View File

@ -216,6 +216,17 @@ class ImapService extends EventEmitter {
uids.forEach(uid => this.emit(ImapService.EVENT_DELETED_MAIL, uid)) uids.forEach(uid => this.emit(ImapService.EVENT_DELETED_MAIL, uid))
} }
/**
*
* @param uid delete specific mail per UID
*/
async deleteSpecificEmail(uid) {
debug(`deleting mails ${uid}`)
await this.connection.deleteMessage(uid)
console.log(`deleted mail with UID: ${uid}.`)
this.emit(ImapService.EVENT_DELETED_MAIL, uid)
}
/** /**
* Helper method because ImapSimple#search also fetches each message. We just need the uids here. * Helper method because ImapSimple#search also fetches each message. We just need the uids here.
* *

View File

@ -31,6 +31,11 @@ class MailProcessingService extends EventEmitter {
return this.mailRepository.getForRecipient(address) return this.mailRepository.getForRecipient(address)
} }
deleteSpecificEmail(uid) {
this.imapService.deleteSpecificEmail(uid)
this.mailRepository.removeUid(uid)
}
getOneFullMail(address, uid) { getOneFullMail(address, uid) {
return this.cachedFetchFullMail(address, uid) return this.cachedFetchFullMail(address, uid)
} }
@ -61,7 +66,7 @@ class MailProcessingService extends EventEmitter {
onMailDeleted(uid) { onMailDeleted(uid) {
debug('mail deleted with uid', uid) debug('mail deleted with uid', uid)
this.mailRepository.removeUid(uid) this.mailRepository.removeUid(uid)
// No client notification required, as nobody can cold a connection for 30+ days. // No client notification required, as nobody can hold a connection for 30+ days.
} }
async _deleteOldMails() { async _deleteOldMails() {

View File

@ -26,7 +26,7 @@ class MailRepository {
// TODO: make this more efficient, looping through each email is not cool. // TODO: make this more efficient, looping through each email is not cool.
this.mailSummaries.forEachAssociation((mails, to) => { this.mailSummaries.forEachAssociation((mails, to) => {
mails mails
.filter(mail => mail.uid === uid) .filter(mail => mail.uid === parseInt(uid))
.forEach(mail => { .forEach(mail => {
this.mailSummaries.remove(to, mail) this.mailSummaries.remove(to, mail)
debug('removed ', mail.date, to, mail.subject) debug('removed ', mail.date, to, mail.subject)

View File

@ -7,7 +7,7 @@ function showNewMailsNotification(address, reloadPage) {
const notification = new Notification(address, { const notification = new Notification(address, {
body: 'You have new messages', body: 'You have new messages',
icon: '/images/logo.gif', icon: '/images/logo.gif',
tag: 'voidmail-replace-notification', tag: '48hr-email-replace-notification',
renotify: true renotify: true
}) })
notification.addEventListener('click', event => { notification.addEventListener('click', event => {

View File

@ -39,6 +39,7 @@ router.get(
title: req.params.address, title: req.params.address,
address: req.params.address, address: req.params.address,
mail, mail,
uid: req.params.uid,
madeby: config.branding[1], madeby: config.branding[1],
madebysite: config.branding[2] madebysite: config.branding[2]
}) })
@ -52,4 +53,19 @@ router.get(
} }
) )
router.get(
'^/:address/delete/:uid([0-9]+$)',
sanitizeAddress,
async (req, res, next) => {
try {
const mailProcessingService = req.app.get('mailProcessingService')
await mailProcessingService.deleteSpecificEmail(req.params.uid)
res.redirect(`/${req.params.address}`)
} catch (error) {
console.error('error while deleting email', error)
next(error)
}
}
)
module.exports = router module.exports = router

View File

@ -6,6 +6,9 @@
<a href="/{{ address }}"> <a href="/{{ address }}">
← Return to inbox</a> ← Return to inbox</a>
<br> <br>
<a href="/{{ address }}/delete/{{ uid }}">
Delete Email</a>
<br>
<a href="/login"> <a href="/login">
Logout</a> Logout</a>
</div> </div>

View File

@ -1,6 +1,6 @@
const path = require('path') const path = require('path')
const http = require('http') const http = require('http')
const debug = require('debug')('voidmail:server') const debug = require('debug')('48hr-email:server')
const express = require('express') const express = require('express')
const logger = require('morgan') const logger = require('morgan')
const Twig = require('twig') const Twig = require('twig')