mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-09-06 13:14:34 +08:00
notify
This commit is contained in:
parent
d6b028997f
commit
72512fbce7
4 changed files with 22 additions and 27 deletions
|
@ -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));
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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
41
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();
|
||||
|
|
Loading…
Add table
Reference in a new issue