/** * * @param Expressomail_Model_Message $entry * @param array $options * @return void|Syncroton_Model_EmailBody */ protected function _getSyncrotonBody(Expressomail_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; }