Class: Net::SMTP::Authenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/net/smtp/authenticator.rb

Direct Known Subclasses

AuthCramMD5, AuthLogin, AuthPlain, AuthXoauth2

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(smtp) ⇒ Authenticator

Returns a new instance of Authenticator.



29
30
31
# File 'lib/net/smtp/authenticator.rb', line 29

def initialize(smtp)
  @smtp = smtp
end

Instance Attribute Details

#smtpObject (readonly)

Returns the value of attribute smtp.



27
28
29
# File 'lib/net/smtp/authenticator.rb', line 27

def smtp
  @smtp
end

Class Method Details

.auth_class(type) ⇒ Object



13
14
15
16
# File 'lib/net/smtp/authenticator.rb', line 13

def self.auth_class(type)
  type = type.to_s.upcase.tr(?_, ?-).to_sym
  Authenticator.auth_classes[type]
end

.auth_classesObject



4
5
6
# File 'lib/net/smtp/authenticator.rb', line 4

def self.auth_classes
  @classes ||= {}
end

.auth_type(type) ⇒ Object



8
9
10
11
# File 'lib/net/smtp/authenticator.rb', line 8

def self.auth_type(type)
  type = type.to_s.upcase.tr(?_, ?-).to_sym
  Authenticator.auth_classes[type] = self
end

.check_args(user_arg = nil, secret_arg = nil) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/net/smtp/authenticator.rb', line 18

def self.check_args(user_arg = nil, secret_arg = nil, *, **)
  unless user_arg
    raise ArgumentError, 'SMTP-AUTH requested but missing user name'
  end
  unless secret_arg
    raise ArgumentError, 'SMTP-AUTH requested but missing secret phrase'
  end
end

Instance Method Details

#base64_encode(str) ⇒ String

Returns Base64 encoded string.

Parameters:

  • str (String)

Returns:

  • (String)

    Base64 encoded string



51
52
53
54
# File 'lib/net/smtp/authenticator.rb', line 51

def base64_encode(str)
  # expects "str" may not become too long
  [str].pack('m0')
end

#continue(arg) ⇒ String

Returns message from server.

Parameters:

  • arg (String)

    message to server

Returns:

  • (String)

    message from server

Raises:

  • (res.exception_class)


35
36
37
38
39
# File 'lib/net/smtp/authenticator.rb', line 35

def continue(arg)
  res = smtp.get_response arg
  raise res.exception_class.new(res) unless res.continue?
  res.string.split[1]
end

#finish(arg) ⇒ Net::SMTP::Response

Returns response from server.

Parameters:

  • arg (String)

    message to server

Returns:

Raises:



43
44
45
46
47
# File 'lib/net/smtp/authenticator.rb', line 43

def finish(arg)
  res = smtp.get_response arg
  raise SMTPAuthenticationError.new(res) unless res.success?
  res
end