mirror of
https://github.com/Crazyco-xyz/48hr.email.git
synced 2025-12-14 13:56:32 +01:00
QoL updates
This commit is contained in:
parent
f42fbd4e74
commit
075940b0d8
3 changed files with 8 additions and 13 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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'])
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue