@@ -16,7 +16,7 @@ |
||
| 16 | 16 | * New custom method which can be called through a mask |
| 17 | 17 | * @return string |
| 18 | 18 | */ |
| 19 | - public function my_token(){ |
|
| 19 | + public function my_token() { |
|
| 20 | 20 | return implode('-', [$this->message_id, $this->uid, $this->message_no]); |
| 21 | 21 | } |
| 22 | 22 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | public function __construct(Client $client, $charset = 'UTF-8') { |
| 70 | 70 | $this->setClient($client); |
| 71 | 71 | |
| 72 | - if(config('imap.options.fetch') === IMAP::FT_PEEK) $this->leaveUnread(); |
|
| 72 | + if (config('imap.options.fetch') === IMAP::FT_PEEK) $this->leaveUnread(); |
|
| 73 | 73 | |
| 74 | 74 | $this->date_format = config('imap.date_format', 'd M y'); |
| 75 | 75 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | /** |
| 82 | 82 | * Instance boot method for additional functionality |
| 83 | 83 | */ |
| 84 | - protected function boot(){} |
|
| 84 | + protected function boot() {} |
|
| 85 | 85 | |
| 86 | 86 | /** |
| 87 | 87 | * Parse a given value |
@@ -89,8 +89,8 @@ discard block |
||
| 89 | 89 | * |
| 90 | 90 | * @return string |
| 91 | 91 | */ |
| 92 | - protected function parse_value($value){ |
|
| 93 | - switch(true){ |
|
| 92 | + protected function parse_value($value) { |
|
| 93 | + switch (true) { |
|
| 94 | 94 | case $value instanceof \Carbon\Carbon: |
| 95 | 95 | $value = $value->format($this->date_format); |
| 96 | 96 | break; |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * @throws MessageSearchValidationException |
| 108 | 108 | */ |
| 109 | 109 | protected function parse_date($date) { |
| 110 | - if($date instanceof \Carbon\Carbon) return $date; |
|
| 110 | + if ($date instanceof \Carbon\Carbon) return $date; |
|
| 111 | 111 | |
| 112 | 112 | try { |
| 113 | 113 | $date = Carbon::parse($date); |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | * @return \Illuminate\Support\Collection |
| 147 | 147 | * @throws \Webklex\IMAP\Exceptions\ConnectionFailedException |
| 148 | 148 | */ |
| 149 | - protected function search(){ |
|
| 149 | + protected function search() { |
|
| 150 | 150 | $this->generate_query(); |
| 151 | 151 | $available_messages = []; |
| 152 | 152 | |
@@ -159,14 +159,14 @@ discard block |
||
| 159 | 159 | try { |
| 160 | 160 | if ($this->getCharset() == null) { |
| 161 | 161 | $available_messages = \imap_search($this->getClient()->getConnection(), $this->getRawQuery(), IMAP::SE_UID); |
| 162 | - }else{ |
|
| 162 | + } else { |
|
| 163 | 163 | $available_messages = \imap_search($this->getClient()->getConnection(), $this->getRawQuery(), IMAP::SE_UID, $this->getCharset()); |
| 164 | 164 | } |
| 165 | 165 | } catch (\Exception $e) { |
| 166 | 166 | if (strpos($e, ' [BADCHARSET (')) { |
| 167 | 167 | preg_match('/ \[BADCHARSET \((.*)\)\]/', $e, $matches); |
| 168 | 168 | if (isset($matches[1])) { |
| 169 | - if ($matches[1] !== $this->getCharset()){ |
|
| 169 | + if ($matches[1] !== $this->getCharset()) { |
|
| 170 | 170 | $this->setCharset($matches[1]); |
| 171 | 171 | return $this->search(); |
| 172 | 172 | } |
@@ -210,15 +210,15 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | $options = config('imap.options'); |
| 212 | 212 | |
| 213 | - if(strtolower($options['fetch_order']) === 'desc'){ |
|
| 213 | + if (strtolower($options['fetch_order']) === 'desc') { |
|
| 214 | 214 | $available_messages = $available_messages->reverse(); |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - $query =& $this; |
|
| 217 | + $query = & $this; |
|
| 218 | 218 | |
| 219 | 219 | $available_messages->forPage($this->page, $this->limit)->each(function($msgno, $msglist) use(&$messages, $options, $query) { |
| 220 | 220 | $oMessage = new Message($msgno, $msglist, $query->getClient(), $query->getFetchOptions(), $query->getFetchBody(), $query->getFetchAttachment(), $query->getFetchFlags()); |
| 221 | - switch ($options['message_key']){ |
|
| 221 | + switch ($options['message_key']) { |
|
| 222 | 222 | case 'number': |
| 223 | 223 | $message_key = $oMessage->getMessageNo(); |
| 224 | 224 | break; |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | * @return \Illuminate\Pagination\LengthAwarePaginator |
| 250 | 250 | * @throws GetMessagesFailedException |
| 251 | 251 | */ |
| 252 | - public function paginate($per_page = 5, $page = null, $page_name = 'imap_page'){ |
|
| 252 | + public function paginate($per_page = 5, $page = null, $page_name = 'imap_page') { |
|
| 253 | 253 | $this->page = $page > $this->page ? $page : $this->page; |
| 254 | 254 | $this->limit = $per_page; |
| 255 | 255 | |
@@ -264,13 +264,13 @@ discard block |
||
| 264 | 264 | * @throws \Webklex\IMAP\Exceptions\ConnectionFailedException |
| 265 | 265 | * @throws \Webklex\IMAP\Exceptions\InvalidMessageDateException |
| 266 | 266 | */ |
| 267 | - public function idle(callable $callback = null, $timeout = 10){ |
|
| 267 | + public function idle(callable $callback = null, $timeout = 10) { |
|
| 268 | 268 | $known_messages = []; |
| 269 | 269 | $this->getClient()->overview()->each(function($message) use(&$known_messages){ |
| 270 | 270 | /** @var object $message */ |
| 271 | 271 | $known_messages[] = $message->uid; |
| 272 | 272 | }); |
| 273 | - while ($this->getClient()->isConnected()){ |
|
| 273 | + while ($this->getClient()->isConnected()) { |
|
| 274 | 274 | $this->getClient()->expunge(); |
| 275 | 275 | $new_messages = []; |
| 276 | 276 | $this->getClient()->overview()->each(function($message) use(&$new_messages, &$known_messages){ |
@@ -281,10 +281,10 @@ discard block |
||
| 281 | 281 | } |
| 282 | 282 | }); |
| 283 | 283 | |
| 284 | - foreach($new_messages as $msg) { |
|
| 284 | + foreach ($new_messages as $msg) { |
|
| 285 | 285 | $message = new Message($msg->uid, $msg->msgno, $this->getClient()); |
| 286 | 286 | MessageNewEvent::dispatch($message); |
| 287 | - if ($callback){ |
|
| 287 | + if ($callback) { |
|
| 288 | 288 | $callback($message); |
| 289 | 289 | } |
| 290 | 290 | } |
@@ -304,9 +304,9 @@ discard block |
||
| 304 | 304 | if (count($statement) == 1) { |
| 305 | 305 | $query .= $statement[0]; |
| 306 | 306 | } else { |
| 307 | - if($statement[1] === null){ |
|
| 307 | + if ($statement[1] === null) { |
|
| 308 | 308 | $query .= $statement[0]; |
| 309 | - }else{ |
|
| 309 | + } else { |
|
| 310 | 310 | $query .= $statement[0].' "'.$statement[1].'"'; |
| 311 | 311 | } |
| 312 | 312 | } |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | * @return $this |
| 337 | 337 | */ |
| 338 | 338 | public function limit($limit, $page = 1) { |
| 339 | - if($page >= 1) $this->page = $page; |
|
| 339 | + if ($page >= 1) $this->page = $page; |
|
| 340 | 340 | $this->limit = $limit; |
| 341 | 341 | |
| 342 | 342 | return $this; |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | public function __construct($uid, $msglist, Client $client, $fetch_options = null, $fetch_body = null, $fetch_attachment = null, $fetch_flags = null) { |
| 208 | 208 | |
| 209 | 209 | $default_mask = $client->getDefaultMessageMask(); |
| 210 | - if($default_mask != null) { |
|
| 210 | + if ($default_mask != null) { |
|
| 211 | 211 | $this->mask = $default_mask; |
| 212 | 212 | } |
| 213 | 213 | |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | $this->msglist = $msglist; |
| 227 | 227 | $this->client = $client; |
| 228 | 228 | |
| 229 | - $this->uid = $uid; |
|
| 229 | + $this->uid = $uid; |
|
| 230 | 230 | $this->msgn = ($this->fetch_options == IMAP::FT_UID) ? \imap_msgno($this->client->getConnection(), $uid) : $uid; |
| 231 | 231 | |
| 232 | 232 | $this->parseHeader(); |
@@ -249,17 +249,17 @@ discard block |
||
| 249 | 249 | * @throws MethodNotFoundException |
| 250 | 250 | */ |
| 251 | 251 | public function __call($method, $arguments) { |
| 252 | - if(strtolower(substr($method, 0, 3)) === 'get') { |
|
| 252 | + if (strtolower(substr($method, 0, 3)) === 'get') { |
|
| 253 | 253 | $name = Str::snake(substr($method, 3)); |
| 254 | 254 | |
| 255 | - if(in_array($name, array_keys($this->attributes))) { |
|
| 255 | + if (in_array($name, array_keys($this->attributes))) { |
|
| 256 | 256 | return $this->attributes[$name]; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | }elseif (strtolower(substr($method, 0, 3)) === 'set') { |
| 260 | 260 | $name = Str::snake(substr($method, 3)); |
| 261 | 261 | |
| 262 | - if(in_array($name, array_keys($this->attributes))) { |
|
| 262 | + if (in_array($name, array_keys($this->attributes))) { |
|
| 263 | 263 | $this->attributes[$name] = array_pop($arguments); |
| 264 | 264 | |
| 265 | 265 | return $this->attributes[$name]; |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | * @return mixed|null |
| 289 | 289 | */ |
| 290 | 290 | public function __get($name) { |
| 291 | - if(isset($this->attributes[$name])) { |
|
| 291 | + if (isset($this->attributes[$name])) { |
|
| 292 | 292 | return $this->attributes[$name]; |
| 293 | 293 | } |
| 294 | 294 | |
@@ -384,19 +384,19 @@ discard block |
||
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | if (property_exists($header, 'subject')) { |
| 387 | - if($this->config['decoder']['message']['subject'] === 'utf-8') { |
|
| 387 | + if ($this->config['decoder']['message']['subject'] === 'utf-8') { |
|
| 388 | 388 | $this->subject = \imap_utf8($header->subject); |
| 389 | 389 | if (Str::startsWith(mb_strtolower($this->subject), '=?utf-8?')) { |
| 390 | 390 | $this->subject = mb_decode_mimeheader($header->subject); |
| 391 | 391 | } |
| 392 | - }elseif($this->config['decoder']['message']['subject'] === 'iconv') { |
|
| 392 | + }elseif ($this->config['decoder']['message']['subject'] === 'iconv') { |
|
| 393 | 393 | $this->subject = iconv_mime_decode($header->subject); |
| 394 | - }else{ |
|
| 394 | + } else { |
|
| 395 | 395 | $this->subject = mb_decode_mimeheader($header->subject); |
| 396 | 396 | } |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | - foreach(['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $part){ |
|
| 399 | + foreach (['from', 'to', 'cc', 'bcc', 'reply_to', 'sender'] as $part) { |
|
| 400 | 400 | $this->extractHeaderAddressPart($header, $part); |
| 401 | 401 | } |
| 402 | 402 | |
@@ -426,9 +426,9 @@ discard block |
||
| 426 | 426 | * @return int|null |
| 427 | 427 | */ |
| 428 | 428 | private function extractPriority($header) { |
| 429 | - if(preg_match('/x\-priority\:.*([0-9]{1,2})/i', $header, $priority)){ |
|
| 429 | + if (preg_match('/x\-priority\:.*([0-9]{1,2})/i', $header, $priority)) { |
|
| 430 | 430 | $priority = isset($priority[1]) ? (int) $priority[1] : 0; |
| 431 | - switch($priority){ |
|
| 431 | + switch ($priority) { |
|
| 432 | 432 | case IMAP::MESSAGE_PRIORITY_HIGHEST; |
| 433 | 433 | $priority = IMAP::MESSAGE_PRIORITY_HIGHEST; |
| 434 | 434 | break; |
@@ -479,7 +479,7 @@ discard block |
||
| 479 | 479 | if (property_exists($header, 'date')) { |
| 480 | 480 | $date = $header->date; |
| 481 | 481 | |
| 482 | - if(preg_match('/\+0580/', $date)) { |
|
| 482 | + if (preg_match('/\+0580/', $date)) { |
|
| 483 | 483 | $date = str_replace('+0580', '+0530', $date); |
| 484 | 484 | } |
| 485 | 485 | |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | $date = trim(array_pop($array)); |
| 503 | 503 | break; |
| 504 | 504 | } |
| 505 | - try{ |
|
| 505 | + try { |
|
| 506 | 506 | $parsed_date = Carbon::parse($date); |
| 507 | 507 | } catch (\Exception $_e) { |
| 508 | 508 | throw new InvalidMessageDateException("Invalid message date. ID:".$this->getMessageId(), 1100, $e); |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | $this->client->openFolder($this->folder_path); |
| 526 | 526 | $flags = \imap_fetch_overview($this->client->getConnection(), $this->uid, IMAP::FT_UID); |
| 527 | 527 | if (is_array($flags) && isset($flags[0])) { |
| 528 | - foreach($this->available_flags as $flag) { |
|
| 528 | + foreach ($this->available_flags as $flag) { |
|
| 529 | 529 | $this->parseFlag($flags, $flag); |
| 530 | 530 | } |
| 531 | 531 | } |
@@ -597,7 +597,7 @@ discard block |
||
| 597 | 597 | } else { |
| 598 | 598 | $personalParts = \imap_mime_header_decode($address->personal); |
| 599 | 599 | |
| 600 | - if(is_array($personalParts)) { |
|
| 600 | + if (is_array($personalParts)) { |
|
| 601 | 601 | $address->personal = ''; |
| 602 | 602 | foreach ($personalParts as $p) { |
| 603 | 603 | $address->personal .= $this->convertEncoding($p->text, $this->getEncoding($p)); |
@@ -675,7 +675,7 @@ discard block |
||
| 675 | 675 | * @return object |
| 676 | 676 | * @throws Exceptions\ConnectionFailedException |
| 677 | 677 | */ |
| 678 | - private function createBody($type, $structure, $partNumber){ |
|
| 678 | + private function createBody($type, $structure, $partNumber) { |
|
| 679 | 679 | return (object) [ |
| 680 | 680 | "type" => $type, |
| 681 | 681 | "content" => $this->fetchPart($structure, $partNumber), |
@@ -690,7 +690,7 @@ discard block |
||
| 690 | 690 | * @return mixed|string |
| 691 | 691 | * @throws Exceptions\ConnectionFailedException |
| 692 | 692 | */ |
| 693 | - private function fetchPart($structure, $partNumber){ |
|
| 693 | + private function fetchPart($structure, $partNumber) { |
|
| 694 | 694 | $encoding = $this->getEncoding($structure); |
| 695 | 695 | |
| 696 | 696 | if (!$partNumber) { |
@@ -904,7 +904,7 @@ discard block |
||
| 904 | 904 | } |
| 905 | 905 | }elseif (property_exists($structure, 'charset')) { |
| 906 | 906 | return EncodingAliases::get($structure->charset, $this->fallback_encoding); |
| 907 | - }elseif (is_string($structure) === true){ |
|
| 907 | + }elseif (is_string($structure) === true) { |
|
| 908 | 908 | return mb_detect_encoding($structure); |
| 909 | 909 | } |
| 910 | 910 | |
@@ -954,7 +954,7 @@ discard block |
||
| 954 | 954 | return null; |
| 955 | 955 | } |
| 956 | 956 | |
| 957 | - public function getFolder(){ |
|
| 957 | + public function getFolder() { |
|
| 958 | 958 | return $this->client->getFolder($this->folder_path); |
| 959 | 959 | } |
| 960 | 960 | |
@@ -970,7 +970,7 @@ discard block |
||
| 970 | 970 | */ |
| 971 | 971 | public function moveToFolder($mailbox = 'INBOX', $expunge = false, $create_folder = true) { |
| 972 | 972 | |
| 973 | - if($create_folder) $this->client->createFolder($mailbox, true); |
|
| 973 | + if ($create_folder) $this->client->createFolder($mailbox, true); |
|
| 974 | 974 | |
| 975 | 975 | $target_folder = $this->client->getFolder($mailbox); |
| 976 | 976 | $target_status = $target_folder->getStatus(IMAP::SA_ALL); |
@@ -978,8 +978,8 @@ discard block |
||
| 978 | 978 | $this->client->openFolder($this->folder_path); |
| 979 | 979 | $status = \imap_mail_move($this->client->getConnection(), $this->uid, $mailbox, IMAP::CP_UID); |
| 980 | 980 | |
| 981 | - if($status === true){ |
|
| 982 | - if($expunge) $this->client->expunge(); |
|
| 981 | + if ($status === true) { |
|
| 982 | + if ($expunge) $this->client->expunge(); |
|
| 983 | 983 | $this->client->openFolder($target_folder->path); |
| 984 | 984 | |
| 985 | 985 | $message = $target_folder->getMessage($target_status->uidnext, null, $this->fetch_options, $this->fetch_body, $this->fetch_attachment, $this->fetch_flags); |
@@ -1001,7 +1001,7 @@ discard block |
||
| 1001 | 1001 | $this->client->openFolder($this->folder_path); |
| 1002 | 1002 | |
| 1003 | 1003 | $status = \imap_delete($this->client->getConnection(), $this->uid, IMAP::FT_UID); |
| 1004 | - if($expunge) $this->client->expunge(); |
|
| 1004 | + if ($expunge) $this->client->expunge(); |
|
| 1005 | 1005 | MessageDeletedEvent::dispatch($this); |
| 1006 | 1006 | |
| 1007 | 1007 | return $status; |
@@ -1018,7 +1018,7 @@ discard block |
||
| 1018 | 1018 | $this->client->openFolder($this->folder_path); |
| 1019 | 1019 | |
| 1020 | 1020 | $status = \imap_undelete($this->client->getConnection(), $this->uid, IMAP::FT_UID); |
| 1021 | - if($expunge) $this->client->expunge(); |
|
| 1021 | + if ($expunge) $this->client->expunge(); |
|
| 1022 | 1022 | MessageRestoredEvent::dispatch($this); |
| 1023 | 1023 | |
| 1024 | 1024 | return $status; |
@@ -1095,7 +1095,7 @@ discard block |
||
| 1095 | 1095 | * @return string |
| 1096 | 1096 | * @throws Exceptions\ConnectionFailedException |
| 1097 | 1097 | */ |
| 1098 | - public function getToken(){ |
|
| 1098 | + public function getToken() { |
|
| 1099 | 1099 | return base64_encode(implode('-', [$this->message_id, $this->subject, strlen($this->getRawBody())])); |
| 1100 | 1100 | } |
| 1101 | 1101 | |
@@ -1158,7 +1158,7 @@ discard block |
||
| 1158 | 1158 | /** |
| 1159 | 1159 | * @return object|null |
| 1160 | 1160 | */ |
| 1161 | - public function getStructure(){ |
|
| 1161 | + public function getStructure() { |
|
| 1162 | 1162 | return $this->structure; |
| 1163 | 1163 | } |
| 1164 | 1164 | |
@@ -1182,7 +1182,7 @@ discard block |
||
| 1182 | 1182 | /** |
| 1183 | 1183 | * @return array |
| 1184 | 1184 | */ |
| 1185 | - public function getAttributes(){ |
|
| 1185 | + public function getAttributes() { |
|
| 1186 | 1186 | return $this->attributes; |
| 1187 | 1187 | } |
| 1188 | 1188 | |
@@ -1190,8 +1190,8 @@ discard block |
||
| 1190 | 1190 | * @param $mask |
| 1191 | 1191 | * @return $this |
| 1192 | 1192 | */ |
| 1193 | - public function setMask($mask){ |
|
| 1194 | - if(class_exists($mask)){ |
|
| 1193 | + public function setMask($mask) { |
|
| 1194 | + if (class_exists($mask)) { |
|
| 1195 | 1195 | $this->mask = $mask; |
| 1196 | 1196 | } |
| 1197 | 1197 | |
@@ -1201,7 +1201,7 @@ discard block |
||
| 1201 | 1201 | /** |
| 1202 | 1202 | * @return string |
| 1203 | 1203 | */ |
| 1204 | - public function getMask(){ |
|
| 1204 | + public function getMask() { |
|
| 1205 | 1205 | return $this->mask; |
| 1206 | 1206 | } |
| 1207 | 1207 | |
@@ -1212,9 +1212,9 @@ discard block |
||
| 1212 | 1212 | * @return mixed |
| 1213 | 1213 | * @throws MaskNotFoundException |
| 1214 | 1214 | */ |
| 1215 | - public function mask($mask = null){ |
|
| 1215 | + public function mask($mask = null) { |
|
| 1216 | 1216 | $mask = $mask !== null ? $mask : $this->mask; |
| 1217 | - if(class_exists($mask)){ |
|
| 1217 | + if (class_exists($mask)) { |
|
| 1218 | 1218 | return new $mask($this); |
| 1219 | 1219 | } |
| 1220 | 1220 | |