Fixes #2407, Fixes #3003 - Mac Mail inline PDF destroys E-Mail-Body

This commit is contained in:
Mantas 2021-07-16 12:15:00 +03:00 committed by Thorsten Eckel
parent 66b14aa274
commit f50016b008
3 changed files with 6720 additions and 4 deletions

View file

@ -600,11 +600,27 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again
end
def message_body_hash(mail)
message = [mail.html_part, mail.text_part, mail].find { |m| m&.body.present? }
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?
content_type = 'text/plain'
if message.present? && (message.mime_type.nil? || message.mime_type.match?(%r{^text/(plain|html)$}))
content_type = message.mime_type || 'text/plain'
body = body_text(message, strict_html: content_type.eql?('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)
elsif part.inline? && part.content_type&.start_with?('image')
content_type = 'text/html'
memo += "<img src=\'cid:#{part.cid}\'>"
end
memo
end
elsif mail&.body.present? && (mail.mime_type.nil? || mail.mime_type.match?(%r{^text/(plain|html)$}))
content_type = mail.mime_type || 'text/plain'
body = body_text(mail, strict_html: content_type.eql?('text/html'))
end
content_type = 'text/plain' if body.blank?
@ -685,6 +701,7 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again
def get_attachments(file, attachments, mail)
return file.parts.map { |p| get_attachments(p, attachments, mail) } if file.parts.any?
return [] if [mail.text_part&.body&.encoded, mail.html_part&.body&.encoded].include?(file.body.encoded)
return [] if file.content_type&.start_with?('text/plain') && !file.attachment?
# get file preferences
headers_store = {}

6650
test/data/mail/mail102.box Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long