• Модуль: mail
  • Путь к файлу: ~/bitrix/modules/mail/lib/imap.php
  • Класс: BitrixMailImap
  • Вызов: Imap::listex
public function listex($reference, $pattern, &$error)
{
	$error = null;

	if (!$this->authenticate($error))
	{
		return false;
	}

	$response = $this->executeCommand(sprintf(
		'LIST "%s" "%s"',
		static::escapeQuoted($this->encodeUtf7Imap($reference)),
		static::escapeQuoted($this->encodeUtf7Imap($pattern))
	), $error);

	if ($error)
	{
		$error = $error == Imap::ERR_COMMAND_REJECTED ? null : $error;
		$error = $this->errorMessage(array(Imap::ERR_LIST, $error), $response);

		return false;
	}

	$list = array();

	$regex = sprintf(
		'/^ * x20 LIST x20
			( (? ( x5c? %1$s ( x20 x5c? %1$s )* )? ) ) x20
			(? NIL | " ( %2$s ) " ) x20
			(? { d+ } | " ( %2$s )* " | %3$s ) rn
			(? .* )
		/ix',
		self::$atomRegex, self::$qcharRegex, self::$astringRegex
	);
	foreach ($this->getUntagged($regex, true) as $item)
	{
		[$item, $matches] = $item;

		$sflags = $matches['flags'];
		$sdelim = $matches['delim'];
		$sname  = $matches['name'];

		if (preg_match('/^ " ( .+ ) " $/ix', $sdelim, $quoted))
		{
			$sdelim = static::unescapeQuoted($quoted[1]);
		}

		if (preg_match('/^ { ( d+ ) } $/ix', $sname, $literal))
		{
			$sname = substr($matches['ext'], 0, $literal[1]);
		}
		else if (preg_match('/^ " ( .* ) " $/ix', $sname, $quoted))
		{
			$sname = static::unescapeQuoted($quoted[1]);
		}

		$sname = $this->decodeUtf7Imap($sname);

		// #79498
		if (mb_strtoupper($sdelim) != 'NIL')
			$sname = rtrim($sname, $sdelim);

		$list[] = array(
			'name'  => $sname,
			'delim' => mb_strtoupper($sdelim) == 'NIL' ? 'NIL' : $sdelim,
			'flags' => preg_split('/s+/i', $sflags, -1, PREG_SPLIT_NO_EMPTY),
		);
	}

	return $list;
}