diff --git a/.env.example b/.env.example index d89bf7b..6fc97c7 100644 --- a/.env.example +++ b/.env.example @@ -10,6 +10,7 @@ EMAIL_PURGE_CONVERT=true # Convert to hig # --- Example emails to keep clean --- EMAIL_EXAMPLE_ACCOUNT="example@48hr.email" # example email to preserve EMAIL_EXAMPLE_UIDS=[1,2,3] # example UIDs to preserve +EMAIL_BLACKLISTED_SENDERS=[] # List of email addresses to block (Useful to prevent account generators) ["noreply@facebook.com", "noreply@amazon.com"] # --- IMAP CONFIGURATION --- IMAP_USER="user@example.com" # IMAP username diff --git a/application/config.js b/application/config.js index 990bd48..d98437e 100644 --- a/application/config.js +++ b/application/config.js @@ -40,7 +40,8 @@ const config = { examples: { account: parseValue(process.env.EMAIL_EXAMPLE_ACCOUNT), uids: parseValue(process.env.EMAIL_EXAMPLE_UIDS) - } + }, + blacklistedSenders: parseValue(process.env.EMAIL_BLACKLISTED_SENDERS) || [] }, imap: { @@ -84,4 +85,4 @@ if (!config.email.domains.length) { debug(`Configuration validated successfully: ${config.email.domains.length} domains, IMAP host: ${config.imap.host}`) -module.exports = config; \ No newline at end of file +module.exports = config; diff --git a/application/mail-processing-service.js b/application/mail-processing-service.js index 39e530b..06d3069 100644 --- a/application/mail-processing-service.js +++ b/application/mail-processing-service.js @@ -144,6 +144,20 @@ class MailProcessingService extends EventEmitter { onNewMail(mail) { debug('onNewMail called for:', mail.to) + + // Check if sender is blacklisted + const senderAddress = mail.from && mail.from[0] && mail.from[0].address + if (senderAddress && this.config.email.blacklistedSenders.length > 0) { + const isBlacklisted = this.config.email.blacklistedSenders.some(blocked => + blocked.toLowerCase() === senderAddress.toLowerCase() + ) + if (isBlacklisted) { + debug(`Blacklisted sender detected: ${senderAddress}, deleting UID ${mail.uid}`) + this.imapService.deleteSpecificEmail(mail.uid) + return + } + } + if (this.initialLoadDone) { // For now, only log messages if they arrive after the initial load debug('New mail for', mail.to[0]) @@ -210,4 +224,4 @@ class MailProcessingService extends EventEmitter { } } -module.exports = MailProcessingService \ No newline at end of file +module.exports = MailProcessingService diff --git a/package.json b/package.json index a9025c6..37e90e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "48hr.email", - "version": "1.8.0", + "version": "1.8.1", "private": false, "description": "48hr.email is your favorite open-source tempmail client.", "keywords": [ @@ -78,4 +78,4 @@ ] }] } -} \ No newline at end of file +}