How do I convert the e-mails to use this API?
require 'yaml'
require 'net/imap'
require 'mail'
yaml = File.open( "/home/thufir/ruby/email.yml" )
email = YAML.load_file( yaml )
server = email["server"]
user = email["user"]
password = email["password"]
puts server
puts user
puts password
imap = Net::IMAP.new(server)
puts "connected"
imap.login(user,password)
puts "logged in"
imap.select('INBOX')
mailIds = imap.search(['ALL'])
mailIds.each do |id|
msg = imap.fetch(id,'RFC822')[0].attr['RFC822']
puts msg
end
imap.logout()
imap.disconnect()
I see in the docs:
The first 10 emails sorted by date in ascending order:
emails = Mail.find(:what => :first, :count => 10, :order => :asc)
emails.length #=> 10
Or even all emails:
emails = Mail.all
emails.length #=> LOTS!
Reading an Email
mail = Mail.read('/path/to/message.eml')
https://github.com/mikel/mail
but I'm not sure how to get msg = imap.fetch(id,'RFC822')[0].attr['RFC822'] into Mail.read, unfortunately.
thanks,
Thufir