@@ -6,6 +6,9 @@ discard block |
||
| 6 | 6 | { |
| 7 | 7 | public static $decodeWindows1252 = false; |
| 8 | 8 | |
| 9 | + /** |
|
| 10 | + * @param string $string |
|
| 11 | + */ |
|
| 9 | 12 | public function decode($string) |
| 10 | 13 | { |
| 11 | 14 | /* Take out any spaces between multiple encoded words. */ |
@@ -66,6 +69,11 @@ discard block |
||
| 66 | 69 | return $out . substr($string, $old_pos); |
| 67 | 70 | } |
| 68 | 71 | |
| 72 | + /** |
|
| 73 | + * @param string $str |
|
| 74 | + * @param string $orig |
|
| 75 | + * @param string $to |
|
| 76 | + */ |
|
| 69 | 77 | public static function convertCharset($str, $orig, $to) |
| 70 | 78 | { |
| 71 | 79 | //@todo convert charset |
@@ -45,8 +45,8 @@ |
||
| 45 | 45 | switch ($encoding) { |
| 46 | 46 | case 'Q' : |
| 47 | 47 | case 'q' : |
| 48 | - $out .= self::convertCharset(preg_replace_callback('/=([0-9a-f]{2})/i', function ($ord) { |
|
| 49 | - return chr(hexdec($ord [1])); |
|
| 48 | + $out .= self::convertCharset(preg_replace_callback('/=([0-9a-f]{2})/i', function($ord) { |
|
| 49 | + return chr(hexdec($ord [ 1 ])); |
|
| 50 | 50 | }, str_replace('_', ' ', $encoded_text)), $orig_charset, 'UTF-8'); |
| 51 | 51 | break; |
| 52 | 52 | |
@@ -43,10 +43,10 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * |
| 46 | - * @param stream $stream |
|
| 46 | + * @param resource $stream |
|
| 47 | 47 | * @param boolean $fillHeaders (default to false) |
| 48 | 48 | * @param \Swift_Mime_MimeEntity $message (default to null) |
| 49 | - * @return Swift_Mime_MimeEntity|\Swift_Message |
|
| 49 | + * @return \Swift_Mime_MimeEntity |
|
| 50 | 50 | */ |
| 51 | 51 | public function parseStream($stream, $fillHeaders = false, \Swift_Mime_MimeEntity $message = null) |
| 52 | 52 | { |
@@ -167,6 +167,9 @@ discard block |
||
| 167 | 167 | return $parts; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | + /** |
|
| 171 | + * @return string |
|
| 172 | + */ |
|
| 170 | 173 | private function extractValueHeader($header) |
| 171 | 174 | { |
| 172 | 175 | $pos = stripos($header, ';'); |
@@ -18,8 +18,8 @@ discard block |
||
| 18 | 18 | { |
| 19 | 19 | $this->cache = \Swift_DependencyContainer::getInstance()->lookup('cache'); |
| 20 | 20 | $this->grammar = \Swift_DependencyContainer::getInstance()->lookup('mime.grammar'); |
| 21 | - $this->contentDecoder = new ContentDecoder (); |
|
| 22 | - $this->headerDecoder = new HeaderDecoder (); |
|
| 21 | + $this->contentDecoder = new ContentDecoder(); |
|
| 22 | + $this->headerDecoder = new HeaderDecoder(); |
|
| 23 | 23 | |
| 24 | 24 | $this->allowedHeaders = array_merge($this->allowedHeaders, $allowedHeaders); |
| 25 | 25 | $this->removeHeaders = array_merge($this->removeHeaders, $removeHeaders); |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | $parts = $this->parseParts($stream, $partHeaders); |
| 58 | 58 | |
| 59 | 59 | if (!$message) { |
| 60 | - $message = new \Swift_Message (); |
|
| 60 | + $message = new \Swift_Message(); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | $headers = $this->createHeadersSet($filteredHeaders); |
@@ -82,19 +82,19 @@ discard block |
||
| 82 | 82 | break; |
| 83 | 83 | } |
| 84 | 84 | if (preg_match('/^([a-z0-9\-]+)\s*:(.*)/i', $row, $mch)) { |
| 85 | - $hName = strtolower($mch [1]); |
|
| 85 | + $hName = strtolower($mch [ 1 ]); |
|
| 86 | 86 | if (!in_array($hName, array("content-type", "content-transfer-encoding"))) { |
| 87 | - $hName = $mch [1]; |
|
| 87 | + $hName = $mch [ 1 ]; |
|
| 88 | 88 | } |
| 89 | - $row = $mch [2]; |
|
| 89 | + $row = $mch [ 2 ]; |
|
| 90 | 90 | } |
| 91 | 91 | if (!$hName) { |
| 92 | 92 | continue; |
| 93 | 93 | } |
| 94 | - $headers [$hName] [] = trim($row); |
|
| 94 | + $headers [ $hName ] [ ] = trim($row); |
|
| 95 | 95 | } |
| 96 | 96 | foreach ($headers as $header => $values) { |
| 97 | - $headers [$header] = $this->headerDecoder->decode(trim(implode(" ", $values))); |
|
| 97 | + $headers [ $header ] = $this->headerDecoder->decode(trim(implode(" ", $values))); |
|
| 98 | 98 | } |
| 99 | 99 | return $headers; |
| 100 | 100 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | { |
| 104 | 104 | foreach ($headers as $header => $values) { |
| 105 | 105 | if (in_array(strtolower($header), $this->removeHeaders) && !in_array(strtolower($header), $this->allowedHeaders)) { |
| 106 | - unset ($headers [$header]); |
|
| 106 | + unset ($headers [ $header ]); |
|
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | return $headers; |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | if (stripos($contentType, 'multipart/') !== false) { |
| 118 | 118 | $headerParts = $this->extractHeaderParts($this->getContentType($partHeaders)); |
| 119 | - $boundary = $headerParts ["boundary"]; |
|
| 119 | + $boundary = $headerParts [ "boundary" ]; |
|
| 120 | 120 | } else { |
| 121 | 121 | $boundary = null; |
| 122 | 122 | } |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $childContentType = $this->extractValueHeader($this->getContentType($partHeaders)); |
| 142 | 142 | |
| 143 | 143 | if (stripos($childContentType, 'multipart/') !== false) { |
| 144 | - $parts ["parts"] [] = $this->parseParts($stream, $partHeaders); |
|
| 144 | + $parts [ "parts" ] [ ] = $this->parseParts($stream, $partHeaders); |
|
| 145 | 145 | try { |
| 146 | 146 | $this->extractPart($stream, $boundary, $this->getTransferEncoding($partHeaders)); |
| 147 | 147 | } catch (Exception\EndOfPartReachedException $e) { |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | $this->extractPart($stream, $boundary, $this->getTransferEncoding($partHeaders)); |
| 151 | 151 | } |
| 152 | 152 | } catch (Exception\EndOfPartReachedException $e) { |
| 153 | - $parts ["parts"] [] = array( |
|
| 153 | + $parts [ "parts" ] [ ] = array( |
|
| 154 | 154 | "type" => $childContentType, |
| 155 | 155 | "parent-type" => $contentType, |
| 156 | 156 | "headers" => $partHeaders, |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | private function getContentType(array $partHeaders) |
| 181 | 181 | { |
| 182 | 182 | if (array_key_exists('content-type', $partHeaders)) { |
| 183 | - return $partHeaders['content-type']; |
|
| 183 | + return $partHeaders[ 'content-type' ]; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | return ''; |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | continue; |
| 199 | 199 | } |
| 200 | 200 | list ($k, $v) = explode("=", trim($pv), 2); |
| 201 | - $p [$k] = trim($v, '"'); |
|
| 201 | + $p [ $k ] = trim($v, '"'); |
|
| 202 | 202 | } |
| 203 | 203 | return $p; |
| 204 | 204 | } else { |
@@ -214,21 +214,21 @@ discard block |
||
| 214 | 214 | |
| 215 | 215 | if ($boundary !== null) { |
| 216 | 216 | if (strpos($row, "--$boundary--") === 0) { |
| 217 | - throw new Exception\EndOfMultiPartReachedException ($this->contentDecoder->decode(implode("", $rows), $encoding)); |
|
| 217 | + throw new Exception\EndOfMultiPartReachedException($this->contentDecoder->decode(implode("", $rows), $encoding)); |
|
| 218 | 218 | } |
| 219 | 219 | if (strpos($row, "--$boundary") === 0) { |
| 220 | - throw new Exception\EndOfPartReachedException ($this->contentDecoder->decode(implode("", $rows), $encoding)); |
|
| 220 | + throw new Exception\EndOfPartReachedException($this->contentDecoder->decode(implode("", $rows), $encoding)); |
|
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | - $rows [] = $row; |
|
| 223 | + $rows [ ] = $row; |
|
| 224 | 224 | } |
| 225 | - throw new Exception\EndOfMultiPartReachedException ($this->contentDecoder->decode(implode("", $rows), $encoding)); |
|
| 225 | + throw new Exception\EndOfMultiPartReachedException($this->contentDecoder->decode(implode("", $rows), $encoding)); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | private function getTransferEncoding(array $partHeaders) |
| 229 | 229 | { |
| 230 | 230 | if (array_key_exists('content-transfer-encoding', $partHeaders)) { |
| 231 | - return $partHeaders ['content-transfer-encoding']; |
|
| 231 | + return $partHeaders [ 'content-transfer-encoding' ]; |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | return ''; |
@@ -247,13 +247,13 @@ discard block |
||
| 247 | 247 | switch (strtolower($name)) { |
| 248 | 248 | case "content-type" : |
| 249 | 249 | $parts = $this->extractHeaderParts($value); |
| 250 | - unset ($parts ["boundary"]); |
|
| 250 | + unset ($parts [ "boundary" ]); |
|
| 251 | 251 | $headers->addParameterizedHeader($name, $this->extractValueHeader($value), $parts); |
| 252 | 252 | break; |
| 253 | 253 | case "return-path" : |
| 254 | 254 | if (preg_match_all('/([a-z][a-z0-9_\-\.]*@[a-z0-9\.\-]*\.[a-z]{2,5})/i', $value, $mch)) { |
| 255 | - foreach ($mch [0] as $k => $mails) { |
|
| 256 | - $headers->addPathHeader($name, $mch [1] [$k]); |
|
| 255 | + foreach ($mch [ 0 ] as $k => $mails) { |
|
| 256 | + $headers->addPathHeader($name, $mch [ 1 ] [ $k ]); |
|
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | break; |
@@ -266,16 +266,16 @@ discard block |
||
| 266 | 266 | case "cc" : |
| 267 | 267 | $adresses = array(); |
| 268 | 268 | if (preg_match_all('/(.*?)<([a-z][a-z0-9_\-\.]*@[a-z0-9\.\-]*\.[a-z]{2,5})>\s*[;,]*/i', $value, $mch)) { |
| 269 | - foreach ($mch [0] as $k => $mail) { |
|
| 270 | - if (!$mch [1] [$k]) { |
|
| 271 | - $adresses [$mch [2] [$k]] = trim($mch [2] [$k]); |
|
| 269 | + foreach ($mch [ 0 ] as $k => $mail) { |
|
| 270 | + if (!$mch [ 1 ] [ $k ]) { |
|
| 271 | + $adresses [ $mch [ 2 ] [ $k ] ] = trim($mch [ 2 ] [ $k ]); |
|
| 272 | 272 | } else { |
| 273 | - $adresses [$mch [2] [$k]] = trim($mch [1] [$k]); |
|
| 273 | + $adresses [ $mch [ 2 ] [ $k ] ] = trim($mch [ 1 ] [ $k ]); |
|
| 274 | 274 | } |
| 275 | 275 | } |
| 276 | 276 | } elseif (preg_match_all('/([a-z][a-z0-9_\-\.]*@[a-z0-9\.\-]*\.[a-z]{2,5})/i', $value, $mch)) { |
| 277 | - foreach ($mch [0] as $k => $mails) { |
|
| 278 | - $adresses [$mch [1] [$k]] = trim($mch [1] [$k]); |
|
| 277 | + foreach ($mch [ 0 ] as $k => $mails) { |
|
| 278 | + $adresses [ $mch [ 1 ] [ $k ] ] = trim($mch [ 1 ] [ $k ]); |
|
| 279 | 279 | } |
| 280 | 280 | } |
| 281 | 281 | $headers->addMailboxHeader($name, $adresses); |
@@ -290,42 +290,42 @@ discard block |
||
| 290 | 290 | |
| 291 | 291 | protected function createMessage(array $message, \Swift_Mime_MimeEntity $entity) |
| 292 | 292 | { |
| 293 | - if (stripos($message ["type"], 'multipart/') !== false) { |
|
| 293 | + if (stripos($message [ "type" ], 'multipart/') !== false) { |
|
| 294 | 294 | |
| 295 | - if (strpos($message ["type"], '/alternative')) { |
|
| 295 | + if (strpos($message [ "type" ], '/alternative')) { |
|
| 296 | 296 | $nestingLevel = \Swift_Mime_MimeEntity::LEVEL_ALTERNATIVE; |
| 297 | - } elseif (strpos($message ["type"], '/related')) { |
|
| 297 | + } elseif (strpos($message [ "type" ], '/related')) { |
|
| 298 | 298 | $nestingLevel = \Swift_Mime_MimeEntity::LEVEL_RELATED; |
| 299 | - } elseif (strpos($message ["type"], '/mixed')) { |
|
| 299 | + } elseif (strpos($message [ "type" ], '/mixed')) { |
|
| 300 | 300 | $nestingLevel = \Swift_Mime_MimeEntity::LEVEL_MIXED; |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | $childrens = array(); |
| 304 | - foreach ($message ["parts"] as $part) { |
|
| 304 | + foreach ($message [ "parts" ] as $part) { |
|
| 305 | 305 | |
| 306 | - $headers = $this->createHeadersSet($part ["headers"]); |
|
| 307 | - $encoder = $this->getEncoder($this->getTransferEncoding($part ["headers"])); |
|
| 306 | + $headers = $this->createHeadersSet($part [ "headers" ]); |
|
| 307 | + $encoder = $this->getEncoder($this->getTransferEncoding($part [ "headers" ])); |
|
| 308 | 308 | |
| 309 | - if (stripos($part ["type"], 'multipart/') !== false) { |
|
| 310 | - $newEntity = new \Swift_Mime_MimePart ($headers, $encoder, $this->cache, $this->grammar); |
|
| 309 | + if (stripos($part [ "type" ], 'multipart/') !== false) { |
|
| 310 | + $newEntity = new \Swift_Mime_MimePart($headers, $encoder, $this->cache, $this->grammar); |
|
| 311 | 311 | } else { |
| 312 | - $newEntity = new \Swift_Mime_SimpleMimeEntity ($headers, $encoder, $this->cache, $this->grammar); |
|
| 312 | + $newEntity = new \Swift_Mime_SimpleMimeEntity($headers, $encoder, $this->cache, $this->grammar); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | $this->createMessage($part, $newEntity); |
| 316 | 316 | |
| 317 | - $ref = new \ReflectionObject ($newEntity); |
|
| 317 | + $ref = new \ReflectionObject($newEntity); |
|
| 318 | 318 | $m = $ref->getMethod('_setNestingLevel'); |
| 319 | 319 | $m->setAccessible(true); |
| 320 | 320 | $m->invoke($newEntity, $nestingLevel); |
| 321 | 321 | |
| 322 | - $childrens [] = $newEntity; |
|
| 322 | + $childrens [ ] = $newEntity; |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | - $entity->setContentType($part ["type"]); |
|
| 325 | + $entity->setContentType($part [ "type" ]); |
|
| 326 | 326 | $entity->setChildren($childrens); |
| 327 | 327 | } else { |
| 328 | - $entity->setBody($message ["body"], $message ["type"]); |
|
| 328 | + $entity->setBody($message [ "body" ], $message [ "type" ]); |
|
| 329 | 329 | } |
| 330 | 330 | } |
| 331 | 331 | |