mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-09-16 01:54:39 +08:00
log connection events
This commit is contained in:
parent
decec4d2d5
commit
3cc0e3e35b
7 changed files with 65 additions and 23 deletions
|
@ -68,7 +68,8 @@ function authenticate(connection, token, requireClientToken, callback) {
|
|||
method: 'PLAIN',
|
||||
username,
|
||||
password,
|
||||
clientToken
|
||||
clientToken,
|
||||
connection
|
||||
},
|
||||
connection.session,
|
||||
(err, response) => {
|
||||
|
|
|
@ -52,7 +52,8 @@ module.exports = {
|
|||
{
|
||||
method: 'LOGIN',
|
||||
username,
|
||||
password
|
||||
password,
|
||||
connection: this
|
||||
},
|
||||
this.session,
|
||||
(err, response) => {
|
||||
|
|
|
@ -100,6 +100,8 @@ class IMAPConnection extends EventEmitter {
|
|||
}
|
||||
};
|
||||
});
|
||||
|
||||
this.loggelf = () => false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -296,9 +298,15 @@ class IMAPConnection extends EventEmitter {
|
|||
);
|
||||
}
|
||||
|
||||
if (this._closed) {
|
||||
return;
|
||||
}
|
||||
this.loggelf({
|
||||
short_message: '[CONNRELEASE] Connection closed for ' + this.user,
|
||||
_connection: 'release',
|
||||
_service: 'imap',
|
||||
_session: this.session,
|
||||
_user: this.user,
|
||||
_cid: this.id,
|
||||
_ip: this.remoteAddress
|
||||
});
|
||||
|
||||
this._closed = true;
|
||||
this._closing = false;
|
||||
|
@ -774,9 +782,9 @@ class IMAPConnection extends EventEmitter {
|
|||
flag && flag.value
|
||||
? flag
|
||||
: {
|
||||
type: 'ATOM',
|
||||
value: flag
|
||||
}
|
||||
type: 'ATOM',
|
||||
value: flag
|
||||
}
|
||||
);
|
||||
break;
|
||||
|
||||
|
@ -785,9 +793,9 @@ class IMAPConnection extends EventEmitter {
|
|||
value && value.value
|
||||
? value
|
||||
: {
|
||||
type: 'ATOM',
|
||||
value: (value || '0').toString()
|
||||
};
|
||||
type: 'ATOM',
|
||||
value: (value || '0').toString()
|
||||
};
|
||||
break;
|
||||
|
||||
case 'MODSEQ':
|
||||
|
@ -795,9 +803,9 @@ class IMAPConnection extends EventEmitter {
|
|||
value && value.value
|
||||
? value
|
||||
: {
|
||||
type: 'ATOM',
|
||||
value: (value || '0').toString()
|
||||
}
|
||||
type: 'ATOM',
|
||||
value: (value || '0').toString()
|
||||
}
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -52,13 +52,19 @@ class IMAPServer extends EventEmitter {
|
|||
// ignore, should not happen
|
||||
}
|
||||
if (this.options.secured) {
|
||||
return this.connect(socket, socketOptions);
|
||||
return this.connect(
|
||||
socket,
|
||||
socketOptions
|
||||
);
|
||||
}
|
||||
this._upgrade(socket, (err, tlsSocket) => {
|
||||
if (err) {
|
||||
return this._onError(err);
|
||||
}
|
||||
this.connect(tlsSocket, socketOptions);
|
||||
this.connect(
|
||||
tlsSocket,
|
||||
socketOptions
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -68,16 +74,22 @@ class IMAPServer extends EventEmitter {
|
|||
if (err) {
|
||||
// ignore, should not happen
|
||||
}
|
||||
this.connect(socket, socketOptions);
|
||||
this.connect(
|
||||
socket,
|
||||
socketOptions
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
this._setListeners();
|
||||
|
||||
this.loggelf = () => false;
|
||||
}
|
||||
|
||||
connect(socket, socketOptions) {
|
||||
let connection = new IMAPConnection(this, socket, socketOptions);
|
||||
connection.loggelf = message => this.loggelf(message);
|
||||
this.connections.add(connection);
|
||||
connection.on('error', this._onError.bind(this));
|
||||
connection.init();
|
||||
|
|
4
imap.js
4
imap.js
|
@ -127,6 +127,10 @@ let createInterface = (ifaceOptions, callback) => {
|
|||
server.onGetQuotaRoot = onGetQuotaRoot(server);
|
||||
server.onGetQuota = onGetQuota(server);
|
||||
|
||||
if (loggelf) {
|
||||
server.loggelf = loggelf;
|
||||
}
|
||||
|
||||
// start listening
|
||||
server.listen(ifaceOptions.port, ifaceOptions.host, () => {
|
||||
if (started) {
|
||||
|
|
|
@ -33,6 +33,8 @@ module.exports = (server, userHandler, userCache) => (login, session, callback)
|
|||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
let connection = login.connection || {};
|
||||
server.notifier.allocateConnection(
|
||||
{
|
||||
service: 'imap',
|
||||
|
@ -40,7 +42,21 @@ module.exports = (server, userHandler, userCache) => (login, session, callback)
|
|||
user: result.user,
|
||||
limit
|
||||
},
|
||||
next
|
||||
(err, success) => {
|
||||
if (success) {
|
||||
server.loggelf({
|
||||
short_message: '[CONNSTART] Connection established for ' + result.user,
|
||||
_connection: 'establish',
|
||||
_service: 'imap',
|
||||
_session: session,
|
||||
_user: result.user,
|
||||
_cid: connection.id,
|
||||
_ip: connection.remoteAddress,
|
||||
_limit: limit
|
||||
});
|
||||
}
|
||||
next(err, success);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
10
package.json
10
package.json
|
@ -20,7 +20,7 @@
|
|||
"apidoc": "0.17.6",
|
||||
"browserbox": "0.9.1",
|
||||
"chai": "4.2.0",
|
||||
"eslint": "5.7.0",
|
||||
"eslint": "5.8.0",
|
||||
"eslint-config-nodemailer": "1.2.0",
|
||||
"eslint-config-prettier": "3.1.0",
|
||||
"grunt": "1.0.3",
|
||||
|
@ -42,7 +42,7 @@
|
|||
"bcryptjs": "2.4.3",
|
||||
"bugsnag": "2.4.3",
|
||||
"gelf": "2.0.1",
|
||||
"generate-password": "1.4.0",
|
||||
"generate-password": "1.4.1",
|
||||
"he": "1.2.0",
|
||||
"html-to-text": "4.0.0",
|
||||
"humanname": "0.2.2",
|
||||
|
@ -50,7 +50,7 @@
|
|||
"ioredfour": "1.0.2-ioredis-02",
|
||||
"ioredis": "4.2.0",
|
||||
"isemail": "3.2.0",
|
||||
"joi": "14.0.1",
|
||||
"joi": "14.0.2",
|
||||
"js-yaml": "3.12.0",
|
||||
"key-fingerprint": "1.1.0",
|
||||
"libbase64": "1.0.3",
|
||||
|
@ -65,10 +65,10 @@
|
|||
"nodemailer": "4.6.8",
|
||||
"npmlog": "4.1.2",
|
||||
"openpgp": "4.1.2",
|
||||
"pem": "1.13.1",
|
||||
"pem": "1.13.2",
|
||||
"pwnedpasswords": "1.0.4",
|
||||
"qrcode": "1.3.0",
|
||||
"restify": "7.2.1",
|
||||
"restify": "7.2.2",
|
||||
"restify-logger": "2.0.1",
|
||||
"seq-index": "1.1.0",
|
||||
"smtp-server": "3.4.7",
|
||||
|
|
Loading…
Add table
Reference in a new issue