Skip to content

Instantly share code, notes, and snippets.

@nevyn
Created January 6, 2011 14:46
Show Gist options
  • Select an option

  • Save nevyn/767956 to your computer and use it in GitHub Desktop.

Select an option

Save nevyn/767956 to your computer and use it in GitHub Desktop.
Get unread and flag count in inbox. Drives http://nevyn.nu/unreads/. Good indicator of how stressed I am.
#!/usr/bin/env ruby
require 'net/imap'
require 'rubygems'
require 'sqlite3'
imap = Net::IMAP.new("imap.gmail.com", 993, true)
imap.login("someusername", "somepassword")
imap.select('INBOX')
total = imap.responses["EXISTS"][-1]
unread = imap.search(["UNSEEN"]).length
flagged = imap.search(["FLAGGED"]).length
db = SQLite3::Database.new "/beta/www/main/unreads/data/[email protected]"
db.execute "create table if not exists unreads (at int, total int, unread int, flagged int);"
db.execute "insert into unreads (at, total, unread, flagged) values (?, ?, ?, ?);", Time.new.to_i, total, unread, flagged
db.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment