Method: Net::IMAP#authenticate
- Defined in:
- lib/net/imap.rb
#authenticate(auth_type, *args) ⇒ Object
Sends an AUTHENTICATE command to authenticate the client. The auth_type parameter is a string that represents the authentication mechanism to be used. Currently Net::IMAP supports authentication mechanisms:
LOGIN:: login using cleartext user and password.
CRAM-MD5:: login with cleartext user and encrypted password
(see [RFC-2195] for a full description). This
mechanism requires that the server have the user's
password stored in clear-text password.
For both these mechanisms, there should be two args: username and (cleartext) password. A server may not support one or other of these mechanisms; check #capability() for a capability of the form “AUTH=LOGIN” or “AUTH=CRAM-MD5”.
Authentication is done using the appropriate authenticator object: see @@authenticators for more information on plugging in your own authenticator.
For example:
imap.authenticate('LOGIN', user, password)
A Net::IMAP::NoResponseError is raised if authentication fails.
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/net/imap.rb', line 350 def authenticate(auth_type, *args) auth_type = auth_type.upcase unless @@authenticators.has_key?(auth_type) raise ArgumentError, format('unknown auth type - "%s"', auth_type) end authenticator = @@authenticators[auth_type].new(*args) send_command("AUTHENTICATE", auth_type) do |resp| if resp.instance_of?(ContinuationRequest) data = authenticator.process(resp.data.text.unpack("m")[0]) s = [data].pack("m").gsub(/\n/, "") send_string_data(s) put_string(CRLF) end end end |