diff --git a/lib/uri/mailto.rb b/lib/uri/mailto.rb index cb8024f..83de2f7 100644 --- a/lib/uri/mailto.rb +++ b/lib/uri/mailto.rb @@ -266,18 +266,18 @@ def to_s # # => "To: ruby-list@ruby-lang.org\nSubject: subscribe\nCc: myaddr\n\n\n" # def to_mailtext - to = URI.decode_www_form_component(@to) + to = URI.decode_uri_component(@to) head = '' body = '' @headers.each do |x| case x[0] when 'body' - body = URI.decode_www_form_component(x[1]) + body = URI.decode_uri_component(x[1]) when 'to' - to << ', ' + URI.decode_www_form_component(x[1]) + to << ', ' + URI.decode_uri_component(x[1]) else - head << URI.decode_www_form_component(x[0]).capitalize + ': ' + - URI.decode_www_form_component(x[1]) + "\n" + head << URI.decode_uri_component(x[0]).capitalize + ': ' + + URI.decode_uri_component(x[1]) + "\n" end end diff --git a/test/uri/test_mailto.rb b/test/uri/test_mailto.rb index 6cd3352..007f227 100644 --- a/test/uri/test_mailto.rb +++ b/test/uri/test_mailto.rb @@ -14,6 +14,14 @@ def uri_to_ary(uri) uri.class.component.collect {|c| uri.send(c)} end + + def test_to_mailtext_preserves_literal_plus + uri = URI.parse("mailto:a+b@example.test?subject=a+b&body=x+y") + + assert_equal("To: a+b@example.test\nSubject: a+b\n\nx+y\n", uri.to_mailtext) + assert_equal(uri.to_mailtext, uri.to_rfc822text) + end + def test_build ok = [] bad = []