private bool AuthenticatePlain(NetworkCredential credentials)
{
var capabilities = _client.ServerCapability;
var username = credentials.UserName;
var password = credentials.Password;
var auth = username + "\0" + username + "\0" + password;
var encodedAuth = Base64Encoder.Encode(auth);
if (capabilities.IsInitialClientResponseSupported)
{
var text = string.Format("AUTHENTICATE PLAIN {0}", encodedAuth);
var command = new ImapCommand(text);
return(_client.SendAndReceive(command).IsOk);
}
var authCommand = new ImapCommand("AUTHENTICATE PLAIN");
var response = _client.SendAndReceive(authCommand);
if (response.IsContinuation)
{
var command = new BlankImapCommand(encodedAuth);
_client.Send(command);
return(_client.Receive().IsOk);
}
return(false);
}