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/develop' into zend-validator-bitwise
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 21 deletions.
38 changes: 29 additions & 9 deletions src/Message.php
Expand Up @@ -222,8 +222,9 @@ public static function createFromMessage($message, $boundary, $EOL = Mime::LINEE

$res = new static();
foreach ($parts as $part) {

// now we build a new MimePart for the current Message Part:
$newPart = new Part($part['body']);
$properties = array();
foreach ($part['header'] as $header) {
/** @var \Zend\Mail\Header\HeaderInterface $header */
/**
Expand All @@ -234,30 +235,49 @@ public static function createFromMessage($message, $boundary, $EOL = Mime::LINEE
$fieldValue = $header->getFieldValue();
switch (strtolower($fieldName)) {
case 'content-type':
$newPart->type = $fieldValue;
$properties['type'] = $fieldValue;
break;
case 'content-transfer-encoding':
$newPart->encoding = $fieldValue;
$properties['encoding'] = $fieldValue;
break;
case 'content-id':
$newPart->id = trim($fieldValue,'<>');
$properties['id'] = trim($fieldValue,'<>');
break;
case 'content-disposition':
$newPart->disposition = $fieldValue;
$properties['disposition'] = $fieldValue;
break;
case 'content-description':
$newPart->description = $fieldValue;
$properties['description'] = $fieldValue;
break;
case 'content-location':
$newPart->location = $fieldValue;
$properties['location'] = $fieldValue;
break;
case 'content-language':
$newPart->language = $fieldValue;
$properties['language'] = $fieldValue;
break;
default:
throw new Exception\RuntimeException('Unknown header ignored for MimePart:' . $fieldName);
// Ignore unknown header
break;
}
}

$body = $part['body'];

if (isset($properties['encoding'])) {
switch ($properties['encoding']) {
case 'quoted-printable':
$body = quoted_printable_decode($body);
break;
case 'base64':
$body = base64_decode($body);
break;
}
}

$newPart = new Part($body);
foreach ($properties as $key => $value) {
$newPart->$key = $value;
}
$res->addPart($newPart);
}

Expand Down
4 changes: 0 additions & 4 deletions test/MessageTest.php
Expand Up @@ -5,17 +5,13 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Mime
*/

namespace ZendTest\Mime;

use Zend\Mime;

/**
* @category Zend
* @package Zend_Mime
* @subpackage UnitTests
* @group Zend_Mime
*/
class MessageTest extends \PHPUnit_Framework_TestCase
Expand Down
61 changes: 57 additions & 4 deletions test/MimeTest.php
Expand Up @@ -5,17 +5,13 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Mime
*/

namespace ZendTest\Mime;

use Zend\Mime;

/**
* @category Zend
* @package Zend_Mime
* @subpackage UnitTests
* @group Zend_Mime
*/
class MimeTest extends \PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -135,6 +131,63 @@ public static function dataTestEncodeMailHeaderBase64()
);
}

public function testFromMessageMultiPart()
{
$message = Mime\Message::createFromMessage(
'--089e0141a1902f83ee04e0a07b7a'."\r\n"
.'Content-Type: multipart/alternative; boundary=089e0141a1902f83e904e0a07b78'."\r\n"
."\r\n"
.'--089e0141a1902f83e904e0a07b78'."\r\n"
.'Content-Type: text/plain; charset=UTF-8'."\r\n"
."\r\n"
.'Foo'."\r\n"
."\r\n"
.'--089e0141a1902f83e904e0a07b78'."\r\n"
.'Content-Type: text/html; charset=UTF-8'."\r\n"
."\r\n"
.'<p>Foo</p>'."\r\n"
."\r\n"
.'--089e0141a1902f83e904e0a07b78--'."\r\n"
.'--089e0141a1902f83ee04e0a07b7a'."\r\n"
.'Content-Type: image/png; name="1.png"'."\r\n"
.'Content-Disposition: attachment; filename="1.png"'."\r\n"
.'Content-Transfer-Encoding: base64'."\r\n"
.'X-Attachment-Id: barquux'."\r\n"
."\r\n"
.'Zm9vCg=='."\r\n"
.'--089e0141a1902f83ee04e0a07b7a--',
'089e0141a1902f83ee04e0a07b7a'
);
$this->assertSame(2, count($message->getParts()));
}

public static function dataTestFromMessageDecode()
{
return array(
array('äöü', 'quoted-printable', '=C3=A4=C3=B6=C3=BC'),
array('Alle meine Entchen schwimmen in dem See, schwimmen in dem See, Köpfchen in das Wasser, Schwänzchen in die Höh!', 'quoted-printable', 'Alle meine Entchen schwimmen in dem See, schwimmen in dem See, K=C3=B6pfche=
n in das Wasser, Schw=C3=A4nzchen in die H=C3=B6h!'),
array('foobar', 'base64', 'Zm9vYmFyCg=='),
);
}

/**
* @dataProvider dataTestFromMessageDecode
*/
public function testFromMessageDecode($input, $encoding, $result)
{
$parts = Mime\Message::createFromMessage(
'--089e0141a1902f83ee04e0a07b7a'."\r\n"
.'Content-Type: text/plain; charset=UTF-8'."\r\n"
.'Content-Transfer-Encoding: '.$encoding."\r\n"
."\r\n"
.$result."\r\n"
.'--089e0141a1902f83ee04e0a07b7a--',
'089e0141a1902f83ee04e0a07b7a'
)->getParts();
$this->assertSame($input."\n", $parts[0]->getRawContent());
}

/**
* @group ZF-1688
*/
Expand Down
4 changes: 0 additions & 4 deletions test/PartTest.php
Expand Up @@ -5,17 +5,13 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Mime
*/

namespace ZendTest\Mime;

use Zend\Mime;

/**
* @category Zend
* @package Zend_Mime
* @subpackage UnitTests
* @group Zend_Mime
*/
class PartTest extends \PHPUnit_Framework_TestCase
Expand Down

0 comments on commit 2fc78f0

Please sign in to comment.