Example #1
0
 public function getPlainText($content, $baseUrl)
 {
     $tmpFile = tempnam(sys_get_temp_dir(), 'html');
     file_put_contents($tmpFile, $content);
     $cmd = escapeshellcmd(Tx_Newsletter_Tools::confParam('path_to_lynx')) . ' -dump -stdin < ' . escapeshellarg($tmpFile);
     exec($cmd, $output);
     unlink($tmpFile);
     $plainText = implode("\n", $output);
     return $plainText;
 }
 /**
  * This method is designed to return some additional information about the task,
  * that may help to set it apart from other tasks from the same class
  * This additional information is used - for example - in the Scheduler's BE module
  * This method should be implemented in most task classes
  *
  * @return	string	Information to display
  */
 public function getAdditionalInformation()
 {
     $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Extbase_Object_ObjectManager');
     $newsletterRepository = $objectManager->get('Tx_Newsletter_Domain_Repository_NewsletterRepository');
     $emailNotSentCount = 0;
     $newsletters = $newsletterRepository->findAllReadyToSend();
     $newsletterCount = count($newsletters);
     foreach ($newsletters as $newsletter) {
         $emailNotSentCount += $newsletter->getEmailNotSentCount();
     }
     $emailsPerRound = Tx_Newsletter_Tools::confParam('mails_per_round');
     return Tx_Extbase_Utility_Localization::translate('task_send_emails_additional_information', 'newsletter', array($emailsPerRound, $emailNotSentCount, $newsletterCount));
 }
 /**
  * Fetch all email from Bounce Accounts and pipe each of them to cli/bounce.php
  */
 public static function fetchBouncedEmails()
 {
     // Check that th configured fetchmail is actually available
     $fetchmail = Tx_Newsletter_Tools::confParam('path_to_fetchmail');
     $foo = $exitStatus = null;
     exec("{$fetchmail} --version 2>&1", $foo, $exitStatus);
     if ($exitStatus) {
         throw new Exception("fetchmail is not available with path configured via Extension Manager '{$fetchmail}'. Install fetchmail or update configuration and try again.");
     }
     // Find all bounce accounts we need to check
     $content = '';
     $servers = array();
     $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Extbase_Object_ObjectManager');
     $bounceAccountRepository = $objectManager->get('Tx_Newsletter_Domain_Repository_BounceAccountRepository');
     foreach ($bounceAccountRepository->findAll() as $bounceAccount) {
         $server = $bounceAccount->getServer();
         $protocol = $bounceAccount->getProtocol();
         $username = $bounceAccount->getUsername();
         $password = $bounceAccount->getPassword();
         $content .= "poll {$server} proto {$protocol} username \"{$username}\" password \"{$password}\"\n";
         $servers[] = $server;
     }
     // Write a new fetchmailrc based on bounce accounts found
     $fetchmailhome = PATH_site . 'uploads/tx_newsletter';
     $fetchmailfile = "{$fetchmailhome}/fetchmailrc";
     file_put_contents($fetchmailfile, $content);
     chmod($fetchmailfile, 0600);
     putenv("FETCHMAILHOME={$fetchmailhome}");
     // Keep messages on server
     $keep = Tx_Newsletter_Tools::confParam('keep_messages') ? '--keep ' : '';
     // Execute fetchtmail and ask him to pipe emails to our cli/bounce.php
     $cli_dispatcher = PATH_typo3 . 'cli_dispatch.phpsh';
     // This needs to be the absolute path of /typo3/cli_dispatch.phpsh
     foreach ($servers as $server) {
         $cmd = "{$fetchmail} -s {$keep} -m \"{$cli_dispatcher} newsletter_bounce\" {$server}";
         exec($cmd);
     }
     unlink($fetchmailfile);
 }
 /**
  * Returns the URL of the content of this newsletter
  * @return string
  */
 public function getContentUrl($language = null)
 {
     $append_url = Tx_Newsletter_Tools::confParam('append_url');
     $domain = $this->getDomain();
     if (!is_null($language)) {
         $language = '&L=' . $language;
     }
     return "http://{$domain}/index.php?no_cache=1&id=" . $this->getPid() . $language . $append_url;
 }
 /**
  * Sends an email to the address configured in extension settings when a recipient unsubscribe
  * @param Tx_Newsletter_Domain_Model_Newsletter $newsletter
  * @param Tx_Newsletter_Domain_Model_RecipientList $recipientList
  * @param Tx_Newsletter_Domain_Model_Email $email
  * @return void
  */
 protected function notifyUnsubscribe($newsletter, $recipientList, Tx_Newsletter_Domain_Model_Email $email)
 {
     $notificationEmail = Tx_Newsletter_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 = Tx_Extbase_Utility_Localization::translate('unsubscribe_notification_subject', 'newsletter');
     $body = Tx_Extbase_Utility_Localization::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();
 }
Example #6
0
 /**
  * Run the spool from a browser
  * This has some limitations. No load balance. Different permissions. And should have a mails_per_round-value
  *
  * @global \TYPO3\CMS\Core\Database\DatabaseConnection $TYPO3_DB
  * @return    void
  */
 public static function runSpoolOne(Tx_Newsletter_Domain_Model_Newsletter $newsletter)
 {
     global $TYPO3_DB;
     /* Do we any limit to this session? */
     if ($mails_per_round = Tx_Newsletter_Tools::confParam('mails_per_round')) {
         $limit = " LIMIT 0, {$mails_per_round} ";
     }
     /* Find the receivers, select userdata, uid of target, uid of page, uid of logrecord */
     $rs = $TYPO3_DB->sql_query("SELECT tx_newsletter_domain_model_newsletter.uid, tx_newsletter_domain_model_email.uid\n\t\t\t\t\t\tFROM tx_newsletter_domain_model_email\n\t\t\t\t\t\tLEFT JOIN tx_newsletter_domain_model_newsletter ON (tx_newsletter_domain_model_email.newsletter = tx_newsletter_domain_model_newsletter.uid)\n\t\t\t\t\t\tWHERE tx_newsletter_domain_model_newsletter.uid = " . $newsletter->getUid() . "\n\t\t\t\t\t\tAND tx_newsletter_domain_model_email.begin_time = 0\n\t\t\t\t\t\tORDER BY tx_newsletter_domain_model_email.newsletter " . $limit);
     /* Do it, if there is any records */
     if ($numRows = $TYPO3_DB->sql_num_rows($rs)) {
         self::runSpool($rs);
     }
     return $numRows;
 }