From 72512fbce702638529b5f2f820bf3ff2059f3f7a Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Sun, 12 Mar 2017 13:20:35 +0200 Subject: [PATCH] notify --- imap-core/lib/commands/capability.js | 4 ++- imap-core/lib/commands/copy.js | 3 +- imap-notifier.js | 1 + imap.js | 41 +++++++++++----------------- 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/imap-core/lib/commands/capability.js b/imap-core/lib/commands/capability.js index 207f9874..9dc8f60a 100644 --- a/imap-core/lib/commands/capability.js +++ b/imap-core/lib/commands/capability.js @@ -27,7 +27,9 @@ module.exports = { capabilities.push('UNSELECT'); capabilities.push('ENABLE'); capabilities.push('CONDSTORE'); - capabilities.push('UTF8=ACCEPT'); + // hide UTF8 capability as there are still some bugs related + // to converting data from binary to utf8 charset + //capabilities.push('UTF8=ACCEPT'); } capabilities.sort((a, b) => a.localeCompare(b)); diff --git a/imap-core/lib/commands/copy.js b/imap-core/lib/commands/copy.js index c40f55b7..062700cc 100644 --- a/imap-core/lib/commands/copy.js +++ b/imap-core/lib/commands/copy.js @@ -26,7 +26,8 @@ module.exports = { } let range = command.attributes[0] && command.attributes[0].value || ''; - let mailbox = imapTools.normalizeMailbox(command.attributes[1] && command.attributes[1].value || '', !this.acceptUTF8Enabled); + let mailbox = command.attributes[1] && command.attributes[1].value || ''; + mailbox = imapTools.normalizeMailbox(mailbox, !this.acceptUTF8Enabled); if (!mailbox) { return callback(new Error('Invalid mailbox argument for ' + cmd)); diff --git a/imap-notifier.js b/imap-notifier.js index b0382778..3354d720 100644 --- a/imap-notifier.js +++ b/imap-notifier.js @@ -100,6 +100,7 @@ class ImapNotifier extends EventEmitter { entries.forEach(entry => { entry.created = new Date(); + this.logger.info('NOTIFY "%s":"%s" %s', username, path, JSON.stringify(entry)); }); this.database.collection('mailboxes').findOneAndUpdate({ diff --git a/imap.js b/imap.js index 41cb30a7..0033202f 100644 --- a/imap.js +++ b/imap.js @@ -458,6 +458,18 @@ server.onStore = function (path, update, session, callback) { ]); let notifyEntries = []; + let done = (...args) => { + if (notifyEntries.length) { + setImmediate(() => this.notifier.addEntries(username, path, notifyEntries, () => { + this.notifier.fire(username, path); + return callback(...args); + })); + notifyEntries = []; + return; + } + this.notifier.fire(username, path); + return callback(...args); + }; let processNext = () => { cursor.next((err, message) => { @@ -465,18 +477,7 @@ server.onStore = function (path, update, session, callback) { return callback(err); } if (!message) { - return cursor.close(() => { - if (notifyEntries.length) { - setImmediate(() => this.notifier.addEntries(username, path, notifyEntries, () => { - this.notifier.fire(username, path); - return callback(null, true); - })); - notifyEntries = []; - return; - } - this.notifier.fire(username, path); - return callback(null, true); - }); + return cursor.close(() => done(null, true)); } let flagsupdate = {}; @@ -541,18 +542,7 @@ server.onStore = function (path, update, session, callback) { _id: message._id }, flagsupdate, {}, err => { if (err) { - return cursor.close(() => { - if (notifyEntries.length) { - setImmediate(() => this.notifier.addEntries(username, path, notifyEntries, () => { - this.notifier.fire(username, path); - return callback(err); - })); - notifyEntries = []; - return; - } - this.notifier.fire(username, path); - callback(err); - }); + return cursor.close(() => done(err)); } notifyEntries.push({ @@ -567,8 +557,9 @@ server.onStore = function (path, update, session, callback) { setImmediate(() => this.notifier.addEntries(username, path, notifyEntries, processNext)); notifyEntries = []; return; + } else { + setImmediate(() => processNext()); } - setImmediate(() => processNext()); }); } else { processNext();