imap_notifier 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MDNjNzY3MjU5YjZhMDcyMzY5OWQ5YmQxZTc3ODViNzJmZmM3NzU1MQ==
5
+ data.tar.gz: !binary |-
6
+ NWE5YmNiYTdhNzk1Y2I1YjI0YzdlMGQxZmQyYmEzZjEwNDY3ZDdiMw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NTNhY2ZlYTdjMTVmNTFiNWI5NjA4NWY0N2E4ZTIzNzgxMGZmYzNiYzE5YmI3
10
+ ZDhkMTA4ZTA4YmMxZTJmOWQyNDhjMDc1OWE2YTA4MDU4ZTA4Zjc1NWIzYzMw
11
+ YTcyMTAwNDQ4Y2JmYTgzZWUwMjFhMDJmNzE4MjZlZDgwNWZiMjg=
12
+ data.tar.gz: !binary |-
13
+ NmYzN2ZkZDE3MDY4OTUwYTkxYTIzZGRlM2YwYzRjZGM3Y2M3ZjJkNjgwMGNi
14
+ YjgxNTU5OTFiY2FkMDM3NTQzOTkzZDM0OGZlM2ZmODU0MzBiNjNkYTUzZjE3
15
+ NWNkMWJiYmYxMjE5YjBkNjlmZDFjOTk1NDVjMzFjY2VjNDA1OTc=
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *~
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in imap_notifier.gemspec
4
+ gemspec
5
+
6
+ if `uname`.strip == 'Darwin'
7
+ if `sw_vers -productVersion`.strip >= '10.8'
8
+ gem 'terminal-notifier'
9
+ else
10
+ gem 'ruby-growl'
11
+ end
12
+ else
13
+ raise "You must be running Mac OS X for imap_notifier to work!"
14
+ end
15
+
16
+ gem 'highline'
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ imap_notifier (0.2.1)
5
+ highline
6
+ ruby-growl
7
+ terminal-notifier
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ highline (1.6.19)
13
+ macaddr (1.6.1)
14
+ systemu (~> 2.5.0)
15
+ rake (10.1.0)
16
+ ruby-growl (4.0)
17
+ uuid (~> 2.3, >= 2.3.5)
18
+ systemu (2.5.2)
19
+ terminal-notifier (1.4.2)
20
+ uuid (2.3.7)
21
+ macaddr (~> 1.0)
22
+
23
+ PLATFORMS
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ bundler (~> 1.3)
28
+ highline
29
+ imap_notifier!
30
+ rake
31
+ terminal-notifier
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 David Campbell
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ IMAP Notifier
2
+ =============
3
+
4
+ Notification of new, unread email via IMAP using Ruby, [Highline](http://highline.rubyforge.org/doc/), [Net/IMAP](http://ruby-doc.org/stdlib-1.9.3/libdoc/net/imap/rdoc/Net/IMAP.html), and [terminal-notifier](https://github.com/alloy/terminal-notifier)/[ruby-growl](https://github.com/drbrain/ruby-growl).
5
+
6
+ If you're running Max OSX > 10.8, [terminal-notifier](https://github.com/alloy/terminal-notifier) is required, otherwise [ruby-growl](https://github.com/drbrain/ruby-growl) and [Growl](http://growl.info/) is required.
7
+
8
+ Setup
9
+ --------
10
+ Configure your .imap_notifier config file in your homedir or specific the flags via the command line. Your config file must have permissions of 600, thus allowing you to put in your password if you so choose. The config file is in YAML format and should be read in as a hash.
11
+
12
+
13
+ Example ~/.imap_notifier file
14
+
15
+ folders:
16
+ - INBOX
17
+ - Monitoring
18
+ - Commits
19
+ - Team+Status
20
+ user: 'han.solo'
21
+ domain: 'example.org'
22
+ password: "1H@t3BuG$!"
23
+ max: 10
24
+
25
+ Usage
26
+ ---------
27
+
28
+ $ ./bin/imap_notifier -h
29
+ Usage: imap_notifier [OPTIONS]
30
+ Options:
31
+ -h, --help Display this message
32
+ -V, --version Display 'IMAP Notifier 0.2.0' and exit
33
+ -v, --debug Write debug output into /tmp/imap_notifier.debug
34
+ -f, --file FILE Read configuration file. [DEFAULT: ~/.imap_notifier]
35
+ -s, --server STR Specify imap server. [Default: imap.gmail.com]
36
+ -d, --domain STR Specify email domain. [Default: gmail.com]
37
+ -u, --user STR Specify user login. [Default: ENV['USER']]
38
+ -m, --max INT Max mail mentioned before grouping them together. [Default: 5]
39
+ -k, --kill Kill currently running IMAP Notifier process with SIGINT
40
+
41
+
42
+ Tips
43
+ ------
44
+
45
+ * User name is pulled from your environment via ```ruby ENV['USER'] ```
46
+ * If the root domain of your IMAP server is the same as your email domain (i.e. imap._gmail.com_ IS the same as user@_gmail.com_) then you only need to specify the IMAP server.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/imap_notifier ADDED
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'imap_notifier'
5
+ require 'optparse'
6
+
7
+ opts = {}
8
+
9
+ opt_parser = OptionParser.new do |opt|
10
+ opt.banner = "Usage: #{opt.program_name} [OPTIONS]"
11
+ opt.program_name = "IMAP Notifier"
12
+ opt.separator "Options:"
13
+ opt.on('-h', '--help', 'Display this message') do
14
+ puts opt_parser
15
+ exit
16
+ end
17
+
18
+ opt.on('-V', '--version', "Display '#{opt.program_name} #{IMAP_Notifier::VERSION}' and exit") do
19
+ puts opt.program_name << ' ' << IMAP_Notifier::VERSION
20
+ exit
21
+ end
22
+
23
+ opt.on('-v', '--debug', "Write debug output into #{DEBUGFILE}") do
24
+ opts[:debug] = true
25
+ end
26
+
27
+ opt.on('-f', '--file FILE', "Read configuration file. [DEFAULT: ~/.imap_notifier]") do |c|
28
+ opts[:config] = c
29
+ end
30
+
31
+ opt.on('-s','--server STR', "Specify imap server. [Default: #{$imap_server}]") do |s|
32
+ $imap_server = s
33
+ end
34
+
35
+ opt.on('-d','--domain STR',
36
+ "Specify email domain. [Default: #{$imap_server.split('.').pop(2).join('.')}]") do |d|
37
+ opts[:domain] = d.gsub('@','')
38
+ end
39
+
40
+ opt.on('-u','--user STR', "Specify user login. [Default: ENV['USER']]") do |d|
41
+ opts[:domain] = d.gsub('@','')
42
+ end
43
+
44
+ opt.on('-m','--max INT', "Max mail mentioned before grouping them together. [Default: #{MAX_MAIL}]") do |m|
45
+ opts[:max] = m.to_i
46
+ end
47
+
48
+ opt.on('-k', '--kill', "Kill currently running #{opt.program_name} process with SIGINT") do
49
+ begin
50
+ pid = IO.readlines(PIDFILE).first.to_i
51
+ puts "Killing PID: #{pid}"
52
+ Process.kill("SIGINT", pid)
53
+ rescue Errno::ESRCH, Errno::ENOENT => e
54
+ puts "#{e.message} - Exiting..."
55
+ ensure
56
+ File.delete(PIDFILE) if File.exists?(PIDFILE)
57
+ end
58
+ exit
59
+ end
60
+ end
61
+
62
+ opt_parser.parse!
63
+
64
+ if File.exists?(PIDFILE) && IO.readlines(PIDFILE).any?
65
+ puts "#{PIDFILE} already exists -- Exiting..."
66
+ exit -1
67
+ end
68
+
69
+ IMAP_Notifier.new(opts)
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'imap_notifier/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "imap_notifier"
8
+ spec.version = IMAP_Notifier::VERSION
9
+ spec.author = "David Campbell"
10
+ spec.email = "david@mrcampbell.org"
11
+ spec.description = %q{Notification of new, unread email via IMAP}
12
+ spec.summary = %q{Notification of new, unread email via IMAP using Ruby, Highline, Net/IMAP, and terminal-notifier/ruby-growl.
13
+
14
+ If you're running Max OSX > 10.8, terminal-notifier is required, otherwise ruby-growl and Growl is required.}
15
+ spec.homepage = "https://github.com/dacamp/imap_notifier"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_dependency "highline"
26
+ spec.add_dependency "ruby-growl"
27
+ spec.add_dependency "terminal-notifier"
28
+ end
@@ -0,0 +1,81 @@
1
+ class IMAP_Notifier
2
+ def initialize(opts={})
3
+ config opts
4
+ @notifier = IMAP_Notifier::Alert.new
5
+
6
+ pid = fork do
7
+ $stderr.reopen(ERRFILE, 'w')
8
+ if @debug
9
+ $stdout.reopen(DEBUGFILE, 'w')
10
+ @notifier.alert("DEBUG MODE ENABLED", "DEBUG LOGFILE: #{DEBUGFILE}")
11
+ end
12
+ run
13
+ end
14
+ File.open(PIDFILE, 'w') { |f| f.write pid }
15
+ end
16
+
17
+ def imap
18
+ @imap ||= _imap
19
+ end
20
+
21
+ def run
22
+ begin
23
+ @folders.each do |f, ids|
24
+ imap.examine("#{f}")
25
+
26
+ p "Mailbox: #{f}" if @debug
27
+ unseen = imap.search(["UNSEEN"])
28
+ ungrowled = unseen - ids
29
+ ungrowled_count = ungrowled.length
30
+ p "All unseen mail ids: #{unseen}",
31
+ "All ungrowled mail ids: #{ungrowled}",
32
+ "Ungrowled count: #{ungrowled_count}" if @debug
33
+
34
+ if ungrowled_count > @max_mail
35
+ p "New Mail in #{f}!",
36
+ "New: #{ungrowled_count}\nTotal: #{unseen.length}" if @debug
37
+ @notifier.alert("New Mail in #{f}!", "New: #{ungrowled_count}")
38
+ else
39
+ ungrowled.each do |msg_id|
40
+ msg = imap.fetch(msg_id, "ENVELOPE")[0].attr["ENVELOPE"]
41
+ next if ids.include?(msg.message_id)
42
+ p "Growled about #{msg.message_id}" if @debug
43
+ @notifier.alert("Mail from #{msg.sender.first.mailbox}", "#{msg.subject}")
44
+ end
45
+ end
46
+ @folders[f] = unseen
47
+ end
48
+ sleep SLEEP
49
+ rescue Interrupt
50
+ @notifier.alert("Goodbye!", '')
51
+ raise
52
+ rescue EOFError
53
+ imap.login(@user, @password)
54
+ rescue Exception => err
55
+ p "Class: #{err.class}",
56
+ "Message: #{err.message}",
57
+ "See #{ERRFILE} for more info." if @debug
58
+ @notifier.alert(err.class, err.message)
59
+
60
+ warn Time.now
61
+ warn @user
62
+ warn $imap_server
63
+ warn err.class
64
+ warn err.message
65
+ err.backtrace.map{ |e| warn e }
66
+ raise
67
+ end while true
68
+ end
69
+
70
+ private
71
+ def get_password(prompt="Enter Password: ")
72
+ ask(prompt) { |q| q.echo = false }
73
+ end
74
+
75
+ def _imap
76
+ imap = Net::IMAP.new($imap_server, { :port => 993, :ssl => true } )
77
+ imap.login(@user, @password)
78
+ @notifier.alert("User connected to #{@domain}!", "USER: #{@user}")
79
+ return imap
80
+ end
81
+ end
@@ -0,0 +1,21 @@
1
+ class IMAP_Notifier
2
+ def config(opts={})
3
+ file = File.expand_path("~#{opts[:user]}/.imap_notifier")
4
+ if File.exists? file
5
+ m = sprintf("%o", File.stat(file).mode).split('').last(3).join().to_i
6
+ if m != 600
7
+ warn "#{file} must have permissions 0644, not #{m}"
8
+ exit 1
9
+ end
10
+ YAML.load(File.open(file)).each do |k,v|
11
+ opts[k.to_sym] ||= v
12
+ end
13
+ end
14
+ @domain = opts[:domain] || $imap_server.split('.').pop(2).join('.')
15
+ @user = "#{opts[:user] || ENV['USER']}@#{@domain}"
16
+ @password = opts[:password] || get_password
17
+ @folders = Hash[(opts[:folders] || ['INBOX']).map{ |f| [f,Array.new] }]
18
+ @debug = opts[:debug] || false
19
+ @max_mail = opts[:max] || MAX_MAIL
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ require 'ruby-growl'
2
+
3
+ class IMAP_Notifier::Alert < Growl
4
+ def initialize
5
+ super("localhost", ::IMAP_Notifier::VERSION)
6
+ end
7
+
8
+ def alert(title, body)
9
+ add_notification ::IMAP_Notifier::VERSION
10
+ notify ::IMAP_Notifier::VERSION, title, body
11
+ end
12
+
13
+ end
@@ -0,0 +1,9 @@
1
+ require 'terminal-notifier'
2
+
3
+ class IMAP_Notifier::Alert
4
+ include TerminalNotifier
5
+
6
+ def alert(title,body)
7
+ notify(body, :title => title)
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ class IMAP_Notifier
2
+ VERSION='0.2.1'
3
+ end
@@ -0,0 +1,26 @@
1
+ require 'yaml'
2
+ require 'net/imap'
3
+ require 'highline/import'
4
+
5
+ require 'imap_notifier/version'
6
+ require 'imap_notifier/config'
7
+ require 'imap_notifier/base'
8
+
9
+
10
+ MAX_MAIL = 5 # Max new mails mentioned before they
11
+ # are grouped together
12
+ SLEEP = 30
13
+ ERRFILE = '/tmp/imap_notifier.err'
14
+ DEBUGFILE = '/tmp/imap_notifier.debug'
15
+ PIDFILE = '/tmp/imap_notifier.pid'
16
+ $imap_server = "imap.gmail.com" # could be anything with tweaks
17
+
18
+ if `uname`.strip == 'Darwin'
19
+ if (OSX_VERSION = `sw_vers -productVersion`.strip) >= '10.8'
20
+ require 'imap_notifier/notifier'
21
+ else
22
+ require 'imap_notifier/growler'
23
+ end
24
+ else
25
+ raise "You must be running Mac OS X for imap_notifier to work!"
26
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imap_notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - David Campbell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: highline
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ruby-growl
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: terminal-notifier
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Notification of new, unread email via IMAP
84
+ email: david@mrcampbell.org
85
+ executables:
86
+ - imap_notifier
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/imap_notifier
97
+ - imap_notifier.gemspec
98
+ - lib/imap_notifier.rb
99
+ - lib/imap_notifier/base.rb
100
+ - lib/imap_notifier/config.rb
101
+ - lib/imap_notifier/growler.rb
102
+ - lib/imap_notifier/notifier.rb
103
+ - lib/imap_notifier/version.rb
104
+ homepage: https://github.com/dacamp/imap_notifier
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.0.6
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Notification of new, unread email via IMAP using Ruby, Highline, Net/IMAP,
128
+ and terminal-notifier/ruby-growl. If you're running Max OSX > 10.8, terminal-notifier
129
+ is required, otherwise ruby-growl and Growl is required.
130
+ test_files: []