fix: Email encoding issue - utf8 (#1264)
There were issues in parsing Arabic or UTF characters (emojis) correctly for the incoming emails. All these characters were converted to question marks which is teh fallback character when an encoding is enforced and there is a missing matching character.
This commit is contained in:
parent
f9b0427751
commit
381c448627
1 changed files with 4 additions and 2 deletions
|
@ -12,7 +12,7 @@ class MailPresenter < SimpleDelegator
|
|||
end
|
||||
|
||||
def text_content
|
||||
@decoded_text_content ||= encode_to_unicode(text_part&.body&.decoded || fallback_content)
|
||||
@decoded_text_content ||= encode_to_unicode(text_part&.decoded || fallback_content)
|
||||
@text_content ||= {
|
||||
full: @decoded_text_content,
|
||||
reply: extract_reply(@decoded_text_content)[:reply],
|
||||
|
@ -21,7 +21,7 @@ class MailPresenter < SimpleDelegator
|
|||
end
|
||||
|
||||
def html_content
|
||||
@decoded_html_content ||= encode_to_unicode(html_part&.body&.decoded || fallback_content)
|
||||
@decoded_html_content ||= encode_to_unicode(html_part&.decoded || fallback_content)
|
||||
@html_content ||= {
|
||||
full: @decoded_html_content,
|
||||
reply: extract_reply(@decoded_html_content)[:reply],
|
||||
|
@ -70,6 +70,8 @@ class MailPresenter < SimpleDelegator
|
|||
# forcing the encoding of the content to UTF-8 so as to be compatible with database and serializers
|
||||
def encode_to_unicode(str)
|
||||
current_encoding = str.encoding.name
|
||||
return str if current_encoding == 'UTF-8'
|
||||
|
||||
str.encode(current_encoding, 'UTF-8', invalid: :replace, undef: :replace, replace: '?')
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue