diff --git a/lib/db.js b/lib/db.js index 80bb216..2f4fca1 100644 --- a/lib/db.js +++ b/lib/db.js @@ -16,7 +16,7 @@ module.exports.redisConfig = false; let getDBConnection = (main, config, callback) => { if (main) { if (!config) { - return callback(null, main); + return callback(null, false); } if (config && !/[:/]/.test(config)) { return callback(null, main.db(config)); @@ -26,6 +26,9 @@ let getDBConnection = (main, config, callback) => { if (err) { return callback(err); } + if (main && db.s && db.s.options && db.s.options.dbName) { + db = db.db(db.s.options.dbName); + } return callback(null, db); }); }; @@ -35,22 +38,30 @@ module.exports.connect = callback => { if (err) { return callback(err); } - module.exports.database = db; + + if (db.s && db.s.options && db.s.options.dbName) { + module.exports.database = db.db(db.s.options.dbName); + } else { + module.exports.database = db; + } + getDBConnection(db, config.dbs.gridfs, (err, gdb) => { if (err) { return callback(err); } - module.exports.gridfs = gdb || db; + module.exports.gridfs = gdb || module.exports.database; + getDBConnection(db, config.dbs.users, (err, udb) => { if (err) { return callback(err); } - module.exports.users = udb || db; + module.exports.users = udb || module.exports.database; + getDBConnection(db, config.dbs.sender, (err, sdb) => { if (err) { return callback(err); } - module.exports.senderDb = sdb || db; + module.exports.senderDb = sdb || module.exports.database; module.exports.redisConfig = tools.redisConfig(config.dbs.redis); module.exports.redis = new Redis(module.exports.redisConfig); diff --git a/lib/maildropper.js b/lib/maildropper.js index 88f71df..1fc1a60 100644 --- a/lib/maildropper.js +++ b/lib/maildropper.js @@ -16,7 +16,6 @@ class Maildropper { constructor(options) { this.options = options || {}; this.db = options.db; - this.enabled = !!options.enabled; this.zone = options.zone; this.collection = options.collection; this.gfs = options.gfs; @@ -29,11 +28,6 @@ class Maildropper { } push(options, callback) { - if (!this.enabled) { - setImmediate(() => callback(null, false)); - return false; - } - let id = options.id || seqIndex.get(); let seq = 0; let documents = []; diff --git a/package.json b/package.json index 2030fc8..a490582 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,10 @@ "test": "mongo --eval 'db.dropDatabase()' wildduck-test && redis-cli -n 13 flushdb && NODE_ENV=test grunt", "apidoc": "apidoc -i lib/api/ -o docs/" }, - "keywords": ["imap", "mail server"], + "keywords": [ + "imap", + "mail server" + ], "author": "Andris Reinman", "license": "EUPL-1.1", "devDependencies": { @@ -42,14 +45,14 @@ "ioredis": "3.2.2", "joi": "13.0.2", "js-yaml": "3.10.0", - "libbase64": "1.0.1", + "libbase64": "1.0.2", "libmime": "3.1.0", "libqp": "1.1.0", "linkify-it": "2.0.3", - "mailsplit": "4.1.1", + "mailsplit": "4.1.2", "mobileconfig": "2.1.0", "mongo-cursor-pagination-node6": "5.0.0", - "mongodb": "2.2.33", + "mongodb": "3.0.0-rc0", "mongodb-extended-json": "^1.10.0", "nodemailer": "4.4.1", "npmlog": "4.1.2",