public function indexAction() { $this->_helper->viewRenderer->setNoRender(); //$value = 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩъыьЭЮЯ'; $value = 'いろはにほへとちりぬるをわかよたれそつねならむ'; echo "<pre>B-1. Zend_Mime::encodeBase64Header:<br>\r\n"; echo Zend_Mime::encodeBase64Header($value, $this->_charset, $this->_len, $this->_feed); echo "\r\n<br><br>"; echo "Q-1. Zend_Mime::encodeQuotedPrintableHeader:<br>\r\n"; echo Zend_Mime::encodeQuotedPrintableHeader($value, $this->_charset, $this->_len, $this->_feed); echo "\r\n<br><br>"; mb_internal_encoding($this->_charset); echo "B-2. Base64 by mb_encode_mimeheader:<br>\r\n"; echo mb_encode_mimeheader($value, $this->_charset, 'B', $this->_feed, $this->_len); echo "\r\n<br><br>"; echo "Q-2. QuotedPrintable by mb_encode_mimeheader:<br>\r\n"; echo mb_encode_mimeheader($value, $this->_charset, 'Q', $this->_feed, $this->_len); echo "</pre>\r\n"; }
/** * 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; }
/** * add attachments to mail * * @param Expressomail_mail $_mail * @param Expressomail_Model_Message $_message */ protected function _addAttachments(Expressomail_mail $_mail, Expressomail_Model_Message $_message) { if (!isset($_message->attachments) || empty($_message->attachments)) { return; } $size = 0; $tempFileBackend = Tinebase_TempFile::getInstance(); foreach ($_message->attachments as $attachment) { if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Adding attachment: ' . (is_object($attachment) ? print_r($attachment->toArray(), TRUE) : print_r($attachment, TRUE))); } if ($attachment['partId'] && $_message->original_id instanceof Expressomail_Model_Message) { $originlPart = $this->getMessagePart($_message->original_id, $attachment['partId']); switch ($originlPart->encoding) { case Zend_Mime::ENCODING_BASE64: $part = new Zend_Mime_Part(base64_decode(stream_get_contents($originlPart->getRawStream()))); $part->encoding = Zend_Mime::ENCODING_BASE64; break; case Zend_Mime::ENCODING_QUOTEDPRINTABLE: $part = new Zend_Mime_Part(quoted_printable_decode(stream_get_contents($originlPart->getRawStream()))); $part->encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE; break; default: $part = new Zend_Mime_Part(stream_get_contents($originlPart->getRawStream())); $part->encoding = null; break; } $name = $attachment['name']; $type = $attachment['type']; } else { $tempFile = $attachment instanceof Tinebase_Model_TempFile ? $attachment : (array_key_exists('tempFile', $attachment) ? $tempFileBackend->get($attachment['tempFile']['id']) : NULL); if ($tempFile === NULL) { continue; } if (!$tempFile->path) { Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Could not find attachment.'); continue; } // get contents from uploaded file $stream = fopen($tempFile->path, 'r'); $part = new Zend_Mime_Part($stream); // RFC822 attachments are not encoded, set all others to ENCODING_BASE64 $part->encoding = $tempFile->type == Expressomail_Model_Message::CONTENT_TYPE_MESSAGE_RFC822 ? null : Zend_Mime::ENCODING_BASE64; $name = $tempFile->name; $type = $tempFile->type; // try to detect the correct file type, on error fallback to the default application/octet-stream if ($tempFile->type == "undefined" || $tempFile->type == "unknown") { try { $finfo = finfo_open(FILEINFO_MIME_TYPE); $type = finfo_file($finfo, $tempFile->path); } catch (Exception $e) { $type = "application/octet-stream"; } try { finfo_close($finfo); } catch (Exception $e) { } } } $part->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; $name = Zend_Mime::encodeQuotedPrintableHeader(addslashes($name), 'utf-8'); $partTypeString = $type . '; name="' . $name . '"'; $part->type = $partTypeString; if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Adding attachment ' . $partTypeString); } $_mail->addAttachment($part); } }
/** * set part type and disposition (with name if available) * * @param string $type * @param string $name */ public function setTypeAndDispositionForAttachment($type, $name = NULL) { $this->disposition = Zend_Mime::DISPOSITION_ATTACHMENT; $partTypeString = $type; if ($name) { $name = Zend_Mime::encodeQuotedPrintableHeader($name, 'utf-8'); $partTypeString .= '; name="' . $name . '"'; $this->disposition .= '; filename="' . $name . '"'; } $this->type = $partTypeString; }
private function assertDateInSubject($period, $expectedDate) { $alerts = $this->getTriggeredAlerts(); Mail::setDefaultTransport(new \Zend_Mail_Transport_File()); $mail = new Mail(); $this->notifier->sendAlertsPerEmailToRecipient($alerts, $mail, '*****@*****.**', $period, 1); $expected = 'New alert for website Piwik test [' . $expectedDate . ']'; $expecteds = array($expected, \Zend_Mime::encodeQuotedPrintableHeader($expected, 'utf-8')); $isExpected = in_array($mail->getSubject(), $expecteds); $this->assertTrue($isExpected, $mail->getSubject() . " not found in " . var_export($expecteds, true)); }
/** * @group ZF-1688 */ public function testLineLengthInQuotedPrintableHeaderEncoding() { $subject = "Alle meine Entchen schwimmen in dem See, schwimmen in dem See, Köpfchen in das Wasser, Schwänzchen in die Höh!"; $encoded = Zend_Mime::encodeQuotedPrintableHeader($subject, "UTF-8", 100); foreach (explode(Zend_Mime::LINEEND, $encoded) as $line) { if (strlen($line) > 100) { $this->fail("Line '" . $line . "' is " . strlen($line) . " chars long, only 100 allowed."); } } $encoded = Zend_Mime::encodeQuotedPrintableHeader($subject, "UTF-8", 40); foreach (explode(Zend_Mime::LINEEND, $encoded) as $line) { if (strlen($line) > 40) { $this->fail("Line '" . $line . "' is " . strlen($line) . " chars long, only 40 allowed."); } } }