Skip to content
This repository has been archived by the owner on Dec 2, 2017. It is now read-only.

Commit

Permalink
- Fixed README.rdoc and cleaned up establish_connection()
Browse files Browse the repository at this point in the history
  • Loading branch information
Amol Hatwár committed May 24, 2010
1 parent da06f80 commit 30e7f56
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
5 changes: 3 additions & 2 deletions README.rdoc
Expand Up @@ -15,8 +15,9 @@ Install using:

== Dependencies

This plugin depends on the SystemTimer gem. Do not forget to add it to your Gemfile. After adding,
remember to do a "bundle install"
If you are using a 1.8 series Ruby, this plugin depends on the SystemTimer gem to work reliably.
Do not forget to add it to your Gemfile or environment.rb. As Ruby 1.9 onwards use native threads
SystemTimer gem becomes redundant, and timeout.rb is used instead.

== Usage

Expand Down
35 changes: 9 additions & 26 deletions lib/fetcher/imap.rb
Expand Up @@ -27,33 +27,16 @@ def initialize(options={})

# Open connection and login to server
def establish_connection
meth18 = <<-eos
# Work around a freezing bug in Ruby's IMAP implementation using the SystemTimer library.
# It will have a SIGALRM sent to the process if this block doesn't exit in 15 seconds.
# Ruby 1.8 timeouts are unreliable if a system call is invoked.
SystemTimer.timeout_after(15.seconds) do
@connection = Net::IMAP.new(@server, @port, @ssl)
if @use_login
@connection.login(@username, @password)
else
@connection.authenticate(@authentication, @username, @password)
end
end
eos

meth19 = <<-eos
# Use the normal native threading goodness that Ruby 1.9 onwards provide for timeouts.
Timeout::timeout(15) do
@connection = Net::IMAP.new(@server, @port, @ssl)
if @use_login
@connection.login(@username, @password)
else
@connection.authenticate(@authentication, @username, @password)
end
end
eos
timeout_call = (RUBY_VERSION < '1.9.0') ? "SystemTimer.timeout_after(15.seconds) do" : "Timeout::timeout(15) do"

(RUBY_VERSION < '1.9.0') ? eval(meth18) : eval(meth19)
eval("#{timeout_call}
@connection = Net::IMAP.new(@server, @port, @ssl)
if @use_login
@connection.login(@username, @password)
else
@connection.authenticate(@authentication, @username, @password)
end
end")
end

# Retrieve messages from server
Expand Down

0 comments on commit 30e7f56

Please sign in to comment.