123456789_123456789_123456789_123456789_123456789_

Class: Net::IMAP::SASL::ClientAdapter

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: lib/net/imap/sasl/client_adapter.rb

Overview

This API is experimental, and may change.

TODO: use with more clients, to verify the API can accommodate them.

An abstract base class for implementing a ::Net::IMAP::SASL authentication exchange. Different clients will each have their own adapter subclass, overridden to match their needs.

Although the default implementations may be sufficient, subclasses will probably need to override some methods. Additionally, subclasses may need to include a protocol adapter mixin, if the default ProtocolAdapters::Generic isn’t sufficient.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

ProtocolAdapters::Generic - Included

Constructor Details

.new(client, &command_proc) ⇒ ClientAdapter

#command_proc can used to avoid exposing private methods on #client. It should run a command with the arguments sent to it, yield each continuation payload, respond to the server with the result of each yield, and return the result. Non-successful results MUST raise an exception. Exceptions in the block MUST cause the command to fail.

Subclasses that override #run_command may use #command_proc for other purposes.

[ GitHub ]

  
# File 'lib/net/imap/sasl/client_adapter.rb', line 32

def initialize(client, &command_proc)
  @client, @command_proc = client, command_proc
end

Instance Attribute Details

#client (readonly)

[ GitHub ]

  
# File 'lib/net/imap/sasl/client_adapter.rb', line 22

attr_reader :client, :command_proc

#command_proc (readonly)

[ GitHub ]

  
# File 'lib/net/imap/sasl/client_adapter.rb', line 22

attr_reader :client, :command_proc

#sasl_ir_capable?Boolean (readonly)

Do the protocol and server both support an initial response?

[ GitHub ]

  
# File 'lib/net/imap/sasl/client_adapter.rb', line 40

def sasl_ir_capable?; client.sasl_ir_capable? end

Instance Method Details

#auth_capable?(mechanism) ⇒ Boolean

Does the server advertise support for the mechanism?

[ GitHub ]

  
# File 'lib/net/imap/sasl/client_adapter.rb', line 43

def auth_capable?(mechanism); client.auth_capable?(mechanism) end

#authenticate

[ GitHub ]

  
# File 'lib/net/imap/sasl/client_adapter.rb', line 37

def authenticate(...) AuthenticationExchange.authenticate(self, ...) end

#drop_connection

Drop the connection gracefully.

[ GitHub ]

  
# File 'lib/net/imap/sasl/client_adapter.rb', line 65

def drop_connection;  client.drop_connection end

#drop_connection!

Drop the connection abruptly.

[ GitHub ]

  
# File 'lib/net/imap/sasl/client_adapter.rb', line 68

def drop_connection!; client.drop_connection! end

#response_errors

Returns an array of server responses errors raised by run_command. Exceptions in this array won’t drop the connection.

[ GitHub ]

  
# File 'lib/net/imap/sasl/client_adapter.rb', line 62

def response_errors; [] end

#run_command(mechanism, initial_response = nil, &block)

Runs the authenticate command with mechanism and initial_response. When initial_response is nil, an initial response must NOT be sent.

Yields each continuation payload, responds to the server with the result of each yield, and returns the result. Non-successful results MUST raise an exception. Exceptions in the block MUST cause the command to fail.

Subclasses that override this may use #command_proc differently.

[ GitHub ]

  
# File 'lib/net/imap/sasl/client_adapter.rb', line 54

def run_command(mechanism, initial_response = nil, &block)
  command_proc or raise Error, "initialize with block or override"
  args = [command_name, mechanism, initial_response].compact
  command_proc.call(*args, &block)
end