/** * Create a new instance for an ComposerMessage for example. * * @param \GO\Base\Fs\File $file The temporary file * @return \MessageAttachment */ public function createFromTempFile(\GO\Base\Fs\File $file) { // $a['name'] = $file->name(); $a = new MessageAttachment(); $a->name = $file->name(); $a->mime = $file->mimeType(); $a->setTempFile($file); $a->size = $file->size(); return $a; }
private function _getParts($structure, $part_number_prefix = '') { if (isset($structure->parts)) { $structure->ctype_primary = strtolower($structure->ctype_primary); $structure->ctype_secondary = strtolower($structure->ctype_secondary); //$part_number=0; foreach ($structure->parts as $part_number => $part) { $part->ctype_primary = strtolower($part->ctype_primary); $part->ctype_secondary = strtolower($part->ctype_secondary); //text part and no attachment so it must be the body if ($structure->ctype_primary == 'multipart' && $structure->ctype_secondary == 'alternative' && $part->ctype_primary == 'text' && $part->ctype_secondary == 'plain') { //check if html part is there if ($this->_hasHtmlPart($structure)) { continue; } } if ($part->ctype_primary == 'text' && ($part->ctype_secondary == 'plain' || $part->ctype_secondary == 'html') && (!isset($part->disposition) || $part->disposition != 'attachment') && empty($part->d_parameters['filename'])) { $charset = isset($part->ctype_parameters['charset']) ? $part->ctype_parameters['charset'] : 'UTF-8'; $body = \GO\Base\Util\String::clean_utf8($part->body, $charset); if (stripos($part->ctype_secondary, 'plain') !== false) { $body = nl2br($body); } else { $body = \GO\Base\Util\String::convertLinks($body); $body = \GO\Base\Util\String::sanitizeHtml($body); $body = $body; } $this->_loadedBody .= $body; } elseif ($part->ctype_primary == 'multipart') { } else { //attachment if (!empty($part->ctype_parameters['name'])) { $filename = $part->ctype_parameters['name']; } elseif (!empty($part->d_parameters['filename'])) { $filename = $part->d_parameters['filename']; } elseif (!empty($part->d_parameters['filename*'])) { $filename = $part->d_parameters['filename*']; } else { $filename = uniqid(time()); } $mime_type = $part->ctype_primary . '/' . $part->ctype_secondary; if (isset($part->headers['content-id'])) { $content_id = trim($part->headers['content-id']); if (strpos($content_id, '>')) { $content_id = substr($part->headers['content-id'], 1, strlen($part->headers['content-id']) - 2); } } else { $content_id = ''; } $f = new \GO\Base\Fs\File($filename); $a = new MessageAttachment(); $a->name = $filename; $a->number = $part_number_prefix . $part_number; $a->content_id = $content_id; $a->mime = $mime_type; $tmp_file = new \GO\Base\Fs\File($this->_getTempDir() . $filename); if (!empty($part->body)) { $tmp_file = new \GO\Base\Fs\File($this->_getTempDir() . $filename); if (!$tmp_file->exists()) { $tmp_file->putContents($part->body); } $a->setTempFile($tmp_file); } $a->index = count($this->attachments); $a->size = isset($part->body) ? strlen($part->body) : 0; $a->encoding = isset($part->headers['content-transfer-encoding']) ? $part->headers['content-transfer-encoding'] : ''; $a->disposition = isset($part->disposition) ? $part->disposition : ''; $this->addAttachment($a); } //$part_number++; if (isset($part->parts)) { $this->_getParts($part, $part_number_prefix . $part_number . '.'); } } } elseif (isset($structure->body)) { $charset = isset($structure->ctype_parameters['charset']) ? $structure->ctype_parameters['charset'] : 'UTF-8'; $text_part = \GO\Base\Util\String::clean_utf8($structure->body, $charset); //convert text to html if (stripos($structure->ctype_secondary, 'plain') !== false) { $this->extractUuencodedAttachments($text_part); $text_part = nl2br($text_part); } else { $text_part = \GO\Base\Util\String::convertLinks($text_part); $text_part = \GO\Base\Util\String::sanitizeHtml($text_part); } $this->_loadedBody .= $text_part; } }