rb-mailnotify 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/mailnotify +37 -0
- data/bin/riff +25 -0
- data/lib/rb-mailnotify.rb +64 -0
- metadata +108 -0
data/bin/mailnotify
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rb-mailnotify'
|
5
|
+
|
6
|
+
def main
|
7
|
+
# First: build list of maildirs. use 'find' and build that list
|
8
|
+
maildirs = find_maildirs(File.join(ENV["HOME"], "Maildir"))
|
9
|
+
|
10
|
+
# Second: setup inotify watchers on those directories
|
11
|
+
# if there are new events in the "new" directories,
|
12
|
+
# then trigger the libnotify for that subdir
|
13
|
+
notifier = INotify::Notifier.new
|
14
|
+
maildirs.each do |mdir|
|
15
|
+
notifier.watch(File.join(mdir, 'new'), :create, :moved_to) do |path|
|
16
|
+
check_maildir(mdir) do |new_mails|
|
17
|
+
@log.debug("notifying about #{new_mails.length} emails in #{File.basename(mdir)}")
|
18
|
+
notify_new_mail(File.basename(mdir), new_mails.length)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
begin
|
24
|
+
notifier.run
|
25
|
+
rescue Interrupt
|
26
|
+
@log.info("caught Interrupt, closing")
|
27
|
+
true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
if ARGV.include?("-d") or ARGV.include?("--debug")
|
32
|
+
@log.level = Logger::DEBUG
|
33
|
+
end
|
34
|
+
|
35
|
+
main
|
36
|
+
|
37
|
+
# vim:set sw=2 sts=2 et:
|
data/bin/riff
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rb-mailnotify'
|
5
|
+
|
6
|
+
def main
|
7
|
+
# First: build list of maildirs. use 'find' and build that list
|
8
|
+
maildirs = find_maildirs(File.join(ENV["HOME"], "Maildir"))
|
9
|
+
|
10
|
+
# Second: show the stats
|
11
|
+
maildirs.each do |mdir|
|
12
|
+
check_maildir(mdir) do |new_mails|
|
13
|
+
puts "#{File.basename(mdir)}: #{new_mails.length}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
if ARGV.include?("-d") or ARGV.include?("--debug")
|
20
|
+
@log.level = Logger::DEBUG
|
21
|
+
end
|
22
|
+
|
23
|
+
main
|
24
|
+
|
25
|
+
# vim:set sw=2 sts=2 et:
|
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
require 'find'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'libnotify'
|
7
|
+
require 'maildir'
|
8
|
+
require 'rb-inotify'
|
9
|
+
|
10
|
+
WAIT_TIME = 3.5 # 1.5 (s), 1000 (ms), "2", nil, false
|
11
|
+
|
12
|
+
@log = Logger.new(STDERR)
|
13
|
+
@log.level = Logger::INFO
|
14
|
+
|
15
|
+
def notify_new_mail(box, num)
|
16
|
+
@log.debug("prepping to notify on #{box} email box, for #{num} emails")
|
17
|
+
n = Libnotify.new do |notify|
|
18
|
+
notify.summary = "in %s: " % box
|
19
|
+
notify.body = "%d unread email" % num
|
20
|
+
notify.timeout = WAIT_TIME
|
21
|
+
notify.urgency = :low # :low, :normal, :critical
|
22
|
+
notify.append = false # default true - append onto existing notification
|
23
|
+
notify.transient = false # default false - keep the notifications around after display
|
24
|
+
notify.icon_path = "/usr/share/icons/gnome/scalable/status/mail-unread-symbolic.svg"
|
25
|
+
end
|
26
|
+
@log.debug("libnotify show!")
|
27
|
+
n.show!
|
28
|
+
|
29
|
+
@log.debug("sleep for #{WAIT_TIME + 0.1}")
|
30
|
+
Kernel.sleep WAIT_TIME + 0.1
|
31
|
+
@log.debug("libnotify close")
|
32
|
+
n.close
|
33
|
+
end
|
34
|
+
|
35
|
+
def find_maildirs(base_path)
|
36
|
+
dirs = []
|
37
|
+
@log.debug("searching for maildirs")
|
38
|
+
Find.find(base_path) do |path|
|
39
|
+
if FileTest.directory?(path) && File.basename(path) == 'new'
|
40
|
+
dir = File.dirname(path)
|
41
|
+
dirs << dir
|
42
|
+
@log.debug("adding directory #{dir}")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
@log.debug("returning #{dirs.length} dirs")
|
46
|
+
return dirs
|
47
|
+
end
|
48
|
+
|
49
|
+
def check_maildir(path, &block)
|
50
|
+
@log.debug("setup maildir for path #{path}")
|
51
|
+
|
52
|
+
mdir = Maildir.new(path, false)
|
53
|
+
@log.debug(mdir)
|
54
|
+
|
55
|
+
new_mail = mdir.list(:new)
|
56
|
+
@log.debug(new_mail)
|
57
|
+
|
58
|
+
yield(new_mail)
|
59
|
+
|
60
|
+
@log.debug("nil out the vars, for good measure")
|
61
|
+
mdir = new_mail = nil
|
62
|
+
end
|
63
|
+
|
64
|
+
# vim:set sw=2 sts=2 et:
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rb-mailnotify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Vincent Batts
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-02-10 00:00:00 Z
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
20
|
+
name: libnotify
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: maildir
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 3
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
|
+
type: :runtime
|
46
|
+
version_requirements: *id002
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rb-inotify
|
49
|
+
prerelease: false
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
type: :runtime
|
60
|
+
version_requirements: *id003
|
61
|
+
description: "mail notification-ish tools "
|
62
|
+
email: vbatts@redhat.com
|
63
|
+
executables:
|
64
|
+
- riff
|
65
|
+
- mailnotify
|
66
|
+
extensions: []
|
67
|
+
|
68
|
+
extra_rdoc_files: []
|
69
|
+
|
70
|
+
files:
|
71
|
+
- bin/riff
|
72
|
+
- bin/mailnotify
|
73
|
+
- lib/rb-mailnotify.rb
|
74
|
+
homepage:
|
75
|
+
licenses: []
|
76
|
+
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
hash: 3
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
version: "0"
|
100
|
+
requirements: []
|
101
|
+
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.8.11
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: mail notification-ish tools
|
107
|
+
test_files: []
|
108
|
+
|