Class: SMTPD

Inherits:
Object
  • Object
show all
Defined in:
lib/smtpserver.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sock, domain) ⇒ SMTPD

Returns a new instance of SMTPD.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/smtpserver.rb', line 37

def initialize(sock, domain)
  @sock = sock
  @domain = domain
  @error_interval = 5
  class << @sock
    include GetsSafe
  end
  @helo_hook = nil
  @mail_hook = nil
  @rcpt_hook = nil
  @data_hook = nil
  @data_each_line = nil
  @rset_hook = nil
  @noop_hook = nil
  @quit_hook = nil
end

Instance Attribute Details

#data_each_line=(value) ⇒ Object (writeonly)

Sets the attribute data_each_line

Parameters:

  • value

    the value to set the attribute data_each_line to.



53
54
55
# File 'lib/smtpserver.rb', line 53

def data_each_line=(value)
  @data_each_line = value
end

#data_hook=(value) ⇒ Object (writeonly)

Sets the attribute data_hook

Parameters:

  • value

    the value to set the attribute data_hook to.



53
54
55
# File 'lib/smtpserver.rb', line 53

def data_hook=(value)
  @data_hook = value
end

#error_intervalObject

Returns the value of attribute error_interval.



93
94
95
# File 'lib/smtpserver.rb', line 93

def error_interval
  @error_interval
end

#helo_hook=(value) ⇒ Object (writeonly)

Sets the attribute helo_hook

Parameters:

  • value

    the value to set the attribute helo_hook to.



53
54
55
# File 'lib/smtpserver.rb', line 53

def helo_hook=(value)
  @helo_hook = value
end

#input_timeoutObject

Returns the value of attribute input_timeout.



92
93
94
# File 'lib/smtpserver.rb', line 92

def input_timeout
  @input_timeout
end

#line_length_limitObject

Returns the value of attribute line_length_limit.



92
93
94
# File 'lib/smtpserver.rb', line 92

def line_length_limit
  @line_length_limit
end

#mail_hook=(value) ⇒ Object (writeonly)

Sets the attribute mail_hook

Parameters:

  • value

    the value to set the attribute mail_hook to.



53
54
55
# File 'lib/smtpserver.rb', line 53

def mail_hook=(value)
  @mail_hook = value
end

#max_sizeObject

Returns the value of attribute max_size.



94
95
96
# File 'lib/smtpserver.rb', line 94

def max_size
  @max_size
end

#noop_hook=(value) ⇒ Object (writeonly)

Sets the attribute noop_hook

Parameters:

  • value

    the value to set the attribute noop_hook to.



53
54
55
# File 'lib/smtpserver.rb', line 53

def noop_hook=(value)
  @noop_hook = value
end

#quit_hook=(value) ⇒ Object (writeonly)

Sets the attribute quit_hook

Parameters:

  • value

    the value to set the attribute quit_hook to.



53
54
55
# File 'lib/smtpserver.rb', line 53

def quit_hook=(value)
  @quit_hook = value
end

#rcpt_hook=(value) ⇒ Object (writeonly)

Sets the attribute rcpt_hook

Parameters:

  • value

    the value to set the attribute rcpt_hook to.



53
54
55
# File 'lib/smtpserver.rb', line 53

def rcpt_hook=(value)
  @rcpt_hook = value
end

#rset_hook=(value) ⇒ Object (writeonly)

Sets the attribute rset_hook

Parameters:

  • value

    the value to set the attribute rset_hook to.



53
54
55
# File 'lib/smtpserver.rb', line 53

def rset_hook=(value)
  @rset_hook = value
end

#use_fileObject

Returns the value of attribute use_file.



94
95
96
# File 'lib/smtpserver.rb', line 94

def use_file
  @use_file
end

Instance Method Details

#startObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/smtpserver.rb', line 56

def start
  @helo_name = nil
  @sender = nil
  @recipients = []
  catch(:close) do
    puts_safe "220 #{@domain} service ready"
    while comm = @sock.gets_safe do
catch :next_comm do
  comm.sub!(/\r?\n/, '')
  comm, arg = comm.split(/\s+/,2)
        break if comm == nil
  case comm.upcase
  when 'EHLO' then comm_helo arg
  when 'HELO' then comm_helo arg
  when 'MAIL' then comm_mail arg
  when 'RCPT' then comm_rcpt arg
  when 'DATA' then comm_data arg
  when 'RSET' then comm_rset arg
  when 'NOOP' then comm_noop arg
  when 'QUIT' then comm_quit arg
  else
    error '502 Error: command not implemented'
  end
end
    end
  end
end