public Method

MailTo.to_mailtext

Returns the RFC822 e-mail text equivalent of the URL, as a String.

Example:

require 'uri'

uri = URI.parse("mailto:ruby-list@ruby-lang.org?Subject=subscribe&cc=myaddr")
uri.to_mailtext
# => "To: ruby-list@ruby-lang.org\nSubject: subscribe\nCc: myaddr\n\n\n"

Source Code

# File uri/mailto.rb, line 241
def to_mailtext
  to = URI::unescape(@to)
  head = ''
  body = ''
  @headers.each do |x|
    case x[0]
    when 'body'
      body = URI::unescape(x[1])
    when 'to'
      to << ', ' + URI::unescape(x[1])
    else
      head << URI::unescape(x[0]).capitalize + ': ' +
        URI::unescape(x[1])  + "\n"
    end
  end

  return "To: #{to}
#{head}
#{body}
"
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.