コード例 #1
0
 /**
  * testGetMessagePartRfc822
  */
 public function testGetMessagePartRfc822()
 {
     $cachedMessage = $this->messageTestHelper('multipart_rfc2822-2.eml', 'multipart/rfc2822-2');
     $messagePart = $this->_controller->getMessagePart($cachedMessage, 2);
     ob_start();
     fpassthru($messagePart->getRawStream());
     $out = ob_get_clean();
     $this->assertContains('X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12]', $out, 'header not found');
     $this->assertContains('This component, from the feedback I have, will mostly be used on', $out, 'body not found');
 }
コード例 #2
0
 /**
  * 
  * @param Felamimail_Model_Message $entry
  * @param array $options
  * @return void|Syncroton_Model_EmailBody
  */
 protected function _getSyncrotonBody(Felamimail_Model_Message $entry, $options)
 {
     //var_dump($options);
     // get truncation
     $truncateAt = null;
     $previewSize = null;
     if ($options['mimeSupport'] == Syncroton_Command_Sync::MIMESUPPORT_SEND_MIME) {
         $airSyncBaseType = Syncroton_Command_Sync::BODY_TYPE_MIME;
         if (isset($options['bodyPreferences'][Syncroton_Command_Sync::BODY_TYPE_MIME]['truncationSize'])) {
             $truncateAt = $options['bodyPreferences'][Syncroton_Command_Sync::BODY_TYPE_MIME]['truncationSize'];
         } elseif (isset($options['mimeTruncation']) && $options['mimeTruncation'] < Syncroton_Command_Sync::TRUNCATE_NOTHING) {
             switch ($options['mimeTruncation']) {
                 case Syncroton_Command_Sync::TRUNCATE_ALL:
                     $truncateAt = 0;
                     break;
                 case Syncroton_Command_Sync::TRUNCATE_4096:
                     $truncateAt = 4096;
                     break;
                 case Syncroton_Command_Sync::TRUNCATE_5120:
                     $truncateAt = 5120;
                     break;
                 case Syncroton_Command_Sync::TRUNCATE_7168:
                     $truncateAt = 7168;
                     break;
                 case Syncroton_Command_Sync::TRUNCATE_10240:
                     $truncateAt = 10240;
                     break;
                 case Syncroton_Command_Sync::TRUNCATE_20480:
                     $truncateAt = 20480;
                     break;
                 case Syncroton_Command_Sync::TRUNCATE_51200:
                     $truncateAt = 51200;
                     break;
                 case Syncroton_Command_Sync::TRUNCATE_102400:
                     $truncateAt = 102400;
                     break;
             }
         }
     } elseif (isset($options['bodyPreferences'][Syncroton_Command_Sync::BODY_TYPE_HTML])) {
         $airSyncBaseType = Syncroton_Command_Sync::BODY_TYPE_HTML;
         if (isset($options['bodyPreferences'][Syncroton_Command_Sync::BODY_TYPE_HTML]['truncationSize'])) {
             $truncateAt = $options['bodyPreferences'][Syncroton_Command_Sync::BODY_TYPE_HTML]['truncationSize'];
         }
         if (isset($options['bodyPreferences'][Syncroton_Command_Sync::BODY_TYPE_HTML]['preview'])) {
             $previewSize = $options['bodyPreferences'][Syncroton_Command_Sync::BODY_TYPE_HTML]['preview'];
         }
     } else {
         $airSyncBaseType = Syncroton_Command_Sync::BODY_TYPE_PLAIN_TEXT;
         if (isset($options['bodyPreferences'][Syncroton_Command_Sync::BODY_TYPE_PLAIN_TEXT]['truncationSize'])) {
             $truncateAt = $options['bodyPreferences'][Syncroton_Command_Sync::BODY_TYPE_PLAIN_TEXT]['truncationSize'];
         }
         if (isset($options['bodyPreferences'][Syncroton_Command_Sync::BODY_TYPE_PLAIN_TEXT]['preview'])) {
             $previewSize = $options['bodyPreferences'][Syncroton_Command_Sync::BODY_TYPE_PLAIN_TEXT]['preview'];
         }
     }
     if ($airSyncBaseType == Syncroton_Command_Sync::BODY_TYPE_MIME) {
         // getMessagePart will return Zend_Mime_Part
         $messageBody = $this->_contentController->getMessagePart($entry);
         $messageBody = stream_get_contents($messageBody->getRawStream());
     } else {
         $messageBody = $this->_contentController->getMessageBody($entry, null, $airSyncBaseType == 2 ? Zend_Mime::TYPE_HTML : Zend_Mime::TYPE_TEXT, NULL, true);
     }
     if ($previewSize !== null) {
         $preview = substr($this->_contentController->getMessageBody($entry, null, Zend_Mime::TYPE_TEXT, NULL, true), 0, $previewSize);
         // strip out any non utf-8 characters
         $preview = @iconv('utf-8', 'utf-8//IGNORE', $preview);
     }
     if ($truncateAt !== null && strlen($messageBody) > $truncateAt) {
         $messageBody = substr($messageBody, 0, $truncateAt);
         $isTruncacted = 1;
     } else {
         $isTruncacted = 0;
     }
     // strip out any non utf-8 characters
     $messageBody = @iconv('utf-8', 'utf-8//IGNORE', $messageBody);
     $synrotonBody = new Syncroton_Model_EmailBody(array('type' => $airSyncBaseType, 'estimatedDataSize' => $entry->size));
     if (strlen($messageBody) > 0) {
         $synrotonBody->data = $messageBody;
     }
     if (isset($preview) && strlen($preview) > 0) {
         $synrotonBody->preview = $preview;
     }
     if ($isTruncacted === 1) {
         $synrotonBody->truncated = 1;
     } else {
         $synrotonBody->truncated = 0;
     }
     return $synrotonBody;
 }
コード例 #3
0
ファイル: Email.php プロジェクト: rodrigofns/ExpressoLivre3
 /**
  * append email data to xml element
  *
  * @param DOMElement  $_domParrent   the parrent xml node
  * @param string      $_folderId  the local folder id
  * @param string      $_serverId  the local entry id
  * @param boolean     $_withBody  retrieve body of entry
  */
 public function appendXML(DOMElement $_domParrent, $_collectionData, $_serverId)
 {
     Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " append email " . $_serverId);
     $data = $_serverId instanceof Tinebase_Record_Abstract ? $_serverId : $this->_contentController->get($_serverId);
     $_domParrent->ownerDocument->documentElement->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:Email', 'uri:Email');
     foreach ($this->_mapping as $key => $value) {
         if (!empty($data->{$value}) || $data->{$value} == '0') {
             $nodeContent = null;
             switch ($value) {
                 case 'received':
                     if ($data->{$value} instanceof DateTime) {
                         $nodeContent = $data->{$value}->toString('Y-m-d\\TH:i:s') . '.000Z';
                     }
                     break;
                 case 'from_email':
                     $nodeContent = $this->_createEmailAddress($data->from_name, $data->from_email);
                     break;
                 case 'to':
                 case 'cc':
                     $nodeContent = implode(', ', $data->{$value});
                     break;
                 default:
                     $nodeContent = $data->{$value};
                     break;
             }
             // skip empty elements
             if ($nodeContent === null || $nodeContent == '') {
                 //Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " Value for $key is empty. Skip element.");
                 continue;
             }
             // strip off any non printable control characters
             if (!ctype_print($nodeContent)) {
                 $nodeContent = $this->removeControlChars($nodeContent);
             }
             $node = $_domParrent->ownerDocument->createElementNS('uri:Email', $key);
             $node->appendChild($_domParrent->ownerDocument->createTextNode($nodeContent));
             $_domParrent->appendChild($node);
         }
     }
     // read flag
     if (in_array('\\Seen', $data->flags)) {
         $_domParrent->appendChild(new DOMElement('Read', 1, 'uri:Email'));
     } else {
         $_domParrent->appendChild(new DOMElement('Read', 0, 'uri:Email'));
     }
     // attachments?
     if ($data->has_attachment == true) {
         $attachments = $this->_contentController->getAttachments($data);
         if (count($attachments) > 0) {
             $tagAttachments = $_domParrent->appendChild(new DOMElement('Attachments', null, 'uri:AirSyncBase'));
             foreach ($attachments as $attachment) {
                 $tagAttachment = $tagAttachments->appendChild(new DOMElement('Attachment', null, 'uri:AirSyncBase'));
                 $filenameNode = $tagAttachment->appendChild(new DOMElement('DisplayName', null, 'uri:AirSyncBase'));
                 $filenameNode->appendChild(new DOMText($this->removeControlChars(trim($attachment['filename']))));
                 $tagAttachment->appendChild(new DOMElement('FileReference', $data->getId() . '-' . $attachment['partId'], 'uri:AirSyncBase'));
                 $tagAttachment->appendChild(new DOMElement('Method', 1, 'uri:AirSyncBase'));
                 $tagAttachment->appendChild(new DOMElement('EstimatedDataSize', $this->removeControlChars($attachment['size']), 'uri:AirSyncBase'));
             }
         }
     }
     // get truncation
     $truncateAt = null;
     if (isset($_collectionData['mimeSupport']) && $_collectionData['mimeSupport'] == 2 && (version_compare($this->_device->acsversion, '12.0', '<=') || isset($_collectionData['bodyPreferences'][4]))) {
         if (isset($_collectionData['bodyPreferences'][4]) && isset($_collectionData['bodyPreferences'][4]['truncationSize'])) {
             $truncateAt = $_collectionData['bodyPreferences'][4]['truncationSize'];
         }
         $airSyncBaseType = 4;
     } elseif (isset($_collectionData['bodyPreferences'][2])) {
         if (isset($_collectionData['bodyPreferences'][2]['truncationSize'])) {
             $truncateAt = $_collectionData['bodyPreferences'][2]['truncationSize'];
         }
         $airSyncBaseType = 2;
     } else {
         if (isset($_collectionData['bodyPreferences'][1]) && isset($_collectionData['bodyPreferences'][1]['truncationSize'])) {
             $truncateAt = $_collectionData['bodyPreferences'][1]['truncationSize'];
         }
         $airSyncBaseType = 1;
     }
     if (isset($_collectionData['mimeTruncation']) && $_collectionData['mimeTruncation'] < 8) {
         switch ($_collectionData['mimeTruncation']) {
             case Syncope_Command_Sync::TRUNCATE_ALL:
                 $truncateAt = 0;
                 break;
             case Syncope_Command_Sync::TRUNCATE_4096:
                 $truncateAt = 4096;
                 break;
             case Syncope_Command_Sync::TRUNCATE_5120:
                 $truncateAt = 5120;
                 break;
             case Syncope_Command_Sync::TRUNCATE_7168:
                 $truncateAt = 7168;
                 break;
             case Syncope_Command_Sync::TRUNCATE_10240:
                 $truncateAt = 10240;
                 break;
             case Syncope_Command_Sync::TRUNCATE_20480:
                 $truncateAt = 20480;
                 break;
             case Syncope_Command_Sync::TRUNCATE_51200:
                 $truncateAt = 51200;
                 break;
             case Syncope_Command_Sync::TRUNCATE_102400:
                 $truncateAt = 102400;
                 break;
         }
     }
     if ($airSyncBaseType == 4) {
         // getMessagePart will return Zend_Mime_Part
         $messageBody = $this->_contentController->getMessagePart($_serverId);
         $messageBody = stream_get_contents($messageBody->getRawStream());
         if (version_compare($this->_device->acsversion, '12.0', '<')) {
             // if the email contains non 7bit ascii characters we can't transfer them via MIMEData xml and we need to fall back to plain text
             if (preg_match('/(?:[^\\x00-\\x7F])/', $messageBody)) {
                 $airSyncBaseType = 1;
                 $messageBody = $this->_contentController->getMessageBody($_serverId, null, Zend_Mime::TYPE_TEXT, NULL, true);
             }
         }
     } else {
         $messageBody = $this->_contentController->getMessageBody($_serverId, null, $airSyncBaseType == 2 ? Zend_Mime::TYPE_HTML : Zend_Mime::TYPE_TEXT, NULL, true);
     }
     if ($truncateAt !== null && strlen($messageBody) > $truncateAt) {
         $messageBody = substr($messageBody, 0, $truncateAt);
         $isTruncacted = 1;
     } else {
         $isTruncacted = 0;
     }
     if (strlen($messageBody) > 0) {
         // remove control chars
         $messageBody = $this->removeControlChars($messageBody);
         // strip out any non utf-8 characters
         $messageBody = @iconv('utf-8', 'utf-8//IGNORE', $messageBody);
         if (version_compare($this->_device->acsversion, '12.0', '>=')) {
             $body = $_domParrent->appendChild(new DOMElement('Body', null, 'uri:AirSyncBase'));
             $body->appendChild(new DOMElement('Type', $airSyncBaseType, 'uri:AirSyncBase'));
             $body->appendChild(new DOMElement('Truncated', $isTruncacted, 'uri:AirSyncBase'));
             $body->appendChild(new DOMElement('EstimatedDataSize', $data->size, 'uri:AirSyncBase'));
             $dataTag = $body->appendChild(new DOMElement('Data', null, 'uri:AirSyncBase'));
             $dataTag->appendChild(new DOMText($messageBody));
             $_domParrent->appendChild(new DOMElement('NativeBodyType', $airSyncBaseType, 'uri:AirSyncBase'));
         } else {
             if ($airSyncBaseType == 4) {
                 $_domParrent->appendChild(new DOMElement('MIMETruncated', $isTruncacted, 'uri:Email'));
                 $body = $_domParrent->appendChild(new DOMElement('MIMEData', null, 'uri:Email'));
                 $body->appendChild(new DOMText($messageBody));
             } else {
                 $_domParrent->appendChild(new DOMElement('BodyTruncated', $isTruncacted, 'uri:Email'));
                 $body = $_domParrent->appendChild(new DOMElement('Body', null, 'uri:Email'));
                 $body->appendChild(new DOMText($messageBody));
             }
         }
     }
     if ($airSyncBaseType == 4) {
         $_domParrent->appendChild(new DOMElement('MessageClass', 'IPM.Note.SMIME', 'uri:Email'));
     } else {
         $_domParrent->appendChild(new DOMElement('MessageClass', 'IPM.Note', 'uri:Email'));
     }
     $_domParrent->appendChild(new DOMElement('ContentClass', 'urn:content-classes:message', 'uri:Email'));
     return;
     /*
     foreach($message->getHeaders() as $headerName => $headerValue) {
         switch($headerName) {
             case 'importance':
                 switch (strtolower($headerValue)) {
                     case 'low':
                         $_domParrent->appendChild($_xmlDocument->createElementNS('uri:Email', 'Importance', 0));
                         break;
                 	
                     case 'high':
                         $_domParrent->appendChild($_xmlDocument->createElementNS('uri:Email', 'Importance', 2));
                         break;
                         
                 }
                 
                 break;
         }
     }
     */
 }