diff --git a/.horde.yml b/.horde.yml index 07dcbbdf..0be37aa9 100644 --- a/.horde.yml +++ b/.horde.yml @@ -56,3 +56,9 @@ autoload-dev: files: - test/Horde/ActiveSync/Helpers/ControllerRequestStub.php vendor: horde +keywords: + - contacts + - outlook + - sync + - eas + - exchange diff --git a/lib/Horde/ActiveSync.php b/lib/Horde/ActiveSync.php index 71ac97a4..327aca64 100644 --- a/lib/Horde/ActiveSync.php +++ b/lib/Horde/ActiveSync.php @@ -1,4 +1,5 @@ self::$_logger, 'protocolversion' => self::$_version, - 'device' => self::$_device)); + 'device' => self::$_device]); } /** @@ -508,8 +509,8 @@ public function __construct( Horde_ActiveSync_Wbxml_Decoder $decoder, Horde_ActiveSync_Wbxml_Encoder $encoder, Horde_ActiveSync_State_Base $state, - Horde_Controller_Request_Http $request) - { + Horde_Controller_Request_Http $request + ) { // The http request $this->_request = $request; @@ -653,25 +654,27 @@ public function setRootCertificatePath($path) public function __get($property) { switch ($property) { - case 'encoder': - case 'decoder': - case 'state': - case 'request': - case 'driver': - case 'provisioning': - case 'multipart': - case 'certPath': - $property = '_' . $property; - return $this->$property; - case 'logger': - return self::$_logger; - case 'device': - return self::$_device; - default: - throw new InvalidArgumentException(sprintf( - 'The property %s does not exist', - $property) - ); + case 'encoder': + case 'decoder': + case 'state': + case 'request': + case 'driver': + case 'provisioning': + case 'multipart': + case 'certPath': + $property = '_' . $property; + return $this->$property; + case 'logger': + return self::$_logger; + case 'device': + return self::$_device; + default: + throw new InvalidArgumentException( + sprintf( + 'The property %s does not exist', + $property + ) + ); } } @@ -763,7 +766,7 @@ public function handleRequest($cmd, $devId) // @TODO: Remove is_callable check for H6. // Callback to give the backend the option to limit EAS version based // on user/device/etc... - if (is_callable(array($this->_driver, 'versionCallback'))) { + if (is_callable([$this->_driver, 'versionCallback'])) { $this->_driver->versionCallback($this); } @@ -786,11 +789,13 @@ public function handleRequest($cmd, $devId) throw new Horde_Exception_AuthenticationFailure('', $this->_globalError); } - self::$_logger->info(sprintf( - '%s%s request received for user %s', - str_repeat('-', 10), - Horde_String::upper($cmd), - $this->_driver->getUser()) + self::$_logger->info( + sprintf( + '%s%s request received for user %s', + str_repeat('-', 10), + Horde_String::upper($cmd), + $this->_driver->getUser() + ) ); // These are all handled in the same class. @@ -837,8 +842,8 @@ public function handleRequest($cmd, $devId) // Support Multipart response for ITEMOPERATIONS requests? $headers = $this->_request->getHeaders(); - if ((!empty($headers['ms-asacceptmultipart']) && $headers['ms-asacceptmultipart'] == 'T') || - !empty($get['AcceptMultiPart'])) { + if ((!empty($headers['ms-asacceptmultipart']) && $headers['ms-asacceptmultipart'] == 'T') + || !empty($get['AcceptMultiPart'])) { $this->_multipart = true; self::$_logger->info('Requesting multipart data.'); } @@ -855,7 +860,7 @@ public function handleRequest($cmd, $devId) // Should we announce a new version is available to the client? if (!empty($this->_needMsRp)) { self::$_logger->info('Announcing X-MS-RP to client.'); - header("X-MS-RP: ". $this->getSupportedVersions()); + header("X-MS-RP: " . $this->getSupportedVersions()); } // @TODO: Look at getting rid of having to set the version in the driver @@ -866,9 +871,11 @@ public function handleRequest($cmd, $devId) $request = new $class($this); $request->setLogger(self::$_logger); $result = $request->handle(); - self::$_logger->info(sprintf( - 'Maximum memory usage for ActiveSync request: %d bytes.', - memory_get_peak_usage(true)) + self::$_logger->info( + sprintf( + 'Maximum memory usage for ActiveSync request: %d bytes.', + memory_get_peak_usage(true) + ) ); return $result; @@ -916,20 +923,21 @@ protected function _handleDevice($devId) // @TODO: Remove is_callable check for H6. // Combine this with the modifyDevice callback? Allow $device // to be modified here? - if (is_callable(array($this->_driver, 'createDeviceCallback'))) { + if (is_callable([$this->_driver, 'createDeviceCallback'])) { $callback_ret = $this->_driver->createDeviceCallback(self::$_device); if ($callback_ret !== true) { $msg = sprintf( 'The device %s was disallowed for user %s per policy settings.', self::$_device->id, - self::$_device->user); + self::$_device->user + ); self::$_logger->err($msg); // Always throw exception in place of status code since we // won't have a version number before the device is created. throw new Horde_Exception_AuthenticationFailure($msg, $callback_ret); } else { // Give the driver a chance to modify device properties. - if (is_callable(array($this->_driver, 'modifyDeviceCallback'))) { + if (is_callable([$this->_driver, 'modifyDeviceCallback'])) { self::$_device = $this->_driver->modifyDeviceCallback(self::$_device); } } @@ -949,13 +957,13 @@ protected function _handleDevice($devId) if (empty(self::$_device->version)) { self::$_device->version = $version; } - if (self::$_device->version < $this->_maxVersion && - self::$_device->needsVersionUpdate($this->getSupportedVersions())) { + if (self::$_device->version < $this->_maxVersion + && self::$_device->needsVersionUpdate($this->getSupportedVersions())) { $this->_needMsRp = true; } // Give the driver a chance to modify device properties. - if (is_callable(array($this->_driver, 'modifyDeviceCallback'))) { + if (is_callable([$this->_driver, 'modifyDeviceCallback'])) { self::$_device = $this->_driver->modifyDeviceCallback(self::$_device); } } @@ -963,13 +971,14 @@ protected function _handleDevice($devId) // Save the device now that we know it is at least allowed to connect, // or it has connected successfully at least once in the past. self::$_device->save(); - if (is_callable(array($this->_driver, 'deviceCallback'))) { + if (is_callable([$this->_driver, 'deviceCallback'])) { $callback_ret = $this->_driver->deviceCallback(self::$_device); if ($callback_ret !== true) { $msg = sprintf( 'The device %s was disallowed for user %s per policy settings.', self::$_device->id, - self::$_device->user); + self::$_device->user + ); self::$_logger->err($msg); if ($version > self::VERSION_TWELVEONE) { // Use a status code here, since the device has already @@ -986,7 +995,8 @@ protected function _handleDevice($devId) if (self::$_device->blocked) { $msg = sprintf( 'The device %s was blocked.', - self::$_device->id); + self::$_device->id + ); self::$_logger->err($msg); if ($version > self::VERSION_TWELVEONE) { $this->_globalError = Horde_ActiveSync_Status::DEVICE_BLOCKED_FOR_USER; @@ -1007,30 +1017,30 @@ protected function _handleDevice($devId) */ public function activeSyncHeader() { - $headers = array( + $headers = [ 'Allow: OPTIONS,POST', sprintf('Server: Horde_ActiveSync Library v%s', self::LIBRARY_VERSION), - 'Public: OPTIONS,POST' - ); + 'Public: OPTIONS,POST', + ]; switch ($this->_maxVersion) { - case self::VERSION_TWOFIVE: - $headers[] = 'MS-Server-ActiveSync: 6.5.7638.1'; - break; - case self::VERSION_TWELVE: - $headers[] = 'MS-Server-ActiveSync: 12.0'; - break; - case self::VERSION_TWELVEONE: - $headers[] = 'MS-Server-ActiveSync: 12.1'; - break; - case self::VERSION_FOURTEEN: - $headers[] = 'MS-Server-ActiveSync: 14.0'; - break; - case self::VERSION_FOURTEENONE: - $headers[] = 'MS-Server-ActiveSync: 14.1'; - break; - case self::VERSION_SIXTEEN: - $headers[] = 'MS-Server-ActiveSync: 16.0'; + case self::VERSION_TWOFIVE: + $headers[] = 'MS-Server-ActiveSync: 6.5.7638.1'; + break; + case self::VERSION_TWELVE: + $headers[] = 'MS-Server-ActiveSync: 12.0'; + break; + case self::VERSION_TWELVEONE: + $headers[] = 'MS-Server-ActiveSync: 12.1'; + break; + case self::VERSION_FOURTEEN: + $headers[] = 'MS-Server-ActiveSync: 14.0'; + break; + case self::VERSION_FOURTEENONE: + $headers[] = 'MS-Server-ActiveSync: 14.1'; + break; + case self::VERSION_SIXTEEN: + $headers[] = 'MS-Server-ActiveSync: 16.0'; } foreach ($headers as $hdr) { @@ -1086,15 +1096,15 @@ public function commandsHeader() public function getSupportedCommands() { switch ($this->_maxVersion) { - case self::VERSION_TWOFIVE: - return 'Sync,SendMail,SmartForward,SmartReply,GetAttachment,GetHierarchy,CreateCollection,DeleteCollection,MoveCollection,FolderSync,FolderCreate,FolderDelete,FolderUpdate,MoveItems,GetItemEstimate,MeetingResponse,ResolveRecipients,ValidateCert,Provision,Search,Ping'; - - case self::VERSION_TWELVE: - case self::VERSION_TWELVEONE: - case self::VERSION_FOURTEEN: - case self::VERSION_FOURTEENONE: - case self::VERSION_SIXTEEN: - return 'Sync,SendMail,SmartForward,SmartReply,GetAttachment,GetHierarchy,CreateCollection,DeleteCollection,MoveCollection,FolderSync,FolderCreate,FolderDelete,FolderUpdate,MoveItems,GetItemEstimate,MeetingResponse,Search,Settings,Ping,ItemOperations,Provision,ResolveRecipients,ValidateCert'; + case self::VERSION_TWOFIVE: + return 'Sync,SendMail,SmartForward,SmartReply,GetAttachment,GetHierarchy,CreateCollection,DeleteCollection,MoveCollection,FolderSync,FolderCreate,FolderDelete,FolderUpdate,MoveItems,GetItemEstimate,MeetingResponse,ResolveRecipients,ValidateCert,Provision,Search,Ping'; + + case self::VERSION_TWELVE: + case self::VERSION_TWELVEONE: + case self::VERSION_FOURTEEN: + case self::VERSION_FOURTEENONE: + case self::VERSION_SIXTEEN: + return 'Sync,SendMail,SmartForward,SmartReply,GetAttachment,GetHierarchy,CreateCollection,DeleteCollection,MoveCollection,FolderSync,FolderCreate,FolderDelete,FolderUpdate,MoveItems,GetItemEstimate,MeetingResponse,Search,Settings,Ping,ItemOperations,Provision,ResolveRecipients,ValidateCert'; } } @@ -1156,7 +1166,7 @@ public function getGetVars() return $this->_get; } - $results = array(); + $results = []; $get = $this->_request->getGetVars(); // Do we need to decode the request parameters? @@ -1166,19 +1176,19 @@ public function getGetVars() $results = Horde_ActiveSync_Utils::decodeBase64($serverVars['QUERY_STRING']); // Normalize values. switch ($results['DeviceType']) { - case 'PPC': - $results['DeviceType'] = 'PocketPC'; - break; - case 'SP': - $results['DeviceType'] = 'SmartPhone'; - break; - case 'WP': - case 'WP8': - $results['DeviceType'] = 'WindowsPhone'; - break; - case 'android': - case 'android40': - $results['DeviceType'] = 'android'; + case 'PPC': + $results['DeviceType'] = 'PocketPC'; + break; + case 'SP': + $results['DeviceType'] = 'SmartPhone'; + break; + case 'WP': + case 'WP8': + $results['DeviceType'] = 'WindowsPhone'; + break; + case 'android': + case 'android40': + $results['DeviceType'] = 'android'; } $this->_get = $results; } @@ -1226,9 +1236,13 @@ protected function _handleOptionsRequest() $as_headers = implode("\r\n", $this->activeSyncHeader()); $version_header = $this->versionHeader(); $cmd_header = $this->commandsHeader(); - self::$_logger->meta(sprintf( - "Returning OPTIONS response:\r\n%s\r\n%s\r\n%s", - $as_headers, $version_header, $cmd_header) + self::$_logger->meta( + sprintf( + "Returning OPTIONS response:\r\n%s\r\n%s\r\n%s", + $as_headers, + $version_header, + $cmd_header + ) ); } @@ -1244,27 +1258,27 @@ protected function _handleOptionsRequest() */ public static function getMIMETruncSize($truncation) { - switch($truncation) { - case Horde_ActiveSync::TRUNCATION_ALL: - return 0; - case Horde_ActiveSync::TRUNCATION_1: - return 4096; - case Horde_ActiveSync::TRUNCATION_2: - return 5120; - case Horde_ActiveSync::TRUNCATION_3: - return 7168; - case Horde_ActiveSync::TRUNCATION_4: - return 10240; - case Horde_ActiveSync::TRUNCATION_5: - return 20480; - case Horde_ActiveSync::TRUNCATION_6: - return 51200; - case Horde_ActiveSync::TRUNCATION_7: - return 102400; - case Horde_ActiveSync::TRUNCATION_8: - return false; - default: - return 1024; // Default to 1Kb + switch ($truncation) { + case Horde_ActiveSync::TRUNCATION_ALL: + return 0; + case Horde_ActiveSync::TRUNCATION_1: + return 4096; + case Horde_ActiveSync::TRUNCATION_2: + return 5120; + case Horde_ActiveSync::TRUNCATION_3: + return 7168; + case Horde_ActiveSync::TRUNCATION_4: + return 10240; + case Horde_ActiveSync::TRUNCATION_5: + return 20480; + case Horde_ActiveSync::TRUNCATION_6: + return 51200; + case Horde_ActiveSync::TRUNCATION_7: + return 102400; + case Horde_ActiveSync::TRUNCATION_8: + return false; + default: + return 1024; // Default to 1Kb } } @@ -1280,30 +1294,30 @@ public static function getMIMETruncSize($truncation) */ public static function getTruncSize($truncation) { - switch($truncation) { - case Horde_ActiveSync::TRUNCATION_ALL: - return 0; - case Horde_ActiveSync::TRUNCATION_1: - return 512; - case Horde_ActiveSync::TRUNCATION_2: - return 1024; - case Horde_ActiveSync::TRUNCATION_3: - return 2048; - case Horde_ActiveSync::TRUNCATION_4: - return 5120; - case Horde_ActiveSync::TRUNCATION_5: - return 10240; - case Horde_ActiveSync::TRUNCATION_6: - return 20480; - case Horde_ActiveSync::TRUNCATION_7: - return 51200; - case Horde_ActiveSync::TRUNCATION_8: - return 102400; - case Horde_ActiveSync::TRUNCATION_9: - case Horde_ActiveSync::TRUNCATION_NONE: // @deprecated - return false; - default: - return 1024; // Default to 1Kb + switch ($truncation) { + case Horde_ActiveSync::TRUNCATION_ALL: + return 0; + case Horde_ActiveSync::TRUNCATION_1: + return 512; + case Horde_ActiveSync::TRUNCATION_2: + return 1024; + case Horde_ActiveSync::TRUNCATION_3: + return 2048; + case Horde_ActiveSync::TRUNCATION_4: + return 5120; + case Horde_ActiveSync::TRUNCATION_5: + return 10240; + case Horde_ActiveSync::TRUNCATION_6: + return 20480; + case Horde_ActiveSync::TRUNCATION_7: + return 51200; + case Horde_ActiveSync::TRUNCATION_8: + return 102400; + case Horde_ActiveSync::TRUNCATION_9: + case Horde_ActiveSync::TRUNCATION_NONE: // @deprecated + return false; + default: + return 1024; // Default to 1Kb } } diff --git a/lib/Horde/ActiveSync/Collections.php b/lib/Horde/ActiveSync/Collections.php index 73eba308..98b1f63e 100644 --- a/lib/Horde/ActiveSync/Collections.php +++ b/lib/Horde/ActiveSync/Collections.php @@ -1,4 +1,5 @@ _cache = $cache; $this->_as = $as; @@ -172,9 +173,11 @@ public function loadCollectionsFromCache() } } $this->_collections[$collection['id']] = $collection; - $this->_logger->meta(sprintf( - 'COLLECTIONS: Loaded %s from the cache.', - $collection['serverid']) + $this->_logger->meta( + sprintf( + 'COLLECTIONS: Loaded %s from the cache.', + $collection['serverid'] + ) ); } } @@ -185,12 +188,12 @@ public function loadCollectionsFromCache() public function __call($method, $parameters) { switch ($method) { - case 'hasPingChangeFlag': - case 'addConfirmedKey': - case 'updateCollection': - case 'collectionExists': - case 'updateWindowSize': - return call_user_func_array(array($this->_cache, $method), $parameters); + case 'hasPingChangeFlag': + case 'addConfirmedKey': + case 'updateCollection': + case 'collectionExists': + case 'updateWindowSize': + return call_user_func_array([$this->_cache, $method], $parameters); } throw new BadMethodCallException('Unknown method: ' . $method); @@ -202,17 +205,17 @@ public function __call($method, $parameters) public function __get($property) { switch ($property) { - case 'hbinterval': - case 'wait': - case 'confirmed_synckeys': - case 'lasthbsyncstarted': - case 'lastsyncendnormal': - return $this->_cache->$property; - case 'importedChanges': - case 'shortSyncRequest': - case 'hangingSync': - $p = '_' . $property; - return $this->$p; + case 'hbinterval': + case 'wait': + case 'confirmed_synckeys': + case 'lasthbsyncstarted': + case 'lastsyncendnormal': + return $this->_cache->$property; + case 'importedChanges': + case 'shortSyncRequest': + case 'hangingSync': + $p = '_' . $property; + return $this->$p; } throw new InvalidArgumentException('Unknown property: ' . $property); @@ -224,21 +227,21 @@ public function __get($property) public function __set($property, $value) { switch ($property) { - case 'importedChanges': - case 'shortSyncRequest': - case 'hangingSync': - $p = '_' . $property; - $this->$p = $value; - return; - case 'lasthbsyncstarted': - case 'lastsyncendnormal': - case 'hbinterval': - case 'wait': - $this->_cache->$property = $value; - return; - - case 'confirmed_synckeys': - throw new InvalidArgumentException($property . ' is READONLY.'); + case 'importedChanges': + case 'shortSyncRequest': + case 'hangingSync': + $p = '_' . $property; + $this->$p = $value; + return; + case 'lasthbsyncstarted': + case 'lastsyncendnormal': + case 'hbinterval': + case 'wait': + $this->_cache->$property = $value; + return; + + case 'confirmed_synckeys': + throw new InvalidArgumentException($property . ' is READONLY.'); } throw new InvalidArgumentException('Unknown property: ' . $property); @@ -251,13 +254,13 @@ public function __set($property, $value) */ public function getNewCollection() { - return array( - 'clientids' => array(), - 'fetchids' => array(), + return [ + 'clientids' => [], + 'fetchids' => [], 'windowsize' => 100, 'soft' => false, - 'conflict' => Horde_ActiveSync::CONFLICT_OVERWRITE_PIM - ); + 'conflict' => Horde_ActiveSync::CONFLICT_OVERWRITE_PIM, + ]; } /** @@ -269,16 +272,18 @@ public function getNewCollection() public function ensureOptions() { foreach ($this->_collections as &$collection) { - $this->_logger->meta(sprintf( - 'COLLECTIONS: Loading default OPTIONS for %s collection.', - $collection['id']) + $this->_logger->meta( + sprintf( + 'COLLECTIONS: Loading default OPTIONS for %s collection.', + $collection['id'] + ) ); if (!isset($collection['mimesupport'])) { $collection['mimesupport'] = Horde_ActiveSync::MIME_SUPPORT_NONE; } if (!isset($collection['bodyprefs'])) { - $collection['bodyprefs'] = array(); + $collection['bodyprefs'] = []; } } } @@ -304,7 +309,8 @@ public function addCollection(array $collection, $requireSyncKey = false) : 0; if ($collection['synckey'] === 0) { - $this->_logger->err('COLLECTIONS: Attempting to add a collection + $this->_logger->err( + 'COLLECTIONS: Attempting to add a collection to the sync cache while requiring a synckey, but no synckey could be found. Most likely a client error in requesting a collection during PING before it has issued a @@ -315,10 +321,12 @@ public function addCollection(array $collection, $requireSyncKey = false) ); } - $this->_logger->meta(sprintf( - 'COLLECTIONS: Obtained synckey for collection %s from cache: %s', - $collection['id'], - $collection['synckey']) + $this->_logger->meta( + sprintf( + 'COLLECTIONS: Obtained synckey for collection %s from cache: %s', + $collection['id'], + $collection['synckey'] + ) ); } @@ -335,10 +343,12 @@ public function addCollection(array $collection, $requireSyncKey = false) } $this->_collections[$collection['id']] = $collection; - $this->_logger->meta(sprintf( - 'COLLECTIONS: Collection added to collection handler: collection: %s, synckey: %s.', - $collection['serverid'], - !empty($collection['synckey']) ? $collection['synckey'] : 'NONE') + $this->_logger->meta( + sprintf( + 'COLLECTIONS: Collection added to collection handler: collection: %s, synckey: %s.', + $collection['serverid'], + !empty($collection['synckey']) ? $collection['synckey'] : 'NONE' + ) ); } @@ -484,9 +494,11 @@ public function updateCollectionsFromCache() $collections = $this->_cache->getCollections(); foreach (array_keys($this->_collections) as $id) { if (!empty($collections[$id])) { - $this->_logger->meta(sprintf( - 'COLLECTIONS: Refreshing %s from the cache.', - $id) + $this->_logger->meta( + sprintf( + 'COLLECTIONS: Refreshing %s from the cache.', + $id + ) ); $this->_collections[$id] = $collections[$id]; } @@ -514,9 +526,12 @@ public function getCollectionClass($id) // Next look in the SyncCache. if (isset($this->_cache->folders[$id]['class'])) { $class = $this->_cache->folders[$id]['class']; - $this->_logger->meta(sprintf( - 'COLLECTIONS: Obtaining collection class of %s for collection id %s', - $class, $id) + $this->_logger->meta( + sprintf( + 'COLLECTIONS: Obtaining collection class of %s for collection id %s', + $class, + $id + ) ); return $class; } @@ -538,9 +553,12 @@ public function getCollectionType($id) // Next look in the SyncCache. if (isset($this->_cache->folders[$id]['type'])) { $type = $this->_cache->folders[$id]['type']; - $this->_logger->meta(sprintf( - 'COLLECTIONS: Obtaining collection type of %s for collection id %s', - $type, $id) + $this->_logger->meta( + sprintf( + 'COLLECTIONS: Obtaining collection type of %s for collection id %s', + $type, + $id + ) ); return $type; } @@ -564,9 +582,12 @@ public function haveSyncableCollections($version) $found = false; foreach ($this->_cache->getCollections() as $value) { if (isset($value['synckey'])) { - $this->_logger->meta(sprintf( - 'COLLECTIONS: Found syncable collection: %s : %s.', - $value['serverid'], $value['synckey']) + $this->_logger->meta( + sprintf( + 'COLLECTIONS: Found syncable collection: %s : %s.', + $value['serverid'], + $value['synckey'] + ) ); $this->_collections[$value['id']] = $value; $found = true; @@ -658,9 +679,10 @@ public function haveHierarchy() public function initHierarchySync($synckey) { $this->_as->state->loadState( - array(), + [], $synckey, - Horde_ActiveSync::REQUEST_TYPE_FOLDERSYNC); + Horde_ActiveSync::REQUEST_TYPE_FOLDERSYNC + ); // Refresh the cache since it might have changed like e.g., if synckey // was empty. @@ -676,8 +698,9 @@ public function initHierarchySync($synckey) * @param boolean $update Update the state objects? @since 2.4.0 */ public function updateFolderinHierarchy( - Horde_ActiveSync_Message_Folder $folder, $update = false) - { + Horde_ActiveSync_Message_Folder $folder, + $update = false + ) { $this->_cache->updateFolder($folder); $cols = $this->_cache->getCollections(false); $cols[$folder->serverid]['serverid'] = $folder->_serverid; @@ -695,10 +718,10 @@ public function updateFolderinHierarchy( public function deleteFolderFromHierarchy($uid) { $this->_cache->deleteFolder($uid); - $this->_as->state->removeState(array( + $this->_as->state->removeState([ 'id' => $uid, 'devId' => $this->_as->device->id, - 'user' => $this->_as->device->user)); + 'user' => $this->_as->device->user]); } /** @@ -718,25 +741,27 @@ public function getHierarchyChanges() * @param Horde_ActiveSync_Connector_Exporter_FolderSync $exporter The exporter. * @param array $seenFolders An array of folders. */ - public function validateHierarchyChanges(Horde_ActiveSync_Connector_Exporter_FolderSync $exporter, array $seenFolders = array()) + public function validateHierarchyChanges(Horde_ActiveSync_Connector_Exporter_FolderSync $exporter, array $seenFolders = []) { - if ($this->_as->device->version < Horde_ActiveSync::VERSION_TWELVEONE || - count($exporter->changed)) { + if ($this->_as->device->version < Horde_ActiveSync::VERSION_TWELVEONE + || count($exporter->changed)) { return; } // Remove unnecessary changes. foreach ($exporter->changed as $key => $folder) { - if (isset($folder->serverid) && - $syncFolder = $this->_cache->getFolder($folder->serverid) && - in_array($folder->serverid, $seenFolders) && - $syncFolder['parentid'] == $folder->parentid && - $syncFolder['displayname'] == $folder->displayname && - $syncFolder['type'] == $folder->type) { - - $this->_logger->meta(sprintf( - 'COLLECTIONS: Ignoring %s from changes because it contains no changes from device.', - $folder->serverid) + if (isset($folder->serverid) + && $syncFolder = $this->_cache->getFolder($folder->serverid) + && in_array($folder->serverid, $seenFolders) + && $syncFolder['parentid'] == $folder->parentid + && $syncFolder['displayname'] == $folder->displayname + && $syncFolder['type'] == $folder->type) { + + $this->_logger->meta( + sprintf( + 'COLLECTIONS: Ignoring %s from changes because it contains no changes from device.', + $folder->serverid + ) ); unset($exporter->changed[$key]); $exporter->count--; @@ -746,9 +771,11 @@ public function validateHierarchyChanges(Horde_ActiveSync_Connector_Exporter_Fol // Remove unnecessary deletions. foreach ($exporter->deleted as $key => $folder) { if (($sid = array_search($folder, $seenFolders)) === false) { - $this->_logger->meta(sprintf( - 'COLLECTIONS: Ignoring %s from deleted list because the device does not know it', - $folder) + $this->_logger->meta( + sprintf( + 'COLLECTIONS: Ignoring %s from deleted list because the device does not know it', + $folder + ) ); unset($exporter->deleted[$key]); $exporter->count--; @@ -771,7 +798,7 @@ public function updateHierarchyKey($key) */ public function initFullSync() { - $this->_cache->confirmed_synckeys = array(); + $this->_cache->confirmed_synckeys = []; $this->_cache->clearCollectionKeys(); } @@ -789,9 +816,11 @@ public function initEmptySync() // Remove keys from confirmed synckeys array and count them if (isset($value['synckey'])) { if (isset($this->_cache->confirmed_synckeys[$value['synckey']])) { - $this->_logger->meta(sprintf( - 'COLLECTIONS: Removed %s from confirmed_synckeys', - $value['synckey']) + $this->_logger->meta( + sprintf( + 'COLLECTIONS: Removed %s from confirmed_synckeys', + $value['synckey'] + ) ); $this->_cache->removeConfirmedKey($value['synckey']); } @@ -894,9 +923,11 @@ public function initPartialSync() foreach ($this->_collections as $value) { if (isset($value['synckey'])) { if (isset($this->_cache->confirmed_synckeys[$value['synckey']])) { - $this->_logger->meta(sprintf( - 'COLLECTIONS: Removed %s from confirmed_synckeys', - $value['synckey']) + $this->_logger->meta( + sprintf( + 'COLLECTIONS: Removed %s from confirmed_synckeys', + $value['synckey'] + ) ); $this->_cache->removeConfirmedKey($value['synckey']); } @@ -922,9 +953,11 @@ protected function _checkConfirmedKeys() { $csk = $this->_cache->confirmed_synckeys; if ($csk) { - $this->_logger->meta(sprintf( - 'COLLECTIONS: Confirmed Synckeys contains %s', - serialize($csk)) + $this->_logger->meta( + sprintf( + 'COLLECTIONS: Confirmed Synckeys contains %s', + serialize($csk) + ) ); return false; } @@ -939,8 +972,8 @@ protected function _checkConfirmedKeys() */ public function canSendEmptyResponse() { - return !$this->_importedChanges && - ($this->_hangingSync && ($this->_cache->wait !== false || $this->_cache->hbinterval !== false)); + return !$this->_importedChanges + && ($this->_hangingSync && ($this->_cache->wait !== false || $this->_cache->hbinterval !== false)); } /** @@ -952,9 +985,9 @@ public function canSendEmptyResponse() */ protected function _haveNoChangesInPartialSync() { - return $this->_synckeyCount > 0 && - $this->_unchangedCount == $this->_synckeyCount && - $this->_cache->wait == false && $this->_cache->hbinterval == false; + return $this->_synckeyCount > 0 + && $this->_unchangedCount == $this->_synckeyCount + && $this->_cache->wait == false && $this->_cache->hbinterval == false; } /** @@ -999,12 +1032,15 @@ protected function _getMissingCollectionsFromCache() public function checkFilterType($id, $filter) { $cc = $this->_cache->getCollections(); - if (!empty($cc[$id]['filtertype']) && - !is_null($filter) && - $cc[$id]['filtertype'] != $filter) { - $this->_logger->meta(sprintf( - 'COLLECTIONS: Filtertype change from: %d to %d', - $cc[$id]['filtertype'], $filter) + if (!empty($cc[$id]['filtertype']) + && !is_null($filter) + && $cc[$id]['filtertype'] != $filter) { + $this->_logger->meta( + sprintf( + 'COLLECTIONS: Filtertype change from: %d to %d', + $cc[$id]['filtertype'], + $filter + ) ); $this->_cache->updateFiltertype($id, $filter); return false; @@ -1077,23 +1113,28 @@ public function initCollectionState(array &$collection, $requireSyncKey = false) if ($requireSyncKey && empty($collection['synckey'])) { - throw new Horde_ActiveSync_Exception_InvalidRequest(sprintf( - 'Empty synckey for %s.', - $collection['id']) + throw new Horde_ActiveSync_Exception_InvalidRequest( + sprintf( + 'Empty synckey for %s.', + $collection['id'] + ) ); } // Initialize the state - $this->_logger->info(sprintf( - 'COLLECTIONS: Initializing state for collection: %s, synckey: %s', - $collection['serverid'], - $collection['synckey']) + $this->_logger->info( + sprintf( + 'COLLECTIONS: Initializing state for collection: %s, synckey: %s', + $collection['serverid'], + $collection['synckey'] + ) ); $this->_as->state->loadState( $collection, $collection['synckey'], Horde_ActiveSync::REQUEST_TYPE_SYNC, - $collection['id']); + $collection['id'] + ); } /** @@ -1109,15 +1150,17 @@ public function initCollectionState(array &$collection, $requireSyncKey = false) * collections, false if no changes detected * or a status code if failed. */ - public function pollForChanges($heartbeat, $interval, array $options = array()) + public function pollForChanges($heartbeat, $interval, array $options = []) { $dataavailable = false; $started = time(); $until = $started + $heartbeat; - $this->_logger->info(sprintf( - 'COLLECTIONS: Waiting for changes for %s seconds', - $heartbeat) + $this->_logger->info( + sprintf( + 'COLLECTIONS: Waiting for changes for %s seconds', + $heartbeat + ) ); // If pinging, make sure we have pingable collections. Note we can't @@ -1159,8 +1202,8 @@ public function pollForChanges($heartbeat, $interval, array $options = array()) // Check for WIPE request once every 5 iterations to balance between // performance and speed of catching a remote wipe request. if ($rw_check_countdown-- == 0) { - $rw_check_countdown = 5; - if ($this->_as->provisioning != Horde_ActiveSync::PROVISIONING_NONE) { + $rw_check_countdown = 5; + if ($this->_as->provisioning != Horde_ActiveSync::PROVISIONING_NONE) { $rwstatus = $this->_as->state->getDeviceRWStatus($this->_as->device->id, true); if ($rwstatus == Horde_ActiveSync::RWSTATUS_PENDING || $rwstatus == Horde_ActiveSync::RWSTATUS_WIPED) { return self::COLLECTION_ERR_FOLDERSYNC_REQUIRED; @@ -1175,9 +1218,11 @@ public function pollForChanges($heartbeat, $interval, array $options = array()) try { $this->initCollectionState($collection, true); } catch (Horde_ActiveSync_Exception_StateGone $e) { - $this->_logger->notice(sprintf( - 'COLLECTIONS: State not found for %s. Continuing by rquesting a SYNC.', - $id) + $this->_logger->notice( + sprintf( + 'COLLECTIONS: State not found for %s. Continuing by rquesting a SYNC.', + $id + ) ); $dataavailable = true; $this->setGetChangesFlag($id); @@ -1186,10 +1231,12 @@ public function pollForChanges($heartbeat, $interval, array $options = array()) // Thrown when state is unable to be initialized because the // collection has not yet been synched, but was requested to // be pinged. - $this->_logger->err(sprintf( - 'COLLECTIONS: Unable to initialize state for %s. Ignoring during pollForChanges: %s.', - $id, - $e->getMessage()) + $this->_logger->err( + sprintf( + 'COLLECTIONS: Unable to initialize state for %s. Ignoring during pollForChanges: %s.', + $id, + $e->getMessage() + ) ); continue; } catch (Horde_ActiveSync_Exception_FolderGone $e) { @@ -1198,10 +1245,11 @@ public function pollForChanges($heartbeat, $interval, array $options = array()) } catch (Horde_ActiveSync_Exception $e) { $this->_logger->err('COLLECTIONS: Error loading state: ' . $e->getMessage()); $this->_as->state->loadState( - array(), + [], null, Horde_ActiveSync::REQUEST_TYPE_SYNC, - $id); + $id + ); $this->setGetChangesFlag($id); $dataavailable = true; continue; @@ -1227,21 +1275,26 @@ public function pollForChanges($heartbeat, $interval, array $options = array()) } } } catch (Horde_ActiveSync_Exception_StaleState $e) { - $this->_logger->notice(sprintf( - 'COLLECTIONS: SYNC terminating and force-clearing device state: %s', - $e->getMessage()) + $this->_logger->notice( + sprintf( + 'COLLECTIONS: SYNC terminating and force-clearing device state: %s', + $e->getMessage() + ) ); $this->_as->state->loadState( - array(), + [], null, Horde_ActiveSync::REQUEST_TYPE_SYNC, - $id); + $id + ); $this->setGetChangesFlag($id); $dataavailable = true; } catch (Horde_ActiveSync_Exception_FolderGone $e) { - $this->_logger->notice(sprintf( - 'COLLECTIONS: SYNC terminating: %s', - $e->getMessage()) + $this->_logger->notice( + sprintf( + 'COLLECTIONS: SYNC terminating: %s', + $e->getMessage() + ) ); // If we are missing a folder, we should clear the PING // cache also, to be sure it picks up any hierarchy changes @@ -1254,9 +1307,11 @@ public function pollForChanges($heartbeat, $interval, array $options = array()) $this->_logger->err('COLLECTIONS: Authentication lost during PING!!'); return self::COLLECTION_ERR_AUTHENTICATION; } catch (Horde_ActiveSync_Exception $e) { - $this->_logger->err(sprintf( - 'COLLECTIONS: Sync object cannot be configured, throttling: %s', - $e->getMessage()) + $this->_logger->err( + sprintf( + 'COLLECTIONS: Sync object cannot be configured, throttling: %s', + $e->getMessage() + ) ); $this->_sleep(30); continue; @@ -1283,10 +1338,12 @@ public function pollForChanges($heartbeat, $interval, array $options = array()) return self::COLLECTION_ERR_STALE; } - $this->_logger->meta(sprintf( - 'COLLECTIONS: Looping Sync complete: DataAvailable: %s, DataImported: %s', - $dataavailable, - $this->importedChanges) + $this->_logger->meta( + sprintf( + 'COLLECTIONS: Looping Sync complete: DataAvailable: %s, DataImported: %s', + $dataavailable, + $this->importedChanges + ) ); return $dataavailable; @@ -1304,11 +1361,12 @@ protected function _sleep($interval) $this->_logger->info(sprintf( '%sCOLLECTIONS: Sleeping for %s seconds.', str_repeat('-', 10), - $interval)); + $interval + )); // Close any backend connections. $this->_cache->state->disconnect(); - sleep ($interval); + sleep($interval); $this->_cache->state->connect(); } @@ -1336,17 +1394,21 @@ public function updatePingableFlag() $collections = $this->_cache->getCollections(false); foreach ($collections as $id => $collection) { if (!empty($this->_collections[$id]['synckey'])) { - $this->_logger->meta(sprintf( - 'COLLECTIONS: Setting collection %s (%s) PINGABLE.', - $collection['serverid'], - $id) + $this->_logger->meta( + sprintf( + 'COLLECTIONS: Setting collection %s (%s) PINGABLE.', + $collection['serverid'], + $id + ) ); $this->_cache->setPingableCollection($id); } else { - $this->_logger->meta(sprintf( - 'COLLECTIONS: UNSETTING collection %s (%s) PINGABLE flag.', - $collection['serverid'], - $id) + $this->_logger->meta( + sprintf( + 'COLLECTIONS: UNSETTING collection %s (%s) PINGABLE flag.', + $collection['serverid'], + $id + ) ); $this->_cache->removePingableCollection($id); } @@ -1362,10 +1424,12 @@ public function resetPingCache() { $collections = $this->_cache->getCollections(false); foreach ($collections as $id => $collection) { - $this->_logger->meta(sprintf( - 'COLLECTIONS: UNSETTING collection %s (%s) PINGABLE flag.', - $collection['serverid'], - $id) + $this->_logger->meta( + sprintf( + 'COLLECTIONS: UNSETTING collection %s (%s) PINGABLE flag.', + $collection['serverid'], + $id + ) ); $this->_cache->removePingableCollection($id); } @@ -1384,10 +1448,10 @@ public function resetPingCache() * * @return array The changes array. */ - public function getCollectionChanges($ping = false, array $ensure = array()) + public function getCollectionChanges($ping = false, array $ensure = []) { if (empty($this->_changes)) { - $this->_changes = $this->_as->state->getChanges(array('ping' => $ping)); + $this->_changes = $this->_as->state->getChanges(['ping' => $ping]); } return $this->_changes; diff --git a/lib/Horde/ActiveSync/Connector/Exporter/Base.php b/lib/Horde/ActiveSync/Connector/Exporter/Base.php index 3dff31bf..4ec619bf 100644 --- a/lib/Horde/ActiveSync/Connector/Exporter/Base.php +++ b/lib/Horde/ActiveSync/Connector/Exporter/Base.php @@ -1,4 +1,5 @@ _as = $as; $this->_encoder = $encoder; $this->_logger = $as->logger; @@ -97,7 +98,7 @@ public function __construct( public function setChanges($changes, $collection = null) { $this->_changes = $changes; - $this->_seenObjects = array(); + $this->_seenObjects = []; $this->_step = 0; } diff --git a/lib/Horde/ActiveSync/Connector/Exporter/FolderSync.php b/lib/Horde/ActiveSync/Connector/Exporter/FolderSync.php index 1bd83a90..109c1e34 100644 --- a/lib/Horde/ActiveSync/Connector/Exporter/FolderSync.php +++ b/lib/Horde/ActiveSync/Connector/Exporter/FolderSync.php @@ -1,4 +1,5 @@ _sendNextFolderSyncChange(); } - /** + /** * Sends the next folder change to the client. * * @return @see self::sendNextChange() @@ -65,38 +65,44 @@ protected function _sendNextFolderSyncChange() { if ($this->_step < count($this->_changes)) { $change = $this->_changes[$this->_step]; - switch($change['type']) { - case Horde_ActiveSync::CHANGE_TYPE_CHANGE: - // Folder add/change. - if ($folder = $this->_as->driver->getFolder($change['serverid'])) { - // @TODO BC HACK. Need to ensure we have a _serverid here. - // REMOVE IN H6. - if (empty($folder->_serverid)) { - $folder->_serverid = $folder->serverid; + switch ($change['type']) { + case Horde_ActiveSync::CHANGE_TYPE_CHANGE: + // Folder add/change. + if ($folder = $this->_as->driver->getFolder($change['serverid'])) { + // @TODO BC HACK. Need to ensure we have a _serverid here. + // REMOVE IN H6. + if (empty($folder->_serverid)) { + $folder->_serverid = $folder->serverid; + } + $stat = $this->_as->driver->statFolder( + $change['id'], + $folder->parentid, + $folder->displayname, + $folder->_serverid, + $folder->type + ); + $this->folderChange($folder); + } else { + $this->_logger->err(sprintf( + 'Error stating %s: ignoring.', + $change['id'] + )); + $stat = ['id' => $change['id'], 'mod' => $change['id'], 0]; } - $stat = $this->_as->driver->statFolder( - $change['id'], - $folder->parentid, - $folder->displayname, - $folder->_serverid, - $folder->type); - $this->folderChange($folder); - } else { - $this->_logger->err(sprintf( - 'Error stating %s: ignoring.', - $change['id'])); - $stat = array('id' => $change['id'], 'mod' => $change['id'], 0); - } - // Update the state. - $this->_as->state->updateState( - Horde_ActiveSync::CHANGE_TYPE_FOLDERSYNC, $stat); - break; + // Update the state. + $this->_as->state->updateState( + Horde_ActiveSync::CHANGE_TYPE_FOLDERSYNC, + $stat + ); + break; - case Horde_ActiveSync::CHANGE_TYPE_DELETE: - $this->folderDeletion($change['id']); - $this->_as->state->updateState( - Horde_ActiveSync::CHANGE_TYPE_DELETE, $change); - break; + case Horde_ActiveSync::CHANGE_TYPE_DELETE: + $this->folderDeletion($change['id']); + $this->_as->state->updateState( + Horde_ActiveSync::CHANGE_TYPE_DELETE, + $change + ); + break; } $this->_step++; return true; diff --git a/lib/Horde/ActiveSync/Connector/Exporter/Sync.php b/lib/Horde/ActiveSync/Connector/Exporter/Sync.php index 1d3b365e..0f09230d 100644 --- a/lib/Horde/ActiveSync/Connector/Exporter/Sync.php +++ b/lib/Horde/ActiveSync/Connector/Exporter/Sync.php @@ -1,4 +1,5 @@ getClass() != $this->_currentCollection['class'] || - in_array($id, $this->_seenObjects)) { + if ($message->getClass() != $this->_currentCollection['class'] + || in_array($id, $this->_seenObjects)) { $this->_logger->notice(sprintf( 'IGNORING message %s since it looks like it was already sent or does not belong to this collection. Class: %s, CurrentClass: %s', $id, $message->getClass(), - $this->_currentCollection['class'])); + $this->_currentCollection['class'] + )); return; } @@ -88,7 +89,8 @@ public function messageChange($id, Horde_ActiveSync_Message_Base $message) 'IGNORING message %s since it looks like it does not contain any data. Class: %s, CurrentClass: %s', $id, $message->getClass(), - $this->_currentCollection['class'])); + $this->_currentCollection['class'] + )); return; } @@ -140,9 +142,7 @@ public function messageDeletion($id, $soft = false) * * @param Horde_ActiveSync_Message_Base $message The message */ - public function messageMove($message) - { - } + public function messageMove($message) {} /** * Send the SYNC_ADD response for any items added from the client. @@ -207,16 +207,16 @@ public function syncModifiedResponse($collection) foreach ($collection['modifiedids'] as $serverid) { switch ($collection['class']) { - case Horde_ActiveSync::CLASS_CALENDAR: - if (empty($collection['atchash'][$serverid])) { - continue 2; - } - break; - case Horde_ActiveSync::CLASS_EMAIL: - if (empty($collection['conversations'])) { - continue 2; - } - break; + case Horde_ActiveSync::CLASS_CALENDAR: + if (empty($collection['atchash'][$serverid])) { + continue 2; + } + break; + case Horde_ActiveSync::CLASS_EMAIL: + if (empty($collection['conversations'])) { + continue 2; + } + break; } // Start SYNC_MODIFY $this->_encoder->startTag(Horde_ActiveSync::SYNC_MODIFY); @@ -304,9 +304,11 @@ public function fetchIds($driver, $collection) $this->_encoder->endTag(); $this->_encoder->endTag(); } catch (Horde_Exception_NotFound $e) { - $this->_logger->err(sprintf( - 'Unable to fetch %s', - $fetch_id) + $this->_logger->err( + sprintf( + 'Unable to fetch %s', + $fetch_id + ) ); $this->_encoder->startTag(Horde_ActiveSync::SYNC_FETCH); $this->_encoder->startTag(Horde_ActiveSync::SYNC_SERVERENTRYID); @@ -385,9 +387,9 @@ public function syncStatus($statusCode) protected function _sendEas16MessageResponse($serverid, $collection) { // @todo. Use a Exporter_Sync_Response_[Mail|Message|] object. - if ($this->_as->device->version >= Horde_ActiveSync::VERSION_SIXTEEN && - $collection['class'] == Horde_ActiveSync::CLASS_CALENDAR && - !empty($collection['atchash'][$serverid])) { + if ($this->_as->device->version >= Horde_ActiveSync::VERSION_SIXTEEN + && $collection['class'] == Horde_ActiveSync::CLASS_CALENDAR + && !empty($collection['atchash'][$serverid])) { $this->_encoder->startTag(Horde_ActiveSync::SYNC_SERVERENTRYID); $this->_encoder->content($serverid); @@ -404,9 +406,9 @@ protected function _sendEas16MessageResponse($serverid, $collection) $this->_encoder->startTag(Horde_ActiveSync::SYNC_DATA); $msg->encodeStream($this->_encoder); $this->_encoder->endTag(); - } elseif ($this->_as->device->version >= Horde_ActiveSync::VERSION_SIXTEEN && - $collection['class'] == Horde_ActiveSync::CLASS_EMAIL && - !empty($collection['conversations'][$serverid])) { + } elseif ($this->_as->device->version >= Horde_ActiveSync::VERSION_SIXTEEN + && $collection['class'] == Horde_ActiveSync::CLASS_EMAIL + && !empty($collection['conversations'][$serverid])) { $msg = $this->_as->messageFactory('Mail'); $msg->conversationid = $collection['conversations'][$serverid][0]; $msg->conversationindex = $collection['conversations'][$serverid][1]; @@ -435,11 +437,11 @@ protected function _getNextChange() if (!is_array($change)) { // This is an initial sync, so we know it's a CHANGE_TYPE_CHANGE // and a new message with no flag changes etc... - $change = array( + $change = [ 'id' => $change, 'type' => Horde_ActiveSync::CHANGE_TYPE_CHANGE, - 'flags' => Horde_ActiveSync::FLAG_NEWMESSAGE - ); + 'flags' => Horde_ActiveSync::FLAG_NEWMESSAGE, + ]; } return $change; @@ -473,89 +475,95 @@ protected function _sendNextChange() // Actually export the change by calling the appropriate // method to output the correct wbxml for this change. if (empty($change['ignore'])) { - switch($change['type']) { - case Horde_ActiveSync::CHANGE_TYPE_CHANGE: - case Horde_ActiveSync::CHANGE_TYPE_DRAFT: - try { - $message = $this->_as->driver->getMessage( - $this->_currentCollection['serverid'], - $change['id'], - $this->_currentCollection); - $message->flags = (isset($change['flags'])) ? $change['flags'] : false; - $this->messageChange($change['id'], $message); - } catch (Horde_Exception_NotFound $e) { - $this->_logger->notice(sprintf( - 'Message gone or error reading message from server: %s', - $e->getMessage())); - $this->_as->state->updateState($change['type'], $change); - $this->_step++; - return $e; - } catch (Horde_ActiveSync_Exception_TemporaryFailure $e) { - $this->_logger->err(sprintf( - 'Backend server reported an error: %s.', - $e->getMessage()) - ); - throw $e; - } catch (Horde_ActiveSync_Exception $e) { - $this->_logger->err(sprintf( - 'Unknown backend error skipping message: %s', - $e->getMessage()) - ); - $this->_as->state->updateState($change['type'], $change); - $this->_step++; - return $e; - } - break; - - case Horde_ActiveSync::CHANGE_TYPE_DELETE: - $this->messageDeletion($change['id']); - break; - - case Horde_ActiveSync::CHANGE_TYPE_SOFTDELETE: - $this->messageDeletion($change['id'], true); - break; - - case Horde_ActiveSync::CHANGE_TYPE_FLAGS: - // Read flag. - $message = Horde_ActiveSync::messageFactory('Mail'); - $message->flags = Horde_ActiveSync::CHANGE_TYPE_CHANGE; - $message->read = isset($change['flags']['read']) ? $change['flags']['read'] : false; - - // "Flagged" flag. - if (isset($change['flags']['flagged']) && $this->_as->device->version >= Horde_ActiveSync::VERSION_TWELVE) { - $flag = Horde_ActiveSync::messageFactory('Flag'); - $flag->flagstatus = $change['flags']['flagged'] == 1 - ? Horde_ActiveSync_Message_Flag::FLAG_STATUS_ACTIVE - : Horde_ActiveSync_Message_Flag::FLAG_STATUS_CLEAR; - $message->flag = $flag; - } + switch ($change['type']) { + case Horde_ActiveSync::CHANGE_TYPE_CHANGE: + case Horde_ActiveSync::CHANGE_TYPE_DRAFT: + try { + $message = $this->_as->driver->getMessage( + $this->_currentCollection['serverid'], + $change['id'], + $this->_currentCollection + ); + $message->flags = (isset($change['flags'])) ? $change['flags'] : false; + $this->messageChange($change['id'], $message); + } catch (Horde_Exception_NotFound $e) { + $this->_logger->notice(sprintf( + 'Message gone or error reading message from server: %s', + $e->getMessage() + )); + $this->_as->state->updateState($change['type'], $change); + $this->_step++; + return $e; + } catch (Horde_ActiveSync_Exception_TemporaryFailure $e) { + $this->_logger->err( + sprintf( + 'Backend server reported an error: %s.', + $e->getMessage() + ) + ); + throw $e; + } catch (Horde_ActiveSync_Exception $e) { + $this->_logger->err( + sprintf( + 'Unknown backend error skipping message: %s', + $e->getMessage() + ) + ); + $this->_as->state->updateState($change['type'], $change); + $this->_step++; + return $e; + } + break; + + case Horde_ActiveSync::CHANGE_TYPE_DELETE: + $this->messageDeletion($change['id']); + break; + + case Horde_ActiveSync::CHANGE_TYPE_SOFTDELETE: + $this->messageDeletion($change['id'], true); + break; + + case Horde_ActiveSync::CHANGE_TYPE_FLAGS: + // Read flag. + $message = Horde_ActiveSync::messageFactory('Mail'); + $message->flags = Horde_ActiveSync::CHANGE_TYPE_CHANGE; + $message->read = $change['flags']['read'] ?? false; + + // "Flagged" flag. + if (isset($change['flags']['flagged']) && $this->_as->device->version >= Horde_ActiveSync::VERSION_TWELVE) { + $flag = Horde_ActiveSync::messageFactory('Flag'); + $flag->flagstatus = $change['flags']['flagged'] == 1 + ? Horde_ActiveSync_Message_Flag::FLAG_STATUS_ACTIVE + : Horde_ActiveSync_Message_Flag::FLAG_STATUS_CLEAR; + $message->flag = $flag; + } - // Categories - if (!empty($change['categories']) && $this->_as->device->version > Horde_ActiveSync::VERSION_TWELVEONE) { - $message->categories = $change['categories']; - } + // Categories + if (!empty($change['categories']) && $this->_as->device->version > Horde_ActiveSync::VERSION_TWELVEONE) { + $message->categories = $change['categories']; + } - // Verbs - if ($this->_as->device->version >= Horde_ActiveSync::VERSION_FOURTEEN) { - if (isset($change['flags'][Horde_ActiveSync::CHANGE_REPLY_STATE])) { - $message->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_REPLY_SENDER; - $message->lastverbexecutiontime = new Horde_Date($change['flags'][Horde_ActiveSync::CHANGE_REPLY_STATE]); - } elseif (isset($change['flags'][Horde_ActiveSync::CHANGE_REPLYALL_STATE])) { - $message->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_REPLY_ALL; - $message->lastverbexecutiontime = new Horde_Date($change['flags'][Horde_ActiveSync::CHANGE_REPLYALL_STATE]); - } elseif (isset($change['flags'][Horde_ActiveSync::CHANGE_FORWARD_STATE])) { - $message->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_FORWARD; - $message->lastverbexecutiontime = new Horde_Date($change['flags'][Horde_ActiveSync::CHANGE_FORWARD_STATE]); + // Verbs + if ($this->_as->device->version >= Horde_ActiveSync::VERSION_FOURTEEN) { + if (isset($change['flags'][Horde_ActiveSync::CHANGE_REPLY_STATE])) { + $message->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_REPLY_SENDER; + $message->lastverbexecutiontime = new Horde_Date($change['flags'][Horde_ActiveSync::CHANGE_REPLY_STATE]); + } elseif (isset($change['flags'][Horde_ActiveSync::CHANGE_REPLYALL_STATE])) { + $message->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_REPLY_ALL; + $message->lastverbexecutiontime = new Horde_Date($change['flags'][Horde_ActiveSync::CHANGE_REPLYALL_STATE]); + } elseif (isset($change['flags'][Horde_ActiveSync::CHANGE_FORWARD_STATE])) { + $message->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_FORWARD; + $message->lastverbexecutiontime = new Horde_Date($change['flags'][Horde_ActiveSync::CHANGE_FORWARD_STATE]); + } } - } - // Export it. - $this->messageChange($change['id'], $message); - break; + // Export it. + $this->messageChange($change['id'], $message); + break; - case Horde_ActiveSync::CHANGE_TYPE_MOVE: - $this->messageMove($change['id'], $change['parent']); - break; + case Horde_ActiveSync::CHANGE_TYPE_MOVE: + $this->messageMove($change['id'], $change['parent']); + break; } } diff --git a/lib/Horde/ActiveSync/Connector/Importer.php b/lib/Horde/ActiveSync/Connector/Importer.php index f7a7679b..500144de 100644 --- a/lib/Horde/ActiveSync/Connector/Importer.php +++ b/lib/Horde/ActiveSync/Connector/Importer.php @@ -1,4 +1,5 @@ _state->isDuplicatePIMChange($id, $synckey)) { + if (!($message instanceof Horde_ActiveSync_Message_Appointment) + && $this->_state->isDuplicatePIMChange($id, $synckey)) { $conflict = $this->_isConflict( Horde_ActiveSync::CHANGE_TYPE_CHANGE, @@ -168,21 +172,25 @@ public function importMessageChange( $id ); if ($conflict) { - $this->_logger->notice(sprintf( - 'Conflict when updating %s, will overwrite client version on next sync.', - $id) + $this->_logger->notice( + sprintf( + 'Conflict when updating %s, will overwrite client version on next sync.', + $id + ) ); - return array( + return [ $id, - 'error' => array(Horde_ActiveSync_Request_Sync::STATUS_CONFLICT) - ); + 'error' => [Horde_ActiveSync_Request_Sync::STATUS_CONFLICT], + ]; } } } elseif (!$id && $uid = $this->_state->isDuplicatePIMAddition($clientid)) { // Already saw this addition, but client never received UID - $this->_logger->notice(sprintf( - 'Duplicate addition for %s', - $uid) + $this->_logger->notice( + sprintf( + 'Duplicate addition for %s', + $uid + ) ); return $uid; } @@ -194,12 +202,15 @@ public function importMessageChange( // Tell the backend about the change if (!$stat = $this->_as->driver->changeMessage($this->_folderId, $id, $message, $device)) { - $this->_logger->err(sprintf( - 'Change message failed when updating %s', $id) + $this->_logger->err( + sprintf( + 'Change message failed when updating %s', + $id + ) ); return $id - ? array(0 => $id, 'error' => Horde_ActiveSync_Request_Sync::STATUS_SERVERERROR) - : array(0 => false, 'error' => Horde_ActiveSync_Request_Sync::STATUS_SERVERERROR); + ? [0 => $id, 'error' => Horde_ActiveSync_Request_Sync::STATUS_SERVERERROR] + : [0 => false, 'error' => Horde_ActiveSync_Request_Sync::STATUS_SERVERERROR]; } $stat['serverid'] = $this->_folderId; @@ -252,18 +263,18 @@ public function importMessageDeletion(array $ids, $class, $instanceids = false) { // Don't support SMS, but can't tell client that. if ($class == Horde_ActiveSync::CLASS_SMS) { - return array(); + return []; } if ($instanceids) { foreach ($ids as $uid => $iid) { $mod = $this->_as->driver->getSyncStamp($this->_folderId); - $this->_as->driver->deleteMessage($this->_folderId, array($uid => $iid), true); - $change = array( + $this->_as->driver->deleteMessage($this->_folderId, [$uid => $iid], true); + $change = [ 'id' => $uid, 'mod' => $mod, - 'serverid' => $this->_folderId - ); + 'serverid' => $this->_folderId, + ]; // Log this as a change in the state, not a deletion because // these are actually instances of recurring series being // deleted, not the entire item being deleted. @@ -283,10 +294,10 @@ public function importMessageDeletion(array $ids, $class, $instanceids = false) $ids = $this->_as->driver->deleteMessage($this->_folderId, $ids); foreach ($ids as $id) { // Ignore SMS changes. - if (strpos($id, "IGNORESMS_") === 0) { + if (strpos($id, "IGNORESMS_") === 0) { continue; - } - $change = array(); + } + $change = []; $change['id'] = $id; $change['mod'] = $mod; $change['serverid'] = $this->_folderId; @@ -294,7 +305,8 @@ public function importMessageDeletion(array $ids, $class, $instanceids = false) Horde_ActiveSync::CHANGE_TYPE_DELETE, $change, Horde_ActiveSync::CHANGE_ORIGIN_PIM, - $this->_as->driver->getUser()); + $this->_as->driver->getUser() + ); } return $ids; @@ -308,15 +320,16 @@ public function importMessageDeletion(array $ids, $class, $instanceids = false) */ public function importMessageReadFlag($id, $flag) { - $change = array(); + $change = []; $change['id'] = $id; - $change['flags'] = array('read' => $flag); + $change['flags'] = ['read' => $flag]; $change['parent'] = $this->_folderId; $this->_state->updateState( Horde_ActiveSync::CHANGE_TYPE_FLAGS, $change, Horde_ActiveSync::CHANGE_ORIGIN_PIM, - $this->_as->driver->getUser()); + $this->_as->driver->getUser() + ); $this->_as->driver->setReadFlag($this->_folderId, $id, $flag); } @@ -344,7 +357,9 @@ public function importMessageMove(array $uids, $dst, $class = null) // Filter out SMS if $class is not CLASS_SMS $uids = array_filter( $uids, - function($e) { return strpos($e, 'IGNORESMS_') === false; } + function ($e) { + return strpos($e, 'IGNORESMS_') === false; + } ); $collections = $this->_as->getCollectionsObject(); $dst = $collections->getBackendIdForFolderUid($dst); @@ -353,7 +368,7 @@ function($e) { return strpos($e, 'IGNORESMS_') === false; } // Check for any missing (not found) source messages. $missing = count($results) != count($uids) ? array_diff($uids, array_keys($results)) - : array(); + : []; // Update client state. For MOVEITEMS, we are supposed to send // a DELETE and ADD command to the appropriate folders on the next @@ -364,7 +379,7 @@ function($e) { return strpos($e, 'IGNORESMS_') === false; } if (empty($results[$uid])) { continue; } - $change = array(); + $change = []; $change['id'] = $results[$uid]; $change['mod'] = $mod; $change['serverid'] = $dst; @@ -374,10 +389,11 @@ function($e) { return strpos($e, 'IGNORESMS_') === false; } Horde_ActiveSync::CHANGE_TYPE_CHANGE, $change, Horde_ActiveSync::CHANGE_ORIGIN_PIM, - $this->_as->driver->getUser()); + $this->_as->driver->getUser() + ); } - return array('results' => $results, 'missing' => $missing); + return ['results' => $results, 'missing' => $missing]; } /** @@ -392,9 +408,14 @@ function($e) { return strpos($e, 'IGNORESMS_') === false; } */ public function importFolderChange($uid, $displayname, $parent = Horde_ActiveSync::FOLDER_ROOT, $type = null) { - $this->_logger->meta(sprintf( - 'Horde_ActiveSync_Connector_Importer::importFolderChange(%s, %s, %s, %s)', - $uid, $displayname, $parent, $type) + $this->_logger->meta( + sprintf( + 'Horde_ActiveSync_Connector_Importer::importFolderChange(%s, %s, %s, %s)', + $uid, + $displayname, + $parent, + $type + ) ); // Convert the uids to serverids. @@ -409,7 +430,12 @@ public function importFolderChange($uid, $displayname, $parent = Horde_ActiveSyn // Perform the creation in the backend. try { $results = $this->_as->driver->changeFolder( - $folderid, $displayname, $parent_sid, $uid, $type); + $folderid, + $displayname, + $parent_sid, + $uid, + $type + ); } catch (Horde_ActiveSync_Exception $e) { $this->_logger->err($e->getMessage()); throw $e; @@ -429,7 +455,7 @@ public function importFolderChange($uid, $displayname, $parent = Horde_ActiveSyn $results->_serverid = $folderid; } - $change = array(); + $change = []; $change['id'] = $uid; $change['folderid'] = $folderid; $change['mod'] = $displayname; @@ -437,7 +463,8 @@ public function importFolderChange($uid, $displayname, $parent = Horde_ActiveSyn $this->_state->updateState( Horde_ActiveSync::CHANGE_TYPE_CHANGE, $change, - Horde_ActiveSync::CHANGE_ORIGIN_PIM); + Horde_ActiveSync::CHANGE_ORIGIN_PIM + ); return $results; } @@ -455,13 +482,14 @@ public function importFolderDeletion($uid, $parent = Horde_ActiveSync::FOLDER_RO ? $collections->getBackendIdForFolderUid($parent) : $parent; $folderid = $collections->getBackendIdForFolderUid($uid); - $change = array(); + $change = []; $change['id'] = $uid; $this->_as->driver->deleteFolder($folderid, $parent_sid); $this->_state->updateState( Horde_ActiveSync::CHANGE_TYPE_DELETE, $change, - Horde_ActiveSync::CHANGE_ORIGIN_NA); + Horde_ActiveSync::CHANGE_ORIGIN_NA + ); } /** diff --git a/lib/Horde/ActiveSync/Credentials.php b/lib/Horde/ActiveSync/Credentials.php index 12253a37..46824cae 100644 --- a/lib/Horde/ActiveSync/Credentials.php +++ b/lib/Horde/ActiveSync/Credentials.php @@ -1,4 +1,5 @@ _credentials[0]) ? $this->_credentials[0] : false; - case 'password': - return !empty($this->_credentials[1]) ? $this->_credentials[1] : false; + case 'username': + return !empty($this->_credentials[0]) ? $this->_credentials[0] : false; + case 'password': + return !empty($this->_credentials[1]) ? $this->_credentials[1] : false; } } public function __set($property, $value) { switch ($property) { - case 'username': - $this->_credentials[0] = $value; - break; - default: - throw new InvalidArgumentException(sprintf('%s is not a valid property.', $property)); + case 'username': + $this->_credentials[0] = $value; + break; + default: + throw new InvalidArgumentException(sprintf('%s is not a valid property.', $property)); } } @@ -89,9 +90,9 @@ protected function _getCredentials() // Standard case, PHP was passed the needed authentication info. $user = $serverVars['PHP_AUTH_USER']; $pass = $serverVars['PHP_AUTH_PW']; - } elseif (!empty($serverVars['HTTP_AUTHORIZATION']) || - !empty($serverVars['REDIRECT_HTTP_AUTHORIZATION']) || - !empty($serverVars['Authorization'])) { + } elseif (!empty($serverVars['HTTP_AUTHORIZATION']) + || !empty($serverVars['REDIRECT_HTTP_AUTHORIZATION']) + || !empty($serverVars['Authorization'])) { $authorization = !empty($serverVars['HTTP_AUTHORIZATION']) ? $serverVars['HTTP_AUTHORIZATION'] : (!empty($serverVars['REDIRECT_HTTP_AUTHORIZATION']) @@ -99,7 +100,7 @@ protected function _getCredentials() : $serverVars['Authorization']); $hash = base64_decode(str_replace('Basic ', '', $authorization)); if (strpos($hash, ':') !== false) { - list($user, $pass) = explode(':', $hash, 2); + [$user, $pass] = explode(':', $hash, 2); } } else { // Might be using X509 certs, so won't have the Auth headers or a @@ -110,7 +111,7 @@ protected function _getCredentials() } } - return array($user, $pass); + return [$user, $pass]; } } diff --git a/lib/Horde/ActiveSync/Device.php b/lib/Horde/ActiveSync/Device.php index 0f4aa016..800e22fe 100644 --- a/lib/Horde/ActiveSync/Device.php +++ b/lib/Horde/ActiveSync/Device.php @@ -1,4 +1,5 @@ _state = $state; $this->_properties = $data; @@ -155,40 +156,42 @@ public function __construct(Horde_ActiveSync_State_Base $state, array $data = ar public function &__get($property) { switch ($property) { - case self::MULTIPLEX: - if (!$this->_multiplexSet && empty($this->_properties['properties'][self::MULTIPLEX])) { - $this->_sniffMultiplex(); - $this->multiplex = $this->_properties['properties'][self::MULTIPLEX]; - $this->save(); - } - case self::ANNOUNCED_VERSION: - case self::BLOCKED: - return $this->_properties['properties'][$property]; - case 'clientType': - if (!isset($this->_clientType)) { - $this->_clientType = $this->_getClientType(); - } - return $this->_clientType; - case self::VERSION: - if (isset($this->_properties['properties'][self::VERSION])) { - return $this->_properties['properties'][self::VERSION]; - } - break; - case self::OS: - if (isset($this->_properties['properties'][self::OS])) { - return $this->_properties['properties'][self::OS]; - } - break; - case 'properties': - if (!isset($this->_properties['properties'])) { - $return = array(); - return $return; - } - // Fall through. - default: - if (isset($this->_properties[$property])) { - return $this->_properties[$property]; - } + case self::MULTIPLEX: + if (!$this->_multiplexSet && empty($this->_properties['properties'][self::MULTIPLEX])) { + $this->_sniffMultiplex(); + $this->multiplex = $this->_properties['properties'][self::MULTIPLEX]; + $this->save(); + } + // no break + case self::ANNOUNCED_VERSION: + case self::BLOCKED: + return $this->_properties['properties'][$property]; + case 'clientType': + if (!isset($this->_clientType)) { + $this->_clientType = $this->_getClientType(); + } + return $this->_clientType; + case self::VERSION: + if (isset($this->_properties['properties'][self::VERSION])) { + return $this->_properties['properties'][self::VERSION]; + } + break; + case self::OS: + if (isset($this->_properties['properties'][self::OS])) { + return $this->_properties['properties'][self::OS]; + } + break; + case 'properties': + if (!isset($this->_properties['properties'])) { + $return = []; + return $return; + } + // Fall through. + // no break + default: + if (isset($this->_properties[$property])) { + return $this->_properties[$property]; + } } $return = null; @@ -201,29 +204,30 @@ public function &__get($property) public function __set($property, $value) { switch ($property) { - case self::MULTIPLEX: - $this->_multiplexSet = true; - // fallthrough - case self::ANNOUNCED_VERSION: - case self::BLOCKED: - case self::VERSION: - case self::OS: - $properties = $this->properties; - if (empty($properties)) { - $properties = array(); - } - $properties[$property] = $value; - $this->setDeviceProperties($properties); - break; - case 'clientType': - $this->_clientType = $value; - break; - - default: - if (!isset($this->_properties[$property]) || $value != $this->_properties[$property]) { - $this->_dirty[$property] = true; - $this->_properties[$property] = $value; - } + case self::MULTIPLEX: + $this->_multiplexSet = true; + // fallthrough + // no break + case self::ANNOUNCED_VERSION: + case self::BLOCKED: + case self::VERSION: + case self::OS: + $properties = $this->properties; + if (empty($properties)) { + $properties = []; + } + $properties[$property] = $value; + $this->setDeviceProperties($properties); + break; + case 'clientType': + $this->_clientType = $value; + break; + + default: + if (!isset($this->_properties[$property]) || $value != $this->_properties[$property]) { + $this->_dirty[$property] = true; + $this->_properties[$property] = $value; + } } } @@ -278,8 +282,8 @@ public function isNonProvisionable() // but Outlook 2013 doesn't even send the ITEMSETTINGS command, so we // need to check the userAgent header. Early versions used Microsoft.Outlook, // but after some update it was changed to 'Outlook/15.0' - if (strpos($this->deviceType, 'MicrosoftOutlook') !== false || - strpos($this->userAgent, 'Outlook') !== false) { + if (strpos($this->deviceType, 'MicrosoftOutlook') !== false + || strpos($this->userAgent, 'Outlook') !== false) { return true; } @@ -330,11 +334,11 @@ public function setDeviceProperties(array $data) */ public function getFormattedDeviceProperties() { - $data = array( + $data = [ _("Id") => $this->id, _("Policy Key") => $this->policykey, - _("User Agent") => $this->userAgent - ); + _("User Agent") => $this->userAgent, + ]; if (!empty($this->properties[self::MODEL])) { $data[_("Model")] = $this->properties[self::MODEL]; @@ -394,7 +398,7 @@ public function save($all = true) if (!empty($this->_dirty['properties'])) { $this->_state->setDeviceProperties($this->properties, $this->id); } - $this->_dirty = array(); + $this->_dirty = []; } /** @@ -437,7 +441,7 @@ public function getMajorVersion() } break; case self::TYPE_TOUCHDOWN: - if (preg_match('/(.+)\/(\d+)\.(\d+)/', $this->userAgent, $matches)) { + if (preg_match('/(.+)\/(\d+)\.(\d+)/', $this->userAgent, $matches)) { return $matches[2]; } break; @@ -453,8 +457,8 @@ protected function _getIosVersion() { // First see if we have a newer client that sends the OS version // Newer iOS sends e.g., "iOS 8.2.2" in OS field. - if (!empty($this->properties[self::OS]) && - preg_match('/\d+\.\d+\.?\d?/', $this->properties[self::OS], $matches)) { + if (!empty($this->properties[self::OS]) + && preg_match('/\d+\.\d+\.?\d?/', $this->properties[self::OS], $matches)) { if (!empty($matches[0])) { $this->_iOSVersion = $matches[0]; return; @@ -508,7 +512,7 @@ public function getMinorVersion() } break; case self::TYPE_TOUCHDOWN: - if (preg_match('/(.+)\/(\d+)\.(\d+)/', $this->userAgent, $matches)) { + if (preg_match('/(.+)\/(\d+)\.(\d+)/', $this->userAgent, $matches)) { return $matches[3]; } break; @@ -600,80 +604,80 @@ public function getMinorVersion() public function normalizePoomContactsDates($date, $toEas = false) { switch (Horde_String::lower($this->clientType)) { - case self::TYPE_WP: - case 'wp8': // Legacy. Remove in H6. - case 'wp': // Legacy. Remove in H6. - if ($toEas) { - return new Horde_Date($date->format('Y-m-d'), 'UTC'); - } - $date = new Horde_Date($date->format('Y-m-d')); - return $date->setTimezone('UTC'); - - case self::TYPE_GMAIL: - if ($toEas) { - return new Horde_Date($date->format('Y-m-d'), 'UTC'); - } - $date = new Horde_Date($date->format('Y-m-d')); - return $date->setTimezone('UTC'); - - case self::TYPE_ANDROID: - // Need to protect against clients that don't send the actual Android - // version in the OS field. - if (stripos($this->deviceType, 'samsung') === 0) { - // Samsung's native Contacts app works differently than stock - // Android, always sending as 00:00:00 + case self::TYPE_WP: + case 'wp8': // Legacy. Remove in H6. + case 'wp': // Legacy. Remove in H6. if ($toEas) { return new Horde_Date($date->format('Y-m-d'), 'UTC'); } $date = new Horde_Date($date->format('Y-m-d')); return $date->setTimezone('UTC'); - } - if ($this->getMajorVersion() >= 4 && $this->getMajorVersion() <= 10) { + + case self::TYPE_GMAIL: if ($toEas) { - return new Horde_Date($date->format('Y-m-d 08:00:00'), 'UTC'); + return new Horde_Date($date->format('Y-m-d'), 'UTC'); } $date = new Horde_Date($date->format('Y-m-d')); return $date->setTimezone('UTC'); - } - // POOMCONTACTS:BIRTHDAY not really supported in early Android - // versions. Return as is. - return $date; - - case self::TYPE_IPAD: - case self::TYPE_IPHONE: - case self::TYPE_IPOD: - if ($this->getMajorVersion() >= 5) { - // iOS >= 5 handles it correctly more or less. + case self::TYPE_ANDROID: + // Need to protect against clients that don't send the actual Android + // version in the OS field. + if (stripos($this->deviceType, 'samsung') === 0) { + // Samsung's native Contacts app works differently than stock + // Android, always sending as 00:00:00 + if ($toEas) { + return new Horde_Date($date->format('Y-m-d'), 'UTC'); + } + $date = new Horde_Date($date->format('Y-m-d')); + return $date->setTimezone('UTC'); + } + if ($this->getMajorVersion() >= 4 && $this->getMajorVersion() <= 10) { + if ($toEas) { + return new Horde_Date($date->format('Y-m-d 08:00:00'), 'UTC'); + } + $date = new Horde_Date($date->format('Y-m-d')); + return $date->setTimezone('UTC'); + + } + // POOMCONTACTS:BIRTHDAY not really supported in early Android + // versions. Return as is. + return $date; + + case self::TYPE_IPAD: + case self::TYPE_IPHONE: + case self::TYPE_IPOD: + if ($this->getMajorVersion() >= 5) { + // iOS >= 5 handles it correctly more or less. + if ($toEas) { + return new Horde_Date($date->format('Y-m-d 00:00:00'), 'UTC'); + } + $date = new Horde_Date($date->format('Y-m-d')); + return $date->setTimezone('UTC'); + } + if ($toEas) { + return new Horde_Date($date->format('Y-m-d'), 'UTC'); + } + return new Horde_Date($date->format('Y-m-d')); + + case self::TYPE_NINE: if ($toEas) { return new Horde_Date($date->format('Y-m-d 00:00:00'), 'UTC'); } $date = new Horde_Date($date->format('Y-m-d')); return $date->setTimezone('UTC'); - } - if ($toEas) { - return new Horde_Date($date->format('Y-m-d'), 'UTC'); - } - return new Horde_Date($date->format('Y-m-d')); - - case self::TYPE_NINE: - if ($toEas) { - return new Horde_Date($date->format('Y-m-d 00:00:00'), 'UTC'); - } - $date = new Horde_Date($date->format('Y-m-d')); - return $date->setTimezone('UTC'); - case self::TYPE_BLACKBERRY: - if ($toEas) { - return new Horde_Date($date->format('Y-m-d 11:00:00'), 'UTC'); - } - $date = new Horde_Date($date->format('Y-m-d')); - return $date->setTimezone('UTC'); + case self::TYPE_BLACKBERRY: + if ($toEas) { + return new Horde_Date($date->format('Y-m-d 11:00:00'), 'UTC'); + } + $date = new Horde_Date($date->format('Y-m-d')); + return $date->setTimezone('UTC'); - case self::TYPE_TOUCHDOWN: - case self::TYPE_UNKNOWN: - default: - return $date; + case self::TYPE_TOUCHDOWN: + case self::TYPE_UNKNOWN: + default: + return $date; } } @@ -695,9 +699,9 @@ public function hasQuirk($quirk) case self::QUIRK_SUPPORTS_TNEF: // These clients can support TNEF data naitively. - return (strpos($this->deviceType, 'MicrosoftOutlook') !== false || - strpos($this->deviceType, 'WindowsOutlook') != false || - strpos($this->userAgent, 'Outlook') !== false); + return (strpos($this->deviceType, 'MicrosoftOutlook') !== false + || strpos($this->deviceType, 'WindowsOutlook') != false + || strpos($this->userAgent, 'Outlook') !== false); default: return false; @@ -713,27 +717,27 @@ public function hasQuirk($quirk) protected function _getClientType() { // Differentiate between the deviceType and the client app. - if ((!empty($this->properties[self::OS]) && - stripos($this->properties[self::OS], 'Android') !== false) || - Horde_String::lower($this->deviceType) == self::TYPE_ANDROID) { + if ((!empty($this->properties[self::OS]) + && stripos($this->properties[self::OS], 'Android') !== false) + || Horde_String::lower($this->deviceType) == self::TYPE_ANDROID) { // We can detect native Android, TouchDown, and Nine. // Moxier does not distinguish itself, so we can't sniff it. if (strpos($this->userAgent, 'TouchDown') !== false) { return self::TYPE_TOUCHDOWN; - } else if ($this->_isNine()) { + } elseif ($this->_isNine()) { return self::TYPE_NINE; - } else if (stripos($this->userAgent, 'Android-Mail') !== false) { + } elseif (stripos($this->userAgent, 'Android-Mail') !== false) { // Modern android OS uses GMAIL as the stock client. return self::TYPE_GMAIL; - } else if (stripos($this->userAgent, 'Android') !== false) { + } elseif (stripos($this->userAgent, 'Android') !== false) { return $this->deviceType; } else { return self::TYPE_ANDROID; } - } else { + } else { return $this->deviceType; - } + } } /** @@ -763,63 +767,63 @@ protected function _sniffMultiplex() if ($this->_isIos()) { // iOS seems to support multiple collections for everything except Notes. $this->_properties['properties'][self::MULTIPLEX] = Horde_ActiveSync_Device::MULTIPLEX_NOTES; - } else if ($clientType == self::TYPE_ANDROID) { + } elseif ($clientType == self::TYPE_ANDROID) { // Special cases: These clients don't support non-multiplexed // collections. Samsung's native client and HTCOnemini2. - if (stripos($this->deviceType, 'samsung') === 0 || - stripos($this->model, 'HTCOnemini2') === 0 || - $this->deviceType == 'HTCOnemini2') { - $this->_properties['properties'][self::MULTIPLEX] = - Horde_ActiveSync_Device::MULTIPLEX_CONTACTS | - Horde_ActiveSync_Device::MULTIPLEX_CALENDAR | - Horde_ActiveSync_Device::MULTIPLEX_NOTES | - Horde_ActiveSync_Device::MULTIPLEX_TASKS; + if (stripos($this->deviceType, 'samsung') === 0 + || stripos($this->model, 'HTCOnemini2') === 0 + || $this->deviceType == 'HTCOnemini2') { + $this->_properties['properties'][self::MULTIPLEX] + = Horde_ActiveSync_Device::MULTIPLEX_CONTACTS + | Horde_ActiveSync_Device::MULTIPLEX_CALENDAR + | Horde_ActiveSync_Device::MULTIPLEX_NOTES + | Horde_ActiveSync_Device::MULTIPLEX_TASKS; return; } // Newer GMAIL applications may not send the self::OS value. if (strpos($this->userAgent, 'Android-Mail/7.5') !== false) { - $this->_properties['properties'][SELF::MULTIPLEX] = 0; + $this->_properties['properties'][self::MULTIPLEX] = 0; return; } // All android before 4.4 KitKat requires multiplex. KitKat and // Android 5 native supports non-multiplexed calendars only. - if (!empty($this->properties[self::OS]) && - preg_match('/(\d+\.\d+(\.\d+)*)/', $this->properties[self::OS], $matches) && - version_compare($matches[0], '4.4.0') >= 0) { - $this->_properties['properties'][self::MULTIPLEX] = - Horde_ActiveSync_Device::MULTIPLEX_NOTES | - Horde_ActiveSync_Device::MULTIPLEX_CONTACTS | - Horde_ActiveSync_Device::MULTIPLEX_TASKS; + if (!empty($this->properties[self::OS]) + && preg_match('/(\d+\.\d+(\.\d+)*)/', $this->properties[self::OS], $matches) + && version_compare($matches[0], '4.4.0') >= 0) { + $this->_properties['properties'][self::MULTIPLEX] + = Horde_ActiveSync_Device::MULTIPLEX_NOTES + | Horde_ActiveSync_Device::MULTIPLEX_CONTACTS + | Horde_ActiveSync_Device::MULTIPLEX_TASKS; } else { - $this->_properties['properties'][self::MULTIPLEX] = - Horde_ActiveSync_Device::MULTIPLEX_CONTACTS | - Horde_ActiveSync_Device::MULTIPLEX_CALENDAR | - Horde_ActiveSync_Device::MULTIPLEX_NOTES | - Horde_ActiveSync_Device::MULTIPLEX_TASKS; + $this->_properties['properties'][self::MULTIPLEX] + = Horde_ActiveSync_Device::MULTIPLEX_CONTACTS + | Horde_ActiveSync_Device::MULTIPLEX_CALENDAR + | Horde_ActiveSync_Device::MULTIPLEX_NOTES + | Horde_ActiveSync_Device::MULTIPLEX_TASKS; } - } else if (strpos($this->userAgent, 'MSFT-WP/8.10') !== false) { + } elseif (strpos($this->userAgent, 'MSFT-WP/8.10') !== false) { // Windows Phone 8.10 supports multiple calendars and tasks, but // no contacts. - $this->_properties['properties'][self::MULTIPLEX] = - Horde_ActiveSync_Device::MULTIPLEX_CONTACTS; - } else if (strpos($this->userAgent, 'MSFT-WP/8.0') !== false || $this->deviceType == 'WP8') { + $this->_properties['properties'][self::MULTIPLEX] + = Horde_ActiveSync_Device::MULTIPLEX_CONTACTS; + } elseif (strpos($this->userAgent, 'MSFT-WP/8.0') !== false || $this->deviceType == 'WP8') { // Windows Phone 8.0 seems that only multiple tasklists are // supported. The rest must be multiplexed. - $this->_properties['properties'][self::MULTIPLEX] = - Horde_ActiveSync_Device::MULTIPLEX_CONTACTS | - Horde_ActiveSync_Device::MULTIPLEX_CALENDAR; - } else if (strpos($this->userAgent, 'MSFT-PPC') !== false || $this->deviceType == 'PocketPC') { + $this->_properties['properties'][self::MULTIPLEX] + = Horde_ActiveSync_Device::MULTIPLEX_CONTACTS + | Horde_ActiveSync_Device::MULTIPLEX_CALENDAR; + } elseif (strpos($this->userAgent, 'MSFT-PPC') !== false || $this->deviceType == 'PocketPC') { // PocketPC versions seem to not support any user defined // collections at all, though I've only tested on a single HTC device. - $this->_properties['properties'][self::MULTIPLEX] = - Horde_ActiveSync_Device::MULTIPLEX_CONTACTS | - Horde_ActiveSync_Device::MULTIPLEX_CALENDAR | - Horde_ActiveSync_Device::MULTIPLEX_NOTES | - Horde_ActiveSync_Device::MULTIPLEX_TASKS; - } else if (strpos($this->userAgent, 'Outlook/15.0') !== false || - strpos($this->userAgent, 'Outlook/16.0') !== false) { + $this->_properties['properties'][self::MULTIPLEX] + = Horde_ActiveSync_Device::MULTIPLEX_CONTACTS + | Horde_ActiveSync_Device::MULTIPLEX_CALENDAR + | Horde_ActiveSync_Device::MULTIPLEX_NOTES + | Horde_ActiveSync_Device::MULTIPLEX_TASKS; + } elseif (strpos($this->userAgent, 'Outlook/15.0') !== false + || strpos($this->userAgent, 'Outlook/16.0') !== false) { // OL2013 and OL2016 do not support multiple contact lists. $this->_properties['properties'][self::MULTIPLEX] = Horde_ActiveSync_Device::MULTIPLEX_CONTACTS; } else { @@ -836,10 +840,10 @@ protected function _sniffMultiplex() protected function _isIos() { // Compare in order of likelyhood / most recent to least recent versions. - if (strpos($this->{self::OS}, 'iOS') === 0 || - strpos($this->userAgent, 'iOS') === 0 || - in_array(Horde_String::lower($this->clientType), array(self::TYPE_IPAD, self::TYPE_IPOD, self::TYPE_IPHONE)) || - strpos($this->userAgent, 'Apple-') === 0) { + if (strpos($this->{self::OS}, 'iOS') === 0 + || strpos($this->userAgent, 'iOS') === 0 + || in_array(Horde_String::lower($this->clientType), [self::TYPE_IPAD, self::TYPE_IPOD, self::TYPE_IPHONE]) + || strpos($this->userAgent, 'Apple-') === 0) { return true; } diff --git a/lib/Horde/ActiveSync/Device/Ios.php b/lib/Horde/ActiveSync/Device/Ios.php index 828b500a..e6a9c7b9 100644 --- a/lib/Horde/ActiveSync/Device/Ios.php +++ b/lib/Horde/ActiveSync/Device/Ios.php @@ -1,4 +1,5 @@ "4.0", "801.306" => "4.0.1", "801.400" => "4.0.2", @@ -53,14 +54,14 @@ class Horde_ActiveSync_Device_Ios "902.206" => "5.1.1", "1001.40\d+" => "6.0", "1001.52\d+" => "6.0.1", - "1002.14\d+"=> "6.1", + "1002.14\d+" => "6.1", "1002.146" => "6.1.2", "1002.329" => "6.1.3", "1002.350" => "6.1.3", "1101.465" => "7.0", - "1101.470"=>"7.0.1", - "1101.47000001"=>"7.0.1", - "1101.501"=>"7.0.2", + "1101.470" => "7.0.1", + "1101.47000001" => "7.0.1", + "1101.501" => "7.0.2", "1102.511" => "7.0.3", "1102.55400001" => "7.0.4", "1102.601" => "7.0.5", @@ -69,5 +70,5 @@ class Horde_ActiveSync_Device_Ios "1104.169" => "7.1", "1104.201" => "7.1.1", "1104.257" => "7.1.2", - ); + ]; } diff --git a/lib/Horde/ActiveSync/Driver/Base.php b/lib/Horde/ActiveSync/Driver/Base.php index 44bd9221..715dd8c1 100644 --- a/lib/Horde/ActiveSync/Driver/Base.php +++ b/lib/Horde/ActiveSync/Driver/Base.php @@ -1,4 +1,5 @@ Horde_ActiveSync::CLASS_EMAIL, 'C' => Horde_ActiveSync::CLASS_CONTACTS, 'A' => Horde_ActiveSync::CLASS_CALENDAR, 'T' => Horde_ActiveSync::CLASS_TASKS, - 'N' => Horde_ActiveSync::CLASS_NOTES - ); + 'N' => Horde_ActiveSync::CLASS_NOTES, + ]; /** * Const'r @@ -107,18 +108,18 @@ abstract class Horde_ActiveSync_Driver_Base * * @return Horde_ActiveSync_Driver */ - public function __construct($params = array()) + public function __construct($params = []) { $this->_params = $params; - if (empty($params['state']) || - !($params['state'] instanceof Horde_ActiveSync_State_Base)) { + if (empty($params['state']) + || !($params['state'] instanceof Horde_ActiveSync_State_Base)) { throw new InvalidArgumentException('Missing required state object'); } /* Create a stub if we don't have a useable logger. */ if (isset($params['logger']) - && is_callable(array($params['logger'], 'log'))) { + && is_callable([$params['logger'], 'log'])) { $this->_logger = Horde_ActiveSync::_wrapLogger($params['logger']); unset($params['logger']); } else { @@ -405,10 +406,12 @@ protected function _getFolderUidForBackendId($id, $type = null, $old_id = null) // None found, generate a new UID. $this->_tempMap[$id] = sprintf('%s%04x%04x', $prefix, mt_rand(0, 0xffff), mt_rand(0, 0xffff)); - $this->_logger->meta(sprintf( - 'Creating new folder uuid for %s: %s', - $id, - $this->_tempMap[$id]) + $this->_logger->meta( + sprintf( + 'Creating new folder uuid for %s: %s', + $id, + $this->_tempMap[$id] + ) ); return $this->_tempMap[$id]; @@ -430,29 +433,29 @@ protected function _getClassFromType($type) } switch ($type) { - case Horde_ActiveSync::FOLDER_TYPE_APPOINTMENT: - case Horde_ActiveSync::FOLDER_TYPE_USER_APPOINTMENT: - return Horde_ActiveSync::CLASS_CALENDAR; - - case Horde_ActiveSync::FOLDER_TYPE_CONTACT: - case Horde_ActiveSync::FOLDER_TYPE_USER_CONTACT: - return Horde_ActiveSync::CLASS_CONTACTS; - - case Horde_ActiveSync::FOLDER_TYPE_TASK: - case Horde_ActiveSync::FOLDER_TYPE_USER_TASK: - return Horde_ActiveSync::CLASS_TASKS; - - case Horde_ActiveSync::FOLDER_TYPE_NOTE: - case Horde_ActiveSync::FOLDER_TYPE_USER_NOTE: - return Horde_ActiveSync::CLASS_NOTES; - - case Horde_ActiveSync::FOLDER_TYPE_INBOX: - case Horde_ActiveSync::FOLDER_TYPE_DRAFTS: - case Horde_ActiveSync::FOLDER_TYPE_WASTEBASKET: - case Horde_ActiveSync::FOLDER_TYPE_SENTMAIL: - case Horde_ActiveSync::FOLDER_TYPE_OUTBOX: - case Horde_ActiveSync::FOLDER_TYPE_USER_MAIL: - return Horde_ActiveSync::CLASS_EMAIL; + case Horde_ActiveSync::FOLDER_TYPE_APPOINTMENT: + case Horde_ActiveSync::FOLDER_TYPE_USER_APPOINTMENT: + return Horde_ActiveSync::CLASS_CALENDAR; + + case Horde_ActiveSync::FOLDER_TYPE_CONTACT: + case Horde_ActiveSync::FOLDER_TYPE_USER_CONTACT: + return Horde_ActiveSync::CLASS_CONTACTS; + + case Horde_ActiveSync::FOLDER_TYPE_TASK: + case Horde_ActiveSync::FOLDER_TYPE_USER_TASK: + return Horde_ActiveSync::CLASS_TASKS; + + case Horde_ActiveSync::FOLDER_TYPE_NOTE: + case Horde_ActiveSync::FOLDER_TYPE_USER_NOTE: + return Horde_ActiveSync::CLASS_NOTES; + + case Horde_ActiveSync::FOLDER_TYPE_INBOX: + case Horde_ActiveSync::FOLDER_TYPE_DRAFTS: + case Horde_ActiveSync::FOLDER_TYPE_WASTEBASKET: + case Horde_ActiveSync::FOLDER_TYPE_SENTMAIL: + case Horde_ActiveSync::FOLDER_TYPE_OUTBOX: + case Horde_ActiveSync::FOLDER_TYPE_USER_MAIL: + return Horde_ActiveSync::CLASS_EMAIL; } } @@ -467,12 +470,12 @@ protected function _getClassFromType($type) protected function _isSpecialMailbox($server_id) { $folder = $this->getFolder($server_id); - return in_array($folder->type, array( - Horde_ActiveSync::FOLDER_TYPE_INBOX, - Horde_ActiveSync::FOLDER_TYPE_DRAFTS, - Horde_ActiveSync::FOLDER_TYPE_WASTEBASKET, - Horde_ActiveSync::FOLDER_TYPE_SENTMAIL, - Horde_ActiveSync::FOLDER_TYPE_OUTBOX)); + return in_array($folder->type, [ + Horde_ActiveSync::FOLDER_TYPE_INBOX, + Horde_ActiveSync::FOLDER_TYPE_DRAFTS, + Horde_ActiveSync::FOLDER_TYPE_WASTEBASKET, + Horde_ActiveSync::FOLDER_TYPE_SENTMAIL, + Horde_ActiveSync::FOLDER_TYPE_OUTBOX]); } /** @@ -606,7 +609,12 @@ abstract public function getFolders(); * sent. */ abstract public function getServerChanges( - $folder, $from_ts, $to_ts, $cutoffdate, $ping); + $folder, + $from_ts, + $to_ts, + $cutoffdate, + $ping + ); /** * Get a message stat. @@ -697,7 +705,12 @@ abstract public function setReadFlag($folderid, $uid, $flag); * @return boolean */ abstract public function sendMail( - $rfc822, $forward = null, $reply = null, $parent = null, $save = true); + $rfc822, + $forward = null, + $reply = null, + $parent = null, + $save = true + ); /** * Return the specified attachment. @@ -713,7 +726,7 @@ abstract public function sendMail( * array('content-type' => {the content-type of the attachement}, * 'data' => {the raw attachment data}) */ - abstract public function getAttachment($name, array $options = array()); + abstract public function getAttachment($name, array $options = []); /** * Return the specified attachement data for an ITEMOPERATIONS request. @@ -851,7 +864,7 @@ abstract public function getUsernameFromEmail($email); * - availability: (string) A EAS style FB string. * - picture: (Horde_ActiveSync_Message_ResolveRecipientsPicture) */ - abstract public function resolveRecipient($type, $search, array $options = array()); + abstract public function resolveRecipient($type, $search, array $options = []); /** * Returns the provisioning support for the current request. @@ -886,6 +899,6 @@ abstract public function meetingResponse(array $response); * false. * @deprecated Will be removed in 3.0 - this is provided by resolveRecipients */ - abstract public function getFreebusy($user, array $options = array()); + abstract public function getFreebusy($user, array $options = []); } diff --git a/lib/Horde/ActiveSync/Driver/Mock.php b/lib/Horde/ActiveSync/Driver/Mock.php index b4f1d505..8c66a419 100644 --- a/lib/Horde/ActiveSync/Driver/Mock.php +++ b/lib/Horde/ActiveSync/Driver/Mock.php @@ -1,4 +1,5 @@ 'Calendar', self::CONTACTS_FOLDER_UID => 'Contacts', self::TASKS_FOLDER_UID => 'Tasks', self::NOTES_FOLDER_UID => 'Notes', - ); + ]; - public function __construct($params = array()) + public function __construct($params = []) { parent::__construct($params); $this->_connector = $params['connector']; @@ -61,7 +62,7 @@ public function __construct($params = array()) * @param string $id The server's folder id. * @param string $parent The folder's parent, if needed. */ - public function deleteFolder($id, $parent = Horde_ActiveSync::FOLDER_ROOT) { } + public function deleteFolder($id, $parent = Horde_ActiveSync::FOLDER_ROOT) {} /** * Change a folder on the server. @@ -118,7 +119,7 @@ public function getSearchResults(Horde_ActiveSync_Search_Params $params): Horde_ */ public function statFolder($id, $parent = 0, $mod = null) { - $folder = array(); + $folder = []; $folder['id'] = $id; $folder['mod'] = empty($mod) ? $id : $mod; $folder['parent'] = $parent; @@ -137,61 +138,65 @@ public function statFolder($id, $parent = 0, $mod = null) public function getFolder($id) { switch ($id) { - case self::APPOINTMENTS_FOLDER_UID: - $folder = $this->_buildNonMailFolder( - $id, - 0, - Horde_ActiveSync::FOLDER_TYPE_APPOINTMENT, - $this->_displayMap[self::APPOINTMENTS_FOLDER_UID]); - break; - case self::CONTACTS_FOLDER_UID: - $folder = $this->_buildNonMailFolder( - $id, - 0, - Horde_ActiveSync::FOLDER_TYPE_CONTACT, - $this->_displayMap[self::CONTACTS_FOLDER_UID]); - break; - case self::TASKS_FOLDER_UID: - $folder = $this->_buildNonMailFolder( - $id, - 0, - Horde_ActiveSync::FOLDER_TYPE_TASK, - $this->_displayMap[self::TASKS_FOLDER_UID]); - break; - case self::NOTES_FOLDER_UID: - $folder = $this->_buildNonMailFolder( - $id, - 0, - Horde_ActiveSync::FOLDER_TYPE_NOTE, - $this->_displayMap[self::NOTES_FOLDER_UID]); + case self::APPOINTMENTS_FOLDER_UID: + $folder = $this->_buildNonMailFolder( + $id, + 0, + Horde_ActiveSync::FOLDER_TYPE_APPOINTMENT, + $this->_displayMap[self::APPOINTMENTS_FOLDER_UID] + ); + break; + case self::CONTACTS_FOLDER_UID: + $folder = $this->_buildNonMailFolder( + $id, + 0, + Horde_ActiveSync::FOLDER_TYPE_CONTACT, + $this->_displayMap[self::CONTACTS_FOLDER_UID] + ); + break; + case self::TASKS_FOLDER_UID: + $folder = $this->_buildNonMailFolder( + $id, + 0, + Horde_ActiveSync::FOLDER_TYPE_TASK, + $this->_displayMap[self::TASKS_FOLDER_UID] + ); break; - default: - // Must be a mail folder - $folders = $this->_getMailFolders(); - foreach ($folders as $folder) { - if ($folder->_serverid == $id) { - return $folder; + case self::NOTES_FOLDER_UID: + $folder = $this->_buildNonMailFolder( + $id, + 0, + Horde_ActiveSync::FOLDER_TYPE_NOTE, + $this->_displayMap[self::NOTES_FOLDER_UID] + ); + break; + default: + // Must be a mail folder + $folders = $this->_getMailFolders(); + foreach ($folders as $folder) { + if ($folder->_serverid == $id) { + return $folder; + } } - } - throw new Horde_ActiveSync_Exception('Folder ' . $id . ' unknown'); + throw new Horde_ActiveSync_Exception('Folder ' . $id . ' unknown'); } return $folder; } - /** - * Return the list of mail server folders. - * - * @return array An array of Horde_ActiveSync_Message_Folder objects. - */ + /** + * Return the list of mail server folders. + * + * @return array An array of Horde_ActiveSync_Message_Folder objects. + */ protected function _getMailFolders() { if (empty($this->_imap)) { - $this->_mailFolders = array($this->_buildDummyFolder(self::SPECIAL_INBOX)); + $this->_mailFolders = [$this->_buildDummyFolder(self::SPECIAL_INBOX)]; $this->_mailFolders[] = $this->_buildDummyFolder(self::SPECIAL_TRASH); $this->_mailFolders[] = $this->_buildDummyFolder(self::SPECIAL_SENT); } else { - $folders = array(); + $folders = []; $imap_folders = $this->_imap->getMailboxes(); // Build the folder tree, making sure the lower levels are @@ -219,10 +224,10 @@ protected function _getMailFolders() protected function _getFolderUidForBackendId($sid, $type = null, $old_id = null) { switch ($sid) { - case 'INBOX': - return '519422f1-4c5c-4547-946a-1701c0a8015f'; - default: - return $sid; + case 'INBOX': + return '519422f1-4c5c-4547-946a-1701c0a8015f'; + default: + return $sid; } } @@ -256,9 +261,11 @@ protected function _getMailFolder($sid, array $fl, array $f) try { $specialFolders = $this->_imap->getSpecialMailboxes(); } catch (Horde_ActiveSync_Exception $e) { - $this->_logger->err(sprintf( - 'Problem retrieving special folders: %s', - $e->getMessage()) + $this->_logger->err( + sprintf( + 'Problem retrieving special folders: %s', + $e->getMessage() + ) ); throw $e; } @@ -266,30 +273,30 @@ protected function _getMailFolder($sid, array $fl, array $f) // Check for known, supported special folders. foreach ($specialFolders as $key => $value) { if (!is_array($value)) { - $value = array($value); + $value = [$value]; } foreach ($value as $mailbox) { if (!is_null($mailbox)) { switch ($key) { - case self::SPECIAL_SENT: - if ($sid == $mailbox->value) { - $folder->type = Horde_ActiveSync::FOLDER_TYPE_SENTMAIL; - return $folder; - } - break; - case self::SPECIAL_TRASH: - if ($sid == $mailbox->value) { - $folder->type = Horde_ActiveSync::FOLDER_TYPE_WASTEBASKET; - return $folder; - } - break; - - case self::SPECIAL_DRAFTS: - if ($sid == $mailbox->value) { - $folder->type = Horde_ActiveSync::FOLDER_TYPE_DRAFTS; - return $folder; - } - break; + case self::SPECIAL_SENT: + if ($sid == $mailbox->value) { + $folder->type = Horde_ActiveSync::FOLDER_TYPE_SENTMAIL; + return $folder; + } + break; + case self::SPECIAL_TRASH: + if ($sid == $mailbox->value) { + $folder->type = Horde_ActiveSync::FOLDER_TYPE_WASTEBASKET; + return $folder; + } + break; + + case self::SPECIAL_DRAFTS: + if ($sid == $mailbox->value) { + $folder->type = Horde_ActiveSync::FOLDER_TYPE_DRAFTS; + return $folder; + } + break; } } } @@ -330,7 +337,7 @@ protected function _buildNonMailFolder($id, $parent, $type, $name) public function getFolderList() { $folderlist = $this->getFolders(); - $folders = array(); + $folders = []; foreach ($folderlist as $f) { $folders[] = $this->statFolder($f->serverid, $f->parentid, $f->displayname, $f->_serverid); } @@ -349,9 +356,9 @@ public function getFolders() try { $supported = $this->_connector->listApis(); } catch (Exception $e) { - return array(); + return []; } - $folders = array(); + $folders = []; if (array_search('calendar', $supported) !== false) { $folders[] = $this->getFolder(self::APPOINTMENTS_FOLDER_UID); } @@ -372,7 +379,7 @@ public function getFolders() try { $folders = array_merge($folders, $this->_getMailFolders()); } catch (Horde_ActiveSync_Exception $e) { - return array(); + return []; } } $this->_folders = $folders; @@ -402,51 +409,51 @@ public function getFolders() public function getServerChanges($folderId, $from_ts, $to_ts, $cutoffdate, $ping) { - $changes = array( - 'add' => array(), - 'delete' => array(), - 'modify' => array() - ); + $changes = [ + 'add' => [], + 'delete' => [], + 'modify' => [], + ]; if ($from_ts == 0 && !$ignoreFirstSync) { - $startstamp = (int)$cutoffdate; + $startstamp = (int) $cutoffdate; $endstamp = time() + 32140800; //60 * 60 * 24 * 31 * 12 == one year $changes['add'] = $this->_connector->listUids($startstamp, $endstamp); } else { $changes = $this->_connector->getChanges($folderId, $from_ts, $to_ts); } - $results = array(); + $results = []; foreach ($changes['add'] as $add) { - $results[] = array( + $results[] = [ 'id' => $add, 'type' => Horde_ActiveSync::CHANGE_TYPE_CHANGE, - 'flags' => Horde_ActiveSync::FLAG_NEWMESSAGE); + 'flags' => Horde_ActiveSync::FLAG_NEWMESSAGE]; } // For CLASS_EMAIL, all changes are a change in flags. if ($folder->collectionClass() == Horde_ActiveSync::CLASS_EMAIL) { $flags = $folder->flags(); foreach ($changes['modify'] as $uid) { - $results[] = array( + $results[] = [ 'id' => $uid, 'type' => Horde_ActiveSync::CHANGE_TYPE_FLAGS, - 'flags' => $flags[$uid] - ); + 'flags' => $flags[$uid], + ]; } } else { foreach ($changes['modify'] as $change) { - $results[] = array( + $results[] = [ 'id' => $change, - 'type' => Horde_ActiveSync::CHANGE_TYPE_CHANGE - ); + 'type' => Horde_ActiveSync::CHANGE_TYPE_CHANGE, + ]; } } // Server Deletions foreach ($changes['delete'] as $deleted) { - $results[] = array( + $results[] = [ 'id' => $deleted, - 'type' => Horde_ActiveSync::CHANGE_TYPE_DELETE); + 'type' => Horde_ActiveSync::CHANGE_TYPE_DELETE]; } return $results; @@ -463,7 +470,7 @@ public function getServerChanges($folderId, $from_ts, $to_ts, $cutoffdate, $ping public function statMessage($folderId, $id) { $mod = $this->_connector->getActionTimestamp($id, 'modify'); - $message = array(); + $message = []; $message['id'] = $id; $message['mod'] = $mod; $message['flags'] = 1; @@ -488,7 +495,7 @@ public function statMessage($folderId, $id) */ public function getMessage($folderid, $id, array $collection) { - return $this->_connector->export($id, array()); + return $this->_connector->export($id, []); } /** @@ -528,7 +535,7 @@ public function getWasteBasket($class) * * @return array|boolean A stat array if successful, otherwise false. */ - public function changeMessage($folderid, $id, Horde_ActiveSync_Message_Base $message, $device) { } + public function changeMessage($folderid, $id, Horde_ActiveSync_Message_Base $message, $device) {} /** * Set the read (\seen) flag on the specified message. @@ -538,7 +545,7 @@ public function changeMessage($folderid, $id, Horde_ActiveSync_Message_Base $mes * @param integer $flag The value to set the flag to. * @deprecated Will be removed in 3.0, use changeMessage() instead. */ - public function setReadFlag($folderid, $uid, $flag) { } + public function setReadFlag($folderid, $uid, $flag) {} /** * Sends the email represented by the rfc822 string received by the client. @@ -554,8 +561,12 @@ public function setReadFlag($folderid, $uid, $flag) { } * @return boolean */ public function sendMail( - $rfc822, $forward = null, $reply = null, $parent = null, $save = true) - { + $rfc822, + $forward = null, + $reply = null, + $parent = null, + $save = true + ) { return true; } @@ -573,7 +584,7 @@ public function sendMail( * array('content-type' => {the content-type of the attachement}, * 'data' => {the raw attachment data}) */ - public function getAttachment($name, array $options = array()) { } + public function getAttachment($name, array $options = []) {} /** * Return the specified attachement data for an ITEMOPERATIONS request. @@ -582,7 +593,7 @@ public function getAttachment($name, array $options = array()) { } * * @return */ - public function itemOperationsGetAttachmentData($filereference) { } + public function itemOperationsGetAttachmentData($filereference) {} /** * Returnmail object represented by the specified longid. Used to fetch @@ -594,7 +605,7 @@ public function itemOperationsGetAttachmentData($filereference) { } * * @return Horde_ActiveSync_Message_Base The message requested. */ - public function itemOperationsFetchMailbox($longid, array $bodyprefs, $mimesupport) { } + public function itemOperationsFetchMailbox($longid, array $bodyprefs, $mimesupport) {} /** * Return a documentlibrary item. @@ -606,7 +617,7 @@ public function itemOperationsFetchMailbox($longid, array $bodyprefs, $mimesuppo * * @return array An array containing the data and metadata: */ - public function itemOperationsGetDocumentLibraryLink($linkid, $cred) { } + public function itemOperationsGetDocumentLibraryLink($linkid, $cred) {} /** * Build a stat structure for an email message. @@ -618,10 +629,10 @@ public function itemOperationsGetDocumentLibraryLink($linkid, $cred) { } */ public function statMailMessage($folderid, $id) { - return array( + return [ 'id' => $id, 'mod' => 0, - 'flags' => false); + 'flags' => false]; } /** @@ -647,7 +658,7 @@ public function getSpecialFolderNameByType($type) * set to false otherwise. @since 3.0 * @return array An array of provisionable properties and values. */ - public function getCurrentPolicy() { } + public function getCurrentPolicy() {} /** * Return settings from the backend for a SETTINGS request. @@ -657,7 +668,7 @@ public function getCurrentPolicy() { } * * @return array The requested settings. */ - public function getSettings(array $settings, $device) { } + public function getSettings(array $settings, $device) {} /** * Set backend settings from a SETTINGS request. @@ -669,14 +680,14 @@ public function getSettings(array $settings, $device) { } * array('oof' => Horde_ActiveSync_Request_Settings::STATUS_SUCCESS, * 'deviceinformation' => Horde_ActiveSync_Request_Settings::STATUS_SUCCESS) { } */ - public function setSettings(array $settings, $device) { } + public function setSettings(array $settings, $device) {} /** * Return properties for an AUTODISCOVER request. * * @return array An array of properties. */ - public function autoDiscover() { } + public function autoDiscover() {} /** * Attempt to guess a username based on the email address passed from @@ -686,7 +697,7 @@ public function autoDiscover() { } * * @return string The username to use to authenticate to Horde with. */ - public function getUsernameFromEmail($email) { } + public function getUsernameFromEmail($email) {} /** * Handle ResolveRecipient requests @@ -718,14 +729,14 @@ public function getUsernameFromEmail($email) { } * - availability: (string) A EAS style FB string. * - picture: (Horde_ActiveSync_Message_ResolveRecipientsPicture) */ - public function resolveRecipient($type, $search, array $options = array()) { } + public function resolveRecipient($type, $search, array $options = []) {} /** * Returns the provisioning support for the current request. * * @return mixed The value of the provisiong support flag. */ - public function getProvisioning() { } + public function getProvisioning() {} /** * Hanlde meeting responses. @@ -741,7 +752,7 @@ public function getProvisioning() { } * @return string The UID of any created calendar entries, otherwise false. * @throws Horde_ActiveSync_Exception, Horde_Exception_NotFound */ - public function meetingResponse(array $response) { } + public function meetingResponse(array $response) {} /** * Request freebusy information from the server @@ -752,16 +763,16 @@ public function meetingResponse(array $response) { } * @return mixed boolean|array The FB information, if available. Otherwise * false. */ - public function getFreebusy($user, array $options = array()) { } + public function getFreebusy($user, array $options = []) {} public function getHeartbeatConfig() { - return array( + return [ 'heartbeatmin' => 60, 'heartbeatmax' => 2700, 'heartbeatdefault' => 480, 'deviceping' => true, - 'waitinterval' => 10); + 'waitinterval' => 10]; } } diff --git a/lib/Horde/ActiveSync/Driver/MockConnector.php b/lib/Horde/ActiveSync/Driver/MockConnector.php index 952018bb..52368324 100644 --- a/lib/Horde/ActiveSync/Driver/MockConnector.php +++ b/lib/Horde/ActiveSync/Driver/MockConnector.php @@ -1,4 +1,5 @@ array(), - 'modify' => array(), - 'delete' => array()); + return [ + 'add' => [], + 'modify' => [], + 'delete' => []]; } /** @@ -61,10 +61,7 @@ public function getActionTimestamp($id, $action) * * @return Horde_ActiveSync_Message_Base */ - public function export($id, $options) - { - - } + public function export($id, $options) {} diff --git a/lib/Horde/ActiveSync/Exception.php b/lib/Horde/ActiveSync/Exception.php index 68d130ee..5d9f0117 100644 --- a/lib/Horde/ActiveSync/Exception.php +++ b/lib/Horde/ActiveSync/Exception.php @@ -1,8 +1,9 @@ * @package ActiveSync */ -class Horde_ActiveSync_Exception_FolderExists extends Horde_ActiveSync_Exception -{ -} +class Horde_ActiveSync_Exception_FolderExists extends Horde_ActiveSync_Exception {} diff --git a/lib/Horde/ActiveSync/Exception/FolderGone.php b/lib/Horde/ActiveSync/Exception/FolderGone.php index 7cfb39d5..4a5e6c3a 100644 --- a/lib/Horde/ActiveSync/Exception/FolderGone.php +++ b/lib/Horde/ActiveSync/Exception/FolderGone.php @@ -1,4 +1,5 @@ * @package ActiveSync */ -class Horde_ActiveSync_Exception_FolderGone extends Horde_ActiveSync_Exception -{ -} +class Horde_ActiveSync_Exception_FolderGone extends Horde_ActiveSync_Exception {} diff --git a/lib/Horde/ActiveSync/Exception/InvalidRequest.php b/lib/Horde/ActiveSync/Exception/InvalidRequest.php index 99b88af2..1b1735f4 100644 --- a/lib/Horde/ActiveSync/Exception/InvalidRequest.php +++ b/lib/Horde/ActiveSync/Exception/InvalidRequest.php @@ -1,4 +1,5 @@ * @package ActiveSync */ -class Horde_ActiveSync_Exception_InvalidRequest extends Horde_ActiveSync_Exception -{ -} +class Horde_ActiveSync_Exception_InvalidRequest extends Horde_ActiveSync_Exception {} diff --git a/lib/Horde/ActiveSync/Exception/StaleState.php b/lib/Horde/ActiveSync/Exception/StaleState.php index 53d49357..cd263bb9 100644 --- a/lib/Horde/ActiveSync/Exception/StaleState.php +++ b/lib/Horde/ActiveSync/Exception/StaleState.php @@ -1,4 +1,5 @@ * @package ActiveSync */ -class Horde_ActiveSync_Exception_StaleState extends Horde_ActiveSync_Exception -{ -} +class Horde_ActiveSync_Exception_StaleState extends Horde_ActiveSync_Exception {} diff --git a/lib/Horde/ActiveSync/Exception/StateGone.php b/lib/Horde/ActiveSync/Exception/StateGone.php index b42abbc1..5f8b905d 100644 --- a/lib/Horde/ActiveSync/Exception/StateGone.php +++ b/lib/Horde/ActiveSync/Exception/StateGone.php @@ -1,4 +1,5 @@ * @package ActiveSync */ -class Horde_ActiveSync_Exception_StateGone extends Horde_ActiveSync_Exception -{ -} +class Horde_ActiveSync_Exception_StateGone extends Horde_ActiveSync_Exception {} diff --git a/lib/Horde/ActiveSync/Exception/TemporaryFailure.php b/lib/Horde/ActiveSync/Exception/TemporaryFailure.php index c3e179da..bb082e96 100644 --- a/lib/Horde/ActiveSync/Exception/TemporaryFailure.php +++ b/lib/Horde/ActiveSync/Exception/TemporaryFailure.php @@ -1,4 +1,5 @@ * @package ActiveSync */ -class Horde_ActiveSync_Exception_TemporaryFailure extends Horde_ActiveSync_Exception -{ -} +class Horde_ActiveSync_Exception_TemporaryFailure extends Horde_ActiveSync_Exception {} diff --git a/lib/Horde/ActiveSync/Folder/Base.php b/lib/Horde/ActiveSync/Folder/Base.php index d37c1958..e40367e4 100644 --- a/lib/Horde/ActiveSync/Folder/Base.php +++ b/lib/Horde/ActiveSync/Folder/Base.php @@ -1,4 +1,5 @@ _serverid = $serverid; $this->_status = $status; $this->_class = $class; @@ -139,7 +142,7 @@ public function setSoftDeleteTimes($sincedate, $ts) */ public function getSoftDeleteTimes() { - return array($this->_lastSinceDate, $this->_softDelete); + return [$this->_lastSinceDate, $this->_softDelete]; } /** diff --git a/lib/Horde/ActiveSync/Folder/Collection.php b/lib/Horde/ActiveSync/Folder/Collection.php index c866f83c..8e5190d6 100644 --- a/lib/Horde/ActiveSync/Folder/Collection.php +++ b/lib/Horde/ActiveSync/Folder/Collection.php @@ -1,10 +1,11 @@ * @package ActiveSync */ @@ -14,13 +15,13 @@ * * @license http://www.horde.org/licenses/gpl GPLv2 * - * @copyright 2012-2026 Horde LLC (http://www.horde.org) + * @copyright 2012-2020 Horde LLC (http://www.horde.org) * @author Michael J Rubinsky * @package ActiveSync */ class Horde_ActiveSync_Folder_Collection extends Horde_ActiveSync_Folder_Base implements Serializable { - const VERSION = 1; + public const VERSION = 1; /** * Updates the internal UID cache, and clears the internal @@ -41,38 +42,39 @@ public function __toString() return sprintf( 'serverid: %s\nclass: %s\n', $this->serverid(), - $this->collectionClass()); + $this->collectionClass() + ); } /** - * Serialize this object using modern PHP serialization. + * Serialize this object. * - * @return array The data to serialize. - * @since 3.0.0-beta2 + * @return string The serialized data. */ - public function __serialize(): array + public function serialize() { - return array( - 's' => $this->_status, - 'f' => $this->_serverid, - 'c' => $this->_class, - 'lsd' => $this->_lastSinceDate, - 'sd' => $this->_softDelete, - 'i' => $this->haveInitialSync, - 'v' => self::VERSION + return json_encode( + [ + 's' => $this->_status, + 'f' => $this->_serverid, + 'c' => $this->_class, + 'lsd' => $this->_lastSinceDate, + 'sd' => $this->_softDelete, + 'i' => $this->haveInitialSync, + 'v' => self::VERSION] ); } /** - * Reconstruct the object from serialized data using modern PHP serialization. + * Reconstruct the object from serialized data. * - * @param array $data The serialized data. + * @param string $data The serialized data. * @throws Horde_ActiveSync_Exception_StaleState - * @since 3.0.0-beta2 */ - public function __unserialize(array $data): void + public function unserialize($data) { - if (empty($data['v']) || $data['v'] != self::VERSION) { + $data = @json_decode($data, true); + if (!is_array($data) || empty($data['v']) || $data['v'] != self::VERSION) { throw new Horde_ActiveSync_Exception_StaleState('Cache version change'); } $this->_status = $data['s']; @@ -83,39 +85,4 @@ public function __unserialize(array $data): void $this->_softDelete = empty($data['sd']) ? 0 : $data['sd']; } - /** - * Serialize this object (legacy Serializable interface). - * - * Delegates to __serialize() and JSON-encodes for backward compatibility - * with old "C" format data storage. - * - * @return string The serialized data. - */ - public function serialize() - { - return json_encode($this->__serialize()); - } - - /** - * Reconstruct the object from serialized data (legacy Serializable interface). - * - * Supports both old "C" format (JSON-encoded) data and delegates to - * __unserialize() for processing. - * - * @param string $data The serialized data. - * @throws Horde_ActiveSync_Exception_StaleState - */ - public function unserialize($data) - { - $decoded = @json_decode($data, true); - if (!is_array($decoded)) { - throw new Horde_ActiveSync_Exception_StaleState('Invalid serialized data'); - } - // Ensure version key exists for old data that might be missing it - if (!isset($decoded['v'])) { - $decoded['v'] = self::VERSION; - } - $this->__unserialize($decoded); - } - } diff --git a/lib/Horde/ActiveSync/Folder/Imap.php b/lib/Horde/ActiveSync/Folder/Imap.php index f788b8b6..a485c274 100644 --- a/lib/Horde/ActiveSync/Folder/Imap.php +++ b/lib/Horde/ActiveSync/Folder/Imap.php @@ -1,10 +1,11 @@ * @package ActiveSync */ @@ -14,23 +15,23 @@ * * @license http://www.horde.org/licenses/gpl GPLv2 * - * @copyright 2012-2026 Horde LLC (http://www.horde.org) + * @copyright 2012-2020 Horde LLC (http://www.horde.org) * @author Michael J Rubinsky * @package ActiveSync */ class Horde_ActiveSync_Folder_Imap extends Horde_ActiveSync_Folder_Base implements Serializable { /* Key names for various IMAP server status values */ - const UIDVALIDITY = 'uidvalidity'; - const UIDNEXT = 'uidnext'; - const HIGHESTMODSEQ = 'highestmodseq'; - const MESSAGES = 'messages'; + public const UIDVALIDITY = 'uidvalidity'; + public const UIDNEXT = 'uidnext'; + public const HIGHESTMODSEQ = 'highestmodseq'; + public const MESSAGES = 'messages'; /* Serialize version */ - const VERSION = 2; + public const VERSION = 2; /* The UID count at which UID lists will be compressed before serialization */ - const COMPRESSION_LIMIT = 500; + public const COMPRESSION_LIMIT = 500; /** * The folder's current message list. @@ -39,7 +40,7 @@ class Horde_ActiveSync_Folder_Imap extends Horde_ActiveSync_Folder_Base implemen * * @var array */ - protected $_messages = array(); + protected $_messages = []; /** * Internal cache of message UIDs that have been added since last sync. @@ -47,7 +48,7 @@ class Horde_ActiveSync_Folder_Imap extends Horde_ActiveSync_Folder_Base implemen * * @var array */ - protected $_added = array(); + protected $_added = []; /** * Internal cache of message UIDs that have been modified on the server @@ -55,7 +56,7 @@ class Horde_ActiveSync_Folder_Imap extends Horde_ActiveSync_Folder_Base implemen * * @var array */ - protected $_changed = array(); + protected $_changed = []; /** * Internal cache of message UIDs that have been expunged from the IMAP @@ -63,7 +64,7 @@ class Horde_ActiveSync_Folder_Imap extends Horde_ActiveSync_Folder_Base implemen * * @var array */ - protected $_removed = array(); + protected $_removed = []; /** * Array of messages to be SOFTDELETEd from client. Only used when we have @@ -72,7 +73,7 @@ class Horde_ActiveSync_Folder_Imap extends Horde_ActiveSync_Folder_Base implemen * * @var array */ - protected $_softDeleted = array(); + protected $_softDeleted = []; /** * Internal cache of message flag changes. Should be one entry for each UID @@ -82,7 +83,7 @@ class Horde_ActiveSync_Folder_Imap extends Horde_ActiveSync_Folder_Base implemen * * @var array */ - protected $_flags = array(); + protected $_flags = []; /** * Internal cache of custom message flags (i.e., categories). Should contain @@ -92,7 +93,7 @@ class Horde_ActiveSync_Folder_Imap extends Horde_ActiveSync_Folder_Base implemen * * @var array */ - protected $_categories = array(); + protected $_categories = []; /** * Internal flag to indicate initial first sync/prime. @@ -114,9 +115,11 @@ class Horde_ActiveSync_Folder_Imap extends Horde_ActiveSync_Folder_Base implemen * being returned. @since 2.24.0 */ public function setChanges( - array $messages, array $flags = array(), array $categories = array(), - $resetMinUid = false) - { + array $messages, + array $flags = [], + array $categories = [], + $resetMinUid = false + ) { $uidnext = $this->uidnext(); $minuid = $this->minuid(); $modseq = $this->modseq(); @@ -140,8 +143,8 @@ public function setChanges( // Do not know about this message continue; } - if ((isset($flags[$uid]['read']) && $flags[$uid]['read'] != $this->_messages[$uid]['read']) || - (isset($flags[$uid]['flagged']) && $flags[$uid]['flagged'] != $this->_messages[$uid]['flagged'])) { + if ((isset($flags[$uid]['read']) && $flags[$uid]['read'] != $this->_messages[$uid]['read']) + || (isset($flags[$uid]['flagged']) && $flags[$uid]['flagged'] != $this->_messages[$uid]['flagged'])) { $this->_changed[] = $uid; } @@ -229,7 +232,7 @@ public function setSoftDeleted(array $softDeleted) * * @throws Horde_ActiveSync_Exception_StaleState */ - public function checkValidity(array $params = array()) + public function checkValidity(array $params = []) { if (!$this->uidvalidity()) { throw new Horde_ActiveSync_Exception('State not initialized.'); @@ -251,7 +254,8 @@ public function setRemoved(array $uids) if (count($uids)) { if ($uids[0] < $this->minuid()) { throw new Horde_ActiveSync_Exception_StaleState( - 'BROKEN IMAP server has returned all VANISHED UIDs.'); + 'BROKEN IMAP server has returned all VANISHED UIDs.' + ); } } @@ -284,11 +288,11 @@ public function updateState() } // Clean up - $this->_removed = array(); - $this->_added = array(); - $this->_changed = array(); - $this->_flags = array(); - $this->_softDeleted = array(); + $this->_removed = []; + $this->_added = []; + $this->_changed = []; + $this->_flags = []; + $this->_softDeleted = []; $this->haveInitialSync = true; } @@ -423,104 +427,61 @@ public function minuid() } /** - * Serialize this object using modern PHP serialization. + * Serialize this object. * - * @return array The data to serialize. - * @since 3.0.0-beta2 + * @return string The serialized data. */ - public function __serialize(): array + public function serialize() { if (!empty($this->_status[self::HIGHESTMODSEQ])) { - $msgs = (count($this->_messages) > self::COMPRESSION_LIMIT) ? - $this->_toSequenceString($this->_messages) : - implode(',', $this->_messages); + $msgs = (count($this->_messages) > self::COMPRESSION_LIMIT) + ? $this->_toSequenceString($this->_messages) + : implode(',', $this->_messages); } else { $msgs = $this->_messages; } - return array( - 's' => $this->_status, - 'm' => $msgs, - 'f' => $this->_serverid, - 'c' => $this->_class, - 'lsd' => $this->_lastSinceDate, - 'sd' => $this->_softDelete, - 'hi' => $this->haveInitialSync, - 'v' => self::VERSION + return json_encode( + [ + 's' => $this->_status, + 'm' => $msgs, + 'f' => $this->_serverid, + 'c' => $this->_class, + 'lsd' => $this->_lastSinceDate, + 'sd' => $this->_softDelete, + 'hi' => $this->haveInitialSync, + 'v' => self::VERSION] ); } /** - * Reconstruct the object from serialized data using modern PHP serialization. - * - * @param array $data The serialized data. - * @throws Horde_ActiveSync_Exception_StaleState - * @since 3.0.0-beta2 - */ - public function __unserialize(array $data): void - { - if (empty($data['v']) || $data['v'] != self::VERSION) { - throw new Horde_ActiveSync_Exception_StaleState('Cache version change'); - } - $this->_status = $data['s']; - $this->_messages = $data['m']; - $this->_serverid = $data['f']; - $this->_class = $data['c']; - $this->_lastSinceDate = $data['lsd']; - $this->_softDelete = $data['sd']; - $this->haveInitialSync = empty($data['hi']) ? !empty($this->_messages) : $data['hi']; - - if (!empty($this->_status[self::HIGHESTMODSEQ]) && is_string($this->_messages)) { - $this->_messages = $this->_fromSequenceString($this->_messages); - } - } - - /** - * Serialize this object (legacy Serializable interface). - * - * Delegates to __serialize() and JSON-encodes for backward compatibility - * with old "C" format data storage. Also supports fallback to old - * serialization format for expensive email collection resyncs. - * - * @return string The serialized data. - */ - public function serialize() - { - return json_encode($this->__serialize()); - } - - /** - * Reconstruct the object from serialized data (legacy Serializable interface). - * - * Supports both old "C" format (JSON-encoded or PHP-serialized) data and - * delegates to __unserialize() for processing. Falls back to old - * serialization strategy to avoid expensive email collection resyncs. + * Reconstruct the object from serialized data. * * @param string $data The serialized data. * @throws Horde_ActiveSync_Exception_StaleState */ public function unserialize($data) { - $decoded = json_decode($data, true); - if (!is_array($decoded) || empty($decoded['v']) || $decoded['v'] != self::VERSION) { + $d_data = json_decode($data, true); + if (!is_array($d_data) || empty($d_data['v']) || $d_data['v'] != self::VERSION) { // Try using the old serialization strategy, since this would save // an expensive resync of email collections. - $decoded = @unserialize($data); - if (!is_array($decoded) || empty($decoded['v']) || $decoded['v'] != 1) { + $d_data = @unserialize($data); + if (!is_array($d_data) || empty($d_data['v']) || $d_data['v'] != 1) { throw new Horde_ActiveSync_Exception_StaleState('Cache version change'); } - // Upgrade version 1 data to current VERSION - $decoded['v'] = self::VERSION; - - // Version 1 had messages as indexed array, but version 2 needs - // associative array (uid => flags) for non-MODSEQ servers - if (is_array($decoded['m']) && !empty($decoded['m']) && - empty($decoded['s'][self::HIGHESTMODSEQ])) { - // Convert indexed array to associative: [100, 101] -> [100 => [], 101 => []] - $decoded['m'] = array_fill_keys($decoded['m'], []); - } } - $this->__unserialize($decoded); + $this->_status = $d_data['s']; + $this->_messages = $d_data['m']; + $this->_serverid = $d_data['f']; + $this->_class = $d_data['c']; + $this->_lastSinceDate = $d_data['lsd']; + $this->_softDelete = $d_data['sd']; + $this->haveInitialSync = empty($d_data['hi']) ? !empty($this->_messages) : $d_data['hi']; + + if (!empty($this->_status[self::HIGHESTMODSEQ]) && is_string($this->_messages)) { + $this->_messages = $this->_fromSequenceString($this->_messages); + } } /** @@ -558,7 +519,7 @@ protected function _toSequenceString(array $ids) sort($in, SORT_NUMERIC); $first = $last = array_shift($in); $i = count($in) - 1; - $out = array(); + $out = []; reset($in); foreach ($in as $key => $val) { @@ -598,7 +559,7 @@ protected function _toSequenceString(array $ids) */ protected function _fromSequenceString($str) { - $ids = array(); + $ids = []; $str = trim($str); if (!strlen($str)) { diff --git a/lib/Horde/ActiveSync/Folder/RI.php b/lib/Horde/ActiveSync/Folder/RI.php index a2e895d3..e8d9b1bb 100644 --- a/lib/Horde/ActiveSync/Folder/RI.php +++ b/lib/Horde/ActiveSync/Folder/RI.php @@ -1,10 +1,11 @@ * @package ActiveSync */ @@ -14,23 +15,23 @@ * * @license http://www.horde.org/licenses/gpl GPLv2 * - * @copyright 2014-2026 Horde LLC (http://www.horde.org) + * @copyright 2014-2020 Horde LLC (http://www.horde.org) * @author Michael J Rubinsky * @package ActiveSync */ class Horde_ActiveSync_Folder_RI extends Horde_ActiveSync_Folder_Base implements Serializable { - const VERSION = 1; + public const VERSION = 1; /** * The current list of recipient email addresses. * * @var array */ - protected $_contacts = array(); + protected $_contacts = []; protected $_serverid = 'RI'; - protected $_removed = array(); - protected $_added = array(); + protected $_removed = []; + protected $_added = []; /** * Set the current Recipient Cache @@ -65,8 +66,8 @@ public function setChanges(array $contacts) public function updateState() { $this->haveInitialSync = true; - $this->_removed = array(); - $this->_added = array(); + $this->_removed = []; + $this->_added = []; } /** @@ -79,7 +80,8 @@ public function __toString() return sprintf( 'serverid: %s\nclass: %s\n', $this->serverid(), - $this->collectionClass()); + $this->collectionClass() + ); } /** @@ -107,31 +109,31 @@ public function removed() } /** - * Serialize this object using modern PHP serialization. + * Serialize this object. * - * @return array The data to serialize. - * @since 3.0.0-beta2 + * @return string The serialized data. */ - public function __serialize(): array + public function serialize() { - return array( - 'd' => $this->_contacts, - 'f' => $this->_serverid, - 'c' => $this->_class, - 'v' => self::VERSION + return json_encode( + [ + 'd' => $this->_contacts, + 'f' => $this->_serverid, + 'c' => $this->_class, + 'v' => self::VERSION] ); } /** - * Reconstruct the object from serialized data using modern PHP serialization. + * Reconstruct the object from serialized data. * - * @param array $data The serialized data. + * @param string $data The serialized data. * @throws Horde_ActiveSync_Exception_StaleState - * @since 3.0.0-beta2 */ - public function __unserialize(array $data): void + public function unserialize($data) { - if (empty($data['v']) || $data['v'] != self::VERSION) { + $data = @json_decode($data, true); + if (!is_array($data) || empty($data['v']) || $data['v'] != self::VERSION) { throw new Horde_ActiveSync_Exception_StaleState('Cache version change'); } $this->_contacts = $data['d']; @@ -139,39 +141,4 @@ public function __unserialize(array $data): void $this->_class = $data['c']; } - /** - * Serialize this object (legacy Serializable interface). - * - * Delegates to __serialize() and JSON-encodes for backward compatibility - * with old "C" format data storage. - * - * @return string The serialized data. - */ - public function serialize() - { - return json_encode($this->__serialize()); - } - - /** - * Reconstruct the object from serialized data (legacy Serializable interface). - * - * Supports both old "C" format (JSON-encoded) data and delegates to - * __unserialize() for processing. - * - * @param string $data The serialized data. - * @throws Horde_ActiveSync_Exception_StaleState - */ - public function unserialize($data) - { - $decoded = @json_decode($data, true); - if (!is_array($decoded)) { - throw new Horde_ActiveSync_Exception_StaleState('Invalid serialized data'); - } - // Ensure version key exists for old data that might be missing it - if (!isset($decoded['v'])) { - $decoded['v'] = self::VERSION; - } - $this->__unserialize($decoded); - } - } diff --git a/lib/Horde/ActiveSync/Imap/Adapter.php b/lib/Horde/ActiveSync/Imap/Adapter.php index b9167af1..57589bcd 100644 --- a/lib/Horde/ActiveSync/Imap/Adapter.php +++ b/lib/Horde/ActiveSync/Imap/Adapter.php @@ -1,4 +1,5 @@ _imap = $params['factory']; Horde_Mime_Part::$defaultCharset = 'UTF-8'; @@ -91,9 +92,9 @@ public function setOptions(array $options) * on failure. @since 2.37.0 * @throws new Horde_ActiveSync_Exception, Horde_ActiveSync_Exception_FolderGone */ - public function appendMessage($folderid, $msg, array $flags = array()) + public function appendMessage($folderid, $msg, array $flags = []) { - $message = array(array('data' => $msg, 'flags' => $flags)); + $message = [['data' => $msg, 'flags' => $flags]]; $mbox = new Horde_Imap_Client_Mailbox($folderid); try { $ids = $this->_getImapOb()->append($mbox, $message); @@ -184,7 +185,7 @@ public function emptyMailbox($mbox) { $mbox = new Horde_Imap_Client_Mailbox($mbox); try { - $this->_getImapOb()->expunge($mbox, array('delete' => true)); + $this->_getImapOb()->expunge($mbox, ['delete' => true]); } catch (Horde_Imap_Client_Exception $e) { throw new Horde_ActiveSync_Exception($e); } @@ -219,11 +220,13 @@ public function deleteMessages(array $uids, $folderid) } try { - $imap->store($mbox, array( - 'ids' => $ids_obj, - 'add' => array('\deleted')) + $imap->store( + $mbox, + [ + 'ids' => $ids_obj, + 'add' => ['\deleted']] ); - $imap->expunge($mbox, array('ids' => $ids_obj)); + $imap->expunge($mbox, ['ids' => $ids_obj]); } catch (Horde_Imap_Client_Exception $e) { throw new Horde_ActiveSync_Exception($e); } @@ -246,7 +249,7 @@ public function getAttachment($mailbox, $uid, $part) { $imap = $this->_getImapOb(); $mbox = new Horde_Imap_Client_Mailbox($mailbox); - $messages = $this->_getMailMessages($mbox, array($uid)); + $messages = $this->_getMailMessages($mbox, [$uid]); if (empty($messages[$uid]) || !$messages[$uid]->exists(Horde_Imap_Client::FETCH_STRUCTURE)) { throw new Horde_ActiveSync_Exception('Message Gone'); } @@ -292,17 +295,17 @@ public function getSpecialMailboxes() * @todo This should be renamed to getImapMessages since we can now accept * an array of $uids. */ - public function getImapMessage($mailbox, $uid, array $options = array()) + public function getImapMessage($mailbox, $uid, array $options = []) { if (!is_array($uid)) { - $uid = array($uid); + $uid = [$uid]; } $mbox = new Horde_Imap_Client_Mailbox($mailbox); // @todo H6 - expand the $options array the same as _getMailMessages() // for now, always retrieve the envelope data as well. $options['envelope'] = true; $messages = $this->_getMailMessages($mbox, $uid, $options); - $res = array(); + $res = []; foreach ($messages as $id => $message) { if ($message->exists(Horde_Imap_Client::FETCH_STRUCTURE)) { $res[$id] = new Horde_ActiveSync_Imap_Message($this->_getImapOb(), $mbox, $message, $this->_options); @@ -334,19 +337,20 @@ public function getImapMessage($mailbox, $uid, array $options = array()) * Horde_ActiveSync_Exception, Horde_ActiveSync_Exception_StaleState */ public function getMessageChanges( - Horde_ActiveSync_Folder_Imap $folder, array $options = array()) - { + Horde_ActiveSync_Folder_Imap $folder, + array $options = [] + ) { $imap = $this->_getImapOb(); $mbox = new Horde_Imap_Client_Mailbox($folder->serverid()); - $flags = array(); - $search_uids = array(); + $flags = []; + $search_uids = []; // Note: non-CONDSTORE servers will return a highestmodseq of 0 - $status_flags = Horde_Imap_Client::STATUS_HIGHESTMODSEQ | - Horde_Imap_Client::STATUS_UIDVALIDITY | - Horde_Imap_Client::STATUS_UIDNEXT_FORCE | - Horde_Imap_Client::STATUS_MESSAGES | - Horde_Imap_Client::STATUS_FORCE_REFRESH; + $status_flags = Horde_Imap_Client::STATUS_HIGHESTMODSEQ + | Horde_Imap_Client::STATUS_UIDVALIDITY + | Horde_Imap_Client::STATUS_UIDNEXT_FORCE + | Horde_Imap_Client::STATUS_MESSAGES + | Horde_Imap_Client::STATUS_FORCE_REFRESH; try { $status = $imap->status($mbox, $status_flags); @@ -355,9 +359,11 @@ public function getMessageChanges( throw new Horde_ActiveSync_Exception_FolderGone($e); } - $this->_logger->meta(sprintf( - 'IMAP status: %s', - serialize($status)) + $this->_logger->meta( + sprintf( + 'IMAP status: %s', + serialize($status) + ) ); // UIDVALIDITY @@ -367,21 +373,30 @@ public function getMessageChanges( $current_modseq = $status[Horde_ActiveSync_Folder_Imap::HIGHESTMODSEQ]; $modseq_corrupted = $folder->modseq() > $current_modseq; - if ($modseq_corrupted || (($current_modseq && $folder->modseq() > 0) && - (($folder->modseq() < $current_modseq) || - !empty($options['softdelete']) || !empty($options['refreshfilter'])))) { + if ($modseq_corrupted || (($current_modseq && $folder->modseq() > 0) + && (($folder->modseq() < $current_modseq) + || !empty($options['softdelete']) || !empty($options['refreshfilter'])))) { $strategy = new Horde_ActiveSync_Imap_Strategy_Modseq( - $this->_imap, $status, $folder, $this->_logger + $this->_imap, + $status, + $folder, + $this->_logger ); $folder = $strategy->getChanges($options); } elseif ($folder->uidnext() == 0) { $strategy = new Horde_ActiveSync_Imap_Strategy_Initial( - $this->_imap, $status, $folder, $this->_logger + $this->_imap, + $status, + $folder, + $this->_logger ); $folder = $strategy->getChanges($options); } elseif ($current_modseq == 0) { $strategy = new Horde_ActiveSync_Imap_Strategy_Plain( - $this->_imap, $status, $folder, $this->_logger + $this->_imap, + $status, + $folder, + $this->_logger ); $folder = $strategy->getChanges($options); } elseif ($current_modseq > 0 && $folder->modseq() == 0) { @@ -412,11 +427,11 @@ public function getMessageChanges( * * @return array An array of Horde_ActiveSync_Message_Mail objects. */ - public function getMessages($folderid, array $messages, array $options = array()) + public function getMessages($folderid, array $messages, array $options = []) { $mbox = new Horde_Imap_Client_Mailbox($folderid); - $results = $this->_getMailMessages($mbox, $messages, array('headers' => true, 'envelope' => true)); - $ret = array(); + $results = $this->_getMailMessages($mbox, $messages, ['headers' => true, 'envelope' => true]); + $ret = []; foreach ($results as $data) { if ($data->exists(Horde_Imap_Client::FETCH_STRUCTURE)) { try { @@ -474,7 +489,7 @@ public function getUidFromMidInFolders($id, array $folders) } $uid = $results['match']->ids; if (!empty($uid)) { - return array($mbox, current($uid)); + return [$mbox, current($uid)]; } } @@ -509,7 +524,7 @@ public function moveMessage($folderid, array $ids, $newfolderid) } try { - return $imap->copy($from, $to, array('ids' => $ids_obj, 'move' => true, 'force_map' => true)); + return $imap->copy($from, $to, ['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()); @@ -530,10 +545,10 @@ public function ping(Horde_ActiveSync_Folder_Imap $folder) { $mbox = new Horde_Imap_Client_Mailbox($folder->serverid()); // Note: non-CONDSTORE servers will return a highestmodseq of 0 - $status_flags = Horde_Imap_Client::STATUS_HIGHESTMODSEQ | - Horde_Imap_Client::STATUS_UIDNEXT_FORCE | - Horde_Imap_Client::STATUS_MESSAGES | - Horde_Imap_Client::STATUS_FORCE_REFRESH; + $status_flags = Horde_Imap_Client::STATUS_HIGHESTMODSEQ + | Horde_Imap_Client::STATUS_UIDNEXT_FORCE + | Horde_Imap_Client::STATUS_MESSAGES + | Horde_Imap_Client::STATUS_FORCE_REFRESH; // Get IMAP status. try { @@ -546,9 +561,11 @@ public function ping(Horde_ActiveSync_Folder_Imap $folder) throw new Horde_ActiveSync_Exception($e); } - $this->_logger->meta(sprintf( - 'IMAP status: %s', - serialize($status)) + $this->_logger->meta( + sprintf( + 'IMAP status: %s', + serialize($status) + ) ); // If we have per mailbox MODSEQ then we can pick up flag changes too. @@ -627,15 +644,15 @@ public function renameMailbox($old, $new, $parent = null) public function setImapFlag($mailbox, $uid, $flag) { $mbox = new Horde_Imap_Client_Mailbox($mailbox); - $options = array( - 'ids' => new Horde_Imap_Client_Ids(array($uid)) - ); + $options = [ + 'ids' => new Horde_Imap_Client_Ids([$uid]), + ]; switch ($flag) { - case Horde_ActiveSync::IMAP_FLAG_REPLY: - $options['add'] = array(Horde_Imap_Client::FLAG_ANSWERED); - break; - case Horde_ActiveSync::IMAP_FLAG_FORWARD: - $options['add'] = array(Horde_Imap_Client::FLAG_FORWARDED); + case Horde_ActiveSync::IMAP_FLAG_REPLY: + $options['add'] = [Horde_Imap_Client::FLAG_ANSWERED]; + break; + case Horde_ActiveSync::IMAP_FLAG_FORWARD: + $options['add'] = [Horde_Imap_Client::FLAG_FORWARDED]; } try { $this->_getImapOb()->store($mbox, $options); @@ -674,15 +691,15 @@ public function setMessageFlag($mailbox, $uid, $flag) // 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)), - ); + $options = [ + 'ids' => new Horde_Imap_Client_Ids([$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); + case Horde_ActiveSync_Message_Flag::FLAG_STATUS_ACTIVE: + $options['add'] = [Horde_Imap_Client::FLAG_FLAGGED]; + break; + default: + $options['remove'] = [Horde_Imap_Client::FLAG_FLAGGED]; } try { $this->_getImapOb()->store($mbox, $options); @@ -695,10 +712,10 @@ 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() - ); + $options = [ + 'ids' => new Horde_Imap_Client_Ids([$uid]), + 'add' => [], + ]; 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), ' ', '_')); @@ -728,13 +745,13 @@ public function categoriesToFlags($mailbox, $categories, $uid) public function setReadFlag($mailbox, $uid, $flag) { $mbox = new Horde_Imap_Client_Mailbox($mailbox); - $options = array( - 'ids' => new Horde_Imap_Client_Ids(array($uid)), - ); + $options = [ + 'ids' => new Horde_Imap_Client_Ids([$uid]), + ]; if ($flag == Horde_ActiveSync_Message_Mail::FLAG_READ_SEEN) { - $options['add'] = array(Horde_Imap_Client::FLAG_SEEN); - } else if ($flag == Horde_ActiveSync_Message_Mail::FLAG_READ_UNSEEN) { - $options['remove'] = array(Horde_Imap_Client::FLAG_SEEN); + $options['add'] = [Horde_Imap_Client::FLAG_SEEN]; + } elseif ($flag == Horde_ActiveSync_Message_Mail::FLAG_READ_UNSEEN) { + $options['remove'] = [Horde_Imap_Client::FLAG_SEEN]; } try { $this->_getImapOb()->store($mbox, $options); @@ -756,19 +773,19 @@ protected function _buildSubQuery(array $query) foreach ($query as $q) { foreach ($q['value'] as $type => $value) { switch ($type) { - case Horde_ActiveSync_Message_Mail::POOMMAIL_DATERECEIVED: - if ($q['op'] == Horde_ActiveSync_Request_Search::SEARCH_GREATERTHAN) { - $range = Horde_Imap_Client_Search_Query::DATE_SINCE; - } elseif ($q['op'] == Horde_ActiveSync_Request_Search::SEARCH_LESSTHAN) { - $range = Horde_Imap_Client_Search_Query::DATE_BEFORE; - } else { - $range = Horde_Imap_Client_Search_Query::DATE_ON; - } - $imap_query->dateSearch($value, $range); - break; - case Horde_ActiveSync_Request_Search::SEARCH_FREETEXT: - $imap_query->text($value); - break; + case Horde_ActiveSync_Message_Mail::POOMMAIL_DATERECEIVED: + if ($q['op'] == Horde_ActiveSync_Request_Search::SEARCH_GREATERTHAN) { + $range = Horde_Imap_Client_Search_Query::DATE_SINCE; + } elseif ($q['op'] == Horde_ActiveSync_Request_Search::SEARCH_LESSTHAN) { + $range = Horde_Imap_Client_Search_Query::DATE_BEFORE; + } else { + $range = Horde_Imap_Client_Search_Query::DATE_ON; + } + $imap_query->dateSearch($value, $range); + break; + case Horde_ActiveSync_Request_Search::SEARCH_FREETEXT: + $imap_query->text($value); + break; } } } @@ -801,8 +818,8 @@ protected function _buildSubQuery(array $query) protected function _buildMailMessage( Horde_Imap_Client_Mailbox $mbox, Horde_Imap_Client_Data_Fetch $data, - $options = array()) - { + $options = [] + ) { $version = $options['protocolversion'] = empty($options['protocolversion']) ? Horde_ActiveSync::VERSION_TWOFIVE : $options['protocolversion']; @@ -818,7 +835,7 @@ protected function _buildMailMessage( // Inject flags since this saves us from having to inject the imapOb // into the builder. - $params = array(); + $params = []; if ($version > Horde_ActiveSync::VERSION_TWELVEONE) { $params['flags'] = $this->_getMsgFlags(); } @@ -877,7 +894,7 @@ protected function _getNamespacelist() try { return $this->_getImapOb()->getNamespaces(); } catch (Horde_Imap_Client_Exception $e) { - return array(); + return []; } } @@ -932,31 +949,31 @@ protected function _doQuery(array $query, array $options, bool $deepTraversal): foreach ($query as $q) { foreach ($q as $key => $value) { switch ($key) { - case 'FolderType': - if ($value !== Horde_ActiveSync::CLASS_EMAIL) { - throw new Horde_ActiveSync_Exception('Only Email folders are supported.'); - } - break; - case 'serverid': - $mboxes[] = new Horde_Imap_Client_Mailbox($value); - break; - case Horde_ActiveSync_Message_Mail::POOMMAIL_DATERECEIVED: - $op = $q['op'] ?? ''; - if ($op == Horde_ActiveSync_Request_Search::SEARCH_GREATERTHAN) { - $query_range = Horde_Imap_Client_Search_Query::DATE_SINCE; - } elseif ($op == Horde_ActiveSync_Request_Search::SEARCH_LESSTHAN) { - $query_range = Horde_Imap_Client_Search_Query::DATE_BEFORE; - } else { - $query_range = Horde_Imap_Client_Search_Query::DATE_ON; - } - $imap_query->dateSearch($value, $query_range); - break; - case Horde_ActiveSync_Request_Search::SEARCH_FREETEXT: - $imap_query->text($value, false); - break; - case 'subquery': - $imap_query->andSearch(array($this->_buildSubQuery($value))); - break; + case 'FolderType': + if ($value !== Horde_ActiveSync::CLASS_EMAIL) { + throw new Horde_ActiveSync_Exception('Only Email folders are supported.'); + } + break; + case 'serverid': + $mboxes[] = new Horde_Imap_Client_Mailbox($value); + break; + case Horde_ActiveSync_Message_Mail::POOMMAIL_DATERECEIVED: + $op = $q['op'] ?? ''; + if ($op == Horde_ActiveSync_Request_Search::SEARCH_GREATERTHAN) { + $query_range = Horde_Imap_Client_Search_Query::DATE_SINCE; + } elseif ($op == Horde_ActiveSync_Request_Search::SEARCH_LESSTHAN) { + $query_range = Horde_Imap_Client_Search_Query::DATE_BEFORE; + } else { + $query_range = Horde_Imap_Client_Search_Query::DATE_ON; + } + $imap_query->dateSearch($value, $query_range); + break; + case Horde_ActiveSync_Request_Search::SEARCH_FREETEXT: + $imap_query->text($value, false); + break; + case 'subquery': + $imap_query->andSearch([$this->_buildSubQuery($value)]); + break; } } } @@ -975,7 +992,7 @@ protected function _doQuery(array $query, array $options, bool $deepTraversal): $imap_query, [ 'results' => [ Horde_Imap_Client::SEARCH_RESULTS_MATCH, Horde_Imap_Client::SEARCH_RESULTS_SAVE, Horde_Imap_Client::SEARCH_RESULTS_COUNT ], - 'sort' => [ Horde_Imap_Client::SORT_REVERSE, Horde_Imap_Client::SORT_ARRIVAL ] + 'sort' => [ Horde_Imap_Client::SORT_REVERSE, Horde_Imap_Client::SORT_ARRIVAL ], ] ); } catch (Horde_Imap_Client_Exception $e) { @@ -1028,14 +1045,16 @@ protected function _getImapOb() * @throws Horde_ActiveSync_Exception */ protected function _getMailMessages( - Horde_Imap_Client_Mailbox $mbox, array $uids, array $options = array()) - { + Horde_Imap_Client_Mailbox $mbox, + array $uids, + array $options = [] + ) { $options = array_merge( - array( + [ 'headers' => false, 'structure' => true, 'flags' => true, - 'envelope' => false), + 'envelope' => false], $options ); @@ -1050,22 +1069,24 @@ protected function _getMailMessages( $query->envelope(); } if (!empty($options['headers'])) { - $query->headerText(array('peek' => true)); + $query->headerText(['peek' => true]); } try { return $this->_getImapOb()->fetch( $mbox, $query, - array('ids' => new Horde_Imap_Client_Ids($uids), 'exists' => true) + ['ids' => new Horde_Imap_Client_Ids($uids), 'exists' => true] ); } catch (Horde_Imap_Client_Exception $e) { if ($e->getCode() == Horde_Imap_Client_Exception::DISCONNECT) { $this->_logger->err("Connection to IMAP server lost"); throw new Horde_ActiveSync_Exception_TemporaryFailure($e); } - $this->_logger->err(sprintf( - 'Unable to fetch message: %s', - $e->getMessage()) + $this->_logger->err( + sprintf( + 'Unable to fetch message: %s', + $e->getMessage() + ) ); throw new Horde_ActiveSync_Exception($e); } @@ -1097,6 +1118,6 @@ protected function _getMsgFlags() return $this->_imap->getMsgFlags(); } - return array(); + return []; } } diff --git a/lib/Horde/ActiveSync/Imap/EasMessageBuilder.php b/lib/Horde/ActiveSync/Imap/EasMessageBuilder.php index 92e31b96..4c7eb24e 100644 --- a/lib/Horde/ActiveSync/Imap/EasMessageBuilder.php +++ b/lib/Horde/ActiveSync/Imap/EasMessageBuilder.php @@ -1,4 +1,5 @@ _imapMessage = $imap_message; $this->_mbd = $this->_imapMessage->getMessageBodyDataObject($options); $this->_easMessage = Horde_ActiveSync::messageFactory('Mail'); @@ -98,7 +101,7 @@ public function __construct( * * @return Horde_ActiveSync_Message_Base */ - public function getMessageObject($params = array()) + public function getMessageObject($params = []) { // Perform the bulk of the work. $this->_populateObject(); @@ -112,17 +115,17 @@ public function getMessageObject($params = array()) $this->_buildBody(); // It's legal to have both a BODY and a BODYPART - if ($this->_version > Horde_ActiveSync::VERSION_FOURTEEN && - !empty($options['bodypartprefs'])) { + if ($this->_version > Horde_ActiveSync::VERSION_FOURTEEN + && !empty($options['bodypartprefs'])) { $this->_easMessage->airsyncbasebodypart = $this->_buildBodyPart(); } // Body Preview. Note that this is different than the BodyPart preview. - if ($this->_version >= Horde_ActiveSync::VERSION_FOURTEEN && - !empty($this->_options['bodyprefs']['preview'])) { + if ($this->_version >= Horde_ActiveSync::VERSION_FOURTEEN + && !empty($this->_options['bodyprefs']['preview'])) { $this->_mbd->plain['body']->rewind(); - $this->_easMessage->airsyncbasebody->preview = - $this->_mbd->plain['body']->substring(0, $this->_options['bodyprefs']['preview']); + $this->_easMessage->airsyncbasebody->preview + = $this->_mbd->plain['body']->substring(0, $this->_options['bodyprefs']['preview']); } return $this->_easMessage; @@ -227,7 +230,7 @@ protected function _setHeaderProperties() protected function _setFlags($msgFlags) { // Flags - $flags = array(); + $flags = []; foreach ($this->_imapMessage->getFlags() as $flag) { if (!empty($msgFlags[Horde_String::lower($flag)])) { $flags[] = $msgFlags[Horde_String::lower($flag)]; @@ -251,40 +254,40 @@ protected function _deliveryNotification() $part1_id = next($ids); $part2_id = Horde_Mime::mimeIdArithmetic($part1_id, 'next'); try { - $lines = explode(chr(13), $this->_imapMessage->getBodyPart($part2_id, array('decode' => true))); + $lines = explode(chr(13), $this->_imapMessage->getBodyPart($part2_id, ['decode' => true])); } catch (Horde_ActiveSync_Exception $e) { return; } switch ($part->getContentTypeParameter('report-type')) { - case 'delivery-status': - foreach ($lines as $line) { - if (strpos(trim($line), 'Action:') === 0) { - switch (trim(substr(trim($line), 7))) { - case 'failed': - $this->_easMessage->messageclass = 'REPORT.IPM.NOTE.NDR'; - break 2; - case 'delayed': - $this->_easMessage->messageclass = 'REPORT.IPM.NOTE.DELAYED'; - break 2; - case 'delivered': - $this->_easMessage->messageclass = 'REPORT.IPM.NOTE.DR'; - break 2; + case 'delivery-status': + foreach ($lines as $line) { + if (strpos(trim($line), 'Action:') === 0) { + switch (trim(substr(trim($line), 7))) { + case 'failed': + $this->_easMessage->messageclass = 'REPORT.IPM.NOTE.NDR'; + break 2; + case 'delayed': + $this->_easMessage->messageclass = 'REPORT.IPM.NOTE.DELAYED'; + break 2; + case 'delivered': + $this->_easMessage->messageclass = 'REPORT.IPM.NOTE.DR'; + break 2; + } } } - } - break; - case 'disposition-notification': - foreach ($lines as $line) { - if (strpos(trim($line), 'Disposition:') === 0) { - if (strpos($line, 'displayed') !== false) { - $this->_easMessage->messageclass = 'REPORT.IPM.NOTE.IPNRN'; - } elseif (strpos($line, 'deleted') !== false) { - $this->_easMessage->messageclass = 'REPORT.IPM.NOTE.IPNNRN'; + break; + case 'disposition-notification': + foreach ($lines as $line) { + if (strpos(trim($line), 'Disposition:') === 0) { + if (strpos($line, 'displayed') !== false) { + $this->_easMessage->messageclass = 'REPORT.IPM.NOTE.IPNRN'; + } elseif (strpos($line, 'deleted') !== false) { + $this->_easMessage->messageclass = 'REPORT.IPM.NOTE.IPNNRN'; + } + break; } - break; } - } } } @@ -294,8 +297,8 @@ protected function _deliveryNotification() protected function _meetingRequest() { // Exit if we don't support or don't have an iTip. - if ($this->_version < Horde_ActiveSync::VERSION_TWELVE || - !($mime_part = $this->_imapMessage->hasiCalendar())) { + if ($this->_version < Horde_ActiveSync::VERSION_TWELVE + || !($mime_part = $this->_imapMessage->hasiCalendar())) { return; } @@ -311,7 +314,7 @@ protected function _meetingRequest() if ($vCal->parsevCalendar($data, 'VCALENDAR', $mime_part->getCharset())) { $classes = $vCal->getComponentClasses(); } else { - $classes = array(); + $classes = []; } } catch (Horde_Icalendar_Exception $e) { $this->_logger->err($e->getMessage()); @@ -332,32 +335,32 @@ protected function _meetingRequest() } switch ($method) { - case 'REQUEST': - case 'PUBLISH': - $this->_easMessage->messageclass = 'IPM.Schedule.Meeting.Request'; - $mtg = Horde_ActiveSync::messageFactory('MeetingRequest'); - $mtg->fromvEvent($vCal); - $this->_easMessage->meetingrequest = $mtg; - break; - case 'REPLY': - try { - $reply_status = $this->_getiTipStatus($vCal); - switch ($reply_status) { - case 'ACCEPTED': - $this->_easMessage->messageclass = 'IPM.Schedule.Meeting.Resp.Pos'; - break; - case 'DECLINED': - $this->_easMessage->messageclass = 'IPM.Schedule.Meeting.Resp.Neg'; - break; - case 'TENTATIVE': - $this->_easMessage->messageclass = 'IPM.Schedule.Meeting.Resp.Tent'; - } + case 'REQUEST': + case 'PUBLISH': + $this->_easMessage->messageclass = 'IPM.Schedule.Meeting.Request'; $mtg = Horde_ActiveSync::messageFactory('MeetingRequest'); $mtg->fromvEvent($vCal); $this->_easMessage->meetingrequest = $mtg; - } catch (Horde_ActiveSync_Exception $e) { - $this->_logger->err($e->getMessage()); - } + break; + case 'REPLY': + try { + $reply_status = $this->_getiTipStatus($vCal); + switch ($reply_status) { + case 'ACCEPTED': + $this->_easMessage->messageclass = 'IPM.Schedule.Meeting.Resp.Pos'; + break; + case 'DECLINED': + $this->_easMessage->messageclass = 'IPM.Schedule.Meeting.Resp.Neg'; + break; + case 'TENTATIVE': + $this->_easMessage->messageclass = 'IPM.Schedule.Meeting.Resp.Tent'; + } + $mtg = Horde_ActiveSync::messageFactory('MeetingRequest'); + $mtg->fromvEvent($vCal); + $this->_easMessage->meetingrequest = $mtg; + } catch (Horde_ActiveSync_Exception $e) { + $this->_logger->err($e->getMessage()); + } } } @@ -438,16 +441,16 @@ protected function _messageImportance() protected function _getEASImportance($importance) { switch (Horde_String::lower($importance)) { - case '1': - case 'high': - return 2; - case '5': - case 'low': - return 0; - case 'normal': - case '3': - default: - return 1; + case '1': + case 'high': + return 2; + case '5': + case 'low': + return 0; + case 'normal': + case '3': + default: + return 1; } } @@ -463,18 +466,18 @@ protected function _getiTipStatus($vCal) { foreach ($vCal->getComponents() as $component) { switch ($component->getType()) { - case 'vEvent': - try { - $atparams = $component->getAttribute('ATTENDEE', true); - } catch (Horde_Icalendar_Exception $e) { - throw new Horde_ActiveSync_Exception($e); - } + case 'vEvent': + try { + $atparams = $component->getAttribute('ATTENDEE', true); + } catch (Horde_Icalendar_Exception $e) { + throw new Horde_ActiveSync_Exception($e); + } - if (!is_array($atparams)) { - throw new Horde_Icalendar_Exception('Unexpected value'); - } + if (!is_array($atparams)) { + throw new Horde_Icalendar_Exception('Unexpected value'); + } - return $atparams[0]['PARTSTAT']; + return $atparams[0]['PARTSTAT']; } } } @@ -510,9 +513,11 @@ protected function _buildBodyPart() * * @return Horde_ActiveSync_Imap_EasMessageType */ - static public function create( - Horde_ActiveSync_Imap_Message $imap_message, array $options, $logger) - { + public static function create( + Horde_ActiveSync_Imap_Message $imap_message, + array $options, + $logger + ) { $mbd = $imap_message->getMessageBodyDataObject($options); // First, see if we are EAS 2.5 @@ -521,14 +526,14 @@ static public function create( } switch ($mbd->getBodyTypePreference()) { - case Horde_ActiveSync::BODYPREF_TYPE_MIME: - $class = 'Mime'; - break; - case Horde_ActiveSync::BODYPREF_TYPE_HTML: - $class = 'Html'; - break; - case Horde_ActiveSync::BODYPREF_TYPE_PLAIN: - $class = 'Plain'; + case Horde_ActiveSync::BODYPREF_TYPE_MIME: + $class = 'Mime'; + break; + case Horde_ActiveSync::BODYPREF_TYPE_HTML: + $class = 'Html'; + break; + case Horde_ActiveSync::BODYPREF_TYPE_PLAIN: + $class = 'Plain'; } $class_name = 'Horde_ActiveSync_Imap_EasMessageBuilder_' . $class; diff --git a/lib/Horde/ActiveSync/Imap/EasMessageBuilder/Html.php b/lib/Horde/ActiveSync/Imap/EasMessageBuilder/Html.php index d00f83ef..246bc1a6 100644 --- a/lib/Horde/ActiveSync/Imap/EasMessageBuilder/Html.php +++ b/lib/Horde/ActiveSync/Imap/EasMessageBuilder/Html.php @@ -1,4 +1,5 @@ _mbd->html) { $this->_airsyncBody->type = Horde_ActiveSync::BODYPREF_TYPE_PLAIN; - $this->_mbd->html = array( + $this->_mbd->html = [ 'body' => $this->_mbd->plain['body'], 'estimated_size' => $this->_mbd->plain['size'], - 'truncated' => $this->_mbd->plain['truncated'] - ); + 'truncated' => $this->_mbd->plain['truncated'], + ]; } else { $this->_airsyncBody->type = Horde_ActiveSync::BODYPREF_TYPE_HTML; } @@ -50,8 +53,8 @@ protected function _buildBody() $this->_logger->meta('Building HTML Message.'); $this->_buildHtmlPart(); $this->_easMessage->airsyncbasebody = $this->_airsyncBody; - $this->_easMessage->airsyncbaseattachments = - $this->_imapMessage->getAttachments($this->_version); + $this->_easMessage->airsyncbaseattachments + = $this->_imapMessage->getAttachments($this->_version); } /** diff --git a/lib/Horde/ActiveSync/Imap/EasMessageBuilder/Mime.php b/lib/Horde/ActiveSync/Imap/EasMessageBuilder/Mime.php index 1ae14caf..0ff1e921 100644 --- a/lib/Horde/ActiveSync/Imap/EasMessageBuilder/Mime.php +++ b/lib/Horde/ActiveSync/Imap/EasMessageBuilder/Mime.php @@ -1,4 +1,5 @@ _airsyncBody->type = Horde_ActiveSync::BODYPREF_TYPE_MIME; @@ -102,16 +105,18 @@ protected function _buildMessage() try { $headers = $this->_getHeaders(); // Populate the EAS body structure with the MIME data. - $this->_airsyncBody->data = $base->toString(array( - 'headers' => $headers, - 'stream' => true) + $this->_airsyncBody->data = $base->toString( + [ + 'headers' => $headers, + 'stream' => true] ); } catch (Horde_Idna_Exception $e) { $this->_logger->err($e->getMessage()); $this->_handleIdnaErrors($headers); - $this->_airsyncBody->data = $base->toString(array( - 'headers' => $headers, - 'stream' => true) + $this->_airsyncBody->data = $base->toString( + [ + 'headers' => $headers, + 'stream' => true] ); } $this->_airsyncBody->estimateddatasize = $base->getBytes(); @@ -125,7 +130,7 @@ protected function _buildMessage() */ protected function _handleIdnaErrors(Horde_Mime_Headers $headers) { - foreach (array('from', 'to', 'cc', 'reply-to') as $name) { + foreach (['from', 'to', 'cc', 'reply-to'] as $name) { if ($obj = $headers->getHeader($name)) { $obj_idn = new Horde_ActiveSync_Mime_Headers_Addresses($name, $obj->full_value); $headers->removeHeader($name); @@ -151,14 +156,16 @@ protected function _doTruncation() ? $this->_options['truncation'] : false); - $this->_logger->meta(sprintf( - 'Checking MIMETRUNCATION: %d, ServerData: %d', - $mime_truncation, - $this->_airsyncBody->estimateddatasize) + $this->_logger->meta( + sprintf( + 'Checking MIMETRUNCATION: %d, ServerData: %d', + $mime_truncation, + $this->_airsyncBody->estimateddatasize + ) ); - if (!empty($mime_truncation) && - $this->_airsyncBody->estimateddatasize > $mime_truncation) { + if (!empty($mime_truncation) + && $this->_airsyncBody->estimateddatasize > $mime_truncation) { ftruncate($this->_airsyncBody->data, $mime_truncation); $this->_airsyncBody->truncated = '1'; } else { @@ -175,7 +182,7 @@ protected function _buildPlainMime() { $part = new Horde_Mime_Part(); $part->setType('text/plain'); - $part->setContents($this->_mbd->plain['body']->stream, array('usestream' => true)); + $part->setContents($this->_mbd->plain['body']->stream, ['usestream' => true]); $part->setCharset('UTF-8'); return $part; @@ -190,7 +197,7 @@ protected function _buildHtmlMime() { $part = new Horde_Mime_Part(); $part->setType('text/html'); - $part->setContents($this->_mbd->html['body']->stream, array('usestream' => true)); + $part->setContents($this->_mbd->html['body']->stream, ['usestream' => true]); $part->setCharset('UTF-8'); return $part; diff --git a/lib/Horde/ActiveSync/Imap/EasMessageBuilder/Plain.php b/lib/Horde/ActiveSync/Imap/EasMessageBuilder/Plain.php index 7574c10b..61202fc8 100644 --- a/lib/Horde/ActiveSync/Imap/EasMessageBuilder/Plain.php +++ b/lib/Horde/ActiveSync/Imap/EasMessageBuilder/Plain.php @@ -1,4 +1,5 @@ _airsyncBody->type = Horde_ActiveSync::BODYPREF_TYPE_PLAIN; } @@ -42,8 +45,8 @@ protected function _buildBody() $this->_buildPlainPart(); } $this->_easMessage->airsyncbasebody = $this->_airsyncBody; - $this->_easMessage->airsyncbaseattachments = - $this->_imapMessage->getAttachments($this->_version); + $this->_easMessage->airsyncbaseattachments + = $this->_imapMessage->getAttachments($this->_version); } /** diff --git a/lib/Horde/ActiveSync/Imap/EasMessageBuilder/TwoFive.php b/lib/Horde/ActiveSync/Imap/EasMessageBuilder/TwoFive.php index e83ebad6..340bd9d4 100644 --- a/lib/Horde/ActiveSync/Imap/EasMessageBuilder/TwoFive.php +++ b/lib/Horde/ActiveSync/Imap/EasMessageBuilder/TwoFive.php @@ -1,4 +1,5 @@ _imap = $imap; $this->_mbox = $mbox; $this->_data = $data; $this->_options = array_merge( - array(self::OPTIONS_DECODE_TNEF => true), + [self::OPTIONS_DECODE_TNEF => true], $options ); @@ -131,20 +132,20 @@ public function __destruct() public function &__get($property) { switch ($property) { - case 'envelope': - $e = $this->_data->getEnvelope(); - return $e; - case 'flags': - $f = $this->_data->getFlags(); - return $f; - case 'uid': - $u = $this->_data->getUid(); - return $u; - case 'basePart': - if (empty($this->_basePart)) { - $this->_basePart = new Horde_ActiveSync_Mime($this->_data->getStructure()); - } - return $this->_basePart; + case 'envelope': + $e = $this->_data->getEnvelope(); + return $e; + case 'flags': + $f = $this->_data->getFlags(); + return $f; + case 'uid': + $u = $this->_data->getUid(); + return $u; + case 'basePart': + if (empty($this->_basePart)) { + $this->_basePart = new Horde_ActiveSync_Mime($this->_data->getStructure()); + } + return $this->_basePart; } throw new InvalidArgumentException(sprintf('The property %s of Horde_ActiveSync_Imap_Message does not exist', $property)); @@ -168,7 +169,7 @@ public function getHeaders() */ public function getForwardHeaders() { - $tmp = array(); + $tmp = []; $h = $this->getHeaders(); if (($ob = $h->getValue('date'))) { @@ -195,7 +196,7 @@ public function getForwardHeaders() $tmp[Horde_ActiveSync_Translation::t('Cc')] = $ob; } - $max = max(array_map(array('Horde_String', 'length'), array_keys($tmp))) + 2; + $max = max(array_map(['Horde_String', 'length'], array_keys($tmp))) + 2; $text = ''; foreach ($tmp as $key => $val) { @@ -217,7 +218,7 @@ public function getFullMsg($stream = false) { // First see if we already have it. if ($stream) { - $full = new Horde_Stream_Existing(array('stream' => $this->_data->getFullMsg($stream))); + $full = new Horde_Stream_Existing(['stream' => $this->_data->getFullMsg($stream)]); $length = $full->length(); if (!$length) { $full->close(); @@ -228,12 +229,12 @@ public function getFullMsg($stream = false) } if (!$length) { $query = new Horde_Imap_Client_Fetch_Query(); - $query->fullText(array('peek' => true)); + $query->fullText(['peek' => true]); try { $fetch_ret = $this->_imap->fetch( $this->_mbox, $query, - array('ids' => new Horde_Imap_Client_Ids(array($this->uid))) + ['ids' => new Horde_Imap_Client_Ids([$this->uid])] ); } catch (Horde_Imap_Client_Exception $e) { throw new Horde_ActiveSync_Exception($e); @@ -274,7 +275,7 @@ public function getStructure() * @throws Horde_ActiveSync_Exception, Horde_Exception_NotFound * @deprecated - no longer used and will be removed in Horde 6. */ - public function getMessageBodyData(array $options = array()) + public function getMessageBodyData(array $options = []) { return $this->getMessageBodyDataObject($options)->toArray(); } @@ -297,15 +298,15 @@ public function getMessageBodyData(array $options = array()) * * @throws Horde_ActiveSync_Exception, Horde_Exception_NotFound */ - public function getMessageBodyDataObject(array $options = array()) + public function getMessageBodyDataObject(array $options = []) { if (empty($this->_mbd)) { - $this->_mbd = new Horde_ActiveSync_Imap_MessageBodyData( - array( + $this->_mbd = new Horde_ActiveSync_Imap_MessageBodyData( + [ 'imap' => $this->_imap, 'mbox' => $this->_mbox, 'uid' => $this->uid, - 'mime' => $this->basePart), + 'mime' => $this->basePart], $options ); } @@ -323,13 +324,13 @@ public function getMessageBodyDataObject(array $options = array()) */ public function getAttachments($version) { - $ret = array(); + $ret = []; $iterator = new Horde_ActiveSync_Mime_Iterator($this->_basePart->base); foreach ($iterator as $part) { $type = $part->getType(); $id = $part->getMimeId(); if ($this->isAttachment($id, $type)) { - $mime_part = $this->getMimePart($id, array('nocontents' => true)); + $mime_part = $this->getMimePart($id, ['nocontents' => true]); $ret[] = $this->_buildEasAttachmentFromMime($id, $mime_part, $version); $mime_part = null; } @@ -361,7 +362,7 @@ protected function _buildEasAttachmentFromMime($id, Horde_Mime_Part $mime_part, $atc->attsize = intval($mime_part->getBytes(true)); $atc->attname = $this->_mbox . ':' . $this->uid . ':' . $id; $atc->displayname = $this->getPartName($mime_part, true); - $atc->attmethod = in_array($mime_part->getType(), array('message/disposition-notification')) + $atc->attmethod = in_array($mime_part->getType(), ['message/disposition-notification']) ? Horde_ActiveSync_Message_AirSyncBaseAttachment::ATT_TYPE_EMBEDDED : Horde_ActiveSync_Message_AirSyncBaseAttachment::ATT_TYPE_NORMAL; @@ -413,7 +414,7 @@ protected function _decodeTnefData($data) $tmp_part->setContents($data['stream']); $type = $data['type'] . '/' . $data['subtype']; - if (in_array($type, array('application/octet-stream', 'application/base64'))) { + if (in_array($type, ['application/octet-stream', 'application/base64'])) { $type = Horde_Mime_Magic::filenameToMIME($data['name']); } $tmp_part->setType($type); @@ -432,7 +433,7 @@ protected function _decodeTnefData($data) */ public function getAttachmentsMimeParts() { - $mime_parts = array(); + $mime_parts = []; $map = $this->basePart->contentTypeMap(); foreach ($map as $id => $type) { if ($this->isAttachment($id, $type)) { @@ -459,8 +460,8 @@ protected function _prepareTnef() } $map = $this->basePart->contentTypeMap(); foreach ($map as $id => $type) { - if ($type == 'application/ms-tnef' && - !empty($this->_options[self::OPTIONS_DECODE_TNEF])) { + if ($type == 'application/ms-tnef' + && !empty($this->_options[self::OPTIONS_DECODE_TNEF])) { $mpart = $this->getMimePart($id); $tnef_part = $this->_decodeTnefData($mpart); @@ -486,29 +487,29 @@ protected function _prepareTnef() * * @return Horde_Mime_Part The raw MIME part asked for. */ - public function getMimePart($id, array $options = array()) + public function getMimePart($id, array $options = []) { $part = $this->basePart->getPart($id); - if ($part && - (strcasecmp($part->getCharset(), 'ISO-8859-1') === 0)) { + if ($part + && (strcasecmp($part->getCharset(), 'ISO-8859-1') === 0)) { $part->setCharset('windows-1252'); } - if (!empty($id) && - !is_null($part) && - substr($id, -2) != '.0' && - empty($options['nocontents']) && - !$part->getContents(array('stream' => true))) { + if (!empty($id) + && !is_null($part) + && substr($id, -2) != '.0' + && empty($options['nocontents']) + && !$part->getContents(['stream' => true])) { try { $body = $this->getBodyPart( $id, - array( + [ 'decode' => true, 'length' => empty($options['length']) ? null : $options['length'], - 'stream' => true) + 'stream' => true] ); - $part->setContents($body, array('encoding' => $this->_lastBodyPartDecode, 'usestream' => true)); + $part->setContents($body, ['encoding' => $this->_lastBodyPartDecode, 'usestream' => true]); } catch (Horde_ActiveSync_Exception $e) { } } @@ -535,44 +536,45 @@ public function getPartName(Horde_Mime_Part $part, $use_descrip = false) } switch ($ptype = $part->getPrimaryType()) { - case 'multipart': - if (($part->getSubType() == 'related') && - ($view_id = $part->getMetaData('viewable_part')) && - ($viewable = $this->getMimePart($view_id, array('nocontents' => true)))) { - return $this->getPartName($viewable, $use_descrip); - } - /* Fall-through. */ + case 'multipart': + if (($part->getSubType() == 'related') + && ($view_id = $part->getMetaData('viewable_part')) + && ($viewable = $this->getMimePart($view_id, ['nocontents' => true]))) { + return $this->getPartName($viewable, $use_descrip); + } + /* Fall-through. */ - case 'application': - case 'model': - $ptype = $part->getSubType(); - break; + // no break + case 'application': + case 'model': + $ptype = $part->getSubType(); + break; } switch ($ptype) { - case 'audio': - return Horde_ActiveSync_Translation::t('Audio part'); + case 'audio': + return Horde_ActiveSync_Translation::t('Audio part'); - case 'image': - return Horde_ActiveSync_Translation::t('Image part'); + case 'image': + return Horde_ActiveSync_Translation::t('Image part'); - case 'message': - case Horde_Mime_Part::UNKNOWN: - return Horde_ActiveSync_Translation::t('Message part'); + case 'message': + case Horde_Mime_Part::UNKNOWN: + return Horde_ActiveSync_Translation::t('Message part'); - case 'multipart': - return Horde_ActiveSync_Translation::t('Multipart part'); + case 'multipart': + return Horde_ActiveSync_Translation::t('Multipart part'); - case 'text': - return Horde_ActiveSync_Translation::t('Text part'); + case 'text': + return Horde_ActiveSync_Translation::t('Text part'); - case 'video': - return Horde_ActiveSync_Translation::t('Video part'); + case 'video': + return Horde_ActiveSync_Translation::t('Video part'); - default: - // Attempt to translate this type, if possible. Odds are that - // it won't appear in the dictionary though. - return sprintf(Horde_ActiveSync_Translation::t('%s part'), _(Horde_String::ucfirst($ptype))); + default: + // Attempt to translate this type, if possible. Odds are that + // it won't appear in the dictionary though. + return sprintf(Horde_ActiveSync_Translation::t('%s part'), _(Horde_String::ucfirst($ptype))); } } @@ -601,18 +603,19 @@ public function getPartName(Horde_Mime_Part $part, $use_descrip = false) public function getBodyPart($id, $options) { $options = array_merge( - array( + [ 'decode' => false, 'mimeheaders' => false, - 'stream' => false), - $options); + 'stream' => false], + $options + ); $this->_lastBodyPartDecode = null; $query = new Horde_Imap_Client_Fetch_Query(); if (!isset($options['length']) || !empty($options['length'])) { - $bodypart_params = array( + $bodypart_params = [ 'decode' => true, - 'peek' => true - ); + 'peek' => true, + ]; if (isset($options['length'])) { $bodypart_params['start'] = 0; @@ -623,15 +626,15 @@ public function getBodyPart($id, $options) } if (!empty($options['mimeheaders'])) { - $query->mimeHeader($id, array( - 'peek' => true - )); + $query->mimeHeader($id, [ + 'peek' => true, + ]); } $fetch_res = $this->_imap->fetch( $this->_mbox, $query, - array('ids' => new Horde_Imap_Client_Ids(array($this->uid))) + ['ids' => new Horde_Imap_Client_Ids([$this->uid])] ); if (empty($fetch_res[$this->uid])) { @@ -645,9 +648,9 @@ public function getBodyPart($id, $options) return $fetch_res[$this->uid]->getMimeHeader($id) . $fetch_res[$this->uid]->getBodyPart($id); } else { $swrapper = new Horde_Support_CombineStream( - array( + [ $fetch_res[$this->uid]->getMimeHeader($id, Horde_Imap_Client_Data_Fetch::HEADER_STREAM), - $fetch_res[$this->uid]->getBodyPart($id, true)) + $fetch_res[$this->uid]->getBodyPart($id, true)] ); return $swrapper->fopen(); @@ -663,13 +666,13 @@ public function getBodyPart($id, $options) public function getToAddresses() { $to = $this->envelope->to; - $dtos = $tos = array(); + $dtos = $tos = []; foreach ($to->raw_addresses as $e) { $tos[] = Horde_ActiveSync_Utils::ensureUtf8($e->bare_address, 'UTF-8'); $dtos[] = Horde_ActiveSync_Utils::ensureUtf8($e->label, 'UTF-8'); } - return array('to' => $tos, 'displayto' => $dtos); + return ['to' => $tos, 'displayto' => $dtos]; } /** @@ -746,10 +749,10 @@ public function getDate() // Newer IMAP envelope handling may provide a Unix timestamp as string. // Horde_Date accepts int timestamps but not numeric timestamp strings. if (is_string($date) && ctype_digit($date)) { - return new Horde_Date((int)$date); + return new Horde_Date((int) $date); } - return new Horde_Date((string)$date); + return new Horde_Date((string) $date); } /** @@ -815,7 +818,7 @@ public function hasiCalendar() if ($id = $this->basePart->hasiCalendar()) { // May already have downloaded the part. $part = $this->basePart->base->getPart($id); - if (!$part->getContents(array('stream' => true))) { + if (!$part->getContents(['stream' => true])) { return $this->getMimePart($id); } return $part; @@ -842,7 +845,7 @@ public function hasAttachments() * * @return boolean True if message is S/MIME signed, false otherwise. */ - public function isSigned(Horde_Mime_Part $message = null) + public function isSigned(?Horde_Mime_Part $message = null) { if (!empty($message)) { $message = new Horde_ActiveSync_Mime($message); @@ -861,7 +864,7 @@ public function isSigned(Horde_Mime_Part $message = null) * @return boolean True if message is S/MIME signed or encrypted, * false otherwise. */ - public function isEncrypted(Horde_Mime_Part $message = null) + public function isEncrypted(?Horde_Mime_Part $message = null) { if (!empty($message)) { $message = new Horde_ActiveSync_Mime($message); diff --git a/lib/Horde/ActiveSync/Imap/MessageBodyData.php b/lib/Horde/ActiveSync/Imap/MessageBodyData.php index 118fe01d..edd90177 100644 --- a/lib/Horde/ActiveSync/Imap/MessageBodyData.php +++ b/lib/Horde/ActiveSync/Imap/MessageBodyData.php @@ -1,4 +1,5 @@ _uid = $params['uid']; $this->_options = $options; - $this->_version = empty($options['protocolversion']) ? - Horde_ActiveSync::VERSION_TWOFIVE : - $options['protocolversion']; + $this->_version = empty($options['protocolversion']) + ? Horde_ActiveSync::VERSION_TWOFIVE + : $options['protocolversion']; $this->_getParts(); } @@ -160,30 +161,30 @@ public function __destruct() public function &__get($property) { switch ($property) { - case 'plain': - $body = $this->plainBody(); - return $body; - case 'html': - $body = $this->htmlBody(); - return $body; - case 'bodyPart': - $body = $this->bodyPartBody(); - return $body; - case 'nativeBodyType': - return $this->_nativeType; - default: - throw new InvalidArgumentException("Unknown property: $property"); + case 'plain': + $body = $this->plainBody(); + return $body; + case 'html': + $body = $this->htmlBody(); + return $body; + case 'bodyPart': + $body = $this->bodyPartBody(); + return $body; + case 'nativeBodyType': + return $this->_nativeType; + default: + throw new InvalidArgumentException("Unknown property: $property"); } } public function __set($property, $value) { switch ($property) { - case 'html': - $this->_html = $value; - break; - default: - throw new InvalidArgumentException("$property can not be set."); + case 'html': + $this->_html = $value; + break; + default: + throw new InvalidArgumentException("$property can not be set."); } } @@ -240,23 +241,23 @@ protected function _getParts() // [message/disposition-notification] and (3) The (optional) original // message [message/rfc822] switch ($this->_basePart->getType()) { - case 'message/disposition-notification': - // OL may send this without an appropriate multipart/report wrapper. - // Not sure what to do about this yet. Probably parse the machine - // part and write out some basic text? - break; - case 'multipart/report': - $iterator = $this->_basePart->partIterator(false); - $iterator->rewind(); - if (!$curr = $iterator->current()) { + case 'message/disposition-notification': + // OL may send this without an appropriate multipart/report wrapper. + // Not sure what to do about this yet. Probably parse the machine + // part and write out some basic text? break; - } - $text_id = $curr->getMimeId(); - $html_id = null; - break; - default: - $text_id = $this->_basePart->findBody('plain'); - $html_id = $this->_basePart->findBody('html'); + case 'multipart/report': + $iterator = $this->_basePart->partIterator(false); + $iterator->rewind(); + if (!$curr = $iterator->current()) { + break; + } + $text_id = $curr->getMimeId(); + $html_id = null; + break; + default: + $text_id = $this->_basePart->findBody('plain'); + $html_id = $this->_basePart->findBody('html'); } // Deduce which part(s) we need to request. @@ -268,33 +269,33 @@ protected function _getParts() if (!empty($text_id) && $want_plain_text) { $text_body_part = $this->_basePart->getPart($text_id); - } elseif ($want_plain_text && !empty($html_id) && - empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_MIME])) { + } elseif ($want_plain_text && !empty($html_id) + && empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_MIME])) { $want_html_text = true; $want_html_as_plain = true; } if (!empty($html_id) && $want_html_text) { $html_body_part = $this->_basePart->getPart($html_id); - } elseif ($want_html_text && - empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_MIME])) { + } elseif ($want_html_text + && empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_MIME])) { // Want HTML text, but do not have a text/html part. $want_plain_as_html = true; } // Make sure we have truncation if needed. - if (empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_PLAIN]) && - !empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_HTML]) && - $want_plain_text && $want_html_text) { + if (empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_PLAIN]) + && !empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_HTML]) + && $want_plain_text && $want_html_text) { // We only have HTML truncation data, requested HTML body but only // have plaintext. - $this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_PLAIN] = - $this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_HTML]; + $this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_PLAIN] + = $this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_HTML]; } // Fetch the data from the IMAP client. - $data = $this->_fetchData(array('html_id' => $html_id, 'text_id' => $text_id)); + $data = $this->_fetchData(['html_id' => $html_id, 'text_id' => $text_id]); // Get the text/plain part if needed, possibly also converting it to // text/html if required. @@ -336,10 +337,10 @@ protected function _getParts() */ protected function _wantHtml() { - return $this->_version >= Horde_ActiveSync::VERSION_TWELVE && - (!empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_HTML]) || - !empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_MIME]) || - !empty($this->_options['bodypartprefs'])); + return $this->_version >= Horde_ActiveSync::VERSION_TWELVE + && (!empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_HTML]) + || !empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_MIME]) + || !empty($this->_options['bodypartprefs'])); } /** @@ -355,12 +356,12 @@ protected function _wantHtml() */ protected function _wantPlainText($html_id, $want_html) { - return $this->_version == Horde_ActiveSync::VERSION_TWOFIVE || - empty($this->_options['bodyprefs']) || - !empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_PLAIN]) || - !empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_RTF]) || - !empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_MIME]) || - ($want_html && empty($html_id)); + return $this->_version == Horde_ActiveSync::VERSION_TWOFIVE + || empty($this->_options['bodyprefs']) + || !empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_PLAIN]) + || !empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_RTF]) + || !empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_MIME]) + || ($want_html && empty($html_id)); } /** @@ -377,10 +378,10 @@ protected function _wantPlainText($html_id, $want_html) protected function _fetchData(array $params) { $query = new Horde_Imap_Client_Fetch_Query(); - $query_opts = array( + $query_opts = [ 'decode' => true, - 'peek' => true - ); + 'peek' => true, + ]; // Get body information if ($this->_version >= Horde_ActiveSync::VERSION_TWELVE) { @@ -401,7 +402,7 @@ protected function _fetchData(array $params) $fetch_ret = $this->_imap->fetch( $this->_mbox, $query, - array('ids' => new Horde_Imap_Client_Ids(array($this->_uid))) + ['ids' => new Horde_Imap_Client_Ids([$this->_uid])] ); } catch (Horde_Imap_Client_Exception $e) { // If we lost the connection, don't continue to try. @@ -412,7 +413,8 @@ protected function _fetchData(array $params) } if (!$data = $fetch_ret->first()) { throw new Horde_Exception_NotFound( - sprintf('Could not load message %s from server.', $this->_uid)); + sprintf('Could not load message %s from server.', $this->_uid) + ); } return $data; @@ -432,9 +434,9 @@ protected function _fetchData(array $params) */ protected function _getPlainPart( Horde_Imap_Client_Data_Fetch $data, - Horde_Mime_Part $text_mime) - { - $results = array(); + Horde_Mime_Part $text_mime + ) { + $results = []; $text_id = $text_mime->getMimeId(); $text = $data->getBodyPart($text_id); @@ -459,17 +461,17 @@ protected function _getPlainPart( } $truncated = $text_size > strlen($text); - if ($this->_version >= Horde_ActiveSync::VERSION_TWELVE && - $truncated && !empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_PLAIN]['allornone'])) { + if ($this->_version >= Horde_ActiveSync::VERSION_TWELVE + && $truncated && !empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_PLAIN]['allornone'])) { $text = ''; } - return array( + return [ 'charset' => $text_mime->getCharset(), 'body' => $text, 'truncated' => $truncated, - 'size' => $text_size - ); + 'size' => $text_size, + ]; } /** @@ -486,8 +488,8 @@ protected function _getPlainPart( */ protected function _getPlainPart2Html( Horde_Imap_Client_Data_Fetch $data, - Horde_Mime_Part $text_mime) - { + Horde_Mime_Part $text_mime + ) { $text_id = $text_mime->getMimeId(); $text = $data->getBodyPart($text_id); @@ -511,14 +513,14 @@ protected function _getPlainPart2Html( */ protected function _plain2Html($plain_text, $charset) { - // Perform barebones conversion. + // Perform barebones conversion. $html_text = Horde_Text_Filter::filter( $plain_text, 'Text2html', - array( + [ 'charset' => $charset, - 'parselevel' => Horde_Text_Filter_Text2html::MICRO - ) + 'parselevel' => Horde_Text_Filter_Text2html::MICRO, + ] ); // Truncation @@ -534,17 +536,17 @@ protected function _plain2Html($plain_text, $charset) $html_truncated = $html_text_size > strlen($html_text); // Honor ALLORNONE - if ($this->_version >= Horde_ActiveSync::VERSION_TWELVE && - $html_truncated && !empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_HTML]['allornone'])) { + if ($this->_version >= Horde_ActiveSync::VERSION_TWELVE + && $html_truncated && !empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_HTML]['allornone'])) { $html_text = ''; } - return array( + return [ 'charset' => $charset, 'body' => $html_text, 'estimated_size' => $html_text_size, - 'truncated' => $html_truncated - ); + 'truncated' => $html_truncated, + ]; } /** @@ -557,8 +559,9 @@ protected function _plain2Html($plain_text, $charset) * @see self::_getPlainPart for structure. */ protected function _getHtmlPart( - Horde_Imap_Client_Data_Fetch $data, Horde_Mime_Part $html_mime) - { + Horde_Imap_Client_Data_Fetch $data, + Horde_Mime_Part $html_mime + ) { // @todo The length stuff in this method should really be done after // we validate the text since it might change if there was an incorrect // charset etc... For BC reasons, however, we need to keep the @@ -584,22 +587,23 @@ protected function _getHtmlPart( $html, 0, $this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_HTML]['truncationsize'], - $charset); + $charset + ); } $truncated = $html_size > strlen($html); - if ($this->_version >= Horde_ActiveSync::VERSION_TWELVE && - $truncated && - !empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_HTML]['allornone'])) { + if ($this->_version >= Horde_ActiveSync::VERSION_TWELVE + && $truncated + && !empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_HTML]['allornone'])) { $html = ''; } - return array( + return [ 'charset' => $charset, 'body' => $html, 'estimated_size' => $html_size, - 'truncated' => $truncated - ); + 'truncated' => $truncated, + ]; } /** @@ -609,8 +613,9 @@ protected function _getHtmlPart( * */ protected function _getHtmlPart2Plain( - Horde_Imap_Client_Data_Fetch $data, Horde_Mime_Part $html_mime) - { + Horde_Imap_Client_Data_Fetch $data, + Horde_Mime_Part $html_mime + ) { $html_id = $html_mime->getMimeId(); $html = $data->getBodyPart($html_id); if (!$data->getBodyPartDecode($html_id)) { @@ -619,7 +624,10 @@ protected function _getHtmlPart2Plain( } $charset = $html_mime->getCharset(); $html_plain = Horde_Text_Filter::filter( - $html, 'Html2text', array('charset' => $charset, 'nestingLimit' => 1000)); + $html, + 'Html2text', + ['charset' => $charset, 'nestingLimit' => 1000] + ); $html_plain_size = strlen($html_plain); if (!empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_PLAIN]['truncationsize'])) { @@ -632,19 +640,19 @@ protected function _getHtmlPart2Plain( ); } $truncated = $html_plain_size > strlen($html_plain); - if ($this->_version >= Horde_ActiveSync::VERSION_TWELVE && - $truncated && - !empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_PLAIN]['allornone'])) { + if ($this->_version >= Horde_ActiveSync::VERSION_TWELVE + && $truncated + && !empty($this->_options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_PLAIN]['allornone'])) { $html_plain = ''; } - return array( + return [ 'charset' => $charset, 'body' => $html_plain, 'truncated' => $truncated, - 'size' => $html_plain_size - ); + 'size' => $html_plain_size, + ]; } /** @@ -662,8 +670,10 @@ protected function _getHtmlPart2Plain( * - size: (integer) The original part size, in bytes. */ protected function _getBodyPart( - Horde_Imap_Client_Data_Fetch $data, Horde_Mime_Part $mime, $to_html) - { + Horde_Imap_Client_Data_Fetch $data, + Horde_Mime_Part $mime, + $to_html + ) { $id = $mime->getMimeId(); $text = $data->getBodyPart($id); if (!$data->getBodyPartDecode($id)) { @@ -673,7 +683,10 @@ protected function _getBodyPart( if ($to_html) { $text = Horde_Text_Filter::filter( - $text, 'Text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO, 'charset' => $mime->getCharset())); + $text, + 'Text2html', + ['parselevel' => Horde_Text_Filter_Text2html::MICRO, 'charset' => $mime->getCharset()] + ); $size = strlen($text); } else { $size = !is_null($data->getBodyPartSize($id)) @@ -686,15 +699,16 @@ protected function _getBodyPart( $text, 0, $this->_options['bodypartprefs']['truncationsize'], - $mime->getCharset()); + $mime->getCharset() + ); } - return array( + return [ 'charset' => $mime->getCharset(), 'body' => $text, 'truncated' => $size > strlen($text), - 'size' => $size - ); + 'size' => $size, + ]; } /** @@ -769,7 +783,7 @@ public function bodyPartBody() */ protected function _validateBodyData(&$data) { - $stream = new Horde_Stream_Temp(array('max_memory' => 1048576)); + $stream = new Horde_Stream_Temp(['max_memory' => 1048576]); $filter_h = stream_filter_append($stream->stream, 'horde_eol', STREAM_FILTER_WRITE); $stream->add(Horde_ActiveSync_Utils::ensureUtf8($data['body'], $data['charset']), true); stream_filter_remove($filter_h); @@ -785,7 +799,7 @@ protected function _validateBodyData(&$data) */ public function toArray() { - $result = array(); + $result = []; if ($this->plain) { $result['plain'] = $this->_plain; } diff --git a/lib/Horde/ActiveSync/Imap/Strategy/Base.php b/lib/Horde/ActiveSync/Imap/Strategy/Base.php index 5760b58e..f192029c 100644 --- a/lib/Horde/ActiveSync/Imap/Strategy/Base.php +++ b/lib/Horde/ActiveSync/Imap/Strategy/Base.php @@ -1,4 +1,5 @@ _imap = $imap; $this->_imap_ob = $imap->getImapOb(); $this->_status = $status; @@ -111,7 +112,7 @@ protected function _getMsgFlags() return $this->_imap->getMsgFlags(); } - return array(); + return []; } } diff --git a/lib/Horde/ActiveSync/Imap/Strategy/Initial.php b/lib/Horde/ActiveSync/Imap/Strategy/Initial.php index 9d5d0036..f58f456e 100644 --- a/lib/Horde/ActiveSync/Imap/Strategy/Initial.php +++ b/lib/Horde/ActiveSync/Imap/Strategy/Initial.php @@ -1,4 +1,5 @@ * @package ActiveSync */ -class Horde_ActiveSync_Imap_Strategy_Initial -extends Horde_ActiveSync_Imap_Strategy_Base +class Horde_ActiveSync_Imap_Strategy_Initial extends Horde_ActiveSync_Imap_Strategy_Base { /** * Return a folder object containing all IMAP server change information. @@ -41,11 +41,11 @@ public function getChanges(array $options) $search_ret = $this->_imap_ob->search( $this->_mbox, $query, - array('results' => array(Horde_Imap_Client::SEARCH_RESULTS_MATCH)) + ['results' => [Horde_Imap_Client::SEARCH_RESULTS_MATCH]] ); - if ($this->_status[Horde_ActiveSync_Folder_Imap::HIGHESTMODSEQ] && - !$this->_folder->haveInitialSync) { + if ($this->_status[Horde_ActiveSync_Folder_Imap::HIGHESTMODSEQ] + && !$this->_folder->haveInitialSync) { $this->_logger->meta('Priming IMAP folder object.'); $this->_folder->primeFolder($search_ret['match']->ids); @@ -54,7 +54,7 @@ public function getChanges(array $options) $query = new Horde_Imap_Client_Fetch_Query(); $query->flags(); $cnt = ($search_ret['count'] / Horde_ActiveSync_Imap_Adapter::MAX_FETCH) + 1; - $flags = array(); + $flags = []; for ($i = 0; $i <= $cnt; $i++) { $ids = new Horde_Imap_Client_Ids( array_slice( @@ -66,12 +66,12 @@ public function getChanges(array $options) $fetch_ret = $this->_imap_ob->fetch( $this->_mbox, $query, - array('ids' => $ids) + ['ids' => $ids] ); foreach ($fetch_ret as $uid => $data) { - $flags[$uid] = array( - 'read' => (array_search(Horde_Imap_Client::FLAG_SEEN, $data->getFlags()) !== false) ? 1 : 0 - ); + $flags[$uid] = [ + 'read' => (array_search(Horde_Imap_Client::FLAG_SEEN, $data->getFlags()) !== false) ? 1 : 0, + ]; if (($options['protocolversion']) > Horde_ActiveSync::VERSION_TWOFIVE) { $flags[$uid]['flagged'] = (array_search(Horde_Imap_Client::FLAG_FLAGGED, $data->getFlags()) !== false) ? 1 : 0; } diff --git a/lib/Horde/ActiveSync/Imap/Strategy/Modseq.php b/lib/Horde/ActiveSync/Imap/Strategy/Modseq.php index df1b48ce..9b1bea5c 100644 --- a/lib/Horde/ActiveSync/Imap/Strategy/Modseq.php +++ b/lib/Horde/ActiveSync/Imap/Strategy/Modseq.php @@ -1,4 +1,5 @@ _logger->meta('CONDSTORE and CHANGES'); - $flags = array(); + $flags = []; $current_modseq = $this->_status[Horde_ActiveSync_Folder_Imap::HIGHESTMODSEQ]; $query = new Horde_Imap_Client_Search_Query(); @@ -86,21 +87,23 @@ public function getChanges(array $options) $search_ret = $this->_imap_ob->search( $this->_mbox, $query, - array('results' => array(Horde_Imap_Client::SEARCH_RESULTS_MATCH)) + ['results' => [Horde_Imap_Client::SEARCH_RESULTS_MATCH]] ); $search_uids = $search_ret['count'] ? $search_ret['match']->ids - : array(); + : []; // Catch changes to FILTERTYPE. if (!empty($options['refreshfilter'])) { $this->_logger->meta('Checking for additional messages within the new FilterType parameters.'); $search_ret = $this->_searchQuery($options, false); if ($search_ret['count']) { - $this->_logger->meta(sprintf( - 'Found %d messages that are now outside FilterType.', - $search_ret['count']) + $this->_logger->meta( + sprintf( + 'Found %d messages that are now outside FilterType.', + $search_ret['count'] + ) ); $search_uids = array_merge($search_uids, $search_ret['match']->ids); } @@ -113,27 +116,33 @@ public function getChanges(array $options) $query->modseq(); } $query->flags(); - $changes = array(); - $categories = array(); + $changes = []; + $categories = []; for ($i = 0; $i <= $cnt; $i++) { $ids = new Horde_Imap_Client_Ids( array_slice( $search_uids, - $i * Horde_ActiveSync_Imap_Adapter::MAX_FETCH, Horde_ActiveSync_Imap_Adapter::MAX_FETCH + $i * Horde_ActiveSync_Imap_Adapter::MAX_FETCH, + Horde_ActiveSync_Imap_Adapter::MAX_FETCH ) ); try { $fetch_ret = $this->_imap_ob->fetch( $this->_mbox, $query, - array('ids' => $ids) + ['ids' => $ids] ); } catch (Horde_Imap_Client_Exception $e) { $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); } $this->_buildModSeqChanges( - $changes, $flags, $categories, $fetch_ret, $options, $current_modseq + $changes, + $flags, + $categories, + $fetch_ret, + $options, + $current_modseq ); } @@ -150,29 +159,37 @@ public function getChanges(array $options) $deleted = $this->_imap_ob->vanished( $this->_mbox, $this->_folder->modseq(), - array('ids' => new Horde_Imap_Client_Ids($this->_folder->messages()))); + ['ids' => new Horde_Imap_Client_Ids($this->_folder->messages())] + ); } catch (Horde_Imap_Client_Excetion $e) { $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); } $this->_folder->setRemoved($deleted->ids); - $this->_logger->meta(sprintf( - 'Found %d deleted messages.', - $deleted->count()) + $this->_logger->meta( + sprintf( + 'Found %d deleted messages.', + $deleted->count() + ) ); // Check for SOFTDELETE messages. - if (!empty($options['sincedate']) && - (!empty($options['softdelete']) || !empty($options['refreshfilter']))) { - $this->_logger->meta(sprintf( - 'Polling for SOFTDELETE in %s before %d', - $this->_folder->serverid(), $options['sincedate']) + if (!empty($options['sincedate']) + && (!empty($options['softdelete']) || !empty($options['refreshfilter']))) { + $this->_logger->meta( + sprintf( + 'Polling for SOFTDELETE in %s before %d', + $this->_folder->serverid(), + $options['sincedate'] + ) ); $search_ret = $this->_searchQuery($options, true); if ($search_ret['count']) { - $this->_logger->meta(sprintf( - 'Found %d messages to SOFTDELETE.', - count($search_ret['match']->ids)) + $this->_logger->meta( + sprintf( + 'Found %d messages to SOFTDELETE.', + count($search_ret['match']->ids) + ) ); $this->_folder->setSoftDeleted($search_ret['match']->ids); } @@ -205,7 +222,8 @@ protected function _searchQuery($options, $is_delete) return $this->_imap_ob->search( $this->_mbox, $query, - array('results' => array(Horde_Imap_Client::SEARCH_RESULTS_MATCH))); + ['results' => [Horde_Imap_Client::SEARCH_RESULTS_MATCH]] + ); } catch (Horde_Imap_Client_Exception $e) { $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); @@ -224,8 +242,13 @@ protected function _searchQuery($options, $is_delete) * @param integer $modseq Current MODSEQ. */ protected function _buildModSeqChanges( - &$changes, &$flags, &$categories, $fetch_ret, $options, $modseq) - { + &$changes, + &$flags, + &$categories, + $fetch_ret, + $options, + $modseq + ) { // Get custom flags to use as categories. $msgFlags = $this->_getMsgFlags(); @@ -238,14 +261,14 @@ protected function _buildModSeqChanges( $data = $fetch_ret[$uid]; if ($data->getModSeq() <= $modseq) { $changes[] = $uid; - $flags[$uid] = array( - 'read' => (array_search(Horde_Imap_Client::FLAG_SEEN, $data->getFlags()) !== false) ? 1 : 0 - ); + $flags[$uid] = [ + 'read' => (array_search(Horde_Imap_Client::FLAG_SEEN, $data->getFlags()) !== false) ? 1 : 0, + ]; if (($options['protocolversion']) > Horde_ActiveSync::VERSION_TWOFIVE) { $flags[$uid]['flagged'] = (array_search(Horde_Imap_Client::FLAG_FLAGGED, $data->getFlags()) !== false) ? 1 : 0; } if ($options['protocolversion'] > Horde_ActiveSync::VERSION_TWELVEONE) { - $categories[$uid] = array(); + $categories[$uid] = []; foreach ($data->getFlags() as $flag) { if (!empty($msgFlags[Horde_String::lower($flag)])) { $categories[$uid][] = $msgFlags[Horde_String::lower($flag)]; diff --git a/lib/Horde/ActiveSync/Imap/Strategy/Plain.php b/lib/Horde/ActiveSync/Imap/Strategy/Plain.php index c982d9f3..6fb7891d 100644 --- a/lib/Horde/ActiveSync/Imap/Strategy/Plain.php +++ b/lib/Horde/ActiveSync/Imap/Strategy/Plain.php @@ -1,4 +1,5 @@ * @package ActiveSync */ -class Horde_ActiveSync_Imap_Strategy_Plain -extends Horde_ActiveSync_Imap_Strategy_Base +class Horde_ActiveSync_Imap_Strategy_Plain extends Horde_ActiveSync_Imap_Strategy_Base { /** * Return a folder object containing all IMAP server change information. @@ -29,9 +29,12 @@ class Horde_ActiveSync_Imap_Strategy_Plain */ public function getChanges(array $options) { - $this->_logger->meta(sprintf( - 'NO CONDSTORE or per mailbox MODSEQ. minuid: %s, total_messages: %s', - $this->_folder->minuid(), $this->_status['messages']) + $this->_logger->meta( + sprintf( + 'NO CONDSTORE or per mailbox MODSEQ. minuid: %s, total_messages: %s', + $this->_folder->minuid(), + $this->_status['messages'] + ) ); $query = new Horde_Imap_Client_Search_Query(); @@ -46,7 +49,7 @@ public function getChanges(array $options) $search_ret = $this->_imap_ob->search( $this->_mbox, $query, - array('results' => array(Horde_Imap_Client::SEARCH_RESULTS_MATCH)) + ['results' => [Horde_Imap_Client::SEARCH_RESULTS_MATCH]] ); } catch (Horde_Imap_Client_Exception $e) { $this->_logger->err($e->getMessage()); @@ -56,7 +59,7 @@ public function getChanges(array $options) $cnt = ($search_ret['count'] / Horde_ActiveSync_Imap_Adapter::MAX_FETCH) + 1; $query = new Horde_Imap_Client_Fetch_Query(); $query->flags(); - $flags = array(); + $flags = []; for ($i = 0; $i <= $cnt; $i++) { $ids = new Horde_Imap_Client_Ids( array_slice( @@ -69,19 +72,19 @@ public function getChanges(array $options) $fetch_ret = $this->_imap_ob->fetch( $this->_mbox, $query, - array('ids' => $ids) + ['ids' => $ids] ); } catch (Horde_Imap_Client_Exception $e) { $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); } foreach ($fetch_ret as $uid => $data) { - $flags[$uid] = array( - 'read' => (array_search(Horde_Imap_Client::FLAG_SEEN, $data->getFlags()) !== false) ? 1 : 0 - ); + $flags[$uid] = [ + 'read' => (array_search(Horde_Imap_Client::FLAG_SEEN, $data->getFlags()) !== false) ? 1 : 0, + ]; if (($options['protocolversion']) > Horde_ActiveSync::VERSION_TWOFIVE) { - $flags[$uid]['flagged'] = - (array_search(Horde_Imap_Client::FLAG_FLAGGED, $data->getFlags()) !== false) ? 1 : 0; + $flags[$uid]['flagged'] + = (array_search(Horde_Imap_Client::FLAG_FLAGGED, $data->getFlags()) !== false) ? 1 : 0; } } } @@ -92,7 +95,7 @@ public function getChanges(array $options) $this->_imap_ob->vanished( $this->_mbox, null, - array('ids' => new Horde_Imap_Client_Ids($this->_folder->messages())) + ['ids' => new Horde_Imap_Client_Ids($this->_folder->messages())] )->ids ); diff --git a/lib/Horde/ActiveSync/Interface/ImapFactory.php b/lib/Horde/ActiveSync/Interface/ImapFactory.php index 3fe99ff0..0dfbb895 100644 --- a/lib/Horde/ActiveSync/Interface/ImapFactory.php +++ b/lib/Horde/ActiveSync/Interface/ImapFactory.php @@ -1,4 +1,5 @@ _params['path'])) { - new Horde_ActiveSync_Log_Logger(new Horde_Log_Handler_Null()); + new Horde_ActiveSync_Log_Logger(new Horde_Log_Handler_Null()); } switch ($this->_params['type']) { - case 'onefile': - if (!empty($properties['DeviceId'])) { - $device_id = Horde_String::upper($properties['DeviceId']); - $stream = @fopen($this->_params['path'], 'a'); - } - break; - case 'perdevice': - if (!empty($properties['DeviceId'])) { - $stream = @fopen( - $this->_params['path'] . '/' . Horde_String::upper($properties['DeviceId']) . '.txt', - 'a' - ); - } - break; - case 'perrequest': - if (!empty($properties['DeviceId'])) { - $dir = sprintf('%s/%s', - $this->_params['path'], - Horde_String::upper($properties['DeviceId']) - ); - if (!is_dir($dir)) { - mkdir($dir, 0755, true); + case 'onefile': + if (!empty($properties['DeviceId'])) { + $device_id = Horde_String::upper($properties['DeviceId']); + $stream = @fopen($this->_params['path'], 'a'); + } + break; + case 'perdevice': + if (!empty($properties['DeviceId'])) { + $stream = @fopen( + $this->_params['path'] . '/' . Horde_String::upper($properties['DeviceId']) . '.txt', + 'a' + ); + } + break; + case 'perrequest': + if (!empty($properties['DeviceId'])) { + $dir = sprintf( + '%s/%s', + $this->_params['path'], + Horde_String::upper($properties['DeviceId']) + ); + if (!is_dir($dir)) { + mkdir($dir, 0o755, true); + } + $path = sprintf( + '%s/%s-%s-%s.txt', + $dir, + time(), + getmypid(), + (!empty($properties['Cmd']) ? $properties['Cmd'] : 'UnknownCmd') + ); + $stream = fopen($path, 'a'); } - $path = sprintf('%s/%s-%s-%s.txt', - $dir, - time(), - getmypid(), - (!empty($properties['Cmd']) ? $properties['Cmd'] : 'UnknownCmd') - ); - $stream = fopen($path, 'a'); - } } if ($stream) { diff --git a/lib/Horde/ActiveSync/Log/Formatter.php b/lib/Horde/ActiveSync/Log/Formatter.php index 8c266414..c86fc441 100644 --- a/lib/Horde/ActiveSync/Log/Formatter.php +++ b/lib/Horde/ActiveSync/Log/Formatter.php @@ -1,4 +1,5 @@ 'I', 'SERVER' => 'O', - 'META' => '>>>' - ); + 'META' => '>>>', + ]; /** * Formats an event to be written by the handler. diff --git a/lib/Horde/ActiveSync/Log/Handler.php b/lib/Horde/ActiveSync/Log/Handler.php index 13846c44..6f288a42 100644 --- a/lib/Horde/ActiveSync/Log/Handler.php +++ b/lib/Horde/ActiveSync/Log/Handler.php @@ -1,4 +1,5 @@ _stream, fread($message, 8192)); + fwrite($this->_stream, fread($message, 8192)); } fwrite($this->_stream, PHP_EOL); rewind($event['message']); diff --git a/lib/Horde/ActiveSync/Log/Logger.php b/lib/Horde/ActiveSync/Log/Logger.php index 711d72f1..113b2a94 100644 --- a/lib/Horde/ActiveSync/Log/Logger.php +++ b/lib/Horde/ActiveSync/Log/Logger.php @@ -1,4 +1,5 @@ _levels[$levelName])) { throw new Horde_Log_Exception('Bad log level ' . $levelName); } - if (in_array($method, array('client', 'server'))) { - $event = array( + if (in_array($method, ['client', 'server'])) { + $event = [ 'message' => $params[0], 'indent' => $params[1], 'level' => $this->_levels[$levelName], - 'timestamp' => date('c') - ); + 'timestamp' => date('c'), + ]; } else { - $event = array( + $event = [ 'message' => array_shift($params), 'level' => $this->_levels[$levelName], 'indent' => 0, - 'timestamp' => date('c') - ); + 'timestamp' => date('c'), + ]; } $this->log($event); diff --git a/lib/Horde/ActiveSync/Log/Logger/Deprecated.php b/lib/Horde/ActiveSync/Log/Logger/Deprecated.php index 16cf7b6b..966ffa21 100644 --- a/lib/Horde/ActiveSync/Log/Logger/Deprecated.php +++ b/lib/Horde/ActiveSync/Log/Logger/Deprecated.php @@ -1,4 +1,5 @@ addLevel('SERVER', Horde_ActiveSync_Log_Logger::SERVER); @@ -57,19 +58,19 @@ public function __call($method, $params) if (!isset($this->_levels[$levelName])) { throw new Horde_Log_Exception('Bad log level ' . $levelName); } - if (in_array($method, array('client', 'server', 'meta'))) { + if (in_array($method, ['client', 'server', 'meta'])) { switch ($method) { - case 'client': - $pre = 'I '; - break; - case 'server': - $pre = 'O '; - break; - default: - $pre = ''; - $params[1] = 0; + case 'client': + $pre = 'I '; + break; + case 'server': + $pre = 'O '; + break; + default: + $pre = ''; + $params[1] = 0; } - $message = sprintf('[%s] %s%s ', getmypid(), $pre, str_repeat(' ' , $params[1])); + $message = sprintf('[%s] %s%s ', getmypid(), $pre, str_repeat(' ', $params[1])); if (is_resource($params[0])) { rewind($params[0]); $message .= stream_get_contents($params[0]); @@ -77,17 +78,17 @@ public function __call($method, $params) } else { $message .= $params[0]; } - $event = array( + $event = [ 'message' => $message, 'indent' => $params[1], - 'level' => $this->_levels['DEBUG'] - ); + 'level' => $this->_levels['DEBUG'], + ]; } else { - $event = array( + $event = [ 'message' => array_shift($params), 'level' => $this->_levels[$levelName], - 'indent' => 0 - ); + 'indent' => 0, + ]; } $this->_logger->log($event); diff --git a/lib/Horde/ActiveSync/Message/AirSyncBaseAdd.php b/lib/Horde/ActiveSync/Message/AirSyncBaseAdd.php index c56e6989..fbbbde21 100644 --- a/lib/Horde/ActiveSync/Message/AirSyncBaseAdd.php +++ b/lib/Horde/ActiveSync/Message/AirSyncBaseAdd.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'clientid'), - Horde_ActiveSync::AIRSYNCBASE_CONTENT => array(self::KEY_ATTRIBUTE => 'content'), - Horde_ActiveSync::AIRSYNCBASE_CONTENTID => array(self::KEY_ATTRIBUTE => 'contentid'), - Horde_ActiveSync::AIRSYNCBASE_CONTENTLOCATION => array(self::KEY_ATTRIBUTE => 'contentlocation'), - Horde_ActiveSync::AIRSYNCBASE_CONTENTTYPE => array(self::KEY_ATTRIBUTE => 'contenttype'), - Horde_ActiveSync::AIRSYNCBASE_DISPLAYNAME => array(self::KEY_ATTRIBUTE => 'displayname'), - Horde_ActiveSync::AIRSYNCBASE_ISINLINE => array(self::KEY_ATTRIBUTE => 'isinline'), - Horde_ActiveSync::AIRSYNCBASE_METHOD => array(self::KEY_ATTRIBUTE => 'method') - ); + protected $_mapping = [ + Horde_ActiveSync::AIRSYNCBASE_CLIENTID => [self::KEY_ATTRIBUTE => 'clientid'], + Horde_ActiveSync::AIRSYNCBASE_CONTENT => [self::KEY_ATTRIBUTE => 'content'], + Horde_ActiveSync::AIRSYNCBASE_CONTENTID => [self::KEY_ATTRIBUTE => 'contentid'], + Horde_ActiveSync::AIRSYNCBASE_CONTENTLOCATION => [self::KEY_ATTRIBUTE => 'contentlocation'], + Horde_ActiveSync::AIRSYNCBASE_CONTENTTYPE => [self::KEY_ATTRIBUTE => 'contenttype'], + Horde_ActiveSync::AIRSYNCBASE_DISPLAYNAME => [self::KEY_ATTRIBUTE => 'displayname'], + Horde_ActiveSync::AIRSYNCBASE_ISINLINE => [self::KEY_ATTRIBUTE => 'isinline'], + Horde_ActiveSync::AIRSYNCBASE_METHOD => [self::KEY_ATTRIBUTE => 'method'], + ]; /** * Property mapping. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'clientid' => false, 'content' => false, 'contentid' => false, @@ -50,7 +50,7 @@ class Horde_ActiveSync_Message_AirSyncBaseAdd extends Horde_ActiveSync_Message_B 'displayname' => false, 'isinline' => false, 'method' => false, - ); + ]; /** * Return the type of message. diff --git a/lib/Horde/ActiveSync/Message/AirSyncBaseAttachment.php b/lib/Horde/ActiveSync/Message/AirSyncBaseAttachment.php index fbf3464c..51870e11 100644 --- a/lib/Horde/ActiveSync/Message/AirSyncBaseAttachment.php +++ b/lib/Horde/ActiveSync/Message/AirSyncBaseAttachment.php @@ -1,4 +1,5 @@ array (self::KEY_ATTRIBUTE => 'displayname'), - Horde_ActiveSync::AIRSYNCBASE_FILEREFERENCE => array (self::KEY_ATTRIBUTE => 'attname'), - Horde_ActiveSync::AIRSYNCBASE_METHOD => array (self::KEY_ATTRIBUTE => 'attmethod'), - Horde_ActiveSync::AIRSYNCBASE_ESTIMATEDDATASIZE => array (self::KEY_ATTRIBUTE => 'attsize'), - Horde_ActiveSync::AIRSYNCBASE_CONTENTID => array (self::KEY_ATTRIBUTE => 'contentid'), - Horde_ActiveSync::AIRSYNCBASE_CONTENTLOCATION => array (self::KEY_ATTRIBUTE => 'contentlocation'), - Horde_ActiveSync::AIRSYNCBASE_ISINLINE => array (self::KEY_ATTRIBUTE => 'isinline'), - Horde_ActiveSync::AIRSYNCBASE_DATA => array (self::KEY_ATTRIBUTE => '_data'), - ); + protected $_mapping = [ + Horde_ActiveSync::AIRSYNCBASE_DISPLAYNAME => [self::KEY_ATTRIBUTE => 'displayname'], + Horde_ActiveSync::AIRSYNCBASE_FILEREFERENCE => [self::KEY_ATTRIBUTE => 'attname'], + Horde_ActiveSync::AIRSYNCBASE_METHOD => [self::KEY_ATTRIBUTE => 'attmethod'], + Horde_ActiveSync::AIRSYNCBASE_ESTIMATEDDATASIZE => [self::KEY_ATTRIBUTE => 'attsize'], + Horde_ActiveSync::AIRSYNCBASE_CONTENTID => [self::KEY_ATTRIBUTE => 'contentid'], + Horde_ActiveSync::AIRSYNCBASE_CONTENTLOCATION => [self::KEY_ATTRIBUTE => 'contentlocation'], + Horde_ActiveSync::AIRSYNCBASE_ISINLINE => [self::KEY_ATTRIBUTE => 'isinline'], + Horde_ActiveSync::AIRSYNCBASE_DATA => [self::KEY_ATTRIBUTE => '_data'], + ]; /** * Property mapping. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'attmethod' => false, 'attsize' => false, 'displayname' => false, @@ -74,26 +75,26 @@ class Horde_ActiveSync_Message_AirSyncBaseAttachment extends Horde_ActiveSync_Me 'contentid' => false, 'contentlocation' => false, 'isinline' => false, - '_data' => false - ); + '_data' => false, + ]; /** * Const'r * * @see Horde_ActiveSync_Message_Base::__construct() */ - public function __construct(array $options = array()) + public function __construct(array $options = []) { parent::__construct($options); if ($this->_version >= Horde_ActiveSync::VERSION_SIXTEEN) { - $this->_mapping += array( - Horde_ActiveSync::AIRSYNCBASE_CLIENTID=> array(self::KEY_ATTRIBUTE => 'clientid') - ); + $this->_mapping += [ + Horde_ActiveSync::AIRSYNCBASE_CLIENTID => [self::KEY_ATTRIBUTE => 'clientid'], + ]; - $this->_properties += array( + $this->_properties += [ 'clientid' => false, 'filereference' => false, - ); + ]; } } diff --git a/lib/Horde/ActiveSync/Message/AirSyncBaseBody.php b/lib/Horde/ActiveSync/Message/AirSyncBaseBody.php index 392e3583..f5b992d8 100644 --- a/lib/Horde/ActiveSync/Message/AirSyncBaseBody.php +++ b/lib/Horde/ActiveSync/Message/AirSyncBaseBody.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'type'), - Horde_ActiveSync::AIRSYNCBASE_ESTIMATEDDATASIZE => array(self::KEY_ATTRIBUTE => 'estimateddatasize'), - Horde_ActiveSync::AIRSYNCBASE_TRUNCATED => array(self::KEY_ATTRIBUTE => 'truncated'), - Horde_ActiveSync::AIRSYNCBASE_DATA => array(self::KEY_ATTRIBUTE => 'data'), - ); + protected $_mapping = [ + Horde_ActiveSync::AIRSYNCBASE_TYPE => [self::KEY_ATTRIBUTE => 'type'], + Horde_ActiveSync::AIRSYNCBASE_ESTIMATEDDATASIZE => [self::KEY_ATTRIBUTE => 'estimateddatasize'], + Horde_ActiveSync::AIRSYNCBASE_TRUNCATED => [self::KEY_ATTRIBUTE => 'truncated'], + Horde_ActiveSync::AIRSYNCBASE_DATA => [self::KEY_ATTRIBUTE => 'data'], + ]; /** * Property values * * @var array */ - protected $_properties = array( + protected $_properties = [ 'type' => false, 'estimateddatasize' => false, 'truncated' => false, - 'data' => false - ); + 'data' => false, + ]; /** * Const'r * * @see Horde_ActiveSync_Message_Base::__construct() */ - public function __construct(array $options = array()) + public function __construct(array $options = []) { parent::__construct($options); if ($this->_version >= Horde_ActiveSync::VERSION_FOURTEEN) { - $this->_mapping += array( - Horde_ActiveSync::AIRSYNCBASE_PREVIEW => array(self::KEY_ATTRIBUTE => 'preview') - ); - $this->_properties += array( - 'preview' => false - ); + $this->_mapping += [ + Horde_ActiveSync::AIRSYNCBASE_PREVIEW => [self::KEY_ATTRIBUTE => 'preview'], + ]; + $this->_properties += [ + 'preview' => false, + ]; } } diff --git a/lib/Horde/ActiveSync/Message/AirSyncBaseBodypart.php b/lib/Horde/ActiveSync/Message/AirSyncBaseBodypart.php index 85d803b6..cf46af4d 100644 --- a/lib/Horde/ActiveSync/Message/AirSyncBaseBodypart.php +++ b/lib/Horde/ActiveSync/Message/AirSyncBaseBodypart.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'status'), - Horde_ActiveSync::AIRSYNCBASE_TYPE => array(self::KEY_ATTRIBUTE => 'type'), - Horde_ActiveSync::AIRSYNCBASE_ESTIMATEDDATASIZE => array(self::KEY_ATTRIBUTE => 'estimateddatasize'), - Horde_ActiveSync::AIRSYNCBASE_TRUNCATED => array(self::KEY_ATTRIBUTE => 'truncated'), - Horde_ActiveSync::AIRSYNCBASE_DATA => array(self::KEY_ATTRIBUTE => 'data'), - Horde_ActiveSync::AIRSYNCBASE_PREVIEW => array(self::KEY_ATTRIBUTE => 'preview') - ); + protected $_mapping = [ + Horde_ActiveSync::AIRSYNCBASE_STATUS => [self::KEY_ATTRIBUTE => 'status'], + Horde_ActiveSync::AIRSYNCBASE_TYPE => [self::KEY_ATTRIBUTE => 'type'], + Horde_ActiveSync::AIRSYNCBASE_ESTIMATEDDATASIZE => [self::KEY_ATTRIBUTE => 'estimateddatasize'], + Horde_ActiveSync::AIRSYNCBASE_TRUNCATED => [self::KEY_ATTRIBUTE => 'truncated'], + Horde_ActiveSync::AIRSYNCBASE_DATA => [self::KEY_ATTRIBUTE => 'data'], + Horde_ActiveSync::AIRSYNCBASE_PREVIEW => [self::KEY_ATTRIBUTE => 'preview'], + ]; /** * Property values * * @var array */ - protected $_properties = array( + protected $_properties = [ 'status' => false, 'type' => Horde_ActiveSync::BODYPREF_TYPE_HTML, 'estimateddatasize' => false, 'truncated' => false, 'data' => false, 'preview' => false, - ); + ]; /** * Return the message type. diff --git a/lib/Horde/ActiveSync/Message/AirSyncBaseDelete.php b/lib/Horde/ActiveSync/Message/AirSyncBaseDelete.php index 293cf17d..36357bca 100644 --- a/lib/Horde/ActiveSync/Message/AirSyncBaseDelete.php +++ b/lib/Horde/ActiveSync/Message/AirSyncBaseDelete.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'filereference') - ); + protected $_mapping = [ + Horde_ActiveSync::AIRSYNCBASE_FILEREFERENCE => [self::KEY_ATTRIBUTE => 'filereference'], + ]; /** * Property mapping. * * @var array */ - protected $_properties = array( - 'filereference' => false - ); + protected $_properties = [ + 'filereference' => false, + ]; /** * Return the type of message. diff --git a/lib/Horde/ActiveSync/Message/AirSyncBaseFileAttachment.php b/lib/Horde/ActiveSync/Message/AirSyncBaseFileAttachment.php index 3a29caf0..d9756341 100644 --- a/lib/Horde/ActiveSync/Message/AirSyncBaseFileAttachment.php +++ b/lib/Horde/ActiveSync/Message/AirSyncBaseFileAttachment.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'data'), - Horde_ActiveSync_Request_ItemOperations::ITEMOPERATIONS_RANGE => array(self::KEY_ATTRIBUTE => 'range'), - Horde_ActiveSync_Request_ItemOperations::ITEMOPERATIONS_TOTAL => array(self::KEY_ATTRIBUTE => 'total'), - Horde_ActiveSync::AIRSYNCBASE_CONTENTTYPE => array(self::KEY_ATTRIBUTE => 'contenttype'), - ); + protected $_mapping = [ + Horde_ActiveSync_Request_ItemOperations::ITEMOPERATIONS_DATA => [self::KEY_ATTRIBUTE => 'data'], + Horde_ActiveSync_Request_ItemOperations::ITEMOPERATIONS_RANGE => [self::KEY_ATTRIBUTE => 'range'], + Horde_ActiveSync_Request_ItemOperations::ITEMOPERATIONS_TOTAL => [self::KEY_ATTRIBUTE => 'total'], + Horde_ActiveSync::AIRSYNCBASE_CONTENTTYPE => [self::KEY_ATTRIBUTE => 'contenttype'], + ]; /** * Property values * * @var array */ - protected $_properties = array( + protected $_properties = [ 'range' => false, 'total' => false, 'contenttype' => false, 'data' => false, - ); + ]; /** * Return the message type. @@ -87,14 +88,14 @@ protected function _checkEncoding($data, $tag) // PHP when using base64-encode as STREAM_FILTER_READ. feof() is // apparently not safe to use when using STREAM_FILTER_READ. if (is_resource($data)) { - $temp = fopen('php://temp/', 'r+'); - $filter = stream_filter_prepend($temp, 'convert.base64-encode', STREAM_FILTER_WRITE); - rewind($data); - while (!feof($data)) { - fwrite($temp, fread($data, 8192)); - } - stream_filter_remove($filter); - rewind($temp); + $temp = fopen('php://temp/', 'r+'); + $filter = stream_filter_prepend($temp, 'convert.base64-encode', STREAM_FILTER_WRITE); + rewind($data); + while (!feof($data)) { + fwrite($temp, fread($data, 8192)); + } + stream_filter_remove($filter); + rewind($temp); return $temp; } else { return base64_encode($data); diff --git a/lib/Horde/ActiveSync/Message/AirSyncBaseLocation.php b/lib/Horde/ActiveSync/Message/AirSyncBaseLocation.php index 60a2faab..8d7fd8e9 100644 --- a/lib/Horde/ActiveSync/Message/AirSyncBaseLocation.php +++ b/lib/Horde/ActiveSync/Message/AirSyncBaseLocation.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'accuracy'), - Horde_ActiveSync::AIRSYNCBASE_ALTITUDE => array(self::KEY_ATTRIBUTE => 'altitude'), - Horde_ActiveSync::AIRSYNCBASE_ALTITUDEACCURACY => array(self::KEY_ATTRIBUTE => 'altitudeaccuracy'), - Horde_ActiveSync::AIRSYNCBASE_ANNOTATION => array(self::KEY_ATTRIBUTE => 'annotation'), - Horde_ActiveSync::AIRSYNCBASE_CITY => array(self::KEY_ATTRIBUTE => 'city'), - Horde_ActiveSync::AIRSYNCBASE_COUNTRY => array(self::KEY_ATTRIBUTE => 'country'), - Horde_ActiveSync::AIRSYNCBASE_DISPLAYNAME => array(self::KEY_ATTRIBUTE => 'displayname'), - Horde_ActiveSync::AIRSYNCBASE_LATITUDE => array(self::KEY_ATTRIBUTE => 'latitude'), - Horde_ActiveSync::AIRSYNCBASE_LOCATIONURI => array(self::KEY_ATTRIBUTE => 'locationuri'), - Horde_ActiveSync::AIRSYNCBASE_LONGITUDE => array(self::KEY_ATTRIBUTE => 'longitude'), - Horde_ActiveSync::AIRSYNCBASE_POSTALCODE => array(self::KEY_ATTRIBUTE => 'postalcode'), - Horde_ActiveSync::AIRSYNCBASE_STATE => array(self::KEY_ATTRIBUTE => 'state'), - Horde_ActiveSync::AIRSYNCBASE_STREET => array(self::KEY_ATTRIBUTE => 'street'), - ); + protected $_mapping = [ + Horde_ActiveSync::AIRSYNCBASE_ACCURACY => [self::KEY_ATTRIBUTE => 'accuracy'], + Horde_ActiveSync::AIRSYNCBASE_ALTITUDE => [self::KEY_ATTRIBUTE => 'altitude'], + Horde_ActiveSync::AIRSYNCBASE_ALTITUDEACCURACY => [self::KEY_ATTRIBUTE => 'altitudeaccuracy'], + Horde_ActiveSync::AIRSYNCBASE_ANNOTATION => [self::KEY_ATTRIBUTE => 'annotation'], + Horde_ActiveSync::AIRSYNCBASE_CITY => [self::KEY_ATTRIBUTE => 'city'], + Horde_ActiveSync::AIRSYNCBASE_COUNTRY => [self::KEY_ATTRIBUTE => 'country'], + Horde_ActiveSync::AIRSYNCBASE_DISPLAYNAME => [self::KEY_ATTRIBUTE => 'displayname'], + Horde_ActiveSync::AIRSYNCBASE_LATITUDE => [self::KEY_ATTRIBUTE => 'latitude'], + Horde_ActiveSync::AIRSYNCBASE_LOCATIONURI => [self::KEY_ATTRIBUTE => 'locationuri'], + Horde_ActiveSync::AIRSYNCBASE_LONGITUDE => [self::KEY_ATTRIBUTE => 'longitude'], + Horde_ActiveSync::AIRSYNCBASE_POSTALCODE => [self::KEY_ATTRIBUTE => 'postalcode'], + Horde_ActiveSync::AIRSYNCBASE_STATE => [self::KEY_ATTRIBUTE => 'state'], + Horde_ActiveSync::AIRSYNCBASE_STREET => [self::KEY_ATTRIBUTE => 'street'], + ]; /** * Property values * * @var array */ - protected $_properties = array( + protected $_properties = [ 'accuracy' => false, 'altitude' => false, 'altitudeaccuracy' => false, @@ -60,7 +60,7 @@ class Horde_ActiveSync_Message_AirSyncBaseLocation extends Horde_ActiveSync_Mess 'postalcode' => false, 'state' => false, 'street' => false, - ); + ]; /** * Return the message type. @@ -90,14 +90,14 @@ protected function _checkEncoding($data, $tag) // PHP when using base64-encode as STREAM_FILTER_READ. feof() is // apparently not safe to use when using STREAM_FILTER_READ. if (is_resource($data)) { - $temp = fopen('php://temp/', 'r+'); - $filter = stream_filter_prepend($temp, 'convert.base64-encode', STREAM_FILTER_WRITE); - rewind($data); - while (!feof($data)) { - fwrite($temp, fread($data, 8192)); - } - stream_filter_remove($filter); - rewind($temp); + $temp = fopen('php://temp/', 'r+'); + $filter = stream_filter_prepend($temp, 'convert.base64-encode', STREAM_FILTER_WRITE); + rewind($data); + while (!feof($data)) { + fwrite($temp, fread($data, 8192)); + } + stream_filter_remove($filter); + rewind($temp); return $temp; } else { return base64_encode($data); diff --git a/lib/Horde/ActiveSync/Message/Appointment.php b/lib/Horde/ActiveSync/Message/Appointment.php index a548894a..e554bd05 100644 --- a/lib/Horde/ActiveSync/Message/Appointment.php +++ b/lib/Horde/ActiveSync/Message/Appointment.php @@ -1,4 +1,5 @@ Horde_Date::MASK_SUNDAY, Horde_Date::DATE_MONDAY => Horde_Date::MASK_MONDAY, Horde_Date::DATE_TUESDAY => Horde_Date::MASK_TUESDAY, @@ -131,46 +132,46 @@ class Horde_ActiveSync_Message_Appointment extends Horde_ActiveSync_Message_Base Horde_Date::DATE_THURSDAY => Horde_Date::MASK_THURSDAY, Horde_Date::DATE_FRIDAY => Horde_Date::MASK_FRIDAY, Horde_Date::DATE_SATURDAY => Horde_Date::MASK_SATURDAY, - ); + ]; /** * Property mapping. * * @var array */ - protected $_mapping = array( - self::POOMCAL_TIMEZONE => array (self::KEY_ATTRIBUTE => 'timezone'), - self::POOMCAL_ALLDAYEVENT => array (self::KEY_ATTRIBUTE => 'alldayevent'), - self::POOMCAL_BUSYSTATUS => array (self::KEY_ATTRIBUTE => 'busystatus'), - self::POOMCAL_ORGANIZERNAME => array (self::KEY_ATTRIBUTE => 'organizername'), - self::POOMCAL_ORGANIZEREMAIL => array (self::KEY_ATTRIBUTE => 'organizeremail'), - self::POOMCAL_DTSTAMP => array (self::KEY_ATTRIBUTE => 'dtstamp', self::KEY_TYPE => self::TYPE_DATE), - self::POOMCAL_ENDTIME => array (self::KEY_ATTRIBUTE => 'endtime', self::KEY_TYPE => self::TYPE_DATE), - self::POOMCAL_REMINDER => array (self::KEY_ATTRIBUTE => 'reminder'), - self::POOMCAL_SENSITIVITY => array (self::KEY_ATTRIBUTE => 'sensitivity'), - self::POOMCAL_SUBJECT => array (self::KEY_ATTRIBUTE => 'subject'), - self::POOMCAL_STARTTIME => array (self::KEY_ATTRIBUTE => 'starttime', self::KEY_TYPE => self::TYPE_DATE), - self::POOMCAL_UID => array (self::KEY_ATTRIBUTE => 'uid'), - self::POOMCAL_MEETINGSTATUS => array (self::KEY_ATTRIBUTE => 'meetingstatus'), - self::POOMCAL_ATTENDEES => array (self::KEY_ATTRIBUTE => 'attendees', self::KEY_TYPE => 'Horde_ActiveSync_Message_Attendee', self::KEY_VALUES => self::POOMCAL_ATTENDEE), - self::POOMCAL_CATEGORIES => array (self::KEY_ATTRIBUTE => 'categories', self::KEY_VALUES => self::POOMCAL_CATEGORY), - self::POOMCAL_RECURRENCE => array (self::KEY_ATTRIBUTE => 'recurrence', self::KEY_TYPE => 'Horde_ActiveSync_Message_Recurrence'), - self::POOMCAL_EXCEPTIONS => array (self::KEY_ATTRIBUTE => 'exceptions', self::KEY_TYPE => 'Horde_ActiveSync_Message_Exception', self::KEY_VALUES => self::POOMCAL_EXCEPTION), - ); + protected $_mapping = [ + self::POOMCAL_TIMEZONE => [self::KEY_ATTRIBUTE => 'timezone'], + self::POOMCAL_ALLDAYEVENT => [self::KEY_ATTRIBUTE => 'alldayevent'], + self::POOMCAL_BUSYSTATUS => [self::KEY_ATTRIBUTE => 'busystatus'], + self::POOMCAL_ORGANIZERNAME => [self::KEY_ATTRIBUTE => 'organizername'], + self::POOMCAL_ORGANIZEREMAIL => [self::KEY_ATTRIBUTE => 'organizeremail'], + self::POOMCAL_DTSTAMP => [self::KEY_ATTRIBUTE => 'dtstamp', self::KEY_TYPE => self::TYPE_DATE], + self::POOMCAL_ENDTIME => [self::KEY_ATTRIBUTE => 'endtime', self::KEY_TYPE => self::TYPE_DATE], + self::POOMCAL_REMINDER => [self::KEY_ATTRIBUTE => 'reminder'], + self::POOMCAL_SENSITIVITY => [self::KEY_ATTRIBUTE => 'sensitivity'], + self::POOMCAL_SUBJECT => [self::KEY_ATTRIBUTE => 'subject'], + self::POOMCAL_STARTTIME => [self::KEY_ATTRIBUTE => 'starttime', self::KEY_TYPE => self::TYPE_DATE], + self::POOMCAL_UID => [self::KEY_ATTRIBUTE => 'uid'], + self::POOMCAL_MEETINGSTATUS => [self::KEY_ATTRIBUTE => 'meetingstatus'], + self::POOMCAL_ATTENDEES => [self::KEY_ATTRIBUTE => 'attendees', self::KEY_TYPE => 'Horde_ActiveSync_Message_Attendee', self::KEY_VALUES => self::POOMCAL_ATTENDEE], + self::POOMCAL_CATEGORIES => [self::KEY_ATTRIBUTE => 'categories', self::KEY_VALUES => self::POOMCAL_CATEGORY], + self::POOMCAL_RECURRENCE => [self::KEY_ATTRIBUTE => 'recurrence', self::KEY_TYPE => 'Horde_ActiveSync_Message_Recurrence'], + self::POOMCAL_EXCEPTIONS => [self::KEY_ATTRIBUTE => 'exceptions', self::KEY_TYPE => 'Horde_ActiveSync_Message_Exception', self::KEY_VALUES => self::POOMCAL_EXCEPTION], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'alldayevent' => false, - 'attendees' => array(), + 'attendees' => [], 'busystatus' => false, - 'categories' => array(), + 'categories' => [], 'dtstamp' => false, 'endtime' => false, - 'exceptions' => array(), + 'exceptions' => [], 'organizeremail' => false, 'organizername' => false, 'meetingstatus' => false, @@ -183,88 +184,88 @@ class Horde_ActiveSync_Message_Appointment extends Horde_ActiveSync_Message_Base 'uid' => false, // Not part of the protocol. Used internally. 'serveruid' => false, - ); + ]; /** * Const'r * * @see Horde_ActiveSync_Message_Base::__construct() */ - public function __construct(array $options = array()) + public function __construct(array $options = []) { parent::__construct($options); // Removed in 16.0 if ($this->_version <= Horde_ActiveSync::VERSION_FOURTEENONE) { - $this->_mapping += array( - self::POOMCAL_LOCATION => array(self::KEY_ATTRIBUTE => 'location'), - ); - $this->_properties += array( + $this->_mapping += [ + self::POOMCAL_LOCATION => [self::KEY_ATTRIBUTE => 'location'], + ]; + $this->_properties += [ 'location' => false, - ); + ]; } if ($this->_version < Horde_ActiveSync::VERSION_TWELVE) { - $this->_mapping += array( - self::POOMCAL_BODY => array(self::KEY_ATTRIBUTE => 'body'), - self::POOMCAL_BODYTRUNCATED => array(self::KEY_ATTRIBUTE => 'bodytruncated'), - self::POOMCAL_RTF => array(self::KEY_ATTRIBUTE => 'rtf'), - ); + $this->_mapping += [ + self::POOMCAL_BODY => [self::KEY_ATTRIBUTE => 'body'], + self::POOMCAL_BODYTRUNCATED => [self::KEY_ATTRIBUTE => 'bodytruncated'], + self::POOMCAL_RTF => [self::KEY_ATTRIBUTE => 'rtf'], + ]; - $this->_properties += array( + $this->_properties += [ 'body' => false, 'bodytruncated' => 0, - 'rtf' => false - ); + 'rtf' => false, + ]; } else { - $this->_mapping += array( - Horde_ActiveSync::AIRSYNCBASE_BODY => array(self::KEY_ATTRIBUTE => 'airsyncbasebody', self::KEY_TYPE => 'Horde_ActiveSync_Message_AirSyncBaseBody') - ); - $this->_properties += array( - 'airsyncbasebody' => false - ); + $this->_mapping += [ + Horde_ActiveSync::AIRSYNCBASE_BODY => [self::KEY_ATTRIBUTE => 'airsyncbasebody', self::KEY_TYPE => 'Horde_ActiveSync_Message_AirSyncBaseBody'], + ]; + $this->_properties += [ + 'airsyncbasebody' => false, + ]; if ($this->_version >= Horde_ActiveSync::VERSION_FOURTEEN) { - $this->_mapping += array( - self::POOMCAL_RESPONSEREQUESTED => array(self::KEY_ATTRIBUTE => 'responserequested'), - self::POOMCAL_APPOINTMENTREPLYTIME => array(self::KEY_ATTRIBUTE => 'appointmentreplytime', self::KEY_TYPE => self::TYPE_DATE_DASHES), - self::POOMCAL_RESPONSETYPE => array(self::KEY_ATTRIBUTE => 'responsetype'), - self::POOMCAL_DISALLOWNEWTIMEPROPOSAL => array(self::KEY_ATTRIBUTE => 'disallownewtimeproposal'), - ); - $this->_properties += array( + $this->_mapping += [ + self::POOMCAL_RESPONSEREQUESTED => [self::KEY_ATTRIBUTE => 'responserequested'], + self::POOMCAL_APPOINTMENTREPLYTIME => [self::KEY_ATTRIBUTE => 'appointmentreplytime', self::KEY_TYPE => self::TYPE_DATE_DASHES], + self::POOMCAL_RESPONSETYPE => [self::KEY_ATTRIBUTE => 'responsetype'], + self::POOMCAL_DISALLOWNEWTIMEPROPOSAL => [self::KEY_ATTRIBUTE => 'disallownewtimeproposal'], + ]; + $this->_properties += [ 'disallownewtimeproposal' => false, 'responserequested' => false, 'appointmentreplytime' => false, 'responsetype' => false, - ); + ]; } if ($this->_version >= Horde_ActiveSync::VERSION_FOURTEENONE) { - $this->_mapping += array( - self::POOMCAL_ONLINECONFLINK => array(self::KEY_ATTRIBUTE => 'onlinemeetingconflink'), - self::POOMCAL_ONLINEEXTLINK => array(self::KEY_ATTRIBUTE => 'onlinemeetingexternallink') - ); - $this->_properties += array( + $this->_mapping += [ + self::POOMCAL_ONLINECONFLINK => [self::KEY_ATTRIBUTE => 'onlinemeetingconflink'], + self::POOMCAL_ONLINEEXTLINK => [self::KEY_ATTRIBUTE => 'onlinemeetingexternallink'], + ]; + $this->_properties += [ 'onlinemeetingconflink' => false, - 'onlinemeetingexternallink' => false - ); + 'onlinemeetingexternallink' => false, + ]; } if ($this->_version >= Horde_ActiveSync::VERSION_SIXTEEN) { - $this->_mapping += array( - Horde_ActiveSync::AIRSYNCBASE_LOCATION => array(self::KEY_ATTRIBUTE => 'location', self::KEY_TYPE => 'Horde_ActiveSync_Message_AirSyncBaseLocation'), - self::POOMCAL_CLIENTUID => array(self::KEY_ATTRIBUTE => 'clientuid'), - Horde_ActiveSync::AIRSYNCBASE_INSTANCEID => array(self::KEY_ATTRIBUTE => 'instanceid', self::KEY_TYPE => self::TYPE_DATE), - Horde_ActiveSync::AIRSYNCBASE_ATTACHMENTS => array( + $this->_mapping += [ + Horde_ActiveSync::AIRSYNCBASE_LOCATION => [self::KEY_ATTRIBUTE => 'location', self::KEY_TYPE => 'Horde_ActiveSync_Message_AirSyncBaseLocation'], + self::POOMCAL_CLIENTUID => [self::KEY_ATTRIBUTE => 'clientuid'], + Horde_ActiveSync::AIRSYNCBASE_INSTANCEID => [self::KEY_ATTRIBUTE => 'instanceid', self::KEY_TYPE => self::TYPE_DATE], + Horde_ActiveSync::AIRSYNCBASE_ATTACHMENTS => [ self::KEY_ATTRIBUTE => 'airsyncbaseattachments', - self::KEY_TYPE => array('Horde_ActiveSync_Message_AirSyncBaseAttachment', 'Horde_ActiveSync_Message_AirSyncBaseAdd', 'Horde_ActiveSync_Message_AirSyncBaseDelete'), - self::KEY_VALUES => array(Horde_ActiveSync::AIRSYNCBASE_ATTACHMENT, Horde_ActiveSync::AIRSYNCBASE_ADD, Horde_ActiveSync::AIRSYNCBASE_DELETE) - ), - ); - $this->_properties += array( + self::KEY_TYPE => ['Horde_ActiveSync_Message_AirSyncBaseAttachment', 'Horde_ActiveSync_Message_AirSyncBaseAdd', 'Horde_ActiveSync_Message_AirSyncBaseDelete'], + self::KEY_VALUES => [Horde_ActiveSync::AIRSYNCBASE_ATTACHMENT, Horde_ActiveSync::AIRSYNCBASE_ADD, Horde_ActiveSync::AIRSYNCBASE_DELETE], + ], + ]; + $this->_properties += [ 'location' => false, 'clientuid' => false, 'instanceid' => false, - 'airsyncbaseattachments' => array(), - ); + 'airsyncbaseattachments' => [], + ]; } } } @@ -276,8 +277,8 @@ public function __construct(array $options = array()) */ protected function _validateDecodedValues() { - if ($this->commandType == Horde_ActiveSync::SYNC_MODIFY && - $this->_version == Horde_ActiveSync::VERSION_SIXTEEN) { + if ($this->commandType == Horde_ActiveSync::SYNC_MODIFY + && $this->_version == Horde_ActiveSync::VERSION_SIXTEEN) { if ($this->_properties['alldayevent'] == true) { // Timezone element is forbidden here. @@ -288,22 +289,22 @@ protected function _validateDecodedValues() // No time components allowed here. The server is to interpret // the starttime as occuring on the date listed here regardless // of the timezone. - if ($this->_properties['starttime'] && - ($this->_properties['starttime']->hour != 0 || - $this->_properties['starttime']->min != 0 || - $this->_properties['starttime']->sec != 0)) { + if ($this->_properties['starttime'] + && ($this->_properties['starttime']->hour != 0 + || $this->_properties['starttime']->min != 0 + || $this->_properties['starttime']->sec != 0)) { return false; } - if ($this->_properties['endtime'] && - ($this->_properties['endtime']->hour != 0 || - $this->_properties['endtime']->min != 0 || - $this->_properties['endtime']->sec != 0)) { + if ($this->_properties['endtime'] + && ($this->_properties['endtime']->hour != 0 + || $this->_properties['endtime']->min != 0 + || $this->_properties['endtime']->sec != 0)) { return false; } - if ($this->_properties['recurrence'] && $this->_properties['recurrence']->until && - ($this->_properties['recurrence']->until != 0 || - $this->_properties['recurrence']->until != 0 || - $this->_properties['recurrence']->until != 0)) { + if ($this->_properties['recurrence'] && $this->_properties['recurrence']->until + && ($this->_properties['recurrence']->until != 0 + || $this->_properties['recurrence']->until != 0 + || $this->_properties['recurrence']->until != 0)) { return false; } } @@ -320,10 +321,10 @@ protected function _validateDecodedValues() // These values are not allowed in a EAS 16.0 command request. // @todo - should we just wipe the values instead of failing the test? if ($this->_version == Horde_ActiveSync::VERSION_SIXTEEN) { - if (!empty($this->_properties['uid']) || - !empty($this->_properties['dtstamp']) || - !empty($this->_properties['organizername']) || - !empty($this->_properties['organizeremail'])) { + if (!empty($this->_properties['uid']) + || !empty($this->_properties['dtstamp']) + || !empty($this->_properties['organizername']) + || !empty($this->_properties['organizeremail'])) { return false; } } @@ -342,15 +343,15 @@ protected function _validateDecodedValues() protected function _preEncodeValidation() { if ($this->_properties['alldayevent']) { - if ($this->_properties['starttime']->hour != 0 || - $this->_properties['starttime']->min != 0 || - $this->_properties['starttime']->sec != 0) { + if ($this->_properties['starttime']->hour != 0 + || $this->_properties['starttime']->min != 0 + || $this->_properties['starttime']->sec != 0) { return false; } - if ($this->_properties['endtime'] && - ($this->_properties['endtime']->hour != 0 || - $this->_properties['endtime']->min != 0 || - $this->_properties['endtime']->sec != 0)) { + if ($this->_properties['endtime'] + && ($this->_properties['endtime']->hour != 0 + || $this->_properties['endtime']->min != 0 + || $this->_properties['endtime']->sec != 0)) { return false; } @@ -394,7 +395,8 @@ public function setTimezone($date) if (!($date instanceof Horde_Date)) { if (!is_string($date)) { throw new InvalidArgumentException( - '$date must be an instance of Horde_Date or a valid timezone descriptor'); + '$date must be an instance of Horde_Date or a valid timezone descriptor' + ); } $date = new Horde_Date(time(), $date); } @@ -408,11 +410,11 @@ public function setTimezone($date) * * @return string The timezone identifier */ - public function getTimezone() - { - $parser = new Horde_Mapi_Timezone(); - return $parser->getTimezone($this->timezone, date_default_timezone_get()); - } + public function getTimezone() + { + $parser = new Horde_Mapi_Timezone(); + return $parser->getTimezone($this->timezone, date_default_timezone_get()); + } /** * Set the appointment's modify timestamp @@ -452,7 +454,7 @@ public function getDTStamp() * @throws InvalidArgumentException * @deprecated Set individual properties manually from calling code. */ - public function setDatetime(array $datetime = array()) + public function setDatetime(array $datetime = []) { // Start date is always required if (empty($datetime['start'])) { @@ -471,19 +473,20 @@ public function setDatetime(array $datetime = array()) } // Is this an all day event? - if ($start->hour == 0 && $start->min == 0 && $start->sec == 0 && - $end->hour == 23 && $end->min == 59) { + if ($start->hour == 0 && $start->min == 0 && $start->sec == 0 + && $end->hour == 23 && $end->min == 59) { // Yes, with end date ending on 23:59, bump up to 00:00 next day. $end = new Horde_Date( - array('year' => (int)$end->year, - 'month' => (int)$end->month, - 'mday' => (int)$end->mday + 1), - $end->timezone); + ['year' => (int) $end->year, + 'month' => (int) $end->month, + 'mday' => (int) $end->mday + 1], + $end->timezone + ); $this->_properties['alldayevent'] = self::IS_ALL_DAY; - } elseif ($start->hour == 0 && $start->min == 0 && $start->sec == 0 && - $end->hour == 0 && $end->min == 0 && $end->sec == 0 && - ($end->mday > $start->mday || $end->month > $start->month || - $end->year > $start->year)) { + } elseif ($start->hour == 0 && $start->min == 0 && $start->sec == 0 + && $end->hour == 0 && $end->min == 0 && $end->sec == 0 + && ($end->mday > $start->mday || $end->month > $start->month + || $end->year > $start->year)) { // Yes, can use values as-is. $this->_properties['alldayevent'] = self::IS_ALL_DAY; } elseif (!empty($datetime['allday'])) { @@ -491,10 +494,11 @@ public function setDatetime(array $datetime = array()) // start time is 00:00. $start->hour = $start->min = $start->sec = 0; $end = new Horde_Date( - array('year' => (int)$end->year, - 'month' => (int)$end->month, - 'mday' => (int)$end->mday + 1), - $end->timezone); + ['year' => (int) $end->year, + 'month' => (int) $end->month, + 'mday' => (int) $end->mday + 1], + $end->timezone + ); $this->_properties['alldayevent'] = self::IS_ALL_DAY; } $this->_properties['starttime'] = $start; @@ -513,11 +517,11 @@ public function setDatetime(array $datetime = array()) public function getDatetime() { $this->_checkDatetime(); - return array( + return [ 'start' => $this->_properties['starttime'], 'end' => $this->_properties['endtime'], - 'allday' => !empty($this->_properties['alldayevent']) ? true : false - ); + 'allday' => !empty($this->_properties['alldayevent']) ? true : false, + ]; } public function getStarttime() @@ -546,7 +550,7 @@ protected function _checkDatetime() $now = new Horde_Date(time()); $now->min = ($now->min > 0 && $now->min < 30) ? 30 : 60; $this->_properties['starttime'] = clone $now; - $now->add(array('min' => 30)); + $now->add(['min' => 30]); $this->_properties['endtime'] = clone $now; } else { throw new Horde_ActiveSync_Exception("Invalid dates"); @@ -556,7 +560,7 @@ protected function _checkDatetime() throw new Horde_ActiveSync_Exception("Invalid dates"); } $end = clone $this->_properties['starttime']; - $end->add(array('min' => 30)); + $end->add(['min' => 30]); $this->_properties['endtime'] = $end; } } @@ -654,9 +658,9 @@ public function setOrganizer(array $organizer) */ public function getOrganizer() { - return array( + return [ 'name' => $this->_getAttribute('organizername'), - 'email' => $this->_getAttribute('organizeremail')); + 'email' => $this->_getAttribute('organizeremail')]; } /** @@ -698,37 +702,37 @@ public function setRecurrence(Horde_Date_Recurrence $recurrence, $fdow = null) /* Map the type fields */ switch ($recurrence->recurType) { - case Horde_Date_Recurrence::RECUR_DAILY: - $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_DAILY; - break; - case Horde_Date_Recurrence::RECUR_WEEKLY: - $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_WEEKLY; - $r->dayofweek = $recurrence->getRecurOnDays(); - break; - case Horde_Date_Recurrence::RECUR_MONTHLY_DATE: - $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY; - break; - case Horde_Date_Recurrence::RECUR_MONTHLY_WEEKDAY; - $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY_NTH; - $r->weekofmonth = ceil($recurrence->start->mday / 7); - $r->dayofweek = $this->_dayOfWeekMap[$recurrence->start->dayOfWeek()]; - break; - case Horde_Date_Recurrence::RECUR_YEARLY_DATE: - $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_YEARLY; - $r->monthofyear = $recurrence->start->month; - $r->dayofmonth = $recurrence->start->mday; - break; - case Horde_Date_Recurrence::RECUR_YEARLY_DAY: - $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_YEARLYNTH; - $r->weekofmonth = ceil($recurrence->start->mday / 7); - $r->monthofyear = $recurrence->start->month; - break; - case Horde_Date_Recurrence::RECUR_YEARLY_WEEKDAY: - $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_YEARLYNTH; - $r->dayofweek = $this->_dayOfWeekMap[$recurrence->start->dayOfWeek()]; - $r->weekofmonth = ceil($recurrence->start->mday / 7); - $r->monthofyear = $recurrence->start->month; - break; + case Horde_Date_Recurrence::RECUR_DAILY: + $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_DAILY; + break; + case Horde_Date_Recurrence::RECUR_WEEKLY: + $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_WEEKLY; + $r->dayofweek = $recurrence->getRecurOnDays(); + break; + case Horde_Date_Recurrence::RECUR_MONTHLY_DATE: + $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY; + break; + case Horde_Date_Recurrence::RECUR_MONTHLY_WEEKDAY: + $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY_NTH; + $r->weekofmonth = ceil($recurrence->start->mday / 7); + $r->dayofweek = $this->_dayOfWeekMap[$recurrence->start->dayOfWeek()]; + break; + case Horde_Date_Recurrence::RECUR_YEARLY_DATE: + $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_YEARLY; + $r->monthofyear = $recurrence->start->month; + $r->dayofmonth = $recurrence->start->mday; + break; + case Horde_Date_Recurrence::RECUR_YEARLY_DAY: + $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_YEARLYNTH; + $r->weekofmonth = ceil($recurrence->start->mday / 7); + $r->monthofyear = $recurrence->start->month; + break; + case Horde_Date_Recurrence::RECUR_YEARLY_WEEKDAY: + $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_YEARLYNTH; + $r->dayofweek = $this->_dayOfWeekMap[$recurrence->start->dayOfWeek()]; + $r->weekofmonth = ceil($recurrence->start->mday / 7); + $r->monthofyear = $recurrence->start->month; + break; } if (!empty($recurrence->recurInterval)) { $r->interval = $recurrence->recurInterval; @@ -768,27 +772,27 @@ public function getRecurrence() /* Map MS AS type field to Horde_Date_Recurrence types */ switch ($recurrence->type) { - case Horde_ActiveSync_Message_Recurrence::TYPE_DAILY: - $rrule->setRecurType(Horde_Date_Recurrence::RECUR_DAILY); - break; - case Horde_ActiveSync_Message_Recurrence::TYPE_WEEKLY: - $rrule->setRecurType(Horde_Date_Recurrence::RECUR_WEEKLY); - $rrule->setRecurOnDay($recurrence->dayofweek); - break; - case Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY: - $rrule->setRecurType(Horde_Date_Recurrence::RECUR_MONTHLY_DATE); - break; - case Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY_NTH: - $rrule->setRecurType(Horde_Date_Recurrence::RECUR_MONTHLY_WEEKDAY); - $rrule->setRecurOnDay($recurrence->dayofweek); - break; - case Horde_ActiveSync_Message_Recurrence::TYPE_YEARLY: - $rrule->setRecurType(Horde_Date_Recurrence::RECUR_YEARLY_DATE); - break; - case Horde_ActiveSync_Message_Recurrence::TYPE_YEARLYNTH: - $rrule->setRecurType(Horde_Date_Recurrence::RECUR_YEARLY_WEEKDAY); - $rrule->setRecurOnDay($recurrence->dayofweek); - break; + case Horde_ActiveSync_Message_Recurrence::TYPE_DAILY: + $rrule->setRecurType(Horde_Date_Recurrence::RECUR_DAILY); + break; + case Horde_ActiveSync_Message_Recurrence::TYPE_WEEKLY: + $rrule->setRecurType(Horde_Date_Recurrence::RECUR_WEEKLY); + $rrule->setRecurOnDay($recurrence->dayofweek); + break; + case Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY: + $rrule->setRecurType(Horde_Date_Recurrence::RECUR_MONTHLY_DATE); + break; + case Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY_NTH: + $rrule->setRecurType(Horde_Date_Recurrence::RECUR_MONTHLY_WEEKDAY); + $rrule->setRecurOnDay($recurrence->dayofweek); + break; + case Horde_ActiveSync_Message_Recurrence::TYPE_YEARLY: + $rrule->setRecurType(Horde_Date_Recurrence::RECUR_YEARLY_DATE); + break; + case Horde_ActiveSync_Message_Recurrence::TYPE_YEARLYNTH: + $rrule->setRecurType(Horde_Date_Recurrence::RECUR_YEARLY_WEEKDAY); + $rrule->setRecurOnDay($recurrence->dayofweek); + break; } if ($rcnt = $recurrence->occurrences) { @@ -907,7 +911,7 @@ public function getResponseType() */ public function setReminder($minutes) { - $this->_properties['reminder'] = (int)$minutes; + $this->_properties['reminder'] = (int) $minutes; } /** @@ -1030,8 +1034,8 @@ public function addAttachment(Horde_ActiveSync_Message_AirSyncBaseAttachment $at */ public function isGhosted($property) { - if ($this->_version >= Horde_ActiveSync::VERSION_SIXTEEN && - empty($this->_exists[$property])) { + if ($this->_version >= Horde_ActiveSync::VERSION_SIXTEEN + && empty($this->_exists[$property])) { return true; } return parent::isGhosted($property); diff --git a/lib/Horde/ActiveSync/Message/Attachment.php b/lib/Horde/ActiveSync/Message/Attachment.php index 0b075505..dcfb9675 100644 --- a/lib/Horde/ActiveSync/Message/Attachment.php +++ b/lib/Horde/ActiveSync/Message/Attachment.php @@ -1,4 +1,5 @@ array (self::KEY_ATTRIBUTE => 'attmethod'), - self::POOMMAIL_ATTSIZE => array (self::KEY_ATTRIBUTE => 'attsize'), - self::POOMMAIL_DISPLAYNAME => array (self::KEY_ATTRIBUTE => 'displayname'), - self::POOMMAIL_ATTNAME => array (self::KEY_ATTRIBUTE => 'attname'), - self::POOMMAIL_ATTOID => array (self::KEY_ATTRIBUTE => 'attoid'), - self::POOMMAIL_ATTREMOVED => array (self::KEY_ATTRIBUTE => 'attremoved'), - ); + protected $_mapping = [ + self::POOMMAIL_ATTMETHOD => [self::KEY_ATTRIBUTE => 'attmethod'], + self::POOMMAIL_ATTSIZE => [self::KEY_ATTRIBUTE => 'attsize'], + self::POOMMAIL_DISPLAYNAME => [self::KEY_ATTRIBUTE => 'displayname'], + self::POOMMAIL_ATTNAME => [self::KEY_ATTRIBUTE => 'attname'], + self::POOMMAIL_ATTOID => [self::KEY_ATTRIBUTE => 'attoid'], + self::POOMMAIL_ATTREMOVED => [self::KEY_ATTRIBUTE => 'attremoved'], + ]; /** * Property values * * @var array */ - protected $_properties = array( + protected $_properties = [ 'attmethod' => false, 'attsize' => false, 'displayname' => false, 'attname' => false, 'attoid' => false, - 'attremoved' => false - ); + 'attremoved' => false, + ]; /** * Return the message type. diff --git a/lib/Horde/ActiveSync/Message/Attendee.php b/lib/Horde/ActiveSync/Message/Attendee.php index 54e2da55..9da67e96 100644 --- a/lib/Horde/ActiveSync/Message/Attendee.php +++ b/lib/Horde/ActiveSync/Message/Attendee.php @@ -1,4 +1,5 @@ array (self::KEY_ATTRIBUTE => 'email'), - Horde_ActiveSync_Message_Appointment::POOMCAL_NAME => array (self::KEY_ATTRIBUTE => 'name'), - Horde_ActiveSync_Message_Appointment::POOMCAL_ATTENDEESTATUS => array(self::KEY_ATTRIBUTE => 'status'), - Horde_ActiveSync_Message_Appointment::POOMCAL_ATTENDEETYPE => array(self::KEY_ATTRIBUTE => 'type') - ); + protected $_mapping = [ + Horde_ActiveSync_Message_Appointment::POOMCAL_EMAIL => [self::KEY_ATTRIBUTE => 'email'], + Horde_ActiveSync_Message_Appointment::POOMCAL_NAME => [self::KEY_ATTRIBUTE => 'name'], + Horde_ActiveSync_Message_Appointment::POOMCAL_ATTENDEESTATUS => [self::KEY_ATTRIBUTE => 'status'], + Horde_ActiveSync_Message_Appointment::POOMCAL_ATTENDEETYPE => [self::KEY_ATTRIBUTE => 'type'], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'email' => false, 'name' => false, 'status' => false, - 'type' => false - ); + 'type' => false, + ]; /** * Give concrete classes the chance to enforce rules on property values. @@ -78,8 +79,8 @@ class Horde_ActiveSync_Message_Attendee extends Horde_ActiveSync_Message_Base */ protected function _validateDecodedValues() { - if ($this->_version == Horde_ActiveSync::VERSION_SIXTEEN && - !empty($this->_properties['status'])) { + if ($this->_version == Horde_ActiveSync::VERSION_SIXTEEN + && !empty($this->_properties['status'])) { return false; } diff --git a/lib/Horde/ActiveSync/Message/Base.php b/lib/Horde/ActiveSync/Message/Base.php index bc8c4a53..a79eab31 100644 --- a/lib/Horde/ActiveSync/Message/Base.php +++ b/lib/Horde/ActiveSync/Message/Base.php @@ -1,4 +1,5 @@ _logger = Horde_ActiveSync::_wrapLogger($options['logger']); @@ -183,7 +184,8 @@ public function propertyExists($property) * @return mixed The value of the requested property. * @todo: to be used instead of accessor method */ - public function getProperty($property) { + public function getProperty($property) + { return $this->_getAttribute($property, false); } @@ -301,7 +303,7 @@ public function __isset($property) */ public function setSupported(array $fields) { - $this->_supported = array(); + $this->_supported = []; if (current($fields) == Horde_ActiveSync::ALL_GHOSTED) { $this->_supported = $fields; return; @@ -341,13 +343,13 @@ public function isGhosted($property) if (empty($this->_supported)) { return false; } - if (current($this->_supported) == Horde_ActiveSync::ALL_GHOSTED && - empty($this->_exists[$property])) { + if (current($this->_supported) == Horde_ActiveSync::ALL_GHOSTED + && empty($this->_exists[$property])) { return true; } - return array_search($property, $this->_supported) === false && - empty($this->_exists[$property]); + return array_search($property, $this->_supported) === false + && empty($this->_exists[$property]); } /** @@ -381,7 +383,7 @@ public function decodeStream(Horde_ActiveSync_Wbxml_Decoder &$decoder) if (!($entity[Horde_ActiveSync_Wbxml::EN_FLAGS] & Horde_ActiveSync_Wbxml::EN_FLAGS_CONTENT)) { $map = $this->_mapping[$entity[Horde_ActiveSync_Wbxml::EN_TAG]]; if (isset($map[self::KEY_VALUES])) { - $this->{$map[self::KEY_ATTRIBUTE]} = array(); + $this->{$map[self::KEY_ATTRIBUTE]} = []; } elseif (!isset($map[self::KEY_TYPE]) || $map[self::KEY_TYPE] == self::TYPE_DATE || $map[self::KEY_TYPE] == self::TYPE_DATE_DASHES) { $this->{$map[self::KEY_ATTRIBUTE]} = ''; } @@ -393,10 +395,12 @@ public function decodeStream(Horde_ActiveSync_Wbxml_Decoder &$decoder) // content types or empty tags. Otherwise fatal out, as it's a // protocol error. if (!isset($this->_mapping[$entity[Horde_ActiveSync_Wbxml::EN_TAG]])) { - $this->_logger->err(sprintf( - 'Tag %s unexpected in type XML type %s. Attempting to ignore unknown tag.', - $entity[Horde_ActiveSync_Wbxml::EN_TAG], - get_class($this)) + $this->_logger->err( + sprintf( + 'Tag %s unexpected in type XML type %s. Attempting to ignore unknown tag.', + $entity[Horde_ActiveSync_Wbxml::EN_TAG], + get_class($this) + ) ); // Empty? @@ -411,7 +415,7 @@ public function decodeStream(Horde_ActiveSync_Wbxml_Decoder &$decoder) $entity = $decoder->getToken(); if ($entity[Horde_ActiveSync_Wbxml::EN_TYPE] == Horde_ActiveSync_Wbxml::EN_TYPE_CONTENT) { $unknownContent = $decoder->getElementContent(); - while($unknownContent !== false) { + while ($unknownContent !== false) { $this->_logger->err('Content of unknown tag: %s', $unknownContent); $unknownContent = $decoder->getElementContent(); } @@ -442,8 +446,8 @@ public function decodeStream(Horde_ActiveSync_Wbxml_Decoder &$decoder) if ($token[Horde_ActiveSync_Wbxml_Decoder::EN_TYPE] == Horde_ActiveSync_Wbxml_Decoder::EN_TYPE_ENDTAG) { break; } - } elseif (!(isset($map[self::KEY_PROPERTY]) && $map[self::KEY_PROPERTY] == self::PROPERTY_NO_CONTAINER) && - !$decoder->getElementStartTag($map[self::KEY_VALUES])) { + } elseif (!(isset($map[self::KEY_PROPERTY]) && $map[self::KEY_PROPERTY] == self::PROPERTY_NO_CONTAINER) + && !$decoder->getElementStartTag($map[self::KEY_VALUES])) { break; } @@ -454,9 +458,10 @@ public function decodeStream(Horde_ActiveSync_Wbxml_Decoder &$decoder) $token = $decoder->getToken(); if (($idx = array_search($token[Horde_ActiveSync_Wbxml_Decoder::EN_TAG], $map[self::KEY_VALUES])) !== false) { $class = $map[self::KEY_TYPE][$idx]; - $decoded = new $class(array( - 'protocolversion' => $this->_version, - 'logger' => $this->_logger) + $decoded = new $class( + [ + 'protocolversion' => $this->_version, + 'logger' => $this->_logger] ); $decoded->commandType = $this->commandType; $decoded->decodeStream($decoder); @@ -465,9 +470,10 @@ public function decodeStream(Horde_ActiveSync_Wbxml_Decoder &$decoder) } } elseif (isset($map[self::KEY_TYPE])) { $class = $map[self::KEY_TYPE]; - $decoded = new $class(array( - 'protocolversion' => $this->_version, - 'logger' => $this->_logger) + $decoded = new $class( + [ + 'protocolversion' => $this->_version, + 'logger' => $this->_logger] ); $decoded->commandType = $this->commandType; $decoded->decodeStream($decoder); @@ -477,7 +483,7 @@ public function decodeStream(Horde_ActiveSync_Wbxml_Decoder &$decoder) // Assign the parsed value to the mapped attribute. if (!isset($this->{$map[self::KEY_ATTRIBUTE]})) { - $this->{$map[self::KEY_ATTRIBUTE]} = array($decoded); + $this->{$map[self::KEY_ATTRIBUTE]} = [$decoded]; } else { $this->{$map[self::KEY_ATTRIBUTE]}[] = $decoded; } @@ -505,23 +511,24 @@ public function decodeStream(Horde_ActiveSync_Wbxml_Decoder &$decoder) } // Do not get container end tag for an array without a container - if (!(isset($map[self::KEY_PROPERTY]) && $map[self::KEY_PROPERTY] == self::PROPERTY_NO_CONTAINER) && - !$decoder->getElementEndTag()) { + if (!(isset($map[self::KEY_PROPERTY]) && $map[self::KEY_PROPERTY] == self::PROPERTY_NO_CONTAINER) + && !$decoder->getElementEndTag()) { return false; } } else { // Handle a simple attribute value if (isset($map[self::KEY_TYPE])) { - if (in_array($map[self::KEY_TYPE], array(self::TYPE_DATE, self::TYPE_DATE_DASHES, self::TYPE_DATE_LOCAL))) { + if (in_array($map[self::KEY_TYPE], [self::TYPE_DATE, self::TYPE_DATE_DASHES, self::TYPE_DATE_LOCAL])) { $decoded = $this->_parseDate($decoder->getElementContent()); } elseif ($map[self::KEY_TYPE] == self::TYPE_HEX) { $decoded = self::_hex2bin($decoder->getElementContent()); } else { // Complex type, decode recursively $class = $map[self::KEY_TYPE]; - $subdecoder = new $class(array( - 'protocolversion' => $this->_version, - 'logger' => $this->_logger) + $subdecoder = new $class( + [ + 'protocolversion' => $this->_version, + 'logger' => $this->_logger] ); $subdecoder->commandType = $this->commandType; $subdecoder->decodeStream($decoder); @@ -532,16 +539,20 @@ public function decodeStream(Horde_ActiveSync_Wbxml_Decoder &$decoder) $decoded = $decoder->getElementContent(); if ($decoded === false) { $decoded = ''; - $this->_logger->notice(sprintf( - 'Unable to get expected content for %s: Setting to an empty string.', - $entity[Horde_ActiveSync_Wbxml::EN_TAG]) + $this->_logger->notice( + sprintf( + 'Unable to get expected content for %s: Setting to an empty string.', + $entity[Horde_ActiveSync_Wbxml::EN_TAG] + ) ); } } if (!$decoder->getElementEndTag()) { - $this->_logger->err(sprintf( - 'Unable to get end tag for %s.', - $entity[Horde_ActiveSync_Wbxml::EN_TAG]) + $this->_logger->err( + sprintf( + 'Unable to get end tag for %s.', + $entity[Horde_ActiveSync_Wbxml::EN_TAG] + ) ); throw new Horde_ActiveSync_Exception('Missing expected wbxml end tag'); } @@ -550,9 +561,11 @@ public function decodeStream(Horde_ActiveSync_Wbxml_Decoder &$decoder) } if (!$this->_validateDecodedValues()) { - throw new Horde_ActiveSync_Exception(sprintf( - 'Invalid values detected in %s.', - get_class($this)) + throw new Horde_ActiveSync_Exception( + sprintf( + 'Invalid values detected in %s.', + get_class($this) + ) ); } } @@ -567,13 +580,17 @@ public function decodeStream(Horde_ActiveSync_Wbxml_Decoder &$decoder) public function encodeStream(Horde_ActiveSync_Wbxml_Encoder &$encoder) { if (!$this->_preEncodeValidation()) { - $this->_logger->err(sprintf( - 'Pre-encoding validation failed for %s item', - get_class($this)) + $this->_logger->err( + sprintf( + 'Pre-encoding validation failed for %s item', + get_class($this) + ) ); - throw new Horde_ActiveSync_Exception(sprintf( - 'Pre-encoding validation failed for %s item', - get_class($this)) + throw new Horde_ActiveSync_Exception( + sprintf( + 'Pre-encoding validation failed for %s item', + get_class($this) + ) ); } @@ -583,19 +600,19 @@ public function encodeStream(Horde_ActiveSync_Wbxml_Encoder &$encoder) } // Variable is available - if (is_object($this->{$map[self::KEY_ATTRIBUTE]}) && - !($this->{$map[self::KEY_ATTRIBUTE]} instanceof Horde_Date)) { + if (is_object($this->{$map[self::KEY_ATTRIBUTE]}) + && !($this->{$map[self::KEY_ATTRIBUTE]} instanceof Horde_Date)) { // Objects can do their own encoding $encoder->startTag($tag); $this->{$map[self::KEY_ATTRIBUTE]}->encodeStream($encoder); $encoder->endTag(); - } elseif (isset($map[self::KEY_VALUES]) && - is_array($this->{$map[self::KEY_ATTRIBUTE]})) { + } elseif (isset($map[self::KEY_VALUES]) + && is_array($this->{$map[self::KEY_ATTRIBUTE]})) { // Array of objects. Note that some array values must be // sent as an empty tag if they contain no elements. if (count($this->{$map[self::KEY_ATTRIBUTE]})) { - if (!isset($map[self::KEY_PROPERTY]) || - $map[self::KEY_PROPERTY] != self::PROPERTY_NO_CONTAINER) { + if (!isset($map[self::KEY_PROPERTY]) + || $map[self::KEY_PROPERTY] != self::PROPERTY_NO_CONTAINER) { $encoder->startTag($tag); } foreach ($this->{$map[self::KEY_ATTRIBUTE]} as $element) { @@ -613,7 +630,7 @@ public function encodeStream(Horde_ActiveSync_Wbxml_Encoder &$encoder) $encoder->endTag(); } else { // Do not ever output empty items here - if(strlen($element) > 0) { + if (strlen($element) > 0) { $encoder->startTag($map[self::KEY_VALUES]); $encoder->content($element); $encoder->endTag(); @@ -628,23 +645,25 @@ public function encodeStream(Horde_ActiveSync_Wbxml_Encoder &$encoder) } } else { // Simple type - if (!is_resource($this->{$map[self::KEY_ATTRIBUTE]}) && - strlen($this->{$map[self::KEY_ATTRIBUTE]}) == 0) { - // Do not output empty items except for the following: - if ($this->_checkSendEmpty($tag)) { - $encoder->startTag($tag, $this->{$map[self::KEY_ATTRIBUTE]}, true); - } - continue; - } elseif ($encoder->multipart && - in_array($tag, array( - Horde_ActiveSync::SYNC_DATA, - Horde_ActiveSync::AIRSYNCBASE_DATA, - Horde_ActiveSync_Request_ItemOperations::ITEMOPERATIONS_DATA) + if (!is_resource($this->{$map[self::KEY_ATTRIBUTE]}) + && strlen($this->{$map[self::KEY_ATTRIBUTE]}) == 0) { + // Do not output empty items except for the following: + if ($this->_checkSendEmpty($tag)) { + $encoder->startTag($tag, $this->{$map[self::KEY_ATTRIBUTE]}, true); + } + continue; + } elseif ($encoder->multipart + && in_array( + $tag, + [ + Horde_ActiveSync::SYNC_DATA, + Horde_ActiveSync::AIRSYNCBASE_DATA, + Horde_ActiveSync_Request_ItemOperations::ITEMOPERATIONS_DATA] )) { $this->_logger->meta('HANDLING MULTIPART OUTPUT'); $encoder->addPart($this->{$map[self::KEY_ATTRIBUTE]}); $encoder->startTag(Horde_ActiveSync_Request_ItemOperations::ITEMOPERATIONS_PART); - $encoder->content((string)(count($encoder->getParts()) - 1)); + $encoder->content((string) (count($encoder->getParts()) - 1)); $encoder->endTag(); continue; } @@ -652,8 +671,8 @@ public function encodeStream(Horde_ActiveSync_Wbxml_Encoder &$encoder) $encoder->startTag($tag); if (isset($map[self::KEY_TYPE]) && $map[self::KEY_TYPE] == 'opaque') { $encoder->content($this->{$map[self::KEY_ATTRIBUTE]}, true); - } elseif (isset($map[self::KEY_TYPE]) && - (in_array($map[self::KEY_TYPE], array(self::TYPE_DATE, self::TYPE_DATE_DASHES, self::TYPE_DATE_LOCAL)))) { + } elseif (isset($map[self::KEY_TYPE]) + && (in_array($map[self::KEY_TYPE], [self::TYPE_DATE, self::TYPE_DATE_DASHES, self::TYPE_DATE_LOCAL]))) { if (!empty($this->{$map[self::KEY_ATTRIBUTE]})) { // don't output 1-1-1970 $encoder->content($this->_formatDate($this->{$map[self::KEY_ATTRIBUTE]}, $map[self::KEY_TYPE])); } @@ -663,7 +682,8 @@ public function encodeStream(Horde_ActiveSync_Wbxml_Encoder &$encoder) $encoder->content($this->{$map[self::KEY_ATTRIBUTE]}); } else { $encoder->content( - $this->_checkEncoding($this->{$map[self::KEY_ATTRIBUTE]}, $tag)); + $this->_checkEncoding($this->{$map[self::KEY_ATTRIBUTE]}, $tag) + ); } $encoder->endTag(); } @@ -757,14 +777,14 @@ public function isEmpty() protected function _formatDate(Horde_Date $dt, $type) { switch ($type) { - case self::TYPE_DATE: - return $dt->setTimezone('UTC')->format('Ymd\THis\Z'); - case self::TYPE_DATE_DASHES: - return $dt->setTimezone('UTC')->format('Y-m-d\TH:i:s\.000\Z'); - case self::TYPE_DATE_LOCAL: - return $dt->format('Y-m-d\TH:i:s\.000\Z'); - default: - throw new InvalidArgumentException('Unidentified DATE_TYPE'); + case self::TYPE_DATE: + return $dt->setTimezone('UTC')->format('Ymd\THis\Z'); + case self::TYPE_DATE_DASHES: + return $dt->setTimezone('UTC')->format('Y-m-d\TH:i:s\.000\Z'); + case self::TYPE_DATE_LOCAL: + return $dt->format('Y-m-d\TH:i:s\.000\Z'); + default: + throw new InvalidArgumentException('Unidentified DATE_TYPE'); } } diff --git a/lib/Horde/ActiveSync/Message/Contact.php b/lib/Horde/ActiveSync/Message/Contact.php index 74e9db46..f693b281 100644 --- a/lib/Horde/ActiveSync/Message/Contact.php +++ b/lib/Horde/ActiveSync/Message/Contact.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'anniversary', self::KEY_TYPE => self::TYPE_DATE_DASHES), - self::BIRTHDAY => array(self::KEY_ATTRIBUTE => 'birthday', self::KEY_TYPE => self::TYPE_DATE_DASHES), - self::WEBPAGE => array(self::KEY_ATTRIBUTE => 'webpage'), - self::CHILDREN => array(self::KEY_ATTRIBUTE => 'children', self::KEY_VALUES => self::CHILD), - self::BUSINESSCOUNTRY => array(self::KEY_ATTRIBUTE => 'businesscountry'), - self::DEPARTMENT => array(self::KEY_ATTRIBUTE => 'department'), - self::EMAIL1ADDRESS => array(self::KEY_ATTRIBUTE => 'email1address'), - self::EMAIL2ADDRESS => array(self::KEY_ATTRIBUTE => 'email2address'), - self::EMAIL3ADDRESS => array(self::KEY_ATTRIBUTE => 'email3address'), - self::BUSINESSFAXNUMBER => array(self::KEY_ATTRIBUTE => 'businessfaxnumber'), - self::FILEAS => array(self::KEY_ATTRIBUTE => 'fileas'), - self::FIRSTNAME => array(self::KEY_ATTRIBUTE => 'firstname'), - self::HOMECITY => array(self::KEY_ATTRIBUTE => 'homecity'), - self::HOMECOUNTRY => array(self::KEY_ATTRIBUTE => 'homecountry'), - self::HOMEFAXNUMBER => array(self::KEY_ATTRIBUTE => 'homefaxnumber'), - self::HOMEPHONENUMBER => array(self::KEY_ATTRIBUTE => 'homephonenumber'), - self::HOME2PHONENUMBER => array(self::KEY_ATTRIBUTE => 'home2phonenumber'), - self::HOMEPOSTALCODE => array(self::KEY_ATTRIBUTE => 'homepostalcode'), - self::HOMESTATE => array(self::KEY_ATTRIBUTE => 'homestate'), - self::HOMESTREET => array(self::KEY_ATTRIBUTE => 'homestreet'), - self::BUSINESSCITY => array(self::KEY_ATTRIBUTE => 'businesscity'), - self::MIDDLENAME => array(self::KEY_ATTRIBUTE => 'middlename'), - self::MOBILEPHONENUMBER => array(self::KEY_ATTRIBUTE => 'mobilephonenumber'), - self::SUFFIX => array(self::KEY_ATTRIBUTE => 'suffix'), - self::COMPANYNAME => array(self::KEY_ATTRIBUTE => 'companyname'), - self::OTHERCITY => array(self::KEY_ATTRIBUTE => 'othercity'), - self::OTHERCOUNTRY => array(self::KEY_ATTRIBUTE => 'othercountry'), - self::CARPHONENUMBER => array(self::KEY_ATTRIBUTE => 'carphonenumber'), - self::OTHERPOSTALCODE => array(self::KEY_ATTRIBUTE => 'otherpostalcode'), - self::OTHERSTATE => array(self::KEY_ATTRIBUTE => 'otherstate'), - self::OTHERSTREET => array(self::KEY_ATTRIBUTE => 'otherstreet'), - self::PAGERNUMBER => array(self::KEY_ATTRIBUTE => 'pagernumber'), - self::TITLE => array(self::KEY_ATTRIBUTE => 'title'), - self::BUSINESSPOSTALCODE => array(self::KEY_ATTRIBUTE => 'businesspostalcode'), - self::ASSISTANTNAME => array(self::KEY_ATTRIBUTE => 'assistantname'), - self::ASSISTNAMEPHONENUMBER => array(self::KEY_ATTRIBUTE => 'assistnamephonenumber'), - self::LASTNAME => array(self::KEY_ATTRIBUTE => 'lastname'), - self::SPOUSE => array(self::KEY_ATTRIBUTE => 'spouse'), - self::BUSINESSSTATE => array(self::KEY_ATTRIBUTE => 'businessstate'), - self::BUSINESSSTREET => array(self::KEY_ATTRIBUTE => 'businessstreet'), - self::BUSINESSPHONENUMBER => array(self::KEY_ATTRIBUTE => 'businessphonenumber'), - self::BUSINESS2PHONENUMBER => array(self::KEY_ATTRIBUTE => 'business2phonenumber'), - self::JOBTITLE => array(self::KEY_ATTRIBUTE => 'jobtitle'), - self::YOMIFIRSTNAME => array(self::KEY_ATTRIBUTE => 'yomifirstname'), - self::YOMILASTNAME => array(self::KEY_ATTRIBUTE => 'yomilastname'), - self::YOMICOMPANYNAME => array(self::KEY_ATTRIBUTE => 'yomicompanyname'), - self::OFFICELOCATION => array(self::KEY_ATTRIBUTE => 'officelocation'), - self::RADIOPHONENUMBER => array(self::KEY_ATTRIBUTE => 'radiophonenumber'), - self::CATEGORIES => array(self::KEY_ATTRIBUTE => 'categories', self::KEY_VALUES => self::CATEGORY), - self::PICTURE => array(self::KEY_ATTRIBUTE => 'picture'), + protected $_mapping = [ + self::ANNIVERSARY => [self::KEY_ATTRIBUTE => 'anniversary', self::KEY_TYPE => self::TYPE_DATE_DASHES], + self::BIRTHDAY => [self::KEY_ATTRIBUTE => 'birthday', self::KEY_TYPE => self::TYPE_DATE_DASHES], + self::WEBPAGE => [self::KEY_ATTRIBUTE => 'webpage'], + self::CHILDREN => [self::KEY_ATTRIBUTE => 'children', self::KEY_VALUES => self::CHILD], + self::BUSINESSCOUNTRY => [self::KEY_ATTRIBUTE => 'businesscountry'], + self::DEPARTMENT => [self::KEY_ATTRIBUTE => 'department'], + self::EMAIL1ADDRESS => [self::KEY_ATTRIBUTE => 'email1address'], + self::EMAIL2ADDRESS => [self::KEY_ATTRIBUTE => 'email2address'], + self::EMAIL3ADDRESS => [self::KEY_ATTRIBUTE => 'email3address'], + self::BUSINESSFAXNUMBER => [self::KEY_ATTRIBUTE => 'businessfaxnumber'], + self::FILEAS => [self::KEY_ATTRIBUTE => 'fileas'], + self::FIRSTNAME => [self::KEY_ATTRIBUTE => 'firstname'], + self::HOMECITY => [self::KEY_ATTRIBUTE => 'homecity'], + self::HOMECOUNTRY => [self::KEY_ATTRIBUTE => 'homecountry'], + self::HOMEFAXNUMBER => [self::KEY_ATTRIBUTE => 'homefaxnumber'], + self::HOMEPHONENUMBER => [self::KEY_ATTRIBUTE => 'homephonenumber'], + self::HOME2PHONENUMBER => [self::KEY_ATTRIBUTE => 'home2phonenumber'], + self::HOMEPOSTALCODE => [self::KEY_ATTRIBUTE => 'homepostalcode'], + self::HOMESTATE => [self::KEY_ATTRIBUTE => 'homestate'], + self::HOMESTREET => [self::KEY_ATTRIBUTE => 'homestreet'], + self::BUSINESSCITY => [self::KEY_ATTRIBUTE => 'businesscity'], + self::MIDDLENAME => [self::KEY_ATTRIBUTE => 'middlename'], + self::MOBILEPHONENUMBER => [self::KEY_ATTRIBUTE => 'mobilephonenumber'], + self::SUFFIX => [self::KEY_ATTRIBUTE => 'suffix'], + self::COMPANYNAME => [self::KEY_ATTRIBUTE => 'companyname'], + self::OTHERCITY => [self::KEY_ATTRIBUTE => 'othercity'], + self::OTHERCOUNTRY => [self::KEY_ATTRIBUTE => 'othercountry'], + self::CARPHONENUMBER => [self::KEY_ATTRIBUTE => 'carphonenumber'], + self::OTHERPOSTALCODE => [self::KEY_ATTRIBUTE => 'otherpostalcode'], + self::OTHERSTATE => [self::KEY_ATTRIBUTE => 'otherstate'], + self::OTHERSTREET => [self::KEY_ATTRIBUTE => 'otherstreet'], + self::PAGERNUMBER => [self::KEY_ATTRIBUTE => 'pagernumber'], + self::TITLE => [self::KEY_ATTRIBUTE => 'title'], + self::BUSINESSPOSTALCODE => [self::KEY_ATTRIBUTE => 'businesspostalcode'], + self::ASSISTANTNAME => [self::KEY_ATTRIBUTE => 'assistantname'], + self::ASSISTNAMEPHONENUMBER => [self::KEY_ATTRIBUTE => 'assistnamephonenumber'], + self::LASTNAME => [self::KEY_ATTRIBUTE => 'lastname'], + self::SPOUSE => [self::KEY_ATTRIBUTE => 'spouse'], + self::BUSINESSSTATE => [self::KEY_ATTRIBUTE => 'businessstate'], + self::BUSINESSSTREET => [self::KEY_ATTRIBUTE => 'businessstreet'], + self::BUSINESSPHONENUMBER => [self::KEY_ATTRIBUTE => 'businessphonenumber'], + self::BUSINESS2PHONENUMBER => [self::KEY_ATTRIBUTE => 'business2phonenumber'], + self::JOBTITLE => [self::KEY_ATTRIBUTE => 'jobtitle'], + self::YOMIFIRSTNAME => [self::KEY_ATTRIBUTE => 'yomifirstname'], + self::YOMILASTNAME => [self::KEY_ATTRIBUTE => 'yomilastname'], + self::YOMICOMPANYNAME => [self::KEY_ATTRIBUTE => 'yomicompanyname'], + self::OFFICELOCATION => [self::KEY_ATTRIBUTE => 'officelocation'], + self::RADIOPHONENUMBER => [self::KEY_ATTRIBUTE => 'radiophonenumber'], + self::CATEGORIES => [self::KEY_ATTRIBUTE => 'categories', self::KEY_VALUES => self::CATEGORY], + self::PICTURE => [self::KEY_ATTRIBUTE => 'picture'], // POOMCONTACTS2 - self::CUSTOMERID => array(self::KEY_ATTRIBUTE => 'customerid'), - self::GOVERNMENTID => array(self::KEY_ATTRIBUTE => 'governmentid'), - self::IMADDRESS => array(self::KEY_ATTRIBUTE => 'imaddress'), - self::IMADDRESS2 => array(self::KEY_ATTRIBUTE => 'imaddress2'), - self::IMADDRESS3 => array(self::KEY_ATTRIBUTE => 'imaddress3'), - self::MANAGERNAME => array(self::KEY_ATTRIBUTE => 'managername'), - self::COMPANYMAINPHONE => array(self::KEY_ATTRIBUTE => 'companymainphone'), - self::ACCOUNTNAME => array(self::KEY_ATTRIBUTE => 'accountname'), - self::NICKNAME => array(self::KEY_ATTRIBUTE => 'nickname'), - self::MMS => array(self::KEY_ATTRIBUTE => 'mms'), - ); + self::CUSTOMERID => [self::KEY_ATTRIBUTE => 'customerid'], + self::GOVERNMENTID => [self::KEY_ATTRIBUTE => 'governmentid'], + self::IMADDRESS => [self::KEY_ATTRIBUTE => 'imaddress'], + self::IMADDRESS2 => [self::KEY_ATTRIBUTE => 'imaddress2'], + self::IMADDRESS3 => [self::KEY_ATTRIBUTE => 'imaddress3'], + self::MANAGERNAME => [self::KEY_ATTRIBUTE => 'managername'], + self::COMPANYMAINPHONE => [self::KEY_ATTRIBUTE => 'companymainphone'], + self::ACCOUNTNAME => [self::KEY_ATTRIBUTE => 'accountname'], + self::NICKNAME => [self::KEY_ATTRIBUTE => 'nickname'], + self::MMS => [self::KEY_ATTRIBUTE => 'mms'], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'anniversary' => false, 'assistantname' => false, 'assistnamephonenumber' => false, @@ -263,7 +264,7 @@ class Horde_ActiveSync_Message_Contact extends Horde_ActiveSync_Message_Base 'businessfaxnumber' => false, 'businessphonenumber' => false, 'carphonenumber' => false, - 'children' => array(), + 'children' => [], 'companyname' => false, 'department' => false, 'email1address' => false, @@ -312,46 +313,46 @@ class Horde_ActiveSync_Message_Contact extends Horde_ActiveSync_Message_Base 'accountname' => false, 'nickname' => false, 'mms' => false, - ); + ]; /** * Const'r * * @see Horde_ActiveSync_Message_Base::__construct() */ - public function __construct(array $options = array()) + public function __construct(array $options = []) { parent::__construct($options); if ($this->_version < Horde_ActiveSync::VERSION_TWELVE) { - $this->_mapping += array( - self::BODY => array(self::KEY_ATTRIBUTE => 'body'), - self::BODYSIZE => array(self::KEY_ATTRIBUTE => 'bodysize'), - self::BODYTRUNCATED => array(self::KEY_ATTRIBUTE => 'bodytruncated'), - self::RTF => array(self::KEY_ATTRIBUTE => 'rtf'), - ); + $this->_mapping += [ + self::BODY => [self::KEY_ATTRIBUTE => 'body'], + self::BODYSIZE => [self::KEY_ATTRIBUTE => 'bodysize'], + self::BODYTRUNCATED => [self::KEY_ATTRIBUTE => 'bodytruncated'], + self::RTF => [self::KEY_ATTRIBUTE => 'rtf'], + ]; - $this->_properties += array( + $this->_properties += [ 'body' => false, 'bodysize' => false, 'bodytruncated' => 0, - 'rtf' => false - ); + 'rtf' => false, + ]; } else { - $this->_mapping += array( - Horde_ActiveSync::AIRSYNCBASE_BODY => array(self::KEY_ATTRIBUTE => 'airsyncbasebody', self::KEY_TYPE => 'Horde_ActiveSync_Message_AirSyncBaseBody') - ); - $this->_properties += array( - 'airsyncbasebody' => false - ); + $this->_mapping += [ + Horde_ActiveSync::AIRSYNCBASE_BODY => [self::KEY_ATTRIBUTE => 'airsyncbasebody', self::KEY_TYPE => 'Horde_ActiveSync_Message_AirSyncBaseBody'], + ]; + $this->_properties += [ + 'airsyncbasebody' => false, + ]; if ($this->_version > Horde_ActiveSync::VERSION_TWELVEONE) { - $this->_mapping += array( - self::ALIAS => array(self::KEY_ATTRIBUTE => 'alias'), - self::WEIGHTEDRANK => array(self::KEY_ATTRIBUTE => 'weightedrank') - ); - $this->_properties += array( + $this->_mapping += [ + self::ALIAS => [self::KEY_ATTRIBUTE => 'alias'], + self::WEIGHTEDRANK => [self::KEY_ATTRIBUTE => 'weightedrank'], + ]; + $this->_properties += [ 'alias' => false, - 'weightedrank' => false - ); + 'weightedrank' => false, + ]; } } } @@ -443,7 +444,7 @@ protected function _formatDate(Horde_Date $dt, $type) * * @return boolean */ - public function isGhosted($property, $options = array()) + public function isGhosted($property, $options = []) { // MS-ASCMD 2.2.3.168: // An empty SUPPORTED container indicates that ALL elements able to be @@ -453,16 +454,16 @@ public function isGhosted($property, $options = array()) // any SUPPORTED container and also not sending the picture field during // edits. if ($property == $this->_mapping[self::PICTURE][self::KEY_ATTRIBUTE]) { - if (empty($options['ignoreEmptyPictureTagCheck']) && - $this->_device->hasQuirk(Horde_ActiveSync_Device::QUIRK_INCORRECTLY_SENDS_EMPTY_PICTURE_TAG) && - ((!empty($this->_exists[$property]) && - $this->{$property} == '') || empty($this->_exists[$property]))) { + if (empty($options['ignoreEmptyPictureTagCheck']) + && $this->_device->hasQuirk(Horde_ActiveSync_Device::QUIRK_INCORRECTLY_SENDS_EMPTY_PICTURE_TAG) + && ((!empty($this->_exists[$property]) + && $this->{$property} == '') || empty($this->_exists[$property]))) { return true; } - if (empty($this->_exists[$property]) && - empty($this->_supported) && - $this->_device->hasQuirk(Horde_ActiveSync_Device::QUIRK_NEEDS_SUPPORTED_PICTURE_TAG)) { + if (empty($this->_exists[$property]) + && empty($this->_supported) + && $this->_device->hasQuirk(Horde_ActiveSync_Device::QUIRK_NEEDS_SUPPORTED_PICTURE_TAG)) { return true; } } diff --git a/lib/Horde/ActiveSync/Message/DeviceInformation.php b/lib/Horde/ActiveSync/Message/DeviceInformation.php index 0c3e507a..236962ea 100644 --- a/lib/Horde/ActiveSync/Message/DeviceInformation.php +++ b/lib/Horde/ActiveSync/Message/DeviceInformation.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'model'), - Horde_ActiveSync_Request_Settings::SETTINGS_IMEI => array(self::KEY_ATTRIBUTE => 'imei'), - Horde_ActiveSync_Request_Settings::SETTINGS_FRIENDLYNAME => array(self::KEY_ATTRIBUTE => 'friendlyname'), - Horde_ActiveSync_Request_Settings::SETTINGS_OS => array(self::KEY_ATTRIBUTE => 'os'), - Horde_ActiveSync_Request_Settings::SETTINGS_OSLANGUAGE => array(self::KEY_ATTRIBUTE => 'oslanguage'), - Horde_ActiveSync_Request_Settings::SETTINGS_PHONENUMBER => array(self::KEY_ATTRIBUTE => 'phonenumber'), - Horde_ActiveSync_Request_Settings::SETTINGS_USERAGENT => array(self::KEY_ATTRIBUTE => 'useragent'), - Horde_ActiveSync_Request_Settings::SETTINGS_MOBILEOPERATOR => array(self::KEY_ATTRIBUTE => 'mobileoperator'), - Horde_ActiveSync_Request_Settings::SETTINGS_ENABLEOUTBOUNDSMS => array(self::KEY_ATTRIBUTE => 'enableoutboundsms') - ); + protected $_mapping = [ + Horde_ActiveSync_Request_Settings::SETTINGS_MODEL => [self::KEY_ATTRIBUTE => 'model'], + Horde_ActiveSync_Request_Settings::SETTINGS_IMEI => [self::KEY_ATTRIBUTE => 'imei'], + Horde_ActiveSync_Request_Settings::SETTINGS_FRIENDLYNAME => [self::KEY_ATTRIBUTE => 'friendlyname'], + Horde_ActiveSync_Request_Settings::SETTINGS_OS => [self::KEY_ATTRIBUTE => 'os'], + Horde_ActiveSync_Request_Settings::SETTINGS_OSLANGUAGE => [self::KEY_ATTRIBUTE => 'oslanguage'], + Horde_ActiveSync_Request_Settings::SETTINGS_PHONENUMBER => [self::KEY_ATTRIBUTE => 'phonenumber'], + Horde_ActiveSync_Request_Settings::SETTINGS_USERAGENT => [self::KEY_ATTRIBUTE => 'useragent'], + Horde_ActiveSync_Request_Settings::SETTINGS_MOBILEOPERATOR => [self::KEY_ATTRIBUTE => 'mobileoperator'], + Horde_ActiveSync_Request_Settings::SETTINGS_ENABLEOUTBOUNDSMS => [self::KEY_ATTRIBUTE => 'enableoutboundsms'], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'model' => false, 'imei' => false, 'friendlyname' => false, @@ -63,7 +63,7 @@ class Horde_ActiveSync_Message_DeviceInformation extends Horde_ActiveSync_Messag 'phonenumber' => false, 'useragent' => false, 'mobileoperator' => false, - 'enableoutboundsms' => false - ); + 'enableoutboundsms' => false, + ]; } diff --git a/lib/Horde/ActiveSync/Message/Document.php b/lib/Horde/ActiveSync/Message/Document.php index 7c679639..5712accd 100644 --- a/lib/Horde/ActiveSync/Message/Document.php +++ b/lib/Horde/ActiveSync/Message/Document.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'range'), - Horde_ActiveSync_Request_ItemOperations::ITEMOPERATIONS_TOTAL => array(self::KEY_ATTRIBUTE => 'total'), - Horde_ActiveSync_Request_ItemOperations::ITEMOPERATIONS_DATA => array(self::KEY_ATTRIBUTE => 'data'), - Horde_ActiveSync_Request_ItemOperations::ITEMOPERATIONS_VERSION => array(self::KEY_ATTRIBUTE => 'version', self::KEY_TYPE => self::TYPE_DATE), - ); + protected $_mapping = [ + Horde_ActiveSync_Request_ItemOperations::ITEMOPERATIONS_RANGE => [self::KEY_ATTRIBUTE => 'range'], + Horde_ActiveSync_Request_ItemOperations::ITEMOPERATIONS_TOTAL => [self::KEY_ATTRIBUTE => 'total'], + Horde_ActiveSync_Request_ItemOperations::ITEMOPERATIONS_DATA => [self::KEY_ATTRIBUTE => 'data'], + Horde_ActiveSync_Request_ItemOperations::ITEMOPERATIONS_VERSION => [self::KEY_ATTRIBUTE => 'version', self::KEY_TYPE => self::TYPE_DATE], + ]; /** * Property values * * @var array */ - protected $_properties = array( + protected $_properties = [ 'range' => false, 'total' => false, 'data' => false, - 'version' => false - ); + 'version' => false, + ]; } diff --git a/lib/Horde/ActiveSync/Message/DocumentLibrary.php b/lib/Horde/ActiveSync/Message/DocumentLibrary.php index 04f751af..b0d2c244 100644 --- a/lib/Horde/ActiveSync/Message/DocumentLibrary.php +++ b/lib/Horde/ActiveSync/Message/DocumentLibrary.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'linkid'), - Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_DISPLAYNAME => array(self::KEY_ATTRIBUTE => 'displayname'), - Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_ISFOLDER => array(self::KEY_ATTRIBUTE => 'isfolder'), - Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_CREATIONDATE => array(self::KEY_ATTRIBUTE => 'creationdate', self::KEY_TYPE => self::TYPE_DATE_DASHES), - Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_LASTMODIFIEDDATE => array(self::KEY_ATTRIBUTE => 'lastmodifieddate', self::KEY_TYPE => self::TYPE_DATE_DASHES), - Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_ISHIDDEN => array(self::KEY_ATTRIBUTE => 'ishidden'), - Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_CONTENTLENGTH => array(self::KEY_ATTRIBUTE => 'contentlength'), - Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_CONTENTTYPE => array(self::KEY_ATTRIBUTE => 'contenttype') - ); + protected $_mapping = [ + Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_LINKID => [self::KEY_ATTRIBUTE => 'linkid'], + Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_DISPLAYNAME => [self::KEY_ATTRIBUTE => 'displayname'], + Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_ISFOLDER => [self::KEY_ATTRIBUTE => 'isfolder'], + Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_CREATIONDATE => [self::KEY_ATTRIBUTE => 'creationdate', self::KEY_TYPE => self::TYPE_DATE_DASHES], + Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_LASTMODIFIEDDATE => [self::KEY_ATTRIBUTE => 'lastmodifieddate', self::KEY_TYPE => self::TYPE_DATE_DASHES], + Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_ISHIDDEN => [self::KEY_ATTRIBUTE => 'ishidden'], + Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_CONTENTLENGTH => [self::KEY_ATTRIBUTE => 'contentlength'], + Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_CONTENTTYPE => [self::KEY_ATTRIBUTE => 'contenttype'], + ]; /** * Property values * * @var array */ - protected $_properties = array( + protected $_properties = [ 'linkid' => false, 'displayname' => false, 'isfolder' => false, @@ -51,7 +51,7 @@ class Horde_ActiveSync_Message_DocumentLibrary extends Horde_ActiveSync_Message_ 'lastmodifieddate' => false, 'ishidden' => false, 'contentlength' => false, - 'contenttype' => 'application/octet-stream' - ); + 'contenttype' => 'application/octet-stream', + ]; } diff --git a/lib/Horde/ActiveSync/Message/Exception.php b/lib/Horde/ActiveSync/Message/Exception.php index a805eedb..f544c998 100644 --- a/lib/Horde/ActiveSync/Message/Exception.php +++ b/lib/Horde/ActiveSync/Message/Exception.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'timezone'), - Horde_ActiveSync_Message_Appointment::POOMCAL_DTSTAMP => array(self::KEY_ATTRIBUTE => 'dtstamp', self::KEY_TYPE => self::TYPE_DATE), - Horde_ActiveSync_Message_Appointment::POOMCAL_STARTTIME => array(self::KEY_ATTRIBUTE => 'starttime', self::KEY_TYPE => self::TYPE_DATE), - Horde_ActiveSync_Message_Appointment::POOMCAL_SUBJECT => array(self::KEY_ATTRIBUTE => 'subject'), - Horde_ActiveSync_Message_Appointment::POOMCAL_ORGANIZERNAME => array(self::KEY_ATTRIBUTE => 'organizername'), - Horde_ActiveSync_Message_Appointment::POOMCAL_ORGANIZEREMAIL => array (self::KEY_ATTRIBUTE => 'organizeremail'), - Horde_ActiveSync_Message_Appointment::POOMCAL_ENDTIME => array(self::KEY_ATTRIBUTE => 'endtime', self::KEY_TYPE => self::TYPE_DATE), - Horde_ActiveSync_Message_Appointment::POOMCAL_SENSITIVITY => array(self::KEY_ATTRIBUTE => 'sensitivity'), - Horde_ActiveSync_Message_Appointment::POOMCAL_BUSYSTATUS => array(self::KEY_ATTRIBUTE => 'busystatus'), - Horde_ActiveSync_Message_Appointment::POOMCAL_ALLDAYEVENT => array(self::KEY_ATTRIBUTE => 'alldayevent'), - Horde_ActiveSync_Message_Appointment::POOMCAL_REMINDER => array(self::KEY_ATTRIBUTE => 'reminder'), - Horde_ActiveSync_Message_Appointment::POOMCAL_MEETINGSTATUS => array(self::KEY_ATTRIBUTE => 'meetingstatus'), - Horde_ActiveSync_Message_Appointment::POOMCAL_ATTENDEES => array(self::KEY_ATTRIBUTE => 'attendees', self::KEY_TYPE => 'Horde_ActiveSync_Message_Attendee', self::KEY_VALUES => Horde_ActiveSync_Message_Appointment::POOMCAL_ATTENDEE), - Horde_ActiveSync_Message_Appointment::POOMCAL_CATEGORIES => array(self::KEY_ATTRIBUTE => 'categories', self::KEY_VALUES => Horde_ActiveSync_Message_Appointment::POOMCAL_CATEGORY), - Horde_ActiveSync_Message_Appointment::POOMCAL_DELETED => array(self::KEY_ATTRIBUTE => 'deleted'), - ); + protected $_mapping = [ + Horde_ActiveSync_Message_Appointment::POOMCAL_TIMEZONE => [self::KEY_ATTRIBUTE => 'timezone'], + Horde_ActiveSync_Message_Appointment::POOMCAL_DTSTAMP => [self::KEY_ATTRIBUTE => 'dtstamp', self::KEY_TYPE => self::TYPE_DATE], + Horde_ActiveSync_Message_Appointment::POOMCAL_STARTTIME => [self::KEY_ATTRIBUTE => 'starttime', self::KEY_TYPE => self::TYPE_DATE], + Horde_ActiveSync_Message_Appointment::POOMCAL_SUBJECT => [self::KEY_ATTRIBUTE => 'subject'], + Horde_ActiveSync_Message_Appointment::POOMCAL_ORGANIZERNAME => [self::KEY_ATTRIBUTE => 'organizername'], + Horde_ActiveSync_Message_Appointment::POOMCAL_ORGANIZEREMAIL => [self::KEY_ATTRIBUTE => 'organizeremail'], + Horde_ActiveSync_Message_Appointment::POOMCAL_ENDTIME => [self::KEY_ATTRIBUTE => 'endtime', self::KEY_TYPE => self::TYPE_DATE], + Horde_ActiveSync_Message_Appointment::POOMCAL_SENSITIVITY => [self::KEY_ATTRIBUTE => 'sensitivity'], + Horde_ActiveSync_Message_Appointment::POOMCAL_BUSYSTATUS => [self::KEY_ATTRIBUTE => 'busystatus'], + Horde_ActiveSync_Message_Appointment::POOMCAL_ALLDAYEVENT => [self::KEY_ATTRIBUTE => 'alldayevent'], + Horde_ActiveSync_Message_Appointment::POOMCAL_REMINDER => [self::KEY_ATTRIBUTE => 'reminder'], + Horde_ActiveSync_Message_Appointment::POOMCAL_MEETINGSTATUS => [self::KEY_ATTRIBUTE => 'meetingstatus'], + Horde_ActiveSync_Message_Appointment::POOMCAL_ATTENDEES => [self::KEY_ATTRIBUTE => 'attendees', self::KEY_TYPE => 'Horde_ActiveSync_Message_Attendee', self::KEY_VALUES => Horde_ActiveSync_Message_Appointment::POOMCAL_ATTENDEE], + Horde_ActiveSync_Message_Appointment::POOMCAL_CATEGORIES => [self::KEY_ATTRIBUTE => 'categories', self::KEY_VALUES => Horde_ActiveSync_Message_Appointment::POOMCAL_CATEGORY], + Horde_ActiveSync_Message_Appointment::POOMCAL_DELETED => [self::KEY_ATTRIBUTE => 'deleted'], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'timezone' => false, 'dtstamp' => false, 'starttime' => false, @@ -91,9 +92,9 @@ class Horde_ActiveSync_Message_Exception extends Horde_ActiveSync_Message_Appoin 'reminder' => false, 'meetingstatus' => false, 'deleted' => false, - 'attendees' => array(), - 'categories' => array(), - ); + 'attendees' => [], + 'categories' => [], + ]; /** * The parent appointment for this exception. Only set when client code @@ -108,30 +109,30 @@ class Horde_ActiveSync_Message_Exception extends Horde_ActiveSync_Message_Appoin * * @see Horde_ActiveSync_Message_Base::__construct() */ - public function __construct(array $options = array()) + public function __construct(array $options = []) { parent::__construct($options); // Removed in 16.0 if ($this->_version <= Horde_ActiveSync::VERSION_FOURTEENONE) { - $this->_mapping += array( - Horde_ActiveSync_Message_Appointment::POOMCAL_EXCEPTIONSTARTTIME => array(self::KEY_ATTRIBUTE => 'exceptionstarttime', self::KEY_TYPE => self::TYPE_DATE), - Horde_ActiveSync_Message_Appointment::POOMCAL_LOCATION => array(self::KEY_ATTRIBUTE => 'location'), - ); - $this->_properties += array( + $this->_mapping += [ + Horde_ActiveSync_Message_Appointment::POOMCAL_EXCEPTIONSTARTTIME => [self::KEY_ATTRIBUTE => 'exceptionstarttime', self::KEY_TYPE => self::TYPE_DATE], + Horde_ActiveSync_Message_Appointment::POOMCAL_LOCATION => [self::KEY_ATTRIBUTE => 'location'], + ]; + $this->_properties += [ 'exceptionstarttime' => false, 'location' => false, - ); + ]; } if ($this->_version >= Horde_ActiveSync::VERSION_SIXTEEN) { - $this->_mapping += array( - Horde_ActiveSync::AIRSYNCBASE_LOCATION => array(self::KEY_ATTRIBUTE => 'location', self::KEY_TYPE => Horde_ActiveSync_Message_AirSyncBaseLocation), - Horde_ActiveSync::AIRSYNCBASE_INSTANCEID => array(self::KEY_ATTRIBUTE => 'instanceid', self::KEY_TYPE => self::TYPE_DATE) - ); - $this->_properties += array( + $this->_mapping += [ + Horde_ActiveSync::AIRSYNCBASE_LOCATION => [self::KEY_ATTRIBUTE => 'location', self::KEY_TYPE => Horde_ActiveSync_Message_AirSyncBaseLocation], + Horde_ActiveSync::AIRSYNCBASE_INSTANCEID => [self::KEY_ATTRIBUTE => 'instanceid', self::KEY_TYPE => self::TYPE_DATE], + ]; + $this->_properties += [ 'location' => false, 'instanceid' => false, - ); + ]; } } @@ -187,11 +188,11 @@ public function setParentAppointment(Horde_ActiveSync_Message_Appointment $paren */ public function getDatetime() { - return array( + return [ 'start' => $this->getStarttime(), 'end' => $this->getEndtime(), - 'allday' => !empty($this->_properties['alldayevent']) ? true : false - ); + 'allday' => !empty($this->_properties['alldayevent']) ? true : false, + ]; } /** diff --git a/lib/Horde/ActiveSync/Message/Flag.php b/lib/Horde/ActiveSync/Message/Flag.php index 09852783..f4f7b142 100644 --- a/lib/Horde/ActiveSync/Message/Flag.php +++ b/lib/Horde/ActiveSync/Message/Flag.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'flagstatus'), - self::POOMMAIL_FLAGTYPE => array(self::KEY_ATTRIBUTE => 'flagtype'), - Horde_ActiveSync_Message_Task::POOMTASKS_STARTDATE => array(self::KEY_ATTRIBUTE => 'startdate', self::KEY_TYPE => self::TYPE_DATE_DASHES), - Horde_ActiveSync_Message_Task::POOMTASKS_UTCSTARTDATE => array(self::KEY_ATTRIBUTE => 'utcstartdate', self::KEY_TYPE => self::TYPE_DATE_DASHES), - Horde_ActiveSync_Message_Task::POOMTASKS_DUEDATE => array(self::KEY_ATTRIBUTE => 'duedate', self::KEY_TYPE => self::TYPE_DATE_DASHES), - Horde_ActiveSync_Message_Task::POOMTASKS_UTCDUEDATE => array(self::KEY_ATTRIBUTE => 'utcduedate', self::KEY_TYPE => self::TYPE_DATE_DASHES), - Horde_ActiveSync_Message_Task::POOMTASKS_DATECOMPLETED => array(self::KEY_ATTRIBUTE => 'datecompleted', self::KEY_TYPE => self::TYPE_DATE_DASHES), - Horde_ActiveSync_Message_Task::POOMTASKS_REMINDERSET => array(self::KEY_ATTRIBUTE => 'reminderset'), - Horde_ActiveSync_Message_Task::POOMTASKS_REMINDERTIME => array(self::KEY_ATTRIBUTE => 'remindertime', self::KEY_TYPE => self::TYPE_DATE_DASHES), - Horde_ActiveSync_Message_Task::POOMTASKS_SUBJECT => array(self::KEY_ATTRIBUTE => 'subject'), - Horde_ActiveSync_Message_Task::POOMTASKS_ORDINALDATE => array(self::KEY_ATTRIBUTE => 'ordinaldate', self::KEY_TYPE => self::TYPE_DATE_DASHES), - Horde_ActiveSync_Message_Task::POOMTASKS_SUBORDINALDATE => array(self::KEY_ATTRIBUTE => 'subordinaldate'), - self::POOMMAIL_COMPLETETIME => array(self::KEY_ATTRIBUTE => 'completetime'), - ); + protected $_mapping = [ + self::POOMMAIL_FLAGSTATUS => [self::KEY_ATTRIBUTE => 'flagstatus'], + self::POOMMAIL_FLAGTYPE => [self::KEY_ATTRIBUTE => 'flagtype'], + Horde_ActiveSync_Message_Task::POOMTASKS_STARTDATE => [self::KEY_ATTRIBUTE => 'startdate', self::KEY_TYPE => self::TYPE_DATE_DASHES], + Horde_ActiveSync_Message_Task::POOMTASKS_UTCSTARTDATE => [self::KEY_ATTRIBUTE => 'utcstartdate', self::KEY_TYPE => self::TYPE_DATE_DASHES], + Horde_ActiveSync_Message_Task::POOMTASKS_DUEDATE => [self::KEY_ATTRIBUTE => 'duedate', self::KEY_TYPE => self::TYPE_DATE_DASHES], + Horde_ActiveSync_Message_Task::POOMTASKS_UTCDUEDATE => [self::KEY_ATTRIBUTE => 'utcduedate', self::KEY_TYPE => self::TYPE_DATE_DASHES], + Horde_ActiveSync_Message_Task::POOMTASKS_DATECOMPLETED => [self::KEY_ATTRIBUTE => 'datecompleted', self::KEY_TYPE => self::TYPE_DATE_DASHES], + Horde_ActiveSync_Message_Task::POOMTASKS_REMINDERSET => [self::KEY_ATTRIBUTE => 'reminderset'], + Horde_ActiveSync_Message_Task::POOMTASKS_REMINDERTIME => [self::KEY_ATTRIBUTE => 'remindertime', self::KEY_TYPE => self::TYPE_DATE_DASHES], + Horde_ActiveSync_Message_Task::POOMTASKS_SUBJECT => [self::KEY_ATTRIBUTE => 'subject'], + Horde_ActiveSync_Message_Task::POOMTASKS_ORDINALDATE => [self::KEY_ATTRIBUTE => 'ordinaldate', self::KEY_TYPE => self::TYPE_DATE_DASHES], + Horde_ActiveSync_Message_Task::POOMTASKS_SUBORDINALDATE => [self::KEY_ATTRIBUTE => 'subordinaldate'], + self::POOMMAIL_COMPLETETIME => [self::KEY_ATTRIBUTE => 'completetime'], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'flagstatus' => false, 'flagtype' => false, 'startdate' => false, @@ -103,7 +104,7 @@ class Horde_ActiveSync_Message_Flag extends Horde_ActiveSync_Message_Base 'ordinaldate' => false, 'subordinaldate' => false, 'completetime' => false, - ); + ]; /** * Return the message class. diff --git a/lib/Horde/ActiveSync/Message/Folder.php b/lib/Horde/ActiveSync/Message/Folder.php index 8f892fa1..8a4617f6 100644 --- a/lib/Horde/ActiveSync/Message/Folder.php +++ b/lib/Horde/ActiveSync/Message/Folder.php @@ -1,4 +1,5 @@ array (self::KEY_ATTRIBUTE => 'serverid'), - Horde_ActiveSync::FOLDERHIERARCHY_PARENTID => array (self::KEY_ATTRIBUTE => 'parentid'), - Horde_ActiveSync::FOLDERHIERARCHY_DISPLAYNAME => array (self::KEY_ATTRIBUTE => 'displayname'), - Horde_ActiveSync::FOLDERHIERARCHY_TYPE => array (self::KEY_ATTRIBUTE => 'type') - ); + protected $_mapping = [ + Horde_ActiveSync::FOLDERHIERARCHY_SERVERENTRYID => [self::KEY_ATTRIBUTE => 'serverid'], + Horde_ActiveSync::FOLDERHIERARCHY_PARENTID => [self::KEY_ATTRIBUTE => 'parentid'], + Horde_ActiveSync::FOLDERHIERARCHY_DISPLAYNAME => [self::KEY_ATTRIBUTE => 'displayname'], + Horde_ActiveSync::FOLDERHIERARCHY_TYPE => [self::KEY_ATTRIBUTE => 'type'], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'serverid' => false, '_serverid' => false, '_parentid' => false, 'displayname' => false, 'type' => false, - ); + ]; /** * Get message type. diff --git a/lib/Horde/ActiveSync/Message/Forwardee.php b/lib/Horde/ActiveSync/Message/Forwardee.php index fccf278c..236804bf 100644 --- a/lib/Horde/ActiveSync/Message/Forwardee.php +++ b/lib/Horde/ActiveSync/Message/Forwardee.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'name'), - Horde_ActiveSync_Message_SendMail::FORWARDEEEMAIL => array(self::KEY_ATTRIBUTE => 'email') - ); + protected $_mapping = [ + Horde_ActiveSync_Message_SendMail::FORWARDEENAME => [self::KEY_ATTRIBUTE => 'name'], + Horde_ActiveSync_Message_SendMail::FORWARDEEEMAIL => [self::KEY_ATTRIBUTE => 'email'], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'name' => false, - 'email' => false - ); + 'email' => false, + ]; } diff --git a/lib/Horde/ActiveSync/Message/GalPicture.php b/lib/Horde/ActiveSync/Message/GalPicture.php index 4348e37c..b87948eb 100644 --- a/lib/Horde/ActiveSync/Message/GalPicture.php +++ b/lib/Horde/ActiveSync/Message/GalPicture.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'status'), - Horde_ActiveSync::GAL_DATA => array(self::KEY_ATTRIBUTE => 'data') - ); + protected $_mapping = [ + Horde_ActiveSync::GAL_STATUS => [self::KEY_ATTRIBUTE => 'status'], + Horde_ActiveSync::GAL_DATA => [self::KEY_ATTRIBUTE => 'data'], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'status' => false, - 'data' => false - ); + 'data' => false, + ]; } diff --git a/lib/Horde/ActiveSync/Message/Mail.php b/lib/Horde/ActiveSync/Message/Mail.php index ea772e91..e2f73fc4 100644 --- a/lib/Horde/ActiveSync/Message/Mail.php +++ b/lib/Horde/ActiveSync/Message/Mail.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'to'), - self::POOMMAIL_CC => array(self::KEY_ATTRIBUTE => 'cc'), - self::POOMMAIL_FROM => array(self::KEY_ATTRIBUTE => 'from'), - self::POOMMAIL_SUBJECT => array(self::KEY_ATTRIBUTE => 'subject'), - self::POOMMAIL_REPLY_TO => array(self::KEY_ATTRIBUTE => 'reply_to'), - self::POOMMAIL_DATERECEIVED => array(self::KEY_ATTRIBUTE => 'datereceived', self::KEY_TYPE => self::TYPE_DATE_DASHES), - self::POOMMAIL_DISPLAYTO => array(self::KEY_ATTRIBUTE => 'displayto'), - self::POOMMAIL_THREADTOPIC => array(self::KEY_ATTRIBUTE => 'threadtopic'), - self::POOMMAIL_IMPORTANCE => array(self::KEY_ATTRIBUTE => 'importance'), - self::POOMMAIL_READ => array(self::KEY_ATTRIBUTE => 'read'), - self::POOMMAIL_MIMETRUNCATED => array(self::KEY_ATTRIBUTE => 'mimetruncated' ), + protected $_mapping = [ + self::POOMMAIL_TO => [self::KEY_ATTRIBUTE => 'to'], + self::POOMMAIL_CC => [self::KEY_ATTRIBUTE => 'cc'], + self::POOMMAIL_FROM => [self::KEY_ATTRIBUTE => 'from'], + self::POOMMAIL_SUBJECT => [self::KEY_ATTRIBUTE => 'subject'], + self::POOMMAIL_REPLY_TO => [self::KEY_ATTRIBUTE => 'reply_to'], + self::POOMMAIL_DATERECEIVED => [self::KEY_ATTRIBUTE => 'datereceived', self::KEY_TYPE => self::TYPE_DATE_DASHES], + self::POOMMAIL_DISPLAYTO => [self::KEY_ATTRIBUTE => 'displayto'], + self::POOMMAIL_THREADTOPIC => [self::KEY_ATTRIBUTE => 'threadtopic'], + self::POOMMAIL_IMPORTANCE => [self::KEY_ATTRIBUTE => 'importance'], + self::POOMMAIL_READ => [self::KEY_ATTRIBUTE => 'read'], + self::POOMMAIL_MIMETRUNCATED => [self::KEY_ATTRIBUTE => 'mimetruncated' ], // Not used. - self::POOMMAIL_MIMEDATA => array(self::KEY_ATTRIBUTE => 'mimedata', self::KEY_TYPE => 'KEY_TYPE_MAPI_STREAM'), - self::POOMMAIL_MIMESIZE => array(self::KEY_ATTRIBUTE => 'mimesize' ), + self::POOMMAIL_MIMEDATA => [self::KEY_ATTRIBUTE => 'mimedata', self::KEY_TYPE => 'KEY_TYPE_MAPI_STREAM'], + self::POOMMAIL_MIMESIZE => [self::KEY_ATTRIBUTE => 'mimesize' ], - self::POOMMAIL_MESSAGECLASS => array(self::KEY_ATTRIBUTE => 'messageclass'), - self::POOMMAIL_MEETINGREQUEST => array(self::KEY_ATTRIBUTE => 'meetingrequest', self::KEY_TYPE => 'Horde_ActiveSync_Message_MeetingRequest'), - self::POOMMAIL_INTERNETCPID => array(self::KEY_ATTRIBUTE => 'cpid'), - ); + self::POOMMAIL_MESSAGECLASS => [self::KEY_ATTRIBUTE => 'messageclass'], + self::POOMMAIL_MEETINGREQUEST => [self::KEY_ATTRIBUTE => 'meetingrequest', self::KEY_TYPE => 'Horde_ActiveSync_Message_MeetingRequest'], + self::POOMMAIL_INTERNETCPID => [self::KEY_ATTRIBUTE => 'cpid'], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'to' => false, 'cc' => false, 'from' => false, @@ -220,133 +221,133 @@ class Horde_ActiveSync_Message_Mail extends Horde_ActiveSync_Message_Base 'reply_to' => false, 'read' => false, 'cpid' => false, - ); + ]; /** * Const'r * * @see Horde_ActiveSync_Message_Base::__construct() */ - public function __construct(array $options = array()) + public function __construct(array $options = []) { parent::__construct($options); if ($this->_version == Horde_ActiveSync::VERSION_TWOFIVE) { - $this->_mapping += array( - self::POOMMAIL_ATTACHMENTS => array(self::KEY_ATTRIBUTE => 'attachments', self::KEY_TYPE => 'Horde_ActiveSync_Message_Attachment', self::KEY_VALUES => self::POOMMAIL_ATTACHMENT), - self::POOMMAIL_BODYTRUNCATED => array(self::KEY_ATTRIBUTE => 'bodytruncated'), - self::POOMMAIL_BODYSIZE => array(self::KEY_ATTRIBUTE => 'bodysize'), - self::POOMMAIL_BODY => array(self::KEY_ATTRIBUTE => 'body'), - ); - - $this->_properties += array( + $this->_mapping += [ + self::POOMMAIL_ATTACHMENTS => [self::KEY_ATTRIBUTE => 'attachments', self::KEY_TYPE => 'Horde_ActiveSync_Message_Attachment', self::KEY_VALUES => self::POOMMAIL_ATTACHMENT], + self::POOMMAIL_BODYTRUNCATED => [self::KEY_ATTRIBUTE => 'bodytruncated'], + self::POOMMAIL_BODYSIZE => [self::KEY_ATTRIBUTE => 'bodysize'], + self::POOMMAIL_BODY => [self::KEY_ATTRIBUTE => 'body'], + ]; + + $this->_properties += [ 'attachments' => false, 'bodytruncated' => false, 'bodysize' => false, 'body' => false, - ); + ]; } if ($this->_version >= Horde_ActiveSync::VERSION_TWELVE) { - $this->_mapping += array( - Horde_ActiveSync::AIRSYNCBASE_NATIVEBODYTYPE => array(self::KEY_ATTRIBUTE => 'airsyncbasenativebodytype'), - Horde_ActiveSync::AIRSYNCBASE_BODY => array(self::KEY_ATTRIBUTE => 'airsyncbasebody', self::KEY_TYPE=> 'Horde_ActiveSync_Message_AirSyncBaseBody'), - Horde_ActiveSync::AIRSYNCBASE_ATTACHMENTS => array( + $this->_mapping += [ + Horde_ActiveSync::AIRSYNCBASE_NATIVEBODYTYPE => [self::KEY_ATTRIBUTE => 'airsyncbasenativebodytype'], + Horde_ActiveSync::AIRSYNCBASE_BODY => [self::KEY_ATTRIBUTE => 'airsyncbasebody', self::KEY_TYPE => 'Horde_ActiveSync_Message_AirSyncBaseBody'], + Horde_ActiveSync::AIRSYNCBASE_ATTACHMENTS => [ self::KEY_ATTRIBUTE => 'airsyncbaseattachments', - self::KEY_TYPE => array('Horde_ActiveSync_Message_AirSyncBaseAttachment', 'Horde_ActiveSync_Message_AirSyncBaseAdd', 'Horde_ActiveSync_Message_AirSyncBaseDelete'), - self::KEY_VALUES => array(Horde_ActiveSync::AIRSYNCBASE_ATTACHMENT, Horde_ActiveSync::AIRSYNCBASE_ADD, Horde_ActiveSync::AIRSYNCBASE_DELETE), - ), - self::POOMMAIL_FLAG => array(self::KEY_ATTRIBUTE => 'flag', self::KEY_TYPE => 'Horde_ActiveSync_Message_Flag'), - self::POOMMAIL_CONTENTCLASS => array(self::KEY_ATTRIBUTE => 'contentclass'), - ); - - $this->_properties += array( + self::KEY_TYPE => ['Horde_ActiveSync_Message_AirSyncBaseAttachment', 'Horde_ActiveSync_Message_AirSyncBaseAdd', 'Horde_ActiveSync_Message_AirSyncBaseDelete'], + self::KEY_VALUES => [Horde_ActiveSync::AIRSYNCBASE_ATTACHMENT, Horde_ActiveSync::AIRSYNCBASE_ADD, Horde_ActiveSync::AIRSYNCBASE_DELETE], + ], + self::POOMMAIL_FLAG => [self::KEY_ATTRIBUTE => 'flag', self::KEY_TYPE => 'Horde_ActiveSync_Message_Flag'], + self::POOMMAIL_CONTENTCLASS => [self::KEY_ATTRIBUTE => 'contentclass'], + ]; + + $this->_properties += [ 'airsyncbasenativebodytype' => false, 'airsyncbasebody' => false, - 'airsyncbaseattachments' => array(), + 'airsyncbaseattachments' => [], 'contentclass' => false, 'flag' => false, - ); + ]; // Removed in 16.0 if ($this->_version <= Horde_ActiveSync::VERSION_FOURTEENONE) { - $this->_mapping += array( - self::POOMMAIL_LOCATION => array(self::KEY_ATTRIBUTE => 'location'), - self::POOMMAIL_GLOBALOBJID => array(self::KEY_ATTRIBUTE => 'globalobjid') - ); - $this->_properties += array( + $this->_mapping += [ + self::POOMMAIL_LOCATION => [self::KEY_ATTRIBUTE => 'location'], + self::POOMMAIL_GLOBALOBJID => [self::KEY_ATTRIBUTE => 'globalobjid'], + ]; + $this->_properties += [ 'location' => false, 'globalobjid' => false, - ); + ]; } if ($this->_version >= Horde_ActiveSync::VERSION_FOURTEEN) { - $this->_mapping += array( - self::POOMMAIL_CATEGORIES => array(self::KEY_ATTRIBUTE => 'categories', self::KEY_VALUES => self::POOMMAIL_CATEGORY), - self::POOMMAIL_CATEGORY => array(self::KEY_ATTRIBUTE => 'category'), - self::POOMMAIL2_UMCALLERID => array(self::KEY_ATTRIBUTE => 'umcallerid'), - self::POOMMAIL2_UMUSERNOTES => array(self::KEY_ATTRIBUTE => 'umusernotes'), - self::POOMMAIL2_UMATTDURATION => array(self::KEY_ATTRIBUTE => 'umattduration'), - self::POOMMAIL2_UMATTORDER => array(self::KEY_ATTRIBUTE => 'umattorder'), - self::POOMMAIL2_CONVERSATIONID => array(self::KEY_ATTRIBUTE => 'conversationid'), - self::POOMMAIL2_CONVERSATIONINDEX => array(self::KEY_ATTRIBUTE => 'conversationindex'), - self::POOMMAIL2_LASTVERBEXECUTED => array(self::KEY_ATTRIBUTE => 'lastverbexecuted'), - self::POOMMAIL2_LASTVERBEXECUTIONTIME => array(self::KEY_ATTRIBUTE => 'lastverbexecutiontime', self::KEY_TYPE => self::TYPE_DATE_DASHES), - self::POOMMAIL2_RECEIVEDASBCC => array(self::KEY_ATTRIBUTE => 'receivedasbcc'), - self::POOMMAIL2_SENDER => array(self::KEY_ATTRIBUTE => 'sender'), - self::POOMMAIL2_CALENDARTYPE => array(self::KEY_ATTRIBUTE => 'calendartype'), - self::POOMMAIL2_ISLEAPMONTH => array(self::KEY_ATTRIBUTE => 'isleapmonth'), - self::POOMMAIL2_ACCOUNTID => array(self::KEY_ATTRIBUTE => 'accountid'), - self::POOMMAIL2_FIRSTDAYOFWEEK => array(self::KEY_ATTRIBUTE => 'firstdayofweek') - ); - - $this->_properties += array( - 'umcallerid' => false, - 'umusernotes' => false, - 'umattduration' => false, - 'umattorder' => false, - 'conversationid' => false, - 'conversationindex' => false, - 'lastverbexecuted' => false, - 'lastverbexecutiontime' => false, - 'receivedasbcc' => false, - 'sender' => false, - 'calendartype' => false, - 'isleapmonth' => false, - 'accountid' => false, - 'firstdayofweek' => false, - 'categories' => array(), - - // Internal use - 'messageid' => false, - 'answered' => false, - 'forwarded' => false, - ); + $this->_mapping += [ + self::POOMMAIL_CATEGORIES => [self::KEY_ATTRIBUTE => 'categories', self::KEY_VALUES => self::POOMMAIL_CATEGORY], + self::POOMMAIL_CATEGORY => [self::KEY_ATTRIBUTE => 'category'], + self::POOMMAIL2_UMCALLERID => [self::KEY_ATTRIBUTE => 'umcallerid'], + self::POOMMAIL2_UMUSERNOTES => [self::KEY_ATTRIBUTE => 'umusernotes'], + self::POOMMAIL2_UMATTDURATION => [self::KEY_ATTRIBUTE => 'umattduration'], + self::POOMMAIL2_UMATTORDER => [self::KEY_ATTRIBUTE => 'umattorder'], + self::POOMMAIL2_CONVERSATIONID => [self::KEY_ATTRIBUTE => 'conversationid'], + self::POOMMAIL2_CONVERSATIONINDEX => [self::KEY_ATTRIBUTE => 'conversationindex'], + self::POOMMAIL2_LASTVERBEXECUTED => [self::KEY_ATTRIBUTE => 'lastverbexecuted'], + self::POOMMAIL2_LASTVERBEXECUTIONTIME => [self::KEY_ATTRIBUTE => 'lastverbexecutiontime', self::KEY_TYPE => self::TYPE_DATE_DASHES], + self::POOMMAIL2_RECEIVEDASBCC => [self::KEY_ATTRIBUTE => 'receivedasbcc'], + self::POOMMAIL2_SENDER => [self::KEY_ATTRIBUTE => 'sender'], + self::POOMMAIL2_CALENDARTYPE => [self::KEY_ATTRIBUTE => 'calendartype'], + self::POOMMAIL2_ISLEAPMONTH => [self::KEY_ATTRIBUTE => 'isleapmonth'], + self::POOMMAIL2_ACCOUNTID => [self::KEY_ATTRIBUTE => 'accountid'], + self::POOMMAIL2_FIRSTDAYOFWEEK => [self::KEY_ATTRIBUTE => 'firstdayofweek'], + ]; + + $this->_properties += [ + 'umcallerid' => false, + 'umusernotes' => false, + 'umattduration' => false, + 'umattorder' => false, + 'conversationid' => false, + 'conversationindex' => false, + 'lastverbexecuted' => false, + 'lastverbexecutiontime' => false, + 'receivedasbcc' => false, + 'sender' => false, + 'calendartype' => false, + 'isleapmonth' => false, + 'accountid' => false, + 'firstdayofweek' => false, + 'categories' => [], + + // Internal use + 'messageid' => false, + 'answered' => false, + 'forwarded' => false, + ]; } if ($this->_version > Horde_ActiveSync::VERSION_FOURTEEN) { - $this->_mapping += array( - Horde_ActiveSync::AIRSYNCBASE_BODYPART => array(self::KEY_ATTRIBUTE => 'airsyncbasebodypart', self::KEY_TYPE => 'Horde_ActiveSync_Message_AirSyncBaseBodypart') - ); - $this->_properties += array( - 'airsyncbasebodypart' => false - ); + $this->_mapping += [ + Horde_ActiveSync::AIRSYNCBASE_BODYPART => [self::KEY_ATTRIBUTE => 'airsyncbasebodypart', self::KEY_TYPE => 'Horde_ActiveSync_Message_AirSyncBaseBodypart'], + ]; + $this->_properties += [ + 'airsyncbasebodypart' => false, + ]; } if ($this->_version >= Horde_ActiveSync::VERSION_SIXTEEN) { - $this->_mapping += array( - self::POOMMAIL2_ISDRAFT => array(self::KEY_ATTRIBUTE => 'isdraft'), - self::POOMMAIL2_BCC => array(self::KEY_ATTRIBUTE => 'bcc'), - self::POOMMAIL2_SEND => array(self::KEY_ATTRIBUTE => 'send'), - Horde_ActiveSync::AIRSYNCBASE_LOCATION => array(self::KEY_ATTRIBUTE => 'location', - Horde_ActiveSync_Message_Appointment::POOMCAL_UID => array(self::KEY_ATTRIBUTE => 'uid')), - ); - - $this->_properties += array( + $this->_mapping += [ + self::POOMMAIL2_ISDRAFT => [self::KEY_ATTRIBUTE => 'isdraft'], + self::POOMMAIL2_BCC => [self::KEY_ATTRIBUTE => 'bcc'], + self::POOMMAIL2_SEND => [self::KEY_ATTRIBUTE => 'send'], + Horde_ActiveSync::AIRSYNCBASE_LOCATION => [self::KEY_ATTRIBUTE => 'location', + Horde_ActiveSync_Message_Appointment::POOMCAL_UID => [self::KEY_ATTRIBUTE => 'uid']], + ]; + + $this->_properties += [ 'isdraft' => false, 'bcc' => false, 'send' => false, 'location' => false, 'uid' => false, - ); + ]; } } } @@ -394,10 +395,10 @@ public function draftToMime() $headers->addHeader('importance', $this->importance); } - return array( + return [ 'part' => $text, - 'headers' => $headers - ); + 'headers' => $headers, + ]; } /** @@ -435,9 +436,9 @@ public function getClass() protected function _checkSendEmpty($tag) { switch ($tag) { - case self::POOMMAIL_FLAG: - case self::POOMMAIL_CATEGORIES: - return true; + case self::POOMMAIL_FLAG: + case self::POOMMAIL_CATEGORIES: + return true; } return false; diff --git a/lib/Horde/ActiveSync/Message/MeetingRequest.php b/lib/Horde/ActiveSync/Message/MeetingRequest.php index 5cc15a1f..795a6403 100644 --- a/lib/Horde/ActiveSync/Message/MeetingRequest.php +++ b/lib/Horde/ActiveSync/Message/MeetingRequest.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'alldayevent'), - Horde_ActiveSync_Message_Mail::POOMMAIL_STARTTIME => array(self::KEY_ATTRIBUTE => 'starttime', self::KEY_TYPE => self::TYPE_DATE_DASHES), - Horde_ActiveSync_Message_Mail::POOMMAIL_DTSTAMP => array(self::KEY_ATTRIBUTE => 'dtstamp', self::KEY_TYPE => self::TYPE_DATE_DASHES), - Horde_ActiveSync_Message_Mail::POOMMAIL_ENDTIME => array(self::KEY_ATTRIBUTE => 'endtime', self::KEY_TYPE => self::TYPE_DATE_DASHES), - Horde_ActiveSync_Message_Mail::POOMMAIL_INSTANCETYPE => array(self::KEY_ATTRIBUTE => 'instancetype'), - Horde_ActiveSync_Message_Mail::POOMMAIL_LOCATION => array(self::KEY_ATTRIBUTE => 'location'), - Horde_ActiveSync_Message_Mail::POOMMAIL_ORGANIZER => array(self::KEY_ATTRIBUTE => 'organizer'), - Horde_ActiveSync_Message_Mail::POOMMAIL_RECURRENCEID => array(self::KEY_ATTRIBUTE => 'recurrenceid', self::KEY_TYPE => self::TYPE_DATE_DASHES), - Horde_ActiveSync_Message_Mail::POOMMAIL_REMINDER => array(self::KEY_ATTRIBUTE => 'reminder'), - Horde_ActiveSync_Message_Mail::POOMMAIL_RESPONSEREQUESTED => array(self::KEY_ATTRIBUTE => 'responserequested'), - Horde_ActiveSync_Message_Mail::POOMMAIL_RECURRENCES => array(self::KEY_ATTRIBUTE => 'recurrences', self::KEY_TYPE => 'Horde_ActiveSync_Message_MeetingRequestRecurrence', self::KEY_VALUES => Horde_ActiveSync_Message_Mail::POOMMAIL_RECURRENCE), - Horde_ActiveSync_Message_Mail::POOMMAIL_SENSITIVITY => array(self::KEY_ATTRIBUTE => 'sensitivity'), - Horde_ActiveSync_Message_Mail::POOMMAIL_BUSYSTATUS => array(self::KEY_ATTRIBUTE => 'busystatus'), - Horde_ActiveSync_Message_Mail::POOMMAIL_TIMEZONE => array(self::KEY_ATTRIBUTE => 'timezone'), - Horde_ActiveSync_Message_Mail::POOMMAIL_GLOBALOBJID => array(self::KEY_ATTRIBUTE => 'globalobjid'), - ); + protected $_mapping = [ + Horde_ActiveSync_Message_Mail::POOMMAIL_ALLDAYEVENT => [self::KEY_ATTRIBUTE => 'alldayevent'], + Horde_ActiveSync_Message_Mail::POOMMAIL_STARTTIME => [self::KEY_ATTRIBUTE => 'starttime', self::KEY_TYPE => self::TYPE_DATE_DASHES], + Horde_ActiveSync_Message_Mail::POOMMAIL_DTSTAMP => [self::KEY_ATTRIBUTE => 'dtstamp', self::KEY_TYPE => self::TYPE_DATE_DASHES], + Horde_ActiveSync_Message_Mail::POOMMAIL_ENDTIME => [self::KEY_ATTRIBUTE => 'endtime', self::KEY_TYPE => self::TYPE_DATE_DASHES], + Horde_ActiveSync_Message_Mail::POOMMAIL_INSTANCETYPE => [self::KEY_ATTRIBUTE => 'instancetype'], + Horde_ActiveSync_Message_Mail::POOMMAIL_LOCATION => [self::KEY_ATTRIBUTE => 'location'], + Horde_ActiveSync_Message_Mail::POOMMAIL_ORGANIZER => [self::KEY_ATTRIBUTE => 'organizer'], + Horde_ActiveSync_Message_Mail::POOMMAIL_RECURRENCEID => [self::KEY_ATTRIBUTE => 'recurrenceid', self::KEY_TYPE => self::TYPE_DATE_DASHES], + Horde_ActiveSync_Message_Mail::POOMMAIL_REMINDER => [self::KEY_ATTRIBUTE => 'reminder'], + Horde_ActiveSync_Message_Mail::POOMMAIL_RESPONSEREQUESTED => [self::KEY_ATTRIBUTE => 'responserequested'], + Horde_ActiveSync_Message_Mail::POOMMAIL_RECURRENCES => [self::KEY_ATTRIBUTE => 'recurrences', self::KEY_TYPE => 'Horde_ActiveSync_Message_MeetingRequestRecurrence', self::KEY_VALUES => Horde_ActiveSync_Message_Mail::POOMMAIL_RECURRENCE], + Horde_ActiveSync_Message_Mail::POOMMAIL_SENSITIVITY => [self::KEY_ATTRIBUTE => 'sensitivity'], + Horde_ActiveSync_Message_Mail::POOMMAIL_BUSYSTATUS => [self::KEY_ATTRIBUTE => 'busystatus'], + Horde_ActiveSync_Message_Mail::POOMMAIL_TIMEZONE => [self::KEY_ATTRIBUTE => 'timezone'], + Horde_ActiveSync_Message_Mail::POOMMAIL_GLOBALOBJID => [self::KEY_ATTRIBUTE => 'globalobjid'], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'alldayevent' => '0', 'starttime' => false, 'dtstamp' => false, @@ -84,12 +85,12 @@ class Horde_ActiveSync_Message_MeetingRequest extends Horde_ActiveSync_Message_B 'recurrenceid' => false, 'reminder' => false, 'responserequested' => false, - 'recurrences' => array(), + 'recurrences' => [], 'sensitivity' => false, 'busystatus' => false, 'timezone' => false, - 'globalobjid' => false - ); + 'globalobjid' => false, + ]; /** * Copy of the vEvent object. @@ -103,16 +104,16 @@ class Horde_ActiveSync_Message_MeetingRequest extends Horde_ActiveSync_Message_B * * @see Horde_ActiveSync_Message_Base::__construct() */ - public function __construct(array $options = array()) + public function __construct(array $options = []) { parent::__construct($options); if ($this->_version > Horde_ActiveSync::VERSION_FOURTEEN) { - $this->_mapping += array( - Horde_ActiveSync_Message_Mail::POOMMAIL2_MEETINGMESSAGETYPE => array(self::KEY_ATTRIBUTE => 'meetingmessagetype') - ); - $this->_properties += array( - 'meetingmessagetype' => false - ); + $this->_mapping += [ + Horde_ActiveSync_Message_Mail::POOMMAIL2_MEETINGMESSAGETYPE => [self::KEY_ATTRIBUTE => 'meetingmessagetype'], + ]; + $this->_properties += [ + 'meetingmessagetype' => false, + ]; } } @@ -132,17 +133,17 @@ public function fromvEvent($vCal) } foreach ($vCal->getComponents() as $component) { switch ($component->getType()) { - case 'vEvent': - $this->_vEvent = $component; - $this->_parsevEvent($component, $method); - break; + case 'vEvent': + $this->_vEvent = $component; + $this->_parsevEvent($component, $method); + break; - case 'vTimeZone': - // Not sure what to do with Timezone yet/how to get it into - // a TZ structure etc... For now, defaults to default timezone (as the - // specs say it should for iCal without tz specified). - default: - break; + case 'vTimeZone': + // Not sure what to do with Timezone yet/how to get it into + // a TZ structure etc... For now, defaults to default timezone (as the + // specs say it should for iCal without tz specified). + default: + break; } } @@ -156,8 +157,9 @@ public function fromvEvent($vCal) $this->timezone = $tz->getSyncTZFromOffsets( $tz->getOffsetsFromDate(new Horde_Date($this->_vEvent->getAttribute('DTSTART'))) ); - } catch (Horde_Icalendar_Exception $e) {} - $this->alldayevent = (int)$this->_isAllDay(); + } catch (Horde_Icalendar_Exception $e) { + } + $this->alldayevent = (int) $this->_isAllDay(); } /** @@ -188,7 +190,8 @@ protected function _parsevEvent($vevent, $method = 'REQUEST') try { $organizer = parse_url($vevent->getAttribute('ORGANIZER')); $this->organizer = $organizer['path']; - } catch (Horde_Icalendar_Exception $e) {} + } catch (Horde_Icalendar_Exception $e) { + } try { $this->globalobjid = Horde_Mapi::createGoid($vevent->getAttributeDefault('UID', 'nouid')); @@ -199,12 +202,14 @@ protected function _parsevEvent($vevent, $method = 'REQUEST') try { $this->dtstamp = new Horde_Date($vevent->getAttribute('DTSTAMP')); - } catch (Horde_Exception $e) {} + } catch (Horde_Exception $e) { + } try { $this->endtime = new Horde_Date($vevent->getAttribute('DTEND')); $this->location = Horde_String::truncate($vevent->getAttribute('LOCATION'), 255); - } catch (Horde_Icalendar_Exception $e) {} + } catch (Horde_Icalendar_Exception $e) { + } try { $class = $vevent->getAttribute('CLASS'); @@ -215,7 +220,8 @@ protected function _parsevEvent($vevent, $method = 'REQUEST') : ($class == 'PERSONAL' ? Horde_ActiveSync_Message_Appointment::SENSITIVITY_PERSONAL : Horde_ActiveSync_Message_Appointment::SENSITIVITY_NORMAL)); } - } catch (Horde_Icalendar_Exception $e) {} + } catch (Horde_Icalendar_Exception $e) { + } try { $status = $vevent->getAttribute('STATUS'); @@ -225,7 +231,8 @@ protected function _parsevEvent($vevent, $method = 'REQUEST') : ($status == 'CONFIRMED' ? Horde_ActiveSync_Message_Appointment::BUSYSTATUS_BUSY : Horde_ActiveSync_Message_Appointment::BUSYSTATUS_FREE); } - } catch (Horde_Icalendar_Exception $e) {} + } catch (Horde_Icalendar_Exception $e) { + } // vCalendar 1.0 alarms try { @@ -233,7 +240,8 @@ protected function _parsevEvent($vevent, $method = 'REQUEST') if (!is_array($alarm) && intval($alarm)) { $this->reminder = intval($this->starttime->timestamp() - $alarm); } - } catch (Horde_Icalendar_Exception $e) {} + } catch (Horde_Icalendar_Exception $e) { + } // vCalendar 2.0 alarms foreach ($vevent->getComponents() as $alarm) { @@ -246,10 +254,10 @@ protected function _parsevEvent($vevent, $method = 'REQUEST') } catch (Horde_Icalendar_Exception $e) { continue; } - if (isset($triggerParams['VALUE']) && - $triggerParams['VALUE'] == 'DATE-TIME') { - if (isset($triggerParams['RELATED']) && - $triggerParams['RELATED'] == 'END') { + if (isset($triggerParams['VALUE']) + && $triggerParams['VALUE'] == 'DATE-TIME') { + if (isset($triggerParams['RELATED']) + && $triggerParams['RELATED'] == 'END') { $this->reminder = intval($this->endtime->timestamp() - $trigger); } else { $this->reminder = intval($this->starttime->timestamp() - $trigger); @@ -268,12 +276,12 @@ protected function _parsevEvent($vevent, $method = 'REQUEST') */ protected function _isAllDay() { - return ($this->starttime->hour == 0 && $this->starttime->min == 0 && $this->starttime->sec == 0 && - (($this->endtime->hour == 23 && $this->endtime->min == 59) || - ($this->endtime->hour == 0 && $this->endtime->min == 0 && $this->endtime->sec == 0 && - ($this->endtime->mday > $this->starttime->mday || - $this->endtime->month > $this->starttime->month || - $this->endtime->year > $this->starttime->year)))); + return ($this->starttime->hour == 0 && $this->starttime->min == 0 && $this->starttime->sec == 0 + && (($this->endtime->hour == 23 && $this->endtime->min == 59) + || ($this->endtime->hour == 0 && $this->endtime->min == 0 && $this->endtime->sec == 0 + && ($this->endtime->mday > $this->starttime->mday + || $this->endtime->month > $this->starttime->month + || $this->endtime->year > $this->starttime->year)))); } } diff --git a/lib/Horde/ActiveSync/Message/Note.php b/lib/Horde/ActiveSync/Message/Note.php index fbce4850..bea43118 100644 --- a/lib/Horde/ActiveSync/Message/Note.php +++ b/lib/Horde/ActiveSync/Message/Note.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'body', self::KEY_TYPE => 'Horde_ActiveSync_Message_AirSyncBaseBody'), - self::CATEGORIES => array(self::KEY_ATTRIBUTE => 'categories', self::KEY_VALUES => self::CATEGORY), - self::LASTMODIFIEDDATE => array(self::KEY_ATTRIBUTE => 'lastmodified', self::KEY_TYPE => self::TYPE_DATE), - self::MESSAGECLASS => array(self::KEY_ATTRIBUTE => 'messageclass'), - self::SUBJECT => array(self::KEY_ATTRIBUTE => 'subject') - ); + protected $_mapping = [ + Horde_ActiveSync::AIRSYNCBASE_BODY => [self::KEY_ATTRIBUTE => 'body', self::KEY_TYPE => 'Horde_ActiveSync_Message_AirSyncBaseBody'], + self::CATEGORIES => [self::KEY_ATTRIBUTE => 'categories', self::KEY_VALUES => self::CATEGORY], + self::LASTMODIFIEDDATE => [self::KEY_ATTRIBUTE => 'lastmodified', self::KEY_TYPE => self::TYPE_DATE], + self::MESSAGECLASS => [self::KEY_ATTRIBUTE => 'messageclass'], + self::SUBJECT => [self::KEY_ATTRIBUTE => 'subject'], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'body' => false, 'lastmodified' => false, 'messageclass' => false, - 'subject' => false - ); + 'subject' => false, + ]; /** * Return this object's folder class diff --git a/lib/Horde/ActiveSync/Message/Oof.php b/lib/Horde/ActiveSync/Message/Oof.php index 8f7d1fd2..43871d1f 100644 --- a/lib/Horde/ActiveSync/Message/Oof.php +++ b/lib/Horde/ActiveSync/Message/Oof.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'state'), - Horde_ActiveSync_Request_Settings::SETTINGS_STARTTIME => array(self::KEY_ATTRIBUTE => 'starttime', self::KEY_TYPE => self::TYPE_DATE_DASHES), - Horde_ActiveSync_Request_Settings::SETTINGS_ENDTIME => array(self::KEY_ATTRIBUTE => 'endtime', self::KEY_TYPE => self::TYPE_DATE_DASHES), - Horde_ActiveSync_Request_Settings::SETTINGS_OOFMESSAGE => array( + protected $_mapping = [ + Horde_ActiveSync_Request_Settings::SETTINGS_OOFSTATE => [self::KEY_ATTRIBUTE => 'state'], + Horde_ActiveSync_Request_Settings::SETTINGS_STARTTIME => [self::KEY_ATTRIBUTE => 'starttime', self::KEY_TYPE => self::TYPE_DATE_DASHES], + Horde_ActiveSync_Request_Settings::SETTINGS_ENDTIME => [self::KEY_ATTRIBUTE => 'endtime', self::KEY_TYPE => self::TYPE_DATE_DASHES], + Horde_ActiveSync_Request_Settings::SETTINGS_OOFMESSAGE => [ self::KEY_ATTRIBUTE => 'messages', self::KEY_TYPE => 'Horde_ActiveSync_Message_OofMessage', self::KEY_VALUES => Horde_ActiveSync_Request_Settings::SETTINGS_OOFMESSAGE, - self::KEY_PROPERTY => self::PROPERTY_NO_CONTAINER - ), - Horde_ActiveSync_Request_Settings::SETTINGS_BODYTYPE => array(self::KEY_ATTRIBUTE => 'bodytype'), - ); + self::KEY_PROPERTY => self::PROPERTY_NO_CONTAINER, + ], + Horde_ActiveSync_Request_Settings::SETTINGS_BODYTYPE => [self::KEY_ATTRIBUTE => 'bodytype'], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'state' => false, 'starttime' => false, 'endtime' => false, - 'bodytype' => false - ); + 'bodytype' => false, + ]; } diff --git a/lib/Horde/ActiveSync/Message/OofMessage.php b/lib/Horde/ActiveSync/Message/OofMessage.php index d1e1eca7..96091a55 100644 --- a/lib/Horde/ActiveSync/Message/OofMessage.php +++ b/lib/Horde/ActiveSync/Message/OofMessage.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'internal'), - Horde_ActiveSync_Request_Settings::SETTINGS_APPLIESTOEXTERNALKNOWN => array(self::KEY_ATTRIBUTE => 'externalknown'), - Horde_ActiveSync_Request_Settings::SETTINGS_APPLIESTOEXTERNALUNKNOWN => array(self::KEY_ATTRIBUTE => 'externalunknown'), - Horde_ActiveSync_Request_Settings::SETTINGS_ENABLED => array(self::KEY_ATTRIBUTE => 'enabled'), - Horde_ActiveSync_Request_Settings::SETTINGS_REPLYMESSAGE => array(self::KEY_ATTRIBUTE => 'reply'), - Horde_ActiveSync_Request_Settings::SETTINGS_BODYTYPE => array(self::KEY_ATTRIBUTE => 'bodytype') - ); + protected $_mapping = [ + Horde_ActiveSync_Request_Settings::SETTINGS_APPLIESTOINTERNAL => [self::KEY_ATTRIBUTE => 'internal'], + Horde_ActiveSync_Request_Settings::SETTINGS_APPLIESTOEXTERNALKNOWN => [self::KEY_ATTRIBUTE => 'externalknown'], + Horde_ActiveSync_Request_Settings::SETTINGS_APPLIESTOEXTERNALUNKNOWN => [self::KEY_ATTRIBUTE => 'externalunknown'], + Horde_ActiveSync_Request_Settings::SETTINGS_ENABLED => [self::KEY_ATTRIBUTE => 'enabled'], + Horde_ActiveSync_Request_Settings::SETTINGS_REPLYMESSAGE => [self::KEY_ATTRIBUTE => 'reply'], + Horde_ActiveSync_Request_Settings::SETTINGS_BODYTYPE => [self::KEY_ATTRIBUTE => 'bodytype'], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'enabled' => false, 'reply' => false, 'bodytype' => false, - ); + ]; /** * Checks to see if we should send an empty value. diff --git a/lib/Horde/ActiveSync/Message/RecipientInformation.php b/lib/Horde/ActiveSync/Message/RecipientInformation.php index e499250e..d6eb6807 100644 --- a/lib/Horde/ActiveSync/Message/RecipientInformation.php +++ b/lib/Horde/ActiveSync/Message/RecipientInformation.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'email1address'), - Horde_ActiveSync_Message_Contact::FILEAS => array(self::KEY_ATTRIBUTE => 'fileas'), - Horde_ActiveSync_Message_Contact::ALIAS => array(self::KEY_ATTRIBUTE => 'alias'), - Horde_ActiveSync_Message_Contact::WEIGHTEDRANK => array(self::KEY_ATTRIBUTE => 'weightedrank'), - ); + protected $_mapping = [ + Horde_ActiveSync_Message_Contact::EMAIL1ADDRESS => [self::KEY_ATTRIBUTE => 'email1address'], + Horde_ActiveSync_Message_Contact::FILEAS => [self::KEY_ATTRIBUTE => 'fileas'], + Horde_ActiveSync_Message_Contact::ALIAS => [self::KEY_ATTRIBUTE => 'alias'], + Horde_ActiveSync_Message_Contact::WEIGHTEDRANK => [self::KEY_ATTRIBUTE => 'weightedrank'], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'email1address' => false, 'fileas' => false, 'alias' => false, 'weightedrank' => false, - ); + ]; /** * Return message type diff --git a/lib/Horde/ActiveSync/Message/Recurrence.php b/lib/Horde/ActiveSync/Message/Recurrence.php index c56422c0..22bc1683 100644 --- a/lib/Horde/ActiveSync/Message/Recurrence.php +++ b/lib/Horde/ActiveSync/Message/Recurrence.php @@ -1,4 +1,5 @@ array (self::KEY_ATTRIBUTE => 'type'), - Horde_ActiveSync_Message_Appointment::POOMCAL_UNTIL => array (self::KEY_ATTRIBUTE => 'until', self::KEY_TYPE => self::TYPE_DATE), - Horde_ActiveSync_Message_Appointment::POOMCAL_OCCURRENCES => array (self::KEY_ATTRIBUTE => 'occurrences'), - Horde_ActiveSync_Message_Appointment::POOMCAL_INTERVAL => array (self::KEY_ATTRIBUTE => 'interval'), - Horde_ActiveSync_Message_Appointment::POOMCAL_DAYOFWEEK => array (self::KEY_ATTRIBUTE => 'dayofweek'), - Horde_ActiveSync_Message_Appointment::POOMCAL_DAYOFMONTH => array (self::KEY_ATTRIBUTE => 'dayofmonth'), - Horde_ActiveSync_Message_Appointment::POOMCAL_WEEKOFMONTH => array (self::KEY_ATTRIBUTE => 'weekofmonth'), - Horde_ActiveSync_Message_Appointment::POOMCAL_MONTHOFYEAR => array (self::KEY_ATTRIBUTE => 'monthofyear') - ); + protected $_mapping = [ + Horde_ActiveSync_Message_Appointment::POOMCAL_TYPE => [self::KEY_ATTRIBUTE => 'type'], + Horde_ActiveSync_Message_Appointment::POOMCAL_UNTIL => [self::KEY_ATTRIBUTE => 'until', self::KEY_TYPE => self::TYPE_DATE], + Horde_ActiveSync_Message_Appointment::POOMCAL_OCCURRENCES => [self::KEY_ATTRIBUTE => 'occurrences'], + Horde_ActiveSync_Message_Appointment::POOMCAL_INTERVAL => [self::KEY_ATTRIBUTE => 'interval'], + Horde_ActiveSync_Message_Appointment::POOMCAL_DAYOFWEEK => [self::KEY_ATTRIBUTE => 'dayofweek'], + Horde_ActiveSync_Message_Appointment::POOMCAL_DAYOFMONTH => [self::KEY_ATTRIBUTE => 'dayofmonth'], + Horde_ActiveSync_Message_Appointment::POOMCAL_WEEKOFMONTH => [self::KEY_ATTRIBUTE => 'weekofmonth'], + Horde_ActiveSync_Message_Appointment::POOMCAL_MONTHOFYEAR => [self::KEY_ATTRIBUTE => 'monthofyear'], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'type' => false, 'until' => false, 'occurrences' => false, @@ -99,33 +100,33 @@ class Horde_ActiveSync_Message_Recurrence extends Horde_ActiveSync_Message_Base 'dayofmonth' => false, 'weekofmonth' => false, 'monthofyear' => false, - ); + ]; /** * Const'r * * @see Horde_ActiveSync_Message_Base::__construct() */ - public function __construct(array $options = array()) + public function __construct(array $options = []) { parent::__construct($options); if ($this->_version >= Horde_ActiveSync::VERSION_FOURTEEN) { - $this->_mapping += array( - Horde_ActiveSync_Message_Appointment::POOMCAL_CALENDARTYPE => array(self::KEY_ATTRIBUTE => 'calendartype'), - Horde_ActiveSync_Message_Appointment::POOMCAL_ISLEAPMONTH => array(self::KEY_ATTRIBUTE => 'isleapmonth')); + $this->_mapping += [ + Horde_ActiveSync_Message_Appointment::POOMCAL_CALENDARTYPE => [self::KEY_ATTRIBUTE => 'calendartype'], + Horde_ActiveSync_Message_Appointment::POOMCAL_ISLEAPMONTH => [self::KEY_ATTRIBUTE => 'isleapmonth']]; - $this->_properties += array( + $this->_properties += [ 'calendartype' => false, - 'isleapmonth' => false); + 'isleapmonth' => false]; } if ($this->_version >= Horde_ActiveSync::VERSION_FOURTEENONE) { - $this->_mapping += array( - Horde_ActiveSync_Message_Appointment::POOMCAL_FIRSTDAYOFWEEK => array(self::KEY_ATTRIBUTE => 'firstdayofweek') - ); - $this->_properties += array( - 'firstdayofweek' => false - ); + $this->_mapping += [ + Horde_ActiveSync_Message_Appointment::POOMCAL_FIRSTDAYOFWEEK => [self::KEY_ATTRIBUTE => 'firstdayofweek'], + ]; + $this->_properties += [ + 'firstdayofweek' => false, + ]; } } diff --git a/lib/Horde/ActiveSync/Message/ResolveRecipientsPicture.php b/lib/Horde/ActiveSync/Message/ResolveRecipientsPicture.php index f4fe6c8f..3f9db480 100644 --- a/lib/Horde/ActiveSync/Message/ResolveRecipientsPicture.php +++ b/lib/Horde/ActiveSync/Message/ResolveRecipientsPicture.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'status'), - Horde_ActiveSync_Request_ResolveRecipients::TAG_DATA => array(self::KEY_ATTRIBUTE => 'data', self::KEY_TYPE => 'opaque') - ); + protected $_mapping = [ + Horde_ActiveSync_Request_ResolveRecipients::TAG_STATUS => [self::KEY_ATTRIBUTE => 'status'], + Horde_ActiveSync_Request_ResolveRecipients::TAG_DATA => [self::KEY_ATTRIBUTE => 'data', self::KEY_TYPE => 'opaque'], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'status' => false, - 'data' => false - ); + 'data' => false, + ]; } diff --git a/lib/Horde/ActiveSync/Message/SendMail.php b/lib/Horde/ActiveSync/Message/SendMail.php index 86eda4a2..769298ed 100644 --- a/lib/Horde/ActiveSync/Message/SendMail.php +++ b/lib/Horde/ActiveSync/Message/SendMail.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'clientid'), - self::COMPOSEMAIL_SAVEINSENTITEMS => array(self::KEY_ATTRIBUTE => 'saveinsent'), - self::COMPOSEMAIL_REPLACEMIME => array(self::KEY_ATTRIBUTE => 'replacemime'), - self::COMPOSEMAIL_ACCOUNTID => array(self::KEY_ATTRIBUTE => 'accountid'), - self::COMPOSEMAIL_SOURCE => array(self::KEY_ATTRIBUTE => 'source', self::KEY_TYPE => 'Horde_ActiveSync_Message_SendMailSource'), - self::COMPOSEMAIL_MIME => array(self::KEY_ATTRIBUTE => 'mime'), - Horde_ActiveSync::RM_TEMPLATEID => array(self::KEY_ATTRIBUTE => 'templateid') - ); + protected $_mapping = [ + self::COMPOSEMAIL_CLIENTID => [self::KEY_ATTRIBUTE => 'clientid'], + self::COMPOSEMAIL_SAVEINSENTITEMS => [self::KEY_ATTRIBUTE => 'saveinsent'], + self::COMPOSEMAIL_REPLACEMIME => [self::KEY_ATTRIBUTE => 'replacemime'], + self::COMPOSEMAIL_ACCOUNTID => [self::KEY_ATTRIBUTE => 'accountid'], + self::COMPOSEMAIL_SOURCE => [self::KEY_ATTRIBUTE => 'source', self::KEY_TYPE => 'Horde_ActiveSync_Message_SendMailSource'], + self::COMPOSEMAIL_MIME => [self::KEY_ATTRIBUTE => 'mime'], + Horde_ActiveSync::RM_TEMPLATEID => [self::KEY_ATTRIBUTE => 'templateid'], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'clientid' => false, 'saveinsent' => false, 'replacemime' => false, @@ -96,23 +97,23 @@ class Horde_ActiveSync_Message_SendMail extends Horde_ActiveSync_Message_Base 'source' => false, 'mime' => false, 'templateid' => false, - ); + ]; /** * Const'r * * @see Horde_ActiveSync_Message_Base::__construct() */ - public function __construct(array $options = array()) + public function __construct(array $options = []) { parent::__construct($options); if ($this->_version >= Horde_ActiveSync::VERSION_SIXTEEN) { - $this->_mapping += array( - self::COMPOSEMAIL_FORWARDEES => array(self::KEY_ATTRIBUTE => 'forwardees', self::KEY_TYPE => 'Horde_ActiveSync_Message_Forwardee', self::KEY_VALUES => self::COMPOSEMAIL_FORWARDEE), - ); - $this->_properties += array( - 'forwardees' => false - ); + $this->_mapping += [ + self::COMPOSEMAIL_FORWARDEES => [self::KEY_ATTRIBUTE => 'forwardees', self::KEY_TYPE => 'Horde_ActiveSync_Message_Forwardee', self::KEY_VALUES => self::COMPOSEMAIL_FORWARDEE], + ]; + $this->_properties += [ + 'forwardees' => false, + ]; } } @@ -122,10 +123,10 @@ public function &__get($property) // present. // Deal with the empty tags that are considered true if they are present switch ($property) { - case 'saveinsent': - case 'replacemime': - $return = $this->_properties[$property] !== false; - return $return; + case 'saveinsent': + case 'replacemime': + $return = $this->_properties[$property] !== false; + return $return; } return parent::__get($property); @@ -150,8 +151,8 @@ public function getClass() */ protected function _checkSendEmpty($tag) { - if ($tag == self::COMPOSEMAIL_SAVEINSENTITEMS || - $tag == self::COMPOSEMAIL_REPLACEMIME) { + if ($tag == self::COMPOSEMAIL_SAVEINSENTITEMS + || $tag == self::COMPOSEMAIL_REPLACEMIME) { return true; } diff --git a/lib/Horde/ActiveSync/Message/SendMailSource.php b/lib/Horde/ActiveSync/Message/SendMailSource.php index cf8d3a1f..f46988b0 100644 --- a/lib/Horde/ActiveSync/Message/SendMailSource.php +++ b/lib/Horde/ActiveSync/Message/SendMailSource.php @@ -1,4 +1,5 @@ array(self::KEY_ATTRIBUTE => 'folderid'), - self::COMPOSEMAIL_ITEMID => array(self::KEY_ATTRIBUTE => 'itemid'), - self::COMPOSEMAIL_LONGID => array(self::KEY_ATTRIBUTE => 'longid'), - self::COMPOSEMAIL_INSTANCEID => array(self::KEY_ATTRIBUTE => 'instanceid') - ); + protected $_mapping = [ + self::COMPOSEMAIL_FOLDERID => [self::KEY_ATTRIBUTE => 'folderid'], + self::COMPOSEMAIL_ITEMID => [self::KEY_ATTRIBUTE => 'itemid'], + self::COMPOSEMAIL_LONGID => [self::KEY_ATTRIBUTE => 'longid'], + self::COMPOSEMAIL_INSTANCEID => [self::KEY_ATTRIBUTE => 'instanceid'], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'folderid' => false, 'itemid' => false, 'longid' => false, 'instanceid' => false, - ); + ]; /** * Return this object's folder class diff --git a/lib/Horde/ActiveSync/Message/Task.php b/lib/Horde/ActiveSync/Message/Task.php index 0a07daf8..551d9f2a 100644 --- a/lib/Horde/ActiveSync/Message/Task.php +++ b/lib/Horde/ActiveSync/Message/Task.php @@ -1,4 +1,5 @@ Horde_Date::MASK_SUNDAY, Horde_Date::DATE_MONDAY => Horde_Date::MASK_MONDAY, Horde_Date::DATE_TUESDAY => Horde_Date::MASK_TUESDAY, @@ -108,38 +109,38 @@ class Horde_ActiveSync_Message_Task extends Horde_ActiveSync_Message_Base Horde_Date::DATE_THURSDAY => Horde_Date::MASK_THURSDAY, Horde_Date::DATE_FRIDAY => Horde_Date::MASK_FRIDAY, Horde_Date::DATE_SATURDAY => Horde_Date::MASK_SATURDAY, - ); + ]; /** * Property mapping * * @var array */ - protected $_mapping = array ( - self::POOMTASKS_COMPLETE => array (self::KEY_ATTRIBUTE => 'complete'), - self::POOMTASKS_DATECOMPLETED => array (self::KEY_ATTRIBUTE => 'datecompleted', self::KEY_TYPE => self::TYPE_DATE_DASHES), - self::POOMTASKS_DUEDATE => array (self::KEY_ATTRIBUTE => 'duedate', self::KEY_TYPE => self::TYPE_DATE_LOCAL), - self::POOMTASKS_UTCDUEDATE => array (self::KEY_ATTRIBUTE => 'utcduedate', self::KEY_TYPE => self::TYPE_DATE_DASHES), - self::POOMTASKS_IMPORTANCE => array (self::KEY_ATTRIBUTE => 'importance'), - self::POOMTASKS_RECURRENCE => array (self::KEY_ATTRIBUTE => 'recurrence', self::KEY_TYPE => 'Horde_ActiveSync_Message_TaskRecurrence'), - self::POOMTASKS_REMINDERSET => array (self::KEY_ATTRIBUTE => 'reminderset'), - self::POOMTASKS_REMINDERTIME => array (self::KEY_ATTRIBUTE => 'remindertime', self::KEY_TYPE => self::TYPE_DATE_DASHES), - self::POOMTASKS_SENSITIVITY => array (self::KEY_ATTRIBUTE => 'sensitiviy'), - self::POOMTASKS_STARTDATE => array (self::KEY_ATTRIBUTE => 'startdate', self::KEY_TYPE => self::TYPE_DATE_LOCAL), - self::POOMTASKS_UTCSTARTDATE => array (self::KEY_ATTRIBUTE => 'utcstartdate', self::KEY_TYPE => self::TYPE_DATE_DASHES), - self::POOMTASKS_SUBJECT => array (self::KEY_ATTRIBUTE => 'subject'), - self::POOMTASKS_CATEGORIES => array (self::KEY_ATTRIBUTE => 'categories', self::KEY_VALUES => self::POOMTASKS_CATEGORY), - ); + protected $_mapping = [ + self::POOMTASKS_COMPLETE => [self::KEY_ATTRIBUTE => 'complete'], + self::POOMTASKS_DATECOMPLETED => [self::KEY_ATTRIBUTE => 'datecompleted', self::KEY_TYPE => self::TYPE_DATE_DASHES], + self::POOMTASKS_DUEDATE => [self::KEY_ATTRIBUTE => 'duedate', self::KEY_TYPE => self::TYPE_DATE_LOCAL], + self::POOMTASKS_UTCDUEDATE => [self::KEY_ATTRIBUTE => 'utcduedate', self::KEY_TYPE => self::TYPE_DATE_DASHES], + self::POOMTASKS_IMPORTANCE => [self::KEY_ATTRIBUTE => 'importance'], + self::POOMTASKS_RECURRENCE => [self::KEY_ATTRIBUTE => 'recurrence', self::KEY_TYPE => 'Horde_ActiveSync_Message_TaskRecurrence'], + self::POOMTASKS_REMINDERSET => [self::KEY_ATTRIBUTE => 'reminderset'], + self::POOMTASKS_REMINDERTIME => [self::KEY_ATTRIBUTE => 'remindertime', self::KEY_TYPE => self::TYPE_DATE_DASHES], + self::POOMTASKS_SENSITIVITY => [self::KEY_ATTRIBUTE => 'sensitiviy'], + self::POOMTASKS_STARTDATE => [self::KEY_ATTRIBUTE => 'startdate', self::KEY_TYPE => self::TYPE_DATE_LOCAL], + self::POOMTASKS_UTCSTARTDATE => [self::KEY_ATTRIBUTE => 'utcstartdate', self::KEY_TYPE => self::TYPE_DATE_DASHES], + self::POOMTASKS_SUBJECT => [self::KEY_ATTRIBUTE => 'subject'], + self::POOMTASKS_CATEGORIES => [self::KEY_ATTRIBUTE => 'categories', self::KEY_VALUES => self::POOMTASKS_CATEGORY], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'subject' => false, 'importance' => false, - 'categories' => array(), + 'categories' => [], 'startdate' => false, 'duedate' => false, 'utcduedate' => false, @@ -153,36 +154,36 @@ class Horde_ActiveSync_Message_Task extends Horde_ActiveSync_Message_Base 'regenerate' => false, 'sensitiviy' => false, 'utcstartdate' => false, - ); + ]; /** * Const'r * * @see Horde_ActiveSync_Message_Base::__construct() */ - public function __construct(array $options = array()) + public function __construct(array $options = []) { parent::__construct($options); if ($this->_version < Horde_ActiveSync::VERSION_TWELVE) { - $this->_mapping += array( - self::POOMTASKS_BODY => array(self::KEY_ATTRIBUTE => 'body'), - self::POOMTASKS_RTF => array(self::KEY_ATTRIBUTE => 'rtf'), - self::POOMTASKS_BODYTRUNCATED => array(self::KEY_ATTRIBUTE => 'bodytruncated') - ); + $this->_mapping += [ + self::POOMTASKS_BODY => [self::KEY_ATTRIBUTE => 'body'], + self::POOMTASKS_RTF => [self::KEY_ATTRIBUTE => 'rtf'], + self::POOMTASKS_BODYTRUNCATED => [self::KEY_ATTRIBUTE => 'bodytruncated'], + ]; - $this->_properties += array( + $this->_properties += [ 'body' => false, 'rtf' => false, 'bodytruncated' => 0, - ); + ]; } else { - $this->_mapping += array( - Horde_ActiveSync::AIRSYNCBASE_BODY => array(self::KEY_ATTRIBUTE => 'airsyncbasebody', self::KEY_TYPE=> 'Horde_ActiveSync_Message_AirSyncBaseBody'), - ); + $this->_mapping += [ + Horde_ActiveSync::AIRSYNCBASE_BODY => [self::KEY_ATTRIBUTE => 'airsyncbasebody', self::KEY_TYPE => 'Horde_ActiveSync_Message_AirSyncBaseBody'], + ]; - $this->_properties += array( + $this->_properties += [ 'airsyncbasebody' => false, - ); + ]; } } @@ -245,31 +246,31 @@ public function setRecurrence(Horde_Date_Recurrence $recurrence) // Map the type fields switch ($recurrence->recurType) { - case Horde_Date_Recurrence::RECUR_DAILY: - $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_DAILY; - break; - case Horde_Date_Recurrence::RECUR_WEEKLY: - $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_WEEKLY; - $r->dayofweek = $recurrence->getRecurOnDays(); - break; - case Horde_Date_Recurrence::RECUR_MONTHLY_DATE: - $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY; - $r->dayofmonth = $recurrence->start->mday; - break; - case Horde_Date_Recurrence::RECUR_MONTHLY_WEEKDAY; - $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY_NTH; - $r->weekofmonth = ceil($recurrence->start->mday / 7); - $r->dayofweek = $this->_dayOfWeekMap[$recurrence->start->dayOfWeek()]; - break; - case Horde_Date_Recurrence::RECUR_YEARLY_DATE: - $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_YEARLY; - break; - case Horde_Date_Recurrence::RECUR_YEARLY_WEEKDAY: - $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_YEARLYNTH; - $r->dayofweek = $this->_dayOfWeekMap[$recurrence->start->dayOfWeek()]; - $r->weekofmonth = ceil($recurrence->start->mday / 7); - $r->monthofyear = $recurrence->start->month; - break; + case Horde_Date_Recurrence::RECUR_DAILY: + $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_DAILY; + break; + case Horde_Date_Recurrence::RECUR_WEEKLY: + $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_WEEKLY; + $r->dayofweek = $recurrence->getRecurOnDays(); + break; + case Horde_Date_Recurrence::RECUR_MONTHLY_DATE: + $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY; + $r->dayofmonth = $recurrence->start->mday; + break; + case Horde_Date_Recurrence::RECUR_MONTHLY_WEEKDAY: + $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY_NTH; + $r->weekofmonth = ceil($recurrence->start->mday / 7); + $r->dayofweek = $this->_dayOfWeekMap[$recurrence->start->dayOfWeek()]; + break; + case Horde_Date_Recurrence::RECUR_YEARLY_DATE: + $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_YEARLY; + break; + case Horde_Date_Recurrence::RECUR_YEARLY_WEEKDAY: + $r->type = Horde_ActiveSync_Message_Recurrence::TYPE_YEARLYNTH; + $r->dayofweek = $this->_dayOfWeekMap[$recurrence->start->dayOfWeek()]; + $r->weekofmonth = ceil($recurrence->start->mday / 7); + $r->monthofyear = $recurrence->start->month; + break; } if (!empty($recurrence->recurInterval)) { $r->interval = $recurrence->recurInterval; @@ -307,27 +308,27 @@ public function getRecurrence() /* Map MS AS type field to Horde_Date_Recurrence types */ switch ($recurrence->type) { - case Horde_ActiveSync_Message_Recurrence::TYPE_DAILY: - $rrule->setRecurType(Horde_Date_Recurrence::RECUR_DAILY); - break; - case Horde_ActiveSync_Message_Recurrence::TYPE_WEEKLY: - $rrule->setRecurType(Horde_Date_Recurrence::RECUR_WEEKLY); - $rrule->setRecurOnDay($recurrence->dayofweek); - break; - case Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY: - $rrule->setRecurType(Horde_Date_Recurrence::RECUR_MONTHLY_DATE); - break; - case Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY_NTH: - $rrule->setRecurType(Horde_Date_Recurrence::RECUR_MONTHLY_WEEKDAY); - $rrule->setRecurOnDay($recurrence->dayofweek); - break; - case Horde_ActiveSync_Message_Recurrence::TYPE_YEARLY: - $rrule->setRecurType(Horde_Date_Recurrence::RECUR_YEARLY_DATE); - break; - case Horde_ActiveSync_Message_Recurrence::TYPE_YEARLYNTH: - $rrule->setRecurType(Horde_Date_Recurrence::RECUR_YEARLY_WEEKDAY); - $rrule->setRecurOnDay($recurrence->dayofweek); - break; + case Horde_ActiveSync_Message_Recurrence::TYPE_DAILY: + $rrule->setRecurType(Horde_Date_Recurrence::RECUR_DAILY); + break; + case Horde_ActiveSync_Message_Recurrence::TYPE_WEEKLY: + $rrule->setRecurType(Horde_Date_Recurrence::RECUR_WEEKLY); + $rrule->setRecurOnDay($recurrence->dayofweek); + break; + case Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY: + $rrule->setRecurType(Horde_Date_Recurrence::RECUR_MONTHLY_DATE); + break; + case Horde_ActiveSync_Message_Recurrence::TYPE_MONTHLY_NTH: + $rrule->setRecurType(Horde_Date_Recurrence::RECUR_MONTHLY_WEEKDAY); + $rrule->setRecurOnDay($recurrence->dayofweek); + break; + case Horde_ActiveSync_Message_Recurrence::TYPE_YEARLY: + $rrule->setRecurType(Horde_Date_Recurrence::RECUR_YEARLY_DATE); + break; + case Horde_ActiveSync_Message_Recurrence::TYPE_YEARLYNTH: + $rrule->setRecurType(Horde_Date_Recurrence::RECUR_YEARLY_WEEKDAY); + $rrule->setRecurOnDay($recurrence->dayofweek); + break; } if ($rcnt = $recurrence->occurrences) { diff --git a/lib/Horde/ActiveSync/Message/TaskRecurrence.php b/lib/Horde/ActiveSync/Message/TaskRecurrence.php index 6715c825..515abe42 100644 --- a/lib/Horde/ActiveSync/Message/TaskRecurrence.php +++ b/lib/Horde/ActiveSync/Message/TaskRecurrence.php @@ -1,4 +1,5 @@ array (self::KEY_ATTRIBUTE => 'regenerate'), - Horde_ActiveSync_Message_Task::POOMTASKS_INTERVAL => array(self::KEY_ATTRIBUTE => 'interval'), - Horde_ActiveSync_Message_Task::POOMTASKS_START => array(self::KEY_ATTRIBUTE => 'start', self::KEY_TYPE => self::TYPE_DATE_DASHES), - Horde_ActiveSync_Message_Task::POOMTASKS_TYPE => array(self::KEY_ATTRIBUTE => 'type'), - Horde_ActiveSync_Message_Task::POOMTASKS_UNTIL => array(self::KEY_ATTRIBUTE => 'until', self::KEY_TYPE => self::TYPE_DATE_DASHES), - Horde_ActiveSync_Message_Task::POOMTASKS_OCCURRENCES => array(self::KEY_ATTRIBUTE => 'occurrences'), - Horde_ActiveSync_Message_Task::POOMTASKS_DAYOFWEEK => array(self::KEY_ATTRIBUTE => 'dayofweek'), - Horde_ActiveSync_Message_Task::POOMTASKS_DAYOFMONTH => array(self::KEY_ATTRIBUTE => 'dayofmonth'), - Horde_ActiveSync_Message_Task::POOMTASKS_WEEKOFMONTH => array(self::KEY_ATTRIBUTE => 'weekofmonth'), - Horde_ActiveSync_Message_Task::POOMTASKS_MONTHOFYEAR => array(self::KEY_ATTRIBUTE => 'monthofyear'), - Horde_ActiveSync_Message_Task::POOMTASKS_DEADOCCUR => array (self::KEY_ATTRIBUTE => 'deadoccur'), - Horde_ActiveSync_Message_Task::POOMTASKS_CALENDARTYPE => array(self::KEY_ATTRIBUTE => 'calendartype'), - Horde_ActiveSync_Message_Task::POOMTASKS_ISLEAPMONTH => array(self::KEY_ATTRIBUTE => 'isleapmonth'), - Horde_ActiveSync_Message_Task::POOMTASKS_FIRSTDAYOFWEEK => array(self::KEY_ATTRIBUTE => 'firstdayofweek'), - ); + protected $_mapping = [ + Horde_ActiveSync_Message_Task::POOMTASKS_REGENERATE => [self::KEY_ATTRIBUTE => 'regenerate'], + Horde_ActiveSync_Message_Task::POOMTASKS_INTERVAL => [self::KEY_ATTRIBUTE => 'interval'], + Horde_ActiveSync_Message_Task::POOMTASKS_START => [self::KEY_ATTRIBUTE => 'start', self::KEY_TYPE => self::TYPE_DATE_DASHES], + Horde_ActiveSync_Message_Task::POOMTASKS_TYPE => [self::KEY_ATTRIBUTE => 'type'], + Horde_ActiveSync_Message_Task::POOMTASKS_UNTIL => [self::KEY_ATTRIBUTE => 'until', self::KEY_TYPE => self::TYPE_DATE_DASHES], + Horde_ActiveSync_Message_Task::POOMTASKS_OCCURRENCES => [self::KEY_ATTRIBUTE => 'occurrences'], + Horde_ActiveSync_Message_Task::POOMTASKS_DAYOFWEEK => [self::KEY_ATTRIBUTE => 'dayofweek'], + Horde_ActiveSync_Message_Task::POOMTASKS_DAYOFMONTH => [self::KEY_ATTRIBUTE => 'dayofmonth'], + Horde_ActiveSync_Message_Task::POOMTASKS_WEEKOFMONTH => [self::KEY_ATTRIBUTE => 'weekofmonth'], + Horde_ActiveSync_Message_Task::POOMTASKS_MONTHOFYEAR => [self::KEY_ATTRIBUTE => 'monthofyear'], + Horde_ActiveSync_Message_Task::POOMTASKS_DEADOCCUR => [self::KEY_ATTRIBUTE => 'deadoccur'], + Horde_ActiveSync_Message_Task::POOMTASKS_CALENDARTYPE => [self::KEY_ATTRIBUTE => 'calendartype'], + Horde_ActiveSync_Message_Task::POOMTASKS_ISLEAPMONTH => [self::KEY_ATTRIBUTE => 'isleapmonth'], + Horde_ActiveSync_Message_Task::POOMTASKS_FIRSTDAYOFWEEK => [self::KEY_ATTRIBUTE => 'firstdayofweek'], + ]; /** * Property values. * * @var array */ - protected $_properties = array( + protected $_properties = [ 'type' => false, 'start' => false, 'until' => false, @@ -101,6 +102,6 @@ class Horde_ActiveSync_Message_TaskRecurrence extends Horde_ActiveSync_Message_B 'calendartype' => false, 'isleapmonth' => false, 'firstdayofweek' => false, - ); + ]; } diff --git a/lib/Horde/ActiveSync/Mime.php b/lib/Horde/ActiveSync/Mime.php index 31ecafe8..def0390a 100644 --- a/lib/Horde/ActiveSync/Mime.php +++ b/lib/Horde/ActiveSync/Mime.php @@ -1,4 +1,5 @@ _base; + case 'base': + return $this->_base; } return $this->_base->property; } @@ -77,8 +78,8 @@ public function __get($property) */ public function __call($method, array $params) { - if (is_callable(array($this->_base, $method))) { - return call_user_func_array(array($this->_base, $method), $params); + if (is_callable([$this->_base, $method])) { + return call_user_func_array([$this->_base, $method], $params); } throw new InvalidArgumentException(); @@ -121,36 +122,36 @@ public function hasAttachments() public function isAttachment($id, $mime_type) { switch ($mime_type) { - case 'text/plain': - if (!($this->_base->findBody('plain') == $id)) { - return true; - } - return false; - case 'text/html': - if (!($this->_base->findBody('html') == $id)) { - return true; - } - return false; - case 'application/pkcs7-signature': - case 'application/x-pkcs7-signature': - return false; + case 'text/plain': + if (!($this->_base->findBody('plain') == $id)) { + return true; + } + return false; + case 'text/html': + if (!($this->_base->findBody('html') == $id)) { + return true; + } + return false; + case 'application/pkcs7-signature': + case 'application/x-pkcs7-signature': + return false; } if ($this->_base->getPart($id)->getDisposition() == 'attachment') { return true; } - list($ptype,) = explode('/', $mime_type, 2); + [$ptype, ] = explode('/', $mime_type, 2); switch ($ptype) { - case 'message': - return in_array($mime_type, array('message/rfc822', 'message/disposition-notification')); + case 'message': + return in_array($mime_type, ['message/rfc822', 'message/disposition-notification']); - case 'multipart': - return false; + case 'multipart': + return false; - default: - return true; + default: + return true; } } @@ -181,7 +182,7 @@ public function hasiCalendar() * * @return boolean True if message is S/MIME signed, otherwise false. */ - public function isSigned(Horde_Mime_Part $mime = null) + public function isSigned(?Horde_Mime_Part $mime = null) { if (empty($mime)) { $mime = $this->_base; @@ -213,14 +214,14 @@ public function isSigned(Horde_Mime_Part $mime = null) * @todo For 3.0, combine into one method with self::isSigned() and return * a bitmask result. */ - public function isEncrypted(Horde_Mime_Part $mime = null) + public function isEncrypted(?Horde_Mime_Part $mime = null) { if (empty($mime)) { $mime = $this->_base; } - if ($mime->getType() == 'application/pkcs7-mime' || - $mime->getType() == 'application/x-pkcs7-mime') { + if ($mime->getType() == 'application/pkcs7-mime' + || $mime->getType() == 'application/x-pkcs7-mime') { return true; } @@ -250,10 +251,10 @@ public function findBody($subtype = null) $iterator = new Horde_ActiveSync_Mime_Iterator($this->_base, true); foreach ($iterator as $val) { $id = $val->getMimeId(); - if (($val->getPrimaryType() == 'text') && - ((intval($id) === 1) || !$this->getMimeId()) && - (is_null($subtype) || ($val->getSubType() == $subtype)) && - !$this->isAttachment($id, $val->getType())) { + if (($val->getPrimaryType() == 'text') + && ((intval($id) === 1) || !$this->getMimeId()) + && (is_null($subtype) || ($val->getSubType() == $subtype)) + && !$this->isAttachment($id, $val->getType())) { return $id; } } diff --git a/lib/Horde/ActiveSync/Mime/Headers/Addresses.php b/lib/Horde/ActiveSync/Mime/Headers/Addresses.php index 6fb0d386..23a73609 100644 --- a/lib/Horde/ActiveSync/Mime/Headers/Addresses.php +++ b/lib/Horde/ActiveSync/Mime/Headers/Addresses.php @@ -1,25 +1,26 @@ getMimeId(); $mime_type = $part->getType(); switch ($mime_type) { - case 'text/plain': - if (!($this->_part->findBody('plain') == $id)) { - return true; - } - return false; - case 'text/html': - if (!($this->_part->findBody('html') == $id)) { - return true; - } - return false; - case 'application/pkcs7-signature': - case 'application/x-pkcs7-signature': - return false; + case 'text/plain': + if (!($this->_part->findBody('plain') == $id)) { + return true; + } + return false; + case 'text/html': + if (!($this->_part->findBody('html') == $id)) { + return true; + } + return false; + case 'application/pkcs7-signature': + case 'application/x-pkcs7-signature': + return false; } - list($ptype,) = explode('/', $mime_type, 2); + [$ptype, ] = explode('/', $mime_type, 2); switch ($ptype) { - case 'message': - return in_array($mime_type, array('message/rfc822', 'message/disposition-notification')); + case 'message': + return in_array($mime_type, ['message/rfc822', 'message/disposition-notification']); - case 'multipart': - return false; + case 'multipart': + return false; - default: - return true; + default: + return true; } } @@ -118,7 +118,7 @@ protected function _isAttachment($part) */ protected function _allowRecursion($part) { - return !in_array($part->getType(), array('message/rfc822')); + return !in_array($part->getType(), ['message/rfc822']); } /* RecursiveIterator methods. */ @@ -151,14 +151,14 @@ public function next() $out = $this->_state->current->getPartByIndex($this->_state->index++); if ($out) { - if (($this->_ignoreAttachments && $this->_isAttachment($out)) || - !$this->_allowRecursion($this->_state->current)) { + if (($this->_ignoreAttachments && $this->_isAttachment($out)) + || !$this->_allowRecursion($this->_state->current)) { return $this->next(); } - $this->_state->recurse[] = array( + $this->_state->recurse[] = [ $this->_state->current, - $this->_state->index - ); + $this->_state->index, + ]; $this->_state->current = $out; $this->_state->index = 0; @@ -175,10 +175,10 @@ public function next() */ public function rewind() { - $this->_state = new stdClass; + $this->_state = new stdClass(); $this->_state->current = $this->_part; $this->_state->index = 0; - $this->_state->recurse = array(); + $this->_state->recurse = []; } /** diff --git a/lib/Horde/ActiveSync/Policies.php b/lib/Horde/ActiveSync/Policies.php index d30b6abf..e91008c8 100644 --- a/lib/Horde/ActiveSync/Policies.php +++ b/lib/Horde/ActiveSync/Policies.php @@ -1,4 +1,5 @@ false, self::POLICY_AEFVALUE => '0', self::POLICY_MAXFAILEDATTEMPTS => '5', self::POLICY_CODEFREQ => '0', self::POLICY_MINLENGTH => '5', - ); + ]; /** * Deafaults for 12.0 policies. * * @var array */ - protected $_defaults_twelve = array( + protected $_defaults_twelve = [ self::POLICY_ATC => '1', self::POLICY_ENCRYPTION => '0', self::POLICY_MAXATCSIZE => '5000000', @@ -77,14 +78,14 @@ class Horde_ActiveSync_Policies //self::POLICY_PWDRECOVERY => '0', //self::POLICY_PWDEXPIRATION => '0', //self::POLICY_PWDHISTORY => '0', - ); + ]; /** * Defaults used only in 12.1 * * @var array */ - protected $_defaults_twelveone = array( + protected $_defaults_twelveone = [ // 1 == Allow/Yes, 0 == Disallow/No. self::POLICY_ALLOW_SDCARD => '1', self::POLICY_ALLOW_CAMERA => '1', @@ -99,7 +100,7 @@ class Horde_ActiveSync_Policies self::POLICY_ALLOW_HTML => '1', self::POLICY_MAX_EMAIL_AGE => '0', self::POLICY_ROAMING_NOPUSH => '0', - ); + ]; /** * Explicitly set policies. @@ -127,7 +128,7 @@ class Horde_ActiveSync_Policies * * @var array */ - protected $_policies = array(); + protected $_policies = []; /** * Const'r @@ -137,10 +138,10 @@ class Horde_ActiveSync_Policies * @param array $policies The policy array. */ public function __construct( - Horde_ActiveSync_Wbxml_Encoder $encoder = null, + ?Horde_ActiveSync_Wbxml_Encoder $encoder = null, $version = Horde_ActiveSync::VERSION_TWELVEONE, - array $policies = array()) - { + array $policies = [] + ) { $this->_encoder = $encoder; if ($version >= Horde_ActiveSync::VERSION_TWELVE) { $this->_defaults = array_merge($this->_defaults, $this->_defaults_twelve); @@ -177,8 +178,8 @@ public function validatePolicyVersion() // Validate the version against the required policies. if ($this->_version < Horde_ActiveSync::VERSION_TWELVEONE) { foreach ($policies as $key => $value) { - if (!empty($this->_defaults_twelveone[$key]) && - $this->_defaults_twelveone[$key] != $value) { + if (!empty($this->_defaults_twelveone[$key]) + && $this->_defaults_twelveone[$key] != $value) { return false; } @@ -207,10 +208,10 @@ public function toXml() . ''; if ($policies[self::POLICY_PIN]) { $xml .= '' - . '' - . '' - . (!empty($policies[self::POLICY_AEFVALUE]) ? '' : '') - . ''; + . '' + . '' + . (!empty($policies[self::POLICY_AEFVALUE]) ? '' : '') + . ''; if (!empty($policies[self::POLICY_MAXFAILEDATTEMPTS])) { $xml .= ''; @@ -287,10 +288,10 @@ protected function _sendPolicy($policy, $value, $nodefault = false) if ($nodefault && $value == $this->_defaults[$policy]) { return; } - if ($value === false) { + if ($value === false) { $value = 0; } elseif ($value === true) { - $value = 1; + $value = 1; } $this->_encoder->startTag('Provision:' . $policy); $this->_encoder->content($value); diff --git a/lib/Horde/ActiveSync/Request/Autodiscover.php b/lib/Horde/ActiveSync/Request/Autodiscover.php index 4fc333ca..2635011e 100644 --- a/lib/Horde/ActiveSync/Request/Autodiscover.php +++ b/lib/Horde/ActiveSync/Request/Autodiscover.php @@ -1,4 +1,5 @@ $request->getGetVars()['Protocol']); - $results = $this->_driver->autoDiscover($params, 2); - if (!empty($results['url'])) { - $this->_encoder->getStream()->add('{"Protocol": "' . $params['protocol'] . '", "Url": "' . $results['url'] . '"}'); - } - return 'application/json'; + $params = ['protocol' => $request->getGetVars()['Protocol']]; + $results = $this->_driver->autoDiscover($params, 2); + if (!empty($results['url'])) { + $this->_encoder->getStream()->add('{"Protocol": "' . $params['protocol'] . '", "Url": "' . $results['url'] . '"}'); + } + return 'application/json'; } xml_parse_into_struct( - $parser, - $this->_decoder->getStream()->getString(), - $values); + $parser, + $this->_decoder->getStream()->getString(), + $values + ); // Obtain the credentials sent by the client. // NOTE: Some broken clients *cough* android *cough* don't send the @@ -66,7 +68,7 @@ public function handle(Horde_Controller_Request $request = null) } if (!empty($values)) { - $params = array('request_schema' => trim($values[0]['attributes']['XMLNS'])); + $params = ['request_schema' => trim($values[0]['attributes']['XMLNS'])]; // Response Schema is not in a set place. foreach ($values as $value) { if ($value['tag'] == 'ACCEPTABLERESPONSESCHEMA') { @@ -76,10 +78,10 @@ public function handle(Horde_Controller_Request $request = null) } } else { // Assume broken clients want these schemas. - $params = array( - 'request_schema' => 'http://schemas.microsoft.com/exchange/autodiscover/mobilesync/requestschema/2006', - 'response_schema' => 'http://schemas.microsoft.com/exchange/autodiscover/mobilesync/responseschema/2006' - ); + $params = [ + 'request_schema' => 'http://schemas.microsoft.com/exchange/autodiscover/mobilesync/requestschema/2006', + 'response_schema' => 'http://schemas.microsoft.com/exchange/autodiscover/mobilesync/responseschema/2006', + ]; } $results = $this->_driver->autoDiscover($params); if (empty($results['raw_xml'])) { @@ -95,9 +97,7 @@ public function handle(Horde_Controller_Request $request = null) /** * Noop. This class overrides the handle method. */ - protected function _handle() - { - } + protected function _handle() {} /** * Build the appropriate response string to send back to the client. @@ -122,8 +122,8 @@ protected function _handle() protected function _buildResponseString($properties) { // Default response is for mobilesync. - if (empty($properties['request_schema']) || - stripos($properties['request_schema'], 'autodiscover/mobilesync') !== false) { + if (empty($properties['request_schema']) + || stripos($properties['request_schema'], 'autodiscover/mobilesync') !== false) { return ' @@ -202,23 +202,23 @@ protected function _buildResponseString($properties) return $xml; } else { - // Unknown request. - return $this->_buildFailureResponse($properties['email'], '600', $properties['response_schema']); + // Unknown request. + return $this->_buildFailureResponse($properties['email'], '600', $properties['response_schema']); } } protected function _getEncryptionValue($type, $properties) { - if (!empty($properties[$type]['encryption'])) { - return '' . $properties[$type]['encryption'] . ''; - } - // Older version of autodiscover. - if (!empty($properties[$type]['ssl'])) { - return 'SSL'; - } - - // None specified. - return 'None'; + if (!empty($properties[$type]['encryption'])) { + return '' . $properties[$type]['encryption'] . ''; + } + // Older version of autodiscover. + if (!empty($properties[$type]['ssl'])) { + return 'SSL'; + } + + // None specified. + return 'None'; } /** diff --git a/lib/Horde/ActiveSync/Request/Base.php b/lib/Horde/ActiveSync/Request/Base.php index 877aaa7c..75b79ce7 100644 --- a/lib/Horde/ActiveSync/Request/Base.php +++ b/lib/Horde/ActiveSync/Request/Base.php @@ -1,4 +1,5 @@ _logger->meta(sprintf( 'Checking policykey for device: %s user: %s', $this->_device->id, - $this->_driver->getUser())); + $this->_driver->getUser() + )); // Use looseprovisioning? - if (empty($sentKey) && !$this->_device->enforceProvisioning() && - $this->_provisioning === Horde_ActiveSync::PROVISIONING_LOOSE) { + if (empty($sentKey) && !$this->_device->enforceProvisioning() + && $this->_provisioning === Horde_ActiveSync::PROVISIONING_LOOSE) { $sentKey = null; - $this->_logger->meta(sprintf( - 'Allowing %s to connect since PROVISIONING_LOOSE is true and device is either non-provisionable or has broken provisioning.', - $this->_device->id) + $this->_logger->meta( + sprintf( + 'Allowing %s to connect since PROVISIONING_LOOSE is true and device is either non-provisionable or has broken provisioning.', + $this->_device->id + ) ); } elseif (empty($sentKey) && $this->_device->isNonProvisionable()) { // Check for non-provisionable, but allowable, devices. - $this->_logger->meta(sprintf( - 'Allowing %s to connect since it is non-provisionable.', - $this->_device->id) + $this->_logger->meta( + sprintf( + 'Allowing %s to connect since it is non-provisionable.', + $this->_device->id + ) ); $sentKey = null; } @@ -185,9 +191,9 @@ public function checkPolicyKey($sentKey, $requestType = null) // Validate the stored key against the device key, honoring // the value of _provisioning. - if ((empty($storedKey) || $storedKey != $sentKey) && - ($this->_provisioning != Horde_ActiveSync::PROVISIONING_LOOSE || - ($this->_provisioning == Horde_ActiveSync::PROVISIONING_LOOSE && !is_null($sentKey)))) { + if ((empty($storedKey) || $storedKey != $sentKey) + && ($this->_provisioning != Horde_ActiveSync::PROVISIONING_LOOSE + || ($this->_provisioning == Horde_ActiveSync::PROVISIONING_LOOSE && !is_null($sentKey)))) { // We send the headers AND the WBXML if EAS 12.1+ since some // devices report EAS 14.1 but don't accept the WBXML. @@ -228,17 +234,21 @@ public function setLogger(Horde_Log_Logger $logger) */ public function handle() { - $this->_logger->info(sprintf( - '%sRequest being handled for device: %s, of type: %s, supporting protocol version: %s, using Horde_ActiveSync v%s', - str_repeat('-', 10), - $this->_device->id, - $this->_device->deviceType, - $this->_device->version, - Horde_ActiveSync::LIBRARY_VERSION) + $this->_logger->info( + sprintf( + '%sRequest being handled for device: %s, of type: %s, supporting protocol version: %s, using Horde_ActiveSync v%s', + str_repeat('-', 10), + $this->_device->id, + $this->_device->deviceType, + $this->_device->version, + Horde_ActiveSync::LIBRARY_VERSION + ) ); - $this->_logger->meta(sprintf( - 'GET VARIABLES: %s', - print_r($this->_activeSync->getGetVars(), true)) + $this->_logger->meta( + sprintf( + 'GET VARIABLES: %s', + print_r($this->_activeSync->getGetVars(), true) + ) ); $this->_logger->meta(sprintf( '%sDevice data: %s', @@ -267,7 +277,7 @@ protected function _cleanUpAfterPairing() // to avoid having 2 device entries for every android client. if ($this->_device->id == 'validate') { $this->_logger->meta('Removing state for bogus VALIDATE device.'); - $this->_state->removeState(array('devId' => 'validate')); + $this->_state->removeState(['devId' => 'validate']); } } diff --git a/lib/Horde/ActiveSync/Request/FolderCreate.php b/lib/Horde/ActiveSync/Request/FolderCreate.php index 578cc248..55f0320a 100644 --- a/lib/Horde/ActiveSync/Request/FolderCreate.php +++ b/lib/Horde/ActiveSync/Request/FolderCreate.php @@ -1,4 +1,5 @@ importFolderDeletion($server_uid); + $importer->importFolderDeletion($server_uid); } catch (Horde_ActiveSync_Exception_DeletionNotSupported $e) { $status = self::STATUS_DELETION_NOT_SUPPORTED; } catch (Horde_ActiveSync_Exception_FolderGone $e) { diff --git a/lib/Horde/ActiveSync/Request/FolderSync.php b/lib/Horde/ActiveSync/Request/FolderSync.php index 3d731305..72838868 100644 --- a/lib/Horde/ActiveSync/Request/FolderSync.php +++ b/lib/Horde/ActiveSync/Request/FolderSync.php @@ -1,4 +1,5 @@ importFolderChange( - $folder->serverid, $folder->displayname); - $serverid = $new_server->serverid; - if (!in_array($serverid, $seenfolders)) { - $seenfolders[] = $serverid; - $collections->updateFolderInHierarchy($folder); - } else { - $collections->updateFolderInHierarchy($folder, true); - } - $changes = true; - break; - case SYNC_REMOVE: - $importer->importFolderDeletion($folder->serverid); - if (($sid = array_search($folder->serverid, $seenfolders)) !== false) { - unset($seenfolders[$sid]); - $seenfolders = array_values($seenfolders); - } - $collections->deleteFolderFromHierarchy($folder->serverid); - $changes = true; - break; + case SYNC_ADD: + case SYNC_MODIFY: + $new_server = $importer->importFolderChange( + $folder->serverid, + $folder->displayname + ); + $serverid = $new_server->serverid; + if (!in_array($serverid, $seenfolders)) { + $seenfolders[] = $serverid; + $collections->updateFolderInHierarchy($folder); + } else { + $collections->updateFolderInHierarchy($folder, true); + } + $changes = true; + break; + case SYNC_REMOVE: + $importer->importFolderDeletion($folder->serverid); + if (($sid = array_search($folder->serverid, $seenfolders)) !== false) { + unset($seenfolders[$sid]); + $seenfolders = array_values($seenfolders); + } + $collections->deleteFolderFromHierarchy($folder->serverid); + $changes = true; + break; } } @@ -178,7 +181,7 @@ protected function _handle() $exporter->setChanges($collections->getHierarchyChanges()); // Perform the actual sync operation - while($exporter->sendNextChange()); + while ($exporter->sendNextChange()); // Output our WBXML reply now $this->_encoder->StartWBXML(); diff --git a/lib/Horde/ActiveSync/Request/GetAttachment.php b/lib/Horde/ActiveSync/Request/GetAttachment.php index c116015f..09d0a30d 100644 --- a/lib/Horde/ActiveSync/Request/GetAttachment.php +++ b/lib/Horde/ActiveSync/Request/GetAttachment.php @@ -1,4 +1,5 @@ _logger->meta(sprintf( - 'Fetching attachment: %s', - $attname) + $this->_logger->meta( + sprintf( + 'Fetching attachment: %s', + $attname + ) ); $att = $this->_driver->getAttachment($attname); diff --git a/lib/Horde/ActiveSync/Request/GetHierarchy.php b/lib/Horde/ActiveSync/Request/GetHierarchy.php index b7037dff..452fada0 100644 --- a/lib/Horde/ActiveSync/Request/GetHierarchy.php +++ b/lib/Horde/ActiveSync/Request/GetHierarchy.php @@ -1,4 +1,5 @@ _activeSync->getCollectionsObject(); - if (!$this->_decoder->getElementStartTag(self::GETITEMESTIMATE) || - !$this->_decoder->getElementStartTag(self::FOLDERS)) { + if (!$this->_decoder->getElementStartTag(self::GETITEMESTIMATE) + || !$this->_decoder->getElementStartTag(self::FOLDERS)) { return false; } while ($this->_decoder->getElementStartTag(self::FOLDER)) { - $options = array(); + $options = []; $cStatus = self::STATUS_SUCCESS; - while (($type = ($this->_decoder->getElementStartTag(self::FOLDERTYPE) ? self::FOLDERTYPE : - ($this->_decoder->getElementStartTag(self::FOLDERID) ? self::FOLDERID : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FILTERTYPE) ? Horde_ActiveSync::SYNC_FILTERTYPE : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_SYNCKEY) ? Horde_ActiveSync::SYNC_SYNCKEY : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_CONVERSATIONMODE) ? Horde_ActiveSync::SYNC_CONVERSATIONMODE : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_OPTIONS) ? Horde_ActiveSync::SYNC_OPTIONS : - -1))))))) != -1) { + while (($type = ($this->_decoder->getElementStartTag(self::FOLDERTYPE) ? self::FOLDERTYPE + : ($this->_decoder->getElementStartTag(self::FOLDERID) ? self::FOLDERID + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FILTERTYPE) ? Horde_ActiveSync::SYNC_FILTERTYPE + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_SYNCKEY) ? Horde_ActiveSync::SYNC_SYNCKEY + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_CONVERSATIONMODE) ? Horde_ActiveSync::SYNC_CONVERSATIONMODE + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_OPTIONS) ? Horde_ActiveSync::SYNC_OPTIONS + : -1))))))) != -1) { switch ($type) { - case self::FOLDERTYPE: - $class = $this->_decoder->getElementContent(); - if (!$this->_decoder->getElementEndTag()) { - return false; - } - break; - case self::FOLDERID: - $collectionid = $this->_decoder->getElementContent(); - if (!$this->_decoder->getElementEndTag()) { - return false; - } - break; - case Horde_ActiveSync::SYNC_CONVERSATIONMODE: - $conversationmode = $this->_decoder->getElementContent(); - if ($conversationmode !== false && !$this->_decoder->getElementEndTag()) { - throw new Horde_ActiveSync_Exception('Protocol Error'); - } elseif ($conversationmode === false) { - $conversationmode = true; - } - break; - case Horde_ActiveSync::SYNC_FILTERTYPE: - $filtertype = $this->_decoder->getElementContent(); - if (!$this->_decoder->getElementEndTag()) { - return false; - } - break; - case Horde_ActiveSync::SYNC_SYNCKEY: - $synckey = $this->_decoder->getElementContent(); - if (empty($synckey)) { - $cStatus = self::STATUS_NOTPRIMED; - } - if (!$this->_decoder->getElementEndTag()) { - return false; - } - break; - case Horde_ActiveSync::SYNC_OPTIONS: - // EAS > 12.1 only. - while (1) { - $firstOption = true; - if ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FOLDERTYPE)) { - $class = $this->_decoder->getElementContent(); - if (!$this->_decoder->getElementEndTag()) { - throw new Horde_ActiveSync_Exception('Protocol Error'); - } - } elseif ($firstOption) { - // Default options? + case self::FOLDERTYPE: + $class = $this->_decoder->getElementContent(); + if (!$this->_decoder->getElementEndTag()) { + return false; } - $firstOption = false; - - if ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FILTERTYPE)) { - // Set filtertype? self::$decoder->getElementContent()); - $filtertype = $this->_decoder->getElementContent(); - if (!$this->_decoder->getElementEndTag()) { - throw new Horde_ActiveSync_Exception('Protocol Error'); - } + break; + case self::FOLDERID: + $collectionid = $this->_decoder->getElementContent(); + if (!$this->_decoder->getElementEndTag()) { + return false; } - if ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_WINDOWSIZE)) { - // Setwindowsize ($maxitems = self::$decoder->getElementContent()); - if (!$this->_decoder->getElementEndTag()) { - throw new Horde_ActiveSync_Exception('Protocol Error'); - } + break; + case Horde_ActiveSync::SYNC_CONVERSATIONMODE: + $conversationmode = $this->_decoder->getElementContent(); + if ($conversationmode !== false && !$this->_decoder->getElementEndTag()) { + throw new Horde_ActiveSync_Exception('Protocol Error'); + } elseif ($conversationmode === false) { + $conversationmode = true; + } + break; + case Horde_ActiveSync::SYNC_FILTERTYPE: + $filtertype = $this->_decoder->getElementContent(); + if (!$this->_decoder->getElementEndTag()) { + return false; + } + break; + case Horde_ActiveSync::SYNC_SYNCKEY: + $synckey = $this->_decoder->getElementContent(); + if (empty($synckey)) { + $cStatus = self::STATUS_NOTPRIMED; } + if (!$this->_decoder->getElementEndTag()) { + return false; + } + break; + case Horde_ActiveSync::SYNC_OPTIONS: + // EAS > 12.1 only. + while (1) { + $firstOption = true; + if ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FOLDERTYPE)) { + $class = $this->_decoder->getElementContent(); + if (!$this->_decoder->getElementEndTag()) { + throw new Horde_ActiveSync_Exception('Protocol Error'); + } + } elseif ($firstOption) { + // Default options? + } + $firstOption = false; - // Only supported for 'RI' searches - which we don't support - // need to parse it though to avoid wbxml errors. - if ($this->_decoder->getELementStartTag(Horde_ActiveSync::SYNC_MAXITEMS)) { - if ($collectionid != 'RI') { - $gStatus = self::STATUS_INVALIDCOL; + if ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FILTERTYPE)) { + // Set filtertype? self::$decoder->getElementContent()); + $filtertype = $this->_decoder->getElementContent(); + if (!$this->_decoder->getElementEndTag()) { + throw new Horde_ActiveSync_Exception('Protocol Error'); + } } - if (!$this->_decoder->getElementEndTag()) { - throw new Horde_ActiveSync_Exception('Protocol Error'); + if ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_WINDOWSIZE)) { + // Setwindowsize ($maxitems = self::$decoder->getElementContent()); + if (!$this->_decoder->getElementEndTag()) { + throw new Horde_ActiveSync_Exception('Protocol Error'); + } } - } - $elm = $this->_decoder->peek(); - if ($elm[Horde_ActiveSync_Wbxml::EN_TYPE] == Horde_ActiveSync_Wbxml::EN_TYPE_ENDTAG) { - $this->_decoder->getElementEndTag(); - break; + // Only supported for 'RI' searches - which we don't support + // need to parse it though to avoid wbxml errors. + if ($this->_decoder->getELementStartTag(Horde_ActiveSync::SYNC_MAXITEMS)) { + if ($collectionid != 'RI') { + $gStatus = self::STATUS_INVALIDCOL; + } + if (!$this->_decoder->getElementEndTag()) { + throw new Horde_ActiveSync_Exception('Protocol Error'); + } + } + + $elm = $this->_decoder->peek(); + if ($elm[Horde_ActiveSync_Wbxml::EN_TYPE] == Horde_ActiveSync_Wbxml::EN_TYPE_ENDTAG) { + $this->_decoder->getElementEndTag(); + break; + } } - } } } // End the FOLDER element @@ -170,11 +171,11 @@ protected function _handle() } // Build the collection array - $collection = array(); + $collection = []; $collection['synckey'] = $synckey; $collection['filtertype'] = !empty($filtertype) ? $filtertype : false; $collection['id'] = $collectionid; - $collection['conversationmode'] = isset($conversationmode) ? $conversationmode : false; + $collection['conversationmode'] = $conversationmode ?? false; $status[$collection['id']] = $cStatus; if (!empty($class)) { $collection['class'] = $class; @@ -202,8 +203,11 @@ protected function _handle() $collections->initCollectionState($collection); $count = $collections->getCollectionChangeCount(); } catch (Horde_ActiveSync_Exception_StaleState $e) { - $this->_logger->warn(sprintf('Stale state detected: %s', - $e->getMessage()) + $this->_logger->warn( + sprintf( + 'Stale state detected: %s', + $e->getMessage() + ) ); $status = self::STATUS_KEYMISM; } catch (Horde_ActiveSync_Exception_StateGone $e) { diff --git a/lib/Horde/ActiveSync/Request/ItemOperations.php b/lib/Horde/ActiveSync/Request/ItemOperations.php index d9726c71..850d849e 100644 --- a/lib/Horde/ActiveSync/Request/ItemOperations.php +++ b/lib/Horde/ActiveSync/Request/ItemOperations.php @@ -1,4 +1,5 @@ _decoder->getElementStartTag(self::ITEMOPERATIONS_FETCH) ? self::ITEMOPERATIONS_FETCH : - ($this->_decoder->getElementStartTag(self::ITEMOPERATIONS_EMPTYFOLDERCONTENT) ? self::ITEMOPERATIONS_EMPTYFOLDERCONTENT : -1))) != -1) { + while (($reqtype = ($this->_decoder->getElementStartTag(self::ITEMOPERATIONS_FETCH) ? self::ITEMOPERATIONS_FETCH + : ($this->_decoder->getElementStartTag(self::ITEMOPERATIONS_EMPTYFOLDERCONTENT) ? self::ITEMOPERATIONS_EMPTYFOLDERCONTENT : -1))) != -1) { if ($reqtype == self::ITEMOPERATIONS_FETCH) { $thisio['type'] = 'fetch'; - while (($reqtag = ($this->_decoder->getElementStartTag(self::ITEMOPERATIONS_STORE) ? self::ITEMOPERATIONS_STORE : - ($this->_decoder->getElementStartTag(self::ITEMOPERATIONS_OPTIONS) ? self::ITEMOPERATIONS_OPTIONS : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_SERVERENTRYID) ? Horde_ActiveSync::SYNC_SERVERENTRYID : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FOLDERID) ? Horde_ActiveSync::SYNC_FOLDERID : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_LINKID) ? Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_LINKID : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::AIRSYNCBASE_FILEREFERENCE) ? Horde_ActiveSync::AIRSYNCBASE_FILEREFERENCE : - ($this->_decoder->getElementStartTag(Horde_ActiveSync_Request_Search::SEARCH_LONGID) ? Horde_ActiveSync_Request_Search::SEARCH_LONGID : - -1)))))))) != -1) { + while (($reqtag = ($this->_decoder->getElementStartTag(self::ITEMOPERATIONS_STORE) ? self::ITEMOPERATIONS_STORE + : ($this->_decoder->getElementStartTag(self::ITEMOPERATIONS_OPTIONS) ? self::ITEMOPERATIONS_OPTIONS + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_SERVERENTRYID) ? Horde_ActiveSync::SYNC_SERVERENTRYID + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FOLDERID) ? Horde_ActiveSync::SYNC_FOLDERID + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_LINKID) ? Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_LINKID + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::AIRSYNCBASE_FILEREFERENCE) ? Horde_ActiveSync::AIRSYNCBASE_FILEREFERENCE + : ($this->_decoder->getElementStartTag(Horde_ActiveSync_Request_Search::SEARCH_LONGID) ? Horde_ActiveSync_Request_Search::SEARCH_LONGID + : -1)))))))) != -1) { if ($reqtag == self::ITEMOPERATIONS_OPTIONS) { - while (($thisoption = ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_MIMESUPPORT) ? Horde_ActiveSync::SYNC_MIMESUPPORT : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::AIRSYNCBASE_BODYPREFERENCE) ? Horde_ActiveSync::AIRSYNCBASE_BODYPREFERENCE : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::AIRSYNCBASE_BODYPARTPREFERENCE) ? Horde_ActiveSync::AIRSYNCBASE_BODYPARTPREFERENCE : - ($this->_decoder->getElementStartTag(self::ITEMOPERATIONS_SCHEMA) ? self::ITEMOPERATIONS_SCHEMA : - ($this->_decoder->getElementStartTag(self::ITEMOPERATIONS_RANGE) ? self::ITEMOPERATIONS_RANGE : - ($this->_decoder->getElementStartTag(self::ITEMOPERATIONS_USERNAME) ? self::ITEMOPERATIONS_USERNAME : - ($this->_decoder->getElementStartTag(self::ITEMOPERATIONS_PASSWORD) ? self::ITEMOPERATIONS_PASSWORD : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::RM_SUPPORT) ? Horde_ActiveSync::RM_SUPPORT : - -1))))))))) != -1) { + while (($thisoption = ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_MIMESUPPORT) ? Horde_ActiveSync::SYNC_MIMESUPPORT + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::AIRSYNCBASE_BODYPREFERENCE) ? Horde_ActiveSync::AIRSYNCBASE_BODYPREFERENCE + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::AIRSYNCBASE_BODYPARTPREFERENCE) ? Horde_ActiveSync::AIRSYNCBASE_BODYPARTPREFERENCE + : ($this->_decoder->getElementStartTag(self::ITEMOPERATIONS_SCHEMA) ? self::ITEMOPERATIONS_SCHEMA + : ($this->_decoder->getElementStartTag(self::ITEMOPERATIONS_RANGE) ? self::ITEMOPERATIONS_RANGE + : ($this->_decoder->getElementStartTag(self::ITEMOPERATIONS_USERNAME) ? self::ITEMOPERATIONS_USERNAME + : ($this->_decoder->getElementStartTag(self::ITEMOPERATIONS_PASSWORD) ? self::ITEMOPERATIONS_PASSWORD + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::RM_SUPPORT) ? Horde_ActiveSync::RM_SUPPORT + : -1))))))))) != -1) { switch ($thisoption) { - case Horde_ActiveSync::SYNC_MIMESUPPORT: - $mimesupport = $this->_decoder->getElementContent(); - $this->_decoder->getElementEndTag(); - break; - case Horde_ActiveSync::AIRSYNCBASE_BODYPREFERENCE: - $this->_bodyPrefs($thisio); - break; - case Horde_ActiveSync::AIRSYNCBASE_BODYPARTPREFERENCE: - $this->_bodyPartPrefs($thisio); - break; - case Horde_ActiveSync::RM_SUPPORT: - $this->_rightsManagement($thisio); - break; - case self::ITEMOPERATIONS_PASSWORD: - $thisio['password'] = $this->_decoder->getElementContent(); - break; - case self::ITEMOPERATIONS_USERNAME: - $thisio['username'] = $this->_decoder->getElementContent(); - break; + case Horde_ActiveSync::SYNC_MIMESUPPORT: + $mimesupport = $this->_decoder->getElementContent(); + $this->_decoder->getElementEndTag(); + break; + case Horde_ActiveSync::AIRSYNCBASE_BODYPREFERENCE: + $this->_bodyPrefs($thisio); + break; + case Horde_ActiveSync::AIRSYNCBASE_BODYPARTPREFERENCE: + $this->_bodyPartPrefs($thisio); + break; + case Horde_ActiveSync::RM_SUPPORT: + $this->_rightsManagement($thisio); + break; + case self::ITEMOPERATIONS_PASSWORD: + $thisio['password'] = $this->_decoder->getElementContent(); + break; + case self::ITEMOPERATIONS_USERNAME: + $thisio['username'] = $this->_decoder->getElementContent(); + break; - case self::ITEMOPERATIONS_RANGE: - $thisio['range'] = $this->_decoder->getElementContent(); - break; + case self::ITEMOPERATIONS_RANGE: + $thisio['range'] = $this->_decoder->getElementContent(); + break; - case self::ITEMOPERATIONS_SCHEMA: - while (1) { - $el = $this->_decoder->getElement(); - $e = $this->_decoder->peek(); - if ($e[Horde_ActiveSync_Wbxml::EN_TYPE] == Horde_ActiveSync_Wbxml::EN_TYPE_ENDTAG) { - $this->_decoder->getElementEndTag(); - break; + case self::ITEMOPERATIONS_SCHEMA: + while (1) { + $el = $this->_decoder->getElement(); + $e = $this->_decoder->peek(); + if ($e[Horde_ActiveSync_Wbxml::EN_TYPE] == Horde_ActiveSync_Wbxml::EN_TYPE_ENDTAG) { + $this->_decoder->getElementEndTag(); + break; + } } - } } } } elseif ($reqtag == self::ITEMOPERATIONS_STORE) { @@ -169,8 +170,8 @@ protected function _handle() $this->_decoder->getElementEndTag(); // end SYNC_ITEMOPERATIONS_FETCH } elseif ($reqtype == self::ITEMOPERATIONS_EMPTYFOLDERCONTENT) { $thisio['type'] = 'empty'; - while (($tag = ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FOLDERID) ? Horde_ActiveSync::SYNC_FOLDERID : - ($this->_decoder->getElementStartTag(self::ITEMOPERATIONS_OPTIONS) ? self::ITEMOPERATIONS_OPTIONS : -1))) != -1) { + while (($tag = ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FOLDERID) ? Horde_ActiveSync::SYNC_FOLDERID + : ($this->_decoder->getElementStartTag(self::ITEMOPERATIONS_OPTIONS) ? self::ITEMOPERATIONS_OPTIONS : -1))) != -1) { if ($tag == Horde_ActiveSync::SYNC_FOLDERID) { $thisio['folderid'] = $this->_decoder->getElementContent(); @@ -195,129 +196,134 @@ protected function _handle() $this->_encoder->startTag(self::ITEMOPERATIONS_RESPONSE); $collections = $this->_activeSync->getCollectionsObject(); - foreach($itemoperations as $value) { - switch($value['type']) { - case 'fetch' : - switch(Horde_String::lower($value['store'])) { - case 'mailbox' : - // Yes, even though this is a "mailbox" store, this is - // how EAS identifies calendar attachments too since - // they are not documentLibrary items. The backend - // needs to be able to identify where to get the - // item from based solely on the filereference. - $this->_encoder->startTag(self::ITEMOPERATIONS_FETCH); - if (isset($value['airsyncbasefilereference'])) { - // filereference is already in the backend serverid format - // since it is taken from the AIRSYNCBASE_FILEREFERENCE - try { - $msg = $this->_driver->itemOperationsGetAttachmentData($value['airsyncbasefilereference']); - } catch (Horde_ActiveSync_Exception $e) { - $this->_statusCode = self::STATUS_ATTINVALID; - } - if (!$this->_encoder->multipart) { - $msg->total = $this->_getDataSize($msg->data); - $msg->range = '0-' . ($msg->total - 1); - } - $this->_outputStatus(); - $this->_encoder->startTag(Horde_ActiveSync::AIRSYNCBASE_FILEREFERENCE); - $this->_encoder->content($value['airsyncbasefilereference']); - $this->_encoder->endTag(); - } elseif (isset($value['searchlongid'])) { - $this->_outputStatus(); - $this->_encoder->startTag(Horde_ActiveSync_Request_Search::SEARCH_LONGID); - $this->_encoder->content($value['searchlongid']); - $this->_encoder->endTag(); - $this->_encoder->startTag(Horde_ActiveSync::SYNC_FOLDERTYPE); - $this->_encoder->content('Email'); - $this->_encoder->endTag(); - $msg = $this->_driver->itemOperationsFetchMailbox($value['searchlongid'], $value['bodyprefs'], $mimesupport); - } else { - $this->_outputStatus(); - if (isset($value['folderid']) && isset($value['serverentryid'])) { - $this->_encoder->startTag(Horde_ActiveSync::SYNC_FOLDERID); - $this->_encoder->content($value['folderid']); + foreach ($itemoperations as $value) { + switch ($value['type']) { + case 'fetch': + switch (Horde_String::lower($value['store'])) { + case 'mailbox': + // Yes, even though this is a "mailbox" store, this is + // how EAS identifies calendar attachments too since + // they are not documentLibrary items. The backend + // needs to be able to identify where to get the + // item from based solely on the filereference. + $this->_encoder->startTag(self::ITEMOPERATIONS_FETCH); + if (isset($value['airsyncbasefilereference'])) { + // filereference is already in the backend serverid format + // since it is taken from the AIRSYNCBASE_FILEREFERENCE + try { + $msg = $this->_driver->itemOperationsGetAttachmentData($value['airsyncbasefilereference']); + } catch (Horde_ActiveSync_Exception $e) { + $this->_statusCode = self::STATUS_ATTINVALID; + } + if (!$this->_encoder->multipart) { + $msg->total = $this->_getDataSize($msg->data); + $msg->range = '0-' . ($msg->total - 1); + } + $this->_outputStatus(); + $this->_encoder->startTag(Horde_ActiveSync::AIRSYNCBASE_FILEREFERENCE); + $this->_encoder->content($value['airsyncbasefilereference']); + $this->_encoder->endTag(); + } elseif (isset($value['searchlongid'])) { + $this->_outputStatus(); + $this->_encoder->startTag(Horde_ActiveSync_Request_Search::SEARCH_LONGID); + $this->_encoder->content($value['searchlongid']); + $this->_encoder->endTag(); + $this->_encoder->startTag(Horde_ActiveSync::SYNC_FOLDERTYPE); + $this->_encoder->content('Email'); + $this->_encoder->endTag(); + $msg = $this->_driver->itemOperationsFetchMailbox($value['searchlongid'], $value['bodyprefs'], $mimesupport); + } else { + $this->_outputStatus(); + if (isset($value['folderid']) && isset($value['serverentryid'])) { + $this->_encoder->startTag(Horde_ActiveSync::SYNC_FOLDERID); + $this->_encoder->content($value['folderid']); + $this->_encoder->endTag(); + + $this->_encoder->startTag(Horde_ActiveSync::SYNC_SERVERENTRYID); + $this->_encoder->content($value['serverentryid']); + $this->_encoder->endTag(); + + $this->_encoder->startTag(Horde_ActiveSync::SYNC_FOLDERTYPE); + $this->_encoder->content('Email'); + $this->_encoder->endTag(); + $mailbox = $collections->getBackendIdForFolderUid($value['folderid']); + $msg = $this->_driver->fetch( + $mailbox, + $value['serverentryid'], + [ + 'bodyprefs' => $value['bodyprefs'], + 'mimesupport' => $mimesupport] + ); + } + } + if ($this->_statusCode == self::STATUS_SUCCESS) { + $this->_encoder->startTag(self::ITEMOPERATIONS_PROPERTIES); + $msg->encodeStream($this->_encoder); + $this->_encoder->endTag(); + } $this->_encoder->endTag(); + break; + case 'documentlibrary': + $this->_encoder->startTag(self::ITEMOPERATIONS_FETCH); + try { + $u = $this->_driver->itemOperationsGetDocumentLibraryLink($value['documentlibrarylinkid'], []); + $doc = Horde_ActiveSync::messageFactory('Document'); + $doc->range = '0-' . ($u['content-length'] - 1); + $doc->total = $u['content-length']; + $doc->data = $u['data']->stream; + $doc->version = $u['modified']; + } catch (Horde_ActiveSync_Exception $e) { + $this->_status = self::STATUS_NOT_SUPPORTED; + } + $this->_outputStatus(); - $this->_encoder->startTag(Horde_ActiveSync::SYNC_SERVERENTRYID); - $this->_encoder->content($value['serverentryid']); + $this->_encoder->startTag(Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_LINKID); + $this->_encoder->content($u['linkid']); $this->_encoder->endTag(); - $this->_encoder->startTag(Horde_ActiveSync::SYNC_FOLDERTYPE); - $this->_encoder->content('Email'); + $this->_encoder->startTag(self::ITEMOPERATIONS_PROPERTIES); + $doc->encodeStream($this->_encoder); $this->_encoder->endTag(); - $mailbox = $collections->getBackendIdForFolderUid($value['folderid']); - $msg = $this->_driver->fetch( - $mailbox, - $value['serverentryid'], - array( - 'bodyprefs' => $value['bodyprefs'], - 'mimesupport' => $mimesupport) + + $this->_encoder->endTag(); + break; + + default: + $this->_logger->err( + sprintf( + '%s not supported by HANDLEITEMOPERATIONS.', + $value['type'] + ) ); - } - } - if ($this->_statusCode == self::STATUS_SUCCESS) { - $this->_encoder->startTag(self::ITEMOPERATIONS_PROPERTIES); - $msg->encodeStream($this->_encoder); - $this->_encoder->endTag(); + break; } - $this->_encoder->endTag(); break; - case 'documentlibrary': - $this->_encoder->startTag(self::ITEMOPERATIONS_FETCH); - try { - $u = $this->_driver->itemOperationsGetDocumentLibraryLink($value['documentlibrarylinkid'], array()); - $doc = Horde_ActiveSync::messageFactory('Document'); - $doc->range = '0-' . ($u['content-length'] - 1); - $doc->total = $u['content-length']; - $doc->data = $u['data']->stream; - $doc->version = $u['modified']; - } catch (Horde_ActiveSync_Exception $e) { - $this->_status = self::STATUS_NOT_SUPPORTED; + case 'empty': + // @todo remove check for H6. + if (method_exists($this->_driver, 'itemOperationsEmptyFolder')) { + $map = array_flip($this->_state->getFolderUidToBackendIdMap()); + $value['folderid'] = $map[$value['folderid']]; + $this->_logger->meta(sprintf( + 'Handling EMPTYFOLDERCONTENT for collection %s.', + $value['folderid'] + )); + try { + $this->_driver->itemOperationsEmptyFolder($value); + } catch (Horde_ActiveSync_Exception $e) { + $this->_status = self::STATUS_NOT_SUPPORTED; + } + } else { + $this->_logger->err('EMPTYFOLDERCONTENT not supported by driver.'); } - $this->_outputStatus(); - - $this->_encoder->startTag(Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_LINKID); - $this->_encoder->content($u['linkid']); - $this->_encoder->endTag(); - - $this->_encoder->startTag(self::ITEMOPERATIONS_PROPERTIES); - $doc->encodeStream($this->_encoder); - $this->_encoder->endTag(); - - $this->_encoder->endTag(); break; - - default : - $this->_logger->err(sprintf( - '%s not supported by HANDLEITEMOPERATIONS.', - $value['type']) + default: + $this->_logger->err( + sprintf( + '%s not supported by HANDLEITEMOPERATIONS.', + $value['type'] + ) ); break; - } - break; - case 'empty': - // @todo remove check for H6. - if (method_exists($this->_driver, 'itemOperationsEmptyFolder')) { - $map = array_flip($this->_state->getFolderUidToBackendIdMap()); - $value['folderid'] = $map[$value['folderid']]; - $this->_logger->meta(sprintf( - 'Handling EMPTYFOLDERCONTENT for collection %s.', - $value['folderid'])); - try { - $this->_driver->itemOperationsEmptyFolder($value); - } catch (Horde_ActiveSync_Exception $e) { - $this->_status = self::STATUS_NOT_SUPPORTED; - } - } else { - $this->_logger->err('EMPTYFOLDERCONTENT not supported by driver.'); - } - break; - default : - $this->_logger->err(sprintf( - '%s not supported by HANDLEITEMOPERATIONS.', - $value['type']) - ); - break; } } $this->_encoder->endTag(); //end SYNC_ITEMOPERATIONS_RESPONSE diff --git a/lib/Horde/ActiveSync/Request/MeetingResponse.php b/lib/Horde/ActiveSync/Request/MeetingResponse.php index 57f10dcc..2cad0251 100644 --- a/lib/Horde/ActiveSync/Request/MeetingResponse.php +++ b/lib/Horde/ActiveSync/Request/MeetingResponse.php @@ -1,4 +1,5 @@ _decoder->getElementStartTag(self::MEETINGRESPONSE_MEETINGRESPONSE)) { throw new Horde_ActiveSync_Exception('Protocol Error'); } while ($this->_decoder->getElementStartTag(self::MEETINGRESPONSE_REQUEST)) { - $req = array(); - while (($tag = ($this->_decoder->getElementStartTag(self::MEETINGRESPONSE_USERRESPONSE) ? self::MEETINGRESPONSE_USERRESPONSE : - ($this->_decoder->getElementStartTag(self::MEETINGRESPONSE_FOLDERID) ? self::MEETINGRESPONSE_FOLDERID : - ($this->_decoder->getElementStartTag(self::MEETINGRESPONSE_REQUESTID) ? self::MEETINGRESPONSE_REQUESTID : - ($this->_decoder->getElementStartTag(Horde_ActiveSync_Request_Search::SEARCH_LONGID) ? Horde_ActiveSync_Request_Search::SEARCH_LONGID : - ($this->_decoder->getElementStartTag(self::MEETINGRESPONSE_INSTANCEID) ? self::MEETINGRESPONSE_INSTANCEID : - ($this->_decoder->getElementStartTag(self::MEETINGRESPONSE_SENDRESPONSE) ? self::MEETINGRESPONSE_SENDRESPONSE : -1))))))) != -1) { + $req = []; + while (($tag = ($this->_decoder->getElementStartTag(self::MEETINGRESPONSE_USERRESPONSE) ? self::MEETINGRESPONSE_USERRESPONSE + : ($this->_decoder->getElementStartTag(self::MEETINGRESPONSE_FOLDERID) ? self::MEETINGRESPONSE_FOLDERID + : ($this->_decoder->getElementStartTag(self::MEETINGRESPONSE_REQUESTID) ? self::MEETINGRESPONSE_REQUESTID + : ($this->_decoder->getElementStartTag(Horde_ActiveSync_Request_Search::SEARCH_LONGID) ? Horde_ActiveSync_Request_Search::SEARCH_LONGID + : ($this->_decoder->getElementStartTag(self::MEETINGRESPONSE_INSTANCEID) ? self::MEETINGRESPONSE_INSTANCEID + : ($this->_decoder->getElementStartTag(self::MEETINGRESPONSE_SENDRESPONSE) ? self::MEETINGRESPONSE_SENDRESPONSE : -1))))))) != -1) { switch ($tag) { - case self::MEETINGRESPONSE_USERRESPONSE: - $req['response'] = $this->_decoder->getElementContent(); - if (!$this->_decoder->getElementEndTag()) { - throw new Horde_ActiveSync_Exception('Protocol Error'); - } - break; - case self::MEETINGRESPONSE_FOLDERID: - $req['folderid'] = $this->_activeSync->getCollectionsObject() - ->getBackendIdForFolderUid($this->_decoder->getElementContent()); - if (!$this->_decoder->getElementEndTag()) { - throw new Horde_ActiveSync_Exception('Protocol Error'); - } - break; - case self::MEETINGRESPONSE_REQUESTID: - $req['requestid'] = $this->_decoder->getElementContent(); - if (!$this->_decoder->getElementEndTag()) { - throw new Horde_ActiveSync_Exception('Protocol Error'); - } - break; - case self::MEETINGRESPONSE_INSTANCEID: - // Original UTC time of appointment instance to be modified - // sent in EAS 16 to indicate which instance we are - // responding to. - $req['instanceid'] = $this->_decoder->getElementContent(); - if (!$this->_decoder->getElementEndTag()) { - throw new Horde_ActiveSync_Exception('Protocol Error'); - } - break; - case Horde_ActiveSync_Request_Search::SEARCH_LONGID: - // Used in EAS 16 when responding from a search result. - $req['longid'] = $this->_decoder->getElementContent(); - if (!$this->_decoder->getElementEndTag()) { - throw new Horde_ActiveSync_Exception('Protocol Error'); - } - break; - case self::MEETINGRESPONSE_SENDRESPONSE: - // Used in EAS 16 as either a flag to indicate the server - // should send the iTip response email, and/or to contain - // the body of such an email. - if ($this->_decoder->isEmptyElement($this->_decoder->getLastStartElement())) { - $req['sendresponse'] = true; - } else { - // elementContent is an AirSyncBaseBody object. - $this->_decoder->getElementStartTag(Horde_ActiveSync::AIRSYNCBASE_BODY); - $body = Horde_ActiveSync::messageFactory('AirSyncBaseBody'); - $body->decodeStream($this->_decoder); - $req['sendresponse'] = $body; - $this->_decoder->getElementEndTag(); // AirSyncbaseBody + case self::MEETINGRESPONSE_USERRESPONSE: + $req['response'] = $this->_decoder->getElementContent(); + if (!$this->_decoder->getElementEndTag()) { + throw new Horde_ActiveSync_Exception('Protocol Error'); + } + break; + case self::MEETINGRESPONSE_FOLDERID: + $req['folderid'] = $this->_activeSync->getCollectionsObject() + ->getBackendIdForFolderUid($this->_decoder->getElementContent()); + if (!$this->_decoder->getElementEndTag()) { + throw new Horde_ActiveSync_Exception('Protocol Error'); + } + break; + case self::MEETINGRESPONSE_REQUESTID: + $req['requestid'] = $this->_decoder->getElementContent(); if (!$this->_decoder->getElementEndTag()) { throw new Horde_ActiveSync_Exception('Protocol Error'); } - } - break; + break; + case self::MEETINGRESPONSE_INSTANCEID: + // Original UTC time of appointment instance to be modified + // sent in EAS 16 to indicate which instance we are + // responding to. + $req['instanceid'] = $this->_decoder->getElementContent(); + if (!$this->_decoder->getElementEndTag()) { + throw new Horde_ActiveSync_Exception('Protocol Error'); + } + break; + case Horde_ActiveSync_Request_Search::SEARCH_LONGID: + // Used in EAS 16 when responding from a search result. + $req['longid'] = $this->_decoder->getElementContent(); + if (!$this->_decoder->getElementEndTag()) { + throw new Horde_ActiveSync_Exception('Protocol Error'); + } + break; + case self::MEETINGRESPONSE_SENDRESPONSE: + // Used in EAS 16 as either a flag to indicate the server + // should send the iTip response email, and/or to contain + // the body of such an email. + if ($this->_decoder->isEmptyElement($this->_decoder->getLastStartElement())) { + $req['sendresponse'] = true; + } else { + // elementContent is an AirSyncBaseBody object. + $this->_decoder->getElementStartTag(Horde_ActiveSync::AIRSYNCBASE_BODY); + $body = Horde_ActiveSync::messageFactory('AirSyncBaseBody'); + $body->decodeStream($this->_decoder); + $req['sendresponse'] = $body; + $this->_decoder->getElementEndTag(); // AirSyncbaseBody + if (!$this->_decoder->getElementEndTag()) { + throw new Horde_ActiveSync_Exception('Protocol Error'); + } + } + break; } } diff --git a/lib/Horde/ActiveSync/Request/MoveItems.php b/lib/Horde/ActiveSync/Request/MoveItems.php index bebb02ee..af0849a4 100644 --- a/lib/Horde/ActiveSync/Request/MoveItems.php +++ b/lib/Horde/ActiveSync/Request/MoveItems.php @@ -1,4 +1,5 @@ _decoder->getElementStartTag(self::MOVE)) { - $move = array(); + $move = []; if ($this->_decoder->getElementStartTag(self::SRCMSGID)) { $move[self::SRCMSGKEY] = $this->_decoder->getElementContent(); - if(!$this->_decoder->getElementEndTag()) + if (!$this->_decoder->getElementEndTag()) { break; + } } if ($this->_decoder->getElementStartTag(self::SRCFLDID)) { $move[self::SRCFLDKEY] = $this->_decoder->getElementContent(); @@ -116,8 +118,9 @@ protected function _handle() $importer->init($this->_state, $move[self::SRCFLDKEY]); try { $move_res = $importer->importMessageMove( - array($move[self::SRCMSGKEY]), - $move[self::DSTFLDKEY]); + [$move[self::SRCMSGKEY]], + $move[self::DSTFLDKEY] + ); if (empty($move_res['results'][$move[self::SRCMSGKEY]])) { // Hm. Specs say to send INVALID_SRC if the msg is // already moved, or no longer present, but that seems diff --git a/lib/Horde/ActiveSync/Request/Ping.php b/lib/Horde/ActiveSync/Request/Ping.php index a9014fce..c9a2c3f5 100644 --- a/lib/Horde/ActiveSync/Request/Ping.php +++ b/lib/Horde/ActiveSync/Request/Ping.php @@ -1,4 +1,5 @@ _logger->meta(sprintf( - 'Handling PING command received at timestamp: %s.', - $now) + $this->_logger->meta( + sprintf( + 'Handling PING command received at timestamp: %s.', + $now + ) ); // Check global errors. @@ -126,9 +129,11 @@ protected function _handle() $heartbeat = !empty($this->_pingSettings['heartbeatdefault']) ? $this->_pingSettings['heartbeatdefault'] : 60; - $this->_logger->meta(sprintf( - 'Cached heartbeat is %s', - $heartbeat) + $this->_logger->meta( + sprintf( + 'Cached heartbeat is %s', + $heartbeat + ) ); } $this->_statusCode = self::STATUS_NOCHANGES; @@ -138,8 +143,8 @@ protected function _handle() $this->_logger->info('Handling empty PING request.'); $isEmpty = true; $collections->loadCollectionsFromCache(); - if ($collections->collectionCount() == 0 || - !$collections->havePingableCollections()) { + if ($collections->collectionCount() == 0 + || !$collections->havePingableCollections()) { $this->_logger->warn('Empty PING request with no cached collections. Request full PING.'); $this->_statusCode = self::STATUS_MISSING; $this->_handleGlobalError(); @@ -151,14 +156,14 @@ protected function _handle() if (!$heartbeat = $this->_checkHeartbeat($this->_decoder->getElementContent())) { $heartbeat = $this->_pingSettings['heartbeatdefault']; } - $collections->setHeartbeat(array('hbinterval' => $heartbeat)); + $collections->setHeartbeat(['hbinterval' => $heartbeat]); $forceCacheSave = true; $this->_decoder->getElementEndTag(); } $this->_logger->meta(sprintf('Actual heartbeat value in use is %s.', $heartbeat)); if ($this->_decoder->getElementStartTag(self::FOLDERS)) { while ($this->_decoder->getElementStartTag(self::FOLDER)) { - $collection = array(); + $collection = []; if ($this->_decoder->getElementStartTag(self::SERVERENTRYID)) { $collection['id'] = $this->_decoder->getElementContent(); $this->_decoder->getElementEndTag(); @@ -205,38 +210,38 @@ protected function _handle() // Start waiting for changes, but only if we don't have any errors if ($this->_statusCode == self::STATUS_NOCHANGES) { - $changes = $collections->pollForChanges($heartbeat, $interval, array('pingable' => true)); + $changes = $collections->pollForChanges($heartbeat, $interval, ['pingable' => true]); if ($changes !== true && $changes !== false) { switch ($changes) { - case Horde_ActiveSync_Collections::COLLECTION_ERR_STALE: - $this->_logger->info('Changes in cache detected during PING, exiting here.'); - return true; - case Horde_ActiveSync_Collections::COLLECTION_ERR_FOLDERSYNC_REQUIRED; - $this->_statusCode = self::STATUS_FOLDERSYNCREQD; - $this->_handleGlobalError(); - return true; - case Horde_ActiveSync_Collections::COLLECTION_ERR_AUTHENTICATION; - // If we lose authentication here, it means it was - // successful initially, but later failed for some reason. - // Send it as a general ping error, which should allow the - // client to retry later. If the auth is still bad, it will - // be caught during initial login, - $this->_statusCode = self::STATUS_SERVERERROR; - $this->_handleGlobalError(); - return true; - case Horde_ActiveSync_Collections::COLLECTION_ERR_SYNC_REQUIRED; - $this->_statusCode = self::STATUS_NEEDSYNC; - break; - default: - if ($this->_device->version < Horde_ActiveSync::VERSION_FOURTEEN) { - $this->_logger->warn('Version is < 14.0, returning false since we have no PINGABLE collections.'); - return false; - } else { - $this->_logger->warn('Version is >= 14.0 returning status code 132 since we have no PINGABLE collections.'); - $this->_statusCode = Horde_ActiveSync_Status::STATEFILE_NOT_FOUND; + case Horde_ActiveSync_Collections::COLLECTION_ERR_STALE: + $this->_logger->info('Changes in cache detected during PING, exiting here.'); + return true; + case Horde_ActiveSync_Collections::COLLECTION_ERR_FOLDERSYNC_REQUIRED: + $this->_statusCode = self::STATUS_FOLDERSYNCREQD; $this->_handleGlobalError(); return true; - } + case Horde_ActiveSync_Collections::COLLECTION_ERR_AUTHENTICATION: + // If we lose authentication here, it means it was + // successful initially, but later failed for some reason. + // Send it as a general ping error, which should allow the + // client to retry later. If the auth is still bad, it will + // be caught during initial login, + $this->_statusCode = self::STATUS_SERVERERROR; + $this->_handleGlobalError(); + return true; + case Horde_ActiveSync_Collections::COLLECTION_ERR_SYNC_REQUIRED: + $this->_statusCode = self::STATUS_NEEDSYNC; + break; + default: + if ($this->_device->version < Horde_ActiveSync::VERSION_FOURTEEN) { + $this->_logger->warn('Version is < 14.0, returning false since we have no PINGABLE collections.'); + return false; + } else { + $this->_logger->warn('Version is >= 14.0 returning status code 132 since we have no PINGABLE collections.'); + $this->_statusCode = Horde_ActiveSync_Status::STATEFILE_NOT_FOUND; + $this->_handleGlobalError(); + return true; + } } } elseif ($changes) { $collections->save(true); diff --git a/lib/Horde/ActiveSync/Request/Provision.php b/lib/Horde/ActiveSync/Request/Provision.php index 44238621..74b85934 100644 --- a/lib/Horde/ActiveSync/Request/Provision.php +++ b/lib/Horde/ActiveSync/Request/Provision.php @@ -1,4 +1,5 @@ Server Status */ - const STATUS_CLIENT_SUCCESS = 1; - const STATUS_CLIENT_PARTIAL = 2; // Only pin was enabled. - const STATUS_CLIENT_FAILED = 3; // No policies applied at all. - const STATUS_CLIENT_THIRDPARTY = 4; // Client provisioned by 3rd party? + public const STATUS_CLIENT_SUCCESS = 1; + public const STATUS_CLIENT_PARTIAL = 2; // Only pin was enabled. + public const STATUS_CLIENT_FAILED = 3; // No policies applied at all. + public const STATUS_CLIENT_THIRDPARTY = 4; // Client provisioned by 3rd party? /** * Handle the Provision request. This is a 3-phase process. Phase 1 is @@ -82,8 +83,8 @@ protected function _handle() return $this->_globalError(self::STATUS_PROTERROR); } $status = $this->_decoder->getElementContent(); - if (!$this->_decoder->getElementEndTag() || - !$this->_decoder->getElementEndTag()) { + if (!$this->_decoder->getElementEndTag() + || !$this->_decoder->getElementEndTag()) { return $this->_globalError(self::STATUS_PROTERROR); } if ($status == self::STATUS_CLIENT_SUCCESS) { @@ -97,8 +98,8 @@ protected function _handle() $this->_device->save(); } - if (!$this->_decoder->getElementStartTag(Horde_ActiveSync::PROVISION_POLICIES) || - !$this->_decoder->getElementStartTag(Horde_ActiveSync::PROVISION_POLICY)) { + if (!$this->_decoder->getElementStartTag(Horde_ActiveSync::PROVISION_POLICIES) + || !$this->_decoder->getElementStartTag(Horde_ActiveSync::PROVISION_POLICY)) { return $this->_globalError(self::STATUS_PROTERROR); } @@ -129,8 +130,8 @@ protected function _handle() if ($this->_decoder->getElementStartTag(Horde_ActiveSync::PROVISION_POLICYKEY)) { $policykey = $this->_decoder->getElementContent(); $this->_logger->meta(sprintf('PHASE 3 policykey sent from client: %s', $policykey)); - if (!$this->_decoder->getElementEndTag() || - !$this->_decoder->getElementStartTag(Horde_ActiveSync::PROVISION_STATUS)) { + if (!$this->_decoder->getElementEndTag() + || !$this->_decoder->getElementStartTag(Horde_ActiveSync::PROVISION_STATUS)) { return $this->_globalError(self::STATUS_PROTERROR); } @@ -152,8 +153,8 @@ protected function _handle() $phase2 = false; } - if (!$this->_decoder->getElementEndTag() || - !$this->_decoder->getElementEndTag()) { + if (!$this->_decoder->getElementEndTag() + || !$this->_decoder->getElementEndTag()) { return $this->_globalError(self::STATUS_PROTERROR); } @@ -164,8 +165,8 @@ protected function _handle() return $this->_globalError(self::STATUS_PROTERROR); } $status = $this->_decoder->getElementContent(); - if (!$this->_decoder->getElementEndTag() || - !$this->_decoder->getElementEndTag()) { + if (!$this->_decoder->getElementEndTag() + || !$this->_decoder->getElementEndTag()) { return $this->_globalError(self::STATUS_PROTERROR); } if ($status == self::STATUS_CLIENT_SUCCESS) { @@ -191,9 +192,12 @@ protected function _handle() // send it to the client. if (!$phase2) { // Verify intermediate key - $this->_logger->meta(sprintf( - 'Verifying Phase 3 policykey: From Device: %s, Stored: %s', - $policykey, $this->_device->policykey) + $this->_logger->meta( + sprintf( + 'Verifying Phase 3 policykey: From Device: %s, Stored: %s', + $policykey, + $this->_device->policykey + ) ); if ($this->_state->getPolicyKey($this->_device->id) != $policykey) { $policyStatus = self::STATUS_POLKEYMISM; @@ -208,16 +212,18 @@ protected function _handle() // This is phase2 - we need to set the intermediate key $policykey = $this->_state->generatePolicyKey(); $this->_logger->meta(sprintf( - 'Generating PHASE2 policy key: %s', $policykey)); + 'Generating PHASE2 policy key: %s', + $policykey + )); $this->_state->setPolicyKey($this->_device->id, $policykey); } // If we are phase2 we need to check this here, before the status is // sent. Prevents devices not supporting the required policies from // being able to connect. - if ($phase2 && $status == self::STATUS_SUCCESS && - $policyStatus == self::STATUS_SUCCESS && - $this->_provisioning == Horde_ActiveSync::PROVISIONING_FORCE) { + if ($phase2 && $status == self::STATUS_SUCCESS + && $policyStatus == self::STATUS_SUCCESS + && $this->_provisioning == Horde_ActiveSync::PROVISIONING_FORCE) { $policyHandler = new Horde_ActiveSync_Policies( $this->_encoder, @@ -263,8 +269,8 @@ protected function _handle() // Remote wipe if requested. $rwstatus = $this->_state->getDeviceRWStatus($this->_device->id); - if ($rwstatus == Horde_ActiveSync::RWSTATUS_PENDING || - $rwstatus == Horde_ActiveSync::RWSTATUS_WIPED) { + if ($rwstatus == Horde_ActiveSync::RWSTATUS_PENDING + || $rwstatus == Horde_ActiveSync::RWSTATUS_WIPED) { $this->_encoder->startTag(Horde_ActiveSync::PROVISION_REMOTEWIPE, false, true); $this->_state->setDeviceRWStatus($this->_device->id, Horde_ActiveSync::RWSTATUS_WIPED); @@ -330,7 +336,7 @@ protected function _handleSettings() if (!$this->_decoder->getElementStartTag(Horde_ActiveSync_Request_Settings::SETTINGS_SET)) { return false; } - $di = array(); + $di = []; $settings = Horde_ActiveSync::messageFactory('DeviceInformation'); $settings->decodeStream($this->_decoder); $di[Horde_ActiveSync_Request_Settings::SETTINGS_MODEL] = $settings->model; diff --git a/lib/Horde/ActiveSync/Request/ResolveRecipients.php b/lib/Horde/ActiveSync/Request/ResolveRecipients.php index e0d23119..d19ce446 100644 --- a/lib/Horde/ActiveSync/Request/ResolveRecipients.php +++ b/lib/Horde/ActiveSync/Request/ResolveRecipients.php @@ -1,4 +1,5 @@ _decoder->getElementStartTag(self::TAG_TO) ? self::TAG_TO : - ($this->_decoder->getElementStartTag(self::TAG_OPTIONS) ? self::TAG_OPTIONS : - -1))) != -1) { + while ($status == self::STATUS_SUCCESS + && ($field = ($this->_decoder->getElementStartTag(self::TAG_TO) ? self::TAG_TO + : ($this->_decoder->getElementStartTag(self::TAG_OPTIONS) ? self::TAG_OPTIONS + : -1))) != -1) { if ($field == self::TAG_OPTIONS) { - while ($status == self::STATUS_SUCCESS && - ($option = ($this->_decoder->getElementStartTag(self::TAG_CERTIFICATERETRIEVAL) ? self::TAG_CERTIFICATERETRIEVAL : - ($this->_decoder->getElementStartTag(self::TAG_MAXCERTIFICATES) ? self::TAG_MAXCERTIFICATES : - ($this->_decoder->getElementStartTag(self::TAG_MAXAMBIGUOUSRECIPIENTS) ? self::TAG_MAXAMBIGUOUSRECIPIENTS : - ($this->_decoder->getElementStartTag(self::TAG_AVAILABILITY) ? self::TAG_AVAILABILITY : - ($this->_decoder->getElementStartTag(self::TAG_PICTURE) ? self::TAG_PICTURE : - -1)))))) != -1) { + while ($status == self::STATUS_SUCCESS + && ($option = ($this->_decoder->getElementStartTag(self::TAG_CERTIFICATERETRIEVAL) ? self::TAG_CERTIFICATERETRIEVAL + : ($this->_decoder->getElementStartTag(self::TAG_MAXCERTIFICATES) ? self::TAG_MAXCERTIFICATES + : ($this->_decoder->getElementStartTag(self::TAG_MAXAMBIGUOUSRECIPIENTS) ? self::TAG_MAXAMBIGUOUSRECIPIENTS + : ($this->_decoder->getElementStartTag(self::TAG_AVAILABILITY) ? self::TAG_AVAILABILITY + : ($this->_decoder->getElementStartTag(self::TAG_PICTURE) ? self::TAG_PICTURE + : -1)))))) != -1) { if ($option == self::TAG_AVAILABILITY) { $options[self::TAG_AVAILABILITY] = true; - while ($status == self::STATUS_SUCCESS && - ($tag = ($this->_decoder->getElementStartTag(self::TAG_STARTTIME) ? self::TAG_STARTTIME : - ($this->_decoder->getElementStartTag(self::TAG_ENDTIME) ? self::TAG_ENDTIME : - -1))) != -1) { + while ($status == self::STATUS_SUCCESS + && ($tag = ($this->_decoder->getElementStartTag(self::TAG_STARTTIME) ? self::TAG_STARTTIME + : ($this->_decoder->getElementStartTag(self::TAG_ENDTIME) ? self::TAG_ENDTIME + : -1))) != -1) { $options[$tag] = $this->_decoder->getElementContent(); if (!$this->_decoder->getElementEndTag()) { $status = self::STATUS_PROTERR; @@ -116,10 +117,10 @@ protected function _handle() } } elseif ($option == self::TAG_PICTURE) { $options[self::TAG_PICTURE] = true; - while ($status == self::STATUS_SUCCESS && - ($tag = ($this->_decoder->getElementStartTag(self::TAG_MAXSIZE) ? self::TAG_MAXSIZE : - ($this->_decoder->getElementStartTag(self::TAG_MAXPICTURES) ? self::TAG_MAXPICTURES : - -1 ))) != -1) { + while ($status == self::STATUS_SUCCESS + && ($tag = ($this->_decoder->getElementStartTag(self::TAG_MAXSIZE) ? self::TAG_MAXSIZE + : ($this->_decoder->getElementStartTag(self::TAG_MAXPICTURES) ? self::TAG_MAXPICTURES + : -1))) != -1) { if ($tag == self::TAG_MAXSIZE) { $options[self::TAG_MAXSIZE] = $this->_decoder->getElementContent(); @@ -130,7 +131,7 @@ protected function _handle() if ($tag == self::TAG_MAXPICTURES) { $options[self::TAG_MAXPICTURES] = $this->_decoder->getElementContent(); if (!$this->_decoder->getElementEndTag()) { - $status = self::STATUS_PROTERR; + $status = self::STATUS_PROTERR; } } } @@ -164,10 +165,10 @@ protected function _handle() $status = self::STATUS_PROTERR; } - $results = array(); + $results = []; if ($status == self::STATUS_SUCCESS) { foreach ($to as $item) { - $driver_opts = array( + $driver_opts = [ 'maxcerts' => !empty($options[self::TAG_MAXCERTIFICATES]) ? $options[self::TAG_MAXCERTIFICATES] : false, 'maxambiguous' => !empty($options[self::TAG_MAXAMBIGUOUSRECIPIENTS]) ? $options[self::TAG_MAXAMBIGUOUSRECIPIENTS] : false, 'starttime' => !empty($options[self::TAG_STARTTIME]) ? new Horde_Date($options[self::TAG_STARTTIME], 'utc') : false, @@ -175,7 +176,7 @@ protected function _handle() 'pictures' => !empty($options[self::TAG_PICTURE]), 'maxsize' => !empty($options[self::TAG_MAXSIZE]) ? $options[self::TAG_MAXSIZE] : false, 'maxpictures' => !empty($options[self::TAG_MAXPICTURES]) ? $options[self::TAG_MAXPICTURES] : false, - ); + ]; $results[$item] = $this->_driver->resolveRecipient( isset($options[self::TAG_CERTIFICATERETRIEVAL]) ? 'certificate' : 'availability', $item, @@ -228,8 +229,8 @@ protected function _handle() $this->_encoder->content($value['emailaddress']); $this->_encoder->endTag(); - if (isset($options[self::TAG_CERTIFICATERETRIEVAL]) && - $options[self::TAG_CERTIFICATERETRIEVAL] > 1) { + if (isset($options[self::TAG_CERTIFICATERETRIEVAL]) + && $options[self::TAG_CERTIFICATERETRIEVAL] > 1) { $this->_encoder->startTag(self::TAG_CERTIFICATES); @@ -247,19 +248,19 @@ protected function _handle() $this->_encoder->endTag(); switch ($options[self::TAG_CERTIFICATERETRIEVAL]) { - case self::CERT_RETRIEVAL_FULL: - foreach($value['entries'] as $cert) { - $this->_encoder->startTag(self::TAG_CERTIFICATE); - $this->_encoder->content($cert); - $this->_encoder->endTag(); - } - break; - case self::CERT_RETRIEVAL_MINI: - foreach($value['entries'] as $cert) { - $this->_encoder->startTag(self::TAG_MINICERTIFICATE); - $this->_encoder->content($cert); - $this->_encoder->endTag(); - } + case self::CERT_RETRIEVAL_FULL: + foreach ($value['entries'] as $cert) { + $this->_encoder->startTag(self::TAG_CERTIFICATE); + $this->_encoder->content($cert); + $this->_encoder->endTag(); + } + break; + case self::CERT_RETRIEVAL_MINI: + foreach ($value['entries'] as $cert) { + $this->_encoder->startTag(self::TAG_MINICERTIFICATE); + $this->_encoder->content($cert); + $this->_encoder->endTag(); + } } $this->_encoder->endTag(); } @@ -279,9 +280,9 @@ protected function _handle() $this->_encoder->endTag(); } - if ($this->_device->version >= Horde_ActiveSync::VERSION_FOURTEENONE && - isset($options[self::TAG_PICTURE]) && - !empty($value['picture'])) { + if ($this->_device->version >= Horde_ActiveSync::VERSION_FOURTEENONE + && isset($options[self::TAG_PICTURE]) + && !empty($value['picture'])) { $this->_encoder->startTag(self::TAG_PICTURE); $value['picture']->encodeStream($this->_encoder); diff --git a/lib/Horde/ActiveSync/Request/Search.php b/lib/Horde/ActiveSync/Request/Search.php index 4cd3cfb7..babffe67 100644 --- a/lib/Horde/ActiveSync/Request/Search.php +++ b/lib/Horde/ActiveSync/Request/Search.php @@ -1,4 +1,5 @@ _collections = $this->_activeSync->getCollectionsObject(); - if (!$this->_decoder->getElementStartTag(self::SEARCH_SEARCH) || - !$this->_decoder->getElementStartTag(self::SEARCH_STORE) || - !$this->_decoder->getElementStartTag(self::SEARCH_NAME)) { + if (!$this->_decoder->getElementStartTag(self::SEARCH_SEARCH) + || !$this->_decoder->getElementStartTag(self::SEARCH_STORE) + || !$this->_decoder->getElementStartTag(self::SEARCH_NAME)) { throw new Horde_ActiveSync_Exception_InvalidRequest('Missing required SEARCH|STORE|NAME'); } @@ -124,23 +125,24 @@ protected function _handle() $maxResults = 100; switch (Horde_String::lower($search_name)) { - case 'documentlibrary': - $maxResults = 1000; - // fall through - case 'mailbox': - $query = $this->_parseQuery(); - if (!$query) { + case 'documentlibrary': + $maxResults = 1000; + // fall through + // no break + case 'mailbox': + $query = $this->_parseQuery(); + if (!$query) { + $search_status = self::SEARCH_STATUS_ERROR; + $store_status = self::STORE_STATUS_PROTERR; + } + break; + case 'gal': + $query = (array) $this->_decoder->getElementContent(); + break; + default: + $query = null; $search_status = self::SEARCH_STATUS_ERROR; $store_status = self::STORE_STATUS_PROTERR; - } - break; - case 'gal': - $query = (array) $this->_decoder->getElementContent(); - break; - default: - $query = null; - $search_status = self::SEARCH_STATUS_ERROR; - $store_status = self::STORE_STATUS_PROTERR; } if (!$this->_decoder->getElementEndTag()) { @@ -154,7 +156,7 @@ protected function _handle() $mime = Horde_ActiveSync::MIME_SUPPORT_NONE; $searchbodypreference = []; if ($this->_decoder->getElementStartTag(self::SEARCH_OPTIONS)) { - while(1) { + while (1) { if ($this->_decoder->getElementStartTag(self::SEARCH_RANGE)) { //FIXME: The result of including more than one Range element in a Search command request // is undefined. The server MAY return a protocol status error in response to such a command request. @@ -185,11 +187,11 @@ protected function _handle() } } if ($this->_decoder->getElementStartTag(self::SEARCH_PASSWORD)) { - if (!($options['password'] = $this->_decoder->getElementContent())) + if (!($options['password'] = $this->_decoder->getElementContent())) { return false; - else - if(!$this->_decoder->getElementEndTag()) + } elseif (!$this->_decoder->getElementEndTag()) { return false; + } } if ($this->_decoder->getElementStartTag(self::SEARCH_SCHEMA)) { if (!($options['schema'] = $this->_decoder->getElementContent())) { @@ -226,7 +228,7 @@ protected function _handle() // EAS 14.1 if ($this->_device->version >= Horde_ActiveSync::VERSION_FOURTEENONE) { - $rm = array(); + $rm = []; if ($this->_decoder->getElementStartTag(Horde_ActiveSync::RM_SUPPORT)) { $this->_rightsManagement($rm); } @@ -259,8 +261,8 @@ protected function _handle() $limit = $maxResults; if ($range !== null) { if (preg_match('/^(\d+)-(\d+)$/', $range, $matches)) { - $start = (int)$matches[1]; - $end = (int)$matches[2]; + $start = (int) $matches[1]; + $end = (int) $matches[2]; if ($end < $start) { $store_status = self::STORE_STATUS_PROTERR; } else { @@ -278,7 +280,7 @@ protected function _handle() } } - // In the Search command response, the Total element (section 2.2.3.184.3) indicates an estimate + // In the Search command response, the Total element (section 2.2.3.184.3) indicates an estimate // of the total number of entries that matched the Query element (section 2.2.3.142.2) value. if ($store_status === self::STORE_STATUS_SUCCESS && $query) { // Prepare search parameters @@ -322,102 +324,102 @@ protected function _handle() if ($results && $results->rows) { foreach ($results->rows as $u) { switch (Horde_String::lower($search_name)) { - case 'documentlibrary': - $this->_encoder->startTag(self::SEARCH_RESULT); - - $doc = Horde_ActiveSync::messageFactory('DocumentLibrary'); - $doc->linkid = $u['linkid']; - $doc->displayname = $u['name']; - $doc->isfolder = $u['is_folder'] ? '1' : '0'; - $doc->creationdate = $u['created']; - $doc->lastmodifieddate = $u['modified']; - $doc->ishidden = '0'; - $doc->contentlength = $u['content-length']; - if (!empty($u['content-type'])) { - $doc->contenttype = $u['content-type']; - } - - $this->_encoder->startTag(self::SEARCH_PROPERTIES); - $doc->encodeStream($this->_encoder); - $this->_encoder->endTag(); + case 'documentlibrary': + $this->_encoder->startTag(self::SEARCH_RESULT); + + $doc = Horde_ActiveSync::messageFactory('DocumentLibrary'); + $doc->linkid = $u['linkid']; + $doc->displayname = $u['name']; + $doc->isfolder = $u['is_folder'] ? '1' : '0'; + $doc->creationdate = $u['created']; + $doc->lastmodifieddate = $u['modified']; + $doc->ishidden = '0'; + $doc->contentlength = $u['content-length']; + if (!empty($u['content-type'])) { + $doc->contenttype = $u['content-type']; + } - $this->_encoder->endTag(); - break; + $this->_encoder->startTag(self::SEARCH_PROPERTIES); + $doc->encodeStream($this->_encoder); + $this->_encoder->endTag(); - case 'gal': - $this->_encoder->startTag(self::SEARCH_RESULT); - $this->_encoder->startTag(self::SEARCH_PROPERTIES); + $this->_encoder->endTag(); + break; - $this->_encoder->startTag(Horde_ActiveSync::GAL_DISPLAYNAME); - $this->_encoder->content($u[Horde_ActiveSync::GAL_DISPLAYNAME]); - $this->_encoder->endTag(); + case 'gal': + $this->_encoder->startTag(self::SEARCH_RESULT); + $this->_encoder->startTag(self::SEARCH_PROPERTIES); - $this->_encoder->startTag(Horde_ActiveSync::GAL_PHONE); - $this->_encoder->content($u[Horde_ActiveSync::GAL_PHONE]); - $this->_encoder->endTag(); + $this->_encoder->startTag(Horde_ActiveSync::GAL_DISPLAYNAME); + $this->_encoder->content($u[Horde_ActiveSync::GAL_DISPLAYNAME]); + $this->_encoder->endTag(); - $this->_encoder->startTag(Horde_ActiveSync::GAL_OFFICE); - $this->_encoder->content($u[Horde_ActiveSync::GAL_OFFICE]); - $this->_encoder->endTag(); + $this->_encoder->startTag(Horde_ActiveSync::GAL_PHONE); + $this->_encoder->content($u[Horde_ActiveSync::GAL_PHONE]); + $this->_encoder->endTag(); - $this->_encoder->startTag(Horde_ActiveSync::GAL_TITLE); - $this->_encoder->content($u[Horde_ActiveSync::GAL_TITLE]); - $this->_encoder->endTag(); + $this->_encoder->startTag(Horde_ActiveSync::GAL_OFFICE); + $this->_encoder->content($u[Horde_ActiveSync::GAL_OFFICE]); + $this->_encoder->endTag(); - $this->_encoder->startTag(Horde_ActiveSync::GAL_COMPANY); - $this->_encoder->content($u[Horde_ActiveSync::GAL_COMPANY]); - $this->_encoder->endTag(); + $this->_encoder->startTag(Horde_ActiveSync::GAL_TITLE); + $this->_encoder->content($u[Horde_ActiveSync::GAL_TITLE]); + $this->_encoder->endTag(); - $this->_encoder->startTag(Horde_ActiveSync::GAL_ALIAS); - $this->_encoder->content($u[Horde_ActiveSync::GAL_ALIAS]); - $this->_encoder->endTag(); + $this->_encoder->startTag(Horde_ActiveSync::GAL_COMPANY); + $this->_encoder->content($u[Horde_ActiveSync::GAL_COMPANY]); + $this->_encoder->endTag(); - $this->_encoder->startTag(Horde_ActiveSync::GAL_FIRSTNAME); - $this->_encoder->content($u[Horde_ActiveSync::GAL_FIRSTNAME]); - $this->_encoder->endTag(); + $this->_encoder->startTag(Horde_ActiveSync::GAL_ALIAS); + $this->_encoder->content($u[Horde_ActiveSync::GAL_ALIAS]); + $this->_encoder->endTag(); - $this->_encoder->startTag(Horde_ActiveSync::GAL_LASTNAME); - $this->_encoder->content($u[Horde_ActiveSync::GAL_LASTNAME]); - $this->_encoder->endTag(); + $this->_encoder->startTag(Horde_ActiveSync::GAL_FIRSTNAME); + $this->_encoder->content($u[Horde_ActiveSync::GAL_FIRSTNAME]); + $this->_encoder->endTag(); - $this->_encoder->startTag(Horde_ActiveSync::GAL_HOMEPHONE); - $this->_encoder->content($u[Horde_ActiveSync::GAL_HOMEPHONE]); - $this->_encoder->endTag(); + $this->_encoder->startTag(Horde_ActiveSync::GAL_LASTNAME); + $this->_encoder->content($u[Horde_ActiveSync::GAL_LASTNAME]); + $this->_encoder->endTag(); - $this->_encoder->startTag(Horde_ActiveSync::GAL_MOBILEPHONE); - $this->_encoder->content($u[Horde_ActiveSync::GAL_MOBILEPHONE]); - $this->_encoder->endTag(); + $this->_encoder->startTag(Horde_ActiveSync::GAL_HOMEPHONE); + $this->_encoder->content($u[Horde_ActiveSync::GAL_HOMEPHONE]); + $this->_encoder->endTag(); - $this->_encoder->startTag(Horde_ActiveSync::GAL_EMAILADDRESS); - $this->_encoder->content($u[Horde_ActiveSync::GAL_EMAILADDRESS]); - $this->_encoder->endTag(); + $this->_encoder->startTag(Horde_ActiveSync::GAL_MOBILEPHONE); + $this->_encoder->content($u[Horde_ActiveSync::GAL_MOBILEPHONE]); + $this->_encoder->endTag(); - if ($this->_device->version >= Horde_ActiveSync::VERSION_FOURTEENONE && - !empty($u[Horde_ActiveSync::GAL_PICTURE])) { - $this->_encoder->startTag(Horde_ActiveSync::GAL_PICTURE); - $u[Horde_ActiveSync::GAL_PICTURE]->encodeStream($this->_encoder); + $this->_encoder->startTag(Horde_ActiveSync::GAL_EMAILADDRESS); + $this->_encoder->content($u[Horde_ActiveSync::GAL_EMAILADDRESS]); $this->_encoder->endTag(); - } - $this->_encoder->endTag();//properties - $this->_encoder->endTag();//result - break; - case 'mailbox': - $this->_encoder->startTag(self::SEARCH_RESULT); - $this->_encoder->startTag(Horde_ActiveSync::SYNC_FOLDERTYPE); - $this->_encoder->content(Horde_ActiveSync::CLASS_EMAIL); - $this->_encoder->endTag(); - $this->_encoder->startTag(self::SEARCH_LONGID); - $this->_encoder->content($u['uniqueid']); - $this->_encoder->endTag(); - $this->_encoder->startTag(Horde_ActiveSync::SYNC_FOLDERID); - $this->_encoder->content($this->_collections->getFolderUidForBackendId($u['searchfolderid'])); - $this->_encoder->endTag(); - $this->_encoder->startTag(self::SEARCH_PROPERTIES); - $msg = $this->_driver->ItemOperationsFetchMailbox($u['uniqueid'], $searchbodypreference, $mime); - $msg->encodeStream($this->_encoder); - $this->_encoder->endTag();//properties - $this->_encoder->endTag();//result + if ($this->_device->version >= Horde_ActiveSync::VERSION_FOURTEENONE + && !empty($u[Horde_ActiveSync::GAL_PICTURE])) { + $this->_encoder->startTag(Horde_ActiveSync::GAL_PICTURE); + $u[Horde_ActiveSync::GAL_PICTURE]->encodeStream($this->_encoder); + $this->_encoder->endTag(); + } + + $this->_encoder->endTag();//properties + $this->_encoder->endTag();//result + break; + case 'mailbox': + $this->_encoder->startTag(self::SEARCH_RESULT); + $this->_encoder->startTag(Horde_ActiveSync::SYNC_FOLDERTYPE); + $this->_encoder->content(Horde_ActiveSync::CLASS_EMAIL); + $this->_encoder->endTag(); + $this->_encoder->startTag(self::SEARCH_LONGID); + $this->_encoder->content($u['uniqueid']); + $this->_encoder->endTag(); + $this->_encoder->startTag(Horde_ActiveSync::SYNC_FOLDERID); + $this->_encoder->content($this->_collections->getFolderUidForBackendId($u['searchfolderid'])); + $this->_encoder->endTag(); + $this->_encoder->startTag(self::SEARCH_PROPERTIES); + $msg = $this->_driver->ItemOperationsFetchMailbox($u['uniqueid'], $searchbodypreference, $mime); + $msg->encodeStream($this->_encoder); + $this->_encoder->endTag();//properties + $this->_encoder->endTag();//result } } @@ -452,58 +454,58 @@ protected function _handle() */ protected function _parseQuery($subquery = null) { - $query = array(); - while (($type = ($this->_decoder->getElementStartTag(self::SEARCH_AND) ? self::SEARCH_AND : - ($this->_decoder->getElementStartTag(self::SEARCH_OR) ? self::SEARCH_OR : - ($this->_decoder->getElementStartTag(self::SEARCH_EQUALTO) ? self::SEARCH_EQUALTO : - ($this->_decoder->getElementStartTag(self::SEARCH_LESSTHAN) ? self::SEARCH_LESSTHAN : - ($this->_decoder->getElementStartTag(self::SEARCH_GREATERTHAN) ? self::SEARCH_GREATERTHAN : - ($this->_decoder->getElementStartTag(self::SEARCH_FREETEXT) ? self::SEARCH_FREETEXT : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FOLDERID) ? Horde_ActiveSync::SYNC_FOLDERID : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FOLDERTYPE) ? Horde_ActiveSync::SYNC_FOLDERTYPE : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_LINKID) ? Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_LINKID : - ($this->_decoder->getElementStartTag(Horde_ActiveSync_Message_Mail::POOMMAIL_DATERECEIVED) ? Horde_ActiveSync_Message_Mail::POOMMAIL_DATERECEIVED : - -1))))))))))) != -1) { + $query = []; + while (($type = ($this->_decoder->getElementStartTag(self::SEARCH_AND) ? self::SEARCH_AND + : ($this->_decoder->getElementStartTag(self::SEARCH_OR) ? self::SEARCH_OR + : ($this->_decoder->getElementStartTag(self::SEARCH_EQUALTO) ? self::SEARCH_EQUALTO + : ($this->_decoder->getElementStartTag(self::SEARCH_LESSTHAN) ? self::SEARCH_LESSTHAN + : ($this->_decoder->getElementStartTag(self::SEARCH_GREATERTHAN) ? self::SEARCH_GREATERTHAN + : ($this->_decoder->getElementStartTag(self::SEARCH_FREETEXT) ? self::SEARCH_FREETEXT + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FOLDERID) ? Horde_ActiveSync::SYNC_FOLDERID + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FOLDERTYPE) ? Horde_ActiveSync::SYNC_FOLDERTYPE + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_LINKID) ? Horde_ActiveSync::SYNC_DOCUMENTLIBRARY_LINKID + : ($this->_decoder->getElementStartTag(Horde_ActiveSync_Message_Mail::POOMMAIL_DATERECEIVED) ? Horde_ActiveSync_Message_Mail::POOMMAIL_DATERECEIVED + : -1))))))))))) != -1) { switch ($type) { - case self::SEARCH_AND: - case self::SEARCH_OR: - case self::SEARCH_EQUALTO: - case self::SEARCH_LESSTHAN: - case self::SEARCH_GREATERTHAN: - $q = array( - 'op' => $type, - 'value' => $this->_parseQuery(true) - ); - if ($subquery) { - $query['subquery'][] = $q; - } else { - $query[] = $q; - } - $this->_decoder->getElementEndTag(); - break; - default: - if (($query[$type] = $this->_decoder->getElementContent())) { - if ($type == Horde_ActiveSync::SYNC_FOLDERID) { - try { - $query['serverid'] = $this->_collections->getBackendIdForFolderUid($query[$type]); - } catch (Horde_ActiveSync_Exception_FolderGone $e) { - $this->_logger->err($e->getMessage()); - } - } - $this->_decoder->getElementEndTag(); - } else { - $this->_decoder->getElementStartTag(self::SEARCH_VALUE); - $query[$type] = $this->_decoder->getElementContent(); - switch ($type) { - case Horde_ActiveSync_Message_Mail::POOMMAIL_DATERECEIVED: - $query[$type] = new Horde_Date($query[$type]); - break; + case self::SEARCH_AND: + case self::SEARCH_OR: + case self::SEARCH_EQUALTO: + case self::SEARCH_LESSTHAN: + case self::SEARCH_GREATERTHAN: + $q = [ + 'op' => $type, + 'value' => $this->_parseQuery(true), + ]; + if ($subquery) { + $query['subquery'][] = $q; + } else { + $query[] = $q; } $this->_decoder->getElementEndTag(); - }; - break; + break; + default: + if (($query[$type] = $this->_decoder->getElementContent())) { + if ($type == Horde_ActiveSync::SYNC_FOLDERID) { + try { + $query['serverid'] = $this->_collections->getBackendIdForFolderUid($query[$type]); + } catch (Horde_ActiveSync_Exception_FolderGone $e) { + $this->_logger->err($e->getMessage()); + } + } + $this->_decoder->getElementEndTag(); + } else { + $this->_decoder->getElementStartTag(self::SEARCH_VALUE); + $query[$type] = $this->_decoder->getElementContent(); + switch ($type) { + case Horde_ActiveSync_Message_Mail::POOMMAIL_DATERECEIVED: + $query[$type] = new Horde_Date($query[$type]); + break; + } + $this->_decoder->getElementEndTag(); + }; + break; } } diff --git a/lib/Horde/ActiveSync/Request/SendMail.php b/lib/Horde/ActiveSync/Request/SendMail.php index e0d318e7..7ed493f5 100644 --- a/lib/Horde/ActiveSync/Request/SendMail.php +++ b/lib/Horde/ActiveSync/Request/SendMail.php @@ -1,4 +1,5 @@ _logger->err($e->getMessage()); $this->_handleError( Horde_ActiveSync_Status::MAIL_SUBMISSION_FAILED, - Horde_ActiveSync_Message_SendMail::COMPOSEMAIL_SENDMAIL); + Horde_ActiveSync_Message_SendMail::COMPOSEMAIL_SENDMAIL + ); return true; } @@ -71,33 +73,35 @@ protected function _handleWbxmlRequest() if ($e[Horde_ActiveSync_Wbxml::EN_TYPE] != Horde_ActiveSync_Wbxml::EN_TYPE_STARTTAG) { $this->_handleError( Horde_ActiveSync_Status::INVALID_WBXML, - Horde_ActiveSync_Message_SendMail::COMPOSEMAIL_SENDMAIL); + Horde_ActiveSync_Message_SendMail::COMPOSEMAIL_SENDMAIL + ); return true; } $sendmail = $smartreply = $smartforward = false; switch ($e[Horde_ActiveSync_Wbxml::EN_TAG]) { - case Horde_ActiveSync_Message_SendMail::COMPOSEMAIL_SENDMAIL: - $sendmail = true; - break; - case Horde_ActiveSync_Message_SendMail::COMPOSEMAIL_SMARTREPLY: - $smartreply = true; - break; - case Horde_ActiveSync_Message_SendMail::COMPOSEMAIL_SMARTFORWARD: - $smartforward = true; + case Horde_ActiveSync_Message_SendMail::COMPOSEMAIL_SENDMAIL: + $sendmail = true; + break; + case Horde_ActiveSync_Message_SendMail::COMPOSEMAIL_SMARTREPLY: + $smartreply = true; + break; + case Horde_ActiveSync_Message_SendMail::COMPOSEMAIL_SMARTFORWARD: + $smartforward = true; } if (!$sendmail && !$smartreply && !$smartforward) { - return $this->_handleError( - Horde_ActiveSync_Status::INVALID_CONTENT, - Horde_ActiveSync_Message_SendMail::COMPOSEMAIL_SENDMAIL); + return $this->_handleError( + Horde_ActiveSync_Status::INVALID_CONTENT, + Horde_ActiveSync_Message_SendMail::COMPOSEMAIL_SENDMAIL + ); } $mail = Horde_ActiveSync::messageFactory('SendMail'); $mail->decodeStream($this->_decoder); if ($smartreply || $smartforward) { - $mail->source->folderid = - $this->_activeSync->getCollectionsObject() + $mail->source->folderid + = $this->_activeSync->getCollectionsObject() ->getBackendIdForFolderUid($mail->source->folderid); } @@ -108,7 +112,8 @@ protected function _handleWbxmlRequest() $this->_logger->err($ex->getMessage()); $this->_handleError( Horde_ActiveSync_Status::ITEM_NOT_FOUND, - $e[Horde_ActiveSync_Wbxml::EN_TAG]); + $e[Horde_ActiveSync_Wbxml::EN_TAG] + ); } catch (Horde_ActiveSync_Exception_EmailFatalFailure $ex) { $this->_logger->err($ex->getMessage()); if ($this->_device->version < Horde_ActiveSync::VERSION_FOURTEEN) { @@ -120,7 +125,8 @@ protected function _handleWbxmlRequest() } $this->_handleError( Horde_ActiveSync_Status::SERVER_ERROR, - $e[Horde_ActiveSync_Wbxml::EN_TAG]); + $e[Horde_ActiveSync_Wbxml::EN_TAG] + ); } catch (Horde_ActiveSync_Exception $ex) { $this->_logger->err($ex->getMessage()); if ($this->_device->version < Horde_ActiveSync::VERSION_FOURTEEN) { @@ -131,7 +137,8 @@ protected function _handleWbxmlRequest() } $this->_handleError( Horde_ActiveSync_Status::MAIL_SUBMISSION_FAILED, - $e[Horde_ActiveSync_Wbxml::EN_TAG]); + $e[Horde_ActiveSync_Wbxml::EN_TAG] + ); } return true; diff --git a/lib/Horde/ActiveSync/Request/Settings.php b/lib/Horde/ActiveSync/Request/Settings.php index 28133f87..98deac92 100644 --- a/lib/Horde/ActiveSync/Request/Settings.php +++ b/lib/Horde/ActiveSync/Request/Settings.php @@ -1,4 +1,5 @@ _device->version; - $request = array(); - while (($reqtype = ($this->_decoder->getElementStartTag(self::SETTINGS_OOF) ? self::SETTINGS_OOF : - ($this->_decoder->getElementStartTag(self::SETTINGS_DEVICEINFORMATION) ? self::SETTINGS_DEVICEINFORMATION : - ($this->_decoder->getElementStartTag(self::SETTINGS_USERINFORMATION) ? self::SETTINGS_USERINFORMATION : - ($this->_decoder->getElementStartTag(self::SETTINGS_DEVICEPASSWORD) ? self::SETTINGS_DEVICEPASSWORD : - ($this->_decoder->getElementStartTag(self::SETTINGS_RIGHTSMANAGEMENTINFO) ? self::SETTINGS_RIGHTSMANAGEMENTINFO : - -1)))))) != -1) { + $request = []; + while (($reqtype = ($this->_decoder->getElementStartTag(self::SETTINGS_OOF) ? self::SETTINGS_OOF + : ($this->_decoder->getElementStartTag(self::SETTINGS_DEVICEINFORMATION) ? self::SETTINGS_DEVICEINFORMATION + : ($this->_decoder->getElementStartTag(self::SETTINGS_USERINFORMATION) ? self::SETTINGS_USERINFORMATION + : ($this->_decoder->getElementStartTag(self::SETTINGS_DEVICEPASSWORD) ? self::SETTINGS_DEVICEPASSWORD + : ($this->_decoder->getElementStartTag(self::SETTINGS_RIGHTSMANAGEMENTINFO) ? self::SETTINGS_RIGHTSMANAGEMENTINFO + : -1)))))) != -1) { - while (($querytype = ($this->_decoder->getElementStartTag(self::SETTINGS_GET) ? self::SETTINGS_GET : - ($this->_decoder->getElementStartTag(self::SETTINGS_SET) ? self::SETTINGS_SET : - -1))) != -1) { + while (($querytype = ($this->_decoder->getElementStartTag(self::SETTINGS_GET) ? self::SETTINGS_GET + : ($this->_decoder->getElementStartTag(self::SETTINGS_SET) ? self::SETTINGS_SET + : -1))) != -1) { switch ($querytype) { - case self::SETTINGS_GET: - switch ($reqtype) { - case self::SETTINGS_OOF: - $oof = Horde_ActiveSync::messageFactory('Oof'); - $oof->decodeStream($this->_decoder); - $request['get']['oof']['bodytype'] = $oof->bodytype; - $this->_decoder->getElementEndTag(); // SETTINGS_GET - break; - case self::SETTINGS_USERINFORMATION: - // These are empty tags. - $request['get']['userinformation'] = array(); - $this->_decoder->getElementContent(); - break; - case self::SETTINGS_RIGHTSMANAGEMENTINFO: - // These are empty tags. - $request['get']['rightsmanagementinfo'] = true; - $this->_decoder->getElementContent(); + case self::SETTINGS_GET: + switch ($reqtype) { + case self::SETTINGS_OOF: + $oof = Horde_ActiveSync::messageFactory('Oof'); + $oof->decodeStream($this->_decoder); + $request['get']['oof']['bodytype'] = $oof->bodytype; + $this->_decoder->getElementEndTag(); // SETTINGS_GET + break; + case self::SETTINGS_USERINFORMATION: + // These are empty tags. + $request['get']['userinformation'] = []; + $this->_decoder->getElementContent(); + break; + case self::SETTINGS_RIGHTSMANAGEMENTINFO: + // These are empty tags. + $request['get']['rightsmanagementinfo'] = true; + $this->_decoder->getElementContent(); + break; + } break; - } - break; - case self::SETTINGS_SET: - switch ($reqtype) { - case self::SETTINGS_OOF: - $oof = Horde_ActiveSync::messageFactory('Oof'); - $oof->decodeStream($this->_decoder); + case self::SETTINGS_SET: + switch ($reqtype) { + case self::SETTINGS_OOF: + $oof = Horde_ActiveSync::messageFactory('Oof'); + $oof->decodeStream($this->_decoder); - $request['set']['oof']['oofstate'] = $oof->state; - $request['set']['oof']['starttime'] = $oof->starttime; - $request['set']['oof']['endtime'] = $oof->endtime; - $request['set']['oof']['oofmsgs'] = array(); - foreach ($oof->messages as $msg) { - $message = array(); - $message['appliesto'] = !empty($msg->internal) - ? Horde_ActiveSync_Request_Settings::SETTINGS_APPLIESTOINTERNAL - : (!empty($msg->externalknown) - ? Horde_ActiveSync_Request_Settings::SETTINGS_APPLIESTOEXTERNALKNOWN - : Horde_ActiveSync_Request_Settings::SETTINGS_APPLIESTOEXTERNALUNKNOWN); - $message['enabled'] = $msg->enabled; - $message['replymessage'] = $msg->reply; - $message['bodytype'] = $msg->bodytype; - $request['set']['oof']['oofmsgs'][] = $message; - } - break; - case self::SETTINGS_DEVICEINFORMATION : - // @TODO Clean the return values up when we can break bc. - $device_properties = $this->_device->properties; - $settings = Horde_ActiveSync::messageFactory('DeviceInformation'); - $settings->decodeStream($this->_decoder); - $device_properties[self::SETTINGS_MODEL] = $settings->model; - $device_properties[self::SETTINGS_IMEI] = $settings->imei; - $device_properties[self::SETTINGS_FRIENDLYNAME] = $settings->friendlyname; - $device_properties[self::SETTINGS_OS] = $settings->os; - $device_properties[self::SETTINGS_OSLANGUAGE] = $settings->oslanguage; - $device_properties[self::SETTINGS_PHONENUMBER] = $settings->phonenumber; - $device_properties[self::SETTINGS_USERAGENT] = $settings->useragent; - $device_properties[self::SETTINGS_MOBILEOPERATOR] = $settings->mobileoperator; - $device_properties[self::SETTINGS_ENABLEOUTBOUNDSMS] = $settings->enableoutboundsms; + $request['set']['oof']['oofstate'] = $oof->state; + $request['set']['oof']['starttime'] = $oof->starttime; + $request['set']['oof']['endtime'] = $oof->endtime; + $request['set']['oof']['oofmsgs'] = []; + foreach ($oof->messages as $msg) { + $message = []; + $message['appliesto'] = !empty($msg->internal) + ? Horde_ActiveSync_Request_Settings::SETTINGS_APPLIESTOINTERNAL + : (!empty($msg->externalknown) + ? Horde_ActiveSync_Request_Settings::SETTINGS_APPLIESTOEXTERNALKNOWN + : Horde_ActiveSync_Request_Settings::SETTINGS_APPLIESTOEXTERNALUNKNOWN); + $message['enabled'] = $msg->enabled; + $message['replymessage'] = $msg->reply; + $message['bodytype'] = $msg->bodytype; + $request['set']['oof']['oofmsgs'][] = $message; + } + break; + case self::SETTINGS_DEVICEINFORMATION: + // @TODO Clean the return values up when we can break bc. + $device_properties = $this->_device->properties; + $settings = Horde_ActiveSync::messageFactory('DeviceInformation'); + $settings->decodeStream($this->_decoder); + $device_properties[self::SETTINGS_MODEL] = $settings->model; + $device_properties[self::SETTINGS_IMEI] = $settings->imei; + $device_properties[self::SETTINGS_FRIENDLYNAME] = $settings->friendlyname; + $device_properties[self::SETTINGS_OS] = $settings->os; + $device_properties[self::SETTINGS_OSLANGUAGE] = $settings->oslanguage; + $device_properties[self::SETTINGS_PHONENUMBER] = $settings->phonenumber; + $device_properties[self::SETTINGS_USERAGENT] = $settings->useragent; + $device_properties[self::SETTINGS_MOBILEOPERATOR] = $settings->mobileoperator; + $device_properties[self::SETTINGS_ENABLEOUTBOUNDSMS] = $settings->enableoutboundsms; - try { - $device_properties['version'] = $version; - $this->_device->setDeviceProperties($device_properties); - $this->_device->save(); - } catch (Horde_ActiveSync_Exception $e) { - $this->_logger->err($e->getMessage()); - unset($device_properties); - } - break; - case self::SETTINGS_DEVICEPASSWORD : - $this->_decoder->getElementStartTag(self::SETTINGS_PASSWORD); - if (($password = $this->_decoder->getElementContent()) !== false) { - $this->_decoder->getElementEndTag(); // end $field + try { + $device_properties['version'] = $version; + $this->_device->setDeviceProperties($device_properties); + $this->_device->save(); + } catch (Horde_ActiveSync_Exception $e) { + $this->_logger->err($e->getMessage()); + unset($device_properties); + } + break; + case self::SETTINGS_DEVICEPASSWORD: + $this->_decoder->getElementStartTag(self::SETTINGS_PASSWORD); + if (($password = $this->_decoder->getElementContent()) !== false) { + $this->_decoder->getElementEndTag(); // end $field + } + $request['set']['devicepassword'] = $password; + break; } - $request['set']['devicepassword'] = $password; - break; - } - $this->_decoder->getElementEndTag(); // SETTINGS_SET - break; + $this->_decoder->getElementEndTag(); // SETTINGS_SET + break; } } // SETTINGS_OOF || SETTINGS_DEVICEPW || SETTINGS_DEVICEINFORMATION || SETTINGS_USERINFORMATION @@ -245,9 +246,9 @@ protected function _handle() $encoder->endTag(); // end self::SETTINGS_STATUS $encoder->endTag(); // end self::SETTINGS_DEVICEPASSWORD } - if ($version >= Horde_ActiveSync::VERSION_TWELVE && - isset($request['get']['userinformation']) && - isset($result['get']['userinformation'])) { + if ($version >= Horde_ActiveSync::VERSION_TWELVE + && isset($request['get']['userinformation']) + && isset($result['get']['userinformation'])) { $encoder->startTag(self::SETTINGS_USERINFORMATION); $encoder->startTag(self::SETTINGS_STATUS); $encoder->content($result['get']['userinformation']['status']); @@ -281,7 +282,7 @@ protected function _handle() $encoder->startTag(self::SETTINGS_PRIMARYSMTPADDRESS); $encoder->content($account['emailaddresses'][0]); $encoder->endTag(); // end self::SETTINGS_PRIMARYSMTPADDRESS - foreach($account['emailaddresses'] as $value) { + foreach ($account['emailaddresses'] as $value) { $encoder->startTag(self::SETTINGS_SMTPADDRESS); $encoder->content($value); $encoder->endTag(); // end self::SETTINGS_SMTPADDRESS @@ -295,7 +296,7 @@ protected function _handle() } else { // EAS 12.0, 12.1, 14.0 $encoder->startTag(self::SETTINGS_EMAILADDRESSES); if (!empty($result['get']['userinformation']['emailaddresses'])) { - foreach($result['get']['userinformation']['emailaddresses'] as $value) { + foreach ($result['get']['userinformation']['emailaddresses'] as $value) { $encoder->startTag(self::SETTINGS_SMTPADDRESS); $encoder->content($value); $encoder->endTag(); // end self::SETTINGS_SMTPADDRESS diff --git a/lib/Horde/ActiveSync/Request/SmartForward.php b/lib/Horde/ActiveSync/Request/SmartForward.php index f8674cf1..862b3454 100644 --- a/lib/Horde/ActiveSync/Request/SmartForward.php +++ b/lib/Horde/ActiveSync/Request/SmartForward.php @@ -1,4 +1,5 @@ _logger->err($e->getMessage()); $this->_handleError( Horde_ActiveSync_Status::ITEM_NOT_FOUND, - Horde_ActiveSync_Message_SendMail::COMPOSEMAIL_SMARTFORWARD); + Horde_ActiveSync_Message_SendMail::COMPOSEMAIL_SMARTFORWARD + ); } catch (Horde_ActiveSync_Exception $e) { $this->_handleError( Horde_ActiveSync_Status::MAIL_SUBMISSION_FAILED, - Horde_ActiveSync_Message_SendMail::COMPOSEMAIL_SMARTFORWARD); + Horde_ActiveSync_Message_SendMail::COMPOSEMAIL_SMARTFORWARD + ); } return true; diff --git a/lib/Horde/ActiveSync/Request/SmartReply.php b/lib/Horde/ActiveSync/Request/SmartReply.php index 772be76d..3f523f01 100644 --- a/lib/Horde/ActiveSync/Request/SmartReply.php +++ b/lib/Horde/ActiveSync/Request/SmartReply.php @@ -1,4 +1,5 @@ _logger->err($e->getMessage()); $this->_handleError( Horde_ActiveSync_Status::ITEM_NOT_FOUND, - Horde_ActiveSync_Message_SendMail::COMPOSEMAIL_SMARTREPLY); + Horde_ActiveSync_Message_SendMail::COMPOSEMAIL_SMARTREPLY + ); } catch (Horde_ActiveSync_Exception $e) { $this->_handleError( Horde_ActiveSync_Status::MAIL_REPLY_FAILED, - Horde_ActiveSync_Message_SendMail::COMPOSEMAIL_SMARTREPLY); + Horde_ActiveSync_Message_SendMail::COMPOSEMAIL_SMARTREPLY + ); } return true; diff --git a/lib/Horde/ActiveSync/Request/Sync.php b/lib/Horde/ActiveSync/Request/Sync.php index 402b9e71..7013ac70 100644 --- a/lib/Horde/ActiveSync/Request/Sync.php +++ b/lib/Horde/ActiveSync/Request/Sync.php @@ -1,4 +1,5 @@ _collections->hangingSync = false; - while (($sync_tag = ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_WINDOWSIZE) ? Horde_ActiveSync::SYNC_WINDOWSIZE : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FOLDERS) ? Horde_ActiveSync::SYNC_FOLDERS : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_PARTIAL) ? Horde_ActiveSync::SYNC_PARTIAL : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_WAIT) ? Horde_ActiveSync::SYNC_WAIT : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_HEARTBEATINTERVAL) ? Horde_ActiveSync::SYNC_HEARTBEATINTERVAL : - -1)))))) != -1 ) { - - switch($sync_tag) { - case Horde_ActiveSync::SYNC_HEARTBEATINTERVAL: - if ($hbinterval = $this->_decoder->getElementContent()) { - $this->_collections->setHeartbeat(array('hbinterval' => $hbinterval)); - $this->_collections->hangingSync = true; - $this->_decoder->getElementEndTag(); - if ($hbinterval > (self::MAX_HEARTBEAT)) { - $this->_logger->err('HeartbeatInterval outside of allowed range.'); - $this->_statusCode = self::STATUS_INVALID_WAIT_HEARTBEAT; - $this->_handleGlobalSyncError(self::MAX_HEARTBEAT); - return true; + while (($sync_tag = ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_WINDOWSIZE) ? Horde_ActiveSync::SYNC_WINDOWSIZE + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FOLDERS) ? Horde_ActiveSync::SYNC_FOLDERS + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_PARTIAL) ? Horde_ActiveSync::SYNC_PARTIAL + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_WAIT) ? Horde_ActiveSync::SYNC_WAIT + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_HEARTBEATINTERVAL) ? Horde_ActiveSync::SYNC_HEARTBEATINTERVAL + : -1)))))) != -1) { + + switch ($sync_tag) { + case Horde_ActiveSync::SYNC_HEARTBEATINTERVAL: + if ($hbinterval = $this->_decoder->getElementContent()) { + $this->_collections->setHeartbeat(['hbinterval' => $hbinterval]); + $this->_collections->hangingSync = true; + $this->_decoder->getElementEndTag(); + if ($hbinterval > (self::MAX_HEARTBEAT)) { + $this->_logger->err('HeartbeatInterval outside of allowed range.'); + $this->_statusCode = self::STATUS_INVALID_WAIT_HEARTBEAT; + $this->_handleGlobalSyncError(self::MAX_HEARTBEAT); + return true; + } } - } - break; - case Horde_ActiveSync::SYNC_WAIT: - if ($wait = $this->_decoder->getElementContent()) { - $this->_collections->setHeartbeat(array('wait' => $wait)); - $this->_collections->hangingSync = true; - $this->_decoder->getElementEndTag(); - if ($wait > (self::MAX_HEARTBEAT / 60)) { - $this->_logger->err('Wait value outside of allowed range.'); - $this->_statusCode = self::STATUS_INVALID_WAIT_HEARTBEAT; - $this->_handleGlobalSyncError(self::MAX_HEARBEAT / 60); + break; + case Horde_ActiveSync::SYNC_WAIT: + if ($wait = $this->_decoder->getElementContent()) { + $this->_collections->setHeartbeat(['wait' => $wait]); + $this->_collections->hangingSync = true; + $this->_decoder->getElementEndTag(); + if ($wait > (self::MAX_HEARTBEAT / 60)) { + $this->_logger->err('Wait value outside of allowed range.'); + $this->_statusCode = self::STATUS_INVALID_WAIT_HEARTBEAT; + $this->_handleGlobalSyncError(self::MAX_HEARBEAT / 60); + return true; + } + } + break; + case Horde_ActiveSync::SYNC_PARTIAL: + if ($this->_decoder->getElementContent(Horde_ActiveSync::SYNC_PARTIAL)) { + $this->_decoder->getElementEndTag(); + } + $partial = true; + break; + case Horde_ActiveSync::SYNC_WINDOWSIZE: + $this->_collections->setDefaultWindowSize($this->_decoder->getElementContent()); + if (!$this->_decoder->getElementEndTag()) { + $this->_logger->err('PROTOCOL ERROR'); + return false; + } + break; + case Horde_ActiveSync::SYNC_FOLDERS: + if (!$this->_parseSyncFolders()) { + // Any errors are handled in _parseSyncFolders() and + // appropriate error codes sent to device. return true; } - } - break; - case Horde_ActiveSync::SYNC_PARTIAL: - if ($this->_decoder->getElementContent(Horde_ActiveSync::SYNC_PARTIAL)) { - $this->_decoder->getElementEndTag(); - } - $partial = true; - break; - case Horde_ActiveSync::SYNC_WINDOWSIZE: - $this->_collections->setDefaultWindowSize($this->_decoder->getElementContent()); - if (!$this->_decoder->getElementEndTag()) { - $this->_logger->err('PROTOCOL ERROR'); - return false; - } - break; - case Horde_ActiveSync::SYNC_FOLDERS: - if (!$this->_parseSyncFolders()) { - // Any errors are handled in _parseSyncFolders() and - // appropriate error codes sent to device. - return true; - } } } if ($this->_device->version >= Horde_ActiveSync::VERSION_TWELVEONE) { // These are not allowed in the same request. - if ($this->_collections->hbinterval !== false && - $this->_collections->wait !== false) { + if ($this->_collections->hbinterval !== false + && $this->_collections->wait !== false) { $this->_logger->err('Received both HBINTERVAL and WAIT interval in same request.'); $this->_statusCode = Horde_ActiveSync_Status::INVALID_XML; @@ -248,9 +249,9 @@ protected function _handle() } // If this is >= 12.1, see if we want a looping SYNC. - if ($this->_collections->canDoLoopingSync() && - $this->_device->version >= Horde_ActiveSync::VERSION_TWELVEONE && - $this->_statusCode == self::STATUS_SUCCESS) { + if ($this->_collections->canDoLoopingSync() + && $this->_device->version >= Horde_ActiveSync::VERSION_TWELVEONE + && $this->_statusCode == self::STATUS_SUCCESS) { // Calculate the heartbeat if (!$heartbeat = $this->_collections->getHeartbeat()) { @@ -263,30 +264,30 @@ protected function _handle() $changes = $this->_collections->pollForChanges($heartbeat, $pingSettings['waitinterval']); if ($changes !== true && $changes !== false) { switch ($changes) { - case Horde_ActiveSync_Collections::COLLECTION_ERR_STALE: - $this->_logger->info('Changes in cache detected during looping SYNC exiting here.'); - return true; - case Horde_ActiveSync_Collections::COLLECTION_ERR_FOLDERSYNC_REQUIRED; - $this->_statusCode = self::STATUS_FOLDERSYNC_REQUIRED; - $this->_handleGlobalSyncError(); - return true; - case Horde_ActiveSync_Collections::COLLECTION_ERR_SYNC_REQUIRED; - $this->_statusCode = self::STATUS_REQUEST_INCOMPLETE; - $this->_handleGlobalSyncError(); - return true; - default: - $this->_statusCode = self::STATUS_SERVERERROR; - $this->_handleGlobalSyncError(); - return true; + case Horde_ActiveSync_Collections::COLLECTION_ERR_STALE: + $this->_logger->info('Changes in cache detected during looping SYNC exiting here.'); + return true; + case Horde_ActiveSync_Collections::COLLECTION_ERR_FOLDERSYNC_REQUIRED: + $this->_statusCode = self::STATUS_FOLDERSYNC_REQUIRED; + $this->_handleGlobalSyncError(); + return true; + case Horde_ActiveSync_Collections::COLLECTION_ERR_SYNC_REQUIRED: + $this->_statusCode = self::STATUS_REQUEST_INCOMPLETE; + $this->_handleGlobalSyncError(); + return true; + default: + $this->_statusCode = self::STATUS_SERVERERROR; + $this->_handleGlobalSyncError(); + return true; } } } // See if we can do an empty response - if ($this->_device->version >= Horde_ActiveSync::VERSION_TWELVEONE && - $this->_statusCode == self::STATUS_SUCCESS && - empty($changes) && - $this->_collections->canSendEmptyResponse()) { + if ($this->_device->version >= Horde_ActiveSync::VERSION_TWELVEONE + && $this->_statusCode == self::STATUS_SUCCESS + && empty($changes) + && $this->_collections->canSendEmptyResponse()) { $this->_logger->info('Sending an empty SYNC response.'); $this->_collections->lastsyncendnormal = time(); @@ -294,9 +295,11 @@ protected function _handle() return true; } - $this->_logger->info(sprintf( - 'Completed parsing incoming request. Peak memory usage: %d.', - memory_get_peak_usage(true)) + $this->_logger->info( + sprintf( + 'Completed parsing incoming request. Peak memory usage: %d.', + memory_get_peak_usage(true) + ) ); // Start output to client @@ -364,23 +367,27 @@ protected function _handle() $this->_logger->err(sprintf( 'Force restting of state for %s: %s', $id, - $e->getMessage())); + $e->getMessage() + )); $this->_state->loadState( - array(), + [], null, Horde_ActiveSync::REQUEST_TYPE_SYNC, - $id); + $id + ); $statusCode = self::STATUS_KEYMISM; } catch (Horde_ActiveSync_Exception_StateGone $e) { $this->_logger->warn('SYNCKEY not found. Reset required.'); - $statusCode = self::STATUS_KEYMISM; + $statusCode = self::STATUS_KEYMISM; } catch (Horde_ActiveSync_Exception_FolderGone $e) { $this->_logger->warn('FOLDERSYNC required, collection gone.'); $statusCode = self::STATUS_FOLDERSYNC_REQUIRED; } catch (Horde_ActiveSync_Exception_TemporaryFailure $e) { - $this->_logger->err(sprintf( - 'Failure in polling for changes: "%s".', - $e->getMessage()) + $this->_logger->err( + sprintf( + 'Failure in polling for changes: "%s".', + $e->getMessage() + ) ); $statusCode = Horde_ActiveSync_Status::SERVER_ERROR_RETRY; } catch (Horde_Exception_AuthenticationFailure $e) { @@ -395,20 +402,22 @@ protected function _handle() // - This is the initial sync pairing of the collection. // - We received a SYNC due to changes found during a PING // (See Bug: 12075). - if ($statusCode == self::STATUS_SUCCESS && - (!empty($collection['importedchanges']) || - !empty($changecount) || - $collection['synckey'] == '0' || - $this->_state->getSyncKeyCounter($collection['synckey']) == 1 || - !empty($collection['fetchids']) || - $this->_collections->hasPingChangeFlag($id))) { + if ($statusCode == self::STATUS_SUCCESS + && (!empty($collection['importedchanges']) + || !empty($changecount) + || $collection['synckey'] == '0' + || $this->_state->getSyncKeyCounter($collection['synckey']) == 1 + || !empty($collection['fetchids']) + || $this->_collections->hasPingChangeFlag($id))) { try { $collection['newsynckey'] = $this->_state->getNewSyncKeyWrapper($collection['synckey']); - $this->_logger->meta(sprintf( - 'Old SYNCKEY: %s, New SYNCKEY: %s', - $collection['synckey'], - $collection['newsynckey']) + $this->_logger->meta( + sprintf( + 'Old SYNCKEY: %s, New SYNCKEY: %s', + $collection['synckey'], + $collection['newsynckey'] + ) ); } catch (Horde_ActiveSync_Exception $e) { $statusCode = self::STATUS_KEYMISM; @@ -432,20 +441,25 @@ protected function _handle() if ($statusCode == self::STATUS_SUCCESS) { // Server changes - if ($statusCode == self::STATUS_SUCCESS && - empty($forceChanges) && - !empty($collection['getchanges'])) { + if ($statusCode == self::STATUS_SUCCESS + && empty($forceChanges) + && !empty($collection['getchanges'])) { $max_windowsize = !empty($pingSettings['maximumwindowsize']) ? min($collection['windowsize'], $pingSettings['maximumwindowsize']) : $collection['windowsize']; // MOREAVAILABLE? - if (!empty($changecount) && - (($changecount > $max_windowsize) || $cnt_global + $changecount > $this->_collections->getDefaultWindowSize())) { - $this->_logger->meta(sprintf( - 'Sending MOREAVAILABLE. WINDOWSIZE = %d, $changecount = %d, MAX_REQUEST_WINDOWSIZE = %d, $cnt_global = %d', - $max_windowsize, $changecount, $this->_collections->getDefaultWindowSize(), $cnt_global) + if (!empty($changecount) + && (($changecount > $max_windowsize) || $cnt_global + $changecount > $this->_collections->getDefaultWindowSize())) { + $this->_logger->meta( + sprintf( + 'Sending MOREAVAILABLE. WINDOWSIZE = %d, $changecount = %d, MAX_REQUEST_WINDOWSIZE = %d, $cnt_global = %d', + $max_windowsize, + $changecount, + $this->_collections->getDefaultWindowSize(), + $cnt_global + ) ); $this->_encoder->startTag(Horde_ActiveSync::SYNC_MOREAVAILABLE, false, true); $over_window = ($cnt_global + $changecount > $this->_collections->getDefaultWindowSize()); @@ -456,12 +470,14 @@ protected function _handle() $exporter->setChanges($this->_collections->getCollectionChanges(false), $collection); $this->_encoder->startTag(Horde_ActiveSync::SYNC_COMMANDS); $cnt_collection = 0; - while ($cnt_collection < $max_windowsize && - $cnt_global < $this->_collections->getDefaultWindowSize() && - $progress = $exporter->sendNextChange()) { - $this->_logger->meta(sprintf( - 'Peak memory usage after message: %d', - memory_get_peak_usage(true)) + while ($cnt_collection < $max_windowsize + && $cnt_global < $this->_collections->getDefaultWindowSize() + && $progress = $exporter->sendNextChange()) { + $this->_logger->meta( + sprintf( + 'Peak memory usage after message: %d', + memory_get_peak_usage(true) + ) ); if ($progress === true) { ++$cnt_collection; @@ -488,8 +504,8 @@ protected function _handle() // EAS 16. CHANGED responses for items that need one. This // is basically the results of any AirSyncBaseAttachments // actions on Appointment or Draft Email items. - if ($this->_device->version >= Horde_ActiveSync::VERSION_SIXTEEN && - !empty($collection['modifiedids'])) { + if ($this->_device->version >= Horde_ActiveSync::VERSION_SIXTEEN + && !empty($collection['modifiedids'])) { $exporter->syncModifiedResponse($collection); } @@ -519,7 +535,7 @@ protected function _handle() $this->_collections->addConfirmedKey($collection['newsynckey']); $this->_collections->updateCollection( $collection, - array('newsynckey' => true, 'unsetChanges' => true, 'unsetPingChangeFlag' => true) + ['newsynckey' => true, 'unsetChanges' => true, 'unsetPingChangeFlag' => true] ); } elseif (!isset($changes)) { // See if we could benefit from updating the collection's @@ -536,9 +552,11 @@ protected function _handle() // End SYNC_FOLDER $this->_encoder->endTag(); - $this->_logger->meta(sprintf( - 'Collection output peak memory usage: %d', - memory_get_peak_usage(true)) + $this->_logger->meta( + sprintf( + 'Collection output peak memory usage: %d', + memory_get_peak_usage(true) + ) ); } @@ -607,147 +625,147 @@ protected function _parseSyncFolders() { while ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FOLDER)) { $collection = $this->_collections->getNewCollection(); - while (($folder_tag = ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FOLDERTYPE) ? Horde_ActiveSync::SYNC_FOLDERTYPE : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_SYNCKEY) ? Horde_ActiveSync::SYNC_SYNCKEY : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FOLDERID) ? Horde_ActiveSync::SYNC_FOLDERID : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_SUPPORTED) ? Horde_ActiveSync::SYNC_SUPPORTED : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_DELETESASMOVES) ? Horde_ActiveSync::SYNC_DELETESASMOVES : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_GETCHANGES) ? Horde_ActiveSync::SYNC_GETCHANGES : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_WINDOWSIZE) ? Horde_ActiveSync::SYNC_WINDOWSIZE : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_CONVERSATIONMODE) ? Horde_ActiveSync::SYNC_CONVERSATIONMODE : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_OPTIONS) ? Horde_ActiveSync::SYNC_OPTIONS : - ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_COMMANDS) ? Horde_ActiveSync::SYNC_COMMANDS : - -1))))))))))) != -1) { + while (($folder_tag = ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FOLDERTYPE) ? Horde_ActiveSync::SYNC_FOLDERTYPE + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_SYNCKEY) ? Horde_ActiveSync::SYNC_SYNCKEY + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FOLDERID) ? Horde_ActiveSync::SYNC_FOLDERID + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_SUPPORTED) ? Horde_ActiveSync::SYNC_SUPPORTED + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_DELETESASMOVES) ? Horde_ActiveSync::SYNC_DELETESASMOVES + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_GETCHANGES) ? Horde_ActiveSync::SYNC_GETCHANGES + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_WINDOWSIZE) ? Horde_ActiveSync::SYNC_WINDOWSIZE + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_CONVERSATIONMODE) ? Horde_ActiveSync::SYNC_CONVERSATIONMODE + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_OPTIONS) ? Horde_ActiveSync::SYNC_OPTIONS + : ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_COMMANDS) ? Horde_ActiveSync::SYNC_COMMANDS + : -1))))))))))) != -1) { switch ($folder_tag) { - case Horde_ActiveSync::SYNC_FOLDERTYPE: - // According to docs, in 12.1 this is sent here, in > 12.1 - // it is NOT sent here, it is sent in the ADD command ONLY. - // BUT, I haven't seen any 12.1 client actually send this. - // Only < 12.1 - leave version sniffing out in this case. - $collection['class'] = $this->_decoder->getElementContent(); - if (!$this->_decoder->getElementEndTag()) { - throw new Horde_ActiveSync_Exception('Protocol error'); - } - break; + case Horde_ActiveSync::SYNC_FOLDERTYPE: + // According to docs, in 12.1 this is sent here, in > 12.1 + // it is NOT sent here, it is sent in the ADD command ONLY. + // BUT, I haven't seen any 12.1 client actually send this. + // Only < 12.1 - leave version sniffing out in this case. + $collection['class'] = $this->_decoder->getElementContent(); + if (!$this->_decoder->getElementEndTag()) { + throw new Horde_ActiveSync_Exception('Protocol error'); + } + break; - case Horde_ActiveSync::SYNC_SYNCKEY: - $collection['synckey'] = $this->_decoder->getElementContent(); - if (!$this->_decoder->getElementEndTag()) { - throw new Horde_ActiveSync_Exception('Protocol error'); - } - break; - - case Horde_ActiveSync::SYNC_FOLDERID: - $collection['id'] = $this->_decoder->getElementContent(); - if ($collection['id'] === false) { - // Log this case explicitly since we can't send back - // a protocol error status (the response requires a - // collection id and we obviously don't have one). - $this->_logger->err('PROTOCOL ERROR. Client sent an empty SYNC_FOLDERID value.'); - throw new Horde_ActiveSync_Exception('Protocol error'); - } - if (!$this->_decoder->getElementEndTag()) { - throw new Horde_ActiveSync_Exception('Protocol error'); - } - break; + case Horde_ActiveSync::SYNC_SYNCKEY: + $collection['synckey'] = $this->_decoder->getElementContent(); + if (!$this->_decoder->getElementEndTag()) { + throw new Horde_ActiveSync_Exception('Protocol error'); + } + break; - case Horde_ActiveSync::SYNC_WINDOWSIZE: - $collection['windowsize'] = $this->_decoder->getElementContent(); - if (!$this->_decoder->getElementEndTag()) { - $this->_statusCode = self::STATUS_PROTERROR; - $this->_handleError($collection); - return false; - } - if ($collection['windowsize'] < 1 || $collection['windowsize'] > self::MAX_WINDOW_SIZE) { - $this->_logger->err('Bad windowsize sent, defaulting to 512'); - $collection['windowsize'] = self::MAX_WINDOW_SIZE; - } - break; - - case Horde_ActiveSync::SYNC_CONVERSATIONMODE: - // Optional element, but if it's present with an empty value - // it defaults to true. - $collection['conversationmode'] = $this->_decoder->getElementContent(); - if ($collection['conversationmode'] !== false && !$this->_decoder->getElementEndTag()) { - throw new Horde_ActiveSync_Exception('Protocol Error'); - } elseif ($collection['conversationmode'] === false) { - $collection['conversationmode'] = true; - } + case Horde_ActiveSync::SYNC_FOLDERID: + $collection['id'] = $this->_decoder->getElementContent(); + if ($collection['id'] === false) { + // Log this case explicitly since we can't send back + // a protocol error status (the response requires a + // collection id and we obviously don't have one). + $this->_logger->err('PROTOCOL ERROR. Client sent an empty SYNC_FOLDERID value.'); + throw new Horde_ActiveSync_Exception('Protocol error'); + } + if (!$this->_decoder->getElementEndTag()) { + throw new Horde_ActiveSync_Exception('Protocol error'); + } + break; - break; + case Horde_ActiveSync::SYNC_WINDOWSIZE: + $collection['windowsize'] = $this->_decoder->getElementContent(); + if (!$this->_decoder->getElementEndTag()) { + $this->_statusCode = self::STATUS_PROTERROR; + $this->_handleError($collection); + return false; + } + if ($collection['windowsize'] < 1 || $collection['windowsize'] > self::MAX_WINDOW_SIZE) { + $this->_logger->err('Bad windowsize sent, defaulting to 512'); + $collection['windowsize'] = self::MAX_WINDOW_SIZE; + } + break; - case Horde_ActiveSync::SYNC_SUPPORTED: - // Only allowed on initial sync request - if ($collection['synckey'] != '0') { - $this->_statusCode = self::STATUS_PROTERROR; - $this->_handleError($collection); - return false; - } - while (1) { - $el = $this->_decoder->getElement(); - if ($this->_decoder->isEmptyElement($this->_decoder->getLastStartElement())) { - // MS-ASCMD 2.2.3.168 An empty SUPPORTED tag - // indicates that ALL elements able to be ghosted - // ARE ghosted. - $collection['supported'] = array(Horde_ActiveSync::ALL_GHOSTED); - break; + case Horde_ActiveSync::SYNC_CONVERSATIONMODE: + // Optional element, but if it's present with an empty value + // it defaults to true. + $collection['conversationmode'] = $this->_decoder->getElementContent(); + if ($collection['conversationmode'] !== false && !$this->_decoder->getElementEndTag()) { + throw new Horde_ActiveSync_Exception('Protocol Error'); + } elseif ($collection['conversationmode'] === false) { + $collection['conversationmode'] = true; } - if ($el[Horde_ActiveSync_Wbxml::EN_TYPE] == Horde_ActiveSync_Wbxml::EN_TYPE_ENDTAG) { - break; + + break; + + case Horde_ActiveSync::SYNC_SUPPORTED: + // Only allowed on initial sync request + if ($collection['synckey'] != '0') { + $this->_statusCode = self::STATUS_PROTERROR; + $this->_handleError($collection); + return false; } - $collection['supported'][] = $el[2]; - } - if (!empty($collection['supported'])) { - // Initial sync and we have SUPPORTED data - save it - if (empty($this->_device->supported)) { - $this->_device->supported = array(); + while (1) { + $el = $this->_decoder->getElement(); + if ($this->_decoder->isEmptyElement($this->_decoder->getLastStartElement())) { + // MS-ASCMD 2.2.3.168 An empty SUPPORTED tag + // indicates that ALL elements able to be ghosted + // ARE ghosted. + $collection['supported'] = [Horde_ActiveSync::ALL_GHOSTED]; + break; + } + if ($el[Horde_ActiveSync_Wbxml::EN_TYPE] == Horde_ActiveSync_Wbxml::EN_TYPE_ENDTAG) { + break; + } + $collection['supported'][] = $el[2]; + } + if (!empty($collection['supported'])) { + // Initial sync and we have SUPPORTED data - save it + if (empty($this->_device->supported)) { + $this->_device->supported = []; + } + // Not all clients send the $collection['class'] in more + // recent EAS versions. Grab it from the collection + // handler if needed. + if (empty($collection['class'])) { + $collection['class'] = $this->_collections->getCollectionClass($collection['id']); + } + $this->_device->supported[$collection['class']] = $collection['supported']; + $this->_device->save(); } - // Not all clients send the $collection['class'] in more - // recent EAS versions. Grab it from the collection - // handler if needed. - if (empty($collection['class'])) { - $collection['class'] = $this->_collections->getCollectionClass($collection['id']); + break; + + case Horde_ActiveSync::SYNC_DELETESASMOVES: + // Optional element, but if it's present with an empty value + // it defaults to true. + $collection['deletesasmoves'] = $this->_decoder->getElementContent(); + if ($collection['deletesasmoves'] !== false && !$this->_decoder->getElementEndTag()) { + throw new Horde_ActiveSync_Exception('Protocol Error'); + } elseif ($collection['deletesasmoves'] === false) { + $collection['deletesasmoves'] = true; } - $this->_device->supported[$collection['class']] = $collection['supported']; - $this->_device->save(); - } - break; - - case Horde_ActiveSync::SYNC_DELETESASMOVES: - // Optional element, but if it's present with an empty value - // it defaults to true. - $collection['deletesasmoves'] = $this->_decoder->getElementContent(); - if ($collection['deletesasmoves'] !== false && !$this->_decoder->getElementEndTag()) { - throw new Horde_ActiveSync_Exception('Protocol Error'); - } elseif ($collection['deletesasmoves'] === false) { - $collection['deletesasmoves'] = true; - } - break; - - case Horde_ActiveSync::SYNC_GETCHANGES: - // Optional element, but if it's present with an empty value - // it defaults to true. - $collection['getchanges'] = $this->_decoder->getElementContent(); - if ($collection['getchanges'] !== false && !$this->_decoder->getElementEndTag()) { - // Present, has a value, but no closing tag. - throw new Horde_ActiveSync_Exception('Protocol Error'); - } elseif ($collection['getchanges'] === false) { - // Present, but is an empty tag, so defaults to true. - $collection['getchanges'] = true; - } - break; + break; - case Horde_ActiveSync::SYNC_OPTIONS: - if (!$this->_decoder->isEmptyElement($this->_decoder->getLastStartElement())) { - $this->_parseSyncOptions($collection); - } - break; + case Horde_ActiveSync::SYNC_GETCHANGES: + // Optional element, but if it's present with an empty value + // it defaults to true. + $collection['getchanges'] = $this->_decoder->getElementContent(); + if ($collection['getchanges'] !== false && !$this->_decoder->getElementEndTag()) { + // Present, has a value, but no closing tag. + throw new Horde_ActiveSync_Exception('Protocol Error'); + } elseif ($collection['getchanges'] === false) { + // Present, but is an empty tag, so defaults to true. + $collection['getchanges'] = true; + } + break; - case Horde_ActiveSync::SYNC_COMMANDS: - if (!$this->_parseSyncCommands($collection)) { - return false; - } + case Horde_ActiveSync::SYNC_OPTIONS: + if (!$this->_decoder->isEmptyElement($this->_decoder->getLastStartElement())) { + $this->_parseSyncOptions($collection); + } + break; + + case Horde_ActiveSync::SYNC_COMMANDS: + if (!$this->_parseSyncCommands($collection)) { + return false; + } } } @@ -757,8 +775,8 @@ protected function _parseSyncFolders() return false; } - if (isset($collection['filtertype']) && - !$this->_collections->checkFilterType($collection['id'], $collection['filtertype'])) { + if (isset($collection['filtertype']) + && !$this->_collections->checkFilterType($collection['id'], $collection['filtertype'])) { $this->_logger->meta('Updated filtertype, will force a SOFTDELETE.'); $collection['forcerefresh'] = true; } @@ -850,10 +868,10 @@ protected function _parseSyncCommands(&$collection) $commandType = $element[Horde_ActiveSync_Wbxml::EN_TAG]; $instanceid = false; // Only sent during SYNC_MODIFY/SYNC_REMOVE/SYNC_FETCH - if (($commandType == Horde_ActiveSync::SYNC_MODIFY || - $commandType == Horde_ActiveSync::SYNC_REMOVE || - $commandType == Horde_ActiveSync::SYNC_FETCH) && - $this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_SERVERENTRYID)) { + if (($commandType == Horde_ActiveSync::SYNC_MODIFY + || $commandType == Horde_ActiveSync::SYNC_REMOVE + || $commandType == Horde_ActiveSync::SYNC_FETCH) + && $this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_SERVERENTRYID)) { $serverid = $this->_decoder->getElementContent(); // Work around broken clients (Blackberry) that can send empty @@ -883,9 +901,9 @@ protected function _parseSyncCommands(&$collection) // This tag is only sent here during > 12.1 and SYNC_ADD requests... // and it's not even sent by all clients. Parse it if it's there, // ignore it if not. - if ($this->_activeSync->device->version > Horde_ActiveSync::VERSION_TWELVEONE && - $commandType == Horde_ActiveSync::SYNC_ADD && - $this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FOLDERTYPE)) { + if ($this->_activeSync->device->version > Horde_ActiveSync::VERSION_TWELVEONE + && $commandType == Horde_ActiveSync::SYNC_ADD + && $this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FOLDERTYPE)) { $collection['class'] = $this->_decoder->getElementContent(); if (!$this->_decoder->getElementEndTag()) { @@ -897,8 +915,8 @@ protected function _parseSyncCommands(&$collection) } // Only sent during SYNC_ADD - if ($commandType == Horde_ActiveSync::SYNC_ADD && - $this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_CLIENTENTRYID)) { + if ($commandType == Horde_ActiveSync::SYNC_ADD + && $this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_CLIENTENTRYID)) { $clientid = $this->_decoder->getElementContent(); if (!$this->_decoder->getElementEndTag()) { $this->_statusCode = self::STATUS_PROTERROR; @@ -912,42 +930,42 @@ protected function _parseSyncCommands(&$collection) // Create Message object from messages passed from client. // Only passed during SYNC_ADD or SYNC_MODIFY - if (($commandType == Horde_ActiveSync::SYNC_ADD || - $commandType == Horde_ActiveSync::SYNC_MODIFY) && - ($el = $this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_DATA))) { + if (($commandType == Horde_ActiveSync::SYNC_ADD + || $commandType == Horde_ActiveSync::SYNC_MODIFY) + && ($el = $this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_DATA))) { if ($this->_decoder->isEmptyElement($el)) { $this->_logger->err('Client sent an empty element. This is a protocol error, but attempting to ignore.'); } else { switch ($collection['class']) { - case Horde_ActiveSync::CLASS_EMAIL: - $appdata = Horde_ActiveSync::messageFactory('Mail'); - $appdata->decodeStream($this->_decoder); - break; - case Horde_ActiveSync::CLASS_CONTACTS: - $appdata = Horde_ActiveSync::messageFactory('Contact'); - $appdata->decodeStream($this->_decoder); - break; - case Horde_ActiveSync::CLASS_CALENDAR: - $appdata = Horde_ActiveSync::messageFactory('Appointment'); - $appdata->decodeStream($this->_decoder); - // EAS 16.0 sends instanceid/serverid for exceptions. - if (!empty($instanceid) && - $commandType == Horde_ActiveSync::SYNC_MODIFY) { - $appdata->instanceid = $instanceid; - } - break; - case Horde_ActiveSync::CLASS_TASKS: - $appdata = Horde_ActiveSync::messageFactory('Task'); - $appdata->decodeStream($this->_decoder); - break; - case Horde_ActiveSync::CLASS_NOTES: - $appdata = Horde_ActiveSync::messageFactory('Note'); - $appdata->decodeStream($this->_decoder); - break; - case Horde_ActiveSync::CLASS_SMS: - $appdata = Horde_ActiveSync::messageFactory('Mail'); - $appdata->decodeStream($this->_decoder); - break; + case Horde_ActiveSync::CLASS_EMAIL: + $appdata = Horde_ActiveSync::messageFactory('Mail'); + $appdata->decodeStream($this->_decoder); + break; + case Horde_ActiveSync::CLASS_CONTACTS: + $appdata = Horde_ActiveSync::messageFactory('Contact'); + $appdata->decodeStream($this->_decoder); + break; + case Horde_ActiveSync::CLASS_CALENDAR: + $appdata = Horde_ActiveSync::messageFactory('Appointment'); + $appdata->decodeStream($this->_decoder); + // EAS 16.0 sends instanceid/serverid for exceptions. + if (!empty($instanceid) + && $commandType == Horde_ActiveSync::SYNC_MODIFY) { + $appdata->instanceid = $instanceid; + } + break; + case Horde_ActiveSync::CLASS_TASKS: + $appdata = Horde_ActiveSync::messageFactory('Task'); + $appdata->decodeStream($this->_decoder); + break; + case Horde_ActiveSync::CLASS_NOTES: + $appdata = Horde_ActiveSync::messageFactory('Note'); + $appdata->decodeStream($this->_decoder); + break; + case Horde_ActiveSync::CLASS_SMS: + $appdata = Horde_ActiveSync::messageFactory('Mail'); + $appdata->decodeStream($this->_decoder); + break; } if (!$this->_decoder->getElementEndTag()) { @@ -962,64 +980,71 @@ protected function _parseSyncCommands(&$collection) if (!empty($collection['synckey'])) { switch ($commandType) { - case Horde_ActiveSync::SYNC_MODIFY: - if (isset($appdata)) { - $ires = $importer->importMessageChange( - $serverid, $appdata, $this->_device, false, - $collection['class'], $collection['synckey'] - ); - if (is_array($ires) && !empty($ires['error'])) { - $collection['importfailures'][$ires[0]] = $ires['error']; - } elseif (is_array($ires)) { - $collection['importedchanges'] = true; - if (empty($collection['modifiedids'])) { - $collection['modifiedids'] = array(); + case Horde_ActiveSync::SYNC_MODIFY: + if (isset($appdata)) { + $ires = $importer->importMessageChange( + $serverid, + $appdata, + $this->_device, + false, + $collection['class'], + $collection['synckey'] + ); + if (is_array($ires) && !empty($ires['error'])) { + $collection['importfailures'][$ires[0]] = $ires['error']; + } elseif (is_array($ires)) { + $collection['importedchanges'] = true; + if (empty($collection['modifiedids'])) { + $collection['modifiedids'] = []; + } + $collection['modifiedids'][] = $ires['id']; + $collection['atchash'][$serverid] = !empty($ires['atchash']) + ? $ires['atchash'] + : []; } - $collection['modifiedids'][] = $ires['id']; - $collection['atchash'][$serverid] = !empty($ires['atchash']) - ? $ires['atchash'] - : array(); } - } - break; + break; - case Horde_ActiveSync::SYNC_ADD: - if (isset($appdata)) { - $ires = $importer->importMessageChange( - false, $appdata, $this->_device, $clientid, - $collection['class'] - ); - if (!$ires || !empty($ires['error'])) { - $collection['clientids'][$clientid] = false; - } elseif ($clientid && is_array($ires)) { - $collection['clientids'][$clientid] = $ires['id']; - $collection['atchash'][$ires['id']] = !empty($ires['atchash']) - ? $ires['atchash'] - : array(); - if (!empty($ires['conversationid'])) { - $collection['conversations'][$ires['id']] = - array($ires['conversationid'], - $ires['conversationindex']); + case Horde_ActiveSync::SYNC_ADD: + if (isset($appdata)) { + $ires = $importer->importMessageChange( + false, + $appdata, + $this->_device, + $clientid, + $collection['class'] + ); + if (!$ires || !empty($ires['error'])) { + $collection['clientids'][$clientid] = false; + } elseif ($clientid && is_array($ires)) { + $collection['clientids'][$clientid] = $ires['id']; + $collection['atchash'][$ires['id']] = !empty($ires['atchash']) + ? $ires['atchash'] + : []; + if (!empty($ires['conversationid'])) { + $collection['conversations'][$ires['id']] + = [$ires['conversationid'], + $ires['conversationindex']]; + } + $collection['importedchanges'] = true; + } elseif (!$id || is_array($id)) { + $collection['clientids'][$clientid] = false; } - $collection['importedchanges'] = true; - } elseif (!$id || is_array($id)) { - $collection['clientids'][$clientid] = false; } - } - break; - - case Horde_ActiveSync::SYNC_REMOVE: - if ($instanceid) { - $collection['instanceid_removes'][$serverid] = $instanceid; - } elseif ($serverid) { - // Work around broken clients that send empty $serverid. - $collection['removes'][] = $serverid; - } - break; + break; + + case Horde_ActiveSync::SYNC_REMOVE: + if ($instanceid) { + $collection['instanceid_removes'][$serverid] = $instanceid; + } elseif ($serverid) { + // Work around broken clients that send empty $serverid. + $collection['removes'][] = $serverid; + } + break; - case Horde_ActiveSync::SYNC_FETCH: - $collection['fetchids'][] = $serverid; - break; + case Horde_ActiveSync::SYNC_FETCH: + $collection['fetchids'][] = $serverid; + break; } } @@ -1032,8 +1057,8 @@ protected function _parseSyncCommands(&$collection) } // Do all the SYNC_REMOVE requests at once - if (!empty($collection['removes']) && - !empty($collection['synckey'])) { + if (!empty($collection['removes']) + && !empty($collection['synckey'])) { if (!empty($collection['deletesasmoves']) && $folderid = $this->_driver->getWasteBasket($collection['class'])) { $results = $importer->importMessageMove($collection['removes'], $folderid); } else { @@ -1051,9 +1076,9 @@ protected function _parseSyncCommands(&$collection) } // EAS 16.0 instance deletions. if (!empty($collection['instanceid_removes']) && !empty($collection['synckey'])) { - foreach ($collection['instanceid_removes'] as $uid => $instanceid) { - $importer->importMessageDeletion(array($uid => $instanceid), $collection['class'], true); - } + foreach ($collection['instanceid_removes'] as $uid => $instanceid) { + $importer->importMessageDeletion([$uid => $instanceid], $collection['class'], true); + } unset($collection['instanceid_removes']); } @@ -1077,11 +1102,11 @@ protected function _parseSyncCommands(&$collection) */ public function _parseSyncOptions(&$collection) { - $options = array(); + $options = []; $haveElement = false; // These can be sent in any order. - while(1) { + while (1) { if ($this->_decoder->getElementStartTag(Horde_ActiveSync::SYNC_FILTERTYPE)) { $options['filtertype'] = $this->_decoder->getElementContent(); $haveElement = true; @@ -1193,9 +1218,9 @@ public function _parseSyncOptions(&$collection) $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; + $depth = $this->_decoder->isEmptyElement($e) + ? $depth + : $depth + 1; } elseif ($e[Horde_ActiveSync_Wbxml::EN_TYPE] == Horde_ActiveSync_Wbxml::EN_TYPE_ENDTAG) { $depth--; } @@ -1269,15 +1294,15 @@ protected function _handleError(array $collection) $this->_encoder->startTag(Horde_ActiveSync::SYNC_FOLDERS); // Generate new synckey for initial sync, state reset, or when synckey missing/invalid - if ($this->_statusCode == self::STATUS_KEYMISM || - !empty($collection['importedchanges']) || - !empty($collection['getchanges']) || - empty($collection['synckey']) || - $collection['synckey'] == '0') { + if ($this->_statusCode == self::STATUS_KEYMISM + || !empty($collection['importedchanges']) + || !empty($collection['getchanges']) + || empty($collection['synckey']) + || $collection['synckey'] == '0') { $collection['newsynckey'] = Horde_ActiveSync_State_Base::getNewSyncKey(($this->_statusCode == self::STATUS_KEYMISM) ? 0 : ($collection['synckey'] ?? 0)); if (!empty($collection['synckey']) && $collection['synckey'] != '0') { - $this->_state->removeState(array('synckey' => $collection['synckey'])); + $this->_state->removeState(['synckey' => $collection['synckey']]); } } diff --git a/lib/Horde/ActiveSync/Request/SyncBase.php b/lib/Horde/ActiveSync/Request/SyncBase.php index 34917cc8..a43b11bf 100644 --- a/lib/Horde/ActiveSync/Request/SyncBase.php +++ b/lib/Horde/ActiveSync/Request/SyncBase.php @@ -1,4 +1,5 @@ _decoder->getElementStartTag(Horde_ActiveSync::AIRSYNCBASE_TYPE)) { $options['bodypartprefs']['type'] = $this->_decoder->getElementContent(); // MS-ASAIRS 2.2.2.22.3 type MUST be BODYPREF_TYPE_HTML - if (!$this->_decoder->getElementEndTag() || - $options['bodypartprefs']['type'] != Horde_ActiveSync::BODYPREF_TYPE_HTML) { + if (!$this->_decoder->getElementEndTag() + || $options['bodypartprefs']['type'] != Horde_ActiveSync::BODYPREF_TYPE_HTML) { $this->_statusCode = self::STATUS_PROTERROR; $this->_handleError($options); exit; @@ -64,8 +65,8 @@ protected function _bodyPartPrefs(&$options) if ($this->_decoder->getElementStartTag(Horde_ActiveSync::AIRSYNCBASE_PREVIEW)) { $options['bodypartprefs']['preview'] = $this->_decoder->getElementContent(); // MS-ASAIRS 2.2.2.18.3 - Max size of preview is 255. - if (!$this->_decoder->getElementEndTag() || - $options['bodypartprefs']['preview'] > 255) { + if (!$this->_decoder->getElementEndTag() + || $options['bodypartprefs']['preview'] > 255) { $this->_statusCode = self::STATUS_PROTERROR; $this->_handleError($options); @@ -86,9 +87,9 @@ protected function _bodyPartPrefs(&$options) */ protected function _bodyPrefs(&$options) { - $body_pref = array(); + $body_pref = []; if (empty($options['bodyprefs'])) { - $options['bodyprefs'] = array(); + $options['bodyprefs'] = []; } while (1) { if ($this->_decoder->getElementStartTag(Horde_ActiveSync::AIRSYNCBASE_TYPE)) { diff --git a/lib/Horde/ActiveSync/Request/ValidateCert.php b/lib/Horde/ActiveSync/Request/ValidateCert.php index a6628fdb..2888f4b2 100644 --- a/lib/Horde/ActiveSync/Request/ValidateCert.php +++ b/lib/Horde/ActiveSync/Request/ValidateCert.php @@ -1,4 +1,5 @@ _decoder->getElementStartTag(self::VALIDATECERT_CERTIFICATES) ? self::VALIDATECERT_CERTIFICATES : - ($this->_decoder->getElementStartTag(self::VALIDATECERT_CERTIFICATECHAIN) ? self::VALIDATECERT_CERTIFICATECHAIN : - ($this->_decoder->getElementStartTag(self::VALIDATECERT_CHECKCRL) ? self::VALIDATECERT_CHECKCRL : - -1)))) != -1) { + $certificates = []; + $chain_certificates = []; + while (($field = ($this->_decoder->getElementStartTag(self::VALIDATECERT_CERTIFICATES) ? self::VALIDATECERT_CERTIFICATES + : ($this->_decoder->getElementStartTag(self::VALIDATECERT_CERTIFICATECHAIN) ? self::VALIDATECERT_CERTIFICATECHAIN + : ($this->_decoder->getElementStartTag(self::VALIDATECERT_CHECKCRL) ? self::VALIDATECERT_CHECKCRL + : -1)))) != -1) { if ($field == self::VALIDATECERT_CERTIFICATES) { while ($this->_decoder->getElementStartTag(self::VALIDATECERT_CERTIFICATE)) { $certificates[] = $this->_decoder->getElementContent(); @@ -90,14 +91,14 @@ protected function _handle() throw new Horde_ActiveSync_Exception('Protocol Error'); } } elseif ($field == self::VALIDATECERT_CHECKCRL) { - $checkcrl = $this->_decoder->getElementContent(); + $checkcrl = $this->_decoder->getElementContent(); if (!$this->_decoder->getElementEndTag()) { throw new Horde_ActiveSync_Exception('Protocol Error'); } } } - $cert_status = array(); + $cert_status = []; foreach ($certificates as $key => $certificate) { $cert_der = base64_decode($certificate); $cert_pem = "-----BEGIN CERTIFICATE-----\n" @@ -119,7 +120,7 @@ protected function _handle() // Valid purpose/trusted? // @TODO: CRL support, CHAIN support - $result = openssl_x509_checkpurpose($cert_pem, X509_PURPOSE_SMIME_SIGN, array($this->_activeSync->certPath)); + $result = openssl_x509_checkpurpose($cert_pem, X509_PURPOSE_SMIME_SIGN, [$this->_activeSync->certPath]); if ($result === false) { // @TODO: // checkpurpose returns false if either the purpose is invalid OR diff --git a/lib/Horde/ActiveSync/Rfc822.php b/lib/Horde/ActiveSync/Rfc822.php index 6f5e3782..f53d94e7 100644 --- a/lib/Horde/ActiveSync/Rfc822.php +++ b/lib/Horde/ActiveSync/Rfc822.php @@ -1,4 +1,5 @@ * @package ActiveSync */ - /** - * Horde_ActiveSync_Rfc822:: class provides functionality related to dealing - * with raw RFC822 message strings within an ActiveSync context. - * - * @license http://www.horde.org/licenses/gpl GPLv2 - * @copyright 2010-2020 Horde LLC (http://www.horde.org) - * @author Michael J Rubinsky - * @package ActiveSync - */ +/** + * Horde_ActiveSync_Rfc822:: class provides functionality related to dealing + * with raw RFC822 message strings within an ActiveSync context. + * + * @license http://www.horde.org/licenses/gpl GPLv2 + * @copyright 2010-2020 Horde LLC (http://www.horde.org) + * @author Michael J Rubinsky + * @package ActiveSync + */ class Horde_ActiveSync_Rfc822 { /** @@ -66,10 +67,10 @@ class Horde_ActiveSync_Rfc822 public function __construct($rfc822, $auto_add_headers = true) { if (is_resource($rfc822)) { - $stream = new Horde_Stream_Existing(array('stream' => $rfc822)); + $stream = new Horde_Stream_Existing(['stream' => $rfc822]); $stream->rewind(); } else { - $stream = new Horde_Stream_Temp(array('max_memory' => self::$memoryLimit)); + $stream = new Horde_Stream_Temp(['max_memory' => self::$memoryLimit]); $stream->add($rfc822, true); } $this->_parseStream($stream); @@ -86,7 +87,7 @@ public function __construct($rfc822, $auto_add_headers = true) protected function _parseStream(Horde_Stream $stream) { $this->_stream = $stream; - list($this->_hdr_pos, $this->_eol) = $this->_findHeader(); + [$this->_hdr_pos, $this->_eol] = $this->_findHeader(); } /** @@ -98,7 +99,7 @@ public function getMessage() { // Position to after the headers. fseek($this->_stream->stream, $this->_hdr_pos + $this->_eol); - $new_stream = new Horde_Stream_Temp(array('max_memory' => self::$memoryLimit)); + $new_stream = new Horde_Stream_Temp(['max_memory' => self::$memoryLimit]); $new_stream->add($this->_stream, true); return $new_stream; } @@ -112,11 +113,12 @@ public function getMessage() */ public function replaceMime(Horde_Mime_Part $part) { - $mime_stream = $part->toString(array( - 'stream' => true, - 'headers' => false) + $mime_stream = $part->toString( + [ + 'stream' => true, + 'headers' => false] ); - $mime_stream = new Horde_Stream_Existing(array('stream' => $mime_stream)); + $mime_stream = new Horde_Stream_Existing(['stream' => $mime_stream]); // Since we are still using the headers sent from the device, we can // simply zero out the position members etc... @@ -134,7 +136,7 @@ public function replaceMime(Horde_Mime_Part $part) public function getString() { if (!empty($this->_header_text)) { - return Horde_Stream_Wrapper_Combine::getStream(array($this->_header_text, $this->getMessage()->stream)); + return Horde_Stream_Wrapper_Combine::getStream([$this->_header_text, $this->getMessage()->stream]); } else { $this->_stream->rewind(); return $this->_stream->stream; @@ -182,7 +184,7 @@ public function addStandardHeaders() $updated = true; } if ($updated) { - $this->_header_text = $headers->toString(array('charset' => 'UTF-8')); + $this->_header_text = $headers->toString(['charset' => 'UTF-8']); } } @@ -228,10 +230,10 @@ protected function _findHeader() // separate the headers. // See: https://ninefolders.plan.io/track/10606/1dcfed switch ($this->_stream->getEOL()) { - case "\n": - return array($this->_stream->search("\n\n"), 2); - case "\r\n": - return array($this->_stream->search("\r\n\r\n"), 4); + case "\n": + return [$this->_stream->search("\n\n"), 2]; + case "\r\n": + return [$this->_stream->search("\r\n\r\n"), 4]; } } diff --git a/lib/Horde/ActiveSync/Search/Params.php b/lib/Horde/ActiveSync/Search/Params.php index 3715d546..f69fa02b 100644 --- a/lib/Horde/ActiveSync/Search/Params.php +++ b/lib/Horde/ActiveSync/Search/Params.php @@ -1,4 +1,5 @@ _params = $params; if (empty($params['logger'])) { @@ -163,7 +164,7 @@ public function getCurrentSyncKey() */ public function generatePolicyKey() { - return mt_rand(1000000000, mt_getrandmax()); + return mt_rand(1000000000, mt_getrandmax()); } /** @@ -203,7 +204,9 @@ public function getDeviceRWStatus($devId, $refresh = false) /* Should we refresh? */ if ($refresh) { $this->loadDeviceInfo( - $this->_deviceInfo->id, $this->_deviceInfo->user, array('force' => true) + $this->_deviceInfo->id, + $this->_deviceInfo->user, + ['force' => true] ); } @@ -263,13 +266,13 @@ public function getChangeCount() public function isConflict($stat, $type) { // $stat == server's message information - if ($stat['mod'] > $this->_lastSyncStamp && - ($type == Horde_ActiveSync::CHANGE_TYPE_DELETE || - $type == Horde_ActiveSync::CHANGE_TYPE_CHANGE)) { + if ($stat['mod'] > $this->_lastSyncStamp + && ($type == Horde_ActiveSync::CHANGE_TYPE_DELETE + || $type == Horde_ActiveSync::CHANGE_TYPE_CHANGE)) { - // changed here - deleted there - // changed here - changed there - return true; + // changed here - deleted there + // changed here - changed there + return true; } return false; @@ -287,7 +290,7 @@ public function getKnownFolders() if (!isset($this->_folder)) { throw new Horde_ActiveSync_Exception('Sync state not loaded'); } - $folders = array(); + $folders = []; foreach ($this->_folder as $folder) { $folders[] = $folder['id']; } @@ -304,11 +307,12 @@ public function getKnownFolders() public function getFolderUidToBackendIdMap() { if (!isset($this->_folderUidMap)) { - $this->_folderUidMap = array(); + $this->_folderUidMap = []; $cache = $this->getSyncCache( $this->_deviceInfo->id, $this->_deviceInfo->user, - array('folders')); + ['folders'] + ); foreach ($cache['folders'] as $id => $folder) { $this->_folderUidMap[$folder['serverid']] = $id; } @@ -331,22 +335,28 @@ public function getFolderUidForBackendId($serverid) { $cache = $this->getSyncCache( $this->_deviceInfo->id, - $this->_deviceInfo->user); + $this->_deviceInfo->user + ); $folders = $cache['folders']; foreach ($folders as $id => $folder) { if ($folder['serverid'] == $serverid) { - $this->_logger->meta(sprintf( - 'STORAGE: Found serverid for %s: %s', - $serverid, $id) + $this->_logger->meta( + sprintf( + 'STORAGE: Found serverid for %s: %s', + $serverid, + $id + ) ); return $id; } } - $this->_logger->meta(sprintf( - 'STORAGE: No folderid found for %s', - $serverid) + $this->_logger->meta( + sprintf( + 'STORAGE: No folderid found for %s', + $serverid + ) ); return false; @@ -377,7 +387,7 @@ public function getFolderUidForBackendId($serverid) * @throws Horde_ActiveSync_Exception_StaleState * @throws Horde_ActiveSync_Exception_FolderGone */ - public function getChanges(array $options = array()) + public function getChanges(array $options = []) { if (!empty($this->_collection['id'])) { // How far back to sync for those collections that use this. @@ -385,10 +395,12 @@ public function getChanges(array $options = array()) ? $this->_collection['filtertype'] : 0); - $this->_logger->meta(sprintf( - 'STATE: Initializing message diff engine for %s (%s)', - $this->_collection['id'], - $this->_folder->serverid()) + $this->_logger->meta( + sprintf( + 'STATE: Initializing message diff engine for %s (%s)', + $this->_collection['id'], + $this->_folder->serverid() + ) ); // Check for previously found changes first. @@ -409,18 +421,20 @@ public function getChanges(array $options = array()) ); } - $this->_logger->meta(sprintf( - 'STATE: Using SYNCSTAMP %s for %s.', - $this->_thisSyncStamp, - $this->_collection['id']) + $this->_logger->meta( + sprintf( + 'STATE: Using SYNCSTAMP %s for %s.', + $this->_thisSyncStamp, + $this->_collection['id'] + ) ); // No existing changes, poll the backend try { $changes = $this->_backend->getServerChanges( $this->_folder, - (int)$this->_lastSyncStamp, - (int)$this->_thisSyncStamp, + (int) $this->_lastSyncStamp, + (int) $this->_thisSyncStamp, $cutoffdate, !empty($options['ping']), $this->_folder->haveInitialSync, @@ -431,9 +445,11 @@ public function getChanges(array $options = array()) // @todo For BC reasons, we need to treat AuthenticationFailure // here as a need to resync folders since to the backend, the // end result is the same, the folder is "missing". - $this->_logger->meta(sprintf( - 'STATE: Unable to find folder %s. Could be vanished, or permissions denied.', - $this->_folder->serverId()) + $this->_logger->meta( + sprintf( + 'STATE: Unable to find folder %s. Could be vanished, or permissions denied.', + $this->_folder->serverId() + ) ); throw new Horde_ActiveSync_Exception_FolderGone($e->getMessage()); } @@ -443,100 +459,108 @@ public function getChanges(array $options = array()) $this->_folder->updateState(); } - $this->_logger->meta(sprintf( - 'STATE: Found %d message changes in %s.', - count($changes), - $this->_collection['id']) + $this->_logger->meta( + sprintf( + 'STATE: Found %d message changes in %s.', + count($changes), + $this->_collection['id'] + ) ); // Check for mirrored client changes. - $this->_changes = array(); + $this->_changes = []; if (count($changes) && $this->_havePIMChanges()) { $this->_logger->meta('STATE: Checking for client initiated changes.'); switch ($this->_collection['class']) { - case Horde_ActiveSync::CLASS_EMAIL: - // @todo Fix me with a changes object that transparently - // deals with different data structure for initial sync and - // knows how to filter out client-sourced changes - if (!empty($changes) && !is_array($changes[0])) { - $this->_changes = $changes; - break; - } - - // Map of client-sourced changes - $mailmap = $this->_getMailMapChanges($changes); - - // Map constants to more human readable/loggable text. - $flag_map = array( - Horde_ActiveSync::CHANGE_TYPE_FLAGS => 'flag change', - Horde_ActiveSync::CHANGE_TYPE_DELETE => 'deletion', - Horde_ActiveSync::CHANGE_TYPE_CHANGE => 'move', - Horde_ActiveSync::CHANGE_TYPE_DRAFT => 'draft' - ); - - $cnt = count($changes); - for ($i = 0; $i < $cnt; $i++) { - if (empty($mailmap[$changes[$i]['id']][$changes[$i]['type']])) { - $this->_changes[] = $changes[$i]; - continue; + case Horde_ActiveSync::CLASS_EMAIL: + // @todo Fix me with a changes object that transparently + // deals with different data structure for initial sync and + // knows how to filter out client-sourced changes + if (!empty($changes) && !is_array($changes[0])) { + $this->_changes = $changes; + break; } - // @todo For 3.0, create a Changes and - // ChangeFilter classes to abstract out a bunch of - // this stuff. (Needs BC breaking changes in - // storage/state classes). - - // OL2013 is broken and duplicates the destination - // email during MOVEITEMS requests (instead it - // reassigns the existing email the new UID). Don't - // send the ADD command for these changes. - if ($changes[$i]['type'] == Horde_ActiveSync::CHANGE_TYPE_CHANGE && - $changes[$i]['flags'] == Horde_ActiveSync::FLAG_NEWMESSAGE && - $this->_deviceInfo->deviceType != 'WindowsOutlook15') { + + // Map of client-sourced changes + $mailmap = $this->_getMailMapChanges($changes); + + // Map constants to more human readable/loggable text. + $flag_map = [ + Horde_ActiveSync::CHANGE_TYPE_FLAGS => 'flag change', + Horde_ActiveSync::CHANGE_TYPE_DELETE => 'deletion', + Horde_ActiveSync::CHANGE_TYPE_CHANGE => 'move', + Horde_ActiveSync::CHANGE_TYPE_DRAFT => 'draft', + ]; + + $cnt = count($changes); + for ($i = 0; $i < $cnt; $i++) { + if (empty($mailmap[$changes[$i]['id']][$changes[$i]['type']])) { + $this->_changes[] = $changes[$i]; + continue; + } + // @todo For 3.0, create a Changes and + // ChangeFilter classes to abstract out a bunch of + // this stuff. (Needs BC breaking changes in + // storage/state classes). + + // OL2013 is broken and duplicates the destination + // email during MOVEITEMS requests (instead it + // reassigns the existing email the new UID). Don't + // send the ADD command for these changes. + if ($changes[$i]['type'] == Horde_ActiveSync::CHANGE_TYPE_CHANGE + && $changes[$i]['flags'] == Horde_ActiveSync::FLAG_NEWMESSAGE + && $this->_deviceInfo->deviceType != 'WindowsOutlook15') { + $this->_changes[] = $changes[$i]; + continue; + } + $changes[$i]['ignore'] = true; $this->_changes[] = $changes[$i]; - continue; + $this->_logger->meta( + sprintf( + 'STATE: Ignoring client initiated %s for %s', + $flag_map[$changes[$i]['type']], + $changes[$i]['id'] + ) + ); } - $changes[$i]['ignore'] = true; - $this->_changes[] = $changes[$i]; - $this->_logger->meta(sprintf( - 'STATE: Ignoring client initiated %s for %s', - $flag_map[$changes[$i]['type']], - $changes[$i]['id']) - ); - } - break; - - default: - $client_timestamps = $this->_getPIMChangeTS($changes); - $cnt = count($changes); - - if (!empty($changes) && !is_array($changes[0])) { - $this->_changes = $changes; break; - } - for ($i = 0; $i < $cnt; $i++) { - if (empty($client_timestamps[$changes[$i]['id']])) { - $this->_changes[] = $changes[$i]; - continue; - } - if ($changes[$i]['type'] == Horde_ActiveSync::CHANGE_TYPE_DELETE) { - // If we have a delete, don't bother stating the message, - // the entry should already be deleted on the client. - $stat['mod'] = 0; - } else { - // stat only returns MODIFY times, not deletion times, - // so will return (int)0 for ADD or DELETE. - $stat = $this->_backend->statMessage($this->_folder->serverid(), $changes[$i]['id']); + default: + $client_timestamps = $this->_getPIMChangeTS($changes); + $cnt = count($changes); + + if (!empty($changes) && !is_array($changes[0])) { + $this->_changes = $changes; + break; } - if ($client_timestamps[$changes[$i]['id']] >= $stat['mod']) { - $this->_logger->meta(sprintf( - 'STATE: Ignoring client initiated change for %s (client TS: %s Stat TS: %s)', - $changes[$i]['id'], $client_timestamps[$changes[$i]['id']], $stat['mod']) - ); - } else { - $this->_changes[] = $changes[$i]; + + for ($i = 0; $i < $cnt; $i++) { + if (empty($client_timestamps[$changes[$i]['id']])) { + $this->_changes[] = $changes[$i]; + continue; + } + if ($changes[$i]['type'] == Horde_ActiveSync::CHANGE_TYPE_DELETE) { + // If we have a delete, don't bother stating the message, + // the entry should already be deleted on the client. + $stat['mod'] = 0; + } else { + // stat only returns MODIFY times, not deletion times, + // so will return (int)0 for ADD or DELETE. + $stat = $this->_backend->statMessage($this->_folder->serverid(), $changes[$i]['id']); + } + if ($client_timestamps[$changes[$i]['id']] >= $stat['mod']) { + $this->_logger->meta( + sprintf( + 'STATE: Ignoring client initiated change for %s (client TS: %s Stat TS: %s)', + $changes[$i]['id'], + $client_timestamps[$changes[$i]['id']], + $stat['mod'] + ) + ); + } else { + $this->_changes[] = $changes[$i]; + } } - } } } elseif (count($changes)) { $this->_logger->meta('STATE: No client changes, returning all messages.'); @@ -573,15 +597,18 @@ protected function _getFolderChanges() } } $this->_changes = $this->_getDiff( - (empty($this->_folder) ? array() : $this->_folder), - $folderlist); + (empty($this->_folder) ? [] : $this->_folder), + $folderlist + ); if (!count($this->_changes)) { $this->_logger->meta('STATE: No folder changes found.'); } else { - $this->_logger->meta(sprintf( - 'STATE: Found %d folder changes.', - count($this->_changes)) + $this->_logger->meta( + sprintf( + 'STATE: Found %d folder changes.', + count($this->_changes) + ) ); } } @@ -599,9 +626,11 @@ protected function _getFolderChanges() public function getNewSyncKeyWrapper($syncKey) { if ($this->checkCollision($newKey = self::getNewSyncKey($syncKey))) { - $this->_logger->err(sprintf( - 'STATE: Found collision when generating synckey %s. Trying again.', - $newKey) + $this->_logger->err( + sprintf( + 'STATE: Found collision when generating synckey %s. Trying again.', + $newKey + ) ); return $this->getNewSyncKeyWrapper($synckey); } @@ -683,18 +712,18 @@ public static function getSyncKeyCounter($syncKey) */ public static function getSyncKeyUid($syncKey) { - if (preg_match('/^(\{[a-fA-F0-9-]+\})([0-9]+)$/', $syncKey, $matches)) { + if (preg_match('/^(\{[a-fA-F0-9-]+\})([0-9]+)$/', $syncKey, $matches)) { return $matches[1]; } } - /** - * Returns the timestamp of the earliest modification time to consider - * - * @param integer $restrict The time period to restrict to - * - * @return integer - */ + /** + * Returns the timestamp of the earliest modification time to consider + * + * @param integer $restrict The time period to restrict to + * + * @return integer + */ protected static function _getCutOffDate($restrict) { // @todo Should just pass the filtertype to the driver instead @@ -702,30 +731,30 @@ protected static function _getCutOffDate($restrict) if ($restrict == Horde_ActiveSync::FILTERTYPE_INCOMPLETETASKS) { return $restrict; } - switch($restrict) { - case Horde_ActiveSync::FILTERTYPE_1DAY: - $back = 86400; - break; - case Horde_ActiveSync::FILTERTYPE_3DAYS: - $back = 259200; - break; - case Horde_ActiveSync::FILTERTYPE_1WEEK: - $back = 604800; - break; - case Horde_ActiveSync::FILTERTYPE_2WEEKS: - $back = 1209600; - break; - case Horde_ActiveSync::FILTERTYPE_1MONTH: - $back = 2419200; - break; - case Horde_ActiveSync::FILTERTYPE_3MONTHS: - $back = 7257600; - break; - case Horde_ActiveSync::FILTERTYPE_6MONTHS: - $back = 14515200; - break; - default: - break; + switch ($restrict) { + case Horde_ActiveSync::FILTERTYPE_1DAY: + $back = 86400; + break; + case Horde_ActiveSync::FILTERTYPE_3DAYS: + $back = 259200; + break; + case Horde_ActiveSync::FILTERTYPE_1WEEK: + $back = 604800; + break; + case Horde_ActiveSync::FILTERTYPE_2WEEKS: + $back = 1209600; + break; + case Horde_ActiveSync::FILTERTYPE_1MONTH: + $back = 2419200; + break; + case Horde_ActiveSync::FILTERTYPE_3MONTHS: + $back = 7257600; + break; + case Horde_ActiveSync::FILTERTYPE_6MONTHS: + $back = 14515200; + break; + default: + break; } if (isset($back)) { @@ -747,18 +776,18 @@ protected static function _getCutOffDate($restrict) */ protected function _getDiff($old, $new) { - $changes = array(); + $changes = []; // Sort both arrays in the same way by ID - usort($old, array(__CLASS__, 'RowCmp')); - usort($new, array(__CLASS__, 'RowCmp')); + usort($old, [__CLASS__, 'RowCmp']); + usort($new, [__CLASS__, 'RowCmp']); $inew = 0; $iold = 0; // Get changes by comparing our list of folders with // our previous state while (1) { - $change = array(); + $change = []; if ($iold >= count($old) || $inew >= count($new)) { break; } @@ -856,17 +885,19 @@ public function loadState(array $collection, $syncKey, $type = null, $id = null) // synckey == 0 is an initial sync or reset. if (empty($syncKey)) { - $this->_logger->notice(sprintf( - '%s::loadState: clearing folder state.', - __CLASS__) + $this->_logger->notice( + sprintf( + '%s::loadState: clearing folder state.', + __CLASS__ + ) ); if ($type == Horde_ActiveSync::REQUEST_TYPE_FOLDERSYNC) { - $this->_folder = array(); + $this->_folder = []; } else { // Create a new folder object. - $this->_folder = ($this->_collection['class'] == Horde_ActiveSync::CLASS_EMAIL) ? - new Horde_ActiveSync_Folder_Imap($this->_collection['serverid'], Horde_ActiveSync::CLASS_EMAIL) : - ($this->_collection['serverid'] == 'RI' ? new Horde_ActiveSync_Folder_RI('RI', 'RI') : new Horde_ActiveSync_Folder_Collection($this->_collection['serverid'], $this->_collection['class'])); + $this->_folder = ($this->_collection['class'] == Horde_ActiveSync::CLASS_EMAIL) + ? new Horde_ActiveSync_Folder_Imap($this->_collection['serverid'], Horde_ActiveSync::CLASS_EMAIL) + : ($this->_collection['serverid'] == 'RI' ? new Horde_ActiveSync_Folder_RI('RI', 'RI') : new Horde_ActiveSync_Folder_Collection($this->_collection['serverid'], $this->_collection['class'])); } $this->_syncKey = '0'; $this->_resetDeviceState($id); @@ -986,8 +1017,12 @@ abstract public function save(); * @param string $clientid client clientid sent when adding a new message */ abstract public function updateState( - $type, array $change, $origin = Horde_ActiveSync::CHANGE_ORIGIN_NA, - $user = null, $clientid = ''); + $type, + array $change, + $origin = Horde_ActiveSync::CHANGE_ORIGIN_NA, + $user = null, + $clientid = '' + ); /** * Save a new device policy key to storage. @@ -1029,7 +1064,7 @@ abstract public function setDeviceRWStatus($devId, $status); * * @return Horde_ActiveSync_Device */ - abstract public function loadDeviceInfo($device, $user = null, $params = array()); + abstract public function loadDeviceInfo($device, $user = null, $params = []); /** * Check that a given device id is known to the server. This is regardless @@ -1048,7 +1083,7 @@ abstract public function deviceExists($devId, $user = null); * @param object $data The device information * @param array $dirty Array of dirty properties. @since 2.9.0 */ - abstract public function setDeviceInfo(Horde_ActiveSync_Device $data, array $dirty = array()); + abstract public function setDeviceInfo(Horde_ActiveSync_Device $data, array $dirty = []); /** * Set the device's properties as sent by a SETTINGS request. @@ -1102,7 +1137,7 @@ abstract public function getLastSyncTimestamp(); * @return array The current sync cache for the user/device combination. * @throws Horde_ActiveSync_Exception */ - abstract public function getSyncCache($devid, $user, array $fields = null); + abstract public function getSyncCache($devid, $user, ?array $fields = null); /** * Save the provided sync_cache. @@ -1114,7 +1149,7 @@ abstract public function getSyncCache($devid, $user, array $fields = null); * * @throws Horde_ActiveSync_Exception */ - abstract public function saveSyncCache(array $cache, $devid, $user, array $dirty = array()); + abstract public function saveSyncCache(array $cache, $devid, $user, array $dirty = []); /** * Delete a complete sync cache @@ -1136,17 +1171,17 @@ abstract public function deleteSyncCache($devid, $user); * @return string The UID for the given clientid, null if none found. * @throws Horde_ActiveSync_Exception */ - abstract public function isDuplicatePIMAddition($id); - - /** - * Close the underlying backend storage connection. - * To be used during PING or looping SYNC operations. - */ - abstract public function disconnect(); - - /** - * (Re)open backend storage connection. - */ - abstract public function connect(); + abstract public function isDuplicatePIMAddition($id); + + /** + * Close the underlying backend storage connection. + * To be used during PING or looping SYNC operations. + */ + abstract public function disconnect(); + + /** + * (Re)open backend storage connection. + */ + abstract public function connect(); } diff --git a/lib/Horde/ActiveSync/State/Mongo.php b/lib/Horde/ActiveSync/State/Mongo.php index faf1dc34..6f023934 100644 --- a/lib/Horde/ActiveSync/State/Mongo.php +++ b/lib/Horde/ActiveSync/State/Mongo.php @@ -1,4 +1,5 @@ array( - 'index_id_user' => array( + protected $_indexes = [ + self::COLLECTION_DEVICE => [ + 'index_id_user' => [ self::MONGO_ID => 1, - self::DEVICE_USERS_USER => 1 - ) - ), - self::COLLECTION_STATE => array( - 'index_devid_folderid' => array( + self::DEVICE_USERS_USER => 1, + ], + ], + self::COLLECTION_STATE => [ + 'index_devid_folderid' => [ self::SYNC_DEVID => 1, - self::SYNC_FOLDERID => 1 - ) - ), - self::COLLECTION_MAP => array( - 'index_folder_dev_uid_user' => array( + self::SYNC_FOLDERID => 1, + ], + ], + self::COLLECTION_MAP => [ + 'index_folder_dev_uid_user' => [ self::SYNC_DEVID => 1, self::SYNC_USER => 1, self::SYNC_FOLDERID => 1, - self::MESSAGE_UID => 1 - ), - 'index_dev_user_uid_key' => array( + self::MESSAGE_UID => 1, + ], + 'index_dev_user_uid_key' => [ self::SYNC_DEVID => 1, self::SYNC_USER => 1, self::MESSAGE_UID => 1, self::SYNC_KEY => 1, self::SYNC_DELETED => 1, - ), - 'index_client_user_dev' => array( + ], + 'index_client_user_dev' => [ self::SYNC_CLIENTID => 1, self::SYNC_USER => 1, - self::SYNC_DEVID => 1 - ) - ), - self::COLLECTION_MAILMAP => array( - 'index_folder_dev_uid_user' => array( + self::SYNC_DEVID => 1, + ], + ], + self::COLLECTION_MAILMAP => [ + 'index_folder_dev_uid_user' => [ self::SYNC_DEVID => 1, self::SYNC_USER => 1, self::SYNC_FOLDERID => 1, - self::MESSAGE_UID => 1 - ) - ), - self::COLLECTION_CACHE => array( - 'index_dev_user' => array( + self::MESSAGE_UID => 1, + ], + ], + self::COLLECTION_CACHE => [ + 'index_dev_user' => [ self::CACHE_DEVID => 1, - self::CACHE_USER => 1 - ) - ) - ); + self::CACHE_USER => 1, + ], + ], + ]; - protected $_propertyMap = array( + protected $_propertyMap = [ 'deviceType' => self::DEVICE_TYPE, 'userAgent' => self::DEVICE_AGENT, 'rwstatus' => self::DEVICE_RWSTATUS, 'supported' => self::DEVICE_SUPPORTED, 'properties' => self::DEVICE_PROPERTIES, - 'id' => self::DEVICE_ID - ); + 'id' => self::DEVICE_ID, + ]; /** * Const'r @@ -194,7 +194,7 @@ class Horde_ActiveSync_State_Mongo extends Horde_ActiveSync_State_Base implement * * @return Horde_ActiveSync_State_Sql */ - public function __construct(array $params = array()) + public function __construct(array $params = []) { parent::__construct($params); if (empty($this->_params['connection']) || !($this->_params['connection'] instanceof MongoClient)) { @@ -218,23 +218,25 @@ public function __construct(array $params = array()) */ public function updateServerIdInState($uid, $serverid) { - $this->_logger->meta(sprintf( - 'Updating serverid in folder state. Setting %s for %s.', - $serverid, - $uid) + $this->_logger->meta( + sprintf( + 'Updating serverid in folder state. Setting %s for %s.', + $serverid, + $uid + ) ); - $query = array( + $query = [ self::SYNC_DEVID => $this->_deviceInfo->id, self::SYNC_USER => $this->_deviceInfo->user, - self::SYNC_FOLDERID => $uid - ); + self::SYNC_FOLDERID => $uid, + ]; try { $cursor = $this->_db->selectCollection(self::COLLECTION_STATE) - ->find($query, array(self::SYNC_DATA => true)); + ->find($query, [self::SYNC_DATA => true]); } catch (Exception $e) { - $this->_logger->err($e->getMessage()); + $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); } @@ -245,8 +247,8 @@ public function updateServerIdInState($uid, $serverid) try { $this->_db->selectCollection(self::COLLECTION_STATE)->update( $query, - array('$set' => array(self::SYNC_DATA => $folder)), - array('multiple' => true) + ['$set' => [self::SYNC_DATA => $folder]], + ['multiple' => true] ); } catch (Exception $e) { $this->_logger->err($e->getMessage()); @@ -265,16 +267,16 @@ protected function _loadState() try { $results = $this->_db->selectCollection(self::COLLECTION_STATE) ->findOne( - array( + [ self::MONGO_ID => $this->_syncKey, - self::SYNC_FOLDERID => $this->_collection['id'] - ), - array( + self::SYNC_FOLDERID => $this->_collection['id'], + ], + [ self::SYNC_DATA => true, self::SYNC_DEVID => true, self::SYNC_MOD => true, - self::SYNC_PENDING => true - ) + self::SYNC_PENDING => true, + ] ); } catch (Exception $e) { $this->_logger->err('Error in loading state from DB: ' . $e->getMessage()); @@ -284,7 +286,8 @@ protected function _loadState() if (empty($results)) { $this->_logger->warn(sprintf( 'Could not find state for synckey %s.', - $this->_syncKey)); + $this->_syncKey + )); throw new Horde_ActiveSync_Exception_StateGone(); } @@ -314,18 +317,22 @@ protected function _loadStateFromResults(array $results) $pending = $results[self::SYNC_PENDING]; if ($this->_type == Horde_ActiveSync::REQUEST_TYPE_FOLDERSYNC) { - $this->_folder = ($data !== false) ? $data : array(); - $this->_logger->meta(sprintf( - 'Loading FOLDERSYNC state containing %d folders.', - count($this->_folder)) + $this->_folder = ($data !== false) ? $data : []; + $this->_logger->meta( + sprintf( + 'Loading FOLDERSYNC state containing %d folders.', + count($this->_folder) + ) ); } elseif ($this->_type == Horde_ActiveSync::REQUEST_TYPE_SYNC) { $this->_folder = $data; $this->_changes = ($pending !== false) ? $pending : null; if ($this->_changes) { $this->_logger->meta( - sprintf('Found %d changes remaining from previous SYNC.', - count($this->_changes)) + sprintf( + 'Found %d changes remaining from previous SYNC.', + count($this->_changes) + ) ); } } @@ -352,7 +359,7 @@ public function save() // If we are setting the first synckey iteration, do not save the // timestamp, otherwise we will never get the initial set of data. - $document = array( + $document = [ self::MONGO_ID => $this->_syncKey, self::SYNC_KEY => $this->_syncKey, self::SYNC_DATA => $data, @@ -361,24 +368,28 @@ public function save() self::SYNC_FOLDERID => (!empty($this->_collection['id']) ? $this->_collection['id'] : Horde_ActiveSync::REQUEST_TYPE_FOLDERSYNC), self::SYNC_USER => $this->_deviceInfo->user, self::SYNC_PENDING => $pending, - self::SYNC_TIMESTAMP => time() - ); + self::SYNC_TIMESTAMP => time(), + ]; $this->_logger->meta( - sprintf('Saving state for sync_key %s: %s', + sprintf( + 'Saving state for sync_key %s: %s', $this->_syncKey, - serialize($document)) + serialize($document) + ) ); try { $this->_db->selectCollection(self::COLLECTION_STATE)->insert($document); } catch (Exception $e) { // Might exist already if the last sync attempt failed. - $this->_logger->notice(sprintf( - 'Previous request processing for synckey %s failed to be accepted by the client, removing previous state and trying again.', - $this->_syncKey) + $this->_logger->notice( + sprintf( + 'Previous request processing for synckey %s failed to be accepted by the client, removing previous state and trying again.', + $this->_syncKey + ) ); try { - $this->_db->selectCollection(self::COLLECTION_STATE)->remove(array(self::MONGO_ID => $this->_syncKey)); + $this->_db->selectCollection(self::COLLECTION_STATE)->remove([self::MONGO_ID => $this->_syncKey]); $this->_db->selectCollection(self::COLLECTION_STATE)->insert($document); } catch (Exception $e) { throw new Horde_ActiveSync_Exception('Error saving state.'); @@ -418,12 +429,20 @@ public function save() * @throws Horde_ActiveSync_Exception */ public function updateState( - $type, array $change, $origin = Horde_ActiveSync::CHANGE_ORIGIN_NA, - $user = null, $clientid = '') - { + $type, + array $change, + $origin = Horde_ActiveSync::CHANGE_ORIGIN_NA, + $user = null, + $clientid = '' + ) { $this->_logger->meta(sprintf( 'Horde_ActiveSync_State_Mongo::updateState(%s, %s, %d, %s, %s)', - $type, serialize($change), $origin, $user, $clientid)); + $type, + serialize($change), + $origin, + $user, + $clientid + )); if ($origin == Horde_ActiveSync::CHANGE_ORIGIN_PIM) { if ($this->_type == Horde_ActiveSync::REQUEST_TYPE_FOLDERSYNC) { @@ -444,9 +463,9 @@ public function updateState( // information since there is no SYNCKEY. Attempt to map this from // the $change array. if (empty($this->_collection)) { - $this->_collection = array( + $this->_collection = [ 'class' => $change['class'], - 'id' => $change['folderuid']); + 'id' => $change['folderuid']]; } $syncKey = empty($this->_syncKey) ? $this->getLatestSynckeyForCollection($this->_collection['id']) @@ -455,59 +474,59 @@ public function updateState( // This is an incoming change from the client, store it so we // don't mirror it back to device. switch ($this->_collection['class']) { - case Horde_ActiveSync::CLASS_EMAIL: - if ($type == Horde_ActiveSync::CHANGE_TYPE_CHANGE && - isset($change['flags']) && is_array($change['flags']) && - !empty($change['flags'])) { - $type = Horde_ActiveSync::CHANGE_TYPE_FLAGS; - } - $document = array( - self::MESSAGE_UID => (string)$change['id'], - self::SYNC_KEY => $syncKey, - self::SYNC_DEVID => $this->_deviceInfo->id, - self::SYNC_FOLDERID => $change['serverid'], - self::SYNC_USER => $user - ); - switch ($type) { - case Horde_ActiveSync::CHANGE_TYPE_FLAGS: - if (isset($change['flags']['read'])) { - $document[self::SYNC_READ] = !empty($change['flags']['read']); - } else { - $document[self::SYNC_FLAGGED] = $flag_value = !empty($change['flags']['flagged']); + case Horde_ActiveSync::CLASS_EMAIL: + if ($type == Horde_ActiveSync::CHANGE_TYPE_CHANGE + && isset($change['flags']) && is_array($change['flags']) + && !empty($change['flags'])) { + $type = Horde_ActiveSync::CHANGE_TYPE_FLAGS; + } + $document = [ + self::MESSAGE_UID => (string) $change['id'], + self::SYNC_KEY => $syncKey, + self::SYNC_DEVID => $this->_deviceInfo->id, + self::SYNC_FOLDERID => $change['serverid'], + self::SYNC_USER => $user, + ]; + switch ($type) { + case Horde_ActiveSync::CHANGE_TYPE_FLAGS: + if (isset($change['flags']['read'])) { + $document[self::SYNC_READ] = !empty($change['flags']['read']); + } else { + $document[self::SYNC_FLAGGED] = $flag_value = !empty($change['flags']['flagged']); + } + break; + case Horde_ActiveSync::CHANGE_TYPE_DELETE: + $document[self::SYNC_DELETED] = true; + break; + case Horde_ActiveSync::CHANGE_TYPE_CHANGE: + $document[self::SYNC_CHANGED] = true; + break; + } + try { + $this->_db->selectCollection(self::COLLECTION_MAILMAP)->insert($document); + } catch (Exception $e) { + throw Horde_ActiveSync_Exception($e); } break; - case Horde_ActiveSync::CHANGE_TYPE_DELETE: - $document[self::SYNC_DELETED] = true; - break; - case Horde_ActiveSync::CHANGE_TYPE_CHANGE: - $document[self::SYNC_CHANGED] = true; - break; - } - try { - $this->_db->selectCollection(self::COLLECTION_MAILMAP)->insert($document); - } catch (Exception $e) { - throw Horde_ActiveSync_Exception($e); - } - break; - - default: - $document = array( - self::MESSAGE_UID => $change['id'], - self::SYNC_MODTIME => $change['mod'], - self::SYNC_KEY => $syncKey, - self::SYNC_DEVID => $this->_deviceInfo->id, - self::SYNC_FOLDERID => $change['serverid'], - self::SYNC_USER => $user, - self::SYNC_CLIENTID => $clientid, - self::SYNC_DELETED => $type == Horde_ActiveSync::CHANGE_TYPE_DELETE - ); - try { - $this->_db->selectCollection(self::COLLECTION_MAP)->insert($document); - } catch (Exception $e) { - throw new Horde_ActiveSync_Exception($e); - } - break; + default: + $document = [ + self::MESSAGE_UID => $change['id'], + self::SYNC_MODTIME => $change['mod'], + self::SYNC_KEY => $syncKey, + self::SYNC_DEVID => $this->_deviceInfo->id, + self::SYNC_FOLDERID => $change['serverid'], + self::SYNC_USER => $user, + self::SYNC_CLIENTID => $clientid, + self::SYNC_DELETED => $type == Horde_ActiveSync::CHANGE_TYPE_DELETE, + ]; + + try { + $this->_db->selectCollection(self::COLLECTION_MAP)->insert($document); + } catch (Exception $e) { + throw new Horde_ActiveSync_Exception($e); + } + break; } } else { // We are sending server changes; $this->_changes will contain all @@ -533,7 +552,8 @@ public function updateState( (empty($value['parent']) ? '0' : $value['parent']), $folder->displayname, $folder->_serverid, - $folder->type); + $folder->type + ); $this->_folder[] = $stat; $this->_folder = array_values($this->_folder); } @@ -559,18 +579,18 @@ public function updateState( * @return Horde_ActiveSync_Device The device object * @throws Horde_ActiveSync_Exception */ - public function loadDeviceInfo($devId, $user = null, $params = array()) + public function loadDeviceInfo($devId, $user = null, $params = []) { // See if we already have this device, for this user loaded - if (empty($params['force']) && - !empty($this->_deviceInfo) && - $this->_deviceInfo->id == $devId && - !empty($this->_deviceInfo) && - $user == $this->_deviceInfo->user) { + if (empty($params['force']) + && !empty($this->_deviceInfo) + && $this->_deviceInfo->id == $devId + && !empty($this->_deviceInfo) + && $user == $this->_deviceInfo->user) { return $this->_deviceInfo; } - $query = array(self::MONGO_ID => $devId); + $query = [self::MONGO_ID => $devId]; if (!empty($user)) { $query[self::DEVICE_USERS_USER] = $user; } @@ -585,7 +605,7 @@ public function loadDeviceInfo($devId, $user = null, $params = array()) throw new Horde_ActiveSync_Exception('Device not found.'); } $map = array_flip($this->_propertyMap); - $device = array(); + $device = []; foreach ($device_data as $field => $data) { if (!empty($map[$field])) { $device[$map[$field]] = $data; @@ -613,25 +633,27 @@ public function loadDeviceInfo($devId, $user = null, $params = array()) * * @throws Horde_ActiveSync_Exception */ - public function setDeviceInfo(Horde_ActiveSync_Device $data, array $dirty = array()) + public function setDeviceInfo(Horde_ActiveSync_Device $data, array $dirty = []) { if (count($dirty)) { - $device = array(); + $device = []; foreach (array_keys($dirty) as $property) { if (!empty($this->_propertyMap[$property])) { $device[$this->_propertyMap[$property]] = $data->$property; } } - $this->_logger->meta(sprintf( - 'setDeviceInfo saving properties: %s', - serialize($dirty)) + $this->_logger->meta( + sprintf( + 'setDeviceInfo saving properties: %s', + serialize($dirty) + ) ); if (count($device)) { try { $this->_db->selectCollection(self::COLLECTION_DEVICE)->update( - array(self::MONGO_ID => $data->id), - array('$set' => $device), - array('upsert' => true) + [self::MONGO_ID => $data->id], + ['$set' => $device], + ['upsert' => true] ); } catch (Exception $e) { $this->_logger->err($e->getMessage()); @@ -640,19 +662,19 @@ public function setDeviceInfo(Horde_ActiveSync_Device $data, array $dirty = arra } if (!empty($dirty['user']) || !empty($dirty['policykey'])) { - $user_data = array( + $user_data = [ self::DEVICE_USER => $data->user, - self::DEVICE_POLICYKEY => (string)$data->policykey - ); + self::DEVICE_POLICYKEY => (string) $data->policykey, + ]; try { $this->_db->selectCollection(self::COLLECTION_DEVICE)->update( - array(self::MONGO_ID => $data->id), - array('$pull' => array('users' => array(self::DEVICE_USER => $data->user))) + [self::MONGO_ID => $data->id], + ['$pull' => ['users' => [self::DEVICE_USER => $data->user]]] ); $this->_db->selectCollection(self::COLLECTION_DEVICE)->update( - array(self::MONGO_ID => $data->id), - array('$addToSet' => array('users' => $user_data)) + [self::MONGO_ID => $data->id], + ['$addToSet' => ['users' => $user_data]] ); } catch (Exception $e) { $this->_logger->err($e->getMessage()); @@ -674,14 +696,14 @@ public function setDeviceInfo(Horde_ActiveSync_Device $data, array $dirty = arra */ public function setDeviceProperties(array $data, $deviceId) { - $query = array(self::MONGO_ID => $deviceId); - $update = array( - '$set' => array( - self::DEVICE_PROPERTIES => $data - ) - ); + $query = [self::MONGO_ID => $deviceId]; + $update = [ + '$set' => [ + self::DEVICE_PROPERTIES => $data, + ], + ]; try { - $this->_db->selectCollection(self::COLLECTION_DEVICE)->update($query, $update, array('upsert' => true)); + $this->_db->selectCollection(self::COLLECTION_DEVICE)->update($query, $update, ['upsert' => true]); } catch (Exception $e) { $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); @@ -701,7 +723,7 @@ public function setDeviceProperties(array $data, $deviceId) */ public function deviceExists($devId, $user = null) { - $query = array(self::MONGO_ID => $devId); + $query = [self::MONGO_ID => $devId]; if (!empty($user)) { $query[self::DEVICE_USERS_USER] = $user; } @@ -738,13 +760,13 @@ protected function _checkCollision($guid) * @return array An array of device hashes * @throws Horde_ActiveSync_Exception */ - public function listDevices($user = null, $filter = array()) + public function listDevices($user = null, $filter = []) { - $query = array(); + $query = []; if (!empty($user)) { $query[self::DEVICE_USERS_USER] = $user; } - $explicit_fields = array(self::DEVICE_ID, self::DEVICE_TYPE, self::DEVICE_AGENT, self::DEVICE_USER); + $explicit_fields = [self::DEVICE_ID, self::DEVICE_TYPE, self::DEVICE_AGENT, self::DEVICE_USER]; foreach ($filter as $key => $value) { if (in_array($key, $explicit_fields)) { $query[$key] = new MongoRegex("/^$value*/"); @@ -759,12 +781,12 @@ public function listDevices($user = null, $filter = array()) $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); } - $results = array(); + $results = []; foreach ($cursor as $item) { if (!empty($item['users'])) { foreach ($item['users'] as $user) { $device = $item; - $device = array_merge ($device, $user); + $device = array_merge($device, $user); unset($device['users']); $results[] = $device; } @@ -799,13 +821,13 @@ public function resetAllPolicyKeys() // throw new Horde_ActiveSync_Exception($e); // } $cursor = $this->_db->selectCollection(self::COLLECTION_DEVICE) - ->find(array(), array('users' => true)); + ->find([], ['users' => true]); foreach ($cursor as $row) { foreach ($row['users'] as $user) { $this->_db->selectCollection(self::COLLECTION_DEVICE)->update( - array(self::DEVICE_USERS_USER => $user[self::DEVICE_USER]), - array('$set' => array('users.$.device_policykey' => 0)), - array('multiple' => true) + [self::DEVICE_USERS_USER => $user[self::DEVICE_USER]], + ['$set' => ['users.$.device_policykey' => 0]], + ['multiple' => true] ); } } @@ -821,9 +843,9 @@ public function resetAllPolicyKeys() */ public function setDeviceRWStatus($devId, $status) { - $query = array(self::MONGO_ID => $devId); - $new_data = array(self::DEVICE_RWSTATUS => $status); - $update = array('$set' => $new_data); + $query = [self::MONGO_ID => $devId]; + $new_data = [self::DEVICE_RWSTATUS => $status]; + $update = ['$set' => $new_data]; try { $this->_db->selectCollection(self::COLLECTION_DEVICE)->update($query, $update); } catch (Exception $e) { @@ -834,14 +856,14 @@ public function setDeviceRWStatus($devId, $status) if ($status == Horde_ActiveSync::RWSTATUS_PENDING) { $new_data[self::DEVICE_USERS_POLICYKEY] = 0; $cursor = $this->_db->selectCollection(self::COLLECTION_DEVICE) - ->find($query, array('users' => true)); + ->find($query, ['users' => true]); try { foreach ($cursor as $row) { foreach ($row['users'] as $user) { $this->_db->selectCollection(self::COLLECTION_DEVICE)->update( - array(self::DEVICE_USERS_USER => $user[self::DEVICE_USER]), - array('$set' => array('users.$.device_policykey' => 0)), - array('multiple' => true) + [self::DEVICE_USERS_USER => $user[self::DEVICE_USER]], + ['$set' => ['users.$.device_policykey' => 0]], + ['multiple' => true] ); } } @@ -866,13 +888,14 @@ protected function _resetDeviceState($id) 'Resetting device state for device: %s, user: %s, and collection: %s.', $this->_deviceInfo->id, $this->_deviceInfo->user, - $id)); + $id + )); - $query = array( + $query = [ self::SYNC_DEVID => $this->_deviceInfo->id, self::SYNC_FOLDERID => $id, - self::SYNC_USER => $this->_deviceInfo->user - ); + self::SYNC_USER => $this->_deviceInfo->user, + ]; try { $this->_db->selectCollection(self::COLLECTION_STATE)->remove($query); @@ -915,15 +938,15 @@ public function getLastSyncTimestamp($id = null, $user = null) $id = empty($id) ? $this->_deviceInfo->id : $id; $user = empty($user) ? $this->_deviceInfo->user : $user; - $match = array(self::SYNC_DEVID => $id); + $match = [self::SYNC_DEVID => $id]; if (!empty($user)) { $match[self::SYNC_USER] = $user; } try { $results = $this->_db->selectCollection(self::COLLECTION_STATE)->aggregate( - array('$match' => $match), - array('$group' => array(self::MONGO_ID => '$sync_dev', 'max' => array('$max' => '$sync_timestamp'))) + ['$match' => $match], + ['$group' => [self::MONGO_ID => '$sync_dev', 'max' => ['$max' => '$sync_timestamp']]] ); } catch (Exception $e) { $this->_logger->err($e->getMessage()); @@ -951,9 +974,13 @@ public function setPolicyKey($devId, $key) $this->_logger->err('Device not loaded'); throw new Horde_ActiveSync_Exception('Device not loaded'); } - $this->_logger->meta(sprintf( - 'Setting policykey: %s, %s, %s', - $devId, $this->_backend->getUser(), $key) + $this->_logger->meta( + sprintf( + 'Setting policykey: %s, %s, %s', + $devId, + $this->_backend->getUser(), + $key + ) ); $this->_deviceInfo->policykey = $key; $this->_deviceInfo->save(); @@ -981,13 +1008,13 @@ public function removeState(array $options) // device table entry, and the device will continue to be wiped each // time it connects. if (!empty($options['devId']) && !empty($options['user'])) { - $query = array( + $query = [ self::MONGO_ID => $options['devId'], - '$or' => array(array(self::DEVICE_RWSTATUS => Horde_ActiveSync::RWSTATUS_PENDING), array(self::DEVICE_RWSTATUS => Horde_ActiveSync::RWSTATUS_WIPED)) - ); + '$or' => [[self::DEVICE_RWSTATUS => Horde_ActiveSync::RWSTATUS_PENDING], [self::DEVICE_RWSTATUS => Horde_ActiveSync::RWSTATUS_WIPED]], + ]; try { $results = $this->_db->selectCollection(self::COLLECTION_DEVICE) - ->findOne($query, array(self::MONGO_ID => true)); + ->findOne($query, [self::MONGO_ID => true]); } catch (Exception $e) { $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); @@ -998,22 +1025,26 @@ public function removeState(array $options) } // Query for state and map tables. - $query = array( + $query = [ self::SYNC_DEVID => $options['devId'], - self::SYNC_USER => $options['user'] - ); + self::SYNC_USER => $options['user'], + ]; if (!empty($options['id'])) { $query[self::SYNC_FOLDERID] = $options['id']; - $this->_logger->meta(sprintf( - 'Removing device state for user %s and collection %s.', - $options['user'], - $options['id']) + $this->_logger->meta( + sprintf( + 'Removing device state for user %s and collection %s.', + $options['user'], + $options['id'] + ) ); } else { - $this->_logger->meta(sprintf( - 'Removing device %s state for user %s.', - $options['devId'], - $options['user']) + $this->_logger->meta( + sprintf( + 'Removing device %s state for user %s.', + $options['devId'], + $options['user'] + ) ); $this->deleteSyncCache($options['devId'], $options['user']); } @@ -1021,8 +1052,8 @@ public function removeState(array $options) // Remove device data for user try { $this->_db->selectCollection(self::COLLECTION_DEVICE)->update( - array(self::MONGO_ID => $options['devId'], self::DEVICE_USERS_USER => $options['user']), - array('$pull' => array('users' => array(self::DEVICE_USER=> $options['user']))) + [self::MONGO_ID => $options['devId'], self::DEVICE_USERS_USER => $options['user']], + ['$pull' => ['users' => [self::DEVICE_USER => $options['user']]]] ); } catch (Exception $e) { $this->_logger->err($e->getMessage()); @@ -1030,44 +1061,50 @@ public function removeState(array $options) } } elseif (!empty($options['devId'])) { // Query for state and map tables. - $query = array(self::SYNC_DEVID => $options['devId']); - $this->_logger->meta(sprintf( - 'Removing all device state for device %s.', - $options['devId']) + $query = [self::SYNC_DEVID => $options['devId']]; + $this->_logger->meta( + sprintf( + 'Removing all device state for device %s.', + $options['devId'] + ) ); $this->deleteSyncCache($options['devId']); // Remove device data. try { - $this->_db->selectCollection(self::COLLECTION_DEVICE)->remove(array(self::MONGO_ID => $options['devId'])); + $this->_db->selectCollection(self::COLLECTION_DEVICE)->remove([self::MONGO_ID => $options['devId']]); } catch (Exception $e) { $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); } } elseif (!empty($options['user'])) { // Query for state and map tables. - $query = array(self::SYNC_USER => $options['user']); - $this->_logger->meta(sprintf( - 'Removing all device state for user %s.', - $options['user']) + $query = [self::SYNC_USER => $options['user']]; + $this->_logger->meta( + sprintf( + 'Removing all device state for user %s.', + $options['user'] + ) ); $this->deleteSyncCache(null, $options['user']); // Delete all user's device info. try { $this->_db->selectCollection(self::COLLECTION_DEVICE)->update( - array(self::DEVICE_USERS_USER), - array('$pull' => array('users' => array(self::DEVICE_USER => $options['user']))) + [self::DEVICE_USERS_USER], + ['$pull' => ['users' => [self::DEVICE_USER => $options['user']]]] ); } catch (Exception $e) { $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); } } elseif (!empty($options['synckey'])) { - $query = array(self::SYNC_KEY => $options['synckey']); - $this->_logger->meta(sprintf( - 'Removing device state for sync_key %s only.', - $options['synckey']) + $query = [self::SYNC_KEY => $options['synckey']]; + $this->_logger->meta( + sprintf( + 'Removing device state for sync_key %s only.', + $options['synckey'] + ) ); } else { return; @@ -1078,9 +1115,9 @@ public function removeState(array $options) $this->_db->selectCollection(self::COLLECTION_STATE)->remove($query); $this->_db->selectCollection(self::COLLECTION_MAP)->remove($query); $this->_db->selectCollection(self::COLLECTION_MAILMAP)->remove($query); - $this->_db->selectCollection(self::COLLECTION_DEVICE)->remove(array('users' => array('$size' => 0))); + $this->_db->selectCollection(self::COLLECTION_DEVICE)->remove(['users' => ['$size' => 0]]); } catch (Exception $e) { - $this->_logger->err($e->getMessage()); + $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); } @@ -1096,19 +1133,19 @@ public function removeState(array $options) * @return string The UID for the given clientid, null if none found. * @throws Horde_ActiveSync_Exception */ - public function isDuplicatePIMAddition($id) - { - $query = array( + public function isDuplicatePIMAddition($id) + { + $query = [ self::SYNC_CLIENTID => $id, self::SYNC_USER => $this->_deviceInfo->user, - self::SYNC_DEVID => $this->_deviceInfo->id - ); + self::SYNC_DEVID => $this->_deviceInfo->id, + ]; try { $result = $this->_db->selectCollection(self::COLLECTION_MAP) ->findOne( $query, - array(self::MESSAGE_UID => true) + [self::MESSAGE_UID => true] ); } catch (Exception $e) { $this->_logger->err($e->getMessage()); @@ -1120,7 +1157,7 @@ public function isDuplicatePIMAddition($id) } return $result[self::MESSAGE_UID]; - } + } /** * Return the sync cache. @@ -1133,23 +1170,24 @@ public function isDuplicatePIMAddition($id) * @return array The current sync cache for the user/device combination. * @throws Horde_ActiveSync_Exception */ - public function getSyncCache($devid, $user, array $fields = null) + public function getSyncCache($devid, $user, ?array $fields = null) { $this->_logger->meta(sprintf( 'Loading SyncCache from storage: %s', - serialize($fields))); + serialize($fields) + )); - $query = array( + $query = [ self::CACHE_DEVID => $devid, - self::CACHE_USER => $user - ); - $projection = array(); + self::CACHE_USER => $user, + ]; + $projection = []; if (!is_null($fields)) { foreach ($fields as $field) { $projection[self::CACHE_DATA . '.' . $field] = true; } } else { - $projection = array(self::CACHE_DATA => true); + $projection = [self::CACHE_DATA => true]; } try { $data = $this->_db->selectCollection(self::COLLECTION_CACHE) @@ -1160,17 +1198,17 @@ public function getSyncCache($devid, $user, array $fields = null) } if (is_null($fields) && (empty($data) || empty($data[self::CACHE_DATA]))) { - return array( - 'confirmed_synckeys' => array(), + return [ + 'confirmed_synckeys' => [], 'lasthbsyncstarted' => false, 'lastsyncendnormal' => false, 'timestamp' => false, 'wait' => false, 'hbinterval' => false, - 'folders' => array(), + 'folders' => [], 'hierarchy' => false, - 'collections' => array(), - 'pingheartbeat' => false); + 'collections' => [], + 'pingheartbeat' => false]; } else { return $data[self::CACHE_DATA]; } @@ -1186,19 +1224,23 @@ public function getSyncCache($devid, $user, array $fields = null) * * @throws Horde_ActiveSync_Exception */ - public function saveSyncCache(array $cache, $devid, $user, array $dirty = array()) + public function saveSyncCache(array $cache, $devid, $user, array $dirty = []) { - $this->_logger->meta(sprintf( - 'Saving SYNC_CACHE entry fields %s for user %s and device %s.', - serialize($dirty), $user, $devid) + $this->_logger->meta( + sprintf( + 'Saving SYNC_CACHE entry fields %s for user %s and device %s.', + serialize($dirty), + $user, + $devid + ) ); $cache['timestamp'] = strval($cache['timestamp']); - $query = array( + $query = [ self::CACHE_DEVID => $devid, - self::CACHE_USER => $user - ); - $update = array(); + self::CACHE_USER => $user, + ]; + $update = []; // Ensure the initial object is written for the collection data. if (empty($cache['collections'])) { @@ -1219,8 +1261,8 @@ public function saveSyncCache(array $cache, $devid, $user, array $dirty = array( try { $this->_db->selectCollection(self::COLLECTION_CACHE)->update( $query, - array('$set' => $update), - array('upsert' => true) + ['$set' => $update], + ['upsert' => true] ); } catch (Exception $e) { $this->_logger->err($e->getMessage()); @@ -1240,9 +1282,11 @@ public function deleteSyncCache($devid, $user = null) { $this->_logger->meta(sprintf( 'Horde_ActiveSync_State_Mongo::deleteSyncCache(%s, %s)', - $devid, $user)); + $devid, + $user + )); - $params = array(); + $params = []; if (!empty($devid)) { $params[self::CACHE_DEVID] = $devid; } @@ -1273,30 +1317,29 @@ protected function _getPIMChangeTS(array $changes) // Get the allowed synckeys to include. $uuid = self::getSyncKeyUid($this->_syncKey); $cnt = self::getSyncKeyCounter($this->_syncKey); - $keys = array(); - foreach (array($uuid . $cnt, $uuid . ($cnt - 1)) as $v) { + $keys = []; + foreach ([$uuid . $cnt, $uuid . ($cnt - 1)] as $v) { $keys[] = $v; } - $match = array( + $match = [ self::SYNC_DEVID => $this->_deviceInfo->id, self::SYNC_USER => $this->_deviceInfo->user, - self::SYNC_KEY => array('$in' => $keys) - ); - $uids = array(); - $match['$or'] = array(); + self::SYNC_KEY => ['$in' => $keys], + ]; + $uids = []; + $match['$or'] = []; foreach ($changes as $change) { - $match['$or'][] = array( - '$and' => array( - array(self::MESSAGE_UID => $change['id']), - array(self::SYNC_DELETED => $change['type'] == Horde_ActiveSync::CHANGE_TYPE_DELETE) - ) - ); + $match['$or'][] = [ + '$and' => [ + [self::MESSAGE_UID => $change['id']], + [self::SYNC_DELETED => $change['type'] == Horde_ActiveSync::CHANGE_TYPE_DELETE], + ], + ]; } try { $rows = $this->_db->selectCollection(self::COLLECTION_MAP)->aggregate( - array('$match' => $match), - array('$group' => array(self::MONGO_ID => '$message_uid', 'max' => array('$max' => '$sync_modtime'))) - + ['$match' => $match], + ['$group' => [self::MONGO_ID => '$message_uid', 'max' => ['$max' => '$sync_modtime']]] ); } catch (Exception $e) { $this->_logger->err($e->getMessage()); @@ -1305,9 +1348,10 @@ protected function _getPIMChangeTS(array $changes) if (empty($rows) || empty($rows['ok'])) { throw new Horde_ActiveSync_Exception(sprintf( 'Error running aggregation: %s', - empty($rows['errmsg']) ? '' : $rows['errmsg'])); + empty($rows['errmsg']) ? '' : $rows['errmsg'] + )); } - $results = array(); + $results = []; foreach ($rows['result'] as $row) { $results[$row[self::MONGO_ID]] = $row['max']; } @@ -1332,19 +1376,21 @@ protected function _havePIMChanges() return true; } - $this->_logger->meta(sprintf( - 'Horde_ActiveSync_State_Mongo::_havePIMChanges() for %s', - $this->_collection['serverid']) + $this->_logger->meta( + sprintf( + 'Horde_ActiveSync_State_Mongo::_havePIMChanges() for %s', + $this->_collection['serverid'] + ) ); $c = $this->_db->selectCollection(self::COLLECTION_MAP); - $query = array( + $query = [ self::SYNC_DEVID => $this->_deviceInfo->id, self::SYNC_USER => $this->_deviceInfo->user, - self::SYNC_FOLDERID => $this->_collection['serverid'] - ); + self::SYNC_FOLDERID => $this->_collection['serverid'], + ]; try { - return (bool)$c->find($query, array(self::MONGO_ID => true)) + return (bool) $c->find($query, [self::MONGO_ID => true]) ->count(); } catch (Exception $e) { $this->_logger->err($e->getMessage()); @@ -1365,43 +1411,43 @@ protected function _havePIMChanges() */ protected function _getMailMapChanges(array $changes) { - $ids = array(); + $ids = []; foreach ($changes as $change) { $ids[] = strval($change['id']); } - $query = array( + $query = [ self::SYNC_FOLDERID => $this->_collection['serverid'], self::SYNC_DEVID => $this->_deviceInfo->id, self::SYNC_USER => $this->_deviceInfo->user, - self::MESSAGE_UID => array('$in' => $ids) - ); + self::MESSAGE_UID => ['$in' => $ids], + ]; $rows = $this->_db->selectCollection(self::COLLECTION_MAILMAP)->find( $query, - array( + [ self::MESSAGE_UID => true, self::SYNC_READ => true, self::SYNC_FLAGGED => true, self::SYNC_DELETED => true, - self::SYNC_CHANGED - ) + self::SYNC_CHANGED, + ] ); - $results = array(); + $results = []; foreach ($rows as $row) { foreach ($changes as $change) { if ($change['id'] == $row[self::MESSAGE_UID]) { switch ($change['type']) { - case Horde_ActiveSync::CHANGE_TYPE_FLAGS: - $results[$row[self::MESSAGE_UID]][$change['type']] = - (!is_null($row[self::SYNC_READ]) && $row[self::SYNC_READ] == $change['flags']['read']) || - (!is_null($row[self::SYNC_FLAGGED] && $row[self::SYNC_FLAGGED] == $change['flags']['flagged'])); - continue 3; - case Horde_ActiveSync::CHANGE_TYPE_DELETE: - $results[$row[self::MESSAGE_UID]][$change['type']] = - !is_null($row[self::SYNC_DELETED]) && $row[self::SYNC_DELETED] == true; - continue 3; - case Horde_ActiveSync::CHANGE_TYPE_CHANGE: - $results[$row[self::MESSAGE_UID]][$change['type']] = - !is_null($row[self::SYNC_CHANGED]) && $row[self::SYNC_CHANGED] == true; + case Horde_ActiveSync::CHANGE_TYPE_FLAGS: + $results[$row[self::MESSAGE_UID]][$change['type']] + = (!is_null($row[self::SYNC_READ]) && $row[self::SYNC_READ] == $change['flags']['read']) + || (!is_null($row[self::SYNC_FLAGGED] && $row[self::SYNC_FLAGGED] == $change['flags']['flagged'])); + continue 3; + case Horde_ActiveSync::CHANGE_TYPE_DELETE: + $results[$row[self::MESSAGE_UID]][$change['type']] + = !is_null($row[self::SYNC_DELETED]) && $row[self::SYNC_DELETED] == true; + continue 3; + case Horde_ActiveSync::CHANGE_TYPE_CHANGE: + $results[$row[self::MESSAGE_UID]][$change['type']] + = !is_null($row[self::SYNC_CHANGED]) && $row[self::SYNC_CHANGED] == true; } } } @@ -1429,25 +1475,25 @@ protected function _gc($syncKey) // ensures that we can still respond to SYNC requests for the previous // key if the client never received the new key in a SYNC response. $js = << $this->_deviceInfo->id, self::SYNC_FOLDERID => !empty($this->_collection['id']) ? $this->_collection['id'] : Horde_ActiveSync::CHANGE_TYPE_FOLDERSYNC, - '$where' => $js - ); + '$where' => $js, + ]; try { $this->_db->selectCollection(self::COLLECTION_STATE)->remove($query); @@ -1460,22 +1506,22 @@ function() { // SYNC cycle. Keep the same number of old keys for the same reasons as // above. $js = <<_db->selectCollection(self::COLLECTION_MAP), $this->_db->selectCollection(self::COLLECTION_MAILMAP)) as $c) { - $query = array( + return false; + } + EOT; + foreach ([$this->_db->selectCollection(self::COLLECTION_MAP), $this->_db->selectCollection(self::COLLECTION_MAILMAP)] as $c) { + $query = [ self::SYNC_DEVID => $this->_deviceInfo->id, self::SYNC_USER => $this->_deviceInfo->user, - '$where' => $js - ); + '$where' => $js, + ]; try { $c->remove($query); } catch (Exception $e) { @@ -1508,19 +1554,15 @@ public function createMongoIndices() } } - /** - * Close the underlying backend storage connection. - * To be used during PING or looping SYNC operations. - */ - public function disconnect() - { - } - - /** - * (Re)open backend storage connection. - */ - public function connect() - { - } + /** + * Close the underlying backend storage connection. + * To be used during PING or looping SYNC operations. + */ + public function disconnect() {} + + /** + * (Re)open backend storage connection. + */ + public function connect() {} } diff --git a/lib/Horde/ActiveSync/State/Sql.php b/lib/Horde/ActiveSync/State/Sql.php index 1c6f1806..bef84ed5 100644 --- a/lib/Horde/ActiveSync/State/Sql.php +++ b/lib/Horde/ActiveSync/State/Sql.php @@ -1,9 +1,8 @@ _params['db']) || !($this->_params['db'] instanceof Horde_Db_Adapter)) { @@ -158,17 +157,21 @@ public function __construct(array $params = array()) */ public function updateServerIdInState($uid, $serverid) { - $this->_logger->meta(sprintf( - 'STATE: Updating serverid in folder state. Setting %s for %s.', - $serverid, - $uid) + $this->_logger->meta( + sprintf( + 'STATE: Updating serverid in folder state. Setting %s for %s.', + $serverid, + $uid + ) ); $sql = 'SELECT sync_key, sync_data FROM ' . $this->_syncStateTable . ' WHERE ' . 'sync_devid = ? AND sync_user = ? AND sync_folderid = ?'; try { - $results = $this->_db->select($sql, - array($this->_deviceInfo->id, $this->_deviceInfo->user, $uid)); + $results = $this->_db->select( + $sql, + [$this->_deviceInfo->id, $this->_deviceInfo->user, $uid] + ); } catch (Horde_Db_Exception $e) { $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); @@ -190,14 +193,15 @@ public function updateServerIdInState($uid, $serverid) $folder->setServerId($serverid); $folder = serialize($folder); try { - $this->_db->update($update, - array( + $this->_db->update( + $update, + [ new Horde_Db_Value_Binary($folder), $this->_deviceInfo->id, $this->_deviceInfo->user, $uid, - $result['sync_key'] - ) + $result['sync_key'], + ] ); } catch (Horde_Db_Exception $e) { $this->_logger->err($e->getMessage()); @@ -216,7 +220,7 @@ protected function _loadState() // Load the previous syncState from storage $sql = 'SELECT sync_data, sync_devid, sync_mod, sync_pending FROM ' . $this->_syncStateTable . ' WHERE sync_key = ?'; - $values = array($this->_syncKey); + $values = [$this->_syncKey]; if (!empty($this->_collection['id'])) { $sql .= ' AND sync_folderid = ?'; $values[] = $this->_collection['id']; @@ -229,9 +233,11 @@ protected function _loadState() } if (empty($results)) { - $this->_logger->warn(sprintf( - 'STATE: Could not find state for synckey %s.', - $this->_syncKey) + $this->_logger->warn( + sprintf( + 'STATE: Could not find state for synckey %s.', + $this->_syncKey + ) ); throw new Horde_ActiveSync_Exception_StateGone(); } @@ -266,15 +272,18 @@ protected function _loadStateFromResults($results) $pending = unserialize($results['sync_pending']); if ($this->_type == Horde_ActiveSync::REQUEST_TYPE_FOLDERSYNC) { - $this->_folder = ($data !== false) ? $data : array(); - $this->_logger->meta(sprintf( - 'STATE: Loading FOLDERSYNC state containing %d folders.', - count($this->_folder)) + $this->_folder = ($data !== false) ? $data : []; + $this->_logger->meta( + sprintf( + 'STATE: Loading FOLDERSYNC state containing %d folders.', + count($this->_folder) + ) ); } elseif ($this->_type == Horde_ActiveSync::REQUEST_TYPE_SYNC) { // @TODO: This shouldn't default to an empty folder object, // if we don't have the data, it's an exception. - $this->_folder = ($data !== false + $this->_folder = ( + $data !== false ? $data : ($this->_collection['class'] == Horde_ActiveSync::CLASS_EMAIL ? new Horde_ActiveSync_Folder_Imap($this->_collection['serverid'], Horde_ActiveSync::CLASS_EMAIL) @@ -282,9 +291,11 @@ protected function _loadStateFromResults($results) ); $this->_changes = ($pending !== false) ? $pending : null; if ($this->_changes) { - $this->_logger->meta(sprintf( - 'STATE: Found %d changes remaining from previous SYNC.', - count($this->_changes)) + $this->_logger->meta( + sprintf( + 'STATE: Found %d changes remaining from previous SYNC.', + count($this->_changes) + ) ); } } @@ -301,23 +312,25 @@ protected function _loadStateFromResults($results) public function updateSyncStamp() { if (($this->_thisSyncStamp - $this->_lastSyncStamp) >= self::SYNCSTAMP_UPDATE_THRESHOLD) { - $this->_logger->meta(sprintf( - 'STATE: Updating sync_mod value from %s to %s without changes.', - $this->_lastSyncStamp, - $this->_thisSyncStamp) + $this->_logger->meta( + sprintf( + 'STATE: Updating sync_mod value from %s to %s without changes.', + $this->_lastSyncStamp, + $this->_thisSyncStamp + ) ); $sql = 'UPDATE ' . $this->_syncStateTable . ' SET sync_mod = ?' . ' WHERE sync_mod = ? AND sync_key = ? AND sync_user = ? AND sync_folderid = ?'; try { $this->_db->update( $sql, - array( + [ $this->_thisSyncStamp, $this->_lastSyncStamp, $this->_syncKey, $this->_deviceInfo->user, - $this->_collection['id'] - ) + $this->_collection['id'], + ] ); } catch (Horde_Db_Exception $e) { throw new Horde_ActiveSync_Exception($e); @@ -346,7 +359,7 @@ public function save() // If we are setting the first synckey iteration, do not save the // syncstamp/mod, otherwise we will never get the initial set of data. - $params = array( + $params = [ 'sync_key' => $this->_syncKey, 'sync_data' => new Horde_Db_Value_Binary($data), 'sync_devid' => $this->_deviceInfo->id, @@ -354,11 +367,12 @@ public function save() 'sync_folderid' => (!empty($this->_collection['id']) ? $this->_collection['id'] : Horde_ActiveSync::REQUEST_TYPE_FOLDERSYNC), 'sync_user' => $this->_deviceInfo->user, 'sync_pending' => $pending, - 'sync_timestamp' => time() - ); + 'sync_timestamp' => time(), + ]; $this->_logger->meta( - sprintf('STATE: Saving state: %s', - serialize(array( + sprintf( + 'STATE: Saving state: %s', + serialize([ $params['sync_key'], $params['sync_data'], $params['sync_devid'], @@ -366,26 +380,31 @@ public function save() $params['sync_folderid'], $params['sync_user'], $this->_changes ? count($this->_changes) : 0, - time())) - ) - ); + time()]) + ) + ); try { $this->_db->insertBlob($this->_syncStateTable, $params, 'sync_key', $params['sync_key']); } catch (Horde_Db_Exception $e) { // Might exist already if the last sync attempt failed. - $this->_logger->notice(sprintf( - 'STATE: Error saving state, checking if this is due to previous synckey %s not being accepted by client.', - $this->_syncKey) + $this->_logger->notice( + sprintf( + 'STATE: Error saving state, checking if this is due to previous synckey %s not being accepted by client.', + $this->_syncKey + ) ); } try { - $this->_db->delete('DELETE FROM ' . $this->_syncStateTable . ' WHERE sync_key = ?', array($this->_syncKey)); + $this->_db->delete('DELETE FROM ' . $this->_syncStateTable . ' WHERE sync_key = ?', [$this->_syncKey]); $this->_db->insertBlob($this->_syncStateTable, $params, 'sync_key', $params['sync_key']); } catch (Horde_Db_Exception $e) { - $this->_logger->err(sprintf( - 'STATE: Unrecoverable error while saving state for synckey %s: %s', - $this->_syncKey, $e->getMessage()) + $this->_logger->err( + sprintf( + 'STATE: Unrecoverable error while saving state for synckey %s: %s', + $this->_syncKey, + $e->getMessage() + ) ); throw new Horde_ActiveSync_Exception($e); } @@ -423,9 +442,12 @@ public function save() * @todo This method needs some cleanup, abstraction. */ public function updateState( - $type, array $change, $origin = Horde_ActiveSync::CHANGE_ORIGIN_NA, - $user = null, $clientid = '') - { + $type, + array $change, + $origin = Horde_ActiveSync::CHANGE_ORIGIN_NA, + $user = null, + $clientid = '' + ) { $this->_logger->meta(sprintf('STATE: Updating state during %s', $type)); if ($origin == Horde_ActiveSync::CHANGE_ORIGIN_PIM) { @@ -447,9 +469,9 @@ public function updateState( // information since there is no SYNCKEY. Attempt to map this from // the $change array. if (empty($this->_collection)) { - $this->_collection = array( + $this->_collection = [ 'class' => $change['class'], - 'id' => $change['folderuid']); + 'id' => $change['folderuid']]; } $syncKey = empty($this->_syncKey) ? $this->getLatestSynckeyForCollection($this->_collection['id']) @@ -460,80 +482,80 @@ public function updateState( // @todo: Use bitmask for the change type so we don't have to // maintain a separate field for each type. switch ($this->_collection['class']) { - case Horde_ActiveSync::CLASS_EMAIL: - if ($type == Horde_ActiveSync::CHANGE_TYPE_CHANGE && - isset($change['flags']) && is_array($change['flags']) && - !empty($change['flags'])) { - $type = Horde_ActiveSync::CHANGE_TYPE_FLAGS; - } - switch ($type) { - case Horde_ActiveSync::CHANGE_TYPE_FLAGS: - if (isset($change['flags']['read'])) { - // This is a mail sync changing only a read flag. - $sql = 'INSERT INTO ' . $this->_syncMailMapTable - . ' (message_uid, sync_key, sync_devid,' - . ' sync_folderid, sync_user, sync_read)' - . ' VALUES (?, ?, ?, ?, ?, ?)'; - $flag_value = !empty($change['flags']['read']); - } elseif (isset($change['flags']['flagged'])) { - $sql = 'INSERT INTO ' . $this->_syncMailMapTable - . ' (message_uid, sync_key, sync_devid,' - . ' sync_folderid, sync_user, sync_flagged)' - . ' VALUES (?, ?, ?, ?, ?, ?)'; - $flag_value = !empty($change['flags']['flagged']); + case Horde_ActiveSync::CLASS_EMAIL: + if ($type == Horde_ActiveSync::CHANGE_TYPE_CHANGE + && isset($change['flags']) && is_array($change['flags']) + && !empty($change['flags'])) { + $type = Horde_ActiveSync::CHANGE_TYPE_FLAGS; } - if (isset($change['categories']) && $change['categories']) { - $sql = 'INSERT INTO ' . $this->_syncMailMapTable - . ' (message_uid, sync_key, sync_devid,' - . ' sync_folderid, sync_user, sync_category)' - . ' VALUES (?, ?, ?, ?, ?, ?)'; - $flag_value = md5(implode('', $change['categories'])); + switch ($type) { + case Horde_ActiveSync::CHANGE_TYPE_FLAGS: + if (isset($change['flags']['read'])) { + // This is a mail sync changing only a read flag. + $sql = 'INSERT INTO ' . $this->_syncMailMapTable + . ' (message_uid, sync_key, sync_devid,' + . ' sync_folderid, sync_user, sync_read)' + . ' VALUES (?, ?, ?, ?, ?, ?)'; + $flag_value = !empty($change['flags']['read']); + } elseif (isset($change['flags']['flagged'])) { + $sql = 'INSERT INTO ' . $this->_syncMailMapTable + . ' (message_uid, sync_key, sync_devid,' + . ' sync_folderid, sync_user, sync_flagged)' + . ' VALUES (?, ?, ?, ?, ?, ?)'; + $flag_value = !empty($change['flags']['flagged']); + } + if (isset($change['categories']) && $change['categories']) { + $sql = 'INSERT INTO ' . $this->_syncMailMapTable + . ' (message_uid, sync_key, sync_devid,' + . ' sync_folderid, sync_user, sync_category)' + . ' VALUES (?, ?, ?, ?, ?, ?)'; + $flag_value = md5(implode('', $change['categories'])); + } + break; + case Horde_ActiveSync::CHANGE_TYPE_DELETE: + $sql = 'INSERT INTO ' . $this->_syncMailMapTable + . ' (message_uid, sync_key, sync_devid,' + . ' sync_folderid, sync_user, sync_deleted)' + . ' VALUES (?, ?, ?, ?, ?, ?)'; + $flag_value = true; + break; + case Horde_ActiveSync::CHANGE_TYPE_CHANGE: + // Used to remember "new" messages that are a result of + // a MOVEITEMS request. + $sql = 'INSERT INTO ' . $this->_syncMailMapTable + . ' (message_uid, sync_key, sync_devid,' + . ' sync_folderid, sync_user, sync_changed)' + . ' VALUES (?, ?, ?, ?, ?, ?)'; + $flag_value = true; + break; + case Horde_ActiveSync::CHANGE_TYPE_DRAFT: + // Incoming draft messge. + $sql = 'INSERT INTO ' . $this->_syncMailMapTable + . ' (message_uid, sync_key, sync_devid,' + . ' sync_folderid, sync_user, sync_draft)' + . ' VALUES (?, ?, ?, ?, ?, ?)'; + $flag_value = true; + break; } + $params = [$change['id'], $syncKey, $this->_deviceInfo->id, + $change['serverid'], $user, $flag_value, + ]; break; - case Horde_ActiveSync::CHANGE_TYPE_DELETE: - $sql = 'INSERT INTO ' . $this->_syncMailMapTable - . ' (message_uid, sync_key, sync_devid,' - . ' sync_folderid, sync_user, sync_deleted)' - . ' VALUES (?, ?, ?, ?, ?, ?)'; - $flag_value = true; - break; - case Horde_ActiveSync::CHANGE_TYPE_CHANGE: - // Used to remember "new" messages that are a result of - // a MOVEITEMS request. - $sql = 'INSERT INTO ' . $this->_syncMailMapTable - . ' (message_uid, sync_key, sync_devid,' - . ' sync_folderid, sync_user, sync_changed)' - . ' VALUES (?, ?, ?, ?, ?, ?)'; - $flag_value = true; - break; - case Horde_ActiveSync::CHANGE_TYPE_DRAFT: - // Incoming draft messge. - $sql = 'INSERT INTO ' . $this->_syncMailMapTable - . ' (message_uid, sync_key, sync_devid,' - . ' sync_folderid, sync_user, sync_draft)' - . ' VALUES (?, ?, ?, ?, ?, ?)'; - $flag_value = true; - break; - } - $params = array($change['id'], $syncKey, $this->_deviceInfo->id, - $change['serverid'], $user, $flag_value - ); - break; - - default: - $sql = 'INSERT INTO ' . $this->_syncMapTable - . ' (message_uid, sync_modtime, sync_key, sync_devid,' - . ' sync_folderid, sync_user, sync_clientid, sync_deleted)' - . ' VALUES (?, ?, ?, ?, ?, ?, ?, ?)'; - $params = array( - $change['id'], - $change['mod'], - $syncKey, - $this->_deviceInfo->id, - $change['serverid'], - $user, - $clientid, - $type == Horde_ActiveSync::CHANGE_TYPE_DELETE); + + default: + $sql = 'INSERT INTO ' . $this->_syncMapTable + . ' (message_uid, sync_modtime, sync_key, sync_devid,' + . ' sync_folderid, sync_user, sync_clientid, sync_deleted)' + . ' VALUES (?, ?, ?, ?, ?, ?, ?, ?)'; + $params = [ + $change['id'], + $change['mod'], + $syncKey, + $this->_deviceInfo->id, + $change['serverid'], + $user, + $clientid, + $type == Horde_ActiveSync::CHANGE_TYPE_DELETE]; } try { @@ -567,7 +589,8 @@ public function updateState( (empty($value['parent']) ? '0' : $value['parent']), $folder->displayname, $folder->_serverid, - $folder->type); + $folder->type + ); $this->_folder[] = $stat; $this->_folder = array_values($this->_folder); } @@ -593,14 +616,14 @@ public function updateState( * @return Horde_ActiveSync_Device The device object * @throws Horde_ActiveSync_Exception */ - public function loadDeviceInfo($devId, $user = null, $params = array()) + public function loadDeviceInfo($devId, $user = null, $params = []) { // See if we already have this device, for this user loaded - if (empty($params['force']) && - !empty($this->_deviceInfo) && - $this->_deviceInfo->id == $devId && - !empty($this->_deviceInfo) && - $user == $this->_deviceInfo->user) { + if (empty($params['force']) + && !empty($this->_deviceInfo) + && $this->_deviceInfo->id == $devId + && !empty($this->_deviceInfo) + && $user == $this->_deviceInfo->user) { return $this->_deviceInfo; } @@ -609,7 +632,7 @@ public function loadDeviceInfo($devId, $user = null, $params = array()) . $this->_syncDeviceTable . ' WHERE device_id = ?'; try { - if (!$device = $this->_db->selectOne($query, array($devId))) { + if (!$device = $this->_db->selectOne($query, [$devId])) { throw new Horde_ActiveSync_Exception('Device not found.'); } $columns = $this->_db->columns($this->_syncDeviceTable); @@ -625,7 +648,7 @@ public function loadDeviceInfo($devId, $user = null, $params = array()) $query = 'SELECT device_policykey FROM ' . $this->_syncUsersTable . ' WHERE device_id = ? AND device_user = ?'; try { - $duser = $this->_db->selectOne($query, array($devId, $user)); + $duser = $this->_db->selectOne($query, [$devId, $user]); } catch (Horde_Db_Exception $e) { throw new Horde_ActiveSync_Exception($e); } @@ -659,7 +682,7 @@ public function loadDeviceInfo($devId, $user = null, $params = array()) * * @throws Horde_ActiveSync_Exception */ - public function setDeviceInfo(Horde_ActiveSync_Device $data, array $dirty = array()) + public function setDeviceInfo(Horde_ActiveSync_Device $data, array $dirty = []) { // Make sure we have the device entry try { @@ -668,35 +691,37 @@ public function setDeviceInfo(Horde_ActiveSync_Device $data, array $dirty = arra $query = 'INSERT INTO ' . $this->_syncDeviceTable . ' (device_type, device_agent, device_rwstatus, device_id, device_supported)' . ' VALUES(?, ?, ?, ?, ?)'; - $values = array( + $values = [ $data->deviceType, (!empty($data->userAgent) ? $data->userAgent : ''), $data->rwstatus, $data->id, - (!empty($data->supported) ? serialize($data->supported) : '') - ); + (!empty($data->supported) ? serialize($data->supported) : ''), + ]; $this->_db->insert($query, $values); } else { - $this->_logger->meta((sprintf( - 'STATE: Device entry exists for %s, updating userAgent, version, and supported.', - $data->id)) + $this->_logger->meta( + (sprintf( + 'STATE: Device entry exists for %s, updating userAgent, version, and supported.', + $data->id + )) ); // device_supported is immutable, and only sent during the initial // sync request, so only set it if it's non-empty. $query = 'UPDATE ' . $this->_syncDeviceTable . ' SET device_agent = ?, device_properties = ?' . (!empty($data->supported) ? ', device_supported = ?' : '') . ' WHERE device_id = ?'; - $values = array( + $values = [ (!empty($data->userAgent) ? $data->userAgent : ''), - serialize($data->properties) - ); + serialize($data->properties), + ]; if (!empty($data->supported)) { $values[] = serialize($data->supported); } $values[] = $data->id; $this->_db->update($query, $values); } - } catch(Horde_Db_Exception $e) { + } catch (Horde_Db_Exception $e) { throw new Horde_ActiveSync_Exception($e); } @@ -705,22 +730,24 @@ public function setDeviceInfo(Horde_ActiveSync_Device $data, array $dirty = arra // See if we have the user already also try { $query = 'SELECT COUNT(*) FROM ' . $this->_syncUsersTable . ' WHERE device_id = ? AND device_user = ?'; - $cnt = $this->_db->selectValue($query, array($data->id, $data->user)); + $cnt = $this->_db->selectValue($query, [$data->id, $data->user]); if ($cnt == 0) { - $this->_logger->meta(sprintf( - 'STATE: Device entry does not exist for device %s and user %s - creating it.', - $data->id, - $data->user) + $this->_logger->meta( + sprintf( + 'STATE: Device entry does not exist for device %s and user %s - creating it.', + $data->id, + $data->user + ) ); $query = 'INSERT INTO ' . $this->_syncUsersTable . ' (device_id, device_user, device_policykey)' . ' VALUES(?, ?, ?)'; - $values = array( + $values = [ $data->id, $data->user, - $data->policykey - ); + $data->policykey, + ]; return $this->_db->insert($query, $values); } } catch (Horde_Db_Exception $e) { @@ -740,9 +767,9 @@ public function setDeviceProperties(array $data, $deviceId) { $query = 'UPDATE ' . $this->_syncDeviceTable . ' SET device_properties = ?' . ' WHERE device_id = ?'; - $properties = array( + $properties = [ serialize($data), - $deviceId); + $deviceId]; try { $this->_db->update($query, $properties); } catch (Horde_Db_Exception $e) { @@ -768,10 +795,10 @@ public function deviceExists($devId, $user = null) . ' d INNER JOIN ' . $this->_syncUsersTable . ' u on d.device_id = u.device_id' . ' WHERE u.device_id = ? AND device_user = ?'; - $values = array($devId, $user); + $values = [$devId, $user]; } else { $query = 'SELECT COUNT(*) FROM ' . $this->_syncDeviceTable . ' WHERE device_id = ?'; - $values = array($devId); + $values = [$devId]; } try { @@ -792,20 +819,20 @@ public function deviceExists($devId, $user = null) * @return array An array of device hashes * @throws Horde_ActiveSync_Exception */ - public function listDevices($user = null, $filter = array()) + public function listDevices($user = null, $filter = []) { $query = 'SELECT d.device_id AS device_id, device_type, device_agent,' . ' device_policykey, device_rwstatus, device_user, device_properties FROM ' . $this->_syncDeviceTable . ' d INNER JOIN ' . $this->_syncUsersTable . ' u ON d.device_id = u.device_id'; - $values = array(); + $values = []; $glue = false; if (!empty($user)) { $query .= ' WHERE u.device_user = ?'; $values[] = $user; $glue = true; } - $explicit_fields = array('device_id', 'device_type', 'device_agent', 'device_user'); + $explicit_fields = ['device_id', 'device_type', 'device_agent', 'device_user']; foreach ($filter as $key => $value) { if (in_array($key, $explicit_fields)) { $query .= ($glue ? ' AND ' : ' WHERE ') . 'd.' . $key . ' LIKE ?'; @@ -838,7 +865,7 @@ public function getLastSyncTimestamp($id = null, $user = null) } $id = empty($id) ? $this->_deviceInfo->id : $id; $user = empty($user) ? $this->_deviceInfo->user : $user; - $params = array($id); + $params = [$id]; $sql = 'SELECT MAX(sync_timestamp) FROM ' . $this->_syncStateTable . ' WHERE sync_devid = ?'; if (!empty($user)) { @@ -871,7 +898,7 @@ public function setPolicyKey($devId, $key) $query = 'UPDATE ' . $this->_syncUsersTable . ' SET device_policykey = ? WHERE device_id = ? AND device_user = ?'; try { - $this->_db->update($query, array($key, $devId, $this->_backend->getUser())); + $this->_db->update($query, [$key, $devId, $this->_backend->getUser()]); } catch (Horde_Db_Exception $e) { throw new Horde_ActiveSync_Exception($e); } @@ -907,7 +934,7 @@ public function setDeviceRWStatus($devId, $status) { $query = 'UPDATE ' . $this->_syncDeviceTable . ' SET device_rwstatus = ?' . ' WHERE device_id = ?'; - $values = array($status, $devId); + $values = [$status, $devId]; try { $this->_db->update($query, $values); } catch (Horde_Db_Exception $e) { @@ -920,7 +947,7 @@ public function setDeviceRWStatus($devId, $status) $query = 'UPDATE ' . $this->_syncUsersTable . ' SET device_policykey = 0 WHERE device_id = ?'; try { - $this->_db->update($query, array($devId)); + $this->_db->update($query, [$devId]); } catch (Horde_Db_Exception $e) { throw new Horde_ActiveSync_Exception($e); } @@ -956,10 +983,10 @@ public function removeState(array $options) . ' WHERE device_id = ?'; try { - $results = $this->_db->selectValue($q, array($options['devId'])); - if ($results != Horde_ActiveSync::RWSTATUS_NA && - $results != Horde_ActiveSync::RWSTATUS_OK) { - return $this->removeState(array('devId' => $options['devId'])); + $results = $this->_db->selectValue($q, [$options['devId']]); + if ($results != Horde_ActiveSync::RWSTATUS_NA + && $results != Horde_ActiveSync::RWSTATUS_OK) { + return $this->removeState(['devId' => $options['devId']]); } } catch (Horde_Db_Exception $e) { throw new Horde_ActiveSync_Exception($e); @@ -969,24 +996,28 @@ public function removeState(array $options) $map_query .= ' sync_devid = ? AND sync_user = ?'; $user_query = 'DELETE FROM ' . $this->_syncUsersTable . ' WHERE device_id = ? AND device_user = ?'; - $state_values = $values = array($options['devId'], $options['user']); + $state_values = $values = [$options['devId'], $options['user']]; if (!empty($options['id'])) { $state_query .= ' AND sync_folderid = ?'; $map_query .= ' AND sync_folderid = ?'; $state_values[] = $options['id']; - $this->_logger->meta(sprintf( - 'STATE: Removing device %s state for user %s and collection %s.', - $options['devId'], - $options['user'], - $options['id']) + $this->_logger->meta( + sprintf( + 'STATE: Removing device %s state for user %s and collection %s.', + $options['devId'], + $options['user'], + $options['id'] + ) ); } else { - $this->_logger->meta(sprintf( - 'STATE: Removing device %s state for user %s.', - $options['devId'], - $options['user']) + $this->_logger->meta( + sprintf( + 'STATE: Removing device %s state for user %s.', + $options['devId'], + $options['user'] + ) ); $this->deleteSyncCache($options['devId'], $options['user']); } @@ -997,10 +1028,12 @@ public function removeState(array $options) . ' WHERE device_id = ?'; $device_query = 'DELETE FROM ' . $this->_syncDeviceTable . ' WHERE device_id = ?'; - $state_values = $values = array($options['devId']); - $this->_logger->meta(sprintf( - 'STATE: Removing all device state for device %s.', - $options['devId']) + $state_values = $values = [$options['devId']]; + $this->_logger->meta( + sprintf( + 'STATE: Removing all device state for device %s.', + $options['devId'] + ) ); $this->deleteSyncCache($options['devId']); } elseif (!empty($options['user'])) { @@ -1008,19 +1041,23 @@ public function removeState(array $options) $map_query .= ' sync_user = ?'; $user_query = 'DELETE FROM ' . $this->_syncUsersTable . ' WHERE device_user = ?'; - $state_values = $values = array($options['user']); - $this->_logger->meta(sprintf( - 'STATE: Removing all device state for user %s.', - $options['user']) + $state_values = $values = [$options['user']]; + $this->_logger->meta( + sprintf( + 'STATE: Removing all device state for user %s.', + $options['user'] + ) ); $this->deleteSyncCache(null, $options['user']); } elseif (!empty($options['synckey'])) { $state_query .= ' sync_key = ?'; $map_query .= ' sync_key = ?'; - $state_values = $values = array($options['synckey']); - $this->_logger->meta(sprintf( - 'STATE: Removing device state for sync_key %s only.', - $options['synckey']) + $state_values = $values = [$options['synckey']]; + $this->_logger->meta( + sprintf( + 'STATE: Removing device state for sync_key %s only.', + $options['synckey'] + ) ); } else { return; @@ -1030,10 +1067,12 @@ public function removeState(array $options) $this->_db->delete($state_query, $state_values); $this->_db->delete( str_replace('%TABLE%', $this->_syncMapTable, $map_query), - $state_values); + $state_values + ); $this->_db->delete( str_replace('%TABLE%', $this->_syncMailMapTable, $map_query), - $state_values); + $state_values + ); if (!empty($user_query)) { $this->_db->delete($user_query, $values); @@ -1049,7 +1088,8 @@ public function removeState(array $options) foreach ($devids as $id) { $this->_db->delete( 'DELETE FROM horde_activesync_device WHERE device_id = ?', - array($id)); + [$id] + ); } } catch (Horde_Db_Exception $e) { throw new Horde_ActiveSync_Exception($e->getMessage()); @@ -1070,39 +1110,39 @@ public function removeState(array $options) * @return string The UID for the given clientid, null if none found. * @throws Horde_ActiveSync_Exception */ - public function isDuplicatePIMAddition($id) - { + public function isDuplicatePIMAddition($id) + { $sql = 'SELECT message_uid FROM ' . $this->_syncMapTable . ' WHERE sync_clientid = ? AND sync_user = ?'; try { - $uid = $this->_db->selectValue($sql, array($id, $this->_deviceInfo->user)); + $uid = $this->_db->selectValue($sql, [$id, $this->_deviceInfo->user]); return $uid; } catch (Horde_Db_Exception $e) { throw new Horde_ActiveSync_Exception($e); } - } - - /** - * Check if the UID provided was altered during the SYNC_KEY provided. - * - * @param string $uid The UID to check. - * @param string $synckey The synckey to check. - * - * @return boolean True if the provided UID was updated during the - * SYNC for the synckey provided. - * @since 2.31.0 - */ - public function isDuplicatePIMChange($uid, $synckey) - { + } + + /** + * Check if the UID provided was altered during the SYNC_KEY provided. + * + * @param string $uid The UID to check. + * @param string $synckey The synckey to check. + * + * @return boolean True if the provided UID was updated during the + * SYNC for the synckey provided. + * @since 2.31.0 + */ + public function isDuplicatePIMChange($uid, $synckey) + { $sql = 'SELECT count(*) FROM ' . $this->_syncMapTable . ' WHERE message_uid = ? AND sync_user = ? AND sync_key = ?'; try { - return $this->_db->selectValue($sql, array($uid, $this->_deviceInfo->user, $synckey)); + return $this->_db->selectValue($sql, [$uid, $this->_deviceInfo->user, $synckey]); } catch (Horde_Db_Exception $e) { throw new Horde_ActiveSync_Exception($e); } - } + } /** * Return the sync cache. * @@ -1114,30 +1154,30 @@ public function isDuplicatePIMChange($uid, $synckey) * @return array The current sync cache for the user/device combination. * @throws Horde_ActiveSync_Exception */ - public function getSyncCache($devid, $user, array $fields = null) + public function getSyncCache($devid, $user, ?array $fields = null) { $sql = 'SELECT cache_data FROM ' . $this->_syncCacheTable . ' WHERE cache_devid = ? AND cache_user = ?'; try { - $data = $this->_db->selectValue($sql, array($devid, $user)); + $data = $this->_db->selectValue($sql, [$devid, $user]); $columns = $this->_db->columns($this->_syncCacheTable); $data = $columns['cache_data']->binaryToString($data); } catch (Horde_Db_Exception $e) { throw new Horde_ActiveSync_Exception($e); } if (!$data = unserialize($data)) { - $data = array( - 'confirmed_synckeys' => array(), + $data = [ + 'confirmed_synckeys' => [], 'lasthbsyncstarted' => false, 'lastsyncendnormal' => false, 'timestamp' => false, 'wait' => false, 'hbinterval' => false, - 'folders' => array(), + 'folders' => [], 'hierarchy' => false, - 'collections' => array(), + 'collections' => [], 'pingheartbeat' => false, - 'synckeycounter' => array()); + 'synckeycounter' => []]; } if (!is_null($fields)) { $data = array_intersect_key($data, array_flip($fields)); @@ -1156,45 +1196,53 @@ public function getSyncCache($devid, $user, array $fields = null) * * @throws Horde_ActiveSync_Exception */ - public function saveSyncCache(array $cache, $devid, $user, array $dirty = array()) + public function saveSyncCache(array $cache, $devid, $user, array $dirty = []) { $cache['timestamp'] = strval($cache['timestamp']); $sql = 'SELECT count(*) FROM ' . $this->_syncCacheTable . ' WHERE cache_devid = ? AND cache_user = ?'; try { - $have = $this->_db->selectValue($sql, array($devid, $user)); + $have = $this->_db->selectValue($sql, [$devid, $user]); } catch (Horde_Db_Exception $e) { $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); } $cache = serialize($cache); if ($have) { - $this->_logger->meta(sprintf( - 'STATE: Replacing SYNC_CACHE entry for user %s and device %s: %s', - $user, $devid, $cache) + $this->_logger->meta( + sprintf( + 'STATE: Replacing SYNC_CACHE entry for user %s and device %s: %s', + $user, + $devid, + $cache + ) ); $sql = 'UPDATE ' . $this->_syncCacheTable . ' SET cache_data = ? WHERE cache_devid = ? AND cache_user = ?'; try { $this->_db->update( $sql, - array($cache, $devid, $user) + [$cache, $devid, $user] ); } catch (Horde_Db_Exception $e) { $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); } } else { - $this->_logger->meta(sprintf( - 'STATE: Adding new SYNC_CACHE entry for user %s and device %s: %s', - $user, $devid, $cache) + $this->_logger->meta( + sprintf( + 'STATE: Adding new SYNC_CACHE entry for user %s and device %s: %s', + $user, + $devid, + $cache + ) ); $sql = 'INSERT INTO ' . $this->_syncCacheTable . ' (cache_data, cache_devid, cache_user) VALUES (?, ?, ?)'; try { $this->_db->insert( $sql, - array($cache, $devid, $user) + [$cache, $devid, $user] ); } catch (Horde_Db_Exception $e) { $this->_logger->err($e->getMessage()); @@ -1213,14 +1261,17 @@ public function saveSyncCache(array $cache, $devid, $user, array $dirty = array( */ public function deleteSyncCache($devid, $user = null) { - $this->_logger->meta(sprintf( - 'Horde_ActiveSync_State_Sql::deleteSyncCache(%s, %s)', - $devid, $user) + $this->_logger->meta( + sprintf( + 'Horde_ActiveSync_State_Sql::deleteSyncCache(%s, %s)', + $devid, + $user + ) ); $sql = 'DELETE FROM ' . $this->_syncCacheTable . ' WHERE '; - $params = array(); + $params = []; if (!empty($devid)) { $sql .= 'cache_devid = ? '; $params[] = $devid; @@ -1262,15 +1313,15 @@ protected function _getPIMChangeTS(array $changes) // Get the allowed synckeys to include. $uuid = self::getSyncKeyUid($this->_syncKey); $cnt = self::getSyncKeyCounter($this->_syncKey); - $values = array($this->_deviceInfo->id, + $values = [$this->_deviceInfo->id, $this->_deviceInfo->user, - $this->_collection['serverid'] - ); - foreach (array($this->_syncKey, $uuid . ($cnt - 1)) as $v) { + $this->_collection['serverid'], + ]; + foreach ([$this->_syncKey, $uuid . ($cnt - 1)] as $v) { $values[] = $v; } - $conditions = array(); + $conditions = []; foreach ($changes as $change) { $d = $change['type'] == Horde_ActiveSync::CHANGE_TYPE_DELETE; $conditions[] = '(message_uid = ?' . ($d ? ' AND sync_deleted = ?) ' : ') '); @@ -1308,8 +1359,10 @@ protected function _havePIMChanges() $sql = 'SELECT COUNT(*) FROM ' . $this->_syncMapTable . ' WHERE sync_devid = ? AND sync_user = ? AND sync_folderid = ?'; try { - return (bool)$this->_db->selectValue( - $sql, array($this->_deviceInfo->id, $this->_deviceInfo->user, $this->_collection['serverid'])); + return (bool) $this->_db->selectValue( + $sql, + [$this->_deviceInfo->id, $this->_deviceInfo->user, $this->_collection['serverid']] + ); } catch (Horde_Db_Exception $e) { throw new Horde_ActiveSync_Exception($e); } @@ -1336,45 +1389,46 @@ protected function _getMailMapChanges(array $changes) . ' AND sync_user = ? AND message_uid IN ' . '(' . implode(',', array_fill(0, count($changes), '?')) . ')'; - $ids = array(); + $ids = []; foreach ($changes as $change) { $ids[] = $change['id']; } $values = array_merge( - array($this->_collection['serverid'], - $this->_deviceInfo->id, - $this->_deviceInfo->user), - $ids); + [$this->_collection['serverid'], + $this->_deviceInfo->id, + $this->_deviceInfo->user], + $ids + ); try { $rows = $this->_db->select($sql, $values); } catch (Horde_Db_Exception $e) { throw new Horde_ActiveSync_Exception($e); } - $results = array(); + $results = []; foreach ($rows as $row) { foreach ($changes as $change) { if ($change['id'] == $row['message_uid']) { switch ($change['type']) { - case Horde_ActiveSync::CHANGE_TYPE_FLAGS: - $results[$row['message_uid']][$change['type']] = - (!is_null($row['sync_read']) && $row['sync_read'] == $change['flags']['read']) || - (!is_null($row['sync_flagged']) && $row['sync_flagged'] == $change['flags']['flagged']) || - (!is_null($row['sync_category']) && !empty($change['categories']) && $row['sync_category'] == md5(implode('', $change['categories']))); - continue 3; - case Horde_ActiveSync::CHANGE_TYPE_DELETE: - $results[$row['message_uid']][$change['type']] = - !is_null($row['sync_deleted']) && $row['sync_deleted'] == true; - continue 3; - case Horde_ActiveSync::CHANGE_TYPE_CHANGE: - $results[$row['message_uid']][$change['type']] = - !is_null($row['sync_changed']) && $row['sync_changed'] == true; - continue 3; - case Horde_ActiveSync::CHANGE_TYPE_DRAFT: - $results[$row['message_uid']][$change['type']] = - !is_null($row['sync_draft']) && $row['sync_draft'] == true; - continue 3; + case Horde_ActiveSync::CHANGE_TYPE_FLAGS: + $results[$row['message_uid']][$change['type']] + = (!is_null($row['sync_read']) && $row['sync_read'] == $change['flags']['read']) + || (!is_null($row['sync_flagged']) && $row['sync_flagged'] == $change['flags']['flagged']) + || (!is_null($row['sync_category']) && !empty($change['categories']) && $row['sync_category'] == md5(implode('', $change['categories']))); + continue 3; + case Horde_ActiveSync::CHANGE_TYPE_DELETE: + $results[$row['message_uid']][$change['type']] + = !is_null($row['sync_deleted']) && $row['sync_deleted'] == true; + continue 3; + case Horde_ActiveSync::CHANGE_TYPE_CHANGE: + $results[$row['message_uid']][$change['type']] + = !is_null($row['sync_changed']) && $row['sync_changed'] == true; + continue 3; + case Horde_ActiveSync::CHANGE_TYPE_DRAFT: + $results[$row['message_uid']][$change['type']] + = !is_null($row['sync_draft']) && $row['sync_draft'] == true; + continue 3; } } } @@ -1395,10 +1449,10 @@ protected function _checkCollision($guid) { $sql = 'SELECT COUNT(sync_key) FROM ' . $this->_syncStateTable . ' WHERE sync_devid = ? AND sync_folderid != ? AND sync_key LIKE ?'; - $values = array($this->_deviceInfo->id, $this->_collection['id'], '{' . $guid . '}%'); + $values = [$this->_deviceInfo->id, $this->_collection['id'], '{' . $guid . '}%']; try { - return (boolean)$this->_db->selectValue($sql, $values); + return (bool) $this->_db->selectValue($sql, $values); } catch (Horde_Db_Exception $e) { $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); @@ -1425,12 +1479,12 @@ protected function _gc($syncKey) // key if the client never received the new key in a SYNC response. $sql = 'SELECT sync_key FROM ' . $this->_syncStateTable . ' WHERE sync_devid = ? AND sync_folderid = ? AND sync_user = ?'; - $values = array( + $values = [ $this->_deviceInfo->id, !empty($this->_collection['id']) ? $this->_collection['id'] : Horde_ActiveSync::CHANGE_TYPE_FOLDERSYNC, - $this->_deviceInfo->user); + $this->_deviceInfo->user]; try { $results = $this->_db->select($sql, $values); @@ -1438,8 +1492,8 @@ protected function _gc($syncKey) $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); } - $remove = array(); - $guids = array($guid); + $remove = []; + $guids = [$guid]; foreach ($results as $oldkey) { if (preg_match('/^\{([0-9A-Za-z-]+)\}([0-9]+)$/', $oldkey['sync_key'], $matches)) { if ($matches[1] == $guid && $matches[2] < ($n - 1)) { @@ -1466,15 +1520,15 @@ protected function _gc($syncKey) // Also clean up the map table since this data is only needed for one // SYNC cycle. Keep the same number of old keys for the same reasons as // above. - foreach (array($this->_syncMapTable, $this->_syncMailMapTable) as $table) { - $remove = array(); + foreach ([$this->_syncMapTable, $this->_syncMailMapTable] as $table) { + $remove = []; $sql = 'SELECT DISTINCT sync_key FROM ' . $table . ' WHERE sync_devid = ? AND sync_user = ?'; try { $maps = $this->_db->selectValues( $sql, - array($this->_deviceInfo->id, $this->_deviceInfo->user) + [$this->_deviceInfo->id, $this->_deviceInfo->user] ); } catch (Horde_Db_Exception $e) { $this->_logger->err($e->getMessage()); @@ -1511,19 +1565,21 @@ protected function _gc($syncKey) */ protected function _resetDeviceState($id) { - $this->_logger->meta(sprintf( - 'STATE: Resetting device state for device: %s, user: %s, and collection: %s.', - $this->_deviceInfo->id, - $this->_deviceInfo->user, - $id) + $this->_logger->meta( + sprintf( + 'STATE: Resetting device state for device: %s, user: %s, and collection: %s.', + $this->_deviceInfo->id, + $this->_deviceInfo->user, + $id + ) ); $state_query = 'DELETE FROM ' . $this->_syncStateTable . ' WHERE sync_devid = ? AND sync_folderid = ? AND sync_user = ?'; $map_query = 'DELETE FROM ' . $this->_syncMapTable . ' WHERE sync_devid = ? AND sync_folderid = ? AND sync_user = ?'; $mailmap_query = 'DELETE FROM ' . $this->_syncMailMapTable . ' WHERE sync_devid = ? AND sync_folderid = ? AND sync_user = ?'; try { - $this->_db->delete($state_query, array($this->_deviceInfo->id, $id, $this->_deviceInfo->user)); - $this->_db->delete($map_query, array($this->_deviceInfo->id, $id, $this->_deviceInfo->user)); - $this->_db->delete($mailmap_query, array($this->_deviceInfo->id, $id, $this->_deviceInfo->user)); + $this->_db->delete($state_query, [$this->_deviceInfo->id, $id, $this->_deviceInfo->user]); + $this->_db->delete($map_query, [$this->_deviceInfo->id, $id, $this->_deviceInfo->user]); + $this->_db->delete($mailmap_query, [$this->_deviceInfo->id, $id, $this->_deviceInfo->user]); } catch (Horde_Db_Exception $e) { throw new Horde_ActiveSync_Exception($e); } @@ -1541,21 +1597,21 @@ protected function _resetDeviceState($id) $cache->save(); } - /** - * Close the underlying backend storage connection. - * To be used during PING or looping SYNC operations. - */ - public function disconnect() - { + /** + * Close the underlying backend storage connection. + * To be used during PING or looping SYNC operations. + */ + public function disconnect() + { $this->_db->disconnect(); - } + } - /** - * (Re)open backend storage connection. - */ - public function connect() - { + /** + * (Re)open backend storage connection. + */ + public function connect() + { $this->_db->connect(); - } + } } diff --git a/lib/Horde/ActiveSync/Status.php b/lib/Horde/ActiveSync/Status.php index d432eca2..a93f9065 100644 --- a/lib/Horde/ActiveSync/Status.php +++ b/lib/Horde/ActiveSync/Status.php @@ -1,4 +1,5 @@ _state = $state; $this->_devid = $devid; $this->_user = $user; @@ -157,9 +158,9 @@ public function __isset($property) protected function _isValidProperty($property) { - return in_array($property, array( + return in_array($property, [ 'hbinterval', 'wait', 'hierarchy', 'confirmed_synckeys', 'timestamp', - 'lasthbsyncstarted', 'lastsyncendnormal', 'folders', 'pingheartbeat')); + 'lasthbsyncstarted', 'lastsyncendnormal', 'folders', 'pingheartbeat']); } /** @@ -176,10 +177,11 @@ public function validateCache($hb_only = false) $cache = $this->_state->getSyncCache( $this->_devid, $this->_user, - array('lasthbsyncstarted', 'timestamp')); + ['lasthbsyncstarted', 'timestamp'] + ); - if ((!$hb_only && $cache['timestamp'] > $this->_data['timestamp']) || - (!empty($cache['lasthbsyncstarted']) && $cache['lasthbsyncstarted'] > $this->_data['lasthbsyncstarted'])) { + if ((!$hb_only && $cache['timestamp'] > $this->_data['timestamp']) + || (!empty($cache['lasthbsyncstarted']) && $cache['lasthbsyncstarted'] > $this->_data['lasthbsyncstarted'])) { return false; } @@ -192,7 +194,7 @@ public function validateCache($hb_only = false) public function loadCacheFromStorage() { $this->_data = $this->_state->getSyncCache($this->_devid, $this->_user); - $this->_dirty = array(); + $this->_dirty = []; } /** @@ -205,9 +207,9 @@ public function loadCacheFromStorage() */ public function validateTimestamps() { - if ((!empty($this->_data['lasthbsyncstarted']) && empty($this->_data['lastsyncendnormal'])) || - (!empty($this->_data['lasthbsyncstarted']) && !empty($this->_data['lastsyncendnormal']) && - ($this->_data['lasthbsyncstarted'] > $this->_data['lastsyncendnormal']))) { + if ((!empty($this->_data['lasthbsyncstarted']) && empty($this->_data['lastsyncendnormal'])) + || (!empty($this->_data['lasthbsyncstarted']) && !empty($this->_data['lastsyncendnormal']) + && ($this->_data['lasthbsyncstarted'] > $this->_data['lastsyncendnormal']))) { return false; } @@ -234,7 +236,7 @@ public function updateTimestamp() */ public function getCollections($requireKey = true) { - $collections = array(); + $collections = []; foreach ($this->_data['collections'] as $key => $collection) { if (!$requireKey || ($requireKey && !empty($collection['lastsynckey']))) { $collection['id'] = $key; @@ -265,7 +267,7 @@ public function countCollections() public function clearCollections() { $this->_logger->meta('Clearing collections data from cache.'); - $this->_data['collections'] = array(); + $this->_data['collections'] = []; $this->_dirty['collections'] = true; } @@ -303,9 +305,11 @@ public function setPingableCollection($id) public function removePingableCollection($id) { if (empty($this->_data['collections'][$id])) { - $this->_logger->warn(sprintf( - 'Collection %s was asked to be removed from PINGABLE but does not exist.', - $id) + $this->_logger->warn( + sprintf( + 'Collection %s was asked to be removed from PINGABLE but does not exist.', + $id + ) ); return; } @@ -322,8 +326,8 @@ public function removePingableCollection($id) */ public function collectionIsPingable($id) { - return !empty($this->_data['collections'][$id]) && - !empty($this->_data['collections'][$id]['pingable']); + return !empty($this->_data['collections'][$id]) + && !empty($this->_data['collections'][$id]['pingable']); } /** @@ -379,9 +383,9 @@ public function refreshCollections() $syncCache = $this->_state->getSyncCache( $this->_devid, $this->_user, - array('collections') + ['collections'] ); - $cache_collections = !is_array($syncCache['collections']) ? array() : $syncCache['collections']; + $cache_collections = !is_array($syncCache['collections']) ? [] : $syncCache['collections']; foreach ($cache_collections as $id => $cache_collection) { if (!isset($cache_collection['lastsynckey'])) { continue; @@ -412,9 +416,10 @@ public function save() $this->_data, $this->_devid, $this->_user, - $this->_dirty); + $this->_dirty + ); - $this->_dirty = array(); + $this->_dirty = []; } /** @@ -424,19 +429,19 @@ public function save() */ public function addCollection(array $collection) { - $this->_data['collections'][$collection['id']] = array( + $this->_data['collections'][$collection['id']] = [ 'class' => $collection['class'], - 'windowsize' => isset($collection['windowsize']) ? $collection['windowsize'] : null, - 'deletesasmoves' => isset($collection['deletesasmoves']) ? $collection['deletesasmoves'] : null, - 'filtertype' => isset($collection['filtertype']) ? $collection['filtertype'] : null, - 'truncation' => isset($collection['truncation']) ? $collection['truncation'] : null, - 'rtftruncation' => isset($collection['rtftruncation']) ? $collection['rtftruncation'] : null, - 'mimesupport' => isset($collection['mimesupport']) ? $collection['mimesupport'] : null, - 'mimetruncation' => isset($collection['mimetruncation']) ? $collection['mimetruncation'] : null, - 'conflict' => isset($collection['conflict']) ? $collection['conflict'] : null, - 'bodyprefs' => isset($collection['bodyprefs']) ? $collection['bodyprefs'] : null, - 'serverid' => isset($collection['serverid']) ? $collection['serverid'] : $collection['id'] - ); + 'windowsize' => $collection['windowsize'] ?? null, + 'deletesasmoves' => $collection['deletesasmoves'] ?? null, + 'filtertype' => $collection['filtertype'] ?? null, + 'truncation' => $collection['truncation'] ?? null, + 'rtftruncation' => $collection['rtftruncation'] ?? null, + 'mimesupport' => $collection['mimesupport'] ?? null, + 'mimetruncation' => $collection['mimetruncation'] ?? null, + 'conflict' => $collection['conflict'] ?? null, + 'bodyprefs' => $collection['bodyprefs'] ?? null, + 'serverid' => $collection['serverid'] ?? $collection['id'], + ]; $this->_markCollectionsDirty($collection['id']); } @@ -450,8 +455,11 @@ public function addCollection(array $collection) public function removeCollection($id, $purge = true) { if ($purge) { - $this->_logger->meta(sprintf( - 'Removing collection %s from SyncCache.', $id) + $this->_logger->meta( + sprintf( + 'Removing collection %s from SyncCache.', + $id + ) ); unset($this->_data['collections'][$id]); $this->_dirty['collections'] = true; @@ -533,10 +541,10 @@ public function removeConfirmedKey($key) * DEFUALT: false (Do not uset the PINGCHANGES flag). * @since 2.3.0 */ - public function updateCollection(array $collection, array $options = array()) + public function updateCollection(array $collection, array $options = []) { $options = array_merge( - array('newsynckey' => false, 'unsetChanges' => false, 'unsetPingChangeFlag' => false), + ['newsynckey' => false, 'unsetChanges' => false, 'unsetPingChangeFlag' => false], $options ); if (!empty($collection['id'])) { @@ -607,9 +615,11 @@ public function updateCollection(array $collection, array $options = array()) $this->_markCollectionsDirty($collection['id']); } } else { - $this->_logger->meta(sprintf( - 'Collection without id found: %s', - serialize($collection)) + $this->_logger->meta( + sprintf( + 'Collection without id found: %s', + serialize($collection) + ) ); } } @@ -657,25 +667,24 @@ public function validateCollectionsFromCache(&$collections) } if (!isset($values['windowsize'])) { - $collections[$key]['windowsize'] = - isset($this->_data['collections'][$values['id']]['windowsize']) - ? $this->_data['collections'][$values['id']]['windowsize'] - : 100; + $collections[$key]['windowsize'] + = $this->_data['collections'][$values['id']]['windowsize'] + ?? 100; $this->_markCollectionsDirty($key); } // According to specs, if WINDOWSIZE is out of bounds, interpret as 512. - if ($collections[$key]['windowsize'] > Horde_ActiveSync_Request_Sync::MAX_WINDOW_SIZE || - $collections[$key]['windowsize'] == 0) { + if ($collections[$key]['windowsize'] > Horde_ActiveSync_Request_Sync::MAX_WINDOW_SIZE + || $collections[$key]['windowsize'] == 0) { $collections[$key]['windowsize'] = self::MAX_WINDOW_SIZE; $this->_markCollectionsDirty($key); } - if (isset($values['synckey']) && - $values['synckey'] == '0' && - isset($this->_data['collections'][$values['id']]['synckey']) && - $this->_data['collections'][$values['id']]['synckey'] != '0') { + if (isset($values['synckey']) + && $values['synckey'] == '0' + && isset($this->_data['collections'][$values['id']]['synckey']) + && $this->_data['collections'][$values['id']]['synckey'] != '0') { unset($this->_data['collections'][$values['id']]['synckey']); $this->_markCollectionsDirty($key); @@ -695,7 +704,7 @@ public function validateCollectionsFromCache(&$collections) */ public function getFolders() { - return count($this->_data['folders']) ? $this->_data['folders'] : array(); + return count($this->_data['folders']) ? $this->_data['folders'] : []; } /** @@ -703,7 +712,7 @@ public function getFolders() */ public function clearFolders() { - $this->_data['folders'] = array(); + $this->_data['folders'] = []; $this->_dirty['folders'] = true; } @@ -727,24 +736,24 @@ public function refreshFolderCache() public function updateFolder(Horde_ActiveSync_Message_Folder $folder) { switch ($folder->type) { - case 7: - case 15: - $this->_data['folders'][$folder->serverid] = array('class' => 'Tasks'); - break; - case 8: - case 13: - $this->_data['folders'][$folder->serverid] = array('class' => 'Calendar'); - break; - case 9: - case 14: - $this->_data['folders'][$folder->serverid] = array('class' => 'Contacts'); - break; - case 17: - case 10: - $this->_data['folders'][$folder->serverid] = array('class' => 'Notes'); - break; - default: - $this->_data['folders'][$folder->serverid] = array('class' => 'Email'); + case 7: + case 15: + $this->_data['folders'][$folder->serverid] = ['class' => 'Tasks']; + break; + case 8: + case 13: + $this->_data['folders'][$folder->serverid] = ['class' => 'Calendar']; + break; + case 9: + case 14: + $this->_data['folders'][$folder->serverid] = ['class' => 'Contacts']; + break; + case 17: + case 10: + $this->_data['folders'][$folder->serverid] = ['class' => 'Notes']; + break; + default: + $this->_data['folders'][$folder->serverid] = ['class' => 'Email']; } $this->_data['folders'][$folder->serverid]['serverid'] = $folder->_serverid; $this->_data['folders'][$folder->serverid]['type'] = $folder->type; @@ -783,8 +792,8 @@ public function getFolder($folder) public function delete() { $this->_state->deleteSyncCache($this->_devid, $this->_user); - $this->_data = array(); - $this->_dirty = array(); + $this->_data = []; + $this->_dirty = []; } /** @@ -798,7 +807,7 @@ protected function _markCollectionsDirty($id) if (isset($this->_dirty['collections']) && is_array($this->_dirty['collections'])) { $this->_dirty['collections'][$id] = true; } elseif (!isset($this->_dirty['collections']) || $this->_dirty['collections'] !== true) { - $this->_dirty['collections'] = array(); + $this->_dirty['collections'] = []; $this->_markCollectionsDirty($id); } } diff --git a/lib/Horde/ActiveSync/Timezone.php b/lib/Horde/ActiveSync/Timezone.php index 9c01fd29..f8de6cef 100644 --- a/lib/Horde/ActiveSync/Timezone.php +++ b/lib/Horde/ActiveSync/Timezone.php @@ -1,4 +1,5 @@ 0, 'stdname' => '', 'stdyear' => 0, @@ -150,11 +171,11 @@ public static function getOffsetsFromDate(Horde_Date $date) 'dstminute' => 0, 'dstsecond' => 0, 'dstmillis' => 0, - 'dstbias' => 0 - ); + 'dstbias' => 0, + ]; $timezone = $date->toDateTime()->getTimezone(); - list($std, $dst) = self::_getTransitions($timezone, $date); + [$std, $dst] = self::_getTransitions($timezone, $date); if ($std) { $offsets['bias'] = $std['offset'] / 60 * -1; if ($dst) { @@ -181,7 +202,7 @@ public static function getOffsetsFromDate(Horde_Date $date) protected static function _getTransitions(DateTimeZone $timezone, Horde_Date $date) { - $std = $dst = array(); + $std = $dst = []; $transitions = $timezone->getTransitions( mktime(0, 0, 0, 12, 1, $date->year - 1), mktime(24, 0, 0, 12, 31, $date->year) @@ -189,8 +210,8 @@ protected static function _getTransitions(DateTimeZone $timezone, Horde_Date $da foreach ($transitions as $i => $transition) { try { - $d = new Horde_Date($transition['time']); - $d->setTimezone('UTC'); + $d = new Horde_Date($transition['time']); + $d->setTimezone('UTC'); } catch (Exception $e) { continue; } @@ -200,7 +221,7 @@ protected static function _getTransitions(DateTimeZone $timezone, Horde_Date $da $dst = $transition['isdst'] ? $transition : $transitions[$i + 1]; $std = $transition['isdst'] ? $transitions[$i + 1] : $transition; } else { - $dst = $transition['isdst'] ? $transition: null; + $dst = $transition['isdst'] ? $transition : null; $std = $transition['isdst'] ? null : $transition; } break; @@ -209,7 +230,7 @@ protected static function _getTransitions(DateTimeZone $timezone, Horde_Date $da } } - return array($std, $dst); + return [$std, $dst]; } /** @@ -232,8 +253,8 @@ protected static function _generateOffsetsForTransition(array $offsets, array $t $transitionDate = new Horde_Date($transitionDate); $offsets[$type . 'month'] = $transitionDate->format('n'); $offsets[$type . 'day'] = $transitionDate->format('w'); - $offsets[$type . 'minute'] = (int)$transitionDate->format('i'); - $offsets[$type . 'hour'] = (int)$transitionDate->format('H'); + $offsets[$type . 'minute'] = (int) $transitionDate->format('i'); + $offsets[$type . 'hour'] = (int) $transitionDate->format('H'); for ($i = 5; $i > 0; $i--) { if (self::_isNthOcurrenceOfWeekdayInMonth($transition['ts'], $i)) { $offsets[$type . 'week'] = $i; @@ -280,12 +301,12 @@ public function getListOfTimezones($offsets, $expectedTimezone = null) $offsets = self::getOffsetsFromSyncTZ($offsets); } $this->_setDefaultStartDate($offsets); - $timezones = array(); + $timezones = []; foreach (DateTimeZone::listIdentifiers() as $timezoneIdentifier) { $timezone = new DateTimeZone($timezoneIdentifier); if (false !== ($matchingTransition = $this->_checkTimezone($timezone, $offsets))) { if ($timezoneIdentifier == $expectedTimezone) { - $timezones = array($timezoneIdentifier => $matchingTransition['abbr']); + $timezones = [$timezoneIdentifier => $matchingTransition['abbr']]; break; } else { $timezones[$timezoneIdentifier] = $matchingTransition['abbr']; @@ -294,7 +315,7 @@ public function getListOfTimezones($offsets, $expectedTimezone = null) } if (empty($timezones)) { - throw new Horde_ActiveSync_Exception('No timezone found for the given offsets'); + throw new Horde_ActiveSync_Exception('No timezone found for the given offsets'); } return $timezones; @@ -308,7 +329,7 @@ public function getListOfTimezones($offsets, $expectedTimezone = null) * * @param array $offsets Offsets may be avaluated for a given start year */ - protected function _setDefaultStartDate(array $offsets = null) + protected function _setDefaultStartDate(?array $offsets = null) { if (!empty($this->_startDate)) { return; @@ -335,7 +356,7 @@ protected function _setDefaultStartDate(array $offsets = null) */ protected function _checkTimezone(DateTimeZone $timezone, array $offsets) { - list($std, $dst) = $this->_getTransitions($timezone, $this->_startDate); + [$std, $dst] = $this->_getTransitions($timezone, $this->_startDate); if ($this->_checkTransition($std, $dst, $offsets)) { return $std; } @@ -364,26 +385,25 @@ protected function _checkTransition(array $std, array $dst, array $offsets) // check each condition in a single if statement and break the chain // when one condition is not met - for performance reasons if ($standardOffset == $std['offset']) { - if ((empty($offsets['dstmonth']) && (empty($dst) || empty($dst['isdst']))) || - (empty($dst) && !empty($offsets['dstmonth']))) { + if ((empty($offsets['dstmonth']) && (empty($dst) || empty($dst['isdst']))) + || (empty($dst) && !empty($offsets['dstmonth']))) { // Offset contains DST, but no dst to compare return true; } $daylightOffset = ($offsets['bias'] + $offsets['dstbias']) * 60 * -1; // the milestone is sending a positive value for daylightBias while it should send a negative value - $daylightOffsetMilestone = ($offsets['dstbias'] + ($offsets['dstbias'] * -1) ) * 60 * -1; + $daylightOffsetMilestone = ($offsets['dstbias'] + ($offsets['dstbias'] * -1)) * 60 * -1; if ($daylightOffset == $dst['offset'] || $daylightOffsetMilestone == $dst['offset']) { $standardParsed = new DateTime($std['time']); $daylightParsed = new DateTime($dst['time']); - if ($standardParsed->format('n') == $offsets['stdmonth'] && - $daylightParsed->format('n') == $offsets['dstmonth'] && - $standardParsed->format('w') == $offsets['stdday'] && - $daylightParsed->format('w') == $offsets['dstday']) - { - return self::_isNthOcurrenceOfWeekdayInMonth($dst['ts'], $offsets['dstweek']) && - self::_isNthOcurrenceOfWeekdayInMonth($std['ts'], $offsets['stdweek']); + if ($standardParsed->format('n') == $offsets['stdmonth'] + && $daylightParsed->format('n') == $offsets['dstmonth'] + && $standardParsed->format('w') == $offsets['stdday'] + && $daylightParsed->format('w') == $offsets['dstday']) { + return self::_isNthOcurrenceOfWeekdayInMonth($dst['ts'], $offsets['dstweek']) + && self::_isNthOcurrenceOfWeekdayInMonth($std['ts'], $offsets['stdweek']); } } } @@ -407,15 +427,15 @@ protected static function _isNthOcurrenceOfWeekdayInMonth($timestamp, $occurence $original = new Horde_Date($timestamp); $original->setTimezone('UTC'); if ($occurence == 5) { - $modified = $original->add(array('mday' => 7)); + $modified = $original->add(['mday' => 7]); return $modified->month > $original->month; } else { - $modified = $original->sub(array('mday' => 7 * $occurence)); - $modified2 = $original->sub(array('mday' => 7 * ($occurence - 1))); + $modified = $original->sub(['mday' => 7 * $occurence]); + $modified2 = $original->sub(['mday' => 7 * ($occurence - 1)]); - return $modified->month < $original->month && - $modified2->month == $original->month; - } + return $modified->month < $original->month + && $modified2->month == $original->month; + } } /** @@ -426,7 +446,8 @@ protected static function _isNthOcurrenceOfWeekdayInMonth($timestamp, $occurence * * @return integer The number, in the reverse byte order. */ - protected static function _chbo($num) { + protected static function _chbo($num) + { $u = unpack('l', strrev(pack('l', $num))); return $u[1]; diff --git a/lib/Horde/ActiveSync/Translation.php b/lib/Horde/ActiveSync/Translation.php index d484ce07..54d9d32c 100644 --- a/lib/Horde/ActiveSync/Translation.php +++ b/lib/Horde/ActiveSync/Translation.php @@ -1,4 +1,5 @@ 'Sync', - 1 => 'SendMail', - 2 => 'SmartForward', - 3 => 'SmartReply', - 4 => 'GetAttachment', - 9 => 'FolderSync', - 10 => 'FolderCreate', - 11 => 'FolderDelete', - 12 => 'FolderUpdate', - 13 => 'MoveItems', - 14 => 'GetItemEstimate', - 15 => 'MeetingResponse', - 16 => 'Search', - 17 => 'Settings', - 18 => 'Ping', - 19 => 'ItemOperations', - 20 => 'Provision', - 21 => 'ResolveRecipients', - 22 => 'ValidateCert' - ); + $commandMap = [ + 0 => 'Sync', + 1 => 'SendMail', + 2 => 'SmartForward', + 3 => 'SmartReply', + 4 => 'GetAttachment', + 9 => 'FolderSync', + 10 => 'FolderCreate', + 11 => 'FolderDelete', + 12 => 'FolderUpdate', + 13 => 'MoveItems', + 14 => 'GetItemEstimate', + 15 => 'MeetingResponse', + 16 => 'Search', + 17 => 'Settings', + 18 => 'Ping', + 19 => 'ItemOperations', + 20 => 'Provision', + 21 => 'ResolveRecipients', + 22 => 'ValidateCert', + ]; $stream = fopen('php://temp', 'r+'); fwrite($stream, base64_decode($uri)); rewind($stream); - $results = array(); + $results = []; // Version, command, locale $data = unpack('CprotocolVersion/Ccommand/vlocale', fread($stream, 4)); $results['ProtVer'] = substr($data['protocolVersion'], 0, -1) . '.' . substr($data['protocolVersion'], -1); @@ -87,39 +88,39 @@ public static function decodeBase64($uri) $length = ord(fread($stream, 1)); if ($length > 0 || $tag == 7) { switch ($tag) { - case 0: - $data = unpack('A' . $length . 'AttName', fread($stream, $length)); - $results['AttachmentName'] = $data['AttName']; - break; - case 1: - $data = unpack('A' . $length . 'CollId', fread($stream, $length)); - $results['CollectionId'] = $data['CollId']; - break; - case 3: - $data = unpack('A' . $length . 'ItemId', fread($stream, $length)); - $results['ItemId'] = $data['ItemId']; - break; - case 4: - $data = unpack('A' . $length . 'Lid', fread($stream, $length)); - $results['LongId'] = $data['Lid']; - break; - case 5: - $data = unpack('A' . $length . 'Pid', fread($stream, $length)); - $results['ParentId'] = $data['Pid']; - break; - case 6: - $data = unpack('A' . $length . 'Oc', fread($stream, $length)); - $results['Occurrence'] = $data['Oc']; - break; - case 7: - $options = ord(fread($stream, 1)); - $results['SaveInSent'] = !!($options & 0x01); - $results['AcceptMultiPart'] = !!($options & 0x02); - break; - case 8: - $data = unpack('A' . $length . 'User', fread($stream, $length)); - $results['User'] = $data['User']; - break; + case 0: + $data = unpack('A' . $length . 'AttName', fread($stream, $length)); + $results['AttachmentName'] = $data['AttName']; + break; + case 1: + $data = unpack('A' . $length . 'CollId', fread($stream, $length)); + $results['CollectionId'] = $data['CollId']; + break; + case 3: + $data = unpack('A' . $length . 'ItemId', fread($stream, $length)); + $results['ItemId'] = $data['ItemId']; + break; + case 4: + $data = unpack('A' . $length . 'Lid', fread($stream, $length)); + $results['LongId'] = $data['Lid']; + break; + case 5: + $data = unpack('A' . $length . 'Pid', fread($stream, $length)); + $results['ParentId'] = $data['Pid']; + break; + case 6: + $data = unpack('A' . $length . 'Oc', fread($stream, $length)); + $results['Occurrence'] = $data['Oc']; + break; + case 7: + $options = ord(fread($stream, 1)); + $results['SaveInSent'] = !!($options & 0x01); + $results['AcceptMultiPart'] = !!($options & 0x02); + break; + case 8: + $data = unpack('A' . $length . 'User', fread($stream, $length)); + $results['User'] = $data['User']; + break; } } } @@ -152,11 +153,11 @@ public static function getUidFromGoid($goid) // If it's not a vCal UID, then it is Outlook style UID: // The entire decoded goid is converted to hex representation with // bytes 17 - 20 converted to zero - $hex = array(); + $hex = []; foreach (str_split($goid) as $chr) { $hex[] = sprintf('%02X', ord($chr)); } - array_splice($hex, 16, 4, array('00', '00', '00', '00')); + array_splice($hex, 16, 4, ['00', '00', '00', '00']); return implode('', $hex); } } @@ -170,7 +171,7 @@ public static function getUidFromGoid($goid) * @return string A Base64 encoded GOID * @deprecated Will be removed in H6. Use Horde_Mapi::createGoid */ - public static function createGoid($uid, $options = array()) + public static function createGoid($uid, $options = []) { // Bytes 1 - 16 MUST be equal to the GOID identifier: $arrayid = '040000008200E00074C5B7101A82E008'; @@ -219,10 +220,10 @@ public static function ensureUtf8($data, $from_charset) { $text = Horde_String::convertCharset($data, $from_charset, 'UTF-8'); if (!Horde_String::validUtf8($text)) { - $test_charsets = array( + $test_charsets = [ 'windows-1252', - 'UTF-8' - ); + 'UTF-8', + ]; foreach ($test_charsets as $charset) { if ($charset != $from_charset) { $text = Horde_String::convertCharset($data, $charset, 'UTF-8'); diff --git a/lib/Horde/ActiveSync/Wbxml.php b/lib/Horde/ActiveSync/Wbxml.php index 79ac9c96..91397f50 100644 --- a/lib/Horde/ActiveSync/Wbxml.php +++ b/lib/Horde/ActiveSync/Wbxml.php @@ -1,4 +1,5 @@ array ( - 0 => array ( + protected $_dtd = [ + 'codes' => [ + 0 => [ 0x05 => 'Synchronize', 0x06 => 'Replies', 0x07 => 'Add', @@ -122,9 +123,9 @@ class Horde_ActiveSync_Wbxml 0x27 => 'ConversationMode', 0x28 => 'MaxItems', 0x29 => 'HeartbeatInterval', - ), + ], /* POOMCONTACTS */ - 1 => array ( + 1 => [ 0x05 => 'Anniversary', 0x06 => 'AssistantName', 0x07 => 'AssistnamePhoneNumber', @@ -184,9 +185,9 @@ class Horde_ActiveSync_Wbxml // EAS 14.0 0x3d => 'Alias', 0x3e => 'WeightedRank', - ), + ], /* POOMMAIL */ - 2 => array ( + 2 => [ 0x05 => 'Attachment', 0x06 => 'Attachments', 0x07 => 'AttName', @@ -248,12 +249,12 @@ class Horde_ActiveSync_Wbxml 0x3e => 'CompleteTime', // EAS 14.0 0x3f => 'DisallowNewTimeProposal', - ), + ], /* 3 == AirNotify == deprecated */ /* POOMCAL */ - 4 => array ( + 4 => [ 0x05 => 'Timezone', 0x06 => 'AllDayEvent', 0x07 => 'Attendees', @@ -315,9 +316,9 @@ class Horde_ActiveSync_Wbxml 0x3b => 'OnlineMeetingExternalLink', // EAS 16.0 0x3c => 'ClientUid', - ), + ], /* MOVE */ - 5 => array ( + 5 => [ 0x05 => 'Moves', 0x06 => 'Move', 0x07 => 'SrcMsgId', @@ -326,9 +327,9 @@ class Horde_ActiveSync_Wbxml 0x0a => 'Response', 0x0b => 'Status', 0x0c => 'DstMsgId', - ), + ], /* GETITEMESTIMATE */ - 6 => array ( + 6 => [ 0x05 => 'GetItemEstimate', 0x06 => 'Version', // 12.1 0x07 => 'Folders', @@ -339,9 +340,9 @@ class Horde_ActiveSync_Wbxml 0x0c => 'Estimate', 0x0d => 'Response', 0x0e => 'Status', - ), + ], /* FOLDERHIERARCHY */ - 7 => array ( + 7 => [ 0x05 => 'Folders', 0x06 => 'Folder', 0x07 => 'DisplayName', @@ -362,9 +363,9 @@ class Horde_ActiveSync_Wbxml 0x16 => 'FolderSync', 0x17 => 'Count', 0x18 => 'Version', - ), + ], /* MEETINGRESPONSE */ - 8 => array ( + 8 => [ 0x05 => 'CalendarId', 0x06 => 'FolderId', 0x07 => 'MeetingResponse', @@ -378,9 +379,9 @@ class Horde_ActiveSync_Wbxml 0x0e => 'InstanceId', // EAS 16.0 0x12 => 'SendResponse', - ), + ], /* POOMTASKS */ - 9 => array ( + 9 => [ 0x05 => 'Body', 0x06 => 'BodySize', 0x07 => 'BodyTruncated', @@ -418,9 +419,9 @@ class Horde_ActiveSync_Wbxml 0x25 => 'IsLeapMonth', // EAS 14.1 0x26 => 'FirstDayOfWeek', - ), + ], /* RESOLVERECIPIENTS */ - 0xa => array ( + 0xa => [ 0x05 => 'ResolveRecipients', 0x06 => 'Response', 0x07 => 'Status', @@ -447,18 +448,18 @@ class Horde_ActiveSync_Wbxml 0x1b => 'MaxSize', 0x1c => 'Data', 0x1d => 'MaxPictures', - ), + ], /* VALIDATECERT */ - 0xb => array ( + 0xb => [ 0x05 => 'ValidateCert', 0x06 => 'Certificates', 0x07 => 'Certificate', 0x08 => 'CertificateChain', 0x09 => 'CheckCRL', 0x0a => 'Status', - ), + ], /* POOMCONTACTS2*/ - 0xc => array ( + 0xc => [ 0x05 => 'CustomerId', 0x06 => 'GovernmentId', 0x07 => 'IMAddress', @@ -469,9 +470,9 @@ class Horde_ActiveSync_Wbxml 0x0c => 'AccountName', 0x0d => 'NickName', 0x0e => 'MMS', - ), + ], /* PING */ - 0xd => array ( + 0xd => [ 0x05 => 'Ping', 0x06 => 'AutdState', 0x07 => 'Status', @@ -481,9 +482,9 @@ class Horde_ActiveSync_Wbxml 0x0b => 'ServerEntryId', 0x0c => 'FolderType', 0x0d => 'MaxFolders', - ), + ], /* PROVISION */ - 0xe => array ( + 0xe => [ 0x05 => 'Provision', 0x06 => 'Policies', 0x07 => 'Policy', @@ -540,9 +541,9 @@ class Horde_ActiveSync_Wbxml 0x38 => 'ApplicationName', 0x39 => 'ApprovedApplicationList', 0x3A => 'Hash', - ), + ], /* SEARCH */ - 0xf => array( + 0xf => [ 0x05 => 'Search', 0x07 => 'Store', 0x08 => 'Name', @@ -574,9 +575,9 @@ class Horde_ActiveSync_Wbxml 0x21 => 'Picture', 0x22 => 'MaxSize', 0x23 => 'MaxPictures', - ), + ], /* GAL (Global Address List) */ - 0x10 => array( + 0x10 => [ 0x05 => 'DisplayName', 0x06 => 'Phone', 0x07 => 'Office', @@ -592,11 +593,11 @@ class Horde_ActiveSync_Wbxml 0x10 => 'Picture', 0x11 => 'Status', 0x12 => 'Data', - ), + ], // EAS 12.0 /* AIRSYNCBASE */ - 0x11 => array( + 0x11 => [ 0x05 => 'BodyPreference', 0x06 => 'Type', 0x07 => 'TruncationSize', @@ -640,10 +641,10 @@ class Horde_ActiveSync_Wbxml 0x2b => 'AltitudeAccuracy', 0x2c => 'LocationUri', 0x2d => 'InstanceId', - ), + ], /* SETTINGS */ - 0x12 => array( + 0x12 => [ 0x05 => 'Settings', 0x06 => 'Status', 0x07 => 'Get', @@ -685,10 +686,10 @@ class Horde_ActiveSync_Wbxml 0x28 => 'UserDisplayName', 0x29 => 'SendDisabled', 0x2b => 'RightsManagementInformation', - ), + ], /* Document Library */ - 0x13 => array( + 0x13 => [ 0x05 => 'LinkId', 0x06 => 'DisplayName', 0x07 => 'IsFolder', @@ -696,11 +697,11 @@ class Horde_ActiveSync_Wbxml 0x09 => 'LastModifiedDate', 0x0A => 'IsHidden', 0x0B => 'ContentLength', - 0x0C => 'ContentType' - ), + 0x0C => 'ContentType', + ], /* ITEMOPERATIONS */ - 0x14 => array( + 0x14 => [ 0x05 => 'ItemOperations', 0x06 => 'Fetch', 0x07 => 'Store', @@ -725,10 +726,10 @@ class Horde_ActiveSync_Wbxml 0x18 => 'ConversationId', 0x19 => 'MoveAlways', - ), + ], /* COMPOSEMAIL (14.0) */ - 0x15 => array( + 0x15 => [ 0x05 => 'SendMail', 0x06 => 'SmartForward', 0x07 => 'SmartReply', @@ -749,11 +750,11 @@ class Horde_ActiveSync_Wbxml 0x15 => 'Forwardees', 0x16 => 'Forwardee', 0x17 => 'ForwardeeName', - 0x18 => 'ForwardeeEmail' - ), + 0x18 => 'ForwardeeEmail', + ], /* POOMMAIL2 (14.0) */ - 0x16 => array( + 0x16 => [ 0x05 => 'UmCallerId', 0x06 => 'UmUserNotes', 0x07 => 'UmAttDuration', @@ -773,22 +774,22 @@ class Horde_ActiveSync_Wbxml // EAS 16.0 0x15 => 'IsDraft', 0x16 => 'Bcc', - 0x17 => 'Send' - ), + 0x17 => 'Send', + ], /* Notes (14.0) */ - 0x17 => array( + 0x17 => [ 0x05 => 'Subject', 0x06 => 'MessageClass', 0x07 => 'LastModifiedDate', 0x08 => 'Categories', 0x09 => 'Category', - ), + ], /* Rights Management (14.1) */ // Included here to decode without errors. // Functionality not implemented. - 0x18 => array( + 0x18 => [ 0x05 => 'RightsManagementSupport', 0x06 => 'RightsManagementTemplates', 0x07 => 'RightsManagementTemplate', @@ -808,48 +809,48 @@ class Horde_ActiveSync_Wbxml 0x15 => 'TemplateName', 0x16 => 'TemplateDescription', 0x17 => 'ContentOwner', - 0x18 => 'RemoveRightsManagementDistribution' - ), + 0x18 => 'RemoveRightsManagementDistribution', + ], // Windows Live - 0xFE => array( + 0xFE => [ 0x05 => 'Annotations', 0x06 => 'Annotation', 0x07 => 'Name', - 0x08 => 'Value' - ) - ), + 0x08 => 'Value', + ], + ], - 'namespaces' => array( - 1 => 'POOMCONTACTS', - 2 => 'POOMMAIL', - 4 => 'POOMCAL', - 5 => 'Move', - 6 => 'GetItemEstimate', - 7 => 'FolderHierarchy', - 8 => 'MeetingResponse', - 9 => 'POOMTASKS', - 0xA => 'ResolveRecipients', - 0xB => 'ValidateCert', - 0xC => 'POOMCONTACTS2', - 0xD => 'Ping', - 0xE => 'Provision', - 0xF => 'Search', - 0x10 => 'GAL', - // EAS 12.0 - 0x11 => 'AirSyncBase', - 0x12 => 'Settings', - 0x13 => 'DocumentLibrary', - 0x14 => 'ItemOperations', - // EAS 14 - 0x15 => 'ComposeMail', - 0x16 => 'POOMMAIL2', - 0x17 => 'Notes', - 0x18 => 'RightsManagement', - // Hotmail/Outlook.com WBXML extension. - 0xFE => 'WindowsLive' - ) - ); + 'namespaces' => [ + 1 => 'POOMCONTACTS', + 2 => 'POOMMAIL', + 4 => 'POOMCAL', + 5 => 'Move', + 6 => 'GetItemEstimate', + 7 => 'FolderHierarchy', + 8 => 'MeetingResponse', + 9 => 'POOMTASKS', + 0xA => 'ResolveRecipients', + 0xB => 'ValidateCert', + 0xC => 'POOMCONTACTS2', + 0xD => 'Ping', + 0xE => 'Provision', + 0xF => 'Search', + 0x10 => 'GAL', + // EAS 12.0 + 0x11 => 'AirSyncBase', + 0x12 => 'Settings', + 0x13 => 'DocumentLibrary', + 0x14 => 'ItemOperations', + // EAS 14 + 0x15 => 'ComposeMail', + 0x16 => 'POOMMAIL2', + 0x17 => 'Notes', + 0x18 => 'RightsManagement', + // Hotmail/Outlook.com WBXML extension. + 0xFE => 'WindowsLive', + ], + ]; /** * Track the codepage for the currently output tag so we know when to @@ -865,7 +866,7 @@ class Horde_ActiveSync_Wbxml * * @var array */ - protected $_logStack = array(); + protected $_logStack = []; /** * Logger @@ -879,21 +880,21 @@ class Horde_ActiveSync_Wbxml * * @var Horde_Stream */ - protected $_stream; + protected $_stream; - /** - * The current procid - * - * @var integer - */ - protected $_procid; + /** + * The current procid + * + * @var integer + */ + protected $_procid; - /** - * Logging level. - * - * @param integer - */ - protected $_logLevel; + /** + * Logging level. + * + * @param integer + */ + protected $_logLevel; /** * @@ -901,7 +902,7 @@ class Horde_ActiveSync_Wbxml */ public function __construct($stream, $log_level = self::LOG_PROTOCOL) { - $this->_stream = new Horde_Stream_Existing(array('stream' => $stream)); + $this->_stream = new Horde_Stream_Existing(['stream' => $stream]); $this->_logger = new Horde_ActiveSync_Log_Logger(new Horde_Log_Handler_Null()); $this->_procid = getmypid(); $this->_logLevel = $log_level; diff --git a/lib/Horde/ActiveSync/Wbxml/Decoder.php b/lib/Horde/ActiveSync/Wbxml/Decoder.php index 4a40d9ef..d34f1021 100644 --- a/lib/Horde/ActiveSync/Wbxml/Decoder.php +++ b/lib/Horde/ActiveSync/Wbxml/Decoder.php @@ -1,4 +1,5 @@ getToken(); if ($element !== false) { - if ($element[self::EN_TYPE] === self::EN_TYPE_STARTTAG && - $element[self::EN_TAG] === $tag) { + if ($element[self::EN_TYPE] === self::EN_TYPE_STARTTAG + && $element[self::EN_TAG] === $tag) { $this->_lastStartElement = $element; return $element; } @@ -297,29 +298,29 @@ public function getToken() protected function _logToken($el) { switch ($el[self::EN_TYPE]) { - case self::EN_TYPE_STARTTAG: - $indent = count($this->_logStack); - if ($el[self::EN_FLAGS] & self::EN_FLAGS_CONTENT) { - $this->_logStack[] = $el[self::EN_TAG]; - $this->_logger->client(sprintf('<%s>', $el[self::EN_TAG]), $indent); - } else { - $this->_logger->client(sprintf('<%s />', $el[self::EN_TAG]), $indent); - } - break; - case self::EN_TYPE_ENDTAG: - $tag = array_pop($this->_logStack); - $indent = count($this->_logStack); - $this->_logger->client(sprintf('', $tag), $indent); - break; - case self::EN_TYPE_CONTENT: - $indent = count($this->_logStack) + 1; - if ($this->_logLevel == self::LOG_PROTOCOL && - ($l = Horde_String::length($el[self::EN_CONTENT])) > self::LOG_MAXCONTENT) { - $this->_logger->client(sprintf('[%d bytes of content]', $l), $indent); - } else { - $this->_logger->client($el[self::EN_CONTENT], $indent); - } - break; + case self::EN_TYPE_STARTTAG: + $indent = count($this->_logStack); + if ($el[self::EN_FLAGS] & self::EN_FLAGS_CONTENT) { + $this->_logStack[] = $el[self::EN_TAG]; + $this->_logger->client(sprintf('<%s>', $el[self::EN_TAG]), $indent); + } else { + $this->_logger->client(sprintf('<%s />', $el[self::EN_TAG]), $indent); + } + break; + case self::EN_TYPE_ENDTAG: + $tag = array_pop($this->_logStack); + $indent = count($this->_logStack); + $this->_logger->client(sprintf('', $tag), $indent); + break; + case self::EN_TYPE_CONTENT: + $indent = count($this->_logStack) + 1; + if ($this->_logLevel == self::LOG_PROTOCOL + && ($l = Horde_String::length($el[self::EN_CONTENT])) > self::LOG_MAXCONTENT) { + $this->_logger->client(sprintf('[%d bytes of content]', $l), $indent); + } else { + $this->_logger->client($el[self::EN_CONTENT], $indent); + } + break; } } @@ -328,7 +329,8 @@ protected function _logToken($el) * * @return array|boolean The element array or false on end of stream. */ - protected function _getToken() { + protected function _getToken() + { // Get the data from the input stream $element = []; @@ -341,93 +343,93 @@ protected function _getToken() { } switch ($byte) { - case self::SWITCH_PAGE: - $this->_tagcp = $this->_getByte(); - break; - - case self::END: - $element[self::EN_TYPE] = self::EN_TYPE_ENDTAG; - return $element; - - case self::ENTITY: - $entity = $this->_getMBUInt(); - $element[self::EN_TYPE] = self::EN_TYPE_CONTENT; - $element[self::EN_CONTENT] = $this->entityToCharset($entity); - return $element; - - case self::STR_I: - $element[self::EN_TYPE] = self::EN_TYPE_CONTENT; - $element[self::EN_CONTENT] = $this->_getTermStr(); - return $element; - - case self::LITERAL: - $element[self::EN_TYPE] = self::EN_TYPE_STARTTAG; - $element[self::EN_TAG] = $this->_getStringTableEntry($this->_getMBUInt()); - $element[self::EN_FLAGS] = 0; - return $element; - - case self::EXT_I_0: - case self::EXT_I_1: - case self::EXT_I_2: - $this->_getTermStr(); - // Ignore extensions - break; - - case self::PI: - // Ignore PI - $this->_getAttributes(); - break; + case self::SWITCH_PAGE: + $this->_tagcp = $this->_getByte(); + break; - case self::LITERAL_C: - $element[self::EN_TYPE] = self::EN_TYPE_STARTTAG; - $element[self::EN_TAG] = $this->_getStringTableEntry($this->_getMBUInt()); - $element[self::EN_FLAGS] = self::EN_FLAGS_CONTENT; - return $element; + case self::END: + $element[self::EN_TYPE] = self::EN_TYPE_ENDTAG; + return $element; + + case self::ENTITY: + $entity = $this->_getMBUInt(); + $element[self::EN_TYPE] = self::EN_TYPE_CONTENT; + $element[self::EN_CONTENT] = $this->entityToCharset($entity); + return $element; + + case self::STR_I: + $element[self::EN_TYPE] = self::EN_TYPE_CONTENT; + $element[self::EN_CONTENT] = $this->_getTermStr(); + return $element; + + case self::LITERAL: + $element[self::EN_TYPE] = self::EN_TYPE_STARTTAG; + $element[self::EN_TAG] = $this->_getStringTableEntry($this->_getMBUInt()); + $element[self::EN_FLAGS] = 0; + return $element; + + case self::EXT_I_0: + case self::EXT_I_1: + case self::EXT_I_2: + $this->_getTermStr(); + // Ignore extensions + break; - case self::EXT_T_0: - case self::EXT_T_1: - case self::EXT_T_2: - $this->_getMBUInt(); - // Ingore extensions; - break; + case self::PI: + // Ignore PI + $this->_getAttributes(); + break; - case self::STR_T: - $element[self::EN_TYPE] = self::EN_TYPE_CONTENT; - $element[self::EN_CONTENT] = $this->_getStringTableEntry($this->_getMBUInt()); - return $element; + case self::LITERAL_C: + $element[self::EN_TYPE] = self::EN_TYPE_STARTTAG; + $element[self::EN_TAG] = $this->_getStringTableEntry($this->_getMBUInt()); + $element[self::EN_FLAGS] = self::EN_FLAGS_CONTENT; + return $element; + + case self::EXT_T_0: + case self::EXT_T_1: + case self::EXT_T_2: + $this->_getMBUInt(); + // Ingore extensions; + break; - case self::LITERAL_A: - $element[self::EN_TYPE] = self::EN_TYPE_STARTTAG; - $element[self::EN_TAG] = $this->_getStringTableEntry($this->_getMBUInt()); - $element[self::EN_ATTRIBUTES] = $this->_getAttributes(); - $element[self::EN_FLAGS] = self::EN_FLAGS_ATTRIBUTES; - return $element; - case self::EXT_0: - case self::EXT_1: - case self::EXT_2: - break; + case self::STR_T: + $element[self::EN_TYPE] = self::EN_TYPE_CONTENT; + $element[self::EN_CONTENT] = $this->_getStringTableEntry($this->_getMBUInt()); + return $element; - case self::OPAQUE: - $length = $this->_getMBUInt(); - $element[self::EN_TYPE] = self::EN_TYPE_CONTENT; - $element[self::EN_CONTENT] = $this->_getOpaque($length); - return $element; + case self::LITERAL_A: + $element[self::EN_TYPE] = self::EN_TYPE_STARTTAG; + $element[self::EN_TAG] = $this->_getStringTableEntry($this->_getMBUInt()); + $element[self::EN_ATTRIBUTES] = $this->_getAttributes(); + $element[self::EN_FLAGS] = self::EN_FLAGS_ATTRIBUTES; + return $element; + case self::EXT_0: + case self::EXT_1: + case self::EXT_2: + break; - case self::LITERAL_AC: - $element[self::EN_TYPE] = self::EN_TYPE_STARTTAG; - $element[self::EN_TAG] = $this->_getStringTableEntry($this->_getMBUInt()); - $element[self::EN_ATTRIBUTES] = $this->_getAttributes(); - $element[self::EN_FLAGS] = self::EN_FLAGS_ATTRIBUTES | self::EN_FLAGS_CONTENT; - return $element; + case self::OPAQUE: + $length = $this->_getMBUInt(); + $element[self::EN_TYPE] = self::EN_TYPE_CONTENT; + $element[self::EN_CONTENT] = $this->_getOpaque($length); + return $element; - default: - $element[self::EN_TYPE] = self::EN_TYPE_STARTTAG; - $element[self::EN_TAG] = $this->_getMapping($this->_tagcp, $byte & 0x3f); - $element[self::EN_FLAGS] = ($byte & 0x80 ? self::EN_FLAGS_ATTRIBUTES : 0) | ($byte & 0x40 ? self::EN_FLAGS_CONTENT : 0); - if ($byte & 0x80) { + case self::LITERAL_AC: + $element[self::EN_TYPE] = self::EN_TYPE_STARTTAG; + $element[self::EN_TAG] = $this->_getStringTableEntry($this->_getMBUInt()); $element[self::EN_ATTRIBUTES] = $this->_getAttributes(); - } - return $element; + $element[self::EN_FLAGS] = self::EN_FLAGS_ATTRIBUTES | self::EN_FLAGS_CONTENT; + return $element; + + default: + $element[self::EN_TYPE] = self::EN_TYPE_STARTTAG; + $element[self::EN_TAG] = $this->_getMapping($this->_tagcp, $byte & 0x3f); + $element[self::EN_FLAGS] = ($byte & 0x80 ? self::EN_FLAGS_ATTRIBUTES : 0) | ($byte & 0x40 ? self::EN_FLAGS_CONTENT : 0); + if ($byte & 0x80) { + $element[self::EN_ATTRIBUTES] = $this->_getAttributes(); + } + return $element; } } @@ -457,7 +459,7 @@ public function _ungetElement($element) protected function _readVersion() { $b = $this->_getByte(); - if ($b != NULL) { + if ($b != null) { $this->version = $b; } } @@ -469,7 +471,7 @@ protected function _readVersion() */ protected function _getAttributes() { - $attributes = array(); + $attributes = []; $attr = ''; while (1) { @@ -478,80 +480,80 @@ protected function _getAttributes() break; } - switch($byte) { - case self::SWITCH_PAGE: - $this->_attrcp = $this->_getByte(); - break; + switch ($byte) { + case self::SWITCH_PAGE: + $this->_attrcp = $this->_getByte(); + break; - case self::END: - if ($attr != '') { - $attributes += $this->_splitAttribute($attr); - } - return $attributes; + case self::END: + if ($attr != '') { + $attributes += $this->_splitAttribute($attr); + } + return $attributes; - case self::ENTITY: - $entity = $this->_getMBUInt(); - $attr .= $this->entityToCharset($entity); - return $element; + case self::ENTITY: + $entity = $this->_getMBUInt(); + $attr .= $this->entityToCharset($entity); + return $element; - case self::STR_I: - $attr .= $this->_getTermStr(); - return $element; + case self::STR_I: + $attr .= $this->_getTermStr(); + return $element; - case self::LITERAL: - if ($attr != '') { - $attributes += $this->_splitAttribute($attr); - } - $attr = $this->_getStringTableEntry($this->_getMBUInt()); - return $element; + case self::LITERAL: + if ($attr != '') { + $attributes += $this->_splitAttribute($attr); + } + $attr = $this->_getStringTableEntry($this->_getMBUInt()); + return $element; - case self::EXT_I_0: - case self::EXT_I_1: - case self::EXT_I_2: - $this->_getTermStr(); - break; + case self::EXT_I_0: + case self::EXT_I_1: + case self::EXT_I_2: + $this->_getTermStr(); + break; - case self::PI: - case self::LITERAL_C: - // Invalid - return false; + case self::PI: + case self::LITERAL_C: + // Invalid + return false; - case self::EXT_T_0: - case self::EXT_T_1: - case self::EXT_T_2: - $this->_getMBUInt(); - break; + case self::EXT_T_0: + case self::EXT_T_1: + case self::EXT_T_2: + $this->_getMBUInt(); + break; - case self::STR_T: - $attr .= $this->_getStringTableEntry($this->_getMBUInt()); - return $element; + case self::STR_T: + $attr .= $this->_getStringTableEntry($this->_getMBUInt()); + return $element; - case self::LITERAL_A: - return false; + case self::LITERAL_A: + return false; - case self::EXT_0: - case self::EXT_1: - case self::EXT_2: - break; + case self::EXT_0: + case self::EXT_1: + case self::EXT_2: + break; - case self::OPAQUE: - $length = $this->_getMBUInt(); - $attr .= $this->_getOpaque($length); - return $element; + case self::OPAQUE: + $length = $this->_getMBUInt(); + $attr .= $this->_getOpaque($length); + return $element; - case self::LITERAL_AC: - return false; + case self::LITERAL_AC: + return false; - default: - if ($byte < 128) { - if ($attr != '') { - $attributes += $this->_splitAttribute($attr); - $attr = ''; + default: + if ($byte < 128) { + if ($attr != '') { + $attributes += $this->_splitAttribute($attr); + $attr = ''; + } } - } - $attr .= $this->_getMapping($this->_attrcp, $byte); - break; + $attr .= $this->_getMapping($this->_attrcp, $byte); + break; } } } @@ -565,10 +567,10 @@ protected function _getAttributes() */ protected function _splitAttribute($attr) { - $attributes = array(); - $pos = strpos($attr,chr(61)); // equals sign + $attributes = []; + $pos = strpos($attr, chr(61)); // equals sign if ($pos) { - $attributes[substr($attr, 0, $pos)] = substr($attr, $pos+1); + $attributes[substr($attr, 0, $pos)] = substr($attr, $pos + 1); } else { $attributes[$attr] = null; } @@ -584,7 +586,7 @@ protected function _splitAttribute($attr) protected function _getTermStr() { $str = ''; - while(1) { + while (1) { $in = $this->_getByte(); if ($in == 0) { @@ -620,7 +622,8 @@ protected function _getOpaque($len) throw new Horde_ActiveSync_Exception(sprintf( 'Connection unavailable while trying to read %d bytes from stream. Aborting after %d bytes read.', $len, - strlen($d))); + strlen($d) + )); } else { $d .= $data; } @@ -658,13 +661,13 @@ protected function _getMBUInt() { $uint = 0; while (1) { - $byte = $this->_getByte(); - $uint |= $byte & 0x7f; - if ($byte & 0x80) { - $uint = $uint << 7; - } else { - break; - } + $byte = $this->_getByte(); + $uint |= $byte & 0x7f; + if ($byte & 0x80) { + $uint = $uint << 7; + } else { + break; + } } return $uint; diff --git a/lib/Horde/ActiveSync/Wbxml/Encoder.php b/lib/Horde/ActiveSync/Wbxml/Encoder.php index 0c9a8518..96b9a0b0 100644 --- a/lib/Horde/ActiveSync/Wbxml/Encoder.php +++ b/lib/Horde/ActiveSync/Wbxml/Encoder.php @@ -1,4 +1,5 @@ _dtd['namespaces'] as $nsid => $nsname) { $dtd['namespaces'][$nsname] = $nsid; } foreach ($this->_dtd['codes'] as $cp => $value) { - $dtd['codes'][$cp] = array(); + $dtd['codes'][$cp] = []; foreach ($this->_dtd['codes'][$cp] as $tagid => $tagname) { $dtd['codes'][$cp][$tagname] = $tagid; } @@ -129,7 +130,7 @@ public function outputWbxmlHeader() */ public function startTag($tag, $attributes = false, $output_empty = false) { - $stackelem = array(); + $stackelem = []; if (!$output_empty) { $stackelem['tag'] = $tag; $stackelem['attributes'] = $attributes; @@ -178,7 +179,7 @@ public function endTag() $this->_tempStream->add($header); $this->_stream->rewind(); $this->_tempStream->add($this->_stream); - foreach($this->_parts as $bp) { + foreach ($this->_parts as $bp) { if (is_resource($bp)) { rewind($bp); $this->_tempStream->add($bp); @@ -253,7 +254,8 @@ private function _outputStack() if (!$this->_stack[$i]['sent']) { $this->_startTag( $this->_stack[$i]['tag'], - $this->_stack[$i]['attributes']); + $this->_stack[$i]['attributes'] + ); $this->_stack[$i]['sent'] = true; } } @@ -271,7 +273,7 @@ private function _startTag($tag, $attributes = false, $output_empty = false) $this->_logStartTag($tag, $attributes, $output_empty); $mapping = $this->_getMapping($tag); if (!$mapping) { - return false; + return false; } /* Make sure we don't need to switch code pages */ @@ -301,8 +303,8 @@ private function _startTag($tag, $attributes = false, $output_empty = false) private function _content($content, $opaque = false) { if (!is_resource($content)) { - if ($this->_logLevel == self::LOG_PROTOCOL && - ($l = Horde_String::length($content)) > self::LOG_MAXCONTENT) { + if ($this->_logLevel == self::LOG_PROTOCOL + && ($l = Horde_String::length($content)) > self::LOG_MAXCONTENT) { $this->_logContent(sprintf('[%d bytes of content]', $l)); } else { $this->_logContent($content); @@ -336,7 +338,8 @@ private function _content($content, $opaque = false) * Output the endtag * */ - private function _endTag() { + private function _endTag() + { $this->_logEndTag(); $this->_outByte(self::END); } @@ -416,7 +419,7 @@ private function _outSwitchPage($page) */ private function _getMapping($tag) { - $mapping = array(); + $mapping = []; $split = $this->_splitTag($tag); if (isset($split['ns'])) { $cp = $this->_dtd['namespaces'][$split['ns']]; @@ -445,12 +448,12 @@ private function _splitTag($fulltag) $pos = strpos($fulltag, chr(58)); // chr(58) == ':' if ($pos) { $ns = substr($fulltag, 0, $pos); - $tag = substr($fulltag, $pos+1); + $tag = substr($fulltag, $pos + 1); } else { $tag = $fulltag; } - $ret = array(); + $ret = []; if ($ns) { $ret['ns'] = $ns; } diff --git a/migration/Horde/ActiveSync/10_horde_activesync_add_deviceproperties.php b/migration/Horde/ActiveSync/10_horde_activesync_add_deviceproperties.php index 66b9015a..b25492f3 100644 --- a/migration/Horde/ActiveSync/10_horde_activesync_add_deviceproperties.php +++ b/migration/Horde/ActiveSync/10_horde_activesync_add_deviceproperties.php @@ -1,4 +1,5 @@ addColumn( 'horde_activesync_device', 'device_properties', - 'text'); + 'text' + ); } public function down() diff --git a/migration/Horde/ActiveSync/11_horde_activesync_removepingstate.php b/migration/Horde/ActiveSync/11_horde_activesync_removepingstate.php index 83e023ca..24ab0650 100644 --- a/migration/Horde/ActiveSync/11_horde_activesync_removepingstate.php +++ b/migration/Horde/ActiveSync/11_horde_activesync_removepingstate.php @@ -1,4 +1,5 @@ addColumn( 'horde_activesync_device_users', 'device_ping', - 'text'); + 'text' + ); $this->addColumn( 'horde_activesync_device_users', 'device_folders', - 'text'); + 'text' + ); } } diff --git a/migration/Horde/ActiveSync/12_horde_activesync_longtextcachefield.php b/migration/Horde/ActiveSync/12_horde_activesync_longtextcachefield.php index 41b11ce1..ff8aee19 100644 --- a/migration/Horde/ActiveSync/12_horde_activesync_longtextcachefield.php +++ b/migration/Horde/ActiveSync/12_horde_activesync_longtextcachefield.php @@ -1,4 +1,5 @@ changeColumn( 'horde_activesync_cache', 'cache_data', - 'mediumtext'); + 'mediumtext' + ); } public function down() @@ -14,7 +16,8 @@ public function down() $this->changeColumn( 'horde_activesync_cache', 'cache_data', - 'text'); + 'text' + ); } -} \ No newline at end of file +} diff --git a/migration/Horde/ActiveSync/13_horde_activesync_booleanfields.php b/migration/Horde/ActiveSync/13_horde_activesync_booleanfields.php index 8b1bfa6d..1c0ad2e9 100644 --- a/migration/Horde/ActiveSync/13_horde_activesync_booleanfields.php +++ b/migration/Horde/ActiveSync/13_horde_activesync_booleanfields.php @@ -1,4 +1,5 @@ changeColumn( 'horde_activesync_state', 'sync_data', - 'binary'); + 'binary' + ); } public function down() @@ -14,7 +16,8 @@ public function down() $this->changeColumn( 'horde_activesync_state', 'sync_data', - 'mediumtext'); + 'mediumtext' + ); } -} \ No newline at end of file +} diff --git a/migration/Horde/ActiveSync/15_horde_activesync_integerimapuidfield.php b/migration/Horde/ActiveSync/15_horde_activesync_integerimapuidfield.php index 68dcf28b..852de0b3 100644 --- a/migration/Horde/ActiveSync/15_horde_activesync_integerimapuidfield.php +++ b/migration/Horde/ActiveSync/15_horde_activesync_integerimapuidfield.php @@ -1,4 +1,5 @@ false, 'default' => 0)); + ['null' => false, 'default' => 0] + ); } public function down() @@ -16,8 +18,8 @@ public function down() 'horde_activesync_mailmap', 'message_uid', 'string', - array('limit' => 255, 'null' => false) + ['limit' => 255, 'null' => false] ); } -} \ No newline at end of file +} diff --git a/migration/Horde/ActiveSync/16_horde_activesync_fix_blob_length.php b/migration/Horde/ActiveSync/16_horde_activesync_fix_blob_length.php index 94977a3f..3bfd6522 100644 --- a/migration/Horde/ActiveSync/16_horde_activesync_fix_blob_length.php +++ b/migration/Horde/ActiveSync/16_horde_activesync_fix_blob_length.php @@ -1,4 +1,5 @@ changeColumn('horde_activesync_state', 'sync_data', 'binary'); } - public function down() - { - } + public function down() {} } diff --git a/migration/Horde/ActiveSync/17_horde_activesync_clearallstate.php b/migration/Horde/ActiveSync/17_horde_activesync_clearallstate.php index 278ccbba..9aa0adc1 100644 --- a/migration/Horde/ActiveSync/17_horde_activesync_clearallstate.php +++ b/migration/Horde/ActiveSync/17_horde_activesync_clearallstate.php @@ -1,4 +1,5 @@ delete('DELETE FROM horde_activesync_cache'); } -} \ No newline at end of file +} diff --git a/migration/Horde/ActiveSync/18_horde_activesync_addmapdeleteflag.php b/migration/Horde/ActiveSync/18_horde_activesync_addmapdeleteflag.php index cfdbd346..c04424c5 100644 --- a/migration/Horde/ActiveSync/18_horde_activesync_addmapdeleteflag.php +++ b/migration/Horde/ActiveSync/18_horde_activesync_addmapdeleteflag.php @@ -1,4 +1,5 @@ addColumn( 'horde_activesync_map', 'sync_deleted', - 'boolean'); + 'boolean' + ); } public function down() diff --git a/migration/Horde/ActiveSync/19_horde_activesync_addtimestamp.php b/migration/Horde/ActiveSync/19_horde_activesync_addtimestamp.php index 194f53f7..a3b398be 100644 --- a/migration/Horde/ActiveSync/19_horde_activesync_addtimestamp.php +++ b/migration/Horde/ActiveSync/19_horde_activesync_addtimestamp.php @@ -1,4 +1,5 @@ tables())) { - $t = $this->createTable('horde_activesync_state', array('autoincrementKey' => false)); + $t = $this->createTable('horde_activesync_state', ['autoincrementKey' => false]); $t->column('sync_time', 'integer'); - $t->column('sync_key', 'string', array('limit' => 255, 'null' => false)); + $t->column('sync_key', 'string', ['limit' => 255, 'null' => false]); $t->column('sync_data', 'text'); - $t->column('sync_devid', 'string', array('limit' => 255)); - $t->column('sync_folderid', 'string', array('limit' => 255)); - $t->column('sync_user', 'string', array('limit' => 255)); - $t->primaryKey(array('sync_key')); + $t->column('sync_devid', 'string', ['limit' => 255]); + $t->column('sync_folderid', 'string', ['limit' => 255]); + $t->column('sync_user', 'string', ['limit' => 255]); + $t->primaryKey(['sync_key']); $t->end(); - $this->addIndex('horde_activesync_state', array('sync_folderid')); - $this->addIndex('horde_activesync_state', array('sync_devid')); + $this->addIndex('horde_activesync_state', ['sync_folderid']); + $this->addIndex('horde_activesync_state', ['sync_devid']); } if (!in_array('horde_activesync_map', $this->tables())) { - $t = $this->createTable('horde_activesync_map', array('autoincrementKey' => false)); - $t->column('message_uid', 'string', array('limit' => 255, 'null' => false)); + $t = $this->createTable('horde_activesync_map', ['autoincrementKey' => false]); + $t->column('message_uid', 'string', ['limit' => 255, 'null' => false]); $t->column('sync_modtime', 'integer'); - $t->column('sync_key', 'string', array('limit' => 255, 'null' => false)); - $t->column('sync_devid', 'string', array('limit' => 255, 'null' => false)); - $t->column('sync_folderid', 'string', array('limit' => 255, 'null' => false)); - $t->column('sync_user', 'string', array('limit' => 255)); + $t->column('sync_key', 'string', ['limit' => 255, 'null' => false]); + $t->column('sync_devid', 'string', ['limit' => 255, 'null' => false]); + $t->column('sync_folderid', 'string', ['limit' => 255, 'null' => false]); + $t->column('sync_user', 'string', ['limit' => 255]); $t->end(); - $this->addIndex('horde_activesync_map', array('sync_devid')); - $this->addIndex('horde_activesync_map', array('message_uid')); - $this->addIndex('horde_activesync_map', array('sync_user')); + $this->addIndex('horde_activesync_map', ['sync_devid']); + $this->addIndex('horde_activesync_map', ['message_uid']); + $this->addIndex('horde_activesync_map', ['sync_user']); } if (!in_array('horde_activesync_device', $this->tables())) { - $t = $this->createTable('horde_activesync_device', array('autoincrementKey' => false)); - $t->column('device_id', 'string', array('limit' => 255, 'null' => false)); - $t->column('device_type', 'string', array('limit' => 255, 'null' => false)); - $t->column('device_agent', 'string', array('limit' => 255, 'null' => false)); + $t = $this->createTable('horde_activesync_device', ['autoincrementKey' => false]); + $t->column('device_id', 'string', ['limit' => 255, 'null' => false]); + $t->column('device_type', 'string', ['limit' => 255, 'null' => false]); + $t->column('device_agent', 'string', ['limit' => 255, 'null' => false]); $t->column('device_supported', 'text'); - $t->column('device_policykey', 'bigint', array('default' => 0)); + $t->column('device_policykey', 'bigint', ['default' => 0]); $t->column('device_rwstatus', 'integer'); - $t->primaryKey(array('device_id')); + $t->primaryKey(['device_id']); $t->end(); } if (!in_array('horde_activesync_device_users', $this->tables())) { - $t = $this->createTable('horde_activesync_device_users', array('autoincrementKey' => false)); - $t->column('device_id', 'string', array('limit' => 255, 'null' => false)); - $t->column('device_user', 'string', array('limit' => 255, 'null' => false)); + $t = $this->createTable('horde_activesync_device_users', ['autoincrementKey' => false]); + $t->column('device_id', 'string', ['limit' => 255, 'null' => false]); + $t->column('device_user', 'string', ['limit' => 255, 'null' => false]); $t->column('device_ping', 'text'); $t->column('device_folders', 'text'); $t->end(); - $this->addIndex('horde_activesync_device_users', array('device_user')); - $this->addIndex('horde_activesync_device_users', array('device_id')); + $this->addIndex('horde_activesync_device_users', ['device_user']); + $this->addIndex('horde_activesync_device_users', ['device_id']); } } diff --git a/migration/Horde/ActiveSync/20_horde_activesync_removesynccounters.php b/migration/Horde/ActiveSync/20_horde_activesync_removesynccounters.php index 49634e57..e20ee47f 100644 --- a/migration/Horde/ActiveSync/20_horde_activesync_removesynccounters.php +++ b/migration/Horde/ActiveSync/20_horde_activesync_removesynccounters.php @@ -1,4 +1,5 @@ _connection->update($insert_sql, array($row['cache_data'], $row['cache_devid'], $row['cache_user'])); + $this->_connection->update($insert_sql, [$row['cache_data'], $row['cache_devid'], $row['cache_user']]); } } diff --git a/migration/Horde/ActiveSync/21_horde_activesync_addmailmapchangeflag.php b/migration/Horde/ActiveSync/21_horde_activesync_addmailmapchangeflag.php index 317f5d6c..64dbf878 100644 --- a/migration/Horde/ActiveSync/21_horde_activesync_addmailmapchangeflag.php +++ b/migration/Horde/ActiveSync/21_horde_activesync_addmailmapchangeflag.php @@ -1,4 +1,5 @@ addColumn( 'horde_activesync_mailmap', 'sync_changed', - 'boolean'); + 'boolean' + ); } public function down() diff --git a/migration/Horde/ActiveSync/22_horde_activesync_addcategorymap.php b/migration/Horde/ActiveSync/22_horde_activesync_addcategorymap.php index c88e0750..347912e6 100644 --- a/migration/Horde/ActiveSync/22_horde_activesync_addcategorymap.php +++ b/migration/Horde/ActiveSync/22_horde_activesync_addcategorymap.php @@ -1,4 +1,5 @@ addColumn( 'horde_activesync_mailmap', 'sync_category', - 'string'); + 'string' + ); } public function down() @@ -14,4 +16,4 @@ public function down() $this->removeColumn('horde_activesync_mailmap', 'sync_category'); } -} \ No newline at end of file +} diff --git a/migration/Horde/ActiveSync/23_horde_activesync_addmailmapdraftflag.php b/migration/Horde/ActiveSync/23_horde_activesync_addmailmapdraftflag.php index ecb150cd..d67c8f1f 100644 --- a/migration/Horde/ActiveSync/23_horde_activesync_addmailmapdraftflag.php +++ b/migration/Horde/ActiveSync/23_horde_activesync_addmailmapdraftflag.php @@ -1,4 +1,5 @@ addColumn( 'horde_activesync_mailmap', 'sync_draft', - 'boolean'); + 'boolean' + ); } public function down() diff --git a/migration/Horde/ActiveSync/2_horde_activesync_peruserpolicykey.php b/migration/Horde/ActiveSync/2_horde_activesync_peruserpolicykey.php index b9254dab..3a6fdc27 100644 --- a/migration/Horde/ActiveSync/2_horde_activesync_peruserpolicykey.php +++ b/migration/Horde/ActiveSync/2_horde_activesync_peruserpolicykey.php @@ -1,4 +1,5 @@ 0)); + ['default' => 0] + ); $this->removeColumn('horde_activesync_device', 'device_policykey'); } @@ -17,9 +19,10 @@ public function down() 'horde_activesync_device', 'device_policykey', 'bigint', - array('default' => 0)); + ['default' => 0] + ); $this->removeColumn('horde_activesync_device_users', 'device_policykey'); } -} \ No newline at end of file +} diff --git a/migration/Horde/ActiveSync/3_horde_activesync_clientidmap.php b/migration/Horde/ActiveSync/3_horde_activesync_clientidmap.php index c57fdcd9..7e4cbf7a 100644 --- a/migration/Horde/ActiveSync/3_horde_activesync_clientidmap.php +++ b/migration/Horde/ActiveSync/3_horde_activesync_clientidmap.php @@ -1,4 +1,5 @@ 255)); + ['limit' => 255] + ); } public function down() @@ -15,4 +17,4 @@ public function down() $this->removeColumn('horde_activesync_map', 'sync_clientid'); } -} \ No newline at end of file +} diff --git a/migration/Horde/ActiveSync/4_horde_activesync_longtextstatefield.php b/migration/Horde/ActiveSync/4_horde_activesync_longtextstatefield.php index 0f241863..0fb4d423 100644 --- a/migration/Horde/ActiveSync/4_horde_activesync_longtextstatefield.php +++ b/migration/Horde/ActiveSync/4_horde_activesync_longtextstatefield.php @@ -1,4 +1,5 @@ changeColumn( 'horde_activesync_state', 'sync_data', - 'mediumtext'); + 'mediumtext' + ); } public function down() @@ -14,7 +16,8 @@ public function down() $this->changeColumn( 'horde_activesync_state', 'sync_data', - 'text'); + 'text' + ); } -} \ No newline at end of file +} diff --git a/migration/Horde/ActiveSync/5_horde_activesync_addpendingfield.php b/migration/Horde/ActiveSync/5_horde_activesync_addpendingfield.php index 82a99ef7..b99ced61 100644 --- a/migration/Horde/ActiveSync/5_horde_activesync_addpendingfield.php +++ b/migration/Horde/ActiveSync/5_horde_activesync_addpendingfield.php @@ -1,4 +1,5 @@ addColumn( 'horde_activesync_state', 'sync_pending', - 'mediumtext'); + 'mediumtext' + ); } public function down() @@ -14,4 +16,4 @@ public function down() $this->removeColumn('horde_activesync_state', 'sync_pending'); } -} \ No newline at end of file +} diff --git a/migration/Horde/ActiveSync/6_horde_activesync_addmailmap.php b/migration/Horde/ActiveSync/6_horde_activesync_addmailmap.php index 0d51450a..9c4ef789 100644 --- a/migration/Horde/ActiveSync/6_horde_activesync_addmailmap.php +++ b/migration/Horde/ActiveSync/6_horde_activesync_addmailmap.php @@ -1,21 +1,22 @@ createTable('horde_activesync_mailmap', array('autoincrementKey' => false)); - $t->column('message_uid', 'string', array('limit' => 255, 'null' => false)); - $t->column('sync_key', 'string', array('limit' => 255, 'null' => false)); - $t->column('sync_devid', 'string', array('limit' => 255, 'null' => false)); - $t->column('sync_folderid', 'string', array('limit' => 255, 'null' => false)); - $t->column('sync_user', 'string', array('limit' => 255)); + $t = $this->createTable('horde_activesync_mailmap', ['autoincrementKey' => false]); + $t->column('message_uid', 'string', ['limit' => 255, 'null' => false]); + $t->column('sync_key', 'string', ['limit' => 255, 'null' => false]); + $t->column('sync_devid', 'string', ['limit' => 255, 'null' => false]); + $t->column('sync_folderid', 'string', ['limit' => 255, 'null' => false]); + $t->column('sync_user', 'string', ['limit' => 255]); $t->column('sync_read', 'integer'); $t->column('sync_deleted', 'integer'); $t->end(); - $this->addIndex('horde_activesync_mailmap', array('message_uid')); - $this->addIndex('horde_activesync_mailmap', array('sync_devid')); - $this->addIndex('horde_activesync_mailmap', array('sync_folderid')); + $this->addIndex('horde_activesync_mailmap', ['message_uid']); + $this->addIndex('horde_activesync_mailmap', ['sync_devid']); + $this->addIndex('horde_activesync_mailmap', ['sync_folderid']); } public function down() @@ -23,4 +24,4 @@ public function down() $this->dropTable('horde_activesync_mailmap'); } -} \ No newline at end of file +} diff --git a/migration/Horde/ActiveSync/7_horde_activesync_clearstate.php b/migration/Horde/ActiveSync/7_horde_activesync_clearstate.php index eaa0dd23..aef4dc5a 100644 --- a/migration/Horde/ActiveSync/7_horde_activesync_clearstate.php +++ b/migration/Horde/ActiveSync/7_horde_activesync_clearstate.php @@ -1,4 +1,5 @@ delete('DELETE from horde_activesync_state'); - $this->delete('DELETE from horde_activesync_map'); + $this->delete('DELETE from horde_activesync_state'); + $this->delete('DELETE from horde_activesync_map'); } -} \ No newline at end of file +} diff --git a/migration/Horde/ActiveSync/8_horde_activesync_addmailflagged.php b/migration/Horde/ActiveSync/8_horde_activesync_addmailflagged.php index 7e1b4f9b..cd6ab8be 100644 --- a/migration/Horde/ActiveSync/8_horde_activesync_addmailflagged.php +++ b/migration/Horde/ActiveSync/8_horde_activesync_addmailflagged.php @@ -1,4 +1,5 @@ addColumn( 'horde_activesync_mailmap', 'sync_flagged', - 'integer'); + 'integer' + ); } public function down() @@ -14,4 +16,4 @@ public function down() $this->removeColumn('horde_activesync_mailmap', 'sync_flagged'); } -} \ No newline at end of file +} diff --git a/migration/Horde/ActiveSync/9_horde_activesync_add_cache.php b/migration/Horde/ActiveSync/9_horde_activesync_add_cache.php index 056df5d3..04c5a909 100644 --- a/migration/Horde/ActiveSync/9_horde_activesync_add_cache.php +++ b/migration/Horde/ActiveSync/9_horde_activesync_add_cache.php @@ -1,16 +1,17 @@ createTable('horde_activesync_cache', array('autoincrementKey' => false)); - $t->column('cache_devid', 'string', array('limit' => 255)); - $t->column('cache_user', 'string', array('limit' => 255)); + $t = $this->createTable('horde_activesync_cache', ['autoincrementKey' => false]); + $t->column('cache_devid', 'string', ['limit' => 255]); + $t->column('cache_user', 'string', ['limit' => 255]); $t->column('cache_data', 'text'); $t->end(); - $this->addIndex('horde_activesync_cache', array('cache_devid')); - $this->addIndex('horde_activesync_cache', array('cache_user')); + $this->addIndex('horde_activesync_cache', ['cache_devid']); + $this->addIndex('horde_activesync_cache', ['cache_user']); } public function down() diff --git a/test/Horde/ActiveSync/AllTests.php b/test/Horde/ActiveSync/AllTests.php index 1f7a9bf4..6966fde3 100644 --- a/test/Horde/ActiveSync/AllTests.php +++ b/test/Horde/ActiveSync/AllTests.php @@ -1,4 +1,5 @@ markTestIncomplete('Needs updated fixture.'); $logger = new Horde_ActiveSync_Log_Logger(new Horde_Log_Handler_Null()); - $appt = new Horde_ActiveSync_Message_Appointment(array('logger' => $logger)); + $appt = new Horde_ActiveSync_Message_Appointment(['logger' => $logger]); $appt->setSubject('Event Title'); $appt->setBody('Event Description'); $appt->setLocation('Philadelphia, PA'); $start = new Horde_Date('2011-12-01T15:00:00'); - $appt->setDatetime(array( - 'start' => $start, - 'end' => new Horde_Date('2011-12-01T16:00:00'), - 'allday' => false) + $appt->setDatetime( + [ + 'start' => $start, + 'end' => new Horde_Date('2011-12-01T16:00:00'), + 'allday' => false] ); $appt->setTimezone($start); $appt->setSensitivity(Horde_ActiveSync_Message_Appointment::SENSITIVITY_PERSONAL); @@ -81,7 +87,7 @@ public function testDecoding() $decoder->setLogger($logger); $element = $decoder->getElementStartTag(Horde_ActiveSync::SYNC_DATA); - $appt = new Horde_ActiveSync_Message_Appointment(array('logger' => $logger)); + $appt = new Horde_ActiveSync_Message_Appointment(['logger' => $logger]); $appt->decodeStream($decoder); fclose($stream); $decoder->getElementEndTag(); @@ -89,8 +95,8 @@ public function testDecoding() $this->assertEquals('Event Title', $appt->subject); $this->assertEquals('Event Description', $appt->body); $this->assertEquals('Philadelphia, PA', $appt->location); - $this->assertEquals(Horde_ActiveSync_Message_Appointment::SENSITIVITY_PERSONAL, (integer)$appt->sensitivity); - $this->assertEquals(Horde_ActiveSync_Message_Appointment::BUSYSTATUS_BUSY, (integer)$appt->busystatus); + $this->assertEquals(Horde_ActiveSync_Message_Appointment::SENSITIVITY_PERSONAL, (int) $appt->sensitivity); + $this->assertEquals(Horde_ActiveSync_Message_Appointment::BUSYSTATUS_BUSY, (int) $appt->busystatus); $start = clone($appt->starttime); // Ensure it's UTC @@ -98,7 +104,7 @@ public function testDecoding() //...and correct. $start->setTimezone('America/New_York'); - $this->assertEquals('2011-12-01 15:00:00', (string)$start); + $this->assertEquals('2011-12-01 15:00:00', (string) $start); } public function testEncodingRecurrence() @@ -112,15 +118,16 @@ public function testEncodingRecurrence() $r->setRecurInterval(2); $r->setRecurOnDay(Horde_Date::MASK_THURSDAY); - $appt = new Horde_ActiveSync_Message_Appointment(array('logger' => $logger)); + $appt = new Horde_ActiveSync_Message_Appointment(['logger' => $logger]); $appt->setSubject('Event Title'); $appt->setBody('Event Description'); $appt->setLocation('Philadelphia, PA'); $start = new Horde_Date('2011-12-01T15:00:00'); - $appt->setDatetime(array( - 'start' => $start, - 'end' => new Horde_Date('2011-12-01T16:00:00'), - 'allday' => false) + $appt->setDatetime( + [ + 'start' => $start, + 'end' => new Horde_Date('2011-12-01T16:00:00'), + 'allday' => false] ); $appt->setTimezone($start); $appt->setSensitivity(Horde_ActiveSync_Message_Appointment::SENSITIVITY_PERSONAL); @@ -151,7 +158,7 @@ public function testDecodingRecurrence() $decoder = new Horde_ActiveSync_Wbxml_Decoder($stream); $element = $decoder->getElementStartTag(Horde_ActiveSync::SYNC_DATA); - $appt = new Horde_ActiveSync_Message_Appointment(array('logger' => $logger)); + $appt = new Horde_ActiveSync_Message_Appointment(['logger' => $logger]); $appt->decodeStream($decoder); fclose($stream); $decoder->getElementEndTag(); @@ -161,19 +168,19 @@ public function testDecodingRecurrence() $this->assertEquals('Event Title', $appt->subject); $this->assertEquals('Event Description', $appt->body); $this->assertEquals('Philadelphia, PA', $appt->location); - $this->assertEquals(Horde_ActiveSync_Message_Appointment::SENSITIVITY_PERSONAL, (integer)$appt->sensitivity); - $this->assertEquals(Horde_ActiveSync_Message_Appointment::BUSYSTATUS_BUSY, (integer)$appt->busystatus); + $this->assertEquals(Horde_ActiveSync_Message_Appointment::SENSITIVITY_PERSONAL, (int) $appt->sensitivity); + $this->assertEquals(Horde_ActiveSync_Message_Appointment::BUSYSTATUS_BUSY, (int) $appt->busystatus); $start = clone($appt->starttime); // Ensure it's UTC $this->assertEquals('UTC', $start->timezone); //...and correct. $start->setTimezone('America/New_York'); - $this->assertEquals('2011-12-01 15:00:00', (string)$start); + $this->assertEquals('2011-12-01 15:00:00', (string) $start); // Recurrence properties $rrule = $appt->getRecurrence(); - $this->assertEquals('2011-12-01 15:00:00', (string)$rrule->getRecurStart()->setTimezone('America/New_York')); - $this->assertEquals('', (string)$rrule->getRecurEnd()); + $this->assertEquals('2011-12-01 15:00:00', (string) $rrule->getRecurStart()->setTimezone('America/New_York')); + $this->assertEquals('', (string) $rrule->getRecurEnd()); $this->assertEquals(Horde_Date_Recurrence::RECUR_WEEKLY, $rrule->getRecurType()); $this->assertEquals(2, $rrule->getRecurInterval()); $this->assertEquals(Horde_Date::MASK_THURSDAY, $days = $rrule->getRecurOnDays()); @@ -196,15 +203,16 @@ public function testEncodingSimpleExceptions() $e->setExceptionStartTime($d); $e->deleted = true; - $appt = new Horde_ActiveSync_Message_Appointment(array('logger' => $logger)); + $appt = new Horde_ActiveSync_Message_Appointment(['logger' => $logger]); $appt->setSubject('Event Title'); $appt->setBody('Event Description'); $appt->setLocation('Philadelphia, PA'); $start = new Horde_Date('2011-12-01T15:00:00'); - $appt->setDatetime(array( - 'start' => $start, - 'end' => new Horde_Date('2011-12-01T16:00:00'), - 'allday' => false) + $appt->setDatetime( + [ + 'start' => $start, + 'end' => new Horde_Date('2011-12-01T16:00:00'), + 'allday' => false] ); $appt->setTimezone($start); $appt->setSensitivity(Horde_ActiveSync_Message_Appointment::SENSITIVITY_PERSONAL); @@ -236,7 +244,7 @@ public function testAlldayEncoding() $stream_out = fopen('php://memory', 'w+'); $encoder = new Horde_ActiveSync_Wbxml_Encoder($stream_out); $message = new Horde_ActiveSync_Message_Appointment( - array('logger' => $logger, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN) + ['logger' => $logger, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN] ); $message->setSubject('Test Event'); $message->alldayevent = true; @@ -255,7 +263,7 @@ public function testAlldayEncoding() // Make sure EAS versions work properly. rewind($stream_out); $message = new Horde_ActiveSync_Message_Appointment( - array('logger' => $logger, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN) + ['logger' => $logger, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN] ); $decoder = new Horde_ActiveSync_Wbxml_Decoder($stream_out); $decoder->getElementStartTag(Horde_ActiveSync::SYNC_DATA); @@ -263,12 +271,12 @@ public function testAlldayEncoding() $end = $message->endtime; $end->setTimezone('America/New_York'); $start->setTimezone('America/New_York'); - $this->assertEquals('1970-03-21 00:00:00', (string)$end); - $this->assertEquals('1970-03-20 00:00:00', (string)$start); + $this->assertEquals('1970-03-21 00:00:00', (string) $end); + $this->assertEquals('1970-03-20 00:00:00', (string) $start); rewind($stream_out); $message = new Horde_ActiveSync_Message_Appointment( - array('logger' => $logger, 'protocolversion' => Horde_ActiveSync::VERSION_SIXTEEN) + ['logger' => $logger, 'protocolversion' => Horde_ActiveSync::VERSION_SIXTEEN] ); $decoder = new Horde_ActiveSync_Wbxml_Decoder($stream_out); $decoder->getElementStartTag(Horde_ActiveSync::SYNC_DATA); @@ -276,8 +284,8 @@ public function testAlldayEncoding() $end = $message->endtime; $end->setTimezone('America/New_York'); $start->setTimezone('America/New_York'); - $this->assertEquals('1970-03-21 00:00:00', (string)$end); - $this->assertEquals('1970-03-20 00:00:00', (string)$start); + $this->assertEquals('1970-03-21 00:00:00', (string) $end); + $this->assertEquals('1970-03-20 00:00:00', (string) $start); } /** @@ -291,90 +299,90 @@ public function testSetDatetimeAlldayHandling() // and set properties. // Single day 00:00 to 00:00 $message = new Horde_ActiveSync_Message_Appointment( - array('logger' => $logger, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN) + ['logger' => $logger, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN] ); $start = new Horde_Date('1970-03-20T00:00:00', 'America/New_York'); $end = new Horde_Date('1970-03-21T00:00:00', 'America/New_York'); - $message->setDatetime(array('start' => $start, 'end' => $end)); + $message->setDatetime(['start' => $start, 'end' => $end]); $this->assertEquals(true, $message->alldayevent); // Multiday 00:00 to 23:59 $message = new Horde_ActiveSync_Message_Appointment( - array('logger' => $logger, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN) + ['logger' => $logger, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN] ); $start = new Horde_Date('1970-03-20T00:00:00', 'America/New_York'); $end = new Horde_Date('1970-03-21T23:59:00', 'America/New_York'); - $message->setDatetime(array('start' => $start, 'end' => $end)); + $message->setDatetime(['start' => $start, 'end' => $end]); $this->assertEquals(true, $message->alldayevent); $end = $message->endtime; $end->setTimezone('America/New_York'); - $this->assertEquals('1970-03-22 00:00:00', (string)$end); + $this->assertEquals('1970-03-22 00:00:00', (string) $end); // Single day with incorrect time part, no endtime given. $message = new Horde_ActiveSync_Message_Appointment( - array('logger' => $logger, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN) + ['logger' => $logger, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN] ); $start = new Horde_Date('1970-03-20T04:00:00', 'America/New_York'); - $message->setDatetime(array('start' => $start, 'allday' => true)); + $message->setDatetime(['start' => $start, 'allday' => true]); $this->assertEquals(true, $message->alldayevent); $start = $message->starttime; $start->setTimezone('America/New_York'); - $this->assertEquals('1970-03-20 00:00:00', (string)$start); + $this->assertEquals('1970-03-20 00:00:00', (string) $start); $end = $message->endtime; $end->setTimezone('America/New_York'); - $this->assertEquals('1970-03-21 00:00:00', (string)$end); + $this->assertEquals('1970-03-21 00:00:00', (string) $end); // Single day, no endtime given. $message = new Horde_ActiveSync_Message_Appointment( - array('logger' => $logger, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN) + ['logger' => $logger, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN] ); $start = new Horde_Date('1970-03-20T00:00:00', 'America/New_York'); - $message->setDatetime(array('start' => $start, 'allday' => true)); + $message->setDatetime(['start' => $start, 'allday' => true]); $this->assertEquals(true, $message->alldayevent); $end = $message->endtime; $end->setTimezone('America/New_York'); - $this->assertEquals('1970-03-21 00:00:00', (string)$end); + $this->assertEquals('1970-03-21 00:00:00', (string) $end); // Make sure non-all day events don't inadvertently get converted to one $message = new Horde_ActiveSync_Message_Appointment( - array('logger' => $logger, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN) + ['logger' => $logger, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN] ); $start = new Horde_Date('1970-03-20T05:00:00', 'America/New_York'); $end = new Horde_Date('1970-03-21T00:00:00', 'America/New_York'); - $message->setDatetime(array('start' => $start, 'end' => $end)); + $message->setDatetime(['start' => $start, 'end' => $end]); $this->assertEquals(false, $message->alldayevent); $start = $message->starttime; $start->setTimezone('America/New_York'); - $this->assertEquals('1970-03-20 05:00:00', (string)$start); + $this->assertEquals('1970-03-20 05:00:00', (string) $start); // Incorrect timeparts given, but allday flag is set. $message = new Horde_ActiveSync_Message_Appointment( - array('logger' => $logger, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN) + ['logger' => $logger, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN] ); $start = new Horde_Date('1970-03-20T00:00:00', 'America/New_York'); $end = new Horde_Date('1970-03-21T05:00:00', 'America/New_York'); - $message->setDatetime(array('start' => $start, 'end' => $end, 'allday' => true)); + $message->setDatetime(['start' => $start, 'end' => $end, 'allday' => true]); $this->assertEquals(true, $message->alldayevent); $start = $message->starttime; $start->setTimezone('America/New_York'); $end = $message->endtime; $end->setTimezone('America/New_York'); - $this->assertEquals('1970-03-20 00:00:00', (string)$start); - $this->assertEquals('1970-03-22 00:00:00', (string)$end); + $this->assertEquals('1970-03-20 00:00:00', (string) $start); + $this->assertEquals('1970-03-22 00:00:00', (string) $end); $message = new Horde_ActiveSync_Message_Appointment( - array('logger' => $logger, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN) + ['logger' => $logger, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN] ); $start = new Horde_Date('1970-03-20T08:00:00', 'America/New_York'); $end = new Horde_Date('1970-03-21T05:00:00', 'America/New_York'); - $message->setDatetime(array('start' => $start, 'end' => $end, 'allday' => true)); + $message->setDatetime(['start' => $start, 'end' => $end, 'allday' => true]); $this->assertEquals(true, $message->alldayevent); $start = $message->starttime; $start->setTimezone('America/New_York'); $end = $message->endtime; $end->setTimezone('America/New_York'); - $this->assertEquals('1970-03-20 00:00:00', (string)$start); - $this->assertEquals('1970-03-22 00:00:00', (string)$end); + $this->assertEquals('1970-03-20 00:00:00', (string) $start); + $this->assertEquals('1970-03-22 00:00:00', (string) $end); } public function testDecodingSimpleExceptions() @@ -386,7 +394,7 @@ public function testDecodingSimpleExceptions() $decoder = new Horde_ActiveSync_Wbxml_Decoder($stream); $element = $decoder->getElementStartTag(Horde_ActiveSync::SYNC_DATA); - $appt = new Horde_ActiveSync_Message_Appointment(array('logger' => $logger)); + $appt = new Horde_ActiveSync_Message_Appointment(['logger' => $logger]); $appt->decodeStream($decoder); fclose($stream); $decoder->getElementEndTag(); @@ -396,19 +404,19 @@ public function testDecodingSimpleExceptions() $this->assertEquals('Event Title', $appt->subject); $this->assertEquals('Event Description', $appt->body); $this->assertEquals('Philadelphia, PA', $appt->location); - $this->assertEquals(Horde_ActiveSync_Message_Appointment::SENSITIVITY_PERSONAL, (integer)$appt->sensitivity); - $this->assertEquals(Horde_ActiveSync_Message_Appointment::BUSYSTATUS_BUSY, (integer)$appt->busystatus); + $this->assertEquals(Horde_ActiveSync_Message_Appointment::SENSITIVITY_PERSONAL, (int) $appt->sensitivity); + $this->assertEquals(Horde_ActiveSync_Message_Appointment::BUSYSTATUS_BUSY, (int) $appt->busystatus); $start = clone($appt->starttime); // Ensure it's UTC $this->assertEquals('UTC', $start->timezone); //...and correct. $start->setTimezone('America/New_York'); - $this->assertEquals('2011-12-01 15:00:00', (string)$start); + $this->assertEquals('2011-12-01 15:00:00', (string) $start); // Recurrence properties $rrule = $appt->getRecurrence(); - $this->assertEquals('2011-12-01 15:00:00', (string)$rrule->getRecurStart()->setTimezone('America/New_York')); - $this->assertEquals('', (string)$rrule->getRecurEnd()); + $this->assertEquals('2011-12-01 15:00:00', (string) $rrule->getRecurStart()->setTimezone('America/New_York')); + $this->assertEquals('', (string) $rrule->getRecurEnd()); $this->assertEquals(Horde_Date_Recurrence::RECUR_WEEKLY, $rrule->getRecurType()); $this->assertEquals(2, $rrule->getRecurInterval()); $this->assertEquals(Horde_Date::MASK_THURSDAY, $days = $rrule->getRecurOnDays()); @@ -418,13 +426,13 @@ public function testDecodingSimpleExceptions() // on 2011-12-29) $exceptions = $appt->getExceptions(); $e = array_pop($exceptions); - $this->assertEquals(true, (boolean)$e->deleted); + $this->assertEquals(true, (bool) $e->deleted); $dt = $e->getExceptionStartTime(); $rrule->addException($dt->format('Y'), $dt->format('m'), $dt->format('d')); // This would normally be 2011-12-29, but that's an exception. $date = $rrule->nextActiveRecurrence(new Horde_Date('2011-12-16')); - $this->assertEquals('2012-01-12 15:00:00', (string)$date); + $this->assertEquals('2012-01-12 15:00:00', (string) $date); } public function testRecurrenceDSTSwitch() @@ -437,7 +445,7 @@ public function testRecurrenceDSTSwitch() $decoder = new Horde_ActiveSync_Wbxml_Decoder($stream); $element = $decoder->getElementStartTag(Horde_ActiveSync::SYNC_DATA); - $appt = new Horde_ActiveSync_Message_Appointment(array('logger' => $logger)); + $appt = new Horde_ActiveSync_Message_Appointment(['logger' => $logger]); $appt->decodeStream($decoder); fclose($stream); $decoder->getElementEndTag(); @@ -445,29 +453,29 @@ public function testRecurrenceDSTSwitch() // Get the next recurrence, still during EDST $next = $rrule->nextActiveRecurrence(new Horde_Date('2011-10-15')); - $this->assertEquals('2011-10-15 15:00:00', (string)$next->setTimezone('America/New_York')); + $this->assertEquals('2011-10-15 15:00:00', (string) $next->setTimezone('America/New_York')); // Now get an occurence after the transition to EST. $next = $rrule->nextActiveRecurrence(new Horde_Date('2011-12-01')); - $this->assertEquals('2011-12-10 15:00:00', (string)$next->setTimezone('America/New_York')); + $this->assertEquals('2011-12-10 15:00:00', (string) $next->setTimezone('America/New_York')); } public function testMissingSupportedTag() { $state = $this->getMockBuilder('Horde_ActiveSync_State_Base')->disableOriginalConstructor()->getMock(); - $fixture = array( + $fixture = [ 'userAgent' => 'Apple-iPad3C6/1202.435', - 'properties' => array(Horde_ActiveSync_Device::OS => 'iOS 8.1.1') - ); + 'properties' => [Horde_ActiveSync_Device::OS => 'iOS 8.1.1'], + ]; $device = new Horde_ActiveSync_Device($state, $fixture); - $contact = new Horde_ActiveSync_Message_Appointment(array('device' => $device, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN)); - $contact->setSupported(array()); + $contact = new Horde_ActiveSync_Message_Appointment(['device' => $device, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN]); + $contact->setSupported([]); $this->assertEquals(false, $contact->isGhosted('subject')); $this->assertEquals(false, $contact->isGhosted('body')); $device = new Horde_ActiveSync_Device($state, $fixture); - $contact = new Horde_ActiveSync_Message_Appointment(array('device' => $device, 'protocolversion' => Horde_ActiveSync::VERSION_SIXTEEN)); - $contact->setSupported(array()); + $contact = new Horde_ActiveSync_Message_Appointment(['device' => $device, 'protocolversion' => Horde_ActiveSync::VERSION_SIXTEEN]); + $contact->setSupported([]); $this->assertEquals(true, $contact->isGhosted('subject')); $this->assertEquals(true, $contact->isGhosted('body')); } @@ -475,19 +483,19 @@ public function testMissingSupportedTag() public function testEmptySupportedTag() { $state = $this->getMockBuilder('Horde_ActiveSync_State_Base')->disableOriginalConstructor()->getMock(); - $fixture = array( + $fixture = [ 'userAgent' => 'Apple-iPad3C6/1202.435', - 'properties' => array(Horde_ActiveSync_Device::OS => 'iOS 8.1.1') - ); + 'properties' => [Horde_ActiveSync_Device::OS => 'iOS 8.1.1'], + ]; $device = new Horde_ActiveSync_Device($state, $fixture); - $contact = new Horde_ActiveSync_Message_Appointment(array('device' => $device, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN)); - $contact->setSupported(array(Horde_ActiveSync::ALL_GHOSTED)); + $contact = new Horde_ActiveSync_Message_Appointment(['device' => $device, 'protocolversion' => Horde_ActiveSync::VERSION_FOURTEEN]); + $contact->setSupported([Horde_ActiveSync::ALL_GHOSTED]); $this->assertEquals(true, $contact->isGhosted('subject')); $this->assertEquals(true, $contact->isGhosted('body')); $device = new Horde_ActiveSync_Device($state, $fixture); - $contact = new Horde_ActiveSync_Message_Appointment(array('device' => $device, 'protocolversion' => Horde_ActiveSync::VERSION_SIXTEEN)); - $contact->setSupported(array(Horde_ActiveSync::ALL_GHOSTED)); + $contact = new Horde_ActiveSync_Message_Appointment(['device' => $device, 'protocolversion' => Horde_ActiveSync::VERSION_SIXTEEN]); + $contact->setSupported([Horde_ActiveSync::ALL_GHOSTED]); $this->assertEquals(true, $contact->isGhosted('subject')); $this->assertEquals(true, $contact->isGhosted('body')); } diff --git a/test/Horde/ActiveSync/AutodiscoverTest.php b/test/Horde/ActiveSync/AutodiscoverTest.php index 8a6f8420..1498fe0b 100644 --- a/test/Horde/ActiveSync/AutodiscoverTest.php +++ b/test/Horde/ActiveSync/AutodiscoverTest.php @@ -1,4 +1,5 @@ markTestSkipped('Requires horde/controller package and complex mock setup'); + $factory = new TestServer(); + + $request = << + + + mike@example.com + + http://schemas.microsoft.com/exchange/autodiscover/mobilesync/responseschema/2006 + + + + EOT; + fwrite($factory->input, $request); + rewind($factory->input); + + // Mock the getUsernameFromEmail method to return 'mike' when 'mike@example.com' + // is passed. + $factory->driver->expects($this->once()) + ->method('getUsernameFromEmail') + ->will($this->returnValueMap([['mike@example.com', 'mike']])); + + // Mock authenticate to return true only if mike is passed as username. + $factory->driver->expects($this->any()) + ->method('authenticate') + ->will($this->returnValueMap([['mike', 'password', null, true]])); + + // Setup is called once, and must return true. + $factory->driver->expects($this->once()) + ->method('setup') + ->will($this->returnValue(true)); + + // Checks that the correct schema was detected. + $mock_driver_parameters = [ + 'request_schema' => 'http://schemas.microsoft.com/exchange/autodiscover/mobilesync/requestschema/2006', + 'response_schema' => 'http://schemas.microsoft.com/exchange/autodiscover/mobilesync/responseschema/2006']; + + // ...and will only return this if it was. + $mock_driver_results = [ + 'display_name' => 'Michael Rubinsky', + 'email' => 'mike@example.com', + 'culture' => 'en:en', + 'username' => 'mike', + 'url' => 'https://example.com/Microsoft-Server-ActiveSync', + ]; + + $factory->driver->expects($this->once()) + ->method('autoDiscover') + ->will($this->returnValueMap([[$mock_driver_parameters, $mock_driver_results]])); + + $factory->server->handleRequest('Autodiscover', 'testdevice'); + + // Test the results + $expected = << + + + en:en + + Michael Rubinsky + mike@example.com + + + + + MobileSync + https://example.com/Microsoft-Server-ActiveSync + https://example.com/Microsoft-Server-ActiveSync + + + + + + EOT; + $factory->server->encoder->getStream()->rewind(); + $this->assertEquals($expected, $factory->server->encoder->getStream()->getString()); } /** @@ -28,7 +110,74 @@ public function testAutodiscoverWithProperXML() */ public function testAutodiscoverWithMissingXML() { - $this->markTestSkipped('Requires horde/controller package and complex mock setup'); + // Basic auth: mike:password + $auth = 'Basic bWlrZTpwYXNzd29yZA=='; + $factory = new TestServer(); + $factory->request->expects($this->any()) + ->method('getServerVars') + ->will($this->returnValue(['HTTP_AUTHORIZATION' => $auth])); + + // Mock the getUsernameFromEmail method to return 'mike' when 'mike' + // is passed. + $factory->driver->expects($this->once()) + ->method('getUsernameFromEmail') + ->will($this->returnValueMap([['mike', 'mike']])); + + // Mock authenticate to return true only if 'mike' is passed as username + // and 'password' is passed as the password. + $factory->driver->expects($this->any()) + ->method('authenticate') + ->will($this->returnValueMap([['mike', 'password', null, true]])); + + // Setup is called once, and must return true. + $factory->driver->expects($this->once()) + ->method('setup') + ->will($this->returnValue(true)); + + // Checks that the correct schema was detected. + $mock_driver_parameters = [ + 'request_schema' => 'http://schemas.microsoft.com/exchange/autodiscover/mobilesync/requestschema/2006', + 'response_schema' => 'http://schemas.microsoft.com/exchange/autodiscover/mobilesync/responseschema/2006']; + + // ...and will only return this if it was. + $mock_driver_results = [ + 'display_name' => 'Michael Rubinsky', + 'email' => 'mike@example.com', + 'culture' => 'en:en', + 'username' => 'mike', + 'url' => 'https://example.com/Microsoft-Server-ActiveSync', + ]; + + $factory->driver->expects($this->once()) + ->method('autoDiscover') + ->will($this->returnValueMap([[$mock_driver_parameters, $mock_driver_results]])); + + $factory->server->handleRequest('Autodiscover', 'testdevice'); + + // Test the results + $expected = << + + + en:en + + Michael Rubinsky + mike@example.com + + + + + MobileSync + https://example.com/Microsoft-Server-ActiveSync + https://example.com/Microsoft-Server-ActiveSync + + + + + + EOT; + $factory->server->encoder->getStream()->rewind(); + $this->assertEquals($expected, $factory->server->encoder->getStream()->getString()); } } diff --git a/test/Horde/ActiveSync/CacheTest.php b/test/Horde/ActiveSync/CacheTest.php index eb5f988e..b52b9d6e 100644 --- a/test/Horde/ActiveSync/CacheTest.php +++ b/test/Horde/ActiveSync/CacheTest.php @@ -1,4 +1,5 @@ _state = $this->getMockBuilder('Horde_ActiveSync_State_Sql')->disableOriginalConstructor()->getMock(); - $this->_state->expects($this->any())->method('getSyncCache')->willReturn($this->_fixture); + $this->_state->expects($this->any())->method('getSyncCache')->will($this->returnValue($this->_fixture)); } public function testPropertyAccess() @@ -43,9 +49,9 @@ public function testValidProperties() { $cache = new Horde_ActiveSync_SyncCache($this->_state, 'devid', 'userone'); $cache->save(); - foreach (array('hbinterval', 'wait', 'hierarchy', 'confirmed_synckeys', + foreach (['hbinterval', 'wait', 'hierarchy', 'confirmed_synckeys', 'lasthbsyncstarted', 'lastsyncendnormal', 'folders', 'pingheartbeat', - 'timestamp') as $p) { + 'timestamp'] as $p) { $cache->{$p}; } @@ -61,4 +67,4 @@ public function testValidateTimestamps() $this->assertEquals(false, $cache->validateTimestamps()); } -} \ No newline at end of file +} diff --git a/test/Horde/ActiveSync/ContactTest.php b/test/Horde/ActiveSync/ContactTest.php index 4e2b5994..2cfe4eb3 100644 --- a/test/Horde/ActiveSync/ContactTest.php +++ b/test/Horde/ActiveSync/ContactTest.php @@ -1,4 +1,5 @@ getMockBuilder('Horde_ActiveSync_State_Base')->disableOriginalConstructor()->getMock(); - $fixture = array( + $fixture = [ 'deviceType' => 'iPod', - 'userAgent' => 'Apple-iPod2C1/803.148' - ); + 'userAgent' => 'Apple-iPod2C1/803.148', + ]; $device = new Horde_ActiveSync_Device($state, $fixture); - $contact = new Horde_ActiveSync_Message_Contact(array('device' => $device)); - $contact->setSupported(array()); + $contact = new Horde_ActiveSync_Message_Contact(['device' => $device]); + $contact->setSupported([]); $this->assertEquals(true, $contact->isGhosted('picture')); - $fixture = array( + $fixture = [ 'deviceType' => 'iPad', 'userAgent' => 'Apple-iPad3C6/1202.435', - 'properties' => array(Horde_ActiveSync_Device::OS => 'iOS 8.1.1') - ); + 'properties' => [Horde_ActiveSync_Device::OS => 'iOS 8.1.1'], + ]; $device = new Horde_ActiveSync_Device($state, $fixture); - $contact = new Horde_ActiveSync_Message_Contact(array('device' => $device)); - $contact->setSupported(array()); + $contact = new Horde_ActiveSync_Message_Contact(['device' => $device]); + $contact->setSupported([]); $this->assertEquals(false, $contact->isGhosted('picture')); } public function testMissingSupportedTag() { $state = $this->getMockBuilder('Horde_ActiveSync_State_Base')->disableOriginalConstructor()->getMock(); - $fixture = array( + $fixture = [ 'userAgent' => 'Apple-iPad3C6/1202.435', - 'properties' => array(Horde_ActiveSync_Device::OS => 'iOS 8.1.1') - ); + 'properties' => [Horde_ActiveSync_Device::OS => 'iOS 8.1.1'], + ]; $device = new Horde_ActiveSync_Device($state, $fixture); - $contact = new Horde_ActiveSync_Message_Contact(array('device' => $device)); - $contact->setSupported(array()); + $contact = new Horde_ActiveSync_Message_Contact(['device' => $device]); + $contact->setSupported([]); $this->assertEquals(false, $contact->isGhosted('fileas')); } public function testEmptySupportedTag() { $state = $this->getMockBuilder('Horde_ActiveSync_State_Base')->disableOriginalConstructor()->getMock(); - $fixture = array( + $fixture = [ 'userAgent' => 'Apple-iPad3C6/1202.435', - 'properties' => array(Horde_ActiveSync_Device::OS => 'iOS 8.1.1') - ); + 'properties' => [Horde_ActiveSync_Device::OS => 'iOS 8.1.1'], + ]; $device = new Horde_ActiveSync_Device($state, $fixture); - $contact = new Horde_ActiveSync_Message_Contact(array('device' => $device)); - $contact->setSupported(array(Horde_ActiveSync::ALL_GHOSTED)); + $contact = new Horde_ActiveSync_Message_Contact(['device' => $device]); + $contact->setSupported([Horde_ActiveSync::ALL_GHOSTED]); $this->assertEquals(true, $contact->isGhosted('fileas')); } diff --git a/test/Horde/ActiveSync/DeviceTest.php b/test/Horde/ActiveSync/DeviceTest.php index b5bea007..78227765 100644 --- a/test/Horde/ActiveSync/DeviceTest.php +++ b/test/Horde/ActiveSync/DeviceTest.php @@ -1,4 +1,5 @@ getMockBuilder('Horde_ActiveSync_State_Base')->disableOriginalConstructor()->getMock(); - $fixture = array( + $fixture = [ 'deviceType' => 'iPod', 'userAgent' => 'Apple-iPod5C1/1102.55400001', - 'properties' => array(Horde_ActiveSync_Device::OS => 'iOS 7.0.4') - ); + 'properties' => [Horde_ActiveSync_Device::OS => 'iOS 7.0.4'], + ]; $device = new Horde_ActiveSync_Device($state, $fixture); $this->assertEquals(7, $device->getMajorVersion()); $this->assertEquals(0, $device->getMinorVersion()); $this->assertEquals(Horde_ActiveSync_Device::TYPE_IPOD, Horde_String::lower($device->deviceType)); $this->assertEquals(Horde_ActiveSync_Device::MULTIPLEX_NOTES, $device->multiplex); - $fixture = array( + $fixture = [ 'deviceType' => 'iPhone', - 'userAgent' => 'iOS/1002.329' - ); + 'userAgent' => 'iOS/1002.329', + ]; $device = new Horde_ActiveSync_Device($state, $fixture); $this->assertEquals(6, $device->getMajorVersion()); $this->assertEquals(1, $device->getMinorVersion()); @@ -40,42 +46,42 @@ public function testDeviceDetection() $this->assertEquals(Horde_ActiveSync_Device::MULTIPLEX_NOTES, $device->multiplex); $this->assertEquals(false, $device->hasQuirk(Horde_ActiveSync_Device::QUIRK_NEEDS_SUPPORTED_PICTURE_TAG)); - $fixture = array( + $fixture = [ 'deviceType' => 'iPod', - 'userAgent' => 'Apple-iPod2C1/803.148' - ); + 'userAgent' => 'Apple-iPod2C1/803.148', + ]; $device = new Horde_ActiveSync_Device($state, $fixture); $this->assertEquals(4, $device->getMajorVersion()); $this->assertEquals(2, $device->getMinorVersion()); $this->assertEquals(true, $device->hasQuirk(Horde_ActiveSync_Device::QUIRK_NEEDS_SUPPORTED_PICTURE_TAG)); - $fixture = array( + $fixture = [ 'deviceType' => 'iPad', 'userAgent' => 'Apple-iPad3C6/1202.435', - 'properties' => array(Horde_ActiveSync_Device::OS => 'iOS 8.1.1') - ); + 'properties' => [Horde_ActiveSync_Device::OS => 'iOS 8.1.1'], + ]; $device = new Horde_ActiveSync_Device($state, $fixture); $this->assertEquals(8, $device->getMajorVersion()); $this->assertEquals(1, $device->getMinorVersion()); $this->assertEquals(Horde_ActiveSync_Device::TYPE_IPAD, Horde_String::lower($device->deviceType)); $this->assertEquals(Horde_ActiveSync_Device::MULTIPLEX_NOTES, $device->multiplex); - $fixture = array( + $fixture = [ 'deviceType' => 'iPad', 'userAgent' => 'Apple-iPad4C5/1206.69', - 'properties' => array(Horde_ActiveSync_Device::OS => 'iOS 8.3 12F69') - ); + 'properties' => [Horde_ActiveSync_Device::OS => 'iOS 8.3 12F69'], + ]; $device = new Horde_ActiveSync_Device($state, $fixture); $this->assertEquals(8, $device->getMajorVersion()); $this->assertEquals(3, $device->getMinorVersion()); $this->assertEquals(Horde_ActiveSync_Device::TYPE_IPAD, Horde_String::lower($device->deviceType)); $this->assertEquals(Horde_ActiveSync_Device::MULTIPLEX_NOTES, $device->multiplex); - $fixture = array( + $fixture = [ 'deviceType' => 'iPhone', 'userAgent' => 'Apple-iPhone6C1/1104.201', - 'properties' => array(Horde_ActiveSync_Device::OS => 'iOS 9.0.2 13A452') - ); + 'properties' => [Horde_ActiveSync_Device::OS => 'iOS 9.0.2 13A452'], + ]; $device = new Horde_ActiveSync_Device($state, $fixture); $this->assertEquals(9, $device->getMajorVersion()); $this->assertEquals(0, $device->getMinorVersion()); @@ -84,23 +90,23 @@ public function testDeviceDetection() // Old Android. - $fixture = array( - 'userAgent' => 'Android/0.3', - 'deviceType' => 'Android'); + $fixture = [ + 'userAgent' => 'Android/0.3', + 'deviceType' => 'Android']; $device = new Horde_ActiveSync_Device($state, $fixture); $this->assertEquals(0, $device->getMajorVersion()); $this->assertEquals(3, $device->getMinorVersion()); $this->assertEquals(Horde_ActiveSync_Device::TYPE_ANDROID, Horde_String::lower($device->deviceType)); $this->assertEquals(Horde_ActiveSync_Device::TYPE_ANDROID, Horde_String::lower($device->clientType)); - $this->assertEquals(Horde_ActiveSync_Device::MULTIPLEX_CONTACTS | - Horde_ActiveSync_Device::MULTIPLEX_CALENDAR | - Horde_ActiveSync_Device::MULTIPLEX_NOTES | - Horde_ActiveSync_Device::MULTIPLEX_TASKS, $device->multiplex); + $this->assertEquals(Horde_ActiveSync_Device::MULTIPLEX_CONTACTS + | Horde_ActiveSync_Device::MULTIPLEX_CALENDAR + | Horde_ActiveSync_Device::MULTIPLEX_NOTES + | Horde_ActiveSync_Device::MULTIPLEX_TASKS, $device->multiplex); // Touchdown client on Android. - $fixture = array( - 'userAgent' => 'TouchDown(MSRPC)/7.1.0005', - 'deviceType' => 'Android'); + $fixture = [ + 'userAgent' => 'TouchDown(MSRPC)/7.1.0005', + 'deviceType' => 'Android']; $device = new Horde_ActiveSync_Device($state, $fixture); $this->assertEquals(7, $device->getMajorVersion()); $this->assertEquals(1, $device->getMinorVersion()); @@ -109,9 +115,9 @@ public function testDeviceDetection() $this->assertEquals(0, $device->multiplex); // Not-so-old-but-still-old Android. - $fixture = array( - 'userAgent' => 'MOTOROLA-Droid(4D6F7869SAM)/2.1707', - 'deviceType' => 'Android'); + $fixture = [ + 'userAgent' => 'MOTOROLA-Droid(4D6F7869SAM)/2.1707', + 'deviceType' => 'Android']; $device = new Horde_ActiveSync_Device($state, $fixture); $this->assertEquals(2, $device->getMajorVersion()); $this->assertEquals(1707, $device->getMinorVersion()); @@ -121,11 +127,11 @@ public function testDeviceDetection() // KK Android (taken from SDK). - $fixture = array( + $fixture = [ 'userAgent' => 'Android/4.4.2-EAS-1.3', 'deviceType' => 'Android', - 'properties' => array(Horde_ActiveSync_Device::OS => 'Android 4.4.2') - ); + 'properties' => [Horde_ActiveSync_Device::OS => 'Android 4.4.2'], + ]; $device = new Horde_ActiveSync_Device($state, $fixture); $this->assertEquals(4, $device->getMajorVersion()); $this->assertEquals(4, $device->getMinorVersion()); @@ -136,11 +142,11 @@ public function testDeviceDetection() // Devices like this (from a Note 3) we simply can't sniff multiplex for // since there is no version string. Stuff like this would go in the // hook. - $fixture = array( + $fixture = [ 'deviceType' => 'SAMSUNGSMN900V', 'userAgent' => 'SAMSUNG-SM-N900V/101.403', - 'properties' => array(Horde_ActiveSync_Device::OS => 'Android') - ); + 'properties' => [Horde_ActiveSync_Device::OS => 'Android'], + ]; $device = new Horde_ActiveSync_Device($state, $fixture); // These are useless values, but still tests the reliability of the code $this->assertEquals(101, $device->getMajorVersion()); @@ -150,11 +156,11 @@ public function testDeviceDetection() $this->assertEquals(15, $device->multiplex); // Nine (From Note 3 running 4.4.2). - $fixture = array( + $fixture = [ 'deviceType' => 'Android', 'userAgent' => 'hltevzw/KOT49H', - 'properties' => array(Horde_ActiveSync_Device::OS => 'Android 4.4.2.N900VVRUCNC4') - ); + 'properties' => [Horde_ActiveSync_Device::OS => 'Android 4.4.2.N900VVRUCNC4'], + ]; $device = new Horde_ActiveSync_Device($state, $fixture); $device->id = '6E696E656331393035333833303331'; @@ -164,11 +170,11 @@ public function testDeviceDetection() $this->assertEquals(0, $device->multiplex); // HTCOneMini2 - $fixture = array( + $fixture = [ 'userAgent' => 'HTC', // Don't think this matters here. 'deviceType' => 'HTCOnemini2', - 'properties' => array(Horde_ActiveSync_Device::OS => 'Android 4.4.2', Horde_ActiveSync_Device::MODEL => 'HTCOnemini2') - ); + 'properties' => [Horde_ActiveSync_Device::OS => 'Android 4.4.2', Horde_ActiveSync_Device::MODEL => 'HTCOnemini2'], + ]; $device = new Horde_ActiveSync_Device($state, $fixture); $this->assertEquals(4, $device->getMajorVersion()); $this->assertEquals(4, $device->getMinorVersion()); @@ -185,32 +191,32 @@ public function testPoomContactsDate() $state = $this->getMockBuilder('Horde_ActiveSync_State_Base')->disableOriginalConstructor()->getMock(); // WindowsPhone. - $fixture = array('deviceType' => 'windowsphone'); + $fixture = ['deviceType' => 'windowsphone']; $device = new Horde_ActiveSync_Device($state, $fixture); $date = new Horde_Date('2003-09-24', 'UTC'); $bday = $device->normalizePoomContactsDates($date); $this->assertEquals('2003-09-24', $bday->setTimezone('America/New_York')->format('Y-m-d')); // iOS (Sends as 00:00:00 localtime converted to UTC). - $fixture = array( + $fixture = [ 'deviceType' => 'iPhone', 'userAgent' => 'Apple-iPhone4C1/1002.329', - 'properties' => array(Horde_ActiveSync_Device::OS => 'iOS 6.1.3 10B329')); + 'properties' => [Horde_ActiveSync_Device::OS => 'iOS 6.1.3 10B329']]; $device = new Horde_ActiveSync_Device($state, $fixture); $date = new Horde_Date('1970-03-20'); $bday = $device->normalizePoomContactsDates($date, true); - $this->assertEquals('1970-03-20 00:00:00', (string)$bday); + $this->assertEquals('1970-03-20 00:00:00', (string) $bday); $date = new Horde_Date('1970-03-20T05:00:00.000Z'); $bday = $device->normalizePoomContactsDates($date); - $this->assertEquals('1970-03-20 00:00:00', (string)$bday->setTimezone('America/New_York')); + $this->assertEquals('1970-03-20 00:00:00', (string) $bday->setTimezone('America/New_York')); // Try a positive UTC offset timezone date_default_timezone_set('Europe/Berlin'); - $fixture = array( + $fixture = [ 'deviceType' => 'iPhone', 'userAgent' => 'Apple-iPhone4C1/1104.201', - 'properties' => array(Horde_ActiveSync_Device::OS => 'iOS 7.1.1 11D201')); + 'properties' => [Horde_ActiveSync_Device::OS => 'iOS 7.1.1 11D201']]; $device = new Horde_ActiveSync_Device($state, $fixture); $date = new Horde_Date('1966-07-22T23:00:00.000Z'); $bday = $device->normalizePoomContactsDates($date); @@ -219,7 +225,7 @@ public function testPoomContactsDate() // Android date_default_timezone_set('Pacific/Honolulu'); - $fixture = array('deviceType' => 'android', 'userAgent' => 'Android/4.3.1-EAS-1.3'); + $fixture = ['deviceType' => 'android', 'userAgent' => 'Android/4.3.1-EAS-1.3']; $device = new Horde_ActiveSync_Device($state, $fixture); $date = new Horde_Date('2003-09-24 08:00:00', 'UTC'); $bday = $device->normalizePoomContactsDates($date); @@ -227,37 +233,37 @@ public function testPoomContactsDate() // Note 3 date_default_timezone_set('America/Chicago'); - $fixture = array( + $fixture = [ 'deviceType' => 'SAMSUNGSMN900V', 'userAgent' => 'SAMSUNG-SM-N900V/101.403', - 'properties' => array(Horde_ActiveSync_Device::OS => 'Android') - ); + 'properties' => [Horde_ActiveSync_Device::OS => 'Android'], + ]; $device = new Horde_ActiveSync_Device($state, $fixture); $date = new Horde_Date('1970-03-20'); $bday = $device->normalizePoomContactsDates($date, true); - $this->assertEquals('1970-03-20 00:00:00', (string)$bday); + $this->assertEquals('1970-03-20 00:00:00', (string) $bday); - $fixture = array( + $fixture = [ 'deviceType' => 'Android', 'userAgent' => 'hltevzw/KOT49H', - 'properties' => array(Horde_ActiveSync_Device::OS => 'Android 4.4.2.N900VVRUCNC4') - ); + 'properties' => [Horde_ActiveSync_Device::OS => 'Android 4.4.2.N900VVRUCNC4'], + ]; $device = new Horde_ActiveSync_Device($state, $fixture); $device->id = '6E696E656331393035333833303331'; $date = new Horde_Date('1970-03-20'); $bday = $device->normalizePoomContactsDates($date, true); - $this->assertEquals('1970-03-20 00:00:00', (string)$bday); + $this->assertEquals('1970-03-20 00:00:00', (string) $bday); date_default_timezone_set($tz); } public function testOverrideClientType() { - $fixture = array( + $fixture = [ 'deviceType' => 'SAMSUNGSMN900V', 'userAgent' => 'SAMSUNG-SM-N900V/101.403', - 'properties' => array(Horde_ActiveSync_Device::OS => 'Android') - ); + 'properties' => [Horde_ActiveSync_Device::OS => 'Android'], + ]; $device = new Horde_ActiveSync_Device($this->getMockBuilder('Horde_ActiveSync_State_Base')->disableOriginalConstructor()->getMock(), $fixture); $this->assertEquals(Horde_ActiveSync_Device::TYPE_ANDROID, $device->clientType); $device->clientType = 'Samsung'; @@ -266,16 +272,16 @@ public function testOverrideClientType() public function testSupported() { - $fixture = array( + $fixture = [ 'deviceType' => 'SAMSUNGSMN900V', 'userAgent' => 'SAMSUNG-SM-N900V/101.403', - 'properties' => array(Horde_ActiveSync_Device::OS => 'Android') - ); + 'properties' => [Horde_ActiveSync_Device::OS => 'Android'], + ]; $device = new Horde_ActiveSync_Device($this->getMockBuilder('Horde_ActiveSync_State_Base')->disableOriginalConstructor()->getMock(), $fixture); $this->assertEmpty($device->supported); - $device->supported = array(); - $device->supported['contacts'] = array('one', 'two'); - $this->assertEquals($device->supported, array('contacts' => array('one', 'two'))); + $device->supported = []; + $device->supported['contacts'] = ['one', 'two']; + $this->assertEquals($device->supported, ['contacts' => ['one', 'two']]); } } diff --git a/test/Horde/ActiveSync/Factory/TestServer.php b/test/Horde/ActiveSync/Factory/TestServer.php index cd0c4320..06d29e0d 100644 --- a/test/Horde/ActiveSync/Factory/TestServer.php +++ b/test/Horde/ActiveSync/Factory/TestServer.php @@ -1,6 +1,7 @@ driver = $driver; - $this->request = $request ?? $this->createMockRequest(); + $this->driver = $this->getMockBuilder('Horde_ActiveSync_Driver_Base') + ->disableOriginalConstructor() + ->getMock(); $this->input = fopen('php://memory', 'wb+'); $decoder = new Horde_ActiveSync_Wbxml_Decoder($this->input); $this->_output = fopen('php://memory', 'wb+'); $encoder = new Horde_ActiveSync_Wbxml_Encoder($this->_output); - $state = $this->createMockState(); + $state = $this->getMockBuilder('Horde_ActiveSync_State_Base') + ->disableOriginalConstructor() + ->getMock(); + $this->request = $this->getMockBuilder('Horde_Controller_Request_Http') + ->disableOriginalConstructor() + ->getMock(); + $this->markTestSkipped('Methods parameterized below "getHeader" and "getServerVars" arent configurable. '); + $this->request->expects($this->any()) + ->method('getHeader') + ->will($this->returnValue('14.1')); + $this->request->expects($this->any()) + ->method('getServerVars') + ->will($this->returnValue(['PHP_AUTH_USER' => 'mike', 'PHP_AUTH_PW' => 'password'])); $this->server = new Horde_ActiveSync($this->driver, $decoder, $encoder, $state, $this->request); } - /** - * Create mock request object without TestCase. - * Uses anonymous class to stub Horde_Controller_Request_Http. - */ - protected function createMockRequest() - { - return new class { - private $_overrides = []; - - public function setOverride($method, $value) { - $this->_overrides[$method] = $value; - } - - public function getHeader($header) { - return $this->_overrides['getHeader'] ?? '14.1'; - } - - public function getServerVars($var = null) { - $vars = $this->_overrides['getServerVars'] ?? array('PHP_AUTH_USER' => 'mike', 'PHP_AUTH_PW' => 'password'); - return $var ? ($vars[$var] ?? null) : $vars; - } - }; - } - - /** - * Create mock state object without TestCase. - * Uses anonymous class to stub Horde_ActiveSync_State_Base. - */ - protected function createMockState() - { - return new class extends \Horde_ActiveSync_State_Base { - public function __construct() {} - public function listDevices($user = null, $filter = []) { return []; } - public function deviceExists($devId, $user = '') { return false; } - public function loadDeviceInfo($devId, $user = '', $ignorecache = false) { return null; } - public function loadState($collection, $synckey, $type = null, $id = '') {} - public function setNewSyncKey($key) {} - public function removeState($synckey) {} - public function updateState($type, $params = [], $deviceId = null) {} - public function save() {} - public function deleteFolderState($devId, $class, $folderid) {} - public function getCollectionState($devId, $folderid, $type) { return []; } - public function getHeartbeatState($devId, $user = '') { return null; } - public function setHeartbeatState($state) {} - public function getSyncCache($devId, $user, $fields = null) { return []; } - public function saveSyncCache($cache, $devId, $user) {} - public function deleteSyncCache($devId, $user = null) {} - public function loadFolderCache($devId, $user = '') { return false; } - public function setStateParams($params = []) {} - public function isDuplicatePIMAddition($id) { return false; } - public function setHeartbeat($hb) {} - public function getHeartbeat() { return 0; } - public function setBackend($backend) {} - }; - } - } diff --git a/test/Horde/ActiveSync/ImapAdapterTest.php b/test/Horde/ActiveSync/ImapAdapterTest.php index d348de7d..bd435740 100644 --- a/test/Horde/ActiveSync/ImapAdapterTest.php +++ b/test/Horde/ActiveSync/ImapAdapterTest.php @@ -1,4 +1,5 @@ markTestIncomplete("Useless test without all the fixtures."); $factory = new Horde_ActiveSync_Factory_TestServer(); - $imap_client = $this->getMockBuilder(Horde_Imap_Client_Socket::class) - ->disableOriginalConstructor() - ->getMock(); + $imap_client = $this->getMockSkipConstructor('Horde_Imap_Client_Socket'); $imap_client->expects($this->any()) ->method('fetch') ->will($this->_getFixturesFor13711()); $imap_factory = new Horde_ActiveSync_Stub_ImapFactory(); $imap_factory->fixture = $imap_client; - $adapter = new Horde_ActiveSync_Imap_Adapter(array('factory' => $imap_factory)); + $adapter = new Horde_ActiveSync_Imap_Adapter(['factory' => $imap_factory]); $adapter->getMessages( 'INBOX', - array(462), - array( + [462], + [ 'protocolversion' => 14.1, - 'bodyprefs' => array( + 'bodyprefs' => [ 'wanted' => Horde_ActiveSync::BODYPREF_TYPE_MIME, - Horde_ActiveSync::BODYPREF_TYPE_MIME => array( - 'type' => Horde_ActiveSync::BODYPREF_TYPE_MIME, - 'truncationsize' => 200000) - ), + Horde_ActiveSync::BODYPREF_TYPE_MIME => [ + 'type' => Horde_ActiveSync::BODYPREF_TYPE_MIME, + 'truncationsize' => 200000], + ], 'mimesupport' => Horde_ActiveSync::MIME_SUPPORT_ALL, - ) + ] ); } diff --git a/test/Horde/ActiveSync/ImapFolderTest.php b/test/Horde/ActiveSync/ImapFolderTest.php index 717ad4b7..673ad1ee 100644 --- a/test/Horde/ActiveSync/ImapFolderTest.php +++ b/test/Horde/ActiveSync/ImapFolderTest.php @@ -1,4 +1,5 @@ expectException('Horde_ActiveSync_Exception'); - $folder->checkValidity(array(Horde_ActiveSync_Folder_Imap::UIDVALIDITY => '123')); + $folder->checkValidity([Horde_ActiveSync_Folder_Imap::UIDVALIDITY => '123']); $thrown = true; $this->assertEquals(true, $thrown); $this->assertEquals(0, $folder->uidnext()); $this->assertEquals(0, $folder->modseq()); - $this->assertEquals(array(), $folder->messages()); - $this->assertEquals(array(), $folder->flags()); - $this->assertEquals(array(), $folder->added()); - $this->assertEquals(array(), $folder->changed()); - $this->assertEquals(array(), $folder->removed()); + $this->assertEquals([], $folder->messages()); + $this->assertEquals([], $folder->flags()); + $this->assertEquals([], $folder->added()); + $this->assertEquals([], $folder->changed()); + $this->assertEquals([], $folder->removed()); $this->assertEquals(0, $folder->minuid()); } public function testNoModseqUpdate() { $folder = new Horde_ActiveSync_Folder_Imap('INBOX', Horde_ActiveSync::CLASS_EMAIL); - $status = array(Horde_ActiveSync_Folder_Imap::UIDVALIDITY => 100, Horde_ActiveSync_Folder_Imap::UIDNEXT => 105); + $status = [Horde_ActiveSync_Folder_Imap::UIDVALIDITY => 100, Horde_ActiveSync_Folder_Imap::UIDNEXT => 105]; // Initial state for nonmodseq - $msg_changes = array(100, 101, 102, 103, 104); - $flag_changes = array( - 100 => array('read' => 0, 'flagged' => 0), - 101 => array('read' => 0, 'flagged' => 0), - 102 => array('read' => 0, 'flagged' => 0), - 103 => array('read' => 0, 'flagged' => 0), - 104 => array('read' => 0, 'flagged' => 0), - ); + $msg_changes = [100, 101, 102, 103, 104]; + $flag_changes = [ + 100 => ['read' => 0, 'flagged' => 0], + 101 => ['read' => 0, 'flagged' => 0], + 102 => ['read' => 0, 'flagged' => 0], + 103 => ['read' => 0, 'flagged' => 0], + 104 => ['read' => 0, 'flagged' => 0], + ]; $folder->setChanges($msg_changes, $flag_changes); $this->assertEquals($msg_changes, $folder->added()); $this->assertEquals($flag_changes, $folder->flags()); - $this->assertEquals(array(), $folder->changed()); - $this->assertEquals(array(), $folder->removed()); - $this->assertEquals(array(), $folder->messages()); + $this->assertEquals([], $folder->changed()); + $this->assertEquals([], $folder->removed()); + $this->assertEquals([], $folder->messages()); $folder->setStatus($status); $folder->updateState(); - $this->assertEquals(array(), $folder->added()); - $this->assertEquals(array(), $folder->flags()); - $this->assertEquals(array(), $folder->changed()); - $this->assertEquals(array(), $folder->removed()); + $this->assertEquals([], $folder->added()); + $this->assertEquals([], $folder->flags()); + $this->assertEquals([], $folder->changed()); + $this->assertEquals([], $folder->removed()); $this->assertEquals($msg_changes, $folder->messages()); // Now simulate some flag changes and new messages. - $msg_changes = array(100, 101, 102, 103, 104, 105); - $flag_changes = array( - 100 => array('read' => 0, 'flagged' => 1), - 101 => array('read' => 0, 'flagged' => 0), - 102 => array('read' => 0, 'flagged' => 0), - 103 => array('read' => 0, 'flagged' => 0), - 104 => array('read' => 0, 'flagged' => 0), - 105 => array('read' => 1, 'flagged' => 0), - ); + $msg_changes = [100, 101, 102, 103, 104, 105]; + $flag_changes = [ + 100 => ['read' => 0, 'flagged' => 1], + 101 => ['read' => 0, 'flagged' => 0], + 102 => ['read' => 0, 'flagged' => 0], + 103 => ['read' => 0, 'flagged' => 0], + 104 => ['read' => 0, 'flagged' => 0], + 105 => ['read' => 1, 'flagged' => 0], + ]; $folder->setChanges($msg_changes, $flag_changes); - $this->assertEquals(array(105), $folder->added()); - $this->assertEquals(array(100), $folder->changed()); + $this->assertEquals([105], $folder->added()); + $this->assertEquals([100], $folder->changed()); $status[Horde_ActiveSync_Folder_Imap::UIDNEXT] = 106; $folder->setStatus($status); @@ -87,41 +93,41 @@ public function testNoModseqUpdate() public function testModseqUpdate() { $folder = new Horde_ActiveSync_Folder_Imap('INBOX', Horde_ActiveSync::CLASS_EMAIL); - $status = array(Horde_ActiveSync_Folder_Imap::UIDVALIDITY => 100, Horde_ActiveSync_Folder_Imap::UIDNEXT => 105, Horde_ActiveSync_Folder_Imap::HIGHESTMODSEQ => 200); + $status = [Horde_ActiveSync_Folder_Imap::UIDVALIDITY => 100, Horde_ActiveSync_Folder_Imap::UIDNEXT => 105, Horde_ActiveSync_Folder_Imap::HIGHESTMODSEQ => 200]; // Initial state - $msg_changes = array(100, 101, 102, 103, 104); - $flag_changes = array( - 100 => array('read' => 0, 'flagged' => 0), - 101 => array('read' => 0, 'flagged' => 0), - 102 => array('read' => 0, 'flagged' => 0), - 103 => array('read' => 0, 'flagged' => 0), - 104 => array('read' => 0, 'flagged' => 0), - ); + $msg_changes = [100, 101, 102, 103, 104]; + $flag_changes = [ + 100 => ['read' => 0, 'flagged' => 0], + 101 => ['read' => 0, 'flagged' => 0], + 102 => ['read' => 0, 'flagged' => 0], + 103 => ['read' => 0, 'flagged' => 0], + 104 => ['read' => 0, 'flagged' => 0], + ]; $folder->setChanges($msg_changes, $flag_changes); $this->assertEquals($msg_changes, $folder->added()); $this->assertEquals($flag_changes, $folder->flags()); - $this->assertEquals(array(), $folder->changed()); - $this->assertEquals(array(), $folder->removed()); - $this->assertEquals(array(), $folder->messages()); + $this->assertEquals([], $folder->changed()); + $this->assertEquals([], $folder->removed()); + $this->assertEquals([], $folder->messages()); $folder->setStatus($status); $folder->updateState(); - $this->assertEquals(array(), $folder->added()); - $this->assertEquals(array(), $folder->flags()); - $this->assertEquals(array(), $folder->changed()); - $this->assertEquals(array(), $folder->removed()); + $this->assertEquals([], $folder->added()); + $this->assertEquals([], $folder->flags()); + $this->assertEquals([], $folder->changed()); + $this->assertEquals([], $folder->removed()); $this->assertEquals($msg_changes, $folder->messages()); // Now simulate some flag changes and new messages. - $msg_changes = array(100, 105); - $flag_changes = array( - 100 => array('read' => 0, 'flagged' => 1), - 105 => array('read' => 1, 'flagged' => 0), - ); + $msg_changes = [100, 105]; + $flag_changes = [ + 100 => ['read' => 0, 'flagged' => 1], + 105 => ['read' => 1, 'flagged' => 0], + ]; $folder->setChanges($msg_changes, $flag_changes); - $this->assertEquals(array(105), $folder->added()); - $this->assertEquals(array(100), $folder->changed()); + $this->assertEquals([105], $folder->added()); + $this->assertEquals([100], $folder->changed()); $status[Horde_ActiveSync_Folder_Imap::UIDNEXT] = 106; $folder->setStatus($status); @@ -131,8 +137,8 @@ public function testModseqUpdate() public function testSerializationWithImapCompression() { $folder = new Horde_ActiveSync_Folder_Imap('Trash', Horde_ActiveSync::CLASS_EMAIL); - $status = array(Horde_ActiveSync_Folder_Imap::UIDVALIDITY => 100, Horde_ActiveSync_Folder_Imap::UIDNEXT => 47654, Horde_ActiveSync_Folder_Imap::HIGHESTMODSEQ => 200); - $fixture = array(46653,46654,46655,46656,46657,46658,46659,46660,46661,46662,46663,46664,46665,46666,46667,46668,46669,46670,46671,46672,46673,46674,46675,46676,46677,46678,46679,46680,46681,46682,46691,46692,46693,46694,46695,46696,46697,46698,46699,46700,46701,46702,46703,46704,46705,46706,46707,46708,46709,46710,46711,46712,46713,46714,46715,46716,46717,46718,46719,46720,46721,46723,46724,46725,46726,46727,46728,46729,46730,46731,46732,46733,46734,46735,46736,46737,46738,46739,46740,46741,46742,46743,46744,46745,46746,46747,46748,46749,46750,46751,46752,46753,46754,46755,46756,46757,46758,46759,46760,46761,46762,46763,46764,46765,46766,46767,46768,46769,46770,46771,46772,46773,46774,46775,46776,46777,46778,46779,46780,46781,46782,46783,46784,46785,46786,46787,46788,46789,46790,46791,46792,46793,46794,46795,46796,46797,46798,46799,46800,46801,46802,46803,46804,46805,46806,46807,46808,46809,46810,46811,46812,46813,46814,46815,46816,46817,46818,46819,46820,46821,46822,46823,46824,46825,46826,46827,46828,46829,46830,46831,46832,46833,46834,46835,46836,46837,46838,46839,46840,46841,46842,46843,46844,46845,46846,46847,46848,46849,46850,46851,46852,46853,46854,46855,46856,46857,46858,46859,46860,46861,46862,46863,46864,46865,46866,46867,46868,46869,46870,46871,46872,46873,46874,46875,46876,46877,46878,46879,46880,46881,46883,46884,46885,46886,46887,46888,46889,46890,46891,46892,46893,46894,46895,46896,46897,46898,46899,46900,46901,46902,46903,46904,46905,46906,46907,46908,46909,46910,46911,46912,46913,46914,46915,46916,46917,46918,46919,46920,46921,46922,46923,46924,46925,46926,46927,46928,46929,46930,46931,46932,46933,46934,46935,46936,46937,46938,46939,46940,46941,46942,46943,46944,46945,46946,46947,46948,46949,46950,46951,46952,46953,46954,46955,46956,46957,46958,46959,46960,46961,46962,46963,46964,46965,46966,46967,46968,46969,46970,46971,46972,46973,46974,46975,46976,46977,46978,46979,46980,46981,46982,46983,46984,46985,46986,46987,46988,46989,46990,46991,46992,46993,46994,46995,46996,46997,46998,46999,47000,47001,47002,47003,47004,47005,47006,47007,47008,47009,47010,47011,47012,47013,47014,47015,47016,47017,47018,47019,47020,47021,47022,47023,47024,47025,47026,47027,47028,47029,47030,47031,47032,47033,47034,47035,47036,47037,47038,47039,47040,47041,47042,47043,47044,47045,47046,47047,47048,47049,47050,47051,47052,47053,47054,47055,47056,47057,47058,47059,47060,47061,47062,47063,47064,47065,47066,47067,47068,47069,47070,47071,47072,47073,47074,47075,47076,47077,47078,47079,47080,47081,47082,47083,47084,47085,47086,47087,47088,47089,47090,47091,47092,47093,47094,47095,47096,47097,47098,47099,47100,47101,47102,47103,47104,47105,47106,47107,47108,47109,47110,47111,47112,47113,47114,47115,47116,47117,47118,47119,47120,47121,47122,47123,47124,47125,47126,47127,47128,47129,47130,47131,47132,47133,47134,47135,47136,47137,47138,47139,47140,47141,47142,47143,47144,47145,47146,47147,47148,47149,47150,47151,47152,47153,47154,47155,47156,47157,47158,47159,47160,47161,47162,47163,47164,47165,47166,47167,47168,47169,47170,47171,47172,47173,47174,47175,47176,47177,47178,47179,47180,47181,47182,47183,47184,47185,47186,47187,47188,47189,47190,47191,47192,47193,47194,47195,47196,47197,47198,47199,47200,47201,47202,47203,47204,47205,47206,47207,47208,47209,47210,47211,47212,47213,47214,47215,47216,47217,47218,47219,47220,47221,47222,47223,47224,47225,47226,47227,47228,47229,47230,47231,47232,47233,47234,47235,47236,47237,47238,47239,47240,47241,47242,47243,47244,47245,47246,47247,47248,47249,47250,47251,47252,47253,47254,47255,47256,47257,47258,47259,47260,47261,47262,47263,47264,47265,47266,47267,47268,47269,47270,47271,47272,47273,47274,47275,47276,47277,47278,47279,47280,47281,47282,47283,47284,47285,47286,47287,47288,47289,47290,47291,47292,47293,47294,47295,47296,47297,47298,47299,47300,47301,47302,47303,47304,47305,47306,47307,47308,47309,47310,47311,47312,47313,47314,47315,47316,47317,47318,47319,47320,47321,47322,47323,47324,47325,47326,47327,47328,47329,47330,47331,47332,47333,47334,47335,47336,47337,47338,47339,47340,47341,47342,47343,47344,47345,47346,47347,47348,47349,47350,47351,47352,47353,47354,47355,47356,47357,47358,47359,47360,47361,47362,47363,47364,47365,47366,47367,47368,47369,47370,47371,47372,47373,47374,47375,47376,47377,47378,47379,47380,47381,47382,47383,47384,47385,47386,47387,47388,47389,47390,47391,47392,47393,47394,47395,47396,47397,47398,47399,47400,47401,47402,47403,47404,47405,47406,47407,47408,47409,47410,47411,47412,47413,47414,47415,47416,47417,47418,47419,47420,47421,47422,47423,47424,47425,47426,47427,47428,47429,47430,47431,47432,47433,47434,47435,47436,47437,47438,47439,47440,47441,47442,47443,47444,47445,47446,47447,47448,47449,47450,47451,47452,47453,47454,47455,47456,47457,47458,47459,47460,47461,47462,47463,47464,47465,47466,47467,47468,47469,47470,47471,47472,47473,47474,47475,47476,47477,47478,47479,47480,47481,47482,47483,47484,47485,47486,47487,47488,47489,47490,47491,47492,47493,47494,47495,47496,47497,47498,47499,47500,47501,47502,47503,47504,47505,47506,47507,47508,47509,47510,47511,47512,47513,47514,47515,47516,47517,47518,47519,47520,47521,47522,47523,47524,47525,47526,47527,47528,47529,47530,47531,47532,47533,47534,47535,47536,47537,47538,47539,47540,47541,47542,47543,47544,47545,47546,47547,47548,47549,47550,47551,47552,47553,47554,47555,47556,47557,47558,47559,47560,47561,47562,47563,47564,47565,47566,47567,47568,47569,47570,47571,47572,47573,47574,47575,47576,47577,47578,47579,47580,47581,47582,47583,47584,47585,47586,47587,47588,47589,47590,47591,47592,47593,47594,47595,47596,47597,47598,47599,47600,47601,47602,47603,47604,47605,47606,47607,47608,47609,47610,47611,47612,47613,47614,47615,47616,47617,47618,47619,47620,47621,47622,47623,47624,47625,47626,47627,47628,47629,47630,47631,47632,47633,47634,47635,47636,47637,47638,47639,47640,47641,47642,47643,47644,47645,47646,47647,47648,47649,47650,47651,47652,47653); + $status = [Horde_ActiveSync_Folder_Imap::UIDVALIDITY => 100, Horde_ActiveSync_Folder_Imap::UIDNEXT => 47654, Horde_ActiveSync_Folder_Imap::HIGHESTMODSEQ => 200]; + $fixture = [46653,46654,46655,46656,46657,46658,46659,46660,46661,46662,46663,46664,46665,46666,46667,46668,46669,46670,46671,46672,46673,46674,46675,46676,46677,46678,46679,46680,46681,46682,46691,46692,46693,46694,46695,46696,46697,46698,46699,46700,46701,46702,46703,46704,46705,46706,46707,46708,46709,46710,46711,46712,46713,46714,46715,46716,46717,46718,46719,46720,46721,46723,46724,46725,46726,46727,46728,46729,46730,46731,46732,46733,46734,46735,46736,46737,46738,46739,46740,46741,46742,46743,46744,46745,46746,46747,46748,46749,46750,46751,46752,46753,46754,46755,46756,46757,46758,46759,46760,46761,46762,46763,46764,46765,46766,46767,46768,46769,46770,46771,46772,46773,46774,46775,46776,46777,46778,46779,46780,46781,46782,46783,46784,46785,46786,46787,46788,46789,46790,46791,46792,46793,46794,46795,46796,46797,46798,46799,46800,46801,46802,46803,46804,46805,46806,46807,46808,46809,46810,46811,46812,46813,46814,46815,46816,46817,46818,46819,46820,46821,46822,46823,46824,46825,46826,46827,46828,46829,46830,46831,46832,46833,46834,46835,46836,46837,46838,46839,46840,46841,46842,46843,46844,46845,46846,46847,46848,46849,46850,46851,46852,46853,46854,46855,46856,46857,46858,46859,46860,46861,46862,46863,46864,46865,46866,46867,46868,46869,46870,46871,46872,46873,46874,46875,46876,46877,46878,46879,46880,46881,46883,46884,46885,46886,46887,46888,46889,46890,46891,46892,46893,46894,46895,46896,46897,46898,46899,46900,46901,46902,46903,46904,46905,46906,46907,46908,46909,46910,46911,46912,46913,46914,46915,46916,46917,46918,46919,46920,46921,46922,46923,46924,46925,46926,46927,46928,46929,46930,46931,46932,46933,46934,46935,46936,46937,46938,46939,46940,46941,46942,46943,46944,46945,46946,46947,46948,46949,46950,46951,46952,46953,46954,46955,46956,46957,46958,46959,46960,46961,46962,46963,46964,46965,46966,46967,46968,46969,46970,46971,46972,46973,46974,46975,46976,46977,46978,46979,46980,46981,46982,46983,46984,46985,46986,46987,46988,46989,46990,46991,46992,46993,46994,46995,46996,46997,46998,46999,47000,47001,47002,47003,47004,47005,47006,47007,47008,47009,47010,47011,47012,47013,47014,47015,47016,47017,47018,47019,47020,47021,47022,47023,47024,47025,47026,47027,47028,47029,47030,47031,47032,47033,47034,47035,47036,47037,47038,47039,47040,47041,47042,47043,47044,47045,47046,47047,47048,47049,47050,47051,47052,47053,47054,47055,47056,47057,47058,47059,47060,47061,47062,47063,47064,47065,47066,47067,47068,47069,47070,47071,47072,47073,47074,47075,47076,47077,47078,47079,47080,47081,47082,47083,47084,47085,47086,47087,47088,47089,47090,47091,47092,47093,47094,47095,47096,47097,47098,47099,47100,47101,47102,47103,47104,47105,47106,47107,47108,47109,47110,47111,47112,47113,47114,47115,47116,47117,47118,47119,47120,47121,47122,47123,47124,47125,47126,47127,47128,47129,47130,47131,47132,47133,47134,47135,47136,47137,47138,47139,47140,47141,47142,47143,47144,47145,47146,47147,47148,47149,47150,47151,47152,47153,47154,47155,47156,47157,47158,47159,47160,47161,47162,47163,47164,47165,47166,47167,47168,47169,47170,47171,47172,47173,47174,47175,47176,47177,47178,47179,47180,47181,47182,47183,47184,47185,47186,47187,47188,47189,47190,47191,47192,47193,47194,47195,47196,47197,47198,47199,47200,47201,47202,47203,47204,47205,47206,47207,47208,47209,47210,47211,47212,47213,47214,47215,47216,47217,47218,47219,47220,47221,47222,47223,47224,47225,47226,47227,47228,47229,47230,47231,47232,47233,47234,47235,47236,47237,47238,47239,47240,47241,47242,47243,47244,47245,47246,47247,47248,47249,47250,47251,47252,47253,47254,47255,47256,47257,47258,47259,47260,47261,47262,47263,47264,47265,47266,47267,47268,47269,47270,47271,47272,47273,47274,47275,47276,47277,47278,47279,47280,47281,47282,47283,47284,47285,47286,47287,47288,47289,47290,47291,47292,47293,47294,47295,47296,47297,47298,47299,47300,47301,47302,47303,47304,47305,47306,47307,47308,47309,47310,47311,47312,47313,47314,47315,47316,47317,47318,47319,47320,47321,47322,47323,47324,47325,47326,47327,47328,47329,47330,47331,47332,47333,47334,47335,47336,47337,47338,47339,47340,47341,47342,47343,47344,47345,47346,47347,47348,47349,47350,47351,47352,47353,47354,47355,47356,47357,47358,47359,47360,47361,47362,47363,47364,47365,47366,47367,47368,47369,47370,47371,47372,47373,47374,47375,47376,47377,47378,47379,47380,47381,47382,47383,47384,47385,47386,47387,47388,47389,47390,47391,47392,47393,47394,47395,47396,47397,47398,47399,47400,47401,47402,47403,47404,47405,47406,47407,47408,47409,47410,47411,47412,47413,47414,47415,47416,47417,47418,47419,47420,47421,47422,47423,47424,47425,47426,47427,47428,47429,47430,47431,47432,47433,47434,47435,47436,47437,47438,47439,47440,47441,47442,47443,47444,47445,47446,47447,47448,47449,47450,47451,47452,47453,47454,47455,47456,47457,47458,47459,47460,47461,47462,47463,47464,47465,47466,47467,47468,47469,47470,47471,47472,47473,47474,47475,47476,47477,47478,47479,47480,47481,47482,47483,47484,47485,47486,47487,47488,47489,47490,47491,47492,47493,47494,47495,47496,47497,47498,47499,47500,47501,47502,47503,47504,47505,47506,47507,47508,47509,47510,47511,47512,47513,47514,47515,47516,47517,47518,47519,47520,47521,47522,47523,47524,47525,47526,47527,47528,47529,47530,47531,47532,47533,47534,47535,47536,47537,47538,47539,47540,47541,47542,47543,47544,47545,47546,47547,47548,47549,47550,47551,47552,47553,47554,47555,47556,47557,47558,47559,47560,47561,47562,47563,47564,47565,47566,47567,47568,47569,47570,47571,47572,47573,47574,47575,47576,47577,47578,47579,47580,47581,47582,47583,47584,47585,47586,47587,47588,47589,47590,47591,47592,47593,47594,47595,47596,47597,47598,47599,47600,47601,47602,47603,47604,47605,47606,47607,47608,47609,47610,47611,47612,47613,47614,47615,47616,47617,47618,47619,47620,47621,47622,47623,47624,47625,47626,47627,47628,47629,47630,47631,47632,47633,47634,47635,47636,47637,47638,47639,47640,47641,47642,47643,47644,47645,47646,47647,47648,47649,47650,47651,47652,47653]; $folder->setChanges($fixture); $folder->setStatus($status); $folder->updateState(); @@ -147,8 +153,8 @@ public function testSerializationWithImapCompression() public function testSerializationWithoutImapCompression() { $folder = new Horde_ActiveSync_Folder_Imap('Trash', Horde_ActiveSync::CLASS_EMAIL); - $status = array(Horde_ActiveSync_Folder_Imap::UIDVALIDITY => 100, Horde_ActiveSync_Folder_Imap::UIDNEXT => 47654, Horde_ActiveSync_Folder_Imap::HIGHESTMODSEQ => 200); - $fixture = array(46653,46654,46655,46656,46657,46658,46659,46660,46661,46662,46663,46664,46665,46666,46667,46668,46669,46670,46671,46672,46673,46674,46675,46676,46677,46678,46679,46680,46681,46682,46691,46692,46693,46694,46695,46696,46697,46698,46699,46700,46701,46702,46703,46704,46705,46706,46707,46708,46709,46710,46711,46712,46713,46714,46715,46716,46717,46718,46719,46720,46721,46723,46724,46725,46726,46727,46728,46729,46730,46731,46732,46733,46734,46735,46736,46737,46738,46739,46740,46741,46742,46743,46744,46745,46746,46747,46748,46749,46750,46751,46752,46753,46754,46755,46756,46757,46758,46759,46760,46761,46762,46763,46764,46765,46766,46767,46768,46769,46770,46771,46772,46773,46774,46775,46776,46777,46778,46779,46780,46781,46782,46783,46784,46785,46786); + $status = [Horde_ActiveSync_Folder_Imap::UIDVALIDITY => 100, Horde_ActiveSync_Folder_Imap::UIDNEXT => 47654, Horde_ActiveSync_Folder_Imap::HIGHESTMODSEQ => 200]; + $fixture = [46653,46654,46655,46656,46657,46658,46659,46660,46661,46662,46663,46664,46665,46666,46667,46668,46669,46670,46671,46672,46673,46674,46675,46676,46677,46678,46679,46680,46681,46682,46691,46692,46693,46694,46695,46696,46697,46698,46699,46700,46701,46702,46703,46704,46705,46706,46707,46708,46709,46710,46711,46712,46713,46714,46715,46716,46717,46718,46719,46720,46721,46723,46724,46725,46726,46727,46728,46729,46730,46731,46732,46733,46734,46735,46736,46737,46738,46739,46740,46741,46742,46743,46744,46745,46746,46747,46748,46749,46750,46751,46752,46753,46754,46755,46756,46757,46758,46759,46760,46761,46762,46763,46764,46765,46766,46767,46768,46769,46770,46771,46772,46773,46774,46775,46776,46777,46778,46779,46780,46781,46782,46783,46784,46785,46786]; $folder->setChanges($fixture); $folder->setStatus($status); $folder->updateState(); @@ -158,89 +164,5 @@ public function testSerializationWithoutImapCompression() } - /** - * Test that version 1 cached data (old PHP serialize format) can be - * successfully upgraded to version 2 without throwing StaleState exception. - * - * This tests the critical version upgrade path added per amulet1's review. - */ - public function testVersion1DataUpgrade() - { - // Simulate old version 1 data (PHP serialized format from pre-2013) - $version1Data = serialize([ - 's' => [ - Horde_ActiveSync_Folder_Imap::UIDVALIDITY => 100, - Horde_ActiveSync_Folder_Imap::UIDNEXT => 105, - Horde_ActiveSync_Folder_Imap::MESSAGES => 10, - ], - 'm' => [100, 101, 102, 103, 104], - 'f' => 'INBOX', - 'c' => Horde_ActiveSync::CLASS_EMAIL, - 'lsd' => null, - 'sd' => 0, - 'hi' => true, - 'v' => 1 // OLD VERSION - ]); - - $folder = new Horde_ActiveSync_Folder_Imap('INBOX', Horde_ActiveSync::CLASS_EMAIL); - - // Should NOT throw StaleState exception - $folder->unserialize($version1Data); - - // Verify data was loaded correctly - $this->assertEquals('INBOX', $folder->serverid()); - $this->assertEquals(105, $folder->uidnext()); - $this->assertEquals([100, 101, 102, 103, 104], $folder->messages()); - } - - /** - * Test Collection folder with potentially missing version key. - */ - public function testCollectionMissingVersion() - { - // Simulate data without version key (theoretical edge case) - $noVersionData = json_encode([ - 's' => 1, - 'f' => 'Calendar', - 'c' => Horde_ActiveSync::CLASS_CALENDAR, - 'lsd' => null, - 'sd' => 0, - 'i' => true, - // 'v' is intentionally missing - ]); - - $folder = new \Horde_ActiveSync_Folder_Collection( - 'Calendar', - Horde_ActiveSync::CLASS_CALENDAR, - [] - ); - - // Should NOT throw exception - version defaults to VERSION constant - $folder->unserialize($noVersionData); - - $this->assertEquals('Calendar', $folder->serverid()); - } - - /** - * Test RI folder with potentially missing version key. - */ - public function testRIMissingVersion() - { - // Simulate data without version key - $noVersionData = json_encode([ - 'd' => [], - 'f' => 'RI', - 'c' => Horde_ActiveSync::CLASS_CONTACTS, - // 'v' is intentionally missing - ]); - - $folder = new \Horde_ActiveSync_Folder_RI('RI', Horde_ActiveSync::CLASS_CONTACTS); - - // Should NOT throw exception - version defaults to VERSION constant - $folder->unserialize($noVersionData); - - $this->assertEquals('RI', $folder->serverid()); - } - } diff --git a/test/Horde/ActiveSync/InviteTest.php b/test/Horde/ActiveSync/InviteTest.php index b8e30d63..4de0ed26 100644 --- a/test/Horde/ActiveSync/InviteTest.php +++ b/test/Horde/ActiveSync/InviteTest.php @@ -1,4 +1,5 @@ assertEquals($expected, $results); } -} \ No newline at end of file +} diff --git a/test/Horde/ActiveSync/MessageBodyDataTest.php b/test/Horde/ActiveSync/MessageBodyDataTest.php index b6513dce..113177fa 100644 --- a/test/Horde/ActiveSync/MessageBodyDataTest.php +++ b/test/Horde/ActiveSync/MessageBodyDataTest.php @@ -1,4 +1,5 @@ markTestSkipped('Requires horde/controller package'); + $factory = new TestServer(); + $imap_client = $this->getMockBuilder('Horde_Imap_Client_Socket')->disableOriginalConstructor()->getMock(); + $imap_client->expects($this->any()) + ->method('fetch') + ->will($this->_getFixturesFor13711()); + + $imap_factory = new Horde_ActiveSync_Stub_ImapFactory(); + $imap_factory->fixture = $imap_client; + $adapter = new Horde_ActiveSync_Imap_Adapter(['factory' => $imap_factory]); + + $this->markTestIncomplete("Can't use serialized Horde_Mime_Part"); + + $horde_mime_fixture = 'TzoyMToiSG9yZGVfQWN0aXZlU3luY19NaW1lIjoyOntzOjg6IgAqAF9iYXNlIjtDOjE1OiJIb3JkZV9NaW1lX1BhcnQiOjI4MDp7YToyMDp7aTowO2k6MTtpOjE7czo0OiJ0ZXh0IjtpOjI7czo0OiJodG1sIjtpOjM7czoxNjoicXVvdGVkLXByaW50YWJsZSI7aTo0O2E6MDp7fWk6NTtzOjA6IiI7aTo2O3M6MDoiIjtpOjc7YToxOntzOjQ6InNpemUiO3M6NToiMzAzMzYiO31pOjg7YToxOntzOjc6ImNoYXJzZXQiO3M6NToidXRmLTgiO31pOjk7YTowOnt9aToxMDtzOjE6IjEiO2k6MTE7czoxOiIKIjtpOjEyO2E6MDp7fWk6MTM7TjtpOjE0O2k6MzAzMzY7aToxNTtOO2k6MTY7TjtpOjE3O2I6MDtpOjE4O2I6MDtpOjE5O047fX1zOjE4OiIAKgBfaGFzQXR0YWNobWVudHMiO047fQ=='; + $basePart = unserialize(base64_decode($horde_mime_fixture)); + + $mbd = new Horde_ActiveSync_Imap_MessageBodyData( + [ + 'imap' => $imap_client, + 'mime' => $basePart, + 'uid' => 1, + 'mbox' => new Horde_Imap_Client_Mailbox('INBOX')], + [ + 'protocolversion' => 14.1, + 'bodyprefs' => [ + Horde_ActiveSync::BODYPREF_TYPE_HTML => [ + 'truncationsize' => 10240, + 'allornone' => 0], + Horde_ActiveSync::BODYPREF_TYPE_PLAIN => [ + 'truncationsize' => 10240, + 'allornone' => 0], + ], + ] + ); + + $this->assertEquals(10240, $mbd->html['body']->length(true)); + $this->assertEquals(true, $mbd->html['truncated']); } public function testReturnHtmlNoTruncation() { - $this->markTestSkipped('Requires horde/controller package'); + $factory = new TestServer(); + $imap_client = $this->getMockBuilder('Horde_Imap_Client_Socket')->disableOriginalConstructor()->getMock(); + $imap_client->expects($this->any()) + ->method('fetch') + ->will($this->_getFixturesFor13711()); + + $imap_factory = new Horde_ActiveSync_Stub_ImapFactory(); + $imap_factory->fixture = $imap_client; + $adapter = new Horde_ActiveSync_Imap_Adapter(['factory' => $imap_factory]); + + $this->markTestIncomplete("Can't use serialized Horde_Mime_Part"); + + $horde_mime_fixture = 'TzoyMToiSG9yZGVfQWN0aXZlU3luY19NaW1lIjoyOntzOjg6IgAqAF9iYXNlIjtDOjE1OiJIb3JkZV9NaW1lX1BhcnQiOjI4MDp7YToyMDp7aTowO2k6MTtpOjE7czo0OiJ0ZXh0IjtpOjI7czo0OiJodG1sIjtpOjM7czoxNjoicXVvdGVkLXByaW50YWJsZSI7aTo0O2E6MDp7fWk6NTtzOjA6IiI7aTo2O3M6MDoiIjtpOjc7YToxOntzOjQ6InNpemUiO3M6NToiMzAzMzYiO31pOjg7YToxOntzOjc6ImNoYXJzZXQiO3M6NToidXRmLTgiO31pOjk7YTowOnt9aToxMDtzOjE6IjEiO2k6MTE7czoxOiIKIjtpOjEyO2E6MDp7fWk6MTM7TjtpOjE0O2k6MzAzMzY7aToxNTtOO2k6MTY7TjtpOjE3O2I6MDtpOjE4O2I6MDtpOjE5O047fX1zOjE4OiIAKgBfaGFzQXR0YWNobWVudHMiO047fQ=='; + $basePart = unserialize(base64_decode($horde_mime_fixture)); + + $mbd = new Horde_ActiveSync_Imap_MessageBodyData( + [ + 'imap' => $imap_client, + 'mime' => $basePart, + 'uid' => 1, + 'mbox' => new Horde_Imap_Client_Mailbox('INBOX')], + [ + 'protocolversion' => 14.1, + 'bodyprefs' => [ + Horde_ActiveSync::BODYPREF_TYPE_HTML => [ + 'truncationsize' => false, + 'allornone' => 0], + Horde_ActiveSync::BODYPREF_TYPE_PLAIN => [ + 'truncationsize' => false, + 'allornone' => 0], + ], + ] + ); + + $this->assertEquals(26844, $mbd->html['body']->length(true)); + $this->assertEquals(false, $mbd->html['truncated']); } protected function _getFixturesFor13711() diff --git a/test/Horde/ActiveSync/MimeTest.php b/test/Horde/ActiveSync/MimeTest.php index 8664d5ab..bdadd132 100644 --- a/test/Horde/ActiveSync/MimeTest.php +++ b/test/Horde/ActiveSync/MimeTest.php @@ -1,4 +1,5 @@ assertEquals(false, $mime->hasAttachments()); @@ -30,52 +35,54 @@ public function testHasAttachmentsWithNoAttachment() $this->assertEquals(false, $mime->hasAttachments()); $this->assertEquals(false, $mime->isSigned()); $this->assertEquals(false, $mime->hasiCalendar()); - } + } - public function testSignedNoAttachment() - { + public function testSignedNoAttachment() + { $fixture = file_get_contents(__DIR__ . '/fixtures/email_signed.eml'); $mime = new Horde_ActiveSync_Mime(Horde_Mime_Part::parseMessage($fixture)); $this->assertEquals(false, $mime->hasAttachments()); $this->assertEquals(true, $mime->isSigned()); $this->assertEquals(false, $mime->hasiCalendar()); - $fixture = file_get_contents(__DIR__ . '/fixtures/encrypted.eml'); - $mime = new Horde_ActiveSync_Mime(Horde_Mime_Part::parseMessage($fixture)); - $this->assertEquals(false, $mime->isSigned()); - } + $fixture = file_get_contents(__DIR__ . '/fixtures/encrypted.eml'); + $mime = new Horde_ActiveSync_Mime(Horde_Mime_Part::parseMessage($fixture)); + $this->assertEquals(false, $mime->isSigned()); + } - public function testIsEncrypted() - { - $fixture = file_get_contents(__DIR__ . '/fixtures/encrypted.eml'); - $mime = new Horde_ActiveSync_Mime(Horde_Mime_Part::parseMessage($fixture)); - $this->assertEquals(true, $mime->isEncrypted()); + public function testIsEncrypted() + { + $fixture = file_get_contents(__DIR__ . '/fixtures/encrypted.eml'); + $mime = new Horde_ActiveSync_Mime(Horde_Mime_Part::parseMessage($fixture)); + $this->assertEquals(true, $mime->isEncrypted()); - $fixture = file_get_contents(__DIR__ . '/fixtures/email_signed.eml'); - $mime = new Horde_ActiveSync_Mime(Horde_Mime_Part::parseMessage($fixture)); - $this->assertEquals(false, $mime->isEncrypted()); - } + $fixture = file_get_contents(__DIR__ . '/fixtures/email_signed.eml'); + $mime = new Horde_ActiveSync_Mime(Horde_Mime_Part::parseMessage($fixture)); + $this->assertEquals(false, $mime->isEncrypted()); + } - public function testHasAttachmentsWithAttachment() - { + public function testHasAttachmentsWithAttachment() + { $fixture = file_get_contents(__DIR__ . '/fixtures/signed_attachment.eml'); $mime = new Horde_ActiveSync_Mime(Horde_Mime_Part::parseMessage($fixture)); $this->assertEquals(true, $mime->hasAttachments()); $this->assertEquals(true, $mime->isSigned()); $this->assertEquals(false, $mime->hasiCalendar()); - } + } - public function testReplaceMime() - { + public function testReplaceMime() + { $fixture = file_get_contents(__DIR__ . '/fixtures/signed_attachment.eml'); $mime = new Horde_ActiveSync_Mime(Horde_Mime_Part::parseMessage($fixture)); foreach ($mime->contentTypeMap() as $id => $type) { if ($mime->isAttachment($id, $type)) { $part = new Horde_Mime_Part(); $part->setType('text/plain'); - $part->setContents(sprintf( - 'An attachment named %s was removed by Horde_ActiveSync_Test', - $mime->getPart($id)->getName(true)) + $part->setContents( + sprintf( + 'An attachment named %s was removed by Horde_ActiveSync_Test', + $mime->getPart($id)->getName(true) + ) ); $mime->removePart($id); $mime->addPart($part); @@ -94,27 +101,27 @@ public function testRfc822MessageWithMultipartDoesNotIterate() $this->assertEquals(5, $iterator->count()); } - public function testHasiCalendar() - { + public function testHasiCalendar() + { $fixture = file_get_contents(__DIR__ . '/fixtures/invitation_one.eml'); $mime = new Horde_ActiveSync_Mime(Horde_Mime_Part::parseMessage($fixture)); $this->assertEquals(true, $mime->hasAttachments()); $this->assertEquals(false, $mime->isSigned()); - $this->assertEquals(true, (boolean)$mime->hasiCalendar()); - } - - public function testIdna() - { - $fixture = file_get_contents(__DIR__ . '/fixtures/idna.eml'); - $headers = Horde_Mime_Headers::parseHeaders($fixture); - foreach (array('from', 'to', 'cc') as $n) { - if ($header = $headers->getHeader($n)) { - $obj = new Horde_ActiveSync_Mime_Headers_Addresses($n, $header->full_value); - $headers->removeHeader($n); - $headers->addHeaderOb($obj); - } - } - $this->assertEquals('Subject: TT Belieferungsstart der Schulfrei-Exemplare =?utf-8?b?ZsO8cg==?= + $this->assertEquals(true, (bool) $mime->hasiCalendar()); + } + + public function testIdna() + { + $fixture = file_get_contents(__DIR__ . '/fixtures/idna.eml'); + $headers = Horde_Mime_Headers::parseHeaders($fixture); + foreach (['from', 'to', 'cc'] as $n) { + if ($header = $headers->getHeader($n)) { + $obj = new Horde_ActiveSync_Mime_Headers_Addresses($n, $header->full_value); + $headers->removeHeader($n); + $headers->addHeaderOb($obj); + } + } + $this->assertEquals('Subject: TT Belieferungsstart der Schulfrei-Exemplare =?utf-8?b?ZsO8cg==?= das Schuljahr 2017/2018 Date: Fri, 1 Sep 2017 09:52:05 +0100 Message-ID: @@ -126,7 +133,7 @@ public function testIdna() cc: direktion@-abc.at, direktion@nms.-nd.abc.de ', $headers->toString()); - } + } } diff --git a/test/Horde/ActiveSync/PolicyTest.php b/test/Horde/ActiveSync/PolicyTest.php index 9bd1b715..e99bd290 100644 --- a/test/Horde/ActiveSync/PolicyTest.php +++ b/test/Horde/ActiveSync/PolicyTest.php @@ -1,4 +1,5 @@ assertEquals($fixture, $results); } -} \ No newline at end of file +} diff --git a/test/Horde/ActiveSync/Rfc822Test.php b/test/Horde/ActiveSync/Rfc822Test.php index 3aab5f49..6f24dd6f 100644 --- a/test/Horde/ActiveSync/Rfc822Test.php +++ b/test/Horde/ActiveSync/Rfc822Test.php @@ -1,4 +1,5 @@ 'Testing', 'From' => 'mrubinsk@horde.org', 'Content-Type' => 'multipart/alternative; @@ -47,20 +54,20 @@ public static function headersMultipartAlternativeProvider() 'To' => 'Michael Rubinsky ', 'Content-Transfer-Encoding' => '7bit', 'Mime-Version' => '1.0 (1.0)', - 'User-Agent' => 'Horde Application Framework 5' - ), CASE_LOWER); + 'User-Agent' => 'Horde Application Framework 5', + ], CASE_LOWER); ksort($expected); - return array( - array( + return [ + [ file_get_contents(__DIR__ . '/fixtures/iOSMultipartAlternative.eml'), - $expected - ), - array( + $expected, + ], + [ fopen(__DIR__ . '/fixtures/iOSMultipartAlternative.eml', 'r'), - $expected - ) - ); + $expected, + ], + ]; } public function testBaseMimePart() @@ -68,10 +75,10 @@ public function testBaseMimePart() $fixture = file_get_contents(__DIR__ . '/fixtures/iOSMultipartAlternative.eml'); $rfc822 = new Horde_ActiveSync_Rfc822($fixture); $mimepart = $rfc822->getMimeObject(); - $expected = array( + $expected = [ 'multipart/alternative', 'text/plain', - 'text/html'); + 'text/html']; $this->assertEquals($expected, $mimepart->contentTypeMap()); $this->assertEquals(1, $mimepart->findBody('plain')); @@ -88,7 +95,7 @@ public function testMIMEEncodingWhenStandardHeadersAreAdded() $rfc822 = new Horde_ActiveSync_Rfc822($fixture, true); $hdrs = Horde_Mime_Headers::parseHeaders($rfc822->getString()); - $hdr_array = $hdrs->toArray(array('charset' => 'UTF-8')); + $hdr_array = $hdrs->toArray(['charset' => 'UTF-8']); $this->assertEquals('=?utf-8?b?w4PDhMOjw6s=?=', $hdr_array['Subject']); } diff --git a/test/Horde/ActiveSync/ServerTest.php b/test/Horde/ActiveSync/ServerTest.php index e23bdf3f..12b46c3d 100644 --- a/test/Horde/ActiveSync/ServerTest.php +++ b/test/Horde/ActiveSync/ServerTest.php @@ -1,4 +1,5 @@ markTestSkipped('Requires horde/controller package'); + $factory = new TestServer(); + + $this->assertEquals('2.5,12.0,12.1,14.0,14.1,16.0', $factory->server->getSupportedVersions()); + $factory->server->setSupportedVersion(Horde_ActiveSync::VERSION_TWELVEONE); + $this->assertEquals('2.5,12.0,12.1', $factory->server->getSupportedVersions()); + + $factory->server->setSupportedVersion(Horde_ActiveSync::VERSION_FOURTEEN); + $this->assertEquals('2.5,12.0,12.1,14.0', $factory->server->getSupportedVersions()); } public function testSupportedCommands() { - $this->markTestSkipped('Requires horde/controller package'); + $factory = new TestServer(); + $this->assertEquals('Sync,SendMail,SmartForward,SmartReply,GetAttachment,GetHierarchy,CreateCollection,DeleteCollection,MoveCollection,FolderSync,FolderCreate,FolderDelete,FolderUpdate,MoveItems,GetItemEstimate,MeetingResponse,Search,Settings,Ping,ItemOperations,Provision,ResolveRecipients,ValidateCert', $factory->server->getSupportedCommands()); + $factory->server->setSupportedVersion(Horde_ActiveSync::VERSION_TWOFIVE); + $this->assertEquals('Sync,SendMail,SmartForward,SmartReply,GetAttachment,GetHierarchy,CreateCollection,DeleteCollection,MoveCollection,FolderSync,FolderCreate,FolderDelete,FolderUpdate,MoveItems,GetItemEstimate,MeetingResponse,ResolveRecipients,ValidateCert,Provision,Search,Ping', $factory->server->getSupportedCommands()); } } diff --git a/test/Horde/ActiveSync/StateTest/Mongo/BaseTest.php b/test/Horde/ActiveSync/StateTest/Mongo/BaseTest.php index 238d117b..1cd71d6e 100644 --- a/test/Horde/ActiveSync/StateTest/Mongo/BaseTest.php +++ b/test/Horde/ActiveSync/StateTest/Mongo/BaseTest.php @@ -1,4 +1,5 @@ * @license http://www.horde.org/licenses/gpl GPLv2 @@ -6,10 +7,14 @@ * @package Horde_ActiveSync * @subpackage UnitTests */ + namespace Horde\ActiveSync\StateTest\Mongo; + use Horde\ActiveSync\StateTest\TestBase; -use PHPUnit\Framework\Attributes\Depends; +/** + * @coversNothing + */ class BaseTest extends TestBase { protected static $mongo; @@ -20,142 +25,186 @@ public function testGetDeviceInfo() $this->_testGetDeviceInfo(); } - #[Depends('testGetDeviceInfo')] + /** + * @depends testGetDeviceInfo + */ public function testListDevices() { $this->_testListDevices(); } - #[Depends('testListDevices')] + /** + * @depends testListDevices + */ public function testPolicyKeys() { $this->_testPolicyKeys(); } - #[Depends('testListDevices')] + /** + * @depends testListDevices + */ public function testDuplicatePIMAddition() { // @TODO. For now, cheat and add the data directly to the db. - $doc = array( + $doc = [ 'sync_clientid' => 'abc', 'sync_user' => 'mike', 'message_uid' => 'def', - 'sync_devid' => 'dev123' - ); + 'sync_devid' => 'dev123', + ]; self::$mongo->horde_activesync_test->HAS_map->insert($doc); self::$state->loadDeviceInfo('dev123', 'mike'); $this->assertEquals('def', self::$state->isDuplicatePIMAddition('abc')); } - #[Depends('testGetDeviceInfo')] + /** + * @depends testGetDeviceInfo + */ public function testCacheInitialState() { $this->_testCacheInitialState(); } - #[Depends('testCacheInitialState')] + /** + * @depends testCacheInitialState + */ public function testCacheFolders() { $this->_testCacheFolders(); } - #[Depends('testCacheFolders')] + /** + * @depends testCacheFolders + */ public function testCacheDataRestrictFields() { $this->_testCacheDataRestrictFields(); } - #[Depends('testCacheFolders')] + /** + * @depends testCacheFolders + */ public function testCacheFoldersPersistence() { $this->_testCacheFoldersPersistence(); } - #[Depends('testCacheFolders')] + /** + * @depends testCacheFolders + */ public function testCacheUniqueness() { $this->_testCacheUniqueness(); } - #[Depends('testCacheFolders')] + /** + * @depends testCacheFolders + */ public function testCacheCollections() { $this->_testCacheCollections(); } - #[Depends('testCacheCollections')] + /** + * @depends testCacheCollections + */ public function testLoadCollectionsFromCache() { return $this->_testLoadCollectionsFromCache(); } - #[Depends('testCacheCollections')] + /** + * @depends testCacheCollections + */ public function testGettingImapId() { $this->_testGettingImapId(); } - #[Depends('testCacheCollections')] + /** + * @depends testCacheCollections + */ public function testCacheRefreshCollections() { $this->_testCacheRefreshCollections(); } - #[Depends('testCacheCollections')] + /** + * @depends testCacheCollections + */ public function testCollectionsFromCache() { $this->_testCollectionsFromCache(); } - #[Depends('testCacheFolders')] + /** + * @depends testCacheFolders + */ public function testGetStateWithNoState() { $this->_testGetStateWithNoState(); } - #[Depends('testCollectionsFromCache')] + /** + * @depends testCollectionsFromCache + */ public function testCollectionHandler() { $this->_testCollectionHandler(); } - #[Depends('testCollectionHandler')] + /** + * @depends testCollectionHandler + */ public function testPartialSyncWithChangedCollections() { $this->_testPartialSyncWithChangedCollections(); } - #[Depends('testCollectionHandler')] + /** + * @depends testCollectionHandler + */ public function testPartialSyncWithUnchangedCollections() { $this->_testPartialSyncWithUnchangedCollections(); } - #[Depends('testCollectionHandler')] + /** + * @depends testCollectionHandler + */ public function testMissingCollections() { $this->_testMissingCollections(); } - #[Depends('testCollectionHandler')] + /** + * @depends testCollectionHandler + */ public function testChangingFilterType() { $this->_testChangingFilterType(); } - #[Depends('testCollectionHandler')] + /** + * @depends testCollectionHandler + */ public function testEmptyResponse() { $this->_testEmptyResponse(); } - #[Depends('testGetDeviceInfo')] + /** + * @depends testGetDeviceInfo + */ public function testHierarchy() { $this->_testHierarchy(); } - #[Depends('testCollectionHandler')] + /** + * @depends testCollectionHandler + */ public function testPartialSyncWithOnlyChangedHbInterval() { $this->_testPartialSyncWithOnlyChangedHbInterval(); @@ -163,24 +212,25 @@ public function testPartialSyncWithOnlyChangedHbInterval() public static function setUpBeforeClass(): void { - if (!(extension_loaded('mongo') || extension_loaded('mongodb')) || - !class_exists('Horde_Mongo_Client')) { + if (!(extension_loaded('mongo') || extension_loaded('mongodb')) + || !class_exists('Horde_Mongo_Client')) { self::$reason = 'MongoDB extension not loaded.'; return; } - if (($config = self::getConfig('ACTIVESYNC_MONGO_TEST_CONFIG', __DIR__ . '/../..')) && - isset($config['activesync']['mongo']['hostspec'])) { - self::$mongo = \Horde\ActiveSync\Test\Helpers\MongoHelper::createMongoClient([ + if (($config = self::getConfig('ACTIVESYNC_MONGO_TEST_CONFIG', __DIR__ . '/../..')) + && isset($config['activesync']['mongo']['hostspec'])) { + $factory = new Horde_Test_Factory_Mongo(); + self::$mongo = $factory->create([ 'config' => $config['activesync']['mongo']['hostspec'], - 'dbname' => 'horde_activesync_test' + 'dbname' => 'horde_activesync_test', ]); } if (empty(self::$mongo)) { self::$reason = 'Mongo connection failed.'; return; } - self::$state = new Horde_ActiveSync_State_Mongo(array('connection' => self::$mongo)); - self::$logger = \Horde\ActiveSync\Test\Helpers\LogHelper::createMockLogger(); + self::$state = new Horde_ActiveSync_State_Mongo(['connection' => self::$mongo]); + self::$logger = new Horde_Test_Log(); } public function setUp(): void @@ -188,23 +238,22 @@ public function setUp(): void if (empty(self::$mongo)) { $this->markTestSkipped(self::$reason); } - $backend = $this->getMockBuilder(\Horde_ActiveSync_Driver_Base::class) - ->disableOriginalConstructor() - ->getMock(); + $backend = $this->getMockSkipConstructor('Horde_ActiveSync_Driver_Base'); $backend->expects($this->any())->method('getUser')->will($this->returnValue('mike')); self::$state->setBackend($backend); } public static function tearDownAfterClass(): void { - if ((extension_loaded('mongo') || extension_loaded('mongodb')) && - class_exists('Horde_Mongo_Client') && - ($config = self::getConfig('ACTIVESYNC_MONGO_TEST_CONFIG', __DIR__ . '/../..')) && - isset($config['activesync']['mongo']['hostspec'])) { + if ((extension_loaded('mongo') || extension_loaded('mongodb')) + && class_exists('Horde_Mongo_Client') + && ($config = self::getConfig('ACTIVESYNC_MONGO_TEST_CONFIG', __DIR__ . '/../..')) + && isset($config['activesync']['mongo']['hostspec'])) { try { - $mongo = \Horde\ActiveSync\Test\Helpers\MongoHelper::createMongoClient([ + $factory = new Horde_Test_Factory_Mongo(); + $mongo = $factory->create([ 'config' => $config['activesync']['mongo']['hostspec'], - 'dbname' => 'horde_activesync_test' + 'dbname' => 'horde_activesync_test', ]); $mongo->activesync_test->drop(); } catch (MongoConnectionException $e) { diff --git a/test/Horde/ActiveSync/StateTest/Sql/MysqlTest.php b/test/Horde/ActiveSync/StateTest/Sql/MysqlTest.php index 72839658..26ffeb28 100644 --- a/test/Horde/ActiveSync/StateTest/Sql/MysqlTest.php +++ b/test/Horde/ActiveSync/StateTest/Sql/MysqlTest.php @@ -1,4 +1,5 @@ * @license http://www.horde.org/licenses/gpl GPLv2 @@ -6,9 +7,14 @@ * @package Horde_ActiveSync * @subpackage UnitTests */ + namespace Horde\ActiveSync\StateTest\Sql; + use Horde\ActiveSync\StateTest\Sql\TestBase; +/** + * @coversNothing + */ class MysqlTest extends TestBase { public static function setUpBeforeClass(): void @@ -26,4 +32,4 @@ public static function setUpBeforeClass(): void } } -} \ No newline at end of file +} diff --git a/test/Horde/ActiveSync/StateTest/Sql/MysqliTest.php b/test/Horde/ActiveSync/StateTest/Sql/MysqliTest.php index acc29060..9550e527 100644 --- a/test/Horde/ActiveSync/StateTest/Sql/MysqliTest.php +++ b/test/Horde/ActiveSync/StateTest/Sql/MysqliTest.php @@ -1,4 +1,5 @@ * @license http://www.horde.org/licenses/gpl GPLv2 @@ -6,9 +7,14 @@ * @package Horde_ActiveSync * @subpackage UnitTests */ + namespace Horde\ActiveSync\StateTest\Sql; + use Horde\ActiveSync\StateTest\Sql\TestBase; +/** + * @coversNothing + */ class MysqliTest extends TestBase { public static function setUpBeforeClass(): void @@ -17,7 +23,8 @@ public static function setUpBeforeClass(): void self::$reason = 'No mysqli extension'; return; } - $config = self::getConfig('ACTIVESYNC_SQL_MYSQLI_TEST_CONFIG', dirname(__FILE__) . '/../..');; + $config = self::getConfig('ACTIVESYNC_SQL_MYSQLI_TEST_CONFIG', dirname(__FILE__) . '/../..'); + ; if ($config && !empty($config['activesync']['sql']['mysqli'])) { self::$db = new Horde_Db_Adapter_Mysqli($config['activesync']['sql']['mysqli']); parent::setUpBeforeClass(); @@ -26,4 +33,4 @@ public static function setUpBeforeClass(): void } } -} \ No newline at end of file +} diff --git a/test/Horde/ActiveSync/StateTest/Sql/Oci8Test.php b/test/Horde/ActiveSync/StateTest/Sql/Oci8Test.php index e98b9a38..4424ddbe 100644 --- a/test/Horde/ActiveSync/StateTest/Sql/Oci8Test.php +++ b/test/Horde/ActiveSync/StateTest/Sql/Oci8Test.php @@ -1,4 +1,5 @@ * @license http://www.horde.org/licenses/gpl GPLv2 @@ -6,9 +7,14 @@ * @package Horde_ActiveSync * @subpackage UnitTests */ + namespace Horde\ActiveSync\StateTest\Sql; + use Horde\ActiveSync\StateTest\Sql\TestBase; +/** + * @coversNothing + */ class Oci8Test extends TestBase { public static function setUpBeforeClass(): void @@ -26,4 +32,4 @@ public static function setUpBeforeClass(): void } } -} \ No newline at end of file +} diff --git a/test/Horde/ActiveSync/StateTest/Sql/Pdo/MysqlTest.php b/test/Horde/ActiveSync/StateTest/Sql/Pdo/MysqlTest.php index bd36c43d..32eb88bd 100644 --- a/test/Horde/ActiveSync/StateTest/Sql/Pdo/MysqlTest.php +++ b/test/Horde/ActiveSync/StateTest/Sql/Pdo/MysqlTest.php @@ -1,4 +1,5 @@ * @license http://www.horde.org/licenses/gpl GPLv2 @@ -6,16 +7,21 @@ * @package Horde_ActiveSync * @subpackage UnitTests */ + namespace Horde\ActiveSync\StateTest\Sql\Pdo; + use Horde\ActiveSync\StateTest\Sql\TestBase; -use \PDO; +use PDO; +/** + * @coversNothing + */ class MysqlTest extends TestBase { public static function setUpBeforeClass(): void { - if (!extension_loaded('pdo') || - !in_array('mysql', PDO::getAvailableDrivers())) { + if (!extension_loaded('pdo') + || !in_array('mysql', PDO::getAvailableDrivers())) { self::$reason = 'No mysql extension or no mysql PDO driver'; return; } diff --git a/test/Horde/ActiveSync/StateTest/Sql/Pdo/SqliteTest.php b/test/Horde/ActiveSync/StateTest/Sql/Pdo/SqliteTest.php index b68c24b7..ecb03ec1 100644 --- a/test/Horde/ActiveSync/StateTest/Sql/Pdo/SqliteTest.php +++ b/test/Horde/ActiveSync/StateTest/Sql/Pdo/SqliteTest.php @@ -1,4 +1,5 @@ * @license http://www.horde.org/licenses/gpl GPLv2 @@ -6,16 +7,23 @@ * @package Horde_ActiveSync * @subpackage UnitTests */ + namespace Horde\ActiveSync\StateTest\Sql\Pdo; + use Horde\ActiveSync\StateTest\Sql\TestBase; -use Horde\ActiveSync\Test\Helpers\DbHelper; +use Horde_Test_Factory_Db; +/** + * @coversNothing + */ class SqliteTest extends TestBase { public static function setUpBeforeClass(): void { + $factory_db = new Horde_Test_Factory_Db(); + if (class_exists('Horde_Db_Adapter_Pdo_Sqlite')) { - self::$db = DbHelper::createSqliteDb(); + self::$db = $factory_db->create(); parent::setUpBeforeClass(); } else { self::$reason = 'Sqlite not available'; diff --git a/test/Horde/ActiveSync/StateTest/Sql/TestBase.php b/test/Horde/ActiveSync/StateTest/Sql/TestBase.php index 7d3eeea6..56afca59 100644 --- a/test/Horde/ActiveSync/StateTest/Sql/TestBase.php +++ b/test/Horde/ActiveSync/StateTest/Sql/TestBase.php @@ -1,4 +1,5 @@ * @license http://www.horde.org/licenses/gpl GPLv2 @@ -6,9 +7,10 @@ * @package Horde_ActiveSync * @subpackage UnitTests */ + namespace Horde\ActiveSync\StateTest\Sql; + use Horde\ActiveSync\StateTest\TestBase as ExtTestBase; -use PHPUnit\Framework\Attributes\Depends; class TestBase extends ExtTestBase { @@ -21,128 +23,170 @@ public function testGetDeviceInfo() $this->_testGetDeviceInfo(); } - #[Depends('testGetDeviceInfo')] + /** + * @depends testGetDeviceInfo + */ public function testCacheInitialState() { $this->_testCacheInitialState(); } - #[Depends('testCacheInitialState')] + /** + * @depends testCacheInitialState + */ public function testCacheFolders() { $this->_testCacheFolders(); } - #[Depends('testCacheFolders')] + /** + * @depends testCacheFolders + */ public function testCacheDataRestrictFields() { $this->_testCacheDataRestrictFields(); } - #[Depends('testCacheFolders')] + /** + * @depends testCacheFolders + */ public function testCacheFoldersPersistence() { $this->_testCacheFoldersPersistence(); } - #[Depends('testCacheFolders')] + /** + * @depends testCacheFolders + */ public function testCacheUniqueness() { $this->_testCacheUniqueness(); } - #[Depends('testCacheFolders')] + /** + * @depends testCacheFolders + */ public function testCacheCollections() { $this->_testCacheCollections(); } - #[Depends('testCacheCollections')] + /** + * @depends testCacheCollections + */ public function testLoadCollectionsFromCache() { return $this->_testLoadCollectionsFromCache(); } - #[Depends('testCacheCollections')] + /** + * @depends testCacheCollections + */ public function testGettingImapId() { $this->_testGettingImapId(); } - #[Depends('testCacheCollections')] + /** + * @depends testCacheCollections + */ public function testCacheRefreshCollections() { $this->_testCacheRefreshCollections(); } - #[Depends('testCacheCollections')] + /** + * @depends testCacheCollections + */ public function testCollectionsFromCache() { $this->_testCollectionsFromCache(); } - #[Depends('testCacheFolders')] + /** + * @depends testCacheFolders + */ public function testGetStateWithNoState() { $this->_testGetStateWithNoState(); $this->markTestIncomplete(); } - #[Depends('testCollectionsFromCache')] + /** + * @depends testCollectionsFromCache + */ public function testCollectionHandler() { $this->_testCollectionHandler(); } - #[Depends('testCollectionHandler')] + /** + * @depends testCollectionHandler + */ public function testPartialSyncWithChangedCollections() { $this->_testPartialSyncWithChangedCollections(); } - #[Depends('testCollectionHandler')] + /** + * @depends testCollectionHandler + */ public function testPartialSyncWithUnchangedCollections() { $this->_testPartialSyncWithUnchangedCollections(); } - #[Depends('testCollectionHandler')] + /** + * @depends testCollectionHandler + */ public function testMissingCollections() { $this->_testMissingCollections(); } - #[Depends('testCollectionHandler')] + /** + * @depends testCollectionHandler + */ public function testChangingFilterType() { $this->_testChangingFilterType(); } - #[Depends('testCollectionHandler')] + /** + * @depends testCollectionHandler + */ public function testEmptyResponse() { $this->_testEmptyResponse(); } - #[Depends('testGetDeviceInfo')] + /** + * @depends testGetDeviceInfo + */ public function testHierarchy() { $this->_testHierarchy(); } - #[Depends('testGetDeviceInfo')] + /** + * @depends testGetDeviceInfo + */ public function testListDevices() { $this->_testListDevices(); } - #[Depends('testListDevices')] + /** + * @depends testListDevices + */ public function testPolicyKeys() { $this->_testPolicyKeys(); } - #[Depends('testCollectionHandler')] + /** + * @depends testCollectionHandler + */ public function testPartialSyncWithOnlyChangedHbInterval() { $this->_testPartialSyncWithOnlyChangedHbInterval(); @@ -158,13 +202,14 @@ public static function setUpBeforeClass(): void . '/Horde_ActiveSync/migration'; error_reporting(E_ALL | E_STRICT); } - self::$logger = \Horde\ActiveSync\Test\Helpers\LogHelper::createMockLogger(); + self::$logger = new Horde_Test_Log(); if (self::$db) { self::$migrator = new Horde_Db_Migration_Migrator( self::$db, - self::$logger, - array('migrationsPath' => $dir, - 'schemaTableName' => 'horde_activesync_schema_info')); + self::$logger->getLogger(), + ['migrationsPath' => $dir, + 'schemaTableName' => 'horde_activesync_schema_info'] + ); self::$migrator->up(); } } @@ -187,9 +232,9 @@ public function setUp(): void $this->markTestSkipped(self::$reason); return; } - self::$state = new Horde_ActiveSync_State_Sql(array('db' => self::$db)); + self::$state = new Horde_ActiveSync_State_Sql(['db' => self::$db]); $backend = $this->getMockBuilder('Horde_ActiveSync_Driver_Base')->disableOriginalConstructor()->getMock(); $backend->expects($this->any())->method('getUser')->will($this->returnValue('mike')); self::$state->setBackend($backend); } -} \ No newline at end of file +} diff --git a/test/Horde/ActiveSync/StateTest/TestBase.php b/test/Horde/ActiveSync/StateTest/TestBase.php index 1f4576ca..1257ebff 100644 --- a/test/Horde/ActiveSync/StateTest/TestBase.php +++ b/test/Horde/ActiveSync/StateTest/TestBase.php @@ -1,4 +1,5 @@ * @license http://www.horde.org/licenses/gpl GPLv2 @@ -6,36 +7,23 @@ * @package Horde_ActiveSync * @subpackage UnitTests */ + namespace Horde\ActiveSync\StateTest; -use PHPUnit\Framework\TestCase; -use Horde\ActiveSync\Test\Helpers\LogHelper; +use Horde_Test_Case as TestCase; + +/** + * @coversNothing + */ class TestBase extends TestCase { protected static $state; protected static $logger; - /** - * Load test configuration from conf.php if it exists. - * - * @param string $varname Environment variable name - * @param string $path Path to search for conf.php - * @return array|false Configuration array or false - */ - public static function getConfig($varname, $path) - { - $config_file = $path . '/conf.php'; - if (file_exists($config_file)) { - require $config_file; - return $config ?? false; - } - return false; - } - protected function _testGetDeviceInfo() { // First with no existing deivce. - $this->assertEquals(false, (boolean)self::$state->deviceExists('dev123', 'mike')); + $this->assertEquals(false, (bool) self::$state->deviceExists('dev123', 'mike')); // Can't use setExpectedException here since it stops the rest // of the method from running when it's thrown. @@ -53,9 +41,9 @@ protected function _testGetDeviceInfo() $deviceInfo->id = 'dev123'; $deviceInfo->user = 'mike'; $deviceInfo->policykey = 456; - $deviceInfo->supported = array(); + $deviceInfo->supported = []; $deviceInfo->save(); - $this->assertEquals(true, (boolean)self::$state->deviceExists('dev123', 'mike')); + $this->assertEquals(true, (bool) self::$state->deviceExists('dev123', 'mike')); $di = self::$state->loadDeviceInfo('dev123', 'mike'); $this->assertEquals($deviceInfo, $di); @@ -76,7 +64,7 @@ protected function _testListDevices() $deviceInfo->id = 'dev123'; $deviceInfo->user = 'ashley'; $deviceInfo->policykey = 123; - $deviceInfo->supported = array(); + $deviceInfo->supported = []; $deviceInfo->save(); $devices = self::$state->listDevices(); @@ -117,10 +105,10 @@ protected function _testDuplicatePIMAddition() protected function _loadStateTest() { $this->markTestSkipped(); - $collection = array( + $collection = [ 'serverid' => '@Contacts@', 'folderid' => '@Contacts@', - 'class' => Horde_ActiveSync::CLASS_CONTACTS); + 'class' => Horde_ActiveSync::CLASS_CONTACTS]; self::$state->loadDeviceInfo('dev123', 'mike'); self::$state->loadState($collection, 0, Horde_ActiveSync::REQUEST_TYPE_SYNC, 'abcdef'); self::$state->setNewSyncKey('{51941e99-0b9c-41f8-b678-1532c0a8015f}1'); @@ -130,60 +118,60 @@ protected function _loadStateTest() protected function _testCacheInitialState() { $cache = new Horde_ActiveSync_SyncCache(self::$state, 'dev123', 'mike', self::$logger->getLogger()); - $this->assertEquals(array(), $cache->getCollections()); - $this->assertEquals(array(), $cache->getCollections(true)); + $this->assertEquals([], $cache->getCollections()); + $this->assertEquals([], $cache->getCollections(true)); $this->assertEquals(0, $cache->countCollections()); $this->assertEquals(false, $cache->collectionExists('@Contacts@')); $this->assertEquals(false, $cache->collectionIsPingable('@Contacts@')); $this->assertEquals(false, $cache->collectionIsPingable('@Contacts@')); - $this->assertEquals(array(), $cache->getFolders()); + $this->assertEquals([], $cache->getFolders()); $this->assertEquals(false, $cache->getFolder('@Contacts@')); } protected function _testCacheFolders() { - $log = LogHelper::createMockLogger(); + $log = new Horde_Test_Log(); $cache = new Horde_ActiveSync_SyncCache(self::$state, 'dev123', 'mike', self::$logger->getLogger()); // First Fixture - $folder = new Horde_ActiveSync_Message_Folder((array('logger' => $log, 'protocolversion' => Horde_ActiveSync::VERSION_TWELVEONE))); + $folder = new Horde_ActiveSync_Message_Folder((['logger' => $log->getLogger(), 'protocolversion' => Horde_ActiveSync::VERSION_TWELVEONE])); $folder->type = Horde_ActiveSync::FOLDER_TYPE_CONTACT; $folder->serverid = '@Contacts@'; $folder->_serverid = '@Contacts@'; $cache->updateFolder($folder); // Second fixture - $folder = new Horde_ActiveSync_Message_Folder((array('logger' => $log->getLogger(), 'protocolversion' => Horde_ActiveSync::VERSION_TWELVEONE))); + $folder = new Horde_ActiveSync_Message_Folder((['logger' => $log->getLogger(), 'protocolversion' => Horde_ActiveSync::VERSION_TWELVEONE])); $folder->type = Horde_ActiveSync::FOLDER_TYPE_INBOX; $folder->serverid = '519422f1-4c5c-4547-946a-1701c0a8015f'; $folder->_serverid = 'INBOX'; $cache->updateFolder($folder); - $expected = array( - '@Contacts@' => array( + $expected = [ + '@Contacts@' => [ 'class' => 'Contacts', 'serverid' => '@Contacts@', - 'type' => 9 - ), - '519422f1-4c5c-4547-946a-1701c0a8015f' => array( + 'type' => 9, + ], + '519422f1-4c5c-4547-946a-1701c0a8015f' => [ 'class' => 'Email', 'serverid' => 'INBOX', - 'type' => 2 - ) - ); + 'type' => 2, + ], + ]; $this->assertEquals($expected, $cache->getFolders()); - $expected = array( + $expected = [ 'class' => 'Email', 'serverid' => 'INBOX', - 'type' => 2 - ); + 'type' => 2, + ]; $this->assertEquals($expected, $cache->getFolder('519422f1-4c5c-4547-946a-1701c0a8015f')); $cache->save(); } protected function _testCacheDataRestrictFields() { - $cache_data = self::$state->getSyncCache('dev123', 'mike', array('folders')); + $cache_data = self::$state->getSyncCache('dev123', 'mike', ['folders']); $this->assertCount(1, $cache_data); $this->assertEquals('folders', key($cache_data)); } @@ -191,65 +179,65 @@ protected function _testCacheDataRestrictFields() protected function _testCacheFoldersPersistence() { $cache = new Horde_ActiveSync_SyncCache(self::$state, 'dev123', 'mike', self::$logger->getLogger()); - $expected = array( - '@Contacts@' => array( + $expected = [ + '@Contacts@' => [ 'class' => 'Contacts', 'serverid' => '@Contacts@', - 'type' => 9 - ), - '519422f1-4c5c-4547-946a-1701c0a8015f' => array( + 'type' => 9, + ], + '519422f1-4c5c-4547-946a-1701c0a8015f' => [ 'class' => 'Email', 'serverid' => 'INBOX', - 'type' => 2 - ) - ); + 'type' => 2, + ], + ]; $this->assertEquals($expected, $cache->getFolders()); - $expected = array( + $expected = [ 'class' => 'Email', 'serverid' => 'INBOX', - 'type' => 2 - ); + 'type' => 2, + ]; $this->assertEquals($expected, $cache->getFolder('519422f1-4c5c-4547-946a-1701c0a8015f')); } protected function _testCacheCollections() { - $collections = array( - '519422f1-4c5c-4547-946a-1701c0a8015f' => array( + $collections = [ + '519422f1-4c5c-4547-946a-1701c0a8015f' => [ 'class' => 'Email', 'windowsize' => 5, 'truncation' => 0, 'mimesupport' => 0, 'mimetruncation' => 8, 'conflict' => 1, - 'bodyprefs' => array( + 'bodyprefs' => [ 'wanted' => 2, - 2 => array( + 2 => [ 'type' => 2, - 'truncationsize' => 200000) - ), + 'truncationsize' => 200000], + ], 'deletesasmoves' => 1, 'filtertype' => 5, 'id' => '519422f1-4c5c-4547-946a-1701c0a8015f', - 'serverid' => 'INBOX'), - '@Contacts@' => array( + 'serverid' => 'INBOX'], + '@Contacts@' => [ 'class' => 'Contacts', 'windowsize' => 4, 'truncation' => 0, 'mimesupport' => 0, 'mimetruncation' => 8, 'conflict' => 1, - 'bodyprefs' => array( + 'bodyprefs' => [ 'wanted' => 1, - 1 => array( + 1 => [ 'type' => 1, - 'truncationsize' => 200000) + 'truncationsize' => 200000], - ), + ], 'deletesasmoves' => 1, 'id' => '@Contacts@', - 'serverid' => '@Contacts@') - ); + 'serverid' => '@Contacts@'], + ]; $cache = new Horde_ActiveSync_SyncCache(self::$state, 'dev123', 'mike', self::$logger->getLogger()); foreach ($collections as $collection) { $cache->addCollection($collection); @@ -263,7 +251,7 @@ protected function _testCacheCollections() $this->assertEquals(2, $cache->countCollections()); $this->assertEquals($collections, $cache->getCollections(false)); - $this->assertEquals(array(), $cache->getCollections(true)); + $this->assertEquals([], $cache->getCollections(true)); $this->assertEquals(true, $cache->collectionExists('@Contacts@')); $this->assertEquals(true, $cache->collectionExists('519422f1-4c5c-4547-946a-1701c0a8015f')); $this->assertEquals(false, $cache->collectionExists('foo')); @@ -274,8 +262,9 @@ protected function _testCacheCollections() $cache->removePingableCollection('@Contacts@'); $this->assertEquals(false, $cache->collectionIsPingable('@Contacts@')); $cache->updateCollection( - array('id' => '519422f1-4c5c-4547-946a-1701c0a8015f', 'newsynckey' => '{51941e99-0b9c-41f8-b678-1532c0a8015f}2'), - array('newsynckey' => true)); + ['id' => '519422f1-4c5c-4547-946a-1701c0a8015f', 'newsynckey' => '{51941e99-0b9c-41f8-b678-1532c0a8015f}2'], + ['newsynckey' => true] + ); $cache->save(); // Now we should have a lastsynckey @@ -295,23 +284,23 @@ protected function _testLoadCollectionsFromCache() protected function _testCollectionsFromCache() { $cache = new Horde_ActiveSync_SyncCache(self::$state, 'dev123', 'mike', self::$logger->getLogger()); - $collections = array('519422f1-4c5c-4547-946a-1701c0a8015f' => array('id' => '519422f1-4c5c-4547-946a-1701c0a8015f')); - $expected = array('519422f1-4c5c-4547-946a-1701c0a8015f' => array( + $collections = ['519422f1-4c5c-4547-946a-1701c0a8015f' => ['id' => '519422f1-4c5c-4547-946a-1701c0a8015f']]; + $expected = ['519422f1-4c5c-4547-946a-1701c0a8015f' => [ 'class' => 'Email', 'windowsize' => 5, 'truncation' => 0, 'mimesupport' => 0, 'mimetruncation' => 8, - 'bodyprefs' => array( + 'bodyprefs' => [ 'wanted' => 2, - 2 => array( + 2 => [ 'type' => 2, - 'truncationsize' => 200000) - ), + 'truncationsize' => 200000], + ], 'filtertype' => 5, 'id' => '519422f1-4c5c-4547-946a-1701c0a8015f', 'serverid' => 'INBOX', - 'type' => 2)); + 'type' => 2]]; $cache->validateCollectionsFromCache($collections); $this->assertEquals($expected, $collections); } @@ -321,8 +310,9 @@ protected function _testCacheRefreshCollections() $cache = new Horde_ActiveSync_SyncCache(self::$state, 'dev123', 'mike', self::$logger->getLogger()); $newcache = new Horde_ActiveSync_SyncCache(self::$state, 'dev123', 'mike', self::$logger->getLogger()); $newcache->updateCollection( - array('id' => '519422f1-4c5c-4547-946a-1701c0a8015f', 'newsynckey' => '{51941e99-0b9c-41f8-b678-1532c0a8015f}3'), - array('newsynckey' => true)); + ['id' => '519422f1-4c5c-4547-946a-1701c0a8015f', 'newsynckey' => '{51941e99-0b9c-41f8-b678-1532c0a8015f}3'], + ['newsynckey' => true] + ); sleep(1); $newcache->save(); @@ -348,16 +338,16 @@ protected function _testValidateAfterUpdateTimestamp() protected function _testCacheUniqueness() { $cache = new Horde_ActiveSync_SyncCache(self::$state, 'dev123', 'bob', self::$logger->getLogger()); - $this->assertEquals(array(), $cache->getFolders()); + $this->assertEquals([], $cache->getFolders()); $cache = new Horde_ActiveSync_SyncCache(self::$state, 'dev456', 'mike', self::$logger->getLogger()); - $this->assertEquals(array(), $cache->getFolders()); + $this->assertEquals([], $cache->getFolders()); } protected function _testGetStateWithNoState() { self::$state->loadDeviceInfo('dev123'); - self::$state->loadState(array(), 0, Horde_ActiveSync::REQUEST_TYPE_FOLDERSYNC); + self::$state->loadState([], 0, Horde_ActiveSync::REQUEST_TYPE_FOLDERSYNC); } protected function _testCollectionHandler() @@ -391,23 +381,23 @@ protected function _testPartialSyncWithChangedCollections() // Now import a collection that IS different (which is the only reason // to have imported colletions with PARTIAL). - $col = array( + $col = [ 'id' => '519422f1-4c5c-4547-946a-1701c0a8015f', 'windowsize' => 5, 'truncation' => 0, 'mimesupport' => 0, 'mimetruncation' => 8, 'conflict' => 1, - 'bodyprefs' => array( + 'bodyprefs' => [ 'wanted' => 2, - 2 => array( + 2 => [ 'type' => 2, - 'truncationsize' => 100000) - ), + 'truncationsize' => 100000], + ], 'synckey' => '{51941e99-0b9c-41f8-b678-1532c0a8015f}3', 'deletesasmoves' => 1, 'filtertype' => 5, - ); + ]; $collections->addCollection($col); $this->assertEquals(2, $collections->collectionCount()); $this->assertEquals(true, $collections->initPartialSync()); @@ -432,23 +422,23 @@ protected function _testPartialSyncWithUnchangedCollections() // Pretent to read a new collection in from xml. // This one is identical to what we already have, so this should also // fail. - $col = array( + $col = [ 'id' => '519422f1-4c5c-4547-946a-1701c0a8015f', 'windowsize' => 5, 'truncation' => 0, 'mimesupport' => 0, 'mimetruncation' => 8, 'conflict' => 1, - 'bodyprefs' => array( + 'bodyprefs' => [ 'wanted' => 2, - 2 => array( + 2 => [ 'type' => 2, - 'truncationsize' => 200000) - ), + 'truncationsize' => 200000], + ], 'synckey' => '{517541cc-b188-478d-9e1a-fa49c0a8015f}3', 'deletesasmoves' => 1, 'filtertype' => 5, - ); + ]; $collections->addCollection($col); $this->assertEquals(false, $collections->initPartialSync()); @@ -464,7 +454,7 @@ protected function _testPartialSyncWithOnlyChangedHbInterval() $this->markTestIncomplete('No idea why the cache does not load the collections here.'); $collections = $this->getCollectionHandler(); $collections->loadCollectionsFromCache(); - $collections->setHeartbeat(array('hbinterval' => 1)); + $collections->setHeartbeat(['hbinterval' => 1]); $result = $collections->initPartialSync(); $this->assertEquals(true, $result); } @@ -495,28 +485,28 @@ protected function _testMissingCollections() { // Need to prime the cache with a synckey for contacts so we have // another one to load for the test. - $col = array('id' => '@Contacts@', 'newsynckey' => '{517541cc-b188-478d-aaaa-fa49c0a8015f}35'); + $col = ['id' => '@Contacts@', 'newsynckey' => '{517541cc-b188-478d-aaaa-fa49c0a8015f}35']; $cache = new Horde_ActiveSync_SyncCache(self::$state, 'dev123', 'mike', self::$logger->getLogger()); - $cache->updateCollection($col, array('newsynckey' => true)); + $cache->updateCollection($col, ['newsynckey' => true]); $cache->save(); $collections = $this->getCollectionHandler(); - $col = array( + $col = [ 'id' => '519422f1-4c5c-4547-946a-1701c0a8015f', 'windowsize' => 5, 'truncation' => 0, 'mimesupport' => 0, 'mimetruncation' => 8, 'conflict' => 1, - 'bodyprefs' => array( + 'bodyprefs' => [ 'wanted' => 2, - 2 => array( + 2 => [ 'type' => 2, - 'truncationsize' => 300000) - ), + 'truncationsize' => 300000], + ], 'synckey' => '{517541cc-b188-478d-9e1a-fa49c0a8015f}3', 'deletesasmoves' => 1, 'filtertype' => 5, - ); + ]; $collections->addCollection($col); $collections->initPartialSync(); $this->assertEquals(2, $collections->collectionCount()); @@ -528,23 +518,23 @@ protected function _testMissingCollections() protected function _testChangingFilterType() { $collections = $this->getCollectionHandler(); - $col = array( + $col = [ 'id' => '519422f1-4c5c-4547-946a-1701c0a8015f', 'windowsize' => 5, 'truncation' => 0, 'mimesupport' => 0, 'mimetruncation' => 8, 'conflict' => 1, - 'bodyprefs' => array( + 'bodyprefs' => [ 'wanted' => 2, - 2 => array( + 2 => [ 'type' => 2, - 'truncationsize' => 200000) - ), + 'truncationsize' => 200000], + ], 'synckey' => '{517541cc-b188-478d-9e1a-fa49c0a8015f}96', 'deletesasmoves' => 1, 'filtertype' => 4, - ); + ]; $collections->addCollection($col); $this->assertEquals(false, $collections->checkFilterType($col['id'], $col['filtertype'])); } @@ -561,33 +551,33 @@ protected function _testHierarchy() self::$state->setBackend($this->getMockDriver()); $collections = $this->getCollectionHandler(true); $seen = $collections->initHierarchySync(0); - $this->assertEquals(array(), $seen); - $expected = array( - array( + $this->assertEquals([], $seen); + $expected = [ + [ 'type' => 'change', 'flags' => 'NewMessage', 'id' => '@Tasks@', - 'serverid' => '@Tasks@' - ), - array( + 'serverid' => '@Tasks@', + ], + [ 'type' => 'change', 'flags' => 'NewMessage', 'id' => '@Notes@', - 'serverid' => '@Notes@' - ), - array( + 'serverid' => '@Notes@', + ], + [ 'type' => 'change', 'flags' => 'NewMessage', 'id' => '@Contacts@', - 'serverid' => '@Contacts@' - ), - array( + 'serverid' => '@Contacts@', + ], + [ 'type' => 'change', 'flags' => 'NewMessage', 'id' => '@Calendar@', - 'serverid' => '@Calendar@' - ) - ); + 'serverid' => '@Calendar@', + ], + ]; $changes = $collections->getHierarchyChanges(); $this->assertEquals($expected, $changes); } @@ -595,11 +585,11 @@ protected function _testHierarchy() public function getMockDriver() { $connector = new Horde_ActiveSync_Driver_MockConnector(); - $driver = new Horde_ActiveSync_Driver_Mock(array( + $driver = new Horde_ActiveSync_Driver_Mock([ 'connector' => $connector, 'auth' => false, 'imap' => false, - 'state' => self::$state)); + 'state' => self::$state]); return $driver; } diff --git a/test/Horde/ActiveSync/Stub/ImapFactory.php b/test/Horde/ActiveSync/Stub/ImapFactory.php index 92a75cb8..c8bf2f1b 100644 --- a/test/Horde/ActiveSync/Stub/ImapFactory.php +++ b/test/Horde/ActiveSync/Stub/ImapFactory.php @@ -1,6 +1,7 @@ = 12.1 */ $url = 'oBEJBBBOaW5lMkVDN0VDMEJCNTREBAGJpmIHQW5kcm9pZAcBAA=='; $results = Horde_ActiveSync_Utils::decodeBase64($url); - $fixture = array( + $fixture = [ 'ProtVer' => '16.0', 'Cmd' => 'Settings', 'Locale' => 1033, @@ -25,8 +31,8 @@ public function testBase64Uri() 'PolicyKey' => 1655081217, 'DeviceType' => 'Android', 'SaveInSent' => false, - 'AcceptMultiPart' => false - ); + 'AcceptMultiPart' => false, + ]; $this->assertEquals($fixture, $results); /* Smart Forward */ @@ -35,7 +41,7 @@ public function testBase64Uri() $results['PolicyKey'] = sprintf('%u', $results['PolicyKey']); // This is binary data, test it separately. - $fixture = array( + $fixture = [ 'ProtVer' => '12.1', 'Cmd' => 'SmartForward', 'Locale' => 1033, @@ -45,37 +51,37 @@ public function testBase64Uri() 'ItemId' => '119281', 'CollectionId' => 'INBOX', 'AcceptMultiPart' => false, - 'SaveInSent' => true - ); + 'SaveInSent' => true, + ]; $this->assertEquals($fixture, $results); } public function testBodyTypePref() { $this->markTestIncomplete('Needs refactoring.'); - $fixture = array( - 'bodyprefs' => array(Horde_ActiveSync::BODYPREF_TYPE_HTML => true, Horde_ActiveSync::BODYPREF_TYPE_MIME => true) - ); + $fixture = [ + 'bodyprefs' => [Horde_ActiveSync::BODYPREF_TYPE_HTML => true, Horde_ActiveSync::BODYPREF_TYPE_MIME => true], + ]; $this->assertEquals(Horde_ActiveSync::BODYPREF_TYPE_HTML, Horde_ActiveSync_Utils_Mime::getBodyTypePref($fixture)); $this->assertEquals(Horde_ActiveSync::BODYPREF_TYPE_MIME, Horde_ActiveSync_Utils_Mime::getBodyTypePref($fixture, false)); - $fixture = array( - 'bodyprefs' => array(Horde_ActiveSync::BODYPREF_TYPE_HTML => true) - ); + $fixture = [ + 'bodyprefs' => [Horde_ActiveSync::BODYPREF_TYPE_HTML => true], + ]; $this->assertEquals(Horde_ActiveSync::BODYPREF_TYPE_HTML, Horde_ActiveSync_Utils_Mime::getBodyTypePref($fixture)); $this->assertEquals(Horde_ActiveSync::BODYPREF_TYPE_HTML, Horde_ActiveSync_Utils_Mime::getBodyTypePref($fixture, false)); - $fixture = array( - 'bodyprefs' => array(Horde_ActiveSync::BODYPREF_TYPE_HTML => true) - ); + $fixture = [ + 'bodyprefs' => [Horde_ActiveSync::BODYPREF_TYPE_HTML => true], + ]; $this->assertEquals(Horde_ActiveSync::BODYPREF_TYPE_HTML, Horde_ActiveSync_Utils_Mime::getBodyTypePref($fixture)); $this->assertEquals(Horde_ActiveSync::BODYPREF_TYPE_HTML, Horde_ActiveSync_Utils_Mime::getBodyTypePref($fixture, false)); - $fixture = array( - 'bodyprefs' => array(Horde_ActiveSync::BODYPREF_TYPE_MIME => true) - ); + $fixture = [ + 'bodyprefs' => [Horde_ActiveSync::BODYPREF_TYPE_MIME => true], + ]; $this->assertEquals(Horde_ActiveSync::BODYPREF_TYPE_MIME, Horde_ActiveSync_Utils_Mime::getBodyTypePref($fixture)); $this->assertEquals(Horde_ActiveSync::BODYPREF_TYPE_MIME, Horde_ActiveSync_Utils_Mime::getBodyTypePref($fixture, false)); } -} \ No newline at end of file +} diff --git a/test/Horde/ActiveSync/bootstrap.php b/test/Horde/ActiveSync/bootstrap.php index 0acf9ab0..a4f35073 100644 --- a/test/Horde/ActiveSync/bootstrap.php +++ b/test/Horde/ActiveSync/bootstrap.php @@ -1,4 +1,5 @@