Skip to content
This repository
Browse code

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

…a failsafe wrapper around existing #tlsconnect rather than reimplementing.
  • Loading branch information...
commit 57a9165f17b543cc9dfdc1af2c3975bb86447499 1 parent e941c62
Jeremy Kemper authored January 27, 2013

Showing 1 changed file with 12 additions and 13 deletions. Show diff stats Hide diff stats

  1. 25  lib/mail/core_extensions/smtp.rb
25  lib/mail/core_extensions/smtp.rb
@@ -5,21 +5,20 @@ class SMTP
5 5
     # http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30294
6 6
     #
7 7
     # Fixed in what will be Ruby 1.9.3 - tlsconnect also does not exist in some early versions of ruby
8  
-    remove_method :tlsconnect if defined?(Net::SMTP.new.tlsconnect)
  8
+    begin
  9
+      alias_method :original_tlsconnect, :tlsconnect
9 10
 
10  
-    def tlsconnect(s)
11  
-      verified = false
12  
-      s = OpenSSL::SSL::SSLSocket.new s, @ssl_context
13  
-      logging "TLS connection started"
14  
-      s.sync_close = true
15  
-      s.connect
16  
-      if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
17  
-        s.post_connection_check(@address)
  11
+      def tlsconnect(s)
  12
+        verified = false
  13
+        begin
  14
+          original_tlsconnect(s).tap { verified = true }
  15
+        ensure
  16
+          unless verified
  17
+            s.close rescue nil
  18
+          end
  19
+        end
18 20
       end
19  
-      verified = true
20  
-      s
21  
-    ensure
22  
-      s.close unless verified
  21
+    rescue NameError
23 22
     end
24 23
   end
25 24
 end

0 notes on commit 57a9165

Please sign in to comment.
Something went wrong with that request. Please try again.