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 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 '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
|
|
|
protected function ensureLastChildParsed() |
59
|
|
|
{ |
60
|
|
|
if ($this->lastAddedChild !== null) { |
61
|
|
|
$this->lastAddedChild->parseAll(); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Parses the next child of this part and adds it to the children list. |
67
|
|
|
*/ |
68
|
|
|
protected function parseNextChild() |
69
|
|
|
{ |
70
|
|
|
if ($this->allChildrenParsed) { |
71
|
|
|
return; |
72
|
|
|
} |
73
|
|
|
$this->parseContent(); |
74
|
|
|
$this->ensureLastChildParsed(); |
75
|
|
|
$next = $this->parser->parseNextChild($this); |
|
|
|
|
76
|
|
|
if ($next !== null) { |
77
|
|
|
array_push($this->children, $next); |
78
|
|
|
$this->lastAddedChild = $next; |
79
|
|
|
} else { |
80
|
|
|
$this->allChildrenParsed = true; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Returns the next child part if one exists, removing it from the internal |
86
|
|
|
* list of children, or null otherwise. |
87
|
|
|
* |
88
|
|
|
* @return IMessagePart|null the child part. |
|
|
|
|
89
|
|
|
*/ |
90
|
|
|
public function popNextChild() |
91
|
|
|
{ |
92
|
|
|
if (empty($this->children)) { |
93
|
|
|
$this->parseNextChild(); |
94
|
|
|
} |
95
|
|
|
$proxy = array_shift($this->children); |
96
|
|
|
return ($proxy !== null) ? $proxy->getPart() : null; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Parses all content and children for this part. |
101
|
|
|
*/ |
102
|
|
|
public function parseAll() |
103
|
|
|
{ |
104
|
|
|
$this->parseContent(); |
105
|
|
|
$child = null; |
|
|
|
|
106
|
|
|
while (!$this->allChildrenParsed) { |
107
|
|
|
$this->parseNextChild(); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Returns a ParameterHeader representing the parsed Content-Type header for |
113
|
|
|
* this part. |
114
|
|
|
* |
115
|
|
|
* @return \ZBateson\MailMimeParser\Header\ParameterHeader |
116
|
|
|
*/ |
117
|
|
|
public function getContentType() |
118
|
|
|
{ |
119
|
|
|
return $this->getHeaderContainer()->get(HeaderConsts::CONTENT_TYPE); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Returns the parsed boundary parameter of the Content-Type header if set |
124
|
|
|
* for a multipart message part. |
125
|
|
|
* |
126
|
|
|
* @return string |
127
|
|
|
*/ |
128
|
|
|
public function getMimeBoundary() |
129
|
|
|
{ |
130
|
|
|
if ($this->mimeBoundary === false) { |
131
|
|
|
$this->mimeBoundary = null; |
132
|
|
|
$contentType = $this->getContentType(); |
133
|
|
|
if ($contentType !== null) { |
134
|
|
|
$this->mimeBoundary = $contentType->getValueFor('boundary'); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
return $this->mimeBoundary; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Returns true if the passed $line of read input matches this part's mime |
142
|
|
|
* boundary, or any of its parent's mime boundaries for a multipart message. |
143
|
|
|
* |
144
|
|
|
* If the passed $line is the ending boundary for the current part, |
145
|
|
|
* $this->isEndBoundaryFound will return true after. |
146
|
|
|
* |
147
|
|
|
* @param string $line |
148
|
|
|
* @return bool |
149
|
|
|
*/ |
150
|
|
|
public function setEndBoundaryFound($line) |
151
|
|
|
{ |
152
|
|
|
$boundary = $this->getMimeBoundary(); |
153
|
|
|
if ($this->getParent() !== null && $this->getParent()->setEndBoundaryFound($line)) { |
|
|
|
|
154
|
|
|
$this->parentBoundaryFound = true; |
155
|
|
|
return true; |
156
|
|
|
} elseif ($boundary !== null) { |
|
|
|
|
157
|
|
|
if ($line === "--$boundary--") { |
158
|
|
|
$this->endBoundaryFound = true; |
159
|
|
|
return true; |
160
|
|
|
} elseif ($line === "--$boundary") { |
161
|
|
|
return true; |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
return false; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Returns true if the parser passed an input line to setEndBoundary that |
169
|
|
|
* matches a parent's mime boundary, and the following input belongs to a |
170
|
|
|
* new part under its parent. |
171
|
|
|
* |
172
|
|
|
* @return bool |
173
|
|
|
*/ |
174
|
|
|
public function isParentBoundaryFound() |
175
|
|
|
{ |
176
|
|
|
return ($this->parentBoundaryFound); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Returns true if an end boundary was found for this part. |
181
|
|
|
* |
182
|
|
|
* @return bool |
183
|
|
|
*/ |
184
|
|
|
public function isEndBoundaryFound() |
185
|
|
|
{ |
186
|
|
|
return ($this->endBoundaryFound); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Called once EOF is reached while reading content. The method sets the |
191
|
|
|
* flag used by isParentBoundaryFound() to true on this part and all parent |
192
|
|
|
* parts. |
193
|
|
|
*/ |
194
|
|
|
public function setEof() |
195
|
|
|
{ |
196
|
|
|
$this->parentBoundaryFound = true; |
197
|
|
|
if ($this->getParent() !== null) { |
198
|
|
|
$this->getParent()->setEof(); |
|
|
|
|
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
public function setLastLineEndingLength($length) |
203
|
|
|
{ |
204
|
|
|
$this->getParent()->setLastLineEndingLength($length); |
|
|
|
|
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
public function getLastLineEndingLength() |
208
|
|
|
{ |
209
|
|
|
return $this->getParent()->getLastLineEndingLength(); |
|
|
|
|
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.