0010062: structure of rfc/822 subparts overwrites cached structure
authorPhilipp Schüle <p.schuele@metaways.de>
Wed, 16 Jul 2014 15:41:44 +0000 (17:41 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 17 Jul 2014 16:02:45 +0000 (18:02 +0200)
* only cache structure if partId == null (=> main part)
* adds verbose output to "other mails" test
* improves structure array handling (prevents array_key_exists errors)

https://forge.tine20.org/mantisbt/view.php?id=10062

Change-Id: I4c72855aacfca61f63ddbac828b6be8f9a763d67
Reviewed-on: http://gerrit.tine20.com/customers/873
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Felamimail/Controller/MessageTest.php
tine20/Felamimail/Controller/Message.php
tine20/Felamimail/Model/Message.php

index 5c66107..bd1ff28 100644 (file)
@@ -611,8 +611,11 @@ class Felamimail_Controller_MessageTest extends PHPUnit_Framework_TestCase
                     echo "\nchecking message: " . $fileName . "\n";
                     $cachedMessage = $this->messageTestHelper($fileName, $filename);
                     $message = $this->_controller->getCompleteMessage($cachedMessage);
-                    echo $message->body;
                     $this->assertTrue(! empty($message->body));
+                    
+                    echo "body: " . $message->body . "\n";
+                    echo "attachements: ";
+                    print_r($message->attachments);
                 }
             }
         }
index 4ad71ae..3c52108 100644 (file)
@@ -219,21 +219,21 @@ class Felamimail_Controller_Message extends Tinebase_Controller_Record_Abstract
         } else {
             // create new object for rfc822 message
             $structure = $_message->getPartStructure($_partId, FALSE);
-        
+            
             $message = new Felamimail_Model_Message(array(
                 'messageuid'  => $_message->messageuid,
                 'folder_id'   => $_message->folder_id,
                 'received'    => $_message->received,
-                'size'        => ((isset($structure['size']) || array_key_exists('size', $structure))) ? $structure['size'] : 0,
+                'size'        => isset($structure['size']) ? $structure['size'] : 0,
                 'partid'      => $_partId,
                 'body'        => $body,
                 'headers'     => $headers,
                 'attachments' => $attachments
             ));
-        
+            
             $message->parseHeaders($headers);
-        
-            $structure = (isset($structure['messageStructure']) || array_key_exists('messageStructure', $structure)) ? $structure['messageStructure'] : $structure;
+            
+            $structure = isset($structure['messageStructure']) ? $structure['messageStructure'] : $structure;
             $message->parseStructure($structure);
         }
         
@@ -833,10 +833,10 @@ class Felamimail_Controller_Message extends Tinebase_Controller_Record_Abstract
         }
         
         $structure = $message->getPartStructure($_partId);
-
+        
         $attachments = array();
         
-        if (!(isset($structure['parts']) || array_key_exists('parts', $structure))) {
+        if (! isset($structure['parts'])) {
             return $attachments;
         }
         
@@ -894,6 +894,9 @@ class Felamimail_Controller_Message extends Tinebase_Controller_Record_Abstract
             $filename = $part['parameters']['name'];
         } else {
             $filename = 'Part ' . $part['partId'];
+            if (isset($part['contentType'])) {
+                $filename .= ' (' . $part['contentType'] . ')';
+            }
         }
         
         return $filename;
index fed5375..7b285d4 100644 (file)
@@ -228,6 +228,12 @@ class Felamimail_Model_Message extends Tinebase_Record_Abstract
      */
     protected function _setStructure($structure)
     {
+        if (! empty($structure['partId'])) {
+            if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ 
+                . ' Don\'t cache structure of subparts');
+            return;
+        }
+        
         $cacheId = $this->_getStructureCacheId();
         
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Caching message structure: ' . $cacheId);