From 99181bb3b8b05f49c5a26fc81a04527b8d2974e6 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Fri, 2 Oct 2020 15:44:35 +0200 Subject: [PATCH] FIX: Stripping lines from incoming email shouldn't fail for blank body (#10800) --- lib/email/receiver.rb | 2 +- spec/components/email/receiver_spec.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index f27b8518c89..e1aa8ea17df 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -395,7 +395,7 @@ module Email text, elided_text, text_format = markdown, elided_markdown, Receiver::formats[:markdown] end - if SiteSetting.strip_incoming_email_lines + if SiteSetting.strip_incoming_email_lines && text.present? in_code = nil text = text.lines.map! do |line| diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb index 5cd9b9946cc..62e2158fa5b 100644 --- a/spec/components/email/receiver_spec.rb +++ b/spec/components/email/receiver_spec.rb @@ -1549,6 +1549,25 @@ describe Email::Receiver do expect(text).to eq(stripped_text) end + it "works with empty mail body" do + SiteSetting.strip_incoming_email_lines = true + + email = <<~EOF + Date: Tue, 01 Jan 2019 00:00:00 +0300 + Subject: An email with whitespaces + From: Foo + To: bar@discourse.org + Content-Type: text/plain; charset="UTF-8" + + -- + my signature + + EOF + + receiver = Email::Receiver.new(email) + text, _elided, _format = receiver.select_body + expect(text).to be_blank + end end describe "replying to digest" do