mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-01-08 17:07:44 +08:00
36 lines
755 B
JavaScript
36 lines
755 B
JavaScript
|
'use strict';
|
||
|
|
||
|
const db = require('../db');
|
||
|
|
||
|
// 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
|
||
|
}
|
||
|
}, {}, (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);
|
||
|
});
|
||
|
};
|