Horde_ActiveSync_Imap_Adapter::setMessageFlag PHP Method

setMessageFlag() public method

Set a POOMMAIL_FLAG on a mail message. This method differs from setReadFlag() in that it is passed a Flag object, which contains other data beside the seen status. Used for setting flagged for followup and potentially creating tasks based on the email.
public setMessageFlag ( string $mailbox, integer $uid, Horde_ActiveSync_Message_Flag $flag )
$mailbox string The mailbox name.
$uid integer The message uid.
$flag Horde_ActiveSync_Message_Flag The flag
    public function setMessageFlag($mailbox, $uid, $flag)
    {
        // There is no standard in EAS for the name of flags, so it is impossible
        // to map flagtype to an actual message flag. Until a better solution
        // is thought of, just always use \flagged. There is also no meaning
        // of a "completed" flag/task in IMAP email, so if it's not active,
        // clear the flag.
        $mbox = new Horde_Imap_Client_Mailbox($mailbox);
        $options = array('ids' => new Horde_Imap_Client_Ids(array($uid)));
        switch ($flag->flagstatus) {
            case Horde_ActiveSync_Message_Flag::FLAG_STATUS_ACTIVE:
                $options['add'] = array(Horde_Imap_Client::FLAG_FLAGGED);
                break;
            default:
                $options['remove'] = array(Horde_Imap_Client::FLAG_FLAGGED);
        }
        try {
            $this->_getImapOb()->store($mbox, $options);
        } catch (Horde_Imap_Client_Exception $e) {
            throw new Horde_ActiveSync_Exception($e);
        }
    }

Usage Example

Example #1
0
 /**
  * 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::setMessageFlag