From: Sam Roberts Date: 2004-02-07T04:03:17+09:00 Subject: Re: Email parsing 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