3 * File containing the ezcMailStreamFile class
7 * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
8 * @license http://ez.no/licenses/new_bsd New BSD License
12 * Mail part for data in a stream.
14 * @property string $stream
15 * The stream object to be read and added as an attachment. The
16 * mimeType and contentType are set in the constructor or if not
17 * specified they are extracted with the fileinfo extension if it
18 * is available, otherwise they are set to application/octet-stream.
23 class ezcMailStreamFile
extends ezcMailFilePart
26 * Constructs a new attachment with $fileName and $stream.
28 * If the $mimeType and $contentType are not specified they are set
29 * to application/octet-stream.
31 * @param string $fileName
32 * @param resource $stream
33 * @param string $contentType
34 * @param string $mimeType
36 public function __construct( $fileName, $stream, $contentType = null, $mimeType = null )
38 parent
::__construct( $fileName );
39 $this->stream
= $stream;
40 if ( $contentType != null && $mimeType != null )
42 $this->contentType
= $contentType;
43 $this->mimeType
= $mimeType;
47 // default to mimetype application/octet-stream
48 $this->contentType
= self
::CONTENT_TYPE_APPLICATION
;
49 $this->mimeType
= "octet-stream";
54 * Sets the property $name to $value.
56 * @throws ezcBasePropertyNotFoundException
57 * if the property does not exist.
62 public function __set( $name, $value )
67 $this->properties
[$name] = $value;
70 return parent
::__set( $name, $value );
76 * Returns the value of property $value.
78 * @throws ezcBasePropertyNotFoundException
79 * if the property does not exist.
84 public function __get( $name )
89 return $this->properties
[$name];
92 return parent
::__get( $name );
98 * Returns true if the property $name is set, otherwise false.
100 * @param string $name
104 public function __isset( $name )
109 return isset( $this->properties
[$name] );
112 return parent
::__isset( $name );
117 * Returns the contents of the file with the correct encoding.
119 * The stream might become unusable after this if it doesn't support seek.
123 public function generateBody()
125 $contents = stream_get_contents( $this->stream
);
126 return chunk_split( base64_encode( $contents ), 76, ezcMailTools
::lineBreak() );