A platform for community discussion. Free, open, simple.
FIX: Don't elide numbered lists from Word emails (#42103)
Régis Hanol6f082bc7a43d
diff --git a/lib/email/receiver.rb b/lib/email/receiver.rbindex 8479afac287..6d81b969283 100644--- a/lib/email/receiver.rb+++ b/lib/email/receiver.rb@@ -545,10 +545,8 @@ module Emaildef extract_from_word(doc)# Word (?) keeps the content in the 'WordSection1' class and uses <p> tags# When there's something else (<table>, <div>, etc..) there's high chance it's a signature or forwarded email- elided =- doc.css(- ".WordSection1 > :not(p):not(ul):first-of-type, .WordSection1 > :not(p):not(ul):first-of-type ~ *",- ).remove+ signature_start = ".WordSection1 > :not(p):not(ul):not(ol):first-of-type"+ elided = doc.css("#{signature_start}, #{signature_start} ~ *").removeto_markdown(doc.at(".WordSection1").to_html, elided.to_html)enddiff --git a/spec/fixtures/emails/word_html_reply.eml b/spec/fixtures/emails/word_html_reply.emlnew file mode 100644index 00000000000..76f9cc8388f--- /dev/null+++ b/spec/fixtures/emails/word_html_reply.eml@@ -0,0 +1,25 @@+Return-Path: <[email protected]>+From: Foo Bar <[email protected]>+To: [email protected]+Date: Fri, 15 Jan 2017 00:12:43 +0100+Message-ID: <[email protected]>+Mime-Version: 1.0+Content-Type: text/html; charset=UTF-8+Content-Transfer-Encoding: quoted-printable++<div class="WordSection1">+ <p class="MsoNormal">This is the <b>body</b> of the email.</p>+ <ul>+ <li>a bullet</li>+ <li>another bullet</li>+ </ul>+ <p class="MsoNormal">And these are the steps to follow:</p>+ <ol>+ <li>a first step</li>+ <li>a second step</li>+ </ol>+ <p class="MsoNormal">That's all folks!</p>+ <div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">+ <p class="MsoNormal">This is the <i>elided</i> part!</p>+ </div>+</div>diff --git a/spec/lib/email/receiver_spec.rb b/spec/lib/email/receiver_spec.rbindex 5a787d4f6c3..80c9662d0d0 100644--- a/spec/lib/email/receiver_spec.rb+++ b/spec/lib/email/receiver_spec.rb@@ -2059,6 +2059,23 @@ RSpec.describe Email::Receiver doMDend+ it "keeps the lists and only elides the signature from word emails" do+ expect { process(:word_html_reply) }.to change { topic.posts.count }+ expect(topic.posts.last.raw).to eq <<~MD.strip+ This is the **body** of the email.++ - a bullet+ - another bullet++ And these are the steps to follow:++ 1. a first step+ 1. a second step++ That's all folks!+ MD+ end+it "doesn't process email with same message-id more than once" doexpect doprocess(:text_reply)