You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mail-notify 710B

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