IMP_Contents::getPartName PHP Method

getPartName() public method

Return the descriptive part label, making sure it is not empty.
public getPartName ( Horde_Mime_Part $part, boolean $use_descrip = false ) : string
$part Horde_Mime_Part The MIME Part object.
$use_descrip boolean 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));
        }
    }

Usage Example

Example #1
0
File: View.php Project: horde/horde
 /**
  */
 public function downloadAttach($id)
 {
     global $session;
     $session->close();
     if (!($mime = $this->_getRawDownloadPart($id))) {
         return array();
     }
     return array('data' => $mime->getContents(array('stream' => true)), 'name' => $this->_contents->getPartName($mime), 'type' => $mime->getType(true));
 }
All Usage Examples Of IMP_Contents::getPartName