diff --git a/application/imap-service.js b/application/imap-service.js index 49b2649..b20a0c6 100644 --- a/application/imap-service.js +++ b/application/imap-service.js @@ -202,13 +202,11 @@ class ImapService extends EventEmitter { let uids = [] //fetch mails from date +1day (calculated in MS) to avoid wasting resources and to fix imaps missing time-awareness if (helper.moreThanOneDay(moment(), deleteMailsBefore)) { - console.log("Deleting mails older than one day"); uids = await this._searchWithoutFetch([ ['!DELETED'], ['BEFORE', deleteMailsBefore] ]) } else { - console.log("Deleting mails without date filter"); uids = await this._searchWithoutFetch([ ['!DELETED'], ]) @@ -220,17 +218,14 @@ class ImapService extends EventEmitter { const DeleteOlderThan = helper.purgeTimeStamp() const uidsWithHeaders = await this._getMailHeaders(uids) - console.log(`Fetched ${uidsWithHeaders.length} mails for deletion check.`); uidsWithHeaders.forEach(mail => { if (mail['attributes'].date > DeleteOlderThan || this.config.email.examples.uids.includes(parseInt(mail['attributes'].uid))) { uids = uids.filter(uid => uid !== mail['attributes'].uid) - console.log(mail['attributes'].date > DeleteOlderThan ? `Mail UID: ${mail['attributes'].uid} is newer than purge time.` : `Mail UID: ${mail['attributes'].uid} is an example mail.`); } }) if (uids.length === 0) { - console.log("Length 0") debug('no mails to delete.') return } @@ -239,7 +234,6 @@ class ImapService extends EventEmitter { await this.connection.deleteMessage(uids) uids.forEach(uid => { this.emit(ImapService.EVENT_DELETED_MAIL, uid) - console.log(`UID deleted: ${uid}`); }) console.log(`deleted ${uids.length} old messages.`) } @@ -252,7 +246,7 @@ class ImapService extends EventEmitter { debug(`deleting mails ${uid}`) if (!this.config.email.examples.uids.includes(parseInt(uid))) { await this.connection.deleteMessage(uid) - console.log(`deleted mail with UID: ${uid}.`) + debug(`deleted mail with UID: ${uid}.`) this.emit(ImapService.EVENT_DELETED_MAIL, uid) } } diff --git a/application/mail-processing-service.js b/application/mail-processing-service.js index 5f1fd07..305425b 100644 --- a/application/mail-processing-service.js +++ b/application/mail-processing-service.js @@ -1,9 +1,9 @@ const EventEmitter = require('events') const debug = require('debug')('48hr-email:imap-manager') const mem = require('mem') -const moment = require('moment') const ImapService = require('./imap-service') const Helper = require('./helper') +const config = require('./config') const helper = new(Helper) @@ -26,9 +26,12 @@ class MailProcessingService extends EventEmitter { this.imapService.once(ImapService.EVENT_INITIAL_LOAD_DONE, () => this._deleteOldMails() ) + + console.log(`Running old mail deletion every ${this.config.imap.refreshIntervalSeconds} seconds`) + setInterval(() => { this._deleteOldMails() - }, 60 * 1000) + }, this.config.imap.refreshIntervalSeconds * 1000) } getMailSummaries(address) { @@ -51,9 +54,7 @@ class MailProcessingService extends EventEmitter { onInitialLoadDone() { this.initialLoadDone = true - console.log( - `initial load done, got ${this.mailRepository.mailCount()} mails` - ) + console.log(`initial load done, got ${this.mailRepository.mailCount()} mails`) } onNewMail(mail) { diff --git a/domain/mail-repository.js b/domain/mail-repository.js index d8d7585..0297d8d 100644 --- a/domain/mail-repository.js +++ b/domain/mail-repository.js @@ -15,7 +15,7 @@ class MailRepository { mails.forEach(mail => { if (mail.to == this.config.email.examples.account && !this.config.email.examples.uids.includes(parseInt(mail.uid))) { mails = mails.filter(m => m.uid != mail.uid) - console.log('prevented non-example email from being shown in example inbox', mail.uid) + debug('prevented non-example email from being shown in example inbox', mail.uid) } }) return _.orderBy(mails, mail => Date.parse(mail.date), ['desc'])