/** * Encode header fields * * Encodes header content according to RFC1522 if it contains non-printable * characters. * * @param string $value * @return string */ protected function _encodeHeader($value) { if (Zend_Mime::isPrintable($value)) { return $value; } else { $quotedValue = Zend_Mime::encodeQuotedPrintable($value, 400); $quotedValue = str_replace(array('?', ' ', '_'), array('=3F', '=20', '=5F'), $quotedValue); return '=?' . $this->_charset . '?Q?' . $quotedValue . '?='; } }
public function testQP() { $text = "This is a cool Test Text with special chars: дцья\n" . "and with multiple linesдцья some of the Lines are long, long" . ", long, long, long, long, long, long, long, long, long, long" . ", long, long, long, long, long, long, long, long, long, long" . ", long, long, long, long, long, long, long, long, long, long" . ", long, long, long, long and with дцья"; $qp = Zend_Mime::encodeQuotedPrintable($text); $this->assertEquals(quoted_printable_decode($qp), $text); }
protected function _encodeHeader($value) { if (Zend_Mime::isPrintable($value)) { return $value; } else { $quotedValue = Zend_Mime::encodeQuotedPrintable($value); $quotedValue = str_replace(array('?', ' '), array('=3F', '=20'), $quotedValue); $quotedValue = rawurlencode($quotedValue); $quotedValue = str_replace('%3D%0A', '', $quotedValue); $quotedValue = rawurldecode($quotedValue); $quotedValue = '=?' . $this->_charset . '?Q?' . $quotedValue . '?='; } return $quotedValue; }
/** * @param mixed $variableName * @param mixed $variableValue * @return string */ protected function encodeXdfnVariable($variableName, $variableValue) { if ($this->isReservedVariable($variableName)) { $variableName = '*' . $variableName; //reserved variables are prefixed } if ($variableName == '*parts') { $encoded = sprintf('%s=%s', $variableName, $variableValue); } else { $variableValue = addslashes($variableValue); $variableValue = Zend_Mime::encodeQuotedPrintable($variableValue, 4096); $variableValue = str_replace("\r", "", $variableValue); $variableValue = str_replace("\n", " ", $variableValue); $encoded = sprintf('%s="%s"', $variableName, $variableValue); } return $encoded; }
/** * Encode header fields * * Encodes header content according to RFC1522 if it contains non-printable * characters. * * @param string $value * @return string */ protected function _encodeHeader($value) { if (Zend_Mime::isPrintable($value)) { return $value; } elseif ($this->_encodingOfHeaders === Zend_Mime::ENCODING_QUOTEDPRINTABLE) { $quotedValue = Zend_Mime::encodeQuotedPrintable($value); $quotedValue = str_replace(array('?', ' ', '_'), array('=3F', '=20', '=5F'), $quotedValue); return '=?' . $this->_charset . '?Q?' . $quotedValue . '?='; } elseif ($this->_encodingOfHeaders === Zend_Mime::ENCODING_BASE64) { return '=?' . $this->_charset . '?B?' . Zend_Mime::encodeBase64($value) . '?='; } else { /** * @todo 7Bit and 8Bit is currently handled the same way. */ return $value; } }
$client = new Zend_Http_Client("http://de.wikipedia.org/w/index.php?title=PHP&printable=yes"); $string = $client->request()->getBody(); echo "===================================================================\n"; echo "RUNNING BENCHMARK\n"; echo "===================================================================\n"; echo "Starting encoding with imap_8bit() (" . LOOPS . " times)\n"; $startTime = microtime(true); for ($i = 0; $i < LOOPS; $i++) { imap_8bit($string); } $durationImap_8bit = microtime(true) - $startTime; echo "Duration: " . round($durationImap_8bit, 4) . " seconds\n\n"; echo "Starting encoding with Zend_Mime::encodeQuotedPrintable() (" . LOOPS . " times)\n"; $startTime = microtime(true); for ($i = 0; $i < LOOPS; $i++) { Zend_Mime::encodeQuotedPrintable($string, Zend_Mime::LINELENGTH, Zend_Mime::LINEEND); } $durationZendMime = microtime(true) - $startTime; echo "Duration: " . round($durationZendMime, 4) . " seconds\n\n"; echo "Starting encoding with quoted_printable_encode() (" . LOOPS . " times)\n"; $startTime = microtime(true); for ($i = 0; $i < LOOPS; $i++) { quoted_printable_encode($string); } $durationQPE = microtime(true) - $startTime; echo "Duration: " . round($durationQPE, 4) . " seconds\n\n"; echo "===================================================================\n"; echo "SUMMARY\n"; echo "===================================================================\n"; echo "imap_8bit() is " . round($durationZendMime - $durationImap_8bit, 4) . " seconds faster than Zend_Mime!\n"; echo "It is " . round($durationZendMime / $durationImap_8bit, 2) . " times faster\n\n";