Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'develop' of https://github.com/zendframework/zf2 into h…
Browse files Browse the repository at this point in the history
…otfix/zend-session-global-session-storage
  • Loading branch information
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 104 deletions.
21 changes: 21 additions & 0 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,4 +535,25 @@ public function toString()
. Headers::EOL
. $this->getBodyText();
}

/**
* Instantiate from raw message string
*
* @todo Restore body to Mime\Message
* @param string $rawMessage
* @return Message
*/
public static function fromString($rawMessage)
{
$message = new static();
$headers = null;
$content = null;
Mime\Decode::splitMessage($rawMessage, $headers, $content);
if ($headers->has('mime-version')) {
// todo - restore body to mime\message
}
$message->setHeaders($headers);
$message->setBody($content);
return $message;
}
}
2 changes: 1 addition & 1 deletion src/Protocol/AbstractProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ abstract class AbstractProtocol
public function __construct($host = '127.0.0.1', $port = null)
{
$this->validHost = new Validator\ValidatorChain();
$this->validHost->addValidator(new Validator\Hostname(Validator\Hostname::ALLOW_ALL));
$this->validHost->attach(new Validator\Hostname(Validator\Hostname::ALLOW_ALL));

if (!$this->validHost->isValid($host)) {
throw new Exception\RuntimeException(implode(', ', $this->validHost->getMessages()));
Expand Down
26 changes: 20 additions & 6 deletions src/Protocol/Imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,34 @@ public function __destruct()
*/
public function connect($host, $port = null, $ssl = false)
{
if ($ssl == 'SSL') {
$host = 'ssl://' . $host;
$isTls = false;

if ($ssl) {
$ssl = strtolower($ssl);
}

if ($port === null) {
$port = $ssl === 'SSL' ? 993 : 143;
switch ($ssl) {
case 'ssl':
$host = 'ssl://' . $host;
if (!$port) {
$port = 993;
}
break;
case 'tls':
$isTls = true;
// break intentionally omitted
default:
if (!$port) {
$port = 143;
}
}

ErrorHandler::start();
$this->socket = fsockopen($host, $port, $errno, $errstr, self::TIMEOUT_CONNECTION);
$error = ErrorHandler::stop();
if (!$this->socket) {
throw new Exception\RuntimeException(sprintf(
'cannot connect to host%s',
'cannot connect to host %s',
($error ? sprintf('; error = %s (errno = %d )', $error->getMessage(), $error->getCode()) : '')
), 0, $error);
}
Expand All @@ -92,7 +106,7 @@ public function connect($host, $port = null, $ssl = false)
throw new Exception\RuntimeException('host doesn\'t allow connection');
}

if ($ssl === 'TLS') {
if ($isTls) {
$result = $this->requestAndResponse('STARTTLS');
$result = $result && stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
if (!$result) {
Expand Down
26 changes: 20 additions & 6 deletions src/Protocol/Pop3.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,34 @@ public function __destruct()
*/
public function connect($host, $port = null, $ssl = false)
{
if ($ssl == 'SSL') {
$host = 'ssl://' . $host;
$isTls = false;

if ($ssl) {
$ssl = strtolower($ssl);
}

if ($port === null) {
$port = $ssl == 'SSL' ? 995 : 110;
switch ($ssl) {
case 'ssl':
$host = 'ssl://' . $host;
if (!$port) {
$port = 995;
}
break;
case 'tls':
$isTls = true;
// break intentionally omitted
default:
if (!$port) {
$port = 110;
}
}

ErrorHandler::start();
$this->socket = fsockopen($host, $port, $errno, $errstr, self::TIMEOUT_CONNECTION);
$error = ErrorHandler::stop();
if (!$this->socket) {
throw new Exception\RuntimeException(sprintf(
'cannot connect to host%s',
'cannot connect to host %s',
($error ? sprintf('; error = %s (errno = %d )', $error->getMessage(), $error->getCode()) : '')
), 0, $error);
}
Expand All @@ -106,7 +120,7 @@ public function connect($host, $port = null, $ssl = false)
$this->timestamp = '<' . $this->timestamp . '>';
}

if ($ssl === 'TLS') {
if ($isTls) {
$this->request('STLS');
$result = stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
if (!$result) {
Expand Down
Loading

0 comments on commit c1754e3

Please sign in to comment.