diff options
author | Louise Crow <louise.crow@gmail.com> | 2013-06-04 10:29:56 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2013-06-04 10:29:56 +0100 |
commit | a919141992a40599f99b32bd4a8312a0009f3f7a (patch) | |
tree | fbaed74690da0a5ddcc4ad5b38d2d7133ad177a2 /lib/mail_handler/backends | |
parent | dbab7c9e36c06285a042cddd80cef313a9a566b2 (diff) |
Backport ruby 1.9 fix for trailing = sign in message headers from mail 2.5release/0.11
Diffstat (limited to 'lib/mail_handler/backends')
-rw-r--r-- | lib/mail_handler/backends/mail_extensions.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/mail_handler/backends/mail_extensions.rb b/lib/mail_handler/backends/mail_extensions.rb index 54599639b..322c49bb5 100644 --- a/lib/mail_handler/backends/mail_extensions.rb +++ b/lib/mail_handler/backends/mail_extensions.rb @@ -112,4 +112,20 @@ module Mail end end end + class Ruby19 + + def Ruby19.q_value_decode(str) + match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/m) + if match + encoding = match[1] + str = Encodings::QuotedPrintable.decode(match[2].gsub(/_/, '=20')) + # Backport line from mail 2.5 to strip a trailing = character + # Remove trailing = if it exists in a Q encoding + str = str.sub(/\=$/, '') + str.force_encoding(fix_encoding(encoding)) + end + decoded = str.encode("utf-8", :invalid => :replace, :replace => "") + decoded.valid_encoding? ? decoded : decoded.encode("utf-16le", :invalid => :replace, :replace => "").encode("utf-8") + end + end end |