diff --git a/imap-core/lib/length-limiter.js b/imap-core/lib/length-limiter.js index 8569f0c2..1bf96f2c 100644 --- a/imap-core/lib/length-limiter.js +++ b/imap-core/lib/length-limiter.js @@ -63,8 +63,10 @@ class LengthLimiter extends Transform { _flush(done) { if (!this.finished) { // add padding if incoming stream stopped too early - let buf = Buffer.from(this.padding.repeat(this.expectedLength - this.byteCounter)); - this.push(buf); + if (this.expectedLength > this.byteCounter) { + let buf = Buffer.from(this.padding.repeat(this.expectedLength - this.byteCounter)); + this.push(buf); + } this.finished = true; } done();