在密码中的空格时在IMAP中获取邮件时出错

时间:2015-08-18 06:20:33

标签: php imap

我在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()函数添加quuotes或斜杠。但每次它都会导致同样的错误。

echo $ response提供A0001 BAD [CLIENTBUG] Invalid command or arguments

任何提示/想法?

1 个答案:

答案 0 :(得分:1)

  

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

在密码周围加上引号。