Net::IMAP::Hairy

The Ruby Net::IMAP module has a bit of a warty interface, but it does work. It could do with a much nicer interface (perhaps a Net::IMAP::Simple equivalent?) and better docs. Here is a working example:

#!/usr/bin/env ruby

require 'rubygems'
require 'net/imap'
require_gem 'rmail'

imap = Net::IMAP.new('host')
imap.login('username', 'password')
imap.examine('inbox')
imap.search(["SUBJECT", "Some text to look for", "SINCE", "11-Sep-2005"]).each do |message_id|
message = RMail::Parser.read(imap.fetch(message_id, ["BODY[]"])[0].attr['BODY[]'])
puts message.header.subject
end

Not too difficult once you work out what you need to be doing.

One thought on “Net::IMAP::Hairy

  1. More on Ruby and IMAP

    I’ve written here of a Ruby IMAP Script.
    The script is INCREDIBLY simple (but it had to do a simple thing nonethless):

    #!/usr/bin/env ruby
    begin_ = Time.now
    require ‘net/imap’
    if !ARGV[4]
    puts “USAGE: ruby imapcheck.rb [server] […

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.