Permalink
Browse files

Shush warning about redefined Net::SMTP#tolsconnect. Implement it as …

…a failsafe wrapper around existing #tlsconnect rather than reimplementing.
  • Loading branch information...
jeremy committed Jan 28, 2013
1 parent e941c62 commit 57a9165f17b543cc9dfdc1af2c3975bb86447499
Showing with 12 additions and 13 deletions.
  1. +12 −13 lib/mail/core_extensions/smtp.rb
@@ -5,21 +5,20 @@ class SMTP
# http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30294
#
# Fixed in what will be Ruby 1.9.3 - tlsconnect also does not exist in some early versions of ruby
- remove_method :tlsconnect if defined?(Net::SMTP.new.tlsconnect)
+ begin
+ alias_method :original_tlsconnect, :tlsconnect
- def tlsconnect(s)
- verified = false
- s = OpenSSL::SSL::SSLSocket.new s, @ssl_context
- logging "TLS connection started"
- s.sync_close = true
- s.connect
- if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
- s.post_connection_check(@address)
+ def tlsconnect(s)
+ verified = false
+ begin
+ original_tlsconnect(s).tap { verified = true }
+ ensure
+ unless verified
+ s.close rescue nil
+ end
+ end
end
- verified = true
- s
- ensure
- s.close unless verified
+ rescue NameError
end
end
end

0 comments on commit 57a9165

Please sign in to comment.