catfriend 0.10 → 0.11

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.
Files changed (2) hide show
  1. data/lib/catfriend/imap.rb +24 -11
  2. metadata +3 -3
@@ -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
- check_loop
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 and r.name == 'EXISTS'
78
- notify_n_messages r.data
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 notify_n_messages n_messages
84
- @notification.update do |n|
85
- n.summary = "#{id}: #{n_messages}"
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, :notify_n_messages
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.10'
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: &14394100 !ruby/object:Gem::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: *14394100
24
+ version_requirements: *10589720
25
25
  description: E-mail checker with libnotify desktop notifications.
26
26
  email:
27
27
  - catfriend@chilon.net