@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * |
| 45 | - * @param stream $stream |
|
| 45 | + * @param resource $stream |
|
| 46 | 46 | * @param boolean $fillHeaders (default to false) |
| 47 | 47 | * @param \Swift_Mime_SimpleMimeEntity $message (default to null) |
| 48 | - * @return Swift_Mime_SimpleMimeEntity|\Swift_Message |
|
| 48 | + * @return \Swift_Mime_SimpleMimeEntity |
|
| 49 | 49 | */ |
| 50 | 50 | public function parseStream($stream, $fillHeaders = false, \Swift_Mime_SimpleMimeEntity $message = null) |
| 51 | 51 | { |
@@ -166,6 +166,9 @@ discard block |
||
| 166 | 166 | return $parts; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | + /** |
|
| 170 | + * @return string |
|
| 171 | + */ |
|
| 169 | 172 | private function extractValueHeader($header) |
| 170 | 173 | { |
| 171 | 174 | $pos = stripos($header, ';'); |
@@ -3,7 +3,6 @@ |
||
| 3 | 3 | namespace Goetas\Mail\ToSwiftMailParser; |
| 4 | 4 | |
| 5 | 5 | use Goetas\Mail\ToSwiftMailParser\Mime\ContentDecoder; |
| 6 | -use Goetas\Mail\ToSwiftMailParser\Mime\Grammar; |
|
| 7 | 6 | use Goetas\Mail\ToSwiftMailParser\Mime\HeaderDecoder; |
| 8 | 7 | |
| 9 | 8 | class MimeParser |
@@ -23,8 +23,8 @@ discard block |
||
| 23 | 23 | $swiftContainer = \Swift_DependencyContainer::getInstance(); |
| 24 | 24 | $this->cache = $swiftContainer->lookup(static::SWIFT_CONTAINER_CACHE_KEY); |
| 25 | 25 | $this->idGenerator = $swiftContainer->lookup(static::SWIFT_CONTAINER_ID_GENERATOR_KEY); |
| 26 | - $this->contentDecoder = new ContentDecoder (); |
|
| 27 | - $this->headerDecoder = new HeaderDecoder (); |
|
| 26 | + $this->contentDecoder = new ContentDecoder(); |
|
| 27 | + $this->headerDecoder = new HeaderDecoder(); |
|
| 28 | 28 | |
| 29 | 29 | $this->allowedHeaders = array_merge($this->allowedHeaders, $allowedHeaders); |
| 30 | 30 | $this->removeHeaders = array_merge($this->removeHeaders, $removeHeaders); |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | $parts = $this->parseParts($stream, $partHeaders); |
| 57 | 57 | |
| 58 | 58 | if (!$message) { |
| 59 | - $message = new \Swift_Message (); |
|
| 59 | + $message = new \Swift_Message(); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | $headers = $this->createHeadersSet($filteredHeaders); |
@@ -81,19 +81,19 @@ discard block |
||
| 81 | 81 | break; |
| 82 | 82 | } |
| 83 | 83 | if (preg_match('/^([a-z0-9\-]+)\s*:(.*)/i', $row, $mch)) { |
| 84 | - $hName = strtolower($mch [1]); |
|
| 84 | + $hName = strtolower($mch [ 1 ]); |
|
| 85 | 85 | if (!in_array($hName, array("content-type", "content-transfer-encoding"))) { |
| 86 | - $hName = $mch [1]; |
|
| 86 | + $hName = $mch [ 1 ]; |
|
| 87 | 87 | } |
| 88 | - $row = $mch [2]; |
|
| 88 | + $row = $mch [ 2 ]; |
|
| 89 | 89 | } |
| 90 | 90 | if (empty($hName)) { |
| 91 | 91 | continue; |
| 92 | 92 | } |
| 93 | - $headers [$hName] [] = trim($row); |
|
| 93 | + $headers [ $hName ] [ ] = trim($row); |
|
| 94 | 94 | } |
| 95 | 95 | foreach ($headers as $header => $values) { |
| 96 | - $headers [$header] = $this->headerDecoder->decode(trim(implode(" ", $values))); |
|
| 96 | + $headers [ $header ] = $this->headerDecoder->decode(trim(implode(" ", $values))); |
|
| 97 | 97 | } |
| 98 | 98 | return $headers; |
| 99 | 99 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | { |
| 103 | 103 | foreach ($headers as $header => $values) { |
| 104 | 104 | if (in_array(strtolower($header), $this->removeHeaders) && !in_array(strtolower($header), $this->allowedHeaders)) { |
| 105 | - unset ($headers [$header]); |
|
| 105 | + unset ($headers [ $header ]); |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | return $headers; |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | if (stripos($contentType, 'multipart/') !== false) { |
| 117 | 117 | $headerParts = $this->extractHeaderParts($this->getContentType($partHeaders)); |
| 118 | - $boundary = $headerParts ["boundary"]; |
|
| 118 | + $boundary = $headerParts [ "boundary" ]; |
|
| 119 | 119 | } else { |
| 120 | 120 | $boundary = null; |
| 121 | 121 | } |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | $childContentType = $this->extractValueHeader($this->getContentType($partHeaders)); |
| 141 | 141 | |
| 142 | 142 | if (stripos($childContentType, 'multipart/') !== false) { |
| 143 | - $parts ["parts"] [] = $this->parseParts($stream, $partHeaders); |
|
| 143 | + $parts [ "parts" ] [ ] = $this->parseParts($stream, $partHeaders); |
|
| 144 | 144 | try { |
| 145 | 145 | $this->extractPart($stream, $boundary, $this->getTransferEncoding($partHeaders)); |
| 146 | 146 | } catch (Exception\EndOfPartReachedException $e) { |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | $this->extractPart($stream, $boundary, $this->getTransferEncoding($partHeaders)); |
| 150 | 150 | } |
| 151 | 151 | } catch (Exception\EndOfPartReachedException $e) { |
| 152 | - $parts ["parts"] [] = array( |
|
| 152 | + $parts [ "parts" ] [ ] = array( |
|
| 153 | 153 | "type" => $childContentType, |
| 154 | 154 | "parent-type" => $contentType, |
| 155 | 155 | "headers" => $partHeaders, |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | private function getContentType(array $partHeaders) |
| 180 | 180 | { |
| 181 | 181 | if (array_key_exists('content-type', $partHeaders)) { |
| 182 | - return $partHeaders['content-type']; |
|
| 182 | + return $partHeaders[ 'content-type' ]; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | return ''; |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | continue; |
| 198 | 198 | } |
| 199 | 199 | list ($k, $v) = explode("=", trim($pv), 2); |
| 200 | - $p [$k] = trim($v, '"'); |
|
| 200 | + $p [ $k ] = trim($v, '"'); |
|
| 201 | 201 | } |
| 202 | 202 | return $p; |
| 203 | 203 | } else { |
@@ -212,21 +212,21 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | if ($boundary !== null) { |
| 214 | 214 | if (strpos($row, "--$boundary--") === 0) { |
| 215 | - throw new Exception\EndOfMultiPartReachedException ($this->contentDecoder->decode(implode("", $rows), $encoding)); |
|
| 215 | + throw new Exception\EndOfMultiPartReachedException($this->contentDecoder->decode(implode("", $rows), $encoding)); |
|
| 216 | 216 | } |
| 217 | 217 | if (strpos($row, "--$boundary") === 0) { |
| 218 | - throw new Exception\EndOfPartReachedException ($this->contentDecoder->decode(implode("", $rows), $encoding)); |
|
| 218 | + throw new Exception\EndOfPartReachedException($this->contentDecoder->decode(implode("", $rows), $encoding)); |
|
| 219 | 219 | } |
| 220 | 220 | } |
| 221 | - $rows [] = $row; |
|
| 221 | + $rows [ ] = $row; |
|
| 222 | 222 | } |
| 223 | - throw new Exception\EndOfMultiPartReachedException ($this->contentDecoder->decode(implode("", $rows), $encoding)); |
|
| 223 | + throw new Exception\EndOfMultiPartReachedException($this->contentDecoder->decode(implode("", $rows), $encoding)); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | private function getTransferEncoding(array $partHeaders) |
| 227 | 227 | { |
| 228 | 228 | if (array_key_exists('content-transfer-encoding', $partHeaders)) { |
| 229 | - return $partHeaders ['content-transfer-encoding']; |
|
| 229 | + return $partHeaders [ 'content-transfer-encoding' ]; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | return ''; |
@@ -245,13 +245,13 @@ discard block |
||
| 245 | 245 | switch (strtolower($name)) { |
| 246 | 246 | case "content-type": |
| 247 | 247 | $parts = $this->extractHeaderParts($value); |
| 248 | - unset ($parts ["boundary"]); |
|
| 248 | + unset ($parts [ "boundary" ]); |
|
| 249 | 249 | $headers->addParameterizedHeader($name, $this->extractValueHeader($value), $parts); |
| 250 | 250 | break; |
| 251 | 251 | case "return-path" : |
| 252 | 252 | if (preg_match_all('/([a-z][a-z0-9_\-\.]*@[a-z0-9\.\-]*\.[a-z]{2,5})/i', $value, $mch)) { |
| 253 | - foreach ($mch [0] as $k => $mails) { |
|
| 254 | - $headers->addPathHeader($name, $mch [1] [$k]); |
|
| 253 | + foreach ($mch [ 0 ] as $k => $mails) { |
|
| 254 | + $headers->addPathHeader($name, $mch [ 1 ] [ $k ]); |
|
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | 257 | break; |
@@ -265,16 +265,16 @@ discard block |
||
| 265 | 265 | case "cc": |
| 266 | 266 | $adresses = array(); |
| 267 | 267 | if (preg_match_all('/(.*?)<([a-z][a-z0-9_\-\.]*@[a-z0-9\.\-]*\.[a-z]{2,5})>\s*[;,]*/i', $value, $mch)) { |
| 268 | - foreach ($mch [0] as $k => $mail) { |
|
| 269 | - if (!$mch [1] [$k]) { |
|
| 270 | - $adresses [$mch [2] [$k]] = trim($mch [2] [$k]); |
|
| 268 | + foreach ($mch [ 0 ] as $k => $mail) { |
|
| 269 | + if (!$mch [ 1 ] [ $k ]) { |
|
| 270 | + $adresses [ $mch [ 2 ] [ $k ] ] = trim($mch [ 2 ] [ $k ]); |
|
| 271 | 271 | } else { |
| 272 | - $adresses [$mch [2] [$k]] = trim($mch [1] [$k]); |
|
| 272 | + $adresses [ $mch [ 2 ] [ $k ] ] = trim($mch [ 1 ] [ $k ]); |
|
| 273 | 273 | } |
| 274 | 274 | } |
| 275 | 275 | } elseif (preg_match_all('/([a-z][a-z0-9_\-\.]*@[a-z0-9\.\-]*\.[a-z]{2,5})/i', $value, $mch)) { |
| 276 | - foreach ($mch [0] as $k => $mails) { |
|
| 277 | - $adresses [$mch [1] [$k]] = trim($mch [1] [$k]); |
|
| 276 | + foreach ($mch [ 0 ] as $k => $mails) { |
|
| 277 | + $adresses [ $mch [ 1 ] [ $k ] ] = trim($mch [ 1 ] [ $k ]); |
|
| 278 | 278 | } |
| 279 | 279 | } |
| 280 | 280 | $headers->addMailboxHeader($name, $adresses); |
@@ -289,42 +289,42 @@ discard block |
||
| 289 | 289 | |
| 290 | 290 | protected function createMessage(array $message, \Swift_Mime_SimpleMimeEntity $entity) |
| 291 | 291 | { |
| 292 | - if (stripos($message ["type"], 'multipart/') !== false) { |
|
| 292 | + if (stripos($message [ "type" ], 'multipart/') !== false) { |
|
| 293 | 293 | |
| 294 | - if (strpos($message ["type"], '/alternative')) { |
|
| 294 | + if (strpos($message [ "type" ], '/alternative')) { |
|
| 295 | 295 | $nestingLevel = \Swift_Mime_SimpleMimeEntity::LEVEL_ALTERNATIVE; |
| 296 | - } elseif (strpos($message ["type"], '/related')) { |
|
| 296 | + } elseif (strpos($message [ "type" ], '/related')) { |
|
| 297 | 297 | $nestingLevel = \Swift_Mime_SimpleMimeEntity::LEVEL_RELATED; |
| 298 | - } elseif (strpos($message ["type"], '/mixed')) { |
|
| 298 | + } elseif (strpos($message [ "type" ], '/mixed')) { |
|
| 299 | 299 | $nestingLevel = \Swift_Mime_SimpleMimeEntity::LEVEL_MIXED; |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | $childrens = array(); |
| 303 | - foreach ($message ["parts"] as $part) { |
|
| 303 | + foreach ($message [ "parts" ] as $part) { |
|
| 304 | 304 | |
| 305 | - $headers = $this->createHeadersSet($part ["headers"]); |
|
| 306 | - $encoder = $this->getEncoder($this->getTransferEncoding($part ["headers"])); |
|
| 305 | + $headers = $this->createHeadersSet($part [ "headers" ]); |
|
| 306 | + $encoder = $this->getEncoder($this->getTransferEncoding($part [ "headers" ])); |
|
| 307 | 307 | |
| 308 | - if (stripos($part ["type"], 'multipart/') !== false) { |
|
| 309 | - $newEntity = new \Swift_Mime_MimePart ($headers, $encoder, $this->cache, $this->idGenerator); |
|
| 308 | + if (stripos($part [ "type" ], 'multipart/') !== false) { |
|
| 309 | + $newEntity = new \Swift_Mime_MimePart($headers, $encoder, $this->cache, $this->idGenerator); |
|
| 310 | 310 | } else { |
| 311 | - $newEntity = new \Swift_Mime_SimpleMimeEntity ($headers, $encoder, $this->cache, $this->idGenerator); |
|
| 311 | + $newEntity = new \Swift_Mime_SimpleMimeEntity($headers, $encoder, $this->cache, $this->idGenerator); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | $this->createMessage($part, $newEntity); |
| 315 | 315 | |
| 316 | - $ref = new \ReflectionObject ($newEntity); |
|
| 316 | + $ref = new \ReflectionObject($newEntity); |
|
| 317 | 317 | $m = $ref->getMethod('setNestingLevel'); |
| 318 | 318 | $m->setAccessible(true); |
| 319 | 319 | $m->invoke($newEntity, $nestingLevel); |
| 320 | 320 | |
| 321 | - $childrens [] = $newEntity; |
|
| 321 | + $childrens [ ] = $newEntity; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | - $entity->setContentType($part ["type"]); |
|
| 324 | + $entity->setContentType($part [ "type" ]); |
|
| 325 | 325 | $entity->setChildren($childrens); |
| 326 | 326 | } else { |
| 327 | - $entity->setBody($message ["body"], $message ["type"]); |
|
| 327 | + $entity->setBody($message [ "body" ], $message [ "type" ]); |
|
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | |