getBodyPart() public method

Get a body part entry.
public getBodyPart ( string $id, boolean $stream = false ) : mixed
$id string The MIME ID.
$stream boolean Return as a stream?
return mixed The full text of the body part.
Beispiel #1
0
 /**
  * Build the data needed for the BodyPart part.
  *
  * @param  Horde_Imap_Client_Data_Fetch $data  The FETCH results.
  * @param  Horde_Mime_Part $mime  The plaintext MIME part.
  * @param boolean $to_html        If true, $id is assumed to be a text/plain
  *                                part and is converted to html.
  *
  * @return array  The BodyPart data.
  *     - charset:  (string)   The charset of the text.
  *     - body: (string)       The body text.
  *     - truncated: (boolean) True if text was truncated.
  *     - size: (integer)      The original part size, in bytes.
  */
 protected function _getBodyPart(Horde_Imap_Client_Data_Fetch $data, Horde_Mime_Part $mime, $to_html)
 {
     $id = $mime->getMimeId();
     $text = $data->getBodyPart($id);
     if (!$data->getBodyPartDecode($id)) {
         $mime->setContents($text);
         $text = $mime->getContents();
     }
     if ($to_html) {
         $text = Horde_Text_Filter::filter($text, 'Text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO, 'charset' => $mime->getCharset()));
         $size = strlen($text);
     } else {
         $size = !is_null($data->getBodyPartSize($id)) ? $data->getBodyPartSize($id) : strlen($text);
     }
     if (!empty($this->_options['bodypartprefs']['truncationsize'])) {
         $text = Horde_String::substr($text, 0, $this->_options['bodypartprefs']['truncationsize'], $mime->getCharset());
     }
     return array('charset' => $mime->getCharset(), 'body' => $text, 'truncated' => $size > strlen($text), 'size' => $size);
 }
Beispiel #2
0
 /**
  * Process the messagedata and part data to extract the content of this part.
  *
  * @param \Horde_Imap_Client_Data_Fetch $messagedata The structure and part of the message body
  * @param \Horde_Mime_Part $partdata The part data
  * @param string $part The part ID
  * @return string
  */
 private function process_message_part_body($messagedata, $partdata, $part)
 {
     // This is a content section for the main body.
     // Get the string version of it.
     $content = $messagedata->getBodyPart($part);
     if (!$messagedata->getBodyPartDecode($part)) {
         // Decode the content.
         $partdata->setContents($content);
         $content = $partdata->getContents();
     }
     // Convert the text from the current encoding to UTF8.
     $content = \core_text::convert($content, $partdata->getCharset());
     // Fix any invalid UTF8 characters.
     // Note: XSS cleaning is not the responsibility of this code. It occurs immediately before display when
     // format_text is called.
     $content = clean_param($content, PARAM_RAW);
     return $content;
 }