12 * obtain it through the world-wide-web, please send an email |
12 * obtain it through the world-wide-web, please send an email |
13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Mime |
16 * @package Zend_Mime |
17 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
17 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @version $Id: Part.php 24593 2012-01-05 20:35:02Z matthew $ |
19 * @version $Id$ |
20 */ |
20 */ |
21 |
21 |
22 /** |
22 /** |
23 * Zend_Mime |
23 * Zend_Mime |
24 */ |
24 */ |
27 /** |
27 /** |
28 * Class representing a MIME part. |
28 * Class representing a MIME part. |
29 * |
29 * |
30 * @category Zend |
30 * @category Zend |
31 * @package Zend_Mime |
31 * @package Zend_Mime |
32 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
32 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
33 * @license http://framework.zend.com/license/new-bsd New BSD License |
33 * @license http://framework.zend.com/license/new-bsd New BSD License |
34 */ |
34 */ |
35 class Zend_Mime_Part { |
35 class Zend_Mime_Part |
36 |
36 { |
|
37 |
|
38 /** |
|
39 * Type |
|
40 * |
|
41 * @var string |
|
42 */ |
37 public $type = Zend_Mime::TYPE_OCTETSTREAM; |
43 public $type = Zend_Mime::TYPE_OCTETSTREAM; |
|
44 |
|
45 /** |
|
46 * Encoding |
|
47 * |
|
48 * @var string |
|
49 */ |
38 public $encoding = Zend_Mime::ENCODING_8BIT; |
50 public $encoding = Zend_Mime::ENCODING_8BIT; |
|
51 |
|
52 /** |
|
53 * ID |
|
54 * |
|
55 * @var string |
|
56 */ |
39 public $id; |
57 public $id; |
|
58 |
|
59 /** |
|
60 * Disposition |
|
61 * |
|
62 * @var string |
|
63 */ |
40 public $disposition; |
64 public $disposition; |
|
65 |
|
66 /** |
|
67 * Filename |
|
68 * |
|
69 * @var string |
|
70 */ |
41 public $filename; |
71 public $filename; |
|
72 |
|
73 /** |
|
74 * Description |
|
75 * |
|
76 * @var string |
|
77 */ |
42 public $description; |
78 public $description; |
|
79 |
|
80 /** |
|
81 * Character set |
|
82 * |
|
83 * @var string |
|
84 */ |
43 public $charset; |
85 public $charset; |
|
86 |
|
87 /** |
|
88 * Boundary |
|
89 * |
|
90 * @var string |
|
91 */ |
44 public $boundary; |
92 public $boundary; |
|
93 |
|
94 /** |
|
95 * Location |
|
96 * |
|
97 * @var string |
|
98 */ |
45 public $location; |
99 public $location; |
|
100 |
|
101 /** |
|
102 * Language |
|
103 * |
|
104 * @var string |
|
105 */ |
46 public $language; |
106 public $language; |
|
107 |
|
108 /** |
|
109 * Content |
|
110 * |
|
111 * @var mixed |
|
112 */ |
47 protected $_content; |
113 protected $_content; |
|
114 |
|
115 /** |
|
116 * @var bool |
|
117 */ |
48 protected $_isStream = false; |
118 protected $_isStream = false; |
49 |
|
50 |
119 |
51 /** |
120 /** |
52 * create a new Mime Part. |
121 * create a new Mime Part. |
53 * The (unencoded) content of the Part as passed |
122 * The (unencoded) content of the Part as passed |
54 * as a string or stream |
123 * as a string or stream |
55 * |
124 * |
56 * @param mixed $content String or Stream containing the content |
125 * @param mixed $content String or Stream containing the content |
57 */ |
126 */ |
58 public function __construct($content) |
127 public function __construct($content) |
59 { |
128 { |
60 $this->_content = $content; |
129 $this->_content = $content; |
61 if (is_resource($content)) { |
130 if (is_resource($content)) { |
77 * |
146 * |
78 * @return bool |
147 * @return bool |
79 */ |
148 */ |
80 public function isStream() |
149 public function isStream() |
81 { |
150 { |
82 return $this->_isStream; |
151 return $this->_isStream; |
83 } |
152 } |
84 |
153 |
85 /** |
154 /** |
86 * if this was created with a stream, return a filtered stream for |
155 * if this was created with a stream, return a filtered stream for |
87 * reading the content. very useful for large file attachments. |
156 * reading the content. very useful for large file attachments. |
88 * |
157 * |
89 * @return stream |
158 * @return mixed Stream |
90 * @throws Zend_Mime_Exception if not a stream or unable to append filter |
159 * @throws Zend_Mime_Exception if not a stream or unable to append filter |
91 */ |
160 */ |
92 public function getEncodedStream() |
161 public function getEncodedStream() |
93 { |
162 { |
94 if (!$this->_isStream) { |
163 if (!$this->_isStream) { |
95 require_once 'Zend/Mime/Exception.php'; |
164 require_once 'Zend/Mime/Exception.php'; |
96 throw new Zend_Mime_Exception('Attempt to get a stream from a string part'); |
165 throw new Zend_Mime_Exception( |
|
166 'Attempt to get a stream from a string part' |
|
167 ); |
97 } |
168 } |
98 |
169 |
99 //stream_filter_remove(); // ??? is that right? |
170 //stream_filter_remove(); // ??? is that right? |
100 switch ($this->encoding) { |
171 switch ($this->encoding) { |
101 case Zend_Mime::ENCODING_QUOTEDPRINTABLE: |
172 case Zend_Mime::ENCODING_QUOTEDPRINTABLE: |
108 'line-break-chars' => Zend_Mime::LINEEND |
179 'line-break-chars' => Zend_Mime::LINEEND |
109 ) |
180 ) |
110 ); |
181 ); |
111 if (!is_resource($filter)) { |
182 if (!is_resource($filter)) { |
112 require_once 'Zend/Mime/Exception.php'; |
183 require_once 'Zend/Mime/Exception.php'; |
113 throw new Zend_Mime_Exception('Failed to append quoted-printable filter'); |
184 throw new Zend_Mime_Exception( |
|
185 'Failed to append quoted-printable filter' |
|
186 ); |
114 } |
187 } |
115 break; |
188 break; |
|
189 |
116 case Zend_Mime::ENCODING_BASE64: |
190 case Zend_Mime::ENCODING_BASE64: |
117 $filter = stream_filter_append( |
191 $filter = stream_filter_append( |
118 $this->_content, |
192 $this->_content, |
119 'convert.base64-encode', |
193 'convert.base64-encode', |
120 STREAM_FILTER_READ, |
194 STREAM_FILTER_READ, |
123 'line-break-chars' => Zend_Mime::LINEEND |
197 'line-break-chars' => Zend_Mime::LINEEND |
124 ) |
198 ) |
125 ); |
199 ); |
126 if (!is_resource($filter)) { |
200 if (!is_resource($filter)) { |
127 require_once 'Zend/Mime/Exception.php'; |
201 require_once 'Zend/Mime/Exception.php'; |
128 throw new Zend_Mime_Exception('Failed to append base64 filter'); |
202 throw new Zend_Mime_Exception( |
|
203 'Failed to append base64 filter' |
|
204 ); |
129 } |
205 } |
130 break; |
206 break; |
|
207 |
131 default: |
208 default: |
132 } |
209 } |
|
210 |
133 return $this->_content; |
211 return $this->_content; |
134 } |
212 } |
135 |
213 |
136 /** |
214 /** |
137 * Get the Content of the current Mime Part in the given encoding. |
215 * Get the Content of the current Mime Part in the given encoding. |
138 * |
216 * |
139 * @return String |
217 * @param string $EOL Line end; defaults to {@link Zend_Mime::LINEEND} |
|
218 * @throws Zend_Mime_Exception |
|
219 * @return string |
140 */ |
220 */ |
141 public function getContent($EOL = Zend_Mime::LINEEND) |
221 public function getContent($EOL = Zend_Mime::LINEEND) |
142 { |
222 { |
143 if ($this->_isStream) { |
223 if ($this->_isStream) { |
144 return stream_get_contents($this->getEncodedStream()); |
224 return stream_get_contents($this->getEncodedStream()); |
145 } else { |
225 } else { |
146 return Zend_Mime::encode($this->_content, $this->encoding, $EOL); |
226 return Zend_Mime::encode($this->_content, $this->encoding, $EOL); |
147 } |
227 } |
148 } |
228 } |
149 |
229 |
150 /** |
230 /** |
151 * Get the RAW unencoded content from this part |
231 * Get the RAW unencoded content from this part |
|
232 * |
152 * @return string |
233 * @return string |
153 */ |
234 */ |
154 public function getRawContent() |
235 public function getRawContent() |
155 { |
236 { |
156 if ($this->_isStream) { |
237 if ($this->_isStream) { |
175 $contentType .= '; charset=' . $this->charset; |
256 $contentType .= '; charset=' . $this->charset; |
176 } |
257 } |
177 |
258 |
178 if ($this->boundary) { |
259 if ($this->boundary) { |
179 $contentType .= ';' . $EOL |
260 $contentType .= ';' . $EOL |
180 . " boundary=\"" . $this->boundary . '"'; |
261 . " boundary=\"" . $this->boundary . '"'; |
181 } |
262 } |
182 |
263 |
183 $headers[] = array('Content-Type', $contentType); |
264 $headers[] = array( |
|
265 'Content-Type', |
|
266 $contentType |
|
267 ); |
184 |
268 |
185 if ($this->encoding) { |
269 if ($this->encoding) { |
186 $headers[] = array('Content-Transfer-Encoding', $this->encoding); |
270 $headers[] = array( |
|
271 'Content-Transfer-Encoding', |
|
272 $this->encoding |
|
273 ); |
187 } |
274 } |
188 |
275 |
189 if ($this->id) { |
276 if ($this->id) { |
190 $headers[] = array('Content-ID', '<' . $this->id . '>'); |
277 $headers[] = array( |
|
278 'Content-ID', |
|
279 '<' . $this->id . '>' |
|
280 ); |
191 } |
281 } |
192 |
282 |
193 if ($this->disposition) { |
283 if ($this->disposition) { |
194 $disposition = $this->disposition; |
284 $disposition = $this->disposition; |
195 if ($this->filename) { |
285 if ($this->filename) { |
196 $disposition .= '; filename="' . $this->filename . '"'; |
286 $disposition .= '; filename="' . $this->filename . '"'; |
197 } |
287 } |
198 $headers[] = array('Content-Disposition', $disposition); |
288 $headers[] = array( |
|
289 'Content-Disposition', |
|
290 $disposition |
|
291 ); |
199 } |
292 } |
200 |
293 |
201 if ($this->description) { |
294 if ($this->description) { |
202 $headers[] = array('Content-Description', $this->description); |
295 $headers[] = array( |
|
296 'Content-Description', |
|
297 $this->description |
|
298 ); |
203 } |
299 } |
204 |
300 |
205 if ($this->location) { |
301 if ($this->location) { |
206 $headers[] = array('Content-Location', $this->location); |
302 $headers[] = array( |
207 } |
303 'Content-Location', |
208 |
304 $this->location |
209 if ($this->language){ |
305 ); |
210 $headers[] = array('Content-Language', $this->language); |
306 } |
|
307 |
|
308 if ($this->language) { |
|
309 $headers[] = array( |
|
310 'Content-Language', |
|
311 $this->language |
|
312 ); |
211 } |
313 } |
212 |
314 |
213 return $headers; |
315 return $headers; |
214 } |
316 } |
215 |
317 |
216 /** |
318 /** |
217 * Return the headers for this part as a string |
319 * Return the headers for this part as a string |
218 * |
320 * |
219 * @return String |
321 * @param string $EOL Line end; defaults to {@link Zend_Mime::LINEEND} |
|
322 * @return string |
220 */ |
323 */ |
221 public function getHeaders($EOL = Zend_Mime::LINEEND) |
324 public function getHeaders($EOL = Zend_Mime::LINEEND) |
222 { |
325 { |
223 $res = ''; |
326 $res = ''; |
224 foreach ($this->getHeadersArray($EOL) as $header) { |
327 foreach ($this->getHeadersArray($EOL) as $header) { |