@@ -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(); |
@@ -29,8 +29,8 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | public function __construct(array $allowedHeaders = array(), array $removeHeaders = array()) |
| 31 | 31 | { |
| 32 | - $this->contentDecoder = new ContentDecoder (); |
|
| 33 | - $this->headerDecoder = new HeaderDecoder (); |
|
| 32 | + $this->contentDecoder = new ContentDecoder(); |
|
| 33 | + $this->headerDecoder = new HeaderDecoder(); |
|
| 34 | 34 | |
| 35 | 35 | $this->allowedHeaders = array_merge($this->allowedHeaders, $allowedHeaders); |
| 36 | 36 | $this->removeHeaders = array_merge($this->removeHeaders, $removeHeaders); |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | $parts = $this->parseParts($stream, $partHeaders); |
| 90 | 90 | |
| 91 | 91 | if (!$message) { |
| 92 | - $message = new \Swift_Message (); |
|
| 92 | + $message = new \Swift_Message(); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | $headers = $this->createHeadersSet($filteredHeaders); |
@@ -114,19 +114,19 @@ discard block |
||
| 114 | 114 | break; |
| 115 | 115 | } |
| 116 | 116 | if (preg_match('/^([a-z0-9\-]+)\s*:(.*)/i', $row, $mch)) { |
| 117 | - $hName = strtolower($mch [1]); |
|
| 117 | + $hName = strtolower($mch [ 1 ]); |
|
| 118 | 118 | if (!in_array($hName, array("content-type", "content-transfer-encoding"))) { |
| 119 | - $hName = $mch [1]; |
|
| 119 | + $hName = $mch [ 1 ]; |
|
| 120 | 120 | } |
| 121 | - $row = $mch [2]; |
|
| 121 | + $row = $mch [ 2 ]; |
|
| 122 | 122 | } |
| 123 | 123 | if (empty($hName)) { |
| 124 | 124 | continue; |
| 125 | 125 | } |
| 126 | - $headers [$hName] [] = trim($row); |
|
| 126 | + $headers [ $hName ] [ ] = trim($row); |
|
| 127 | 127 | } |
| 128 | 128 | foreach ($headers as $header => $values) { |
| 129 | - $headers [$header] = $this->headerDecoder->decode(trim(implode(" ", $values))); |
|
| 129 | + $headers [ $header ] = $this->headerDecoder->decode(trim(implode(" ", $values))); |
|
| 130 | 130 | } |
| 131 | 131 | return $headers; |
| 132 | 132 | } |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | { |
| 136 | 136 | foreach ($headers as $header => $values) { |
| 137 | 137 | if (in_array(strtolower($header), $this->removeHeaders) && !in_array(strtolower($header), $this->allowedHeaders)) { |
| 138 | - unset ($headers [$header]); |
|
| 138 | + unset ($headers [ $header ]); |
|
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | return $headers; |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | |
| 149 | 149 | if (stripos($contentType, 'multipart/') !== false) { |
| 150 | 150 | $headerParts = $this->extractHeaderParts($this->getContentType($partHeaders)); |
| 151 | - $boundary = $headerParts ["boundary"]; |
|
| 151 | + $boundary = $headerParts [ "boundary" ]; |
|
| 152 | 152 | } else { |
| 153 | 153 | $boundary = null; |
| 154 | 154 | } |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | $childContentType = $this->extractValueHeader($this->getContentType($partHeaders)); |
| 174 | 174 | |
| 175 | 175 | if (stripos($childContentType, 'multipart/') !== false) { |
| 176 | - $parts ["parts"] [] = $this->parseParts($stream, $partHeaders); |
|
| 176 | + $parts [ "parts" ] [ ] = $this->parseParts($stream, $partHeaders); |
|
| 177 | 177 | try { |
| 178 | 178 | $this->extractPart($stream, $boundary, $this->getTransferEncoding($partHeaders)); |
| 179 | 179 | } catch (Exception\EndOfPartReachedException $e) { |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | $this->extractPart($stream, $boundary, $this->getTransferEncoding($partHeaders)); |
| 183 | 183 | } |
| 184 | 184 | } catch (Exception\EndOfPartReachedException $e) { |
| 185 | - $parts ["parts"] [] = array( |
|
| 185 | + $parts [ "parts" ] [ ] = array( |
|
| 186 | 186 | "type" => $childContentType, |
| 187 | 187 | "parent-type" => $contentType, |
| 188 | 188 | "headers" => $partHeaders, |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | private function getContentType(array $partHeaders): string |
| 213 | 213 | { |
| 214 | 214 | if (array_key_exists('content-type', $partHeaders)) { |
| 215 | - return $partHeaders['content-type']; |
|
| 215 | + return $partHeaders[ 'content-type' ]; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | return ''; |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | continue; |
| 231 | 231 | } |
| 232 | 232 | list ($k, $v) = explode("=", trim($pv), 2); |
| 233 | - $p [$k] = trim($v, '"'); |
|
| 233 | + $p [ $k ] = trim($v, '"'); |
|
| 234 | 234 | } |
| 235 | 235 | return $p; |
| 236 | 236 | } else { |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | throw new Exception\EndOfPartReachedException($this->contentDecoder->decode(implode("", $rows), $encoding)); |
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | - $rows [] = $row; |
|
| 259 | + $rows [ ] = $row; |
|
| 260 | 260 | } |
| 261 | 261 | throw new Exception\EndOfMultiPartReachedException($this->contentDecoder->decode(implode("", $rows), $encoding)); |
| 262 | 262 | } |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | private function getTransferEncoding(array $partHeaders): string |
| 265 | 265 | { |
| 266 | 266 | if (array_key_exists('content-transfer-encoding', $partHeaders)) { |
| 267 | - return $partHeaders ['content-transfer-encoding']; |
|
| 267 | + return $partHeaders [ 'content-transfer-encoding' ]; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | return ''; |
@@ -278,13 +278,13 @@ discard block |
||
| 278 | 278 | switch (strtolower($name)) { |
| 279 | 279 | case "content-type": |
| 280 | 280 | $parts = $this->extractHeaderParts($value); |
| 281 | - unset ($parts ["boundary"]); |
|
| 281 | + unset ($parts [ "boundary" ]); |
|
| 282 | 282 | $headers->addParameterizedHeader($name, $this->extractValueHeader($value), $parts); |
| 283 | 283 | break; |
| 284 | 284 | case "return-path": |
| 285 | 285 | if (preg_match_all('/([a-z][a-z0-9_\-\.]*@[a-z0-9\.\-]*\.[a-z]{2,5})/i', $value, $mch)) { |
| 286 | - foreach ($mch [0] as $k => $mails) { |
|
| 287 | - $headers->addPathHeader($name, $mch [1] [$k]); |
|
| 286 | + foreach ($mch [ 0 ] as $k => $mails) { |
|
| 287 | + $headers->addPathHeader($name, $mch [ 1 ] [ $k ]); |
|
| 288 | 288 | } |
| 289 | 289 | } |
| 290 | 290 | break; |
@@ -298,16 +298,16 @@ discard block |
||
| 298 | 298 | case "cc": |
| 299 | 299 | $adresses = array(); |
| 300 | 300 | if (preg_match_all('/(.*?)<([a-z][a-z0-9_\-\.]*@[a-z0-9\.\-]*\.[a-z]{2,5})>\s*[;,]*/i', $value, $mch)) { |
| 301 | - foreach ($mch [0] as $k => $mail) { |
|
| 302 | - if (!$mch [1] [$k]) { |
|
| 303 | - $adresses [$mch [2] [$k]] = trim($mch [2] [$k]); |
|
| 301 | + foreach ($mch [ 0 ] as $k => $mail) { |
|
| 302 | + if (!$mch [ 1 ] [ $k ]) { |
|
| 303 | + $adresses [ $mch [ 2 ] [ $k ] ] = trim($mch [ 2 ] [ $k ]); |
|
| 304 | 304 | } else { |
| 305 | - $adresses [$mch [2] [$k]] = trim($mch [1] [$k]); |
|
| 305 | + $adresses [ $mch [ 2 ] [ $k ] ] = trim($mch [ 1 ] [ $k ]); |
|
| 306 | 306 | } |
| 307 | 307 | } |
| 308 | 308 | } elseif (preg_match_all('/([a-z][a-z0-9_\-\.]*@[a-z0-9\.\-]*\.[a-z]{2,5})/i', $value, $mch)) { |
| 309 | - foreach ($mch [0] as $k => $mails) { |
|
| 310 | - $adresses [$mch [1] [$k]] = trim($mch [1] [$k]); |
|
| 309 | + foreach ($mch [ 0 ] as $k => $mails) { |
|
| 310 | + $adresses [ $mch [ 1 ] [ $k ] ] = trim($mch [ 1 ] [ $k ]); |
|
| 311 | 311 | } |
| 312 | 312 | } |
| 313 | 313 | $headers->addMailboxHeader($name, $adresses); |
@@ -322,42 +322,42 @@ discard block |
||
| 322 | 322 | |
| 323 | 323 | protected function createMessage(array $message, \Swift_Mime_SimpleMimeEntity $entity): void |
| 324 | 324 | { |
| 325 | - if (stripos($message ["type"], 'multipart/') !== false) { |
|
| 325 | + if (stripos($message [ "type" ], 'multipart/') !== false) { |
|
| 326 | 326 | $nestingLevel = \Swift_Mime_SimpleMimeEntity::LEVEL_TOP; |
| 327 | - if (strpos($message ["type"], '/alternative')) { |
|
| 327 | + if (strpos($message [ "type" ], '/alternative')) { |
|
| 328 | 328 | $nestingLevel = \Swift_Mime_SimpleMimeEntity::LEVEL_ALTERNATIVE; |
| 329 | - } elseif (strpos($message ["type"], '/related')) { |
|
| 329 | + } elseif (strpos($message [ "type" ], '/related')) { |
|
| 330 | 330 | $nestingLevel = \Swift_Mime_SimpleMimeEntity::LEVEL_RELATED; |
| 331 | - } elseif (strpos($message ["type"], '/mixed')) { |
|
| 331 | + } elseif (strpos($message [ "type" ], '/mixed')) { |
|
| 332 | 332 | $nestingLevel = \Swift_Mime_SimpleMimeEntity::LEVEL_MIXED; |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | $childs = array(); |
| 336 | - foreach ($message ["parts"] as $part) { |
|
| 336 | + foreach ($message [ "parts" ] as $part) { |
|
| 337 | 337 | |
| 338 | - $headers = $this->createHeadersSet($part["headers"]); |
|
| 339 | - $encoder = $this->getEncoder($this->getTransferEncoding($part["headers"])); |
|
| 338 | + $headers = $this->createHeadersSet($part[ "headers" ]); |
|
| 339 | + $encoder = $this->getEncoder($this->getTransferEncoding($part[ "headers" ])); |
|
| 340 | 340 | |
| 341 | - if (stripos($part["type"], 'multipart/') !== false) { |
|
| 342 | - $newEntity = new \Swift_Mime_MimePart ($headers, $encoder, $this->getCache(), $this->getIdGenertor()); |
|
| 341 | + if (stripos($part[ "type" ], 'multipart/') !== false) { |
|
| 342 | + $newEntity = new \Swift_Mime_MimePart($headers, $encoder, $this->getCache(), $this->getIdGenertor()); |
|
| 343 | 343 | } else { |
| 344 | - $newEntity = new \Swift_Mime_SimpleMimeEntity ($headers, $encoder, $this->getCache(), $this->getIdGenertor()); |
|
| 344 | + $newEntity = new \Swift_Mime_SimpleMimeEntity($headers, $encoder, $this->getCache(), $this->getIdGenertor()); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | $this->createMessage($part, $newEntity); |
| 348 | 348 | |
| 349 | - $ref = new \ReflectionObject ($newEntity); |
|
| 349 | + $ref = new \ReflectionObject($newEntity); |
|
| 350 | 350 | $m = $ref->getMethod('setNestingLevel'); |
| 351 | 351 | $m->setAccessible(true); |
| 352 | 352 | $m->invoke($newEntity, $nestingLevel); |
| 353 | 353 | |
| 354 | - $childs [] = $newEntity; |
|
| 354 | + $childs [ ] = $newEntity; |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - $entity->setContentType($part["type"]); |
|
| 357 | + $entity->setContentType($part[ "type" ]); |
|
| 358 | 358 | $entity->setChildren($childs); |
| 359 | 359 | } else { |
| 360 | - $entity->setBody($message ["body"], $message ["type"]); |
|
| 360 | + $entity->setBody($message [ "body" ], $message [ "type" ]); |
|
| 361 | 361 | } |
| 362 | 362 | } |
| 363 | 363 | |
@@ -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, 'UTF-8'); |
| 56 | 56 | break; |
| 57 | 57 | |