Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #4428 > unrolled thread

Email Parsing

Started byRobert Johns <piratej74@live.com>
First post2011-05-12 15:28 -0500
Last post2011-05-12 19:48 -0500
Articles 5 — 4 participants

Back to article view | Back to comp.lang.ruby


Contents

  Email Parsing Robert Johns <piratej74@live.com> - 2011-05-12 15:28 -0500
    Re: Email Parsing Brian Candler <b.candler@pobox.com> - 2011-05-12 15:39 -0500
    Re: Email Parsing Robert Johns <piratej74@live.com> - 2011-05-12 16:24 -0500
    Re: Email Parsing Ryan Davis <ryand-ruby@zenspider.com> - 2011-05-12 18:57 -0500
      Re: Email Parsing Phillip Gawlowski <cmdjackryan@googlemail.com> - 2011-05-12 19:48 -0500

#4428 — Email Parsing

FromRobert Johns <piratej74@live.com>
Date2011-05-12 15:28 -0500
SubjectEmail Parsing
Message-ID<fc0d26726bd7a41b4a6d7d590b6c0cb5@ruby-forum.com>
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/.

[toc] | [next] | [standalone]


#4431

FromBrian Candler <b.candler@pobox.com>
Date2011-05-12 15:39 -0500
Message-ID<1a310af168f7773526f3d74b3b9af98a@ruby-forum.com>
In reply to#4428
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/.

[toc] | [prev] | [next] | [standalone]


#4439

FromRobert Johns <piratej74@live.com>
Date2011-05-12 16:24 -0500
Message-ID<d719ae7b1d436623a434b729b0bab538@ruby-forum.com>
In reply to#4428
That worked out well thank you very much.

-- 
Posted via http://www.ruby-forum.com/.

[toc] | [prev] | [next] | [standalone]


#4443

FromRyan Davis <ryand-ruby@zenspider.com>
Date2011-05-12 18:57 -0500
Message-ID<5568D131-9173-46F0-BB57-3B34460515BD@zenspider.com>
In reply to#4428
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

BTW... we're discussing stabbing you in the 'indenting "end"' thread. :)

[toc] | [prev] | [next] | [standalone]


#4451

FromPhillip Gawlowski <cmdjackryan@googlemail.com>
Date2011-05-12 19:48 -0500
Message-ID<BANLkTinG-HfCMaZo0XVb-D-a=MFWAa9iFg@mail.gmail.com>
In reply to#4443
On Fri, May 13, 2011 at 1:57 AM, Ryan Davis <ryand-ruby@zenspider.com> wrote:
>
> BTW... we're discussing stabbing you in the 'indenting "end"' thread. :)

def stab
  "ouch"
  end

SCNR. :D


-- 
Phillip Gawlowski

Though the folk I have met,
(Ah, how soon!) they forget
When I've moved on to some other place,
There may be one or two,
When I've played and passed through,
Who'll remember my song or my face.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.ruby


csiph-web