diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 1b54ddf39..60a34c23d 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,5 +1,7 @@ == HEAD +* Fix failing spec Issue 453 on Ruby 1.9.3 + == Version 2.4.4 - Wed Mar 14 22:44:00 +1100 2012 Mikel Lindsaar * Fix security vulnerability allowing command line exploit when using file delivery method diff --git a/Gemfile b/Gemfile index 35cfb16d1..d6c19113d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,17 +1,20 @@ source :rubygems -gem "activesupport", ">= 2.3.6" +gem 'activesupport', '>= 2.3.6' if RUBY_VERSION >= '1.9.3' +gem 'activesupport', '>= 2.3.6', '< 4.0.0' if RUBY_VERSION < '1.9.3' gem "tlsmail" if RUBY_VERSION <= '1.8.6' gem "mime-types", "~> 1.16" gem "treetop", "~> 1.4.10" -gem "i18n", ">= 0.4.0" +gem 'i18n', '>= 0.4.0' if RUBY_VERSION >= '1.9.3' +gem 'i18n', '>= 0.4.0', '< 0.7.0' if RUBY_VERSION < '1.9.3' if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' gem 'jruby-openssl' end group :test do - gem "rake", "> 0.8.7" + gem 'rake', '> 0.8.7' if RUBY_VERSION >= '1.9.3' + gem 'rake', '> 0.8.7', '< 11.0.1' if RUBY_VERSION < '1.9.3' gem "rspec", "~> 2.8.0" case when defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx' diff --git a/lib/mail/version_specific/ruby_1_8.rb b/lib/mail/version_specific/ruby_1_8.rb index 1cb73c704..48790984b 100644 --- a/lib/mail/version_specific/ruby_1_8.rb +++ b/lib/mail/version_specific/ruby_1_8.rb @@ -80,7 +80,10 @@ def Ruby18.q_value_decode(str) match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/m) if match encoding = match[1] - str = Encodings::QuotedPrintable.decode(match[2].gsub(/_/, '=20')) + string = match[2].gsub(/_/, '=20') + # Remove trailing = if it exists in a Q encoding + string = string.sub(/\=$/, '') + str = Encodings::QuotedPrintable.decode(string) end str end diff --git a/lib/mail/version_specific/ruby_1_9.rb b/lib/mail/version_specific/ruby_1_9.rb index 0eb3806bd..cb210d9d0 100644 --- a/lib/mail/version_specific/ruby_1_9.rb +++ b/lib/mail/version_specific/ruby_1_9.rb @@ -68,7 +68,10 @@ def Ruby19.q_value_decode(str) match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/m) if match encoding = match[1] - str = Encodings::QuotedPrintable.decode(match[2].gsub(/_/, '=20')) + string = match[2].gsub(/_/, '=20') + # Remove trailing = if it exists in a Q encoding + string = string.sub(/\=$/, '') + str = Encodings::QuotedPrintable.decode(string) str.force_encoding(fix_encoding(encoding)) end decoded = str.encode("utf-8", :invalid => :replace, :replace => "") diff --git a/mail.gemspec b/mail.gemspec index ffaf02534..cc5ddce91 100644 --- a/mail.gemspec +++ b/mail.gemspec @@ -17,7 +17,8 @@ Gem::Specification.new do |s| s.add_dependency('mime-types', "~> 1.16") s.add_dependency('treetop', '~> 1.4.8') - s.add_dependency('i18n', '>= 0.4.0') + s.add_dependency('i18n', '>= 0.4.0') if RUBY_VERSION >= '1.9.3' + s.add_dependency('i18n', '>= 0.4.0', '< 0.7.0') if RUBY_VERSION < '1.9.3' s.add_dependency('jruby-openssl') if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' s.add_dependency('tlsmail', '~> 0.0.1') if RUBY_VERSION == '1.8.6' diff --git a/spec/mail/encodings_spec.rb b/spec/mail/encodings_spec.rb index e33ebb414..6c4aa698f 100644 --- a/spec/mail/encodings_spec.rb +++ b/spec/mail/encodings_spec.rb @@ -609,6 +609,12 @@ b.should eq expected end + it "should unquote Shift_JIS QP with trailing =" do + a = "=?Shift_JIS?Q?=93=FA=96{=8C=EA=?=" + b = Mail::Encodings.unquote_and_convert_to(a, 'utf-8') + b.should eq "日本語" + end + it "should unquote multiple strings in the middle of the text" do a = "=?Shift_JIS?Q?=93=FA=96{=8C=EA=?= , =?Shift_JIS?Q?=93=FA=96{=8C=EA=?= " b = Mail::Encodings.unquote_and_convert_to(a, 'utf-8') diff --git a/spec/mail/message_spec.rb b/spec/mail/message_spec.rb index a19e1a40d..d9f45c5ab 100644 --- a/spec/mail/message_spec.rb +++ b/spec/mail/message_spec.rb @@ -123,6 +123,10 @@ def basic_email describe "YAML serialization" do before(:each) do + # Ensure specs don't randomly fail due to messages being generated 1 second apart + time = DateTime.now + DateTime.stub(:now).and_return(time) + @yaml_mail = Mail::Message.new(:to => 'someone@somewhere.com', :cc => 'someoneelse@somewhere.com', :bcc => 'someonesecret@somewhere.com',