From f19257e79383dacff878272d1dec3fd8644df715 Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Tue, 25 Jun 2013 13:48:54 -0700 Subject: Add test case and fix for unrecognized encoding in subject line --- lib/mail_handler/backends/mail_extensions.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib/mail_handler/backends/mail_extensions.rb') diff --git a/lib/mail_handler/backends/mail_extensions.rb b/lib/mail_handler/backends/mail_extensions.rb index 6d6a20f8c..a5b6bc97e 100644 --- a/lib/mail_handler/backends/mail_extensions.rb +++ b/lib/mail_handler/backends/mail_extensions.rb @@ -117,6 +117,21 @@ module Mail end class Ruby19 + def Ruby19.b_value_decode(str) + match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/m) + if match + encoding = match[1] + str = Ruby19.decode_base64(match[2]) + # Rescue an ArgumentError arising from an unknown encoding. + begin + str.force_encoding(fix_encoding(encoding)) + rescue ArgumentError + end + end + decoded = str.encode("utf-8", :invalid => :replace, :replace => "") + decoded.valid_encoding? ? decoded : decoded.encode("utf-16le", :invalid => :replace, :replace => "").encode("utf-8") + end + def Ruby19.q_value_decode(str) match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/m) if match -- cgit v1.2.3