Changeset 1044

Show
Ignore:
Timestamp:
07/24/08 08:34:01 (4 months ago)
Author:
bastnic
Message:

fixed #530 : improvement in jMailer, p=lipki

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jelix/CREDITS

    r1039 r1044  
    5757 - trois plugin swf (#498) 
    5858 - plugin coord history (#507) 
     59 - improvement in jMailer (#530) 
    5960 
    6061Loic Mathaud (bballizlife): 
  • trunk/lib/jelix/utils/jMailer.class.php

    r1026 r1044  
    1212* @subpackage  utils 
    1313* @author      Brent R. Matzelle 
    14 * @contributor Laurent Jouanneau 
     14* @contributor Laurent Jouanneau, Kévin Lepeltier 
    1515* @copyright   2001 - 2003  Brent R. Matzelle, 2006 Laurent Jouanneau 
     16* @copyright   2008 Kévin Lepeltier 
    1617* @link        http://www.jelix.org 
    1718* @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 
     
    8586     */ 
    8687    public $Body               = ""; 
     88 
     89    /** 
     90     * Use tpl for sets the Body of the message.  This can be either an HTML or text body. 
     91     * If HTML then run IsHTML(true). 
     92     * @var string 
     93     */ 
     94    public $bodyTpl; 
    8795 
    8896    /** 
     
    346354        $this->ReplyTo[$cur][1] = $name; 
    347355    } 
    348  
     356     
     357 
     358    /** 
     359     * Find the name and address in the form "name<address@hop.tld>" 
     360     * @param string $address 
     361     * @return array( $name, $address ) 
     362     */ 
     363    function getAddrName($address) { 
     364         
     365        preg_match ('`^([^<]*)<([^>]*)>$`', $address, $tab ); 
     366        array_shift($tab); 
     367        return $tab; 
     368         
     369    } 
     370 
     371    /** 
     372     * Adds a Tpl référence. 
     373     * @param string $selector 
     374     * @return void 
     375     */ 
     376    function Tpl( $selector ) { 
     377         
     378        $this->bodyTpl = $selector; 
     379         
     380    } 
    349381 
    350382    ///////////////////////////////////////////////// 
     
    362394        $body = ""; 
    363395        $result = true; 
     396         
     397        if( isset($this->bodyTpl) && $this->bodyTpl != "") { 
     398             
     399            $mailtpl = new jTpl(); 
     400            $metas = $mailtpl->meta( $this->bodyTpl ); 
     401             
     402            if( isset($metas['Subject']) ) 
     403                $this->Subject = $metas['Subject']; 
     404                 
     405            if( isset($metas['Priority']) ) 
     406                $this->Priority = $metas['Priority']; 
     407            $mailtpl->assign('Priority', $this->Priority ); 
     408                 
     409            if( isset($metas['From']) ) { 
     410                $adr = $this->getAddrName( $metas['From'] ); 
     411                $this->From = $adr[1]; 
     412                $this->FromName = $adr[0]; 
     413            } 
     414            $mailtpl->assign('From', $this->From ); 
     415            $mailtpl->assign('FromName', $this->FromName ); 
     416             
     417            if( isset($metas['Sender']) ) 
     418                $this->Sender = $metas['Sender']; 
     419            $mailtpl->assign('Sender', $this->Sender ); 
     420             
     421            if( isset($metas['to']) ) 
     422                foreach( $metas['to'] as $val ) 
     423                    $this->to[] = $this->getAddrName( $val ); 
     424            $mailtpl->assign('to', $this->to ); 
     425                     
     426            if( isset($metas['cc']) ) 
     427                foreach( $metas['cc'] as $val ) 
     428                    $this->cc[] = $this->getAddrName( $val ); 
     429            $mailtpl->assign('cc', $this->cc ); 
     430                     
     431            if( isset($metas['bcc']) ) 
     432                foreach( $metas['bcc'] as $val ) 
     433                    $this->bcc[] = $this->getAddrName( $val ); 
     434            $mailtpl->assign('bcc', $this->bcc ); 
     435                     
     436            if( isset($metas['ReplyTo']) ) 
     437                foreach( $metas['ReplyTo'] as $val ) 
     438                    $this->ReplyTo[] = $this->getAddrName( $val ); 
     439            $mailtpl->assign('ReplyTo', $this->ReplyTo ); 
     440             
     441            $this->Body = $mailtpl->fetch( $this->bodyTpl ); 
     442             
     443        } 
    364444 
    365445        if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) 
Download in other formats: Unified Diff Zip Archive