FIX: Do not strip email lines having lists.

FIX: Do not strip email lines having lists.

diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb
index 07231c7..669f70d 100644
--- a/lib/email/receiver.rb
+++ b/lib/email/receiver.rb
@@ -364,6 +364,10 @@ module Email
         text = text.lines.map! do |line|
           stripped = line.strip << "\n"
 
+          # Do not strip list items.
+          next line if (stripped[0] == '*' || stripped[0] == '-' || stripped[0] == '+') && stripped[1] == ' '
+
+          # Match beginning and ending of code blocks.
           if !in_code && stripped[0..2] == '`‍``'
             in_code = '`‍``'
           elsif in_code == '`‍``' && stripped[0..2] == '`‍``'
@@ -374,6 +378,7 @@ module Email
             in_code = nil
           end
 
+          # Strip only lines outside code blocks.
           in_code ? line : stripped
         end.join
       end
diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb
index ecc056b..1181867 100644
--- a/spec/components/email/receiver_spec.rb
+++ b/spec/components/email/receiver_spec.rb
@@ -1274,6 +1274,18 @@ describe Email::Receiver do
       This is a line that will not be touched.
       This is another line that will not be touched.
 
+      * list
+
+        * sub-list
+
+      - list
+
+        - sub-list
+
+      + list
+
+        + sub-list
+
       [code]
         1.upto(10).each do |i|
           puts i
@@ -1308,6 +1320,18 @@ describe Email::Receiver do
       This is a line that will not be touched.
       This is another line that will not be touched.
 
+      * list
+
+        * sub-list
+
+      - list
+
+        - sub-list
+
+      + list
+
+        + sub-list
+
       [code]
         1.upto(10).each do |i|
           puts i

GitHub sha: 35a866fe

2 Likes

This commit has been mentioned on Discourse Meta. There might be relevant details there: