Use proper filtering function, remove helper array

pull/16/head
ClaraCrazy 2024-10-01 23:51:18 +02:00
parent dc7d7e6676
commit 1f0d57bad0
No known key found for this signature in database
GPG Key ID: EBBC896ACB497011
1 changed files with 9 additions and 11 deletions

View File

@ -199,7 +199,7 @@ class ImapService extends EventEmitter {
* @param {Date} deleteMailsBefore delete mails before this date instance
*/
async deleteOldMails(deleteMailsBefore) {
const uids = await this._searchWithoutFetch([
let uids = await this._searchWithoutFetch([
['!DELETED'],
['BEFORE', deleteMailsBefore]
])
@ -207,28 +207,26 @@ class ImapService extends EventEmitter {
return
}
debug(`deleting mails ${uids}`)
const DeleteOlderThan = moment()
.subtract(this.config.email.deleteMailsOlderThanDays, 'days')
.toDate()
let toDelete = []
const uidwithHeaders = await this._getMailHeaders(uids)
uidwithHeaders.forEach(mail => {
if (mail['attributes'].date < DeleteOlderThan) {
toDelete.push(mail['attributes'].uid)
const uidsWithHeaders = await this._getMailHeaders(uids)
uidsWithHeaders.forEach(mail => {
if (mail['attributes'].date > DeleteOlderThan) {
uids.filter(uid => uid !== mail['attributes'].uid)
}
})
if (toDelete.length === 0) {
if (uids.length === 0) {
debug('no mails to delete.')
return
}
await this.connection.deleteMessage(toDelete)
debug(`deleting mails ${uids}`)
await this.connection.deleteMessage(uids)
toDelete.forEach(uid => this.emit(ImapService.EVENT_DELETED_MAIL, uid))
console.log(`deleted ${toDelete.length} old messages.`)
console.log(`deleted ${uids.length} old messages.`)
}
/**