How would I only pull links from the email's body and not the full
email.
require 'net/pop'
require 'rubygems'
require 'tmail'
username = ' '
pass = ' '
Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE)
Net::POP3.start('pop.gmail.com', 995, username, pass) do |pop|
if pop.mails.empty?
puts "No mail"
else
pop.each_mail do |mail|
email = TMail::Mail.parse(mail.pop)
p email.body
end
end
end
Thanks
···
--
Posted via http://www.ruby-forum.com/.
Robert Johns wrote in post #998352:
How would I only pull links from the email's body
"Links" to me implies that this is an HTML email. In that case, just
parse the body with an HTML parser (e.g. nokogiri). It can easily pull
out all the A (anchor) tags with their href attributes.
If it's plain text, but contains URLs like http://..., then you can
match the body against a regexp. e.g.
p body.scan(%r{\bhttps?://\S+})
···
--
Posted via http://www.ruby-forum.com/\.
That worked out well thank you very much.
···
--
Posted via http://www.ruby-forum.com/.
BTW... we're discussing stabbing you in the 'indenting "end"' thread. 
···
On May 12, 2011, at 13:28 , Robert Johns wrote:
Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE)
Net::POP3.start('pop.gmail.com', 995, username, pass) do |pop|
if pop.mails.empty?
puts "No mail"
else
pop.each_mail do |mail|
email = TMail::Mail.parse(mail.pop)
p email.body
end
end
end
I, for one, would really rather not be stabbed in the indenting end.
···
On Fri, May 13, 2011 at 08:57:27AM +0900, Ryan Davis wrote:
BTW... we're discussing stabbing you in the 'indenting "end"' thread.
--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]