示例#1
0
 /// <summary>
 ///   Send the DONE command to the server on a seperate thread, which will release the IDLE lock.
 /// </summary>
 public void StopIdleAsync()
 {
     var command = new BlankImapCommand("DONE");
     SendAsync(command);
 }
示例#2
0
        private bool AuthenticateCramMd5(NetworkCredential credentials)
        {
            var command = new ImapCommand("AUTHENTICATE CRAM-MD5");
            var response = _client.SendAndReceive(command);

            // don't trim the last plus !!
            var base64 = response.CurrentLine.TrimStart(Characters.Plus).Trim();
            var challenge = Base64Encoder.Decode(base64, Encoding.UTF8);

            var username = credentials.UserName;
            var password = credentials.Password;

            var hash = CramMd5Hasher.ComputeHash(password, challenge);

            var authentication = username + " " + hash;
            var authCommand = new BlankImapCommand(Base64Encoder.Encode(authentication));

            var reader = _client.SendAndReceive(authCommand);
            while (!reader.IsCompleted) {
                reader = _client.Receive(false);
            }
            return reader.IsOk;
        }
示例#3
0
        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;
        }
示例#4
0
 /// <summary>
 ///   Authenticates the client to the server using the XOAUTH mechanism.
 /// </summary>
 /// <param name = "key">The XOAUTH authetication key.</param>
 /// <returns>Returns true on success, false otherwise.</returns>
 public bool AuthenticateXOAuth(string key)
 {
     if (_client.ServerCapability.IsInitialClientResponseSupported) {
         var text = string.Format("AUTHENTICATE XOAUTH {0}", key);
         var command = new ImapCommand(text);
         return _client.SendAndReceive(command).IsOk;
     } else {
         var text = string.Format("AUTHENTICATE XOAUTH");
         var command = new ImapCommand(text);
         var reader = _client.SendAndReceive(command);
         if (reader.IsContinuation) {
             var auth = new BlankImapCommand(key);
             return _client.SendAndReceive(auth).IsOk;
         }
         return false;
     }
 }