mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
FIX: check we used the right encoding when parsing incoming emails
This commit is contained in:
parent
2ac38e9d05
commit
79329c8e85
1 changed files with 4 additions and 3 deletions
|
@ -162,12 +162,13 @@ module Email
|
|||
return fixed if fixed.present?
|
||||
end
|
||||
|
||||
# 2) default to UTF-8
|
||||
try_to_encode(string, "UTF-8")
|
||||
# 2) try most used encodings
|
||||
try_to_encode(string, "UTF-8") || try_to_encode(string, "ISO-8859-1")
|
||||
end
|
||||
|
||||
def try_to_encode(string, encoding)
|
||||
string.encode("UTF-8", encoding)
|
||||
encoded = string.encode("UTF-8", encoding)
|
||||
encoded.present? && encoded.valid_encoding? ? encoded : nil
|
||||
rescue Encoding::InvalidByteSequenceError,
|
||||
Encoding::UndefinedConversionError,
|
||||
Encoding::ConverterNotFoundError
|
||||
|
|
Loading…
Reference in a new issue