diff --git a/lib/api/users.js b/lib/api/users.js index dfd19754..2f3be765 100644 --- a/lib/api/users.js +++ b/lib/api/users.js @@ -417,9 +417,15 @@ module.exports = (db, server, userHandler) => { .falsy(['N', 'false', 'no', 'off', 0, '']) .default(false), - imapMaxUpload: Joi.number().min(0), - imapMaxDownload: Joi.number().min(0), - pop3MaxDownload: Joi.number().min(0), + imapMaxUpload: Joi.number() + .min(0) + .default(0), + imapMaxDownload: Joi.number() + .min(0) + .default(0), + pop3MaxDownload: Joi.number() + .min(0) + .default(0), tags: Joi.array().items( Joi.string() @@ -812,10 +818,31 @@ module.exports = (db, server, userHandler) => { db.redis .multi() // sending counters are stored in Redis + + // sent messages .get('wdr:' + userData._id.toString()) .ttl('wdr:' + userData._id.toString()) + + // forwarded messages .get('wdf:' + userData._id.toString()) .ttl('wdf:' + userData._id.toString()) + + // rate limited recipient + .get('rl:rcpt:' + userData._id.toString()) + .ttl('rl:rcpt:' + userData._id.toString()) + + // rate limited imap uploads + .get('iup:' + userData._id.toString()) + .ttl('iup:' + userData._id.toString()) + + // rate limited imap downloads + .get('idw:' + userData._id.toString()) + .ttl('idw:' + userData._id.toString()) + + // rate limited pop3 downloads + .get('pdw:' + userData._id.toString()) + .ttl('pdw:' + userData._id.toString()) + .exec((err, result) => { if (err) { // ignore @@ -831,6 +858,18 @@ module.exports = (db, server, userHandler) => { let forwardsSent = Number(result && result[2] && result[2][1]) || 0; let forwardsTtl = Number(result && result[3] && result[3][1]) || 0; + let received = Number(result && result[4] && result[4][1]) || 0; + let receivedTtl = Number(result && result[5] && result[5][1]) || 0; + + let imapUpload = Number(result && result[6] && result[6][1]) || 0; + let imapUploadTtl = Number(result && result[7] && result[7][1]) || 0; + + let imapDownload = Number(result && result[8] && result[8][1]) || 0; + let imapDownloadTtl = Number(result && result[9] && result[9][1]) || 0; + + let pop3Download = Number(result && result[10] && result[10][1]) || 0; + let pop3DownloadTtl = Number(result && result[11] && result[11][1]) || 0; + res.json({ success: true, id: user, @@ -858,15 +897,41 @@ module.exports = (db, server, userHandler) => { allowed: Number(userData.quota) || config.maxStorage * 1024 * 1024, used: Math.max(Number(userData.storageUsed) || 0, 0) }, + recipients: { allowed: recipients, used: recipientsSent, ttl: recipientsTtl >= 0 ? recipientsTtl : false }, + forwards: { allowed: forwards, used: forwardsSent, ttl: forwardsTtl >= 0 ? forwardsTtl : false + }, + + received: { + allowed: 150, // TODO: most probably should be read from config or user data + used: received, + ttl: receivedTtl >= 0 ? receivedTtl : false + }, + + imapUpload: { + allowed: Number(userData.imapMaxUpload) || (config.imap.maxUploadMB || 10) * 1024 * 1024, + used: imapUpload, + ttl: imapUploadTtl >= 0 ? imapUploadTtl : false + }, + + imapDownload: { + allowed: Number(userData.imapMaxDownload) || (config.imap.maxDownloadMB || 10) * 1024 * 1024, + used: imapDownload, + ttl: imapDownloadTtl >= 0 ? imapDownloadTtl : false + }, + + pop3Download: { + allowed: Number(userData.pop3MaxDownload) || (config.pop3.maxDownloadMB || 10) * 1024 * 1024, + used: pop3Download, + ttl: pop3DownloadTtl >= 0 ? pop3DownloadTtl : false } }, diff --git a/lib/db.js b/lib/db.js index 2f4fca16..f3f3650e 100644 --- a/lib/db.js +++ b/lib/db.js @@ -22,7 +22,7 @@ let getDBConnection = (main, config, callback) => { return callback(null, main.db(config)); } } - MongoClient.connect(config, (err, db) => { + MongoClient.connect(config, { useNewUrlParser: true }, (err, db) => { if (err) { return callback(err); } diff --git a/lib/user-handler.js b/lib/user-handler.js index 30fe5b76..f4598605 100644 --- a/lib/user-handler.js +++ b/lib/user-handler.js @@ -1033,6 +1033,10 @@ class UserHandler { recipients: data.recipients || 0, forwards: data.forwards || 0, + imapMaxUpload: data.imapMaxUpload || 0, + imapMaxDownload: data.imapMaxDownload || 0, + pop3MaxDownload: data.pop3MaxDownload || 0, + targets: [].concat(data.targets || []), // autoreply status diff --git a/package.json b/package.json index 7af1470d..07583bf7 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "eslint-config-nodemailer": "^1.2.0", "grunt": "^1.0.3", "grunt-cli": "^1.2.0", - "grunt-eslint": "^20.1.0", + "grunt-eslint": "^20.2.0", "grunt-mocha-test": "^0.13.3", "grunt-shell-spawn": "^0.3.10", "grunt-wait": "^0.1.0", @@ -49,16 +49,16 @@ "js-yaml": "3.12.0", "key-fingerprint": "1.1.0", "libbase64": "1.0.2", - "libmime": "3.1.0", + "libmime": "4.0.0", "libqp": "1.1.0", "linkify-it": "2.0.3", - "mailsplit": "4.1.2", + "mailsplit": "4.2.0", "mobileconfig": "2.1.0", "mongo-cursor-pagination-node6": "5.0.0", "mongodb": "3.1.0-beta4", "mongodb-extended-json": "1.10.0", "node-forge": "0.7.5", - "nodemailer": "4.6.5", + "nodemailer": "4.6.6", "npmlog": "4.1.2", "openpgp": "3.0.11", "pem": "^1.12.5",