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] [username] [password] [folder] [flag]"
exit
end

##### Variable Section
## your imap mail server
$SERVER=ARGV[0]
## your imap/smtp mail username
$USERNAME=ARGV[1]
## your imap/smtp mail password
$PASSWORD=ARGV[2]
## your mail folder (for example, INBOX)
$FOLDER=ARGV[3]
## flag to use (as per RFC 2060)
$FLAG=ARGV[4]
##### End Variable Section

imap = Net::IMAP.new($SERVER)
imap.login($USERNAME, $PASSWORD)
imap.select($FOLDER)
count = imap.status($FOLDER,[$FLAG])[$FLAG]

puts "#{count} messages with flag #{$FLAG} \n\n"
total_time = Time.now - begin_
puts "RUNTIME: #{total_time}"

There is another interesting example about this at Will's Blog. It's funny how people try to do the same things at similar times :-)

Of course official doc for this is here.
But If you want to snoop at a more complex webmail application using IMAP from Ruby/Rails you should seriously check out Mailr.

Related posts:

  1. Backup or Store stuff to GMail via IMAP in Ruby
  2. Java… oh Java… (aka "High vs. Low level languages rant")
  3. MX records and small servers
  4. Thoughts, Blogs, and Ruby with .Net
  5. Google has pissed me off this week!

Related posts brought to you by Yet Another Related Posts Plugin.

Leave a Reply

To prevent Comment Spam, we use Asirra, a Human Interactive Proof that will require you to click on pictures of Cats to set them apart from those of Dogs, rather than filling in some unreadable, distorted string of obscured and dodgy letters.

It should be easier and take you just as long.

We promise that no animal will be harmed during this classification process.