Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

BOOL PPOP3Client::LogIn ( const PString username,
const PString password,
int  options = AllowUserPass 
)

Log into the POP server using the mailbox and access codes specified.

Returns:
TRUE if logged in.
Parameters:
username  User name on remote system.
password  Password for user name.
options  See LoginOptions above

Definition at line 963 of file inetmail.cxx.

References AllowClearTextSASL, AllowUserPass, PString::Empty(), PMessageDigest5::Encode(), PInternetProtocol::ExecuteCommand(), PString::IsEmpty(), PInternetProtocol::ReadLine(), PInternetProtocol::ReadResponse(), PString::sprintf(), UseSASL, and PInternetProtocol::WriteLine().

{
#if P_SASL2
  PString mech;
  PSASLClient auth("pop", username, username, password);

  if ((options & UseSASL) && ExecuteCommand(AUTH, "") > 0) {
    PStringSet serverMechs;
    while (ReadLine(mech) && mech[0] != '.')
      serverMechs.Include(mech);

    mech = PString::Empty();
    PStringSet ourMechs;

    if (auth.Init("", ourMechs)) {

      if (!(options & AllowClearTextSASL)) {
        ourMechs.Exclude("PLAIN");
        ourMechs.Exclude("LOGIN");
      }

      for (PINDEX i = 0, max = serverMechs.GetSize() ; i < max ; i++)
        if (ourMechs.Contains(serverMechs.GetKeyAt(i))) {
          mech = serverMechs.GetKeyAt(i);
          break;
        }
    }
  }

  PString output;

  if ((options & UseSASL) && !mech.IsEmpty() && auth.Start(mech, output)) {

    if (ExecuteCommand(AUTH, mech) <= 0)
      return FALSE;

    PSASLClient::PSASLResult result;

    do {
      result = auth.Negotiate(lastResponseInfo, output);
      
      if (result == PSASLClient::Fail)
        return FALSE;

      if (!output.IsEmpty()) {
        WriteLine(output);
        if (!ReadResponse() || !lastResponseCode)
          return FALSE;
      }
    } while (result == PSASLClient::Continue);
    auth.End();
  }
  else {
#endif

    if (!apopBanner.IsEmpty()) { // let's try with APOP

      PMessageDigest::Result bin_digest;
      PMessageDigest5::Encode(apopBanner + password, bin_digest);
      PString digest;

      const BYTE * data = bin_digest.GetPointer();

      for (PINDEX i = 0, max = bin_digest.GetSize(); i < max ; i++)
        digest.sprintf("%02x", (unsigned)data[i]);

      if (ExecuteCommand(APOP, username + " " + digest) > 0)
        return loggedIn = TRUE;
    }

    // No SASL and APOP didn't work for us
    // If we really have to, we'll go with the plain old USER/PASS scheme

    if (!(options & AllowUserPass))
      return FALSE;

    if (ExecuteCommand(USER, username) <= 0)
      return FALSE;

    if (ExecuteCommand(PASS, password) <= 0)
      return FALSE;

#if P_SASL2
  }
#endif

  loggedIn = TRUE;
  return TRUE;
}


Generated by  Doxygen 1.6.0   Back to index