aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mail_handler/backends/mail_extensions.rb
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2013-06-03 10:50:17 +0100
committerLouise Crow <louise.crow@gmail.com>2013-06-03 10:50:17 +0100
commit050b25bd70909913b7e42d53cb69c31b1396cc46 (patch)
treeac2f2b587ffa3504c5cf5164b36f5f436c0582f4 /lib/mail_handler/backends/mail_extensions.rb
parent4db18138584b6394286bbe374f22e6609ab79136 (diff)
parente30a8623a1706d3bad4476198085547d8f47cc88 (diff)
Merge branch 'release/0.11' into wdtk
Diffstat (limited to 'lib/mail_handler/backends/mail_extensions.rb')
-rw-r--r--lib/mail_handler/backends/mail_extensions.rb40
1 files changed, 39 insertions, 1 deletions
diff --git a/lib/mail_handler/backends/mail_extensions.rb b/lib/mail_handler/backends/mail_extensions.rb
index f756abd1a..d25012e39 100644
--- a/lib/mail_handler/backends/mail_extensions.rb
+++ b/lib/mail_handler/backends/mail_extensions.rb
@@ -64,4 +64,42 @@ module Mail
end.join(";\r\n\s")
end
end
-end \ No newline at end of file
+
+ # HACK: Backport encoding fixes for Ruby 1.8 from Mail 2.5
+ # Can be removed when we no longer support Ruby 1.8
+ class Ruby18
+ def Ruby18.b_value_decode(str)
+ match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/m)
+ if match
+ encoding = match[1]
+ str = Ruby18.decode_base64(match[2])
+ str = Iconv.conv('UTF-8//IGNORE', fix_encoding(encoding), str)
+ end
+ str
+ end
+
+ def Ruby18.q_value_decode(str)
+ match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/m)
+ if match
+ encoding = match[1]
+ string = match[2].gsub(/_/, '=20')
+ # 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)
+ end
+ str
+ end
+
+ private
+
+ def Ruby18.fix_encoding(encoding)
+ case encoding.upcase
+ when 'UTF8'
+ 'UTF-8'
+ else
+ encoding
+ end
+ end
+ end
+end