catfriend 0.12 → 0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/catfriend +28 -8
- data/catfriend.example +8 -5
- data/lib/catfriend/imap.rb +8 -6
- data/lib/catfriend/server.rb +7 -2
- metadata +4 -5
- data/lib/catfriend/notify.rb +0 -50
data/bin/catfriend
CHANGED
@@ -9,6 +9,7 @@
|
|
9
9
|
require 'catfriend/filetokenstack'
|
10
10
|
require 'catfriend/imap'
|
11
11
|
require 'net/imap'
|
12
|
+
require 'optparse'
|
12
13
|
|
13
14
|
module Catfriend
|
14
15
|
|
@@ -77,14 +78,16 @@ def self.parse_config
|
|
77
78
|
current[field] = shift_tokens.call
|
78
79
|
when "nossl"
|
79
80
|
current[:no_ssl] = true
|
81
|
+
when "work"
|
82
|
+
current[:work_account] = true
|
80
83
|
else
|
81
84
|
raise ConfigError,
|
82
|
-
"invalid config parameter '#{field}'
|
85
|
+
"invalid config parameter '#{field}'"
|
83
86
|
end
|
84
87
|
end
|
85
88
|
|
86
89
|
servers << ImapServer.new(current) unless current.empty?
|
87
|
-
|
90
|
+
Catfriend.notification_timeout = (defaults["notification_timeout"] or 60).to_i
|
88
91
|
|
89
92
|
servers
|
90
93
|
end
|
@@ -92,24 +95,41 @@ end
|
|
92
95
|
# Main interface to the application. Reads all servers from config then runs
|
93
96
|
# each one in a thread. The program exits when all threads encounter an
|
94
97
|
# unrecoverable error. Perhaps I should make it exit if any thread exits.
|
95
|
-
def self.main
|
98
|
+
def self.main args
|
99
|
+
work_accounts = false
|
100
|
+
Catfriend.verbose = false
|
96
101
|
begin
|
102
|
+
OptionParser.new do |opts|
|
103
|
+
opts.banner = "usage: #{APP_NAME} [options]"
|
104
|
+
|
105
|
+
opts.on("-w", "--work", "enable work accounts") do
|
106
|
+
work_accounts = true
|
107
|
+
end
|
108
|
+
opts.on("-v", "--verbose", "verbose output to console") do
|
109
|
+
Catfriend.verbose = true
|
110
|
+
end
|
111
|
+
end.parse!
|
112
|
+
|
97
113
|
servers = parse_config
|
98
|
-
|
99
|
-
|
100
|
-
end
|
114
|
+
servers.reject! { |s| s.work_account } unless work_accounts
|
115
|
+
raise ConfigError, "no servers to check" if servers.empty?
|
101
116
|
|
102
|
-
begin
|
103
117
|
# todo: daemonize here unless certain command line argument given
|
104
118
|
servers.each { |s| s.start }
|
105
119
|
servers.each { |s| s.join }
|
120
|
+
rescue ConfigError => e
|
121
|
+
puts "misconfiguration: #{e.message}"
|
106
122
|
rescue Interrupt
|
107
123
|
servers.each { |s| s.kill }
|
108
124
|
rescue => e
|
109
125
|
puts "unknown error #{e.message}\n#{e.backtrace.join("\n")}"
|
126
|
+
else
|
127
|
+
return 0
|
110
128
|
end
|
129
|
+
|
130
|
+
1
|
111
131
|
end
|
112
132
|
|
113
133
|
end ########################### end module
|
114
134
|
|
115
|
-
Catfriend.main
|
135
|
+
exit Catfriend.main ARGV
|
data/catfriend.example
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
-
|
2
|
-
user bossman@work.com
|
3
|
-
password secure
|
4
|
-
nossl # turn off ssl, it is on by default
|
1
|
+
# copy to ~/.config/catfriend
|
5
2
|
|
6
3
|
host imap.gmail.com
|
7
4
|
id fun # used instead of host in nofifications when available
|
8
5
|
user friend@gmail.com
|
9
6
|
password faptap
|
10
|
-
cert_file server.pem # path relative to config file
|
7
|
+
cert_file server.pem # path relative to config file i.e. ~/.config
|
8
|
+
|
9
|
+
host insecure.work.com
|
10
|
+
user bossman@work.com
|
11
|
+
password insecure
|
12
|
+
nossl # turn off ssl, it is on by default
|
13
|
+
work # mark as work account, -w command-line argument enables it
|
11
14
|
|
12
15
|
# time notification remains on screen in milliseconds
|
13
16
|
notificationTimeout 10000
|
data/lib/catfriend/imap.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
+
require 'libnotify'
|
1
2
|
require 'catfriend/server'
|
2
|
-
require 'catfriend/notify'
|
3
3
|
require 'catfriend/thread'
|
4
4
|
|
5
5
|
module Catfriend
|
@@ -72,7 +72,7 @@ class ImapServer
|
|
72
72
|
# on an unrecoverable error.
|
73
73
|
def check_loop
|
74
74
|
@imap.idle do |r|
|
75
|
-
|
75
|
+
Catfriend.whisper "#{id}: #{r}"
|
76
76
|
next if r.instance_of? Net::IMAP::ContinuationRequest
|
77
77
|
|
78
78
|
if r.instance_of? Net::IMAP::UntaggedResponse
|
@@ -90,7 +90,7 @@ class ImapServer
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
|
93
|
+
Catfriend.whisper "idle loop over"
|
94
94
|
rescue Net::IMAP::Error, IOError
|
95
95
|
# reconnect and carry on
|
96
96
|
reconnect unless stopped?
|
@@ -103,8 +103,8 @@ class ImapServer
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def notify_message message
|
106
|
-
@notification.update
|
107
|
-
|
106
|
+
@notification.update :summary => "#{id}: #{message}"
|
107
|
+
Catfriend.whisper @notification.summary
|
108
108
|
end
|
109
109
|
|
110
110
|
def kill
|
@@ -130,7 +130,7 @@ class ImapServer
|
|
130
130
|
|
131
131
|
def reconnect
|
132
132
|
# todo: log an error unless this completes within a short time
|
133
|
-
|
133
|
+
Catfriend.whisper "#{id}: reconnecting"
|
134
134
|
new_count = connect
|
135
135
|
notify_message(new_count) if new_count != @message_count
|
136
136
|
@message_count = new_count
|
@@ -140,7 +140,9 @@ class ImapServer
|
|
140
140
|
|
141
141
|
private :connect, :disconnect, :reconnect,
|
142
142
|
:check_loop, :run, :error, :notify_message
|
143
|
+
|
143
144
|
attr_writer :host, :password, :id, :user, :no_ssl, :cert_file, :mailbox
|
145
|
+
attr_accessor :work_account
|
144
146
|
end
|
145
147
|
|
146
148
|
end # end module
|
data/lib/catfriend/server.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
module Catfriend
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
class << self
|
4
|
+
attr_accessor :notification_timeout, :verbose
|
5
|
+
|
6
|
+
# puts something if -v was used
|
7
|
+
def whisper *args
|
8
|
+
puts *args if verbose
|
9
|
+
end
|
5
10
|
end
|
6
11
|
|
7
12
|
# Mixin to provide #configure which allows all instance variables with write
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: catfriend
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.13'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,15 +13,15 @@ date: 2012-01-02 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: libnotify
|
16
|
-
requirement: &
|
16
|
+
requirement: &9300880 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '0.
|
21
|
+
version: '0.7'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *9300880
|
25
25
|
description: E-mail checker with libnotify desktop notifications.
|
26
26
|
email:
|
27
27
|
- catfriend@chilon.net
|
@@ -33,7 +33,6 @@ files:
|
|
33
33
|
- LICENSE
|
34
34
|
- catfriend.example
|
35
35
|
- lib/catfriend/server.rb
|
36
|
-
- lib/catfriend/notify.rb
|
37
36
|
- lib/catfriend/filetokenstack.rb
|
38
37
|
- lib/catfriend/thread.rb
|
39
38
|
- lib/catfriend/imap.rb
|
data/lib/catfriend/notify.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'libnotify'
|
2
|
-
|
3
|
-
# Patch libnotify to add notification updating support. I have pushed
|
4
|
-
# this patch to the libnotify project and it should drop with 0.7
|
5
|
-
module Libnotify
|
6
|
-
# Re-open to import notification update.
|
7
|
-
module FFI
|
8
|
-
class << self
|
9
|
-
alias_method :orig_attach_functions!, :attach_functions!
|
10
|
-
end
|
11
|
-
def self.attach_functions!
|
12
|
-
attach_function :notify_notification_update,
|
13
|
-
[:pointer, :string, :string, :string, :pointer],
|
14
|
-
:pointer
|
15
|
-
orig_attach_functions!
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# Re-open and add update method.
|
20
|
-
class API
|
21
|
-
# Rewrite show to store notification in an instance variable.
|
22
|
-
def show!
|
23
|
-
notify_init(self.class.to_s) or raise "notify_init failed"
|
24
|
-
@notification = notify_notification_new(summary, body, icon_path, nil)
|
25
|
-
notify_notification_set_urgency(@notification, lookup_urgency(urgency))
|
26
|
-
notify_notification_set_timeout(@notification, timeout || -1)
|
27
|
-
if append
|
28
|
-
notify_notification_set_hint_string(@notification, "x-canonical-append", "")
|
29
|
-
notify_notification_set_hint_string(@notification, "append", "")
|
30
|
-
end
|
31
|
-
if transient
|
32
|
-
notify_notification_set_hint_uint32(@notification, "transient", 1)
|
33
|
-
end
|
34
|
-
notify_notification_show(@notification, nil)
|
35
|
-
ensure
|
36
|
-
notify_notification_clear_hints(@notification) if (append || transient)
|
37
|
-
end
|
38
|
-
|
39
|
-
# Updates a previously shown notification.
|
40
|
-
def update(&block)
|
41
|
-
yield(self) if block_given?
|
42
|
-
if @notification
|
43
|
-
notify_notification_update(@notification, summary, body, icon_path, nil)
|
44
|
-
notify_notification_show(@notification, nil)
|
45
|
-
else
|
46
|
-
show!
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|