ZF-10074: Zend_Mime improperly quoted printable encodes lines with zeros at the end

Description

If you have a line which is one character longer than the limit that ends with "0", Zend_Mime::encodeQuotedPrintable() will strip the character due to implicit numerical conversion.

example line: "\t\t\t\tyour own goal! Use those 90 minutes being active yourself. A 90" quoted result with a 74 character limit: "=09=09=09=09your own goal! Use those 90 minutes being active yourself. A 9" expected result: "=09=09=09=09your own goal! Use those 90 minutes being active yourself. A 9= 0"

To fix this you need to do an explicit comparison in the while($str) loop:

-        while ($str) {
+        while ($str != '') {

Comments

This is a major bug and it's still not fixed in trunk.

A test case:


Index: tests/Zend/MimeTest.php
===================================================================
--- tests/Zend/MimeTest.php (revision 11897)
+++ tests/Zend/MimeTest.php (working copy)
@@ -73,6 +73,15 @@
         $this->assertEquals(quoted_printable_decode($qp), $text);
     }
 
+    public function testQPWith0AtTheEnd()
+    {
+        $text = "Test test 123 Long line with 74 chars and 0 at the end: "
+              . "123456789pad pad0";
+
+        $qp = Zend_Mime::encodeQuotedPrintable($text);
+        $this->assertEquals($text, quoted_printable_decode($qp));
+    }
+
     public function testBase64()
     {
         $content = str_repeat("\x88\xAA\xAF\xBF\x29\x88\xAA\xAF\xBF\x29\x88\xAA\xAF", 4);

The suggested fix by Chad works correctly.

Patch with fix + unit tests attached. Implemented unit test using provided test cases: * ZF-10074, by [~sk-lt] * ZF-11866, by [~interrobang]

Fix suggested by OP resolves the issue, and all unit tests in the {{Zend_Mime}} and {{Zend_Mail}} suites pass after patch is applied.

Unless there is a demonstrable case where this fix breaks backwards-compatibility, I recommend inclusion in next mini-release.

Fixed in trunk (1.12.0): r24797