ImapAuthenticate.Login() - bugfix?

Jan 28, 2010 at 7:40 AM
Edited Jan 28, 2010 at 9:17 AM

 

 When sequence number gets bigger than 10000 a login fails with the wonderful error message:
Connect() - Authentication failed: kw34821 OK xxxxxxx@gmail.com authenticated (Success)


public void Login(string username, string password) { string command; string result; if (!(Connection.ConnectionState == ... switch (Connection.LoginType) { ... } result = Connection.Read(); if (result.StartsWith("* CAPABILITY")) // Gmail seems to send capabilities after login { result = Connection.Read(); } // 20100128 bug fix //if (result.StartsWith("* OK") || result.Substring(7, 2) == "OK") // what about sequence numbers above 10000 ? int firstSpace = result.IndexOf(" "); if (result.StartsWith("* OK") || result.Substring(firstSpace + 1, 2) == "OK") Connection.ConnectionState = ConnectionState.Open; else { ...


later: fixed typo in code.

 

Coordinator
Feb 2, 2010 at 5:13 AM

Ive been working at moving some of the code like this to regular expressions since it appears to be the more elegant approach. In this case something like this might work.

 

 

if (Regex.IsMatch(result, @"(*\sOK|kw\d+\sOK).*$")
      Connection.ConnectionState = ConnectionState.Open;
 else
      {
            ...