如何在 mailto link 中找到正文和主题?
How to find the body and the subject in a mailto link?
我有这个邮箱 link :
mailto:email@address.com?&subject=test&body=type%20your&body=message%20here
我想找 to
, subject
, body
.
其实我用的是:
uri = URI('mailto:email@address.com?&subject=test&body=type%20your&body=message%20here')
<URI::MailTo mailto:email@address.com?&subject=test&body=type%20your&body=message%20here>
我有 :to with that :
uri.to
但我无法提取 subject
和 body
。
你知道怎么做吗?
您可以使用 URI::MailTo#headers
其中 returns 数组的数组:
uri.headers
#=> [[], ["subject", "test"], ["body", "type%20your"], ["body", "message%20here"]]
但是,您的 mailto link 有点损坏。它应该是这样的:
uri = URI('mailto:email@address.com?subject=test&body=type%20your%0D%0Amessage%20here')
# ^ ^
# no '&' here newline as %0D%0A
这给出:
uri.headers
#=> [["subject", "test"], ["body", "type%20your%0D%0Amessage%20here"]]
可以通过 assoc
:
访问
uri.headers.assoc('subject').last
#=> "test"
或转换为散列:
headers = uri.headers.to_h
#=> {"subject"=>"test", "body"=>"type%20your%0D%0Amessage%20here"}
获取解码值:
URI.decode_www_form_component(headers['body'])
#=> "type your\r\nmessage here"
我有这个邮箱 link :
mailto:email@address.com?&subject=test&body=type%20your&body=message%20here
我想找 to
, subject
, body
.
其实我用的是:
uri = URI('mailto:email@address.com?&subject=test&body=type%20your&body=message%20here')
<URI::MailTo mailto:email@address.com?&subject=test&body=type%20your&body=message%20here>
我有 :to with that :
uri.to
但我无法提取 subject
和 body
。
你知道怎么做吗?
您可以使用 URI::MailTo#headers
其中 returns 数组的数组:
uri.headers
#=> [[], ["subject", "test"], ["body", "type%20your"], ["body", "message%20here"]]
但是,您的 mailto link 有点损坏。它应该是这样的:
uri = URI('mailto:email@address.com?subject=test&body=type%20your%0D%0Amessage%20here')
# ^ ^
# no '&' here newline as %0D%0A
这给出:
uri.headers
#=> [["subject", "test"], ["body", "type%20your%0D%0Amessage%20here"]]
可以通过 assoc
:
uri.headers.assoc('subject').last
#=> "test"
或转换为散列:
headers = uri.headers.to_h
#=> {"subject"=>"test", "body"=>"type%20your%0D%0Amessage%20here"}
获取解码值:
URI.decode_www_form_component(headers['body'])
#=> "type your\r\nmessage here"