当密码为 space 时在 IMAP 中获取邮件时出错

Error fetching mail in IMAP when space in password

我在 IMAP 中有一个如下所示的函数,当 $password 中有 space 时会抛出错误 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

有 hints/ideas 吗?

$this->connection->sendData( "{$tag} LOGIN {$user} {$password}" );

在密码两边加上引号。