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 git://github.com/zendframework/zf2 into dev…
Browse files Browse the repository at this point in the history
…elop
  • Loading branch information
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Header/GenericHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function setFieldName($fieldName)
// Validate what we have
if (!preg_match('/^[a-z][a-z0-9-]*$/i', $fieldName)) {
throw new Exception\InvalidArgumentException(
'Header name must start with a letter, and consist of only letters, numbers and dashes'
'Header name must start with a letter, and consists of only letters, numbers and dashes.'
);
}

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
6 changes: 3 additions & 3 deletions src/Storage/Imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public function countMessages($flags = null)

$params = array();
foreach ((array) $flags as $flag) {
if (isset(self::$searchFlags[$flag])) {
$params[] = self::$searchFlags[$flag];
if (isset(static::$searchFlags[$flag])) {
$params[] = static::$searchFlags[$flag];
} else {
$params[] = 'KEYWORD';
$params[] = $this->protocol->escapeString($flag);
Expand Down Expand Up @@ -116,7 +116,7 @@ public function getMessage($id)

$flags = array();
foreach ($data['FLAGS'] as $flag) {
$flags[] = isset(self::$knownFlags[$flag]) ? self::$knownFlags[$flag] : $flag;
$flags[] = isset(static::$knownFlags[$flag]) ? static::$knownFlags[$flag] : $flag;
}

return new $this->messageClass(array('handler' => $this, 'id' => $id, 'headers' => $header, 'flags' => $flags));
Expand Down
2 changes: 1 addition & 1 deletion src/Storage/Maildir.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ protected function _getMaildirFiles($dh, $dirname, $default_flags = array())
$length = strlen($flags);
for ($i = 0; $i < $length; ++$i) {
$flag = $flags[$i];
$named_flags[$flag] = isset(self::$knownFlags[$flag]) ? self::$knownFlags[$flag] : $flag;
$named_flags[$flag] = isset(static::$knownFlags[$flag]) ? static::$knownFlags[$flag] : $flag;
}

$data = array('uniq' => $uniq,
Expand Down

0 comments on commit cb43167

Please sign in to comment.