Skip to content
Browse files

Merge branch 'master' of https://github.com/janv/mail into janv-master

  • Loading branch information...
2 parents 4705d61 + 1a6fce4 commit 4a98f9db500268062f1cb2d964fb0a3654d1c5ca @mikel committed Jan 21, 2012
Showing with 22 additions and 7 deletions.
  1. +14 −6 lib/mail/encodings.rb
  2. +8 −1 spec/mail/encodings_spec.rb
View
20 lib/mail/encodings.rb
@@ -126,13 +126,21 @@ def Encodings.value_decode(str)
# Join QP encoded-words that are adjacent to avoid decoding partial chars
text.gsub!(/\?\=\=\?.+?\?[Qq]\?/m, '') if text =~ /\?==\?/
- # Separate encoded-words with a space, so we can treat them one by one
- text.gsub!(/\?\=\=\?/, '?= =?')
- text.split(/ /).map do |word|
- word.to_str.
- gsub( /=\?.+\?[Bb]\?.+\?=/m ) { |substr| b_value_decode(substr) }.
- gsub( /=\?.+\?[Qq]\?.+\?=/m ) { |substr| q_value_decode(substr) }
+ # Search for occurences of quoted strings or plain strings
+ text.scan(/( # Group around entire regex to include it in matches
+ \=\?[^?]+\?([QB])\?[^?]+?\?\= # Quoted String with subgroup for encoding method
+ | # or
+ .+?(?=\=\?) # Plain String
+ )/xmi).map do |matches|
+ string, method = *matches
+ if method == 'b' || method == 'B'
+ b_value_decode(string)
+ elsif method == 'q' || method == 'Q'
+ q_value_decode(string)
+ else
+ string
end
+ end
end
end.join("")
end
View
9 spec/mail/encodings_spec.rb
@@ -613,7 +613,14 @@
a = "=?Shift_JIS?Q?=93=FA=96{=8C=EA=?= <a@example.com>, =?Shift_JIS?Q?=93=FA=96{=8C=EA=?= <b@example.com>"
b = Mail::Encodings.unquote_and_convert_to(a, 'utf-8')
b.should eq "日本語 <a@example.com>, 日本語 <b@example.com>"
- end
+ end
+
+ it "should handle multiline quoted headers with mixed content" do
+ a = "=?iso-2022-jp?B?GyRCP3AwQxsoQg==?=2=?iso-2022-jp?B?GyRCIiobKEI=?= =?iso-2022-jp?B?GyRCOkc2YUxnPj4kcj5+JGsySCQsJFskSCRzJEk4K0V2GyhC?= =?iso-2022-jp?B?GyRCJD8kaSRKJCQhKjxkJDckJCQzJEgkRyQ5JE0hI0Z8GyhC?= =?iso-2022-jp?B?GyRCS1wkTiQkJCQkSCQzJG0hIiRvJFMkNSRTJE5AJDMmGyhC?= =?iso-2022-jp?B?GyRCJCw8OiRvJGwkRCREJCIkazg9Ol8hIiRKJHMkSCQrGyhC?= =?iso-2022-jp?B?GyRCOGVAJCRLO0QkNSRNJFAhIkxeQk4kSiQkISokSCReGyhC?= =?iso-2022-jp?B?GyRCJF4kTztXJCYkTiRAISMbKEI=?="
+ b = Mail::Encodings.unquote_and_convert_to(a, 'utf-8')
+ b.should eq "瑞庵2→最近門松を飾る家がほとんど見当たらない!寂しいことですね。日本のいいところ、わびさびの世界が失われつつある現在、なんとか後世に残さねば、勿体ない!とままは思うのだ。"
+ end
+
end
end

0 comments on commit 4a98f9d

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