rb-mailnotify 0.1 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.rdoc +27 -0
  2. data/bin/mailnotify +56 -9
  3. data/bin/riff +9 -2
  4. data/lib/rb-mailnotify.rb +13 -1
  5. metadata +55 -75
data/README.rdoc ADDED
@@ -0,0 +1,27 @@
1
+ = rb-mailnotify
2
+
3
+ == Summary
4
+
5
+ Two simple tools.
6
+ * riff - a biff like utility to show new mail in all maildir sub-directories of ~/Maildir/
7
+ * mailnotify - an inotify watcher that will send libnotify events for new email in all of ~/Maildir/ (and subdirs)
8
+
9
+ == Options
10
+ currently only responds to a '-d' or '--debug' to show debug output
11
+
12
+
13
+ == Troubleshooting
14
+ If you get an exception the there is no room left on device, run:
15
+ $> echo 100000 | sudo tee /proc/sys/fs/inotify/max_user_watches
16
+
17
+ == License
18
+
19
+ Copyright (c) 2012, Vincent Batts, Raleigh, NC
20
+ All rights reserved.
21
+
22
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
23
+
24
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
25
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
26
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
data/bin/mailnotify CHANGED
@@ -1,21 +1,64 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'optparse'
4
+
3
5
  require 'rubygems'
4
6
  require 'rb-mailnotify'
5
7
 
6
- def main
8
+ $PROGRAM_NAME = "mailnotify"
9
+ DEFAULT_MAILDIR = File.join(ENV["HOME"], "Maildir")
10
+
11
+ def parse_args(args)
12
+ options = {
13
+ :maildir => DEFAULT_MAILDIR,
14
+ }
15
+ opts = OptionParser.new do |opts|
16
+ opts.on("-m MAILDIR", "--maildir", "use alternate maildir directory (default #{DEFAULT_MAILDIR}") do |o|
17
+ options[:maildir] = o
18
+ end
19
+ opts.on("-d", "--debug","enable debugging output") do |o|
20
+ options[:debug] = o
21
+ end
22
+ opts.on("-B","--background", "fork into the background") do |o|
23
+ options[:background] = o
24
+ end
25
+ end
26
+
27
+ begin
28
+ opts.parse!(args)
29
+ rescue OptionParser::InvalidOption => ex
30
+ puts ex
31
+ puts opts
32
+ abort
33
+ end
34
+
35
+
36
+ return options
37
+ end
38
+
39
+ def main(opts)
7
40
  # First: build list of maildirs. use 'find' and build that list
8
- maildirs = find_maildirs(File.join(ENV["HOME"], "Maildir"))
41
+ maildirs = find_maildirs(opts[:maildir])
9
42
 
10
43
  # Second: setup inotify watchers on those directories
11
44
  # if there are new events in the "new" directories,
12
45
  # then trigger the libnotify for that subdir
13
46
  notifier = INotify::Notifier.new
47
+ times = {}
48
+ wait = 10
14
49
  maildirs.each do |mdir|
50
+ times[mdir] = Time.now # Start off with a timestamp
51
+
52
+ # The following block is storing a callback in the notifier
15
53
  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)
54
+ if (times[mdir] + wait) < Time.now
55
+ check_maildir(mdir) do |new_mails,old_mails|
56
+ @log.debug("notifying about #{new_mails.length} emails in #{File.basename(mdir)}")
57
+ notify_new_mail(File.basename(mdir), new_mails.length)
58
+ times[mdir] = Time.now
59
+ end
60
+ else
61
+ @log.debug("too soon, waiting a couple of seconds for the dust to settle")
19
62
  end
20
63
  end
21
64
  end
@@ -28,10 +71,14 @@ def main
28
71
  end
29
72
  end
30
73
 
31
- if ARGV.include?("-d") or ARGV.include?("--debug")
32
- @log.level = Logger::DEBUG
33
- end
74
+ @options = parse_args(ARGV)
75
+ @log.level = Logger::DEBUG if @options[:debug]
34
76
 
35
- main
77
+ if @options[:background]
78
+ pid = Kernel.fork { main(@options) }
79
+ puts "Running in background pid #{pid} ..."
80
+ else
81
+ main(@options)
82
+ end
36
83
 
37
84
  # vim:set sw=2 sts=2 et:
data/bin/riff CHANGED
@@ -8,11 +8,18 @@ def main
8
8
  maildirs = find_maildirs(File.join(ENV["HOME"], "Maildir"))
9
9
 
10
10
  # Second: show the stats
11
+ total_unread = 0
12
+ total_dirs = 0
11
13
  maildirs.each do |mdir|
12
- check_maildir(mdir) do |new_mails|
13
- puts "#{File.basename(mdir)}: #{new_mails.length}"
14
+ check_maildir(mdir) do |new_mails, old_mails|
15
+ puts "#{File.basename(mdir)}: #{new_mails.length} new, #{old_mails.length} current"
16
+ if new_mails.length > 0
17
+ total_unread += new_mails.length
18
+ total_dirs += 1
19
+ end
14
20
  end
15
21
  end
22
+ puts "Total Unread: #{total_unread} in #{total_dirs} directories"
16
23
  end
17
24
 
18
25
 
data/lib/rb-mailnotify.rb CHANGED
@@ -1,3 +1,13 @@
1
+ =begin
2
+ Copyright (c) 2012, Vincent Batts, Raleigh, NC
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6
+
7
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10
+ =end
1
11
 
2
12
  require 'find'
3
13
  require 'logger'
@@ -53,9 +63,11 @@ def check_maildir(path, &block)
53
63
  @log.debug(mdir)
54
64
 
55
65
  new_mail = mdir.list(:new)
66
+ cur_mail = mdir.list(:cur)
56
67
  @log.debug(new_mail)
68
+ @log.debug(cur_mail)
57
69
 
58
- yield(new_mail)
70
+ yield(new_mail,cur_mail)
59
71
 
60
72
  @log.debug("nil out the vars, for good measure")
61
73
  mdir = new_mail = nil
metadata CHANGED
@@ -1,108 +1,88 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rb-mailnotify
3
- version: !ruby/object:Gem::Version
4
- hash: 9
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.3'
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- version: "0.1"
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Vincent Batts
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2012-02-10 00:00:00 Z
18
- dependencies:
19
- - !ruby/object:Gem::Dependency
12
+ date: 2012-09-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
20
15
  name: libnotify
21
- prerelease: false
22
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &17516420 !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- hash: 3
28
- segments:
29
- - 0
30
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
31
22
  type: :runtime
32
- version_requirements: *id001
33
- - !ruby/object:Gem::Dependency
34
- name: maildir
35
23
  prerelease: false
36
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *17516420
25
+ - !ruby/object:Gem::Dependency
26
+ name: maildir
27
+ requirement: &17515760 !ruby/object:Gem::Requirement
37
28
  none: false
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- hash: 3
42
- segments:
43
- - 0
44
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
45
33
  type: :runtime
46
- version_requirements: *id002
47
- - !ruby/object:Gem::Dependency
48
- name: rb-inotify
49
34
  prerelease: false
50
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *17515760
36
+ - !ruby/object:Gem::Dependency
37
+ name: rb-inotify
38
+ requirement: &17515280 !ruby/object:Gem::Requirement
51
39
  none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- hash: 3
56
- segments:
57
- - 0
58
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
59
44
  type: :runtime
60
- version_requirements: *id003
61
- description: "mail notification-ish tools "
62
- email: vbatts@redhat.com
63
- executables:
45
+ prerelease: false
46
+ version_requirements: *17515280
47
+ description: ! 'mail notification-ish tools '
48
+ email: vbatts@hashbangbash.com
49
+ executables:
64
50
  - riff
65
51
  - mailnotify
66
52
  extensions: []
67
-
68
- extra_rdoc_files: []
69
-
70
- files:
53
+ extra_rdoc_files:
54
+ - README.rdoc
55
+ files:
71
56
  - bin/riff
72
57
  - bin/mailnotify
73
58
  - lib/rb-mailnotify.rb
74
- homepage:
59
+ - README.rdoc
60
+ homepage: https://github.com/vbatts/rb-mailnotify/
75
61
  licenses: []
76
-
77
62
  post_install_message:
78
- rdoc_options: []
79
-
80
- require_paths:
63
+ rdoc_options:
64
+ - --main=README.rdoc
65
+ - --line-numbers
66
+ - --inline-source
67
+ - --title=rb-mailnotify 0.3 Documentation
68
+ require_paths:
81
69
  - lib
82
- required_ruby_version: !ruby/object:Gem::Requirement
70
+ required_ruby_version: !ruby/object:Gem::Requirement
83
71
  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
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
77
  none: false
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- hash: 3
97
- segments:
98
- - 0
99
- version: "0"
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
100
82
  requirements: []
101
-
102
83
  rubyforge_project:
103
- rubygems_version: 1.8.11
84
+ rubygems_version: 1.8.17
104
85
  signing_key:
105
86
  specification_version: 3
106
87
  summary: mail notification-ish tools
107
88
  test_files: []
108
-