QoL updates

This commit is contained in:
ClaraCrazy 2025-12-12 19:33:27 +01:00
parent f42fbd4e74
commit 075940b0d8
No known key found for this signature in database
GPG key ID: EBBC896ACB497011
3 changed files with 8 additions and 13 deletions

View file

@ -202,13 +202,11 @@ class ImapService extends EventEmitter {
let uids = [] let uids = []
//fetch mails from date +1day (calculated in MS) to avoid wasting resources and to fix imaps missing time-awareness //fetch mails from date +1day (calculated in MS) to avoid wasting resources and to fix imaps missing time-awareness
if (helper.moreThanOneDay(moment(), deleteMailsBefore)) { if (helper.moreThanOneDay(moment(), deleteMailsBefore)) {
console.log("Deleting mails older than one day");
uids = await this._searchWithoutFetch([ uids = await this._searchWithoutFetch([
['!DELETED'], ['!DELETED'],
['BEFORE', deleteMailsBefore] ['BEFORE', deleteMailsBefore]
]) ])
} else { } else {
console.log("Deleting mails without date filter");
uids = await this._searchWithoutFetch([ uids = await this._searchWithoutFetch([
['!DELETED'], ['!DELETED'],
]) ])
@ -220,17 +218,14 @@ class ImapService extends EventEmitter {
const DeleteOlderThan = helper.purgeTimeStamp() const DeleteOlderThan = helper.purgeTimeStamp()
const uidsWithHeaders = await this._getMailHeaders(uids) const uidsWithHeaders = await this._getMailHeaders(uids)
console.log(`Fetched ${uidsWithHeaders.length} mails for deletion check.`);
uidsWithHeaders.forEach(mail => { uidsWithHeaders.forEach(mail => {
if (mail['attributes'].date > DeleteOlderThan || this.config.email.examples.uids.includes(parseInt(mail['attributes'].uid))) { if (mail['attributes'].date > DeleteOlderThan || this.config.email.examples.uids.includes(parseInt(mail['attributes'].uid))) {
uids = uids.filter(uid => uid !== 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) { if (uids.length === 0) {
console.log("Length 0")
debug('no mails to delete.') debug('no mails to delete.')
return return
} }
@ -239,7 +234,6 @@ class ImapService extends EventEmitter {
await this.connection.deleteMessage(uids) await this.connection.deleteMessage(uids)
uids.forEach(uid => { uids.forEach(uid => {
this.emit(ImapService.EVENT_DELETED_MAIL, uid) this.emit(ImapService.EVENT_DELETED_MAIL, uid)
console.log(`UID deleted: ${uid}`);
}) })
console.log(`deleted ${uids.length} old messages.`) console.log(`deleted ${uids.length} old messages.`)
} }
@ -252,7 +246,7 @@ class ImapService extends EventEmitter {
debug(`deleting mails ${uid}`) debug(`deleting mails ${uid}`)
if (!this.config.email.examples.uids.includes(parseInt(uid))) { if (!this.config.email.examples.uids.includes(parseInt(uid))) {
await this.connection.deleteMessage(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) this.emit(ImapService.EVENT_DELETED_MAIL, uid)
} }
} }

View file

@ -1,9 +1,9 @@
const EventEmitter = require('events') const EventEmitter = require('events')
const debug = require('debug')('48hr-email:imap-manager') const debug = require('debug')('48hr-email:imap-manager')
const mem = require('mem') const mem = require('mem')
const moment = require('moment')
const ImapService = require('./imap-service') const ImapService = require('./imap-service')
const Helper = require('./helper') const Helper = require('./helper')
const config = require('./config')
const helper = new(Helper) const helper = new(Helper)
@ -26,9 +26,12 @@ class MailProcessingService extends EventEmitter {
this.imapService.once(ImapService.EVENT_INITIAL_LOAD_DONE, () => this.imapService.once(ImapService.EVENT_INITIAL_LOAD_DONE, () =>
this._deleteOldMails() this._deleteOldMails()
) )
console.log(`Running old mail deletion every ${this.config.imap.refreshIntervalSeconds} seconds`)
setInterval(() => { setInterval(() => {
this._deleteOldMails() this._deleteOldMails()
}, 60 * 1000) }, this.config.imap.refreshIntervalSeconds * 1000)
} }
getMailSummaries(address) { getMailSummaries(address) {
@ -51,9 +54,7 @@ class MailProcessingService extends EventEmitter {
onInitialLoadDone() { onInitialLoadDone() {
this.initialLoadDone = true this.initialLoadDone = true
console.log( console.log(`initial load done, got ${this.mailRepository.mailCount()} mails`)
`initial load done, got ${this.mailRepository.mailCount()} mails`
)
} }
onNewMail(mail) { onNewMail(mail) {

View file

@ -15,7 +15,7 @@ class MailRepository {
mails.forEach(mail => { mails.forEach(mail => {
if (mail.to == this.config.email.examples.account && !this.config.email.examples.uids.includes(parseInt(mail.uid))) { 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) 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']) return _.orderBy(mails, mail => Date.parse(mail.date), ['desc'])