Email parsing

R

Rove Monteux

Hi there.

Question, Im using net/pop to collect email, is there any way I can get
fields as an object from it ? Such as subject, attachments, etc ?

Thanks

Rove Monteux
 
R

Rove Monteux

That sounds good, thanks !


Rove Monteux

Sam said:
Quoteing (e-mail address removed), on Sat, Feb 07, 2004 at 02:13:56AM +0900:



I don't think ruby has any builtin mail message decoders, but I've used
rubymail to do this kind of thing, and it was easy. There was at least 1
other package, I used rubymail because I thought it looked the best at
the time, and can't for the life of me remember why anymore!

Cheers,
Sam
 
A

Ara.T.Howard

Date: Sat, 7 Feb 2004 02:13:56 +0900
From: Rove Monteux <[email protected]>
Newsgroups: comp.lang.ruby
Subject: Email parsing

Hi there.

Question, Im using net/pop to collect email, is there any way I can get
fields as an object from it ? Such as subject, attachments, etc ?

Thanks

Rove Monteux

http://raa.ruby-lang.org/list.rhtml?name=rubymail

-a
--

ATTN: please update your address books with address below!

===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| STP :: http://www.ngdc.noaa.gov/stp/
| NGDC :: http://www.ngdc.noaa.gov/
| NESDIS :: http://www.nesdis.noaa.gov/
| NOAA :: http://www.noaa.gov/
| US DOC :: http://www.commerce.gov/
|
| The difference between art and science is that science is what we
| understand well enough to explain to a computer.
| Art is everything else.
| -- Donald Knuth, "Discover"
|
| /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done'
===============================================================================
 
R

Rove Monteux

Thanks again,

I see that the 'Guide' session is incomplete, specially on the subjects
of decoding, encoding and using rubymail with net/pop and net/smtp
(whats basically you would use rubymail for), any
sugestions/examples/basic documentation posted somewhere on that by any
chance ?

Again, thanks.

Cheers

Rove Monteux
 
R

Rove Monteux

Hi Sam,

Yes, I got till there using the net/pop alright, can retrieve headers
(subject, from, to etc). Im a bit lost now, I request the message.body
as it says on the docs, and it returns me nil, both on multipart or not
messages.

Follows my snippet (message is the full message retrieved with m.pop),


# do whatever with the message
def process_message(message)
p = RMail::parser.new
m = p.parse(message)

# deals with the header
h = m.header()
subject = h.subject
from = h.from
to = h.to
puts "from: " + from.first
puts "to: " + to.first
puts "subject: " + subject

# deals with the body
puts m.to_s
if m.multipart?()
m.each_part { |g|
puts g.to_s }
else
puts m.decode().to_s
end

end


Everything until the 'body' bit works correctly, and according to the docs,

http://www.lickey.com/rubymail/rubymail/doc/classes/RMail/Message.html#M000015

Its pretty much the same as with the header, as long as you check if it
is multipart or not. Doing a to_s should return me something, what it
doesnt, so obviously Im doing something wrong. Any ideas on that ? :)


Thanks again !

Cheers

Rove Monteux
 
R

Rove Monteux

Hi Sam !

Yes Im pretty puzzled now,

puts m.to_s

Outputs the whole of the message, including the two parts (normal body + attachment).

Now, p m.body and p part return nil. And I can clearly see that the email message is properly formed and has a body (+ attachment).

Gonna browse through the sources for rubymail and try to trace down whats happening, or where Im going wrong.

Anyway I agree with the 4 day schema (as long's still paid full time, of course) :)


Cheers and thanks again !


Rove Monteux
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top