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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 070c8430cdeedbb65f412669840be00759a8423c
4
- data.tar.gz: c6cfb31a9864c96f626a45c3d166dd5913fc1a8a
3
+ metadata.gz: 9a958142e6525ef4f9ee75b68ec554eb9068c85e
4
+ data.tar.gz: ef1bc7d0d5b902c6e38b8ca009883cb057b63a80
5
5
  SHA512:
6
- metadata.gz: 34526617775c9a533ad70293f9fe230a04228708936c5003a05cff9706baa0dcde638acc2654abf3ff7291e248be148ff7e6c5905e630fcee21ac6905a63e812
7
- data.tar.gz: c12eece42e6109ada6e6197e621da2c528c4a98e5b118b2d0babd40a6c71ba899249285f58a0cf0441ab29b858ca7253f8ca208ebfa736a1f1f223b324c909d1
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)
@@ -1,20 +1,40 @@
1
1
  class IMAP_Notifier
2
2
  def self.kill_process
3
- pid = IO.readlines(PIDFILE).first.to_i
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(PIDFILE) if File.exists?(PIDFILE)
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(PIDFILE, 'w') { |f| f.write pid }
45
+ File.open(@custom_pid, 'w') { |f| f.write pid }
26
46
  end
27
47
 
28
48
  def run
@@ -1,18 +1,20 @@
1
1
  class IMAP_Notifier
2
2
  def config(opts={})
3
3
  read_conf opts
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
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
@@ -1,3 +1,3 @@
1
1
  class IMAP_Notifier
2
- VERSION='0.2.8'
2
+ VERSION='0.2.9'
3
3
  end
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.8
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-06-04 00:00:00.000000000 Z
11
+ date: 2015-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler