IMAP --> mail

204 views
Skip to first unread message

THUFIR HAWAT

unread,
Dec 15, 2012, 5:24:36 AM12/15/12
to mail...@googlegroups.com
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

Jeremy Kemper

unread,
Dec 15, 2012, 8:48:12 PM12/15/12
to mail...@googlegroups.com
Mail.new(imap.fetch(id,'RFC822')[0].attr['RFC822'])

Reply all
Reply to author
Forward
0 new messages