Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZMS-196 #772

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions lib/imap-notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,19 +393,29 @@ class ImapNotifier extends EventEmitter {
}

let rlkey = 'lim:' + data.service;
this.counters.limitedcounter(rlkey, data.user, 1, data.limit || 15, (err, res) => {
if (err) {
return callback(err);
}
const { closed: socketClosed, connecting, destroyed } = data.session?.socket || {};

if (!res.success) {
return callback(null, false);
}
if (!socketClosed && !connecting && !destroyed) {
// socket alive, not closed
this.counters.limitedcounter(rlkey, data.user, 1, data.limit || 15, (err, res) => {
if (err) {
return callback(err);
}

this.connectionSessions.set(data.session, { service: data.service, user: data.user });
if (!res.success) {
return callback(null, false);
}

return callback(null, true);
});
this.connectionSessions.set(data.session, { service: data.service, user: data.user });

return callback(null, true);
});
} else {
// socket dead/closed/undefined
const err = new Error('[ALERT] Socket closed unexpectedly before authentication completed.');
err.response = 'NO';
return callback(err, false);
}
}

releaseConnection(data, callback) {
Expand Down