Browse files

Fixed parsing error 'Subject: =?ISO-8859-1?Q?Re=3A_ol=E1?=' (has a ne…

…w line embedded)
  • Loading branch information...
1 parent a237917 commit 4b6335e44ad7f3e0cdda0f2e45dc1d5f718a3998 @mikel committed Dec 17, 2009
View
4 CHANGELOG.rdoc
@@ -1,3 +1,7 @@
+== Thu Dec 17 06:35:05 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
+
+* Fixed parsing error 'Subject: =?ISO-8859-1?Q?Re=3A_ol=E1?=' (has a new line embedded)
+
== Thu Dec 17 02:14:23 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
* Version 1.3.4
View
8 lib/mail/encodings/encodings.rb
@@ -91,14 +91,14 @@ def Encodings.decode_encode(str, output_type)
# String has to be of the format =?<encoding>?[QB]?<string>?=
def Encodings.value_decode(str)
str.gsub!(/\?=(\s*)=\?/, '?==?') # Remove whitespaces between 'encoded-word's
- str.gsub(/(.*?)(=\?.*?\?.\?.*?\?=)|$/) do
+ str.gsub(/(.*?)(=\?.*?\?.\?.*?\?=)|$/m) do
before = $1.to_s
text = $2.to_s
case
- when text =~ /=\?.+\?[Bb]\?/
+ when text =~ /=\?.+\?[Bb]\?/m
before + b_value_decode(text)
- when text =~ /=\?.+\?[Qq]\?/
+ when text =~ /=\?.+\?[Qq]\?/m
before + q_value_decode(text)
else
before + text
@@ -181,7 +181,7 @@ def Encodings.q_value_decode(str)
end
def Encodings.split_encoding_from_string( str )
- match = str.match(/\=\?(.+)?\?[QB]\?(.+)?\?\=/i)
+ match = str.match(/\=\?(.+)?\?[QB]\?(.+)?\?\=/mi)
if match
[match[1], match[2]]
else
View
4 lib/mail/version_specific/ruby_1_8.rb
@@ -45,7 +45,7 @@ def Ruby18.b_value_encode(str, encoding)
end
def Ruby18.b_value_decode(str)
- match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/)
+ match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/m)
if match
encoding = match[1]
str = Ruby18.decode_base64(match[2])
@@ -61,7 +61,7 @@ def Ruby18.q_value_encode(str, encoding)
end
def Ruby18.q_value_decode(str)
- match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/)
+ match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/m)
if match
encoding = match[1]
str = Encodings::QuotedPrintable.decode(match[2])
View
4 lib/mail/version_specific/ruby_1_9.rb
@@ -37,7 +37,7 @@ def Ruby19.b_value_encode(str, encoding = nil)
end
def Ruby19.b_value_decode(str)
- match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/)
+ match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/m)
if match
encoding = match[1]
str = Ruby19.decode_base64(match[2])
@@ -52,7 +52,7 @@ def Ruby19.q_value_encode(str, encoding = nil)
end
def Ruby19.q_value_decode(str)
- match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/)
+ match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/m)
if match
encoding = match[1]
str = Encodings::QuotedPrintable.decode(match[2])
View
10 spec/mail/encodings/encodings_spec.rb
@@ -502,6 +502,16 @@
Mail::Encodings.get_encoding(:quoted_printable).decode(encoded).should == expected
end
+ it "should handle a new line in the text" do
+ if RUBY_VERSION >= '1.9'
+ expected = "\nRe: ol\341".force_encoding('ISO-8859-1')
+ else
+ expected = "\nRe: ol\341"
+ end
+ encoded = "=?ISO-8859-1?Q?\nRe=3A_ol=E1?="
+ Mail::Encodings.value_decode(encoded).should == expected
+ end
+
end
end

0 comments on commit 4b6335e

Please sign in to comment.