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.




%d bloggers like this:

On this website we use first or third-party tools that store small files (cookie) on your device. Cookies are normally used to allow the site to run properly (technical cookies), to generate navigation usage reports (statistics cookies) and to suitable advertise our services/products (profiling cookies). We can directly use technical cookies, but you have the right to choose whether or not to enable statistical and profiling cookies. Enabling these cookies, you help us to offer you a better experience.