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 hot…
Browse files Browse the repository at this point in the history
…fix/cache-empty-namespace
  • Loading branch information
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 115 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 consist of only letters, numbers and dashes.'
);
}

Expand Down
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
28 changes: 21 additions & 7 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 Expand Up @@ -533,7 +547,7 @@ public function fetch($items, $from, $to = null)
} elseif ($to === INF) {
$set = (int) $from . ':*';
} else {
$set = (int) $from . ':' . (int)$to;
$set = (int) $from . ':' . (int) $to;
}

$items = (array) $items;
Expand Down
28 changes: 21 additions & 7 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 Expand Up @@ -283,7 +297,7 @@ public function getList($msgno = null)
$line = strtok($result, "\n");
while ($line) {
list($no, $size) = explode(' ', trim($line));
$messages[(int)$no] = (int) $size;
$messages[(int) $no] = (int) $size;
$line = strtok("\n");
}

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
2 changes: 1 addition & 1 deletion src/Transport/FileOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function setCallback($callback)
public function getCallback()
{
if (null === $this->callback) {
$this->setCallback(function($transport) {
$this->setCallback(function ($transport) {
return 'ZendMail_' . time() . '_' . mt_rand() . '.tmp';
});
}
Expand Down
1 change: 0 additions & 1 deletion src/Transport/Sendmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Zend\Mail;
use Zend\Mail\Address\AddressInterface;
use Zend\Mail\Exception;
use Zend\Mail\Headers;
use Zend\Mail\Header\HeaderInterface;

/**
Expand Down
Loading

0 comments on commit c258e8b

Please sign in to comment.