PHPMailer\PHPMailer

SMTP::get_lines()protectedWP 1.0

Read the SMTP server's response. Either before eof or socket timeout occurs on the operation. With SMTP we can tell if we have more lines to read if the
4th character is '-' symbol. If it is a space then we don't need to read anything else.

Метод класса: SMTP{}

Хуков нет.

Возвращает

Строку.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_lines();

Код SMTP::get_lines() WP 6.5.2

protected function get_lines()
{
    //If the connection is bad, give up straight away
    if (!is_resource($this->smtp_conn)) {
        return '';
    }
    $data = '';
    $endtime = 0;
    stream_set_timeout($this->smtp_conn, $this->Timeout);
    if ($this->Timelimit > 0) {
        $endtime = time() + $this->Timelimit;
    }
    $selR = [$this->smtp_conn];
    $selW = null;
    while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
        //Must pass vars in here as params are by reference
        //solution for signals inspired by https://github.com/symfony/symfony/pull/6540
        set_error_handler([$this, 'errorHandler']);
        $n = stream_select($selR, $selW, $selW, $this->Timelimit);
        restore_error_handler();

        if ($n === false) {
            $message = $this->getError()['detail'];

            $this->edebug(
                'SMTP -> get_lines(): select failed (' . $message . ')',
                self::DEBUG_LOWLEVEL
            );

            //stream_select returns false when the `select` system call is interrupted
            //by an incoming signal, try the select again
            if (stripos($message, 'interrupted system call') !== false) {
                $this->edebug(
                    'SMTP -> get_lines(): retrying stream_select',
                    self::DEBUG_LOWLEVEL
                );
                $this->setError('');
                continue;
            }

            break;
        }

        if (!$n) {
            $this->edebug(
                'SMTP -> get_lines(): select timed-out in (' . $this->Timelimit . ' sec)',
                self::DEBUG_LOWLEVEL
            );
            break;
        }

        //Deliberate noise suppression - errors are handled afterwards
        $str = @fgets($this->smtp_conn, self::MAX_REPLY_LENGTH);
        $this->edebug('SMTP INBOUND: "' . trim($str) . '"', self::DEBUG_LOWLEVEL);
        $data .= $str;
        //If response is only 3 chars (not valid, but RFC5321 S4.2 says it must be handled),
        //or 4th character is a space or a line break char, we are done reading, break the loop.
        //String array access is a significant micro-optimisation over strlen
        if (!isset($str[3]) || $str[3] === ' ' || $str[3] === "\r" || $str[3] === "\n") {
            break;
        }
        //Timed-out? Log and break
        $info = stream_get_meta_data($this->smtp_conn);
        if ($info['timed_out']) {
            $this->edebug(
                'SMTP -> get_lines(): stream timed-out (' . $this->Timeout . ' sec)',
                self::DEBUG_LOWLEVEL
            );
            break;
        }
        //Now check if reads took too long
        if ($endtime && time() > $endtime) {
            $this->edebug(
                'SMTP -> get_lines(): timelimit reached (' .
                $this->Timelimit . ' sec)',
                self::DEBUG_LOWLEVEL
            );
            break;
        }
    }

    return $data;
}