/** * Move a message from one mailbox to another * * @param string List of UIDs to move, separated by comma * @param string Target mailbox * @param string Source mailbox * @return boolean True on success, False on error */ function move_message($uids, $to_mbox, $from_mbox = '') { $fbox = $from_mbox; $tbox = $to_mbox; $to_mbox = $this->mod_mailbox($to_mbox); $from_mbox = $from_mbox ? $this->mod_mailbox($from_mbox) : $this->mailbox; // make sure mailbox exists if ($to_mbox != 'INBOX' && !in_array($to_mbox, $this->_list_mailboxes())) { if (in_array($to_mbox_in, $this->default_folders)) { $this->create_mailbox($to_mbox_in, TRUE); } else { return FALSE; } } // convert the list of uids to array $a_uids = is_string($uids) ? explode(',', $uids) : (is_array($uids) ? $uids : NULL); // exit if no message uids are specified if (!is_array($a_uids) || empty($a_uids)) { 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); $moved = !($iil_move === false || $iil_move < 0); // send expunge command in order to have the moved message // really deleted from the source mailbox if ($moved) { $this->_expunge($from_mbox, FALSE, $a_uids); $this->_clear_messagecount($from_mbox); $this->_clear_messagecount($to_mbox); } else { if (rcmail::get_instance()->config->get('delete_always', false)) { return iil_C_Delete($this->conn, $from_mbox, join(',', $a_uids)); } } // remove message ids from search set if ($moved && $this->search_set && $from_mbox == $this->mailbox) { foreach ($a_uids as $uid) { $a_mids[] = $this->_uid2id($uid, $from_mbox); } $this->search_set = array_diff($this->search_set, $a_mids); } // update cached message headers $cache_key = $from_mbox . '.msg'; if ($moved && ($start_index = $this->get_message_cache_index_min($cache_key, $a_uids))) { // clear cache from the lowest index on $this->clear_message_cache($cache_key, $start_index); } return $moved; }
/** * Move a message from one mailbox to another * * @param string List of UIDs to move, separated by comma * @param string Target mailbox * @param string Source mailbox * @return boolean True on success, False on error */ function move_message($uids, $to_mbox, $from_mbox = '') { $to_mbox = $this->_mod_mailbox($to_mbox); $from_mbox = $from_mbox ? $this->_mod_mailbox($from_mbox) : $this->mailbox; // make sure mailbox exists if ($to_mbox != 'INBOX' && !in_array($to_mbox, $this->_list_mailboxes())) { if (in_array($to_mbox_in, $this->default_folders)) { $this->create_mailbox($to_mbox_in, TRUE); } else { return FALSE; } } // convert the list of uids to array $a_uids = is_string($uids) ? explode(',', $uids) : (is_array($uids) ? $uids : NULL); // exit if no message uids are specified if (!is_array($a_uids)) { return false; } // convert uids to message ids $a_mids = array(); foreach ($a_uids as $uid) { $a_mids[] = $this->_uid2id($uid, $from_mbox); } $iil_move = iil_C_Move($this->conn, join(',', $a_mids), $from_mbox, $to_mbox); $moved = !($iil_move === false || $iil_move < 0); // send expunge command in order to have the moved message // really deleted from the source mailbox if ($moved) { // but only when flag_for_deletion is set to false if (!rcmail::get_instance()->config->get('flag_for_deletion', false)) { $this->_expunge($from_mbox, FALSE); $this->_clear_messagecount($from_mbox); $this->_clear_messagecount($to_mbox); } } else { if (rcmail::get_instance()->config->get('delete_always', false)) { return iil_C_Delete($this->conn, $from_mbox, join(',', $a_mids)); } } // remove message ids from search set if ($moved && $this->search_set && $from_mbox == $this->mailbox) { $this->search_set = array_diff($this->search_set, $a_mids); } // 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); } } // clear cache from the lowest index on $this->clear_message_cache($cache_key, $start_index); } return $moved; }