@@ -4,6 +4,10 @@ discard block |
||
4 | 4 | |
5 | 5 | class HeaderDecoder { |
6 | 6 | public static $decodeWindows1252 = false; |
7 | + |
|
8 | + /** |
|
9 | + * @param string $string |
|
10 | + */ |
|
7 | 11 | public function decode($string) { |
8 | 12 | /* Take out any spaces between multiple encoded words. */ |
9 | 13 | $string = preg_replace ( '|\?=\s+=\?|', '?==?', $string ); |
@@ -62,6 +66,12 @@ discard block |
||
62 | 66 | |
63 | 67 | return $out . substr ( $string, $old_pos ); |
64 | 68 | } |
69 | + |
|
70 | + /** |
|
71 | + * @param string $str |
|
72 | + * @param string $orig |
|
73 | + * @param string $to |
|
74 | + */ |
|
65 | 75 | public static function convertCharset($str, $orig, $to) { |
66 | 76 | //@todo convert charset |
67 | 77 | return $str; |
@@ -6,50 +6,50 @@ discard block |
||
6 | 6 | public static $decodeWindows1252 = false; |
7 | 7 | public function decode($string) { |
8 | 8 | /* Take out any spaces between multiple encoded words. */ |
9 | - $string = preg_replace ( '|\?=\s+=\?|', '?==?', $string ); |
|
9 | + $string = preg_replace('|\?=\s+=\?|', '?==?', $string); |
|
10 | 10 | |
11 | 11 | $out = ''; |
12 | 12 | $old_pos = 0; |
13 | 13 | |
14 | - while ( ($pos = strpos ( $string, '=?', $old_pos )) !== false ) { |
|
14 | + while (($pos = strpos($string, '=?', $old_pos)) !== false) { |
|
15 | 15 | /* Save any preceding text. */ |
16 | - $out .= substr ( $string, $old_pos, $pos - $old_pos ); |
|
16 | + $out .= substr($string, $old_pos, $pos - $old_pos); |
|
17 | 17 | |
18 | 18 | /* Search for first delimiting question mark (charset). */ |
19 | - if (($d1 = strpos ( $string, '?', $pos + 2 )) === false) { |
|
19 | + if (($d1 = strpos($string, '?', $pos + 2)) === false) { |
|
20 | 20 | break; |
21 | 21 | } |
22 | 22 | |
23 | - $orig_charset = substr ( $string, $pos + 2, $d1 - $pos - 2 ); |
|
24 | - if (self::$decodeWindows1252 && mb_strtolower ( $orig_charset ) == 'iso-8859-1') { |
|
23 | + $orig_charset = substr($string, $pos + 2, $d1 - $pos - 2); |
|
24 | + if (self::$decodeWindows1252 && mb_strtolower($orig_charset) == 'iso-8859-1') { |
|
25 | 25 | $orig_charset = 'windows-1252'; |
26 | 26 | } |
27 | 27 | |
28 | 28 | /* Search for second delimiting question mark (encoding). */ |
29 | - if (($d2 = strpos ( $string, '?', $d1 + 1 )) === false) { |
|
29 | + if (($d2 = strpos($string, '?', $d1 + 1)) === false) { |
|
30 | 30 | break; |
31 | 31 | } |
32 | 32 | |
33 | - $encoding = substr ( $string, $d1 + 1, $d2 - $d1 - 1 ); |
|
33 | + $encoding = substr($string, $d1 + 1, $d2 - $d1 - 1); |
|
34 | 34 | |
35 | 35 | /* Search for end of encoded data. */ |
36 | - if (($end = strpos ( $string, '?=', $d2 + 1 )) === false) { |
|
36 | + if (($end = strpos($string, '?=', $d2 + 1)) === false) { |
|
37 | 37 | break; |
38 | 38 | } |
39 | 39 | |
40 | - $encoded_text = substr ( $string, $d2 + 1, $end - $d2 - 1 ); |
|
40 | + $encoded_text = substr($string, $d2 + 1, $end - $d2 - 1); |
|
41 | 41 | |
42 | 42 | switch ($encoding) { |
43 | 43 | case 'Q' : |
44 | 44 | case 'q' : |
45 | - $out .= self::convertCharset ( preg_replace_callback ( '/=([0-9a-f]{2})/i', function ($ord) { |
|
46 | - return chr ( hexdec ( $ord [1] ) ); |
|
47 | - }, str_replace ( '_', ' ', $encoded_text ) ), $orig_charset, 'UTF-8' ); |
|
45 | + $out .= self::convertCharset(preg_replace_callback('/=([0-9a-f]{2})/i', function($ord) { |
|
46 | + return chr(hexdec($ord [ 1 ])); |
|
47 | + }, str_replace('_', ' ', $encoded_text)), $orig_charset, 'UTF-8'); |
|
48 | 48 | break; |
49 | 49 | |
50 | 50 | case 'B' : |
51 | 51 | case 'b' : |
52 | - $out .= self::convertCharset ( base64_decode ( $encoded_text ), $orig_charset, 'UTF-8' ); |
|
52 | + $out .= self::convertCharset(base64_decode($encoded_text), $orig_charset, 'UTF-8'); |
|
53 | 53 | break; |
54 | 54 | |
55 | 55 | default : |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | $old_pos = $end + 2; |
61 | 61 | } |
62 | 62 | |
63 | - return $out . substr ( $string, $old_pos ); |
|
63 | + return $out . substr($string, $old_pos); |
|
64 | 64 | } |
65 | 65 | public static function convertCharset($str, $orig, $to) { |
66 | 66 | //@todo convert charset |
@@ -23,10 +23,10 @@ discard block |
||
23 | 23 | } |
24 | 24 | /** |
25 | 25 | * |
26 | - * @param stream $stream |
|
26 | + * @param resource $stream |
|
27 | 27 | * @param boolean $fillHeaders (default to false) |
28 | 28 | * @param \Swift_Mime_MimeEntity $message (default to null) |
29 | - * @return Swift_Mime_MimeEntity|\Swift_Message |
|
29 | + * @return \Swift_Mime_MimeEntity |
|
30 | 30 | */ |
31 | 31 | public function parseStream($stream, $fillHeaders = false, \Swift_Mime_MimeEntity $message = null) { |
32 | 32 | $partHeaders = $this->extractHeaders ( $stream ); |
@@ -235,6 +235,10 @@ discard block |
||
235 | 235 | $entity->setBody ( $message ["body"], $message ["type"] ); |
236 | 236 | } |
237 | 237 | } |
238 | + |
|
239 | + /** |
|
240 | + * @return string |
|
241 | + */ |
|
238 | 242 | private function extractValueHeader($header) { |
239 | 243 | $pos = stripos ( $header, ';' ); |
240 | 244 | if ($pos !== false) { |
@@ -267,10 +267,10 @@ |
||
267 | 267 | |
268 | 268 | if ($boundary !== null) { |
269 | 269 | if(strpos($row, "--$boundary--")===0){ |
270 | - throw new Exception\EndOfMultiPartReachedException ( $this->contentDecoder->decode ( implode ( "", $rows ), $encoding ) ); |
|
270 | + throw new Exception\EndOfMultiPartReachedException ( $this->contentDecoder->decode ( implode ( "", $rows ), $encoding ) ); |
|
271 | 271 | } |
272 | 272 | if(strpos($row, "--$boundary")===0){ |
273 | - throw new Exception\EndOfPartReachedException ( $this->contentDecoder->decode ( implode ( "", $rows ), $encoding ) ); |
|
273 | + throw new Exception\EndOfPartReachedException ( $this->contentDecoder->decode ( implode ( "", $rows ), $encoding ) ); |
|
274 | 274 | } |
275 | 275 | } |
276 | 276 | $rows [] = $row; |
@@ -10,16 +10,16 @@ discard block |
||
10 | 10 | private $grammar; |
11 | 11 | private $contentDecoder; |
12 | 12 | private $headerDecoder; |
13 | - protected $removeHeaders = array ("Received","From","X-Original-To","MIME-Version","Received-SPF","Delivered-To"); |
|
14 | - protected $allowedHeaders = array ("return-path","subject"); |
|
13 | + protected $removeHeaders = array("Received", "From", "X-Original-To", "MIME-Version", "Received-SPF", "Delivered-To"); |
|
14 | + protected $allowedHeaders = array("return-path", "subject"); |
|
15 | 15 | public function __construct(array $allowedHeaders = array(), array $removeHeaders = array()) { |
16 | - $this->cache = \Swift_DependencyContainer::getInstance ()->lookup ( 'cache' ); |
|
17 | - $this->grammar = \Swift_DependencyContainer::getInstance ()->lookup ( 'mime.grammar' ); |
|
18 | - $this->contentDecoder = new ContentDecoder (); |
|
19 | - $this->headerDecoder = new HeaderDecoder (); |
|
16 | + $this->cache = \Swift_DependencyContainer::getInstance()->lookup('cache'); |
|
17 | + $this->grammar = \Swift_DependencyContainer::getInstance()->lookup('mime.grammar'); |
|
18 | + $this->contentDecoder = new ContentDecoder(); |
|
19 | + $this->headerDecoder = new HeaderDecoder(); |
|
20 | 20 | |
21 | - $this->allowedHeaders = array_merge ( $this->allowedHeaders, $allowedHeaders ); |
|
22 | - $this->removeHeaders = array_merge ( $this->removeHeaders, $removeHeaders ); |
|
21 | + $this->allowedHeaders = array_merge($this->allowedHeaders, $allowedHeaders); |
|
22 | + $this->removeHeaders = array_merge($this->removeHeaders, $removeHeaders); |
|
23 | 23 | } |
24 | 24 | /** |
25 | 25 | * |
@@ -28,25 +28,25 @@ discard block |
||
28 | 28 | * @param \Swift_Mime_MimeEntity $message (default to null) |
29 | 29 | * @return Swift_Mime_MimeEntity|\Swift_Message |
30 | 30 | */ |
31 | - public function parseStream($stream, $fillHeaders = false, \Swift_Mime_MimeEntity $message = null) { |
|
32 | - $partHeaders = $this->extractHeaders ( $stream ); |
|
31 | + public function parseStream($stream, $fillHeaders = false, \Swift_Mime_MimeEntity $message = null) { |
|
32 | + $partHeaders = $this->extractHeaders($stream); |
|
33 | 33 | |
34 | - $filteredHeaders = $this->filterHeaders ( $partHeaders ); |
|
34 | + $filteredHeaders = $this->filterHeaders($partHeaders); |
|
35 | 35 | |
36 | - $parts = $this->parseParts ( $stream, $partHeaders ); |
|
36 | + $parts = $this->parseParts($stream, $partHeaders); |
|
37 | 37 | |
38 | - if(!$message){ |
|
39 | - $message = new \Swift_Message (); |
|
38 | + if (!$message) { |
|
39 | + $message = new \Swift_Message(); |
|
40 | 40 | } |
41 | 41 | |
42 | - $headers = $this->createHeadersSet ( $filteredHeaders ); |
|
42 | + $headers = $this->createHeadersSet($filteredHeaders); |
|
43 | 43 | |
44 | - foreach ( $headers->getAll () as $name => $header ) { |
|
45 | - if ($fillHeaders || in_array ( strtolower ( $header->getFieldName () ), $this->allowedHeaders )) { |
|
46 | - $message->getHeaders ()->set ( $header ); |
|
44 | + foreach ($headers->getAll() as $name => $header) { |
|
45 | + if ($fillHeaders || in_array(strtolower($header->getFieldName()), $this->allowedHeaders)) { |
|
46 | + $message->getHeaders()->set($header); |
|
47 | 47 | } |
48 | 48 | } |
49 | - $this->createMessage ( $parts, $message ); |
|
49 | + $this->createMessage($parts, $message); |
|
50 | 50 | |
51 | 51 | return $message; |
52 | 52 | } |
@@ -57,11 +57,11 @@ discard block |
||
57 | 57 | * @return \Swift_Message |
58 | 58 | */ |
59 | 59 | public function parseString($string) { |
60 | - $fp = tmpfile (); |
|
61 | - fwrite ( $fp, $string ); |
|
62 | - rewind ( $fp ); |
|
63 | - $message = $this->parseStream ( $fp ); |
|
64 | - fclose ( $fp ); |
|
60 | + $fp = tmpfile(); |
|
61 | + fwrite($fp, $string); |
|
62 | + rewind($fp); |
|
63 | + $message = $this->parseStream($fp); |
|
64 | + fclose($fp); |
|
65 | 65 | return $message; |
66 | 66 | } |
67 | 67 | /** |
@@ -71,49 +71,49 @@ discard block |
||
71 | 71 | * @return \Swift_Message |
72 | 72 | */ |
73 | 73 | public function parseFile($path) { |
74 | - $fp = fopen ( $path, "rb" ); |
|
75 | - $message = $this->parseStream ( $fp ); |
|
76 | - fclose ( $fp ); |
|
74 | + $fp = fopen($path, "rb"); |
|
75 | + $message = $this->parseStream($fp); |
|
76 | + fclose($fp); |
|
77 | 77 | return $message; |
78 | 78 | } |
79 | 79 | |
80 | 80 | protected function parseParts($stream, $partHeaders) { |
81 | - $parts = array (); |
|
81 | + $parts = array(); |
|
82 | 82 | $part = 0; |
83 | - $contentTypeHeader = array_key_exists( 'content-type', $partHeaders ) ? $partHeaders ['content-type'] : ''; |
|
84 | - $contentType = $this->extractValueHeader( $contentTypeHeader ); |
|
83 | + $contentTypeHeader = array_key_exists('content-type', $partHeaders) ? $partHeaders [ 'content-type' ] : ''; |
|
84 | + $contentType = $this->extractValueHeader($contentTypeHeader); |
|
85 | 85 | |
86 | - if (stripos ( $contentType, 'multipart/' ) !== false) { |
|
87 | - $headerParts = $this->extractHeaderParts ( $contentTypeHeader ); |
|
88 | - $boundary = $headerParts ["boundary"]; |
|
86 | + if (stripos($contentType, 'multipart/') !== false) { |
|
87 | + $headerParts = $this->extractHeaderParts($contentTypeHeader); |
|
88 | + $boundary = $headerParts [ "boundary" ]; |
|
89 | 89 | } else { |
90 | 90 | $boundary = null; |
91 | 91 | } |
92 | 92 | |
93 | 93 | try { |
94 | 94 | // body |
95 | - $transferEncoding = array_key_exists( 'content-transfer-encoding', $partHeaders ) ? $partHeaders ['content-transfer-encoding'] : ''; |
|
96 | - $this->extractPart ( $stream, $boundary, $transferEncoding ); |
|
97 | - } catch ( Exception\EndOfPartReachedException $e ) { |
|
98 | - $parts = array ("type" => $contentType,"headers" => $partHeaders,"body" => $e->getData (),"boundary" => $boundary,"parts" => array ()); |
|
95 | + $transferEncoding = array_key_exists('content-transfer-encoding', $partHeaders) ? $partHeaders [ 'content-transfer-encoding' ] : ''; |
|
96 | + $this->extractPart($stream, $boundary, $transferEncoding); |
|
97 | + } catch (Exception\EndOfPartReachedException $e) { |
|
98 | + $parts = array("type" => $contentType, "headers" => $partHeaders, "body" => $e->getData(), "boundary" => $boundary, "parts" => array()); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | if ($boundary) { |
102 | - while ( ! feof ( $stream ) ) { |
|
102 | + while (!feof($stream)) { |
|
103 | 103 | try { |
104 | - $partHeaders = $this->extractHeaders ( $stream ); |
|
105 | - $childContentType = $this->extractValueHeader ( $partHeaders ["content-type"] ); |
|
104 | + $partHeaders = $this->extractHeaders($stream); |
|
105 | + $childContentType = $this->extractValueHeader($partHeaders [ "content-type" ]); |
|
106 | 106 | |
107 | - if (stripos ( $childContentType, 'multipart/' ) !== false) { |
|
108 | - $parts ["parts"] [] = $this->parseParts ( $stream, $partHeaders ); |
|
107 | + if (stripos($childContentType, 'multipart/') !== false) { |
|
108 | + $parts [ "parts" ] [ ] = $this->parseParts($stream, $partHeaders); |
|
109 | 109 | try { |
110 | - $this->extractPart ( $stream, $boundary, $partHeaders ["content-transfer-encoding"] ); |
|
111 | - } catch ( Exception\EndOfPartReachedException $e ) {} |
|
110 | + $this->extractPart($stream, $boundary, $partHeaders [ "content-transfer-encoding" ]); |
|
111 | + } catch (Exception\EndOfPartReachedException $e) {} |
|
112 | 112 | } else { |
113 | - $this->extractPart ( $stream, $boundary, $partHeaders ["content-transfer-encoding"] ); |
|
113 | + $this->extractPart($stream, $boundary, $partHeaders [ "content-transfer-encoding" ]); |
|
114 | 114 | } |
115 | - } catch ( Exception\EndOfPartReachedException $e ) { |
|
116 | - $parts ["parts"] [] = array ("type" => $childContentType,"parent-type" => $contentType,"headers" => $partHeaders,"body" => $e->getData (),"parts" => array ()); |
|
115 | + } catch (Exception\EndOfPartReachedException $e) { |
|
116 | + $parts [ "parts" ] [ ] = array("type" => $childContentType, "parent-type" => $contentType, "headers" => $partHeaders, "body" => $e->getData(), "parts" => array()); |
|
117 | 117 | |
118 | 118 | if ($e instanceof Exception\EndOfMultiPartReachedException) { |
119 | 119 | break; |
@@ -131,16 +131,16 @@ discard block |
||
131 | 131 | protected function getEncoder($type) { |
132 | 132 | switch ($type) { |
133 | 133 | case "base64" : |
134 | - return \Swift_DependencyContainer::getInstance ()->lookup ( 'mime.base64contentencoder' ); |
|
134 | + return \Swift_DependencyContainer::getInstance()->lookup('mime.base64contentencoder'); |
|
135 | 135 | break; |
136 | 136 | case "8bit" : |
137 | - return \Swift_DependencyContainer::getInstance ()->lookup ( 'mime.8bitcontentencoder' ); |
|
137 | + return \Swift_DependencyContainer::getInstance()->lookup('mime.8bitcontentencoder'); |
|
138 | 138 | break; |
139 | 139 | case "7bit" : |
140 | - return \Swift_DependencyContainer::getInstance ()->lookup ( 'mime.7bitcontentencoder' ); |
|
140 | + return \Swift_DependencyContainer::getInstance()->lookup('mime.7bitcontentencoder'); |
|
141 | 141 | break; |
142 | 142 | default : |
143 | - return \Swift_DependencyContainer::getInstance ()->lookup ( 'mime.qpcontentencoder' ); |
|
143 | + return \Swift_DependencyContainer::getInstance()->lookup('mime.qpcontentencoder'); |
|
144 | 144 | break; |
145 | 145 | } |
146 | 146 | } |
@@ -150,162 +150,162 @@ discard block |
||
150 | 150 | * @return \Swift_Mime_HeaderSet |
151 | 151 | */ |
152 | 152 | protected function createHeadersSet(array $headersRaw) { |
153 | - $headers = \Swift_DependencyContainer::getInstance ()->lookup ( 'mime.headerset' ); |
|
153 | + $headers = \Swift_DependencyContainer::getInstance()->lookup('mime.headerset'); |
|
154 | 154 | |
155 | - foreach ( $headersRaw as $name => $value ) { |
|
156 | - switch (strtolower ( $name )) { |
|
155 | + foreach ($headersRaw as $name => $value) { |
|
156 | + switch (strtolower($name)) { |
|
157 | 157 | case "content-type" : |
158 | - $parts = $this->extractHeaderParts ( $value ); |
|
159 | - unset ( $parts ["boundary"] ); |
|
160 | - $headers->addParameterizedHeader ( $name, $this->extractValueHeader ( $value ), $parts ); |
|
158 | + $parts = $this->extractHeaderParts($value); |
|
159 | + unset ($parts [ "boundary" ]); |
|
160 | + $headers->addParameterizedHeader($name, $this->extractValueHeader($value), $parts); |
|
161 | 161 | break; |
162 | 162 | case "return-path" : |
163 | - if (preg_match_all ( '/([a-z][a-z0-9_\-\.]*@[a-z0-9\.\-]*\.[a-z]{2,5})/i', $value, $mch )) { |
|
164 | - foreach ( $mch [0] as $k => $mails ) { |
|
165 | - $headers->addPathHeader ( $name, $mch [1] [$k] ); |
|
163 | + if (preg_match_all('/([a-z][a-z0-9_\-\.]*@[a-z0-9\.\-]*\.[a-z]{2,5})/i', $value, $mch)) { |
|
164 | + foreach ($mch [ 0 ] as $k => $mails) { |
|
165 | + $headers->addPathHeader($name, $mch [ 1 ] [ $k ]); |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 | break; |
169 | 169 | case "date": |
170 | - $headers->addDateHeader ( $name, strtotime($value) ); |
|
170 | + $headers->addDateHeader($name, strtotime($value)); |
|
171 | 171 | case "to": |
172 | 172 | case "from" : |
173 | 173 | case "bcc" : |
174 | 174 | case "reply-to" : |
175 | 175 | case "cc" : |
176 | - $adresses = array (); |
|
177 | - if (preg_match_all ( '/(.*?)<([a-z][a-z0-9_\-\.]*@[a-z0-9\.\-]*\.[a-z]{2,5})>\s*[;,]*/i', $value, $mch )) { |
|
178 | - foreach ( $mch [0] as $k => $mail ) { |
|
179 | - if (! $mch [1] [$k]) { |
|
180 | - $adresses [$mch [2] [$k]] = $mch [2] [$k]; |
|
176 | + $adresses = array(); |
|
177 | + if (preg_match_all('/(.*?)<([a-z][a-z0-9_\-\.]*@[a-z0-9\.\-]*\.[a-z]{2,5})>\s*[;,]*/i', $value, $mch)) { |
|
178 | + foreach ($mch [ 0 ] as $k => $mail) { |
|
179 | + if (!$mch [ 1 ] [ $k ]) { |
|
180 | + $adresses [ $mch [ 2 ] [ $k ] ] = $mch [ 2 ] [ $k ]; |
|
181 | 181 | } else { |
182 | - $adresses [$mch [2] [$k]] = $mch [1] [$k]; |
|
182 | + $adresses [ $mch [ 2 ] [ $k ] ] = $mch [ 1 ] [ $k ]; |
|
183 | 183 | } |
184 | 184 | } |
185 | - } elseif (preg_match_all ( '/([a-z][a-z0-9_\-\.]*@[a-z0-9\.\-]*\.[a-z]{2,5})/i', $value, $mch )) { |
|
186 | - foreach ( $mch [0] as $k => $mails ) { |
|
187 | - $adresses [$mch [1] [$k]] = $mch [1] [$k]; |
|
185 | + } elseif (preg_match_all('/([a-z][a-z0-9_\-\.]*@[a-z0-9\.\-]*\.[a-z]{2,5})/i', $value, $mch)) { |
|
186 | + foreach ($mch [ 0 ] as $k => $mails) { |
|
187 | + $adresses [ $mch [ 1 ] [ $k ] ] = $mch [ 1 ] [ $k ]; |
|
188 | 188 | } |
189 | 189 | } |
190 | - $headers->addMailboxHeader ( $name, $adresses ); |
|
190 | + $headers->addMailboxHeader($name, $adresses); |
|
191 | 191 | break; |
192 | 192 | default : |
193 | - $headers->addTextHeader ( $name, $value ); |
|
193 | + $headers->addTextHeader($name, $value); |
|
194 | 194 | break; |
195 | 195 | } |
196 | 196 | } |
197 | 197 | return $headers; |
198 | 198 | } |
199 | 199 | protected function createMessage(array $message, \Swift_Mime_MimeEntity $entity) { |
200 | - if (stripos ( $message ["type"], 'multipart/' ) !== false) { |
|
200 | + if (stripos($message [ "type" ], 'multipart/') !== false) { |
|
201 | 201 | |
202 | - if (strpos ( $message ["type"], '/alternative' )) { |
|
202 | + if (strpos($message [ "type" ], '/alternative')) { |
|
203 | 203 | $nestingLevel = \Swift_Mime_MimeEntity::LEVEL_ALTERNATIVE; |
204 | - } elseif (strpos ( $message ["type"], '/related' )) { |
|
204 | + } elseif (strpos($message [ "type" ], '/related')) { |
|
205 | 205 | $nestingLevel = \Swift_Mime_MimeEntity::LEVEL_RELATED; |
206 | - } elseif (strpos ( $message ["type"], '/mixed' )) { |
|
206 | + } elseif (strpos($message [ "type" ], '/mixed')) { |
|
207 | 207 | $nestingLevel = \Swift_Mime_MimeEntity::LEVEL_MIXED; |
208 | 208 | } |
209 | 209 | |
210 | - $childrens = array (); |
|
211 | - foreach ( $message ["parts"] as $part ) { |
|
210 | + $childrens = array(); |
|
211 | + foreach ($message [ "parts" ] as $part) { |
|
212 | 212 | |
213 | - $headers = $this->createHeadersSet ( $part ["headers"] ); |
|
214 | - $encoder = $this->getEncoder ( $part ["headers"] ["content-transfer-encoding"] ); |
|
213 | + $headers = $this->createHeadersSet($part [ "headers" ]); |
|
214 | + $encoder = $this->getEncoder($part [ "headers" ] [ "content-transfer-encoding" ]); |
|
215 | 215 | |
216 | - if (stripos ( $part ["type"], 'multipart/' ) !== false) { |
|
217 | - $newEntity = new \Swift_Mime_MimePart ( $headers, $encoder, $this->cache, $this->grammar ); |
|
216 | + if (stripos($part [ "type" ], 'multipart/') !== false) { |
|
217 | + $newEntity = new \Swift_Mime_MimePart($headers, $encoder, $this->cache, $this->grammar); |
|
218 | 218 | } else { |
219 | - $newEntity = new \Swift_Mime_SimpleMimeEntity ( $headers, $encoder, $this->cache, $this->grammar ); |
|
219 | + $newEntity = new \Swift_Mime_SimpleMimeEntity($headers, $encoder, $this->cache, $this->grammar); |
|
220 | 220 | } |
221 | 221 | |
222 | - $this->createMessage ( $part, $newEntity ); |
|
222 | + $this->createMessage($part, $newEntity); |
|
223 | 223 | |
224 | - $ref = new \ReflectionObject ( $newEntity ); |
|
225 | - $m = $ref->getMethod ( '_setNestingLevel' ); |
|
226 | - $m->setAccessible ( true ); |
|
227 | - $m->invoke ( $newEntity, $nestingLevel ); |
|
224 | + $ref = new \ReflectionObject($newEntity); |
|
225 | + $m = $ref->getMethod('_setNestingLevel'); |
|
226 | + $m->setAccessible(true); |
|
227 | + $m->invoke($newEntity, $nestingLevel); |
|
228 | 228 | |
229 | - $childrens [] = $newEntity; |
|
229 | + $childrens [ ] = $newEntity; |
|
230 | 230 | } |
231 | 231 | |
232 | - $entity->setContentType ( $part ["type"] ); |
|
233 | - $entity->setChildren ( $childrens ); |
|
232 | + $entity->setContentType($part [ "type" ]); |
|
233 | + $entity->setChildren($childrens); |
|
234 | 234 | } else { |
235 | - $entity->setBody ( $message ["body"], $message ["type"] ); |
|
235 | + $entity->setBody($message [ "body" ], $message [ "type" ]); |
|
236 | 236 | } |
237 | 237 | } |
238 | 238 | private function extractValueHeader($header) { |
239 | - $pos = stripos ( $header, ';' ); |
|
239 | + $pos = stripos($header, ';'); |
|
240 | 240 | if ($pos !== false) { |
241 | - return substr ( $header, 0, $pos ); |
|
241 | + return substr($header, 0, $pos); |
|
242 | 242 | } else { |
243 | 243 | return $header; |
244 | 244 | } |
245 | 245 | } |
246 | 246 | private function extractHeaderParts($header) { |
247 | - $pos = stripos ( $header, ';' ); |
|
247 | + $pos = stripos($header, ';'); |
|
248 | 248 | if ($pos !== false) { |
249 | 249 | |
250 | - $parts = explode ( ";", $header ); |
|
251 | - array_shift ( $parts ); |
|
250 | + $parts = explode(";", $header); |
|
251 | + array_shift($parts); |
|
252 | 252 | |
253 | - $p = array (); |
|
254 | - foreach ( $parts as $pv ) { |
|
255 | - list ( $k, $v ) = explode ( "=", trim ( $pv ), 2 ); |
|
256 | - $p [$k] = trim ( $v, '"' ); |
|
253 | + $p = array(); |
|
254 | + foreach ($parts as $pv) { |
|
255 | + list ($k, $v) = explode("=", trim($pv), 2); |
|
256 | + $p [ $k ] = trim($v, '"'); |
|
257 | 257 | } |
258 | 258 | return $p; |
259 | 259 | } else { |
260 | - return array (); |
|
260 | + return array(); |
|
261 | 261 | } |
262 | 262 | } |
263 | 263 | protected function extractPart($stream, $boundary, $encoding) { |
264 | - $rows = array (); |
|
265 | - while ( ! feof ( $stream ) ) { |
|
266 | - $row = fgets ( $stream ); |
|
264 | + $rows = array(); |
|
265 | + while (!feof($stream)) { |
|
266 | + $row = fgets($stream); |
|
267 | 267 | |
268 | 268 | if ($boundary !== null) { |
269 | - if(strpos($row, "--$boundary--")===0){ |
|
270 | - throw new Exception\EndOfMultiPartReachedException ( $this->contentDecoder->decode ( implode ( "", $rows ), $encoding ) ); |
|
269 | + if (strpos($row, "--$boundary--") === 0) { |
|
270 | + throw new Exception\EndOfMultiPartReachedException($this->contentDecoder->decode(implode("", $rows), $encoding)); |
|
271 | 271 | } |
272 | - if(strpos($row, "--$boundary")===0){ |
|
273 | - throw new Exception\EndOfPartReachedException ( $this->contentDecoder->decode ( implode ( "", $rows ), $encoding ) ); |
|
272 | + if (strpos($row, "--$boundary") === 0) { |
|
273 | + throw new Exception\EndOfPartReachedException($this->contentDecoder->decode(implode("", $rows), $encoding)); |
|
274 | 274 | } |
275 | 275 | } |
276 | - $rows [] = $row; |
|
276 | + $rows [ ] = $row; |
|
277 | 277 | } |
278 | - throw new Exception\EndOfMultiPartReachedException ( $this->contentDecoder->decode ( implode ( "", $rows ), $encoding ) ); |
|
278 | + throw new Exception\EndOfMultiPartReachedException($this->contentDecoder->decode(implode("", $rows), $encoding)); |
|
279 | 279 | } |
280 | 280 | protected function extractHeaders($stream) { |
281 | - $headers = array (); |
|
281 | + $headers = array(); |
|
282 | 282 | $hName = null; |
283 | - while ( ! feof ( $stream ) ) { |
|
284 | - $row = fgets ( $stream ); |
|
283 | + while (!feof($stream)) { |
|
284 | + $row = fgets($stream); |
|
285 | 285 | if ($row == "\r\n" || $row == "\n" || $row == "\r") { |
286 | 286 | break; |
287 | 287 | } |
288 | - if (preg_match ( '/^([a-z0-9\-]+)\s*:(.*)/i', $row, $mch )) { |
|
289 | - $hName = strtolower ( $mch [1] ); |
|
290 | - if (! in_array ( $hName, array ("content-type","content-transfer-encoding") )) { |
|
291 | - $hName = $mch [1]; |
|
288 | + if (preg_match('/^([a-z0-9\-]+)\s*:(.*)/i', $row, $mch)) { |
|
289 | + $hName = strtolower($mch [ 1 ]); |
|
290 | + if (!in_array($hName, array("content-type", "content-transfer-encoding"))) { |
|
291 | + $hName = $mch [ 1 ]; |
|
292 | 292 | } |
293 | - $row = $mch [2]; |
|
293 | + $row = $mch [ 2 ]; |
|
294 | 294 | } |
295 | - if (! $hName) { |
|
295 | + if (!$hName) { |
|
296 | 296 | continue; |
297 | 297 | } |
298 | - $headers [$hName] [] = trim ( $row ); |
|
298 | + $headers [ $hName ] [ ] = trim($row); |
|
299 | 299 | } |
300 | - foreach ( $headers as $header => $values ) { |
|
301 | - $headers [$header] = $this->headerDecoder->decode ( trim ( implode ( " ", $values ) ) ); |
|
300 | + foreach ($headers as $header => $values) { |
|
301 | + $headers [ $header ] = $this->headerDecoder->decode(trim(implode(" ", $values))); |
|
302 | 302 | } |
303 | 303 | return $headers; |
304 | 304 | } |
305 | 305 | private function filterHeaders(array $headers) { |
306 | - foreach ( $headers as $header => $values ) { |
|
307 | - if(in_array(strtolower ( $header ), $this->removeHeaders) && !in_array(strtolower ( $header ), $this->allowedHeaders)){ |
|
308 | - unset ( $headers [$header] ); |
|
306 | + foreach ($headers as $header => $values) { |
|
307 | + if (in_array(strtolower($header), $this->removeHeaders) && !in_array(strtolower($header), $this->allowedHeaders)) { |
|
308 | + unset ($headers [ $header ]); |
|
309 | 309 | } |
310 | 310 | } |
311 | 311 | return $headers; |
@@ -3,10 +3,10 @@ |
||
3 | 3 | namespace Goetas\Mail\ToSwiftMailParser\Exception; |
4 | 4 | |
5 | 5 | class EndOfPartReachedException extends \Exception { |
6 | - protected $data = array (); |
|
6 | + protected $data = array(); |
|
7 | 7 | public function __construct($data) { |
8 | 8 | $this->data = $data; |
9 | - parent::__construct (); |
|
9 | + parent::__construct(); |
|
10 | 10 | } |
11 | 11 | public function getData() { |
12 | 12 | return $this->data; |
@@ -5,11 +5,11 @@ |
||
5 | 5 | class ContentDecoder { |
6 | 6 | public function decode($string, $from) { |
7 | 7 | if ($from == "base64") { |
8 | - return base64_decode ( $string ); |
|
8 | + return base64_decode($string); |
|
9 | 9 | } elseif ($from == "7bit") { |
10 | - return quoted_printable_decode ( $string ); |
|
10 | + return quoted_printable_decode($string); |
|
11 | 11 | } elseif ($from == "quoted-printable") { |
12 | - return quoted_printable_decode ( $string ); |
|
12 | + return quoted_printable_decode($string); |
|
13 | 13 | } |
14 | 14 | return $string; |
15 | 15 | } |