mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-01-10 09:58:08 +08:00
57 lines
1.4 KiB
JavaScript
57 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
const db = require('../db');
|
|
|
|
// CREATE "path/to/mailbox"
|
|
module.exports = server => (path, session, callback) => {
|
|
server.logger.debug(
|
|
{
|
|
tnx: 'create',
|
|
cid: session.id
|
|
},
|
|
'[%s] CREATE "%s"',
|
|
session.id,
|
|
path
|
|
);
|
|
db.database.collection('mailboxes').findOne({
|
|
user: session.user.id,
|
|
path
|
|
}, (err, mailbox) => {
|
|
if (err) {
|
|
return callback(err);
|
|
}
|
|
if (mailbox) {
|
|
return callback(null, 'ALREADYEXISTS');
|
|
}
|
|
|
|
db.users.collection('users').findOne({
|
|
_id: session.user.id
|
|
}, {
|
|
fields: {
|
|
retention: true
|
|
}
|
|
}, (err, user) => {
|
|
if (err) {
|
|
return callback(err);
|
|
}
|
|
|
|
mailbox = {
|
|
user: session.user.id,
|
|
path,
|
|
uidValidity: Math.floor(Date.now() / 1000),
|
|
uidNext: 1,
|
|
modifyIndex: 0,
|
|
subscribed: true,
|
|
flags: [],
|
|
retention: user.retention
|
|
};
|
|
|
|
db.database.collection('mailboxes').insertOne(mailbox, err => {
|
|
if (err) {
|
|
return callback(err);
|
|
}
|
|
return callback(null, true);
|
|
});
|
|
});
|
|
});
|
|
};
|