/// <summary>sends AUTHENTICATE command</summary>
        /// <remarks>valid in non-authenticated state</remarks>
        public ImapCommandResult Authenticate(ICredentialsByHost credentials,
                                          string username,
                                          ImapAuthenticationMechanism authenticationMechanism,
                                          bool reissueCapability)
        {
            var ret = RejectNonConnectedOrGetAuthenticatedResult();

              if (ret != null)
            return ret;

              if (credentials == null)
            throw new ArgumentNullException("credentials");
              if (authenticationMechanism == null)
            throw new ArgumentNullException("authenticationMechanism");

              var credential = credentials.LookupCredential(connection, username, authenticationMechanism);

              if (credential == null)
            return new ImapCommandResult(ImapCommandResultCode.RequestError,
                                     string.Format("credential not found for {0};AUTH={1}@{2}:{3}", username, authenticationMechanism, connection.Host, connection.Port));

              using (var t = new AuthenticateTransaction(connection, credential, serverCapabilities.Has(ImapCapability.SaslIR))) {
            t.RequestArguments["authentication mechanism name"] = authenticationMechanism;

            return AuthenticateInternal(t, credential.UserName, authenticationMechanism, reissueCapability);
              }
        }
        /// <summary>sends AUTHENTICATE command</summary>
        /// <remarks>valid in non-authenticated state</remarks>
        public ImapCommandResult Authenticate(SaslClientMechanism specificAuthenticationMechanism,
                                          bool reissueCapability)
        {
            var ret = RejectNonConnectedOrGetAuthenticatedResult();

              if (ret != null)
            return ret;

              if (specificAuthenticationMechanism == null)
            throw new ArgumentNullException("specificAuthenticationMechanism");

              using (var t = new AuthenticateTransaction(connection, specificAuthenticationMechanism, serverCapabilities.Has(ImapCapability.SaslIR))) {
            var authMechanism = ImapAuthenticationMechanism.GetKnownOrCreate(specificAuthenticationMechanism.Name);
            var username = specificAuthenticationMechanism.Credential == null
              ? null
              : specificAuthenticationMechanism.Credential.UserName;

            return AuthenticateInternal(t, username, authMechanism, reissueCapability);
              }
        }