Permalink
Browse files

- Fixed README.rdoc and cleaned up establish_connection()

  • Loading branch information...
1 parent da06f80 commit 30e7f5681c27cfdae7c2812888d1a580ba0add6e Amol Hatwár committed May 24, 2010
Showing with 12 additions and 28 deletions.
  1. +3 −2 README.rdoc
  2. +9 −26 lib/fetcher/imap.rb
View
@@ -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
View
@@ -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

0 comments on commit 30e7f56

Please sign in to comment.