mixed) */ private $properties = array(); /** * Constructs a new mail part. */ public function __construct() { $this->headers = new ezcMailHeadersHolder(); } /** * Sets the property $name to $value. * * @throws ezcBasePropertyNotFoundException * if the property does not exist. * @throws ezcBasePropertyPermissionException * if the property is read-only. * @param string $name * @param mixed $value * @ignore */ public function __set( $name, $value ) { switch ( $name ) { case 'contentDisposition': $this->properties[$name] = $value; break; case 'headers': throw new ezcBasePropertyPermissionException( $name, ezcBasePropertyPermissionException::READ ); default: throw new ezcBasePropertyNotFoundException( $name ); } } /** * Returns the property $name. * * @throws ezcBasePropertyNotFoundException * if the property does not exist. * @param string $name * @return mixed * @ignore */ public function __get( $name ) { switch ( $name ) { case 'contentDisposition': return isset( $this->properties[$name] ) ? $this->properties[$name] : null; case "headers": return $this->headers; default: throw new ezcBasePropertyNotFoundException( $name ); } } /** * Returns true if the property $name is set, otherwise false. * * @param string $name * @return bool * @ignore */ public function __isset( $name ) { switch ( $name ) { case 'contentDisposition': return isset( $this->properties[$name] ); case "headers": return isset( $this->headers ); default: return false; } } /** * Returns the RAW value of the header $name. * * Returns an empty string if the header is not found. * Getting headers is case insensitive. Getting the header * 'Message-Id' will match both 'Message-ID' and 'MESSAGE-ID' * as well as 'Message-Id'. * * @param string $name * @return string */ public function getHeader( $name ) { if ( isset( $this->headers[$name] ) ) { return $this->headers[$name]; } return ''; } /** * Sets the header $name to the value $value. * * If the header is already set it will override the old value. * * Headers set should be folded at 76 or 998 characters according to * the folding rules described in RFC 2822. * * Note: The header Content-Disposition will be overwritten by the * contents of the contentsDisposition property if set. * * @see generateHeaders() * * @param string $name * @param string $value */ public function setHeader( $name, $value ) { $this->headers[$name] = $value; } /** * Adds the headers $headers. * * The headers specified in the associative array of the * form array(headername=>value) will overwrite any existing * header values. * * Headers set should be folded at 76 or 998 characters according to * the folding rules described in RFC 2822. * * @param array(string=>string) $headers */ public function setHeaders( array $headers ) { foreach ( $headers as $key => $value ) { $this->headers[$key] = $value; } } /** * Returns the headers set for this part as a RFC 822 string. * * Each header is separated by a line break. * This method does not add the required two lines of space * to separate the headers from the body of the part. * * This function is called automatically by generate() and * subclasses can override this method if they wish to set additional * headers when the mail is generated. * * @see setHeader() * * @return string */ public function generateHeaders() { // set content disposition header if ( $this->contentDisposition !== null && ( $this->contentDisposition instanceof ezcMailContentDispositionHeader ) ) { $cdHeader = $this->contentDisposition; $cd = "{$cdHeader->disposition}"; if ( $cdHeader->fileName !== null ) { $cd .= "; filename=\"{$cdHeader->fileName}\""; } if ( $cdHeader->creationDate !== null ) { $cd .= "; creation-date=\"{$cdHeader->creationDate}\""; } if ( $cdHeader->modificationDate !== null ) { $cd .= "; modification-date=\"{$cdHeader->modificationDate}\""; } if ( $cdHeader->readDate !== null ) { $cd .= "; read-date=\"{$cdHeader->readDate}\""; } if ( $cdHeader->size !== null ) { $cd .= "; size={$cdHeader->size}"; } foreach ( $cdHeader->additionalParameters as $addKey => $addValue ) { $cd .="; {$addKey}=\"{$addValue}\""; } $this->setHeader( 'Content-Disposition', $cd ); } // generate headers $text = ""; foreach ( $this->headers->getCaseSensitiveArray() as $header => $value ) { if ( in_array( strtolower( $header ), $this->excludeHeaders ) === false ) { $text .= "$header: $value" . ezcMailTools::lineBreak(); } } return $text; } /** * The array $headers will be excluded when the headers are generated. * * @see generateHeaders() * * @param array(string) $headers */ public function appendExcludeHeaders( array $headers ) { $lowerCaseHeaders = array(); foreach ( $headers as $header ) { $lowerCaseHeaders[] = strtolower( $header ); } $this->excludeHeaders = array_merge( $this->excludeHeaders, $lowerCaseHeaders ); } /** * Returns the body of this part as a string. * * This method is called automatically by generate() and subclasses must * implement it. * * @return string */ abstract public function generateBody(); /** * Returns the complete mail part including both the header and the body * as a string. * * @return string */ public function generate() { return $this->generateHeaders() .ezcMailTools::lineBreak() . $this->generateBody(); } } ?>