Class: Groat::SMTPD::Base
- Inherits:
-
Object
- Object
- Groat::SMTPD::Base
- Includes:
- Hooks
- Defined in:
- lib/groat/smtpd/base.rb
Direct Known Subclasses
Constant Summary collapse
- @@numinstances =
0
Instance Method Summary collapse
- #clientdata? ⇒ Boolean
- #fromclient ⇒ Object
- #getdata(size) ⇒ Object
- #getline ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #log_line(direction, line) ⇒ Object
- #process_line(line) ⇒ Object
- #reply(args) ⇒ Object
- #reset_connection ⇒ Object
- #run(method, *args, &block) ⇒ Object
-
#secure? ⇒ Boolean
Nothing in the base implements security.
- #send_greeting ⇒ Object
- #serve(io) ⇒ Object
- #service_shutdown ⇒ Object
- #set_socket(io) ⇒ Object
- #sockop_timeout(method, arg, wait = 30) ⇒ Object
- #toclient(msg) ⇒ Object
Constructor Details
Instance Method Details
#clientdata? ⇒ Boolean
154 155 156 |
# File 'lib/groat/smtpd/base.rb', line 154 def clientdata? IO.select([@s], nil, nil, 0.1) end |
#fromclient ⇒ Object
127 128 129 130 |
# File 'lib/groat/smtpd/base.rb', line 127 def fromclient line = getline log_line(:in, line) end |
#getdata(size) ⇒ Object
123 124 125 |
# File 'lib/groat/smtpd/base.rb', line 123 def getdata(size) sockop_timeout(:read, size) end |
#getline ⇒ Object
119 120 121 |
# File 'lib/groat/smtpd/base.rb', line 119 def getline sockop_timeout(:gets, "\n") end |
#log_line(direction, line) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/groat/smtpd/base.rb', line 132 def log_line(direction, line) if direction == :in if line.nil? puts "#{@instanceid}>/nil" else puts "#{@instanceid}>>" + line end else if line.nil? puts "#{@instanceid}</nil" else puts "#{@instanceid}<<" + line end end line end |
#process_line(line) ⇒ Object
75 76 |
# File 'lib/groat/smtpd/base.rb', line 75 def process_line(line) end |
#reply(args) ⇒ Object
60 61 62 |
# File 'lib/groat/smtpd/base.rb', line 60 def reply(args) raise @response_class, args end |
#reset_connection ⇒ Object
84 85 |
# File 'lib/groat/smtpd/base.rb', line 84 def reset_connection end |
#run(method, *args, &block) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/groat/smtpd/base.rb', line 64 def run(method, *args, &block) if block_given? yield else send method, *args end rescue Response => r toclient r.reply_text not r.terminate? end |
#secure? ⇒ Boolean
Nothing in the base implements security
88 89 90 |
# File 'lib/groat/smtpd/base.rb', line 88 def secure? false end |
#send_greeting ⇒ Object
78 79 |
# File 'lib/groat/smtpd/base.rb', line 78 def send_greeting end |
#serve(io) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/groat/smtpd/base.rb', line 97 def serve(io) set_socket io reset_connection run :send_greeting continue = true while continue do line = fromclient break if line.nil? continue = process_line line end rescue TimeoutError run :service_shutdown end |
#service_shutdown ⇒ Object
81 82 |
# File 'lib/groat/smtpd/base.rb', line 81 def service_shutdown end |
#set_socket(io) ⇒ Object
92 93 94 95 |
# File 'lib/groat/smtpd/base.rb', line 92 def set_socket(io) @s = io x, @remote_port, x, @remote_address = io.peeraddr end |
#sockop_timeout(method, arg, wait = 30) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/groat/smtpd/base.rb', line 111 def sockop_timeout(method, arg, wait = 30) begin timeout(wait){ return @s.__send__(method, arg) } end end |
#toclient(msg) ⇒ Object
149 150 151 152 |
# File 'lib/groat/smtpd/base.rb', line 149 def toclient(msg) log_line(:out, msg) @s.print(msg) end |