rubygems-update 3.5.5 → 3.5.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +107 -0
  3. data/Manifest.txt +84 -64
  4. data/POLICIES.md +75 -6
  5. data/bundler/CHANGELOG.md +75 -0
  6. data/bundler/lib/bundler/build_metadata.rb +2 -2
  7. data/bundler/lib/bundler/cli/binstubs.rb +1 -1
  8. data/bundler/lib/bundler/cli/gem.rb +1 -1
  9. data/bundler/lib/bundler/cli/lock.rb +5 -4
  10. data/bundler/lib/bundler/cli/plugin.rb +3 -2
  11. data/bundler/lib/bundler/cli.rb +7 -24
  12. data/bundler/lib/bundler/definition.rb +111 -56
  13. data/bundler/lib/bundler/dependency.rb +2 -1
  14. data/bundler/lib/bundler/dsl.rb +16 -1
  15. data/bundler/lib/bundler/environment_preserver.rb +5 -23
  16. data/bundler/lib/bundler/fetcher/downloader.rb +1 -1
  17. data/bundler/lib/bundler/fetcher.rb +2 -2
  18. data/bundler/lib/bundler/gem_version_promoter.rb +42 -38
  19. data/bundler/lib/bundler/injector.rb +3 -2
  20. data/bundler/lib/bundler/installer.rb +2 -2
  21. data/bundler/lib/bundler/man/bundle-add.1 +1 -1
  22. data/bundler/lib/bundler/man/bundle-binstubs.1 +1 -1
  23. data/bundler/lib/bundler/man/bundle-cache.1 +1 -1
  24. data/bundler/lib/bundler/man/bundle-check.1 +3 -1
  25. data/bundler/lib/bundler/man/bundle-check.1.ronn +3 -0
  26. data/bundler/lib/bundler/man/bundle-clean.1 +1 -1
  27. data/bundler/lib/bundler/man/bundle-config.1 +1 -3
  28. data/bundler/lib/bundler/man/bundle-config.1.ronn +0 -3
  29. data/bundler/lib/bundler/man/bundle-console.1 +1 -1
  30. data/bundler/lib/bundler/man/bundle-doctor.1 +1 -1
  31. data/bundler/lib/bundler/man/bundle-exec.1 +1 -1
  32. data/bundler/lib/bundler/man/bundle-gem.1 +1 -1
  33. data/bundler/lib/bundler/man/bundle-help.1 +1 -1
  34. data/bundler/lib/bundler/man/bundle-info.1 +1 -1
  35. data/bundler/lib/bundler/man/bundle-init.1 +1 -1
  36. data/bundler/lib/bundler/man/bundle-inject.1 +1 -1
  37. data/bundler/lib/bundler/man/bundle-install.1 +3 -3
  38. data/bundler/lib/bundler/man/bundle-install.1.ronn +2 -2
  39. data/bundler/lib/bundler/man/bundle-list.1 +1 -1
  40. data/bundler/lib/bundler/man/bundle-lock.1 +1 -1
  41. data/bundler/lib/bundler/man/bundle-open.1 +1 -1
  42. data/bundler/lib/bundler/man/bundle-outdated.1 +1 -1
  43. data/bundler/lib/bundler/man/bundle-platform.1 +1 -1
  44. data/bundler/lib/bundler/man/bundle-plugin.1 +7 -4
  45. data/bundler/lib/bundler/man/bundle-plugin.1.ronn +7 -3
  46. data/bundler/lib/bundler/man/bundle-pristine.1 +1 -1
  47. data/bundler/lib/bundler/man/bundle-remove.1 +1 -1
  48. data/bundler/lib/bundler/man/bundle-show.1 +1 -1
  49. data/bundler/lib/bundler/man/bundle-update.1 +1 -1
  50. data/bundler/lib/bundler/man/bundle-version.1 +1 -1
  51. data/bundler/lib/bundler/man/bundle-viz.1 +1 -1
  52. data/bundler/lib/bundler/man/bundle.1 +1 -1
  53. data/bundler/lib/bundler/man/gemfile.5 +3 -3
  54. data/bundler/lib/bundler/man/gemfile.5.ronn +2 -2
  55. data/bundler/lib/bundler/mirror.rb +3 -3
  56. data/bundler/lib/bundler/plugin/api/source.rb +2 -2
  57. data/bundler/lib/bundler/plugin/installer/path.rb +18 -0
  58. data/bundler/lib/bundler/plugin/installer.rb +36 -16
  59. data/bundler/lib/bundler/plugin/source_list.rb +4 -4
  60. data/bundler/lib/bundler/resolver/candidate.rb +1 -1
  61. data/bundler/lib/bundler/resolver.rb +54 -24
  62. data/bundler/lib/bundler/rubygems_ext.rb +12 -0
  63. data/bundler/lib/bundler/runtime.rb +1 -1
  64. data/bundler/lib/bundler/self_manager.rb +1 -1
  65. data/bundler/lib/bundler/settings.rb +14 -12
  66. data/bundler/lib/bundler/setup.rb +3 -0
  67. data/bundler/lib/bundler/source/git/git_proxy.rb +1 -1
  68. data/bundler/lib/bundler/source/git.rb +1 -1
  69. data/bundler/lib/bundler/source/rubygems/remote.rb +1 -1
  70. data/bundler/lib/bundler/source/rubygems.rb +7 -20
  71. data/bundler/lib/bundler/source_list.rb +17 -4
  72. data/bundler/lib/bundler/spec_set.rb +1 -1
  73. data/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt +4 -3
  74. data/bundler/lib/bundler/templates/newgem/rubocop.yml.tt +0 -5
  75. data/bundler/lib/bundler/uri_credentials_filter.rb +2 -2
  76. data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +22 -22
  77. data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb +1 -0
  78. data/bundler/lib/bundler/vendored_net_http.rb +7 -3
  79. data/bundler/lib/bundler/vendored_timeout.rb +7 -3
  80. data/bundler/lib/bundler/vendored_uri.rb +18 -1
  81. data/bundler/lib/bundler/version.rb +1 -1
  82. data/bundler/lib/bundler/yaml_serializer.rb +12 -0
  83. data/bundler/lib/bundler.rb +23 -2
  84. data/lib/rubygems/command.rb +1 -1
  85. data/lib/rubygems/command_manager.rb +2 -1
  86. data/lib/rubygems/commands/build_command.rb +2 -11
  87. data/lib/rubygems/commands/help_command.rb +2 -2
  88. data/lib/rubygems/commands/rdoc_command.rb +1 -8
  89. data/lib/rubygems/commands/rebuild_command.rb +264 -0
  90. data/lib/rubygems/commands/sources_command.rb +2 -2
  91. data/lib/rubygems/commands/update_command.rb +8 -9
  92. data/lib/rubygems/config_file.rb +20 -8
  93. data/lib/rubygems/defaults.rb +4 -4
  94. data/lib/rubygems/dependency.rb +2 -2
  95. data/lib/rubygems/dependency_list.rb +1 -1
  96. data/lib/rubygems/deprecate.rb +79 -77
  97. data/lib/rubygems/ext/cargo_builder.rb +1 -1
  98. data/lib/rubygems/gemcutter_utilities/webauthn_listener.rb +1 -1
  99. data/lib/rubygems/gemcutter_utilities/webauthn_poller.rb +3 -1
  100. data/lib/rubygems/gemcutter_utilities.rb +40 -23
  101. data/lib/rubygems/gemspec_helpers.rb +19 -0
  102. data/lib/rubygems/local_remote_options.rb +6 -6
  103. data/lib/rubygems/package.rb +13 -7
  104. data/lib/rubygems/remote_fetcher.rb +3 -3
  105. data/lib/rubygems/request.rb +5 -5
  106. data/lib/rubygems/request_set.rb +1 -1
  107. data/lib/rubygems/requirement.rb +5 -0
  108. data/lib/rubygems/resolver/api_set.rb +1 -1
  109. data/lib/rubygems/resolver/best_set.rb +1 -1
  110. data/lib/rubygems/resolver/spec_specification.rb +7 -0
  111. data/lib/rubygems/resolver.rb +5 -5
  112. data/lib/rubygems/s3_uri_signer.rb +3 -3
  113. data/lib/rubygems/safe_yaml.rb +10 -1
  114. data/lib/rubygems/security.rb +1 -1
  115. data/lib/rubygems/source/git.rb +2 -2
  116. data/lib/rubygems/source_list.rb +1 -1
  117. data/lib/rubygems/specification.rb +6 -6
  118. data/lib/rubygems/specification_policy.rb +15 -7
  119. data/lib/rubygems/uri.rb +6 -6
  120. data/lib/rubygems/util/licenses.rb +43 -0
  121. data/lib/rubygems/util.rb +1 -1
  122. data/lib/rubygems/vendor/molinillo/lib/molinillo/delegates/resolution_state.rb +57 -0
  123. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/delegates/specification_provider.rb +11 -11
  124. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/action.rb +1 -1
  125. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb +1 -1
  126. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/add_vertex.rb +1 -1
  127. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/delete_edge.rb +1 -1
  128. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb +1 -1
  129. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/log.rb +1 -1
  130. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/set_payload.rb +1 -1
  131. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/tag.rb +1 -1
  132. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph/vertex.rb +1 -1
  133. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/dependency_graph.rb +2 -2
  134. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/errors.rb +1 -1
  135. data/lib/rubygems/vendor/molinillo/lib/molinillo/gem_metadata.rb +6 -0
  136. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/modules/specification_provider.rb +2 -2
  137. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/modules/ui.rb +1 -1
  138. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/resolution.rb +3 -3
  139. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/resolver.rb +1 -1
  140. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo/state.rb +1 -1
  141. data/lib/rubygems/{resolver → vendor}/molinillo/lib/molinillo.rb +2 -2
  142. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/generic_request.rb +9 -9
  143. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/header.rb +2 -2
  144. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/request.rb +3 -3
  145. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/requests.rb +30 -30
  146. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/response.rb +2 -2
  147. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/responses.rb +6 -6
  148. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/status.rb +1 -1
  149. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http.rb +15 -15
  150. data/lib/rubygems/{net-http → vendor/net-http}/lib/net/https.rb +1 -1
  151. data/lib/rubygems/vendor/optparse/lib/optparse/uri.rb +7 -0
  152. data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse.rb +11 -11
  153. data/lib/rubygems/{timeout → vendor/timeout}/lib/timeout.rb +1 -1
  154. data/lib/rubygems/{tsort → vendor/tsort}/lib/tsort.rb +2 -2
  155. data/lib/rubygems/vendor/uri/.document +1 -0
  156. data/lib/rubygems/vendor/uri/LICENSE.txt +22 -0
  157. data/lib/rubygems/vendor/uri/lib/uri/common.rb +853 -0
  158. data/lib/rubygems/vendor/uri/lib/uri/file.rb +100 -0
  159. data/lib/rubygems/vendor/uri/lib/uri/ftp.rb +267 -0
  160. data/lib/rubygems/vendor/uri/lib/uri/generic.rb +1588 -0
  161. data/lib/rubygems/vendor/uri/lib/uri/http.rb +125 -0
  162. data/lib/rubygems/vendor/uri/lib/uri/https.rb +23 -0
  163. data/lib/rubygems/vendor/uri/lib/uri/ldap.rb +261 -0
  164. data/lib/rubygems/vendor/uri/lib/uri/ldaps.rb +22 -0
  165. data/lib/rubygems/vendor/uri/lib/uri/mailto.rb +293 -0
  166. data/lib/rubygems/vendor/uri/lib/uri/rfc2396_parser.rb +539 -0
  167. data/lib/rubygems/vendor/uri/lib/uri/rfc3986_parser.rb +183 -0
  168. data/lib/rubygems/vendor/uri/lib/uri/version.rb +6 -0
  169. data/lib/rubygems/vendor/uri/lib/uri/ws.rb +83 -0
  170. data/lib/rubygems/vendor/uri/lib/uri/wss.rb +23 -0
  171. data/lib/rubygems/vendor/uri/lib/uri.rb +104 -0
  172. data/lib/rubygems/vendored_molinillo.rb +3 -0
  173. data/lib/rubygems/vendored_net_http.rb +5 -0
  174. data/lib/rubygems/vendored_optparse.rb +3 -0
  175. data/lib/rubygems/vendored_timeout.rb +5 -0
  176. data/lib/rubygems/vendored_tsort.rb +3 -0
  177. data/lib/rubygems/yaml_serializer.rb +12 -0
  178. data/lib/rubygems.rb +2 -2
  179. data/rubygems-update.gemspec +7 -2
  180. metadata +90 -67
  181. data/lib/rubygems/net/http.rb +0 -3
  182. data/lib/rubygems/optparse/lib/optparse/uri.rb +0 -7
  183. data/lib/rubygems/optparse.rb +0 -3
  184. data/lib/rubygems/resolver/molinillo/lib/molinillo/delegates/resolution_state.rb +0 -57
  185. data/lib/rubygems/resolver/molinillo/lib/molinillo/gem_metadata.rb +0 -6
  186. data/lib/rubygems/resolver/molinillo.rb +0 -3
  187. data/lib/rubygems/timeout.rb +0 -3
  188. data/lib/rubygems/tsort.rb +0 -3
  189. /data/lib/rubygems/{net-http → vendor/molinillo}/.document +0 -0
  190. /data/lib/rubygems/{resolver → vendor}/molinillo/LICENSE +0 -0
  191. /data/lib/rubygems/{net-protocol → vendor/net-http}/.document +0 -0
  192. /data/lib/rubygems/{net-http → vendor/net-http}/LICENSE.txt +0 -0
  193. /data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/backward.rb +0 -0
  194. /data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/exceptions.rb +0 -0
  195. /data/lib/rubygems/{net-http → vendor/net-http}/lib/net/http/proxy_delta.rb +0 -0
  196. /data/lib/rubygems/{optparse → vendor/net-protocol}/.document +0 -0
  197. /data/lib/rubygems/{net-protocol → vendor/net-protocol}/LICENSE.txt +0 -0
  198. /data/lib/rubygems/{net-protocol → vendor/net-protocol}/lib/net/protocol.rb +0 -0
  199. /data/lib/rubygems/{resolv → vendor/optparse}/.document +0 -0
  200. /data/lib/rubygems/{optparse → vendor/optparse}/COPYING +0 -0
  201. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optionparser.rb +0 -0
  202. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/ac.rb +0 -0
  203. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/date.rb +0 -0
  204. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/kwargs.rb +0 -0
  205. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/shellwords.rb +0 -0
  206. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/time.rb +0 -0
  207. /data/lib/rubygems/{optparse → vendor/optparse}/lib/optparse/version.rb +0 -0
  208. /data/lib/rubygems/{resolver/molinillo → vendor/resolv}/.document +0 -0
  209. /data/lib/rubygems/{resolv → vendor/resolv}/LICENSE.txt +0 -0
  210. /data/lib/rubygems/{resolv → vendor/resolv}/lib/resolv.rb +0 -0
  211. /data/lib/rubygems/{timeout → vendor/timeout}/.document +0 -0
  212. /data/lib/rubygems/{timeout → vendor/timeout}/LICENSE.txt +0 -0
  213. /data/lib/rubygems/{tsort → vendor/tsort}/.document +0 -0
  214. /data/lib/rubygems/{tsort → vendor/tsort}/LICENSE.txt +0 -0
@@ -0,0 +1,293 @@
1
+ # frozen_string_literal: false
2
+ # = uri/mailto.rb
3
+ #
4
+ # Author:: Akira Yamada <akira@ruby-lang.org>
5
+ # License:: You can redistribute it and/or modify it under the same term as Ruby.
6
+ #
7
+ # See Gem::URI for general documentation
8
+ #
9
+
10
+ require_relative 'generic'
11
+
12
+ module Gem::URI
13
+
14
+ #
15
+ # RFC6068, the mailto URL scheme.
16
+ #
17
+ class MailTo < Generic
18
+ include RFC2396_REGEXP
19
+
20
+ # A Default port of nil for Gem::URI::MailTo.
21
+ DEFAULT_PORT = nil
22
+
23
+ # An Array of the available components for Gem::URI::MailTo.
24
+ COMPONENT = [ :scheme, :to, :headers ].freeze
25
+
26
+ # :stopdoc:
27
+ # "hname" and "hvalue" are encodings of an RFC 822 header name and
28
+ # value, respectively. As with "to", all URL reserved characters must
29
+ # be encoded.
30
+ #
31
+ # "#mailbox" is as specified in RFC 822 [RFC822]. This means that it
32
+ # consists of zero or more comma-separated mail addresses, possibly
33
+ # including "phrase" and "comment" components. Note that all URL
34
+ # reserved characters in "to" must be encoded: in particular,
35
+ # parentheses, commas, and the percent sign ("%"), which commonly occur
36
+ # in the "mailbox" syntax.
37
+ #
38
+ # Within mailto URLs, the characters "?", "=", "&" are reserved.
39
+
40
+ # ; RFC 6068
41
+ # hfields = "?" hfield *( "&" hfield )
42
+ # hfield = hfname "=" hfvalue
43
+ # hfname = *qchar
44
+ # hfvalue = *qchar
45
+ # qchar = unreserved / pct-encoded / some-delims
46
+ # some-delims = "!" / "$" / "'" / "(" / ")" / "*"
47
+ # / "+" / "," / ";" / ":" / "@"
48
+ #
49
+ # ; RFC3986
50
+ # unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
51
+ # pct-encoded = "%" HEXDIG HEXDIG
52
+ HEADER_REGEXP = /\A(?<hfield>(?:%\h\h|[!$'-.0-;@-Z_a-z~])*=(?:%\h\h|[!$'-.0-;@-Z_a-z~])*)(?:&\g<hfield>)*\z/
53
+ # practical regexp for email address
54
+ # https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
55
+ EMAIL_REGEXP = /\A[a-zA-Z0-9.!\#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\z/
56
+ # :startdoc:
57
+
58
+ #
59
+ # == Description
60
+ #
61
+ # Creates a new Gem::URI::MailTo object from components, with syntax checking.
62
+ #
63
+ # Components can be provided as an Array or Hash. If an Array is used,
64
+ # the components must be supplied as <code>[to, headers]</code>.
65
+ #
66
+ # If a Hash is used, the keys are the component names preceded by colons.
67
+ #
68
+ # The headers can be supplied as a pre-encoded string, such as
69
+ # <code>"subject=subscribe&cc=address"</code>, or as an Array of Arrays
70
+ # like <code>[['subject', 'subscribe'], ['cc', 'address']]</code>.
71
+ #
72
+ # Examples:
73
+ #
74
+ # require 'rubygems/vendor/uri/lib/uri'
75
+ #
76
+ # m1 = Gem::URI::MailTo.build(['joe@example.com', 'subject=Ruby'])
77
+ # m1.to_s # => "mailto:joe@example.com?subject=Ruby"
78
+ #
79
+ # m2 = Gem::URI::MailTo.build(['john@example.com', [['Subject', 'Ruby'], ['Cc', 'jack@example.com']]])
80
+ # m2.to_s # => "mailto:john@example.com?Subject=Ruby&Cc=jack@example.com"
81
+ #
82
+ # m3 = Gem::URI::MailTo.build({:to => 'listman@example.com', :headers => [['subject', 'subscribe']]})
83
+ # m3.to_s # => "mailto:listman@example.com?subject=subscribe"
84
+ #
85
+ def self.build(args)
86
+ tmp = Util.make_components_hash(self, args)
87
+
88
+ case tmp[:to]
89
+ when Array
90
+ tmp[:opaque] = tmp[:to].join(',')
91
+ when String
92
+ tmp[:opaque] = tmp[:to].dup
93
+ else
94
+ tmp[:opaque] = ''
95
+ end
96
+
97
+ if tmp[:headers]
98
+ query =
99
+ case tmp[:headers]
100
+ when Array
101
+ tmp[:headers].collect { |x|
102
+ if x.kind_of?(Array)
103
+ x[0] + '=' + x[1..-1].join
104
+ else
105
+ x.to_s
106
+ end
107
+ }.join('&')
108
+ when Hash
109
+ tmp[:headers].collect { |h,v|
110
+ h + '=' + v
111
+ }.join('&')
112
+ else
113
+ tmp[:headers].to_s
114
+ end
115
+ unless query.empty?
116
+ tmp[:opaque] << '?' << query
117
+ end
118
+ end
119
+
120
+ super(tmp)
121
+ end
122
+
123
+ #
124
+ # == Description
125
+ #
126
+ # Creates a new Gem::URI::MailTo object from generic URL components with
127
+ # no syntax checking.
128
+ #
129
+ # This method is usually called from Gem::URI::parse, which checks
130
+ # the validity of each component.
131
+ #
132
+ def initialize(*arg)
133
+ super(*arg)
134
+
135
+ @to = nil
136
+ @headers = []
137
+
138
+ # The RFC3986 parser does not normally populate opaque
139
+ @opaque = "?#{@query}" if @query && !@opaque
140
+
141
+ unless @opaque
142
+ raise InvalidComponentError,
143
+ "missing opaque part for mailto URL"
144
+ end
145
+ to, header = @opaque.split('?', 2)
146
+ # allow semicolon as a addr-spec separator
147
+ # http://support.microsoft.com/kb/820868
148
+ unless /\A(?:[^@,;]+@[^@,;]+(?:\z|[,;]))*\z/ =~ to
149
+ raise InvalidComponentError,
150
+ "unrecognised opaque part for mailtoURL: #{@opaque}"
151
+ end
152
+
153
+ if arg[10] # arg_check
154
+ self.to = to
155
+ self.headers = header
156
+ else
157
+ set_to(to)
158
+ set_headers(header)
159
+ end
160
+ end
161
+
162
+ # The primary e-mail address of the URL, as a String.
163
+ attr_reader :to
164
+
165
+ # E-mail headers set by the URL, as an Array of Arrays.
166
+ attr_reader :headers
167
+
168
+ # Checks the to +v+ component.
169
+ def check_to(v)
170
+ return true unless v
171
+ return true if v.size == 0
172
+
173
+ v.split(/[,;]/).each do |addr|
174
+ # check url safety as path-rootless
175
+ if /\A(?:%\h\h|[!$&-.0-;=@-Z_a-z~])*\z/ !~ addr
176
+ raise InvalidComponentError,
177
+ "an address in 'to' is invalid as Gem::URI #{addr.dump}"
178
+ end
179
+
180
+ # check addr-spec
181
+ # don't s/\+/ /g
182
+ addr.gsub!(/%\h\h/, Gem::URI::TBLDECWWWCOMP_)
183
+ if EMAIL_REGEXP !~ addr
184
+ raise InvalidComponentError,
185
+ "an address in 'to' is invalid as uri-escaped addr-spec #{addr.dump}"
186
+ end
187
+ end
188
+
189
+ true
190
+ end
191
+ private :check_to
192
+
193
+ # Private setter for to +v+.
194
+ def set_to(v)
195
+ @to = v
196
+ end
197
+ protected :set_to
198
+
199
+ # Setter for to +v+.
200
+ def to=(v)
201
+ check_to(v)
202
+ set_to(v)
203
+ v
204
+ end
205
+
206
+ # Checks the headers +v+ component against either
207
+ # * HEADER_REGEXP
208
+ def check_headers(v)
209
+ return true unless v
210
+ return true if v.size == 0
211
+ if HEADER_REGEXP !~ v
212
+ raise InvalidComponentError,
213
+ "bad component(expected opaque component): #{v}"
214
+ end
215
+
216
+ true
217
+ end
218
+ private :check_headers
219
+
220
+ # Private setter for headers +v+.
221
+ def set_headers(v)
222
+ @headers = []
223
+ if v
224
+ v.split('&').each do |x|
225
+ @headers << x.split(/=/, 2)
226
+ end
227
+ end
228
+ end
229
+ protected :set_headers
230
+
231
+ # Setter for headers +v+.
232
+ def headers=(v)
233
+ check_headers(v)
234
+ set_headers(v)
235
+ v
236
+ end
237
+
238
+ # Constructs String from Gem::URI.
239
+ def to_s
240
+ @scheme + ':' +
241
+ if @to
242
+ @to
243
+ else
244
+ ''
245
+ end +
246
+ if @headers.size > 0
247
+ '?' + @headers.collect{|x| x.join('=')}.join('&')
248
+ else
249
+ ''
250
+ end +
251
+ if @fragment
252
+ '#' + @fragment
253
+ else
254
+ ''
255
+ end
256
+ end
257
+
258
+ # Returns the RFC822 e-mail text equivalent of the URL, as a String.
259
+ #
260
+ # Example:
261
+ #
262
+ # require 'rubygems/vendor/uri/lib/uri'
263
+ #
264
+ # uri = Gem::URI.parse("mailto:ruby-list@ruby-lang.org?Subject=subscribe&cc=myaddr")
265
+ # uri.to_mailtext
266
+ # # => "To: ruby-list@ruby-lang.org\nSubject: subscribe\nCc: myaddr\n\n\n"
267
+ #
268
+ def to_mailtext
269
+ to = Gem::URI.decode_www_form_component(@to)
270
+ head = ''
271
+ body = ''
272
+ @headers.each do |x|
273
+ case x[0]
274
+ when 'body'
275
+ body = Gem::URI.decode_www_form_component(x[1])
276
+ when 'to'
277
+ to << ', ' + Gem::URI.decode_www_form_component(x[1])
278
+ else
279
+ head << Gem::URI.decode_www_form_component(x[0]).capitalize + ': ' +
280
+ Gem::URI.decode_www_form_component(x[1]) + "\n"
281
+ end
282
+ end
283
+
284
+ "To: #{to}
285
+ #{head}
286
+ #{body}
287
+ "
288
+ end
289
+ alias to_rfc822text to_mailtext
290
+ end
291
+
292
+ register_scheme 'MAILTO', MailTo
293
+ end