wildduck/lib/handlers/on-delete.js

37 lines
843 B
JavaScript

'use strict';
const db = require('../db');
const consts = require('../consts');
// DELETE "path/to/mailbox"
module.exports = (server, mailboxHandler) => (path, session, callback) => {
server.logger.debug(
{
tnx: 'delete',
cid: session.id
},
'[%s] DELETE "%s"',
session.id,
path
);
db.database.collection('mailboxes').findOne(
{
user: session.user.id,
path
},
{
maxTimeMS: consts.DB_MAX_TIME_MAILBOXES
},
(err, mailbox) => {
if (err) {
return callback(err);
}
if (!mailbox) {
return callback(null, 'NONEXISTENT');
}
mailboxHandler.del(session.user.id, mailbox._id, callback);
}
);
};