|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the ZBateson\MailMimeParser project. |
|
4
|
|
|
* |
|
5
|
|
|
* @license http://opensource.org/licenses/bsd-license.php BSD |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace ZBateson\MailMimeParser\Parser\Proxy; |
|
8
|
|
|
|
|
9
|
|
|
use ZBateson\MailMimeParser\Header\HeaderConsts; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* A bi-directional parser-to-part proxy for MimeParser and IMimeParts. |
|
13
|
|
|
* |
|
14
|
|
|
* @author Zaahid Bateson |
|
15
|
|
|
*/ |
|
16
|
|
|
class ParserMimePartProxy extends ParserPartProxy |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var boolean set to true once the end boundary of the currently-parsed |
|
20
|
|
|
* part is found. |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $endBoundaryFound = false; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var boolean set to true once a boundary belonging to this parent's part |
|
26
|
|
|
* is found. |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $parentBoundaryFound = false; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var bool|null|string FALSE if not queried for in the content-type |
|
32
|
|
|
* header of this part, NULL if the current part does not have a |
|
33
|
|
|
* boundary, and otherwise contains the value of the boundary parameter |
|
34
|
|
|
* of the content-type header if the part contains one. |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $mimeBoundary = false; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var bool true once all children of this part have been parsed. |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $allChildrenParsed = false; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var ParserPartProxy[] Parsed children used as a 'first-in-first-out' |
|
45
|
|
|
* stack as children are parsed. |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $children = []; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var ParserPartProxy Reference to the last child added to this part. |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $lastAddedChild = null; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Ensures that the last child added to this part is fully parsed (content |
|
56
|
|
|
* and children). |
|
57
|
|
|
*/ |
|
58
|
106 |
|
protected function ensureLastChildParsed() |
|
59
|
|
|
{ |
|
60
|
106 |
|
if ($this->lastAddedChild !== null) { |
|
61
|
76 |
|
$this->lastAddedChild->parseAll(); |
|
62
|
|
|
} |
|
63
|
106 |
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Parses the next child of this part and adds it to the 'stack' of |
|
67
|
|
|
* children. |
|
68
|
|
|
*/ |
|
69
|
106 |
|
protected function parseNextChild() |
|
70
|
|
|
{ |
|
71
|
106 |
|
if ($this->allChildrenParsed) { |
|
72
|
19 |
|
return; |
|
73
|
|
|
} |
|
74
|
106 |
|
$this->parseContent(); |
|
75
|
106 |
|
$this->ensureLastChildParsed(); |
|
76
|
106 |
|
$next = $this->parser->parseNextChild($this); |
|
77
|
106 |
|
if ($next !== null) { |
|
78
|
76 |
|
array_push($this->children, $next); |
|
79
|
76 |
|
$this->lastAddedChild = $next; |
|
80
|
|
|
} else { |
|
81
|
106 |
|
$this->allChildrenParsed = true; |
|
82
|
|
|
} |
|
83
|
106 |
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Returns the next child part if one exists, popping it from the internal |
|
87
|
|
|
* 'stack' of children, attempting to parse a new one if the stack is empty, |
|
88
|
|
|
* and returning null if there are no more children. |
|
89
|
|
|
* |
|
90
|
|
|
* @return IMessagePart|null the child part. |
|
|
|
|
|
|
91
|
|
|
*/ |
|
92
|
104 |
|
public function popNextChild() |
|
93
|
|
|
{ |
|
94
|
104 |
|
if (empty($this->children)) { |
|
95
|
104 |
|
$this->parseNextChild(); |
|
96
|
|
|
} |
|
97
|
104 |
|
$proxy = array_shift($this->children); |
|
98
|
104 |
|
return ($proxy !== null) ? $proxy->getPart() : null; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Parses all content and children for this part. |
|
103
|
|
|
*/ |
|
104
|
104 |
|
public function parseAll() |
|
105
|
|
|
{ |
|
106
|
104 |
|
$this->parseContent(); |
|
107
|
104 |
|
$child = null; |
|
|
|
|
|
|
108
|
104 |
|
while (!$this->allChildrenParsed) { |
|
109
|
26 |
|
$this->parseNextChild(); |
|
110
|
|
|
} |
|
111
|
104 |
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Returns a ParameterHeader representing the parsed Content-Type header for |
|
115
|
|
|
* this part. |
|
116
|
|
|
* |
|
117
|
|
|
* @return \ZBateson\MailMimeParser\Header\ParameterHeader |
|
118
|
|
|
*/ |
|
119
|
78 |
|
public function getContentType() |
|
120
|
|
|
{ |
|
121
|
78 |
|
return $this->getHeaderContainer()->get(HeaderConsts::CONTENT_TYPE); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Returns the parsed boundary parameter of the Content-Type header if set |
|
126
|
|
|
* for a multipart message part. |
|
127
|
|
|
* |
|
128
|
|
|
* @return string |
|
129
|
|
|
*/ |
|
130
|
77 |
|
public function getMimeBoundary() |
|
131
|
|
|
{ |
|
132
|
77 |
|
if ($this->mimeBoundary === false) { |
|
133
|
77 |
|
$this->mimeBoundary = null; |
|
134
|
77 |
|
$contentType = $this->getContentType(); |
|
135
|
77 |
|
if ($contentType !== null) { |
|
136
|
75 |
|
$this->mimeBoundary = $contentType->getValueFor('boundary'); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
77 |
|
return $this->mimeBoundary; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Returns true if the passed $line of read input matches this part's mime |
|
144
|
|
|
* boundary, or any of its parent's mime boundaries for a multipart message. |
|
145
|
|
|
* |
|
146
|
|
|
* If the passed $line is the ending boundary for the current part, |
|
147
|
|
|
* $this->isEndBoundaryFound will return true after. |
|
148
|
|
|
* |
|
149
|
|
|
* @param string $line |
|
150
|
|
|
* @return bool |
|
151
|
|
|
*/ |
|
152
|
75 |
|
public function setEndBoundaryFound($line) |
|
153
|
|
|
{ |
|
154
|
75 |
|
$boundary = $this->getMimeBoundary(); |
|
155
|
75 |
|
if ($this->getParent() !== null && $this->getParent()->setEndBoundaryFound($line)) { |
|
|
|
|
|
|
156
|
73 |
|
$this->parentBoundaryFound = true; |
|
157
|
73 |
|
return true; |
|
158
|
75 |
|
} elseif ($boundary !== null) { |
|
|
|
|
|
|
159
|
73 |
|
if ($line === "--$boundary--") { |
|
160
|
73 |
|
$this->endBoundaryFound = true; |
|
161
|
73 |
|
return true; |
|
162
|
73 |
|
} elseif ($line === "--$boundary") { |
|
163
|
73 |
|
return true; |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
37 |
|
return false; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Returns true if the parser passed an input line to setEndBoundary that |
|
171
|
|
|
* matches a parent's mime boundary, and the following input belongs to a |
|
172
|
|
|
* new part under its parent. |
|
173
|
|
|
* |
|
174
|
|
|
* @return bool |
|
175
|
|
|
*/ |
|
176
|
102 |
|
public function isParentBoundaryFound() |
|
177
|
|
|
{ |
|
178
|
102 |
|
return ($this->parentBoundaryFound); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* Returns true if an end boundary was found for this part. |
|
183
|
|
|
* |
|
184
|
|
|
* @return bool |
|
185
|
|
|
*/ |
|
186
|
75 |
|
public function isEndBoundaryFound() |
|
187
|
|
|
{ |
|
188
|
75 |
|
return ($this->endBoundaryFound); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* Called once EOF is reached while reading content. The method sets the |
|
193
|
|
|
* flag used by isParentBoundaryFound() to true on this part and all parent |
|
194
|
|
|
* parts. |
|
195
|
|
|
*/ |
|
196
|
96 |
|
public function setEof() |
|
197
|
|
|
{ |
|
198
|
96 |
|
$this->parentBoundaryFound = true; |
|
199
|
96 |
|
if ($this->getParent() !== null) { |
|
200
|
65 |
|
$this->getParent()->setEof(); |
|
|
|
|
|
|
201
|
|
|
} |
|
202
|
96 |
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* Sets the length of the last line ending read by MimeParser (e.g. 2 for |
|
206
|
|
|
* '\r\n', or 1 for '\n'). |
|
207
|
|
|
* |
|
208
|
|
|
* The line ending may not belong specifically to this part, so |
|
209
|
|
|
* ParserMimePartProxy simply calls setLastLineEndingLength on its parent, |
|
210
|
|
|
* which must eventually reach a ParserMessageProxy which actually stores |
|
211
|
|
|
* the length. |
|
212
|
|
|
* |
|
213
|
|
|
* @param int $length |
|
214
|
|
|
*/ |
|
215
|
73 |
|
public function setLastLineEndingLength($length) |
|
216
|
|
|
{ |
|
217
|
73 |
|
$this->getParent()->setLastLineEndingLength($length); |
|
|
|
|
|
|
218
|
73 |
|
} |
|
219
|
|
|
|
|
220
|
|
|
/** |
|
221
|
|
|
* Returns the length of the last line ending read by MimeParser (e.g. 2 for |
|
222
|
|
|
* '\r\n', or 1 for '\n'). |
|
223
|
|
|
* |
|
224
|
|
|
* The line ending may not belong specifically to this part, so |
|
225
|
|
|
* ParserMimePartProxy simply calls getLastLineEndingLength on its parent, |
|
226
|
|
|
* which must eventually reach a ParserMessageProxy which actually keeps |
|
227
|
|
|
* the length and returns it. |
|
228
|
|
|
* |
|
229
|
|
|
* @return int the length of the last line ending read |
|
230
|
|
|
*/ |
|
231
|
73 |
|
public function getLastLineEndingLength() |
|
232
|
|
|
{ |
|
233
|
73 |
|
return $this->getParent()->getLastLineEndingLength(); |
|
|
|
|
|
|
234
|
|
|
} |
|
235
|
|
|
} |
|
236
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths