Skip to content

Commit 27d911c

Browse files
authored
ImapProtocol: Add STATUS command support. (Webklex#424)
This library currently contains some functions that purport to get the status of a folder, but these are misleading because they issue the EXAMINE command, not the STATUS command. This library actually currently lacks support for the STATUS command, and this command may be necessary to get some information that the EXAMINE command will not provide. This adds support for STATUS at the protocol level and the folder level, and clarifies the difference in the documentation.
1 parent cf32a9d commit 27d911c

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/Connection/Protocols/ImapProtocol.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,25 @@ public function getCapabilities(): Response {
536536
return $response->setResult($response->validatedData()[0]);
537537
}
538538

539+
/**
540+
* Get an array of available STATUS items
541+
*
542+
* @return Response list of STATUS items
543+
*
544+
* @throws ImapBadRequestException
545+
* @throws ImapServerErrorException
546+
* @throws RuntimeException
547+
* @throws ResponseException
548+
*/
549+
public function getStatus(): Response {
550+
$s = implode(" ", $properties);
551+
$response = $this->requestAndResponse('STATUS', array($this->escapeString($folder), "(" . $s . ")"));
552+
553+
if (!$response->getResponse()) return $response;
554+
555+
return $response->setResult($response->validatedData()[0]);
556+
}
557+
539558
/**
540559
* Examine and select have the same response.
541560
* @param string $command can be 'EXAMINE' or 'SELECT'

src/Folder.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,30 @@ public function idle(callable $callback, int $timeout = 300): void {
491491
}
492492
}
493493

494-
/**
495-
* Get folder status information
494+
/**
495+
* Get the standard folder status items from STATUS command
496+
*
497+
* @return array
498+
* @throws ConnectionFailedException
499+
* @throws ImapbadRequestException
500+
* @throws ImapServerErrorException
501+
* @throws RuntimeException
502+
* @throws AuthFailedException
503+
* @throws ResponseException
504+
*/
505+
public function getFolderStatus(string $folder, array $properties): array {
506+
$status = $client->getConnection()->getStatus($folder->full_name, array('MESSAGES', 'UNSEEN', 'RECENT', 'UIDNEXT', 'UIDVALIDITY'))->validatedData();
507+
$c = count($status[2]);
508+
$s = array();
509+
for ($i = 0; $i < $c; $i++) {
510+
$a = $i++;
511+
$s[$status[2][$a]] = $status[2][$i];
512+
}
513+
return $s;
514+
}
515+
516+
/**
517+
* Get folder status information from the EXAMINE command
496518
*
497519
* @return array
498520
* @throws ConnectionFailedException

0 commit comments

Comments
 (0)