From 1d42862c463562942d7007d4d57755a3d581fe9e Mon Sep 17 00:00:00 2001 From: ClaraCrazy Date: Wed, 2 Oct 2024 02:36:25 +0200 Subject: [PATCH] Add example mail(s) --- application/config.sample.js | 6 +++++- application/imap-service.js | 10 ++++++---- domain/mail-repository.js | 10 +++++++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/application/config.sample.js b/application/config.sample.js index e982589..3d2dd2c 100644 --- a/application/config.sample.js +++ b/application/config.sample.js @@ -14,7 +14,11 @@ const config = { }, http: { port: normalizePort(process.env.HTTP_PORT || 3000), - branding: process.env.HTTP_BRANDING || ["48hr.email", "CrazyCo", "https://crazyco.xyz"] + branding: process.env.HTTP_BRANDING || ["48hr.email", "CrazyCo", "https://crazyco.xyz"], + examples: process.env.HTTP_EXAMPLES || { + email: "example@48hr.email", + ids: [1, 2, 3] + } }, } diff --git a/application/imap-service.js b/application/imap-service.js index d127a7d..2567f8c 100644 --- a/application/imap-service.js +++ b/application/imap-service.js @@ -213,7 +213,7 @@ class ImapService extends EventEmitter { const uidsWithHeaders = await this._getMailHeaders(uids) uidsWithHeaders.forEach(mail => { - if (mail['attributes'].date > DeleteOlderThan) { + if (mail['attributes'].date > DeleteOlderThan || this.config.http.examples.uids.includes(parseInt(mail['attributes'].id))) { uids.filter(uid => uid !== mail['attributes'].uid) } }) @@ -235,9 +235,11 @@ class ImapService extends EventEmitter { */ 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) + if (!this.config.http.examples.uids.includes(parseInt(uid))) { + await this.connection.deleteMessage(uid) + console.log(`deleted mail with UID: ${uid}.`) + this.emit(ImapService.EVENT_DELETED_MAIL, uid) + } } /** diff --git a/domain/mail-repository.js b/domain/mail-repository.js index 5b154ac..4b2435d 100644 --- a/domain/mail-repository.js +++ b/domain/mail-repository.js @@ -1,15 +1,23 @@ const debug = require('debug')('48hr-email:mail-summary-store') const MultiMap = require('mnemonist/multi-map') const _ = require('lodash') +const config = require('../application/config') class MailRepository { constructor() { // MultiMap docs: https://yomguithereal.github.io/mnemonist/multi-map this.mailSummaries = new MultiMap() + this.config = config } getForRecipient(address) { - const mails = this.mailSummaries.get(address) || [] + let mails = this.mailSummaries.get(address) || [] + mails.forEach(mail => { + if (mail.to == this.config.http.examples.email && !this.config.http.examples.uids.includes(parseInt(mail.uid))) { + mails = mails.filter(m => m.uid != mail.uid) + console.log('prevent non-example email from being shown', mail.uid) + } + }) return _.orderBy(mails, mail => Date.parse(mail.date), ['desc']) }