Ticket #530: jmailer.diff

File jmailer.diff, 3.5 kB (added by Lipki, 8 months ago)
  • jMailer.class.php

    old new  
    8686    public $Body               = ""; 
    8787 
    8888    /** 
     89     * Use tpl for sets the Body of the message.  This can be either an HTML or text body. 
     90     * If HTML then run IsHTML(true). 
     91     * @var string 
     92     */ 
     93    public $BodyTpl; 
     94 
     95    /** 
    8996     * Sets the text-only body of the message.  This automatically sets the 
    9097     * email to multipart/alternative.  This body can be read by mail 
    9198     * clients that do not have HTML email capability such as mutt. Clients 
     
    345355        $this->ReplyTo[$cur][0] = trim($address); 
    346356        $this->ReplyTo[$cur][1] = $name; 
    347357    } 
     358     
     359    function decAdrs( $adresse, $type = 'addresse' ) { 
     360         
     361        $tab = explode(':', $adresse); 
     362        if( $type == 'addresse' ) return $tab[0]; 
     363        if( $type == 'name' && isset($tab[1]) ) return $tab[1]; 
     364         
     365    } 
    348366 
     367    /** 
     368     * Adds a Tpl référence. 
     369     * @param string $selector 
     370     * @return void 
     371     */ 
     372    function Tpl( $selector ) { 
     373         
     374        $this->BodyTpl = $selector; 
     375         
     376    } 
    349377 
    350378    ///////////////////////////////////////////////// 
    351379    // MAIL SENDING METHODS 
     
    361389        $header = ""; 
    362390        $body = ""; 
    363391        $result = true; 
     392         
     393        if( isset($this->BodyTpl) ) { 
     394             
     395            $mailtpl = new jTpl(); 
     396            $metas = $mailtpl->meta( $this->BodyTpl ); 
     397             
     398            if( isset($metas['Subject']) ) 
     399                $this->Subject = $metas['Subject']; 
     400                 
     401            if( isset($metas['Priority']) ) 
     402                $this->Priority = $metas['Priority']; 
     403            $mailtpl->assign('Priority', $this->Priority ); 
     404                 
     405            if( isset($metas['From']) ) { 
     406                $this->From = $this->decAdrs( $metas['From'], 'addresse' ); 
     407                $this->FromName = $this->decAdrs( $metas['From'], 'name' ); 
     408            } 
     409            $mailtpl->assign('From', $this->From ); 
     410            $mailtpl->assign('FromName', $this->FromName ); 
     411             
     412            if( isset($metas['Sender']) ) 
     413                $this->Sender = $metas['Sender']; 
     414            $mailtpl->assign('Sender', $this->Sender ); 
     415             
     416            if( isset($metas['to']) ) 
     417                foreach( $metas['to'] as $val )  
     418                    $this->AddAddress($this->decAdrs($val, 'addresse'), $this->decAdrs($val, 'name')); 
     419            $mailtpl->assign('to', $this->to ); 
     420                     
     421            if( isset($metas['cc']) ) 
     422                foreach( $metas['cc'] as $val )  
     423                    $this->AddCC($this->decAdrs($val, 'addresse'), $this->decAdrs($val, 'name')); 
     424            $mailtpl->assign('cc', $this->cc ); 
     425                     
     426            if( isset($metas['bcc']) ) 
     427                foreach( $metas['bcc'] as $val )  
     428                    $this->AddBCC($this->decAdrs($val, 'addresse'), $this->decAdrs($val, 'name')); 
     429            $mailtpl->assign('bcc', $this->bcc ); 
     430                     
     431            if( isset($metas['ReplyTo']) ) 
     432                foreach( $metas['ReplyTo'] as $val )  
     433                    $this->AddReplyTo($this->decAdrs($val, 'addresse'), $this->decAdrs($val, 'name')); 
     434            $mailtpl->assign('ReplyTo', $this->ReplyTo ); 
     435             
     436            $this->Body = $mailtpl->fetch( $this->BodyTpl ); 
     437             
     438        } 
    364439 
    365440        if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) 
    366441        { 
Download in other formats: Original Format