diff --git a/config/default.toml b/config/default.toml index 46a725d8..596c319b 100644 --- a/config/default.toml +++ b/config/default.toml @@ -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 diff --git a/imap-core/lib/imap-composer.js b/imap-core/lib/imap-composer.js index 2435289d..40b36f7a 100644 --- a/imap-core/lib/imap-composer.js +++ b/imap-core/lib/imap-composer.js @@ -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: ', - 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: ', + this.connection.id, + description ? ' ' + description : '' + ); + } + obj.pipe( this.connection[!this.connection.compression ? '_socket' : '_deflate'], { diff --git a/imap-core/lib/imap-connection.js b/imap-core/lib/imap-connection.js index 56867dd2..61a09108 100644 --- a/imap-core/lib/imap-connection.js +++ b/imap-core/lib/imap-connection.js @@ -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)); diff --git a/imap-core/lib/imap-server.js b/imap-core/lib/imap-server.js index 67b0408f..e978ac2f 100644 --- a/imap-core/lib/imap-server.js +++ b/imap-core/lib/imap-server.js @@ -82,6 +82,8 @@ class IMAPServer extends EventEmitter { ); } + this.skipFetchLog = options.skipFetchLog; + this._setListeners(); this.loggelf = () => false; diff --git a/imap.js b/imap.js index 98aefd03..b4ed4663 100644 --- a/imap.js +++ b/imap.js @@ -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'); diff --git a/lib/handlers/on-fetch.js b/lib/handlers/on-fetch.js index 181750aa..cbe4c8c3 100644 --- a/lib/handlers/on-fetch.js +++ b/lib/handlers/on-fetch.js @@ -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 );