Пример #1
0
 /**
  * Raw send method. This does not replace markers, or reset the mail afterwards.
  *
  * @param   array      Record with receivers information as name => value pairs.
  * @param   array      Array with extra headers to apply to mails as name => value pairs.
  * @return   void
  */
 private function raw_send(Email $email)
 {
     $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
     $message->setTo($email->getRecipientAddress())->setFrom(array($this->senderEmail => $this->senderName))->setSubject($this->title);
     if ($this->bounceAddress) {
         $message->setReturnPath($this->bounceAddress);
     }
     foreach ($this->attachments as $attachment) {
         $message->attach($attachment);
     }
     // Specify message-id for bounce identification
     $msgId = $message->getHeaders()->get('Message-ID');
     $msgId->setId($email->getAuthCode() . '@' . $this->newsletter->getDomain());
     // Build plaintext
     $plain = $this->getPlain();
     $recipientData = $email->getRecipientData();
     if ($recipientData['plain_only']) {
         $message->setBody($plain, 'text/plain');
     } else {
         // Attach inline files and replace markers used for URL
         foreach ($this->attachmentsEmbedded as $marker => $attachment) {
             $embeddedSrc = $message->embed($attachment);
             $plain = str_replace($marker, $embeddedSrc, $plain);
             $this->html = str_replace($marker, $embeddedSrc, $this->html);
         }
         $message->setBody($this->html, 'text/html');
         $message->addPart($plain, 'text/plain');
     }
     $message->send();
 }
Пример #2
0
 /**
  * Creates the Message object from our current state and returns it
  *
  * @param Email $email
  * @return \TYPO3\CMS\Core\Mail\MailMessage
  */
 public function createMessage(Email $email)
 {
     /* @var $message \TYPO3\CMS\Core\Mail\MailMessage  */
     $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);
     $message->setTo($email->getRecipientAddress())->setFrom([$this->senderEmail => $this->senderName])->setSubject($this->title);
     if ($this->replytoEmail) {
         $message->addReplyTo($this->replytoEmail, $this->replytoName);
     }
     $unsubscribeUrls = ['<' . $email->getUnsubscribeUrl() . '>'];
     if ($this->bounceAddress) {
         $message->setReturnPath($this->bounceAddress);
         array_unshift($unsubscribeUrls, '<mailto:' . $this->bounceAddress . '?subject=unsubscribe-' . $email->getAuthCode() . '>');
     }
     // Add header for easy unsubscribe, either by email, or standard URL
     $message->getHeaders()->addTextHeader('List-Unsubscribe', implode(', ', $unsubscribeUrls));
     $message->getHeaders()->addTextHeader('Precedence', 'bulk');
     foreach ($this->attachments as $attachment) {
         $message->attach($attachment);
     }
     // Specify message-id for bounce identification
     $msgId = $message->getHeaders()->get('Message-ID');
     $msgId->setId($email->getAuthCode() . '@' . $this->newsletter->getDomain());
     // Build plaintext
     $plain = $this->getPlain();
     $recipientData = $email->getRecipientData();
     if ($recipientData['plain_only']) {
         $message->setBody($plain, 'text/plain');
     } else {
         // Attach inline files and replace markers used for URL
         foreach ($this->attachmentsEmbedded as $marker => $attachment) {
             $embeddedSrc = $message->embed($attachment);
             $plain = str_replace($marker, $embeddedSrc, $plain);
             $this->html = str_replace($marker, $embeddedSrc, $this->html);
         }
         $message->setBody($this->html, 'text/html');
         $message->addPart($plain, 'text/plain');
     }
     return $message;
 }
Пример #3
0
 /**
  * Sends an email to the address configured in extension settings when a recipient unsubscribe
  * @param \Ecodev\Newsletter\Domain\Model\Newsletter $newsletter
  * @param \Ecodev\Newsletter\Domain\Model\RecipientList $recipientList
  * @param \Ecodev\Newsletter\Domain\Model\Email $email
  * @return void
  */
 protected function notifyUnsubscribe($newsletter, $recipientList, Email $email)
 {
     $notificationEmail = Tools::confParam('notification_email');
     // Use the page-owner as user
     if ($notificationEmail == 'user') {
         $rs = $GLOBALS['TYPO3_DB']->sql_query("SELECT email\n\t\t\tFROM be_users\n\t\t\tLEFT JOIN pages ON be_users.uid = pages.perms_userid\n\t\t\tWHERE pages.uid = " . $newsletter->getPid());
         list($notificationEmail) = $GLOBALS['TYPO3_DB']->sql_fetch_row($rs);
     }
     // If cannot find valid email, don't send any notification
     if (!\TYPO3\CMS\Core\Utility\GeneralUtility::validEmail($notificationEmail)) {
         return;
     }
     // Build email texts
     $baseUrl = 'http://' . $newsletter->getDomain();
     $urlRecipient = $baseUrl . '/typo3/alt_doc.php?&edit[tx_newsletter_domain_model_email][' . $email->getUid() . ']=edit';
     $urlRecipientList = $baseUrl . '/typo3/alt_doc.php?&edit[tx_newsletter_domain_model_recipientlist][' . $recipientList->getUid() . ']=edit';
     $urlNewsletter = $baseUrl . '/typo3/alt_doc.php?&edit[tx_newsletter_domain_model_newsletter][' . $newsletter->getUid() . ']=edit';
     $subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('unsubscribe_notification_subject', 'newsletter');
     $body = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('unsubscribe_notification_body', 'newsletter', array($email->getRecipientAddress(), $urlRecipient, $recipientList->getTitle(), $urlRecipientList, $newsletter->getTitle(), $urlNewsletter));
     // Actually sends email
     $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
     $message->setTo($notificationEmail)->setFrom(array($newsletter->getSenderEmail() => $newsletter->getSenderName()))->setSubject($subject)->setBody($body, 'text/html');
     $message->send();
 }
Пример #4
0
 /**
  * Returns the content of the newsletter with validation messages. The content
  * is also "fixed" automatically when possible.
  * @param Newsletter $newsletter
  * @param string $language language of the content of the newsletter (the 'L' parameter in TYPO3 URL)
  * @return array ('content' => $content, 'errors' => $errors, 'warnings' => $warnings, 'infos' => $infos);
  */
 public function validate(Newsletter $newsletter, $language = null)
 {
     $this->initializeLang();
     // We need to catch the exception if domain was not found/configured properly
     try {
         $url = $newsletter->getContentUrl($language);
     } catch (Exception $e) {
         return array('content' => '', 'errors' => array($e->getMessage()), 'warnings' => array(), 'infos' => array());
     }
     $content = $this->getURL($url);
     $errors = array();
     $warnings = array();
     $infos = array(sprintf($this->lang->getLL('validation_content_url'), $url));
     // Content should be more that just a few characters. Apache error propably occured
     if (strlen($content) < 200) {
         $errors[] = $this->lang->getLL('validation_mail_too_short');
     }
     // Content should not contain PHP-Warnings
     if (substr($content, 0, 22) == "<br />\n<b>Warning</b>:") {
         $errors[] = $this->lang->getLL('validation_mail_contains_php_warnings');
     }
     // Content should not contain PHP-Warnings
     if (substr($content, 0, 26) == "<br />\n<b>Fatal error</b>:") {
         $errors[] = $this->lang->getLL('validation_mail_contains_php_errors');
     }
     // If the page contains a "Pages is being generared" text... this is bad too
     if (strpos($content, 'Page is being generated.') && strpos($content, 'If this message does not disappear within')) {
         $errors[] = $this->lang->getLL('validation_mail_being_generated');
     }
     // Find out the absolute domain. If specified in HTML source, use it as is.
     if (preg_match('|<base[^>]*href="([^"]*)"[^>]*/>|i', $content, $match)) {
         $absoluteDomain = $match[1];
     } else {
         $absoluteDomain = 'http://' . $newsletter->getDomain() . '/';
     }
     // Fix relative URL to absolute URL
     $urlPatterns = array('hyperlinks' => '/<a [^>]*href="(.*)"/Ui', 'stylesheets' => '/<link [^>]*href="(.*)"/Ui', 'images' => '/ src="(.*)"/Ui', 'background images' => '/ background="(.*)"/Ui');
     foreach ($urlPatterns as $type => $urlPattern) {
         preg_match_all($urlPattern, $content, $urls);
         $replacementCount = 0;
         foreach ($urls[1] as $i => $url) {
             // If this is already an absolute link, dont replace it
             $decodedUrl = html_entity_decode($url);
             if (!Uri::isAbsolute($decodedUrl)) {
                 $replace_url = str_replace($decodedUrl, $absoluteDomain . ltrim($decodedUrl, '/'), $urls[0][$i]);
                 $content = str_replace($urls[0][$i], $replace_url, $content);
                 $replacementCount++;
             }
         }
         if ($replacementCount) {
             $infos[] = sprintf($this->lang->getLL('validation_mail_converted_relative_url'), $type);
         }
     }
     // Find linked css and convert into a style-tag
     preg_match_all('|<link rel="stylesheet" type="text/css" href="([^"]+)"[^>]+>|Ui', $content, $urls);
     foreach ($urls[1] as $i => $url) {
         $content = str_replace($urls[0][$i], "<!-- fetched URL: {$url} -->\n<style type=\"text/css\">\n<!--\n" . $this->getURL($url) . "\n-->\n</style>", $content);
     }
     if (count($urls[1])) {
         $infos[] = $this->lang->getLL('validation_mail_contains_linked_styles');
     }
     // We cant very well have attached javascript in a newsmail ... removing
     $content = preg_replace('|<script[^>]*type="text/javascript"[^>]*>[^<]*</script>|i', '', $content, -1, $count);
     if ($count) {
         $warnings[] = $this->lang->getLL('validation_mail_contains_javascript');
     }
     // Images in CSS
     if (preg_match('|background-image: url\\([^\\)]+\\)|', $content) || preg_match('|list-style-image: url\\([^\\)]+\\)|', $content)) {
         $errors[] = $this->lang->getLL('validation_mail_contains_css_images');
     }
     // CSS-classes
     if (preg_match('|<[a-z]+ [^>]*class="[^"]+"[^>]*>|', $content)) {
         $warnings[] = $this->lang->getLL('validation_mail_contains_css_classes');
     }
     // Positioning & element sizes in CSS
     $forbiddenCssProperties = array('width' => '((min|max)+-)?width', 'height' => '((min|max)+-)?height', 'margin' => 'margin(-(bottom|left|right|top)+)?', 'padding' => 'padding(-(bottom|left|right|top)+)?', 'position' => 'position');
     $forbiddenCssPropertiesWarnings = array();
     if (preg_match_all('|<[a-z]+[^>]+style="([^"]*)"|', $content, $matches)) {
         foreach ($matches[1] as $stylepart) {
             foreach ($forbiddenCssProperties as $property => $regex) {
                 if (preg_match('/(^|[^\\w-])' . $regex . '[^\\w-]/', $stylepart)) {
                     $forbiddenCssPropertiesWarnings[$property] = $property;
                 }
             }
         }
         foreach ($forbiddenCssPropertiesWarnings as $property) {
             $warnings[] = sprintf($this->lang->getLL('validation_mail_contains_css_some_property'), $property);
         }
     }
     return array('content' => $content, 'errors' => $errors, 'warnings' => $warnings, 'infos' => $infos);
 }