Class: MailSmtp::Session

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

Overview

Per-connection state for one SMTP conversation: where the client is in the command sequence, who they authenticated as, and the envelope they are building. One Session lives for the life of a single connection and is handed to every hook on Server. Subclass via Server#build_session.

Message bytes are not stored here — during DATA the engine passes a live DataReader into Server#receive.

Defined Under Namespace

Classes: Envelope

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSession

Returns a new instance of Session.



27
28
29
30
31
32
33
34
35
36
# File 'lib/mailsmtp/session.rb', line 27

def initialize
  @exceptions = 0
  @auth_failures = 0
  @proxy = nil
  @close_after_reply = false
  @tls_version = nil
  @tls_cipher = nil
  reset
  @phase = :helo
end

Instance Attribute Details

#auth_failuresObject

Returns the value of attribute auth_failures.



19
20
21
# File 'lib/mailsmtp/session.rb', line 19

def auth_failures
  @auth_failures
end

#auth_login_usernameObject

Returns the value of attribute auth_login_username.



19
20
21
# File 'lib/mailsmtp/session.rb', line 19

def 
  @auth_login_username
end

#authenticated_atObject

Returns the value of attribute authenticated_at.



19
20
21
# File 'lib/mailsmtp/session.rb', line 19

def authenticated_at
  @authenticated_at
end

#authentication_idObject

Returns the value of attribute authentication_id.



19
20
21
# File 'lib/mailsmtp/session.rb', line 19

def authentication_id
  @authentication_id
end

#authorization_idObject

Returns the value of attribute authorization_id.



19
20
21
# File 'lib/mailsmtp/session.rb', line 19

def authorization_id
  @authorization_id
end

#close_after_replyObject

Returns the value of attribute close_after_reply.



19
20
21
# File 'lib/mailsmtp/session.rb', line 19

def close_after_reply
  @close_after_reply
end

#connected_atObject

Returns the value of attribute connected_at.



19
20
21
# File 'lib/mailsmtp/session.rb', line 19

def connected_at
  @connected_at
end

#encrypted_atObject

Returns the value of attribute encrypted_at.



19
20
21
# File 'lib/mailsmtp/session.rb', line 19

def encrypted_at
  @encrypted_at
end

#envelopeObject (readonly)

Returns the value of attribute envelope.



25
26
27
# File 'lib/mailsmtp/session.rb', line 25

def envelope
  @envelope
end

#exceptionsObject

Returns the value of attribute exceptions.



19
20
21
# File 'lib/mailsmtp/session.rb', line 19

def exceptions
  @exceptions
end

#heloObject

Returns the value of attribute helo.



19
20
21
# File 'lib/mailsmtp/session.rb', line 19

def helo
  @helo
end

#helo_responseObject

Returns the value of attribute helo_response.



19
20
21
# File 'lib/mailsmtp/session.rb', line 19

def helo_response
  @helo_response
end

#local_ipObject

Returns the value of attribute local_ip.



19
20
21
# File 'lib/mailsmtp/session.rb', line 19

def local_ip
  @local_ip
end

#local_responseObject

Returns the value of attribute local_response.



19
20
21
# File 'lib/mailsmtp/session.rb', line 19

def local_response
  @local_response
end

#phaseObject

Returns the value of attribute phase.



19
20
21
# File 'lib/mailsmtp/session.rb', line 19

def phase
  @phase
end

#proxyObject

Returns the value of attribute proxy.



19
20
21
# File 'lib/mailsmtp/session.rb', line 19

def proxy
  @proxy
end

#remote_ipObject

Returns the value of attribute remote_ip.



19
20
21
# File 'lib/mailsmtp/session.rb', line 19

def remote_ip
  @remote_ip
end

#tls_cipherObject

Returns the value of attribute tls_cipher.



19
20
21
# File 'lib/mailsmtp/session.rb', line 19

def tls_cipher
  @tls_cipher
end

#tls_versionObject

Returns the value of attribute tls_version.



19
20
21
# File 'lib/mailsmtp/session.rb', line 19

def tls_version
  @tls_version
end

Instance Method Details

#authenticated?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/mailsmtp/session.rb', line 55

def authenticated?
  !authenticated_at.nil?
end

#encrypted?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/mailsmtp/session.rb', line 59

def encrypted?
  !encrypted_at.nil?
end

#resetObject

Clear the per-message state — envelope and command sequence — while keeping the connection and its authentication. Used on RSET and at the end of each accepted message.



41
42
43
44
45
# File 'lib/mailsmtp/session.rb', line 41

def reset
  @phase = :ready
  @envelope = Envelope.new
  @auth_login_username = nil
end

#reset_authenticationObject

Drop identity asserted before STARTTLS (RFC 3207 §4.2).



48
49
50
51
52
53
# File 'lib/mailsmtp/session.rb', line 48

def reset_authentication
  @authenticated_at = nil
  @authorization_id = nil
  @authentication_id = nil
  @auth_login_username = nil
end