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/ZF-27-MAIL' of https://github.com/Maks3w/zf2 int…
Browse files Browse the repository at this point in the history
…o feature/zen27-mail
  • Loading branch information
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 57 deletions.
8 changes: 4 additions & 4 deletions src/Decode.php
Expand Up @@ -181,13 +181,13 @@ public static function splitContentType($type, $wantedPart = null)
/**
* split a header field like content type in its different parts
*
* @param string $type header field
* @param string $field header field
* @param string $wantedPart the wanted part, else an array with all parts is returned
* @param string $firstName key name for the first part
* @return string|array wanted part or all parts as array($firstName => firstPart, partname => value)
* @throws Exception\RuntimeException
*/
public static function splitHeaderField($field, $wantedPart = null, $firstName = 0)
public static function splitHeaderField($field, $wantedPart = null, $firstName = '0')
{
$wantedPart = strtolower($wantedPart);
$firstName = strtolower($firstName);
Expand Down Expand Up @@ -234,11 +234,11 @@ public static function splitHeaderField($field, $wantedPart = null, $firstName =
*
* The charset of the returned string depends on your iconv settings.
*
* @param string encoded string
* @param string $string encoded string
* @return string decoded string
*/
public static function decodeQuotedPrintable($string)
{
return quoted_printable_decode($string);
return iconv_mime_decode($string, ICONV_MIME_DECODE_CONTINUE_ON_ERROR);
}
}
4 changes: 1 addition & 3 deletions src/Exception/RuntimeException.php
Expand Up @@ -21,8 +21,6 @@

namespace Zend\Mime\Exception;

use RuntimeException;

/**
* Exception for Zend_Mime component.
*
Expand All @@ -33,7 +31,7 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class RuntimeException
extends RuntimeException
extends \RuntimeException
implements ExceptionInterface
{
}
65 changes: 15 additions & 50 deletions test/MimeTest.php
Expand Up @@ -21,8 +21,7 @@

namespace ZendTest\Mime;

use Zend\Mime,
Zend\Mail;
use Zend\Mime;

/**
* @category Zend
Expand All @@ -36,6 +35,7 @@ class MimeTest extends \PHPUnit_Framework_TestCase
{
/**
* Stores the original set timezone
*
* @var string
*/
private $_originaltimezone;
Expand All @@ -49,7 +49,7 @@ public function setUp()
}

/**
* Teardown environment
* Tear down environment
*/
public function tearDown()
{
Expand All @@ -65,7 +65,7 @@ public function testBoundary()

// check instantiating with arbitrary boundary string
$myBoundary = 'mySpecificBoundary';
$m3 = new Mime\Mime($myBoundary);
$m3 = new Mime\Mime($myBoundary);
$this->assertEquals($m3->boundary(), $myBoundary);

}
Expand Down Expand Up @@ -102,25 +102,13 @@ public function testBase64()

public function testZf1058WhitespaceAtEndOfBodyCausesInfiniteLoop()
{
// Set timezone to avoid "date(): It is not safe to rely on the system's timezone settings."
// message.
date_default_timezone_set('GMT');

$mail = new \Zend\Mail\Mail();
$mail->setSubject('my subject');
$mail->setBodyText("my body\r\n\r\n...after two newlines\r\n ");
$mail->setFrom('test@email.com');
$mail->addTo('test@email.com');

// test with generic transport
$mock = new SendmailTransportMock();
$mail->send($mock);
$body = quoted_printable_decode($mock->body);
$this->assertContains("my body\r\n\r\n...after two newlines", $body, $body);
$text = "my body\r\n\r\n...after two newlines\r\n ";
$result = quoted_printable_decode(Mime\Mime::encodeQuotedPrintable($text));
$this->assertContains("my body\r\n\r\n...after two newlines", $result, $result);
}

/**
* @group ZF-1688
* @group ZF-1688
* @dataProvider dataTestEncodeMailHeaderQuotedPrintable
*/
public function testEncodeMailHeaderQuotedPrintable($str, $charset, $result)
Expand All @@ -142,7 +130,7 @@ public static function dataTestEncodeMailHeaderQuotedPrintable()
}

/**
* @group ZF-1688
* @group ZF-1688
* @dataProvider dataTestEncodeMailHeaderBase64
*/
public function testEncodeMailHeaderBase64($str, $charset, $result)
Expand All @@ -167,39 +155,16 @@ public function testLineLengthInQuotedPrintableHeaderEncoding()
{
$subject = "Alle meine Entchen schwimmen in dem See, schwimmen in dem See, Köpfchen in das Wasser, Schwänzchen in die Höh!";
$encoded = Mime\Mime::encodeQuotedPrintableHeader($subject, "UTF-8", 100);
foreach(explode(Mime\Mime::LINEEND, $encoded) AS $line ) {
if(strlen($line) > 100) {
$this->fail("Line '".$line."' is ".strlen($line)." chars long, only 100 allowed.");
foreach (explode(Mime\Mime::LINEEND, $encoded) AS $line) {
if (strlen($line) > 100) {
$this->fail("Line '" . $line . "' is " . strlen($line) . " chars long, only 100 allowed.");
}
}
$encoded = Mime\Mime::encodeQuotedPrintableHeader($subject, "UTF-8", 40);
foreach(explode(Mime\Mime::LINEEND, $encoded) AS $line ) {
if(strlen($line) > 40) {
$this->fail("Line '".$line."' is ".strlen($line)." chars long, only 40 allowed.");
foreach (explode(Mime\Mime::LINEEND, $encoded) AS $line) {
if (strlen($line) > 40) {
$this->fail("Line '" . $line . "' is " . strlen($line) . " chars long, only 40 allowed.");
}
}
}
}


/**
* Mock mail transport class for testing Sendmail transport
*/
class SendmailTransportMock extends Mail\Transport\Sendmail
{
/**
* @var Zend_Mail
*/
public $mail = null;
public $from = null;
public $subject = null;
public $called = false;

public function _sendMail()
{
$this->mail = $this->_mail;
$this->from = $this->_mail->getFrom();
$this->subject = $this->_mail->getSubject();
$this->called = true;
}
}

0 comments on commit 86fe89b

Please sign in to comment.