Class: Imap::Backup::Account::Connection::ClientFactory

Inherits:
Object
  • Object
show all
Includes:
RetryOnError
Defined in:
lib/imap/backup/account/connection/client_factory.rb

Constant Summary collapse

LOGIN_RETRY_CLASSES =
[EOFError, Errno::ECONNRESET, SocketError].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RetryOnError

#retry_on_error

Constructor Details

#initialize(account:) ⇒ ClientFactory

Returns a new instance of ClientFactory.


12
13
14
15
16
# File 'lib/imap/backup/account/connection/client_factory.rb', line 12

def initialize(account:)
  @account = 
  @provider = nil
  @server = nil
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.


10
11
12
# File 'lib/imap/backup/account/connection/client_factory.rb', line 10

def 
  @account
end

Instance Method Details

#runObject


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/imap/backup/account/connection/client_factory.rb', line 18

def run
  retry_on_error(errors: LOGIN_RETRY_CLASSES) do
    options = provider_options
    Logger.logger.debug(
      "Creating IMAP instance: #{server}, options: #{options.inspect}"
    )
    client =
      if provider.is_a?(Email::Provider::AppleMail)
        Client::AppleMail.new(server, options)
      else
        Client::Default.new(server, options)
      end
    Logger.logger.debug "Logging in: #{.username}/#{masked_password}"
    client.(.username, .password)
    Logger.logger.debug "Login complete"
    client
  end
end