@@ -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 | |
@@ -263,23 +263,23 @@ discard block  | 
                                                    ||
| 263 | 263 | * @throws GetMessagesFailedException  | 
                                                        
| 264 | 264 | * @throws \Webklex\IMAP\Exceptions\ConnectionFailedException  | 
                                                        
| 265 | 265 | */  | 
                                                        
| 266 | -    public function idle(callable $callback = null, $timeout = 10){ | 
                                                        |
| 266 | +    public function idle(callable $callback = null, $timeout = 10) { | 
                                                        |
| 267 | 267 | $known_messages = [];  | 
                                                        
| 268 | 268 |          $this->get()->each(function($message) use(&$known_messages){ | 
                                                        
| 269 | 269 | /** @var Message $message */  | 
                                                        
| 270 | 270 | $known_messages[] = $message->getToken();  | 
                                                        
| 271 | 271 | });  | 
                                                        
| 272 | -        while ($this->getClient()->isConnected()){ | 
                                                        |
| 272 | +        while ($this->getClient()->isConnected()) { | 
                                                        |
| 273 | 273 | $this->getClient()->expunge();  | 
                                                        
| 274 | 274 |              $this->get()->each(function($message) use(&$known_messages, $callback){ | 
                                                        
| 275 | 275 | /** @var \Webklex\IMAP\Message $message */  | 
                                                        
| 276 | 276 | $token = $message->getToken();  | 
                                                        
| 277 | -                if(in_array($token, $known_messages)){ | 
                                                        |
| 277 | +                if (in_array($token, $known_messages)) { | 
                                                        |
| 278 | 278 | return;  | 
                                                        
| 279 | 279 | }  | 
                                                        
| 280 | 280 | $known_messages[] = $token;  | 
                                                        
| 281 | 281 | MessageNewEvent::dispatch($message);  | 
                                                        
| 282 | -                if ($callback){ | 
                                                        |
| 282 | +                if ($callback) { | 
                                                        |
| 283 | 283 | $callback($message);  | 
                                                        
| 284 | 284 | }  | 
                                                        
| 285 | 285 | });  | 
                                                        
@@ -298,9 +298,9 @@ discard block  | 
                                                    ||
| 298 | 298 |              if (count($statement) == 1) { | 
                                                        
| 299 | 299 | $query .= $statement[0];  | 
                                                        
| 300 | 300 |              } else { | 
                                                        
| 301 | -                if($statement[1] === null){ | 
                                                        |
| 301 | +                if ($statement[1] === null) { | 
                                                        |
| 302 | 302 | $query .= $statement[0];  | 
                                                        
| 303 | -                }else{ | 
                                                        |
| 303 | +                } else { | 
                                                        |
| 304 | 304 | $query .= $statement[0].' "'.$statement[1].'"';  | 
                                                        
| 305 | 305 | }  | 
                                                        
| 306 | 306 | }  | 
                                                        
@@ -330,7 +330,7 @@ discard block  | 
                                                    ||
| 330 | 330 | * @return $this  | 
                                                        
| 331 | 331 | */  | 
                                                        
| 332 | 332 |      public function limit($limit, $page = 1) { | 
                                                        
| 333 | - if($page >= 1) $this->page = $page;  | 
                                                        |
| 333 | + if ($page >= 1) $this->page = $page;  | 
                                                        |
| 334 | 334 | $this->limit = $limit;  | 
                                                        
| 335 | 335 | |
| 336 | 336 | return $this;  | 
                                                        
@@ -69,7 +69,9 @@ 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) { | 
                                                        |
| 73 | + $this->leaveUnread();  | 
                                                        |
| 74 | + }  | 
                                                        |
| 73 | 75 | |
| 74 | 76 |          $this->date_format = config('imap.date_format', 'd M y'); | 
                                                        
| 75 | 77 | |
@@ -107,7 +109,9 @@ discard block  | 
                                                    ||
| 107 | 109 | * @throws MessageSearchValidationException  | 
                                                        
| 108 | 110 | */  | 
                                                        
| 109 | 111 |      protected function parse_date($date) { | 
                                                        
| 110 | - if($date instanceof \Carbon\Carbon) return $date;  | 
                                                        |
| 112 | +        if($date instanceof \Carbon\Carbon) { | 
                                                        |
| 113 | + return $date;  | 
                                                        |
| 114 | + }  | 
                                                        |
| 111 | 115 | |
| 112 | 116 |          try { | 
                                                        
| 113 | 117 | $date = Carbon::parse($date);  | 
                                                        
@@ -159,7 +163,7 @@ discard block  | 
                                                    ||
| 159 | 163 |          try { | 
                                                        
| 160 | 164 |              if ($this->getCharset() == null) { | 
                                                        
| 161 | 165 | $available_messages = \imap_search($this->getClient()->getConnection(), $this->getRawQuery(), IMAP::SE_UID);  | 
                                                        
| 162 | -            }else{ | 
                                                        |
| 166 | +            } else{ | 
                                                        |
| 163 | 167 | $available_messages = \imap_search($this->getClient()->getConnection(), $this->getRawQuery(), IMAP::SE_UID, $this->getCharset());  | 
                                                        
| 164 | 168 | }  | 
                                                        
| 165 | 169 |          } catch (\Exception $e) { | 
                                                        
@@ -300,7 +304,7 @@ discard block  | 
                                                    ||
| 300 | 304 |              } else { | 
                                                        
| 301 | 305 |                  if($statement[1] === null){ | 
                                                        
| 302 | 306 | $query .= $statement[0];  | 
                                                        
| 303 | -                }else{ | 
                                                        |
| 307 | +                } else{ | 
                                                        |
| 304 | 308 | $query .= $statement[0].' "'.$statement[1].'"';  | 
                                                        
| 305 | 309 | }  | 
                                                        
| 306 | 310 | }  | 
                                                        
@@ -330,7 +334,9 @@ discard block  | 
                                                    ||
| 330 | 334 | * @return $this  | 
                                                        
| 331 | 335 | */  | 
                                                        
| 332 | 336 |      public function limit($limit, $page = 1) { | 
                                                        
| 333 | - if($page >= 1) $this->page = $page;  | 
                                                        |
| 337 | +        if($page >= 1) { | 
                                                        |
| 338 | + $this->page = $page;  | 
                                                        |
| 339 | + }  | 
                                                        |
| 334 | 340 | $this->limit = $limit;  | 
                                                        
| 335 | 341 | |
| 336 | 342 | return $this;  |