Passed
Branch master (ff9d34)
by Mike
09:14
created
version.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,8 +11,7 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
lib/log/filelog.php 1 patch
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -30,8 +30,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
lib/log/log.php 1 patch
Braces   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -259,8 +259,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
lib/log/syslog.php 1 patch
Braces   +10 added lines, -5 removed lines patch added patch discarded remove patch
@@ -79,9 +79,15 @@  discard block
 block discarded – undo
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
 block discarded – undo
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) {
Please login to merge, or discard this patch.
lib/grommunio/exporter.php 1 patch
Braces   +46 added lines, -40 removed lines patch added patch discarded remove patch
@@ -47,13 +47,11 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     /**
Please login to merge, or discard this patch.
lib/grommunio/grommunio.php 1 patch
Braces   +199 added lines, -189 removed lines patch added patch discarded remove patch
@@ -134,8 +134,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
lib/grommunio/mapiutils.php 1 patch
Braces   +56 added lines, -48 removed lines patch added patch discarded remove patch
@@ -377,8 +377,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
             }
Please login to merge, or discard this patch.
lib/grommunio/mapiphpwrapper.php 1 patch
Braces   +14 added lines, -12 removed lines patch added patch discarded remove patch
@@ -89,8 +89,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
lib/grommunio/mapiprovider.php 1 patch
Braces   +494 added lines, -365 removed lines patch added patch discarded remove patch
@@ -48,21 +48,23 @@  discard block
 block discarded – undo
48 48
         // Gets the Sync object from a MAPI object according to its message class
49 49
 
50 50
         $props = mapi_getprops($mapimessage, array(PR_MESSAGE_CLASS));
51
-        if(isset($props[PR_MESSAGE_CLASS]))
52
-            $messageclass = $props[PR_MESSAGE_CLASS];
53
-        else
54
-            $messageclass = "IPM";
55
-
56
-        if(strpos($messageclass,"IPM.Contact") === 0)
57
-            return $this->getContact($mapimessage, $contentparameters);
58
-        else if(strpos($messageclass,"IPM.Appointment") === 0)
59
-            return $this->getAppointment($mapimessage, $contentparameters);
60
-        else if(strpos($messageclass,"IPM.Task") === 0 && strpos($messageclass, "IPM.TaskRequest") === false)
61
-            return $this->getTask($mapimessage, $contentparameters);
62
-        else if(strpos($messageclass,"IPM.StickyNote") === 0)
63
-            return $this->getNote($mapimessage, $contentparameters);
64
-        else
65
-            return $this->getEmail($mapimessage, $contentparameters);
51
+        if(isset($props[PR_MESSAGE_CLASS])) {
52
+                    $messageclass = $props[PR_MESSAGE_CLASS];
53
+        } else {
54
+                    $messageclass = "IPM";
55
+        }
56
+
57
+        if(strpos($messageclass,"IPM.Contact") === 0) {
58
+                    return $this->getContact($mapimessage, $contentparameters);
59
+        } else if(strpos($messageclass,"IPM.Appointment") === 0) {
60
+                    return $this->getAppointment($mapimessage, $contentparameters);
61
+        } else if(strpos($messageclass,"IPM.Task") === 0 && strpos($messageclass, "IPM.TaskRequest") === false) {
62
+                    return $this->getTask($mapimessage, $contentparameters);
63
+        } else if(strpos($messageclass,"IPM.StickyNote") === 0) {
64
+                    return $this->getNote($mapimessage, $contentparameters);
65
+        } else {
66
+                    return $this->getEmail($mapimessage, $contentparameters);
67
+        }
66 68
     }
67 69
 
68 70
     /**
@@ -140,12 +142,14 @@  discard block
 block discarded – undo
140 142
         }
141 143
 
142 144
         // when set the task to complete using the WebAccess, the dateComplete property is not set correctly
143
-        if ($message->complete == 1 && !isset($message->datecompleted))
144
-            $message->datecompleted = time();
145
+        if ($message->complete == 1 && !isset($message->datecompleted)) {
146
+                    $message->datecompleted = time();
147
+        }
145 148
 
146 149
         // if no reminder is set, announce that to the mobile
147
-        if (!isset($message->reminderset))
148
-            $message->reminderset = 0;
150
+        if (!isset($message->reminderset)) {
151
+                    $message->reminderset = 0;
152
+        }
149 153
 
150 154
         return $message;
151 155
     }
@@ -174,16 +178,18 @@  discard block
 block discarded – undo
174 178
 
175 179
         // Set reminder time if reminderset is true
176 180
         if(isset($messageprops[$appointmentprops["reminderset"]]) && $messageprops[$appointmentprops["reminderset"]] == true) {
177
-            if ($messageprops[$appointmentprops["remindertime"]] == 0x5AE980E1)
178
-                $message->reminder = 15;
179
-            else
180
-                $message->reminder = $messageprops[$appointmentprops["remindertime"]];
181
+            if ($messageprops[$appointmentprops["remindertime"]] == 0x5AE980E1) {
182
+                            $message->reminder = 15;
183
+            } else {
184
+                            $message->reminder = $messageprops[$appointmentprops["remindertime"]];
185
+            }
181 186
         }
182 187
 
183
-        if(!isset($message->uid))
184
-            $message->uid = bin2hex($messageprops[$appointmentprops["sourcekey"]]);
185
-        else
186
-            $message->uid = Utils::GetICalUidFromOLUid($message->uid);
188
+        if(!isset($message->uid)) {
189
+                    $message->uid = bin2hex($messageprops[$appointmentprops["sourcekey"]]);
190
+        } else {
191
+                    $message->uid = Utils::GetICalUidFromOLUid($message->uid);
192
+        }
187 193
 
188 194
         // Always set organizer information because some devices do not work properly without it
189 195
         if( isset($messageprops[$appointmentprops["representingentryid"]]) &&
@@ -201,14 +207,12 @@  discard block
 block discarded – undo
201 207
         if (!empty($messageprops[$appointmentprops["timezonetag"]])) {
202 208
             $tz = $this->getTZFromMAPIBlob($messageprops[$appointmentprops["timezonetag"]]);
203 209
             $appTz = true;
204
-        }
205
-        elseif (!empty($messageprops[$appointmentprops["timezonedesc"]])) {
210
+        } elseif (!empty($messageprops[$appointmentprops["timezonedesc"]])) {
206 211
             // Windows uses UTC in timezone description in opposite to mstzones in TimezoneUtil which uses GMT
207 212
             $wintz = str_replace("UTC", "GMT", $messageprops[$appointmentprops["timezonedesc"]]);
208 213
             $tz = TimezoneUtil::GetFullTZFromTZName(TimezoneUtil::GetTZNameFromWinTZ($wintz));
209 214
             $appTz = true;
210
-        }
211
-        else {
215
+        } else {
212 216
             // set server default timezone (correct timezone should be configured!)
213 217
             $tz = TimezoneUtil::GetFullTZ();
214 218
         }
@@ -236,20 +240,22 @@  discard block
 block discarded – undo
236 240
             throw $mbe;
237 241
         }
238 242
 
239
-        if(count($rows) > 0)
240
-            $message->attendees = array();
243
+        if(count($rows) > 0) {
244
+                    $message->attendees = array();
245
+        }
241 246
 
242 247
         foreach($rows as $row) {
243 248
             $attendee = new SyncAttendee();
244 249
 
245 250
             $attendee->name = w2u($row[PR_DISPLAY_NAME]);
246 251
             //smtp address is always a proper email address
247
-            if(isset($row[PR_SMTP_ADDRESS]))
248
-                $attendee->email = w2u($row[PR_SMTP_ADDRESS]);
249
-            elseif (isset($row[PR_ADDRTYPE]) && isset($row[PR_EMAIL_ADDRESS])) {
252
+            if(isset($row[PR_SMTP_ADDRESS])) {
253
+                            $attendee->email = w2u($row[PR_SMTP_ADDRESS]);
254
+            } elseif (isset($row[PR_ADDRTYPE]) && isset($row[PR_EMAIL_ADDRESS])) {
250 255
                 //if address type is SMTP, it's also a proper email address
251
-                if ($row[PR_ADDRTYPE] == "SMTP")
252
-                    $attendee->email = w2u($row[PR_EMAIL_ADDRESS]);
256
+                if ($row[PR_ADDRTYPE] == "SMTP") {
257
+                                    $attendee->email = w2u($row[PR_EMAIL_ADDRESS]);
258
+                }
253 259
                 //if address type is ZARAFA, the PR_EMAIL_ADDRESS contains username
254 260
                 elseif ($row[PR_ADDRTYPE] == "ZARAFA") {
255 261
                     $userinfo = @nsp_getuserinfo($row[PR_EMAIL_ADDRESS]);
@@ -260,8 +266,7 @@  discard block
 block discarded – undo
260 266
                     // @see https://jira.z-hub.io/browse/ZP-1178
261 267
                     elseif (isset($row[PR_SEARCH_KEY])) {
262 268
                         $attendee->email = w2u($this->getEmailAddressFromSearchKey($row[PR_SEARCH_KEY]));
263
-                    }
264
-                    else {
269
+                    } else {
265 270
                         ZLog::Write(LOGLEVEL_WARN, sprintf("MAPIProvider->getAppointment: The attendee '%s' of type ZARAFA can not be resolved. Code: 0x%X", $row[PR_EMAIL_ADDRESS], mapi_last_hresult()));
266 271
                     }
267 272
                 }
@@ -281,14 +286,16 @@  discard block
 block discarded – undo
281 286
             // don't send one of those fields, the phone will give an error ... so
282 287
             // we don't send it in that case.
283 288
             // also ignore the "attendee" if the email is equal to the organizers' email
284
-            if(isset($attendee->name) && isset($attendee->email) && $attendee->email != "" && (!isset($message->organizeremail) || (isset($message->organizeremail) && $attendee->email != $message->organizeremail)))
285
-                array_push($message->attendees, $attendee);
289
+            if(isset($attendee->name) && isset($attendee->email) && $attendee->email != "" && (!isset($message->organizeremail) || (isset($message->organizeremail) && $attendee->email != $message->organizeremail))) {
290
+                            array_push($message->attendees, $attendee);
291
+            }
286 292
         }
287 293
 
288 294
         // Status 0 = no meeting, status 1 = organizer, status 2/3/4/5 = tentative/accepted/declined/notresponded
289 295
         if(isset($messageprops[$appointmentprops["meetingstatus"]]) && $messageprops[$appointmentprops["meetingstatus"]] > 1) {
290
-            if (!isset($message->attendees) || !is_array($message->attendees))
291
-                $message->attendees = array();
296
+            if (!isset($message->attendees) || !is_array($message->attendees)) {
297
+                            $message->attendees = array();
298
+            }
292 299
             // Work around iOS6 cancellation issue when there are no attendees for this meeting. Just add ourselves as the sole attendee.
293 300
             if(count($message->attendees) == 0) {
294 301
 
@@ -324,8 +331,7 @@  discard block
 block discarded – undo
324 331
 
325 332
         if (!isset($message->nativebodytype)) {
326 333
             $message->nativebodytype = MAPIUtils::GetNativeBodyType($messageprops);
327
-        }
328
-        elseif ($message->nativebodytype == SYNC_BODYPREFERENCE_UNDEFINED) {
334
+        } elseif ($message->nativebodytype == SYNC_BODYPREFERENCE_UNDEFINED) {
329 335
             $nbt = MAPIUtils::GetNativeBodyType($messageprops);
330 336
             ZLog::Write(LOGLEVEL_INFO, sprintf("MAPIProvider->getAppointment(): native body type is undefined. Set it to %d.", $nbt));
331 337
             $message->nativebodytype = $nbt;
@@ -373,10 +379,11 @@  discard block
 block discarded – undo
373 379
      * @return
374 380
      */
375 381
     private function getRecurrence($mapimessage, $recurprops, &$syncMessage, &$syncRecurrence, $tz) {
376
-        if ($syncRecurrence instanceof SyncTaskRecurrence)
377
-            $recurrence = new TaskRecurrence($this->store, $mapimessage);
378
-        else
379
-            $recurrence = new Recurrence($this->store, $mapimessage);
382
+        if ($syncRecurrence instanceof SyncTaskRecurrence) {
383
+                    $recurrence = new TaskRecurrence($this->store, $mapimessage);
384
+        } else {
385
+                    $recurrence = new Recurrence($this->store, $mapimessage);
386
+        }
380 387
 
381 388
         switch($recurrence->recur["type"]) {
382 389
             case 10: // daily
@@ -421,8 +428,9 @@  discard block
 block discarded – undo
421 428
             case 0x21:
422 429
                 $syncRecurrence->until = $recurrence->recur["end"];
423 430
                 // fixes Mantis #350 : recur-end does not consider timezones - use ClipEnd if available
424
-                if (isset($recurprops[$recurrence->proptags["enddate_recurring"]]))
425
-                    $syncRecurrence->until = $recurprops[$recurrence->proptags["enddate_recurring"]];
431
+                if (isset($recurprops[$recurrence->proptags["enddate_recurring"]])) {
432
+                                    $syncRecurrence->until = $recurprops[$recurrence->proptags["enddate_recurring"]];
433
+                }
426 434
                 // add one day (minus 1 sec) to the end time to make sure the last occurrence is covered
427 435
                 $syncRecurrence->until += 86399;
428 436
                 break;
@@ -434,14 +442,17 @@  discard block
 block discarded – undo
434 442
         }
435 443
 
436 444
         // Correct 'alldayevent' because outlook fails to set it on recurring items of 24 hours or longer
437
-        if(isset($recurrence->recur["endocc"], $recurrence->recur["startocc"]) && ($recurrence->recur["endocc"] - $recurrence->recur["startocc"] >= 1440))
438
-            $syncMessage->alldayevent = true;
445
+        if(isset($recurrence->recur["endocc"], $recurrence->recur["startocc"]) && ($recurrence->recur["endocc"] - $recurrence->recur["startocc"] >= 1440)) {
446
+                    $syncMessage->alldayevent = true;
447
+        }
439 448
 
440 449
         // Interval is different according to the type/subtype
441 450
         switch($recurrence->recur["type"]) {
442 451
             case 10:
443
-                if($recurrence->recur["subtype"] == 0)
444
-                    $syncRecurrence->interval = (int)($recurrence->recur["everyn"] / 1440);  // minutes
452
+                if($recurrence->recur["subtype"] == 0) {
453
+                                    $syncRecurrence->interval = (int)($recurrence->recur["everyn"] / 1440);
454
+                }
455
+                // minutes
445 456
                 break;
446 457
             case 11:
447 458
             case 12:
@@ -452,24 +463,34 @@  discard block
 block discarded – undo
452 463
                 break; // months
453 464
         }
454 465
 
455
-        if(isset($recurrence->recur["weekdays"]))
456
-            $syncRecurrence->dayofweek = $recurrence->recur["weekdays"]; // bitmask of days (1 == sunday, 128 == saturday
457
-        if(isset($recurrence->recur["nday"]))
458
-            $syncRecurrence->weekofmonth = $recurrence->recur["nday"]; // N'th {DAY} of {X} (0-5)
459
-        if(isset($recurrence->recur["month"]))
460
-            $syncRecurrence->monthofyear = (int)($recurrence->recur["month"] / (60 * 24 * 29)) + 1; // works ok due to rounding. see also $monthminutes below (1-12)
461
-        if(isset($recurrence->recur["monthday"]))
462
-            $syncRecurrence->dayofmonth = $recurrence->recur["monthday"]; // day of month (1-31)
466
+        if(isset($recurrence->recur["weekdays"])) {
467
+                    $syncRecurrence->dayofweek = $recurrence->recur["weekdays"];
468
+        }
469
+        // bitmask of days (1 == sunday, 128 == saturday
470
+        if(isset($recurrence->recur["nday"])) {
471
+                    $syncRecurrence->weekofmonth = $recurrence->recur["nday"];
472
+        }
473
+        // N'th {DAY} of {X} (0-5)
474
+        if(isset($recurrence->recur["month"])) {
475
+                    $syncRecurrence->monthofyear = (int)($recurrence->recur["month"] / (60 * 24 * 29)) + 1;
476
+        }
477
+        // works ok due to rounding. see also $monthminutes below (1-12)
478
+        if(isset($recurrence->recur["monthday"])) {
479
+                    $syncRecurrence->dayofmonth = $recurrence->recur["monthday"];
480
+        }
481
+        // day of month (1-31)
463 482
 
464 483
         // All changed exceptions are appointments within the 'exceptions' array. They contain the same items as a normal appointment
465 484
         foreach($recurrence->recur["changed_occurences"] as $change) {
466 485
             $exception = new SyncAppointmentException();
467 486
 
468 487
             // start, end, basedate, subject, remind_before, reminderset, location, busystatus, alldayevent, label
469
-            if(isset($change["start"]))
470
-                $exception->starttime = $this->getGMTTimeByTZ($change["start"], $tz);
471
-            if(isset($change["end"]))
472
-                $exception->endtime = $this->getGMTTimeByTZ($change["end"], $tz);
488
+            if(isset($change["start"])) {
489
+                            $exception->starttime = $this->getGMTTimeByTZ($change["start"], $tz);
490
+            }
491
+            if(isset($change["end"])) {
492
+                            $exception->endtime = $this->getGMTTimeByTZ($change["end"], $tz);
493
+            }
473 494
             if(isset($change["basedate"])) {
474 495
                 $exception->exceptionstarttime = $this->getGMTTimeByTZ($this->getDayStartOfTimestamp($change["basedate"]) + $recurrence->recur["startocc"] * 60, $tz);
475 496
 
@@ -480,27 +501,36 @@  discard block
 block discarded – undo
480 501
                     $this->setMessageBodyForType($exceptionobj, SYNC_BODYPREFERENCE_PLAIN, $exception);
481 502
                 }
482 503
             }
483
-            if(isset($change["subject"]))
484
-                $exception->subject = w2u($change["subject"]);
485
-            if(isset($change["reminder_before"]) && $change["reminder_before"])
486
-                $exception->reminder = $change["remind_before"];
487
-            if(isset($change["location"]))
488
-                $exception->location = w2u($change["location"]);
489
-            if(isset($change["busystatus"]))
490
-                $exception->busystatus = $change["busystatus"];
491
-            if(isset($change["alldayevent"]))
492
-                $exception->alldayevent = $change["alldayevent"];
504
+            if(isset($change["subject"])) {
505
+                            $exception->subject = w2u($change["subject"]);
506
+            }
507
+            if(isset($change["reminder_before"]) && $change["reminder_before"]) {
508
+                            $exception->reminder = $change["remind_before"];
509
+            }
510
+            if(isset($change["location"])) {
511
+                            $exception->location = w2u($change["location"]);
512
+            }
513
+            if(isset($change["busystatus"])) {
514
+                            $exception->busystatus = $change["busystatus"];
515
+            }
516
+            if(isset($change["alldayevent"])) {
517
+                            $exception->alldayevent = $change["alldayevent"];
518
+            }
493 519
 
494 520
             // set some data from the original appointment
495
-            if (isset($syncMessage->uid))
496
-                $exception->uid = $syncMessage->uid;
497
-            if (isset($syncMessage->organizername))
498
-                $exception->organizername = $syncMessage->organizername;
499
-            if (isset($syncMessage->organizeremail))
500
-                $exception->organizeremail = $syncMessage->organizeremail;
521
+            if (isset($syncMessage->uid)) {
522
+                            $exception->uid = $syncMessage->uid;
523
+            }
524
+            if (isset($syncMessage->organizername)) {
525
+                            $exception->organizername = $syncMessage->organizername;
526
+            }
527
+            if (isset($syncMessage->organizeremail)) {
528
+                            $exception->organizeremail = $syncMessage->organizeremail;
529
+            }
501 530
 
502
-            if(!isset($syncMessage->exceptions))
503
-                $syncMessage->exceptions = array();
531
+            if(!isset($syncMessage->exceptions)) {
532
+                            $syncMessage->exceptions = array();
533
+            }
504 534
 
505 535
             // If the user is working from a location other than the office the busystatus should be interpreted as free.
506 536
             if (isset($exception->busystatus) && $exception->busystatus == fbWorkingElsewhere) {
@@ -528,8 +558,9 @@  discard block
 block discarded – undo
528 558
             $exception->exceptionstarttime = $this->getGMTTimeByTZ($this->getDayStartOfTimestamp($deleted) + $recurrence->recur["startocc"] * 60, $tz);
529 559
             $exception->deleted = "1";
530 560
 
531
-            if(!isset($syncMessage->exceptions))
532
-                $syncMessage->exceptions = array();
561
+            if(!isset($syncMessage->exceptions)) {
562
+                            $syncMessage->exceptions = array();
563
+            }
533 564
 
534 565
             array_push($syncMessage->exceptions, $exception);
535 566
         }
@@ -565,9 +596,9 @@  discard block
 block discarded – undo
565 596
         $emailproperties = MAPIMapping::GetEmailProperties();
566 597
         $messageprops = $this->getProps($mapimessage, $emailproperties);
567 598
 
568
-        if(isset($messageprops[PR_SOURCE_KEY]))
569
-            $sourcekey = $messageprops[PR_SOURCE_KEY];
570
-        else {
599
+        if(isset($messageprops[PR_SOURCE_KEY])) {
600
+                    $sourcekey = $messageprops[PR_SOURCE_KEY];
601
+        } else {
571 602
             $mbe = new SyncObjectBrokenException("The message doesn't have a sourcekey");
572 603
             $mbe->SetSyncObject($message);
573 604
             throw $mbe;
@@ -582,22 +613,25 @@  discard block
 block discarded – undo
582 613
             // remove encapsulating double quotes from the representingname
583 614
             $fromname = preg_replace('/^\"(.*)\"$/',"\${1}", $messageprops[$emailproperties["representingname"]]);
584 615
         }
585
-        if(isset($messageprops[$emailproperties["representingentryid"]]))
586
-            $fromaddr = $this->getSMTPAddressFromEntryID($messageprops[$emailproperties["representingentryid"]]);
616
+        if(isset($messageprops[$emailproperties["representingentryid"]])) {
617
+                    $fromaddr = $this->getSMTPAddressFromEntryID($messageprops[$emailproperties["representingentryid"]]);
618
+        }
587 619
 
588 620
         // if the email address can't be resolved, fall back to PR_SENT_REPRESENTING_SEARCH_KEY
589 621
         if ($fromaddr == "" && isset($messageprops[$emailproperties["representingsearchkey"]])) {
590 622
             $fromaddr = $this->getEmailAddressFromSearchKey($messageprops[$emailproperties["representingsearchkey"]]);
591 623
         }
592 624
 
593
-        if($fromname == $fromaddr)
594
-            $fromname = "";
625
+        if($fromname == $fromaddr) {
626
+                    $fromname = "";
627
+        }
595 628
 
596
-        if($fromname)
597
-            $from = "\"" . w2u($fromname) . "\" <" . w2u($fromaddr) . ">";
598
-        else
599
-            //START CHANGED dw2412 HTC shows "error" if sender name is unknown
629
+        if($fromname) {
630
+                    $from = "\"" . w2u($fromname) . "\" <" . w2u($fromaddr) . ">";
631
+        } else {
632
+                    //START CHANGED dw2412 HTC shows "error" if sender name is unknown
600 633
             $from = "\"" . w2u($fromaddr) . "\" <" . w2u($fromaddr) . ">";
634
+        }
601 635
             //END CHANGED dw2412 HTC shows "error" if sender name is unknown
602 636
 
603 637
         $message->from = $from;
@@ -611,14 +645,14 @@  discard block
 block discarded – undo
611 645
             $props = $this->getProps($mapimessage, $meetingrequestproperties);
612 646
 
613 647
             // Get the GOID
614
-            if(isset($props[$meetingrequestproperties["goidtag"]]))
615
-                $message->meetingrequest->globalobjid = base64_encode($props[$meetingrequestproperties["goidtag"]]);
648
+            if(isset($props[$meetingrequestproperties["goidtag"]])) {
649
+                            $message->meetingrequest->globalobjid = base64_encode($props[$meetingrequestproperties["goidtag"]]);
650
+            }
616 651
 
617 652
             // Set Timezone
618 653
             if (isset($props[$meetingrequestproperties["timezonetag"]])) {
619 654
                 $tz = $this->getTZFromMAPIBlob($props[$meetingrequestproperties["timezonetag"]]);
620
-            }
621
-            else {
655
+            } else {
622 656
                 $tz = TimezoneUtil::GetFullTZ();
623 657
             }
624 658
 
@@ -630,11 +664,10 @@  discard block
 block discarded – undo
630 664
                 if (isset($props[$meetingrequestproperties["recReplTime"]])){
631 665
                     $basedate = $props[$meetingrequestproperties["recReplTime"]];
632 666
                     $message->meetingrequest->recurrenceid = $this->getGMTTimeByTZ($basedate, $this->getGMTTZ());
633
-                }
634
-                else {
635
-                    if (!isset($props[$meetingrequestproperties["goidtag"]]) || !isset($props[$meetingrequestproperties["recurStartTime"]]) || !isset($props[$meetingrequestproperties["timezonetag"]]))
636
-                        ZLog::Write(LOGLEVEL_WARN, "Missing property to set correct basedate for exception");
637
-                    else {
667
+                } else {
668
+                    if (!isset($props[$meetingrequestproperties["goidtag"]]) || !isset($props[$meetingrequestproperties["recurStartTime"]]) || !isset($props[$meetingrequestproperties["timezonetag"]])) {
669
+                                            ZLog::Write(LOGLEVEL_WARN, "Missing property to set correct basedate for exception");
670
+                    } else {
638 671
                         $basedate = Utils::ExtractBaseDate($props[$meetingrequestproperties["goidtag"]], $props[$meetingrequestproperties["recurStartTime"]]);
639 672
                         $message->meetingrequest->recurrenceid = $this->getGMTTimeByTZ($basedate, $tz);
640 673
                     }
@@ -644,8 +677,7 @@  discard block
 block discarded – undo
644 677
             // Organizer is the sender
645 678
             if (strpos($message->messageclass, "IPM.Schedule.Meeting.Resp") === 0) {
646 679
                 $message->meetingrequest->organizer = $message->to;
647
-            }
648
-            else {
680
+            } else {
649 681
                 $message->meetingrequest->organizer = $message->from;
650 682
             }
651 683
 
@@ -658,8 +690,9 @@  discard block
 block discarded – undo
658 690
             }
659 691
 
660 692
             // Force the 'alldayevent' in the object at all times. (non-existent == 0)
661
-            if(!isset($message->meetingrequest->alldayevent) || $message->meetingrequest->alldayevent == "")
662
-                $message->meetingrequest->alldayevent = 0;
693
+            if(!isset($message->meetingrequest->alldayevent) || $message->meetingrequest->alldayevent == "") {
694
+                            $message->meetingrequest->alldayevent = 0;
695
+            }
663 696
 
664 697
             // Instancetype
665 698
             // 0 = single appointment
@@ -667,29 +700,33 @@  discard block
 block discarded – undo
667 700
             // 2 = single instance of recurring appointment
668 701
             // 3 = exception of recurring appointment
669 702
             $message->meetingrequest->instancetype = 0;
670
-            if (isset($props[$meetingrequestproperties["isrecurringtag"]]) && $props[$meetingrequestproperties["isrecurringtag"]] == 1)
671
-                $message->meetingrequest->instancetype = 1;
672
-            else if ((!isset($props[$meetingrequestproperties["isrecurringtag"]]) || $props[$meetingrequestproperties["isrecurringtag"]] == 0 )&& isset($message->meetingrequest->recurrenceid))
673
-                if (isset($props[$meetingrequestproperties["appSeqNr"]]) && $props[$meetingrequestproperties["appSeqNr"]] == 0 )
703
+            if (isset($props[$meetingrequestproperties["isrecurringtag"]]) && $props[$meetingrequestproperties["isrecurringtag"]] == 1) {
704
+                            $message->meetingrequest->instancetype = 1;
705
+            } else if ((!isset($props[$meetingrequestproperties["isrecurringtag"]]) || $props[$meetingrequestproperties["isrecurringtag"]] == 0 )&& isset($message->meetingrequest->recurrenceid)) {
706
+                            if (isset($props[$meetingrequestproperties["appSeqNr"]]) && $props[$meetingrequestproperties["appSeqNr"]] == 0 )
674 707
                     $message->meetingrequest->instancetype = 2;
675
-                else
676
-                    $message->meetingrequest->instancetype = 3;
708
+            } else {
709
+                                    $message->meetingrequest->instancetype = 3;
710
+                }
677 711
 
678 712
             // Disable reminder if it is off
679
-            if(!isset($props[$meetingrequestproperties["reminderset"]]) || $props[$meetingrequestproperties["reminderset"]] == false)
680
-                $message->meetingrequest->reminder = "";
713
+            if(!isset($props[$meetingrequestproperties["reminderset"]]) || $props[$meetingrequestproperties["reminderset"]] == false) {
714
+                            $message->meetingrequest->reminder = "";
715
+            }
681 716
             //the property saves reminder in minutes, but we need it in secs
682 717
             else {
683 718
                 ///set the default reminder time to seconds
684
-                if ($props[$meetingrequestproperties["remindertime"]] == 0x5AE980E1)
685
-                    $message->meetingrequest->reminder = 900;
686
-                else
687
-                    $message->meetingrequest->reminder = $props[$meetingrequestproperties["remindertime"]] * 60;
719
+                if ($props[$meetingrequestproperties["remindertime"]] == 0x5AE980E1) {
720
+                                    $message->meetingrequest->reminder = 900;
721
+                } else {
722
+                                    $message->meetingrequest->reminder = $props[$meetingrequestproperties["remindertime"]] * 60;
723
+                }
688 724
             }
689 725
 
690 726
             // Set sensitivity to 0 if missing
691
-            if(!isset($message->meetingrequest->sensitivity))
692
-                $message->meetingrequest->sensitivity = 0;
727
+            if(!isset($message->meetingrequest->sensitivity)) {
728
+                            $message->meetingrequest->sensitivity = 0;
729
+            }
693 730
 
694 731
             // If the user is working from a location other than the office the busystatus should be interpreted as free.
695 732
             if (isset($message->meetingrequest->busystatus) && $message->meetingrequest->busystatus == fbWorkingElsewhere) {
@@ -761,8 +798,7 @@  discard block
 block discarded – undo
761 798
             if(isset($row[PR_ATTACH_NUM])) {
762 799
                 if (Request::GetProtocolVersion() >= 12.0) {
763 800
                     $attach = new SyncBaseAttachment();
764
-                }
765
-                else {
801
+                } else {
766 802
                     $attach = new SyncAttachment();
767 803
                 }
768 804
 
@@ -793,8 +829,9 @@  discard block
 block discarded – undo
793 829
 
794 830
                     // if displayname does not have the eml extension for embedde messages, android and WP devices won't open it
795 831
                     if ($attach->method == ATTACH_EMBEDDED_MSG) {
796
-                        if (strtolower(substr($attach->displayname, -4)) != '.eml')
797
-                            $attach->displayname .= '.eml';
832
+                        if (strtolower(substr($attach->displayname, -4)) != '.eml') {
833
+                                                    $attach->displayname .= '.eml';
834
+                        }
798 835
                     }
799 836
                     // android devices require attachment size in order to display an attachment properly
800 837
                     if (!isset($attachprops[PR_ATTACH_SIZE])) {
@@ -807,33 +844,37 @@  discard block
 block discarded – undo
807 844
                         }
808 845
                         $stat = mapi_stream_stat($stream);
809 846
                         $attach->estimatedDataSize = $stat['cb'];
810
-                    }
811
-                    else {
847
+                    } else {
812 848
                         $attach->estimatedDataSize = $attachprops[PR_ATTACH_SIZE];
813 849
                     }
814 850
 
815
-                    if (isset($attachprops[PR_ATTACH_CONTENT_ID]) && $attachprops[PR_ATTACH_CONTENT_ID])
816
-                        $attach->contentid = $attachprops[PR_ATTACH_CONTENT_ID];
851
+                    if (isset($attachprops[PR_ATTACH_CONTENT_ID]) && $attachprops[PR_ATTACH_CONTENT_ID]) {
852
+                                            $attach->contentid = $attachprops[PR_ATTACH_CONTENT_ID];
853
+                    }
817 854
 
818
-                    if (!isset($attach->contentid) && isset($attachprops[PR_ATTACH_CONTENT_ID_W]) && $attachprops[PR_ATTACH_CONTENT_ID_W])
819
-                        $attach->contentid = $attachprops[PR_ATTACH_CONTENT_ID_W];
855
+                    if (!isset($attach->contentid) && isset($attachprops[PR_ATTACH_CONTENT_ID_W]) && $attachprops[PR_ATTACH_CONTENT_ID_W]) {
856
+                                            $attach->contentid = $attachprops[PR_ATTACH_CONTENT_ID_W];
857
+                    }
820 858
 
821
-                    if (isset($attachprops[PR_ATTACHMENT_HIDDEN]) && $attachprops[PR_ATTACHMENT_HIDDEN]) $attach->isinline = 1;
859
+                    if (isset($attachprops[PR_ATTACHMENT_HIDDEN]) && $attachprops[PR_ATTACHMENT_HIDDEN]) {
860
+                        $attach->isinline = 1;
861
+                    }
822 862
 
823 863
                     if (isset($attach->contentid, $attachprops[PR_ATTACH_FLAGS]) && $attachprops[PR_ATTACH_FLAGS] & 4) {
824 864
                         $attach->isinline = 1;
825 865
                     }
826 866
 
827
-                    if(!isset($message->asattachments))
828
-                        $message->asattachments = array();
867
+                    if(!isset($message->asattachments)) {
868
+                                            $message->asattachments = array();
869
+                    }
829 870
 
830 871
                     array_push($message->asattachments, $attach);
831
-                }
832
-                else {
872
+                } else {
833 873
                     $attach->attsize = $attachprops[PR_ATTACH_SIZE];
834 874
                     $attach->attname = sprintf("%s:%s:%s", $entryid, $row[PR_ATTACH_NUM], $parentSourcekey);
835
-                    if(!isset($message->attachments))
836
-                        $message->attachments = array();
875
+                    if(!isset($message->attachments)) {
876
+                                            $message->attachments = array();
877
+                    }
837 878
 
838 879
                     array_push($message->attachments, $attach);
839 880
                 }
@@ -854,12 +895,13 @@  discard block
 block discarded – undo
854 895
 
855 896
             $addrtype = isset($row[PR_ADDRTYPE]) ? $row[PR_ADDRTYPE] : "";
856 897
 
857
-            if (isset($row[PR_SMTP_ADDRESS]))
858
-                $address = $row[PR_SMTP_ADDRESS];
859
-            elseif ($addrtype == "SMTP" && isset($row[PR_EMAIL_ADDRESS]))
860
-                $address = $row[PR_EMAIL_ADDRESS];
861
-            elseif ($addrtype == "ZARAFA" && isset($row[PR_ENTRYID]))
862
-                $address = $this->getSMTPAddressFromEntryID($row[PR_ENTRYID]);
898
+            if (isset($row[PR_SMTP_ADDRESS])) {
899
+                            $address = $row[PR_SMTP_ADDRESS];
900
+            } elseif ($addrtype == "SMTP" && isset($row[PR_EMAIL_ADDRESS])) {
901
+                            $address = $row[PR_EMAIL_ADDRESS];
902
+            } elseif ($addrtype == "ZARAFA" && isset($row[PR_ENTRYID])) {
903
+                            $address = $this->getSMTPAddressFromEntryID($row[PR_ENTRYID]);
904
+            }
863 905
 
864 906
             // if the user was not found, do a fallback to PR_SEARCH_KEY
865 907
             // @see https://jira.z-hub.io/browse/ZP-1178
@@ -869,13 +911,12 @@  discard block
 block discarded – undo
869 911
 
870 912
             $name = isset($row[PR_DISPLAY_NAME]) ? $row[PR_DISPLAY_NAME] : "";
871 913
 
872
-            if($name == "" || $name == $address)
873
-                $fulladdr = w2u($address);
874
-            else {
914
+            if($name == "" || $name == $address) {
915
+                            $fulladdr = w2u($address);
916
+            } else {
875 917
                 if (substr($name, 0, 1) != '"' && substr($name, -1) != '"') {
876 918
                     $fulladdr = "\"" . w2u($name) ."\" <" . w2u($address) . ">";
877
-                }
878
-                else {
919
+                } else {
879 920
                     $fulladdr = w2u($name) ."<" . w2u($address) . ">";
880 921
                 }
881 922
             }
@@ -887,22 +928,30 @@  discard block
 block discarded – undo
887 928
             }
888 929
         }
889 930
 
890
-        if (is_array($message->to) && !empty($message->to)) $message->to = implode(", ", $message->to);
891
-        if (is_array($message->cc) && !empty($message->cc)) $message->cc = implode(", ", $message->cc);
931
+        if (is_array($message->to) && !empty($message->to)) {
932
+            $message->to = implode(", ", $message->to);
933
+        }
934
+        if (is_array($message->cc) && !empty($message->cc)) {
935
+            $message->cc = implode(", ", $message->cc);
936
+        }
892 937
 
893 938
         // without importance some mobiles assume "0" (low) - Mantis #439
894
-        if (!isset($message->importance))
895
-            $message->importance = IMPORTANCE_NORMAL;
939
+        if (!isset($message->importance)) {
940
+                    $message->importance = IMPORTANCE_NORMAL;
941
+        }
896 942
 
897
-        if (!isset($message->internetcpid)) $message->internetcpid = (defined('STORE_INTERNET_CPID')) ? constant('STORE_INTERNET_CPID') : INTERNET_CPID_WINDOWS1252;
943
+        if (!isset($message->internetcpid)) {
944
+            $message->internetcpid = (defined('STORE_INTERNET_CPID')) ? constant('STORE_INTERNET_CPID') : INTERNET_CPID_WINDOWS1252;
945
+        }
898 946
         $this->setFlag($mapimessage, $message);
899 947
         //TODO checkcontentclass
900
-        if (!isset($message->contentclass)) $message->contentclass = DEFAULT_EMAIL_CONTENTCLASS;
948
+        if (!isset($message->contentclass)) {
949
+            $message->contentclass = DEFAULT_EMAIL_CONTENTCLASS;
950
+        }
901 951
 
902 952
         if (!isset($message->nativebodytype)) {
903 953
             $message->nativebodytype = MAPIUtils::GetNativeBodyType($messageprops);
904
-        }
905
-        elseif ($message->nativebodytype == SYNC_BODYPREFERENCE_UNDEFINED) {
954
+        } elseif ($message->nativebodytype == SYNC_BODYPREFERENCE_UNDEFINED) {
906 955
             $nbt = MAPIUtils::GetNativeBodyType($messageprops);
907 956
             ZLog::Write(LOGLEVEL_INFO, sprintf("MAPIProvider->getEmail(): native body type is undefined. Set it to %d.", $nbt));
908 957
             $message->nativebodytype = $nbt;
@@ -989,8 +1038,7 @@  discard block
 block discarded – undo
989 1038
         $folder->serverid = ZPush::GetDeviceManager()->GetFolderIdForBackendId($folder->BackendId, true, $folderOrigin, $folderprops[PR_DISPLAY_NAME]);
990 1039
         if($folderprops[PR_PARENT_ENTRYID] == $storeprops[PR_IPM_SUBTREE_ENTRYID] || $folderprops[PR_PARENT_ENTRYID] == $storeprops[PR_IPM_PUBLIC_FOLDERS_ENTRYID]) {
991 1040
             $folder->parentid = "0";
992
-        }
993
-        else {
1041
+        } else {
994 1042
             $folder->parentid = ZPush::GetDeviceManager()->GetFolderIdForBackendId(bin2hex($folderprops[PR_PARENT_SOURCE_KEY]));
995 1043
         }
996 1044
         $folder->displayname = w2u($folderprops[PR_DISPLAY_NAME]);
@@ -1013,45 +1061,61 @@  discard block
 block discarded – undo
1013 1061
         $storeprops = $this->GetStoreProps();
1014 1062
         $inboxprops = $this->GetInboxProps();
1015 1063
 
1016
-        if($entryid == $storeprops[PR_IPM_WASTEBASKET_ENTRYID])
1017
-            return SYNC_FOLDER_TYPE_WASTEBASKET;
1018
-        if($entryid == $storeprops[PR_IPM_SENTMAIL_ENTRYID])
1019
-            return SYNC_FOLDER_TYPE_SENTMAIL;
1020
-        if($entryid == $storeprops[PR_IPM_OUTBOX_ENTRYID])
1021
-            return SYNC_FOLDER_TYPE_OUTBOX;
1064
+        if($entryid == $storeprops[PR_IPM_WASTEBASKET_ENTRYID]) {
1065
+                    return SYNC_FOLDER_TYPE_WASTEBASKET;
1066
+        }
1067
+        if($entryid == $storeprops[PR_IPM_SENTMAIL_ENTRYID]) {
1068
+                    return SYNC_FOLDER_TYPE_SENTMAIL;
1069
+        }
1070
+        if($entryid == $storeprops[PR_IPM_OUTBOX_ENTRYID]) {
1071
+                    return SYNC_FOLDER_TYPE_OUTBOX;
1072
+        }
1022 1073
 
1023 1074
         // Public folders do not have inboxprops
1024 1075
         // @see https://jira.z-hub.io/browse/ZP-995
1025 1076
         if (!empty($inboxprops)) {
1026
-            if($entryid == $inboxprops[PR_ENTRYID])
1027
-                return SYNC_FOLDER_TYPE_INBOX;
1028
-            if($entryid == $inboxprops[PR_IPM_DRAFTS_ENTRYID])
1029
-                return SYNC_FOLDER_TYPE_DRAFTS;
1030
-            if($entryid == $inboxprops[PR_IPM_TASK_ENTRYID])
1031
-                return SYNC_FOLDER_TYPE_TASK;
1032
-            if($entryid == $inboxprops[PR_IPM_APPOINTMENT_ENTRYID])
1033
-                return SYNC_FOLDER_TYPE_APPOINTMENT;
1034
-            if($entryid == $inboxprops[PR_IPM_CONTACT_ENTRYID])
1035
-                return SYNC_FOLDER_TYPE_CONTACT;
1036
-            if($entryid == $inboxprops[PR_IPM_NOTE_ENTRYID])
1037
-                return SYNC_FOLDER_TYPE_NOTE;
1038
-            if($entryid == $inboxprops[PR_IPM_JOURNAL_ENTRYID])
1039
-                return SYNC_FOLDER_TYPE_JOURNAL;
1077
+            if($entryid == $inboxprops[PR_ENTRYID]) {
1078
+                            return SYNC_FOLDER_TYPE_INBOX;
1079
+            }
1080
+            if($entryid == $inboxprops[PR_IPM_DRAFTS_ENTRYID]) {
1081
+                            return SYNC_FOLDER_TYPE_DRAFTS;
1082
+            }
1083
+            if($entryid == $inboxprops[PR_IPM_TASK_ENTRYID]) {
1084
+                            return SYNC_FOLDER_TYPE_TASK;
1085
+            }
1086
+            if($entryid == $inboxprops[PR_IPM_APPOINTMENT_ENTRYID]) {
1087
+                            return SYNC_FOLDER_TYPE_APPOINTMENT;
1088
+            }
1089
+            if($entryid == $inboxprops[PR_IPM_CONTACT_ENTRYID]) {
1090
+                            return SYNC_FOLDER_TYPE_CONTACT;
1091
+            }
1092
+            if($entryid == $inboxprops[PR_IPM_NOTE_ENTRYID]) {
1093
+                            return SYNC_FOLDER_TYPE_NOTE;
1094
+            }
1095
+            if($entryid == $inboxprops[PR_IPM_JOURNAL_ENTRYID]) {
1096
+                            return SYNC_FOLDER_TYPE_JOURNAL;
1097
+            }
1040 1098
         }
1041 1099
 
1042 1100
         // user created folders
1043
-        if ($class == "IPF.Note")
1044
-            return SYNC_FOLDER_TYPE_USER_MAIL;
1045
-        if ($class == "IPF.Task")
1046
-            return SYNC_FOLDER_TYPE_USER_TASK;
1047
-        if ($class == "IPF.Appointment")
1048
-            return SYNC_FOLDER_TYPE_USER_APPOINTMENT;
1049
-        if ($class == "IPF.Contact")
1050
-            return SYNC_FOLDER_TYPE_USER_CONTACT;
1051
-        if ($class == "IPF.StickyNote")
1052
-            return SYNC_FOLDER_TYPE_USER_NOTE;
1053
-        if ($class == "IPF.Journal")
1054
-            return  SYNC_FOLDER_TYPE_USER_JOURNAL;
1101
+        if ($class == "IPF.Note") {
1102
+                    return SYNC_FOLDER_TYPE_USER_MAIL;
1103
+        }
1104
+        if ($class == "IPF.Task") {
1105
+                    return SYNC_FOLDER_TYPE_USER_TASK;
1106
+        }
1107
+        if ($class == "IPF.Appointment") {
1108
+                    return SYNC_FOLDER_TYPE_USER_APPOINTMENT;
1109
+        }
1110
+        if ($class == "IPF.Contact") {
1111
+                    return SYNC_FOLDER_TYPE_USER_CONTACT;
1112
+        }
1113
+        if ($class == "IPF.StickyNote") {
1114
+                    return SYNC_FOLDER_TYPE_USER_NOTE;
1115
+        }
1116
+        if ($class == "IPF.Journal") {
1117
+                    return  SYNC_FOLDER_TYPE_USER_JOURNAL;
1118
+        }
1055 1119
 
1056 1120
         return SYNC_FOLDER_TYPE_OTHER;
1057 1121
     }
@@ -1069,15 +1133,17 @@  discard block
 block discarded – undo
1069 1133
 
1070 1134
         $inboxProps = array();
1071 1135
         $inbox = mapi_msgstore_getreceivefolder($this->store);
1072
-        if(!mapi_last_hresult())
1073
-            $inboxProps = mapi_getprops($inbox, array(PR_ENTRYID));
1136
+        if(!mapi_last_hresult()) {
1137
+                    $inboxProps = mapi_getprops($inbox, array(PR_ENTRYID));
1138
+        }
1074 1139
 
1075 1140
         $root = mapi_msgstore_openentry($this->store, null); // TODO use getRootProps()
1076 1141
         $rootProps = mapi_getprops($root, array(PR_IPM_APPOINTMENT_ENTRYID, PR_IPM_CONTACT_ENTRYID, PR_IPM_DRAFTS_ENTRYID, PR_IPM_JOURNAL_ENTRYID, PR_IPM_NOTE_ENTRYID, PR_IPM_TASK_ENTRYID, PR_ADDITIONAL_REN_ENTRYIDS));
1077 1142
 
1078 1143
         $additional_ren_entryids = array();
1079
-        if(isset($rootProps[PR_ADDITIONAL_REN_ENTRYIDS]))
1080
-            $additional_ren_entryids = $rootProps[PR_ADDITIONAL_REN_ENTRYIDS];
1144
+        if(isset($rootProps[PR_ADDITIONAL_REN_ENTRYIDS])) {
1145
+                    $additional_ren_entryids = $rootProps[PR_ADDITIONAL_REN_ENTRYIDS];
1146
+        }
1081 1147
 
1082 1148
         $defaultfolders = array(
1083 1149
                         "inbox"                 =>      array("inbox"=>PR_ENTRYID),
@@ -1170,7 +1236,9 @@  discard block
 block discarded – undo
1170 1236
      */
1171 1237
     private function setEmail($mapimessage, $message) {
1172 1238
         // update categories
1173
-        if (!isset($message->categories)) $message->categories = array();
1239
+        if (!isset($message->categories)) {
1240
+            $message->categories = array();
1241
+        }
1174 1242
         $emailmap = MAPIMapping::GetEmailMapping();
1175 1243
         $this->setPropsInMAPI($mapimessage, $message, array("categories" => $emailmap["categories"]));
1176 1244
 
@@ -1209,12 +1277,12 @@  discard block
 block discarded – undo
1209 1277
             $delprops[] = $flagprops["completetime"];
1210 1278
             $delprops[] = $flagprops["flagstatus"];
1211 1279
             $delprops[] = $flagprops["flagicon"];
1212
-        }
1213
-        else {
1280
+        } else {
1214 1281
             $this->setPropsInMAPI($mapimessage, $message->flag, $flagmapping);
1215 1282
             $props[$flagprops["todoitemsflags"]] = 1;
1216
-            if (isset($message->subject) && strlen($message->subject) > 0)
1217
-                $props[$flagprops["todotitle"]] = $message->subject;
1283
+            if (isset($message->subject) && strlen($message->subject) > 0) {
1284
+                            $props[$flagprops["todotitle"]] = $message->subject;
1285
+            }
1218 1286
             // ordinal date is utc current time
1219 1287
             if (!isset($message->flag->ordinaldate) || empty($message->flag->ordinaldate)) {
1220 1288
                 $props[$flagprops["ordinaldate"]] = time();
@@ -1257,10 +1325,11 @@  discard block
 block discarded – undo
1257 1325
      */
1258 1326
     private function setAppointment($mapimessage, $appointment) {
1259 1327
         // Get timezone info
1260
-        if(isset($appointment->timezone))
1261
-            $tz = $this->getTZFromSyncBlob(base64_decode($appointment->timezone));
1262
-        else
1263
-            $tz = false;
1328
+        if(isset($appointment->timezone)) {
1329
+                    $tz = $this->getTZFromSyncBlob(base64_decode($appointment->timezone));
1330
+        } else {
1331
+                    $tz = false;
1332
+        }
1264 1333
 
1265 1334
         // start and end time may not be set - try to get them from the existing appointment for further calculation - see https://jira.z-hub.io/browse/ZP-983
1266 1335
         if (!isset($appointment->starttime) || !isset($appointment->endtime)) {
@@ -1382,8 +1451,7 @@  discard block
 block discarded – undo
1382 1451
                         $noexceptions = false;
1383 1452
                         // Delete exception
1384 1453
                         $recurrence->createException(array(), $basedate, true);
1385
-                    }
1386
-                    else {
1454
+                    } else {
1387 1455
                         // Change exception
1388 1456
                         $mapiexception = array("basedate" => $basedate);
1389 1457
                         //other exception properties which are not handled in recurrence
@@ -1397,25 +1465,31 @@  discard block
 block discarded – undo
1397 1465
                             $mapiexception["end"] = $this->getLocaltimeByTZ($exception->endtime, $tz);
1398 1466
                             $exceptionprops[$appointmentprops["endtime"]] = $exception->endtime;
1399 1467
                         }
1400
-                        if(isset($exception->subject))
1401
-                            $exceptionprops[$appointmentprops["subject"]] = $mapiexception["subject"] = u2w($exception->subject);
1402
-                        if(isset($exception->location))
1403
-                            $exceptionprops[$appointmentprops["location"]] = $mapiexception["location"] = u2w($exception->location);
1404
-                        if(isset($exception->busystatus))
1405
-                            $exceptionprops[$appointmentprops["busystatus"]] = $mapiexception["busystatus"] = $exception->busystatus;
1468
+                        if(isset($exception->subject)) {
1469
+                                                    $exceptionprops[$appointmentprops["subject"]] = $mapiexception["subject"] = u2w($exception->subject);
1470
+                        }
1471
+                        if(isset($exception->location)) {
1472
+                                                    $exceptionprops[$appointmentprops["location"]] = $mapiexception["location"] = u2w($exception->location);
1473
+                        }
1474
+                        if(isset($exception->busystatus)) {
1475
+                                                    $exceptionprops[$appointmentprops["busystatus"]] = $mapiexception["busystatus"] = $exception->busystatus;
1476
+                        }
1406 1477
                         if(isset($exception->reminder)) {
1407 1478
                             $exceptionprops[$appointmentprops["reminderset"]] = $mapiexception["reminder_set"] = 1;
1408 1479
                             $exceptionprops[$appointmentprops["remindertime"]] = $mapiexception["remind_before"] = $exception->reminder;
1409 1480
                         }
1410
-                        if(isset($exception->alldayevent))
1411
-                            $exceptionprops[$appointmentprops["alldayevent"]] = $mapiexception["alldayevent"] = $exception->alldayevent;
1481
+                        if(isset($exception->alldayevent)) {
1482
+                                                    $exceptionprops[$appointmentprops["alldayevent"]] = $mapiexception["alldayevent"] = $exception->alldayevent;
1483
+                        }
1412 1484
 
1413 1485
 
1414
-                        if(!isset($recur["changed_occurences"]))
1415
-                            $recur["changed_occurences"] = array();
1486
+                        if(!isset($recur["changed_occurences"])) {
1487
+                                                    $recur["changed_occurences"] = array();
1488
+                        }
1416 1489
 
1417
-                        if (isset($exception->body))
1418
-                            $exceptionprops[$appointmentprops["body"]] = u2w($exception->body);
1490
+                        if (isset($exception->body)) {
1491
+                                                    $exceptionprops[$appointmentprops["body"]] = u2w($exception->body);
1492
+                        }
1419 1493
 
1420 1494
                         if (isset($exception->asbody)) {
1421 1495
                             $this->setASbody($exception->asbody, $exceptionprops, $appointmentprops);
@@ -1430,8 +1504,7 @@  discard block
 block discarded – undo
1430 1504
                             $noexceptions = false;
1431 1505
                             if($recurrence->isException($basedate)){
1432 1506
                                 $recurrence->modifyException($exceptionprops, $basedate);
1433
-                            }
1434
-                            else {
1507
+                            } else {
1435 1508
                                 $recurrence->createException($exceptionprops, $basedate);
1436 1509
                             }
1437 1510
                         }
@@ -1444,8 +1517,7 @@  discard block
 block discarded – undo
1444 1517
             if ($noexceptions) {
1445 1518
                 $recurrence->setRecurrence($tz, $recur);
1446 1519
             }
1447
-        }
1448
-        else {
1520
+        } else {
1449 1521
             $props[$appointmentprops["isrecurring"]] = false;
1450 1522
         }
1451 1523
 
@@ -1521,8 +1593,7 @@  discard block
 block discarded – undo
1521 1593
                     $recip[PR_RECIPIENT_TYPE] = isset($attendee->attendeetype) ? $attendee->attendeetype : MAPI_TO;
1522 1594
                     $recip[PR_RECIPIENT_FLAGS] = recipSendable;
1523 1595
                     $recip[PR_RECIPIENT_TRACKSTATUS] = isset($attendee->attendeestatus) ? $attendee->attendeestatus : olResponseNone;
1524
-                }
1525
-                else {
1596
+                } else {
1526 1597
                     $recip[PR_DISPLAY_NAME] = u2w($attendee->name);
1527 1598
                     $recip[PR_SEARCH_KEY] = "SMTP:".$recip[PR_EMAIL_ADDRESS]."\0";
1528 1599
                     $recip[PR_ADDRTYPE] = "SMTP";
@@ -1552,14 +1623,17 @@  discard block
 block discarded – undo
1552 1623
         mapi_setprops($mapimessage, array(PR_MESSAGE_CLASS => "IPM.Contact"));
1553 1624
 
1554 1625
         // normalize email addresses
1555
-        if (isset($contact->email1address) && (($contact->email1address = $this->extractEmailAddress($contact->email1address)) === false))
1556
-            unset($contact->email1address);
1626
+        if (isset($contact->email1address) && (($contact->email1address = $this->extractEmailAddress($contact->email1address)) === false)) {
1627
+                    unset($contact->email1address);
1628
+        }
1557 1629
 
1558
-        if (isset($contact->email2address) && (($contact->email2address = $this->extractEmailAddress($contact->email2address)) === false))
1559
-            unset($contact->email2address);
1630
+        if (isset($contact->email2address) && (($contact->email2address = $this->extractEmailAddress($contact->email2address)) === false)) {
1631
+                    unset($contact->email2address);
1632
+        }
1560 1633
 
1561
-        if (isset($contact->email3address) && (($contact->email3address = $this->extractEmailAddress($contact->email3address)) === false))
1562
-            unset($contact->email3address);
1634
+        if (isset($contact->email3address) && (($contact->email3address = $this->extractEmailAddress($contact->email3address)) === false)) {
1635
+                    unset($contact->email3address);
1636
+        }
1563 1637
 
1564 1638
         $contactmapping = MAPIMapping::GetContactMapping();
1565 1639
         $contactprops = MAPIMapping::GetContactProperties();
@@ -1578,18 +1652,23 @@  discard block
 block discarded – undo
1578 1652
         $nremails = array();
1579 1653
         $abprovidertype = 0;
1580 1654
 
1581
-        if (isset($contact->email1address))
1582
-            $this->setEmailAddress($contact->email1address, $cname, 1, $props, $contactprops, $nremails, $abprovidertype);
1583
-        if (isset($contact->email2address))
1584
-            $this->setEmailAddress($contact->email2address, $cname, 2, $props, $contactprops, $nremails, $abprovidertype);
1585
-        if (isset($contact->email3address))
1586
-            $this->setEmailAddress($contact->email3address, $cname, 3, $props, $contactprops, $nremails, $abprovidertype);
1655
+        if (isset($contact->email1address)) {
1656
+                    $this->setEmailAddress($contact->email1address, $cname, 1, $props, $contactprops, $nremails, $abprovidertype);
1657
+        }
1658
+        if (isset($contact->email2address)) {
1659
+                    $this->setEmailAddress($contact->email2address, $cname, 2, $props, $contactprops, $nremails, $abprovidertype);
1660
+        }
1661
+        if (isset($contact->email3address)) {
1662
+                    $this->setEmailAddress($contact->email3address, $cname, 3, $props, $contactprops, $nremails, $abprovidertype);
1663
+        }
1587 1664
 
1588 1665
         $props[$contactprops["addressbooklong"]] = $abprovidertype;
1589 1666
         $props[$contactprops["displayname"]] = $props[$contactprops["subject"]] = $cname;
1590 1667
 
1591 1668
         //pda multiple e-mail addresses bug fix for the contact
1592
-        if (!empty($nremails)) $props[$contactprops["addressbookmv"]] = $nremails;
1669
+        if (!empty($nremails)) {
1670
+            $props[$contactprops["addressbookmv"]] = $nremails;
1671
+        }
1593 1672
 
1594 1673
 
1595 1674
         //set addresses
@@ -1601,12 +1680,10 @@  discard block
 block discarded – undo
1601 1680
         if (isset($props[$contactprops["businessaddress"]])) {
1602 1681
             $props[$contactprops["mailingaddress"]] = 2;
1603 1682
             $this->setMailingAddress($contact->businesscity, $contact->businesscountry, $contact->businesspostalcode, $contact->businessstate, $contact->businessstreet, $props[$contactprops["businessaddress"]], $props, $contactprops);
1604
-        }
1605
-        elseif (isset($props[$contactprops["homeaddress"]])) {
1683
+        } elseif (isset($props[$contactprops["homeaddress"]])) {
1606 1684
             $props[$contactprops["mailingaddress"]] = 1;
1607 1685
             $this->setMailingAddress($contact->homecity, $contact->homecountry, $contact->homepostalcode, $contact->homestate, $contact->homestreet, $props[$contactprops["homeaddress"]], $props, $contactprops);
1608
-        }
1609
-        elseif (isset($props[$contactprops["otheraddress"]])) {
1686
+        } elseif (isset($props[$contactprops["otheraddress"]])) {
1610 1687
             $props[$contactprops["mailingaddress"]] = 3;
1611 1688
             $this->setMailingAddress($contact->othercity, $contact->othercountry, $contact->otherpostalcode, $contact->otherstate, $contact->otherstreet, $props[$contactprops["otheraddress"]], $props, $contactprops);
1612 1689
         }
@@ -1667,8 +1744,9 @@  discard block
 block discarded – undo
1667 1744
             $middlename = (isset($contact->middlename)) ? $contact->middlename : "";
1668 1745
             $company = (isset($contact->companyname)) ? $contact->companyname : "";
1669 1746
             $props[$contactprops["fileas"]] = Utils::BuildFileAs($lastname, $firstname, $middlename, $company);
1747
+        } else {
1748
+            ZLog::Write(LOGLEVEL_DEBUG, "FILEAS_ORDER not defined");
1670 1749
         }
1671
-        else ZLog::Write(LOGLEVEL_DEBUG, "FILEAS_ORDER not defined");
1672 1750
 
1673 1751
         mapi_setprops($mapimessage, $props);
1674 1752
         return true;
@@ -1715,8 +1793,10 @@  discard block
 block discarded – undo
1715 1793
         if (isset($task->recurrence) && class_exists('TaskRecurrence')) {
1716 1794
             $deadoccur = false;
1717 1795
             if ((isset($task->recurrence->occurrences) && $task->recurrence->occurrences == 1) ||
1718
-                (isset($task->recurrence->deadoccur) && $task->recurrence->deadoccur == 1)) //ios5 sends deadoccur inside the recurrence
1796
+                (isset($task->recurrence->deadoccur) && $task->recurrence->deadoccur == 1)) {
1797
+                //ios5 sends deadoccur inside the recurrence
1719 1798
                 $deadoccur = true;
1799
+            }
1720 1800
 
1721 1801
             // Set PR_ICON_INDEX to 1281 to show correct icon in category view
1722 1802
             $props[$taskprops["icon"]] = 1281;
@@ -1778,7 +1858,9 @@  discard block
 block discarded – undo
1778 1858
     private function setNote($mapimessage, $note) {
1779 1859
         // Touchdown does not send categories if all are unset or there is none.
1780 1860
         // Setting it to an empty array will unset the property in KC as well
1781
-        if (!isset($note->categories)) $note->categories = array();
1861
+        if (!isset($note->categories)) {
1862
+            $note->categories = array();
1863
+        }
1782 1864
 
1783 1865
         // update icon index to correspond to the color
1784 1866
         if (isset($note->Color) && $note->Color > -1 && $note->Color < 5) {
@@ -1863,10 +1945,11 @@  discard block
 block discarded – undo
1863 1945
 
1864 1946
                 // UTF8->windows1252.. this is ok for all numerical values
1865 1947
                 if(mapi_prop_type($mapiprop) != PT_BINARY && mapi_prop_type($mapiprop) != PT_MV_BINARY) {
1866
-                    if(is_array($message->$asprop))
1867
-                        $value = array_map("u2wi", $message->$asprop);
1868
-                    else
1869
-                        $value = u2wi($message->$asprop);
1948
+                    if(is_array($message->$asprop)) {
1949
+                                            $value = array_map("u2wi", $message->$asprop);
1950
+                    } else {
1951
+                                            $value = u2wi($message->$asprop);
1952
+                    }
1870 1953
                 } else {
1871 1954
                     $value = $message->$asprop;
1872 1955
                 }
@@ -1889,8 +1972,10 @@  discard block
 block discarded – undo
1889 1972
                 // decode base64 value
1890 1973
                 if($mapiprop == PR_RTF_COMPRESSED) {
1891 1974
                     $value = base64_decode($value);
1892
-                    if(strlen($value) == 0)
1893
-                        continue; // PDA will sometimes give us an empty RTF, which we'll ignore.
1975
+                    if(strlen($value) == 0) {
1976
+                                            continue;
1977
+                    }
1978
+                    // PDA will sometimes give us an empty RTF, which we'll ignore.
1894 1979
 
1895 1980
                     // Note that you can still remove notes because when you remove notes it gives
1896 1981
                     // a valid compressed RTF with nothing in it.
@@ -1900,13 +1985,11 @@  discard block
 block discarded – undo
1900 1985
                 if (is_array($value) && empty($value)) {
1901 1986
                     $propsToDelete[] = $mapiprop;
1902 1987
                     ZLog::Write(LOGLEVEL_DEBUG, sprintf("MAPIProvider->setPropsInMAPI(): Property '%s' to be deleted as it is an empty array", $asprop));
1903
-                }
1904
-                else {
1988
+                } else {
1905 1989
                     // all properties will be set at once
1906 1990
                     $propsToSet[$mapiprop] = $value;
1907 1991
                 }
1908
-            }
1909
-            elseif (in_array($asprop, $unsetVars)) {
1992
+            } elseif (in_array($asprop, $unsetVars)) {
1910 1993
                 $propsToDelete[] = $mapiprop;
1911 1994
             }
1912 1995
         }
@@ -1967,24 +2050,28 @@  discard block
 block discarded – undo
1967 2050
             if(isset($messageprops[$mapiprop])) {
1968 2051
                 if(mapi_prop_type($mapiprop) == PT_BOOLEAN) {
1969 2052
                     // Force to actual '0' or '1'
1970
-                    if($messageprops[$mapiprop])
1971
-                        $message->$asprop = 1;
1972
-                    else
1973
-                        $message->$asprop = 0;
2053
+                    if($messageprops[$mapiprop]) {
2054
+                                            $message->$asprop = 1;
2055
+                    } else {
2056
+                                            $message->$asprop = 0;
2057
+                    }
1974 2058
                 } else {
1975 2059
                     // Special handling for PR_MESSAGE_FLAGS
1976
-                    if($mapiprop == PR_MESSAGE_FLAGS)
1977
-                        $message->$asprop = $messageprops[$mapiprop] & 1; // only look at 'read' flag
1978
-                    else if($mapiprop == PR_RTF_COMPRESSED)
1979
-                        //do not send rtf to the mobile
2060
+                    if($mapiprop == PR_MESSAGE_FLAGS) {
2061
+                                            $message->$asprop = $messageprops[$mapiprop] & 1;
2062
+                    }
2063
+                    // only look at 'read' flag
2064
+                    else if($mapiprop == PR_RTF_COMPRESSED) {
2065
+                                            //do not send rtf to the mobile
1980 2066
                         continue;
1981
-                    else if(is_array($messageprops[$mapiprop]))
1982
-                        $message->$asprop = array_map("w2u", $messageprops[$mapiprop]);
1983
-                    else {
1984
-                        if(mapi_prop_type($mapiprop) != PT_BINARY && mapi_prop_type($mapiprop) != PT_MV_BINARY)
1985
-                            $message->$asprop = w2u($messageprops[$mapiprop]);
1986
-                        else
1987
-                            $message->$asprop = $messageprops[$mapiprop];
2067
+                    } else if(is_array($messageprops[$mapiprop])) {
2068
+                                            $message->$asprop = array_map("w2u", $messageprops[$mapiprop]);
2069
+                    } else {
2070
+                        if(mapi_prop_type($mapiprop) != PT_BINARY && mapi_prop_type($mapiprop) != PT_MV_BINARY) {
2071
+                                                    $message->$asprop = w2u($messageprops[$mapiprop]);
2072
+                        } else {
2073
+                                                    $message->$asprop = $messageprops[$mapiprop];
2074
+                        }
1988 2075
                     }
1989 2076
                 }
1990 2077
             }
@@ -2112,13 +2199,15 @@  discard block
 block discarded – undo
2112 2199
      * @return long
2113 2200
      */
2114 2201
     private function getGMTTimeByTZ($localtime, $tz) {
2115
-        if(!isset($tz) || !is_array($tz))
2116
-            return $localtime;
2202
+        if(!isset($tz) || !is_array($tz)) {
2203
+                    return $localtime;
2204
+        }
2117 2205
 
2118
-        if($this->isDST($localtime, $tz))
2119
-            return $localtime + $tz["bias"]*60 + $tz["dstbias"]*60;
2120
-        else
2121
-            return $localtime + $tz["bias"]*60;
2206
+        if($this->isDST($localtime, $tz)) {
2207
+                    return $localtime + $tz["bias"]*60 + $tz["dstbias"]*60;
2208
+        } else {
2209
+                    return $localtime + $tz["bias"]*60;
2210
+        }
2122 2211
     }
2123 2212
 
2124 2213
     /**
@@ -2131,13 +2220,16 @@  discard block
 block discarded – undo
2131 2220
      * @return long
2132 2221
      */
2133 2222
     private function getLocaltimeByTZ($gmttime, $tz) {
2134
-        if(!isset($tz) || !is_array($tz))
2135
-            return $gmttime;
2223
+        if(!isset($tz) || !is_array($tz)) {
2224
+                    return $gmttime;
2225
+        }
2136 2226
 
2137
-        if($this->isDST($gmttime - $tz["bias"]*60, $tz)) // may bug around the switch time because it may have to be 'gmttime - bias - dstbias'
2227
+        if($this->isDST($gmttime - $tz["bias"]*60, $tz)) {
2228
+            // may bug around the switch time because it may have to be 'gmttime - bias - dstbias'
2138 2229
             return $gmttime - $tz["bias"]*60 - $tz["dstbias"]*60;
2139
-        else
2140
-            return $gmttime - $tz["bias"]*60;
2230
+        } else {
2231
+                    return $gmttime - $tz["bias"]*60;
2232
+        }
2141 2233
     }
2142 2234
 
2143 2235
     /**
@@ -2153,8 +2245,9 @@  discard block
 block discarded – undo
2153 2245
         if( !isset($tz) || !is_array($tz) ||
2154 2246
             !isset($tz["dstbias"]) || $tz["dstbias"] == 0 ||
2155 2247
             !isset($tz["dststartmonth"]) || $tz["dststartmonth"] == 0 ||
2156
-            !isset($tz["dstendmonth"]) || $tz["dstendmonth"] == 0)
2157
-            return false;
2248
+            !isset($tz["dstendmonth"]) || $tz["dstendmonth"] == 0) {
2249
+                    return false;
2250
+        }
2158 2251
 
2159 2252
         $year = gmdate("Y", $localtime);
2160 2253
         $start = $this->getTimestampOfWeek($year, $tz["dststartmonth"], $tz["dststartweek"], $tz["dststartday"], $tz["dststarthour"], $tz["dststartminute"], $tz["dststartsecond"]);
@@ -2162,16 +2255,18 @@  discard block
 block discarded – undo
2162 2255
 
2163 2256
         if($start < $end) {
2164 2257
             // northern hemisphere (july = dst)
2165
-          if($localtime >= $start && $localtime < $end)
2166
-              $dst = true;
2167
-          else
2168
-              $dst = false;
2258
+          if($localtime >= $start && $localtime < $end) {
2259
+                        $dst = true;
2260
+          } else {
2261
+                        $dst = false;
2262
+          }
2169 2263
         } else {
2170 2264
             // southern hemisphere (january = dst)
2171
-          if($localtime >= $end && $localtime < $start)
2172
-              $dst = false;
2173
-          else
2174
-              $dst = true;
2265
+          if($localtime >= $end && $localtime < $start) {
2266
+                        $dst = false;
2267
+          } else {
2268
+                        $dst = true;
2269
+          }
2175 2270
         }
2176 2271
 
2177 2272
         return $dst;
@@ -2192,16 +2287,18 @@  discard block
 block discarded – undo
2192 2287
      * @return long
2193 2288
      */
2194 2289
     private function getTimestampOfWeek($year, $month, $week, $wday, $hour, $minute, $second) {
2195
-        if ($month == 0)
2196
-            return;
2290
+        if ($month == 0) {
2291
+                    return;
2292
+        }
2197 2293
 
2198 2294
         $date = gmmktime($hour, $minute, $second, $month, 1, $year);
2199 2295
 
2200 2296
         // Find first day in month which matches day of the week
2201 2297
         while(1) {
2202 2298
             $wdaynow = gmdate("w", $date);
2203
-            if($wdaynow == $wday)
2204
-                break;
2299
+            if($wdaynow == $wday) {
2300
+                            break;
2301
+            }
2205 2302
             $date += 24 * 60 * 60;
2206 2303
         }
2207 2304
 
@@ -2212,10 +2309,11 @@  discard block
 block discarded – undo
2212 2309
         // specified weekday exists
2213 2310
         while(1) {
2214 2311
             $monthnow = gmdate("n", $date); // gmdate returns 1-12
2215
-            if($monthnow > $month)
2216
-                $date = $date - (24 * 7 * 60 * 60);
2217
-            else
2218
-                break;
2312
+            if($monthnow > $month) {
2313
+                            $date = $date - (24 * 7 * 60 * 60);
2314
+            } else {
2315
+                            break;
2316
+            }
2219 2317
         }
2220 2318
 
2221 2319
         return $date;
@@ -2245,22 +2343,25 @@  discard block
 block discarded – undo
2245 2343
         $addrbook = $this->getAddressbook();
2246 2344
 
2247 2345
         $mailuser = mapi_ab_openentry($addrbook, $entryid);
2248
-        if(!$mailuser)
2249
-            return "";
2346
+        if(!$mailuser) {
2347
+                    return "";
2348
+        }
2250 2349
 
2251 2350
         $props = mapi_getprops($mailuser, array(PR_ADDRTYPE, PR_SMTP_ADDRESS, PR_EMAIL_ADDRESS));
2252 2351
 
2253 2352
         $addrtype = isset($props[PR_ADDRTYPE]) ? $props[PR_ADDRTYPE] : "";
2254 2353
 
2255
-        if(isset($props[PR_SMTP_ADDRESS]))
2256
-            return $props[PR_SMTP_ADDRESS];
2354
+        if(isset($props[PR_SMTP_ADDRESS])) {
2355
+                    return $props[PR_SMTP_ADDRESS];
2356
+        }
2257 2357
 
2258
-        if($addrtype == "SMTP" && isset($props[PR_EMAIL_ADDRESS]))
2259
-            return $props[PR_EMAIL_ADDRESS];
2260
-        elseif ($addrtype == "ZARAFA" && isset($props[PR_EMAIL_ADDRESS])) {
2358
+        if($addrtype == "SMTP" && isset($props[PR_EMAIL_ADDRESS])) {
2359
+                    return $props[PR_EMAIL_ADDRESS];
2360
+        } elseif ($addrtype == "ZARAFA" && isset($props[PR_EMAIL_ADDRESS])) {
2261 2361
             $userinfo = nsp_getuserinfo($props[PR_EMAIL_ADDRESS]);
2262
-            if (is_array($userinfo) && isset($userinfo["primary_email"]))
2263
-                return $userinfo["primary_email"];
2362
+            if (is_array($userinfo) && isset($userinfo["primary_email"])) {
2363
+                            return $userinfo["primary_email"];
2364
+            }
2264 2365
         }
2265 2366
 
2266 2367
         return "";
@@ -2350,19 +2451,31 @@  discard block
 block discarded – undo
2350 2451
      * @return
2351 2452
      */
2352 2453
      private function setAddress($type, &$city, &$country, &$postalcode, &$state, &$street, &$props, &$properties) {
2353
-        if (isset($city)) $props[$properties[$type."city"]] = $city = u2w($city);
2454
+        if (isset($city)) {
2455
+            $props[$properties[$type."city"]] = $city = u2w($city);
2456
+        }
2354 2457
 
2355
-        if (isset($country)) $props[$properties[$type."country"]] = $country = u2w($country);
2458
+        if (isset($country)) {
2459
+            $props[$properties[$type."country"]] = $country = u2w($country);
2460
+        }
2356 2461
 
2357
-        if (isset($postalcode)) $props[$properties[$type."postalcode"]] = $postalcode = u2w($postalcode);
2462
+        if (isset($postalcode)) {
2463
+            $props[$properties[$type."postalcode"]] = $postalcode = u2w($postalcode);
2464
+        }
2358 2465
 
2359
-        if (isset($state)) $props[$properties[$type."state"]] = $state = u2w($state);
2466
+        if (isset($state)) {
2467
+            $props[$properties[$type."state"]] = $state = u2w($state);
2468
+        }
2360 2469
 
2361
-        if (isset($street)) $props[$properties[$type."street"]] = $street = u2w($street);
2470
+        if (isset($street)) {
2471
+            $props[$properties[$type."street"]] = $street = u2w($street);
2472
+        }
2362 2473
 
2363 2474
         //set composed address
2364 2475
         $address = Utils::BuildAddressString($street, $postalcode, $city, $state, $country);
2365
-        if ($address) $props[$properties[$type."address"]] = $address;
2476
+        if ($address) {
2477
+            $props[$properties[$type."address"]] = $address;
2478
+        }
2366 2479
     }
2367 2480
 
2368 2481
     /**
@@ -2381,12 +2494,24 @@  discard block
 block discarded – undo
2381 2494
      * @return
2382 2495
      */
2383 2496
     private function setMailingAddress($city, $country, $postalcode,  $state, $street, $address, &$props, &$properties) {
2384
-        if (isset($city)) $props[$properties["city"]] = $city;
2385
-        if (isset($country)) $props[$properties["country"]] = $country;
2386
-        if (isset($postalcode)) $props[$properties["postalcode"]] = $postalcode;
2387
-        if (isset($state)) $props[$properties["state"]] = $state;
2388
-        if (isset($street)) $props[$properties["street"]] = $street;
2389
-        if (isset($address)) $props[$properties["postaladdress"]] = $address;
2497
+        if (isset($city)) {
2498
+            $props[$properties["city"]] = $city;
2499
+        }
2500
+        if (isset($country)) {
2501
+            $props[$properties["country"]] = $country;
2502
+        }
2503
+        if (isset($postalcode)) {
2504
+            $props[$properties["postalcode"]] = $postalcode;
2505
+        }
2506
+        if (isset($state)) {
2507
+            $props[$properties["state"]] = $state;
2508
+        }
2509
+        if (isset($street)) {
2510
+            $props[$properties["street"]] = $street;
2511
+        }
2512
+        if (isset($address)) {
2513
+            $props[$properties["postaladdress"]] = $address;
2514
+        }
2390 2515
     }
2391 2516
 
2392 2517
     /**
@@ -2403,8 +2528,9 @@  discard block
 block discarded – undo
2403 2528
             $recur["complete"] = $message->complete;
2404 2529
         }
2405 2530
 
2406
-        if(!isset($message->recurrence->interval))
2407
-            $message->recurrence->interval = 1;
2531
+        if(!isset($message->recurrence->interval)) {
2532
+                    $message->recurrence->interval = 1;
2533
+        }
2408 2534
 
2409 2535
         //set the default value of numoccur
2410 2536
         $recur["numoccur"] = 0;
@@ -2414,10 +2540,11 @@  discard block
 block discarded – undo
2414 2540
         switch($message->recurrence->type) {
2415 2541
             case 0:
2416 2542
                 $recur["type"] = 10;
2417
-                if(isset($message->recurrence->dayofweek))
2418
-                    $recur["subtype"] = 1;
2419
-                else
2420
-                    $recur["subtype"] = 0;
2543
+                if(isset($message->recurrence->dayofweek)) {
2544
+                                    $recur["subtype"] = 1;
2545
+                } else {
2546
+                                    $recur["subtype"] = 0;
2547
+                }
2421 2548
 
2422 2549
                 $recur["everyn"] = $message->recurrence->interval * (60 * 24);
2423 2550
                 $recur["recurrencetype"] = 1;
@@ -2473,18 +2600,21 @@  discard block
 block discarded – undo
2473 2600
             $recur["term"] = 0x23;
2474 2601
         }
2475 2602
 
2476
-        if(isset($message->recurrence->dayofweek))
2477
-            $recur["weekdays"] = $message->recurrence->dayofweek;
2478
-        if(isset($message->recurrence->weekofmonth))
2479
-            $recur["nday"] = $message->recurrence->weekofmonth;
2603
+        if(isset($message->recurrence->dayofweek)) {
2604
+                    $recur["weekdays"] = $message->recurrence->dayofweek;
2605
+        }
2606
+        if(isset($message->recurrence->weekofmonth)) {
2607
+                    $recur["nday"] = $message->recurrence->weekofmonth;
2608
+        }
2480 2609
         if(isset($message->recurrence->monthofyear)) {
2481 2610
             // MAPI stores months as the amount of minutes until the beginning of the month in a
2482 2611
             // non-leapyear. Why this is, is totally unclear.
2483 2612
             $monthminutes = array(0,44640,84960,129600,172800,217440,260640,305280,348480,393120,437760,480960);
2484 2613
             $recur["month"] = $monthminutes[$message->recurrence->monthofyear-1];
2485 2614
         }
2486
-        if(isset($message->recurrence->dayofmonth))
2487
-            $recur["monthday"] = $message->recurrence->dayofmonth;
2615
+        if(isset($message->recurrence->dayofmonth)) {
2616
+                    $recur["monthday"] = $message->recurrence->dayofmonth;
2617
+        }
2488 2618
     }
2489 2619
 
2490 2620
     /**
@@ -2499,9 +2629,13 @@  discard block
 block discarded – undo
2499 2629
      *  @return string or false on error
2500 2630
      */
2501 2631
     private function extractEmailAddress($email) {
2502
-        if (!isset($this->zRFC822)) $this->zRFC822 = new Mail_RFC822();
2632
+        if (!isset($this->zRFC822)) {
2633
+            $this->zRFC822 = new Mail_RFC822();
2634
+        }
2503 2635
         $parsedAddress = $this->zRFC822->parseAddressList($email);
2504
-        if (!isset($parsedAddress[0]->mailbox) || !isset($parsedAddress[0]->host)) return false;
2636
+        if (!isset($parsedAddress[0]->mailbox) || !isset($parsedAddress[0]->host)) {
2637
+            return false;
2638
+        }
2505 2639
 
2506 2640
         return $parsedAddress[0]->mailbox.'@'.$parsedAddress[0]->host;
2507 2641
     }
@@ -2530,8 +2664,9 @@  discard block
 block discarded – undo
2530 2664
                 break;
2531 2665
             case SYNC_BODYPREFERENCE_MIME:
2532 2666
                 $stat = $this->imtoinet($mapimessage, $message);
2533
-                if (isset($message->asbody))
2534
-                    $message->asbody->type = $bpReturnType;
2667
+                if (isset($message->asbody)) {
2668
+                                    $message->asbody->type = $bpReturnType;
2669
+                }
2535 2670
                 return $stat;
2536 2671
         }
2537 2672
 
@@ -2539,8 +2674,7 @@  discard block
 block discarded – undo
2539 2674
         if ($stream) {
2540 2675
             $stat = mapi_stream_stat($stream);
2541 2676
             $streamsize = $stat['cb'];
2542
-        }
2543
-        else {
2677
+        } else {
2544 2678
             $streamsize = 0;
2545 2679
         }
2546 2680
 
@@ -2551,24 +2685,20 @@  discard block
 block discarded – undo
2551 2685
             if ($bpReturnType == SYNC_BODYPREFERENCE_RTF) {
2552 2686
                 $body = $this->mapiReadStream($stream, $streamsize);
2553 2687
                 $message->asbody->data = StringStreamWrapper::Open(base64_encode($body));
2554
-            }
2555
-            elseif (isset($message->internetcpid) && $bpReturnType == SYNC_BODYPREFERENCE_HTML) {
2688
+            } elseif (isset($message->internetcpid) && $bpReturnType == SYNC_BODYPREFERENCE_HTML) {
2556 2689
                 // if PR_HTML is UTF-8 we can stream it directly, else we have to convert to UTF-8 & wrap it
2557 2690
                 if ($message->internetcpid == INTERNET_CPID_UTF8) {
2558 2691
                     $message->asbody->data = MAPIStreamWrapper::Open($stream, $truncateHtmlSafe);
2559
-                }
2560
-                else {
2692
+                } else {
2561 2693
                     $body = $this->mapiReadStream($stream, $streamsize);
2562 2694
                     $message->asbody->data = StringStreamWrapper::Open(Utils::ConvertCodepageStringToUtf8($message->internetcpid, $body), $truncateHtmlSafe);
2563 2695
                     $message->internetcpid = INTERNET_CPID_UTF8;
2564 2696
                 }
2565
-            }
2566
-            else {
2697
+            } else {
2567 2698
                 $message->asbody->data = MAPIStreamWrapper::Open($stream);
2568 2699
             }
2569 2700
             $message->asbody->estimatedDataSize = $streamsize;
2570
-        }
2571
-        else {
2701
+        } else {
2572 2702
             $body = $this->mapiReadStream($stream, $streamsize);
2573 2703
             $message->body = str_replace("\n","\r\n", w2u(str_replace("\r", "", $body)));
2574 2704
             $message->bodysize = $streamsize;
@@ -2609,8 +2739,7 @@  discard block
 block discarded – undo
2609 2739
         if (isset($mapiEmail[PR_EC_IMAP_EMAIL]) || MAPIUtils::GetError(PR_EC_IMAP_EMAIL, $mapiEmail) == MAPI_E_NOT_ENOUGH_MEMORY) {
2610 2740
             $stream = mapi_openproperty($mapimessage, PR_EC_IMAP_EMAIL, IID_IStream, 0, 0);
2611 2741
             ZLog::Write(LOGLEVEL_DEBUG, "MAPIProvider->imtoinet(): using PR_EC_IMAP_EMAIL as full RFC822 message");
2612
-        }
2613
-        else {
2742
+        } else {
2614 2743
             $addrbook = $this->getAddressbook();
2615 2744
             $stream = mapi_inetmapi_imtoinet($this->session, $addrbook, $mapimessage, array('use_tnef' => -1, 'ignore_missing_attachments' => 1));
2616 2745
         }
@@ -2619,13 +2748,13 @@  discard block
 block discarded – undo
2619 2748
             $streamsize = $mstreamstat["cb"];
2620 2749
             if (isset($streamsize)) {
2621 2750
                 if (Request::GetProtocolVersion() >= 12.0) {
2622
-                    if (!isset($message->asbody))
2623
-                        $message->asbody = new SyncBaseBody();
2751
+                    if (!isset($message->asbody)) {
2752
+                                            $message->asbody = new SyncBaseBody();
2753
+                    }
2624 2754
                     $message->asbody->data = MAPIStreamWrapper::Open($stream);
2625 2755
                     $message->asbody->estimatedDataSize = $streamsize;
2626 2756
                     $message->asbody->truncated = 0;
2627
-                }
2628
-                else {
2757
+                } else {
2629 2758
                     $message->mimedata = MAPIStreamWrapper::Open($stream);
2630 2759
                     $message->mimesize = $streamsize;
2631 2760
                     $message->mimetruncated = 0;
@@ -2696,8 +2825,7 @@  discard block
 block discarded – undo
2696 2825
             if (Request::GetProtocolVersion() >= 14.0 && $bpo->GetPreview()) {
2697 2826
                 $message->asbody->preview = Utils::Utf8_truncate(MAPIUtils::readPropStream($mapimessage, PR_BODY), $bpo->GetPreview());
2698 2827
             }
2699
-        }
2700
-        else {
2828
+        } else {
2701 2829
             // Override 'body' for truncation
2702 2830
             $truncsize = Utils::GetTruncSize($contentparameters->GetTruncation());
2703 2831
             $this->setMessageBodyForType($mapimessage, SYNC_BODYPREFERENCE_PLAIN, $message);
@@ -2707,8 +2835,9 @@  discard block
 block discarded – undo
2707 2835
                 $message->bodytruncated = 1;
2708 2836
             }
2709 2837
 
2710
-            if (!isset($message->body) || strlen($message->body) == 0)
2711
-                $message->body = " ";
2838
+            if (!isset($message->body) || strlen($message->body) == 0) {
2839
+                            $message->body = " ";
2840
+            }
2712 2841
 
2713 2842
             if ($contentparameters->GetMimeSupport() == SYNC_MIMESUPPORT_ALWAYS) {
2714 2843
                 //set the html body for iphone in AS 2.5 version
@@ -2728,7 +2857,9 @@  discard block
 block discarded – undo
2728 2857
     */
2729 2858
     private function setFlag($mapimessage, &$message){
2730 2859
         // do nothing if protocol version is lower than 12.0 as flags haven't been defined before
2731
-        if (Request::GetProtocolVersion() < 12.0 ) return;
2860
+        if (Request::GetProtocolVersion() < 12.0 ) {
2861
+            return;
2862
+        }
2732 2863
 
2733 2864
         $message->flag = new SyncMailFlags();
2734 2865
 
@@ -2762,8 +2893,7 @@  discard block
 block discarded – undo
2762 2893
                 case SYNC_BODYPREFERENCE_MIME:
2763 2894
                     break;
2764 2895
             }
2765
-        }
2766
-        else {
2896
+        } else {
2767 2897
             ZLog::Write(LOGLEVEL_DEBUG, "MAPIProvider->setASbody either type or data are not set. Setting to empty body");
2768 2898
             $props[$appointmentprops["body"]] = "";
2769 2899
         }
@@ -2899,8 +3029,7 @@  discard block
 block discarded – undo
2899 3029
                         $this->specialFoldersData[] = substr($persistData, 8, $unpackedData['elDataSize']);
2900 3030
                         // Add PersistId and DataElementsSize lengths to the data size as they're not part of it
2901 3031
                         $persistData = substr($persistData, $unpackedData['dataSize'] + 4);
2902
-                    }
2903
-                    else {
3032
+                    } else {
2904 3033
                         ZLog::Write(LOGLEVEL_INFO, "MAPIProvider->getSpecialFoldersData(): persistent data is not valid");
2905 3034
                         break;
2906 3035
                     }
Please login to merge, or discard this patch.