commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / packages / ezc / Mail / src / parts / fileparts / stream_file.php
1 <?php
2 /**
3 * File containing the ezcMailStreamFile class
4 *
5 * @package Mail
6 * @version 1.7beta1
7 * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
8 * @license http://ez.no/licenses/new_bsd New BSD License
9 */
10
11 /**
12 * Mail part for data in a stream.
13 *
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.
19 *
20 * @package Mail
21 * @version 1.7beta1
22 */
23 class ezcMailStreamFile extends ezcMailFilePart
24 {
25 /**
26 * Constructs a new attachment with $fileName and $stream.
27 *
28 * If the $mimeType and $contentType are not specified they are set
29 * to application/octet-stream.
30 *
31 * @param string $fileName
32 * @param resource $stream
33 * @param string $contentType
34 * @param string $mimeType
35 */
36 public function __construct( $fileName, $stream, $contentType = null, $mimeType = null )
37 {
38 parent::__construct( $fileName );
39 $this->stream = $stream;
40 if ( $contentType != null && $mimeType != null )
41 {
42 $this->contentType = $contentType;
43 $this->mimeType = $mimeType;
44 }
45 else
46 {
47 // default to mimetype application/octet-stream
48 $this->contentType = self::CONTENT_TYPE_APPLICATION;
49 $this->mimeType = "octet-stream";
50 }
51 }
52
53 /**
54 * Sets the property $name to $value.
55 *
56 * @throws ezcBasePropertyNotFoundException
57 * if the property does not exist.
58 * @param string $name
59 * @param mixed $value
60 * @ignore
61 */
62 public function __set( $name, $value )
63 {
64 switch ( $name )
65 {
66 case 'stream':
67 $this->properties[$name] = $value;
68 break;
69 default:
70 return parent::__set( $name, $value );
71 break;
72 }
73 }
74
75 /**
76 * Returns the value of property $value.
77 *
78 * @throws ezcBasePropertyNotFoundException
79 * if the property does not exist.
80 * @param string $name
81 * @return mixed
82 * @ignore
83 */
84 public function __get( $name )
85 {
86 switch ( $name )
87 {
88 case 'stream':
89 return $this->properties[$name];
90 break;
91 default:
92 return parent::__get( $name );
93 break;
94 }
95 }
96
97 /**
98 * Returns true if the property $name is set, otherwise false.
99 *
100 * @param string $name
101 * @return bool
102 * @ignore
103 */
104 public function __isset( $name )
105 {
106 switch ( $name )
107 {
108 case 'stream':
109 return isset( $this->properties[$name] );
110
111 default:
112 return parent::__isset( $name );
113 }
114 }
115
116 /**
117 * Returns the contents of the file with the correct encoding.
118 *
119 * The stream might become unusable after this if it doesn't support seek.
120 *
121 * @return string
122 */
123 public function generateBody()
124 {
125 $contents = stream_get_contents( $this->stream );
126 return chunk_split( base64_encode( $contents ), 76, ezcMailTools::lineBreak() );
127 }
128 }
129 ?>