Horde_ActiveSync_Imap_Adapter::categoriesToFlags PHP Method

categoriesToFlags() public method

public categoriesToFlags ( $mailbox, $categories, $uid )
    public function categoriesToFlags($mailbox, $categories, $uid)
    {
        $msgFlags = $this->_getMsgFlags();
        $mbox = new Horde_Imap_Client_Mailbox($mailbox);
        $options = array('ids' => new Horde_Imap_Client_Ids(array($uid)), 'add' => array());
        foreach ($categories as $category) {
            // Do our best to make sure the imap flag is a RFC 3501 compliant.
            $atom = new Horde_Imap_Client_Data_Format_Atom(strtr(Horde_String_Transliterate::toAscii($category), ' ', '_'));
            $imapflag = Horde_String::lower($atom->stripNonAtomCharacters());
            if (!empty($msgFlags[$imapflag])) {
                $options['add'][] = $imapflag;
                unset($msgFlags[$imapflag]);
            }
        }
        $options['remove'] = array_keys($msgFlags);
        try {
            $this->_getImapOb()->store($mbox, $options);
        } catch (Horde_Imap_Client_Exception $e) {
            throw new Horde_ActiveSync_Exception($e);
        }
    }

Usage Example

示例#1
0
文件: Driver.php 项目: Gomez/horde
 /**
  * Add/Edit a message
  *
  * @param string $folderid  The server id of the message's folder.
  * @param string $id        The server's uid for the message if this is a
  *                          change to an existing message, false if new.
  * @param Horde_ActiveSync_Message_Base $message The activesync message.
  * @param Horde_ActiveSync_Device $device        The device information
  *        @since 2.5.0
  *
  * @return array|boolean    A stat array if successful, otherwise false.
  *   Contains the following keys:
  *   - id: (mixed)  The UID of the message/item.
  *   - mod: (mixed) A value to indicate the last modification.
  *   - flags: (array) an empty array if no flag changes.
  *   - categories: (array|boolean) false if no changes.
  */
 public function changeMessage($folderid, $id, Horde_ActiveSync_Message_Base $message, $device)
 {
     $this->_logger->info(sprintf("[%s] Horde_Core_ActiveSync_Driver::changeMessage(%s, %s ...)", $this->_pid, $folderid, $id));
     ob_start();
     $folder_split = $this->_parseFolderId($folderid);
     if (is_array($folder_split)) {
         $folder_class = $folder_split[self::FOLDER_PART_CLASS];
         $server_id = $folder_split[self::FOLDER_PART_ID];
     } else {
         $folder_class = $folder_split;
         $server_id = null;
     }
     $stat = false;
     switch ($folder_class) {
         case Horde_ActiveSync::CLASS_CALENDAR:
             if (!$id) {
                 try {
                     $id = $this->_connector->calendar_import($message, $server_id);
                 } catch (Horde_Exception $e) {
                     $this->_logger->err($e->getMessage());
                     $this->_endBuffer();
                     return false;
                 }
                 $stat = array('mod' => $this->getSyncStamp($folderid), 'id' => $id, 'flags' => 1);
             } else {
                 // ActiveSync messages do NOT contain the serverUID value, put
                 // it in ourselves so we can have it during import/change.
                 $message->setServerUID($id);
                 if (!empty($device->supported[self::APPOINTMENTS_FOLDER_UID])) {
                     $message->setSupported($device->supported[self::APPOINTMENTS_FOLDER_UID]);
                 }
                 try {
                     $this->_connector->calendar_replace($id, $message);
                 } catch (Horde_Exception $e) {
                     $this->_logger->err($e->getMessage());
                     $this->_endBuffer();
                     return false;
                 }
                 $stat = $this->_smartStatMessage($folderid, $id, false);
             }
             break;
         case Horde_ActiveSync::CLASS_CONTACTS:
             if (!$id) {
                 try {
                     $id = $this->_connector->contacts_import($message, $server_id);
                 } catch (Horde_Exception $e) {
                     $this->_logger->err($e->getMessage());
                     $this->_endBuffer();
                     return false;
                 }
                 $stat = array('mod' => $this->getSyncStamp($folderid), 'id' => $id, 'flags' => 1);
             } else {
                 if (!empty($device->supported[self::CONTACTS_FOLDER_UID])) {
                     $message->setSupported($device->supported[self::CONTACTS_FOLDER_UID]);
                 }
                 try {
                     $this->_connector->contacts_replace($id, $message);
                 } catch (Horde_Exception $e) {
                     $this->_logger->err($e->getMessage());
                     $this->_endBuffer();
                     return false;
                 }
                 $stat = $this->_smartStatMessage($folderid, $id, false);
             }
             break;
         case Horde_ActiveSync::CLASS_TASKS:
             if (!$id) {
                 try {
                     $id = $this->_connector->tasks_import($message, $server_id);
                 } catch (Horde_Exception $e) {
                     $this->_logger->err($e->getMessage());
                     $this->_endBuffer();
                     return false;
                 }
                 $stat = array('mod' => $this->getSyncStamp($folderid), 'id' => $id, 'flags' => 1);
             } else {
                 if (!empty($device->supported[self::TASKS_FOLDER_UID])) {
                     $message->setSupported($device->supported[self::TASKS_FOLDER_UID]);
                 }
                 try {
                     $this->_connector->tasks_replace($id, $message);
                 } catch (Horde_Exception $e) {
                     $this->_logger->err($e->getMessage());
                     $this->_endBuffer();
                     return false;
                 }
                 $stat = $this->_smartStatMessage($folderid, $id, false);
             }
             break;
         case Horde_ActiveSync::CLASS_NOTES:
             if (!$id) {
                 try {
                     $id = $this->_connector->notes_import($message, $server_id);
                 } catch (Horde_Exception $e) {
                     $this->_logger->err($e->getMessage());
                     $this->_endBuffer();
                     return false;
                 }
                 $stat = array('mod' => $this->getSyncStamp($folderid), 'id' => $id, 'flags' => 1);
             } else {
                 if (!empty($device->supported[self::NOTES_FOLDER_UID])) {
                     $message->setSupported($device->supported[self::NOTES_FOLDER_UID]);
                 }
                 try {
                     $this->_connector->notes_replace($id, $message);
                 } catch (Horde_Exception $e) {
                     $this->_logger->err($e->getMessage());
                     $this->_endBuffer();
                     return false;
                 }
                 $stat = $this->_smartStatMessage($folderid, $id, false);
             }
             break;
         default:
             if ($message instanceof Horde_ActiveSync_Message_Mail) {
                 $stat = array('id' => $id, 'mod' => 0, 'flags' => array(), 'categories' => false);
                 if ($message->read !== '') {
                     $this->setReadFlag($folderid, $id, $message->read);
                     $stat['flags'] = array_merge($stat['flags'], array('read' => $message->read));
                 }
                 if ($message->propertyExists('flag')) {
                     if (!$message->flag) {
                         $message->flag = Horde_ActiveSync::messageFactory('Flag');
                     }
                     $this->_imap->setMessageFlag($folderid, $id, $message->flag);
                     $stat['flags'] = array_merge($stat['flags'], array('flagged' => $message->flag->flagstatus));
                 }
                 if ($message->propertyExists('categories')) {
                     // We *try* to make sure the category is added as a custom
                     // IMAP flag. This might fail in some edge cases, like e.g.
                     // with non-ascii characters.
                     $this->_connector->mail_ensureMessageFlags($message->categories);
                     $this->_imap->categoriesToFlags($folderid, $message->categories, $id);
                     $stat['categories'] = $message->categories;
                 }
             } else {
                 $this->_endBuffer();
                 return false;
             }
     }
     $this->_endBuffer();
     return $stat;
 }
All Usage Examples Of Horde_ActiveSync_Imap_Adapter::categoriesToFlags