This commit is contained in:
Andris Reinman 2017-03-12 13:20:35 +02:00
parent d6b028997f
commit 72512fbce7
4 changed files with 22 additions and 27 deletions

View file

@ -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));

View file

@ -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));

View file

@ -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({

41
imap.js
View file

@ -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();