getBodyPartSize() public method

Returns the body part size, if returned by the server.
public getBodyPartSize ( string $id ) : integer
$id string The MIME ID.
return integer The body part size, in bytes.
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 a message again to add body and attachment data.
  *
  * @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.
  * @param string $filename The filename of the attachment
  * @return \stdClass
  * @throws \core\message\inbound\processing_failed_exception If the attachment can't be saved to disk.
  */
 private function process_message_part_attachment($messagedata, $partdata, $part, $filename)
 {
     global $CFG;
     // If a filename is present, assume that this part is an attachment.
     $attachment = new \stdClass();
     $attachment->filename = $filename;
     $attachment->type = $partdata->getType();
     $attachment->content = $partdata->getContents();
     $attachment->charset = $partdata->getCharset();
     $attachment->description = $partdata->getDescription();
     $attachment->contentid = $partdata->getContentId();
     $attachment->filesize = $messagedata->getBodyPartSize($part);
     if (!empty($CFG->antiviruses)) {
         mtrace("--> Attempting virus scan of '{$attachment->filename}'");
         // Store the file on disk - it will need to be virus scanned first.
         $itemid = rand(1, 999999999);
         $directory = make_temp_directory("/messageinbound/{$itemid}", false);
         $filepath = $directory . "/" . $attachment->filename;
         if (!($fp = fopen($filepath, "w"))) {
             // Unable to open the temporary file to write this to disk.
             mtrace("--> Unable to save the file to disk for virus scanning. Check file permissions.");
             throw new \core\message\inbound\processing_failed_exception('attachmentfilepermissionsfailed', 'tool_messageinbound');
         }
         fwrite($fp, $attachment->content);
         fclose($fp);
         // Perform a virus scan now.
         try {
             \core\antivirus\manager::scan_file($filepath, $attachment->filename, true);
         } catch (\core\antivirus\scanner_exception $e) {
             mtrace("--> A virus was found in the attachment '{$attachment->filename}'.");
             $this->inform_attachment_virus();
             return;
         }
     }
     return $attachment;
 }