Top Level Namespace
Constant Summary collapse
- WAIT_TIME =
1.5 (s), 1000 (ms), “2”, nil, false
3.5
Instance Method Summary collapse
- #check_maildir(path) {|new_mail, cur_mail| ... } ⇒ Object
- #find_maildirs(base_path) ⇒ Object
- #notify_new_mail(box, num) ⇒ Object
Instance Method Details
#check_maildir(path) {|new_mail, cur_mail| ... } ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rb-mailnotify.rb', line 59 def check_maildir(path, &block) @log.debug("setup maildir for path #{path}") mdir = Maildir.new(path, false) @log.debug(mdir) new_mail = mdir.list(:new) cur_mail = mdir.list(:cur) @log.debug(new_mail) @log.debug(cur_mail) yield(new_mail,cur_mail) @log.debug("nil out the vars, for good measure") mdir = new_mail = nil end |
#find_maildirs(base_path) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rb-mailnotify.rb', line 45 def find_maildirs(base_path) dirs = [] @log.debug("searching for maildirs") Find.find(base_path) do |path| if FileTest.directory?(path) && File.basename(path) == 'new' dir = File.dirname(path) dirs << dir @log.debug("adding directory #{dir}") end end @log.debug("returning #{dirs.length} dirs") return dirs end |
#notify_new_mail(box, num) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rb-mailnotify.rb', line 25 def notify_new_mail(box, num) @log.debug("prepping to notify on #{box} email box, for #{num} emails") n = Libnotify.new do |notify| notify.summary = "in %s: " % box notify.body = "%d unread email" % num notify.timeout = WAIT_TIME notify.urgency = :low # :low, :normal, :critical notify.append = false # default true - append onto existing notification notify.transient = false # default false - keep the notifications around after display notify.icon_path = "/usr/share/icons/gnome/scalable/status/mail-unread-symbolic.svg" end @log.debug("libnotify show!") n.show! @log.debug("sleep for #{WAIT_TIME + 0.1}") Kernel.sleep WAIT_TIME + 0.1 @log.debug("libnotify close") n.close end |