/** * Determines if a MIME type is an attachment. * * @param Horde_Mime_Part $part The MIME part. */ public static function isAttachment(Horde_Mime_Part $part) { $type = $part->getType(); switch ($type) { case 'application/ms-tnef': case 'application/pgp-keys': case 'application/vnd.ms-tnef': return false; } if ($part->parent) { switch ($part->parent->getType()) { case 'multipart/encrypted': switch ($type) { case 'application/octet-stream': return false; } break; case 'multipart/signed': switch ($type) { case 'application/pgp-signature': case 'application/pkcs7-signature': case 'application/x-pkcs7-signature': return false; } break; } } switch ($part->getDisposition()) { case 'attachment': return true; } switch ($part->getPrimaryType()) { case 'application': if (strlen($part->getName())) { return true; } break; case 'audio': case 'video': return true; case 'multipart': return false; } return false; }
/** */ protected function _write($filename, Horde_Mime_Part $part) { global $browser; try { $this->_vfs->write($this->_vfspath, $this->_id, $filename, true); } catch (Horde_Vfs_Exception $e) { throw new IMP_Compose_Exception($e); } // Prevent 'jar:' attacks on Firefox. See Ticket #5892. $type = $part->getType(); if ($browser->isBrowser('mozilla') && in_array(Horde_String::lower($type), array('application/java-archive', 'application/x-jar'))) { $type = 'application/octet-stream'; } $md = $this->getMetadata(); $md->filename = $part->getName(true); $md->time = time(); $md->type = $type; $this->saveMetadata($md); }
/** * Return the descriptive part label, making sure it is not empty. * * @param Horde_Mime_Part $part The MIME Part object. * @param boolean $use_descrip Use description? If false, uses name. * * @return string The part label (non-empty). */ public function getPartName(Horde_Mime_Part $part, $use_descrip = false) { $name = $use_descrip ? $part->getDescription(true) : $part->getName(true); if ($name) { return $name; } switch ($ptype = $part->getPrimaryType()) { case 'multipart': if ($part->getSubType() == 'related' && ($view_id = $part->getMetaData('viewable_part')) && ($viewable = $this->getMimePart($view_id, array('nocontents' => true)))) { return $this->getPartName($viewable, $use_descrip); } /* Fall-through. */ /* Fall-through. */ case 'application': case 'model': $ptype = $part->getSubType(); break; } switch ($ptype) { case 'audio': return _("Audio"); case 'image': return _("Image"); case 'message': case '': case Horde_Mime_Part::UNKNOWN: return _("Message"); case 'multipart': return _("Multipart"); case 'text': return _("Text"); case 'video': return _("Video"); default: // Attempt to translate this type, if possible. Odds are that // it won't appear in the dictionary though. return _(Horde_String::ucfirst($ptype)); } }
/** * @return string */ public function getName() { return $this->mimePart->getName(); }
public function testNullCharactersNotAllowedInMimeHeaderData() { $part = new Horde_Mime_Part(); $part->setType("text/plain"); $this->assertEquals('text/plain', $part->getType()); $part->setDisposition("inline"); $this->assertEquals('inline', $part->getDisposition()); $part->setDispositionParameter('size', '123' . "" . '456'); $this->assertEquals(123456, $part->getDispositionParameter('size')); $part->setDispositionParameter('foo', "foobar"); $this->assertEquals('foobar', $part->getDispositionParameter('foo')); $part->setCharset("utf-8"); $this->assertEquals('utf-8', $part->getCharset()); $part->setName("foobar"); $this->assertEquals('foobar', $part->getName()); $this->assertEquals('foobar', $part->getDispositionParameter('filename')); $this->assertEquals('foobar', $part->getContentTypeParameter('name')); $part->setLanguage("en"); $this->assertEquals(array('en'), $part->getLanguage()); $part->setLanguage(array("en", "de")); $this->assertEquals(array('en', 'de'), $part->getLanguage()); $part->setDuration('123' . "" . '456'); $this->assertEquals(123456, $part->getDuration()); $part->setBytes('123' . "" . '456'); $this->assertEquals(123456, $part->getBytes()); $part->setDescription("foobar"); $this->assertEquals('foobar', $part->getDescription()); $part->setContentTypeParameter('foo', "foobar"); $this->assertEquals('foobar', $part->getContentTypeParameter('foo')); $part->setContentId("foobar"); $this->assertEquals('foobar', $part->getContentId()); }
/** * * @param unknown $struct * @param unknown $partno * @param unknown $outStruct */ public function subMimeStructToFlatStruct(Horde_Mime_Part $struct, &$outStruct) { $partno = $struct->getMimeId(); $outStruct[$partno] = array(); $outStruct[$partno]['type'] = $struct->getType(false); $outStruct[$partno]['subtype'] = $struct->getSubType(); $outStruct[$partno]['content'] = $struct->getContents(array('stream' => false)); if ($v = $struct->getCharset()) { $outStruct[$partno]['charset'] = $v; } if ($v = $struct->getName(false)) { $outStruct[$partno]['name'] = $v; } if ($v = $struct->getSize(false)) { $outStruct[$partno]['bytes'] = $v; } if ($v = $struct->getContentId()) { $outStruct[$partno]['id'] = $v; } foreach ($struct->getParts() as $sStruct) { $this->subMimeStructToFlatStruct($sStruct, $outStruct); } }
/** * Adds an attachment from Horde_Mime_Part data. * * @param Horde_Mime_Part $part The object that contains the attachment * data. * * @return IMP_Compose_Attachment Attachment object. * @throws IMP_Compose_Exception */ public function addAttachmentFromPart($part) { /* Extract the data from the Horde_Mime_Part. */ $atc_file = Horde::getTempFile('impatt'); $stream = $part->getContents(array('stream' => true)); rewind($stream); if (file_put_contents($atc_file, $stream) === false) { throw new IMP_Compose_Exception(sprintf(_("Could not attach %s to the message."), $part->getName())); } return $this->_addAttachment($atc_file, ftell($stream), $part->getName(true), $part->getType()); }