Ruby mail program - how to find all email messages I have read but not replied to

Here is the source code for a Ruby mail program I wrote that looks through my INBOX and finds all the email messages I have a) read but b) have not replied to.

This Ruby script comes in very handy on a project I'm working on now where we exchange 50-75 email messages per day. After a little while there are so many messages I can't remember if I replied to the important messages, so this program helps whittle down the list and just shows the ones I have read, but have not replied to. (The ones I haven't read are a lot easier to spot.)

This Ruby mail script uses the same IMAP functionality that I've demonstrated in other posts, but I've added different filters to it. The full list of filters are the FROM, SINCE, SEEN, and NOT ANSWERED fields.

Ruby mail program - source code

Here's the source code for the program I've named read_but_no_reply.rb:

# PROGRAM: read_but_no_reply.rb

require 'net/imap'
require 'login_info'

# put your mail server here

# change your mailbox if necessary

imap =
imap.authenticate('LOGIN', USERNAME, PASSWORD)

# changed the values for the FROM and SINCE fields to meet your needs["FROM",  "",
             "SINCE", "15-Nov-2006",
             "NOT",   "ANSWERED"]).each do |message_id|
  env = imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"]
  puts "#{env.from[0].name}: \t#{env.subject}"


This program relies on a second file named login_info.rb that contains the USERNAME and PASSWORD declarations, as shown here:

# FILE: login_info.rb

If you prefer you can just include these two lines in the read_but_no_reply.rbfile, but I put them in a separate file so I can easily include them in all my ruby mail-related scripts.