1 | <?php |
||
20 | class MessageParser |
||
21 | { |
||
22 | /** |
||
23 | * @var \ZBateson\MailMimeParser\Message\Part\PartFactoryService service |
||
24 | * instance used to create MimePartFactory objects. |
||
25 | */ |
||
26 | protected $partFactoryService; |
||
27 | |||
28 | /** |
||
29 | * @var \ZBateson\MailMimeParser\Message\Part\PartBuilderFactory used to |
||
30 | * create PartBuilders |
||
31 | */ |
||
32 | protected $partBuilderFactory; |
||
33 | |||
34 | /** |
||
35 | * @var \ZBateson\MailMimeParser\Stream\PartStreamRegistry used for |
||
36 | * registering message part streams. |
||
37 | */ |
||
38 | protected $partStreamRegistry; |
||
39 | |||
40 | /** |
||
41 | * Sets up the parser with its dependencies. |
||
42 | * |
||
43 | * @param \ZBateson\MailMimeParser\Message\Part\PartFactoryService $pfs |
||
44 | * @param \ZBateson\MailMimeParser\Message\Part\PartBuilderFactory $pbf |
||
45 | * @param PartStreamRegistry $psr |
||
46 | */ |
||
47 | public function __construct( |
||
56 | |||
57 | /** |
||
58 | * Parses the passed stream handle into a ZBateson\MailMimeParser\Message |
||
59 | * object and returns it. |
||
60 | * |
||
61 | * @param resource $fhandle the resource handle to the input stream of the |
||
62 | * mime message |
||
63 | * @return \ZBateson\MailMimeParser\Message |
||
64 | */ |
||
65 | public function parse($fhandle) |
||
72 | |||
73 | /** |
||
74 | * Ensures the header isn't empty and contains a colon separator character, |
||
75 | * then splits it and calls $partBuilder->addHeader. |
||
76 | * |
||
77 | * @param string $header |
||
78 | * @param PartBuilder $partBuilder |
||
79 | */ |
||
80 | private function addRawHeaderToPart($header, PartBuilder $partBuilder) |
||
87 | |||
88 | /** |
||
89 | * Reads header lines up to an empty line, adding them to the passed |
||
90 | * $partBuilder. |
||
91 | * |
||
92 | * @param resource $handle the resource handle to read from |
||
93 | * @param PartBuilder $partBuilder the current part to add headers to |
||
94 | */ |
||
95 | protected function readHeaders($handle, PartBuilder $partBuilder) |
||
109 | |||
110 | /** |
||
111 | * Reads lines from the passed $handle, calling $partBuilder->setEndBoundary |
||
112 | * with the passed line until either setEndBoundary returns true or there |
||
113 | * are no more lines to be read. |
||
114 | * |
||
115 | * setEndBoundary returns true if the passed line matches a boundary for the |
||
116 | * $partBuilder itself or any of its parents. |
||
117 | * |
||
118 | * As lines are read, setStreamPartAndContentEndPos is called with the |
||
119 | * passed $handle's read pos (ftell($handle)) to update the position of |
||
120 | * content in the part. |
||
121 | * |
||
122 | * If the entire stream is read and an end boundary was found, i.e. |
||
123 | * $partBuilder->setEndBoundary returns true, true is returned to indicate |
||
124 | * that a content boundary was found. Otherwise false is returned. |
||
125 | * |
||
126 | * @param resource $handle |
||
127 | * @param PartBuilder $partBuilder |
||
128 | * @return boolean true if a mime content boundary was found for |
||
129 | * $partBuilder |
||
130 | */ |
||
131 | private function findContentBoundary($handle, PartBuilder $partBuilder) |
||
144 | |||
145 | /** |
||
146 | * Reads content for a non-mime message. If there are uuencoded attachment |
||
147 | * parts in the message (denoted by 'begin' lines), those parts are read and |
||
148 | * added to the passed $partBuilder as children. |
||
149 | * |
||
150 | * @param resource $handle |
||
151 | * @param PartBuilder $partBuilder |
||
152 | * @return string |
||
153 | */ |
||
154 | protected function readUUEncodedOrPlainTextMessage($handle, PartBuilder $partBuilder) |
||
176 | |||
177 | /** |
||
178 | * Reads content for a single part of a MIME message. |
||
179 | * |
||
180 | * If the part being read is in turn a multipart part, readPart is called on |
||
181 | * it recursively to read its headers and content. |
||
182 | * |
||
183 | * The method tries to read content until a mime boundary (for this part for |
||
184 | * a multipart, or for the parent boundary) is found or EOF is reached. |
||
185 | * |
||
186 | * The start/end positions of the part's content are set on the passed |
||
187 | * $partBuilder as lines are read, as is the part's end position. |
||
188 | * |
||
189 | * @param resource $handle |
||
190 | * @param PartBuilder $partBuilder |
||
191 | */ |
||
192 | private function readPartContent($handle, PartBuilder $partBuilder) |
||
215 | |||
216 | /** |
||
217 | * Reads a part and any of its children, into the passed $partBuilder. |
||
218 | * |
||
219 | * @param resource $handle |
||
220 | * @param PartBuilder $partBuilder |
||
221 | * @param boolean $isMessage |
||
222 | */ |
||
223 | protected function readPart($handle, PartBuilder $partBuilder, $isMessage = false) |
||
233 | |||
234 | /** |
||
235 | * Reads the message from the input stream $handle and returns a PartBuilder |
||
236 | * representing it. |
||
237 | * |
||
238 | * @param resource $handle |
||
239 | * @return PartBuilder |
||
240 | */ |
||
241 | protected function read($handle) |
||
249 | } |
||
250 |