From 92674272d5980dd7e64b64792c2af89b1fb4c45f Mon Sep 17 00:00:00 2001 From: ClaraCrazy Date: Wed, 2 Oct 2024 02:36:58 +0200 Subject: [PATCH] retire userRemoveUid function, refactor removeUid --- application/mail-processing-service.js | 2 +- domain/mail-repository.js | 41 ++++++++++---------------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/application/mail-processing-service.js b/application/mail-processing-service.js index 637f9ca..763faa2 100644 --- a/application/mail-processing-service.js +++ b/application/mail-processing-service.js @@ -32,7 +32,7 @@ class MailProcessingService extends EventEmitter { } deleteSpecificEmail(adress, uid) { - if (this.mailRepository.UserRemoveUid(adress, uid) == true) { + if (this.mailRepository.removeUid(uid, adress) == true) { this.imapService.deleteSpecificEmail(uid) } } diff --git a/domain/mail-repository.js b/domain/mail-repository.js index 4b2435d..def5fcf 100644 --- a/domain/mail-repository.js +++ b/domain/mail-repository.js @@ -30,31 +30,22 @@ class MailRepository { this.mailSummaries.set(to.toLowerCase(), mailSummary) } - UserRemoveUid(address, uid) { - var deleted = false - // TODO: make this more efficient, looping through each email is not cool. - this.mailSummaries.forEachAssociation((mails, to) => { - mails - .filter(mail => mail.uid === parseInt(uid) & to == address) - .forEach(mail => { - this.mailSummaries.remove(to, mail) - debug('removed ', mail.date, to, mail.subject) - deleted = true - }) - }) - return deleted - } - - removeUid(uid) { - // TODO: make this more efficient, looping through each email is not cool. - this.mailSummaries.forEachAssociation((mails, to) => { - mails - .filter(mail => mail.uid === parseInt(uid)) - .forEach(mail => { - this.mailSummaries.remove(to, mail) - debug('removed ', mail.date, to, mail.subject) - }) - }) + removeUid(uid, address) { + if (!this.config.http.examples.uids.includes(parseInt(uid))) { + var deleted = false + // TODO: make this more efficient, looping through each email is not cool. + this.mailSummaries.forEachAssociation((mails, to) => { + mails + .filter(mail => mail.uid === parseInt(uid) && (address ? to == address : true)) + .forEach(mail => { + this.mailSummaries.remove(to, mail) + debug('removed ', mail.date, to, mail.subject) + deleted = true + }) + }) + return deleted + } + return false } mailCount() {