/** * 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 { /** * Next strings fixes the problems * According to RFC 1522 (http://www.faqs.org/rfcs/rfc1522.html) */ $quotedValue = ''; $count = 1; for ($i = 0; strlen($value) > $i; $i++) { if ($value[$i] == '?' or $value[$i] == '_' or $value[$i] == ' ') { $quotedValue .= str_replace(array('?', ' ', '_'), array('=3F', '=20', '=5F'), $value[$i]); } else { $quotedValue .= $this->encodeQuotedPrintable($value[$i]); } if (strlen($quotedValue) > $count * \Zend_Mime::LINELENGTH) { $count++; $quotedValue .= "?=\n =?" . $this->_charset . '?Q?'; } } return '=?' . $this->_charset . '?Q?' . $quotedValue . '?='; } }
/** * 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 { $base64Value = base64_encode($value); return "=?" . $this->_charset . "?B?" . $base64Value . "?="; } }
/** * 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 . '?='; } }
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; }
/** * 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) === false) { if ($this->getHeaderEncoding() === Zend_Mime::ENCODING_QUOTEDPRINTABLE) { $value = Zend_Mime::encodeQuotedPrintableHeader($value, $this->getCharset(), Zend_Mime::LINELENGTH, Zend_Mime::LINEEND); } else { $value = Zend_Mime::encodeBase64Header($value, $this->getCharset(), Zend_Mime::LINELENGTH, Zend_Mime::LINEEND); } } return $value; }
public function testIsPrintable_isPrintable() { $this->assertTrue(Zend_Mime::isPrintable('Test without special chars')); }
/** * 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; } }
/** * Assertion that checks if a given mailing header string is RFC conform. * * @param string $header * @return void */ protected function assertMailHeaderConformsToRfc($header) { $this->numAssertions++; $parts = explode(Zend_Mime::LINEEND, $header); if (count($parts) > 0) { for ($i = 0; $i < count($parts); $i++) { if (preg_match('/(=?[a-z0-9-_]+\\?[q|b]{1}\\?)/i', $parts[$i], $matches)) { $dce = sprintf("=?%s", $matches[0]); // Check that Delimiter, Charset, Encoding are at the front of the string if (substr(trim($parts[$i]), 0, strlen($dce)) != $dce) { $this->fail(sprintf("Header-Part '%s' in line '%d' has missing or malformated delimiter, charset, encoding information.", $parts[$i], $i + 1)); } // check that the encoded word is not too long.); // this is only some kind of suggestion by the standard, in PHP its hard to hold it, so we do not enforce it here. /*if(strlen($parts[$i]) > 75) { $this->fail(sprintf( "Each encoded-word is only allowed to be 75 chars long, but line %d is %s chars long: %s", $i+1, strlen($parts[$i]), $parts[$i] )); }*/ // Check that the end-delmiter ?= is correctly placed if (substr(trim($parts[$i]), -2, 2) != "?=") { $this->fail(sprintf("Lines with an encoded-word have to end in ?=, but line %d does not: %s", $i + 1, substr(trim($parts[$i]), -2, 2))); } // Check that only one encoded-word can be found per line. if (substr_count($parts[$i], "=?") != 1) { $this->fail(sprintf("Only one encoded-word is allowed per line in the header. It seems line %d contains more: %s", $i + 1, $parts[$i])); } // Check that the encoded-text only contains US-ASCII chars, and no space $encodedText = substr(trim($parts[$i]), strlen($dce), -2); if (preg_match('/([\\s]+)/', $encodedText)) { $this->fail(sprintf("No whitespace characters allowed in encoded-text of line %d: %s", $i + 1, $parts[$i])); } for ($i = 0; $i < strlen($encodedText); $i++) { if (ord($encodedText[$i]) > 127) { $this->fail(sprintf("No non US-ASCII characters allowed, but line %d has them: %s", $i + 1, $parts[$i])); } } } else { if (Zend_Mime::isPrintable($parts[$i]) == false) { $this->fail(sprintf("Encoded-word in line %d contains non printable characters.", $i + 1)); } } } } }
public function testPrintable() { // check if isPrintable works right. $this->assertFalse(Zend_Mime::isPrintable('Test with special chars: дьяц÷')); $this->assertTrue(Zend_Mime::isPrintable('Test without special chars')); }