Horde_ActiveSync_Imap_Adapter::moveMessage PHP Method

moveMessage() public method

Move a mail message
public moveMessage ( string $folderid, array $ids, string $newfolderid ) : array
$folderid string The existing folderid.
$ids array The message UIDs of the messages to move.
$newfolderid string The folder id to move $id to.
return array An hash of oldUID => newUID.
    public function moveMessage($folderid, array $ids, $newfolderid)
    {
        $imap = $this->_getImapOb();
        $from = new Horde_Imap_Client_Mailbox($folderid);
        $to = new Horde_Imap_Client_Mailbox($newfolderid);
        $ids_obj = new Horde_Imap_Client_Ids($ids);
        // Need to ensure the source message exists so we may properly notify
        // the client of the error.
        $search_q = new Horde_Imap_Client_Search_Query();
        $search_q->ids($ids_obj);
        $fetch_res = $imap->search($from, $search_q);
        if ($fetch_res['count'] != count($ids)) {
            $ids_obj = $fetch_res['match'];
        }
        try {
            return $imap->copy($from, $to, array('ids' => $ids_obj, 'move' => true, 'force_map' => true));
        } catch (Horde_Imap_Client_Exception $e) {
            // We already got rid of the missing ids, must be something else.
            $this->_logger->err($e->getMessage());
            throw new Horde_ActiveSync_Exception($e);
        }
    }

Usage Example

Example #1
0
 /**
  * Move message
  *
  * @param string $folderid     Existing folder id.
  * @param array $ids           Message UIDs to move. @todo For H6 this
  *                             should take a single id. We can't bulk
  *                             move them for other reasons.
  * @param string $newfolderid  The new folder id to move to.
  *
  * @return array  An array of successfully moved messages with
  *                the old UIDs as keys and new UIDs as values.
  *
  * @throws Horde_ActiveSync_Exception
  */
 public function moveMessage($folderid, array $ids, $newfolderid)
 {
     $this->_logger->info(sprintf("[%s] Horde_Core_ActiveSync_Driver::moveMessage(%s, [%s], %s)", $this->_pid, $folderid, implode(',', $ids), $newfolderid));
     $parts = $this->_parseFolderId($folderid);
     if (is_array($parts)) {
         $folder_class = $parts[self::FOLDER_PART_CLASS];
         $folder_id = $parts[self::FOLDER_PART_ID];
     } else {
         $folder_class = $parts;
         $folder_id = null;
     }
     $move_res = array();
     ob_start();
     switch ($folder_class) {
         case Horde_ActiveSync::CLASS_CALENDAR:
             $parts = $this->_parseFolderId($newfolderid);
             if (is_array($parts)) {
                 $newfolderid = $parts[self::FOLDER_PART_ID];
             }
             if ($res = $this->_connector->calendar_move(array_pop($ids), $folder_id, $newfolderid)) {
                 $move_res[$res] = $res;
             }
             break;
         case Horde_ActiveSync::CLASS_CONTACTS:
         case Horde_ActiveSync::CLASS_TASKS:
         case Horde_ActiveSync::CLASS_NOTES:
             $this->_endBuffer();
             // Not supported, so just drop through to return the empty array.
             break;
         default:
             $move_res = $this->_imap->moveMessage($folderid, $ids, $newfolderid);
     }
     $this->_endBuffer();
     return $move_res;
 }
All Usage Examples Of Horde_ActiveSync_Imap_Adapter::moveMessage