Guest User

Untitled

a guest
Jun 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. require "openssl"
  2. require "net/smtp"
  3.  
  4. Net::SMTP.class_eval do
  5. private
  6. def do_start(helodomain, user, secret, authtype)
  7. raise IOError, 'SMTP session already started' if @started
  8. if user or secret
  9. begin
  10. check_auth_args user, secret, authtype
  11. rescue ArgumentError => e
  12. if e.message =~ /wrong number of arguments \(3 for 2\)/
  13. #ruby 1.8.7 fix
  14. check_auth_args user, secret
  15. else
  16. raise e
  17. end
  18. end
  19.  
  20. end
  21.  
  22. sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
  23. @socket = Net::InternetMessageIO.new(sock)
  24. @socket.read_timeout = 60 #@read_timeout
  25.  
  26. check_response(critical { recv_response() })
  27. do_helo(helodomain)
  28.  
  29. if starttls
  30. raise 'openssl library not installed' unless defined?(OpenSSL)
  31. ssl = OpenSSL::SSL::SSLSocket.new(sock)
  32. ssl.sync_close = true
  33. ssl.connect
  34. @socket = Net::InternetMessageIO.new(ssl)
  35. @socket.read_timeout = 60 #@read_timeout
  36. do_helo(helodomain)
  37. end
  38.  
  39. authenticate user, secret, authtype if user
  40. @started = true
  41. ensure
  42. unless @started
  43. # authentication failed, cancel connection.
  44. @socket.close if not @started and @socket and not @socket.closed?
  45. @socket = nil
  46. end
  47. end
  48.  
  49. def do_helo(helodomain)
  50. begin
  51. if @esmtp
  52. ehlo helodomain
  53. else
  54. helo helodomain
  55. end
  56. rescue Net::ProtocolError
  57. if @esmtp
  58. @esmtp = false
  59. @error_occured = false
  60. retry
  61. end
  62. raise
  63. end
  64. end
  65.  
  66. def starttls
  67. getok('STARTTLS') rescue return false
  68. return true
  69. end
  70.  
  71. def quit
  72. begin
  73. getok('QUIT')
  74. rescue EOFError
  75. end
  76. end
  77. end
Add Comment
Please, Sign In to add comment