geekmail 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/geekmail.gemspec +1 -1
  3. data/lib/geekmail.rb +25 -23
  4. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/geekmail.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{geekmail}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Sebastian Probst Eide"]
data/lib/geekmail.rb CHANGED
@@ -17,32 +17,34 @@ class Geekmail
17
17
 
18
18
  private
19
19
  def self.check_mail(config)
20
- begin
21
- # make a connection to imap account
22
- imap = Net::IMAP.new(config["host"], config["port"], true)
23
- imap.login(config["username"], config["password"])
24
- # select inbox as our mailbox to process
25
- imap.examine('Inbox')
20
+ tries = 5
21
+ while (tries > 0) do
22
+
23
+ begin
24
+ # make a connection to imap account
25
+ imap = Net::IMAP.new(config["host"], config["port"], true)
26
+ imap.login(config["username"], config["password"])
27
+ # select inbox as our mailbox to process
28
+ imap.examine('Inbox')
29
+
30
+ number_of_message = 0
31
+ # count number of emails
32
+ imap.uid_search(["NOT", "DELETED"]).each do |uid|
33
+ number_of_message += 1
34
+ end
26
35
 
27
- number_of_message = 0
28
- # count number of emails
29
- imap.uid_search(["NOT", "DELETED"]).each do |uid|
30
- number_of_message += 1
31
- end
36
+ # Log out
37
+ imap.logout
38
+ imap.disconnect
32
39
 
33
- # Log out
34
- imap.logout
35
- imap.disconnect
36
-
37
- number_of_message
40
+ return number_of_message
38
41
 
39
- # NoResponseError and ByResponseError happen often when imap'ing
40
- rescue Net::IMAP::NoResponseError => e
41
- "NoResponseError #{e}"
42
- rescue Net::IMAP::ByeResponseError => e
43
- "ByeResponseError #{e}"
44
- rescue => e
45
- "Unfortunate error..."
42
+ # NoResponseError and ByResponseError happen often when imap'ing
43
+ rescue => e
44
+ tries -= 1
45
+ sleep(1)
46
+ "Failed to get mail count" if (tries == 0)
47
+ end
46
48
  end
47
49
  end
48
50
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geekmail
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sebastian Probst Eide