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

fix: fixed edge cases when session could be null #699

Merged
merged 2 commits into from
Jun 28, 2024
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
37 changes: 19 additions & 18 deletions lib/pop3/connection.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

'use strict';

const crypto = require('crypto');
Expand Down Expand Up @@ -134,7 +135,7 @@ class POP3Connection extends EventEmitter {
tnx: 'close',
cid: this.id,
host: this.remoteAddress,
user: this.session.user && this.session.user.username
user: this?.session?.user?.username
},
'Connection closed to %s',
this.remoteAddress
Expand Down Expand Up @@ -162,7 +163,7 @@ class POP3Connection extends EventEmitter {
{
err,
tnx: 'error',
user: this.session.user && this.session.user.username
user: this?.session?.user?.username
},
'%s',
err.message
Expand Down Expand Up @@ -256,7 +257,7 @@ class POP3Connection extends EventEmitter {
{
tnx: 'receive',
cid: this.id,
user: this.session.user && this.session.user.username
user: this?.session?.user?.username
},
this.id + ' C: <%s bytes of continue data>',
Buffer.byteLength(line)
Expand Down Expand Up @@ -293,7 +294,7 @@ class POP3Connection extends EventEmitter {
{
tnx: 'receive',
cid: this.id,
user: this.session.user && this.session.user.username
user: this?.session?.user?.username
},
this.id + ' C:',
logLine
Expand Down Expand Up @@ -332,10 +333,10 @@ class POP3Connection extends EventEmitter {
let extensions = [
'TOP',
'UIDL',
(this.secured || this._server.options.ignoreSTARTTLS) && !this.session.user ? 'USER' : false,
(this.secured || this._server.options.ignoreSTARTTLS) && !this?.session?.user ? 'USER' : false,
'RESP-CODES',
// https://tools.ietf.org/html/rfc5034#section-6
(this.secured || this._server.options.ignoreSTARTTLS) && !this.session.user ? 'SASL PLAIN' : false,
(this.secured || this._server.options.ignoreSTARTTLS) && !this?.session?.user ? 'SASL PLAIN' : false,
// https://tools.ietf.org/html/rfc2449#section-6.6
'PIPELINING',
!this.secured && !this._server.options.disableSTARTTLS ? 'STLS' : false,
Expand Down Expand Up @@ -374,7 +375,7 @@ class POP3Connection extends EventEmitter {
return next();
}

if (!this.session.user || !args) {
if (!this?.session?.user || !args) {
return next(new Error('malformed command'));
}

Expand Down Expand Up @@ -519,8 +520,8 @@ class POP3Connection extends EventEmitter {
_message_id: message.id,
_message_uid: message.uid,
_mailbox: message.mailbox,
_username: this.session.user && this.session.user.username,
_user: this.session.user && this.session.user.id,
_username: this?.session?.user?.username,
_user: this?.session?.user?.id,
_sess: this.id,
_ip: this.remoteAddress
});
Expand Down Expand Up @@ -734,8 +735,8 @@ class POP3Connection extends EventEmitter {
_message_uid: message.uid,
_mailbox: message.mailbox,
_message_size: message.size,
_username: this.session.user && this.session.user.username,
_user: this.session.user && this.session.user.id,
_username: this?.session?.user?.username,
_user: this?.session?.user?.id,
_sess: this.id,
_ip: this.remoteAddress,

Expand Down Expand Up @@ -765,8 +766,8 @@ class POP3Connection extends EventEmitter {
_message_uid: message.uid,
_mailbox: message.mailbox,
_message_size: message.size,
_username: this.session.user && this.session.user.username,
_user: this.session.user && this.session.user.id,
_username: this?.session?.user?.username,
_user: this?.session?.user?.id,
_sess: this.id,
_ip: this.remoteAddress
});
Expand Down Expand Up @@ -817,8 +818,8 @@ class POP3Connection extends EventEmitter {
_message_uid: message.uid,
_mailbox: message.mailbox,
_message_size: message.size,
_username: this.session.user && this.session.user.username,
_user: this.session.user && this.session.user.id,
_username: this?.session?.user?.username,
_user: this?.session?.user?.id,
_sess: this.id,
_ip: this.remoteAddress,

Expand Down Expand Up @@ -1007,10 +1008,10 @@ class POP3Connection extends EventEmitter {
err,
tnx: 'listerr',
cid: this.id,
user: this.session.user && this.session.user.username
user: this?.session?.user?.username
},
'Failed listing messages for %s. %s',
this.session.user.username,
this?.session?.user?.username,
err.message
);
return next(err);
Expand Down Expand Up @@ -1041,7 +1042,7 @@ class POP3Connection extends EventEmitter {
{
tnx: 'starttls',
cid: this.id,
user: this.session && this.session.user && this.session.user.username,
user: this?.session?.user?.username,
cipher: cipher && cipher.name
},
'[%s] Connection upgraded to TLS using ',
Expand Down