diff --git a/application/imap-service.js b/application/imap-service.js
index 168d79f..6fb4099 100644
--- a/application/imap-service.js
+++ b/application/imap-service.js
@@ -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.
*
diff --git a/application/mail-processing-service.js b/application/mail-processing-service.js
index 67d9e53..9a4d0df 100644
--- a/application/mail-processing-service.js
+++ b/application/mail-processing-service.js
@@ -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() {
diff --git a/domain/mail-repository.js b/domain/mail-repository.js
index 64802d7..ad0a7f5 100644
--- a/domain/mail-repository.js
+++ b/domain/mail-repository.js
@@ -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)
diff --git a/infrastructure/web/public/javascripts/notifications.js b/infrastructure/web/public/javascripts/notifications.js
index 444f374..d3efec9 100644
--- a/infrastructure/web/public/javascripts/notifications.js
+++ b/infrastructure/web/public/javascripts/notifications.js
@@ -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 => {
diff --git a/infrastructure/web/routes/inbox.js b/infrastructure/web/routes/inbox.js
index 3699150..fd90112 100644
--- a/infrastructure/web/routes/inbox.js
+++ b/infrastructure/web/routes/inbox.js
@@ -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
diff --git a/infrastructure/web/views/mail.twig b/infrastructure/web/views/mail.twig
index be36e8c..cda6713 100644
--- a/infrastructure/web/views/mail.twig
+++ b/infrastructure/web/views/mail.twig
@@ -6,6 +6,9 @@
← Return to inbox
+
+ Delete Email
+
Logout
diff --git a/infrastructure/web/web.js b/infrastructure/web/web.js
index 0ba32bf..1448587 100644
--- a/infrastructure/web/web.js
+++ b/infrastructure/web/web.js
@@ -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')