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

Issue Type: Bug Created: 2010-06-29T09:34:47.000+0000 Last Updated: 2012-05-12T19:13:05.000+0000 Status: Resolved Fix version(s): - 1.12.0 (27/Aug/12)

Reporter: Chad Morris (cmorrisrsg) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Mime

  • state:patch-ready-for-review
  • zf-caretaker-adamlundrigan
  • zf-crteam-review

Related issues: - ZF-11866

Attachments: - ZF-10074.patch


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:

<pre class="literal">
-        while ($str) {
+        while ($str != '') {


Posted by Steponas Dauginis (sk-lt) on 2011-05-24T12:44:59.000+0000

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

A test case:

<pre class="highlight">
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.

Posted by Adam Lundrigan (adamlundrigan) on 2011-11-07T15:27:14.000+0000

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.

Posted by Adam Lundrigan (adamlundrigan) on 2012-05-12T19:13:05.000+0000

Fixed in trunk (1.12.0): r24797

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.