oxemail.php

Go to the documentation of this file.
00001 <?php
00005 require oxConfig::getInstance()->getConfigParam( 'sCoreDir' ) . "/phpmailer/class.phpmailer.php";
00006 
00007 
00013 class oxEmail extends PHPMailer
00014 {
00020     public $SMTP_PORT = 25;
00021 
00027     protected $_sForgotPwdTemplate = "email/html/forgotpwd.tpl";
00028 
00034     protected $_sForgotPwdTemplatePlain = "email/plain/forgotpwd.tpl";
00035 
00041     protected $_sNewsletterOptInTemplate = "email/html/newsletteroptin.tpl";
00042 
00048     protected $_sNewsletterOptInTemplatePlain = "email/plain/newsletteroptin.tpl";
00049 
00055     protected $_sSuggestTemplate = "email/html/suggest.tpl";
00056 
00062     protected $_sSuggestTemplatePlain = "email/plain/suggest.tpl";
00063 
00069     protected $_sInviteTemplate = "email/html/invite.tpl";
00070 
00076     protected $_sInviteTemplatePlain = "email/plain/invite.tpl";
00077 
00083     protected $_sSenedNowTemplate = "email/html/sendednow.tpl";
00084 
00090     protected $_sSenedNowTemplatePlain = "email/plain/sendednow.tpl";
00091 
00097     protected $_sWishListTemplate = "email/html/wishlist.tpl";
00098 
00104     protected $_sWishListTemplatePlain = "email/plain/wishlist.tpl";
00105 
00111     protected $_sRegisterTemplate = "email/html/register.tpl";
00112 
00118     protected $_sRegisterTemplatePlain = "email/plain/register.tpl";
00119 
00125     protected $_sReminderMailTemplate = "email/html/owner_reminder.tpl";
00126 
00132     protected $_sOrderUserTemplate          = "email/html/order_cust.tpl";
00133 
00139     protected $_sOrderUserPlainTemplate     = "email/plain/order_cust.tpl";
00140 
00146     protected $_sOrderOwnerTemplate         = "email/html/order_owner.tpl";
00147 
00153     protected $_sOrderOwnerPlainTemplate    = "email/plain/order_owner.tpl";
00154 
00155     // #586A - additional templates for more customizable subjects
00156 
00162     protected $_sOrderUserSubjectTemplate   = "email/html/order_cust_subj.tpl";
00163 
00169     protected $_sOrderOwnerSubjectTemplate  = "email/html/order_owner_subj.tpl";
00170 
00176     protected $_sOwnerPricealarmTemplate    = "email/html/pricealarm_owner.tpl";
00177 
00183     protected $_sPricealamrCustomerTemplate    = "email_pricealarm_customer.tpl";
00184 
00190     protected $_aShops = array();
00191 
00197     protected $_blInlineImgEmail = null;
00198 
00204     protected $_aRecipients = array();
00205 
00211     protected $_aReplies = array();
00212 
00218     protected $_aAttachments = array();
00219 
00225     protected $_oSmarty = null;
00226 
00232     protected $_aViewData = array();
00233 
00239     protected $_oShop = null;
00240 
00246     protected $_sCharSet = null;
00247 
00251     public function __construct()
00252     {
00253         //enabling exception handling in phpmailer class
00254         parent::__construct( true );
00255 
00256         $myConfig = $this->getConfig();
00257 
00258         $this->_setMailerPluginDir();
00259         $this->setSmtp();
00260 
00261         $this->setUseInlineImages( $myConfig->getConfigParam('blInlineImgEmail') );
00262         $this->setMailWordWrap( 100 );
00263 
00264         $this->isHtml( true );
00265         $this->setLanguage( "en", $myConfig->getConfigParam( 'sShopDir' )."/core/phpmailer/language/");
00266 
00267         $this->_getSmarty();
00268     }
00269 
00281     public function __call( $sMethod, $aArgs )
00282     {
00283         if ( defined( 'OXID_PHP_UNIT' ) ) {
00284             if ( substr( $sMethod, 0, 4) == "UNIT" ) {
00285                 $sMethod = str_replace( "UNIT", "_", $sMethod );
00286             }
00287             if ( method_exists( $this, $sMethod)) {
00288                 return call_user_func_array( array( & $this, $sMethod ), $aArgs );
00289             }
00290         }
00291 
00292         throw new oxSystemComponentException( "Function '$sMethod' does not exist or is not accessible! (" . get_class($this) . ")".PHP_EOL);
00293     }
00294 
00300     public function getConfig()
00301     {
00302         if ( $this->_oConfig == null ) {
00303             $this->_oConfig = oxConfig::getInstance();
00304         }
00305 
00306         return $this->_oConfig;
00307     }
00308 
00316     public function setConfig( $oConfig )
00317     {
00318         $this->_oConfig = $oConfig;
00319     }
00320 
00321 
00327     protected function _getSmarty()
00328     {
00329         if ( $this->_oSmarty === null ) {
00330             $this->_oSmarty = oxUtilsView::getInstance()->getSmarty();
00331         }
00332 
00333         //setting default view
00334         $this->_oSmarty->assign( "oEmailView", $this );
00335 
00336         return $this->_oSmarty;
00337     }
00338 
00346     public function send()
00347     {
00348         // if no recipients found, skipping sending
00349         if ( count( $this->getRecipient() ) < 1 ) {
00350             return false;
00351         }
00352 
00353         $myConfig = $this->getConfig();
00354         $this->setCharSet();
00355 
00356         if ( $this->_getUseInlineImages() ) {
00357             $this->_includeImages( $myConfig->getImageDir(), $myConfig->getImageUrl( false, false ), $myConfig->getPictureUrl(null, false),
00358                                    $myConfig->getImageDir(), $myConfig->getPictureDir(false));
00359         }
00360 
00361         $this->_makeOutputProcessing();
00362 
00363         // try to send mail via SMTP
00364         if ( $this->getMailer() == 'smtp' ) {
00365             $blRet = $this->_sendMail();
00366 
00367             // if sending failed, try to send via mail()
00368             if ( !$blRet ) {
00369                 // failed sending via SMTP, sending notification to shop owner
00370                 $this->_sendMailErrorMsg();
00371 
00372                 // trying to send using standard mailer
00373                 $this->setMailer( 'mail' );
00374                 $blRet = $this->_sendMail();
00375             }
00376         } else {
00377             // sending mail via mail()
00378             $this->setMailer( 'mail' );
00379             $blRet = $this->_sendMail();
00380         }
00381 
00382         if ( !$blRet ) {
00383             // failed sending, giving up, trying to send notification to shop owner
00384             $this->_sendMailErrorMsg();
00385         }
00386 
00387         return $blRet;
00388     }
00389 
00398     protected function _setSmtpProtocol($sUrl)
00399     {
00400         $sProtocol = '';
00401         $sSmtpHost = $sUrl;
00402         $aMatch = array();
00403         if ( getStr()->preg_match('@^([0-9a-z]+://)?(.*)$@i', $sUrl, $aMatch ) ) {
00404             if ($aMatch[1]) {
00405                 if (($aMatch[1] == 'ssl://') || ($aMatch[1] == 'tls://')) {
00406                     $this->set( "SMTPSecure", substr($aMatch[1], 0, 3) );
00407                 } else {
00408                     $sProtocol = $aMatch[1];
00409                 }
00410             }
00411             $sSmtpHost = $aMatch[2];
00412         }
00413 
00414         return $sProtocol.$sSmtpHost;
00415     }
00416 
00424     public function setSmtp( $oShop = null )
00425     {
00426         $myConfig = $this->getConfig();
00427         $oShop = ( $oShop ) ? $oShop : $this->_getShop();
00428 
00429         $sSmtpUrl = $this->_setSmtpProtocol($oShop->oxshops__oxsmtp->value);
00430 
00431         if ( !$this->_isValidSmtpHost( $sSmtpUrl ) ) {
00432             $this->setMailer( "mail" );
00433             return;
00434         }
00435 
00436         $this->setHost( $sSmtpUrl );
00437         $this->setMailer( "smtp" );
00438 
00439         if ( $oShop->oxshops__oxsmtpuser->value ) {
00440             $this->_setSmtpAuthInfo( $oShop->oxshops__oxsmtpuser->value, $oShop->oxshops__oxsmtppwd->value );
00441         }
00442 
00443         if ( $myConfig->getConfigParam( 'iDebug' ) == 6 ) {
00444             $this->_setSmtpDebug( true );
00445         }
00446     }
00447 
00455     protected function _isValidSmtpHost( $sSmtpHost )
00456     {
00457         $blIsSmtp = false;
00458         if ( $sSmtpHost ) {
00459             $sSmtpPort = $this->SMTP_PORT;
00460             $aMatch = array();
00461             if ( getStr()->preg_match('@^(.*?)(:([0-9]+))?$@i', $sSmtpHost, $aMatch)) {
00462                 $sSmtpHost = $aMatch[1];
00463                 $sSmtpPort = (int)$aMatch[3];
00464                 if (!$sSmtpPort) {
00465                     $sSmtpPort = $this->SMTP_PORT;
00466                 }
00467             }
00468             if ( $blIsSmtp = (bool) ( $rHandle = @fsockopen( $sSmtpHost, $sSmtpPort, $iErrNo, $sErrStr, 30 )) ) {
00469                 // closing connection ..
00470                 fclose( $rHandle );
00471             }
00472         }
00473 
00474         return $blIsSmtp;
00475     }
00476 
00486     public function sendOrderEmailToUser( $oOrder, $sSubject = null )
00487     {
00488         $myConfig = $this->getConfig();
00489 
00490         // add user defined stuff if there is any
00491         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00492 
00493         $oShop = $this->_getShop();
00494         $this->_setMailParams( $oShop );
00495 
00496         $oUser = $oOrder->getOrderUser();
00497         $this->setUser( $oUser );
00498 
00499         // create messages
00500         $oSmarty = $this->_getSmarty();
00501         $this->setViewData( "order", $oOrder);
00502 
00503         // Process view data array through oxoutput processor
00504         $this->_processViewArray();
00505 
00506         $this->setBody( $oSmarty->fetch( $this->_sOrderUserTemplate ) );
00507         $this->setAltBody( $oSmarty->fetch( $this->_sOrderUserPlainTemplate ) );
00508 
00509         // #586A
00510         if ( $sSubject === null ) {
00511             if ( $oSmarty->template_exists( $this->_sOrderUserSubjectTemplate) ) {
00512                 $sSubject = $oSmarty->fetch( $this->_sOrderUserSubjectTemplate );
00513             } else {
00514                 $sSubject = $oShop->oxshops__oxordersubject->getRawValue()." (#".$oOrder->oxorder__oxordernr->value.")";
00515             }
00516         }
00517 
00518         $this->setSubject( $sSubject );
00519 
00520         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00521 
00522         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00523         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00524 
00525         $blSuccess = $this->send();
00526 
00527         return $blSuccess;
00528     }
00529 
00539     public function sendOrderEmailToOwner( $oOrder, $sSubject = null )
00540     {
00541         $myConfig = $this->getConfig();
00542 
00543         $oShop = $this->_getShop();
00544 
00545         // cleanup
00546         $this->_clearMailer();
00547 
00548         // add user defined stuff if there is any
00549         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00550 
00551         $oUser = $oOrder->getOrderUser();
00552         $this->setUser( $oUser );
00553 
00554         // send confirmation to shop owner
00555         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00556         $this->setFrom( $oUser->oxuser__oxusername->value, $sFullName );
00557 
00558         $oLang = oxLang::getInstance();
00559         $iOrderLang = $oLang->getObjectTplLanguage();
00560 
00561         // if running shop language is different from admin lang. set in config
00562         // we have to load shop in config language
00563         if ( $oShop->getLanguage() != $iOrderLang ) {
00564             $oShop = $this->_getShop( $iOrderLang );
00565         }
00566 
00567         $this->setSmtp( $oShop );
00568 
00569         // create messages
00570         $oSmarty = $this->_getSmarty();
00571         $this->setViewData( "order", $oOrder );
00572 
00573         // Process view data array through oxoutput processor
00574         $this->_processViewArray();
00575 
00576         $this->setBody( $oSmarty->fetch( $myConfig->getTemplatePath( $this->_sOrderOwnerTemplate, false ) ) );
00577         $this->setAltBody( $oSmarty->fetch( $myConfig->getTemplatePath( $this->_sOrderOwnerPlainTemplate, false ) ) );
00578 
00579         //Sets subject to email
00580         // #586A
00581         if ( $sSubject === null ) {
00582             if ( $oSmarty->template_exists( $this->_sOrderOwnerSubjectTemplate) ) {
00583                 $sSubject = $oSmarty->fetch( $this->_sOrderOwnerSubjectTemplate );
00584             } else {
00585                  $sSubject = $oShop->oxshops__oxordersubject->getRawValue()." (#".$oOrder->oxorder__oxordernr->value.")";
00586             }
00587         }
00588 
00589         $this->setSubject( $sSubject );
00590         $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oLang->translateString("order") );
00591 
00592         if ( $oUser->oxuser__oxusername->value != "admin" )
00593             $this->setReplyTo( $oUser->oxuser__oxusername->value, $sFullName );
00594 
00595         $blSuccess = $this->send();
00596 
00597         // add user history
00598         $oRemark = oxNew( "oxremark" );
00599         $oRemark->oxremark__oxtext      = new oxField($this->getAltBody(), oxField::T_RAW);
00600         $oRemark->oxremark__oxparentid  = new oxField($oUser->getId(), oxField::T_RAW);
00601         $oRemark->oxremark__oxtype      = new oxField("o", oxField::T_RAW);
00602         $oRemark->save();
00603 
00604 
00605         if ( $myConfig->getConfigParam( 'iDebug' ) == 6) {
00606             oxUtils::getInstance()->showMessageAndExit( "" );
00607         }
00608 
00609         return $blSuccess;
00610     }
00611 
00621     public function sendRegisterConfirmEmail( $oUser, $sSubject = null )
00622     {
00623         // setting content ident
00624 
00625         $this->setViewData( "contentident", "oxregisteraltemail" );
00626         $this->setViewData( "contentplainident", "oxregisterplainaltemail" );
00627 
00628         // sending email
00629         return $this->sendRegisterEmail( $oUser, $sSubject );
00630     }
00631 
00641     public function sendRegisterEmail( $oUser, $sSubject = null )
00642     {
00643         // add user defined stuff if there is any
00644         $oUser = $this->_addUserRegisterEmail( $oUser );
00645 
00646         // shop info
00647         $oShop = $this->_getShop();
00648 
00649         //set mail params (from, fromName, smtp )
00650         $this->_setMailParams( $oShop );
00651 
00652         // create messages
00653         $oSmarty = $this->_getSmarty();
00654         $this->setUser( $oUser );
00655 
00656         // Process view data array through oxoutput processor
00657         $this->_processViewArray();
00658 
00659         $this->setBody( $oSmarty->fetch( $this->_sRegisterTemplate ) );
00660         $this->setAltBody( $oSmarty->fetch( $this->_sRegisterTemplatePlain ) );
00661 
00662         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxregistersubject->getRawValue() );
00663 
00664         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00665 
00666         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00667         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00668 
00669         return $this->send();
00670     }
00671 
00681     public function sendForgotPwdEmail( $sEmailAddress, $sSubject = null )
00682     {
00683         $myConfig = $this->getConfig();
00684         $oDb = oxDb::getDb();
00685 
00686         // shop info
00687         $oShop = $this->_getShop();
00688 
00689         // add user defined stuff if there is any
00690         $oShop = $this->_addForgotPwdEmail( $oShop );
00691 
00692         //set mail params (from, fromName, smtp)
00693         $this->_setMailParams( $oShop );
00694 
00695         // user
00696         $sWhere = "oxuser.oxactive = 1 and oxuser.oxusername = ".$oDb->quote( $sEmailAddress )." and oxuser.oxpassword != ''";
00697         $sOrder = "";
00698         if ( $myConfig->getConfigParam( 'blMallUsers' )) {
00699             $sOrder = "order by oxshopid = '".$oShop->getId()."' desc";
00700         } else {
00701             $sWhere .= " and oxshopid = '".$oShop->getId()."'";
00702         }
00703 
00704         $sSelect = "select oxid from oxuser where $sWhere $sOrder";
00705         if ( ( $sOxId = $oDb->getOne( $sSelect ) ) ) {
00706 
00707             $oUser = oxNew( 'oxuser' );
00708             if ( $oUser->load($sOxId) ) {
00709                 // create messages
00710                 $oSmarty = $this->_getSmarty();
00711                 $this->setUser( $oUser );
00712 
00713                 // Process view data array through oxoutput processor
00714                 $this->_processViewArray();
00715 
00716                 $this->setBody( $oSmarty->fetch( $this->_sForgotPwdTemplate ) );
00717 
00718                 $this->setAltBody( $oSmarty->fetch( $this->_sForgotPwdTemplatePlain ) );
00719 
00720                 //sets subject of email
00721                 $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxforgotpwdsubject->getRawValue() );
00722 
00723                 $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00724 
00725                 $this->setRecipient( $sEmailAddress, $sFullName );
00726                 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00727 
00728                 return $this->send();
00729             }
00730         }
00731 
00732         return false;
00733     }
00734 
00745     public function sendContactMail( $sEmailAddress = null, $sSubject = null, $sMessage = null )
00746     {
00747 
00748         // shop info
00749         $oShop = $this->_getShop();
00750 
00751         //set mail params (from, fromName, smtp)
00752         $this->_setMailParams( $oShop );
00753 
00754         $this->setBody( $sMessage );
00755         $this->setSubject( $sSubject );
00756 
00757         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00758         $this->setFrom( $sEmailAddress, "" );
00759         $this->setReplyTo( $sEmailAddress, "" );
00760 
00761         return $this->send();
00762     }
00763 
00773     public function sendNewsletterDbOptInMail( $oUser, $sSubject = null )
00774     {
00775         $oLang = oxLang::getInstance();
00776 
00777         // add user defined stuff if there is any
00778         $oUser = $this->_addNewsletterDbOptInMail( $oUser );
00779 
00780         // shop info
00781         $oShop = $this->_getShop();
00782 
00783         //set mail params (from, fromName, smtp)
00784         $this->_setMailParams( $oShop );
00785 
00786         // create messages
00787         $oSmarty = $this->_getSmarty();
00788         $this->setViewData( "subscribeLink", $this->_getNewsSubsLink($oUser->oxuser__oxid->value) );
00789         $this->setUser( $oUser );
00790 
00791         // Process view data array through oxoutput processor
00792         $this->_processViewArray();
00793 
00794         $this->setBody( $oSmarty->fetch( $this->_sNewsletterOptInTemplate ) );
00795         $this->setAltBody( $oSmarty->fetch( $this->_sNewsletterOptInTemplatePlain ) );
00796         $this->setSubject( ( $sSubject !== null ) ? $sSubject : oxLang::getInstance()->translateString("EMAIL_NEWSLETTERDBOPTINMAIL_SUBJECT") . " " . $oShop->oxshops__oxname->getRawValue() );
00797 
00798         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00799 
00800         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00801         $this->setFrom( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00802         $this->setReplyTo( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00803 
00804         return $this->send();
00805     }
00806 
00814     protected function _getNewsSubsLink( $sId )
00815     {
00816         $myConfig = $this->getConfig();
00817         $iActShopLang = $myConfig->getActiveShop()->getLanguage();
00818 
00819         $sUrl = $myConfig->getShopHomeURL().'cl=newsletter&amp;fnc=addme&amp;uid='.$sId;
00820         $sUrl.= ( $iActShopLang ) ? '&amp;lang='.$iActShopLang : "";
00821         return $sUrl;
00822     }
00823 
00834     public function sendNewsletterMail( $oNewsLetter, $oUser, $sSubject = null )
00835     {
00836         // shop info
00837         $oShop = $this->_getShop();
00838 
00839         //set mail params (from, fromName, smtp)
00840         $this->_setMailParams( $oShop );
00841 
00842         $sBody = $oNewsLetter->getHtmlText();
00843 
00844         if ( !empty($sBody) ) {
00845             $this->setBody( $sBody );
00846             $this->setAltBody( $oNewsLetter->getPlainText() );
00847         } else {
00848             $this->isHtml( false );
00849             $this->setBody( $oNewsLetter->getPlainText() );
00850         }
00851 
00852         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oNewsLetter->oxnewsletter__oxtitle->getRawValue() );
00853 
00854         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00855         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00856         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00857 
00858         return $this->send();
00859     }
00860 
00870     public function sendSuggestMail( $oParams, $oProduct )
00871     {
00872         $myConfig = $this->getConfig();
00873 
00874         //sets language of shop
00875         $iCurrLang = $myConfig->getActiveShop()->getLanguage();
00876 
00877         // shop info
00878         $oShop = $this->_getShop( $iCurrLang );
00879 
00880         //sets language to article
00881         if ( $oProduct->getLanguage() != $iCurrLang ) {
00882             $oProduct->setLanguage( $iCurrLang );
00883             $oProduct->load( $oProduct->getId() );
00884         }
00885 
00886         // mailer stuff
00887         $this->setFrom( $oParams->send_email, $oParams->send_name );
00888         $this->setSMTP();
00889 
00890         // create messages
00891         $oSmarty = $this->_getSmarty();
00892         $this->setViewData( "product", $oProduct );
00893         $this->setUser( $oParams );
00894 
00895         $sArticleUrl = $oProduct->getLink();
00896 
00897         //setting recommended user id
00898         if ( $myConfig->getActiveView()->isActive('Invitations') && $oActiveUser = $oShop->getUser() ) {
00899             $sArticleUrl  = oxUtilsUrl::getInstance()->appendParamSeparator( $sArticleUrl );
00900             $sArticleUrl .= "su=" . $oActiveUser->getId();
00901         }
00902 
00903         $this->setViewData( "sArticleUrl", $sArticleUrl );
00904 
00905         // Process view data array through oxoutput processor
00906         $this->_processViewArray();
00907 
00908         $this->setBody( $oSmarty->fetch( $this->_sSuggestTemplate ) );
00909         $this->setAltBody( $oSmarty->fetch( $this->_sSuggestTemplatePlain ) );
00910         $this->setSubject( $oParams->send_subject );
00911 
00912         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
00913         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00914 
00915         return $this->send();
00916     }
00917 
00926     public function sendInviteMail( $oParams )
00927     {
00928         $myConfig = $this->getConfig();
00929 
00930         //sets language of shop
00931         $iCurrLang = $myConfig->getActiveShop()->getLanguage();
00932 
00933         // shop info
00934         $oShop = $this->_getShop( $iCurrLang );
00935 
00936         // mailer stuff
00937         $this->setFrom( $oParams->send_email, $oParams->send_name );
00938         $this->setSMTP();
00939 
00940         // create messages
00941         $oSmarty = oxUtilsView::getInstance()->getSmarty();
00942         $this->setUser( $oParams );
00943 
00944         $sHomeUrl = $this->getViewConfig()->getHomeLink();
00945 
00946         //setting recommended user id
00947         if ( $myConfig->getActiveView()->isActive('Invitations') && $oActiveUser = $oShop->getUser() ) {
00948             $sHomeUrl  = oxUtilsUrl::getInstance()->appendParamSeparator( $sHomeUrl );
00949             $sHomeUrl .= "su=" . $oActiveUser->getId();
00950         }
00951 
00952         if ( is_array($oParams->rec_email) && count($oParams->rec_email) > 0  ) {
00953             foreach ( $oParams->rec_email as $sEmail ) {
00954                 if ( !empty( $sEmail ) ) {
00955                     $sRegisterUrl  = oxUtilsUrl::getInstance()->appendParamSeparator( $sHomeUrl );
00956                     //setting recipient user email
00957                     $sRegisterUrl .= "re=" . md5($sEmail);
00958                     $this->setViewData( "sHomeUrl", $sRegisterUrl );
00959 
00960                     // Process view data array through oxoutput processor
00961                     $this->_processViewArray();
00962 
00963                     $this->setBody( $oSmarty->fetch( $this->_sInviteTemplate ) );
00964 
00965                     $this->setAltBody( $oSmarty->fetch( $this->_sInviteTemplatePlain ) );
00966                     $this->setSubject( $oParams->send_subject );
00967 
00968                     $this->setRecipient( $sEmail );
00969                     $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00970                     $this->send();
00971                     $this->clearAllRecipients();
00972                 }
00973             }
00974             return true;
00975         }
00976 
00977         return false;
00978     }
00979 
00989     public function sendSendedNowMail( $oOrder, $sSubject = null )
00990     {
00991         $myConfig = $this->getConfig();
00992 
00993         $iOrderLang = (int) ( isset( $oOrder->oxorder__oxlang->value ) ? $oOrder->oxorder__oxlang->value : 0 );
00994 
00995         // shop info
00996         $oShop = $this->_getShop( $iOrderLang );
00997 
00998         //set mail params (from, fromName, smtp)
00999         $this->_setMailParams( $oShop );
01000 
01001         //create messages
01002         $oLang = oxLang::getInstance();
01003         $oSmarty = $this->_getSmarty();
01004         $this->setViewData( "order", $oOrder );
01005         $this->setViewData( "shopTemplateDir", $myConfig->getTemplateDir(false) );
01006 
01007         //deprecated var
01008         $oUser = oxNew( 'oxuser' );
01009         $this->setViewData( "reviewuserhash", $oUser->getReviewUserHash($oOrder->oxorder__oxuserid->value) );
01010 
01011         // Process view data array through oxoutput processor
01012         $this->_processViewArray();
01013 
01014         // dodger #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
01015         $aStore['INCLUDE_ANY'] = $oSmarty->security_settings['INCLUDE_ANY'];
01016         //V send email in order language
01017         $iOldTplLang = $oLang->getTplLanguage();
01018         $iOldBaseLang = $oLang->getTplLanguage();
01019         $oLang->setTplLanguage( $iOrderLang );
01020         $oLang->setBaseLanguage( $iOrderLang );
01021 
01022         $oSmarty->security_settings['INCLUDE_ANY'] = true;
01023         // force non admin to get correct paths (tpl, img)
01024         $myConfig->setAdminMode( false );
01025         $this->setBody( $oSmarty->fetch( $this->_sSenedNowTemplate ) );
01026         $this->setAltBody( $oSmarty->fetch( $this->_sSenedNowTemplatePlain ) );
01027         $myConfig->setAdminMode( true );
01028         $oLang->setTplLanguage( $iOldTplLang );
01029         $oLang->setBaseLanguage( $iOldBaseLang );
01030         // set it back
01031         $oSmarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'] ;
01032 
01033         //Sets subject to email
01034         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxsendednowsubject->getRawValue() );
01035 
01036         $sFullName = $oOrder->oxorder__oxbillfname->getRawValue() . " " . $oOrder->oxorder__oxbilllname->getRawValue();
01037 
01038         $this->setRecipient( $oOrder->oxorder__oxbillemail->value, $sFullName );
01039         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01040 
01041         return $this->send();
01042     }
01043 
01058     public function sendBackupMail( $aAttFiles, $sAttPath, $sEmailAddress, $sSubject, $sMessage, &$aStatus, &$aError )
01059     {
01060         // shop info
01061         $oShop = $this->_getShop();
01062 
01063         //set mail params (from, fromName, smtp)
01064         $this->_setMailParams( $oShop );
01065 
01066         $this->setBody( $sMessage );
01067         $this->setSubject( $sSubject );
01068 
01069         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
01070         $sEmailAddress = $sEmailAddress ? $sEmailAddress : $oShop->oxshops__oxowneremail->value;
01071 
01072         $this->setFrom( $sEmailAddress, "" );
01073         $this->setReplyTo( $sEmailAddress, "" );
01074 
01075         //attaching files
01076         $blAttashSucc = true;
01077         $sAttPath = oxUtilsFile::getInstance()->normalizeDir($sAttPath);
01078         foreach ( $aAttFiles as $iNum => $sAttFile ) {
01079             $sFullPath = $sAttPath . $sAttFile;
01080             if ( @is_readable( $sFullPath ) && @is_file( $sFullPath ) ) {
01081                 $blAttashSucc = $this->addAttachment( $sFullPath, $sAttFile );
01082             } else {
01083                 $blAttashSucc = false;
01084                 $aError[] = array( 5, $sAttFile );   //"Error: backup file $sAttFile not found";
01085             }
01086         }
01087 
01088         if ( !$blAttashSucc ) {
01089             $aError[] = array( 4, "" );   //"Error: backup files was not sent to email ...";
01090             $this->clearAttachments();
01091             return false;
01092         }
01093 
01094         $aStatus[] = 3;     //"Mailing backup files ...";
01095         $blSend = $this->send();
01096         $this->clearAttachments();
01097 
01098         return $blSend;
01099     }
01100 
01111     public function sendEmail( $sTo, $sSubject, $sBody )
01112     {
01113         //set mail params (from, fromName, smtp)
01114         $this->_setMailParams();
01115 
01116         if ( is_array($sTo) ) {
01117             foreach ($sTo as $sAddress) {
01118                 $this->setRecipient( $sAddress, "" );
01119                 $this->setReplyTo( $sAddress, "" );
01120             }
01121         } else {
01122             $this->setRecipient( $sTo, "" );
01123             $this->setReplyTo( $sTo, "" );
01124         }
01125 
01126         //may be changed later
01127         $this->isHtml( false );
01128 
01129         $this->setSubject( $sSubject );
01130         $this->setBody( $sBody );
01131 
01132         return $this->send();
01133     }
01134 
01143     public function sendStockReminder( $aBasketContents, $sSubject = null )
01144     {
01145         $blSend = false;
01146 
01147         $oArticleList = oxNew( "oxarticlelist" );
01148         $oArticleList->loadStockRemindProducts( $aBasketContents );
01149 
01150         // nothing to remind?
01151         if ( $oArticleList->count() ) {
01152             $oShop = $this->_getShop();
01153 
01154             //set mail params (from, fromName, smtp... )
01155             $this->_setMailParams( $oShop );
01156             $oLang = oxLang::getInstance();
01157 
01158             $oSmarty = $this->_getSmarty();
01159             $this->setViewData( "articles", $oArticleList );
01160 
01161             // Process view data array through oxoutput processor
01162             $this->_processViewArray();
01163 
01164             $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
01165             $this->setFrom( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
01166             $this->setBody( $oSmarty->fetch( $this->getConfig()->getTemplatePath( $this->_sReminderMailTemplate, false ) ) );
01167             $this->setAltBody( "" );
01168             $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString( 'EMAIL_STOCKREMINDER_SUBJECT' ) );
01169 
01170             $blSend = $this->send();
01171         }
01172 
01173         return $blSend;
01174     }
01175 
01184     public function sendWishlistMail( $oParams )
01185     {
01186         $myConfig = $this->getConfig();
01187 
01188         $this->_clearMailer();
01189 
01190         // shop info
01191         $oShop = $this->_getShop();
01192 
01193         // mailer stuff
01194         $this->setFrom( $oParams->send_email, $oParams->send_name );
01195         $this->setSMTP();
01196 
01197         // create messages
01198         $oSmarty = $this->_getSmarty();
01199         $this->setUser( $oParams );
01200 
01201         // Process view data array through oxoutput processor
01202         $this->_processViewArray();
01203 
01204         $this->setBody( $oSmarty->fetch( $this->_sWishListTemplate ) );
01205         $this->setAltBody( $oSmarty->fetch( $this->_sWishListTemplatePlain ) );
01206         $this->setSubject( $oParams->send_subject );
01207 
01208         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
01209         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
01210 
01211         return $this->send();
01212     }
01213 
01224     public function sendPriceAlarmNotification( $aParams, $oAlarm, $sSubject = null )
01225     {
01226         $this->_clearMailer();
01227         $oShop = $this->_getShop();
01228 
01229         //set mail params (from, fromName, smtp)
01230         $this->_setMailParams( $oShop );
01231 
01232         $iAlarmLang = $oAlarm->oxpricealarm__oxlang->value;
01233 
01234         $oArticle = oxNew( "oxarticle" );
01235         $oArticle->setSkipAbPrice( true );
01236         $oArticle->loadInLang( $iAlarmLang, $aParams['aid'] );
01237         $oLang = oxLang::getInstance();
01238 
01239         // create messages
01240         $oSmarty = $this->_getSmarty();
01241         $this->setViewData( "product", $oArticle );
01242         $this->setViewData( "email", $aParams['email']);
01243         $this->setViewData( "bidprice", $oLang->formatCurrency( $oAlarm->oxpricealarm__oxprice->value, $oCur ) );
01244 
01245         // Process view data array through oxoutput processor
01246         $this->_processViewArray();
01247 
01248         $this->setRecipient( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01249         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString( 'EMAIL_PRICEALARM_OWNER_SUBJECT', $iAlarmLang ) . " " . $oArticle->oxarticles__oxtitle->getRawValue() );
01250         $this->setBody( $oSmarty->fetch( $this->_sOwnerPricealarmTemplate ) );
01251         $this->setFrom( $aParams['email'], "" );
01252         $this->setReplyTo( $aParams['email'], "" );
01253 
01254         return $this->send();
01255     }
01256 
01268     public function sendPricealarmToCustomer( $sRecipient, $oAlarm, $sBody = null, $sReturnMailBody = null )
01269     {
01270         $this->_clearMailer();
01271 
01272         $oShop = $this->_getShop();
01273 
01274         if ( $oShop->getId() != $oAlarm->oxpricealarm__oxshopid->value) {
01275             $oShop = oxNew( "oxshop" );
01276             $oShop->load( $oAlarm->oxpricealarm__oxshopid->value);
01277             $this->setShop( $oShop );
01278         }
01279 
01280         //set mail params (from, fromName, smtp)
01281         $this->_setMailParams( $oShop );
01282 
01283         // create messages
01284         $oSmarty = $this->_getSmarty();
01285 
01286         $this->setViewData( "product", $oAlarm->getArticle() );
01287         $this->setViewData( "oPriceAlarm", $oAlarm );
01288         $this->setViewData( "bidprice", $oAlarm->getFProposedPrice() );
01289         $this->setViewData( "currency", $oAlarm->getPriceAlarmCurrency() );
01290 
01291         // Process view data array through oxoutput processor
01292         $this->_processViewArray();
01293 
01294         $this->setRecipient( $sRecipient, $sRecipient );
01295         $this->setSubject( $oShop->oxshops__oxname->value );
01296 
01297         if ( $sBody === null ) {
01298             $sBody = $oSmarty->fetch( $this->_sPricealamrCustomerTemplate );
01299         }
01300 
01301         $this->setBody( $sBody );
01302 
01303         $this->addAddress( $sRecipient, $sRecipient );
01304         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01305 
01306         if ( $sReturnMailBody ) {
01307             return $this->getBody();
01308         } else {
01309             return $this->send();
01310         }
01311     }
01312 
01324     protected function _includeImages($sImageDir = null, $sImageDirNoSSL = null, $sDynImageDir = null, $sAbsImageDir = null, $sAbsDynImageDir = null)
01325     {
01326         $sBody = $this->getBody();
01327         if (preg_match_all('/<\s*img\s+[^>]*?src[\s]*=[\s]*[\'"]?([^[\'">]]+|.*?)?[\'">]/i', $sBody, $matches, PREG_SET_ORDER)) {
01328 
01329             $oFileUtils = oxUtilsFile::getInstance();
01330             $blReSetBody = false;
01331 
01332             // preparing imput
01333             $sDynImageDir = $oFileUtils->normalizeDir( $sDynImageDir );
01334             $sImageDir = $oFileUtils->normalizeDir( $sImageDir );
01335             $sImageDirNoSSL = $oFileUtils->normalizeDir( $sImageDirNoSSL );
01336 
01337             if (is_array($matches) && count($matches)) {
01338                 $aImageCache = array();
01339                 $myUtils = oxUtils::getInstance();
01340                 $myUtilsObject = oxUtilsObject::getInstance();
01341                 $oImgGenerator = oxNew( "oxDynImgGenerator" );
01342 
01343                 foreach ($matches as $aImage) {
01344 
01345                     $image = $aImage[1];
01346                     $sFileName = '';
01347                     if ( strpos( $image, $sDynImageDir ) === 0 ) {
01348                         $sFileName = $oFileUtils->normalizeDir( $sAbsDynImageDir ) . str_replace( $sDynImageDir, '', $image );
01349                     } elseif ( strpos( $image, $sImageDir ) === 0 ) {
01350                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDir, '', $image );
01351                     } elseif ( strpos( $image, $sImageDirNoSSL ) === 0 ) {
01352                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDirNoSSL, '', $image );
01353                     }
01354 
01355                     if ( $sFileName && !@is_readable( $sFileName ) ) {
01356                         $sFileName = $oImgGenerator->getImagePath( $sFileName );
01357                     }
01358 
01359                     if ( $sFileName ) {
01360                         $sCId = '';
01361                         if ( isset( $aImageCache[$sFileName] ) && $aImageCache[$sFileName] ) {
01362                             $sCId = $aImageCache[$sFileName];
01363                         } else {
01364                             $sCId = $myUtilsObject->generateUID();
01365                             $sMIME = $myUtils->oxMimeContentType($sFileName);
01366                             if ($sMIME == 'image/jpeg' || $sMIME == 'image/gif' || $sMIME == 'image/png') {
01367                                 if ( $this->addEmbeddedImage( $sFileName, $sCId, "image", "base64", $sMIME ) ) {
01368                                     $aImageCache[$sFileName] = $sCId;
01369                                 } else {
01370                                     $sCId = '';
01371                                 }
01372                             }
01373                         }
01374                         if ( $sCId && $sCId == $aImageCache[$sFileName] ) {
01375                             if ( $sReplTag = str_replace( $image, 'cid:'.$sCId, $aImage[0] ) ) {
01376                                 $sBody = str_replace($aImage[0], $sReplTag, $sBody );
01377                                 $blReSetBody = true;
01378                             }
01379                         }
01380                     }
01381                 }
01382             }
01383 
01384             if ( $blReSetBody ) {
01385                 $this->setBody( $sBody );
01386             }
01387         }
01388     }
01389 
01397     public function setSubject( $sSubject = null )
01398     {
01399         // A. HTML entites in subjects must be replaced
01400         $sSubject = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sSubject);
01401 
01402         $this->set( "Subject", $sSubject );
01403     }
01404 
01410     public function getSubject()
01411     {
01412         return $this->Subject;
01413     }
01414 
01424     public function setBody( $sBody = null, $blClearSid = true )
01425     {
01426         if ( $blClearSid ) {
01427             $sBody = getStr()->preg_replace('/((\?|&(amp;)?)(force_)?(admin_)?)sid=[A-Z0-9\.]+/i', '\1sid=x&amp;shp=' . $this->getConfig()->getShopId(), $sBody);
01428         }
01429 
01430         $this->set( "Body", $sBody );
01431     }
01432 
01438     public function getBody()
01439     {
01440         return $this->Body;
01441     }
01442 
01452     public function setAltBody( $sAltBody = null, $blClearSid = true )
01453     {
01454         if ( $blClearSid ) {
01455             $sAltBody = getStr()->preg_replace('/((\?|&(amp;)?)(force_)?(admin_)?)sid=[A-Z0-9\.]+/i', '\1sid=x&amp;shp=' . $this->getConfig()->getShopId(), $sAltBody);
01456         }
01457 
01458         // A. alt body is used for plain text emails so we should eliminate HTML entities
01459         $sAltBody = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sAltBody);
01460 
01461         $this->set( "AltBody", $sAltBody );
01462     }
01463 
01469     public function getAltBody()
01470     {
01471         return $this->AltBody;
01472     }
01473 
01482     public function setRecipient( $sAddress = null, $sName = null )
01483     {
01484         try {
01485             parent::AddAddress( $sAddress, $sName );
01486 
01487             // copying values as original class does not allow to access recipients array
01488             $this->_aRecipients[] = array( $sAddress, $sName );
01489         } catch( Exception $oEx ) {
01490         }
01491     }
01492 
01500     public function getRecipient()
01501     {
01502         return $this->_aRecipients;
01503     }
01504 
01511     public function clearAllRecipients()
01512     {
01513         $this->_aRecipients = array();
01514         parent::clearAllRecipients();
01515     }
01516 
01528     public function setReplyTo( $sEmail = null, $sName = null )
01529     {
01530         if ( !oxUtils::getInstance()->isValidEmail( $sEmail ) ) {
01531             $sEmail = $this->_getShop()->oxshops__oxorderemail->value;
01532         }
01533 
01534         $this->_aReplies[] = array( $sEmail, $sName );
01535 
01536         try {
01537             parent::addReplyTo( $sEmail, $sName );
01538         } catch( Exception $oEx ) {
01539         }
01540     }
01541 
01547     public function getReplyTo()
01548     {
01549         return $this->_aReplies;
01550     }
01551 
01557     public function clearReplyTos()
01558     {
01559         $this->_aReplies = array();
01560         parent::clearReplyTos();
01561     }
01562 
01571     public function setFrom( $sFromAdress, $sFromName = null )
01572     {
01573         // preventing possible email spam over php mail() exploit (http://www.securephpwiki.com/index.php/Email_Injection)
01574         // this is simple but must work
01575         // dodger Task #1532 field "From" in emails from shops
01576         $sFromAdress = substr($sFromAdress, 0, 150);
01577         $sFromName   = substr($sFromName, 0, 150);
01578 
01579         try {
01580             parent::setFrom( $sFromAdress, $sFromName );
01581         } catch( Exception $oEx ) {
01582         }
01583     }
01584 
01590     public function getFrom()
01591     {
01592         return $this->From;
01593     }
01594 
01600     public function getFromName()
01601     {
01602         return $this->FromName;
01603     }
01604 
01613     public function setCharSet( $sCharSet = null )
01614     {
01615         if ( $sCharSet ) {
01616             $this->_sCharSet = $sCharSet;
01617         } else {
01618             $this->_sCharSet = oxLang::getInstance()->translateString( "charset" );
01619         }
01620         $this->set( "CharSet", $this->_sCharSet );
01621     }
01622 
01630     public function setMailer( $sMailer = null )
01631     {
01632         $this->set( "Mailer", $sMailer );
01633     }
01634 
01640     public function getMailer()
01641     {
01642         return $this->Mailer;
01643     }
01644 
01652     public function setHost( $sHost = null )
01653     {
01654         $this->set( "Host", $sHost );
01655     }
01656 
01662     public function getErrorInfo()
01663     {
01664         return $this->ErrorInfo;
01665     }
01666 
01675     public function setMailWordWrap( $iWordWrap = null )
01676     {
01677         $this->set( "WordWrap", $iWordWrap );
01678     }
01679 
01687     public function setUseInlineImages( $blUseImages = null )
01688     {
01689         $this->_blInlineImgEmail = $blUseImages;
01690     }
01691 
01702     public function addAttachment( $sAttPath, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01703     {
01704         $this->_aAttachments[] = array( $sAttPath, $sAttFile, $sEncoding, $sType );
01705         $blResult = false;
01706 
01707         try {
01708              $blResult = parent::addAttachment( $sAttPath, $sAttFile, $sEncoding, $sType );
01709         } catch( Exception $oEx ) {
01710         }
01711 
01712         return $blResult;
01713     }
01714 
01726     public function addEmbeddedImage( $sFullPath, $sCid, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01727     {
01728         $this->_aAttachments[] = array( $sFullPath, basename($sFullPath), $sAttFile, $sEncoding, $sType, false, 'inline', $sCid );
01729         return parent::addEmbeddedImage( $sFullPath, $sCid, $sAttFile, $sEncoding, $sType );
01730     }
01731 
01737     public function getAttachments()
01738     {
01739         return $this->_aAttachments;
01740     }
01741 
01747     public function clearAttachments()
01748     {
01749         $this->_aAttachments = array();
01750         return parent::clearAttachments();
01751     }
01752 
01762     public function headerLine($sName, $sValue)
01763     {
01764         if (stripos($sName, 'X-') !== false) {
01765             return;
01766         }
01767         return parent::headerLine($sName, $sValue);
01768     }
01769 
01775     protected function _getUseInlineImages()
01776     {
01777         return $this->_blInlineImgEmail;
01778     }
01779 
01785     protected function _sendMailErrorMsg()
01786     {
01787         // build addresses
01788         $sToAdress  = "";
01789         $sToName    = "";
01790 
01791         $aRecipients = $this->getRecipient();
01792 
01793         $sOwnerMessage  = "Error sending eMail(". $this->getSubject().") to: \n\n";
01794 
01795         foreach ( $aRecipients as $aEMail ) {
01796             $sOwnerMessage .= $aEMail[0];
01797             $sOwnerMessage .= ( !empty($aEMail[1]) ) ? ' (' . $aEMail[1] . ')' : '';
01798             $sOwnerMessage .= " \n ";
01799         }
01800         $sOwnerMessage .= "\n\nError : " . $this->getErrorInfo();
01801 
01802         // shop info
01803         $oShop = $this->_getShop();
01804 
01805         $blRet = @mail( $oShop->oxshops__oxorderemail->value, "eMail problem in shop!", $sOwnerMessage);
01806 
01807         return $blRet;
01808     }
01809 
01819     protected function _addUserInfoOrderEMail( $oOrder )
01820     {
01821         return $oOrder;
01822     }
01823 
01833     protected function _addUserRegisterEmail( $oUser )
01834     {
01835         return $oUser;
01836     }
01837 
01847     protected function _addForgotPwdEmail( $oShop )
01848     {
01849         return $oShop;
01850     }
01851 
01861     protected function _addNewsletterDbOptInMail( $oUser )
01862     {
01863         return $oUser;
01864     }
01865 
01871     protected function _clearMailer()
01872     {
01873         $this->clearAllRecipients();
01874         $this->clearReplyTos();
01875         $this->clearAttachments();
01876 
01877         //workaround for phpmailer as it doesn't cleanup as it should
01878         $this->error_count = 0;
01879         $this->ErrorInfo   = '';
01880     }
01881 
01889     protected function _setMailParams( $oShop = null )
01890     {
01891         $this->_clearMailer();
01892 
01893         if ( !$oShop ) {
01894             $oShop = $this->_getShop();
01895         }
01896 
01897         $this->setFrom( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01898         $this->setSmtp( $oShop );
01899     }
01900 
01910     protected function _getShop( $iLangId = null, $iShopId = null )
01911     {
01912 
01913         if ( isset( $this->_oShop ) ) {
01914             return $this->_oShop;
01915         }
01916 
01917         $myConfig = $this->getConfig();
01918 
01919         if ( $iLangId === null ) {
01920             $oShop = $myConfig->getActiveShop();
01921         } else {
01922             $oShop = oxNew( 'oxshop' );
01923             $oShop->loadInLang( $iLangId, $myConfig->getShopId() );
01924         }
01925 
01926         return $this->_oShop = $oShop;
01927     }
01928 
01937     protected function _setSmtpAuthInfo( $sUserName = null, $sUserPassword = null )
01938     {
01939         $this->set( "SMTPAuth", true );
01940         $this->set( "Username", $sUserName );
01941         $this->set( "Password", $sUserPassword );
01942     }
01943 
01951     protected function _setSmtpDebug( $blDebug = null )
01952     {
01953         $this->set( "SMTPDebug", $blDebug );
01954     }
01955 
01961     protected function _setMailerPluginDir()
01962     {
01963         $this->set( "PluginDir", getShopBasePath() . "core/phpmailer/" );
01964     }
01965 
01972     protected function _makeOutputProcessing()
01973     {
01974         $oOutput = oxNew( "oxoutput" );
01975         $this->setBody( $oOutput->process($this->getBody(), "oxemail") );
01976         $this->setAltBody( $oOutput->process($this->getAltBody(), "oxemail") );
01977         $oOutput->processEmail( $this );
01978     }
01979 
01985     protected function _sendMail()
01986     {
01987         $blResult = false;
01988         try {
01989              $blResult = parent::send();
01990         } catch( Exception $oEx ) {
01991         }
01992 
01993         return $blResult;
01994     }
01995 
01996 
02002     protected function _processViewArray()
02003     {
02004         $oSmarty = $this->_getSmarty();
02005         $oOutputProcessor = oxNew( "oxoutput" );
02006 
02007         // processing all setted view data
02008         foreach ( $this->_aViewData as $sKey => $sValue ) {
02009             $oSmarty->assign( $sKey, $sValue );
02010         }
02011 
02012         // processing assigned smarty variables
02013         $aNewSmartyArray  = $oOutputProcessor->processViewArray( $oSmarty->get_template_vars(), "oxemail" );
02014 
02015         foreach ( $aNewSmartyArray as $key => $val ) {
02016             $oSmarty->assign( $key, $val );
02017         }
02018     }
02019 
02025     public function getCharset()
02026     {
02027         if ( !$this->_sCharSet ) {
02028             return oxLang::getInstance()->translateString("charset");
02029         } else {
02030             return $this->CharSet;
02031         }
02032     }
02033 
02039     public function getShop()
02040     {
02041         return $this->_getShop();
02042     }
02043 
02051     public function setShop( $oShop )
02052     {
02053         $this->_oShop = $oShop;
02054     }
02055 
02061     public function getViewConfig()
02062     {
02063         return $this->getConfig()->getActiveView()->getViewConfig();
02064     }
02065 
02071     public function getView()
02072     {
02073         return $this->getConfig()->getActiveView();
02074     }
02075 
02081     public function getCurrency()
02082     {
02083         $oConfig = oxConfig::getInstance();
02084 
02085         return $oConfig->getActShopCurrencyObject();
02086     }
02087 
02096     public function setViewData( $sKey, $sValue )
02097     {
02098         $this->_aViewData[$sKey] = $sValue;
02099     }
02100 
02106     public function getViewData()
02107     {
02108         return $this->_aViewData;
02109     }
02110 
02118     public function getViewDataItem( $sKey )
02119     {
02120         if ( isset($this->_aViewData[$sKey]) ) {
02121             return $this->_aViewData;
02122         }
02123     }
02124 
02132     public function setUser( $oUser)
02133     {
02134         $this->_aViewData["oUser"] = $oUser;
02135     }
02136 
02142     public function getUser()
02143     {
02144         return $this->_aViewData["oUser"];
02145     }
02146 
02147 }