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

Commit

Permalink
- Removed dependency on SystemTimer gem for rubies > 1.8.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Amol Hatwár committed May 24, 2010
1 parent 6e06345 commit da06f80
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions lib/fetcher/imap.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'system_timer' (RUBY_VERSION < '1.9.0') ? require('system_timer') : require('timeout')
require File.dirname(__FILE__) + '/../vendor/plain_imap' require File.dirname(__FILE__) + '/../vendor/plain_imap'


module Fetcher module Fetcher
Expand Down Expand Up @@ -27,17 +27,33 @@ def initialize(options={})


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

(RUBY_VERSION < '1.9.0') ? eval(meth18) : eval(meth19)
end end


# Retrieve messages from server # Retrieve messages from server
Expand Down

0 comments on commit da06f80

Please sign in to comment.