diff --git a/lib/email_cook.rb b/lib/email_cook.rb
index 209d940ca3d..7a5056167df 100644
--- a/lib/email_cook.rb
+++ b/lib/email_cook.rb
@@ -47,6 +47,8 @@ class EmailCook
quote_buffer = ""
text.each_line do |line|
+ # replace indentation with non-breaking spaces
+ line.sub!(/^\s{2,}/) { |s| "\u00A0" * s.length }
if line =~ /^\s*>/
in_quote = true
diff --git a/spec/components/email_cook_spec.rb b/spec/components/email_cook_spec.rb
index a29259c6111..211b45ff43e 100644
--- a/spec/components/email_cook_spec.rb
+++ b/spec/components/email_cook_spec.rb
@@ -84,6 +84,28 @@ describe EmailCook do
expect(cook(long)).to eq(long_cooked)
end
+ it "replaces indentation of more than 2 spaces with corresponding amount of non-breaking spaces" do
+ nbsp = "\u00A0"
+ long = plaintext(<<~LONG_EMAIL)
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+
+ this is indended by 4 spaces
+ this is indended by 1 space
+ no indentation, but lots of spaces
+ LONG_EMAIL
+
+ long_cooked = <<~LONG_COOKED.strip!
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+
+
#{nbsp}#{nbsp}#{nbsp}#{nbsp}this is indended by 4 spaces
+
this is indended by 1 space
+
no indentation, but lots of spaces
+
+ LONG_COOKED
+
+ expect(cook(long)).to eq(long_cooked)
+ end
+
it "creates oneboxed link when the line contains only a link" do
raw = plaintext("https://www.eviltrout.com")
expect(cook(raw)).to eq('https://www.eviltrout.com
')