diff --git a/plugins/libkolab/lib/kolab_storage.php b/plugins/libkolab/lib/kolab_storage.php index 17609393..a4868ac5 100644 --- a/plugins/libkolab/lib/kolab_storage.php +++ b/plugins/libkolab/lib/kolab_storage.php @@ -35,6 +35,11 @@ class kolab_storage const UID_KEY_PRIVATE = '/private/vendor/kolab/uniqueid'; const UID_KEY_CYRUS = '/shared/vendor/cmu/cyrus-imapd/uniqueid'; + const ERROR_IMAP_CONN = 1; + const ERROR_CACHE_DB = 2; + const ERROR_NO_PERMISSION = 3; + const ERROR_INVALID_FOLDER = 4; + public static $version = '3.0'; public static $last_error; public static $encode_ids = false; diff --git a/plugins/libkolab/lib/kolab_storage_cache.php b/plugins/libkolab/lib/kolab_storage_cache.php index 4f12df71..134631e7 100644 --- a/plugins/libkolab/lib/kolab_storage_cache.php +++ b/plugins/libkolab/lib/kolab_storage_cache.php @@ -48,6 +48,7 @@ class kolab_storage_cache protected $extra_cols = array(); protected $order_by = null; protected $limit = null; + protected $error = 0; /** @@ -149,6 +150,16 @@ class kolab_storage_cache return $this->folder_id; } + /** + * Returns code of last error + * + * @return int Error code + */ + public function get_error() + { + return $this->error; + } + /** * Synchronize local cache data with remote */ @@ -243,6 +254,7 @@ class kolab_storage_cache } } + $this->check_error(); $this->synched = time(); } @@ -288,6 +300,7 @@ class kolab_storage_cache } } + $this->check_error(); return $this->objects[$msguid]; } @@ -326,6 +339,8 @@ class kolab_storage_cache // ...or set in-memory cache to false $this->objects[$msguid] = $object; } + + $this->check_error(); } @@ -384,6 +399,8 @@ class kolab_storage_cache // keep a copy in memory for fast access $this->objects = array($msguid => $object); $this->uid2msg = array($object['uid'] => $msguid); + + $this->check_error(); } @@ -423,6 +440,7 @@ class kolab_storage_cache } unset($this->uid2msg[$uid]); + $this->check_error(); } @@ -465,6 +483,8 @@ class kolab_storage_cache $target->get_resource_uri(), $this->resource_uri ); + + $this->check_error(); } /** @@ -529,6 +549,7 @@ class kolab_storage_cache } if ($index->is_error()) { + $this->check_error(); if ($uids) { return null; } @@ -551,6 +572,8 @@ class kolab_storage_cache } } + $this->check_error(); + return $result; } @@ -593,6 +616,7 @@ class kolab_storage_cache } if ($index->is_error()) { + $this->check_error(); return null; } @@ -601,6 +625,7 @@ class kolab_storage_cache $count = $index->count(); } + $this->check_error(); return $count; } @@ -937,6 +962,7 @@ class kolab_storage_cache // abort if database is not set-up if ($this->db->is_error()) { + $this->check_error(); $this->ready = false; return; } @@ -975,6 +1001,22 @@ class kolab_storage_cache $this->synclock = false; } + /** + * Check IMAP connection error state + */ + protected function check_error() + { + if (($err_code = $this->imap->get_error_code()) < 0) { + $this->error = kolab_storage::ERROR_IMAP_CONN; + if (($res_code = $this->imap->get_response_code()) !== 0 && in_array($res_code, array(rcube_storage::NOPERM, rcube_storage::READONLY))) { + $this->error = kolab_storage::ERROR_NO_PERMISSION; + } + } + else if ($this->db->is_error()) { + $this->error = kolab_storage::ERROR_CACHE_DB; + } + } + /** * Resolve an object UID into an IMAP message UID * diff --git a/plugins/libkolab/lib/kolab_storage_folder.php b/plugins/libkolab/lib/kolab_storage_folder.php index 0e728a36..6c21ed48 100644 --- a/plugins/libkolab/lib/kolab_storage_folder.php +++ b/plugins/libkolab/lib/kolab_storage_folder.php @@ -36,7 +36,9 @@ class kolab_storage_folder extends kolab_storage_folder_api */ public $valid = false; - private $resource_uri; + protected $error = 0; + + protected $resource_uri; /** @@ -74,6 +76,10 @@ class kolab_storage_folder extends kolab_storage_folder_api $this->id = kolab_storage::folder_id($name); $this->valid = !empty($this->type) && $this->type != 'mail' && (!$type || $this->type == $type); + if (!$this->valid) { + $this->error = $this->imap->get_error_code() < 0 ? kolab_storage::ERROR_IMAP_CONN : kolab_storage::ERROR_INVALID_FOLDER; + } + // reset cached object properties $this->owner = $this->namespace = $this->resource_uri = $this->info = $this->idata = null; @@ -86,6 +92,15 @@ class kolab_storage_folder extends kolab_storage_folder_api $this->imap->set_folder($this->name); } + /** + * Returns code of last error + * + * @return int Error code + */ + public function get_error() + { + return $this->error ?: $this->cache->get_error(); + } /** * Compose a unique resource URI for this IMAP folder