Skip to content

Instantly share code, notes, and snippets.

@snaka
Created March 18, 2009 18:05
Show Gist options
  • Save snaka/81289 to your computer and use it in GitHub Desktop.
Save snaka/81289 to your computer and use it in GitHub Desktop.
Simple biff program by ruby + growl
#
# biff.rb
#
require 'net/pop'
require 'nkf'
require 'rubygems'
require 'ruby-growl'
require 'pit'
config = Pit.get("mail", :require => {
"server" => "pop3 server",
"port" => "pop3 port",
"user" => "user account",
"pass" => "password"
})
serv = config["server"]
port = config["port"].to_i
user = config["user"]
pass = config["pass"]
mails=[]
Net::POP3.start(serv, port, user, pass) {|pop|
mails = pop.mails.collect {|m| m.header}
}
exit if mails.empty?
growl = Growl.new("localhost", "Biff", ["Notify"])
growl.notify("Notify", "Mail recieved", "#{mails.size} of mail(s) recived.")
sleep 5
mails.each {|m|
subject = NKF.nkf('-Jw', m.match(/^Subject:\s+(.*)/)[1])
from = NKF.nkf('-Jw', m.match(/^From:\s+(.*)/)[1])
growl.notify("Notify", "#{from}", "#{subject}")
sleep 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment