From 8f7b184cd13b65859a13d325f48993c8346ecd56 Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Wed, 20 Mar 2019 15:00:57 +0200 Subject: [PATCH] v1.15.0 --- lib/filter-handler.js | 1 + lib/mailbox-handler.js | 94 +++++++++++++++++++++++++----------------- lib/message-handler.js | 28 +++++++++++-- package.json | 22 +++++----- 4 files changed, 93 insertions(+), 52 deletions(-) diff --git a/lib/filter-handler.js b/lib/filter-handler.js index 74146f33..544de691 100644 --- a/lib/filter-handler.js +++ b/lib/filter-handler.js @@ -524,6 +524,7 @@ class FilterHandler { let messageOpts = { user: userData._id, [mailboxQueryKey]: mailboxQueryValue, + inboxDefault: true, // if mailbox is not found, then store to INBOX prepared, maildata, diff --git a/lib/mailbox-handler.js b/lib/mailbox-handler.js index c1a134e7..9642b4b0 100644 --- a/lib/mailbox-handler.js +++ b/lib/mailbox-handler.js @@ -199,49 +199,67 @@ class MailboxHandler { return callback(err); } - // send information about deleted mailbox straightly to connected clients - this.notifier.fire(mailboxData.user, { - command: 'DROP', - mailbox - }); - - this.notifier.addEntries( - mailboxData, + // delete matching filters as well + this.database.collection('filters').deleteOne( { - command: 'DELETE', - mailbox + user, + 'action.mailbox': mailbox }, - () => { - this.database.collection('messages').updateMany( - { + err => { + if (err) { + this.loggelf({ + user, mailbox, - uid: { - $gt: 0, - $lt: mailboxData.uidNext + 100 - } - }, - { - $set: { - exp: true, - // make sure the messages are in top of the expire queue - rdate: Date.now() - 24 * 3600 * 1000 - } - }, - { - multi: true, - w: 1 - }, - err => { - if (err) { - return callback(err); - } + action: 'delete_filter', + error: err.message + }); + } - let done = () => { - this.notifier.fire(mailboxData.user); - callback(null, true, mailbox); - }; + // send information about deleted mailbox straightly to connected clients + this.notifier.fire(mailboxData.user, { + command: 'DROP', + mailbox + }); - return done(); + this.notifier.addEntries( + mailboxData, + { + command: 'DELETE', + mailbox + }, + () => { + this.database.collection('messages').updateMany( + { + mailbox, + uid: { + $gt: 0, + $lt: mailboxData.uidNext + 100 + } + }, + { + $set: { + exp: true, + // make sure the messages are in top of the expire queue + rdate: Date.now() - 24 * 3600 * 1000 + } + }, + { + multi: true, + w: 1 + }, + err => { + if (err) { + return callback(err); + } + + let done = () => { + this.notifier.fire(mailboxData.user); + callback(null, true, mailbox); + }; + + return done(); + } + ); } ); } diff --git a/lib/message-handler.js b/lib/message-handler.js index 68a1f9e3..3f1cd262 100644 --- a/lib/message-handler.js +++ b/lib/message-handler.js @@ -79,18 +79,40 @@ class MessageHandler { } } - this.database.collection('mailboxes').findOne(query, (err, mailbox) => { + this.database.collection('mailboxes').findOne(query, (err, mailboxData) => { if (err) { return callback(err); } - if (!mailbox) { + if (!mailboxData) { + if (options.path !== 'INBOX' && options.inboxDefault) { + return this.database.collection('mailboxes').findOne( + { + user: options.user, + path: 'INBOX' + }, + (err, mailboxData) => { + if (err) { + return callback(err); + } + + if (!mailboxData) { + let err = new Error('Mailbox is missing'); + err.imapResponse = 'TRYCREATE'; + return callback(err); + } + + callback(null, mailboxData); + } + ); + } + let err = new Error('Mailbox is missing'); err.imapResponse = 'TRYCREATE'; return callback(err); } - callback(null, mailbox); + callback(null, mailboxData); }); } diff --git a/package.json b/package.json index 9a15fe59..3422600e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wildduck", - "version": "1.14.1", + "version": "1.15.0", "description": "IMAP/POP3 server built with Node.js and MongoDB", "main": "server.js", "scripts": { @@ -15,13 +15,13 @@ "author": "Andris Reinman", "license": "EUPL-1.1+", "devDependencies": { - "ajv": "6.9.2", + "ajv": "6.10.0", "apidoc": "0.17.7", "browserbox": "0.9.1", "chai": "4.2.0", - "eslint": "5.14.1", + "eslint": "5.15.3", "eslint-config-nodemailer": "1.2.0", - "eslint-config-prettier": "4.0.0", + "eslint-config-prettier": "4.1.0", "grunt": "1.0.3", "grunt-cli": "1.3.2", "grunt-eslint": "21.0.0", @@ -29,8 +29,8 @@ "grunt-shell-spawn": "0.4.0", "grunt-wait": "0.3.0", "icedfrisby": "1.5.0", - "mailparser": "2.4.3", - "mocha": "^5.2.0", + "mailparser": "2.5.0", + "mocha": "5.2.0", "request": "2.88.0" }, "dependencies": { @@ -48,7 +48,7 @@ "ioredis": "4.6.2", "isemail": "3.2.0", "joi": "14.3.1", - "js-yaml": "3.12.1", + "js-yaml": "3.12.2", "key-fingerprint": "1.1.0", "libbase64": "1.0.3", "libmime": "4.0.1", @@ -58,14 +58,14 @@ "mongo-cursor-pagination": "7.1.0", "mongodb": "3.1.13", "mongodb-extended-json": "1.10.1", - "node-forge": "0.8.1", + "node-forge": "0.8.2", "nodemailer": "5.1.1", "npmlog": "4.1.2", - "openpgp": "4.4.7", + "openpgp": "4.4.10", "pem": "1.14.2", "pwnedpasswords": "1.0.4", "qrcode": "1.3.3", - "restify": "8.0.0", + "restify": "8.2.0", "restify-logger": "2.0.1", "seq-index": "1.1.0", "smtp-server": "3.5.0", @@ -74,7 +74,7 @@ "utf7": "1.0.2", "uuid": "3.3.2", "wild-config": "1.4.0", - "yargs": "13.2.1" + "yargs": "13.2.2" }, "repository": { "type": "git",