/** * Wait for newsletter sign out mail * * @param array $userAccount */ public function checkNewsletterSignOutMail($userAccount) { /* Check for mail */ $newsletterUnsubscribeTemplateSubject = $this->__('Newsletter unsubscription success'); // replace markers with information from $userAccount $subject = $newsletterUnsubscribeTemplateSubject; foreach ($userAccount as $key => $value) { $subject = str_replace('###' . strtoupper($key) . '###', $value, $subject); } $idx = $this->waitForMailWhoseSubjectContains($subject); $message = $this->getStorage()->getMessage($idx); $content = Zend_Mime_Decode::decodeQuotedPrintable($message->getContent()); $this->getStorage()->removeMessage($idx); $this->getTest()->assertContains('unsubscription success', $content); }
/** * @magentoDataFixture Magento/Wishlist/_files/wishlist.php */ public function testSendAction() { \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(\Magento\Framework\App\Area::AREA_FRONTEND); $request = ['form_key' => $this->_objectManager->get('Magento\\Framework\\Data\\Form\\FormKey')->getFormKey(), 'emails' => '*****@*****.**', 'message' => 'message', 'rss_url' => null]; $this->getRequest()->setPostValue($request); $this->_objectManager->get('Magento\\Framework\\Registry')->register('wishlist', $this->_objectManager->get('Magento\\Wishlist\\Model\\Wishlist')->loadByCustomerId(1)); $this->dispatch('wishlist/index/send'); /** @var \Magento\TestFramework\Mail\Template\TransportBuilderMock $transportBuilder */ $transportBuilder = $this->_objectManager->get('Magento\\TestFramework\\Mail\\Template\\TransportBuilderMock'); $actualResult = \Zend_Mime_Decode::decodeQuotedPrintable($transportBuilder->getSentMessage()->getBodyHtml()->getContent()); $this->assertStringMatchesFormat('%A' . $this->_customerViewHelper->getCustomerName($this->_customerSession->getCustomerDataObject()) . ' wants to share this Wish List%A', $actualResult); }
public function testDecodeString() { $is = Zend_Mime_Decode::decodeQuotedPrintable('=?UTF-8?Q?"Peter M=C3=BCller"?= <*****@*****.**>'); $should = iconv('UTF-8', iconv_get_encoding('internal_encoding'), '"Peter Müller" <*****@*****.**>'); $this->assertEquals($is, $should); }
public function testDecodeString() { $string = '"Peter M=C3=BCller" <*****@*****.**>'; $is = Zend_Mime_Decode::decodeQuotedPrintable($string); $should = quoted_printable_decode($string); $this->assertEquals($is, $should); }
/** * For mailgun api several additional options for mail sending are available * * decodes the Zend Zend_Mime::encodeQuotedPrintableHeader * * @see https://framework.zend.com/apidoc/1.9/Zend_Mime/Zend_Mime.html#methodencodeQuotedPrintable * * @param $str * @param string $charset * @return string */ protected function decodeZendQuotedPrintableHeader($str, $charset = 'utf-8') { $lines = explode(\Zend_Mime::LINEEND, $str); $result = ''; foreach ($lines as $line) { // matches lines that begins with "=?utf-8?Q?" and ends with "=?" if (preg_match('/^[ ]{0,1}=\\?' . preg_quote($charset) . '\\?Q\\?(.*)\\?=/', $line, $matches)) { $result .= \Zend_Mime_Decode::decodeQuotedPrintable($matches[1]); } else { $result .= \Zend_Mime_Decode::decodeQuotedPrintable($line); } } return $result; }
public function parseMessage($mail, $message, $i) { $response = array('message' => array('subject' => null, 'fromEmail' => null, 'message' => null, 'receiveDate' => null), 'attachments' => array()); // Get the UTC timestamp $timezone = date_default_timezone_get(); date_default_timezone_set('UTC'); $receiveDate = strtotime($message->date); date_default_timezone_set($timezone); // Get from $from = $message->from; $from = str_replace(array('<', '>'), '', $from); $from = explode(' ', $from); $from = array_pop($from); $response['message']['fromEmail'] = $from; // Get the message $messageBody = ''; $boundary = $message->getHeaderField('content-type', 'boundary'); if (stristr($message->contentType, 'text/')) { $messageBody = $mail->getRawContent($i); } else { if (stristr($message->contentType, 'multipart/')) { $messageParts = new Zend_Mail_Part(array('handler' => &$mail, 'id' => $i, 'headers' => $message->getHeaders())); // Get the messages's contents. When fetched it removes the // message $messageParts->getContent(); foreach ($messageParts as $partIndex => $part) { $attachment = array('ticketId' => null, 'replyId' => null, 'filename' => null, 'contentType' => null, 'content' => null); if ($partIndex === 1) { // Decode attachment's data $content = (string) $part; if ($part->headerExists('content-transfer-encoding') and $part->contentTransferEncoding === 'base64') { $content = base64_decode($content); } //-- If an email is set with html + attachment + text alternative, then zend doesn't pickup the sub boundary :( $sub_boundary = preg_match('([a-zA-Z0-9]{28})', $content, $sub_boundaries); if ($sub_boundary > 0) { $subparts = explode('--' . $sub_boundaries[0], $content); foreach ($subparts as $subpart) { if (stristr($subpart, 'text/html')) { $quoted = false; if (stristr($subpart, 'quoted-printable')) { $quoted = true; } $content = explode("\n\n", $subpart); array_shift($content); $content = implode("\n\n", $content); if ($quoted) { $content = Zend_Mime_Decode::decodeQuotedPrintable($content); // Gay ass word wrapping with hmtl is bad idea. $content = str_replace(array("=\n", '=3D'), array('', '='), $content); } } } } $content = nl2br($content); $messageBody = $content; } else { $attachment['contentType'] = $part->contentType; // Grab the filename $attachment['filename'] = $part->getHeaderField('content-type', 'name'); // Decode attachment's data $content = (string) $part; // TODO: Need to part before assuming it has a transfer encoding if ($part->contentTransferEncoding === 'base64') { $content = base64_decode($content); } // TODO: other encodings? $attachment['content'] = $content; array_push($response['attachments'], $attachment); } } } } $response['message']['subject'] = (string) $message->subject; $response['message']['fromDate'] = (string) $message->from; $response['message']['message'] = $messageBody; $response['message']['receiveDate'] = $receiveDate; return $response; }
/** * get content for mail whose content contains the given string and delete the mail then * * @param string $subjectContains * @param bool $useXPath * @param int $timeout * @param int $sleep * @return mixed string|DOMXPath */ public function getMailContent($subjectContains, $useXPath = false, $timeout = 100, $sleep = 10) { $idx = $this->waitForMailWhoseSubjectContains($subjectContains, $timeout, $sleep); $message = $this->getStorage()->getMessage($idx); $content = Zend_Mime_Decode::decodeQuotedPrintable($message->getContent()); $this->getTest()->assertNotEmpty($content); $this->getStorage()->removeMessage($idx); if ($useXPath) { preg_match('/<body.*<\\/body>/misU', $content, $match); $html = str_replace(array('<', '>'), array('<', '>'), htmlentities($match[0], ENT_NOQUOTES)); return new DOMXPath(DOMDocument::loadHTML($html)); } return $content; }