function execute($process, $event)
 {
     $user = eZUser::currentUser();
     if ($user->isLoggedIn()) {
         return eZWorkflowType::STATUS_ACCEPTED;
     }
     $http = eZHTTPTool::instance();
     // Get current content object ID.
     $parameters = $process->attribute('parameter_list');
     $nodeID = $parameters['node_id'];
     $node = eZContentObjectTreeNode::fetch($nodeID);
     if (!$node) {
         return eZWorkflowType::STATUS_REJECTED;
     }
     $objectID = $node->attribute('contentobject_id');
     // Get newsletter hash
     $uri = $GLOBALS['eZRequestedURI'];
     $userParameters = $uri->userParameters();
     $hash = isset($userParameters['hash']) ? $userParameters['hash'] : false;
     $sendItem = eZSendNewsletterItem::fetchByHash($hash);
     if ($http->hasSessionVariable('NewsletterNodeIDArray')) {
         $globalNodeIDList = $http->sessionVariable('NewsletterNodeIDArray');
         if (in_array($nodeID, $http->sessionVariable('NewsletterNodeIDArray'))) {
             $sendID = $http->sessionVariable('NewletterNodeMap_' . $nodeID);
             $sendItem = eZSendNewsletterItem::fetch($sendID);
             $sendItem->addObjectRead($objectID);
             return eZWorkflowType::STATUS_ACCEPTED;
         }
     }
     // Get send item, and check that is contains the object id.
     if (!$sendItem) {
         return eZWorkflowType::STATUS_REJECTED;
     }
     $sendItemIDList = $sendItem->attribute('newsletter_related_object_list');
     if (!$sendItemIDList || !in_array($objectID, $sendItemIDList)) {
         return eZWorkflowType::STATUS_REJECTED;
     }
     $sendNodeIDArray = array();
     // Set session variables
     foreach ($sendItemIDList as $sendObjectID) {
         $sendObject = eZContentObject::fetch($sendObjectID);
         if ($sendObject) {
             foreach ($sendObject->assignedNodes(false) as $nodeArray) {
                 $http->setSessionVariable('NewletterNodeMap_' . $nodeArray['node_id'], $sendItem->attribute('id'));
                 $sendNodeIDArray[] = $nodeArray['node_id'];
             }
         }
     }
     $globalNodeIDList = array_unique(array_merge($globalNodeIDList, $sendNodeIDArray));
     $http->setSessionVariable('NewsletterNodeIDArray', $globalNodeIDList);
     // Add object read
     $sendItem->addObjectRead($objectID);
     return eZWorkflowType::STATUS_ACCEPTED;
 }
 function fetchNewsletterOnHoldCount($status)
 {
     return array('result' => eZSendNewsletterItem::count($status));
 }
Пример #3
0
 static function removeAllBounceInformation($bounceID)
 {
     $bounceItem = eZBounce::fetch($bounceID);
     if (!$bounceItem) {
         return;
     }
     $sendItem = eZSendNewsletterItem::fetch($bounceItem->attribute('newslettersenditem_id'), true);
     if ($sendItem) {
         $subscription = eZSubscription::fetch($sendItem->attribute('subscription_id'));
         if ($subscription) {
             $subscription->setAttribute('bounce_count', 0);
             $subscription->store();
         }
         $sendItem->setAttribute('bounce_id', 0);
         $sendItem->store();
         $bounceItem->remove();
     } else {
         $bounceItem->remove();
     }
 }
<?php

include_once 'kernel/common/eztemplatedesignresource.php';
include_once 'kernel/common/template.php';
include_once "lib/ezutils/classes/ezmail.php";
include_once "lib/ezutils/classes/ezmailtransport.php";
include_once "lib/ezfile/classes/ezfile.php";
include_once eZExtension::baseDirectory() . '/eznewsletter/classes/ezsubscriptionlist.php';
include_once eZExtension::baseDirectory() . '/eznewsletter/classes/ezsubscription.php';
include_once eZExtension::baseDirectory() . '/eznewsletter/classes/eznewsletter.php';
$Module =& $Params['Module'];
$tpl = eZTemplate::instance();
$http = eZHTTPTool::instance();
$res = eZTemplateDesignResource::instance();
$res->setKeys(array(array('newsletter_view', 'register_subscription')));
$NewsletterItem = eZSendNewsletterItem::fetchByHash($Params['UserHash']);
if (!$NewsletterItem) {
    return $Module->handleError(3, 'kernel');
}
$sub = $NewsletterItem->userData();
$subscription = eZSubscription::fetch($NewsletterItem->attribute('subscription_id'));
$tpl->setVariable('NewsletterItem', $NewsletterItem);
$tpl->setVariable('UserHash', $Params['UserHash']);
$tpl->setVariable('subscriptions', $subscription);
if ($http->hasPostVariable('OKButton')) {
    $subscription->unsubscribe();
    $siteini = eZINI::instance();
    $sender = $siteini->variable('MailSettings', 'EmailSender');
    $mail = new eZMail();
    $mail->setReceiver($sub['email']);
    $mail->setSender($sender);
     }
 }
 $MailArray = eZBounce::fetchByOffset($offset, $limit, false, "address");
 if (count($MailArray) >= 1) {
     $bounceDataArray = array();
     foreach ($MailArray as $key => $MailBounceData) {
         $mail = $MailBounceData["address"];
         $sb_c = $db->ArrayQuery("SELECT count(*) as 'softbounces' FROM ez_bouncedata WHERE address='{$mail}' and bounce_type = 0");
         $hb_c = $db->ArrayQuery("SELECT count(*) as 'hardbounces' FROM ez_bouncedata WHERE address='{$mail}' and bounce_type = 1");
         $bounceDataArray[$key]["mail"] = $mail;
         $bounceDataArray[$key]["sb_count"] = $sb_c[0]["softbounces"];
         $bounceDataArray[$key]["hb_count"] = $hb_c[0]["hardbounces"];
         $bounceDataArray[$key]["bounces"] = eZBounce::fetchListByAddress($mail);
         $bounceDataArray[$key]["bounceIDarray"] = array();
         foreach ($bounceDataArray[$key]["bounces"] as $key2 => $bounce) {
             $sendItemBounced = eZSendNewsletterItem::fetch($bounce->ID);
             array_push($bounceDataArray[$key]["bounceIDarray"], $bounce->ID);
             $subscriptionObject = eZSubscription::fetch($sendItemBounced->attribute('subscription_id'));
             if ($subscriptionObject) {
                 $bounceDataArray[$key]["subscriptions"][$key2] = $subscriptionObject;
             }
         }
     }
     $tpl->setVariable('bounce_data_array', $bounceDataArray);
 }
 $tpl->setVariable('statusNames', eZSubscription::statusNameMap());
 $Result = array();
 $Result['newsletter_menu'] = 'design:parts/content/bounce_menu.tpl';
 $Result['left_menu'] = 'design:parts/content/eznewsletter_menu.tpl';
 $Result['content'] = $tpl->fetch("design:{$extension}/list_newsletter_bounce.tpl");
 $Result['path'] = array(array('url' => false, 'text' => ezpI18n::tr('eznewsletter/list_newsletterbounce', 'View newsletter bounces')));
Пример #6
0
function handleBounce($type, $id, $bounceType)
{
    $previousBounce = eZBounce::fetchObject(eZBounce::definition(), null, array('newslettersenditem_id' => $id, 'bounce_type' => $bounceType), true);
    if ($previousBounce) {
        //Update the bounce count for this mailling
        $previousCount = $previousBounce->attribute('bounce_count');
        $previousBounce->setAttribute('bounce_count', ++$previousCount);
        $previousBounce->setAttribute('bounce_message', $type['bounce_message']);
        $previousBounce->store();
        $sendItem = eZSendNewsletterItem::fetch($id, true);
        if ($sendItem) {
            if ($bounceType == EZSOFTBOUNCE && $previousCount < $bounceCountStop) {
                $sendItem->setAttribute('send_status', eZSendNewsletterItem::SendStatusNone);
                $sendItem->store();
            }
            $subscriptionObject = eZSubscription::fetch($sendItem->attribute('subscription_id'));
            if ($subscriptionObject) {
                $bounce_count = $subscriptionObject->attribute('bounce_count');
                $subscriptionObject->setAttribute('bounce_count', ++$bounce_count);
                $subscriptionObject->store();
            }
        }
    } else {
        //We create a new bounce entry
        $db = eZDB::instance();
        $db->begin();
        $bounceData = new eZBounce(array());
        $bounceData->store();
        $bounceData->setAttribute('address', $type['address']);
        $bounceData->setAttribute('bounce_type', $bounceType);
        $bounceData->setAttribute('bounce_count', 1);
        $bounceData->setAttribute('bounce_arrived', $type['bounce_arrived']);
        $bounceData->setAttribute('newslettersenditem_id', $id);
        $bounceData->setAttribute('bounce_message', $type['bounce_message']);
        $bounceData->store();
        $db->commit();
        //Update the sendnewsletteritem table with reference to this bounce entry
        $sendItem = eZSendNewsletterItem::fetch($id, true);
        if ($sendItem) {
            $current_bounceID = $sendItem->attribute('bounce_id');
            if ($current_bounceID == 0) {
                $sendItem->setAttribute('bounce_id', $bounceData->attribute('id'));
                $sendItem->store();
            } else {
                eZDebug::writeNotice("Bounce ID already in place", 'check_bounce');
            }
            if ($bounceType == EZSOFTBOUNCE) {
                $sendItem->setAttribute('send_status', eZSendNewsletterItem::SendStatusNone);
                $sendItem->store();
            }
            //Set the bounce count for the matching subscription_id directly in the subscription table
            $subscription_id = $sendItem->attribute('subscription_id');
            $subscriptionObject = eZSubscription::fetch($subscription_id);
            if ($subscriptionObject) {
                $bounce_count = $subscriptionObject->attribute('bounce_count');
                $subscriptionObject->setAttribute('bounce_count', ++$bounce_count);
                $subscriptionObject->store();
            }
        }
    }
}
Пример #7
0
$cli->output('Fetching prepared newsletter...');
$newsletterArray = eZNewsletter::fetchListBySendStatus(eZNewsletter::SendStatusSending, eZNewsletter::StatusPublished, true, $conditions);
$cli->output('Found ' . count($newsletterArray) . ' newsletter.');
if (0 === count($newsletterArray)) {
    $cli->output('Nothing to send.');
} else {
    $cli->output('Sending newsletter...');
}
// stevo
$totallimit = 200;
$limit = $totallimit / count($newsletterArray);
foreach ($newsletterArray as $newsletter) {
    $cli->output('Sending messages for ' . $newsletter->attribute('name'));
    // stevo
    $statistics = eZNewsletter::sendNewsletterMail($newsletter, false, false, $limit);
    //$newsletter->setAttribute( 'send_status', eZNewsletter::SendStatusFinished );
    //$newsletter->sync();
    $cli->output('Sent ' . $statistics['sendCount'] . ' ( skipped:' . $statistics['skipCount'] . ' )' . ' messages for newsletter : ' . $newsletter->attribute('name'));
    // stevo
    $count = eZSendNewsletterItem::count(eZSendNewsletterItem::SendStatusNone, $newsletter->attribute('id'));
    $cli->output("{$count} users left");
    if ($count <= 0) {
        $newsletter->setAttribute('send_status', eZNewsletter::SendStatusFinished);
        $newsletter->sync();
        $cli->output('Finished sending newsletter : ' . $newsletter->attribute('name'));
    }
}
// remove pid file to unlock cronjob
if (file_exists($pidfilename)) {
    unlink($pidfilename);
}
Пример #8
0
 static function removeEntry($id)
 {
     eZPersistentObject::removeObject(eZSendNewsletterItem::definition(), array('id' => $id));
 }
Пример #9
0
 static function sendNewsletterMail(eZNewsletter $newsletter, $sendPreview = false)
 {
     $sendMailSettings = eZINI::instance('ezsendmailsettings.ini');
     $hostname = $sendMailSettings->variable('SendNewsletter', 'Host');
     $sys = eZSys::instance();
     // Check that the newsletter type exists, if not, process next newsletter
     if (!$newsletter->attribute('newsletter_type')) {
         return false;
     }
     if ($sendPreview) {
         // Fetch the draft because the object is not published during preview
         $contentObject = $newsletter->contentObjectVersion();
     } else {
         $contentObject = $newsletter->contentObject();
     }
     $mailTemplate = $newsletter->generateNewsletter($contentObject);
     $partCounter = 0;
     // 4. Go through revceivers, and send emails.
     if (!$sendPreview) {
         $idcounter = 0;
         $sendCount = 0;
         $skipCount = 0;
         while ($receiverList = eZSendNewsletterItem::fetchByNewsletterID($newsletter->attribute('id'))) {
             foreach ($receiverList as $receiver) {
                 $mail = clone $mailTemplate;
                 $userData = $receiver->attribute('user_data');
                 if (!$userData) {
                     //When no userdata is found, it is usually the result of a deleted subscription,
                     //we mark the mail as being sent, without sending it.
                     $receiver->setAttribute('send_status', eZSendNewsletterItem::SendStatusSent);
                     $receiver->setAttribute('send_ts', time());
                     $receiver->sync();
                     continue;
                 }
                 //personalize if set in type
                 $newsletter_type = eZNewsletterType::fetch($newsletter->attribute('newslettertype_id'));
                 if ($newsletter_type->attribute('personalise') === '1') {
                     $mail->personalize($userData, true);
                 } else {
                     $mail->personalize($userData, false);
                 }
                 $mail->generateMessageId($receiver->attribute('id') . '.' . $newsletter->attribute('id'));
                 $mail->to = array();
                 $mail->addTo(new ezcMailAddress($userData['email'], null, 'utf-8'));
                 $mail->build();
                 $mailResult = eZNewsletterMailTransport::send($mail, false);
                 $sendCount++;
                 $receiver->setAttribute('send_status', eZSendNewsletterItem::SendStatusSent);
                 $receiver->setAttribute('send_ts', time());
                 $receiver->sync();
             }
         }
         return array('sendCount' => $sendCount, 'skipCount' => $skipCount);
     } else {
         $mail = clone $mailTemplate;
         //send preview
         $user = eZUser::currentUser();
         $userObject = $user->attribute('contentobject');
         //personalize if set in type
         $newsletter_type = eZNewsletterType::fetch($newsletter->attribute('newslettertype_id'));
         if ($newsletter_type->attribute('personalise') === '1') {
             $mail->personalize(array('name' => $userObject->attribute('name')), true);
         } else {
             $mail->personalize(array('name' => $userObject->attribute('name')), false);
             $newsletterMail = $newsletter->personalize($mail->plainText, array('name' => $userObject->attribute('name')), false);
         }
         $mail->addTo(new ezcMailAddress($newsletter->attribute('preview_email')));
         $mail->build();
         $mailResult = eZNewsletterMailTransport::send($mail, true);
     }
 }
Пример #10
0
// Further contact information is available at http://ez.no/company/contact/.
//
// The "GNU General Public License" (GPL) is available at
// http://www.gnu.org/copyleft/gpl.html.
//
// Contact licence@ez.no if any conditions of this licencing isn't clear to
// you.
//
$Module = $Params['Module'];
$http = eZHTTPTool::instance();
$sendItemHash = $Params['sendItemHash'];
$objectID = $Params['objectID'];
$newsletterNodeID = $Params['newsletterNodeID'];
$newsletterINI = eZINI::instance('eznewsletter.ini');
// Fetch newsletter and send item
$sendItem = eZSendNewsletterItem::fetchByHash($sendItemHash);
if (!$sendItem) {
    return $Module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel');
}
$newsletter = $sendItem->attribute('newsletter');
if (!$newsletter) {
    return $Module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel');
}
$newsletterObjectID = $newsletter->attribute('contentobject_id');
if (!$newsletterObjectID) {
    return $Module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel');
}
// Count newsletter read
$sendItem->addObjectRead($newsletterObjectID);
// Get send item, and check that is contains the object id.
if (!$sendItem) {
Пример #11
0
 static function sendNewsletterMail($newsletter, $sendPreview = false, $previewFormat = false, $receiverLimit = null)
 {
     $sendMailSettings = eZINI::instance('ezsendmailsettings.ini');
     $replaceMsgIDHost = $sendMailSettings->variable('SendNewsletter', 'ReplaceMessageIDHost');
     $newSendHost = $sendMailSettings->variable('SendNewsletter', 'Host');
     $hostSettings['replace'] = $replaceMsgIDHost;
     $hostSettings['host'] = $newSendHost;
     $mail = new eZNewsletterMail();
     $sys = eZSys::instance();
     $newsletterMailData = array();
     // Check that the newsletter type exists, if not, process next newsletter
     if (!$newsletter->attribute('newsletter_type')) {
         return;
     }
     $newsletterMailData[eZNewsletter::OutputFormatText] = $newsletter->generateNewsletter(eZNewsletter::OutputFormatText, $sendPreview);
     $newsletterMailData[eZNewsletter::OutputFormatHTML] = $newsletter->generateNewsletter(eZNewsletter::OutputFormatHTML, $sendPreview);
     $newsletterMailData[eZNewsletter::OutputFormatExternalHTML] = $newsletter->generateNewsletter(eZNewsletter::OutputFormatExternalHTML, $sendPreview);
     $newsletterMailData[eZNewsletter::OutputFormatSMS] = $newsletter->generateNewsletter(eZNewsletter::OutputFormatSMS, $sendPreview);
     $newsletterOutputFormatList = $newsletter->attribute('output_format_list');
     $noMimeMessage = "This message is in MIME format. Since your mail reader does not understand\nthis format, some or all of this message may not be legible.";
     $lineBreak = "\r\n";
     $partCounter = 0;
     $boundary = date("YmdGHjs") . ':' . getmypid() . ':' . $partCounter++;
     $charset = eZTextCodec::internalCharset();
     $contentTypeHtmlPart = "Content-Type: text/html; charset={$charset}";
     foreach (array(eZNewsletter::OutputFormatHTML, eZNewsletter::OutputFormatExternalHTML) as $key) {
         $htmlOutput =& $newsletterMailData[$key];
         if ($htmlOutput['imageNameMap']) {
             $data = $noMimeMessage . $lineBreak;
             $data .= $lineBreak . '--' . $boundary . $lineBreak;
             $data .= $contentTypeHtmlPart . $lineBreak;
             $data .= "Content-Transfer-Encoding: 8bit" . $lineBreak . $lineBreak;
             $data .= $htmlOutput['body'] . $lineBreak;
             foreach ($htmlOutput['imageNameMap'] as $id => $filename) {
                 $filename = trim($filename);
                 if (is_readable($filename)) {
                     $mime = eZMimeType::findByURL($filename);
                     $encodedFileContent = chunk_split(base64_encode(file_get_contents($filename)), 76, $lineBreak);
                     $data .= $lineBreak . '--' . $boundary . $lineBreak;
                     $data .= "Content-Type: " . $mime['name'] . ';' . $lineBreak . ' name="' . basename($filename) . '"' . $lineBreak;
                     $data .= "Content-ID: <" . $id . ">" . $lineBreak;
                     $data .= "Content-Transfer-Encoding: base64" . $lineBreak;
                     $original_filename = basename($filename);
                     if ($htmlOutput['imageNameMapName'][$id]) {
                         $original_filename = $htmlOutput['imageNameMapName'][$id];
                     }
                     $data .= 'Content-Disposition: INLINE;' . $lineBreak . ' filename="' . $original_filename . '"' . $lineBreak . $lineBreak;
                     $data .= $encodedFileContent;
                 }
             }
             $data .= $lineBreak . '--' . $boundary . '--';
             $htmlOutput['body'] = $data;
         } else {
             $data = $noMimeMessage . $lineBreak;
             $data .= $lineBreak . '--' . $boundary . $lineBreak;
             $data .= $contentTypeHtmlPart . $lineBreak;
             $data .= "Content-Transfer-Encoding: 8bit" . $lineBreak . $lineBreak;
             $data .= $htmlOutput['body'] . $lineBreak;
             $data .= $lineBreak . '--' . $boundary . '--';
             $htmlOutput['body'] = $data;
         }
     }
     // 4. Go through revceivers, and send emails.
     if (!$sendPreview) {
         $mail->setSender($newsletterMailData[eZNewsletter::OutputFormatText]['emailSender'], $newsletterMailData[eZNewsletter::OutputFormatText]['emailSenderName']);
         $idcounter = 0;
         $sendCount = 0;
         $skipCount = 0;
         // HACK!
         $receiverList = eZSendNewsletterItem::fetchByNewsletterID($newsletter->attribute('id'), 0, $receiverLimit);
         foreach ($receiverList as $receiver) {
             $msgid = eZNewsletter::generateMessageId($newsletterMailData[eZNewsletter::OutputFormatText]['emailSender'], $receiver->attribute('id'), $idcounter++, $hostSettings);
             $mail->setMessageID($msgid);
             $userData = $receiver->attribute('user_data');
             if (!$userData) {
                 //When no userdata is found, it is usually the result of a deleted subscription,
                 //we mark the mail as being sent, without sending it.
                 $receiver->setAttribute('send_status', eZSendNewsletterItem::SendStatusSent);
                 $receiver->setAttribute('send_ts', time());
                 $receiver->sync();
                 continue;
             }
             // #TODO# IDs expected
             $userOutputFormatList = explode(',', $userData['output_format']);
             // #TODO#
             #echo " ### userOutputFormatList\n";  ok
             #var_dump( $userOutputFormatList );
             #echo " ### newsletterOutputFormatList\n"; ok
             #var_dump( $newsletterOutputFormatList );
             $outputFormat = false;
             //special case for SMS sending
             if (in_array(eZNewsletter::OutputFormatSMS, $userOutputFormatList) && in_array(eZNewsletter::OutputFormatSMS, $newsletterOutputFormatList)) {
                 $mail->setContentType("sms", false, false, false, $boundary);
                 $outputFormat = eZNewsletter::OutputFormatSMS;
                 //$mail->setSubject( $userMailData['subject'] );                                        ### $userMailData is undefined
                 # echo " ### userMailData\n";
                 # var_dump( $userMailData );
                 # $mail->setSubject( $userMailData['subject'] );
                 # $mail->setReceiver( $userData['email'] );
                 # $mail->setMobile( $userData['mobile'] );
                 //$mail->setBody( $userMailData['body'] );                                              ### $userMailData is undefined
                 # $mail->setBody( $userMailData['body'] );
                 # $mail->setDateTimestamp( $newsletter->attribute( 'send_date') );
                 $mailResult = eZNewsletterMailTransport::send($mail, false);
             }
             //send regular emails
             if (in_array(eZNewsletter::OutputFormatHTML, $userOutputFormatList) && in_array(eZNewsletter::OutputFormatHTML, $newsletterOutputFormatList)) {
                 $mail->setContentType("multipart/related", false, false, false, $boundary);
                 $outputFormat = eZNewsletter::OutputFormatHTML;
             }
             if (in_array(eZNewsletter::OutputFormatExternalHTML, $userOutputFormatList) && in_array(eZNewsletter::OutputFormatExternalHTML, $newsletterOutputFormatList)) {
                 $mail->setContentType("multipart/related", false, false, false, $boundary);
                 $outputFormat = eZNewsletter::OutputFormatExternalHTML;
             }
             // ...
             if ($outputFormat === false) {
                 $outputIntersect = array_intersect($userOutputFormatList, $newsletterOutputFormatList);
                 if (count($outputIntersect) > 0) {
                     $outputFormat = $outputIntersect[0];
                 }
             }
             if ($outputFormat !== false) {
                 //personalize if set in type
                 $newsletter_type = eZNewsletterType::fetch($newsletter->attribute('newslettertype_id'));
                 if ($newsletter_type->attribute('personalise') === '1') {
                     $userMailData = eZNewsletter::personalize($newsletterMailData[$outputFormat], $userData, true);
                 } else {
                     $userMailData = eZNewsletter::personalize($newsletterMailData[$outputFormat], $userData, false);
                 }
                 $mail->setSubject($userMailData['subject']);
                 $mail->setReceiver($userData['email']);
                 $mail->setMobile($userData['mobile']);
                 $mail->setBody($userMailData['body']);
                 $mail->setDateTimestamp($newsletter->attribute('send_date'));
                 //if only SMS was selected, don't send email
                 if (!(in_array(eZNewsletter::OutputFormatSMS, $userOutputFormatList) && count($userOutputFormatList) == 1)) {
                     $mailResult = eZNewsletterMailTransport::send($mail, false);
                 }
                 $sendCount++;
             } else {
                 // User doesnt want any format we defined - skipped
                 $skipCount++;
             }
             $receiver->setAttribute('send_status', eZSendNewsletterItem::SendStatusSent);
             $receiver->setAttribute('send_ts', time());
             $receiver->sync();
         }
         //send SMS messages
         $instance = eZSMS::instance();
         if ($instance->countNumbers() > 0) {
             echo "Preparing to send " . $instance->countNumbers() . " SMS messages..." . "\n";
             $instance->setContent($newsletterMailData[eZNewsletter::OutputFormatSMS]['body']);
             foreach ($instance->getNumbers() as $number) {
                 echo "Recipient is: " . $number . "\n";
             }
             $reply = $instance->sendMessages();
             if ($reply != "") {
                 echo "SMS Reply:" . "\n";
                 echo $reply;
             }
         }
         //}
         return array('sendCount' => $sendCount, 'skipCount' => $skipCount);
     } else {
         //send preview
         $msgid = eZNewsletter::generateMessageId($newsletterMailData[eZNewsletter::OutputFormatText]['emailSender'], 0, 0, $hostSettings);
         $mail->setMessageID($msgid);
         $userOutputFormatList = $previewFormat;
         $outputFormat = false;
         //special case for SMS sending
         if (in_array(eZNewsletter::OutputFormatSMS, $userOutputFormatList)) {
             $mail->setContentType("sms", false, false, false, $boundary);
             $outputFormat = eZNewsletter::OutputFormatSMS;
             $newsletterMail = $newsletterMailData[eZNewsletter::OutputFormatSMS];
             $mail->setSender($newsletterMail['emailSender'], $newsletterMail['emailSenderName']);
             $mail->setReceiver($newsletter->attribute('preview_email'));
             $mail->setMobile($newsletter->attribute('preview_mobile'));
             $mail->setBody($newsletterMail['body']);
             $mail->setSubject($newsletterMail['subject']);
             $mail->setDateTimestamp($newsletter->attribute('send_date'));
             $mailResult = eZNewsletterMailTransport::send($mail, true);
         }
         //send regular emails
         if (in_array(eZNewsletter::OutputFormatHTML, $userOutputFormatList)) {
             $mail->setContentType("multipart/related", false, false, false, $boundary);
             $outputFormat = eZNewsletter::OutputFormatHTML;
         }
         if (in_array(eZNewsletter::OutputFormatExternalHTML, $userOutputFormatList)) {
             $mail->setContentType("multipart/related", false, false, false, $boundary);
             $outputFormat = eZNewsletter::OutputFormatExternalHTML;
         }
         if ($outputFormat === false) {
             $outputIntersect = array_intersect($userOutputFormatList, $newsletterOutputFormatList);
             if (count($outputIntersect) > 0) {
                 $outputFormat = $outputIntersect[0];
             }
         }
         if ($outputFormat === false) {
             $outputFormat = $newsletterOutputFormatList[0];
             if ($outputFormat == eZNewsletter::OutputFormatHTML || $outputFormat == eZNewsletter::OutputFormatExternalHTML) {
                 $mail->setContentType("multipart/related", false, false, false, $boundary);
             }
         }
         $user = eZUser::currentUser();
         $userObject = $user->attribute('contentobject');
         //personalize if set in type
         $newsletter_type = eZNewsletterType::fetch($newsletter->attribute('newslettertype_id'));
         if ($newsletter_type->attribute('personalise') === '1') {
             $newsletterMail = $newsletter->personalize($newsletterMailData[$outputFormat], array('name' => $userObject->attribute('name')), true);
         } else {
             $newsletterMail = $newsletter->personalize($newsletterMailData[$outputFormat], array('name' => $userObject->attribute('name')), false);
         }
         $mail->setSender($newsletterMail['emailSender']);
         $mail->setReceiver($newsletter->attribute('preview_email'));
         $mail->setMobile($newsletter->attribute('preview_mobile'));
         $mail->setBody($newsletterMail['body']);
         $mail->setSubject($newsletterMail['subject']);
         $mail->setDateTimestamp($newsletter->attribute('send_date'));
         //if only SMS was selected, don't send email
         if (!(in_array(eZNewsletter::OutputFormatSMS, $userOutputFormatList) && count($userOutputFormatList) == 1)) {
             $mailResult = eZNewsletterMailTransport::send($mail, true);
         }
         //send SMS messages
         $instance = eZSMS::instance();
         if ($instance->countNumbers() > 0) {
             //echo "Preparing to send ".$instance->countNumbers()." SMS messages..."."\n";
             $instance->setContent($newsletterMailData[eZNewsletter::OutputFormatSMS]['body']);
             $reply = $instance->sendMessages();
             if ($reply != "") {
                 echo "SMS Reply:" . "\n";
                 echo $reply;
             }
         }
     }
 }