mirror of
https://github.com/nodemailer/wildduck.git
synced 2024-11-13 04:46:33 +08:00
43 lines
955 B
JavaScript
43 lines
955 B
JavaScript
'use strict';
|
|
|
|
const db = require('../db');
|
|
const consts = require('../consts');
|
|
|
|
// SUBSCRIBE "path/to/mailbox"
|
|
module.exports = server => (path, session, callback) => {
|
|
server.logger.debug(
|
|
{
|
|
tnx: 'subscribe',
|
|
cid: session.id
|
|
},
|
|
'[%s] SUBSCRIBE to "%s"',
|
|
session.id,
|
|
path
|
|
);
|
|
db.database.collection('mailboxes').findOneAndUpdate(
|
|
{
|
|
user: session.user.id,
|
|
path
|
|
},
|
|
{
|
|
$set: {
|
|
subscribed: true
|
|
}
|
|
},
|
|
{
|
|
maxTimeMS: consts.DB_MAX_TIME_MAILBOXES
|
|
},
|
|
(err, item) => {
|
|
if (err) {
|
|
return callback(err);
|
|
}
|
|
|
|
if (!item || !item.value) {
|
|
// was not able to acquire a lock
|
|
return callback(null, 'NONEXISTENT');
|
|
}
|
|
|
|
callback(null, true);
|
|
}
|
|
);
|
|
};
|