Skip to content

Commit

Permalink
ZP-1561 BackendIMAP: use imap_search() to detect changes of "star" me…
Browse files Browse the repository at this point in the history
…ssages. Released under the Affero GNU General Public License (AGPL) version 3.
  • Loading branch information
bob4os committed Jul 15, 2020
1 parent 76c42c8 commit e949ad7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/backend/imap/imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,19 +691,27 @@ public function ChangesSink($timeout = 30) {
throw new StatusException("BackendIMAP->ChangesSink(): HierarchySync required.", SyncCollections::HIERARCHY_CHANGED);
}

$flaggedMessages = array();

// only check once to reduce pressure in the IMAP server
foreach ($this->sinkfolders as $i => $imapid) {
$this->imap_reopen_folder($imapid);

// courier-imap only clears the status cache after checking
@imap_check($this->mbox);

// get count of recent, unseen and overall messages
$status = @imap_status($this->mbox, $this->server . $imapid, SA_ALL);

// get count of flagged messages (ZP-1561)
$flaggedMessages = @imap_search($this->mbox, 'FLAGGED');
$flaggedMessages = (is_array($flaggedMessages) && $flaggedMessages !== false) ? count($flaggedMessages) : 0;

if (!$status) {
ZLog::Write(LOGLEVEL_WARN, sprintf("ChangesSink: could not stat folder '%s': %s ", $this->getFolderIdFromImapId($imapid), imap_last_error()));
}
else {
$newstate = "M:". $status->messages ."-R:". $status->recent ."-U:". $status->unseen;
$newstate = "M:". $status->messages ."-R:". $status->recent ."-U:". $status->unseen ."-F:". $flaggedMessages;

if (! isset($this->sinkstates[$imapid]) ) {
$this->sinkstates[$imapid] = $newstate;
Expand Down

0 comments on commit e949ad7

Please sign in to comment.