1 | <?php |
||
20 | abstract class MessagePart |
||
21 | { |
||
22 | /** |
||
23 | * @var \ZBateson\MailMimeParser\Message\Part\MimePart parent part |
||
24 | */ |
||
25 | protected $parent; |
||
26 | |||
27 | /** |
||
28 | * @var resource a resource handle containing this part's headers, content |
||
29 | * and children |
||
30 | */ |
||
31 | protected $handle; |
||
32 | |||
33 | /** |
||
34 | * @var resource a resource handle to this part's content |
||
35 | */ |
||
36 | protected $contentHandle; |
||
37 | |||
38 | /** |
||
39 | * @var PartStreamFilterManager manages attached filters to $contentHandle |
||
40 | */ |
||
41 | protected $partStreamFilterManager; |
||
42 | |||
43 | /** |
||
44 | * @var string a unique ID representing the message this part belongs to. |
||
45 | */ |
||
46 | protected $messageObjectId; |
||
47 | |||
48 | /** |
||
49 | * Sets up class dependencies. |
||
50 | * |
||
51 | * @param string $messageObjectId |
||
52 | * @param PartBuilder $partBuilder |
||
53 | * @param PartStreamFilterManager $partStreamFilterManager |
||
54 | */ |
||
55 | public function __construct( |
||
71 | |||
72 | /** |
||
73 | * Closes the attached resource handles. |
||
74 | */ |
||
75 | public function __destruct() |
||
87 | |||
88 | /** |
||
89 | * Returns the unique object ID registered with the PartStreamRegistry |
||
90 | * service object for the message this part belongs to. |
||
91 | * |
||
92 | * @return string |
||
93 | * @see \ZBateson\MailMimeParser\SimpleDi::registerStreamExtensions |
||
94 | * @see \ZBateson\MailMimeParser\Stream\PartStream::stream_open |
||
95 | */ |
||
96 | public function getMessageObjectId() |
||
100 | |||
101 | /** |
||
102 | * Returns true if there's a content stream associated with the part. |
||
103 | * |
||
104 | * @return boolean |
||
105 | */ |
||
106 | public function hasContent() |
||
113 | |||
114 | /** |
||
115 | * Returns true if this part's mime type is text/plain, text/html or has a |
||
116 | * text/* and has a defined 'charset' attribute. |
||
117 | * |
||
118 | * @return bool |
||
119 | */ |
||
120 | public abstract function isTextPart(); |
||
121 | |||
122 | /** |
||
123 | * Returns the mime type of the content. |
||
124 | * |
||
125 | * @return string |
||
126 | */ |
||
127 | public abstract function getContentType(); |
||
128 | |||
129 | /** |
||
130 | * Returns the charset of the content, or null if not applicable/defined. |
||
131 | * |
||
132 | * @return string |
||
133 | */ |
||
134 | public abstract function getCharset(); |
||
135 | |||
136 | /** |
||
137 | * Returns the content's disposition. |
||
138 | * |
||
139 | * @return string |
||
140 | */ |
||
141 | public abstract function getContentDisposition(); |
||
142 | |||
143 | /** |
||
144 | * Returns the content-transfer-encoding used for this part. |
||
145 | * |
||
146 | * @return string |
||
147 | */ |
||
148 | public abstract function getContentTransferEncoding(); |
||
149 | |||
150 | /** |
||
151 | * Returns a filename for the part if one is defined, or null otherwise. |
||
152 | * |
||
153 | * @return string |
||
154 | */ |
||
155 | public function getFilename() |
||
159 | |||
160 | /** |
||
161 | * Returns true if the current part is a mime part. |
||
162 | * |
||
163 | * @return bool |
||
164 | */ |
||
165 | public abstract function isMime(); |
||
166 | |||
167 | /** |
||
168 | * Returns a resource stream handle allowing a user to read the original |
||
169 | * stream (including headers and child parts) that was used to create the |
||
170 | * current part. |
||
171 | * |
||
172 | * Note that 'rewind()' is called on the resource prior to returning it, |
||
173 | * which may affect other read operations if multiple calls to 'getHandle' |
||
174 | * are used. |
||
175 | * |
||
176 | * The resource stream is handled by MessagePart and is closed by the |
||
177 | * destructor. |
||
178 | * |
||
179 | * @return resource the resource handle or null if not set |
||
180 | */ |
||
181 | public function getHandle() |
||
188 | |||
189 | /** |
||
190 | * Returns the resource stream handle for the part's content or null if not |
||
191 | * set. rewind() is called on the stream before returning it. |
||
192 | * |
||
193 | * The resource is automatically closed by MimePart's destructor and should |
||
194 | * not be closed otherwise. |
||
195 | * |
||
196 | * The returned resource handle is a stream with decoding filters appended |
||
197 | * to it. The attached filters are determined by the passed |
||
198 | * $transferEncoding and $charset headers, or by looking at the part's |
||
199 | * Content-Transfer-Encoding and Content-Type headers if not passed. The |
||
200 | * following encodings are currently supported: |
||
201 | * |
||
202 | * - Quoted-Printable |
||
203 | * - Base64 |
||
204 | * - X-UUEncode |
||
205 | * |
||
206 | * In addition a ZBateson\MailMimeParser\Stream\CharsetStreamFilter is |
||
207 | * attached for text parts to convert text in the stream to UTF-8. |
||
208 | * |
||
209 | * @return resource |
||
210 | */ |
||
211 | public function getContentResourceHandle($transferEncoding = '', $charset = '') |
||
231 | |||
232 | /** |
||
233 | * Shortcut to reading stream content and assigning it to a string. Returns |
||
234 | * null if the part doesn't have a content stream. |
||
235 | * |
||
236 | * @return string |
||
237 | */ |
||
238 | public function getContent() |
||
247 | |||
248 | /** |
||
249 | * Returns this part's parent. |
||
250 | * |
||
251 | * @return \ZBateson\MailMimeParser\Message\Part\MimePart |
||
252 | */ |
||
253 | public function getParent() |
||
257 | } |
||
258 |