class Groat::SMTPD::Base

Public Class Methods

new() click to toggle source
# File lib/groat/smtpd/base.rb, line 51
def initialize
  @response_class = Response
  @instanceid = @@numinstances = @@numinstances + 1
  @s = nil
  @remote_address = nil
  @remote_port = nil
  reset_connection
end

Public Instance Methods

clientdata?() click to toggle source
# File lib/groat/smtpd/base.rb, line 154
def clientdata?
  IO.select([@s], nil, nil, 0.1)
end
fromclient() click to toggle source
# File lib/groat/smtpd/base.rb, line 127
def fromclient
  line = getline
  log_line(:in, line)
end
getdata(size) click to toggle source
# File lib/groat/smtpd/base.rb, line 123
def getdata(size)
  sockop_timeout(:read, size)
end
getline() click to toggle source
# File lib/groat/smtpd/base.rb, line 119
def getline
  sockop_timeout(:gets, "\n")
end
log_line(direction, line) click to toggle source
# 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) click to toggle source
# File lib/groat/smtpd/base.rb, line 75
def process_line(line)
end
reply(args) click to toggle source
# File lib/groat/smtpd/base.rb, line 60
def reply(args)
  raise @response_class, args
end
reset_connection() click to toggle source
# File lib/groat/smtpd/base.rb, line 84
def reset_connection
end
run(method, *args) { || ... } click to toggle source
# 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?() click to toggle source

Nothing in the base implements security

# File lib/groat/smtpd/base.rb, line 88
def secure?
  false
end
send_greeting() click to toggle source
# File lib/groat/smtpd/base.rb, line 78
def send_greeting
end
serve(io) click to toggle source
# 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() click to toggle source
# File lib/groat/smtpd/base.rb, line 81
def service_shutdown
end
set_socket(io) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/groat/smtpd/base.rb, line 149
def toclient(msg)
  log_line(:out, msg)
  @s.print(msg)
end