Reputation: 9675
I've a function in IMAP as below which throws an error The IMAP server did not accept the username and/or password
when $password have a space in it.
public function authenticate( $user, $password )
{
if ( $this->state != self::STATE_NOT_AUTHENTICATED )
{
throw new ezcMailTransportException( "Tried to authenticate when there was no connection or when already authenticated." );
}
$tag = $this->getNextTag();
$this->connection->sendData( "{$tag} LOGIN {$user} {$password}" );
$response = trim( $this->connection->getLine() );
// hack for gmail, to fix issue #15837: imap.google.com (google gmail) changed IMAP response
if ( $this->serverType === self::SERVER_GIMAP && strpos( $response, "* CAPABILITY" ) === 0 )
{
$response = trim( $this->connection->getLine() );
}
if ( strpos( $response, '* OK' ) !== false )
{
// the server is busy waiting for authentication process to
// respond, so it is a good idea to just close the connection,
// otherwise the application will be halted until the server
// recovers
$this->connection->close();
$this->connection = null;
$this->state = self::STATE_NOT_CONNECTED;
return false;
}
if ( $this->responseType( $response ) != self::RESPONSE_OK )
{
throw new ezcMailTransportException( "The IMAP server did not accept the username and/or password: {$response}." );
}
else
{
$this->state = self::STATE_AUTHENTICATED;
$this->selectedMailbox = null;
}
return true;
}
I've tried all the method of str_replace()
, adding quuotes or slashes with addslashes() function. But everytime it results into the same error.
echo $response gives A0001 BAD [CLIENTBUG] Invalid command or arguments
Any hints/ideas ?
Upvotes: 1
Views: 444
Reputation: 553
$this->connection->sendData( "{$tag} LOGIN {$user} {$password}" );
Put quotes around the password.
Upvotes: 1