/**
  * get attachments of message
  *
  * @param  array  $_structure
  * @return array
  */
 public function getAttachments($_messageId, $_partId = null)
 {
     if (!$_messageId instanceof Felamimail_Model_Message) {
         $message = $this->_backend->get($_messageId);
     } else {
         $message = $_messageId;
     }
     $structure = $message->getPartStructure($_partId);
     $attachments = array();
     if (!isset($structure['parts'])) {
         return $attachments;
     }
     foreach ($structure['parts'] as $part) {
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($part, TRUE));
         }
         if ($part['type'] == 'multipart') {
             $attachments = $attachments + $this->getAttachments($message, $part['partId']);
         } else {
             $filename = $this->_getAttachmentFilename($part);
             if ($part['type'] == 'text' && (!is_array($part['disposition']) || $part['disposition']['type'] == Zend_Mime::DISPOSITION_INLINE && !(isset($part['disposition']["parameters"]) || array_key_exists("parameters", $part['disposition'])))) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Skipping DISPOSITION_INLINE attachment with name ' . $filename);
                 }
                 if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                     Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' part: ' . print_r($part, TRUE));
                 }
                 continue;
             }
             $expanded = array();
             // if a winmail.dat exists, try to expand it
             if (preg_match('/^winmail[.]*\\.dat/i', $filename) && Tinebase_Core::systemCommandExists('tnef')) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Got winmail.dat attachment (contentType=' . $part['contentType'] . '). Trying to extract files ...');
                 }
                 if ($part['contentType'] == 'application/ms-tnef' || $part['contentType'] == 'text/plain') {
                     $expanded = $this->_expandWinMailDat($_messageId, $part['partId']);
                     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Extracted ' . count($expanded) . ' files from ' . $filename);
                     }
                     if (!empty($expanded)) {
                         $attachments = array_merge($attachments, $expanded);
                     }
                 }
             }
             // if its not a winmail.dat, or the winmail.dat couldn't be expanded
             // properly because it has richtext embedded, return attachment as it is
             if (empty($expanded)) {
                 $attachmentData = array('content-type' => $part['contentType'], 'filename' => $filename, 'partId' => $part['partId'], 'size' => $part['size'], 'description' => $part['description'], 'cid' => !empty($part['id']) ? $part['id'] : NULL);
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                     Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Got attachment with name ' . $filename);
                 }
                 $attachments[] = $attachmentData;
             }
         }
     }
     return $attachments;
 }
示例#2
0
 /**
  * test search with cache
  * - test text_plain.eml message
  * - test from header
  */
 public function testSearchWithCache()
 {
     // get inbox folder id
     Felamimail_Controller_Cache_Folder::getInstance()->update($this->_account->getId());
     $folderBackend = new Felamimail_Backend_Folder();
     $folder = Felamimail_Controller_Folder::getInstance()->getByBackendAndGlobalName($this->_account->getId(), $this->_testFolderName);
     // clear cache and empty folder
     $this->_cache->clear($folder->getId());
     Felamimail_Controller_Folder::getInstance()->emptyFolder($folder->getId());
     // append message
     $this->_appendMessage('text_plain.eml', $this->_folder);
     // search messages in test folder
     $this->_cache->updateCache($folder);
     $result = $this->_controller->search($this->_getFilter($folder->getId()));
     //print_r($result->toArray());
     // check result
     $firstMessage = $result->getFirstRecord();
     $this->_createdMessages->addRecord($firstMessage);
     $this->assertGreaterThan(0, count($result));
     $this->assertEquals($folder->getId(), $firstMessage->folder_id);
     $this->assertEquals("Re: [gentoo-dev] `paludis --info' is not like `emerge --info'", $firstMessage->subject);
     $this->assertEquals('Pipping, Sebastian (Luxembourg)', $firstMessage->from_name);
     $this->assertEquals('*****@*****.**', $firstMessage->from_email);
     $this->assertEquals(array('*****@*****.**', '*****@*****.**'), $firstMessage->to);
     // check cache entries
     $cacheBackend = new Felamimail_Backend_Cache_Sql_Message();
     $cachedMessage = $cacheBackend->get($firstMessage->getId());
     $this->assertEquals($folder->getId(), $cachedMessage->folder_id);
     $this->assertEquals(Tinebase_DateTime::now()->format('Y-m-d'), $cachedMessage->timestamp->format('Y-m-d'));
     // clear cache
     $this->_cache->clear($folder->getId());
 }