| | |
| | | $result = iil_C_Flag($this->conn, $mailbox, join(',', $uids), $flag); |
| | | |
| | | // reload message headers if cached |
| | | $cache_key = $mailbox.'.msg'; |
| | | if ($this->caching_enabled) |
| | | { |
| | | $cache_key = $mailbox.'.msg'; |
| | | $this->remove_message_cache($cache_key, $uids); |
| | | |
| | | // close and re-open connection |
| | |
| | | } |
| | | // update cached message headers |
| | | $cache_key = $from_mbox.'.msg'; |
| | | if ($moved && ($a_cache_index = $this->get_message_cache_index($cache_key))) |
| | | { |
| | | $start_index = 100000; |
| | | foreach ($a_uids as $uid) |
| | | { |
| | | if (($index = array_search($uid, $a_cache_index)) !== FALSE) |
| | | $start_index = min($index, $start_index); |
| | | } |
| | | |
| | | if ($moved && $start_index = $this->get_message_cache_index_min($cache_key, $a_uids)) { |
| | | // clear cache from the lowest index on |
| | | if ($start_index < 100000) |
| | | $this->clear_message_cache($cache_key, $start_index); |
| | | $this->clear_message_cache($cache_key, $start_index); |
| | | } |
| | | |
| | | return $moved; |
| | |
| | | |
| | | // remove deleted messages from cache |
| | | $cache_key = $mailbox.'.msg'; |
| | | if ($deleted && ($a_cache_index = $this->get_message_cache_index($cache_key))) |
| | | { |
| | | $start_index = 100000; |
| | | foreach ($a_uids as $uid) |
| | | { |
| | | if (($index = array_search($uid, $a_cache_index)) !== FALSE) |
| | | $start_index = min($index, $start_index); |
| | | } |
| | | |
| | | if ($deleted && $start_index = $this->get_message_cache_index_min($cache_key, $a_uids)) { |
| | | // clear cache from the lowest index on |
| | | if ($start_index < 100000) |
| | | $this->clear_message_cache($cache_key, $start_index); |
| | | $this->clear_message_cache($cache_key, $start_index); |
| | | } |
| | | |
| | | return $deleted; |
| | |
| | | // read cache |
| | | if (!isset($this->cache[$key]) && $this->caching_enabled) |
| | | { |
| | | $cache_data = $this->_read_cache_record('IMAP.'.$key); |
| | | $this->cache[$key] = strlen($cache_data) ? unserialize($cache_data) : FALSE; |
| | | return $this->_read_cache_record($key); |
| | | } |
| | | |
| | | return $this->cache[$key]; |
| | |
| | | foreach ($this->cache as $key => $data) |
| | | { |
| | | if ($this->cache_changes[$key]) |
| | | $this->_write_cache_record('IMAP.'.$key, serialize($data)); |
| | | $this->_write_cache_record($key, serialize($data)); |
| | | } |
| | | } |
| | | } |
| | |
| | | if ($key===NULL) |
| | | { |
| | | foreach ($this->cache as $key => $data) |
| | | $this->_clear_cache_record('IMAP.'.$key); |
| | | $this->_clear_cache_record($key); |
| | | |
| | | $this->cache = array(); |
| | | $this->cache_changed = FALSE; |
| | |
| | | } |
| | | else |
| | | { |
| | | $this->_clear_cache_record('IMAP.'.$key); |
| | | $this->_clear_cache_record($key); |
| | | $this->cache_changes[$key] = FALSE; |
| | | unset($this->cache[$key]); |
| | | } |
| | |
| | | */ |
| | | function _read_cache_record($key) |
| | | { |
| | | $cache_data = FALSE; |
| | | |
| | | if ($this->db) |
| | | { |
| | | // get cached data from DB |
| | | $sql_result = $this->db->query( |
| | | "SELECT cache_id, data |
| | | "SELECT cache_id, data, cache_key |
| | | FROM ".get_table_name('cache')." |
| | | WHERE user_id=? |
| | | AND cache_key=?", |
| | | $_SESSION['user_id'], |
| | | $key); |
| | | AND cache_key LIKE 'IMAP.%'", |
| | | $_SESSION['user_id']); |
| | | |
| | | if ($sql_arr = $this->db->fetch_assoc($sql_result)) |
| | | while ($sql_arr = $this->db->fetch_assoc($sql_result)) |
| | | { |
| | | $cache_data = $sql_arr['data']; |
| | | $this->cache_keys[$key] = $sql_arr['cache_id']; |
| | | $sql_key = preg_replace('/^IMAP\./', '', $sql_arr['cache_key']); |
| | | $this->cache_keys[$sql_key] = $sql_arr['cache_id']; |
| | | $this->cache[$sql_key] = $sql_arr['data'] ? unserialize($sql_arr['data']) : FALSE; |
| | | } |
| | | } |
| | | |
| | | return $cache_data; |
| | | return $this->cache[$key]; |
| | | } |
| | | |
| | | /** |
| | |
| | | WHERE user_id=? |
| | | AND cache_key=?", |
| | | $_SESSION['user_id'], |
| | | $key); |
| | | 'IMAP.'.$key); |
| | | |
| | | if ($sql_arr = $this->db->fetch_assoc($sql_result)) |
| | | $this->cache_keys[$key] = $sql_arr['cache_id']; |
| | |
| | | AND cache_key=?", |
| | | $data, |
| | | $_SESSION['user_id'], |
| | | $key); |
| | | 'IMAP.'.$key); |
| | | } |
| | | // add new cache record |
| | | else |
| | |
| | | (created, user_id, cache_key, data) |
| | | VALUES (".$this->db->now().", ?, ?, ?)", |
| | | $_SESSION['user_id'], |
| | | $key, |
| | | 'IMAP.'.$key, |
| | | $data); |
| | | } |
| | | } |
| | |
| | | WHERE user_id=? |
| | | AND cache_key=?", |
| | | $_SESSION['user_id'], |
| | | $key); |
| | | 'IMAP.'.$key); |
| | | } |
| | | |
| | | |
| | |
| | | $start_index); |
| | | } |
| | | |
| | | /** |
| | | * @access private |
| | | */ |
| | | function get_message_cache_index_min($key, $uids=NULL) |
| | | { |
| | | if (!$this->caching_enabled) |
| | | return; |
| | | |
| | | $sql_result = $this->db->query( |
| | | "SELECT MIN(idx) AS minidx |
| | | FROM ".get_table_name('messages')." |
| | | WHERE user_id=? |
| | | AND cache_key=?" |
| | | .(!empty($uids) ? " AND uid IN (".$this->db->array2list($uids, 'integer').")" : ''), |
| | | $_SESSION['user_id'], |
| | | $key); |
| | | |
| | | if ($sql_arr = $this->db->fetch_assoc($sql_result)) |
| | | return $sql_arr['minidx']; |
| | | else |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | /* -------------------------------- |