- fix cache flushing after message delete with read_when_deleted=true + some code cleanup

release-0.6
alecpl 15 years ago
parent 4a63f1efaf
commit eb4b147bad

@ -811,20 +811,11 @@ class rcube_imap
foreach ($a_header_index as $i => $headers) foreach ($a_header_index as $i => $headers)
{ {
/*
if ($headers->deleted && $this->skip_deleted)
{
// delete from cache
if ($cache_index[$headers->id] && $cache_index[$headers->id] == $headers->uid)
$this->remove_message_cache($cache_key, $headers->uid);
continue;
}
*/
// add message to cache // add message to cache
if ($this->caching_enabled && $cache_index[$headers->id] != $headers->uid) if ($this->caching_enabled && $cache_index[$headers->id] != $headers->uid) {
$this->add_message_cache($cache_key, $headers->id, $headers, NULL, $this->add_message_cache($cache_key, $headers->id, $headers, NULL,
!in_array((string)$headers->uid, $cache_index, true)); !in_array($headers->uid, $cache_index));
}
$a_msg_headers[$headers->uid] = $headers; $a_msg_headers[$headers->uid] = $headers;
} }
@ -967,7 +958,7 @@ class rcube_imap
if ($headers = iil_C_FetchHeader($this->conn, $mailbox, join(',', $for_update), false, $this->fetch_add_headers)) if ($headers = iil_C_FetchHeader($this->conn, $mailbox, join(',', $for_update), false, $this->fetch_add_headers))
foreach ($headers as $header) foreach ($headers as $header)
$this->add_message_cache($cache_key, $header->id, $header, NULL, $this->add_message_cache($cache_key, $header->id, $header, NULL,
in_array((string)$header->uid, (array)$for_remove, true)); in_array($header->uid, (array)$for_remove));
} }
} }
@ -1533,9 +1524,10 @@ class rcube_imap
* @param mixed Message UIDs as array or as comma-separated string * @param mixed Message UIDs as array or as comma-separated string
* @param string Flag to set: SEEN, UNDELETED, DELETED, RECENT, ANSWERED, DRAFT, MDNSENT * @param string Flag to set: SEEN, UNDELETED, DELETED, RECENT, ANSWERED, DRAFT, MDNSENT
* @param string Folder name * @param string Folder name
* @param boolean True to skip message cache clean up
* @return boolean True on success, False on failure * @return boolean True on success, False on failure
*/ */
function set_flag($uids, $flag, $mbox_name=NULL) function set_flag($uids, $flag, $mbox_name=NULL, $skip_cache=false)
{ {
$mailbox = $mbox_name ? $this->mod_mailbox($mbox_name) : $this->mailbox; $mailbox = $mbox_name ? $this->mod_mailbox($mbox_name) : $this->mailbox;
@ -1549,14 +1541,9 @@ class rcube_imap
$result = iil_C_Flag($this->conn, $mailbox, join(',', $uids), $flag); $result = iil_C_Flag($this->conn, $mailbox, join(',', $uids), $flag);
// reload message headers if cached // reload message headers if cached
if ($this->caching_enabled) if ($this->caching_enabled && !$skip_cache) {
{
$cache_key = $mailbox.'.msg'; $cache_key = $mailbox.'.msg';
$this->remove_message_cache($cache_key, $uids); $this->remove_message_cache($cache_key, $uids);
// close and re-open connection
// this prevents connection problems with Courier
$this->reconnect();
} }
// set nr of messages that were flaged // set nr of messages that were flaged
@ -1624,6 +1611,8 @@ class rcube_imap
*/ */
function move_message($uids, $to_mbox, $from_mbox='') function move_message($uids, $to_mbox, $from_mbox='')
{ {
$fbox = $from_mbox;
$tbox = $to_mbox;
$to_mbox = $this->mod_mailbox($to_mbox); $to_mbox = $this->mod_mailbox($to_mbox);
$from_mbox = $from_mbox ? $this->mod_mailbox($from_mbox) : $this->mailbox; $from_mbox = $from_mbox ? $this->mod_mailbox($from_mbox) : $this->mailbox;
@ -1643,6 +1632,14 @@ class rcube_imap
if (!is_array($a_uids) || empty($a_uids)) if (!is_array($a_uids) || empty($a_uids))
return false; return false;
// flag messages as read before moving them
$config = rcmail::get_instance()->config;
if ($config->get('read_when_deleted') && $tbox == $config->get('trash_mbox')) {
// don't flush cache (4th argument)
$this->set_flag($uids, 'SEEN', $fbox, true);
}
// move messages
$iil_move = iil_C_Move($this->conn, join(',', $a_uids), $from_mbox, $to_mbox); $iil_move = iil_C_Move($this->conn, join(',', $a_uids), $from_mbox, $to_mbox);
$moved = !($iil_move === false || $iil_move < 0); $moved = !($iil_move === false || $iil_move < 0);
@ -1664,6 +1661,7 @@ class rcube_imap
$a_mids[] = $this->_uid2id($uid, $from_mbox); $a_mids[] = $this->_uid2id($uid, $from_mbox);
$this->search_set = array_diff($this->search_set, $a_mids); $this->search_set = array_diff($this->search_set, $a_mids);
} }
// update cached message headers // update cached message headers
$cache_key = $from_mbox.'.msg'; $cache_key = $from_mbox.'.msg';
if ($moved && $start_index = $this->get_message_cache_index_min($cache_key, $a_uids)) { if ($moved && $start_index = $this->get_message_cache_index_min($cache_key, $a_uids)) {
@ -2387,8 +2385,7 @@ class rcube_imap
FROM ".get_table_name('messages')." FROM ".get_table_name('messages')."
WHERE user_id=? WHERE user_id=?
AND cache_key=? AND cache_key=?
AND uid=? AND uid=?",
AND del<>1",
$_SESSION['user_id'], $_SESSION['user_id'],
$key, $key,
$headers->uid); $headers->uid);

@ -33,10 +33,6 @@ if ($RCMAIL->action=='moveto' && !empty($_POST['_uid']) && !empty($_POST['_targe
$target = get_input_value('_target_mbox', RCUBE_INPUT_POST); $target = get_input_value('_target_mbox', RCUBE_INPUT_POST);
$mbox = get_input_value('_mbox', RCUBE_INPUT_POST); $mbox = get_input_value('_mbox', RCUBE_INPUT_POST);
// flag messages as read before moving them
if ($CONFIG['read_when_deleted'] && $target == $CONFIG['trash_mbox'])
$IMAP->set_flag($uids, 'SEEN');
$moved = $IMAP->move_message($uids, $target, $mbox); $moved = $IMAP->move_message($uids, $target, $mbox);
if (!$moved) { if (!$moved) {

Loading…
Cancel
Save