Changeset aa16b4a in github for program/include/rcube_message.php


Ignore:
Timestamp:
Dec 23, 2009 3:01:39 AM (3 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
1004407
Parents:
be11a9f
Message:
  • Improved handling of message parts of type message/rfc822 (fixed e.g. inline images in multipart/alternative messages attached as message/rfc822)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/include/rcube_message.php

    refe5a55 raa16b4a  
    225225   * @param object rcube_message_part Message structure node 
    226226   * @param bool  True when called recursively 
    227    * @param bool  True when message should be parsed as message/alternative 
    228    */ 
    229   private function parse_structure($structure, $recursive = false, $force_alternative = false) 
    230   { 
    231     $message_ctype_primary = strtolower($structure->ctype_primary); 
    232     $message_ctype_secondary = strtolower($structure->ctype_secondary); 
     227   */ 
     228  private function parse_structure($structure, $recursive = false) 
     229  { 
     230    $message_ctype_primary = $structure->ctype_primary; 
     231    $message_ctype_secondary = $structure->ctype_secondary; 
     232    $mimetype = $structure->mimetype; 
     233 
     234    // real content-type of message/rfc822 part 
     235    if ($mimetype == 'message/rfc822') { 
     236      if ($structure->real_mimetype) { 
     237        $mimetype = $structure->real_mimetype; 
     238        list($message_ctype_primary, $message_ctype_secondary) = explode('/', $mimetype); 
     239      } 
     240    } 
    233241 
    234242    // show message headers 
     
    246254    } 
    247255    // the same for pgp signed messages 
    248     else if ($message_ctype_primary == 'application' && $message_ctype_secondary == 'pgp' && !$recursive) { 
     256    else if ($mimetype == 'application/pgp' && !$recursive) { 
    249257      $structure->type = 'content'; 
    250258      $this->parts[] = &$structure; 
    251259    } 
    252260    // message contains alternative parts 
    253     else if ($message_ctype_primary == 'multipart' && ($message_ctype_secondary == 'alternative') && is_array($structure->parts)) { 
     261    else if ($mimetype == 'multipart/alternative' && is_array($structure->parts)) { 
    254262      // get html/plaintext parts 
    255263      $plain_part = $html_part = $print_part = $related_part = null; 
    256264 
    257265      foreach ($structure->parts as $p => $sub_part) { 
    258         $rel_parts = $attachmnts = null; 
    259         $sub_ctype_primary = strtolower($sub_part->ctype_primary); 
    260         $sub_ctype_secondary = strtolower($sub_part->ctype_secondary); 
     266        $sub_mimetype = $sub_part->mimetype; 
    261267         
    262         // check if sub part is  
    263         if ($sub_ctype_primary=='text' && $sub_ctype_secondary=='plain') 
     268        // check if sub part is 
     269        if ($sub_mimetype == 'text/plain') 
    264270          $plain_part = $p; 
    265         else if ($sub_ctype_primary=='text' && $sub_ctype_secondary=='html') 
     271        else if ($sub_mimetype == 'text/html') 
    266272          $html_part = $p; 
    267         else if ($sub_ctype_primary=='text' && $sub_ctype_secondary=='enriched') 
     273        else if ($sub_mimetype == 'text/enriched') 
    268274          $enriched_part = $p; 
    269         else if ($sub_ctype_primary=='multipart' && in_array($sub_ctype_secondary, array('related', 'mixed', 'alternative'))) 
     275        else if (in_array($sub_mimetype, array('multipart/related', 'multipart/mixed', 'multipart/alternative'))) 
    270276          $related_part = $p; 
    271277      } 
     
    319325    } 
    320326    // this is an ecrypted message -> create a plaintext body with the according message 
    321     else if ($message_ctype_primary == 'multipart' && $message_ctype_secondary == 'encrypted') { 
     327    else if ($mimetype == 'multipart/encrypted') { 
    322328      $p = new stdClass; 
    323329      $p->type = 'content'; 
     
    341347      for ($i=0; $i < count($structure->parts); $i++) { 
    342348        $mail_part = &$structure->parts[$i]; 
    343         $primary_type = strtolower($mail_part->ctype_primary); 
    344         $secondary_type = strtolower($mail_part->ctype_secondary); 
     349        $primary_type = $mail_part->ctype_primary; 
     350        $secondary_type = $mail_part->ctype_secondary; 
     351 
     352        // real content-type of message/rfc822 
     353        if ($mail_part->real_mimetype) { 
     354          $part_orig_mimetype = $mail_part->mimetype; 
     355          $part_mimetype = $mail_part->real_mimetype; 
     356          list($primary_type, $secondary_type) = explode('/', $part_mimetype); 
     357        } 
     358        else 
     359          $part_mimetype = $mail_part->mimetype; 
    345360 
    346361        // multipart/alternative 
    347362        if ($primary_type=='multipart') { 
    348363          $this->parse_structure($mail_part, true); 
     364 
     365          // list message/rfc822 as attachment as well (mostly .eml) 
     366          if ($part_orig_mimetype == 'message/rfc822' && !empty($mail_part->filename)) 
     367            $this->attachments[] = $mail_part; 
    349368        } 
    350369        // part text/[plain|html] OR message/delivery-status 
    351         else if (($primary_type == 'text' && ($secondary_type == 'plain' || $secondary_type == 'html') && $mail_part->disposition != 'attachment') || 
    352                  ($primary_type == 'message' && ($secondary_type == 'delivery-status' || $secondary_type == 'disposition-notification'))) { 
     370        else if ((($part_mimetype == 'text/plain' || $part_mimetype == 'text/html') && $mail_part->disposition != 'attachment') || 
     371            $part_mimetype == 'message/delivery-status' || $part_mimetype == 'message/disposition-notification') { 
    353372 
    354373          // add text part if it matches the prefs 
    355           if ((!$this->parse_alternative && !$force_alternative) || 
     374          if (!$this->parse_alternative || 
    356375              ($secondary_type == 'html' && $this->opt['prefer_html']) || 
    357376              ($secondary_type == 'plain' && !$this->opt['prefer_html'])) { 
     
    366385        // part message/* 
    367386        else if ($primary_type=='message') { 
    368           // let's try to find out if message/rfc822 is a multipart/alternative 
    369           if ($secondary_type == 'rfc822' && is_array($mail_part->parts) && count($mail_part->parts) > 1) { 
    370             $types = array(); 
    371             // iterate over parts to find its types and count them by type 
    372             for ($j=0; $j < count($mail_part->parts); $j++) { 
    373               $_type = strtolower($mail_part->parts[$j]->ctype_primary).'/'.strtolower($mail_part->parts[$j]->ctype_secondary); 
    374               $types[$_type] = $types[$_type] ? $types[$_type]+1 : 1; 
    375             } 
    376             if ($types['text/plain'] == 1 && $types['text/html'] == 1) 
    377               $_alternative = true; 
    378           } 
    379           $this->parse_structure($mail_part, true, $_alternative); 
     387          $this->parse_structure($mail_part, true); 
    380388 
    381389          // list as attachment as well (mostly .eml) 
     
    388396           
    389397        // part is Microsoft Outlook TNEF (winmail.dat) 
    390         else if ($primary_type == 'application' && $secondary_type == 'ms-tnef') { 
     398        else if ($part_mimetype == 'application/ms-tnef') { 
    391399          foreach ((array)$this->imap->tnef_decode($mail_part, $structure->headers['uid']) as $tnef_part) { 
    392400            $this->mime_parts[$tnef_part->mime_id] = $tnef_part; 
     
    404412 
    405413          // part belongs to a related message and is linked 
    406           if ($message_ctype_secondary == 'related' 
    407               && preg_match('!^image/!', $mail_part->mimetype) 
     414          if ($mimetype == 'multipart/related' 
     415              && preg_match('!^image/!', $part_mimetype) 
    408416              && ($mail_part->headers['content-id'] || $mail_part->headers['content-location'])) { 
    409417            if ($mail_part->headers['content-id']) 
     
    415423          } 
    416424          // is a regular attachment 
    417           else if (preg_match('!^[a-z]+/[a-z0-9-.+]+$!i', $mail_part->mimetype)) { 
     425          else if (preg_match('!^[a-z]+/[a-z0-9-.+]+$!i', $part_mimetype)) { 
    418426            if (!$mail_part->filename) 
    419427              $mail_part->filename = 'Part '.$mail_part->mime_id; 
     
    424432 
    425433      // if this was a related part try to resolve references 
    426       if ($message_ctype_secondary == 'related' && sizeof($this->inline_parts)) { 
     434      if ($mimetype == 'multipart/related' && sizeof($this->inline_parts)) { 
    427435        $a_replaces = array(); 
    428436 
     
    444452    } 
    445453 
    446     // message is single part non-text 
     454    // message is a single part non-text 
    447455    else if ($structure->filename) { 
    448456      $this->attachments[] = $structure; 
Note: See TracChangeset for help on using the changeset viewer.