Skip to content

Commit 497bf56

Browse files
authored
Merge pull request #1480 from indridieinarsson/pr_fix_cache_bust
fix(backend): delete cached imap responses for servers that don't support SORT extension
2 parents 3e53dcb + 91e1a6f commit 497bf56

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

modules/imap/hm-imap-cache.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@
1212
*/
1313
class Hm_IMAP_Cache extends Hm_IMAP_Parser {
1414

15+
/**
16+
* Store the imap command used to fetch a sorted message list in absence of
17+
* the SORT imap extension. This needs to be removed from cache in some cases.
18+
*/
19+
public function set_fetch_command($newval){
20+
$newval = str_replace(array("\r", "\n"), array(''), preg_replace("/^A\d+ /", '', $newval));
21+
$this->cache_data['INTERNAL_CYPHT_USE']['SORT_BY_FETCH'] = $newval;
22+
}
23+
public function get_fetch_command(){
24+
if (isset($this->cache_data['INTERNAL_CYPHT_USE'])){
25+
if (isset($this->cache_data['INTERNAL_CYPHT_USE']['SORT_BY_FETCH'])){
26+
return $this->cache_data['INTERNAL_CYPHT_USE']['SORT_BY_FETCH'];
27+
}
28+
}
29+
return false;
30+
}
31+
1532
/**
1633
* update the cache untagged QRESYNC FETCH responses
1734
* @param array $data low level parsed IMAP response segment
@@ -273,6 +290,12 @@ public function bust_cache($type, $full=true) {
273290
unset($this->cache_data[$type][$command]);
274291
$this->debug[] = 'Partial cache flush: '.$command;
275292
}
293+
if ($this->get_fetch_command()) {
294+
if (mb_strstr($command, $this->get_fetch_command())){
295+
unset($this->cache_data[$type][$command]);
296+
$this->debug[] = 'Partial cache flush: '.$command;
297+
}
298+
}
276299
}
277300
}
278301
else {

modules/imap/hm-imap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,7 @@ public function sort_by_fetch($sort, $reverse, $filter, $uid_str=false) {
16531653
}
16541654
$command = $command1.$command2;
16551655
$cache_command = $command.(string)$reverse;
1656+
$this->set_fetch_command($cache_command);
16561657
$cache = $this->check_cache($cache_command);
16571658
if ($cache !== false) {
16581659
return $cache;

0 commit comments

Comments
 (0)