Skip to content

Commit

Permalink
Idle operation updated #44
Browse files Browse the repository at this point in the history
  • Loading branch information
Webklex committed Dec 11, 2020
1 parent 5fd862b commit 1852eae
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
- Missing array decoder method added #51 (thanks [@lutchin](https://github.com/lutchin))
- Additional checks added to prevent message from getting marked as seen #33
- Boundary parsing improved #39 #36 (thanks [@AntonioDiPassio-AppSys](https://github.com/AntonioDiPassio-AppSys))
- Idle operation updated #44

### Added
- Force a folder to be opened
Expand Down
9 changes: 3 additions & 6 deletions src/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,17 +353,19 @@ public function idle(callable $callback, $timeout = 1200) {
$this->client->getConnection()->setConnectionTimeout($timeout);

$this->client->reconnect();
$this->client->openFolder($this->path);
$this->client->openFolder($this->path, true);
$connection = $this->client->getConnection();
$connection->idle();

while (true) {
try {
$line = $connection->nextLine();
var_dump($line);
if (($pos = strpos($line, "EXISTS")) !== false) {
$msgn = (int) substr($line, 2, $pos -2);
$connection->done();

$this->client->openFolder($this->path, true);
$message = $this->query()->getMessage($msgn);
$callback($message);

Expand All @@ -375,11 +377,6 @@ public function idle(callable $callback, $timeout = 1200) {
}catch (Exceptions\RuntimeException $e) {
if(strpos($e->getMessage(), "connection closed") === false) {
throw $e;
}else{
$this->client->connect();
$this->client->openFolder($this->path);
$connection = $this->client->getConnection();
$connection->idle();
}
}
}
Expand Down

0 comments on commit 1852eae

Please sign in to comment.