@@ -11,8 +11,7 @@ |
||
| 11 | 11 | $version = exec("hash git 2>/dev/null && cd $path >/dev/null 2>&1 && git describe --always 2>/dev/null"); |
| 12 | 12 | if ($branch && $version) { |
| 13 | 13 | define("GROMMUNIOSYNC_VERSION", $branch .'-'. $version); |
| 14 | - } |
|
| 15 | - else { |
|
| 14 | + } else { |
|
| 16 | 15 | define("GROMMUNIOSYNC_VERSION", "GIT"); |
| 17 | 16 | } |
| 18 | 17 | } |
@@ -30,8 +30,7 @@ discard block |
||
| 30 | 30 | if ($this->log_to_user_file === false) { |
| 31 | 31 | if (in_array(strtolower($this->GetDevid()), ['','validate'])) { |
| 32 | 32 | $this->setLogToUserFile(preg_replace('/[^a-z0-9]/', '_', strtolower($this->GetAuthUser())) . '.log'); |
| 33 | - } |
|
| 34 | - else { |
|
| 33 | + } else { |
|
| 35 | 34 | $this->setLogToUserFile( |
| 36 | 35 | preg_replace('/[^a-z0-9]/', '_', strtolower($this->GetAuthUser())) .'-'. |
| 37 | 36 | (($this->GetAuthUser() != $this->GetUser()) ? preg_replace('/[^a-z0-9]/', '_', strtolower($this->GetUser())) .'-' : '') . |
@@ -72,8 +71,7 @@ discard block |
||
| 72 | 71 | // when the users differ, we need to log both |
| 73 | 72 | if (strcasecmp($this->GetAuthUser(), $this->GetUser()) == 0) { |
| 74 | 73 | $log .= ' ['. $this->GetUser() .']'; |
| 75 | - } |
|
| 76 | - else { |
|
| 74 | + } else { |
|
| 77 | 75 | $log .= ' ['. $this->GetAuthUser() . Request::IMPERSONATE_DELIM . $this->GetUser() .']'; |
| 78 | 76 | } |
| 79 | 77 | } |
@@ -259,8 +259,7 @@ discard block |
||
| 259 | 259 | $this->unauthMessageCache = array(); |
| 260 | 260 | } |
| 261 | 261 | $this->WriteForUser($loglevel, $message); |
| 262 | - } |
|
| 263 | - else { |
|
| 262 | + } else { |
|
| 264 | 263 | $this->unauthMessageCache[] = array($loglevel, $message); |
| 265 | 264 | } |
| 266 | 265 | } |
@@ -299,10 +298,11 @@ discard block |
||
| 299 | 298 | * @return string |
| 300 | 299 | */ |
| 301 | 300 | protected function GetLogLevelString($loglevel, $pad = false) { |
| 302 | - if ($pad) |
|
| 303 | - $s = " "; |
|
| 304 | - else |
|
| 305 | - $s = ""; |
|
| 301 | + if ($pad) { |
|
| 302 | + $s = " "; |
|
| 303 | + } else { |
|
| 304 | + $s = ""; |
|
| 305 | + } |
|
| 306 | 306 | switch($loglevel) { |
| 307 | 307 | case LOGLEVEL_OFF: return ""; break; |
| 308 | 308 | case LOGLEVEL_FATAL: return "[FATAL]"; break; |
@@ -79,9 +79,15 @@ discard block |
||
| 79 | 79 | public function __construct($program_name = null, $host = null, $port = null) { |
| 80 | 80 | parent::__construct(); |
| 81 | 81 | |
| 82 | - if (is_null($program_name)) $program_name = LOG_SYSLOG_PROGRAM; |
|
| 83 | - if (is_null($host)) $host = LOG_SYSLOG_HOST; |
|
| 84 | - if (is_null($port)) $port = LOG_SYSLOG_PORT; |
|
| 82 | + if (is_null($program_name)) { |
|
| 83 | + $program_name = LOG_SYSLOG_PROGRAM; |
|
| 84 | + } |
|
| 85 | + if (is_null($host)) { |
|
| 86 | + $host = LOG_SYSLOG_HOST; |
|
| 87 | + } |
|
| 88 | + if (is_null($port)) { |
|
| 89 | + $port = LOG_SYSLOG_PORT; |
|
| 90 | + } |
|
| 85 | 91 | |
| 86 | 92 | $this->SetProgramName($program_name); |
| 87 | 93 | $this->SetHost($host); |
@@ -153,8 +159,7 @@ discard block |
||
| 153 | 159 | // when the users differ, we need to log both |
| 154 | 160 | if (strcasecmp($this->GetAuthUser(), $this->GetUser()) == 0) { |
| 155 | 161 | $log .= ' ['. $this->GetUser() .']'; |
| 156 | - } |
|
| 157 | - else { |
|
| 162 | + } else { |
|
| 158 | 163 | $log .= ' ['. $this->GetAuthUser() . Request::IMPERSONATE_DELIM . $this->GetUser() .']'; |
| 159 | 164 | } |
| 160 | 165 | if ($loglevel >= LOGLEVEL_DEVICEID) { |
@@ -264,7 +264,7 @@ |
||
| 264 | 264 | * @access public |
| 265 | 265 | * @return int |
| 266 | 266 | */ |
| 267 | - public function GetChangeCount() { |
|
| 267 | + public function GetChangeCount() { |
|
| 268 | 268 | if ($this->exporter) |
| 269 | 269 | return mapi_exportchanges_getchangecount($this->exporter); |
| 270 | 270 | else |
@@ -47,13 +47,11 @@ discard block |
||
| 47 | 47 | try { |
| 48 | 48 | if($folderid) { |
| 49 | 49 | $entryid = mapi_msgstore_entryidfromsourcekey($store, $folderid); |
| 50 | - } |
|
| 51 | - else { |
|
| 50 | + } else { |
|
| 52 | 51 | $storeprops = mapi_getprops($this->store, array(PR_IPM_SUBTREE_ENTRYID, PR_IPM_PUBLIC_FOLDERS_ENTRYID)); |
| 53 | 52 | if (ZPush::GetBackend()->GetImpersonatedUser() == 'system') { |
| 54 | 53 | $entryid = $storeprops[PR_IPM_PUBLIC_FOLDERS_ENTRYID]; |
| 55 | - } |
|
| 56 | - else { |
|
| 54 | + } else { |
|
| 57 | 55 | $entryid = $storeprops[PR_IPM_SUBTREE_ENTRYID]; |
| 58 | 56 | } |
| 59 | 57 | } |
@@ -70,16 +68,13 @@ discard block |
||
| 70 | 68 | if ($folder) { |
| 71 | 69 | if ($folderid) { |
| 72 | 70 | $this->exporter = mapi_openproperty($folder, PR_CONTENTS_SYNCHRONIZER, IID_IExchangeExportChanges, 0 , 0); |
| 73 | - } |
|
| 74 | - else { |
|
| 71 | + } else { |
|
| 75 | 72 | $this->exporter = mapi_openproperty($folder, PR_HIERARCHY_SYNCHRONIZER, IID_IExchangeExportChanges, 0 , 0); |
| 76 | 73 | } |
| 77 | - } |
|
| 78 | - else { |
|
| 74 | + } else { |
|
| 79 | 75 | $this->exporter = false; |
| 80 | 76 | } |
| 81 | - } |
|
| 82 | - catch (MAPIException $me) { |
|
| 77 | + } catch (MAPIException $me) { |
|
| 83 | 78 | $this->exporter = false; |
| 84 | 79 | // We return the general error SYNC_FSSTATUS_CODEUNKNOWN (12) which is also SYNC_STATUS_FOLDERHIERARCHYCHANGED (12) |
| 85 | 80 | // if this happened while doing content sync, the mobile will try to resync the folderhierarchy |
@@ -102,8 +97,9 @@ discard block |
||
| 102 | 97 | $this->flags = $flags; |
| 103 | 98 | |
| 104 | 99 | // this should never happen |
| 105 | - if ($this->exporter === false || is_array($state)) |
|
| 106 | - throw new StatusException("ExportChangesICS->Config(): Error, exporter not available", SYNC_FSSTATUS_CODEUNKNOWN, null, LOGLEVEL_ERROR); |
|
| 100 | + if ($this->exporter === false || is_array($state)) { |
|
| 101 | + throw new StatusException("ExportChangesICS->Config(): Error, exporter not available", SYNC_FSSTATUS_CODEUNKNOWN, null, LOGLEVEL_ERROR); |
|
| 102 | + } |
|
| 107 | 103 | |
| 108 | 104 | // change exporterflags if we are doing a ContentExport |
| 109 | 105 | if($this->folderid) { |
@@ -113,8 +109,9 @@ discard block |
||
| 113 | 109 | // we check the change ID of the syncstate (0 at initial sync) |
| 114 | 110 | // On subsequent syncs, we do want to receive delete events. |
| 115 | 111 | if(strlen($state) == 0 || bin2hex(substr($state,4,4)) == "00000000") { |
| 116 | - if (!($this->flags & BACKEND_DISCARD_DATA)) |
|
| 117 | - ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesICS->Config(): syncing initial data"); |
|
| 112 | + if (!($this->flags & BACKEND_DISCARD_DATA)) { |
|
| 113 | + ZLog::Write(LOGLEVEL_DEBUG, "ExportChangesICS->Config(): syncing initial data"); |
|
| 114 | + } |
|
| 118 | 115 | $this->exporterflags |= SYNC_NO_SOFT_DELETIONS | SYNC_NO_DELETIONS; |
| 119 | 116 | } |
| 120 | 117 | } |
@@ -126,11 +123,13 @@ discard block |
||
| 126 | 123 | |
| 127 | 124 | // Put the state information in a stream that can be used by ICS |
| 128 | 125 | $stream = mapi_stream_create(); |
| 129 | - if(strlen($state) == 0) |
|
| 130 | - $state = hex2bin("0000000000000000"); |
|
| 126 | + if(strlen($state) == 0) { |
|
| 127 | + $state = hex2bin("0000000000000000"); |
|
| 128 | + } |
|
| 131 | 129 | |
| 132 | - if (!($this->flags & BACKEND_DISCARD_DATA)) |
|
| 133 | - ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExportChangesICS->Config() initialized with state: 0x%s", bin2hex($state))); |
|
| 130 | + if (!($this->flags & BACKEND_DISCARD_DATA)) { |
|
| 131 | + ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExportChangesICS->Config() initialized with state: 0x%s", bin2hex($state))); |
|
| 132 | + } |
|
| 134 | 133 | |
| 135 | 134 | mapi_stream_write($stream, $state); |
| 136 | 135 | $this->statestream = $stream; |
@@ -183,8 +182,9 @@ discard block |
||
| 183 | 182 | |
| 184 | 183 | // this should never happen! |
| 185 | 184 | if($this->exporter === false || !isset($this->statestream) || !isset($this->flags) || !isset($this->exporterflags) || |
| 186 | - ($this->folderid && !isset($this->contentParameters)) ) |
|
| 187 | - throw new StatusException("ExportChangesICS->InitializeExporter(): Error, exporter or essential data not available", SYNC_FSSTATUS_CODEUNKNOWN, null, LOGLEVEL_ERROR); |
|
| 185 | + ($this->folderid && !isset($this->contentParameters)) ) { |
|
| 186 | + throw new StatusException("ExportChangesICS->InitializeExporter(): Error, exporter or essential data not available", SYNC_FSSTATUS_CODEUNKNOWN, null, LOGLEVEL_ERROR); |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | 189 | // PHP wrapper |
| 190 | 190 | $phpwrapper = new PHPWrapper($this->session, $this->store, $importer, $this->folderid); |
@@ -196,22 +196,24 @@ discard block |
||
| 196 | 196 | // ICS c++ wrapper |
| 197 | 197 | $mapiimporter = mapi_wrap_importcontentschanges($phpwrapper); |
| 198 | 198 | $includeprops = false; |
| 199 | - } |
|
| 200 | - else { |
|
| 199 | + } else { |
|
| 201 | 200 | $mapiimporter = mapi_wrap_importhierarchychanges($phpwrapper); |
| 202 | 201 | $includeprops = array(PR_SOURCE_KEY, PR_DISPLAY_NAME); |
| 203 | 202 | } |
| 204 | 203 | |
| 205 | - if (!$mapiimporter) |
|
| 206 | - throw new StatusException(sprintf("ExportChangesICS->InitializeExporter(): Error, mapi_wrap_import_*_changes() failed: 0x%X", mapi_last_hresult()), SYNC_FSSTATUS_CODEUNKNOWN, null, LOGLEVEL_WARN); |
|
| 204 | + if (!$mapiimporter) { |
|
| 205 | + throw new StatusException(sprintf("ExportChangesICS->InitializeExporter(): Error, mapi_wrap_import_*_changes() failed: 0x%X", mapi_last_hresult()), SYNC_FSSTATUS_CODEUNKNOWN, null, LOGLEVEL_WARN); |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | 208 | $ret = mapi_exportchanges_config($this->exporter, $this->statestream, $this->exporterflags, $mapiimporter, $this->restriction, $includeprops, false, 1); |
| 209 | - if(!$ret) |
|
| 210 | - throw new StatusException(sprintf("ExportChangesICS->InitializeExporter(): Error, mapi_exportchanges_config() failed: 0x%X", mapi_last_hresult()), SYNC_FSSTATUS_CODEUNKNOWN, null, LOGLEVEL_WARN); |
|
| 209 | + if(!$ret) { |
|
| 210 | + throw new StatusException(sprintf("ExportChangesICS->InitializeExporter(): Error, mapi_exportchanges_config() failed: 0x%X", mapi_last_hresult()), SYNC_FSSTATUS_CODEUNKNOWN, null, LOGLEVEL_WARN); |
|
| 211 | + } |
|
| 211 | 212 | |
| 212 | 213 | $changes = mapi_exportchanges_getchangecount($this->exporter); |
| 213 | - if($changes || !($this->flags & BACKEND_DISCARD_DATA)) |
|
| 214 | - ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExportChangesICS->InitializeExporter() successfully. %d changes ready to sync for '%s'.", $changes, ($this->folderid)?bin2hex($this->folderid) : 'hierarchy')); |
|
| 214 | + if($changes || !($this->flags & BACKEND_DISCARD_DATA)) { |
|
| 215 | + ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExportChangesICS->InitializeExporter() successfully. %d changes ready to sync for '%s'.", $changes, ($this->folderid)?bin2hex($this->folderid) : 'hierarchy')); |
|
| 216 | + } |
|
| 215 | 217 | |
| 216 | 218 | return $ret; |
| 217 | 219 | } |
@@ -238,21 +240,24 @@ discard block |
||
| 238 | 240 | */ |
| 239 | 241 | public function GetState() { |
| 240 | 242 | $error = false; |
| 241 | - if(!isset($this->statestream) || $this->exporter === false) |
|
| 242 | - $error = true; |
|
| 243 | + if(!isset($this->statestream) || $this->exporter === false) { |
|
| 244 | + $error = true; |
|
| 245 | + } |
|
| 243 | 246 | |
| 244 | - if($error === true || mapi_exportchanges_updatestate($this->exporter, $this->statestream) != true ) |
|
| 245 | - throw new StatusException(sprintf("ExportChangesICS->GetState(): Error, state not available or unable to update: 0x%X", mapi_last_hresult()), (($this->folderid)?SYNC_STATUS_FOLDERHIERARCHYCHANGED:SYNC_FSSTATUS_CODEUNKNOWN), null, LOGLEVEL_WARN); |
|
| 247 | + if($error === true || mapi_exportchanges_updatestate($this->exporter, $this->statestream) != true ) { |
|
| 248 | + throw new StatusException(sprintf("ExportChangesICS->GetState(): Error, state not available or unable to update: 0x%X", mapi_last_hresult()), (($this->folderid)?SYNC_STATUS_FOLDERHIERARCHYCHANGED:SYNC_FSSTATUS_CODEUNKNOWN), null, LOGLEVEL_WARN); |
|
| 249 | + } |
|
| 246 | 250 | |
| 247 | 251 | mapi_stream_seek($this->statestream, 0, STREAM_SEEK_SET); |
| 248 | 252 | |
| 249 | 253 | $state = ""; |
| 250 | 254 | while(true) { |
| 251 | 255 | $data = mapi_stream_read($this->statestream, 4096); |
| 252 | - if(strlen($data)) |
|
| 253 | - $state .= $data; |
|
| 254 | - else |
|
| 255 | - break; |
|
| 256 | + if(strlen($data)) { |
|
| 257 | + $state .= $data; |
|
| 258 | + } else { |
|
| 259 | + break; |
|
| 260 | + } |
|
| 256 | 261 | } |
| 257 | 262 | |
| 258 | 263 | return $state; |
@@ -265,10 +270,11 @@ discard block |
||
| 265 | 270 | * @return int |
| 266 | 271 | */ |
| 267 | 272 | public function GetChangeCount() { |
| 268 | - if ($this->exporter) |
|
| 269 | - return mapi_exportchanges_getchangecount($this->exporter); |
|
| 270 | - else |
|
| 271 | - return 0; |
|
| 273 | + if ($this->exporter) { |
|
| 274 | + return mapi_exportchanges_getchangecount($this->exporter); |
|
| 275 | + } else { |
|
| 276 | + return 0; |
|
| 277 | + } |
|
| 272 | 278 | } |
| 273 | 279 | |
| 274 | 280 | /** |
@@ -899,11 +899,11 @@ discard block |
||
| 899 | 899 | $items = $meetingrequest->findCalendarItems($goid); |
| 900 | 900 | |
| 901 | 901 | if (is_array($items)) { |
| 902 | - $newitem = mapi_msgstore_openentry($this->store, $items[0]); |
|
| 903 | - $newprops = mapi_getprops($newitem, array(PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY)); |
|
| 904 | - $calendarid = bin2hex($newprops[PR_SOURCE_KEY]); |
|
| 905 | - $calFolderId = bin2hex($newprops[PR_PARENT_SOURCE_KEY]); |
|
| 906 | - ZLog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->MeetingResponse('%s','%s', '%s'): found other calendar entryid", $requestid, $folderid, $response)); |
|
| 902 | + $newitem = mapi_msgstore_openentry($this->store, $items[0]); |
|
| 903 | + $newprops = mapi_getprops($newitem, array(PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY)); |
|
| 904 | + $calendarid = bin2hex($newprops[PR_SOURCE_KEY]); |
|
| 905 | + $calFolderId = bin2hex($newprops[PR_PARENT_SOURCE_KEY]); |
|
| 906 | + ZLog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->MeetingResponse('%s','%s', '%s'): found other calendar entryid", $requestid, $folderid, $response)); |
|
| 907 | 907 | } |
| 908 | 908 | |
| 909 | 909 | if ($requestid == $calendarid) |
@@ -1319,12 +1319,12 @@ discard block |
||
| 1319 | 1319 | } |
| 1320 | 1320 | |
| 1321 | 1321 | /** |
| 1322 | - * Terminates a search for a given PID |
|
| 1323 | - * |
|
| 1324 | - * @param int $pid |
|
| 1325 | - * |
|
| 1326 | - * @return boolean |
|
| 1327 | - */ |
|
| 1322 | + * Terminates a search for a given PID |
|
| 1323 | + * |
|
| 1324 | + * @param int $pid |
|
| 1325 | + * |
|
| 1326 | + * @return boolean |
|
| 1327 | + */ |
|
| 1328 | 1328 | public function TerminateSearch($pid) { |
| 1329 | 1329 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->TerminateSearch(): terminating search for pid %d", $pid)); |
| 1330 | 1330 | if (!isset($this->store) || $this->store === false) { |
@@ -1829,7 +1829,6 @@ discard block |
||
| 1829 | 1829 | * @param string $type the state type |
| 1830 | 1830 | * @param string $key (opt) |
| 1831 | 1831 | * @param string $counter state counter |
| 1832 | - |
|
| 1833 | 1832 | * |
| 1834 | 1833 | * @access private |
| 1835 | 1834 | * @return MAPIMessage |
@@ -2021,7 +2020,7 @@ discard block |
||
| 2021 | 2020 | // During PING requests the operations store has to be switched constantly |
| 2022 | 2021 | // the cache prevents the same store opened several times |
| 2023 | 2022 | if (isset($this->storeCache[$user])) |
| 2024 | - return $this->storeCache[$user]; |
|
| 2023 | + return $this->storeCache[$user]; |
|
| 2025 | 2024 | |
| 2026 | 2025 | $entryid = false; |
| 2027 | 2026 | $return_public = false; |
@@ -2352,14 +2351,14 @@ discard block |
||
| 2352 | 2351 | } |
| 2353 | 2352 | } |
| 2354 | 2353 | |
| 2355 | - /** |
|
| 2356 | - * Function will create a search folder in FINDER_ROOT folder |
|
| 2357 | - * if folder exists then it will open it |
|
| 2358 | - * |
|
| 2359 | - * @see createSearchFolder($store, $openIfExists = true) function in the webaccess |
|
| 2360 | - * |
|
| 2361 | - * @return mapiFolderObject $folder created search folder |
|
| 2362 | - */ |
|
| 2354 | + /** |
|
| 2355 | + * Function will create a search folder in FINDER_ROOT folder |
|
| 2356 | + * if folder exists then it will open it |
|
| 2357 | + * |
|
| 2358 | + * @see createSearchFolder($store, $openIfExists = true) function in the webaccess |
|
| 2359 | + * |
|
| 2360 | + * @return mapiFolderObject $folder created search folder |
|
| 2361 | + */ |
|
| 2363 | 2362 | private function getSearchFolder() { |
| 2364 | 2363 | // create new or open existing search folder |
| 2365 | 2364 | $searchFolderRoot = $this->getSearchFoldersRoot($this->store); |
@@ -2377,14 +2376,14 @@ discard block |
||
| 2377 | 2376 | return false; |
| 2378 | 2377 | } |
| 2379 | 2378 | |
| 2380 | - /** |
|
| 2381 | - * Function will open FINDER_ROOT folder in root container |
|
| 2382 | - * public folder's don't have FINDER_ROOT folder |
|
| 2383 | - * |
|
| 2384 | - * @see getSearchFoldersRoot($store) function in the webaccess |
|
| 2385 | - * |
|
| 2386 | - * @return mapiFolderObject root folder for search folders |
|
| 2387 | - */ |
|
| 2379 | + /** |
|
| 2380 | + * Function will open FINDER_ROOT folder in root container |
|
| 2381 | + * public folder's don't have FINDER_ROOT folder |
|
| 2382 | + * |
|
| 2383 | + * @see getSearchFoldersRoot($store) function in the webaccess |
|
| 2384 | + * |
|
| 2385 | + * @return mapiFolderObject root folder for search folders |
|
| 2386 | + */ |
|
| 2388 | 2387 | private function getSearchFoldersRoot() { |
| 2389 | 2388 | // check if we can create search folders |
| 2390 | 2389 | $storeProps = mapi_getprops($this->store, array(PR_STORE_SUPPORT_MASK, PR_FINDER_ENTRYID)); |
@@ -134,8 +134,7 @@ discard block |
||
| 134 | 134 | if ($this->impersonateUser !== false) { |
| 135 | 135 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->Logon(): Impersonation active - authenticating: '%s' - impersonating '%s'", $this->mainUser, $this->impersonateUser)); |
| 136 | 136 | $defaultUser = $this->impersonateUser; |
| 137 | - } |
|
| 138 | - else { |
|
| 137 | + } else { |
|
| 139 | 138 | $defaultUser = $this->mainUser; |
| 140 | 139 | } |
| 141 | 140 | |
@@ -149,8 +148,7 @@ discard block |
||
| 149 | 148 | $zpush_version = 'Grommunio-Sync_' . @constant('GROMMUNIOSYNC_VERSION'); |
| 150 | 149 | $user_agent = ($deviceId) ? ZPush::GetDeviceManager()->GetUserAgent() : "unknown"; |
| 151 | 150 | $this->session = @mapi_logon_zarafa($this->mainUser, $pass, MAPI_SERVER, null, null, 0, $zpush_version, $user_agent); |
| 152 | - } |
|
| 153 | - else { |
|
| 151 | + } else { |
|
| 154 | 152 | $this->session = @mapi_logon_zarafa($this->mainUser, $pass, MAPI_SERVER, null, null, 0); |
| 155 | 153 | } |
| 156 | 154 | $this->notifications = true; |
@@ -163,11 +161,11 @@ discard block |
||
| 163 | 161 | |
| 164 | 162 | if (mapi_last_hresult()) { |
| 165 | 163 | ZLog::Write(LOGLEVEL_ERROR, sprintf("Grommunio->Logon(): login failed with error code: 0x%X", mapi_last_hresult())); |
| 166 | - if (mapi_last_hresult() == MAPI_E_NETWORK_ERROR) |
|
| 167 | - throw new ServiceUnavailableException("Error connecting to KC (login)"); |
|
| 164 | + if (mapi_last_hresult() == MAPI_E_NETWORK_ERROR) { |
|
| 165 | + throw new ServiceUnavailableException("Error connecting to KC (login)"); |
|
| 166 | + } |
|
| 168 | 167 | } |
| 169 | - } |
|
| 170 | - catch (MAPIException $ex) { |
|
| 168 | + } catch (MAPIException $ex) { |
|
| 171 | 169 | throw new AuthenticationRequiredException($ex->getDisplayMessage()); |
| 172 | 170 | } |
| 173 | 171 | |
@@ -186,11 +184,13 @@ discard block |
||
| 186 | 184 | $this->defaultstore = $this->openMessageStore($defaultUser); |
| 187 | 185 | } |
| 188 | 186 | |
| 189 | - if (mapi_last_hresult() == MAPI_E_FAILONEPROVIDER) |
|
| 190 | - throw new ServiceUnavailableException("Error connecting to KC (open store)"); |
|
| 187 | + if (mapi_last_hresult() == MAPI_E_FAILONEPROVIDER) { |
|
| 188 | + throw new ServiceUnavailableException("Error connecting to KC (open store)"); |
|
| 189 | + } |
|
| 191 | 190 | |
| 192 | - if($this->defaultstore === false) |
|
| 193 | - throw new AuthenticationRequiredException(sprintf("Grommunio->Logon(): User '%s' has no default store", $defaultUser)); |
|
| 191 | + if($this->defaultstore === false) { |
|
| 192 | + throw new AuthenticationRequiredException(sprintf("Grommunio->Logon(): User '%s' has no default store", $defaultUser)); |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | 195 | $this->store = $this->defaultstore; |
| 196 | 196 | $this->storeName = $defaultUser; |
@@ -229,8 +229,9 @@ discard block |
||
| 229 | 229 | public function Setup($store, $checkACLonly = false, $folderid = false) { |
| 230 | 230 | list($user, $domain) = Utils::SplitDomainUser($store); |
| 231 | 231 | |
| 232 | - if (!isset($this->mainUser)) |
|
| 233 | - return false; |
|
| 232 | + if (!isset($this->mainUser)) { |
|
| 233 | + return false; |
|
| 234 | + } |
|
| 234 | 235 | |
| 235 | 236 | $mainUser = $this->mainUser; |
| 236 | 237 | // when impersonating we need to check against the impersonated user |
@@ -238,8 +239,9 @@ discard block |
||
| 238 | 239 | $mainUser = $this->impersonateUser; |
| 239 | 240 | } |
| 240 | 241 | |
| 241 | - if ($user === false) |
|
| 242 | - $user = $mainUser; |
|
| 242 | + if ($user === false) { |
|
| 243 | + $user = $mainUser; |
|
| 244 | + } |
|
| 243 | 245 | |
| 244 | 246 | // This is a special case. A user will get his entire folder structure by the foldersync by default. |
| 245 | 247 | // The ACL check is executed when an additional folder is going to be sent to the mobile. |
@@ -263,8 +265,7 @@ discard block |
||
| 263 | 265 | $storeProps = mapi_getprops($userstore, array(PR_IPM_SUBTREE_ENTRYID)); |
| 264 | 266 | $rights = $this->HasSecretaryACLs($userstore, '', $storeProps[PR_IPM_SUBTREE_ENTRYID]); |
| 265 | 267 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->Setup(): Checking for secretary ACLs on root folder of impersonated store '%s': '%s'", $user, Utils::PrintAsString($rights))); |
| 266 | - } |
|
| 267 | - else { |
|
| 268 | + } else { |
|
| 268 | 269 | $zarafauserinfo = @nsp_getuserinfo($this->mainUser); |
| 269 | 270 | $rights = (isset($zarafauserinfo['admin']) && $zarafauserinfo['admin'])?true:false; |
| 270 | 271 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->Setup(): Checking for admin ACLs on store '%s': '%s'", $user, Utils::PrintAsString($rights))); |
@@ -329,8 +330,7 @@ discard block |
||
| 329 | 330 | // for SYSTEM user open the public folders |
| 330 | 331 | if (strtoupper($this->storeName) == "SYSTEM") { |
| 331 | 332 | $rootfolder = mapi_msgstore_openentry($this->store, $storeProps[PR_IPM_PUBLIC_FOLDERS_ENTRYID]); |
| 332 | - } |
|
| 333 | - else { |
|
| 333 | + } else { |
|
| 334 | 334 | $rootfolder = mapi_msgstore_openentry($this->store); |
| 335 | 335 | } |
| 336 | 336 | |
@@ -352,8 +352,7 @@ discard block |
||
| 352 | 352 | $folder = $mapiprovider->GetFolder($row); |
| 353 | 353 | if ($folder) { |
| 354 | 354 | $folders[] = $folder; |
| 355 | - } |
|
| 356 | - else { |
|
| 355 | + } else { |
|
| 357 | 356 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->GetHierarchy(): ignoring folder '%s' as MAPIProvider->GetFolder() did not return a SyncFolder object", (isset($row[PR_DISPLAY_NAME]) ? $row[PR_DISPLAY_NAME] : "unknown"))); |
| 358 | 357 | } |
| 359 | 358 | } |
@@ -389,9 +388,9 @@ discard block |
||
| 389 | 388 | return false; |
| 390 | 389 | } |
| 391 | 390 | return new ImportChangesICS($this->session, $this->store, hex2bin($folderid)); |
| 391 | + } else { |
|
| 392 | + return new ImportChangesICS($this->session, $this->store); |
|
| 392 | 393 | } |
| 393 | - else |
|
| 394 | - return new ImportChangesICS($this->session, $this->store); |
|
| 395 | 394 | } |
| 396 | 395 | |
| 397 | 396 | /** |
@@ -412,9 +411,9 @@ discard block |
||
| 412 | 411 | return false; |
| 413 | 412 | } |
| 414 | 413 | return new ExportChangesICS($this->session, $this->store, hex2bin($folderid)); |
| 414 | + } else { |
|
| 415 | + return new ExportChangesICS($this->session, $this->store); |
|
| 415 | 416 | } |
| 416 | - else |
|
| 417 | - return new ExportChangesICS($this->session, $this->store); |
|
| 418 | 417 | } |
| 419 | 418 | |
| 420 | 419 | /** |
@@ -449,11 +448,13 @@ discard block |
||
| 449 | 448 | |
| 450 | 449 | // Open the outbox and create the message there |
| 451 | 450 | $storeprops = mapi_getprops($this->defaultstore, array($sendMailProps["outboxentryid"], $sendMailProps["ipmsentmailentryid"])); |
| 452 | - if(isset($storeprops[$sendMailProps["outboxentryid"]])) |
|
| 453 | - $outbox = mapi_msgstore_openentry($this->defaultstore, $storeprops[$sendMailProps["outboxentryid"]]); |
|
| 451 | + if(isset($storeprops[$sendMailProps["outboxentryid"]])) { |
|
| 452 | + $outbox = mapi_msgstore_openentry($this->defaultstore, $storeprops[$sendMailProps["outboxentryid"]]); |
|
| 453 | + } |
|
| 454 | 454 | |
| 455 | - if(!$outbox) |
|
| 456 | - throw new StatusException(sprintf("Grommunio->SendMail(): No Outbox found or unable to create message: 0x%X", mapi_last_hresult()), SYNC_COMMONSTATUS_SERVERERROR); |
|
| 455 | + if(!$outbox) { |
|
| 456 | + throw new StatusException(sprintf("Grommunio->SendMail(): No Outbox found or unable to create message: 0x%X", mapi_last_hresult()), SYNC_COMMONSTATUS_SERVERERROR); |
|
| 457 | + } |
|
| 457 | 458 | |
| 458 | 459 | $mapimessage = mapi_folder_createmessage($outbox); |
| 459 | 460 | |
@@ -510,12 +511,14 @@ discard block |
||
| 510 | 511 | if(isset($sm->source->itemid) && $sm->source->itemid) { |
| 511 | 512 | // answering an email in a public/shared folder |
| 512 | 513 | // TODO as the store is setup, we should actually user $this->store instead of $this->defaultstore - nevertheless we need to make sure this store is able to send mail (has an outbox) |
| 513 | - if (!$this->Setup(ZPush::GetAdditionalSyncFolderStore($sm->source->folderid))) |
|
| 514 | - throw new StatusException(sprintf("Grommunio->SendMail() could not Setup() the backend for folder id '%s'", $sm->source->folderid), SYNC_COMMONSTATUS_SERVERERROR); |
|
| 514 | + if (!$this->Setup(ZPush::GetAdditionalSyncFolderStore($sm->source->folderid))) { |
|
| 515 | + throw new StatusException(sprintf("Grommunio->SendMail() could not Setup() the backend for folder id '%s'", $sm->source->folderid), SYNC_COMMONSTATUS_SERVERERROR); |
|
| 516 | + } |
|
| 515 | 517 | |
| 516 | 518 | $entryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($sm->source->folderid), hex2bin($sm->source->itemid)); |
| 517 | - if ($entryid) |
|
| 518 | - $fwmessage = mapi_msgstore_openentry($this->store, $entryid); |
|
| 519 | + if ($entryid) { |
|
| 520 | + $fwmessage = mapi_msgstore_openentry($this->store, $entryid); |
|
| 521 | + } |
|
| 519 | 522 | |
| 520 | 523 | if (isset($fwmessage) && $fwmessage) { |
| 521 | 524 | // update icon and last_verb when forwarding or replying message |
@@ -525,8 +528,7 @@ discard block |
||
| 525 | 528 | PR_ICON_INDEX => 262, |
| 526 | 529 | PR_LAST_VERB_EXECUTED => 104, |
| 527 | 530 | ); |
| 528 | - } |
|
| 529 | - elseif ($sm->replyflag) { |
|
| 531 | + } elseif ($sm->replyflag) { |
|
| 530 | 532 | $updateProps = array( |
| 531 | 533 | PR_ICON_INDEX => 261, |
| 532 | 534 | PR_LAST_VERB_EXECUTED => 102, |
@@ -586,8 +588,7 @@ discard block |
||
| 586 | 588 | $mapiprops[$sendMailProps["html"]] = $bodyHtml."<br><br>".$fwbodyHtml; |
| 587 | 589 | } |
| 588 | 590 | } |
| 589 | - } |
|
| 590 | - else { |
|
| 591 | + } else { |
|
| 591 | 592 | // no fwmessage could be opened and we need it because we do not replace mime |
| 592 | 593 | if (!isset($sm->replacemime) || $sm->replacemime == false) { |
| 593 | 594 | throw new StatusException(sprintf("Grommunio->SendMail(): Could not open message id '%s' in folder id '%s' to be replied/forwarded: 0x%X", $sm->source->itemid, $sm->source->folderid, mapi_last_hresult()), SYNC_COMMONSTATUS_ITEMNOTFOUND); |
@@ -631,21 +632,22 @@ discard block |
||
| 631 | 632 | if (! $folderid) { |
| 632 | 633 | $entryid = hex2bin($id); |
| 633 | 634 | $sk = $id; |
| 634 | - } |
|
| 635 | - else { |
|
| 635 | + } else { |
|
| 636 | 636 | // id might be in the new longid format, so we have to split it here |
| 637 | 637 | list($fsk, $sk) = Utils::SplitMessageId($id); |
| 638 | 638 | // get the entry id of the message |
| 639 | 639 | $entryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($folderid), hex2bin($sk)); |
| 640 | 640 | |
| 641 | 641 | } |
| 642 | - if(!$entryid) |
|
| 643 | - throw new StatusException(sprintf("Grommunio->Fetch('%s','%s'): Error getting entryid: 0x%X", $folderid, $sk, mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND); |
|
| 642 | + if(!$entryid) { |
|
| 643 | + throw new StatusException(sprintf("Grommunio->Fetch('%s','%s'): Error getting entryid: 0x%X", $folderid, $sk, mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND); |
|
| 644 | + } |
|
| 644 | 645 | |
| 645 | 646 | // open the message |
| 646 | 647 | $message = mapi_msgstore_openentry($this->store, $entryid); |
| 647 | - if(!$message) |
|
| 648 | - throw new StatusException(sprintf("Grommunio->Fetch('%s','%s'): Error, unable to open message: 0x%X", $folderid, $sk, mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND); |
|
| 648 | + if(!$message) { |
|
| 649 | + throw new StatusException(sprintf("Grommunio->Fetch('%s','%s'): Error, unable to open message: 0x%X", $folderid, $sk, mapi_last_hresult()), SYNC_STATUS_OBJECTNOTFOUND); |
|
| 650 | + } |
|
| 649 | 651 | |
| 650 | 652 | // convert the mapi message into a SyncObject and return it |
| 651 | 653 | $mapiprovider = new MAPIProvider($this->session, $this->store); |
@@ -691,8 +693,9 @@ discard block |
||
| 691 | 693 | public function GetAttachmentData($attname) { |
| 692 | 694 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->GetAttachmentData('%s')", $attname)); |
| 693 | 695 | |
| 694 | - if(!strpos($attname, ":")) |
|
| 695 | - throw new StatusException(sprintf("Grommunio->GetAttachmentData('%s'): Error, attachment requested for non-existing item", $attname), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); |
|
| 696 | + if(!strpos($attname, ":")) { |
|
| 697 | + throw new StatusException(sprintf("Grommunio->GetAttachmentData('%s'): Error, attachment requested for non-existing item", $attname), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); |
|
| 698 | + } |
|
| 696 | 699 | |
| 697 | 700 | list($id, $attachnum, $parentEntryid) = explode(":", $attname); |
| 698 | 701 | if (isset($parentEntryid)) { |
@@ -701,13 +704,15 @@ discard block |
||
| 701 | 704 | |
| 702 | 705 | $entryid = hex2bin($id); |
| 703 | 706 | $message = mapi_msgstore_openentry($this->store, $entryid); |
| 704 | - if(!$message) |
|
| 705 | - throw new StatusException(sprintf("Grommunio->GetAttachmentData('%s'): Error, unable to open item for attachment data for id '%s' with: 0x%X", $attname, $id, mapi_last_hresult()), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); |
|
| 707 | + if(!$message) { |
|
| 708 | + throw new StatusException(sprintf("Grommunio->GetAttachmentData('%s'): Error, unable to open item for attachment data for id '%s' with: 0x%X", $attname, $id, mapi_last_hresult()), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); |
|
| 709 | + } |
|
| 706 | 710 | |
| 707 | 711 | MAPIUtils::ParseSmime($this->session, $this->defaultstore, $this->getAddressbook(), $message); |
| 708 | 712 | $attach = mapi_message_openattach($message, $attachnum); |
| 709 | - if(!$attach) |
|
| 710 | - throw new StatusException(sprintf("Grommunio->GetAttachmentData('%s'): Error, unable to open attachment number '%s' with: 0x%X", $attname, $attachnum, mapi_last_hresult()), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); |
|
| 713 | + if(!$attach) { |
|
| 714 | + throw new StatusException(sprintf("Grommunio->GetAttachmentData('%s'): Error, unable to open attachment number '%s' with: 0x%X", $attname, $attachnum, mapi_last_hresult()), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); |
|
| 715 | + } |
|
| 711 | 716 | |
| 712 | 717 | // get necessary attachment props |
| 713 | 718 | $attprops = mapi_getprops($attach, array(PR_ATTACH_MIME_TAG, PR_ATTACH_MIME_TAG_W, PR_ATTACH_METHOD)); |
@@ -719,19 +724,21 @@ discard block |
||
| 719 | 724 | $stream = mapi_inetmapi_imtoinet($this->session, $addrbook, $embMessage, array('use_tnef' => -1)); |
| 720 | 725 | // set the default contenttype for this kind of messages |
| 721 | 726 | $attachment->contenttype = "message/rfc822"; |
| 727 | + } else { |
|
| 728 | + $stream = mapi_openproperty($attach, PR_ATTACH_DATA_BIN, IID_IStream, 0, 0); |
|
| 722 | 729 | } |
| 723 | - else |
|
| 724 | - $stream = mapi_openproperty($attach, PR_ATTACH_DATA_BIN, IID_IStream, 0, 0); |
|
| 725 | 730 | |
| 726 | - if(!$stream) |
|
| 727 | - throw new StatusException(sprintf("Grommunio->GetAttachmentData('%s'): Error, unable to open attachment data stream: 0x%X", $attname, mapi_last_hresult()), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); |
|
| 731 | + if(!$stream) { |
|
| 732 | + throw new StatusException(sprintf("Grommunio->GetAttachmentData('%s'): Error, unable to open attachment data stream: 0x%X", $attname, mapi_last_hresult()), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT); |
|
| 733 | + } |
|
| 728 | 734 | |
| 729 | 735 | // put the mapi stream into a wrapper to get a standard stream |
| 730 | 736 | $attachment->data = MAPIStreamWrapper::Open($stream); |
| 731 | - if (isset($attprops[PR_ATTACH_MIME_TAG])) |
|
| 732 | - $attachment->contenttype = $attprops[PR_ATTACH_MIME_TAG]; |
|
| 733 | - elseif (isset($attprops[PR_ATTACH_MIME_TAG_W])) |
|
| 734 | - $attachment->contenttype = $attprops[PR_ATTACH_MIME_TAG_W]; |
|
| 737 | + if (isset($attprops[PR_ATTACH_MIME_TAG])) { |
|
| 738 | + $attachment->contenttype = $attprops[PR_ATTACH_MIME_TAG]; |
|
| 739 | + } elseif (isset($attprops[PR_ATTACH_MIME_TAG_W])) { |
|
| 740 | + $attachment->contenttype = $attprops[PR_ATTACH_MIME_TAG_W]; |
|
| 741 | + } |
|
| 735 | 742 | //TODO default contenttype |
| 736 | 743 | return $attachment; |
| 737 | 744 | } |
@@ -751,23 +758,27 @@ discard block |
||
| 751 | 758 | */ |
| 752 | 759 | public function EmptyFolder($folderid, $includeSubfolders = true) { |
| 753 | 760 | $folderentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($folderid)); |
| 754 | - if (!$folderentryid) |
|
| 755 | - throw new StatusException(sprintf("Grommunio->EmptyFolder('%s','%s'): Error, unable to open folder (no entry id)", $folderid, Utils::PrintAsString($includeSubfolders)), SYNC_ITEMOPERATIONSSTATUS_SERVERERROR); |
|
| 761 | + if (!$folderentryid) { |
|
| 762 | + throw new StatusException(sprintf("Grommunio->EmptyFolder('%s','%s'): Error, unable to open folder (no entry id)", $folderid, Utils::PrintAsString($includeSubfolders)), SYNC_ITEMOPERATIONSSTATUS_SERVERERROR); |
|
| 763 | + } |
|
| 756 | 764 | $folder = mapi_msgstore_openentry($this->store, $folderentryid); |
| 757 | 765 | |
| 758 | - if (!$folder) |
|
| 759 | - throw new StatusException(sprintf("Grommunio->EmptyFolder('%s','%s'): Error, unable to open parent folder (open entry)", $folderid, Utils::PrintAsString($includeSubfolders)), SYNC_ITEMOPERATIONSSTATUS_SERVERERROR); |
|
| 766 | + if (!$folder) { |
|
| 767 | + throw new StatusException(sprintf("Grommunio->EmptyFolder('%s','%s'): Error, unable to open parent folder (open entry)", $folderid, Utils::PrintAsString($includeSubfolders)), SYNC_ITEMOPERATIONSSTATUS_SERVERERROR); |
|
| 768 | + } |
|
| 760 | 769 | |
| 761 | 770 | $flags = 0; |
| 762 | - if ($includeSubfolders) |
|
| 763 | - $flags = DEL_ASSOCIATED; |
|
| 771 | + if ($includeSubfolders) { |
|
| 772 | + $flags = DEL_ASSOCIATED; |
|
| 773 | + } |
|
| 764 | 774 | |
| 765 | 775 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->EmptyFolder('%s','%s'): emptying folder",$folderid, Utils::PrintAsString($includeSubfolders))); |
| 766 | 776 | |
| 767 | 777 | // empty folder! |
| 768 | 778 | mapi_folder_emptyfolder($folder, $flags); |
| 769 | - if (mapi_last_hresult()) |
|
| 770 | - throw new StatusException(sprintf("Grommunio->EmptyFolder('%s','%s'): Error, mapi_folder_emptyfolder() failed: 0x%X", $folderid, Utils::PrintAsString($includeSubfolders), mapi_last_hresult()), SYNC_ITEMOPERATIONSSTATUS_SERVERERROR); |
|
| 779 | + if (mapi_last_hresult()) { |
|
| 780 | + throw new StatusException(sprintf("Grommunio->EmptyFolder('%s','%s'): Error, mapi_folder_emptyfolder() failed: 0x%X", $folderid, Utils::PrintAsString($includeSubfolders), mapi_last_hresult()), SYNC_ITEMOPERATIONSSTATUS_SERVERERROR); |
|
| 781 | + } |
|
| 771 | 782 | |
| 772 | 783 | return true; |
| 773 | 784 | } |
@@ -788,12 +799,14 @@ discard block |
||
| 788 | 799 | // Use standard meeting response code to process meeting request |
| 789 | 800 | list($fid, $requestid) = Utils::SplitMessageId($requestid); |
| 790 | 801 | $reqentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($folderid), hex2bin($requestid)); |
| 791 | - if (!$reqentryid) |
|
| 792 | - throw new StatusException(sprintf("Grommunio->MeetingResponse('%s', '%s', '%s'): Error, unable to entryid of the message 0x%X", $requestid, $folderid, $response, mapi_last_hresult()), SYNC_MEETRESPSTATUS_INVALIDMEETREQ); |
|
| 802 | + if (!$reqentryid) { |
|
| 803 | + throw new StatusException(sprintf("Grommunio->MeetingResponse('%s', '%s', '%s'): Error, unable to entryid of the message 0x%X", $requestid, $folderid, $response, mapi_last_hresult()), SYNC_MEETRESPSTATUS_INVALIDMEETREQ); |
|
| 804 | + } |
|
| 793 | 805 | |
| 794 | 806 | $mapimessage = mapi_msgstore_openentry($this->store, $reqentryid); |
| 795 | - if(!$mapimessage) |
|
| 796 | - throw new StatusException(sprintf("Grommunio->MeetingResponse('%s','%s', '%s'): Error, unable to open request message for response 0x%X", $requestid, $folderid, $response, mapi_last_hresult()), SYNC_MEETRESPSTATUS_INVALIDMEETREQ); |
|
| 807 | + if(!$mapimessage) { |
|
| 808 | + throw new StatusException(sprintf("Grommunio->MeetingResponse('%s','%s', '%s'): Error, unable to open request message for response 0x%X", $requestid, $folderid, $response, mapi_last_hresult()), SYNC_MEETRESPSTATUS_INVALIDMEETREQ); |
|
| 809 | + } |
|
| 797 | 810 | |
| 798 | 811 | // ios sends calendar item in MeetingResponse |
| 799 | 812 | // @see https://jira.z-hub.io/browse/ZP-1524 |
@@ -834,11 +847,13 @@ discard block |
||
| 834 | 847 | |
| 835 | 848 | $meetingrequest = new Meetingrequest($this->store, $mapimessage, $this->session); |
| 836 | 849 | |
| 837 | - if(!$meetingrequest->isMeetingRequest()) |
|
| 838 | - throw new StatusException(sprintf("Grommunio->MeetingResponse('%s','%s', '%s'): Error, attempt to respond to non-meeting request", $requestid, $folderid, $response), SYNC_MEETRESPSTATUS_INVALIDMEETREQ); |
|
| 850 | + if(!$meetingrequest->isMeetingRequest()) { |
|
| 851 | + throw new StatusException(sprintf("Grommunio->MeetingResponse('%s','%s', '%s'): Error, attempt to respond to non-meeting request", $requestid, $folderid, $response), SYNC_MEETRESPSTATUS_INVALIDMEETREQ); |
|
| 852 | + } |
|
| 839 | 853 | |
| 840 | - if($meetingrequest->isLocalOrganiser()) |
|
| 841 | - throw new StatusException(sprintf("Grommunio->MeetingResponse('%s','%s', '%s'): Error, attempt to response to meeting request that we organized", $requestid, $folderid, $response), SYNC_MEETRESPSTATUS_INVALIDMEETREQ); |
|
| 854 | + if($meetingrequest->isLocalOrganiser()) { |
|
| 855 | + throw new StatusException(sprintf("Grommunio->MeetingResponse('%s','%s', '%s'): Error, attempt to response to meeting request that we organized", $requestid, $folderid, $response), SYNC_MEETRESPSTATUS_INVALIDMEETREQ); |
|
| 856 | + } |
|
| 842 | 857 | |
| 843 | 858 | // Process the meeting response. We don't have to send the actual meeting response |
| 844 | 859 | // e-mail, because the device will send it itself. This seems not to be the case |
@@ -906,8 +921,9 @@ discard block |
||
| 906 | 921 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->MeetingResponse('%s','%s', '%s'): found other calendar entryid", $requestid, $folderid, $response)); |
| 907 | 922 | } |
| 908 | 923 | |
| 909 | - if ($requestid == $calendarid) |
|
| 910 | - throw new StatusException(sprintf("Grommunio->MeetingResponse('%s','%s', '%s'): Error finding the accepted meeting response in the calendar", $requestid, $folderid, $response), SYNC_MEETRESPSTATUS_INVALIDMEETREQ); |
|
| 924 | + if ($requestid == $calendarid) { |
|
| 925 | + throw new StatusException(sprintf("Grommunio->MeetingResponse('%s','%s', '%s'): Error finding the accepted meeting response in the calendar", $requestid, $folderid, $response), SYNC_MEETRESPSTATUS_INVALIDMEETREQ); |
|
| 926 | + } |
|
| 911 | 927 | } |
| 912 | 928 | |
| 913 | 929 | // delete meeting request from Inbox |
@@ -971,8 +987,9 @@ discard block |
||
| 971 | 987 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->ChangesSinkInitialize(): folderid '%s'", $folderid)); |
| 972 | 988 | |
| 973 | 989 | $entryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($folderid)); |
| 974 | - if (!$entryid) |
|
| 975 | - return false; |
|
| 990 | + if (!$entryid) { |
|
| 991 | + return false; |
|
| 992 | + } |
|
| 976 | 993 | |
| 977 | 994 | // add entryid to the monitored folders |
| 978 | 995 | $this->changesSinkFolders[$entryid] = $folderid; |
@@ -1000,8 +1017,9 @@ discard block |
||
| 1000 | 1017 | $hierarchyNotifications = array(); |
| 1001 | 1018 | $sinkresult = @mapi_sink_timedwait($this->changesSink, $timeout * 1000); |
| 1002 | 1019 | |
| 1003 | - if (!is_array($sinkresult)) |
|
| 1004 | - throw new StatusException("Grommunio->ChangesSink(): Sink returned invalid notification, aborting", SyncCollections::OBSOLETE_CONNECTION); |
|
| 1020 | + if (!is_array($sinkresult)) { |
|
| 1021 | + throw new StatusException("Grommunio->ChangesSink(): Sink returned invalid notification, aborting", SyncCollections::OBSOLETE_CONNECTION); |
|
| 1022 | + } |
|
| 1005 | 1023 | |
| 1006 | 1024 | // reverse array so that the changes on folders are before changes on messages and |
| 1007 | 1025 | // it's possible to filter such notifications |
@@ -1116,8 +1134,7 @@ discard block |
||
| 1116 | 1134 | } |
| 1117 | 1135 | $response->recipientcount++; |
| 1118 | 1136 | $response->recipient[] = $entry; |
| 1119 | - } |
|
| 1120 | - elseif (is_int($recipient)) { |
|
| 1137 | + } elseif (is_int($recipient)) { |
|
| 1121 | 1138 | $response->status = $recipient; |
| 1122 | 1139 | } |
| 1123 | 1140 | } |
@@ -1170,22 +1187,27 @@ discard block |
||
| 1170 | 1187 | //TODO: use PR_ANR for this restriction instead of PR_DISPLAY_NAME and PR_ACCOUNT |
| 1171 | 1188 | $addrbook = $this->getAddressbook(); |
| 1172 | 1189 | // FIXME: create a function to get the adressbook contentstable |
| 1173 | - if ($addrbook) |
|
| 1174 | - $ab_entryid = mapi_ab_getdefaultdir($addrbook); |
|
| 1175 | - if ($ab_entryid) |
|
| 1176 | - $ab_dir = mapi_ab_openentry($addrbook, $ab_entryid); |
|
| 1177 | - if ($ab_dir) |
|
| 1178 | - $table = mapi_folder_getcontentstable($ab_dir); |
|
| 1190 | + if ($addrbook) { |
|
| 1191 | + $ab_entryid = mapi_ab_getdefaultdir($addrbook); |
|
| 1192 | + } |
|
| 1193 | + if ($ab_entryid) { |
|
| 1194 | + $ab_dir = mapi_ab_openentry($addrbook, $ab_entryid); |
|
| 1195 | + } |
|
| 1196 | + if ($ab_dir) { |
|
| 1197 | + $table = mapi_folder_getcontentstable($ab_dir); |
|
| 1198 | + } |
|
| 1179 | 1199 | |
| 1180 | - if (!$table) |
|
| 1181 | - throw new StatusException(sprintf("Grommunio->GetGALSearchResults(): could not open addressbook: 0x%X", mapi_last_hresult()), SYNC_SEARCHSTATUS_STORE_CONNECTIONFAILED); |
|
| 1200 | + if (!$table) { |
|
| 1201 | + throw new StatusException(sprintf("Grommunio->GetGALSearchResults(): could not open addressbook: 0x%X", mapi_last_hresult()), SYNC_SEARCHSTATUS_STORE_CONNECTIONFAILED); |
|
| 1202 | + } |
|
| 1182 | 1203 | |
| 1183 | 1204 | $restriction = MAPIUtils::GetSearchRestriction(u2w($searchquery)); |
| 1184 | 1205 | mapi_table_restrict($table, $restriction); |
| 1185 | 1206 | mapi_table_sort($table, array(PR_DISPLAY_NAME => TABLE_SORT_ASCEND)); |
| 1186 | 1207 | |
| 1187 | - if (mapi_last_hresult()) |
|
| 1188 | - throw new StatusException(sprintf("Grommunio->GetGALSearchResults(): could not apply restriction: 0x%X", mapi_last_hresult()), SYNC_SEARCHSTATUS_STORE_TOOCOMPLEX); |
|
| 1208 | + if (mapi_last_hresult()) { |
|
| 1209 | + throw new StatusException(sprintf("Grommunio->GetGALSearchResults(): could not apply restriction: 0x%X", mapi_last_hresult()), SYNC_SEARCHSTATUS_STORE_TOOCOMPLEX); |
|
| 1210 | + } |
|
| 1189 | 1211 | |
| 1190 | 1212 | //range for the search results, default symbian range end is 50, wm 99, |
| 1191 | 1213 | //so we'll use that of nokia |
@@ -1203,8 +1225,9 @@ discard block |
||
| 1203 | 1225 | //do not return more results as requested in range |
| 1204 | 1226 | $querylimit = (($rangeend + 1) < $querycnt) ? ($rangeend + 1) : $querycnt; |
| 1205 | 1227 | |
| 1206 | - if ($querycnt > 0) |
|
| 1207 | - $abentries = mapi_table_queryrows($table, array(PR_ENTRYID, PR_ACCOUNT, PR_DISPLAY_NAME, PR_SMTP_ADDRESS, PR_BUSINESS_TELEPHONE_NUMBER, PR_GIVEN_NAME, PR_SURNAME, PR_MOBILE_TELEPHONE_NUMBER, PR_HOME_TELEPHONE_NUMBER, PR_TITLE, PR_COMPANY_NAME, PR_OFFICE_LOCATION, PR_EMS_AB_THUMBNAIL_PHOTO), $rangestart, $querylimit); |
|
| 1228 | + if ($querycnt > 0) { |
|
| 1229 | + $abentries = mapi_table_queryrows($table, array(PR_ENTRYID, PR_ACCOUNT, PR_DISPLAY_NAME, PR_SMTP_ADDRESS, PR_BUSINESS_TELEPHONE_NUMBER, PR_GIVEN_NAME, PR_SURNAME, PR_MOBILE_TELEPHONE_NUMBER, PR_HOME_TELEPHONE_NUMBER, PR_TITLE, PR_COMPANY_NAME, PR_OFFICE_LOCATION, PR_EMS_AB_THUMBNAIL_PHOTO), $rangestart, $querylimit); |
|
| 1230 | + } |
|
| 1208 | 1231 | |
| 1209 | 1232 | for ($i = 0; $i < $querylimit; $i++) { |
| 1210 | 1233 | if (!isset($abentries[$i][PR_SMTP_ADDRESS])) { |
@@ -1214,8 +1237,9 @@ discard block |
||
| 1214 | 1237 | |
| 1215 | 1238 | $items[$i][SYNC_GAL_DISPLAYNAME] = w2u($abentries[$i][PR_DISPLAY_NAME]); |
| 1216 | 1239 | |
| 1217 | - if (strlen(trim($items[$i][SYNC_GAL_DISPLAYNAME])) == 0) |
|
| 1218 | - $items[$i][SYNC_GAL_DISPLAYNAME] = w2u($abentries[$i][PR_ACCOUNT]); |
|
| 1240 | + if (strlen(trim($items[$i][SYNC_GAL_DISPLAYNAME])) == 0) { |
|
| 1241 | + $items[$i][SYNC_GAL_DISPLAYNAME] = w2u($abentries[$i][PR_ACCOUNT]); |
|
| 1242 | + } |
|
| 1219 | 1243 | |
| 1220 | 1244 | $items[$i][SYNC_GAL_ALIAS] = w2u($abentries[$i][PR_ACCOUNT]); |
| 1221 | 1245 | //it's not possible not get first and last name of an user |
@@ -1223,32 +1247,42 @@ discard block |
||
| 1223 | 1247 | //to displayname and leave firstname unset |
| 1224 | 1248 | //this was changed in Zarafa 6.40, so we try to get first and |
| 1225 | 1249 | //last name and fall back to the old behaviour if these values are not set |
| 1226 | - if (isset($abentries[$i][PR_GIVEN_NAME])) |
|
| 1227 | - $items[$i][SYNC_GAL_FIRSTNAME] = w2u($abentries[$i][PR_GIVEN_NAME]); |
|
| 1228 | - if (isset($abentries[$i][PR_SURNAME])) |
|
| 1229 | - $items[$i][SYNC_GAL_LASTNAME] = w2u($abentries[$i][PR_SURNAME]); |
|
| 1250 | + if (isset($abentries[$i][PR_GIVEN_NAME])) { |
|
| 1251 | + $items[$i][SYNC_GAL_FIRSTNAME] = w2u($abentries[$i][PR_GIVEN_NAME]); |
|
| 1252 | + } |
|
| 1253 | + if (isset($abentries[$i][PR_SURNAME])) { |
|
| 1254 | + $items[$i][SYNC_GAL_LASTNAME] = w2u($abentries[$i][PR_SURNAME]); |
|
| 1255 | + } |
|
| 1230 | 1256 | |
| 1231 | - if (!isset($items[$i][SYNC_GAL_LASTNAME])) $items[$i][SYNC_GAL_LASTNAME] = $items[$i][SYNC_GAL_DISPLAYNAME]; |
|
| 1257 | + if (!isset($items[$i][SYNC_GAL_LASTNAME])) { |
|
| 1258 | + $items[$i][SYNC_GAL_LASTNAME] = $items[$i][SYNC_GAL_DISPLAYNAME]; |
|
| 1259 | + } |
|
| 1232 | 1260 | |
| 1233 | 1261 | $items[$i][SYNC_GAL_EMAILADDRESS] = w2u($abentries[$i][PR_SMTP_ADDRESS]); |
| 1234 | 1262 | //check if an user has an office number or it might produce warnings in the log |
| 1235 | - if (isset($abentries[$i][PR_BUSINESS_TELEPHONE_NUMBER])) |
|
| 1236 | - $items[$i][SYNC_GAL_PHONE] = w2u($abentries[$i][PR_BUSINESS_TELEPHONE_NUMBER]); |
|
| 1263 | + if (isset($abentries[$i][PR_BUSINESS_TELEPHONE_NUMBER])) { |
|
| 1264 | + $items[$i][SYNC_GAL_PHONE] = w2u($abentries[$i][PR_BUSINESS_TELEPHONE_NUMBER]); |
|
| 1265 | + } |
|
| 1237 | 1266 | //check if an user has a mobile number or it might produce warnings in the log |
| 1238 | - if (isset($abentries[$i][PR_MOBILE_TELEPHONE_NUMBER])) |
|
| 1239 | - $items[$i][SYNC_GAL_MOBILEPHONE] = w2u($abentries[$i][PR_MOBILE_TELEPHONE_NUMBER]); |
|
| 1267 | + if (isset($abentries[$i][PR_MOBILE_TELEPHONE_NUMBER])) { |
|
| 1268 | + $items[$i][SYNC_GAL_MOBILEPHONE] = w2u($abentries[$i][PR_MOBILE_TELEPHONE_NUMBER]); |
|
| 1269 | + } |
|
| 1240 | 1270 | //check if an user has a home number or it might produce warnings in the log |
| 1241 | - if (isset($abentries[$i][PR_HOME_TELEPHONE_NUMBER])) |
|
| 1242 | - $items[$i][SYNC_GAL_HOMEPHONE] = w2u($abentries[$i][PR_HOME_TELEPHONE_NUMBER]); |
|
| 1271 | + if (isset($abentries[$i][PR_HOME_TELEPHONE_NUMBER])) { |
|
| 1272 | + $items[$i][SYNC_GAL_HOMEPHONE] = w2u($abentries[$i][PR_HOME_TELEPHONE_NUMBER]); |
|
| 1273 | + } |
|
| 1243 | 1274 | |
| 1244 | - if (isset($abentries[$i][PR_COMPANY_NAME])) |
|
| 1245 | - $items[$i][SYNC_GAL_COMPANY] = w2u($abentries[$i][PR_COMPANY_NAME]); |
|
| 1275 | + if (isset($abentries[$i][PR_COMPANY_NAME])) { |
|
| 1276 | + $items[$i][SYNC_GAL_COMPANY] = w2u($abentries[$i][PR_COMPANY_NAME]); |
|
| 1277 | + } |
|
| 1246 | 1278 | |
| 1247 | - if (isset($abentries[$i][PR_TITLE])) |
|
| 1248 | - $items[$i][SYNC_GAL_TITLE] = w2u($abentries[$i][PR_TITLE]); |
|
| 1279 | + if (isset($abentries[$i][PR_TITLE])) { |
|
| 1280 | + $items[$i][SYNC_GAL_TITLE] = w2u($abentries[$i][PR_TITLE]); |
|
| 1281 | + } |
|
| 1249 | 1282 | |
| 1250 | - if (isset($abentries[$i][PR_OFFICE_LOCATION])) |
|
| 1251 | - $items[$i][SYNC_GAL_OFFICE] = w2u($abentries[$i][PR_OFFICE_LOCATION]); |
|
| 1283 | + if (isset($abentries[$i][PR_OFFICE_LOCATION])) { |
|
| 1284 | + $items[$i][SYNC_GAL_OFFICE] = w2u($abentries[$i][PR_OFFICE_LOCATION]); |
|
| 1285 | + } |
|
| 1252 | 1286 | |
| 1253 | 1287 | if ($searchpicture !== false && isset($abentries[$i][PR_EMS_AB_THUMBNAIL_PHOTO])) { |
| 1254 | 1288 | $items[$i][SYNC_GAL_PICTURE] = StringStreamWrapper::Open($abentries[$i][PR_EMS_AB_THUMBNAIL_PHOTO]); |
@@ -1297,8 +1331,10 @@ discard block |
||
| 1297 | 1331 | // do the search and wait for all the results available |
| 1298 | 1332 | while (time() - $searchStart < SEARCH_WAIT) { |
| 1299 | 1333 | $searchcriteria = mapi_folder_getsearchcriteria($searchFolder); |
| 1300 | - if(($searchcriteria["searchstate"] & SEARCH_REBUILD) == 0) |
|
| 1301 | - break; // Search is done |
|
| 1334 | + if(($searchcriteria["searchstate"] & SEARCH_REBUILD) == 0) { |
|
| 1335 | + break; |
|
| 1336 | + } |
|
| 1337 | + // Search is done |
|
| 1302 | 1338 | sleep(1); |
| 1303 | 1339 | } |
| 1304 | 1340 | |
@@ -1393,8 +1429,7 @@ discard block |
||
| 1393 | 1429 | // setup the correct store |
| 1394 | 1430 | if ($this->Setup($store, false, $folderid)) { |
| 1395 | 1431 | return $this->store; |
| 1396 | - } |
|
| 1397 | - else { |
|
| 1432 | + } else { |
|
| 1398 | 1433 | ZLog::Write(LOGLEVEL_WARN, sprintf("Grommunio->GetMAPIStoreForFolderId('%s', '%s'): store is not available", $store, $folderid)); |
| 1399 | 1434 | return false; |
| 1400 | 1435 | } |
@@ -1505,8 +1540,7 @@ discard block |
||
| 1505 | 1540 | |
| 1506 | 1541 | if (isset($this->folderStatCache[$user][$folderid])) { |
| 1507 | 1542 | return $this->folderStatCache[$user][$folderid]; |
| 1508 | - } |
|
| 1509 | - else { |
|
| 1543 | + } else { |
|
| 1510 | 1544 | // a timestamp that changes once per hour is returned in case there is no data found for this folder. It will be synchronized only once per hour. |
| 1511 | 1545 | return gmdate("Y-m-d-H"); |
| 1512 | 1546 | } |
@@ -1581,8 +1615,7 @@ discard block |
||
| 1581 | 1615 | if (isset($stateMessageProps[PR_LAST_MODIFICATION_TIME])) { |
| 1582 | 1616 | return $stateMessageProps[PR_LAST_MODIFICATION_TIME]; |
| 1583 | 1617 | } |
| 1584 | - } |
|
| 1585 | - catch (StateNotFoundException $e) { } |
|
| 1618 | + } catch (StateNotFoundException $e) { } |
|
| 1586 | 1619 | return "0"; |
| 1587 | 1620 | } |
| 1588 | 1621 | |
@@ -1779,8 +1812,7 @@ discard block |
||
| 1779 | 1812 | if ($devid) { |
| 1780 | 1813 | $this->setDeviceUserData($this->userDeviceData, bin2hex($hierarchyRows[0][PR_ENTRYID]), $devid, $this->mainUser, "statefolder"); |
| 1781 | 1814 | } |
| 1782 | - } |
|
| 1783 | - elseif ($rowCnt == 0) { |
|
| 1815 | + } elseif ($rowCnt == 0) { |
|
| 1784 | 1816 | // legacy code: create the hidden state folder and the device subfolder |
| 1785 | 1817 | // this should happen when the user configures the device (autodiscover or first sync if no autodiscover) |
| 1786 | 1818 | |
@@ -1792,12 +1824,10 @@ discard block |
||
| 1792 | 1824 | if ($rowCnt == 1) { |
| 1793 | 1825 | $hierarchyRows = mapi_table_queryrows($hierarchy, [PR_ENTRYID], 0, 1); |
| 1794 | 1826 | $stateFolder = mapi_msgstore_openentry($this->store, $hierarchyRows[0][PR_ENTRYID]); |
| 1795 | - } |
|
| 1796 | - elseif ($rowCnt == 0) { |
|
| 1827 | + } elseif ($rowCnt == 0) { |
|
| 1797 | 1828 | $stateFolder = mapi_folder_createfolder($rootfolder, STORE_STATE_FOLDER, ""); |
| 1798 | 1829 | mapi_setprops($stateFolder, array(PR_ATTR_HIDDEN => true)); |
| 1799 | - } |
|
| 1800 | - else { |
|
| 1830 | + } else { |
|
| 1801 | 1831 | // TODO: handle this |
| 1802 | 1832 | } |
| 1803 | 1833 | if (isset($stateFolder) && $stateFolder) { |
@@ -1806,12 +1836,10 @@ discard block |
||
| 1806 | 1836 | $this->stateFolder = mapi_msgstore_openentry($this->store, $devStateFolderProps[PR_ENTRYID]); |
| 1807 | 1837 | mapi_setprops($this->stateFolder, array(PR_ATTR_HIDDEN => true)); |
| 1808 | 1838 | // we don't cache the entryid in redis, because this will happen on the next request anyway |
| 1809 | - } |
|
| 1810 | - else { |
|
| 1839 | + } else { |
|
| 1811 | 1840 | // TODO: unable to create state folder - throw exception |
| 1812 | 1841 | } |
| 1813 | - } |
|
| 1814 | - else { |
|
| 1842 | + } else { |
|
| 1815 | 1843 | // This case is rather unlikely that there would be several |
| 1816 | 1844 | // hidden folders having PR_DISPLAY_NAME the same as device id. |
| 1817 | 1845 | |
@@ -1852,8 +1880,7 @@ discard block |
||
| 1852 | 1880 | if ($rowCnt == 1) { |
| 1853 | 1881 | $stateFolderRows = mapi_table_queryrows($stateFolderContents, [PR_ENTRYID], 0, 1); |
| 1854 | 1882 | return mapi_msgstore_openentry($this->store, $stateFolderRows[0][PR_ENTRYID]); |
| 1855 | - } |
|
| 1856 | - elseif($rowCnt > 1) { |
|
| 1883 | + } elseif($rowCnt > 1) { |
|
| 1857 | 1884 | ZLog::Write(LOGLEVEL_WARN, sprintf("Grommunio->getStateMessage(): Found several (%d) states for '%s'", $rowCnt, $messageName)); |
| 1858 | 1885 | } |
| 1859 | 1886 | } |
@@ -1880,8 +1907,7 @@ discard block |
||
| 1880 | 1907 | } |
| 1881 | 1908 | try { |
| 1882 | 1909 | $stateMessage = $this->getStateMessage($devid, $type, $key, $counter); |
| 1883 | - } |
|
| 1884 | - catch (StateNotFoundException $e) { |
|
| 1910 | + } catch (StateNotFoundException $e) { |
|
| 1885 | 1911 | // if message is not available, try to create a new one |
| 1886 | 1912 | $stateMessage = mapi_folder_createmessage($this->stateFolder, MAPI_ASSOCIATED); |
| 1887 | 1913 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->setStateMessage(): mapi_folder_createmessage 0x%08X", mapi_last_hresult())); |
@@ -1999,8 +2025,7 @@ discard block |
||
| 1999 | 2025 | if (mapi_last_hresult()) { |
| 2000 | 2026 | ZLog::Write(LOGLEVEL_WARN, sprintf("Grommunio->adviseStoreToSink(): failed to advised store '%s' with code 0x%X. Polling will be performed.", $store, mapi_last_hresult())); |
| 2001 | 2027 | return false; |
| 2002 | - } |
|
| 2003 | - else { |
|
| 2028 | + } else { |
|
| 2004 | 2029 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->adviseStoreToSink(): advised store '%s'", $store)); |
| 2005 | 2030 | $this->changesSinkStores[] = $store; |
| 2006 | 2031 | } |
@@ -2020,14 +2045,16 @@ discard block |
||
| 2020 | 2045 | private function openMessageStore($user) { |
| 2021 | 2046 | // During PING requests the operations store has to be switched constantly |
| 2022 | 2047 | // the cache prevents the same store opened several times |
| 2023 | - if (isset($this->storeCache[$user])) |
|
| 2024 | - return $this->storeCache[$user]; |
|
| 2048 | + if (isset($this->storeCache[$user])) { |
|
| 2049 | + return $this->storeCache[$user]; |
|
| 2050 | + } |
|
| 2025 | 2051 | |
| 2026 | 2052 | $entryid = false; |
| 2027 | 2053 | $return_public = false; |
| 2028 | 2054 | |
| 2029 | - if (strtoupper($user) == 'SYSTEM') |
|
| 2030 | - $return_public = true; |
|
| 2055 | + if (strtoupper($user) == 'SYSTEM') { |
|
| 2056 | + $return_public = true; |
|
| 2057 | + } |
|
| 2031 | 2058 | |
| 2032 | 2059 | // loop through the storestable if authenticated user of public folder |
| 2033 | 2060 | if ($user == $this->mainUser || $return_public === true) { |
@@ -2049,9 +2076,9 @@ discard block |
||
| 2049 | 2076 | } |
| 2050 | 2077 | } |
| 2051 | 2078 | } |
| 2079 | + } else { |
|
| 2080 | + $entryid = @mapi_msgstore_createentryid($this->defaultstore, $user); |
|
| 2052 | 2081 | } |
| 2053 | - else |
|
| 2054 | - $entryid = @mapi_msgstore_createentryid($this->defaultstore, $user); |
|
| 2055 | 2082 | |
| 2056 | 2083 | if($entryid) { |
| 2057 | 2084 | $store = @mapi_openmsgstore($this->session, $entryid); |
@@ -2062,13 +2089,13 @@ discard block |
||
| 2062 | 2089 | } |
| 2063 | 2090 | |
| 2064 | 2091 | // add this store to the cache |
| 2065 | - if (!isset($this->storeCache[$user])) |
|
| 2066 | - $this->storeCache[$user] = $store; |
|
| 2092 | + if (!isset($this->storeCache[$user])) { |
|
| 2093 | + $this->storeCache[$user] = $store; |
|
| 2094 | + } |
|
| 2067 | 2095 | |
| 2068 | 2096 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->openMessageStore('%s'): Found '%s' store: '%s'", $user, (($return_public)?'PUBLIC':'DEFAULT'),$store)); |
| 2069 | 2097 | return $store; |
| 2070 | - } |
|
| 2071 | - else { |
|
| 2098 | + } else { |
|
| 2072 | 2099 | ZLog::Write(LOGLEVEL_WARN, sprintf("Grommunio->openMessageStore('%s'): No store found for this user", $user)); |
| 2073 | 2100 | return false; |
| 2074 | 2101 | } |
@@ -2124,8 +2151,7 @@ discard block |
||
| 2124 | 2151 | //if oof state is set it must be set of oof and get otherwise |
| 2125 | 2152 | if (isset($oof->oofstate)) { |
| 2126 | 2153 | $this->settingsOofSet($oof); |
| 2127 | - } |
|
| 2128 | - else { |
|
| 2154 | + } else { |
|
| 2129 | 2155 | $this->settingsOofGet($oof); |
| 2130 | 2156 | } |
| 2131 | 2157 | } |
@@ -2163,26 +2189,22 @@ discard block |
||
| 2163 | 2189 | @mapi_setprops($this->defaultstore, array(PR_EC_OUTOFOFFICE => false)); |
| 2164 | 2190 | @mapi_deleteprops($this->defaultstore, array(PR_EC_OUTOFOFFICE_FROM, PR_EC_OUTOFOFFICE_UNTIL)); |
| 2165 | 2191 | ZLog::Write(LOGLEVEL_INFO, "Grommunio->settingsOofGet(): Out of office is set but the from and until are in the past. Disabling out of office."); |
| 2166 | - } |
|
| 2167 | - elseif ($oofprops[PR_EC_OUTOFOFFICE_FROM] < $oofprops[PR_EC_OUTOFOFFICE_UNTIL]) { |
|
| 2192 | + } elseif ($oofprops[PR_EC_OUTOFOFFICE_FROM] < $oofprops[PR_EC_OUTOFOFFICE_UNTIL]) { |
|
| 2168 | 2193 | $oof->oofstate = SYNC_SETTINGSOOF_TIMEBASED; |
| 2169 | 2194 | $oof->starttime = $oofprops[PR_EC_OUTOFOFFICE_FROM]; |
| 2170 | 2195 | $oof->endtime = $oofprops[PR_EC_OUTOFOFFICE_UNTIL]; |
| 2171 | - } |
|
| 2172 | - else { |
|
| 2196 | + } else { |
|
| 2173 | 2197 | ZLog::Write(LOGLEVEL_WARN, sprintf("Grommunio->settingsOofGet(): Time based out of office set but end time ('%s') is before startime ('%s').", |
| 2174 | 2198 | date("Y-m-d H:i:s", $oofprops[PR_EC_OUTOFOFFICE_FROM]), date("Y-m-d H:i:s", $oofprops[PR_EC_OUTOFOFFICE_UNTIL]))); |
| 2175 | 2199 | $oof->Status = SYNC_SETTINGSSTATUS_PROTOCOLLERROR; |
| 2176 | 2200 | } |
| 2177 | - } |
|
| 2178 | - elseif ($oof->oofstate == SYNC_SETTINGSOOF_GLOBAL && (isset($oofprops[PR_EC_OUTOFOFFICE_FROM]) || isset($oofprops[PR_EC_OUTOFOFFICE_UNTIL]))) { |
|
| 2201 | + } elseif ($oof->oofstate == SYNC_SETTINGSOOF_GLOBAL && (isset($oofprops[PR_EC_OUTOFOFFICE_FROM]) || isset($oofprops[PR_EC_OUTOFOFFICE_UNTIL]))) { |
|
| 2179 | 2202 | ZLog::Write(LOGLEVEL_WARN, sprintf("Grommunio->settingsOofGet(): Time based out of office set but either start time ('%s') or end time ('%s') is missing.", |
| 2180 | 2203 | (isset($oofprops[PR_EC_OUTOFOFFICE_FROM]) ? date("Y-m-d H:i:s", $oofprops[PR_EC_OUTOFOFFICE_FROM]) : 'empty'), |
| 2181 | 2204 | (isset($oofprops[PR_EC_OUTOFOFFICE_UNTIL]) ? date("Y-m-d H:i:s", $oofprops[PR_EC_OUTOFOFFICE_UNTIL]) : 'empty'))); |
| 2182 | 2205 | $oof->Status = SYNC_SETTINGSSTATUS_PROTOCOLLERROR; |
| 2183 | 2206 | } |
| 2184 | - } |
|
| 2185 | - else { |
|
| 2207 | + } else { |
|
| 2186 | 2208 | ZLog::Write(LOGLEVEL_WARN, "Grommunio->Unable to get out of office information"); |
| 2187 | 2209 | } |
| 2188 | 2210 | |
@@ -2213,16 +2235,13 @@ discard block |
||
| 2213 | 2235 | if(isset($oof->starttime) && isset($oof->endtime)) { |
| 2214 | 2236 | $props[PR_EC_OUTOFOFFICE_FROM] = $oof->starttime; |
| 2215 | 2237 | $props[PR_EC_OUTOFOFFICE_UNTIL] = $oof->endtime; |
| 2216 | - } |
|
| 2217 | - elseif (isset($oof->starttime) || isset($oof->endtime)) { |
|
| 2238 | + } elseif (isset($oof->starttime) || isset($oof->endtime)) { |
|
| 2218 | 2239 | $oof->Status = SYNC_SETTINGSSTATUS_PROTOCOLLERROR; |
| 2219 | 2240 | } |
| 2220 | - } |
|
| 2221 | - else { |
|
| 2241 | + } else { |
|
| 2222 | 2242 | $deleteProps = array(PR_EC_OUTOFOFFICE_FROM, PR_EC_OUTOFOFFICE_UNTIL); |
| 2223 | 2243 | } |
| 2224 | - } |
|
| 2225 | - elseif($oof->oofstate == SYNC_SETTINGSOOF_DISABLED) { |
|
| 2244 | + } elseif($oof->oofstate == SYNC_SETTINGSOOF_DISABLED) { |
|
| 2226 | 2245 | $props[PR_EC_OUTOFOFFICE] = false; |
| 2227 | 2246 | $deleteProps = array(PR_EC_OUTOFOFFICE_FROM, PR_EC_OUTOFOFFICE_UNTIL); |
| 2228 | 2247 | } |
@@ -2266,8 +2285,7 @@ discard block |
||
| 2266 | 2285 | $emailaddresses->primarysmtpaddress = $user["primary_email"]; |
| 2267 | 2286 | $account->emailaddresses = $emailaddresses; |
| 2268 | 2287 | $userinformation->accounts[] = $account; |
| 2269 | - } |
|
| 2270 | - else { |
|
| 2288 | + } else { |
|
| 2271 | 2289 | $userinformation->emailaddresses[] = $user["primary_email"]; |
| 2272 | 2290 | } |
| 2273 | 2291 | return true; |
@@ -2519,10 +2537,12 @@ discard block |
||
| 2519 | 2537 | $addrbook = $this->getAddressbook(); |
| 2520 | 2538 | // FIXME: create a function to get the adressbook contentstable |
| 2521 | 2539 | $ab_entryid = mapi_ab_getdefaultdir($addrbook); |
| 2522 | - if ($ab_entryid) |
|
| 2523 | - $ab_dir = mapi_ab_openentry($addrbook, $ab_entryid); |
|
| 2524 | - if ($ab_dir) |
|
| 2525 | - $table = mapi_folder_getcontentstable($ab_dir); |
|
| 2540 | + if ($ab_entryid) { |
|
| 2541 | + $ab_dir = mapi_ab_openentry($addrbook, $ab_entryid); |
|
| 2542 | + } |
|
| 2543 | + if ($ab_dir) { |
|
| 2544 | + $table = mapi_folder_getcontentstable($ab_dir); |
|
| 2545 | + } |
|
| 2526 | 2546 | |
| 2527 | 2547 | if (!$table) { |
| 2528 | 2548 | ZLog::Write(LOGLEVEL_WARN, sprintf("Grommunio->resolveRecipientGAL(): Unable to open addressbook:0x%X", mapi_last_hresult())); |
@@ -2539,12 +2559,10 @@ discard block |
||
| 2539 | 2559 | // some devices request 0 ambiguous recipients |
| 2540 | 2560 | if ($querycnt == 1 && $maxAmbiguousRecipients == 0) { |
| 2541 | 2561 | $rowsToQuery = 1; |
| 2542 | - } |
|
| 2543 | - elseif ($querycnt > 1 && $maxAmbiguousRecipients == 0) { |
|
| 2562 | + } elseif ($querycnt > 1 && $maxAmbiguousRecipients == 0) { |
|
| 2544 | 2563 | ZLog::Write(LOGLEVEL_INFO, sprintf("Grommunio->resolveRecipientGAL(): GAL search found %d recipients but the device hasn't requested ambiguous recipients", $querycnt)); |
| 2545 | 2564 | return $recipientGal; |
| 2546 | - } |
|
| 2547 | - elseif ($querycnt > 1 && $maxAmbiguousRecipients == 1) { |
|
| 2565 | + } elseif ($querycnt > 1 && $maxAmbiguousRecipients == 1) { |
|
| 2548 | 2566 | $rowsToQuery = $querycnt; |
| 2549 | 2567 | } |
| 2550 | 2568 | // get the certificate every time because caching the certificate is less expensive than opening addressbook entry again |
@@ -2565,21 +2583,18 @@ discard block |
||
| 2565 | 2583 | ZLog::Write(LOGLEVEL_WBXML, sprintf("Grommunio->resolveRecipientGAL(): distlist's '%s' member: '%s'", $to, $distListMembers[$j][PR_DISPLAY_NAME])); |
| 2566 | 2584 | $recipientGal[] = $this->createResolveRecipient(SYNC_RESOLVERECIPIENTS_TYPE_GAL, $to, $distListMembers[$j], $nrDistListMembers); |
| 2567 | 2585 | } |
| 2568 | - } |
|
| 2569 | - else { |
|
| 2586 | + } else { |
|
| 2570 | 2587 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->resolveRecipientGAL(): '%s' is a dist list, but return it as is.", $to)); |
| 2571 | 2588 | $recipientGal[] = $this->createResolveRecipient(SYNC_RESOLVERECIPIENTS_TYPE_GAL, $abentries[$i][PR_SMTP_ADDRESS], $abentries[$i]); |
| 2572 | 2589 | } |
| 2573 | - } |
|
| 2574 | - elseif ($abentries[$i][PR_OBJECT_TYPE] == MAPI_MAILUSER) { |
|
| 2590 | + } elseif ($abentries[$i][PR_OBJECT_TYPE] == MAPI_MAILUSER) { |
|
| 2575 | 2591 | $recipientGal[] = $this->createResolveRecipient(SYNC_RESOLVERECIPIENTS_TYPE_GAL, $abentries[$i][PR_SMTP_ADDRESS], $abentries[$i]); |
| 2576 | 2592 | } |
| 2577 | 2593 | } |
| 2578 | 2594 | |
| 2579 | 2595 | ZLog::Write(LOGLEVEL_WBXML, "Grommunio->resolveRecipientGAL(): Found a recipient in GAL"); |
| 2580 | 2596 | return $recipientGal; |
| 2581 | - } |
|
| 2582 | - else { |
|
| 2597 | + } else { |
|
| 2583 | 2598 | ZLog::Write(LOGLEVEL_WARN, sprintf("Grommunio->resolveRecipientGAL(): No recipient found for: '%s' in GAL", $to)); |
| 2584 | 2599 | return SYNC_RESOLVERECIPSSTATUS_RESPONSE_UNRESOLVEDRECIP; |
| 2585 | 2600 | } |
@@ -2655,8 +2670,7 @@ discard block |
||
| 2655 | 2670 | break; |
| 2656 | 2671 | } |
| 2657 | 2672 | } |
| 2658 | - } |
|
| 2659 | - else { |
|
| 2673 | + } else { |
|
| 2660 | 2674 | ZLog::Write(LOGLEVEL_WARN, sprintf("Grommunio->resolveRecipientContact(): Unable to open public store: 0x%X", $result)); |
| 2661 | 2675 | } |
| 2662 | 2676 | |
@@ -2711,18 +2725,15 @@ discard block |
||
| 2711 | 2725 | |
| 2712 | 2726 | if ($type == SYNC_RESOLVERECIPIENTS_TYPE_GAL) { |
| 2713 | 2727 | $certificateProp = PR_EMS_AB_TAGGED_X509_CERT; |
| 2714 | - } |
|
| 2715 | - elseif ($type == SYNC_RESOLVERECIPIENTS_TYPE_CONTACT) { |
|
| 2728 | + } elseif ($type == SYNC_RESOLVERECIPIENTS_TYPE_CONTACT) { |
|
| 2716 | 2729 | $certificateProp = PR_USER_X509_CERTIFICATE; |
| 2717 | - } |
|
| 2718 | - else { |
|
| 2730 | + } else { |
|
| 2719 | 2731 | $certificateProp = null; |
| 2720 | 2732 | } |
| 2721 | 2733 | |
| 2722 | 2734 | if (isset($recipientProperties[$certificateProp]) && is_array($recipientProperties[$certificateProp]) && !empty($recipientProperties[$certificateProp])) { |
| 2723 | 2735 | $certificates = $this->getCertificates($recipientProperties[$certificateProp], $recipientCount); |
| 2724 | - } |
|
| 2725 | - else { |
|
| 2736 | + } else { |
|
| 2726 | 2737 | $certificates = $this->getCertificates(false); |
| 2727 | 2738 | ZLog::Write(LOGLEVEL_INFO, sprintf("Grommunio->createResolveRecipient(): No certificate found for '%s' (requested email address: '%s')", $recipientProperties[PR_DISPLAY_NAME], $email)); |
| 2728 | 2739 | } |
@@ -2854,8 +2865,7 @@ discard block |
||
| 2854 | 2865 | $deviceIdDisabled = ( ($deviceId !==null) && in_array($deviceId, array_map('strtolower', $enabledFeatures[PR_EC_DISABLED_FEATURES])) )? true : false; |
| 2855 | 2866 | if ($mobileDisabled) { |
| 2856 | 2867 | throw new FatalException("User is disabled for grommunio-sync."); |
| 2857 | - } |
|
| 2858 | - elseif ($deviceIdDisabled) { |
|
| 2868 | + } elseif ($deviceIdDisabled) { |
|
| 2859 | 2869 | throw new FatalException(sprintf("User has deviceId %s disabled for usage with grommunio-sync.", $deviceId)); |
| 2860 | 2870 | } |
| 2861 | 2871 | } |
@@ -25,11 +25,11 @@ discard block |
||
| 25 | 25 | public static function GetEmailRestriction($timestamp) { |
| 26 | 26 | // ATTENTION: ON CHANGING THIS RESTRICTION, MAPIUtils::IsInEmailSyncInterval() also needs to be changed |
| 27 | 27 | $restriction = array ( RES_PROPERTY, |
| 28 | - array ( RELOP => RELOP_GE, |
|
| 28 | + array ( RELOP => RELOP_GE, |
|
| 29 | 29 | ULPROPTAG => PR_MESSAGE_DELIVERY_TIME, |
| 30 | 30 | VALUE => $timestamp |
| 31 | - ) |
|
| 32 | - ); |
|
| 31 | + ) |
|
| 32 | + ); |
|
| 33 | 33 | |
| 34 | 34 | return $restriction; |
| 35 | 35 | } |
@@ -56,80 +56,80 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | // ATTENTION: ON CHANGING THIS RESTRICTION, MAPIUtils::IsInCalendarSyncInterval() also needs to be changed |
| 58 | 58 | $restriction = Array(RES_OR, |
| 59 | - Array( |
|
| 60 | - // OR |
|
| 61 | - // item.end > window.start && item.start < window.end |
|
| 62 | - Array(RES_AND, |
|
| 63 | - Array( |
|
| 64 | - Array(RES_PROPERTY, |
|
| 65 | - Array(RELOP => RELOP_LE, |
|
| 66 | - ULPROPTAG => $props["starttime"], |
|
| 67 | - VALUE => $end |
|
| 68 | - ) |
|
| 69 | - ), |
|
| 70 | - Array(RES_PROPERTY, |
|
| 71 | - Array(RELOP => RELOP_GE, |
|
| 72 | - ULPROPTAG => $props["endtime"], |
|
| 73 | - VALUE => $start |
|
| 74 | - ) |
|
| 75 | - ) |
|
| 76 | - ) |
|
| 77 | - ), |
|
| 78 | - // OR |
|
| 79 | - Array(RES_OR, |
|
| 80 | - Array( |
|
| 81 | - // OR |
|
| 82 | - // (EXIST(recurrence_enddate_property) && item[isRecurring] == true && recurrence_enddate_property >= start) |
|
| 83 | - Array(RES_AND, |
|
| 84 | - Array( |
|
| 85 | - Array(RES_EXIST, |
|
| 86 | - Array(ULPROPTAG => $props["recurrenceend"], |
|
| 87 | - ) |
|
| 88 | - ), |
|
| 89 | - Array(RES_PROPERTY, |
|
| 90 | - Array(RELOP => RELOP_EQ, |
|
| 91 | - ULPROPTAG => $props["isrecurring"], |
|
| 92 | - VALUE => true |
|
| 93 | - ) |
|
| 94 | - ), |
|
| 95 | - Array(RES_PROPERTY, |
|
| 96 | - Array(RELOP => RELOP_GE, |
|
| 97 | - ULPROPTAG => $props["recurrenceend"], |
|
| 98 | - VALUE => $start |
|
| 99 | - ) |
|
| 100 | - ) |
|
| 101 | - ) |
|
| 102 | - ), |
|
| 103 | - // OR |
|
| 104 | - // (!EXIST(recurrence_enddate_property) && item[isRecurring] == true && item[start] <= end) |
|
| 105 | - Array(RES_AND, |
|
| 106 | - Array( |
|
| 107 | - Array(RES_NOT, |
|
| 108 | - Array( |
|
| 109 | - Array(RES_EXIST, |
|
| 110 | - Array(ULPROPTAG => $props["recurrenceend"] |
|
| 111 | - ) |
|
| 112 | - ) |
|
| 113 | - ) |
|
| 114 | - ), |
|
| 115 | - Array(RES_PROPERTY, |
|
| 116 | - Array(RELOP => RELOP_LE, |
|
| 117 | - ULPROPTAG => $props["starttime"], |
|
| 118 | - VALUE => $end |
|
| 119 | - ) |
|
| 120 | - ), |
|
| 121 | - Array(RES_PROPERTY, |
|
| 122 | - Array(RELOP => RELOP_EQ, |
|
| 123 | - ULPROPTAG => $props["isrecurring"], |
|
| 124 | - VALUE => true |
|
| 125 | - ) |
|
| 126 | - ) |
|
| 127 | - ) |
|
| 128 | - ) |
|
| 129 | - ) |
|
| 130 | - ) // EXISTS OR |
|
| 131 | - ) |
|
| 132 | - ); // global OR |
|
| 59 | + Array( |
|
| 60 | + // OR |
|
| 61 | + // item.end > window.start && item.start < window.end |
|
| 62 | + Array(RES_AND, |
|
| 63 | + Array( |
|
| 64 | + Array(RES_PROPERTY, |
|
| 65 | + Array(RELOP => RELOP_LE, |
|
| 66 | + ULPROPTAG => $props["starttime"], |
|
| 67 | + VALUE => $end |
|
| 68 | + ) |
|
| 69 | + ), |
|
| 70 | + Array(RES_PROPERTY, |
|
| 71 | + Array(RELOP => RELOP_GE, |
|
| 72 | + ULPROPTAG => $props["endtime"], |
|
| 73 | + VALUE => $start |
|
| 74 | + ) |
|
| 75 | + ) |
|
| 76 | + ) |
|
| 77 | + ), |
|
| 78 | + // OR |
|
| 79 | + Array(RES_OR, |
|
| 80 | + Array( |
|
| 81 | + // OR |
|
| 82 | + // (EXIST(recurrence_enddate_property) && item[isRecurring] == true && recurrence_enddate_property >= start) |
|
| 83 | + Array(RES_AND, |
|
| 84 | + Array( |
|
| 85 | + Array(RES_EXIST, |
|
| 86 | + Array(ULPROPTAG => $props["recurrenceend"], |
|
| 87 | + ) |
|
| 88 | + ), |
|
| 89 | + Array(RES_PROPERTY, |
|
| 90 | + Array(RELOP => RELOP_EQ, |
|
| 91 | + ULPROPTAG => $props["isrecurring"], |
|
| 92 | + VALUE => true |
|
| 93 | + ) |
|
| 94 | + ), |
|
| 95 | + Array(RES_PROPERTY, |
|
| 96 | + Array(RELOP => RELOP_GE, |
|
| 97 | + ULPROPTAG => $props["recurrenceend"], |
|
| 98 | + VALUE => $start |
|
| 99 | + ) |
|
| 100 | + ) |
|
| 101 | + ) |
|
| 102 | + ), |
|
| 103 | + // OR |
|
| 104 | + // (!EXIST(recurrence_enddate_property) && item[isRecurring] == true && item[start] <= end) |
|
| 105 | + Array(RES_AND, |
|
| 106 | + Array( |
|
| 107 | + Array(RES_NOT, |
|
| 108 | + Array( |
|
| 109 | + Array(RES_EXIST, |
|
| 110 | + Array(ULPROPTAG => $props["recurrenceend"] |
|
| 111 | + ) |
|
| 112 | + ) |
|
| 113 | + ) |
|
| 114 | + ), |
|
| 115 | + Array(RES_PROPERTY, |
|
| 116 | + Array(RELOP => RELOP_LE, |
|
| 117 | + ULPROPTAG => $props["starttime"], |
|
| 118 | + VALUE => $end |
|
| 119 | + ) |
|
| 120 | + ), |
|
| 121 | + Array(RES_PROPERTY, |
|
| 122 | + Array(RELOP => RELOP_EQ, |
|
| 123 | + ULPROPTAG => $props["isrecurring"], |
|
| 124 | + VALUE => true |
|
| 125 | + ) |
|
| 126 | + ) |
|
| 127 | + ) |
|
| 128 | + ) |
|
| 129 | + ) |
|
| 130 | + ) // EXISTS OR |
|
| 131 | + ) |
|
| 132 | + ); // global OR |
|
| 133 | 133 | |
| 134 | 134 | return $restriction; |
| 135 | 135 | } |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | //(!EXIST(recurrence_enddate_property) && item[isRecurring] == true && item[start] <= end) |
| 326 | 326 | !isset($p[$props["recurrenceend"]]) && $p[$props["isrecurring"]] == true && $p[$props["starttime"]] <= $end |
| 327 | 327 | ) |
| 328 | - ) { |
|
| 328 | + ) { |
|
| 329 | 329 | ZLog::Write(LOGLEVEL_DEBUG, "MAPIUtils->IsInCalendarSyncInterval: Message is in the synchronization interval"); |
| 330 | 330 | return true; |
| 331 | 331 | } |
@@ -377,8 +377,7 @@ discard block |
||
| 377 | 377 | if ($ret == MAPI_E_NOT_FOUND) { |
| 378 | 378 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("MAPIUtils->readPropStream: property 0x%08X not found. It is either empty or not set. It will be ignored.", $prop)); |
| 379 | 379 | return ""; |
| 380 | - } |
|
| 381 | - elseif ($ret) { |
|
| 380 | + } elseif ($ret) { |
|
| 382 | 381 | ZLog::Write(LOGLEVEL_ERROR, "MAPIUtils->readPropStream error opening stream: 0x%08X", $ret); |
| 383 | 382 | return ""; |
| 384 | 383 | } |
@@ -386,8 +385,9 @@ discard block |
||
| 386 | 385 | $string = ""; |
| 387 | 386 | while(1) { |
| 388 | 387 | $data = mapi_stream_read($stream, 1024); |
| 389 | - if(strlen($data) == 0) |
|
| 390 | - break; |
|
| 388 | + if(strlen($data) == 0) { |
|
| 389 | + break; |
|
| 390 | + } |
|
| 391 | 391 | $string .= $data; |
| 392 | 392 | } |
| 393 | 393 | |
@@ -480,75 +480,85 @@ discard block |
||
| 480 | 480 | */ |
| 481 | 481 | public static function GetNativeBodyType($messageprops) { |
| 482 | 482 | //check if the properties are set and get the error code if needed |
| 483 | - if (!isset($messageprops[PR_BODY])) $messageprops[PR_BODY] = self::GetError(PR_BODY, $messageprops); |
|
| 484 | - if (!isset($messageprops[PR_RTF_COMPRESSED])) $messageprops[PR_RTF_COMPRESSED] = self::GetError(PR_RTF_COMPRESSED, $messageprops); |
|
| 485 | - if (!isset($messageprops[PR_HTML])) $messageprops[PR_HTML] = self::GetError(PR_HTML, $messageprops); |
|
| 486 | - if (!isset($messageprops[PR_RTF_IN_SYNC])) $messageprops[PR_RTF_IN_SYNC] = self::GetError(PR_RTF_IN_SYNC, $messageprops); |
|
| 483 | + if (!isset($messageprops[PR_BODY])) { |
|
| 484 | + $messageprops[PR_BODY] = self::GetError(PR_BODY, $messageprops); |
|
| 485 | + } |
|
| 486 | + if (!isset($messageprops[PR_RTF_COMPRESSED])) { |
|
| 487 | + $messageprops[PR_RTF_COMPRESSED] = self::GetError(PR_RTF_COMPRESSED, $messageprops); |
|
| 488 | + } |
|
| 489 | + if (!isset($messageprops[PR_HTML])) { |
|
| 490 | + $messageprops[PR_HTML] = self::GetError(PR_HTML, $messageprops); |
|
| 491 | + } |
|
| 492 | + if (!isset($messageprops[PR_RTF_IN_SYNC])) { |
|
| 493 | + $messageprops[PR_RTF_IN_SYNC] = self::GetError(PR_RTF_IN_SYNC, $messageprops); |
|
| 494 | + } |
|
| 487 | 495 | |
| 488 | 496 | if ( // 1 |
| 489 | 497 | ($messageprops[PR_BODY] == MAPI_E_NOT_FOUND) && |
| 490 | 498 | ($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND) && |
| 491 | - ($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) |
|
| 492 | - return SYNC_BODYPREFERENCE_PLAIN; |
|
| 493 | - elseif ( // 2 |
|
| 499 | + ($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) { |
|
| 500 | + return SYNC_BODYPREFERENCE_PLAIN; |
|
| 501 | + } elseif ( // 2 |
|
| 494 | 502 | ($messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) && |
| 495 | 503 | ($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND) && |
| 496 | - ($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) |
|
| 497 | - return SYNC_BODYPREFERENCE_PLAIN; |
|
| 498 | - elseif ( // 3 |
|
| 504 | + ($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) { |
|
| 505 | + return SYNC_BODYPREFERENCE_PLAIN; |
|
| 506 | + } elseif ( // 3 |
|
| 499 | 507 | ($messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) && |
| 500 | 508 | ($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) && |
| 501 | - ($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) |
|
| 502 | - return SYNC_BODYPREFERENCE_RTF; |
|
| 503 | - elseif ( // 4 |
|
| 509 | + ($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) { |
|
| 510 | + return SYNC_BODYPREFERENCE_RTF; |
|
| 511 | + } elseif ( // 4 |
|
| 504 | 512 | ($messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) && |
| 505 | 513 | ($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) && |
| 506 | 514 | ($messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) && |
| 507 | - ($messageprops[PR_RTF_IN_SYNC])) |
|
| 508 | - return SYNC_BODYPREFERENCE_RTF; |
|
| 509 | - elseif ( // 5 |
|
| 515 | + ($messageprops[PR_RTF_IN_SYNC])) { |
|
| 516 | + return SYNC_BODYPREFERENCE_RTF; |
|
| 517 | + } elseif ( // 5 |
|
| 510 | 518 | ($messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) && |
| 511 | 519 | ($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) && |
| 512 | 520 | ($messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) && |
| 513 | - (!$messageprops[PR_RTF_IN_SYNC])) |
|
| 514 | - return SYNC_BODYPREFERENCE_HTML; |
|
| 515 | - elseif ( // 6 |
|
| 521 | + (!$messageprops[PR_RTF_IN_SYNC])) { |
|
| 522 | + return SYNC_BODYPREFERENCE_HTML; |
|
| 523 | + } elseif ( // 6 |
|
| 516 | 524 | ($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) && |
| 517 | 525 | ($messageprops[PR_HTML] != MAPI_E_NOT_FOUND || $messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) && |
| 518 | - ($messageprops[PR_RTF_IN_SYNC])) |
|
| 519 | - return SYNC_BODYPREFERENCE_RTF; |
|
| 520 | - elseif ( // 7 |
|
| 526 | + ($messageprops[PR_RTF_IN_SYNC])) { |
|
| 527 | + return SYNC_BODYPREFERENCE_RTF; |
|
| 528 | + } elseif ( // 7 |
|
| 521 | 529 | ($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) && |
| 522 | 530 | ($messageprops[PR_HTML] != MAPI_E_NOT_FOUND || $messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) && |
| 523 | - (!$messageprops[PR_RTF_IN_SYNC])) |
|
| 524 | - return SYNC_BODYPREFERENCE_HTML; |
|
| 525 | - elseif ( // 8 |
|
| 531 | + (!$messageprops[PR_RTF_IN_SYNC])) { |
|
| 532 | + return SYNC_BODYPREFERENCE_HTML; |
|
| 533 | + } elseif ( // 8 |
|
| 526 | 534 | ($messageprops[PR_BODY] != MAPI_E_NOT_FOUND || $messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) && |
| 527 | 535 | ($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) && |
| 528 | - ($messageprops[PR_RTF_IN_SYNC])) |
|
| 529 | - return SYNC_BODYPREFERENCE_RTF; |
|
| 530 | - elseif ( // 9.1 |
|
| 536 | + ($messageprops[PR_RTF_IN_SYNC])) { |
|
| 537 | + return SYNC_BODYPREFERENCE_RTF; |
|
| 538 | + } elseif ( // 9.1 |
|
| 531 | 539 | ($messageprops[PR_BODY] != MAPI_E_NOT_FOUND || $messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) && |
| 532 | 540 | ($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) && |
| 533 | - (!$messageprops[PR_RTF_IN_SYNC])) |
|
| 534 | - return SYNC_BODYPREFERENCE_PLAIN; |
|
| 535 | - elseif ( // 9.2 |
|
| 541 | + (!$messageprops[PR_RTF_IN_SYNC])) { |
|
| 542 | + return SYNC_BODYPREFERENCE_PLAIN; |
|
| 543 | + } elseif ( // 9.2 |
|
| 536 | 544 | ($messageprops[PR_RTF_COMPRESSED] != MAPI_E_NOT_FOUND || $messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_ENOUGH_MEMORY) && |
| 537 | 545 | ($messageprops[PR_BODY] == MAPI_E_NOT_FOUND) && |
| 538 | - ($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) |
|
| 539 | - return SYNC_BODYPREFERENCE_RTF; |
|
| 540 | - elseif ( // 9.3 |
|
| 546 | + ($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) { |
|
| 547 | + return SYNC_BODYPREFERENCE_RTF; |
|
| 548 | + } elseif ( // 9.3 |
|
| 541 | 549 | ($messageprops[PR_BODY] != MAPI_E_NOT_FOUND || $messageprops[PR_BODY] == MAPI_E_NOT_ENOUGH_MEMORY) && |
| 542 | 550 | ($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND) && |
| 543 | - ($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) |
|
| 544 | - return SYNC_BODYPREFERENCE_PLAIN; |
|
| 545 | - elseif ( // 9.4 |
|
| 551 | + ($messageprops[PR_HTML] == MAPI_E_NOT_FOUND)) { |
|
| 552 | + return SYNC_BODYPREFERENCE_PLAIN; |
|
| 553 | + } elseif ( // 9.4 |
|
| 546 | 554 | ($messageprops[PR_HTML] != MAPI_E_NOT_FOUND || $messageprops[PR_HTML] == MAPI_E_NOT_ENOUGH_MEMORY) && |
| 547 | 555 | ($messageprops[PR_BODY] == MAPI_E_NOT_FOUND) && |
| 548 | - ($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND)) |
|
| 549 | - return SYNC_BODYPREFERENCE_HTML; |
|
| 550 | - else // 10 |
|
| 556 | + ($messageprops[PR_RTF_COMPRESSED] == MAPI_E_NOT_FOUND)) { |
|
| 557 | + return SYNC_BODYPREFERENCE_HTML; |
|
| 558 | + } else { |
|
| 559 | + // 10 |
|
| 551 | 560 | return SYNC_BODYPREFERENCE_PLAIN; |
| 561 | + } |
|
| 552 | 562 | } |
| 553 | 563 | |
| 554 | 564 | /** |
@@ -656,8 +666,7 @@ discard block |
||
| 656 | 666 | if ($eid1['length'] < $eid1['min_length'] || $eid1['id'] != $eid2['id']) { |
| 657 | 667 | return false; |
| 658 | 668 | } |
| 659 | - } |
|
| 660 | - elseif ($eid1['length'] < $eid1['min_length'] || $eid1['uniqueId'] != $eid2['uniqueId']) { |
|
| 669 | + } elseif ($eid1['length'] < $eid1['min_length'] || $eid1['uniqueId'] != $eid2['uniqueId']) { |
|
| 661 | 670 | return false; |
| 662 | 671 | } |
| 663 | 672 | |
@@ -795,8 +804,7 @@ discard block |
||
| 795 | 804 | if (substr($entryId, $len - ($offset + 2), $len - $offset) == '00') { |
| 796 | 805 | $padding .= '00'; |
| 797 | 806 | $offset += 2; |
| 798 | - } |
|
| 799 | - else { |
|
| 807 | + } else { |
|
| 800 | 808 | // if non-null character found then break the loop |
| 801 | 809 | break; |
| 802 | 810 | } |
@@ -89,8 +89,9 @@ discard block |
||
| 89 | 89 | $parentsourcekey = $props[PR_PARENT_SOURCE_KEY]; |
| 90 | 90 | $entryid = mapi_msgstore_entryidfromsourcekey($this->store, $parentsourcekey, $sourcekey); |
| 91 | 91 | |
| 92 | - if(!$entryid) |
|
| 93 | - return SYNC_E_IGNORE; |
|
| 92 | + if(!$entryid) { |
|
| 93 | + return SYNC_E_IGNORE; |
|
| 94 | + } |
|
| 94 | 95 | |
| 95 | 96 | $mapimessage = mapi_msgstore_openentry($this->store, $entryid); |
| 96 | 97 | try { |
@@ -103,19 +104,16 @@ discard block |
||
| 103 | 104 | if ($message->SupportsPrivateStripping()) { |
| 104 | 105 | ZLog::Write(LOGLEVEL_DEBUG, "PHPWrapper->ImportMessageChange(): stripping data of private message from a shared folder"); |
| 105 | 106 | $message->StripData(Streamer::STRIP_PRIVATE_DATA); |
| 106 | - } |
|
| 107 | - else { |
|
| 107 | + } else { |
|
| 108 | 108 | ZLog::Write(LOGLEVEL_DEBUG, "PHPWrapper->ImportMessageChange(): ignoring private message from a shared folder"); |
| 109 | 109 | return SYNC_E_IGNORE; |
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | - } |
|
| 113 | - catch (SyncObjectBrokenException $mbe) { |
|
| 112 | + } catch (SyncObjectBrokenException $mbe) { |
|
| 114 | 113 | $brokenSO = $mbe->GetSyncObject(); |
| 115 | 114 | if (!$brokenSO) { |
| 116 | 115 | ZLog::Write(LOGLEVEL_ERROR, sprintf("PHPWrapper->ImportMessageChange(): Caught SyncObjectBrokenException but broken SyncObject available")); |
| 117 | - } |
|
| 118 | - else { |
|
| 116 | + } else { |
|
| 119 | 117 | if (!isset($brokenSO->id)) { |
| 120 | 118 | $brokenSO->id = "Unknown ID"; |
| 121 | 119 | ZLog::Write(LOGLEVEL_ERROR, sprintf("PHPWrapper->ImportMessageChange(): Caught SyncObjectBrokenException but no ID of object set")); |
@@ -128,8 +126,11 @@ discard block |
||
| 128 | 126 | |
| 129 | 127 | |
| 130 | 128 | // substitute the MAPI SYNC_NEW_MESSAGE flag by a grommunio-sync proprietary flag |
| 131 | - if ($flags == SYNC_NEW_MESSAGE) $message->flags = SYNC_NEWMESSAGE; |
|
| 132 | - else $message->flags = $flags; |
|
| 129 | + if ($flags == SYNC_NEW_MESSAGE) { |
|
| 130 | + $message->flags = SYNC_NEWMESSAGE; |
|
| 131 | + } else { |
|
| 132 | + $message->flags = $flags; |
|
| 133 | + } |
|
| 133 | 134 | |
| 134 | 135 | $this->importer->ImportMessageChange($this->prefix.bin2hex($sourcekey), $message); |
| 135 | 136 | ZLog::Write(LOGLEVEL_DEBUG, sprintf("PHPWrapper->ImportMessageChange(): change for: '%s'", $this->prefix.bin2hex($sourcekey))); |
@@ -196,8 +197,9 @@ discard block |
||
| 196 | 197 | $folder = $this->mapiprovider->GetFolder($props); |
| 197 | 198 | |
| 198 | 199 | // do not import folder if there is something "wrong" with it |
| 199 | - if ($folder === false) |
|
| 200 | - return 0; |
|
| 200 | + if ($folder === false) { |
|
| 201 | + return 0; |
|
| 202 | + } |
|
| 201 | 203 | |
| 202 | 204 | $this->importer->ImportFolderChange($folder); |
| 203 | 205 | return 0; |
@@ -374,10 +374,10 @@ discard block |
||
| 374 | 374 | |
| 375 | 375 | |
| 376 | 376 | /** |
| 377 | - * Returns the MAPI to AS mapping for email todo flags |
|
| 378 | - * |
|
| 379 | - * @return array |
|
| 380 | - */ |
|
| 377 | + * Returns the MAPI to AS mapping for email todo flags |
|
| 378 | + * |
|
| 379 | + * @return array |
|
| 380 | + */ |
|
| 381 | 381 | public static function GetMailFlagsMapping() { |
| 382 | 382 | return array ( |
| 383 | 383 | "flagstatus" => PR_FLAG_STATUS, |
@@ -398,12 +398,12 @@ discard block |
||
| 398 | 398 | |
| 399 | 399 | |
| 400 | 400 | /** |
| 401 | - * Returns email todo flags' specific MAPI properties |
|
| 402 | - * |
|
| 403 | - * @access public |
|
| 404 | - * |
|
| 405 | - * @return array |
|
| 406 | - */ |
|
| 401 | + * Returns email todo flags' specific MAPI properties |
|
| 402 | + * |
|
| 403 | + * @access public |
|
| 404 | + * |
|
| 405 | + * @return array |
|
| 406 | + */ |
|
| 407 | 407 | public static function GetMailFlagsProperties() { |
| 408 | 408 | return array( |
| 409 | 409 | "todoitemsflags" => PR_TODO_ITEM_FLAGS, |
@@ -419,12 +419,12 @@ discard block |
||
| 419 | 419 | |
| 420 | 420 | |
| 421 | 421 | /** |
| 422 | - * Returns the MAPI to AS mapping for notes |
|
| 423 | - * |
|
| 424 | - * @access public |
|
| 425 | - * |
|
| 426 | - * @return array |
|
| 427 | - */ |
|
| 422 | + * Returns the MAPI to AS mapping for notes |
|
| 423 | + * |
|
| 424 | + * @access public |
|
| 425 | + * |
|
| 426 | + * @return array |
|
| 427 | + */ |
|
| 428 | 428 | public static function GetNoteMapping() { |
| 429 | 429 | return array( |
| 430 | 430 | "categories" => "PT_MV_STRING8:PS_PUBLIC_STRINGS:Keywords", |
@@ -438,12 +438,12 @@ discard block |
||
| 438 | 438 | |
| 439 | 439 | |
| 440 | 440 | /** |
| 441 | - * Returns note specific MAPI properties |
|
| 442 | - * |
|
| 443 | - * @access public |
|
| 444 | - * |
|
| 445 | - * @return array |
|
| 446 | - */ |
|
| 441 | + * Returns note specific MAPI properties |
|
| 442 | + * |
|
| 443 | + * @access public |
|
| 444 | + * |
|
| 445 | + * @return array |
|
| 446 | + */ |
|
| 447 | 447 | public static function GetNoteProperties() { |
| 448 | 448 | return array( |
| 449 | 449 | "body" => PR_BODY, |
@@ -456,12 +456,12 @@ discard block |
||
| 456 | 456 | |
| 457 | 457 | |
| 458 | 458 | /** |
| 459 | - * Returns properties for sending an email |
|
| 460 | - * |
|
| 461 | - * @access public |
|
| 462 | - * |
|
| 463 | - * @return array |
|
| 464 | - */ |
|
| 459 | + * Returns properties for sending an email |
|
| 460 | + * |
|
| 461 | + * @access public |
|
| 462 | + * |
|
| 463 | + * @return array |
|
| 464 | + */ |
|
| 465 | 465 | public static function GetSendMailProperties() { |
| 466 | 466 | return array( |
| 467 | 467 | "outboxentryid" => PR_IPM_OUTBOX_ENTRYID, |