diff options
author | Louise Crow <louise.crow@gmail.com> | 2013-06-03 18:01:11 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2013-06-03 18:01:11 +0100 |
commit | af003d8cd5909e1c7e1827d70f9ed7dd9586d738 (patch) | |
tree | ac56038a4361b812850865f4f11e7020f280462d /lib/mail_handler/backends/mail_extensions.rb | |
parent | e30a8623a1706d3bad4476198085547d8f47cc88 (diff) | |
parent | 9a4b220be62dcaceee45c70316c1a58a92abcfc5 (diff) |
Merge branch 'hotfix/0.11.0.1' into release/0.110.11.0.1
Diffstat (limited to 'lib/mail_handler/backends/mail_extensions.rb')
-rw-r--r-- | lib/mail_handler/backends/mail_extensions.rb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/mail_handler/backends/mail_extensions.rb b/lib/mail_handler/backends/mail_extensions.rb index d25012e39..54599639b 100644 --- a/lib/mail_handler/backends/mail_extensions.rb +++ b/lib/mail_handler/backends/mail_extensions.rb @@ -73,7 +73,12 @@ module Mail if match encoding = match[1] str = Ruby18.decode_base64(match[2]) - str = Iconv.conv('UTF-8//IGNORE', fix_encoding(encoding), str) + # Adding and removing trailing spaces is a workaround + # for Iconv.conv throwing an exception if it finds an + # invalid character at the end of the string, even + # with UTF-8//IGNORE: + # http://po-ru.com/diary/fixing-invalid-utf-8-in-ruby-revisited/ + str = Iconv.conv('UTF-8//IGNORE', fix_encoding(encoding), str + " ")[0...-4] end str end @@ -86,7 +91,12 @@ module Mail # Remove trailing = if it exists in a Q encoding string = string.sub(/\=$/, '') str = Encodings::QuotedPrintable.decode(string) - str = Iconv.conv('UTF-8//IGNORE', fix_encoding(encoding), str) + # Adding and removing trailing spaces is a workaround + # for Iconv.conv throwing an exception if it finds an + # invalid character at the end of the string, even + # with UTF-8//IGNORE: + # http://po-ru.com/diary/fixing-invalid-utf-8-in-ruby-revisited/ + str = Iconv.conv('UTF-8//IGNORE', fix_encoding(encoding), str + " ")[0...-4] end str end |