From b757f8e2c5b7952483ca11f8a49a6119f50df5e4 Mon Sep 17 00:00:00 2001 From: Mantas Date: Wed, 1 Dec 2021 10:33:03 +0200 Subject: [PATCH] Fixes #3870 - Text rendering does not work for e-mails (no new lines) --- app/models/channel/email_parser.rb | 17 ++++++++++++++--- test/data/mail/mail102.box | 6 ++++++ test/data/mail/mail102.yml | 17 ++--------------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 9c132dc48..2ae902c40 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -606,6 +606,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 += "" + end + + memo + end elsif mail.text_part.present? content_type = 'text/plain' @@ -614,9 +628,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 += "" end memo diff --git a/test/data/mail/mail102.box b/test/data/mail/mail102.box index 2b1bb2097..cf02983fc 100644 --- a/test/data/mail/mail102.box +++ b/test/data/mail/mail102.box @@ -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-- diff --git a/test/data/mail/mail102.yml b/test/data/mail/mail102.yml index 4781b5e0b..d34917964 100644 --- a/test/data/mail/mail102.yml +++ b/test/data/mail/mail102.yml @@ -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 - - - - Text - - - - Text - - - - Text - +body: Text

new line

Test 123


Text



Text



Text

Text line

end
content_type: text/html attachments: - !ruby/hash:ActiveSupport::HashWithIndifferentAccess