Fixes #3870 - Text rendering does not work for e-mails (no new lines)

This commit is contained in:
Mantas 2021-12-01 10:33:03 +02:00 committed by Mantas Masalskis
parent b3de8b2afa
commit be407c23da
3 changed files with 22 additions and 18 deletions

View file

@ -607,6 +607,20 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again
if mail.html_part&.body.present?
content_type = mail.html_part.mime_type || 'text/plain'
body = body_text(mail.html_part, strict_html: true)
elsif mail.text_part.present? && mail.all_parts.any? { |elem| elem.inline? && elem.content_type&.start_with?('image') }
content_type = 'text/html'
body = mail
.all_parts
.reduce('') do |memo, part|
if part.mime_type == 'text/plain' && !part.attachment?
memo += body_text(part, strict_html: false).text2html
elsif part.inline? && part.content_type&.start_with?('image')
memo += "<img src=\'cid:#{part.cid}\'>"
end
memo
end
elsif mail.text_part.present?
content_type = 'text/plain'
@ -615,9 +629,6 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again
.reduce('') do |memo, part|
if part.mime_type == 'text/plain' && !part.attachment?
memo += body_text(part, strict_html: false)
elsif part.inline? && part.content_type&.start_with?('image')
content_type = 'text/html'
memo += "<img src=\'cid:#{part.cid}\'>"
end
memo

View file

@ -29,6 +29,9 @@ Content-Type: text/plain;
Text
new line
Test 123
--Apple-Mail=_57B3D7B4-58AD-4E7A-9A4A-5053521E2862
Content-Disposition: inline;
@ -6646,5 +6649,8 @@ Content-Type: text/plain;
Text
Text line
end
--Apple-Mail=_57B3D7B4-58AD-4E7A-9A4A-5053521E2862--

View file

@ -4,21 +4,8 @@ from_email: top@secret.tld
from_display_name: Mr. Top Secret
to: zammad@XXXXXXXXX.de
subject: Text - Bild - Text - PDF - Text - Bild - Text
body: |+
Text
<img src='cid:inline_attachment_placeholder_1'>
Text
Text
<img src='cid:inline_attachment_placeholder_2'>
Text
body: Text<br><br>new line<br><br>Test 123<br><img src='cid:inline_attachment_placeholder_1'><br><br>Text<br><br><br><br>Text<br><br><img
src='cid:inline_attachment_placeholder_2'><br><br>Text<br><br>Text line<br><br>end<br>
content_type: text/html
attachments:
- !ruby/hash:ActiveSupport::HashWithIndifferentAccess