A platform for community discussion. Free, open, simple.
FIX: Gracefully handle inline images in emails (#12855)
Bianca Nenciue6329d30077e
diff --git a/lib/email/receiver.rb b/lib/email/receiver.rbindex bd328678531..b580e7ea408 100644--- a/lib/email/receiver.rb+++ b/lib/email/receiver.rb@@ -1124,8 +1124,8 @@ module Emailraw = raw.sub(match, replacement)endend- elsif raw[/\[image:.*?\d+[^\]]*\]/i]- raw.sub!(/\[image:.*?\d+[^\]]*\]/i, UploadMarkdown.new(upload).to_markdown)+ elsif raw[/\[image:[^\]]*\]/i]+ raw.sub!(/\[image:[^\]]*\]/i, UploadMarkdown.new(upload).to_markdown)elseraw << "\n\n#{UploadMarkdown.new(upload).to_markdown}\n\n"enddiff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rbindex b3b5a083b33..fcdc094058c 100644--- a/spec/components/email/receiver_spec.rb+++ b/spec/components/email/receiver_spec.rb@@ -585,6 +585,19 @@ describe Email::Receiver doMDend+ it "gracefully handles malformed images in HTML part" do+ expect { process(:inline_image_2) }.to change { topic.posts.count }++ post = topic.posts.last+ upload = post.uploads.last++ expect(post.raw).to eq(<<~MD.chomp)+ [image:#{'0' * 5000}++ + MD+ end+it "supports attached images in signature" doSiteSetting.incoming_email_prefer_html = trueSiteSetting.always_show_trimmed_content = truediff --git a/spec/fixtures/emails/inline_image_2.eml b/spec/fixtures/emails/inline_image_2.emlnew file mode 100644index 00000000000..cba266dc87b--- /dev/null+++ b/spec/fixtures/emails/inline_image_2.eml@@ -0,0 +1,26 @@+Return-Path: <[email protected]>+From: Foo Bar <[email protected]>+To: [email protected]+Date: Fri, 15 Jan 2016 00:12:43 +0100+Message-ID: <[email protected]>+Mime-Version: 1.0+Content-Type: multipart/related; boundary="0000000000006d045f05c0e384eb"++--0000000000006d045f05c0e384eb+Content-Type: multipart/alternative; boundary="0000000000006d045b05c0e384ea"++--0000000000006d045b05c0e384ea+Content-Type: text/html; charset="UTF-8"++[image:00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000++--0000000000006d045b05c0e384ea--+--0000000000006d045f05c0e384eb+Content-Type: image/png; name="poc.png"+Content-Disposition: attachment; filename="poc.png"+Content-Transfer-Encoding: base64+X-Attachment-Id: ii_poc0+Content-ID: <ii_poc0>++iVBORw0KGgoAAAANSUhEUgAABm4AAAHTCAIAAAChr3DwAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAg+--0000000000006d045f05c0e384eb--