Class: SMTP::Session
- Inherits:
-
Object
- Object
- SMTP::Session
- Includes:
- Commands::Definitions
- Defined in:
- lib/drillmail/smtp.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#forward_path ⇒ Object
Returns the value of attribute forward_path.
-
#host ⇒ Object
Returns the value of attribute host.
-
#message ⇒ Object
Returns the value of attribute message.
-
#reverse_path ⇒ Object
Returns the value of attribute reverse_path.
Instance Method Summary collapse
-
#initialize(connection, host) ⇒ Session
constructor
A new instance of Session.
- #process(request_string) ⇒ Object
- #route(request) ⇒ Object
- #run ⇒ Object
- #setup_session ⇒ Object
Methods included from Commands::Definitions
Constructor Details
#initialize(connection, host) ⇒ Session
Returns a new instance of Session.
35 36 37 38 39 40 41 |
# File 'lib/drillmail/smtp.rb', line 35 def initialize(connection, host) @connection = connection @host = host @active = true @domain = nil setup_session end |
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active.
29 30 31 |
# File 'lib/drillmail/smtp.rb', line 29 def active @active end |
#connection ⇒ Object
Returns the value of attribute connection.
27 28 29 |
# File 'lib/drillmail/smtp.rb', line 27 def connection @connection end |
#domain ⇒ Object
Returns the value of attribute domain.
30 31 32 |
# File 'lib/drillmail/smtp.rb', line 30 def domain @domain end |
#forward_path ⇒ Object
Returns the value of attribute forward_path.
32 33 34 |
# File 'lib/drillmail/smtp.rb', line 32 def forward_path @forward_path end |
#host ⇒ Object
Returns the value of attribute host.
28 29 30 |
# File 'lib/drillmail/smtp.rb', line 28 def host @host end |
#message ⇒ Object
Returns the value of attribute message.
33 34 35 |
# File 'lib/drillmail/smtp.rb', line 33 def @message end |
#reverse_path ⇒ Object
Returns the value of attribute reverse_path.
31 32 33 |
# File 'lib/drillmail/smtp.rb', line 31 def reverse_path @reverse_path end |
Instance Method Details
#process(request_string) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/drillmail/smtp.rb', line 68 def process(request_string) if request_string request_array = request_string.split(' ') { command: request_array.shift.to_sym, body: request_array.join(' ') } else { command: :NOOP, body: '' } end end |
#route(request) ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/drillmail/smtp.rb', line 80 def route(request) puts "Requesting: #{request[:command]} #{request[:body]}" if commands.key?(request[:command]) response = commands[request[:command]].call(request[:body]) else response = reply(500) end puts "Responding: #{response}" response end |
#run ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/drillmail/smtp.rb', line 49 def run begin @connection.puts reply(220, "#{@host} Simple Mail Transfer") while @active @connection.sync = true request = @connection.gets response = route(process(request)) @connection.puts "#{response}\r\n" end rescue => e @connection.puts reply(421, e) puts e, e.backtrace ensure @connection.shutdown(:RDWR) @connection.close end end |
#setup_session ⇒ Object
43 44 45 46 47 |
# File 'lib/drillmail/smtp.rb', line 43 def setup_session @reverse_path = '' @forward_path = '' @message = [] end |