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



Sam Roberts wrote:

>Quoteing rove.monteux / fluid-rock.com, on Sat, Feb 07, 2004 at 02:58:24AM +0900:
>  
>
>>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 
>>    
>>
>
>Well, that's one way. The other way is to read a local mailbox in unix
>mbox format (also the format used by Apple's Mail.app), and to injecting
>mail into the delivery system by piping to /usr/bin/mail.
>
>Anyhow, it took me a minute to figure out how I did this, too.
>
>Here's some code ripped from a script I wrote to convert mbox files to
>vcards, with some comments added:
>
>#!/usr/bin/ruby -w
>
>require 'rmail'
>
>addrs = RMail::Address::List.new
>
>ARGV.each { |mbox|
>  File.open(File.expand_path(mbox)) { |file|
>    puts "Reading: #{file.path}..."
>
>    RMail::Mailbox::MBoxReader.new(file).each_message { |input|
>
>    # input is a single string that is one message. I get it here from
>    # the MBoxReader, you'll get it as the return value of pop.pop (used
>    # in the mode where it returns the whole message as a string).
>
>    # Then you have to parse it to create a message, do it like this:
>      message = RMail::Parser.read(input)
>
>    # Now you can play with the mesage:
>      header = message.header
>      addrs.concat(header.from)
>      addrs.concat(header.recipients)
>      addrs.concat(header.reply_to)
>    }
>  }
>}
>
>addrs = addrs.uniq
>
>puts "Unique addrs: #{addrs.size}"
>
>
>Cheers,
>Sam
>
>
>
>
>  
>

-- 
Rove Monteux
Systems Administrator

rove.monteux / fluid-rock.com