diff --git a/app/models/mailboxes.js b/app/models/mailboxes.js index 4d1bcd6d3..008c5436c 100644 --- a/app/models/mailboxes.js +++ b/app/models/mailboxes.js @@ -176,7 +176,9 @@ Mailboxes.pre('save', async function (next) { // default to `alias.retention` or 0 this.retention = ['\\Trash', '\\Junk'].includes(this.specialUse) ? ms('30d') - : alias.retention; + : typeof alias.retention === 'number' + ? alias.retention + : 0; next(); } catch (err) { diff --git a/helpers/imap/on-append.js b/helpers/imap/on-append.js index 086129e4d..b3349529f 100644 --- a/helpers/imap/on-append.js +++ b/helpers/imap/on-append.js @@ -146,13 +146,15 @@ async function onAppend(path, flags, date, raw, session, fn) { // // prepare message for creation // + const retention = + typeof mailbox.retention === 'number' ? mailbox.retention : 0; const data = { alias: alias._id, mailbox: mailbox._id, _id: id, root: id, - exp: mailbox.retention !== 0, - rdate: Date.now() + mailbox.retention, + exp: retention !== 0, + rdate: new Date(Date.now() + retention), idate, hdate, flags, diff --git a/helpers/imap/on-copy.js b/helpers/imap/on-copy.js index 17dab5dd5..f6ff67d2d 100644 --- a/helpers/imap/on-copy.js +++ b/helpers/imap/on-copy.js @@ -26,7 +26,7 @@ const SocketError = require('#helpers/socket-error'); const i18n = require('#helpers/i18n'); const refineAndLogError = require('#helpers/refine-and-log-error'); -// eslint-disable-next-line max-params +// eslint-disable-next-line max-params, complexity async function onCopy(connection, mailboxId, update, session, fn) { this.logger.debug('COPY', { connection, mailboxId, update, session }); @@ -141,8 +141,16 @@ async function onCopy(connection, mailboxId, update, session, fn) { message.id = message._id.toString(); message.mailbox = targetMailbox._id; message.uid = updatedMailbox.uidNext; - message.exp = targetMailbox.retention !== 0; - message.rdate = Date.now() + targetMailbox.retention; + message.exp = + typeof targetMailbox.retention === 'number' + ? targetMailbox.retention !== 0 + : false; + message.rdate = new Date( + Date.now() + + (typeof targetMailbox.retention === 'number' + ? targetMailbox.retention + : 0) + ); message.modseq = updatedMailbox.modifyIndex; message.junk = targetMailbox.specialUse === '\\Junk'; message.remoteAddress = session.remoteAddress; diff --git a/helpers/imap/on-move.js b/helpers/imap/on-move.js index 1b5fb0036..5270c18f1 100644 --- a/helpers/imap/on-move.js +++ b/helpers/imap/on-move.js @@ -190,8 +190,11 @@ async function onMove(mailboxId, update, session, fn) { message.id = message._id.toString(); message.mailbox = targetMailbox._id; message.uid = updatedTargetMailbox.uidNext; - message.exp = targetMailbox.retention !== 0; - message.rdate = Date.now() + targetMailbox.retention; + message.exp = + typeof targetMailbox.retention === 'number' + ? targetMailbox.retention !== 0 + : false; + message.rdate = new Date(Date.now() + (targetMailbox.retention || 0)); message.modseq = updatedTargetMailbox.modifyIndex; message.junk = targetMailbox.specialUse === '\\Junk'; message.remoteAddress = session.remoteAddress;