Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 71 lines (62 sloc) 1.582 kb
509cfc3 @phlipper initial commit
authored
1 require 'pony'
2 require 'openssl'
3 require 'net/smtp'
4
5 Net::SMTP.class_eval do
6 private
7 def do_start(helodomain, user, secret, authtype)
8 raise IOError, 'SMTP session already started' if @started
9
10 if RUBY_VERSION == "1.8.7"
11 check_auth_args user, secret
12 else
13 check_auth_args user, secret, authtype if user or secret
14 end
15
16 sock = timeout(@open_timeout) { TCPSocket.open(@address, @port) }
17 @socket = Net::InternetMessageIO.new(sock)
18 @socket.read_timeout = 60 #@read_timeout
19
20 check_response(critical { recv_response() })
21 do_helo(helodomain)
22
23 if starttls
24 raise 'openssl library not installed' unless defined?(OpenSSL)
25 ssl = OpenSSL::SSL::SSLSocket.new(sock)
26 ssl.sync_close = true
27 ssl.connect
28 @socket = Net::InternetMessageIO.new(ssl)
29 @socket.read_timeout = 60 #@read_timeout
30 do_helo(helodomain)
31 end
32
33 authenticate user, secret, authtype if user
34 @started = true
35 ensure
36 unless @started
37 # authentication failed, cancel connection.
38 @socket.close if not @started and @socket and not @socket.closed?
39 @socket = nil
40 end
41 end
42
43 def do_helo(helodomain)
44 begin
45 if @esmtp
46 ehlo helodomain
47 else
48 helo helodomain
49 end
50 rescue Net::ProtocolError
51 if @esmtp
52 @esmtp = false
53 @error_occured = false
54 retry
55 end
56 raise
57 end
58 end
59
60 def starttls
61 getok('STARTTLS') rescue return false
62 return true
63 end
64
65 def quit
66 begin
67 getok('QUIT')
68 rescue EOFError
69 end
70 end
71 end
Something went wrong with that request. Please try again.