我在IMAP中有一个函数,当$password中有一个空格时抛出错误The IMAP server did not accept the username and/or password
。
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;
}
我已经尝试了str_replace()
的所有方法,添加引号或斜杠与addslashes()函数。但每次都会导致同样的错误。
echo $response给出A0001 BAD [CLIENTBUG] Invalid command or arguments
有什么提示/想法吗?
$ this ->连接-> sendData("{$ tag} {$ user}}{$密码登录");