/** * 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; }
/** * test Tnef-Attachment (winmail.dat) * * @TODO: handle richtext encapsulated in tnef - this test assures, rtf-tnef won't produce any errors * * @see 0010076: Extract winmail.dat */ public function testTnefRichtext() { if (!Tinebase_Core::systemCommandExists('tnef')) { $this->markTestSkipped('The tnef command could not be found!'); } $cachedMessage = $this->messageTestHelper('winmail_dat_richtext.eml'); $message = $this->_controller->getCompleteMessage($cachedMessage); $this->assertEquals(1, count($message->attachments)); $this->assertEquals('winmail.dat', $message->attachments[0]['filename']); }