Add delete button
parent
b2c51c186d
commit
1865a08c87
|
@ -216,6 +216,17 @@ class ImapService extends EventEmitter {
|
|||
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.
|
||||
*
|
||||
|
|
|
@ -31,6 +31,11 @@ class MailProcessingService extends EventEmitter {
|
|||
return this.mailRepository.getForRecipient(address)
|
||||
}
|
||||
|
||||
deleteSpecificEmail(uid) {
|
||||
this.imapService.deleteSpecificEmail(uid)
|
||||
this.mailRepository.removeUid(uid)
|
||||
}
|
||||
|
||||
getOneFullMail(address, uid) {
|
||||
return this.cachedFetchFullMail(address, uid)
|
||||
}
|
||||
|
@ -61,7 +66,7 @@ class MailProcessingService extends EventEmitter {
|
|||
onMailDeleted(uid) {
|
||||
debug('mail deleted with uid', 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() {
|
||||
|
|
|
@ -26,7 +26,7 @@ class MailRepository {
|
|||
// TODO: make this more efficient, looping through each email is not cool.
|
||||
this.mailSummaries.forEachAssociation((mails, to) => {
|
||||
mails
|
||||
.filter(mail => mail.uid === uid)
|
||||
.filter(mail => mail.uid === parseInt(uid))
|
||||
.forEach(mail => {
|
||||
this.mailSummaries.remove(to, mail)
|
||||
debug('removed ', mail.date, to, mail.subject)
|
||||
|
|
|
@ -7,7 +7,7 @@ function showNewMailsNotification(address, reloadPage) {
|
|||
const notification = new Notification(address, {
|
||||
body: 'You have new messages',
|
||||
icon: '/images/logo.gif',
|
||||
tag: 'voidmail-replace-notification',
|
||||
tag: '48hr-email-replace-notification',
|
||||
renotify: true
|
||||
})
|
||||
notification.addEventListener('click', event => {
|
||||
|
|
|
@ -39,6 +39,7 @@ router.get(
|
|||
title: req.params.address,
|
||||
address: req.params.address,
|
||||
mail,
|
||||
uid: req.params.uid,
|
||||
madeby: config.branding[1],
|
||||
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
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
<a href="/{{ address }}">
|
||||
← Return to inbox</a>
|
||||
<br>
|
||||
<a href="/{{ address }}/delete/{{ uid }}">
|
||||
Delete Email</a>
|
||||
<br>
|
||||
<a href="/login">
|
||||
Logout</a>
|
||||
</div>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const path = require('path')
|
||||
const http = require('http')
|
||||
const debug = require('debug')('voidmail:server')
|
||||
const debug = require('debug')('48hr-email:server')
|
||||
const express = require('express')
|
||||
const logger = require('morgan')
|
||||
const Twig = require('twig')
|
||||
|
|
Loading…
Reference in New Issue