@@ -153,6 +153,9 @@ |
||
153 | 153 | return $headers; |
154 | 154 | } |
155 | 155 | |
156 | + /** |
|
157 | + * @param resource $stream |
|
158 | + */ |
|
156 | 159 | protected function parseParts($stream, array $partHeaders): array |
157 | 160 | { |
158 | 161 | $parts = []; |
@@ -11,8 +11,8 @@ discard block |
||
11 | 11 | private const SWIFT_CONTAINER_CACHE_KEY = 'cache'; |
12 | 12 | private const SWIFT_CONTAINER_ID_GENERATOR_KEY = 'mime.idgenerator'; |
13 | 13 | |
14 | - protected $removeHeaders = ['Received', 'From', 'X-Original-To', 'MIME-Version', 'Received-SPF', 'Delivered-To']; |
|
15 | - protected $allowedHeaders = ['return-path', 'subject']; |
|
14 | + protected $removeHeaders = [ 'Received', 'From', 'X-Original-To', 'MIME-Version', 'Received-SPF', 'Delivered-To' ]; |
|
15 | + protected $allowedHeaders = [ 'return-path', 'subject' ]; |
|
16 | 16 | /** |
17 | 17 | * @var ContentDecoder |
18 | 18 | */ |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | private $swiftContainer; |
30 | 30 | |
31 | - public function __construct(array $allowedHeaders = [], array $removeHeaders = []) |
|
31 | + public function __construct(array $allowedHeaders = [ ], array $removeHeaders = [ ]) |
|
32 | 32 | { |
33 | 33 | $this->contentDecoder = new ContentDecoder(); |
34 | 34 | $this->headerDecoder = new HeaderDecoder(); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $parts = $this->parseParts($stream, $partHeaders); |
100 | 100 | |
101 | 101 | if (!$message) { |
102 | - $message = new \Swift_Message (); |
|
102 | + $message = new \Swift_Message(); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | $headers = $this->createHeadersSet($filteredHeaders); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | |
117 | 117 | protected function extractHeaders($stream): array |
118 | 118 | { |
119 | - $headers = []; |
|
119 | + $headers = [ ]; |
|
120 | 120 | $hName = null; |
121 | 121 | while (!feof($stream)) { |
122 | 122 | $row = fgets($stream); |
@@ -124,19 +124,19 @@ discard block |
||
124 | 124 | break; |
125 | 125 | } |
126 | 126 | if (preg_match('/^([a-z0-9\-]+)\s*:(.*)/i', $row, $mch)) { |
127 | - $hName = strtolower($mch[1]); |
|
128 | - if (!in_array($hName, ["content-type", "content-transfer-encoding"], true)) { |
|
129 | - $hName = $mch[1]; |
|
127 | + $hName = strtolower($mch[ 1 ]); |
|
128 | + if (!in_array($hName, [ "content-type", "content-transfer-encoding" ], true)) { |
|
129 | + $hName = $mch[ 1 ]; |
|
130 | 130 | } |
131 | - $row = $mch[2]; |
|
131 | + $row = $mch[ 2 ]; |
|
132 | 132 | } |
133 | 133 | if (empty($hName)) { |
134 | 134 | continue; |
135 | 135 | } |
136 | - $headers[$hName][] = trim($row); |
|
136 | + $headers[ $hName ][ ] = trim($row); |
|
137 | 137 | } |
138 | 138 | foreach ($headers as $header => $values) { |
139 | - $headers[$header] = $this->headerDecoder->decode(trim(implode(" ", $values))); |
|
139 | + $headers[ $header ] = $this->headerDecoder->decode(trim(implode(" ", $values))); |
|
140 | 140 | } |
141 | 141 | return $headers; |
142 | 142 | } |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | if (in_array(strtolower($header), $this->removeHeaders, true) |
148 | 148 | && !in_array(strtolower($header), $this->allowedHeaders, true) |
149 | 149 | ) { |
150 | - unset($headers[$header]); |
|
150 | + unset($headers[ $header ]); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | return $headers; |
@@ -155,16 +155,16 @@ discard block |
||
155 | 155 | |
156 | 156 | protected function parseParts($stream, array $partHeaders): array |
157 | 157 | { |
158 | - $parts = []; |
|
158 | + $parts = [ ]; |
|
159 | 159 | $contentType = $this->extractValueHeader($this->getContentType($partHeaders)); |
160 | 160 | |
161 | 161 | $boundary = null; |
162 | 162 | if (stripos($contentType, 'multipart/') !== false) { |
163 | 163 | $headerParts = $this->extractHeaderParts($this->getContentType($partHeaders)); |
164 | - if (empty($headerParts["boundary"])) { |
|
164 | + if (empty($headerParts[ "boundary" ])) { |
|
165 | 165 | throw new InvalidMessageFormatException("The Content-Type header is not well formed, boundary is missing"); |
166 | 166 | } |
167 | - $boundary = $headerParts["boundary"]; |
|
167 | + $boundary = $headerParts[ "boundary" ]; |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | try { |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | "headers" => $partHeaders, |
177 | 177 | "body" => $e->getData(), |
178 | 178 | "boundary" => $boundary, |
179 | - "parts" => [], |
|
179 | + "parts" => [ ], |
|
180 | 180 | ]; |
181 | 181 | } |
182 | 182 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | $childContentType = $this->extractValueHeader($this->getContentType($partHeaders)); |
189 | 189 | |
190 | 190 | if (stripos($childContentType, 'multipart/') !== false) { |
191 | - $parts["parts"][] = $this->parseParts($stream, $partHeaders); |
|
191 | + $parts[ "parts" ][ ] = $this->parseParts($stream, $partHeaders); |
|
192 | 192 | try { |
193 | 193 | $this->extractPart($stream, $boundary, $this->getTransferEncoding($partHeaders)); |
194 | 194 | } catch (Exception\EndOfPartReachedException $e) { |
@@ -197,12 +197,12 @@ discard block |
||
197 | 197 | $this->extractPart($stream, $boundary, $this->getTransferEncoding($partHeaders)); |
198 | 198 | } |
199 | 199 | } catch (Exception\EndOfPartReachedException $e) { |
200 | - $parts["parts"][] = [ |
|
200 | + $parts[ "parts" ][ ] = [ |
|
201 | 201 | "type" => $childContentType, |
202 | 202 | "parent-type" => $contentType, |
203 | 203 | "headers" => $partHeaders, |
204 | 204 | "body" => $e->getData(), |
205 | - "parts" => [] |
|
205 | + "parts" => [ ] |
|
206 | 206 | ]; |
207 | 207 | |
208 | 208 | if ($e instanceof Exception\EndOfMultiPartReachedException) { |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | private function getContentType(array $partHeaders): string |
228 | 228 | { |
229 | 229 | if (array_key_exists('content-type', $partHeaders)) { |
230 | - return $partHeaders['content-type']; |
|
230 | + return $partHeaders[ 'content-type' ]; |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | return ''; |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | if (strpos($header, ';') !== false) { |
239 | 239 | $parts = explode(";", $header); |
240 | 240 | array_shift($parts); |
241 | - $p = []; |
|
241 | + $p = [ ]; |
|
242 | 242 | $part = ''; |
243 | 243 | foreach ($parts as $pv) { |
244 | 244 | if (preg_match('/="[^"]+$/', $pv)) { |
@@ -257,12 +257,12 @@ discard block |
||
257 | 257 | continue; |
258 | 258 | } |
259 | 259 | list ($k, $v) = explode("=", trim($pv), 2); |
260 | - $p[$k] = trim($v, '"'); |
|
260 | + $p[ $k ] = trim($v, '"'); |
|
261 | 261 | } |
262 | 262 | return $p; |
263 | 263 | } |
264 | 264 | |
265 | - return []; |
|
265 | + return [ ]; |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | */ |
272 | 272 | protected function extractPart($stream, ?string $boundary, string $encoding): void |
273 | 273 | { |
274 | - $rows = []; |
|
274 | + $rows = [ ]; |
|
275 | 275 | while (!feof($stream)) { |
276 | 276 | $row = fgets($stream); |
277 | 277 | |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | throw new Exception\EndOfPartReachedException($this->contentDecoder->decode(implode("", $rows), $encoding)); |
284 | 284 | } |
285 | 285 | } |
286 | - $rows[] = $row; |
|
286 | + $rows[ ] = $row; |
|
287 | 287 | } |
288 | 288 | throw new Exception\EndOfMultiPartReachedException($this->contentDecoder->decode(implode("", $rows), $encoding)); |
289 | 289 | } |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | private function getTransferEncoding(array $partHeaders): string |
292 | 292 | { |
293 | 293 | if (array_key_exists('content-transfer-encoding', $partHeaders)) { |
294 | - return $partHeaders['content-transfer-encoding']; |
|
294 | + return $partHeaders[ 'content-transfer-encoding' ]; |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | return ''; |
@@ -305,13 +305,13 @@ discard block |
||
305 | 305 | switch (strtolower($name)) { |
306 | 306 | case "content-type": |
307 | 307 | $parts = $this->extractHeaderParts($value); |
308 | - unset($parts["boundary"]); |
|
308 | + unset($parts[ "boundary" ]); |
|
309 | 309 | $headers->addParameterizedHeader($name, $this->extractValueHeader($value), $parts); |
310 | 310 | break; |
311 | 311 | case "return-path": |
312 | 312 | if (preg_match_all('/([a-z][a-z0-9_\-\.]*@[a-z0-9\.\-]*\.[a-z]{2,5})/i', $value, $mch)) { |
313 | - foreach ($mch[0] as $k => $mails) { |
|
314 | - $headers->addPathHeader($name, $mch[1][$k]); |
|
313 | + foreach ($mch[ 0 ] as $k => $mails) { |
|
314 | + $headers->addPathHeader($name, $mch[ 1 ][ $k ]); |
|
315 | 315 | } |
316 | 316 | } |
317 | 317 | break; |
@@ -323,18 +323,18 @@ discard block |
||
323 | 323 | case "bcc": |
324 | 324 | case "reply-to": |
325 | 325 | case "cc": |
326 | - $adresses = []; |
|
326 | + $adresses = [ ]; |
|
327 | 327 | if (preg_match_all('/(.*?)<([a-z][a-z0-9_\-\.]*@[a-z0-9\.\-]*\.[a-z]{2,5})>\s*[;,]*/i', $value, $mch)) { |
328 | - foreach ($mch[0] as $k => $mail) { |
|
329 | - if (!$mch[1][$k]) { |
|
330 | - $adresses[$mch[2][$k]] = trim($mch[2][$k]); |
|
328 | + foreach ($mch[ 0 ] as $k => $mail) { |
|
329 | + if (!$mch[ 1 ][ $k ]) { |
|
330 | + $adresses[ $mch[ 2 ][ $k ] ] = trim($mch[ 2 ][ $k ]); |
|
331 | 331 | } else { |
332 | - $adresses[$mch[2][$k]] = trim($mch[1][$k]); |
|
332 | + $adresses[ $mch[ 2 ][ $k ] ] = trim($mch[ 1 ][ $k ]); |
|
333 | 333 | } |
334 | 334 | } |
335 | 335 | } elseif (preg_match_all('/([a-z][a-z0-9_\-\.]*@[a-z0-9\.\-]*\.[a-z]{2,5})/i', $value, $mch)) { |
336 | - foreach ($mch[0] as $k => $mails) { |
|
337 | - $adresses[$mch[1][$k]] = trim($mch[1][$k]); |
|
336 | + foreach ($mch[ 0 ] as $k => $mails) { |
|
337 | + $adresses[ $mch[ 1 ][ $k ] ] = trim($mch[ 1 ][ $k ]); |
|
338 | 338 | } |
339 | 339 | } |
340 | 340 | $headers->addMailboxHeader($name, $adresses); |
@@ -349,42 +349,42 @@ discard block |
||
349 | 349 | |
350 | 350 | protected function createMessage(array $message, \Swift_Mime_SimpleMimeEntity $entity): void |
351 | 351 | { |
352 | - if (!empty($message["parts"]) && stripos($message["type"], 'multipart/') !== false) { |
|
353 | - if (strpos($message["type"], '/alternative')) { |
|
352 | + if (!empty($message[ "parts" ]) && stripos($message[ "type" ], 'multipart/') !== false) { |
|
353 | + if (strpos($message[ "type" ], '/alternative')) { |
|
354 | 354 | $nestingLevel = \Swift_Mime_SimpleMimeEntity::LEVEL_ALTERNATIVE; |
355 | - } elseif (strpos($message["type"], '/related')) { |
|
355 | + } elseif (strpos($message[ "type" ], '/related')) { |
|
356 | 356 | $nestingLevel = \Swift_Mime_SimpleMimeEntity::LEVEL_RELATED; |
357 | - } elseif (strpos($message["type"], '/mixed')) { |
|
357 | + } elseif (strpos($message[ "type" ], '/mixed')) { |
|
358 | 358 | $nestingLevel = \Swift_Mime_SimpleMimeEntity::LEVEL_MIXED; |
359 | 359 | } else { |
360 | 360 | $nestingLevel = \Swift_Mime_SimpleMimeEntity::LEVEL_TOP; |
361 | 361 | } |
362 | 362 | |
363 | - $childs = []; |
|
364 | - foreach ($message["parts"] as $part) { |
|
365 | - $headers = $this->createHeadersSet($part["headers"]); |
|
366 | - $encoder = $this->getEncoder($this->getTransferEncoding($part["headers"])); |
|
363 | + $childs = [ ]; |
|
364 | + foreach ($message[ "parts" ] as $part) { |
|
365 | + $headers = $this->createHeadersSet($part[ "headers" ]); |
|
366 | + $encoder = $this->getEncoder($this->getTransferEncoding($part[ "headers" ])); |
|
367 | 367 | |
368 | - if (stripos($part["type"], 'multipart/') !== false) { |
|
369 | - $newEntity = new \Swift_Mime_MimePart ($headers, $encoder, $this->getCache(), $this->getIdGenertor()); |
|
368 | + if (stripos($part[ "type" ], 'multipart/') !== false) { |
|
369 | + $newEntity = new \Swift_Mime_MimePart($headers, $encoder, $this->getCache(), $this->getIdGenertor()); |
|
370 | 370 | } else { |
371 | - $newEntity = new \Swift_Mime_SimpleMimeEntity ($headers, $encoder, $this->getCache(), $this->getIdGenertor()); |
|
371 | + $newEntity = new \Swift_Mime_SimpleMimeEntity($headers, $encoder, $this->getCache(), $this->getIdGenertor()); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | $this->createMessage($part, $newEntity); |
375 | 375 | |
376 | - $ref = new \ReflectionObject ($newEntity); |
|
376 | + $ref = new \ReflectionObject($newEntity); |
|
377 | 377 | $m = $ref->getMethod('setNestingLevel'); |
378 | 378 | $m->setAccessible(true); |
379 | 379 | $m->invoke($newEntity, $nestingLevel); |
380 | 380 | |
381 | - $childs[] = $newEntity; |
|
381 | + $childs[ ] = $newEntity; |
|
382 | 382 | } |
383 | 383 | |
384 | - $entity->setContentType($part["type"]); |
|
384 | + $entity->setContentType($part[ "type" ]); |
|
385 | 385 | $entity->setChildren($childs); |
386 | 386 | } else { |
387 | - $entity->setBody($message["body"], $message["type"]); |
|
387 | + $entity->setBody($message[ "body" ], $message[ "type" ]); |
|
388 | 388 | } |
389 | 389 | } |
390 | 390 |