oxemail.php

Go to the documentation of this file.
00001 <?php
00005 require oxRegistry::getConfig()->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 $_sSendDownloadsTemplate = "email/html/senddownloadlinks.tpl";
00098 
00104     protected $_sSendDownloadsTemplatePlain = "email/plain/senddownloadlinks.tpl";
00105 
00111     protected $_sWishListTemplate = "email/html/wishlist.tpl";
00112 
00118     protected $_sWishListTemplatePlain = "email/plain/wishlist.tpl";
00119 
00125     protected $_sRegisterTemplate = "email/html/register.tpl";
00126 
00132     protected $_sRegisterTemplatePlain = "email/plain/register.tpl";
00133 
00139     protected $_sReminderMailTemplate = "email/html/owner_reminder.tpl";
00140 
00146     protected $_sOrderUserTemplate          = "email/html/order_cust.tpl";
00147 
00153     protected $_sOrderUserPlainTemplate     = "email/plain/order_cust.tpl";
00154 
00160     protected $_sOrderOwnerTemplate         = "email/html/order_owner.tpl";
00161 
00167     protected $_sOrderOwnerPlainTemplate    = "email/plain/order_owner.tpl";
00168 
00169     // #586A - additional templates for more customizable subjects
00170 
00176     protected $_sOrderUserSubjectTemplate   = "email/html/order_cust_subj.tpl";
00177 
00183     protected $_sOrderOwnerSubjectTemplate  = "email/html/order_owner_subj.tpl";
00184 
00190     protected $_sOwnerPricealarmTemplate    = "email/html/pricealarm_owner.tpl";
00191 
00197     protected $_sPricealamrCustomerTemplate    = "email_pricealarm_customer.tpl";
00198 
00204     protected $_aShops = array();
00205 
00211     protected $_blInlineImgEmail = null;
00212 
00218     protected $_aRecipients = array();
00219 
00225     protected $_aReplies = array();
00226 
00232     protected $_aAttachments = array();
00233 
00239     protected $_oSmarty = null;
00240 
00246     protected $_aViewData = array();
00247 
00253     protected $_oShop = null;
00254 
00260     protected $_sCharSet = null;
00261 
00265     public function __construct()
00266     {
00267         //enabling exception handling in phpmailer class
00268         parent::__construct( true );
00269 
00270         $myConfig = $this->getConfig();
00271 
00272         $this->_setMailerPluginDir();
00273         $this->setSmtp();
00274 
00275         $this->setUseInlineImages( $myConfig->getConfigParam('blInlineImgEmail') );
00276         $this->setMailWordWrap( 100 );
00277 
00278         $this->isHtml( true );
00279         $this->setLanguage( "en", $myConfig->getConfigParam( 'sShopDir' )."/core/phpmailer/language/");
00280 
00281         $this->_getSmarty();
00282     }
00283 
00295     public function __call( $sMethod, $aArgs )
00296     {
00297         if ( defined( 'OXID_PHP_UNIT' ) ) {
00298             if ( substr( $sMethod, 0, 4) == "UNIT" ) {
00299                 $sMethod = str_replace( "UNIT", "_", $sMethod );
00300             }
00301             if ( method_exists( $this, $sMethod)) {
00302                 return call_user_func_array( array( & $this, $sMethod ), $aArgs );
00303             }
00304         }
00305 
00306         throw new oxSystemComponentException( "Function '$sMethod' does not exist or is not accessible! (" . get_class($this) . ")".PHP_EOL);
00307     }
00308 
00314     public function getConfig()
00315     {
00316         if ( $this->_oConfig == null ) {
00317             $this->_oConfig = oxRegistry::getConfig();
00318         }
00319 
00320         return $this->_oConfig;
00321     }
00322 
00330     public function setConfig( $oConfig )
00331     {
00332         $this->_oConfig = $oConfig;
00333     }
00334 
00335 
00341     protected function _getSmarty()
00342     {
00343         if ( $this->_oSmarty === null ) {
00344             $this->_oSmarty = oxRegistry::get("oxUtilsView")->getSmarty();
00345         }
00346 
00347         //setting default view
00348         $this->_oSmarty->assign( "oEmailView", $this );
00349 
00350         return $this->_oSmarty;
00351     }
00352 
00360     public function send()
00361     {
00362         // if no recipients found, skipping sending
00363         if ( count( $this->getRecipient() ) < 1 ) {
00364             return false;
00365         }
00366 
00367         $myConfig = $this->getConfig();
00368         $this->setCharSet();
00369 
00370         if ( $this->_getUseInlineImages() ) {
00371             $this->_includeImages( $myConfig->getImageDir(), $myConfig->getImageUrl( false, false ), $myConfig->getPictureUrl(null, false),
00372                                    $myConfig->getImageDir(), $myConfig->getPictureDir(false));
00373         }
00374 
00375         $this->_makeOutputProcessing();
00376 
00377         // try to send mail via SMTP
00378         if ( $this->getMailer() == 'smtp' ) {
00379             $blRet = $this->_sendMail();
00380 
00381             // if sending failed, try to send via mail()
00382             if ( !$blRet ) {
00383                 // failed sending via SMTP, sending notification to shop owner
00384                 $this->_sendMailErrorMsg();
00385 
00386                 // trying to send using standard mailer
00387                 $this->setMailer( 'mail' );
00388                 $blRet = $this->_sendMail();
00389             }
00390         } else {
00391             // sending mail via mail()
00392             $this->setMailer( 'mail' );
00393             $blRet = $this->_sendMail();
00394         }
00395 
00396         if ( !$blRet ) {
00397             // failed sending, giving up, trying to send notification to shop owner
00398             $this->_sendMailErrorMsg();
00399         }
00400 
00401         return $blRet;
00402     }
00403 
00412     protected function _setSmtpProtocol($sUrl)
00413     {
00414         $sProtocol = '';
00415         $sSmtpHost = $sUrl;
00416         $aMatch = array();
00417         if ( getStr()->preg_match('@^([0-9a-z]+://)?(.*)$@i', $sUrl, $aMatch ) ) {
00418             if ($aMatch[1]) {
00419                 if (($aMatch[1] == 'ssl://') || ($aMatch[1] == 'tls://')) {
00420                     $this->set( "SMTPSecure", substr($aMatch[1], 0, 3) );
00421                 } else {
00422                     $sProtocol = $aMatch[1];
00423                 }
00424             }
00425             $sSmtpHost = $aMatch[2];
00426         }
00427 
00428         return $sProtocol.$sSmtpHost;
00429     }
00430 
00438     public function setSmtp( $oShop = null )
00439     {
00440         $myConfig = $this->getConfig();
00441         $oShop = ( $oShop ) ? $oShop : $this->_getShop();
00442 
00443         $sSmtpUrl = $this->_setSmtpProtocol($oShop->oxshops__oxsmtp->value);
00444 
00445         if ( !$this->_isValidSmtpHost( $sSmtpUrl ) ) {
00446             $this->setMailer( "mail" );
00447             return;
00448         }
00449 
00450         $this->setHost( $sSmtpUrl );
00451         $this->setMailer( "smtp" );
00452 
00453         if ( $oShop->oxshops__oxsmtpuser->value ) {
00454             $this->_setSmtpAuthInfo( $oShop->oxshops__oxsmtpuser->value, $oShop->oxshops__oxsmtppwd->value );
00455         }
00456 
00457         if ( $myConfig->getConfigParam( 'iDebug' ) == 6 ) {
00458             $this->_setSmtpDebug( true );
00459         }
00460     }
00461 
00469     protected function _isValidSmtpHost( $sSmtpHost )
00470     {
00471         $blIsSmtp = false;
00472         if ( $sSmtpHost ) {
00473             $sSmtpPort = $this->SMTP_PORT;
00474             $aMatch = array();
00475             if ( getStr()->preg_match('@^(.*?)(:([0-9]+))?$@i', $sSmtpHost, $aMatch)) {
00476                 $sSmtpHost = $aMatch[1];
00477                 $sSmtpPort = (int)$aMatch[3];
00478                 if (!$sSmtpPort) {
00479                     $sSmtpPort = $this->SMTP_PORT;
00480                 }
00481             }
00482             if ( $blIsSmtp = (bool) ( $rHandle = @fsockopen( $sSmtpHost, $sSmtpPort, $iErrNo, $sErrStr, 30 )) ) {
00483                 // closing connection ..
00484                 fclose( $rHandle );
00485             }
00486         }
00487 
00488         return $blIsSmtp;
00489     }
00490 
00500     public function sendOrderEmailToUser( $oOrder, $sSubject = null )
00501     {
00502         $myConfig = $this->getConfig();
00503 
00504         // add user defined stuff if there is any
00505         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00506 
00507         $oShop = $this->_getShop();
00508         $this->_setMailParams( $oShop );
00509 
00510         $oUser = $oOrder->getOrderUser();
00511         $this->setUser( $oUser );
00512 
00513         // create messages
00514         $oSmarty = $this->_getSmarty();
00515         $this->setViewData( "order", $oOrder);
00516 
00517         if ( $myConfig->getConfigParam( "bl_perfLoadReviews" ) ) {
00518             $this->setViewData( "blShowReviewLink", true );
00519         }
00520 
00521         // Process view data array through oxoutput processor
00522         $this->_processViewArray();
00523 
00524         $this->setBody( $oSmarty->fetch( $this->_sOrderUserTemplate ) );
00525         $this->setAltBody( $oSmarty->fetch( $this->_sOrderUserPlainTemplate ) );
00526 
00527         // #586A
00528         if ( $sSubject === null ) {
00529             if ( $oSmarty->template_exists( $this->_sOrderUserSubjectTemplate) ) {
00530                 $sSubject = $oSmarty->fetch( $this->_sOrderUserSubjectTemplate );
00531             } else {
00532                 $sSubject = $oShop->oxshops__oxordersubject->getRawValue()." (#".$oOrder->oxorder__oxordernr->value.")";
00533             }
00534         }
00535 
00536         $this->setSubject( $sSubject );
00537 
00538         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00539 
00540         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00541         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00542 
00543         $blSuccess = $this->send();
00544 
00545         return $blSuccess;
00546     }
00547 
00557     public function sendOrderEmailToOwner( $oOrder, $sSubject = null )
00558     {
00559         $myConfig = $this->getConfig();
00560 
00561         $oShop = $this->_getShop();
00562 
00563         // cleanup
00564         $this->_clearMailer();
00565 
00566         // add user defined stuff if there is any
00567         $oOrder = $this->_addUserInfoOrderEMail( $oOrder );
00568 
00569         $oUser = $oOrder->getOrderUser();
00570         $this->setUser( $oUser );
00571 
00572         // send confirmation to shop owner
00573         // send not pretending from order user, as different email domain rise spam filters
00574         $this->setFrom( $oShop->oxshops__oxowneremail->value );
00575 
00576         $oLang = oxRegistry::getLang();
00577         $iOrderLang = $oLang->getObjectTplLanguage();
00578 
00579         // if running shop language is different from admin lang. set in config
00580         // we have to load shop in config language
00581         if ( $oShop->getLanguage() != $iOrderLang ) {
00582             $oShop = $this->_getShop( $iOrderLang );
00583         }
00584 
00585         $this->setSmtp( $oShop );
00586 
00587         // create messages
00588         $oSmarty = $this->_getSmarty();
00589         $this->setViewData( "order", $oOrder );
00590 
00591         // Process view data array through oxoutput processor
00592         $this->_processViewArray();
00593 
00594         $this->setBody( $oSmarty->fetch( $myConfig->getTemplatePath( $this->_sOrderOwnerTemplate, false ) ) );
00595         $this->setAltBody( $oSmarty->fetch( $myConfig->getTemplatePath( $this->_sOrderOwnerPlainTemplate, false ) ) );
00596 
00597         //Sets subject to email
00598         // #586A
00599         if ( $sSubject === null ) {
00600             if ( $oSmarty->template_exists( $this->_sOrderOwnerSubjectTemplate) ) {
00601                 $sSubject = $oSmarty->fetch( $this->_sOrderOwnerSubjectTemplate );
00602             } else {
00603                  $sSubject = $oShop->oxshops__oxordersubject->getRawValue()." (#".$oOrder->oxorder__oxordernr->value.")";
00604             }
00605         }
00606 
00607         $this->setSubject( $sSubject );
00608         $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oLang->translateString("order") );
00609 
00610         if ( $oUser->oxuser__oxusername->value != "admin" ) {
00611             $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00612             $this->setReplyTo( $oUser->oxuser__oxusername->value, $sFullName );
00613         }
00614 
00615         $blSuccess = $this->send();
00616 
00617         // add user history
00618         $oRemark = oxNew( "oxremark" );
00619         $oRemark->oxremark__oxtext      = new oxField($this->getAltBody(), oxField::T_RAW);
00620         $oRemark->oxremark__oxparentid  = new oxField($oUser->getId(), oxField::T_RAW);
00621         $oRemark->oxremark__oxtype      = new oxField("o", oxField::T_RAW);
00622         $oRemark->save();
00623 
00624 
00625         if ( $myConfig->getConfigParam( 'iDebug' ) == 6) {
00626             oxRegistry::getUtils()->showMessageAndExit( "" );
00627         }
00628 
00629         return $blSuccess;
00630     }
00631 
00641     public function sendRegisterConfirmEmail( $oUser, $sSubject = null )
00642     {
00643         // setting content ident
00644 
00645         $this->setViewData( "contentident", "oxregisteraltemail" );
00646         $this->setViewData( "contentplainident", "oxregisterplainaltemail" );
00647 
00648         // sending email
00649         return $this->sendRegisterEmail( $oUser, $sSubject );
00650     }
00651 
00661     public function sendRegisterEmail( $oUser, $sSubject = null )
00662     {
00663         // add user defined stuff if there is any
00664         $oUser = $this->_addUserRegisterEmail( $oUser );
00665 
00666         // shop info
00667         $oShop = $this->_getShop();
00668 
00669         //set mail params (from, fromName, smtp )
00670         $this->_setMailParams( $oShop );
00671 
00672         // create messages
00673         $oSmarty = $this->_getSmarty();
00674         $this->setUser( $oUser );
00675 
00676         // Process view data array through oxoutput processor
00677         $this->_processViewArray();
00678 
00679         $this->setBody( $oSmarty->fetch( $this->_sRegisterTemplate ) );
00680         $this->setAltBody( $oSmarty->fetch( $this->_sRegisterTemplatePlain ) );
00681 
00682         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxregistersubject->getRawValue() );
00683 
00684         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00685 
00686         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00687         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00688 
00689         return $this->send();
00690     }
00691 
00701     public function sendForgotPwdEmail( $sEmailAddress, $sSubject = null )
00702     {
00703         $myConfig = $this->getConfig();
00704         $oDb = oxDb::getDb();
00705 
00706         // shop info
00707         $oShop = $this->_getShop();
00708 
00709         // add user defined stuff if there is any
00710         $oShop = $this->_addForgotPwdEmail( $oShop );
00711 
00712         //set mail params (from, fromName, smtp)
00713         $this->_setMailParams( $oShop );
00714 
00715         // user
00716         $sWhere = "oxuser.oxactive = 1 and oxuser.oxusername = ".$oDb->quote( $sEmailAddress )." and oxuser.oxpassword != ''";
00717         $sOrder = "";
00718         if ( $myConfig->getConfigParam( 'blMallUsers' )) {
00719             $sOrder = "order by oxshopid = '".$oShop->getId()."' desc";
00720         } else {
00721             $sWhere .= " and oxshopid = '".$oShop->getId()."'";
00722         }
00723 
00724         $sSelect = "select oxid from oxuser where $sWhere $sOrder";
00725         if ( ( $sOxId = $oDb->getOne( $sSelect ) ) ) {
00726 
00727             $oUser = oxNew( 'oxuser' );
00728             if ( $oUser->load($sOxId) ) {
00729                 // create messages
00730                 $oSmarty = $this->_getSmarty();
00731                 $this->setUser( $oUser );
00732 
00733                 // Process view data array through oxoutput processor
00734                 $this->_processViewArray();
00735 
00736                 $this->setBody( $oSmarty->fetch( $this->_sForgotPwdTemplate ) );
00737 
00738                 $this->setAltBody( $oSmarty->fetch( $this->_sForgotPwdTemplatePlain ) );
00739 
00740                 //sets subject of email
00741                 $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxforgotpwdsubject->getRawValue() );
00742 
00743                 $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00744 
00745                 $this->setRecipient( $sEmailAddress, $sFullName );
00746                 $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00747 
00748                 if ( !$this->send() ) {
00749                     return -1; // failed to send
00750                 }
00751                 return true; // success
00752             }
00753         }
00754 
00755         return false; // user with this email not found
00756     }
00757 
00768     public function sendContactMail( $sEmailAddress = null, $sSubject = null, $sMessage = null )
00769     {
00770 
00771         // shop info
00772         $oShop = $this->_getShop();
00773 
00774         //set mail params (from, fromName, smtp)
00775         $this->_setMailParams( $oShop );
00776 
00777         $this->setBody( $sMessage );
00778         $this->setSubject( $sSubject );
00779 
00780         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
00781         $this->setFrom( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
00782         $this->setReplyTo( $sEmailAddress, "" );
00783 
00784         return $this->send();
00785     }
00786 
00796     public function sendNewsletterDbOptInMail( $oUser, $sSubject = null )
00797     {
00798         $oLang = oxRegistry::getLang();
00799 
00800         // add user defined stuff if there is any
00801         $oUser = $this->_addNewsletterDbOptInMail( $oUser );
00802 
00803         // shop info
00804         $oShop = $this->_getShop();
00805 
00806         //set mail params (from, fromName, smtp)
00807         $this->_setMailParams( $oShop );
00808 
00809         // create messages
00810         $oSmarty = $this->_getSmarty();
00811         $this->setViewData( "subscribeLink", $this->_getNewsSubsLink($oUser->oxuser__oxid->value) );
00812         $this->setUser( $oUser );
00813 
00814         // Process view data array through oxoutput processor
00815         $this->_processViewArray();
00816 
00817         $this->setBody( $oSmarty->fetch( $this->_sNewsletterOptInTemplate ) );
00818         $this->setAltBody( $oSmarty->fetch( $this->_sNewsletterOptInTemplatePlain ) );
00819         $this->setSubject( ( $sSubject !== null ) ? $sSubject : oxRegistry::getLang()->translateString("EMAIL_NEWSLETTERDBOPTINMAIL_SUBJECT") . " " . $oShop->oxshops__oxname->getRawValue() );
00820 
00821         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00822 
00823         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00824         $this->setFrom( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00825         $this->setReplyTo( $oShop->oxshops__oxinfoemail->value, $oShop->oxshops__oxname->getRawValue() );
00826 
00827         return $this->send();
00828     }
00829 
00837     protected function _getNewsSubsLink( $sId )
00838     {
00839         $myConfig = $this->getConfig();
00840         $iActShopLang = $myConfig->getActiveShop()->getLanguage();
00841 
00842         $sUrl = $myConfig->getShopHomeURL().'cl=newsletter&amp;fnc=addme&amp;uid='.$sId;
00843         $sUrl.= ( $iActShopLang ) ? '&amp;lang='.$iActShopLang : "";
00844         return $sUrl;
00845     }
00846 
00857     public function sendNewsletterMail( $oNewsLetter, $oUser, $sSubject = null )
00858     {
00859         // shop info
00860         $oShop = $this->_getShop();
00861 
00862         //set mail params (from, fromName, smtp)
00863         $this->_setMailParams( $oShop );
00864 
00865         $sBody = $oNewsLetter->getHtmlText();
00866 
00867         if ( !empty($sBody) ) {
00868             $this->setBody( $sBody );
00869             $this->setAltBody( $oNewsLetter->getPlainText() );
00870         } else {
00871             $this->isHtml( false );
00872             $this->setBody( $oNewsLetter->getPlainText() );
00873         }
00874 
00875         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oNewsLetter->oxnewsletter__oxtitle->getRawValue() );
00876 
00877         $sFullName = $oUser->oxuser__oxfname->getRawValue() . " " . $oUser->oxuser__oxlname->getRawValue();
00878         $this->setRecipient( $oUser->oxuser__oxusername->value, $sFullName );
00879         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
00880 
00881         return $this->send();
00882     }
00883 
00893     public function sendSuggestMail( $oParams, $oProduct )
00894     {
00895         $myConfig = $this->getConfig();
00896 
00897         //sets language of shop
00898         $iCurrLang = $myConfig->getActiveShop()->getLanguage();
00899 
00900         // shop info
00901         $oShop = $this->_getShop( $iCurrLang );
00902 
00903         //sets language to article
00904         if ( $oProduct->getLanguage() != $iCurrLang ) {
00905             $oProduct->setLanguage( $iCurrLang );
00906             $oProduct->load( $oProduct->getId() );
00907         }
00908 
00909         // mailer stuff
00910         // send not pretending from suggesting user, as different email domain rise spam filters
00911         $this->setFrom( $oShop->oxshops__oxinfoemail->value );
00912         $this->setSMTP();
00913 
00914         // create messages
00915         $oSmarty = $this->_getSmarty();
00916         $this->setViewData( "product", $oProduct );
00917         $this->setUser( $oParams );
00918 
00919         $sArticleUrl = $oProduct->getLink();
00920 
00921         //setting recommended user id
00922         if ( $myConfig->getActiveView()->isActive('Invitations') && $oActiveUser = $oShop->getUser() ) {
00923             $sArticleUrl  = oxRegistry::get("oxUtilsUrl")->appendParamSeparator( $sArticleUrl );
00924             $sArticleUrl .= "su=" . $oActiveUser->getId();
00925         }
00926 
00927         $this->setViewData( "sArticleUrl", $sArticleUrl );
00928 
00929         // Process view data array through oxoutput processor
00930         $this->_processViewArray();
00931 
00932         $this->setBody( $oSmarty->fetch( $this->_sSuggestTemplate ) );
00933         $this->setAltBody( $oSmarty->fetch( $this->_sSuggestTemplatePlain ) );
00934         $this->setSubject( $oParams->send_subject );
00935 
00936         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
00937         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00938 
00939         return $this->send();
00940     }
00941 
00950     public function sendInviteMail( $oParams )
00951     {
00952         $myConfig = $this->getConfig();
00953 
00954         //sets language of shop
00955         $iCurrLang = $myConfig->getActiveShop()->getLanguage();
00956 
00957         // shop info
00958         $oShop = $this->_getShop( $iCurrLang );
00959 
00960         // mailer stuff
00961         $this->setFrom( $oParams->send_email, $oParams->send_name );
00962         $this->setSMTP();
00963 
00964         // create messages
00965         $oSmarty = oxRegistry::get("oxUtilsView")->getSmarty();
00966         $this->setUser( $oParams );
00967 
00968         $sHomeUrl = $this->getViewConfig()->getHomeLink();
00969 
00970         //setting recommended user id
00971         if ( $myConfig->getActiveView()->isActive('Invitations') && $oActiveUser = $oShop->getUser() ) {
00972             $sHomeUrl  = oxRegistry::get("oxUtilsUrl")->appendParamSeparator( $sHomeUrl );
00973             $sHomeUrl .= "su=" . $oActiveUser->getId();
00974         }
00975 
00976         if ( is_array($oParams->rec_email) && count($oParams->rec_email) > 0  ) {
00977             foreach ( $oParams->rec_email as $sEmail ) {
00978                 if ( !empty( $sEmail ) ) {
00979                     $sRegisterUrl  = oxRegistry::get("oxUtilsUrl")->appendParamSeparator( $sHomeUrl );
00980                     //setting recipient user email
00981                     $sRegisterUrl .= "re=" . md5($sEmail);
00982                     $this->setViewData( "sHomeUrl", $sRegisterUrl );
00983 
00984                     // Process view data array through oxoutput processor
00985                     $this->_processViewArray();
00986 
00987                     $this->setBody( $oSmarty->fetch( $this->_sInviteTemplate ) );
00988 
00989                     $this->setAltBody( $oSmarty->fetch( $this->_sInviteTemplatePlain ) );
00990                     $this->setSubject( $oParams->send_subject );
00991 
00992                     $this->setRecipient( $sEmail );
00993                     $this->setReplyTo( $oParams->send_email, $oParams->send_name );
00994                     $this->send();
00995                     $this->clearAllRecipients();
00996                 }
00997             }
00998             return true;
00999         }
01000 
01001         return false;
01002     }
01003 
01013     public function sendSendedNowMail( $oOrder, $sSubject = null )
01014     {
01015         $myConfig = $this->getConfig();
01016 
01017         $iOrderLang = (int) ( isset( $oOrder->oxorder__oxlang->value ) ? $oOrder->oxorder__oxlang->value : 0 );
01018 
01019         // shop info
01020         $oShop = $this->_getShop( $iOrderLang );
01021 
01022         //set mail params (from, fromName, smtp)
01023         $this->_setMailParams( $oShop );
01024 
01025         //create messages
01026         $oLang = oxRegistry::getLang();
01027         $oSmarty = $this->_getSmarty();
01028         $this->setViewData( "order", $oOrder );
01029         $this->setViewData( "shopTemplateDir", $myConfig->getTemplateDir(false) );
01030 
01031         if ( $myConfig->getConfigParam( "bl_perfLoadReviews" ) ) {
01032             $this->setViewData( "blShowReviewLink", true );
01033             $oUser = oxNew( 'oxuser' );
01034             $this->setViewData( "reviewuserhash", $oUser->getReviewUserHash($oOrder->oxorder__oxuserid->value) );
01035         }
01036 
01037         // Process view data array through oxoutput processor
01038         $this->_processViewArray();
01039 
01040         // dodger #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
01041         $aStore['INCLUDE_ANY'] = $oSmarty->security_settings['INCLUDE_ANY'];
01042         //V send email in order language
01043         $iOldTplLang = $oLang->getTplLanguage();
01044         $iOldBaseLang = $oLang->getTplLanguage();
01045         $oLang->setTplLanguage( $iOrderLang );
01046         $oLang->setBaseLanguage( $iOrderLang );
01047 
01048         $oSmarty->security_settings['INCLUDE_ANY'] = true;
01049         // force non admin to get correct paths (tpl, img)
01050         $myConfig->setAdminMode( false );
01051         $this->setBody( $oSmarty->fetch( $this->_sSenedNowTemplate ) );
01052         $this->setAltBody( $oSmarty->fetch( $this->_sSenedNowTemplatePlain ) );
01053         $myConfig->setAdminMode( true );
01054         $oLang->setTplLanguage( $iOldTplLang );
01055         $oLang->setBaseLanguage( $iOldBaseLang );
01056         // set it back
01057         $oSmarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'] ;
01058 
01059         //Sets subject to email
01060         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oShop->oxshops__oxsendednowsubject->getRawValue() );
01061 
01062         $sFullName = $oOrder->oxorder__oxbillfname->getRawValue() . " " . $oOrder->oxorder__oxbilllname->getRawValue();
01063 
01064         $this->setRecipient( $oOrder->oxorder__oxbillemail->value, $sFullName );
01065         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01066 
01067         return $this->send();
01068     }
01069 
01079     public function sendDownloadLinksMail( $oOrder, $sSubject = null )
01080     {
01081         $myConfig = $this->getConfig();
01082 
01083         $iOrderLang = (int) ( isset( $oOrder->oxorder__oxlang->value ) ? $oOrder->oxorder__oxlang->value : 0 );
01084 
01085         // shop info
01086         $oShop = $this->_getShop( $iOrderLang );
01087 
01088         //set mail params (from, fromName, smtp)
01089         $this->_setMailParams( $oShop );
01090 
01091         //create messages
01092         $oLang = oxRegistry::getLang();
01093         $oSmarty = $this->_getSmarty();
01094         $this->setViewData( "order", $oOrder );
01095         $this->setViewData( "shopTemplateDir", $myConfig->getTemplateDir(false) );
01096 
01097         $oUser = oxNew( 'oxuser' );
01098         $this->setViewData( "reviewuserhash", $oUser->getReviewUserHash($oOrder->oxorder__oxuserid->value) );
01099 
01100         // Process view data array through oxoutput processor
01101         $this->_processViewArray();
01102 
01103         // dodger #1469 - we need to patch security here as we do not use standard template dir, so smarty stops working
01104         $aStore['INCLUDE_ANY'] = $oSmarty->security_settings['INCLUDE_ANY'];
01105         //V send email in order language
01106         $iOldTplLang = $oLang->getTplLanguage();
01107         $iOldBaseLang = $oLang->getTplLanguage();
01108         $oLang->setTplLanguage( $iOrderLang );
01109         $oLang->setBaseLanguage( $iOrderLang );
01110 
01111         $oSmarty->security_settings['INCLUDE_ANY'] = true;
01112         // force non admin to get correct paths (tpl, img)
01113         $myConfig->setAdminMode( false );
01114         $this->setBody( $oSmarty->fetch( $this->_sSendDownloadsTemplate ) );
01115         $this->setAltBody( $oSmarty->fetch( $this->_sSendDownloadsTemplatePlain ) );
01116         $myConfig->setAdminMode( true );
01117         $oLang->setTplLanguage( $iOldTplLang );
01118         $oLang->setBaseLanguage( $iOldBaseLang );
01119         // set it back
01120         $oSmarty->security_settings['INCLUDE_ANY'] = $aStore['INCLUDE_ANY'] ;
01121 
01122         //Sets subject to email
01123         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString("EMAIL_SENDDOWNLOADS_SUBJECT") );
01124 
01125         $sFullName = $oOrder->oxorder__oxbillfname->getRawValue() . " " . $oOrder->oxorder__oxbilllname->getRawValue();
01126 
01127         $this->setRecipient( $oOrder->oxorder__oxbillemail->value, $sFullName );
01128         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01129 
01130         return $this->send();
01131     }
01132 
01147     public function sendBackupMail( $aAttFiles, $sAttPath, $sEmailAddress, $sSubject, $sMessage, &$aStatus, &$aError )
01148     {
01149         // shop info
01150         $oShop = $this->_getShop();
01151 
01152         //set mail params (from, fromName, smtp)
01153         $this->_setMailParams( $oShop );
01154 
01155         $this->setBody( $sMessage );
01156         $this->setSubject( $sSubject );
01157 
01158         $this->setRecipient( $oShop->oxshops__oxinfoemail->value, "" );
01159         $sEmailAddress = $sEmailAddress ? $sEmailAddress : $oShop->oxshops__oxowneremail->value;
01160 
01161         $this->setFrom( $sEmailAddress, "" );
01162         $this->setReplyTo( $sEmailAddress, "" );
01163 
01164         //attaching files
01165         $blAttashSucc = true;
01166         $sAttPath = oxRegistry::get("oxUtilsFile")->normalizeDir($sAttPath);
01167         foreach ( $aAttFiles as $iNum => $sAttFile ) {
01168             $sFullPath = $sAttPath . $sAttFile;
01169             if ( @is_readable( $sFullPath ) && @is_file( $sFullPath ) ) {
01170                 $blAttashSucc = $this->addAttachment( $sFullPath, $sAttFile );
01171             } else {
01172                 $blAttashSucc = false;
01173                 $aError[] = array( 5, $sAttFile );   //"Error: backup file $sAttFile not found";
01174             }
01175         }
01176 
01177         if ( !$blAttashSucc ) {
01178             $aError[] = array( 4, "" );   //"Error: backup files was not sent to email ...";
01179             $this->clearAttachments();
01180             return false;
01181         }
01182 
01183         $aStatus[] = 3;     //"Mailing backup files ...";
01184         $blSend = $this->send();
01185         $this->clearAttachments();
01186 
01187         return $blSend;
01188     }
01189 
01200     public function sendEmail( $sTo, $sSubject, $sBody )
01201     {
01202         //set mail params (from, fromName, smtp)
01203         $this->_setMailParams();
01204 
01205         if ( is_array($sTo) ) {
01206             foreach ($sTo as $sAddress) {
01207                 $this->setRecipient( $sAddress, "" );
01208                 $this->setReplyTo( $sAddress, "" );
01209             }
01210         } else {
01211             $this->setRecipient( $sTo, "" );
01212             $this->setReplyTo( $sTo, "" );
01213         }
01214 
01215         //may be changed later
01216         $this->isHtml( false );
01217 
01218         $this->setSubject( $sSubject );
01219         $this->setBody( $sBody );
01220 
01221         return $this->send();
01222     }
01223 
01232     public function sendStockReminder( $aBasketContents, $sSubject = null )
01233     {
01234         $blSend = false;
01235 
01236         $oArticleList = oxNew( "oxarticlelist" );
01237         $oArticleList->loadStockRemindProducts( $aBasketContents );
01238 
01239         // nothing to remind?
01240         if ( $oArticleList->count() ) {
01241             $oShop = $this->_getShop();
01242 
01243             //set mail params (from, fromName, smtp... )
01244             $this->_setMailParams( $oShop );
01245             $oLang = oxRegistry::getLang();
01246 
01247             $oSmarty = $this->_getSmarty();
01248             $this->setViewData( "articles", $oArticleList );
01249 
01250             // Process view data array through oxoutput processor
01251             $this->_processViewArray();
01252 
01253             $this->setRecipient( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
01254             $this->setFrom( $oShop->oxshops__oxowneremail->value, $oShop->oxshops__oxname->getRawValue() );
01255             $this->setBody( $oSmarty->fetch( $this->getConfig()->getTemplatePath( $this->_sReminderMailTemplate, false ) ) );
01256             $this->setAltBody( "" );
01257             $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString( 'EMAIL_STOCKREMINDER_SUBJECT' ) );
01258 
01259             $blSend = $this->send();
01260         }
01261 
01262         return $blSend;
01263     }
01264 
01273     public function sendWishlistMail( $oParams )
01274     {
01275         $myConfig = $this->getConfig();
01276 
01277         $this->_clearMailer();
01278 
01279         // shop info
01280         $oShop = $this->_getShop();
01281 
01282         // mailer stuff
01283         $this->setFrom( $oParams->send_email, $oParams->send_name );
01284         $this->setSMTP();
01285 
01286         // create messages
01287         $oSmarty = $this->_getSmarty();
01288         $this->setUser( $oParams );
01289 
01290         // Process view data array through oxoutput processor
01291         $this->_processViewArray();
01292 
01293         $this->setBody( $oSmarty->fetch( $this->_sWishListTemplate ) );
01294         $this->setAltBody( $oSmarty->fetch( $this->_sWishListTemplatePlain ) );
01295         $this->setSubject( $oParams->send_subject );
01296 
01297         $this->setRecipient( $oParams->rec_email, $oParams->rec_name );
01298         $this->setReplyTo( $oParams->send_email, $oParams->send_name );
01299 
01300         return $this->send();
01301     }
01302 
01313     public function sendPriceAlarmNotification( $aParams, $oAlarm, $sSubject = null )
01314     {
01315         $this->_clearMailer();
01316         $oShop = $this->_getShop();
01317 
01318         //set mail params (from, fromName, smtp)
01319         $this->_setMailParams( $oShop );
01320 
01321         $iAlarmLang = $oAlarm->oxpricealarm__oxlang->value;
01322 
01323         $oArticle = oxNew( "oxarticle" );
01324         //$oArticle->setSkipAbPrice( true );
01325         $oArticle->loadInLang( $iAlarmLang, $aParams['aid'] );
01326         $oLang = oxRegistry::getLang();
01327 
01328         // create messages
01329         $oSmarty = $this->_getSmarty();
01330         $this->setViewData( "product", $oArticle );
01331         $this->setViewData( "email", $aParams['email']);
01332         $this->setViewData( "bidprice", $oLang->formatCurrency( $oAlarm->oxpricealarm__oxprice->value, $oCur ) );
01333 
01334         // Process view data array through oxoutput processor
01335         $this->_processViewArray();
01336 
01337         $this->setRecipient( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01338         $this->setSubject( ( $sSubject !== null ) ? $sSubject : $oLang->translateString( 'EMAIL_PRICEALARM_OWNER_SUBJECT', $iAlarmLang ) . " " . $oArticle->oxarticles__oxtitle->getRawValue() );
01339         $this->setBody( $oSmarty->fetch( $this->_sOwnerPricealarmTemplate ) );
01340         $this->setFrom( $aParams['email'], "" );
01341         $this->setReplyTo( $aParams['email'], "" );
01342 
01343         return $this->send();
01344     }
01345 
01357     public function sendPricealarmToCustomer( $sRecipient, $oAlarm, $sBody = null, $sReturnMailBody = null )
01358     {
01359         $this->_clearMailer();
01360 
01361         $oShop = $this->_getShop();
01362 
01363         if ( $oShop->getId() != $oAlarm->oxpricealarm__oxshopid->value) {
01364             $oShop = oxNew( "oxshop" );
01365             $oShop->load( $oAlarm->oxpricealarm__oxshopid->value);
01366             $this->setShop( $oShop );
01367         }
01368 
01369         //set mail params (from, fromName, smtp)
01370         $this->_setMailParams( $oShop );
01371 
01372         // create messages
01373         $oSmarty = $this->_getSmarty();
01374 
01375         $this->setViewData( "product", $oAlarm->getArticle() );
01376         $this->setViewData( "oPriceAlarm", $oAlarm );
01377         $this->setViewData( "bidprice", $oAlarm->getFProposedPrice() );
01378         $this->setViewData( "currency", $oAlarm->getPriceAlarmCurrency() );
01379 
01380         // Process view data array through oxoutput processor
01381         $this->_processViewArray();
01382 
01383         $this->setRecipient( $sRecipient, $sRecipient );
01384         $this->setSubject( $oShop->oxshops__oxname->value );
01385 
01386         if ( $sBody === null ) {
01387             $sBody = $oSmarty->fetch( $this->_sPricealamrCustomerTemplate );
01388         }
01389 
01390         $this->setBody( $sBody );
01391 
01392         $this->addAddress( $sRecipient, $sRecipient );
01393         $this->setReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01394 
01395         if ( $sReturnMailBody ) {
01396             return $this->getBody();
01397         } else {
01398             return $this->send();
01399         }
01400     }
01401 
01413     protected function _includeImages($sImageDir = null, $sImageDirNoSSL = null, $sDynImageDir = null, $sAbsImageDir = null, $sAbsDynImageDir = null)
01414     {
01415         $sBody = $this->getBody();
01416         if (preg_match_all('/<\s*img\s+[^>]*?src[\s]*=[\s]*[\'"]?([^[\'">]]+|.*?)?[\'">]/i', $sBody, $matches, PREG_SET_ORDER)) {
01417 
01418             $oFileUtils = oxRegistry::get("oxUtilsFile");
01419             $blReSetBody = false;
01420 
01421             // preparing imput
01422             $sDynImageDir = $oFileUtils->normalizeDir( $sDynImageDir );
01423             $sImageDir = $oFileUtils->normalizeDir( $sImageDir );
01424             $sImageDirNoSSL = $oFileUtils->normalizeDir( $sImageDirNoSSL );
01425 
01426             if (is_array($matches) && count($matches)) {
01427                 $aImageCache = array();
01428                 $myUtils = oxRegistry::getUtils();
01429                 $myUtilsObject = oxUtilsObject::getInstance();
01430                 $oImgGenerator = oxNew( "oxDynImgGenerator" );
01431 
01432                 foreach ($matches as $aImage) {
01433 
01434                     $image = $aImage[1];
01435                     $sFileName = '';
01436                     if ( strpos( $image, $sDynImageDir ) === 0 ) {
01437                         $sFileName = $oFileUtils->normalizeDir( $sAbsDynImageDir ) . str_replace( $sDynImageDir, '', $image );
01438                     } elseif ( strpos( $image, $sImageDir ) === 0 ) {
01439                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDir, '', $image );
01440                     } elseif ( strpos( $image, $sImageDirNoSSL ) === 0 ) {
01441                         $sFileName = $oFileUtils->normalizeDir( $sAbsImageDir ) . str_replace( $sImageDirNoSSL, '', $image );
01442                     }
01443 
01444                     if ( $sFileName && !@is_readable( $sFileName ) ) {
01445                         $sFileName = $oImgGenerator->getImagePath( $sFileName );
01446                     }
01447 
01448                     if ( $sFileName ) {
01449                         $sCId = '';
01450                         if ( isset( $aImageCache[$sFileName] ) && $aImageCache[$sFileName] ) {
01451                             $sCId = $aImageCache[$sFileName];
01452                         } else {
01453                             $sCId = $myUtilsObject->generateUID();
01454                             $sMIME = $myUtils->oxMimeContentType($sFileName);
01455                             if ($sMIME == 'image/jpeg' || $sMIME == 'image/gif' || $sMIME == 'image/png') {
01456                                 if ( $this->addEmbeddedImage( $sFileName, $sCId, "image", "base64", $sMIME ) ) {
01457                                     $aImageCache[$sFileName] = $sCId;
01458                                 } else {
01459                                     $sCId = '';
01460                                 }
01461                             }
01462                         }
01463                         if ( $sCId && $sCId == $aImageCache[$sFileName] ) {
01464                             if ( $sReplTag = str_replace( $image, 'cid:'.$sCId, $aImage[0] ) ) {
01465                                 $sBody = str_replace($aImage[0], $sReplTag, $sBody );
01466                                 $blReSetBody = true;
01467                             }
01468                         }
01469                     }
01470                 }
01471             }
01472 
01473             if ( $blReSetBody ) {
01474                 $this->setBody( $sBody );
01475             }
01476         }
01477     }
01478 
01486     public function setSubject( $sSubject = null )
01487     {
01488         // A. HTML entites in subjects must be replaced
01489         $sSubject = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sSubject);
01490 
01491         $this->set( "Subject", $sSubject );
01492     }
01493 
01499     public function getSubject()
01500     {
01501         return $this->Subject;
01502     }
01503 
01513     public function setBody( $sBody = null, $blClearSid = true )
01514     {
01515         if ( $blClearSid ) {
01516             $sBody = getStr()->preg_replace('/((\?|&(amp;)?)(force_)?(admin_)?)sid=[A-Z0-9\.]+/i', '\1sid=x&amp;shp=' . $this->getConfig()->getShopId(), $sBody);
01517         }
01518 
01519         $this->set( "Body", $sBody );
01520     }
01521 
01527     public function getBody()
01528     {
01529         return $this->Body;
01530     }
01531 
01541     public function setAltBody( $sAltBody = null, $blClearSid = true )
01542     {
01543         if ( $blClearSid ) {
01544             $sAltBody = getStr()->preg_replace('/((\?|&(amp;)?)(force_)?(admin_)?)sid=[A-Z0-9\.]+/i', '\1sid=x&amp;shp=' . $this->getConfig()->getShopId(), $sAltBody);
01545         }
01546 
01547         // A. alt body is used for plain text emails so we should eliminate HTML entities
01548         $sAltBody = str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('&', '"', "'", '<', '>' ), $sAltBody);
01549 
01550         $this->set( "AltBody", $sAltBody );
01551     }
01552 
01558     public function getAltBody()
01559     {
01560         return $this->AltBody;
01561     }
01562 
01571     public function setRecipient( $sAddress = null, $sName = null )
01572     {
01573         try {
01574             parent::AddAddress( $sAddress, $sName );
01575 
01576             // copying values as original class does not allow to access recipients array
01577             $this->_aRecipients[] = array( $sAddress, $sName );
01578         } catch( Exception $oEx ) {
01579         }
01580     }
01581 
01589     public function getRecipient()
01590     {
01591         return $this->_aRecipients;
01592     }
01593 
01600     public function clearAllRecipients()
01601     {
01602         $this->_aRecipients = array();
01603         parent::clearAllRecipients();
01604     }
01605 
01617     public function setReplyTo( $sEmail = null, $sName = null )
01618     {
01619         if ( !oxRegistry::getUtils()->isValidEmail( $sEmail ) ) {
01620             $sEmail = $this->_getShop()->oxshops__oxorderemail->value;
01621         }
01622 
01623         $this->_aReplies[] = array( $sEmail, $sName );
01624 
01625         try {
01626             parent::addReplyTo( $sEmail, $sName );
01627         } catch( Exception $oEx ) {
01628         }
01629     }
01630 
01636     public function getReplyTo()
01637     {
01638         return $this->_aReplies;
01639     }
01640 
01646     public function clearReplyTos()
01647     {
01648         $this->_aReplies = array();
01649         parent::clearReplyTos();
01650     }
01651 
01660     public function setFrom( $sFromAdress, $sFromName = null )
01661     {
01662         // preventing possible email spam over php mail() exploit (http://www.securephpwiki.com/index.php/Email_Injection)
01663         // this is simple but must work
01664         // dodger Task #1532 field "From" in emails from shops
01665         $sFromAdress = substr($sFromAdress, 0, 150);
01666         $sFromName   = substr($sFromName, 0, 150);
01667 
01668         try {
01669             parent::setFrom( $sFromAdress, $sFromName );
01670         } catch( Exception $oEx ) {
01671         }
01672     }
01673 
01679     public function getFrom()
01680     {
01681         return $this->From;
01682     }
01683 
01689     public function getFromName()
01690     {
01691         return $this->FromName;
01692     }
01693 
01702     public function setCharSet( $sCharSet = null )
01703     {
01704         if ( $sCharSet ) {
01705             $this->_sCharSet = $sCharSet;
01706         } else {
01707             $this->_sCharSet = oxRegistry::getLang()->translateString( "charset" );
01708         }
01709         $this->set( "CharSet", $this->_sCharSet );
01710     }
01711 
01719     public function setMailer( $sMailer = null )
01720     {
01721         $this->set( "Mailer", $sMailer );
01722     }
01723 
01729     public function getMailer()
01730     {
01731         return $this->Mailer;
01732     }
01733 
01741     public function setHost( $sHost = null )
01742     {
01743         $this->set( "Host", $sHost );
01744     }
01745 
01751     public function getErrorInfo()
01752     {
01753         return $this->ErrorInfo;
01754     }
01755 
01764     public function setMailWordWrap( $iWordWrap = null )
01765     {
01766         $this->set( "WordWrap", $iWordWrap );
01767     }
01768 
01776     public function setUseInlineImages( $blUseImages = null )
01777     {
01778         $this->_blInlineImgEmail = $blUseImages;
01779     }
01780 
01791     public function addAttachment( $sAttPath, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01792     {
01793         $this->_aAttachments[] = array( $sAttPath, $sAttFile, $sEncoding, $sType );
01794         $blResult = false;
01795 
01796         try {
01797              $blResult = parent::addAttachment( $sAttPath, $sAttFile, $sEncoding, $sType );
01798         } catch( Exception $oEx ) {
01799         }
01800 
01801         return $blResult;
01802     }
01803 
01815     public function addEmbeddedImage( $sFullPath, $sCid, $sAttFile = '', $sEncoding = 'base64', $sType = 'application/octet-stream' )
01816     {
01817         $this->_aAttachments[] = array( $sFullPath, basename($sFullPath), $sAttFile, $sEncoding, $sType, false, 'inline', $sCid );
01818         return parent::addEmbeddedImage( $sFullPath, $sCid, $sAttFile, $sEncoding, $sType );
01819     }
01820 
01826     public function getAttachments()
01827     {
01828         return $this->_aAttachments;
01829     }
01830 
01836     public function clearAttachments()
01837     {
01838         $this->_aAttachments = array();
01839         return parent::clearAttachments();
01840     }
01841 
01851     public function headerLine($sName, $sValue)
01852     {
01853         if (stripos($sName, 'X-') !== false) {
01854             return;
01855         }
01856         return parent::headerLine($sName, $sValue);
01857     }
01858 
01864     protected function _getUseInlineImages()
01865     {
01866         return $this->_blInlineImgEmail;
01867     }
01868 
01874     protected function _sendMailErrorMsg()
01875     {
01876         // build addresses
01877         $sToAdress  = "";
01878         $sToName    = "";
01879 
01880         $aRecipients = $this->getRecipient();
01881 
01882         $sOwnerMessage  = "Error sending eMail(". $this->getSubject().") to: \n\n";
01883 
01884         foreach ( $aRecipients as $aEMail ) {
01885             $sOwnerMessage .= $aEMail[0];
01886             $sOwnerMessage .= ( !empty($aEMail[1]) ) ? ' (' . $aEMail[1] . ')' : '';
01887             $sOwnerMessage .= " \n ";
01888         }
01889         $sOwnerMessage .= "\n\nError : " . $this->getErrorInfo();
01890 
01891         // shop info
01892         $oShop = $this->_getShop();
01893 
01894         $blRet = @mail( $oShop->oxshops__oxorderemail->value, "eMail problem in shop!", $sOwnerMessage);
01895 
01896         return $blRet;
01897     }
01898 
01908     protected function _addUserInfoOrderEMail( $oOrder )
01909     {
01910         return $oOrder;
01911     }
01912 
01922     protected function _addUserRegisterEmail( $oUser )
01923     {
01924         return $oUser;
01925     }
01926 
01936     protected function _addForgotPwdEmail( $oShop )
01937     {
01938         return $oShop;
01939     }
01940 
01950     protected function _addNewsletterDbOptInMail( $oUser )
01951     {
01952         return $oUser;
01953     }
01954 
01960     protected function _clearMailer()
01961     {
01962         $this->clearAllRecipients();
01963         $this->clearReplyTos();
01964         $this->clearAttachments();
01965 
01966         //workaround for phpmailer as it doesn't cleanup as it should
01967         $this->error_count = 0;
01968         $this->ErrorInfo   = '';
01969     }
01970 
01978     protected function _setMailParams( $oShop = null )
01979     {
01980         $this->_clearMailer();
01981 
01982         if ( !$oShop ) {
01983             $oShop = $this->_getShop();
01984         }
01985 
01986         $this->setFrom( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue() );
01987         $this->setSmtp( $oShop );
01988     }
01989 
01999     protected function _getShop( $iLangId = null, $iShopId = null )
02000     {
02001         if ( $iLangId === null && $iShopId === null ) {
02002             if ( isset( $this->_oShop ) ) {
02003                 return $this->_oShop;
02004             } else {
02005                 return $this->_oShop = $this->getConfig()->getActiveShop();
02006             }
02007         }
02008 
02009         $myConfig = $this->getConfig();
02010 
02011         $oShop = oxNew( 'oxshop' );
02012         if ( $iShopId !== null ) {
02013             $oShop->setShopId($iShopId);
02014         }
02015         if ( $iLangId !== null ) {
02016             $oShop->setLanguage($iLangId);
02017         }
02018         $oShop->load($myConfig->getShopId());
02019 
02020         return $oShop;
02021     }
02022 
02031     protected function _setSmtpAuthInfo( $sUserName = null, $sUserPassword = null )
02032     {
02033         $this->set( "SMTPAuth", true );
02034         $this->set( "Username", $sUserName );
02035         $this->set( "Password", $sUserPassword );
02036     }
02037 
02045     protected function _setSmtpDebug( $blDebug = null )
02046     {
02047         $this->set( "SMTPDebug", $blDebug );
02048     }
02049 
02055     protected function _setMailerPluginDir()
02056     {
02057         $this->set( "PluginDir", getShopBasePath() . "core/phpmailer/" );
02058     }
02059 
02066     protected function _makeOutputProcessing()
02067     {
02068         $oOutput = oxNew( "oxoutput" );
02069         $this->setBody( $oOutput->process($this->getBody(), "oxemail") );
02070         $this->setAltBody( $oOutput->process($this->getAltBody(), "oxemail") );
02071         $oOutput->processEmail( $this );
02072     }
02073 
02079     protected function _sendMail()
02080     {
02081         $blResult = false;
02082         try {
02083             $blResult = parent::send();
02084         } catch( Exception $oException ) {
02085             $oEx = oxNew( "oxException" );
02086             $oEx->setMessage($oException->getMessage());
02087             $oEx->debugOut();
02088             if ( $this->getConfig()->getConfigParam( 'iDebug' ) != 0 ) {
02089                 throw $oEx;
02090             }
02091         }
02092         return $blResult;
02093     }
02094 
02095 
02101     protected function _processViewArray()
02102     {
02103         $oSmarty = $this->_getSmarty();
02104         $oOutputProcessor = oxNew( "oxoutput" );
02105 
02106         // processing all setted view data
02107         foreach ( $this->_aViewData as $sKey => $sValue ) {
02108             $oSmarty->assign( $sKey, $sValue );
02109         }
02110 
02111         // processing assigned smarty variables
02112         $aNewSmartyArray  = $oOutputProcessor->processViewArray( $oSmarty->get_template_vars(), "oxemail" );
02113 
02114         foreach ( $aNewSmartyArray as $key => $val ) {
02115             $oSmarty->assign( $key, $val );
02116         }
02117     }
02118 
02124     public function getCharset()
02125     {
02126         if ( !$this->_sCharSet ) {
02127             return oxRegistry::getLang()->translateString("charset");
02128         } else {
02129             return $this->CharSet;
02130         }
02131     }
02132 
02138     public function getShop()
02139     {
02140         return $this->_getShop();
02141     }
02142 
02150     public function setShop( $oShop )
02151     {
02152         $this->_oShop = $oShop;
02153     }
02154 
02160     public function getViewConfig()
02161     {
02162         return $this->getConfig()->getActiveView()->getViewConfig();
02163     }
02164 
02170     public function getView()
02171     {
02172         return $this->getConfig()->getActiveView();
02173     }
02174 
02180     public function getCurrency()
02181     {
02182         $oConfig = oxRegistry::getConfig();
02183 
02184         return $oConfig->getActShopCurrencyObject();
02185     }
02186 
02195     public function setViewData( $sKey, $sValue )
02196     {
02197         $this->_aViewData[$sKey] = $sValue;
02198     }
02199 
02205     public function getViewData()
02206     {
02207         return $this->_aViewData;
02208     }
02209 
02217     public function getViewDataItem( $sKey )
02218     {
02219         if ( isset($this->_aViewData[$sKey]) ) {
02220             return $this->_aViewData;
02221         }
02222     }
02223 
02231     public function setUser( $oUser)
02232     {
02233         $this->_aViewData["oUser"] = $oUser;
02234     }
02235 
02241     public function getUser()
02242     {
02243         return $this->_aViewData["oUser"];
02244     }
02245 
02253     public function getOrderFileList( $sOrderId )
02254     {
02255         $oOrderList = oxNew('oxOrderFileList');
02256         $oOrderList->loadOrderFiles( $sOrderId );
02257 
02258         if ( count($oOrderList) > 0 ) {
02259             return $oOrderList;
02260         }
02261 
02262         return false;
02263     }
02264 
02265 }