@@ -141,6 +141,9 @@ |
||
| 141 | 141 | return $headers; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | + /** |
|
| 145 | + * @param resource $stream |
|
| 146 | + */ |
|
| 144 | 147 | protected function parseParts($stream, array $partHeaders): array |
| 145 | 148 | { |
| 146 | 149 | $parts = array(); |
@@ -30,8 +30,8 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | public function __construct(array $allowedHeaders = array(), array $removeHeaders = array()) |
| 32 | 32 | { |
| 33 | - $this->contentDecoder = new ContentDecoder (); |
|
| 34 | - $this->headerDecoder = new HeaderDecoder (); |
|
| 33 | + $this->contentDecoder = new ContentDecoder(); |
|
| 34 | + $this->headerDecoder = new HeaderDecoder(); |
|
| 35 | 35 | |
| 36 | 36 | $this->allowedHeaders = array_merge($this->allowedHeaders, $allowedHeaders); |
| 37 | 37 | $this->removeHeaders = array_merge($this->removeHeaders, $removeHeaders); |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $parts = $this->parseParts($stream, $partHeaders); |
| 91 | 91 | |
| 92 | 92 | if (!$message) { |
| 93 | - $message = new \Swift_Message (); |
|
| 93 | + $message = new \Swift_Message(); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | $headers = $this->createHeadersSet($filteredHeaders); |
@@ -115,19 +115,19 @@ discard block |
||
| 115 | 115 | break; |
| 116 | 116 | } |
| 117 | 117 | if (preg_match('/^([a-z0-9\-]+)\s*:(.*)/i', $row, $mch)) { |
| 118 | - $hName = strtolower($mch [1]); |
|
| 118 | + $hName = strtolower($mch [ 1 ]); |
|
| 119 | 119 | if (!in_array($hName, array("content-type", "content-transfer-encoding"))) { |
| 120 | - $hName = $mch [1]; |
|
| 120 | + $hName = $mch [ 1 ]; |
|
| 121 | 121 | } |
| 122 | - $row = $mch [2]; |
|
| 122 | + $row = $mch [ 2 ]; |
|
| 123 | 123 | } |
| 124 | 124 | if (empty($hName)) { |
| 125 | 125 | continue; |
| 126 | 126 | } |
| 127 | - $headers [$hName] [] = trim($row); |
|
| 127 | + $headers [ $hName ] [ ] = trim($row); |
|
| 128 | 128 | } |
| 129 | 129 | foreach ($headers as $header => $values) { |
| 130 | - $headers [$header] = $this->headerDecoder->decode(trim(implode(" ", $values))); |
|
| 130 | + $headers [ $header ] = $this->headerDecoder->decode(trim(implode(" ", $values))); |
|
| 131 | 131 | } |
| 132 | 132 | return $headers; |
| 133 | 133 | } |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | { |
| 137 | 137 | foreach ($headers as $header => $values) { |
| 138 | 138 | if (in_array(strtolower($header), $this->removeHeaders) && !in_array(strtolower($header), $this->allowedHeaders)) { |
| 139 | - unset ($headers [$header]); |
|
| 139 | + unset ($headers [ $header ]); |
|
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | return $headers; |
@@ -150,10 +150,10 @@ discard block |
||
| 150 | 150 | $boundary = null; |
| 151 | 151 | if (stripos($contentType, 'multipart/') !== false) { |
| 152 | 152 | $headerParts = $this->extractHeaderParts($this->getContentType($partHeaders)); |
| 153 | - if (empty($headerParts["boundary"])) { |
|
| 153 | + if (empty($headerParts[ "boundary" ])) { |
|
| 154 | 154 | throw new InvalidMessageFormatException("The Content-Type header is not well formed, boundary is missing"); |
| 155 | 155 | } |
| 156 | - $boundary = $headerParts["boundary"]; |
|
| 156 | + $boundary = $headerParts[ "boundary" ]; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | try { |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | $childContentType = $this->extractValueHeader($this->getContentType($partHeaders)); |
| 178 | 178 | |
| 179 | 179 | if (stripos($childContentType, 'multipart/') !== false) { |
| 180 | - $parts["parts"][] = $this->parseParts($stream, $partHeaders); |
|
| 180 | + $parts[ "parts" ][ ] = $this->parseParts($stream, $partHeaders); |
|
| 181 | 181 | try { |
| 182 | 182 | $this->extractPart($stream, $boundary, $this->getTransferEncoding($partHeaders)); |
| 183 | 183 | } catch (Exception\EndOfPartReachedException $e) { |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | $this->extractPart($stream, $boundary, $this->getTransferEncoding($partHeaders)); |
| 187 | 187 | } |
| 188 | 188 | } catch (Exception\EndOfPartReachedException $e) { |
| 189 | - $parts["parts"][] = array( |
|
| 189 | + $parts[ "parts" ][ ] = array( |
|
| 190 | 190 | "type" => $childContentType, |
| 191 | 191 | "parent-type" => $contentType, |
| 192 | 192 | "headers" => $partHeaders, |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | private function getContentType(array $partHeaders): string |
| 217 | 217 | { |
| 218 | 218 | if (array_key_exists('content-type', $partHeaders)) { |
| 219 | - return $partHeaders['content-type']; |
|
| 219 | + return $partHeaders[ 'content-type' ]; |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | return ''; |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | continue; |
| 235 | 235 | } |
| 236 | 236 | list ($k, $v) = explode("=", trim($pv), 2); |
| 237 | - $p [$k] = trim($v, '"'); |
|
| 237 | + $p [ $k ] = trim($v, '"'); |
|
| 238 | 238 | } |
| 239 | 239 | return $p; |
| 240 | 240 | } else { |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | throw new Exception\EndOfPartReachedException($this->contentDecoder->decode(implode("", $rows), $encoding)); |
| 261 | 261 | } |
| 262 | 262 | } |
| 263 | - $rows [] = $row; |
|
| 263 | + $rows [ ] = $row; |
|
| 264 | 264 | } |
| 265 | 265 | throw new Exception\EndOfMultiPartReachedException($this->contentDecoder->decode(implode("", $rows), $encoding)); |
| 266 | 266 | } |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | private function getTransferEncoding(array $partHeaders): string |
| 269 | 269 | { |
| 270 | 270 | if (array_key_exists('content-transfer-encoding', $partHeaders)) { |
| 271 | - return $partHeaders ['content-transfer-encoding']; |
|
| 271 | + return $partHeaders [ 'content-transfer-encoding' ]; |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | return ''; |
@@ -282,13 +282,13 @@ discard block |
||
| 282 | 282 | switch (strtolower($name)) { |
| 283 | 283 | case "content-type": |
| 284 | 284 | $parts = $this->extractHeaderParts($value); |
| 285 | - unset ($parts ["boundary"]); |
|
| 285 | + unset ($parts [ "boundary" ]); |
|
| 286 | 286 | $headers->addParameterizedHeader($name, $this->extractValueHeader($value), $parts); |
| 287 | 287 | break; |
| 288 | 288 | case "return-path": |
| 289 | 289 | if (preg_match_all('/([a-z][a-z0-9_\-\.]*@[a-z0-9\.\-]*\.[a-z]{2,5})/i', $value, $mch)) { |
| 290 | - foreach ($mch [0] as $k => $mails) { |
|
| 291 | - $headers->addPathHeader($name, $mch [1] [$k]); |
|
| 290 | + foreach ($mch [ 0 ] as $k => $mails) { |
|
| 291 | + $headers->addPathHeader($name, $mch [ 1 ] [ $k ]); |
|
| 292 | 292 | } |
| 293 | 293 | } |
| 294 | 294 | break; |
@@ -302,16 +302,16 @@ discard block |
||
| 302 | 302 | case "cc": |
| 303 | 303 | $adresses = array(); |
| 304 | 304 | if (preg_match_all('/(.*?)<([a-z][a-z0-9_\-\.]*@[a-z0-9\.\-]*\.[a-z]{2,5})>\s*[;,]*/i', $value, $mch)) { |
| 305 | - foreach ($mch [0] as $k => $mail) { |
|
| 306 | - if (!$mch [1] [$k]) { |
|
| 307 | - $adresses [$mch [2] [$k]] = trim($mch [2] [$k]); |
|
| 305 | + foreach ($mch [ 0 ] as $k => $mail) { |
|
| 306 | + if (!$mch [ 1 ] [ $k ]) { |
|
| 307 | + $adresses [ $mch [ 2 ] [ $k ] ] = trim($mch [ 2 ] [ $k ]); |
|
| 308 | 308 | } else { |
| 309 | - $adresses [$mch [2] [$k]] = trim($mch [1] [$k]); |
|
| 309 | + $adresses [ $mch [ 2 ] [ $k ] ] = trim($mch [ 1 ] [ $k ]); |
|
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | 312 | } elseif (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 | - $adresses [$mch [1] [$k]] = trim($mch [1] [$k]); |
|
| 313 | + foreach ($mch [ 0 ] as $k => $mails) { |
|
| 314 | + $adresses [ $mch [ 1 ] [ $k ] ] = trim($mch [ 1 ] [ $k ]); |
|
| 315 | 315 | } |
| 316 | 316 | } |
| 317 | 317 | $headers->addMailboxHeader($name, $adresses); |
@@ -326,43 +326,43 @@ discard block |
||
| 326 | 326 | |
| 327 | 327 | protected function createMessage(array $message, \Swift_Mime_SimpleMimeEntity $entity): void |
| 328 | 328 | { |
| 329 | - if (stripos($message["type"], 'multipart/') !== false) { |
|
| 329 | + if (stripos($message[ "type" ], 'multipart/') !== false) { |
|
| 330 | 330 | |
| 331 | - if (strpos($message["type"], '/alternative')) { |
|
| 332 | - } elseif (strpos($message["type"], '/related')) { |
|
| 331 | + if (strpos($message[ "type" ], '/alternative')) { |
|
| 332 | + } elseif (strpos($message[ "type" ], '/related')) { |
|
| 333 | 333 | $nestingLevel = \Swift_Mime_SimpleMimeEntity::LEVEL_RELATED; |
| 334 | - } elseif (strpos($message["type"], '/mixed')) { |
|
| 334 | + } elseif (strpos($message[ "type" ], '/mixed')) { |
|
| 335 | 335 | $nestingLevel = \Swift_Mime_SimpleMimeEntity::LEVEL_MIXED; |
| 336 | 336 | } else { |
| 337 | 337 | $nestingLevel = \Swift_Mime_SimpleMimeEntity::LEVEL_TOP; |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | $childs = array(); |
| 341 | - foreach ($message ["parts"] as $part) { |
|
| 341 | + foreach ($message [ "parts" ] as $part) { |
|
| 342 | 342 | |
| 343 | - $headers = $this->createHeadersSet($part["headers"]); |
|
| 344 | - $encoder = $this->getEncoder($this->getTransferEncoding($part["headers"])); |
|
| 343 | + $headers = $this->createHeadersSet($part[ "headers" ]); |
|
| 344 | + $encoder = $this->getEncoder($this->getTransferEncoding($part[ "headers" ])); |
|
| 345 | 345 | |
| 346 | - if (stripos($part["type"], 'multipart/') !== false) { |
|
| 347 | - $newEntity = new \Swift_Mime_MimePart ($headers, $encoder, $this->getCache(), $this->getIdGenertor()); |
|
| 346 | + if (stripos($part[ "type" ], 'multipart/') !== false) { |
|
| 347 | + $newEntity = new \Swift_Mime_MimePart($headers, $encoder, $this->getCache(), $this->getIdGenertor()); |
|
| 348 | 348 | } else { |
| 349 | - $newEntity = new \Swift_Mime_SimpleMimeEntity ($headers, $encoder, $this->getCache(), $this->getIdGenertor()); |
|
| 349 | + $newEntity = new \Swift_Mime_SimpleMimeEntity($headers, $encoder, $this->getCache(), $this->getIdGenertor()); |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | $this->createMessage($part, $newEntity); |
| 353 | 353 | |
| 354 | - $ref = new \ReflectionObject ($newEntity); |
|
| 354 | + $ref = new \ReflectionObject($newEntity); |
|
| 355 | 355 | $m = $ref->getMethod('setNestingLevel'); |
| 356 | 356 | $m->setAccessible(true); |
| 357 | 357 | $m->invoke($newEntity, $nestingLevel); |
| 358 | 358 | |
| 359 | - $childs [] = $newEntity; |
|
| 359 | + $childs [ ] = $newEntity; |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - $entity->setContentType($part["type"]); |
|
| 362 | + $entity->setContentType($part[ "type" ]); |
|
| 363 | 363 | $entity->setChildren($childs); |
| 364 | 364 | } else { |
| 365 | - $entity->setBody($message ["body"], $message["type"]); |
|
| 365 | + $entity->setBody($message [ "body" ], $message[ "type" ]); |
|
| 366 | 366 | } |
| 367 | 367 | } |
| 368 | 368 | |
@@ -50,8 +50,8 @@ |
||
| 50 | 50 | switch ($encoding) { |
| 51 | 51 | case 'Q': |
| 52 | 52 | case 'q': |
| 53 | - $out .= self::convertCharset(preg_replace_callback('/=([0-9a-f]{2})/i', function ($ord) { |
|
| 54 | - return chr(hexdec($ord [1])); |
|
| 53 | + $out .= self::convertCharset(preg_replace_callback('/=([0-9a-f]{2})/i', function($ord) { |
|
| 54 | + return chr(hexdec($ord [ 1 ])); |
|
| 55 | 55 | }, str_replace('_', ' ', $encoded_text)), $orig_charset, mb_internal_encoding()); |
| 56 | 56 | break; |
| 57 | 57 | |