12345678910111213141516171819202122232425 |
- #!/usr/bin/env ruby
- #
- # pbrisbin 2014 - check a Maildir for new messages and spawn a notification via
- # notify-send.
- #
- ###
- directory = ARGV.first || "#{ENV["HOME"]}/Maildir"
- cachefile = "/tmp/mail-notify-message"
- mailboxes = Hash.new(0)
-
- Dir["#{directory}/**/*/new/*"].each do |message|
- unless message =~ %r{/(archive|drafts|sent|spam|trash)/}
- mailbox = message.sub(%r{#{directory}/(.*)/new/.*}, '\1')
- mailboxes[mailbox] += 1
- end
- end
-
- body = mailboxes.map { |mailbox, count| "- #{mailbox} (#{count})" }.join("\n")
- cached_body = File.read(cachefile) rescue ""
-
- if body != "" && body != cached_body
- system("notify-send", "-i", "mail_new", "--", "New mail", body)
-
- File.write(cachefile, body)
- end
|