Example #1
0
 /**
  * Move a message from one folder to another
  *
  * @param mixed  $uids      Message UIDs as array or comma-separated string, or '*'
  * @param string $to_mbox   Target folder
  * @param string $from_mbox Source folder
  *
  * @return boolean True on success, False on error
  */
 public function move_message($uids, $to_mbox, $from_mbox = '')
 {
     if (!strlen($from_mbox)) {
         $from_mbox = $this->folder;
     }
     if ($to_mbox === $from_mbox) {
         return false;
     }
     list($uids, $all_mode) = $this->parse_uids($uids);
     // exit if no message uids are specified
     if (empty($uids)) {
         return false;
     }
     if (!$this->check_connection()) {
         return false;
     }
     $config = rcube::get_instance()->config;
     $to_trash = $to_mbox == $config->get('trash_mbox');
     // flag messages as read before moving them
     if ($to_trash && $config->get('read_when_deleted')) {
         // don't flush cache (4th argument)
         $this->set_flag($uids, 'SEEN', $from_mbox, true);
     }
     // move messages
     $moved = $this->conn->move($uids, $from_mbox, $to_mbox);
     if ($moved) {
         $this->clear_messagecount($from_mbox);
         $this->clear_messagecount($to_mbox);
         $this->set_search_dirty($from_mbox);
         $this->set_search_dirty($to_mbox);
     } else {
         if ($to_trash && $config->get('delete_always', false)) {
             $moved = $this->delete_message($uids, $from_mbox);
         }
     }
     if ($moved) {
         // unset threads internal cache
         unset($this->icache['threads']);
         // remove message ids from search set
         if ($this->search_set && $from_mbox == $this->folder) {
             // threads are too complicated to just remove messages from set
             if ($this->search_threads || $all_mode) {
                 $this->refresh_search();
             } else {
                 if (!$this->search_set->incomplete) {
                     $this->search_set->filter(explode(',', $uids), $this->folder);
                 }
             }
         }
         // remove cached messages
         // @TODO: do cache update instead of clearing it
         $this->clear_message_cache($from_mbox, $all_mode ? null : explode(',', $uids));
     }
     return $moved;
 }
Example #2
0
 /**
  * Move a message from one mailbox to another
  *
  * @param mixed  $uids      Message UIDs as array or comma-separated string, or '*'
  * @param string $to_mbox   Target mailbox
  * @param string $from_mbox 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 = strlen($from_mbox) ? $this->mod_mailbox($from_mbox) : $this->mailbox;
     if ($to_mbox === $from_mbox) {
         return false;
     }
     list($uids, $all_mode) = $this->_parse_uids($uids, $from_mbox);
     // exit if no message uids are specified
     if (empty($uids)) {
         return false;
     }
     // make sure mailbox exists
     if ($to_mbox != 'INBOX' && !$this->mailbox_exists($tbox)) {
         if (in_array($tbox, $this->default_folders)) {
             $this->create_mailbox($tbox, true);
         } else {
             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
     $moved = $this->conn->move($uids, $from_mbox, $to_mbox);
     // send expunge command in order to have the moved message
     // really deleted from the source mailbox
     if ($moved) {
         $this->_expunge($from_mbox, false, $uids);
         $this->_clear_messagecount($from_mbox);
         $this->_clear_messagecount($to_mbox);
     } else {
         if ($config->get('delete_always', false) && $tbox == $config->get('trash_mbox')) {
             $moved = $this->delete_message($uids, $fbox);
         }
     }
     if ($moved) {
         // unset threads internal cache
         unset($this->icache['threads']);
         // remove message ids from search set
         if ($this->search_set && $from_mbox == $this->mailbox) {
             // threads are too complicated to just remove messages from set
             if ($this->search_threads || $all_mode) {
                 $this->refresh_search();
             } else {
                 $uids = explode(',', $uids);
                 foreach ($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 ($all_mode || ($start_index = $this->get_message_cache_index_min($cache_key, $uids))) {
             // clear cache from the lowest index on
             $this->clear_message_cache($cache_key, $all_mode ? 1 : $start_index);
         }
     }
     return $moved;
 }
Example #3
0
 /**
  * Move a message from one mailbox to another
  *
  * @param mixed  $uids      Message UIDs as array or comma-separated string, or '*'
  * @param string $to_mbox   Target mailbox
  * @param string $from_mbox Source mailbox
  * @return boolean True on success, False on error
  */
 function move_message($uids, $to_mbox, $from_mbox = '')
 {
     if (!strlen($from_mbox)) {
         $from_mbox = $this->mailbox;
     }
     if ($to_mbox === $from_mbox) {
         return false;
     }
     list($uids, $all_mode) = $this->_parse_uids($uids, $from_mbox);
     // exit if no message uids are specified
     if (empty($uids)) {
         return false;
     }
     // make sure mailbox exists
     if ($to_mbox != 'INBOX' && !$this->mailbox_exists($to_mbox)) {
         if (in_array($to_mbox, $this->default_folders)) {
             if (!$this->create_mailbox($to_mbox, true)) {
                 return false;
             }
         } else {
             return false;
         }
     }
     $config = rcmail::get_instance()->config;
     $to_trash = $to_mbox == $config->get('trash_mbox');
     // flag messages as read before moving them
     if ($to_trash && $config->get('read_when_deleted')) {
         // don't flush cache (4th argument)
         $this->set_flag($uids, 'SEEN', $from_mbox, true);
     }
     // move messages
     $moved = $this->conn->move($uids, $from_mbox, $to_mbox);
     // send expunge command in order to have the moved message
     // really deleted from the source mailbox
     if ($moved) {
         $this->_expunge($from_mbox, false, $uids);
         $this->_clear_messagecount($from_mbox);
         $this->_clear_messagecount($to_mbox);
     } else {
         if ($to_trash && $config->get('delete_always', false)) {
             $moved = $this->delete_message($uids, $from_mbox);
         }
     }
     if ($moved) {
         // unset threads internal cache
         unset($this->icache['threads']);
         // remove message ids from search set
         if ($this->search_set && $from_mbox == $this->mailbox) {
             // threads are too complicated to just remove messages from set
             if ($this->search_threads || $all_mode) {
                 $this->refresh_search();
             } else {
                 $a_uids = explode(',', $uids);
                 foreach ($a_uids as $uid) {
                     $a_mids[] = $this->uid2id($uid, $from_mbox);
                 }
                 $this->search_set = array_diff($this->search_set, $a_mids);
             }
             unset($a_mids);
             unset($a_uids);
         }
         // remove cached messages
         // @TODO: do cache update instead of clearing it
         $this->clear_message_cache($from_mbox, $all_mode ? null : explode(',', $uids));
     }
     return $moved;
 }