7 class TestMailTo < Test::Unit::TestCase
16 uri.class.component.collect {|c| uri.send(c)}
23 # RFC2368, 6. Examples
24 # mailto:chris@example.com
25 ok << ["mailto:chris@example.com"]
26 ok[-1] << ["chris@example.com", nil]
27 ok[-1] << {:to => "chris@example.com"}
29 # mailto:infobot@example.com?subject=current-issue
30 ok << ["mailto:infobot@example.com?subject=current-issue"]
31 ok[-1] << ["infobot@example.com", ["subject=current-issue"]]
32 ok[-1] << {:to => "infobot@example.com",
33 :headers => ["subject=current-issue"]}
35 # mailto:infobot@example.com?body=send%20current-issue
36 ok << ["mailto:infobot@example.com?body=send%20current-issue"]
37 ok[-1] << ["infobot@example.com", ["body=send%20current-issue"]]
38 ok[-1] << {:to => "infobot@example.com",
39 :headers => ["body=send%20current-issue"]}
41 # mailto:infobot@example.com?body=send%20current-issue%0D%0Asend%20index
42 ok << ["mailto:infobot@example.com?body=send%20current-issue%0D%0Asend%20index"]
43 ok[-1] << ["infobot@example.com",
44 ["body=send%20current-issue%0D%0Asend%20index"]]
45 ok[-1] << {:to => "infobot@example.com",
46 :headers => ["body=send%20current-issue%0D%0Asend%20index"]}
48 # mailto:foobar@example.com?In-Reply-To=%3c3469A91.D10AF4C@example.com
49 ok << ["mailto:foobar@example.com?In-Reply-To=%3c3469A91.D10AF4C@example.com"]
50 ok[-1] << ["foobar@example.com",
51 ["In-Reply-To=%3c3469A91.D10AF4C@example.com"]]
52 ok[-1] << {:to => "foobar@example.com",
53 :headers => ["In-Reply-To=%3c3469A91.D10AF4C@example.com"]}
55 # mailto:majordomo@example.com?body=subscribe%20bamboo-l
56 ok << ["mailto:majordomo@example.com?body=subscribe%20bamboo-l"]
57 ok[-1] << ["majordomo@example.com", ["body=subscribe%20bamboo-l"]]
58 ok[-1] << {:to => "majordomo@example.com",
59 :headers => ["body=subscribe%20bamboo-l"]}
61 # mailto:joe@example.com?cc=bob@example.com&body=hello
62 ok << ["mailto:joe@example.com?cc=bob@example.com&body=hello"]
63 ok[-1] << ["joe@example.com", ["cc=bob@example.com", "body=hello"]]
64 ok[-1] << {:to => "joe@example.com",
65 :headers => ["cc=bob@example.com", "body=hello"]}
67 # mailto:?to=joe@example.com&cc=bob@example.com&body=hello
68 ok << ["mailto:?to=joe@example.com&cc=bob@example.com&body=hello"]
70 ["to=joe@example.com", "cc=bob@example.com", "body=hello"]]
71 ok[-1] << {:headers => ["to=joe@example.com",
72 "cc=bob@example.com", "body=hello"]}
74 # mailto:gorby%25kremvax@example.com
75 ok << ["mailto:gorby%25kremvax@example.com"]
76 ok[-1] << ["gorby%25kremvax@example.com", nil]
77 ok[-1] << {:to => "gorby%25kremvax@example.com"}
79 # mailto:unlikely%3Faddress@example.com?blat=foop
80 ok << ["mailto:unlikely%3Faddress@example.com?blat=foop"]
81 ok[-1] << ["unlikely%3Faddress@example.com", ["blat=foop"]]
82 ok[-1] << {:to => "unlikely%3Faddress@example.com",
83 :headers => ["blat=foop"]}
85 ok_all = ok.flatten.join("\0")
87 # mailto:joe@example.com?cc=bob@example.com?body=hello ; WRONG!
88 bad << ["joe@example.com", ["cc=bob@example.com?body=hello"]]
90 # mailto:javascript:alert()
91 bad << ["javascript:alert()", []]
93 # '=' which is in hname or hvalue is wrong.
94 bad << ["foo@example.jp?subject=1+1=2", []]
104 assert_raise(URI::InvalidComponentError) {
109 assert_equal(ok_all, ok.flatten.join("\0"))
113 u = URI.parse('mailto:joe@example.com?cc=bob@example.com&body=hello')
114 assert_equal(uri_to_ary(u), u.select(*u.component))
115 assert_raise(ArgumentError) do
116 u.select(:scheme, :host, :not_exist, :port)