From 9f4ef8f57a839c5529b4f00a36b832740386b4ed Mon Sep 17 00:00:00 2001 From: Wouter van Os Date: Mon, 23 Jan 2023 16:09:35 +0100 Subject: [PATCH] fix: do not change \r to \r\n (#2154) As this may cause issues when a new buffer is exactly in between \r and \n. Fixes #1624 --- lib/postal/smtp_server/server.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/postal/smtp_server/server.rb b/lib/postal/smtp_server/server.rb index 4aa1412..41c2096 100644 --- a/lib/postal/smtp_server/server.rb +++ b/lib/postal/smtp_server/server.rb @@ -165,8 +165,9 @@ module Postal eof = true end - # Normalize all \r\n and \n to \r\n - buffers[io] = buffers[io].encode(buffers[io].encoding, universal_newline: true).encode(buffers[io].encoding, crlf_newline: true) + # Normalize all \r\n and \n to \r\n, but ignore only \r. + # A \r\n may be split in 2 buffers (\n in one buffer and \r in the other) + buffers[io] = buffers[io].gsub(/\r/,"").encode(buffers[io].encoding, crlf_newline: true) # We line buffer, so look to see if we have received a newline # and keep doing so until all buffered lines have been processed.