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

Commit

Permalink
Merge remote-tracking branch 'zf2/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 290 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

14 changes: 0 additions & 14 deletions .travis/run-tests.sh

This file was deleted.

7 changes: 0 additions & 7 deletions .travis/skipped-components

This file was deleted.

61 changes: 0 additions & 61 deletions .travis/tested-components

This file was deleted.

6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zendframework/zend-mime",
"description": "Zend\\Mime component",
"description": " ",
"license": "BSD-3-Clause",
"keywords": [
"zf2",
Expand All @@ -9,11 +9,11 @@
"homepage": "/~https://github.com/zendframework/zend-mime",
"autoload": {
"psr-4": {
"Zend\\Mime\\": "src/"
"Zend\\Mime": "src/"
}
},
"require": {
"php": ">=5.3.23",
"php": ">=5.3.3",
"zendframework/zend-stdlib": "self.version"
},
"require-dev": {
Expand Down
82 changes: 32 additions & 50 deletions src/Decode.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mime
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Mime
*/

namespace Zend\Mime;

use Zend\Mail\Headers;
use Zend\Stdlib\ErrorHandler;

/**
* @category Zend
* @package Zend_Mime
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Decode
{
Expand Down Expand Up @@ -106,14 +97,18 @@ public static function splitMessageStruct($message, $boundary, $EOL = Mime::LINE
*
* The charset of the returned headers depend on your iconv settings.
*
* @param string $message raw message with header and optional content
* @param array $headers output param, array with headers as array(name => value)
* @param string $body output param, content of message
* @param string $EOL EOL string; defaults to {@link Zend_Mime::LINEEND}
* @param string|Headers $message raw message with header and optional content
* @param Headers $headers output param, headers container
* @param string $body output param, content of message
* @param string $EOL EOL string; defaults to {@link Zend_Mime::LINEEND}
* @param boolean $strict enable strict mode for parsing message
* @return null
*/
public static function splitMessage($message, &$headers, &$body, $EOL = Mime::LINEEND)
public static function splitMessage($message, &$headers, &$body, $EOL = Mime::LINEEND, $strict = false)
{
if ($message instanceof Headers) {
$message = $message->toString();
}
// check for valid header at first line
$firstline = strtok($message, "\n");
if (!preg_match('%^[^\s]+[^:]*:%', $firstline)) {
Expand All @@ -123,45 +118,32 @@ public static function splitMessage($message, &$headers, &$body, $EOL = Mime::LI
return;
}

// see @ZF2-372, pops the first line off a message if it doesn't contain a header
if (!$strict) {
$parts = explode(': ', $firstline, 2);
if (count($parts) != 2) {
$message = substr($message, strpos($message, $EOL)+1);
}
}

// find an empty line between headers and body
// default is set new line
if (strpos($message, $EOL . $EOL)) {
list($headers, $body) = explode($EOL . $EOL, $message, 2);
// next is the standard new line
} else if ($EOL != "\r\n" && strpos($message, "\r\n\r\n")) {
} elseif ($EOL != "\r\n" && strpos($message, "\r\n\r\n")) {
list($headers, $body) = explode("\r\n\r\n", $message, 2);
// next is the other "standard" new line
} else if ($EOL != "\n" && strpos($message, "\n\n")) {
} elseif ($EOL != "\n" && strpos($message, "\n\n")) {
list($headers, $body) = explode("\n\n", $message, 2);
// at last resort find anything that looks like a new line
} else {
@list($headers, $body) = @preg_split("%([\r\n]+)\\1%U", $message, 2);
}

$headers = iconv_mime_decode_headers($headers, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);

if ($headers === false) {
// an error occurs during the decoding
return;
ErrorHandler::start(E_NOTICE|E_WARNING);
list($headers, $body) = preg_split("%([\r\n]+)\\1%U", $message, 2);
ErrorHandler::stop();
}

// normalize header names
foreach ($headers as $name => $header) {
$lower = strtolower($name);
if ($lower == $name) {
continue;
}
unset($headers[$name]);
if (!isset($headers[$lower])) {
$headers[$lower] = $header;
continue;
}
if (is_array($headers[$lower])) {
$headers[$lower][] = $header;
continue;
}
$headers[$lower] = array($headers[$lower], $header);
}
$headers = Headers::fromString($headers, $EOL);
}

/**
Expand Down Expand Up @@ -237,6 +219,6 @@ public static function splitHeaderField($field, $wantedPart = null, $firstName =
*/
public static function decodeQuotedPrintable($string)
{
return iconv_mime_decode($string, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);
return iconv_mime_decode($string, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, 'UTF-8');
}
}
22 changes: 5 additions & 17 deletions src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mime
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Mime
*/

namespace Zend\Mime\Exception;

/**
* @category Zend
* @package Zend_Mime
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface ExceptionInterface
{}
Expand Down
23 changes: 5 additions & 18 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mime
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id$
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Mime
*/

namespace Zend\Mime\Exception;
Expand All @@ -26,8 +15,6 @@
*
* @category Zend
* @package Zend_Mime
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class RuntimeException
extends \RuntimeException
Expand Down
46 changes: 19 additions & 27 deletions src/Message.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
<?php
/**
* Zend Framework
* Zend Framework (http://framework.zend.com/)
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Mime
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Mime
*/

namespace Zend\Mime;

/**
* @category Zend
* @package Zend_Mime
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Message
{
Expand Down Expand Up @@ -237,34 +225,38 @@ public static function createFromMessage($message, $boundary, $EOL = Mime::LINEE
foreach ($parts as $part) {
// now we build a new MimePart for the current Message Part:
$newPart = new Part($part['body']);
foreach ($part['header'] as $key => $value) {
foreach ($part['header'] as $header) {
/** @var \Zend\Mail\Header\HeaderInterface $header */
/**
* @todo check for characterset and filename
*/
switch(strtolower($key)) {

$fieldName = $header->getFieldName();
$fieldValue = $header->getFieldValue();
switch (strtolower($fieldName)) {
case 'content-type':
$newPart->type = $value;
$newPart->type = $fieldValue;
break;
case 'content-transfer-encoding':
$newPart->encoding = $value;
$newPart->encoding = $fieldValue;
break;
case 'content-id':
$newPart->id = trim($value,'<>');
$newPart->id = trim($fieldValue,'<>');
break;
case 'content-disposition':
$newPart->disposition = $value;
$newPart->disposition = $fieldValue;
break;
case 'content-description':
$newPart->description = $value;
$newPart->description = $fieldValue;
break;
case 'content-location':
$newPart->location = $value;
$newPart->location = $fieldValue;
break;
case 'content-language':
$newPart->language = $value;
$newPart->language = $fieldValue;
break;
default:
throw new Exception\RuntimeException('Unknown header ignored for MimePart:' . $key);
throw new Exception\RuntimeException('Unknown header ignored for MimePart:' . $fieldName);
}
}
$res->addPart($newPart);
Expand Down
Loading

0 comments on commit acad728

Please sign in to comment.