Class: PostPolicy::Protocol

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

Constant Summary collapse

PROTOCOLS =
%w(ESMTP SMTP)
STATES =
%w(CONNECT EHLO HELO MAIL RCPT DATA END-OF-MESSAGE VRFY ETRN)
TERMINATOR =
"\n\n"
@@required_request_attributes =

Postfix 2.1 and later

[:request, :protocol_state, :protocol_name, :helo_name, :queue_id, :sender, :recipient, :recipient_count, :client_address, :client_name, :reverse_client_name, :instance].to_set
@@request_attributes =
@@required_request_attributes + 
[:sasl_method, :sasl_username, :sasl_sender, :size, :ccert_subject, :ccert_issuer, :ccert_fingerprint, # Postifx 2.2 and later
:encryption_protocol, :encryption_cipher, :encryption_keysize, :etrn_domain, # Postifx 2.3 and later
:stress].to_set

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProtocol

Returns a new instance of Protocol.



20
21
22
23
24
# File 'lib/postpolicy/protocol.rb', line 20

def initialize
  @attributes = {}
  $stdout.sync = true
  @buffer = []
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



11
12
13
# File 'lib/postpolicy/protocol.rb', line 11

def attributes
  @attributes
end

Instance Method Details

#receive_line(line) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/postpolicy/protocol.rb', line 32

def receive_line( line )
  unless line.empty?
    @buffer << line
  else
    Logger.info @buffer.inspect if VERBOSE
    parse_request
    @buffer.clear
  end
end

#response(action) ⇒ Object



42
43
44
# File 'lib/postpolicy/protocol.rb', line 42

def response( action )
  puts "action=#{action}#{TERMINATOR}" unless POST_POLICY_ENV == 'test'
end

#start!Object



26
27
28
29
30
# File 'lib/postpolicy/protocol.rb', line 26

def start!
  while line = gets do
    receive_line( line.chomp )
  end
end