如何在mailto链接中找到正文和主题?

时间:2017-11-08 15:15:06

标签: ruby uri mailto

我有这个mailto链接:

mailto:email@address.com?&subject=test&body=type%20your&body=message%20here

我想找tosubjectbody

其实我用的是:

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>

我有:对此: uri.to

但我无法提取subjectbody

你知道怎么做吗?

1 个答案:

答案 0 :(得分:3)

您可以使用返回数组数组的URI::MailTo#headers

uri = URI('mailto:email@address.com?subject=test&body=type%20your%0D%0Amessage%20here')
#                                   ^                            ^
#                               no '&' here                newline as %0D%0A

但是,您的mailto链接稍有破坏。它应该是这样的:

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"

获取解码值:

SELECT cl.cl_id, cl.name, COUNT(*) 
FROM cl, st 
WHERE st.cl_id = cl.cl_id 
GROUP BY cl.cl_id 
ORDER BY cl.cl_id;