fix: html content is available and mail_part empty (#3964)

This commit is contained in:
Tejaswini Chile
2022-02-14 20:22:58 +05:30
committed by GitHub
parent f34a2e6115
commit de4e4c6f65
3 changed files with 183 additions and 9 deletions

View File

@@ -27,17 +27,21 @@ class MailPresenter < SimpleDelegator
end
# returns encoded mail body text_part if available.
# returns encoded mail body as it is if mail_part not available.
# returns encoded raw mail body as it is if mail_part not available.
# else returns parsed the html body if contains text/html content.
def select_body(mail_part)
return encoded_mail_body unless mail_part
decoded = if mail_part
mail_part.decoded
else
raw_mail_body
end
decoded = encode_to_unicode(mail_part.decoded)
encoded = encode_to_unicode(decoded)
if mail.text_part
decoded
encoded
elsif html_mail_body?
::HtmlParser.parse_reply(decoded)
::HtmlParser.parse_reply(encoded)
end
end
@@ -131,12 +135,15 @@ class MailPresenter < SimpleDelegator
end
def html_mail_body?
((mail.content_type || '').include? 'text/html') || @mail.html_part || @mail.html_part.content_type.include?('text/html')
((mail.content_type || '').include? 'text/html') || @mail.html_part&.content_type&.include?('text/html')
end
# returns mail body if mail content_type is text/plain
def encoded_mail_body
return encode_to_unicode(@mail.body.decoded) if (@mail.content_type || '').include? 'text/plain'
def text_mail_body?
((mail.content_type || '').include? 'text') || @mail.text_part&.content_type&.include?('text')
end
def raw_mail_body
return @mail.body.decoded if html_mail_body? || text_mail_body?
''
end