- Модуль: mail
- Путь к файлу: ~/bitrix/modules/mail/lib/imap.php
- Класс: BitrixMailImap
- Вызов: Imap::connect
public function connect(&$error)
{
$error = null;
if (!empty($this->sessState))
return true;
$resource = @stream_socket_client(
$this->options['socket'], $errno, $errstr, $this->options['timeout'],
STREAM_CLIENT_CONNECT, $this->options['context']
);
if ($resource === false)
{
$error = $this->errorMessage(Imap::ERR_CONNECT, $errno ?: null);
return false;
}
$this->stream = $resource;
if ($this->options['timeout'] > 0)
stream_set_timeout($this->stream, $this->options['timeout']);
$prompt = $this->readLine();
if ($prompt !== false && preg_match('/^* (OK|PREAUTH)/i', $prompt, $matches))
{
if ($matches[1] == 'OK')
$this->sessState = 'no_auth';
elseif ($matches[1] == 'PREAUTH')
$this->sessState = 'auth';
}
else
{
if ($prompt === false)
$error = Imap::ERR_EMPTY_RESPONSE;
elseif (preg_match('/^* BYE/i', $prompt))
$error = Imap::ERR_REJECTED;
else
$error = Imap::ERR_BAD_SERVER;
$error = $this->errorMessage(array(Imap::ERR_CONNECT, $error));
return false;
}
if (!$this->capability($error))
return false;
if (!$this->options['tls'] && preg_match('/ x20 STARTTLS ( x20 | rn ) /ix', $this->sessCapability))
{
if (!$this->starttls($error))
return false;
}
return true;
}