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 Response to “Net::IMAP::Hairy”

  1. musc@ - Daniele Muscetta's Weblog Says:

    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