wildduck/lib/handlers/on-rename.js

33 lines
822 B
JavaScript
Raw Normal View History

'use strict';
const db = require('../db');
// RENAME "path/to/mailbox" "new/path"
// NB! RENAME affects child and hierarchy mailboxes as well, this example does not do this
2017-07-21 02:33:41 +08:00
module.exports = (server, mailboxHandler) => (path, newname, session, callback) => {
server.logger.debug(
{
tnx: 'rename',
cid: session.id
},
'[%s] RENAME "%s" to "%s"',
session.id,
path,
newname
);
2017-07-21 02:33:41 +08:00
db.database.collection('mailboxes').findOne({
user: session.user.id,
2017-07-21 02:33:41 +08:00
path
}, (err, mailbox) => {
if (err) {
return callback(err);
}
2017-07-21 02:33:41 +08:00
if (!mailbox) {
return callback(null, 'NONEXISTENT');
}
2017-07-21 02:33:41 +08:00
mailboxHandler.rename(session.user.id, mailbox._id, newname, false, callback);
});
};