Created
January 6, 2011 14:46
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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