/**
  * Convert HTML emoji to unicode bytes
  *
  * @param array|string $content
  *
  * @return array|string
  */
 public function reverseTransform($content)
 {
     if (is_array($content)) {
         foreach ($content as &$convert) {
             $convert = $this->reverseTransform($convert);
         }
     } else {
         $content = EmojiHelper::toEmoji($content);
     }
     return $content;
 }
Example #2
0
 /**
  * @param $hash
  * @param $subject
  * @param $body
  */
 public function saveCopy($hash, $subject, $body)
 {
     $db = $this->getEntityManager()->getConnection();
     try {
         $body = EmojiHelper::toShort($body);
         $subject = EmojiHelper::toShort($subject);
         $db->insert(MAUTIC_TABLE_PREFIX . 'email_copies', ['id' => $hash, 'body' => $body, 'subject' => $subject, 'date_created' => (new \DateTime())->setTimezone(new \DateTimeZone('UTC'))->format('Y-m-d H:i:s')]);
         return true;
     } catch (\Exception $e) {
         error_log($e);
         return false;
     }
 }
Example #3
0
 /**
  * Preview email
  *
  * @param $objectId
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function previewAction($objectId)
 {
     /** @var \Mautic\EmailBundle\Model\EmailModel $model */
     $model = $this->factory->getModel('email');
     $emailEntity = $model->getEntity($objectId);
     if ($this->factory->getSecurity()->isAnonymous() && !$emailEntity->isPublished() || !$this->factory->getSecurity()->isAnonymous() && !$this->factory->getSecurity()->hasEntityAccess('email:emails:viewown', 'email:emails:viewother', $emailEntity->getCreatedBy())) {
         return $this->accessDenied();
     }
     //bogus ID
     $idHash = 'xxxxxxxxxxxxxx';
     $template = $emailEntity->getTemplate();
     if (!empty($template)) {
         $slots = $this->factory->getTheme($template)->getSlots('email');
         $response = $this->render('MauticEmailBundle::public.html.php', array('inBrowser' => true, 'slots' => $slots, 'content' => $emailEntity->getContent(), 'email' => $emailEntity, 'lead' => null, 'template' => $template));
         //replace tokens
         $content = $response->getContent();
     } else {
         $content = $emailEntity->getCustomHtml();
     }
     // Convert emojis
     $content = EmojiHelper::toEmoji($content, 'short');
     // Override tracking_pixel
     $tokens = array('{tracking_pixel}' => '');
     // Prepare a fake lead
     /** @var \Mautic\LeadBundle\Model\FieldModel $fieldModel */
     $fieldModel = $this->factory->getModel('lead.field');
     $fields = $fieldModel->getFieldList(false, false);
     array_walk($fields, function (&$field) {
         $field = "[{$field}]";
     });
     $fields['id'] = 0;
     // Generate and replace tokens
     $event = new EmailSendEvent(null, array('content' => $content, 'email' => $emailEntity, 'idHash' => $idHash, 'tokens' => $tokens, 'internalSend' => true, 'lead' => $fields));
     $this->factory->getDispatcher()->dispatch(EmailEvents::EMAIL_ON_DISPLAY, $event);
     $content = $event->getContent(true);
     return new Response($content);
 }
Example #4
0
 /**
  * @param int $objectId
  *
  * @return JsonResponse
  */
 protected function emailAction($objectId = 0)
 {
     $valid = $cancelled = false;
     /** @var \Mautic\LeadBundle\Model\LeadModel $model */
     $model = $this->factory->getModel('lead');
     /** @var \Mautic\LeadBundle\Entity\Lead $lead */
     $lead = $model->getEntity($objectId);
     if ($lead === null || !$this->factory->getSecurity()->hasEntityAccess('lead:leads:viewown', 'lead:leads:viewother', $lead->getOwner())) {
         return $this->modalAccessDenied();
     }
     $leadFields = $model->flattenFields($lead->getFields());
     $leadFields['id'] = $lead->getId();
     $leadEmail = $leadFields['email'];
     $leadName = $leadFields['firstname'] . ' ' . $leadFields['lastname'];
     $inList = $this->request->getMethod() == 'GET' ? $this->request->get('list', 0) : $this->request->request->get('lead_quickemail[list]', 0, true);
     $email = array('list' => $inList);
     $action = $this->generateUrl('mautic_lead_action', array('objectAction' => 'email', 'objectId' => $objectId));
     $form = $this->get('form.factory')->create('lead_quickemail', $email, array('action' => $action));
     if ($this->request->getMethod() == 'POST') {
         $valid = false;
         if (!($cancelled = $this->isFormCancelled($form))) {
             if ($valid = $this->isFormValid($form)) {
                 $email = $form->getData();
                 $bodyCheck = trim(strip_tags($email['body']));
                 if (!empty($bodyCheck)) {
                     $mailer = $this->factory->getMailer();
                     // To lead
                     $mailer->addTo($leadEmail, $leadName);
                     // From user
                     $user = $this->factory->getUser();
                     $mailer->setFrom($email['from'], strtolower($user->getEmail()) !== strtolower($email['from']) ? null : $user->getFirstName() . ' ' . $user->getLastName());
                     // Set Content
                     BuilderTokenHelper::replaceVisualPlaceholdersWithTokens($email['body']);
                     $mailer->setBody($email['body']);
                     $mailer->parsePlainText($email['body']);
                     // Set lead
                     $mailer->setLead($leadFields);
                     $mailer->setIdHash();
                     $mailer->setSubject($email['subject']);
                     // Ensure safe emoji for notification
                     $subject = EmojiHelper::toHtml($email['subject']);
                     if ($mailer->send(true)) {
                         $mailer->createLeadEmailStat();
                         $this->addFlash('mautic.lead.email.notice.sent', array('%subject%' => $subject, '%email%' => $leadEmail));
                     } else {
                         $this->addFlash('mautic.lead.email.error.failed', array('%subject%' => $subject, '%email%' => $leadEmail));
                         $valid = false;
                     }
                 } else {
                     $form['body']->addError(new FormError($this->get('translator')->trans('mautic.lead.email.body.required', array(), 'validators')));
                     $valid = false;
                 }
             }
         }
     }
     if (empty($leadEmail) || $valid || $cancelled) {
         if ($inList) {
             $route = 'mautic_lead_index';
             $viewParameters = array('page' => $this->factory->getSession()->get('mautic.lead.page', 1));
             $func = 'index';
         } else {
             $route = 'mautic_lead_action';
             $viewParameters = array('objectAction' => 'view', 'objectId' => $objectId);
             $func = 'view';
         }
         return $this->postActionRedirect(array('returnUrl' => $this->generateUrl($route, $viewParameters), 'viewParameters' => $viewParameters, 'contentTemplate' => 'MauticLeadBundle:Lead:' . $func, 'passthroughVars' => array('mauticContent' => 'lead', 'closeModal' => 1)));
     }
     return $this->ajaxAction(array('contentTemplate' => 'MauticLeadBundle:Lead:email.html.php', 'viewParameters' => array('form' => $form->createView()), 'passthroughVars' => array('mauticContent' => 'leadEmail', 'route' => false)));
 }
Example #5
0
 /**
  * @deprecated 1.2.3 - to be removed in 2.0
  *
  * @param mixed $copy
  *
  * @return Stat
  */
 public function setCopy($copy)
 {
     // Ensure it's clean of emoji
     $copy = EmojiHelper::toShort($copy);
     $this->copy = $copy;
     return $this;
 }
Example #6
0
 /**
  * Process if an email is resent.
  *
  * @param Events\QueueEmailEvent $event
  */
 public function onEmailResend(Events\QueueEmailEvent $event)
 {
     $message = $event->getMessage();
     if (isset($message->leadIdHash)) {
         $stat = $this->emailModel->getEmailStatus($message->leadIdHash);
         if ($stat !== null) {
             $stat->upRetryCount();
             $retries = $stat->getRetryCount();
             if (true || $retries > 3) {
                 //tried too many times so just fail
                 $reason = $this->translator->trans('mautic.email.dnc.retries', ['%subject%' => EmojiHelper::toShort($message->getSubject())]);
                 $this->emailModel->setDoNotContact($stat, $reason);
             } else {
                 //set it to try again
                 $event->tryAgain();
             }
             $this->em->persist($stat);
             $this->em->flush();
         }
     }
 }
Example #7
0
$percent = $progress[1] ? ceil($progress[0] / $progress[1] * 100) : 100;
$id = $status != 'inprogress' ? 'emailSendProgressComplete' : 'emailSendProgress';
?>

<div class="row ma-lg email-send-progress" id="<?php 
echo $id;
?>
">
    <div class="col-sm-offset-3 col-sm-6 text-center">
        <div class="panel panel-<?php 
echo $status != 'inprogress' ? 'success' : 'danger';
?>
">
            <div class="panel-heading">
                <h4 class="panel-title"><?php 
echo $view['translator']->trans('mautic.email.send.' . $status, ['%subject%' => \Mautic\CoreBundle\Helper\EmojiHelper::toHtml($email->getSubject(), 'short')]);
?>
</h4>
            </div>
            <div class="panel-body">
                <?php 
if ($status != 'inprogress') {
    ?>
                <h4><?php 
    echo $view['translator']->trans('mautic.email.send.stats', ['%sent%' => $stats['sent'], '%failed%' => $stats['failed']]);
    ?>
</h4>
                <?php 
}
?>
                <div class="progress mt-md" style="height:50px;">
Example #8
0
 /**
  * Preview email.
  *
  * @param $objectId
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function previewAction($objectId)
 {
     /** @var \Mautic\EmailBundle\Model\EmailModel $model */
     $model = $this->getModel('email');
     $emailEntity = $model->getEntity($objectId);
     if ($emailEntity === null) {
         return $this->notFound();
     }
     if ($this->get('mautic.security')->isAnonymous() && !$emailEntity->isPublished() || !$this->get('mautic.security')->isAnonymous() && !$this->get('mautic.security')->hasEntityAccess('email:emails:viewown', 'email:emails:viewother', $emailEntity->getCreatedBy())) {
         return $this->accessDenied();
     }
     //bogus ID
     $idHash = 'xxxxxxxxxxxxxx';
     $BCcontent = $emailEntity->getContent();
     $content = $emailEntity->getCustomHtml();
     if (empty($content) && !empty($BCcontent)) {
         $template = $emailEntity->getTemplate();
         $slots = $this->factory->getTheme($template)->getSlots('email');
         $assetsHelper = $this->factory->getHelper('template.assets');
         $assetsHelper->addCustomDeclaration('<meta name="robots" content="noindex">');
         $this->processSlots($slots, $emailEntity);
         $logicalName = $this->factory->getHelper('theme')->checkForTwigTemplate(':' . $template . ':email.html.php');
         $response = $this->render($logicalName, ['inBrowser' => true, 'slots' => $slots, 'content' => $emailEntity->getContent(), 'email' => $emailEntity, 'lead' => null, 'template' => $template]);
         //replace tokens
         $content = $response->getContent();
     }
     // Convert emojis
     $content = EmojiHelper::toEmoji($content, 'short');
     // Override tracking_pixel
     $tokens = ['{tracking_pixel}' => ''];
     // Prepare a fake lead
     /** @var \Mautic\LeadBundle\Model\FieldModel $fieldModel */
     $fieldModel = $this->getModel('lead.field');
     $fields = $fieldModel->getFieldList(false, false);
     array_walk($fields, function (&$field) {
         $field = "[{$field}]";
     });
     $fields['id'] = 0;
     // Generate and replace tokens
     $event = new EmailSendEvent(null, ['content' => $content, 'email' => $emailEntity, 'idHash' => $idHash, 'tokens' => $tokens, 'internalSend' => true, 'lead' => $fields]);
     $this->dispatcher->dispatch(EmailEvents::EMAIL_ON_DISPLAY, $event);
     $content = $event->getContent(true);
     return new Response($content);
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function getPublicActivity($identifier, &$socialCache)
 {
     if ($id = $this->getUserId($identifier, $socialCache)) {
         //due to the way Twitter filters, get more than 10 tweets
         $data = $this->makeRequest($this->getApiUrl("/statuses/user_timeline"), array('user_id' => $id, 'exclude_replies' => 'true', 'count' => 25, 'trim_user' => 'true'));
         if (!empty($data) && count($data)) {
             $socialCache['has']['activity'] = true;
             $socialCache['activity'] = array('tweets' => array(), 'photos' => array(), 'tags' => array());
             foreach ($data as $k => $d) {
                 if ($k == 10) {
                     break;
                 }
                 $tweet = array('tweet' => EmojiHelper::toHtml($d['text']), 'url' => "https://twitter.com/{$id}/status/{$d['id']}", 'coordinates' => $d['coordinates'], 'published' => $d['created_at']);
                 $socialCache['activity']['tweets'][] = $tweet;
                 //images
                 if (isset($d['entities']['media'])) {
                     foreach ($d['entities']['media'] as $m) {
                         if ($m['type'] == 'photo') {
                             $photo = array('url' => isset($m['media_url_https']) ? $m['media_url_https'] : $m['media_url']);
                             $socialCache['activity']['photos'][] = $photo;
                         }
                     }
                 }
                 //hastags
                 if (isset($d['entities']['hashtags'])) {
                     foreach ($d['entities']['hashtags'] as $h) {
                         if (isset($socialCache['activity']['tags'][$h['text']])) {
                             $socialCache['activity']['tags'][$h['text']]['count']++;
                         } else {
                             $socialCache['activity']['tags'][$h['text']] = array('count' => 1, 'url' => 'https://twitter.com/search?q=%23' . $h['text']);
                         }
                     }
                 }
             }
         }
     }
 }
Example #10
0
 /**
  * @param $content
  *
  * @return $this
  */
 public function setContent($content)
 {
     // Ensure safe emoji
     $content = EmojiHelper::toShort($content);
     $this->isChanged('content', $content);
     $this->content = $content;
     return $this;
 }
Example #11
0
 /**
  * @param int $objectId
  *
  * @return JsonResponse
  */
 public function emailAction($objectId = 0)
 {
     $valid = $cancelled = false;
     /** @var \Mautic\LeadBundle\Model\LeadModel $model */
     $model = $this->getModel('lead');
     /** @var \Mautic\LeadBundle\Entity\Lead $lead */
     $lead = $model->getEntity($objectId);
     if ($lead === null || !$this->get('mautic.security')->hasEntityAccess('lead:leads:viewown', 'lead:leads:viewother', $lead->getPermissionUser())) {
         return $this->modalAccessDenied();
     }
     $leadFields = $lead->getProfileFields();
     $leadFields['id'] = $lead->getId();
     $leadEmail = $leadFields['email'];
     $leadName = $leadFields['firstname'] . ' ' . $leadFields['lastname'];
     // Set onwer ID to be the current user ID so it will use his signature
     $leadFields['owner_id'] = $this->get('mautic.helper.user')->getUser()->getId();
     // Check if lead has a bounce status
     /** @var \Mautic\EmailBundle\Model\EmailModel $emailModel */
     $emailModel = $this->getModel('email');
     $dnc = $emailModel->getRepository()->checkDoNotEmail($leadEmail);
     $inList = $this->request->getMethod() == 'GET' ? $this->request->get('list', 0) : $this->request->request->get('lead_quickemail[list]', 0, true);
     $email = ['list' => $inList];
     $action = $this->generateUrl('mautic_contact_action', ['objectAction' => 'email', 'objectId' => $objectId]);
     $form = $this->get('form.factory')->create('lead_quickemail', $email, ['action' => $action]);
     if ($this->request->getMethod() == 'POST') {
         $valid = false;
         if (!($cancelled = $this->isFormCancelled($form))) {
             if ($valid = $this->isFormValid($form)) {
                 $email = $form->getData();
                 $bodyCheck = trim(strip_tags($email['body']));
                 if (!empty($bodyCheck)) {
                     $mailer = $this->get('mautic.helper.mailer')->getMailer();
                     // To lead
                     $mailer->addTo($leadEmail, $leadName);
                     // From user
                     $user = $this->get('mautic.helper.user')->getUser();
                     $mailer->setFrom($email['from'], empty($email['fromname']) ? '' : $email['fromname']);
                     // Set Content
                     BuilderTokenHelper::replaceVisualPlaceholdersWithTokens($email['body']);
                     $mailer->setBody($email['body']);
                     $mailer->parsePlainText($email['body']);
                     // Set lead
                     $mailer->setLead($leadFields);
                     $mailer->setIdHash();
                     $mailer->setSubject($email['subject']);
                     // Ensure safe emoji for notification
                     $subject = EmojiHelper::toHtml($email['subject']);
                     if ($mailer->send(true, false, false)) {
                         $mailer->createEmailStat();
                         $this->addFlash('mautic.lead.email.notice.sent', ['%subject%' => $subject, '%email%' => $leadEmail]);
                     } else {
                         $errors = $mailer->getErrors();
                         // Unset the array of failed email addresses
                         if (isset($errors['failures'])) {
                             unset($errors['failures']);
                         }
                         $form->addError(new FormError($this->get('translator')->trans('mautic.lead.email.error.failed', ['%subject%' => $subject, '%email%' => $leadEmail, '%error%' => is_array($errors) ? implode('<br />', $errors) : $errors], 'flashes')));
                         $valid = false;
                     }
                 } else {
                     $form['body']->addError(new FormError($this->get('translator')->trans('mautic.lead.email.body.required', [], 'validators')));
                     $valid = false;
                 }
             }
         }
     }
     if (empty($leadEmail) || $valid || $cancelled) {
         if ($inList) {
             $route = 'mautic_contact_index';
             $viewParameters = ['page' => $this->get('session')->get('mautic.lead.page', 1)];
             $func = 'index';
         } else {
             $route = 'mautic_contact_action';
             $viewParameters = ['objectAction' => 'view', 'objectId' => $objectId];
             $func = 'view';
         }
         return $this->postActionRedirect(['returnUrl' => $this->generateUrl($route, $viewParameters), 'viewParameters' => $viewParameters, 'contentTemplate' => 'MauticLeadBundle:Lead:' . $func, 'passthroughVars' => ['mauticContent' => 'lead', 'closeModal' => 1]]);
     }
     return $this->ajaxAction(['contentTemplate' => 'MauticLeadBundle:Lead:email.html.php', 'viewParameters' => ['form' => $form->createView(), 'dnc' => $dnc], 'passthroughVars' => ['mauticContent' => 'leadEmail', 'route' => false]]);
 }
Example #12
0
$customButtons[] = array('attr' => array('data-toggle' => 'ajax', 'href' => $view['router']->generate('mautic_email_action', array('objectAction' => 'example', 'objectId' => $email->getId()))), 'iconClass' => 'fa fa-send', 'btnText' => 'mautic.email.send.example');
$customButtons[] = array('attr' => array('data-toggle' => 'ajax', 'href' => $view['router']->generate('mautic_email_action', array("objectAction" => "clone", "objectId" => $email->getId()))), 'iconClass' => 'fa fa-copy', 'btnText' => 'mautic.core.form.clone');
$view['slots']->set('actions', $view->render('MauticCoreBundle:Helper:page_actions.html.php', array('item' => $email, 'templateButtons' => array('edit' => $edit, 'delete' => $security->hasEntityAccess($permissions['email:emails:deleteown'], $permissions['email:emails:deleteother'], $email->getCreatedBy()), 'abtest' => !$isVariant && $edit && $permissions['email:emails:create']), 'routeBase' => 'email', 'preCustomButtons' => $customButtons)));
?>

<!-- start: box layout -->
<div class="box-layout">
    <!-- left section -->
    <div class="col-md-9 bg-white height-auto">
        <div class="bg-auto">
            <!-- email detail header -->
            <div class="pr-md pl-md pt-lg pb-lg">
                <div class="box-layout">
                    <div class="col-xs-10">
                        <div><?php 
echo \Mautic\CoreBundle\Helper\EmojiHelper::toHtml($email->getSubject(), 'short');
?>
</div>
                        <div class="text-muted"><?php 
echo $email->getDescription();
?>
</div>
                    </div>
                    <div class="col-xs-2 text-right">
                        <?php 
echo $view->render('MauticCoreBundle:Helper:publishstatus_badge.html.php', array('entity' => $email));
?>
                    </div>
                </div>
            </div>
            <!--/ email detail header -->
Example #13
0
 /**
  * Activate the builder.
  *
  * @param $objectId
  *
  * @return array|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|Response
  *
  * @throws \Exception
  * @throws \Mautic\CoreBundle\Exception\FileNotFoundException
  */
 public function builderAction($objectId)
 {
     /** @var \Mautic\EmailBundle\Model\EmailModel $model */
     $model = $this->getModel('email');
     //permission check
     if (strpos($objectId, 'new') !== false) {
         $isNew = true;
         if (!$this->get('mautic.security')->isGranted('email:emails:create')) {
             return $this->accessDenied();
         }
         $entity = $model->getEntity();
         $entity->setSessionId($objectId);
     } else {
         $isNew = false;
         $entity = $model->getEntity($objectId);
         if ($entity == null || !$this->get('mautic.security')->hasEntityAccess('email:emails:viewown', 'email:emails:viewother', $entity->getCreatedBy())) {
             return $this->accessDenied();
         }
     }
     $template = InputHelper::clean($this->request->query->get('template'));
     $slots = $this->factory->getTheme($template)->getSlots('email');
     //merge any existing changes
     $newContent = $this->get('session')->get('mautic.emailbuilder.' . $objectId . '.content', []);
     $content = $entity->getContent();
     if (is_array($newContent)) {
         $content = array_merge($content, $newContent);
         // Update the content for processSlots
         $entity->setContent($content);
     }
     // Replace short codes to emoji
     $content = EmojiHelper::toEmoji($content, 'short');
     $this->processSlots($slots, $entity);
     $logicalName = $this->factory->getHelper('theme')->checkForTwigTemplate(':' . $template . ':email.html.php');
     return $this->render($logicalName, ['isNew' => $isNew, 'slots' => $slots, 'content' => $content, 'email' => $entity, 'template' => $template, 'basePath' => $this->request->getBasePath()]);
 }
Example #14
0
 /**
  * @param mixed $subject
  *
  * @return Copy
  */
 public function setSubject($subject)
 {
     // Ensure it's clean of emoji
     $subject = EmojiHelper::toShort($subject);
     $this->subject = $subject;
     return $this;
 }
 /**
  * Activate the builder
  *
  * @param $objectId
  *
  * @return array|\Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|Response
  * @throws \Exception
  * @throws \Mautic\CoreBundle\Exception\FileNotFoundException
  */
 public function builderAction($objectId)
 {
     /** @var \Mautic\EmailBundle\Model\EmailModel $model */
     $model = $this->factory->getModel('email');
     //permission check
     if (strpos($objectId, 'new') !== false) {
         $isNew = true;
         if (!$this->factory->getSecurity()->isGranted('email:emails:create')) {
             return $this->accessDenied();
         }
         $entity = $model->getEntity();
         $entity->setSessionId($objectId);
     } else {
         $isNew = false;
         $entity = $model->getEntity($objectId);
         if ($entity == null || !$this->factory->getSecurity()->hasEntityAccess('email:emails:viewown', 'email:emails:viewother', $entity->getCreatedBy())) {
             return $this->accessDenied();
         }
     }
     $template = InputHelper::clean($this->request->query->get('template'));
     $slots = $this->factory->getTheme($template)->getSlots('email');
     //merge any existing changes
     $newContent = $this->factory->getSession()->get('mautic.emailbuilder.' . $objectId . '.content', array());
     $content = $entity->getContent();
     $tokens = $model->getBuilderComponents($entity, array('tokens', 'visualTokens'));
     BuilderTokenHelper::replaceTokensWithVisualPlaceholders($tokens, $content);
     if (is_array($newContent)) {
         $content = array_merge($content, $newContent);
     }
     // Replace short codes to emoji
     $content = EmojiHelper::toEmoji($content, 'short');
     return $this->render('MauticEmailBundle::builder.html.php', array('isNew' => $isNew, 'slots' => $slots, 'content' => $content, 'email' => $entity, 'template' => $template, 'basePath' => $this->request->getBasePath()));
 }
Example #16
0
 /**
  * Process if an email is resent
  *
  * @param MauticEvents\EmailEvent $event
  */
 public function onEmailResend(MauticEvents\EmailEvent $event)
 {
     $message = $event->getMessage();
     if (isset($message->leadIdHash)) {
         $model = $this->factory->getModel('email');
         $stat = $model->getEmailStatus($message->leadIdHash);
         if ($stat !== null) {
             $stat->upRetryCount();
             $retries = $stat->getRetryCount();
             if (true || $retries > 3) {
                 //tried too many times so just fail
                 $reason = $this->factory->getTranslator()->trans('mautic.email.dnc.retries', array("%subject%" => EmojiHelper::toShort($message->getSubject())));
                 $model->setDoNotContact($stat, $reason);
             } else {
                 //set it to try again
                 $event->tryAgain();
             }
             $em = $this->factory->getEntityManager();
             $em->persist($stat);
             $em->flush();
         }
     }
 }
Example #17
0
 /**
  * Write a notification.
  *
  * @param string    $message   Message of the notification
  * @param string    $type      Optional $type to ID the source of the notification
  * @param bool|true $isRead    Add unread indicator
  * @param string    $header    Header for message
  * @param string    $iconClass Font Awesome CSS class for the icon (e.g. fa-eye)
  * @param \DateTime $datetime  Date the item was created
  * @param User|null $user      User object; defaults to current user
  */
 public function addNotification($message, $type = null, $isRead = false, $header = null, $iconClass = null, \DateTime $datetime = null, User $user = null)
 {
     if ($user === null) {
         $user = $this->userHelper->getUser();
     }
     if ($user === null || !$user->getId()) {
         //ensure notifications aren't written for non users
         return;
     }
     $notification = new Notification();
     $notification->setType($type);
     $notification->setIsRead($isRead);
     $notification->setHeader(EmojiHelper::toHtml(InputHelper::html($header)));
     $notification->setMessage(EmojiHelper::toHtml(InputHelper::html($message)));
     $notification->setIconClass($iconClass);
     $notification->setUser($user);
     if ($datetime == null) {
         $datetime = new \DateTime();
     }
     $notification->setDateAdded($datetime);
     $this->saveEntity($notification);
 }
Example #18
0
 /**
  * @param Email $email
  * @param bool  $allowBcc            Honor BCC if set in email
  * @param array $slots               Slots configured in theme
  * @param array $assetAttachments    Assets to send
  * @param bool  $ignoreTrackingPixel Do not append tracking pixel HTML
  */
 public function setEmail(Email $email, $allowBcc = true, $slots = array(), $assetAttachments = array(), $ignoreTrackingPixel = false)
 {
     $this->email = $email;
     $subject = $email->getSubject();
     // Convert short codes to emoji
     $subject = EmojiHelper::toEmoji($subject, 'short');
     // Set message settings from the email
     $this->setSubject($subject);
     $fromEmail = $email->getFromAddress();
     $fromName = $email->getFromName();
     if (!empty($fromEmail) && !empty($fromEmail)) {
         $this->setFrom($fromEmail, $fromName);
     } else {
         if (!empty($fromEmail)) {
             $this->setFrom($fromEmail, $this->from);
         } else {
             if (!empty($fromName)) {
                 $this->setFrom(key($this->from), $fromName);
             }
         }
     }
     $replyTo = $email->getReplyToAddress();
     if (!empty($replyTo)) {
         $this->setReplyTo($replyTo);
     }
     if ($allowBcc) {
         $bccAddress = $email->getBccAddress();
         if (!empty($bccAddress)) {
             $this->addBcc($bccAddress);
         }
     }
     if ($plainText = $email->getPlainText()) {
         $this->setPlainText($plainText);
     }
     $template = $email->getTemplate();
     if (!empty($template)) {
         if (empty($slots)) {
             $template = $email->getTemplate();
             $slots = $this->factory->getTheme($template)->getSlots('email');
         }
         if (isset($slots[$template])) {
             $slots = $slots[$template];
         }
         $customHtml = $this->setTemplate('MauticEmailBundle::public.html.php', array('slots' => $slots, 'content' => $email->getContent(), 'email' => $email, 'template' => $template), true);
     } else {
         // Tak on the tracking pixel token
         $customHtml = $email->getCustomHtml();
     }
     // Convert short codes to emoji
     $customHtml = EmojiHelper::toEmoji($customHtml, 'short');
     $this->setBody($customHtml, 'text/html', null, $ignoreTrackingPixel);
     // Reset attachments
     $this->assets = $this->attachedAssets = array();
     if (empty($assetAttachments)) {
         if ($assets = $email->getAssetAttachments()) {
             foreach ($assets as $asset) {
                 $this->attachAsset($asset);
             }
         }
     } else {
         foreach ($assetAttachments as $asset) {
             $this->attachAsset($asset);
         }
     }
 }
Example #19
0
 /**
  * @param Email $email
  * @param bool  $allowBcc            Honor BCC if set in email
  * @param array $slots               Slots configured in theme
  * @param array $assetAttachments    Assets to send
  * @param bool  $ignoreTrackingPixel Do not append tracking pixel HTML
  */
 public function setEmail(Email $email, $allowBcc = true, $slots = [], $assetAttachments = [], $ignoreTrackingPixel = false)
 {
     $this->email = $email;
     $subject = $email->getSubject();
     // Convert short codes to emoji
     $subject = EmojiHelper::toEmoji($subject, 'short');
     // Set message settings from the email
     $this->setSubject($subject);
     $fromEmail = $email->getFromAddress();
     $fromName = $email->getFromName();
     if (!empty($fromEmail) && !empty($fromEmail)) {
         $this->setFrom($fromEmail, $fromName);
     } elseif (!empty($fromEmail)) {
         $this->setFrom($fromEmail, $this->from);
     } elseif (!empty($fromName)) {
         $this->setFrom(key($this->from), $fromName);
     }
     $replyTo = $email->getReplyToAddress();
     if (!empty($replyTo)) {
         $this->setReplyTo($replyTo);
     }
     if ($allowBcc) {
         $bccAddress = $email->getBccAddress();
         if (!empty($bccAddress)) {
             $this->addBcc($bccAddress);
         }
     }
     if ($plainText = $email->getPlainText()) {
         $this->setPlainText($plainText);
     }
     $BCcontent = $email->getContent();
     $customHtml = $email->getCustomHtml();
     // Process emails created by Mautic v1
     if (empty($customHtml) && !empty($BCcontent)) {
         $template = $email->getTemplate();
         if (empty($slots)) {
             $template = $email->getTemplate();
             $slots = $this->factory->getTheme($template)->getSlots('email');
         }
         if (isset($slots[$template])) {
             $slots = $slots[$template];
         }
         $this->processSlots($slots, $email);
         $logicalName = $this->factory->getHelper('theme')->checkForTwigTemplate(':' . $template . ':email.html.php');
         $customHtml = $this->setTemplate($logicalName, ['slots' => $slots, 'content' => $email->getContent(), 'email' => $email, 'template' => $template], true);
     }
     // Convert short codes to emoji
     $customHtml = EmojiHelper::toEmoji($customHtml, 'short');
     $this->setBody($customHtml, 'text/html', null, $ignoreTrackingPixel);
     // Reset attachments
     $this->assets = $this->attachedAssets = [];
     if (empty($assetAttachments)) {
         if ($assets = $email->getAssetAttachments()) {
             foreach ($assets as $asset) {
                 $this->attachAsset($asset);
             }
         }
     } else {
         foreach ($assetAttachments as $asset) {
             $this->attachAsset($asset);
         }
     }
 }