catfriend 0.10 → 0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/catfriend/imap.rb +24 -11
- metadata +3 -3
data/lib/catfriend/imap.rb
CHANGED
@@ -60,7 +60,10 @@ class ImapServer
|
|
60
60
|
rescue Net::IMAP::NoResponseError
|
61
61
|
error "no response to connect, try ssl"
|
62
62
|
else
|
63
|
-
|
63
|
+
@message_count = @imap.fetch('*', 'UID').first.seqno
|
64
|
+
notify_message @message_count
|
65
|
+
|
66
|
+
loop { check_loop }
|
64
67
|
end
|
65
68
|
end
|
66
69
|
|
@@ -68,22 +71,32 @@ class ImapServer
|
|
68
71
|
# e-mail arrives or when error conditions happen. This methods only exits
|
69
72
|
# on an unrecoverable error.
|
70
73
|
def check_loop
|
71
|
-
req = @imap.fetch('*', 'UID').first
|
72
|
-
notify_n_messages req.seqno
|
73
|
-
|
74
74
|
@imap.idle do |r|
|
75
75
|
next if r.instance_of? Net::IMAP::ContinuationRequest
|
76
76
|
|
77
|
-
if r.instance_of? Net::IMAP::UntaggedResponse
|
78
|
-
|
77
|
+
if r.instance_of? Net::IMAP::UntaggedResponse
|
78
|
+
if r.name == 'EXISTS'
|
79
|
+
# some servers send this even when the message count
|
80
|
+
# hasn't increased so suspiciously double-check
|
81
|
+
if r.data > @message_count
|
82
|
+
@message_count = r.data
|
83
|
+
notify_message @message_count
|
84
|
+
end
|
85
|
+
elsif r.name == 'EXPUNGE'
|
86
|
+
@message_count -= 1
|
87
|
+
end
|
79
88
|
end
|
80
89
|
end
|
90
|
+
|
91
|
+
notify_message "error - server cancelled idle"
|
92
|
+
rescue => e
|
93
|
+
# todo: see if we have to re-open socket
|
94
|
+
notify_message "error - #{e.message}"
|
81
95
|
end
|
82
96
|
|
83
|
-
def
|
84
|
-
@notification.update
|
85
|
-
|
86
|
-
end
|
97
|
+
def notify_message message
|
98
|
+
@notification.update { |n| n.summary = "#{id}: #{message}" }
|
99
|
+
# puts @notification.summary # debug code
|
87
100
|
end
|
88
101
|
|
89
102
|
def kill
|
@@ -108,7 +121,7 @@ class ImapServer
|
|
108
121
|
|
109
122
|
def disconnect ; @imap.disconnect ; end
|
110
123
|
|
111
|
-
private :connect, :disconnect, :check_loop, :run, :error, :
|
124
|
+
private :connect, :disconnect, :check_loop, :run, :error, :notify_message
|
112
125
|
attr_writer :host, :password, :id, :user, :no_ssl, :cert_file, :mailbox
|
113
126
|
end
|
114
127
|
|
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.11'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-01-01 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: libnotify
|
16
|
-
requirement: &
|
16
|
+
requirement: &10589720 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0.6'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *10589720
|
25
25
|
description: E-mail checker with libnotify desktop notifications.
|
26
26
|
email:
|
27
27
|
- catfriend@chilon.net
|