/** * Helper method to handle incoming OPTIONS nodes. * * @param array $collection The current collection array. */ public function _parseSyncOptions(&$collection) { $options = array(); $haveElement = false; // These can be sent in any order. while (1) { if ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FILTERTYPE)) { $options['filtertype'] = $this->_decoder->getElementContent(); $haveElement = true; if (!$this->_decoder->getElementEndTag()) { $this->_statusCode = self::STATUS_PROTERROR; $this->_handleError($collection); exit; } } // EAS > 12.1 the Collection Class can be part of OPTIONS. if ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FOLDERTYPE)) { $haveElement = true; $options['class'] = $this->_decoder->getElementContent(); if (!$this->_decoder->getElementEndTag()) { $this->_statusCode = self::STATUS_PROTERROR; $this->_handleError($collection); exit; } } if ($this->_decoder->getElementStartTag(Horde_ActiveSync::AIRSYNCBASE_BODYPREFERENCE)) { $this->_bodyPrefs($options); } if ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_CONFLICT)) { $haveElement = true; $options['conflict'] = $this->_decoder->getElementContent(); if (!$this->_decoder->getElementEndTag()) { $this->_statusCode = self::STATUS_PROTERROR; $this->_handleError; exit; } } if ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_MIMESUPPORT)) { $haveElement = true; $this->_mimeSupport($options); } // SYNC_MIMETRUNCATION is used when no SYNC_BODYPREFS element is sent. if ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_MIMETRUNCATION)) { $haveElement = true; $options['mimetruncation'] = Horde_ActiveSync::getMIMETruncSize($this->_decoder->getElementContent()); if (!$this->_decoder->getElementEndTag()) { $this->_statusCode = self::STATUS_PROTERROR; $this->_handleError($collection); exit; } } // SYNC_TRUNCATION only applies to the body of non-email collections // or the BODY element of an Email in EAS 2.5. if ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_TRUNCATION)) { $haveElement = true; $options['truncation'] = Horde_ActiveSync::getTruncSize($this->_decoder->getElementContent()); if (!$this->_decoder->getElementEndTag()) { $this->_statusCode = self::STATUS_PROTERROR; $this->_handleError($collection); exit; } } // @todo This seems to no longer be supported by the specs? Probably // a leftover from EAS 1 or 2.0. Remove in H6. if ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_RTFTRUNCATION)) { $haveElement = true; $options['rtftruncation'] = $this->_decoder->getElementContent(); if (!$this->_decoder->getElementEndTag()) { $this->_statusCode = self::STATUS_PROTERROR; $this->_handleError($collection); exit; } } if ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_MAXITEMS)) { $haveElement = true; $options['maxitems'] = $this->_decoder->getElementContent(); if (!$this->_decoder->getElementEndTag()) { $this->_statusCode = self::STATUS_PROTERROR; $this->_handleError($collection); exit; } } // EAS 14.1 if ($this->_device->version >= Horde_ActiveSync::VERSION_FOURTEENONE) { if ($this->_decoder->getElementStartTag(Horde_ActiveSync::RM_SUPPORT)) { $haveElement = true; $this->_rightsManagement($options); } if ($this->_decoder->getElementStartTag(Horde_ActiveSync::AIRSYNCBASE_BODYPARTPREFERENCE)) { $haveElement = true; $this->_bodyPartPrefs($options); } } $e = $this->_decoder->peek(); if ($e[Horde_ActiveSync_Wbxml::EN_TYPE] == Horde_ActiveSync_Wbxml::EN_TYPE_ENDTAG) { $this->_decoder->getElementEndTag(); break; } elseif (!$haveElement) { $depth = 0; while (1) { $e = $this->_decoder->getElement(); if ($e === false) { $this->_logger->err(sprintf('[%s] Unexpected end of stream.', $this->_procid)); $this->_statusCode = self::STATUS_PROTERROR; $this->_handleError($collection); exit; } elseif ($e[Horde_ActiveSync_Wbxml::EN_TYPE] == Horde_ActiveSync_Wbxml::EN_TYPE_STARTTAG) { $depth = $this->_decoder->isEmptyElement($e) ? $depth : $depth + 1; } elseif ($e[Horde_ActiveSync_Wbxml::EN_TYPE] == Horde_ActiveSync_Wbxml::EN_TYPE_ENDTAG) { $depth--; } if ($depth == 0) { break; } } } } // Default to no filter as per the specs. if (!isset($options['filtertype'])) { $options['filtertype'] = '0'; } if (!empty($options['class']) && $options['class'] == 'SMS') { return; } $collection = array_merge($collection, $options); }
/** * Return AS mail messages, from the given IMAP UIDs. * * @param string $folderid The mailbox folder. * @param array $messages List of IMAP message UIDs * @param array $options Additional Options: * - truncation: (integer) The truncation constant, if sent from device. * DEFAULT: false (No truncation). * - bodyprefs: (array) The bodypref settings, if sent from device. * DEFAULT: none (No body prefs sent, or enforced). * - mimesupport: (integer) Indicates if MIME is supported or not. * Possible values: 0 - Not supported 1 - Only S/MIME or * 2 - All MIME. * DEFAULT: 0 (No MIME support) * - protocolversion: (float) The EAS protocol version to support. * DEFAULT: 2.5 * * @return array An array of Horde_ActiveSync_Message_Mail objects. */ public function getMessages($folderid, array $messages, array $options = array()) { $mbox = new Horde_Imap_Client_Mailbox($folderid); $results = $this->_getMailMessages($mbox, $messages, array('headers' => true, 'envelope' => true)); $ret = array(); if (!empty($options['truncation'])) { $options['truncation'] = Horde_ActiveSync::getTruncSize($options['truncation']); } foreach ($results as $data) { if ($data->exists(Horde_Imap_Client::FETCH_STRUCTURE)) { try { $ret[] = $this->_buildMailMessage($mbox, $data, $options); } catch (Horde_Exception_NotFound $e) { } } } return $ret; }