mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-11-03 19:50:14 +08:00
notify
This commit is contained in:
parent
b535afeb3d
commit
8c7e4a6e5b
2 changed files with 6 additions and 9 deletions
|
|
@ -92,7 +92,6 @@ class ImapNotifier extends EventEmitter {
|
|||
* @param {Function} callback Runs once the entry is either stored or an error occurred
|
||||
*/
|
||||
addEntries(username, path, entries, callback) {
|
||||
this.logger.info('NOTIFY "%s":"%s" %s', username, path, JSON.stringify(entries));
|
||||
if (entries && !Array.isArray(entries)) {
|
||||
entries = [entries];
|
||||
} else if (!entries || !entries.length) {
|
||||
|
|
|
|||
14
imap.js
14
imap.js
|
|
@ -460,11 +460,12 @@ server.onStore = function (path, update, session, callback) {
|
|||
let notifyEntries = [];
|
||||
let done = (...args) => {
|
||||
if (notifyEntries.length) {
|
||||
setImmediate(() => this.notifier.addEntries(username, path, notifyEntries, () => {
|
||||
let entries = notifyEntries;
|
||||
notifyEntries = [];
|
||||
setImmediate(() => this.notifier.addEntries(username, path, entries, () => {
|
||||
this.notifier.fire(username, path);
|
||||
return callback(...args);
|
||||
}));
|
||||
notifyEntries = [];
|
||||
return;
|
||||
}
|
||||
this.notifier.fire(username, path);
|
||||
|
|
@ -474,7 +475,7 @@ server.onStore = function (path, update, session, callback) {
|
|||
let processNext = () => {
|
||||
cursor.next((err, message) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
return done(err);
|
||||
}
|
||||
if (!message) {
|
||||
return cursor.close(() => done(null, true));
|
||||
|
|
@ -537,8 +538,6 @@ server.onStore = function (path, update, session, callback) {
|
|||
}));
|
||||
}
|
||||
|
||||
this.logger.info('UPDATED: %s', updated ? 'YES' : 'NO');
|
||||
|
||||
if (updated) {
|
||||
database.collection('messages').findOneAndUpdate({
|
||||
_id: message._id
|
||||
|
|
@ -555,11 +554,10 @@ server.onStore = function (path, update, session, callback) {
|
|||
message: message._id
|
||||
});
|
||||
|
||||
this.logger.info('NOTIFY: %s', JSON.stringify(notifyEntries));
|
||||
|
||||
if (notifyEntries.length > 100) {
|
||||
setImmediate(() => this.notifier.addEntries(username, path, notifyEntries, processNext));
|
||||
let entries = notifyEntries;
|
||||
notifyEntries = [];
|
||||
setImmediate(() => this.notifier.addEntries(username, path, entries, processNext));
|
||||
return;
|
||||
} else {
|
||||
setImmediate(() => processNext());
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue