Skip to content
Browse files

More work on encode branch for 1.8.7 compat

  • Loading branch information...
1 parent 0cb886c commit b690cb546350160225c544a7b16678ee606ec0a3 @mikel committed
Showing with 11 additions and 9 deletions.
  1. +1 −0 Gemfile
  2. +6 −5 lib/mail/encodings.rb
  3. +2 −2 lib/mail/fields/content_type_field.rb
  4. +2 −2 lib/mail/fields/unstructured_field.rb
View
1 Gemfile
@@ -14,4 +14,5 @@ group :test do
gem "diff-lcs"
gem "ruby-debug" if RUBY_VERSION < '1.9' and RUBY_PLATFORM != 'java'
gem "ruby-debug19" if RUBY_VERSION > '1.9' and RUBY_PLATFORM != 'java'
+ gem "ZenTest"
end
View
11 lib/mail/encodings.rb
@@ -107,14 +107,15 @@ def Encodings.decode_encode(str, output_type)
end
end
end
-
+
# Decodes a given string as Base64 or Quoted Printable, depending on what
# type it is.
#
# String has to be of the format =?<encoding>?[QB]?<string>?=
def Encodings.value_decode(str)
str = str.gsub(/\?=(\s*)=\?/, '?==?') # Remove whitespaces between 'encoded-word's
- # Join QP encoded-words that are adjacent
+
+ # Join QP encoded-words that are adjacent to avoid decoding partial chars
str.gsub!( /=\?==\?.+?\?[Qq]\?/m, '' ) if str =~ /\?==\?/
str.gsub(/(.*?)(=\?.*?\?.\?.*?\?=)|$/m) do # Grab the insides of each encoded-word
@@ -122,9 +123,9 @@ def Encodings.value_decode(str)
text = $2.to_s
case
- when text =~ /=\?.+\?[Bb]\?/m
+ when text.to_str =~ /=\?.+\?[Bb]\?/m
before + b_value_decode(text)
- when text =~ /=\?.+\?[Qq]\?/m
+ when text.to_str =~ /=\?.+\?[Qq]\?/m
before + q_value_decode(text)
else
before + text
@@ -174,7 +175,7 @@ def Encodings.encode_non_usascii(address, charset)
# Encode any non usascii strings embedded inside of quotes
address.gsub!(/(".*?[^#{us_ascii}].+?")/) { |s| Encodings.b_value_encode(unquote(s), charset) }
# Then loop through all remaining items and encode as needed
- tokens = address.mb_chars.split(/\s/)
+ tokens = address.split(/\s/)
tokens.each_with_index.map do |word, i|
if word.ascii_only?
word
View
4 lib/mail/fields/content_type_field.rb
@@ -161,9 +161,9 @@ def sanatize( val )
# Handles misquoted param values
# e.g: application/octet-stream; name=archiveshelp1[1].htm
# and: audio/x-midi;\r\n\tname=Part .exe
- params = $2.to_s.mb_chars.split(/\s+/)
+ params = $2.to_s.split(/\s+/)
params = params.map { |i| i.to_s.chomp.strip }
- params = params.map { |i| i.mb_chars.split(/\s*\=\s*/) }
+ params = params.map { |i| i.split(/\s*\=\s*/) }
params = params.map { |i| "#{i[0]}=#{dquote(i[1].to_s)}" }.join('; ')
"#{type}; #{params}"
when val =~ /^\s*$/
View
4 lib/mail/fields/unstructured_field.rb
@@ -153,8 +153,8 @@ def fold(prepend = 0) # :nodoc:
end
def encode(value)
- value.mb_chars.gsub!("\r", "=0D")
- value.mb_chars.gsub!("\n", "=0A")
+ value.gsub!("\r", "=0D")
+ value.gsub!("\n", "=0A")
Encodings.q_value_encode(value, @charset).split(" ")
end

0 comments on commit b690cb5

Please sign in to comment.
Something went wrong with that request. Please try again.