Changeset 950

Show
Ignore:
Timestamp:
07/24/08 07:22:45 (2 months ago)
Author:
bermiferrer
Message:

Adding automagically inline images to mail bodies as multipart/relative parts.

In order to disable this magic, you can set the attribute attach_html_images to false in your mailer.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/action_mailer/lib/AkActionMailer/AkMailBase.php

    r946 r950  
    1313    var $parts = array(); 
    1414    var $attachments = array(); 
     15     
     16    var $attach_html_images = true; 
    1517 
    1618    function AkMailBase() 
     
    5052            $content_type = @$this->content_type; 
    5153            $this->body = stristr($content_type,'text/') ? str_replace(array("\r\n","\r"),"\n", $body) : $body; 
    52             if($content_type == 'text/html'){ 
     54            if($this->attach_html_images && $content_type == 'text/html'){ 
    5355                $Parser = new AkMailParser(); 
    5456                $Parser->extractImagesIntoInlineParts($this); 
     
    135137    { 
    136138        return empty($this->content_type) ? ($this->isMultipart()?'multipart/alternative':null) : $this->content_type.$this->getContenttypeAttributes(); 
     139    } 
     140     
     141    function hasContentType() 
     142    { 
     143        return !empty($this->content_type); 
    137144    } 
    138145 
     
    291298    } 
    292299 
    293     function getRawHeaders(
     300    function getRawHeaders($options = array()
    294301    { 
    295302        if(empty($this->raw_headers)){ 
     303 
    296304            $this->headers = $this->getHeaders(true); 
    297305            if($this->isPart()){ 
    298                 $this->prepareHeadersForRendering(); 
     306                $this->prepareHeadersForRendering(array( 
     307                'skip' => (array)@$options['skip'], 
     308                'only' => (array)@$options['only'] 
     309                )); 
    299310            } 
    300311            unset($this->headers['Charset']); 
     
    309320            $this->loadHeaders(); 
    310321            $this->_addHeaderAttributes(); 
     322            
    311323        } 
    312324        return $this->headers; 
     
    515527            unset($this->$k); 
    516528        } 
     529         
    517530        $this->_multipart_message = true; 
    518531        $this->setPart($options, 'preppend'); 
     
    587600        $this->setPart($options); 
    588601    } 
    589  
     602     
    590603    function setAttachments($attachments = array()) 
    591604    { 
  • branches/action_mailer/lib/AkActionMailer/AkMailComposer.php

    r946 r950  
    169169            $raw_body = ''; 
    170170            $this->openMultipartBlock(); 
    171  
     171            if(!$Message->hasContentType()){ 
     172                $Message->setContentType('multipart/related'); 
     173            } 
    172174            $Message->content_type_attributes['boundary'] = $this->getBoundary(); 
    173175            $Message->_skip_adding_date_to_headers = !$Message->isMainMessage(); 
  • branches/action_mailer/lib/AkActionMailer/AkMailParser.php

    r915 r950  
    334334            if($modified_html != $html){ 
    335335                $html = $modified_html; 
    336                 $Mail->_moveBodyToInlinePart(false); 
     336                $Mail->_moveBodyToInlinePart(); 
    337337            } 
    338338        } 
  • branches/action_mailer/lib/AkActionMailer/AkMailPart.php

    r946 r950  
    44{ 
    55 
    6      
    7     function prepareHeadersForRendering(
     6 
     7    function prepareHeadersForRendering($options = array()
    88    { 
    9         $this->_removeUnnecesaryHeaders(); 
     9        if($this->isMultipart()){ 
     10            $this->filterHeaders(array('only' => array('Content-Type'))); 
     11        }else{ 
     12            $this->filterHeaders(); 
     13        } 
    1014    } 
    1115 
    12     function _removeUnnecesaryHeaders(
     16    function filterHeaders($options = array()
    1317    { 
    14         $headers = $this->getHeaders(); 
     18        $default_options = array( 
    1519 
    16         $this->headers = array(); 
    17         foreach (array( 
     20        'only' => empty($options['include']) ? array( 
    1821        'Content-Type', 
    1922        'Content-Transfer-Encoding', 
     
    2124        'Content-Disposition', 
    2225        'Content-Description', 
    23         ) as $allowed_header){ 
    24             if(isset($headers[$allowed_header])){ 
    25                 $this->headers[$allowed_header] = $headers[$allowed_header]; 
     26 
     27        ) : array() 
     28        ); 
     29 
     30        $options = array_merge($default_options, $options); 
     31 
     32        if(!empty($options['only'])){ 
     33            $headers = $this->getHeaders(); 
     34            $this->headers = array(); 
     35            foreach ($options['only'] as $allowed_header){ 
     36                if(isset($headers[$allowed_header])){ 
     37                    $this->headers[$allowed_header] = $headers[$allowed_header]; 
     38                } 
     39            } 
     40        }elseif (!empty($options['except'])){ 
     41            $this->headers = array(); 
     42            foreach ($options['except'] as $skip_header){ 
     43                unset($this->headers[$skip_header]); 
    2644            } 
    2745        } 
  • branches/action_mailer/test/unit/lib/AkActionMailer.php

    r946 r950  
    183183 
    184184 
    185     /**
     185    /**
    186186    function test_nested_parts() 
    187187    { 
     
    738738 
    739739 
    740     function _test_should_encode_alternative_message_from_templates() 
     740    function test_should_encode_alternative_message_from_templates() 
    741741    { 
    742742        $TestMailer =& new TestMailer(); 
     
    744744        $rendered_message = $TestMailer->getRawMessage(); 
    745745 
     746         
    746747        $this->assertPattern(   '/Content-Type: multipart\/alternative;charset=UTF-8;boundary=[a-f0-9]{32}\r\n'. 
    747748        'Mime-Version: 1.0\r\n'. 
     
    749750        $this->assertPattern('/To:/', $rendered_message); 
    750751        $this->assertPattern('/Date:/', $rendered_message); 
    751         $this->assertPattern('/--[a-f0-9]{32}\r\nContent-Type: text\/plain;charset=UTF-8\r\nContent-Disposition: inline/', $rendered_message); 
    752         $this->assertPattern('/--[a-f0-9]{32}\r\nContent-Type: text\/html;charset=UTF-8\r\nContent-Disposition: inline/', $rendered_message); 
     752        $this->assertPattern('/--[a-f0-9]{32}\r\nContent-Type: text\/plain;charset=UTF-8\r\nContent-Transfer-Encoding: quoted-printable\r\nContent-Disposition: inline/', $rendered_message); 
     753        $this->assertPattern('/--[a-f0-9]{32}\r\nContent-Type: text\/html;charset=UTF-8\r\nContent-Transfer-Encoding: quoted-printable\r\nContent-Disposition: inline/', $rendered_message); 
    753754        $this->assertPattern('/--[a-f0-9]{32}--/', $rendered_message); 
    754755    } 
    755 */ 
     756    /**/ 
    756757    function test_should_encode_alternative_message_from_templates_with_embeded_images() 
    757758    { 
     
    759760        $Message = $TestMailer->create('alternative_message_from_templates', $this->recipient, true); 
    760761 
    761         $TestMailer->delivery_method = 'smtp'; 
     762        //$TestMailer->delivery_method = 'smtp'; 
    762763 
    763764        $TestMailer->deliver($Message); 
     
    765766        $rendered_message = $TestMailer->getRawMessage(); 
    766767         
    767         echo $rendered_message; 
     768        //echo $rendered_message; 
    768769        return ; 
    769770 
     
    784785} 
    785786 
    786 //Ak::test('Tests_for_Mailers'); 
     787Ak::test('Tests_for_Mailers'); 
    787788Ak::test('Tests_for_AkActionMailer'); 
    788789