Link to home
Start Free TrialLog in
Avatar of bobbit31
bobbit31Flag for United States of America

asked on

Ruby and Regex and POP

I have 2 questions:

1.) -------------------
How to write a string.split command that will take the following line and return an array of 2 email addresses:

To: "Stuart Smith" <stuart@email.com>, "Community" <comm@email.com>


2.)--------------------
I built a pop3 reader using something very similar to below however, I am looking to store the actual attachment as the mime-type itself like a PDF.  Any help?

   



POP3.start('pop.example.com', 110,
               'YourAccount, 'YourPassword') do |pop|
      n = 1
      pop.mails.each do |popmail|
        File.open("inbox/#{n}", 'w') do |f|
          f.write popmail.pop
        end
        popmail.delete
        n += 1
      end
    end

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
1) is a simple split and the collect generates a new array from executing the block on each item of the array generated by the split
the block is a simple regex substitution

2) I am not sure I understand the second part of your question actually
Do you want to safe the attachment and give it an extension based on the mime type?
sorry bobbit I can't agree to your deletion
- I answered the first half of your question, you should award that at least
- I asked for clarification for the second part, you never gave that clarification
Avatar of bobbit31

ASKER

sorry, i don't recall trying to delete this. i agree you deserve points.
no problem,
cheers