Skip to content

Commit

Permalink
fix: fixed mailbox rdate issue
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Oct 18, 2023
1 parent b377a4f commit 7918a1f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
4 changes: 3 additions & 1 deletion app/models/mailboxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions helpers/imap/on-append.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 11 additions & 3 deletions helpers/imap/on-copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions helpers/imap/on-move.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7918a1f

Please sign in to comment.