@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @throws ConnectionFailedException |
90 | 90 | * @throws RuntimeException |
91 | 91 | */ |
92 | - protected function enableStartTls(){ |
|
92 | + protected function enableStartTls() { |
|
93 | 93 | $response = $this->requestAndResponse('STARTTLS'); |
94 | 94 | $result = $response && stream_socket_enable_crypto($this->stream, true, $this->getCryptoMethod()); |
95 | 95 | if (!$result) { |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | $stack = []; |
152 | 152 | |
153 | 153 | // replace any trailing <NL> including spaces with a single space |
154 | - $line = rtrim($line) . ' '; |
|
154 | + $line = rtrim($line).' '; |
|
155 | 155 | while (($pos = strpos($line, ' ')) !== false) { |
156 | 156 | $token = substr($line, 0, $pos); |
157 | 157 | if (!strlen($token)) { |
@@ -181,11 +181,11 @@ discard block |
||
181 | 181 | if (strlen($token) > $chars) { |
182 | 182 | $line = substr($token, $chars); |
183 | 183 | $token = substr($token, 0, $chars); |
184 | - } else { |
|
184 | + }else { |
|
185 | 185 | $line .= $this->nextLine(); |
186 | 186 | } |
187 | 187 | $tokens[] = $token; |
188 | - $line = trim($line) . ' '; |
|
188 | + $line = trim($line).' '; |
|
189 | 189 | continue; |
190 | 190 | } |
191 | 191 | } |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | $line = $this->nextTaggedLine($tag); // get next tag |
236 | 236 | if (!$dontParse) { |
237 | 237 | $tokens = $this->decodeLine($line); |
238 | - } else { |
|
238 | + }else { |
|
239 | 239 | $tokens = $line; |
240 | 240 | } |
241 | 241 | if ($this->debug) echo "<< ".$line."\n"; |
@@ -286,27 +286,27 @@ discard block |
||
286 | 286 | public function sendRequest($command, $tokens = [], &$tag = null) { |
287 | 287 | if (!$tag) { |
288 | 288 | $this->noun++; |
289 | - $tag = 'TAG' . $this->noun; |
|
289 | + $tag = 'TAG'.$this->noun; |
|
290 | 290 | } |
291 | 291 | |
292 | - $line = $tag . ' ' . $command; |
|
292 | + $line = $tag.' '.$command; |
|
293 | 293 | |
294 | 294 | foreach ($tokens as $token) { |
295 | 295 | if (is_array($token)) { |
296 | - if (fwrite($this->stream, $line . ' ' . $token[0] . "\r\n") === false) { |
|
296 | + if (fwrite($this->stream, $line.' '.$token[0]."\r\n") === false) { |
|
297 | 297 | throw new RuntimeException('failed to write - connection closed?'); |
298 | 298 | } |
299 | 299 | if (!$this->assumedNextLine('+ ')) { |
300 | 300 | throw new RuntimeException('failed to send literal string'); |
301 | 301 | } |
302 | 302 | $line = $token[1]; |
303 | - } else { |
|
304 | - $line .= ' ' . $token; |
|
303 | + }else { |
|
304 | + $line .= ' '.$token; |
|
305 | 305 | } |
306 | 306 | } |
307 | 307 | if ($this->debug) echo ">> ".$line."\n"; |
308 | 308 | |
309 | - if (fwrite($this->stream, $line . "\r\n") === false) { |
|
309 | + if (fwrite($this->stream, $line."\r\n") === false) { |
|
310 | 310 | throw new RuntimeException('failed to write - connection closed?'); |
311 | 311 | } |
312 | 312 | } |
@@ -336,9 +336,9 @@ discard block |
||
336 | 336 | public function escapeString($string) { |
337 | 337 | if (func_num_args() < 2) { |
338 | 338 | if (strpos($string, "\n") !== false) { |
339 | - return ['{' . strlen($string) . '}', $string]; |
|
340 | - } else { |
|
341 | - return '"' . str_replace(['\\', '"'], ['\\\\', '\\"'], $string) . '"'; |
|
339 | + return ['{'.strlen($string).'}', $string]; |
|
340 | + }else { |
|
341 | + return '"'.str_replace(['\\', '"'], ['\\\\', '\\"'], $string).'"'; |
|
342 | 342 | } |
343 | 343 | } |
344 | 344 | $result = []; |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | } |
364 | 364 | $result[] = $this->escapeList($v); |
365 | 365 | } |
366 | - return '(' . implode(' ', $result) . ')'; |
|
366 | + return '('.implode(' ', $result).')'; |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | /** |
@@ -403,12 +403,12 @@ discard block |
||
403 | 403 | error_log("got an extra server challenge: $response"); |
404 | 404 | // respond with an empty response. |
405 | 405 | $this->sendRequest(''); |
406 | - } else { |
|
406 | + }else { |
|
407 | 407 | if (preg_match('/^NO /i', $response) || |
408 | 408 | preg_match('/^BAD /i', $response)) { |
409 | 409 | error_log("got failure response: $response"); |
410 | 410 | return false; |
411 | - } else if (preg_match("/^OK /i", $response)) { |
|
411 | + }else if (preg_match("/^OK /i", $response)) { |
|
412 | 412 | return true; |
413 | 413 | } |
414 | 414 | } |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | * |
442 | 442 | * @return bool |
443 | 443 | */ |
444 | - public function connected(){ |
|
444 | + public function connected() { |
|
445 | 445 | return (boolean) $this->stream; |
446 | 446 | } |
447 | 447 | |
@@ -488,10 +488,10 @@ discard block |
||
488 | 488 | $result[strtolower($tokens[1])] = $tokens[0]; |
489 | 489 | break; |
490 | 490 | case '[UIDVALIDITY': |
491 | - $result['uidvalidity'] = (int)$tokens[2]; |
|
491 | + $result['uidvalidity'] = (int) $tokens[2]; |
|
492 | 492 | break; |
493 | 493 | case '[UIDNEXT': |
494 | - $result['uidnext'] = (int)$tokens[2]; |
|
494 | + $result['uidnext'] = (int) $tokens[2]; |
|
495 | 495 | break; |
496 | 496 | default: |
497 | 497 | // ignore |
@@ -546,14 +546,14 @@ discard block |
||
546 | 546 | if (is_array($from)) { |
547 | 547 | $set = implode(',', $from); |
548 | 548 | } elseif ($to === null) { |
549 | - $set = (int)$from; |
|
549 | + $set = (int) $from; |
|
550 | 550 | } elseif ($to === INF) { |
551 | - $set = (int)$from . ':*'; |
|
552 | - } else { |
|
553 | - $set = (int)$from . ':' . (int)$to; |
|
551 | + $set = (int) $from.':*'; |
|
552 | + }else { |
|
553 | + $set = (int) $from.':'.(int) $to; |
|
554 | 554 | } |
555 | 555 | |
556 | - $items = (array)$items; |
|
556 | + $items = (array) $items; |
|
557 | 557 | $itemList = $this->escapeList($items); |
558 | 558 | |
559 | 559 | $this->sendRequest($this->buildUIDCommand("FETCH", $uid), [$set, $itemList], $tag); |
@@ -570,9 +570,9 @@ discard block |
||
570 | 570 | $count = count($tokens[2]); |
571 | 571 | if ($tokens[2][$count - 2] == 'UID') { |
572 | 572 | $uidKey = $count - 1; |
573 | - } else if ($tokens[2][0] == 'UID') { |
|
573 | + }else if ($tokens[2][0] == 'UID') { |
|
574 | 574 | $uidKey = 1; |
575 | - } else { |
|
575 | + }else { |
|
576 | 576 | $uidKey = array_search('UID', $tokens[2]) + 1; |
577 | 577 | } |
578 | 578 | } |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | $data = $tokens[2][1]; |
589 | 589 | } elseif ($uid && $tokens[2][2] == $items[0]) { |
590 | 590 | $data = $tokens[2][3]; |
591 | - } else { |
|
591 | + }else { |
|
592 | 592 | // maybe the server send an other field we didn't wanted |
593 | 593 | $count = count($tokens[2]); |
594 | 594 | // we start with 2, because 0 was already checked |
@@ -600,7 +600,7 @@ discard block |
||
600 | 600 | break; |
601 | 601 | } |
602 | 602 | } |
603 | - } else { |
|
603 | + }else { |
|
604 | 604 | $data = []; |
605 | 605 | while (key($tokens[2]) !== null) { |
606 | 606 | $data[current($tokens[2])] = next($tokens[2]); |
@@ -617,7 +617,7 @@ discard block |
||
617 | 617 | } |
618 | 618 | if ($uid) { |
619 | 619 | $result[$tokens[2][$uidKey]] = $data; |
620 | - }else{ |
|
620 | + }else { |
|
621 | 621 | $result[$tokens[0]] = $data; |
622 | 622 | } |
623 | 623 | } |
@@ -653,7 +653,7 @@ discard block |
||
653 | 653 | * @return array |
654 | 654 | * @throws RuntimeException |
655 | 655 | */ |
656 | - public function headers($uids, $rfc = "RFC822", $uid = IMAP::ST_UID){ |
|
656 | + public function headers($uids, $rfc = "RFC822", $uid = IMAP::ST_UID) { |
|
657 | 657 | return $this->fetch(["$rfc.HEADER"], $uids, null, $uid); |
658 | 658 | } |
659 | 659 | |
@@ -666,7 +666,7 @@ discard block |
||
666 | 666 | * @return array |
667 | 667 | * @throws RuntimeException |
668 | 668 | */ |
669 | - public function flags($uids, $uid = IMAP::ST_UID){ |
|
669 | + public function flags($uids, $uid = IMAP::ST_UID) { |
|
670 | 670 | return $this->fetch(["FLAGS"], $uids, null, $uid); |
671 | 671 | } |
672 | 672 | |
@@ -762,7 +762,7 @@ discard block |
||
762 | 762 | $response = $this->requestAndResponse($command, [$set, $item, $flags], $silent); |
763 | 763 | |
764 | 764 | if ($silent) { |
765 | - return (bool)$response; |
|
765 | + return (bool) $response; |
|
766 | 766 | } |
767 | 767 | |
768 | 768 | $result = []; |
@@ -1063,7 +1063,7 @@ discard block |
||
1063 | 1063 | $ids = []; |
1064 | 1064 | foreach ($uids as $msgn => $v) { |
1065 | 1065 | $id = $uid ? $v : $msgn; |
1066 | - if ( ($to >= $id && $from <= $id) || ($to === "*" && $from <= $id) ){ |
|
1066 | + if (($to >= $id && $from <= $id) || ($to === "*" && $from <= $id)) { |
|
1067 | 1067 | $ids[] = $id; |
1068 | 1068 | } |
1069 | 1069 | } |
@@ -1077,14 +1077,14 @@ discard block |
||
1077 | 1077 | /** |
1078 | 1078 | * Enable the debug mode |
1079 | 1079 | */ |
1080 | - public function enableDebug(){ |
|
1080 | + public function enableDebug() { |
|
1081 | 1081 | $this->debug = true; |
1082 | 1082 | } |
1083 | 1083 | |
1084 | 1084 | /** |
1085 | 1085 | * Disable the debug mode |
1086 | 1086 | */ |
1087 | - public function disableDebug(){ |
|
1087 | + public function disableDebug() { |
|
1088 | 1088 | $this->debug = false; |
1089 | 1089 | } |
1090 | 1090 | |
@@ -1096,9 +1096,9 @@ discard block |
||
1096 | 1096 | * @return int|string |
1097 | 1097 | */ |
1098 | 1098 | public function buildSet($from, $to = null) { |
1099 | - $set = (int)$from; |
|
1099 | + $set = (int) $from; |
|
1100 | 1100 | if ($to !== null) { |
1101 | - $set .= ':' . ($to == INF ? '*' : (int)$to); |
|
1101 | + $set .= ':'.($to == INF ? '*' : (int) $to); |
|
1102 | 1102 | } |
1103 | 1103 | return $set; |
1104 | 1104 | } |
@@ -76,17 +76,17 @@ discard block |
||
76 | 76 | public static function get($key, $default = null) { |
77 | 77 | $parts = explode('.', $key); |
78 | 78 | $value = null; |
79 | - foreach($parts as $part) { |
|
80 | - if($value === null) { |
|
81 | - if(isset(self::$config[$part])) { |
|
79 | + foreach ($parts as $part) { |
|
80 | + if ($value === null) { |
|
81 | + if (isset(self::$config[$part])) { |
|
82 | 82 | $value = self::$config[$part]; |
83 | - }else{ |
|
83 | + }else { |
|
84 | 84 | break; |
85 | 85 | } |
86 | - }else{ |
|
87 | - if(isset($value[$part])) { |
|
86 | + }else { |
|
87 | + if (isset($value[$part])) { |
|
88 | 88 | $value = $value[$part]; |
89 | - }else{ |
|
89 | + }else { |
|
90 | 90 | break; |
91 | 91 | } |
92 | 92 | } |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | */ |
177 | 177 | public function setConfig($config) { |
178 | 178 | |
179 | - if(is_array($config) === false) { |
|
179 | + if (is_array($config) === false) { |
|
180 | 180 | $config = require $config; |
181 | 181 | } |
182 | 182 | |
@@ -186,17 +186,17 @@ discard block |
||
186 | 186 | $vendor_config = require $path; |
187 | 187 | $config = $this->array_merge_recursive_distinct($vendor_config, $config); |
188 | 188 | |
189 | - if(is_array($config)){ |
|
190 | - if(isset($config['default'])){ |
|
191 | - if(isset($config['accounts']) && $config['default'] != false){ |
|
189 | + if (is_array($config)) { |
|
190 | + if (isset($config['default'])) { |
|
191 | + if (isset($config['accounts']) && $config['default'] != false) { |
|
192 | 192 | |
193 | 193 | $default_config = $vendor_config['accounts']['default']; |
194 | - if(isset($config['accounts'][$config['default']])){ |
|
194 | + if (isset($config['accounts'][$config['default']])) { |
|
195 | 195 | $default_config = array_merge($default_config, $config['accounts'][$config['default']]); |
196 | 196 | } |
197 | 197 | |
198 | - if(is_array($config['accounts'])){ |
|
199 | - foreach($config['accounts'] as $account_key => $account){ |
|
198 | + if (is_array($config['accounts'])) { |
|
199 | + foreach ($config['accounts'] as $account_key => $account) { |
|
200 | 200 | $config['accounts'][$account_key] = array_merge($default_config, $account); |
201 | 201 | } |
202 | 202 | } |
@@ -238,20 +238,20 @@ discard block |
||
238 | 238 | return array_keys($arr) !== range(0, count($arr) - 1); |
239 | 239 | }; |
240 | 240 | |
241 | - if(!is_array($base)) $base = empty($base) ? array() : array($base); |
|
241 | + if (!is_array($base)) $base = empty($base) ? array() : array($base); |
|
242 | 242 | |
243 | - foreach($arrays as $append) { |
|
243 | + foreach ($arrays as $append) { |
|
244 | 244 | |
245 | - if(!is_array($append)) $append = array($append); |
|
245 | + if (!is_array($append)) $append = array($append); |
|
246 | 246 | |
247 | - foreach($append as $key => $value) { |
|
247 | + foreach ($append as $key => $value) { |
|
248 | 248 | |
249 | - if(!array_key_exists($key, $base) and !is_numeric($key)) { |
|
249 | + if (!array_key_exists($key, $base) and !is_numeric($key)) { |
|
250 | 250 | $base[$key] = $append[$key]; |
251 | 251 | continue; |
252 | 252 | } |
253 | 253 | |
254 | - if( |
|
254 | + if ( |
|
255 | 255 | ( |
256 | 256 | is_array($value) |
257 | 257 | && $isAssoc($value) |
@@ -265,9 +265,9 @@ discard block |
||
265 | 265 | // else merging $baseConfig['dispositions'] = ['attachment', 'inline'] with $customConfig['dispositions'] = ['attachment'] |
266 | 266 | // results in $resultConfig['dispositions'] = ['attachment', 'inline'] |
267 | 267 | $base[$key] = $this->array_merge_recursive_distinct($base[$key], $append[$key]); |
268 | - } else if(is_numeric($key)) { |
|
269 | - if(!in_array($value, $base)) $base[] = $value; |
|
270 | - } else { |
|
268 | + }else if (is_numeric($key)) { |
|
269 | + if (!in_array($value, $base)) $base[] = $value; |
|
270 | + }else { |
|
271 | 271 | $base[$key] = $value; |
272 | 272 | } |
273 | 273 |
@@ -159,10 +159,10 @@ discard block |
||
159 | 159 | * |
160 | 160 | * @throws InvalidMessageDateException |
161 | 161 | */ |
162 | - protected function parse(){ |
|
162 | + protected function parse() { |
|
163 | 163 | if ($this->header === null) { |
164 | 164 | $body = $this->findHeaders(); |
165 | - }else{ |
|
165 | + }else { |
|
166 | 166 | $body = $this->raw; |
167 | 167 | } |
168 | 168 | |
@@ -174,11 +174,11 @@ discard block |
||
174 | 174 | $this->name = $this->header->get("name"); |
175 | 175 | $this->filename = $this->header->get("filename"); |
176 | 176 | |
177 | - if(!empty($this->header->get("id"))) { |
|
177 | + if (!empty($this->header->get("id"))) { |
|
178 | 178 | $this->id = $this->header->get("id"); |
179 | - } else if(!empty($this->header->get("x_attachment_id"))){ |
|
179 | + }else if (!empty($this->header->get("x_attachment_id"))) { |
|
180 | 180 | $this->id = $this->header->get("x_attachment_id"); |
181 | - } else if(!empty($this->header->get("content_id"))){ |
|
181 | + }else if (!empty($this->header->get("content_id"))) { |
|
182 | 182 | $this->id = strtr($this->header->get("content_id"), [ |
183 | 183 | '<' => '', |
184 | 184 | '>' => '' |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | } |
187 | 187 | |
188 | 188 | $content_types = $this->header->get("content_type"); |
189 | - if(!empty($content_types)){ |
|
189 | + if (!empty($content_types)) { |
|
190 | 190 | $this->subtype = $this->parseSubtype($content_types); |
191 | 191 | $content_type = $content_types; |
192 | 192 | if (is_array($content_types)) { |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * @return string |
208 | 208 | * @throws InvalidMessageDateException |
209 | 209 | */ |
210 | - private function findHeaders(){ |
|
210 | + private function findHeaders() { |
|
211 | 211 | $body = $this->raw; |
212 | 212 | while (($pos = strpos($body, "\r\n")) > 0) { |
213 | 213 | $body = substr($body, $pos + 2); |
@@ -226,16 +226,16 @@ discard block |
||
226 | 226 | * |
227 | 227 | * @return string |
228 | 228 | */ |
229 | - private function parseSubtype($content_type){ |
|
229 | + private function parseSubtype($content_type) { |
|
230 | 230 | if (is_array($content_type)) { |
231 | - foreach ($content_type as $part){ |
|
232 | - if ((strpos($part, "/")) !== false){ |
|
231 | + foreach ($content_type as $part) { |
|
232 | + if ((strpos($part, "/")) !== false) { |
|
233 | 233 | return $this->parseSubtype($part); |
234 | 234 | } |
235 | 235 | } |
236 | 236 | return null; |
237 | 237 | } |
238 | - if (($pos = strpos($content_type, "/")) !== false){ |
|
238 | + if (($pos = strpos($content_type, "/")) !== false) { |
|
239 | 239 | return substr($content_type, $pos + 1); |
240 | 240 | } |
241 | 241 | return null; |
@@ -244,9 +244,9 @@ discard block |
||
244 | 244 | /** |
245 | 245 | * Try to parse the disposition if any is present |
246 | 246 | */ |
247 | - private function parseDisposition(){ |
|
247 | + private function parseDisposition() { |
|
248 | 248 | $content_disposition = $this->header->get("content_disposition"); |
249 | - if($content_disposition !== null) { |
|
249 | + if ($content_disposition !== null) { |
|
250 | 250 | $this->ifdisposition = true; |
251 | 251 | $this->disposition = (is_array($content_disposition)) ? implode(' ', $content_disposition) : $content_disposition; |
252 | 252 | } |
@@ -255,9 +255,9 @@ discard block |
||
255 | 255 | /** |
256 | 256 | * Try to parse the description if any is present |
257 | 257 | */ |
258 | - private function parseDescription(){ |
|
258 | + private function parseDescription() { |
|
259 | 259 | $content_description = $this->header->get("content_description"); |
260 | - if($content_description !== null) { |
|
260 | + if ($content_description !== null) { |
|
261 | 261 | $this->ifdescription = true; |
262 | 262 | $this->description = $content_description; |
263 | 263 | } |
@@ -266,9 +266,9 @@ discard block |
||
266 | 266 | /** |
267 | 267 | * Try to parse the encoding if any is present |
268 | 268 | */ |
269 | - private function parseEncoding(){ |
|
269 | + private function parseEncoding() { |
|
270 | 270 | $encoding = $this->header->get("content_transfer_encoding"); |
271 | - if($encoding !== null) { |
|
271 | + if ($encoding !== null) { |
|
272 | 272 | switch (strtolower($encoding)) { |
273 | 273 | case "quoted-printable": |
274 | 274 | $this->encoding = IMAP::MESSAGE_ENC_QUOTED_PRINTABLE; |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | * |
299 | 299 | * @return bool |
300 | 300 | */ |
301 | - public function isAttachment(){ |
|
301 | + public function isAttachment() { |
|
302 | 302 | $valid_disposition = in_array(strtolower($this->disposition), ClientManager::get('options.dispositions')); |
303 | 303 | |
304 | 304 | if ($this->type == IMAP::MESSAGE_TYPE_TEXT && ($this->ifdisposition == 0 || empty($this->disposition) || !$valid_disposition)) { |