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

	if (!$this->select($mailbox, $error))
	{
		return false;
	}

	if ($this->sessMailbox['exists'] > 0)
	{
		return false;
	}

	$searchUntaggedRegex = '/^ * x20 SEARCH x20 ( .+ ) rn $ /ix';
	$this->getUntagged($searchUntaggedRegex, true);

	$response = $this->executeCommand('UID SEARCH 1', $error);

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

		return false;
	}

	$matches = 0;
	foreach ($this->getUntagged($searchUntaggedRegex, true) as $item)
	{
		$matches = preg_match_all('/d+/', $item[1][1]);
	}

	if ($matches > 0)
	{
		addMessage2Log(
			sprintf(
				'IMAP: invalid mailbox (search>exists) (%s:%s:%s:%u)',
				$this->options['host'], $this->options['login'], $mailbox, $this->sessMailbox['uidvalidity']
			),
			'mail', 0, false
		);

		return false;
	}

	$fetchUntaggedRegex = '/^ * x20 ( d+ ) x20 FETCH x20 ( ( .+ ) ) rn $/isx';
	$this->getUntagged($fetchUntaggedRegex, true);

	$response = $this->executeCommand('FETCH 1 (UID)', $error);

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

		return false;
	}

	$matches = 0;
	foreach ($this->getUntagged($fetchUntaggedRegex, true) as $item)
	{
		$matches = $item[1][1];
	}

	if ($matches > 0)
	{
		addMessage2Log(
			sprintf(
				'IMAP: invalid mailbox (fetch>exists) (%s:%s:%s:%u)',
				$this->options['host'], $this->options['login'], $mailbox, $this->sessMailbox['uidvalidity']
			),
			'mail', 0, false
		);

		return false;
	}

	return true;
}