Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions lib/uri/mailto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ def set_headers(v)
@headers = []
if v
v.split('&').each do |x|
@headers << x.split(/=/, 2)
name, value = x.split(/=/, 2)
@headers << [name, value || '']
end
end
end
Expand Down Expand Up @@ -266,18 +267,20 @@ 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_www_form_component(@to.to_s)
head = ''
body = ''
@headers.each do |x|
case x[0]
name = x[0].to_s
value = x[1].to_s
case name
when 'body'
body = URI.decode_www_form_component(x[1])
body = URI.decode_www_form_component(value)
when 'to'
to << ', ' + URI.decode_www_form_component(x[1])
to << ', ' + URI.decode_www_form_component(value)
else
head << URI.decode_www_form_component(x[0]).capitalize + ': ' +
URI.decode_www_form_component(x[1]) + "\n"
head << URI.decode_www_form_component(name).capitalize + ': ' +
URI.decode_www_form_component(value) + "\n"
end
end

Expand Down
10 changes: 10 additions & 0 deletions test/uri/test_mailto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,16 @@ def test_to_mailtext
u.to_mailtext
end

def test_to_mailtext_with_header_name_only
u = URI.parse('mailto:ruby-list@ruby-lang.org?Subject')
assert_equal [['Subject', '']], u.headers
assert_equal "To: ruby-list@ruby-lang.org\nSubject: \n\n\n", u.to_mailtext

u = URI.parse('mailto:ruby-list@ruby-lang.org?body&cc=myaddr')
assert_equal [['body', ''], ['cc', 'myaddr']], u.headers
assert_equal "To: ruby-list@ruby-lang.org\nCc: myaddr\n\n\n", u.to_mailtext
end

def test_select
u = URI.parse('mailto:joe@example.com?cc=bob@example.com&body=hello')
assert_equal(uri_to_ary(u), u.select(*u.component))
Expand Down
Loading