Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
URI::MailTo#to_mailtext
() -> ::String
to_mailtext
lib/uri/mailto.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/uri/mailto.rb, line 268
def to_mailtext
to = URI.decode_www_form_component(@to)
head = ''
body = ''
@headers.each do |x|
case x[0]
when 'body'
body = URI.decode_www_form_component(x[1])
when 'to'
to << ', ' + URI.decode_www_form_component(x[1])
else
head << URI.decode_www_form_component(x[0]).capitalize + ': ' +
URI.decode_www_form_component(x[1]) + "\n"
end
end
"To: #{to}
#{head}
#{body}
"
end
Returns the RFC822 e-mail text equivalent of the URL, as a String.
Example:
Example
require 'uri' uri = URI.parse("mailto:[email protected]?Subject=subscribe&cc=myaddr") uri.to_mailtext # => "To: [email protected]\nSubject: subscribe\nCc: myaddr\n\n\n"