imap_notifier 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/bin/imap_notifier +4 -6
- data/lib/imap_notifier/base.rb +25 -5
- data/lib/imap_notifier/config.rb +14 -12
- data/lib/imap_notifier/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a958142e6525ef4f9ee75b68ec554eb9068c85e
|
4
|
+
data.tar.gz: ef1bc7d0d5b902c6e38b8ca009883cb057b63a80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b081dfb55146fe8bf52ca2d3d34ee087c0c45a3ac6465953b79fcaa3b833744322595904cc9f4af0914a18c49a57c9bdf609b1e27f36108770c0dc1c1433c6e9
|
7
|
+
data.tar.gz: 5f6874f752af6c6cb7cc1f9797dd9fd2d44e6a78faa336f38e31b7fb08954444f6477b067b5bc25ea4ba2a3c1943799cac1ea1cb783cbca41fb8c5d9084dca72
|
data/README.md
CHANGED
@@ -22,6 +22,8 @@ Example ~/.imap_notifier file
|
|
22
22
|
server: 'imap.server.com'
|
23
23
|
password: "1H@t3BuG$!"
|
24
24
|
max: 10
|
25
|
+
pid: /tmp/imap_notifier.1.pid # defaults to /tmp/imap_notifier.pid set this to initialize multiple imap_notifier instances
|
26
|
+
ignore_exit_code: true #defaults to false. When true, returns 0 instead of 1 on existing pidfile exit
|
25
27
|
|
26
28
|
|
27
29
|
For Keychain Access support, specify the keychain item name and account in .imap_notifier. The item must be designated an 'Internet password' in Keychain Access.
|
data/bin/imap_notifier
CHANGED
@@ -45,6 +45,10 @@ opt_parser = OptionParser.new do |opt|
|
|
45
45
|
opts[:max] = m.to_i
|
46
46
|
end
|
47
47
|
|
48
|
+
opt.on('-p','--pid STR', "PID file path. [Default: #{PIDFILE}]") do |m|
|
49
|
+
opts[:pid] = m.to_i
|
50
|
+
end
|
51
|
+
|
48
52
|
opt.on('-k', '--kill', "Kill currently running #{opt.program_name} process with SIGINT") do
|
49
53
|
IMAP_Notifier.kill_process
|
50
54
|
exit
|
@@ -52,10 +56,4 @@ opt_parser = OptionParser.new do |opt|
|
|
52
56
|
end
|
53
57
|
|
54
58
|
opt_parser.parse!
|
55
|
-
|
56
|
-
if File.exists?(PIDFILE) && IO.readlines(PIDFILE).any?
|
57
|
-
puts "#{PIDFILE} already exists -- Exiting..."
|
58
|
-
exit -1
|
59
|
-
end
|
60
|
-
|
61
59
|
IMAP_Notifier.new(opts)
|
data/lib/imap_notifier/base.rb
CHANGED
@@ -1,20 +1,40 @@
|
|
1
1
|
class IMAP_Notifier
|
2
2
|
def self.kill_process
|
3
|
-
|
3
|
+
matching_pids = Dir['/tmp/imap_notifier*.pid']
|
4
|
+
if matching_pids.length > 1
|
5
|
+
prompts = ["[Q] Cancel"]
|
6
|
+
matching_pids.each_with_index do |p_file, i|
|
7
|
+
prompts.push("[#{i}] #{p_file}")
|
8
|
+
end
|
9
|
+
pidIndex = ask("Select PID by number\n" + prompts.join("\n")) { |q|
|
10
|
+
q.validate = /^[0-#{matching_pids.length-1},q,Q]{1}$/
|
11
|
+
}
|
12
|
+
return if pidIndex.downcase == "q"
|
13
|
+
pidFile = Dir['/tmp/imap_notifier*.pid'][pidIndex.to_i]
|
14
|
+
else
|
15
|
+
pidFile = Dir['/tmp/imap_notifier*.pid'].first
|
16
|
+
end
|
17
|
+
pid = IO.readlines(pidFile).first.to_i
|
4
18
|
puts "Killing PID: #{pid}"
|
5
19
|
Process.kill("SIGINT", pid)
|
6
20
|
rescue Errno::ESRCH, Errno::ENOENT => e
|
7
21
|
puts "#{e.message} - Exiting..."
|
8
22
|
ensure
|
9
|
-
self.delete_pid
|
23
|
+
self.delete_pid(pidFile)
|
10
24
|
end
|
11
25
|
|
12
|
-
def self.delete_pid
|
13
|
-
File.delete(
|
26
|
+
def self.delete_pid(pidFile)
|
27
|
+
File.delete(pidFile) if File.exists?(pidFile)
|
14
28
|
end
|
15
29
|
|
16
30
|
def initialize(opts={})
|
17
31
|
config opts
|
32
|
+
|
33
|
+
if File.exists?(@custom_pid) && IO.readlines(@custom_pid).any?
|
34
|
+
puts "#{@custom_pid} already exists -- Exiting..."
|
35
|
+
exit @ignore_exit_code ? 0 : 1
|
36
|
+
end
|
37
|
+
|
18
38
|
@notifier = IMAP_Notifier::Alert.new
|
19
39
|
|
20
40
|
pid = fork do
|
@@ -22,7 +42,7 @@ class IMAP_Notifier
|
|
22
42
|
at_exit { self.stop }
|
23
43
|
run
|
24
44
|
end
|
25
|
-
File.open(
|
45
|
+
File.open(@custom_pid, 'w') { |f| f.write pid }
|
26
46
|
end
|
27
47
|
|
28
48
|
def run
|
data/lib/imap_notifier/config.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
class IMAP_Notifier
|
2
2
|
def config(opts={})
|
3
3
|
read_conf opts
|
4
|
-
@imap_server
|
5
|
-
@domain
|
6
|
-
@user
|
7
|
-
$key_name
|
8
|
-
$key_account
|
9
|
-
$pass
|
10
|
-
$one_path
|
11
|
-
$onepass
|
12
|
-
@password
|
13
|
-
@folders
|
14
|
-
@debug
|
15
|
-
@max_mail
|
4
|
+
@imap_server = opts[:server] || IMAP_SERVER
|
5
|
+
@domain = opts[:domain] || @imap_server.split('.').pop(2).join('.')
|
6
|
+
@user = "#{opts[:user]}@#{@domain}"
|
7
|
+
$key_name = opts[:key_name] || false
|
8
|
+
$key_account = opts[:key_account] || false
|
9
|
+
$pass = opts[:pass] || false
|
10
|
+
$one_path = opts[:one_path] || false
|
11
|
+
$onepass = opts[:onepass] || false
|
12
|
+
@password = opts[:password] || get_password
|
13
|
+
@folders = mbox_conf opts[:folders] || ['INBOX']
|
14
|
+
@debug = opts[:debug] || false
|
15
|
+
@max_mail = opts[:max] || MAX_MAIL
|
16
|
+
@ignore_exit_code = opts[:ignore_exit_code].to_s == 'true'
|
17
|
+
@custom_pid = opts[:pid] || PIDFILE
|
16
18
|
end
|
17
19
|
|
18
20
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imap_notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Campbell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|