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

Commit

Permalink
Merge branch 'hotfix/4934' into develop
Browse files Browse the repository at this point in the history
Forward port zendframework/zendframework#4934

Conflicts:
	library/Zend/Mime/Message.php
	tests/ZendTest/Mime/MimeTest.php
  • Loading branch information
weierophinney committed Aug 19, 2013
2 parents 924558c + be36a90 commit 4ba6c23
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
36 changes: 27 additions & 9 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +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']);

// now we build a new MimePart for the current Message Part:
$properties = array();
foreach ($part['header'] as $header) {
/** @var \Zend\Mail\Header\HeaderInterface $header */
/**
Expand All @@ -235,31 +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:
// 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
27 changes: 27 additions & 0 deletions test/MimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,33 @@ public function testFromMessageMultiPart()
$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

0 comments on commit 4ba6c23

Please sign in to comment.