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

Mime: base64 encoded string must be multiple of 4 chars #2

Merged
merged 2 commits into from
Apr 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Mime.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ public static function encodeBase64($str,
$lineLength = self::LINELENGTH,
$lineEnd = self::LINEEND)
{
$lineLength = $lineLength - ($lineLength % 4);
return rtrim(chunk_split(base64_encode($str), $lineLength, $lineEnd));
}

Expand Down
21 changes: 21 additions & 0 deletions test/MimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,27 @@ public static function dataTestEncodeMailHeaderBase64()
);
}

/**
* base64 chunk are 4 chars long
* try to encode/decode with 4 line length
* @dataProvider dataTestEncodeMailHeaderBase64wrap
*/
public function testEncodeMailHeaderBase64wrap($str)
{
$this->assertEquals($str, Mime\Decode::decodeQuotedPrintable(Mime\Mime::encodeBase64Header($str, "UTF-8", 20)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you try to execute this test without "the fix"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were 2 failures:

1) ZendTest\Mime\MimeTest::testEncodeMailHeaderBase64wrap with data set #0 ('äöüäöüäöüäöüäö�...äöü')
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'äöüäöüäöüäöüäöüäöüäöü'
+'äöü=?UTF-8?B?6TDtsO8w6?= =?UTF-8?B?TDtsO8w6T?= =?UTF-8?B?DtsO8w6TD?= =?UTF-8?B?tsO8w6TDt?= =?UTF-8?B?sO8w6TDts?= ;'

.../zend-mime/test/MimeTest.php:142

2) ZendTest\Mime\MimeTest::testEncodeMailHeaderBase64wrap with data set #1 ('Alle meine Entchen schwimmen ... Höh!')
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'Alle meine Entchen schwimmen in dem See, schwimmen in dem See, Köpfchen in das Wasser, Schwänzchen in die Höh!'
+'Alle m=?UTF-8?B?WluZSBFbn?= =?UTF-8?B?RjaGVuIHN?= =?UTF-8?B?jaHdpbW1l?= n in d=?UTF-8?B?W0gU2VlLC?= =?UTF-8?B?BzY2h3aW1?= =?UTF-8?B?tZW4gaW4g?= dem Se=?UTF-8?B?SwgS8O2cG?= =?UTF-8?B?ZjaGVuIGl?= =?UTF-8?B?uIGRhcyBX?= asser,=?UTF-8?B?FNjaHfDpG?= =?UTF-8?B?56Y2hlbiB?= =?UTF-8?B?pbiBkaWUg?= Höh!'

.../zend-mime/test/MimeTest.php:142

$this->assertEquals($str, Mime\Decode::decodeQuotedPrintable(Mime\Mime::encodeBase64Header($str, "UTF-8", 21)));
$this->assertEquals($str, Mime\Decode::decodeQuotedPrintable(Mime\Mime::encodeBase64Header($str, "UTF-8", 22)));
$this->assertEquals($str, Mime\Decode::decodeQuotedPrintable(Mime\Mime::encodeBase64Header($str, "UTF-8", 23)));
}

public static function dataTestEncodeMailHeaderBase64wrap()
{
return array(
array("äöüäöüäöüäöüäöüäöüäöü"),
array("Alle meine Entchen schwimmen in dem See, schwimmen in dem See, Köpfchen in das Wasser, Schwänzchen in die Höh!")
);
}

public function testFromMessageMultiPart()
{
$message = Mime\Message::createFromMessage(
Expand Down