class Net::IMAP::SASL::CramMD5Authenticator

traffic. With TLS CRAM-MD5 is okay, but so is PLAIN
of cleartext and recommends TLS version 1.2 or greater be used for all
Additionally, RFC8314 discourage the use
recommends using SCRAM-* or PLAIN protected by TLS instead.
existing servers.
CRAM-MD5 is obsolete and insecure. It is included for compatibility with
== Deprecated<br><br>RFC2195. See Net::IMAP#authenticate.
Authenticator for the “CRAM-MD5” SASL mechanism, specified in

def done?; @done end

def done?; @done end

def hmac_md5(text, key)

def hmac_md5(text, key)
  if key.length > 64
    key = Digest::MD5.digest(key)
  end
  k_ipad = key + "\0" * (64 - key.length)
  k_opad = key + "\0" * (64 - key.length)
  for i in 0..63
    k_ipad[i] = (k_ipad[i].ord ^ 0x36).chr
    k_opad[i] = (k_opad[i].ord ^ 0x5c).chr
  end
  digest = Digest::MD5.digest(k_ipad + text)
  return Digest::MD5.hexdigest(k_opad + digest)
end

def initial_response?; false end

def initial_response?; false end

def initialize(user = nil, pass = nil,

def initialize(user = nil, pass = nil,
               authcid: nil, username: nil,
               password: nil, secret: nil,
               warn_deprecation: true,
               **)
  if warn_deprecation
    warn "WARNING: CRAM-MD5 mechanism is deprecated.", category: :deprecated
  end
  require "digest/md5"
  @user = authcid || username || user
  @password = password || secret || pass
  @done = false
end

def process(challenge)

def process(challenge)
  digest = hmac_md5(challenge, @password)
  return @user + " " + digest
ensure
  @done = true
end