allow to skip logging fetch output

This commit is contained in:
Andris Reinman 2018-11-16 10:01:18 +02:00
parent c763c72127
commit bc334a37be
6 changed files with 40 additions and 17 deletions

View file

@ -46,6 +46,8 @@ bugsnagCode=""
[log]
level="silly"
skipFetchLog=false # if true, then does not output individual * FETCH responses to log
# delete authentication log entries after 30 days
# changing this value only affects new entries
# set to false to not log authentication events

View file

@ -9,7 +9,9 @@ class IMAPComposer extends Transform {
Transform.call(this, {
writableObjectMode: true
});
options = options || {};
this.connection = options.connection;
this.skipFetchLog = options.skipFetchLog;
}
_transform(obj, encoding, done) {
@ -20,16 +22,19 @@ class IMAPComposer extends Transform {
if (typeof obj.pipe === 'function') {
// pipe stream to socket and wait until it finishes before continuing
let description = [obj.description, obj._mailbox, obj._message, obj._uid].filter(v => v).join('/');
this.connection.logger.debug(
{
tnx: 'pipeout',
cid: this.connection.id
},
'[%s] S: <fetch response%s>',
this.connection.id,
description ? ' ' + description : ''
);
if (!this.skipFetchLog) {
let description = [obj.description, obj._mailbox, obj._message, obj._uid].filter(v => v).join('/');
this.connection.logger.debug(
{
tnx: 'pipeout',
cid: this.connection.id
},
'[%s] S: <fetch response%s>',
this.connection.id,
description ? ' ' + description : ''
);
}
obj.pipe(
this.connection[!this.connection.compression ? '_socket' : '_deflate'],
{

View file

@ -40,7 +40,8 @@ class IMAPConnection extends EventEmitter {
this._socket = socket;
this.writeStream = new IMAPComposer({
connection: this
connection: this,
skipFetchLog: server.skipFetchLog
});
this.writeStream.pipe(this._socket);
this.writeStream.on('error', this._onError.bind(this));

View file

@ -82,6 +82,8 @@ class IMAPServer extends EventEmitter {
);
}
this.skipFetchLog = options.skipFetchLog;
this._setListeners();
this.loggelf = () => false;

View file

@ -78,7 +78,9 @@ let createInterface = (ifaceOptions, callback) => {
logger,
maxMessage: config.imap.maxMB * 1024 * 1024,
maxStorage: config.maxStorage * 1024 * 1024
maxStorage: config.maxStorage * 1024 * 1024,
skipFetchLog: config.log.skipFetchLog
};
certs.loadTLSOptions(serverOptions, 'imap');

View file

@ -3,7 +3,6 @@
const config = require('wild-config');
const IMAPServerModule = require('../../imap-core');
const imapHandler = IMAPServerModule.imapHandler;
const util = require('util');
const db = require('../db');
const tools = require('../tools');
const consts = require('../consts');
@ -131,6 +130,16 @@ module.exports = (server, messageHandler, userCache) => (mailbox, options, sessi
}
if (!messageData) {
return cursor.close(() => {
server.logger.debug(
{
tnx: 'fetch',
cid: session.id
},
'[%s] FETCHOK rows=%s',
session.id,
rowCount
);
done(null, true);
});
}
@ -158,7 +167,7 @@ module.exports = (server, messageHandler, userCache) => (mailbox, options, sessi
})
);
stream.description = util.format('* FETCH #%s uid=%s size=%sB ', ++rowCount, messageData.uid, messageData.size);
rowCount++;
stream.once('error', err => {
err.processed = true;
@ -166,11 +175,13 @@ module.exports = (server, messageHandler, userCache) => (mailbox, options, sessi
{
err,
tnx: 'fetch',
cid: session.id
cid: session.id,
mid: messageData._id
},
'[%s] FETCHFAIL %s. %s',
'[%s] FETCHFAIL message=%s rows=%s error=%s',
session.id,
messageData._id,
rowCount,
err.message
);
@ -200,7 +211,7 @@ module.exports = (server, messageHandler, userCache) => (mailbox, options, sessi
tnx: 'flags',
cid: session.id
},
'[%s] UPDATE FLAGS for "%s"',
'[%s] UPDATE FLAGS message=%s',
session.id,
messageData.uid
);