properties['contentType'] = null; $this->properties['mimeType'] = null; $this->properties['dispositionType'] = null; $this->properties['contentId'] = null; $this->fileName = $fileName; } /** * Sets the property $name to $value. * * @throws ezcBasePropertyNotFoundException * if the property does not exist. * @param string $name * @param mixed $value * @ignore */ public function __set( $name, $value ) { switch ( $name ) { case 'fileName': $this->properties['fileName'] = $value; break; case 'mimeType': $this->properties['mimeType'] = $value; break; case 'contentType': $this->properties['contentType'] = $value; break; case 'dispositionType': $this->properties['dispositionType'] = $value; break; case 'contentId': $this->properties['contentId'] = $value; $this->setHeader( 'Content-ID', '<' . $value . '>' ); break; default: return parent::__set( $name, $value ); break; } } /** * Returns the value of property $value. * * @throws ezcBasePropertyNotFoundException * if the property does not exist. * @param string $name * @return mixed * @ignore */ public function __get( $name ) { switch ( $name ) { case 'fileName': case 'mimeType': case 'contentType': case 'dispositionType': case 'contentId': return $this->properties[$name]; break; default: return parent::__get( $name ); break; } } /** * Returns true if the property $name is set, otherwise false. * * @param string $name * @return bool * @ignore */ public function __isset( $name ) { switch ( $name ) { case 'fileName': case 'mimeType': case 'contentType': case 'dispositionType': case 'contentId': return isset( $this->properties[$name] ); default: return parent::__isset( $name ); } } /** * Sets the Content-Type header. * * Based on the contentType, mimeType and fileName. */ private function setHeaderContentType() { $fileName = basename( $this->fileName ); if ( $this->contentDisposition !== null && $this->contentDisposition->fileName !== null ) { $fileName = $this->contentDisposition->fileName; } $this->setHeader( 'Content-Type', $this->contentType . '/' . $this->mimeType . '; ' . 'name="' . $fileName . '"' ); } /** * Sets the Content-Disposition header based on the properties $dispositionType and $fileName. * * Does not set the fileNameCharSet and fileNameLanguage properties of the * Content-Disposition header. For this purpose set directly * $this->contentDisposition with an object of class ezcMailContentDispositionHeader. */ private function setHeaderContentDisposition() { if ( !isset( $this->dispositionType ) ) { $this->dispositionType = self::DISPLAY_ATTACHMENT; } if ( $this->contentDisposition == null ) { $this->contentDisposition = new ezcMailContentDispositionHeader(); // modified for issue #14025: set the file name and disposition // only if the contentDisposition was null (to not overwrite // the value set by the user) $this->contentDisposition->disposition = $this->dispositionType; $this->contentDisposition->fileName = basename( $this->fileName ); } } /** * Override of the generate() method from ezcMailPart. Used to set headers before * generating the part. * * @return string */ public function generate() { $this->setHeaderContentType(); $this->setHeader( 'Content-Transfer-Encoding', 'base64' ); $this->setHeaderContentDisposition(); return parent::generate(); } } ?>