Completed
Push — 16.1 ( 39d432...333927 )
by Klaus
17:10
created
mail/inc/class.mail_zpush.inc.php 2 patches
Spacing   +343 added lines, -344 removed lines patch added patch discarded remove patch
@@ -90,23 +90,23 @@  discard block
 block discarded – undo
90 90
 		$this->backend = $backend;
91 91
 		if (!isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']))
92 92
 		{
93
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Noprefs set: using 0 as default');
93
+			if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' Noprefs set: using 0 as default');
94 94
 			// globals preferences add appname varname value
95
-			$GLOBALS['egw']->preferences->add('activesync','mail-ActiveSyncProfileID',0,'user');
95
+			$GLOBALS['egw']->preferences->add('activesync', 'mail-ActiveSyncProfileID', 0, 'user');
96 96
 			// save prefs
97 97
 			$GLOBALS['egw']->preferences->save_repository(true);
98 98
 		}
99
-		if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' ActiveProfileID:'.array2string(self::$profileID));
99
+		if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' ActiveProfileID:'.array2string(self::$profileID));
100 100
 
101 101
 		if (is_null(self::$profileID))
102 102
 		{
103
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' self::ProfileID isNUll:'.array2string(self::$profileID));
104
-			self::$profileID =& Api\Cache::getSession('mail','activeSyncProfileID');
105
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' ActiveProfileID (after reading Cache):'.array2string(self::$profileID));
103
+			if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' self::ProfileID isNUll:'.array2string(self::$profileID));
104
+			self::$profileID = & Api\Cache::getSession('mail', 'activeSyncProfileID');
105
+			if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' ActiveProfileID (after reading Cache):'.array2string(self::$profileID));
106 106
 		}
107 107
 		if (isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']))
108 108
 		{
109
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Pref for ProfileID:'.array2string($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']));
109
+			if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' Pref for ProfileID:'.array2string($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']));
110 110
 			if ($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'] == 'G')
111 111
 			{
112 112
 				self::$profileID = 'G'; // this should trigger the fetch of the first negative profile (or if no negative profile is available the firstb there is)
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 				self::$profileID = (int)$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'];
117 117
 			}
118 118
 		}
119
-		if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Profile Selected (after reading Prefs):'.array2string(self::$profileID));
119
+		if ($this->debugLevel > 1) error_log(__METHOD__.__LINE__.' Profile Selected (after reading Prefs):'.array2string(self::$profileID));
120 120
 
121 121
 		// verify we are on an existing profile, if not running in setup (settings can not be static according to interface!)
122 122
 		if (!isset($GLOBALS['egw_setup']))
@@ -124,12 +124,12 @@  discard block
 block discarded – undo
124 124
 			try {
125 125
 				Mail\Account::read(self::$profileID);
126 126
 			}
127
-			catch(Exception $e) {
127
+			catch (Exception $e) {
128 128
 				unset($e);
129 129
 				self::$profileID = Mail\Account::get_default_acc_id();
130 130
 			}
131 131
 		}
132
-		if ($this->debugLevel>0) error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.self::$profileID);
132
+		if ($this->debugLevel > 0) error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.self::$profileID);
133 133
 		//$this->debugLevel=0;
134 134
 	}
135 135
 
@@ -226,13 +226,13 @@  discard block
 block discarded – undo
226 226
 			$this->__construct($this->backend);
227 227
 
228 228
 			try {
229
-				$this->_connect(0,true);
229
+				$this->_connect(0, true);
230 230
 				$this->_disconnect();
231 231
 
232 232
 				if (!$this->_wasteID) $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('trash').'</b>');
233 233
 				if (!$this->_sentID) $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('send').'</b>');
234 234
 			}
235
-			catch(Exception $e) {
235
+			catch (Exception $e) {
236 236
 				$errors[] = lang('Can not open IMAP connection').': '.$e->getMessage();
237 237
 			}
238 238
 			if ($errors)
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 	 * @param int $account integer id of account to use
251 251
 	 * @todo support different accounts
252 252
 	 */
253
-	private function _connect($account=0)
253
+	private function _connect($account = 0)
254 254
 	{
255 255
 		if (!$account) $account = self::$profileID ? self::$profileID : 0;
256 256
 		if ($this->mail && $this->account != $account) $this->_disconnect();
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 			$this->account = $account;
264 264
 			// todo: tell mail which account to use
265 265
 			//error_log(__METHOD__.__LINE__.' create object with ProfileID:'.array2string(self::$profileID));
266
-			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
266
+			$this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
267 267
 			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) self::$profileID = $this->mail->icServer->ImapServerId;
268 268
 		}
269 269
 		else
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 			//error_log(__METHOD__.__LINE__." connect with profileID: ".self::$profileID);
272 272
 			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) self::$profileID = $this->mail->icServer->ImapServerId;
273 273
 		}
274
-		$this->mail->openConnection(self::$profileID,false);
274
+		$this->mail->openConnection(self::$profileID, false);
275 275
 
276 276
 		$this->_wasteID = $this->mail->getTrashFolder(false);
277 277
 		//error_log(__METHOD__.__LINE__.' TrashFolder:'.$this->_wasteID);
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 	 */
287 287
 	private function _disconnect()
288 288
 	{
289
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__);
289
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__);
290 290
 		if ($this->mail) $this->mail->closeConnection();
291 291
 
292 292
 		unset($this->mail);
@@ -302,24 +302,24 @@  discard block
 block discarded – undo
302 302
 	public function GetFolderList()
303 303
 	{
304 304
 		$folderlist = array();
305
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
305
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__);
306 306
 		/*foreach($available_accounts as $account)*/ $account = 0;
307 307
 		{
308 308
 			$this->_connect($account);
309
-			if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false,$_alwaysGetDefaultFolders=true);
310
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($this->folders));
309
+			if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true, false, $_alwaysGetDefaultFolders = true);
310
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($this->folders));
311 311
 
312 312
 			foreach ($this->folders as $folder => $folderObj) {
313
-				if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' folder='.$folder);
313
+				if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' folder='.$folder);
314 314
 				$folderlist[] = $f = array(
315
-					'id'     => $this->createID($account,$folder),
315
+					'id'     => $this->createID($account, $folder),
316 316
 					'mod'    => $folderObj->shortDisplayName,
317
-					'parent' => $this->getParentID($account,$folder),
317
+					'parent' => $this->getParentID($account, $folder),
318 318
 				);
319
-				if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($f));
319
+				if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."() returning ".array2string($f));
320 320
 			}
321 321
 		}
322
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($folderlist));
322
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."() returning ".array2string($folderlist));
323 323
 
324 324
 		return $folderlist;
325 325
 	}
@@ -368,83 +368,83 @@  discard block
 block discarded – undo
368 368
 		$ClientSideMeetingRequest = false;
369 369
 		$allowSendingInvitations = 'sendifnocalnotif';
370 370
 		if (isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations']) &&
371
-			$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations']=='nosend')
371
+			$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations'] == 'nosend')
372 372
 		{
373 373
 			$allowSendingInvitations = false;
374 374
 		}
375 375
 		elseif (isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations']) &&
376
-			$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations']!='nosend')
376
+			$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations'] != 'nosend')
377 377
 		{
378 378
 			$allowSendingInvitations = $GLOBALS['egw_info']['user']['preferences']['activesync']['mail-allowSendingInvitations'];
379 379
 		}
380
-		$smartdata_task = ($smartdata->replyflag?'reply':($smartdata->forwardflag?'forward':'new'));
380
+		$smartdata_task = ($smartdata->replyflag ? 'reply' : ($smartdata->forwardflag ? 'forward' : 'new'));
381 381
 
382
-   		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__ . (isset($smartdata->mime) ? $smartdata->mime : ""). "task: ".(isset($smartdata_task) ? $smartdata_task : "")." itemid: ".(isset($smartdata->source->itemid) ? $smartdata->source->itemid : "")." folder: ".(isset($smartdata->source->folderid) ? $smartdata->source->folderid : ""));
383
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata));
382
+   		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.(isset($smartdata->mime) ? $smartdata->mime : "")."task: ".(isset($smartdata_task) ? $smartdata_task : "")." itemid: ".(isset($smartdata->source->itemid) ? $smartdata->source->itemid : "")." folder: ".(isset($smartdata->source->folderid) ? $smartdata->source->folderid : ""));
383
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata));
384 384
 		//error_log("IMAP-Sendmail: Smartdata = ".array2string($smartdata));
385 385
 
386 386
 		// initialize our Mail
387
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
387
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
388 388
 		$activeMailProfiles = $this->mail->getAccountIdentities(self::$profileID);
389 389
 		// use the standardIdentity
390
-		$activeMailProfile = Mail::getStandardIdentityForProfile($activeMailProfiles,self::$profileID);
390
+		$activeMailProfile = Mail::getStandardIdentityForProfile($activeMailProfiles, self::$profileID);
391 391
 
392
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.")".' ProfileID:'.self::$profileID.' ActiveMailProfile:'.array2string($activeMailProfile));
392
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.")".' ProfileID:'.self::$profileID.' ActiveMailProfile:'.array2string($activeMailProfile));
393 393
 		// collect identity / signature for later usage, and to determine if we may have to manipulate TransferEncoding and Charset
394 394
 		try
395 395
 		{
396 396
 			$acc = Mail\Account::read($this->mail->icServer->ImapServerId);
397 397
 			//error_log(__METHOD__.__LINE__.array2string($acc));
398
-			$_signature = Mail\Account::read_identity($acc['ident_id'],true);
398
+			$_signature = Mail\Account::read_identity($acc['ident_id'], true);
399 399
 		}
400 400
 		catch (Exception $e)
401 401
 		{
402
-			$_signature=array();
402
+			$_signature = array();
403 403
 		}
404 404
 		$signature = $_signature['ident_signature'];
405 405
 		if ((isset($preferencesArray['disableRulerForSignatureSeparation']) &&
406 406
 			$preferencesArray['disableRulerForSignatureSeparation']) ||
407
-			empty($signature) || trim(Api\Mail\Html::convertHTMLToText($signature)) =='')
407
+			empty($signature) || trim(Api\Mail\Html::convertHTMLToText($signature)) == '')
408 408
 		{
409 409
 			$disableRuler = true;
410 410
 		}
411 411
 		$beforePlain = $beforeHtml = "";
412
-		$beforeHtml = ($disableRuler ?'&nbsp;<br>':'&nbsp;<br><hr style="border:dotted 1px silver; width:90%; border:dotted 1px silver;">');
413
-		$beforePlain = ($disableRuler ?"\r\n\r\n":"\r\n\r\n-- \r\n");
414
-		$sigText = Mail::merge($signature,array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
415
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Signature to use:'.$sigText);
412
+		$beforeHtml = ($disableRuler ? '&nbsp;<br>' : '&nbsp;<br><hr style="border:dotted 1px silver; width:90%; border:dotted 1px silver;">');
413
+		$beforePlain = ($disableRuler ? "\r\n\r\n" : "\r\n\r\n-- \r\n");
414
+		$sigText = Mail::merge($signature, array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'], 'person_id')));
415
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Signature to use:'.$sigText);
416 416
 		$sigTextHtml = $beforeHtml.$sigText;
417 417
 		$sigTextPlain = $beforePlain.Api\Mail\Html::convertHTMLToText($sigText);
418 418
 
419
-		$force8bit=false;
420
-		if (Api\Translation::detect_encoding($sigTextPlain)!='ascii') $force8bit=true;
419
+		$force8bit = false;
420
+		if (Api\Translation::detect_encoding($sigTextPlain) != 'ascii') $force8bit = true;
421 421
 		// initialize the new Api\Mailer object for sending
422 422
 		$mailObject = new Api\Mailer(self::$profileID);
423
-		$this->mail->parseRawMessageIntoMailObject($mailObject,$smartdata->mime,$force8bit);
423
+		$this->mail->parseRawMessageIntoMailObject($mailObject, $smartdata->mime, $force8bit);
424 424
 		// Horde SMTP Class uses utf-8 by default. as we set charset always to utf-8
425
-		$mailObject->Sender  = $activeMailProfile['ident_email'];
426
-		$mailObject->setFrom($activeMailProfile['ident_email'],Mail::generateIdentityString($activeMailProfile,false));
425
+		$mailObject->Sender = $activeMailProfile['ident_email'];
426
+		$mailObject->setFrom($activeMailProfile['ident_email'], Mail::generateIdentityString($activeMailProfile, false));
427 427
 		$mailObject->addHeader('X-Mailer', 'mail-Activesync');
428 428
 
429 429
 		// prepare addressee list; moved the adding of addresses to the mailobject down
430 430
 		// to
431
-		foreach(Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject) {
431
+		foreach (Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject) {
432 432
 			if (!$addressObject->valid) continue;
433
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail To: ".array2string($addressObject) );
433
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") Header Sentmail To: ".array2string($addressObject));
434 434
 			//$mailObject->AddAddress($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
435 435
 			$toMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
436 436
 		}
437 437
 		// CC
438
-		foreach(Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) {
438
+		foreach (Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) {
439 439
 			if (!$addressObject->valid) continue;
440
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail CC: ".array2string($addressObject) );
440
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") Header Sentmail CC: ".array2string($addressObject));
441 441
 			//$mailObject->AddCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
442 442
 			$ccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
443 443
 		}
444 444
 		// BCC
445
-		foreach($mailObject->getAddresses('bcc') as $addressObject) {
445
+		foreach ($mailObject->getAddresses('bcc') as $addressObject) {
446 446
 			if (!$addressObject->valid) continue;
447
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail BCC: ".array2string($addressObject) );
447
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") Header Sentmail BCC: ".array2string($addressObject));
448 448
 			//$mailObject->AddBCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
449 449
 			$bccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
450 450
 		}
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 		$use_orgbody = false;
454 454
 
455 455
 		$k = 'Content-Type';
456
-		$ContentType =$mailObject->getHeader('Content-Type');
456
+		$ContentType = $mailObject->getHeader('Content-Type');
457 457
 		//error_log(__METHOD__.__LINE__." Header Sentmail original Header (filtered): " . $k.  " = ".trim($ContentType));
458 458
 		// if the message is a multipart message, then we should use the sent body
459 459
 		if (preg_match("/multipart/i", $ContentType)) {
@@ -473,43 +473,43 @@  discard block
 block discarded – undo
473 473
 			$k == "Content-Type" && preg_match("/multipart/i", $ContentType))) {
474 474
 			$use_orgbody = true;
475 475
 		}
476
-		$Body =  $AltBody = "";
476
+		$Body = $AltBody = "";
477 477
 		// get body of the transmitted message
478 478
 		// if this is a simple message, no structure at all
479 479
 		if (preg_match("/text/i", $ContentType))
480 480
 		{
481
-			$simpleBodyType = (preg_match("/html/i", $ContentType)?'text/html':'text/plain');
481
+			$simpleBodyType = (preg_match("/html/i", $ContentType) ? 'text/html' : 'text/plain');
482 482
 			$bodyObj = $mailObject->findBody(preg_match("/html/i", $ContentType) ? 'html' : 'plain');
483
-			$body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]", $bodyObj ?$bodyObj->getContents() : null);
484
-			if  ($simpleBodyType == "text/plain")
483
+			$body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "[$2]", $bodyObj ? $bodyObj->getContents() : null);
484
+			if ($simpleBodyType == "text/plain")
485 485
 			{
486 486
 				$Body = $body;
487 487
 				$AltBody = "<pre>".nl2br($body)."</pre>";
488
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as :". $simpleBodyType.'=> Created AltBody');
488
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched Body as :".$simpleBodyType.'=> Created AltBody');
489 489
 			}
490 490
 			else
491 491
 			{
492 492
 				$AltBody = $body;
493
-				$Body =  trim(Api\Mail\Html::convertHTMLToText($body));
494
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as :". $simpleBodyType.'=> Created Body');
493
+				$Body = trim(Api\Mail\Html::convertHTMLToText($body));
494
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched Body as :".$simpleBodyType.'=> Created Body');
495 495
 			}
496 496
 		}
497 497
 		else
498 498
 		{
499 499
 			// if this is a structured message
500 500
 			// prefer plain over html
501
-			$Body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]",
501
+			$Body = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "[$2]",
502 502
 				($text_body = $mailObject->findBody('plain')) ? $text_body->getContents() : null);
503
-			$AltBody = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]",
503
+			$AltBody = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i", "[$2]",
504 504
 				($html_body = $mailObject->findBody('html')) ? $html_body->getContents() : null);
505 505
 		}
506
-		if ($this->debugLevel>1 && $Body) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as with MessageContentType:". $ContentType.'=>'.$Body);
507
-		if ($this->debugLevel>1 && $AltBody) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:". $ContentType.'=>'.$AltBody);
506
+		if ($this->debugLevel > 1 && $Body) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched Body as with MessageContentType:".$ContentType.'=>'.$Body);
507
+		if ($this->debugLevel > 1 && $AltBody) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:".$ContentType.'=>'.$AltBody);
508 508
 		//error_log(__METHOD__.__LINE__.array2string($mailObject));
509 509
 		// if this is a multipart message with a boundary, we must use the original body
510 510
 		//if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' mailObject after Inital Parse:'.array2string($mailObject));
511 511
         if ($use_orgbody) {
512
-    	    ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") use_orgbody = true ContentType:".$ContentType);
512
+    	    ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") use_orgbody = true ContentType:".$ContentType);
513 513
  			// if it is a ClientSideMeetingRequest, we report it as send at all times
514 514
 			if (($cal_body = $mailObject->findBody('calendar')) &&
515 515
 				($cSMRMethod = $cal_body->getContentTypeParameter('method')))
@@ -518,21 +518,21 @@  discard block
 block discarded – undo
518 518
 				{
519 519
 					$organizer = calendar_ical::getIcalOrganizer($cal_body->getContents());
520 520
 				}
521
-				if ($this->debugLevel) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
521
+				if ($this->debugLevel) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
522 522
 				$ClientSideMeetingRequest = true;
523 523
 			}
524 524
         }
525 525
 		// now handle the addressee list
526 526
 		$toCount = 0;
527 527
 		//error_log(__METHOD__.__LINE__.array2string($toMailAddr));
528
-		foreach((array)$toMailAddr as $address) {
529
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
530
-				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
528
+		foreach ((array)$toMailAddr as $address) {
529
+			foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
530
+				$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
531 531
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' &&
532 532
 					calendar_boupdate::email_update_requested($emailAddress, isset($cSMRMethod) ? $cSMRMethod : 'REQUEST',
533 533
 						$organizer && !strcasecmp($emailAddress, $organizer) ? 'CHAIR' : ''))
534 534
 				{
535
-					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") skiping mail to organizer '$organizer', as it will be send by calendar app");
535
+					ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") skiping mail to organizer '$organizer', as it will be send by calendar app");
536 536
 					continue;
537 537
 				}
538 538
 				$mailObject->AddAddress($emailAddress, $addressObject->personal);
@@ -540,29 +540,29 @@  discard block
 block discarded – undo
540 540
 			}
541 541
 		}
542 542
 		$ccCount = 0;
543
-		foreach((array)$ccMailAddr as $address) {
544
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
545
-				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
543
+		foreach ((array)$ccMailAddr as $address) {
544
+			foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
545
+				$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
546 546
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
547 547
 				$mailObject->AddCC($emailAddress, $addressObject->personal);
548 548
 				$ccCount++;
549 549
 			}
550 550
 		}
551 551
 		$bccCount = 0;
552
-		foreach((array)$bccMailAddr as $address) {
553
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
554
-				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
552
+		foreach ((array)$bccMailAddr as $address) {
553
+			foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
554
+				$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
555 555
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
556 556
 				$mailObject->AddBCC($emailAddress, $addressObject->personal);
557 557
 				$bccCount++;
558 558
 			}
559 559
 		}
560 560
 		// typical organizer reply will end here with nothing send --> return true, because we suppressed the send above
561
-		if ($toCount+$ccCount+$bccCount == 0)
561
+		if ($toCount + $ccCount + $bccCount == 0)
562 562
 		{
563 563
 			return $ClientSideMeetingRequest && $allowSendingInvitations === 'sendifnocalnotif' && $organizer ? true : 0; // noone to send mail to
564 564
 		}
565
-		if ($ClientSideMeetingRequest === true && $allowSendingInvitations===false) return true;
565
+		if ($ClientSideMeetingRequest === true && $allowSendingInvitations === false) return true;
566 566
 		// as we use our mailer (horde mailer) it is detecting / setting the mimetype by itself while creating the mail
567 567
 /*
568 568
 		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' retrieved Body:'.$body);
@@ -579,26 +579,26 @@  discard block
 block discarded – undo
579 579
 		{
580 580
 			// now get on, and fetch the original mail
581 581
 			$uid = $smartdata->source->itemid;
582
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
582
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
583 583
 			$this->splitID($smartdata->source->folderid, $account, $folder);
584 584
 
585 585
 			$this->mail->reopen($folder);
586 586
 			$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
587
-			$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
588
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
589
-		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
587
+			$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail, $bodyStruct, true, false);
588
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
589
+		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/html')) {
590 590
 				// may be html
591
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
591
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
592 592
 				$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
593 593
 				$isreply = true;
594 594
 			}
595 595
 			// plain text Message part
596
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
596
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
597 597
 			// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
598
-			$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
599
-			$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
600
-			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
601
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
598
+			$bodyStruct = $this->mail->getMessageBody($uid, 'never_display'); //'never_display');
599
+			$bodyBUFF = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
600
+			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/plain')) {
601
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
602 602
 				$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
603 603
 				$isreply = true;
604 604
 			}
@@ -606,12 +606,12 @@  discard block
 block discarded – undo
606 606
 			{
607 607
 				$isreply = true;
608 608
 				$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
609
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
609
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
610 610
 			}
611 611
 		}
612 612
 
613 613
 		// how to forward and other prefs
614
-		$preferencesArray =& $GLOBALS['egw_info']['user']['preferences']['mail'];
614
+		$preferencesArray = & $GLOBALS['egw_info']['user']['preferences']['mail'];
615 615
 
616 616
 		// forward -------------------------------------------------------------------------
617 617
 		if ($smartdata_task == 'forward' && isset($smartdata->source->itemid) &&
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
 		{
622 622
 			//force the default for the forwarding -> asmail
623 623
 			if (is_array($preferencesArray)) {
624
-				if (!array_key_exists('message_forwarding',$preferencesArray)
624
+				if (!array_key_exists('message_forwarding', $preferencesArray)
625 625
 					|| !isset($preferencesArray['message_forwarding'])
626 626
 					|| empty($preferencesArray['message_forwarding'])) $preferencesArray['message_forwarding'] = 'asmail';
627 627
 			} else {
@@ -629,18 +629,18 @@  discard block
 block discarded – undo
629 629
 			}
630 630
 			// construct the uid of the message out of the itemid - seems to be the uid, no construction needed
631 631
 			$uid = $smartdata->source->itemid;
632
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.")IMAP Smartfordward is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
632
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.")IMAP Smartfordward is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
633 633
 			$this->splitID($smartdata->source->folderid, $account, $folder);
634 634
 
635 635
 			$this->mail->reopen($folder);
636 636
             // receive entire mail (header + body)
637 637
 			// get message headers for specified message
638
-			$headers	= $this->mail->getMessageEnvelope($uid, $_partID, true, $folder);
638
+			$headers = $this->mail->getMessageEnvelope($uid, $_partID, true, $folder);
639 639
 			// build a new mime message, forward entire old mail as file
640 640
 			if ($preferencesArray['message_forwarding'] == 'asmail')
641 641
 			{
642
-				$rawHeader      = $this->mail->getMessageRawHeader($smartdata->source->itemid, $_partID,$folder);
643
-				$rawBody        = $this->mail->getMessageRawBody($smartdata->source->itemid, $_partID,$folder);
642
+				$rawHeader      = $this->mail->getMessageRawHeader($smartdata->source->itemid, $_partID, $folder);
643
+				$rawBody        = $this->mail->getMessageRawBody($smartdata->source->itemid, $_partID, $folder);
644 644
 				$mailObject->AddStringAttachment($rawHeader.$rawBody, $headers['SUBJECT'].'.eml', 'message/rfc822');
645 645
 				$AltBody = $AltBody."</br>".lang("See Attachments for Content of the Orignial Mail").$sigTextHtml;
646 646
 				$Body = $Body."\r\n".lang("See Attachments for Content of the Orignial Mail").$sigTextPlain;
@@ -650,50 +650,50 @@  discard block
 block discarded – undo
650 650
 			{
651 651
 				// now get on, and fetch the original mail
652 652
 				$uid = $smartdata->source->itemid;
653
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
653
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") IMAP Smartreply is called with FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
654 654
 				$this->splitID($smartdata->source->folderid, $account, $folder);
655 655
 
656 656
 				$this->mail->reopen($folder);
657 657
 				$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
658
-				$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
659
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
660
-				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
658
+				$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail, $bodyStruct, true, false);
659
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
660
+				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/html')) {
661 661
 					// may be html
662
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
662
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
663 663
 					$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
664 664
 					$isforward = true;
665 665
 				}
666 666
 				// plain text Message part
667
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
667
+				if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
668 668
 				// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
669
-				$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
670
-				$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
671
-				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
672
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
669
+				$bodyStruct = $this->mail->getMessageBody($uid, 'never_display'); //'never_display');
670
+				$bodyBUFF = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
671
+				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/plain')) {
672
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
673 673
 					$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
674 674
 					$isforward = true;
675 675
 				}
676 676
 				if (!empty($bodyBUFF) && empty($bodyBUFFHtml) && !empty($AltBody))
677 677
 				{
678 678
 					$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
679
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
679
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
680 680
 					$isforward = true;
681 681
 				}
682 682
 				// get all the attachments and add them too.
683 683
 				// start handle Attachments
684 684
 				//												$_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folderName=''
685
-				$attachments = $this->mail->getMessageAttachments($uid, null,          null,								true,						false,				 true			, $folder);
685
+				$attachments = $this->mail->getMessageAttachments($uid, null, null, true, false, true, $folder);
686 686
 				$attachmentNames = false;
687
-				if (is_array($attachments) && count($attachments)>0)
687
+				if (is_array($attachments) && count($attachments) > 0)
688 688
 				{
689
-					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Attachments for BodyCreation of/for MessageID:'.$uid.' found:'.count($attachments));
690
-					foreach((array)$attachments as $key => $attachment)
689
+					ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' gather Attachments for BodyCreation of/for MessageID:'.$uid.' found:'.count($attachments));
690
+					foreach ((array)$attachments as $key => $attachment)
691 691
 					{
692
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
692
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
693 693
 						$attachmentNames .= $attachment['name']."\n";
694
-						$attachmentData	= $this->mail->getAttachment($uid, $attachment['partID'],0,false,false,$folder);
694
+						$attachmentData = $this->mail->getAttachment($uid, $attachment['partID'], 0, false, false, $folder);
695 695
 						/*$x =*/ $mailObject->AddStringAttachment($attachmentData['attachment'], $attachment['name'], $attachment['mimeType']);
696
-						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' added part with number:'.$x);
696
+						ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' added part with number:'.$x);
697 697
 					}
698 698
 				}
699 699
 			}
@@ -708,38 +708,38 @@  discard block
 block discarded – undo
708 708
 		// now set the body
709 709
 		if ($AltBody && ($html_body = $mailObject->findBody('html')))
710 710
 		{
711
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$AltBody);
711
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> '.$AltBody);
712 712
 			//error_log(__METHOD__.__LINE__.' html:'.$AltBody);
713
-			$html_body->setContents($AltBody,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
713
+			$html_body->setContents($AltBody, array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
714 714
 		}
715 715
 		if ($Body && ($text_body = $mailObject->findBody('plain')))
716 716
 		{
717
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$Body);
717
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> '.$Body);
718 718
 			//error_log(__METHOD__.__LINE__.' text:'.$Body);
719
-			$text_body->setContents($Body,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
719
+			$text_body->setContents($Body, array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
720 720
 		}
721 721
 		//advanced debugging
722 722
 		// Horde SMTP Class uses utf-8 by default.
723 723
         //ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SendMail: parsed message: ". print_r($message,1));
724
-		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
724
+		if ($this->debugLevel > 2) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
725 725
 
726 726
 		// set a higher timeout for big messages
727 727
 		@set_time_limit(120);
728
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.' about to send ....');
728
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> '.' about to send ....');
729 729
 		// send
730 730
 		$send = true;
731 731
 		try {
732 732
 			$mailObject->Send();
733 733
 		}
734
-		catch(Exception $e) {
735
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") The email could not be sent. Last-SMTP-error: ". $e->getMessage());
734
+		catch (Exception $e) {
735
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") The email could not be sent. Last-SMTP-error: ".$e->getMessage());
736 736
 			$send = false;
737 737
 		}
738 738
 
739
-		if (( $smartdata_task == 'reply' || $smartdata_task == 'forward') && $send == true)
739
+		if (($smartdata_task == 'reply' || $smartdata_task == 'forward') && $send == true)
740 740
 		{
741 741
 			$uid = $smartdata->source->itemid;
742
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' tASK:'.$smartdata_task." FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
742
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' tASK:'.$smartdata_task." FolderID:".$smartdata->source->folderid.' and ItemID:'.$smartdata->source->itemid);
743 743
 			$this->splitID($smartdata->source->folderid, $account, $folder);
744 744
 			//error_log(__METHOD__.__LINE__.' Folder:'.$folder.' Uid:'.$uid);
745 745
 			$this->mail->reopen($folder);
@@ -747,90 +747,90 @@  discard block
 block discarded – undo
747 747
 			// unless your templatefolder is a subfolder of your draftfolder, and the message is in there
748 748
 			if ($this->mail->isDraftFolder($folder) && !$this->mail->isTemplateFolder($folder))
749 749
 			{
750
-				$this->mail->deleteMessages(array($uid),$folder);
750
+				$this->mail->deleteMessages(array($uid), $folder);
751 751
 			} else {
752
-				$this->mail->flagMessages("answered", array($uid),$folder);
753
-				if ($smartdata_task== "forward")
752
+				$this->mail->flagMessages("answered", array($uid), $folder);
753
+				if ($smartdata_task == "forward")
754 754
 				{
755
-					$this->mail->flagMessages("forwarded", array($uid),$folder);
755
+					$this->mail->flagMessages("forwarded", array($uid), $folder);
756 756
 				}
757 757
 			}
758 758
 		}
759 759
 
760
-		$asf = ($send ? true:false); // initalize accordingly
761
-		if (/*($smartdata->saveinsent==1 || !isset($smartdata->saveinsent)) && */  $send==true && $this->mail->mailPreferences['sendOptions'] != 'send_only')
760
+		$asf = ($send ? true : false); // initalize accordingly
761
+		if (/*($smartdata->saveinsent==1 || !isset($smartdata->saveinsent)) && */  $send == true && $this->mail->mailPreferences['sendOptions'] != 'send_only')
762 762
 		{
763 763
 			$asf = false;
764 764
 			$sentFolder = $this->mail->getSentFolder();
765 765
 			if ($this->_sentID) {
766 766
 				$folderArray[] = $this->_sentID;
767 767
 			}
768
-			else if(isset($sentFolder) && $sentFolder != 'none')
768
+			else if (isset($sentFolder) && $sentFolder != 'none')
769 769
 			{
770 770
 				$folderArray[] = $sentFolder;
771 771
 			}
772 772
 			// No Sent folder set, try defaults
773 773
 			else
774 774
 			{
775
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") IMAP-SendMail: No Sent mailbox set");
775
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__.") IMAP-SendMail: No Sent mailbox set");
776 776
 				// we dont try guessing
777 777
 				$asf = true;
778 778
 			}
779 779
 			if (count($folderArray) > 0) {
780
-				foreach((array)$bccMailAddr as $address) {
781
-					foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
782
-						$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
780
+				foreach ((array)$bccMailAddr as $address) {
781
+					foreach (Mail::parseAddressList((get_magic_quotes_gpc() ? stripslashes($address) : $address)) as $addressObject) {
782
+						$emailAddress = $addressObject->mailbox.($addressObject->host ? '@'.$addressObject->host : '');
783 783
 						$mailAddr[] = array($emailAddress, $addressObject->personal);
784 784
 					}
785 785
 				}
786 786
 				//$BCCmail='';
787
-				if (count($mailAddr)>0) $mailObject->forceBccHeader();
787
+				if (count($mailAddr) > 0) $mailObject->forceBccHeader();
788 788
 				//$BCCmail = $mailObject->AddrAppend("Bcc",$mailAddr);
789
-				foreach($folderArray as $folderName) {
790
-					if($this->mail->isSentFolder($folderName)) {
789
+				foreach ($folderArray as $folderName) {
790
+					if ($this->mail->isSentFolder($folderName)) {
791 791
 						$flags = '\\Seen';
792
-					} elseif($this->mail->isDraftFolder($folderName)) {
792
+					} elseif ($this->mail->isDraftFolder($folderName)) {
793 793
 						$flags = '\\Draft';
794 794
 					} else {
795 795
 						$flags = '';
796 796
 					}
797 797
 					$asf = true;
798 798
 					//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.array2string($this->mail->icServer));
799
-					$this->mail->openConnection(self::$profileID,false);
799
+					$this->mail->openConnection(self::$profileID, false);
800 800
 					if ($this->mail->folderExists($folderName)) {
801 801
 						try
802 802
 						{
803
-							$this->mail->appendMessage($folderName,$mailObject->getRaw(), null,
803
+							$this->mail->appendMessage($folderName, $mailObject->getRaw(), null,
804 804
 									$flags);
805 805
 						}
806 806
 						catch (Api\Exception\WrongUserinput $e)
807 807
 						{
808 808
 							//$asf = false;
809
-							ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Could not save message to folder %2 due to: %3",$mailObject->getHeader('Subject'),$folderName,$e->getMessage()));
809
+							ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Could not save message to folder %2 due to: %3", $mailObject->getHeader('Subject'), $folderName, $e->getMessage()));
810 810
 						}
811 811
 					}
812 812
 					else
813 813
 					{
814 814
 						//$asf = false;
815
-						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.",$mailObject->getHeader('Subject'),$folderName));
815
+						ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.'->'.lang("Import of message %1 failed. Destination Folder %2 does not exist.", $mailObject->getHeader('Subject'), $folderName));
816 816
 					}
817
-			        ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Outgoing mail saved in configured 'Sent' folder '".$folderName."': ". (($asf)?"success":"failed"));
817
+			        ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(".__LINE__."): Outgoing mail saved in configured 'Sent' folder '".$folderName."': ".(($asf) ? "success" : "failed"));
818 818
 				}
819 819
 				//$this->mail->closeConnection();
820 820
 			}
821 821
 		}
822 822
 
823
-		$this->debugLevel=0;
823
+		$this->debugLevel = 0;
824 824
 
825 825
 		if ($send && $asf)
826 826
 		{
827
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> send successfully');
827
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' -> send successfully');
828 828
 			return true;
829 829
 		}
830 830
 		else
831 831
 		{
832
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." returning ".($ClientSideMeetingRequest ? true : 120)." (MailSubmissionFailed)".($ClientSideMeetingRequest ?" is ClientSideMeetingRequest (we ignore the failure)":""));
833
-			return ($ClientSideMeetingRequest ? true : 120);   //MAIL Submission failed, see MS-ASCMD
832
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." returning ".($ClientSideMeetingRequest ? true : 120)." (MailSubmissionFailed)".($ClientSideMeetingRequest ? " is ClientSideMeetingRequest (we ignore the failure)" : ""));
833
+			return ($ClientSideMeetingRequest ? true : 120); //MAIL Submission failed, see MS-ASCMD
834 834
 		}
835 835
 	}
836 836
 
@@ -848,43 +848,43 @@  discard block
 block discarded – undo
848 848
 	public function GetMessage($folderid, $id, $contentparameters)
849 849
 	{
850 850
 		//$this->debugLevel=4;
851
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' ContentParams='.array2string($contentparameters));
851
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' ContentParams='.array2string($contentparameters));
852 852
 		$truncsize = Utils::GetTruncSize($contentparameters->GetTruncation());
853 853
 		$mimesupport = $contentparameters->GetMimeSupport();
854
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() truncsize=$truncsize, mimeSupport=".array2string($mimesupport));
854
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."() truncsize=$truncsize, mimeSupport=".array2string($mimesupport));
855 855
 		$bodypreference = $contentparameters->GetBodyPreference(); /* fmbiete's contribution r1528, ZP-320 */
856 856
 
857 857
 		// fix for z-push bug returning additional bodypreference type 4, even if only 1 is requested and mimessupport = 0
858 858
 		if (!$mimesupport && ($key = array_search('4', $bodypreference))) unset($bodypreference[$key]);
859 859
 
860 860
 		//$this->debugLevel=4;
861
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
862
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' TruncSize:'.$truncsize.' Bodypreference: '.array2string($bodypreference));
861
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
862
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' TruncSize:'.$truncsize.' Bodypreference: '.array2string($bodypreference));
863 863
 		$account = $_folderName = $xid = null;
864
-		$this->splitID($folderid,$account,$_folderName,$xid);
864
+		$this->splitID($folderid, $account, $_folderName, $xid);
865 865
 		$this->mail->reopen($_folderName);
866
-		$messages = $this->fetchMessages($folderid, NULL, $id, true);	// true: return all headers
866
+		$messages = $this->fetchMessages($folderid, NULL, $id, true); // true: return all headers
867 867
 		$headers = $messages[$id];
868
-		if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($headers));
868
+		if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($headers));
869 869
 		// StatMessage should reopen the folder in question, so we dont need folderids in the following statements.
870 870
 		if ($headers)
871 871
 		{
872
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." Message $id with stat ".array2string($headers));
872
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." Message $id with stat ".array2string($headers));
873 873
 			// initialize the object
874 874
 			$output = new SyncMail();
875 875
 			//$rawHeaders = $this->mail->getMessageRawHeader($id);
876 876
 			// simple style
877 877
 			// start AS12 Stuff (bodypreference === false) case = old behaviour
878
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__. ' for message with ID:'.$id.' with headers:'.array2string($headers));
878
+			if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' for message with ID:'.$id.' with headers:'.array2string($headers));
879 879
 
880 880
 			if ($bodypreference === false) {
881
-				$bodyStruct = $this->mail->getMessageBody($id, 'only_if_no_text', '', null, true,$_folderName);
882
-				$raw_body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
881
+				$bodyStruct = $this->mail->getMessageBody($id, 'only_if_no_text', '', null, true, $_folderName);
882
+				$raw_body = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
883 883
 				//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
884
-				if (stripos($raw_body,'<style')!==false) $body = preg_replace("/<style.*?<\/style>/is", "", $raw_body); // in case there is only a html part
884
+				if (stripos($raw_body, '<style') !== false) $body = preg_replace("/<style.*?<\/style>/is", "", $raw_body); // in case there is only a html part
885 885
 				// remove all other html
886 886
 				$body = strip_tags($raw_body);
887
-				if(strlen($body) > $truncsize) {
887
+				if (strlen($body) > $truncsize) {
888 888
 					$body = Utils::Utf8_truncate($body, $truncsize);
889 889
 					$output->bodytruncated = 1;
890 890
 				}
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
 			else // style with bodypreferences
899 899
 			{
900 900
 				//Select body type preference
901
-				$bpReturnType = 1;//SYNC_BODYPREFERENCE_PLAIN;
901
+				$bpReturnType = 1; //SYNC_BODYPREFERENCE_PLAIN;
902 902
 				if ($bodypreference !== false) {
903 903
 					// bodypreference can occur multiple times
904 904
 					// usually we would use Utils::GetBodyPreferenceBestMatch($bodypreference);
@@ -912,12 +912,12 @@  discard block
 block discarded – undo
912 912
 					}
913 913
 */
914 914
 				}
915
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." getBodyPreferenceBestMatch: ".array2string($bpReturnType));
915
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." getBodyPreferenceBestMatch: ".array2string($bpReturnType));
916 916
 				// set the protocoll class
917 917
 				$output->asbody = new SyncBaseBody();
918 918
 
919 919
 				// return full mime-message without any (charset) conversation directly as stream
920
-				if ($bpReturnType==SYNC_BODYPREFERENCE_MIME)
920
+				if ($bpReturnType == SYNC_BODYPREFERENCE_MIME)
921 921
 				{
922 922
 					//SYNC_BODYPREFERENCE_MIME
923 923
 					$output->asbody->type = SYNC_BODYPREFERENCE_MIME;
@@ -926,58 +926,58 @@  discard block
 block discarded – undo
926 926
 					fseek($stream, 0, SEEK_SET);
927 927
 					$output->asbody->data = $stream;
928 928
 					$output->asbody->estimatedDataSize = $fstat['size'];
929
-					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." bodypreference 4=SYNC_BODYPREFERENCE_MIME=full mime message requested, size=$fstat[size]");
929
+					ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." bodypreference 4=SYNC_BODYPREFERENCE_MIME=full mime message requested, size=$fstat[size]");
930 930
 				}
931 931
 				else
932 932
 				{
933 933
 					// fetch the body (try to gather data only once)
934
-					$css ='';
935
-					$bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', null, true,$_folderName);
936
-					if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
937
-					$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
938
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$body);
939
-					if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
934
+					$css = '';
935
+					$bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', null, true, $_folderName);
936
+					if ($this->debugLevel > 2) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
937
+					$body = $this->mail->getdisplayableBody($this->mail, $bodyStruct, true, false);
938
+					if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' html_only:'.$body);
939
+					if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType'] == 'text/html')) {
940 940
 						// may be html
941
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
941
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
942 942
 						$css = $this->mail->getStyles($bodyStruct);
943
-						$output->nativebodytype=2;
943
+						$output->nativebodytype = 2;
944 944
 					} else {
945 945
 						// plain text Message
946
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
947
-						$output->nativebodytype=1;
948
-						$bodyStruct = $this->mail->getMessageBody($id,'never_display', '', null, true,$_folderName); //'only_if_no_text');
949
-						if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
950
-						$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
951
-						if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' never display html(plain text only):'.$body);
946
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
947
+						$output->nativebodytype = 1;
948
+						$bodyStruct = $this->mail->getMessageBody($id, 'never_display', '', null, true, $_folderName); //'only_if_no_text');
949
+						if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
950
+						$body = $this->mail->getdisplayableBody($this->mail, $bodyStruct, false, false);
951
+						if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' never display html(plain text only):'.$body);
952 952
 					}
953 953
 					// whatever format decode (using the correct encoding)
954
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype==2?' html ':' plain ').$body);
954
+					if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype == 2 ? ' html ' : ' plain ').$body);
955 955
 					//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
956 956
 					// prepare plaintextbody
957
-					$plainBody='';
957
+					$plainBody = '';
958 958
 					if ($output->nativebodytype == 2)
959 959
 					{
960
-						$bodyStructplain = $this->mail->getMessageBody($id,'never_display', '', null, true,$_folderName); //'only_if_no_text');
961
-						if(isset($bodyStructplain[0])&&isset($bodyStructplain[0]['error'])&&$bodyStructplain[0]['error']==1)
960
+						$bodyStructplain = $this->mail->getMessageBody($id, 'never_display', '', null, true, $_folderName); //'only_if_no_text');
961
+						if (isset($bodyStructplain[0]) && isset($bodyStructplain[0]['error']) && $bodyStructplain[0]['error'] == 1)
962 962
 						{
963 963
 							$plainBody = Api\Mail\Html::convertHTMLToText($body); // always display with preserved HTML
964 964
 						}
965 965
 						else
966 966
 						{
967
-							$plainBody = $this->mail->getdisplayableBody($this->mail,$bodyStructplain,false,false);
967
+							$plainBody = $this->mail->getdisplayableBody($this->mail, $bodyStructplain, false, false);
968 968
 						}
969 969
 					}
970 970
 					//if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".$body);
971
-					$plainBody = preg_replace("/<style.*?<\/style>/is", "", (strlen($plainBody)?$plainBody:$body));
971
+					$plainBody = preg_replace("/<style.*?<\/style>/is", "", (strlen($plainBody) ? $plainBody : $body));
972 972
 					// remove all other html
973
-					$plainBody = preg_replace("/<br.*>/is","\r\n",$plainBody);
973
+					$plainBody = preg_replace("/<br.*>/is", "\r\n", $plainBody);
974 974
 					$plainBody = strip_tags($plainBody);
975
-					if ($this->debugLevel>3 && $output->nativebodytype==1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Plain Text:'.$plainBody);
975
+					if ($this->debugLevel > 3 && $output->nativebodytype == 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Plain Text:'.$plainBody);
976 976
 					//$body = str_replace("\n","\r\n", str_replace("\r","",$body)); // do we need that?
977 977
 
978
-					if ($bpReturnType==2) //SYNC_BODYPREFERENCE_HTML
978
+					if ($bpReturnType == 2) //SYNC_BODYPREFERENCE_HTML
979 979
 					{
980
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "HTML Body with requested pref 2");
980
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "HTML Body with requested pref 2");
981 981
 						// Send HTML if requested and native type was html
982 982
 						$output->asbody->type = 2;
983 983
 						$htmlbody = '<html>'.
@@ -987,7 +987,7 @@  discard block
 block discarded – undo
987 987
 							$css.
988 988
 							'</head>'.
989 989
 							'<body>';
990
-						if ($output->nativebodytype==2)
990
+						if ($output->nativebodytype == 2)
991 991
 						{
992 992
 							// as we fetch html, and body is HTML, we may not need to handle this
993 993
 							$htmlbody .= $body;
@@ -995,14 +995,14 @@  discard block
 block discarded – undo
995 995
 						else
996 996
 						{
997 997
 							// html requested but got only plaintext, so fake html
998
-							$htmlbody .= str_replace("\n","<BR>",str_replace("\r","<BR>", str_replace("\r\n","<BR>",$plainBody)));
998
+							$htmlbody .= str_replace("\n", "<BR>", str_replace("\r", "<BR>", str_replace("\r\n", "<BR>", $plainBody)));
999 999
 						}
1000 1000
 						$htmlbody .= '</body>'.
1001 1001
 								'</html>';
1002 1002
 
1003
-						if(isset($truncsize) && strlen($htmlbody) > $truncsize)
1003
+						if (isset($truncsize) && strlen($htmlbody) > $truncsize)
1004 1004
 						{
1005
-							$htmlbody = Utils::Utf8_truncate($htmlbody,$truncsize);
1005
+							$htmlbody = Utils::Utf8_truncate($htmlbody, $truncsize);
1006 1006
 							$output->asbody->truncated = 1;
1007 1007
 						}
1008 1008
 						// output->nativebodytype is used as marker that the original message was of type ... but is now converted to, as type 2 is requested.
@@ -1013,7 +1013,7 @@  discard block
 block discarded – undo
1013 1013
 					else
1014 1014
 					{
1015 1015
 						// Send Plaintext as Fallback or if original body is plainttext
1016
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1016
+						if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1017 1017
 						/* we use plainBody (set above) instead
1018 1018
 						$bodyStruct = $this->mail->getMessageBody($id,'only_if_no_text'); //'never_display');
1019 1019
 						$plain = $this->mail->getdisplayableBody($this->mail,$bodyStruct);
@@ -1023,7 +1023,7 @@  discard block
 block discarded – undo
1023 1023
 						*/
1024 1024
 						$output->asbody->type = 1;
1025 1025
 						$output->nativebodytype = 1;
1026
-						if(isset($truncsize) &&
1026
+						if (isset($truncsize) &&
1027 1027
 							strlen($plainBody) > $truncsize)
1028 1028
 						{
1029 1029
 							$plainBody = Utils::Utf8_truncate($plainBody, $truncsize);
@@ -1042,7 +1042,7 @@  discard block
 block discarded – undo
1042 1042
 				}
1043 1043
 			}
1044 1044
 			// end AS12 Stuff
1045
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Header info:'.$headers['subject'].' from:'.$headers['date']);
1045
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' gather Header info:'.$headers['subject'].' from:'.$headers['date']);
1046 1046
 			$output->read = $headers["flags"];
1047 1047
 
1048 1048
 			$output->flag = new SyncMailFlags();
@@ -1062,9 +1062,8 @@  discard block
 block discarded – undo
1062 1062
 				$output->lastverexecuted = AS_FORWARD;
1063 1063
 			}
1064 1064
 			$output->subject = $headers['subject'];
1065
-			$output->importance = $headers['priority'] > 3 ? 0 :
1066
-				($headers['priority'] < 3 ? 2 : 1) ;
1067
-			$output->datereceived = $this->mail->_strtotime($headers['date'],'ts',true);
1065
+			$output->importance = $headers['priority'] > 3 ? 0 : ($headers['priority'] < 3 ? 2 : 1);
1066
+			$output->datereceived = $this->mail->_strtotime($headers['date'], 'ts', true);
1068 1067
 			$output->to = $headers['to_address'];
1069 1068
 			if ($headers['to']) $output->displayto = $headers['to_address']; //$headers['FETCHED_HEADER']['to_name']
1070 1069
 			$output->from = $headers['sender_address'];
@@ -1072,8 +1071,8 @@  discard block
 block discarded – undo
1072 1071
 			if (isset($headers['reply_to_address']) && $headers['reply_to_address']) $output->reply_to = $headers['reply_to_address'];
1073 1072
 
1074 1073
 			$output->messageclass = "IPM.Note";
1075
-			if (stripos($headers['mimetype'],'multipart')!== false &&
1076
-				stripos($headers['mimetype'],'signed')!== false)
1074
+			if (stripos($headers['mimetype'], 'multipart') !== false &&
1075
+				stripos($headers['mimetype'], 'signed') !== false)
1077 1076
 			{
1078 1077
 				$output->messageclass = "IPM.Note.SMIME.MultipartSigned";
1079 1078
 			}
@@ -1082,20 +1081,20 @@  discard block
 block discarded – undo
1082 1081
 			}
1083 1082
 
1084 1083
 			// start handle Attachments (include text/calendar multipart alternative)
1085
-			$attachments = $this->mail->getMessageAttachments($id, $_partID='', $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=true, true, $_folderName);
1084
+			$attachments = $this->mail->getMessageAttachments($id, $_partID = '', $_structure = null, $fetchEmbeddedImages = true, $fetchTextCalendar = true, true, $_folderName);
1086 1085
 			// Attachments should not needed for MIME messages, so skip this part if bpReturnType==4
1087
-			if (/*$bpReturnType != SYNC_BODYPREFERENCE_MIME &&*/ is_array($attachments) && count($attachments)>0)
1086
+			if (/*$bpReturnType != SYNC_BODYPREFERENCE_MIME &&*/ is_array($attachments) && count($attachments) > 0)
1088 1087
 			{
1089
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Attachments for MessageID:'.$id.' found:'.count($attachments));
1088
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' gather Attachments for MessageID:'.$id.' found:'.count($attachments));
1090 1089
 				//error_log(__METHOD__.__LINE__.array2string($attachments));
1091 1090
 				foreach ($attachments as $key => $attach)
1092 1091
 				{
1093
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1092
+					if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1094 1093
 
1095 1094
 					// pass meeting requests to calendar plugin
1096 1095
 					if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' &&
1097 1096
 						isset($GLOBALS['egw_info']['user']['apps']['calendar']) &&
1098
-						($attachment = $this->mail->getAttachment($id, $attach['partID'],0,false,false,$_folderName)) &&
1097
+						($attachment = $this->mail->getAttachment($id, $attach['partID'], 0, false, false, $_folderName)) &&
1099 1098
 						($output->meetingrequest = calendar_zpush::meetingRequest($attachment['attachment'])))
1100 1099
 					{
1101 1100
 						//overwrite the globalobjId from calendar object, as: if you delete the mail, that is
@@ -1105,7 +1104,7 @@  discard block
 block discarded – undo
1105 1104
 						$output->messageclass = "IPM.Schedule.Meeting.Request";
1106 1105
 						//$output->messageclass = "IPM.Schedule.Meeting";
1107 1106
 						unset($attachment);
1108
-						continue;	// do NOT add attachment as attachment
1107
+						continue; // do NOT add attachment as attachment
1109 1108
 					}
1110 1109
 					if (Request::GetProtocolVersion() >= 12.0) {
1111 1110
 						$attachment = new SyncBaseAttachment();
@@ -1113,33 +1112,33 @@  discard block
 block discarded – undo
1113 1112
 							$output->asattachments = array();
1114 1113
 						$attachment->estimatedDataSize = $attach['size'];
1115 1114
 						$attachment->method = 1;
1116
-						$attachment->filereference = $folderid . ":" . $id . ":" . $attach['partID'];
1115
+						$attachment->filereference = $folderid.":".$id.":".$attach['partID'];
1117 1116
 					} else {
1118 1117
 						$attachment = new SyncAttachment();
1119 1118
 						if (!isset($output->attachments) || !is_array($output->attachments))
1120 1119
 							$output->attachments = array();
1121 1120
 						$attachment->attsize = $attach['size'];
1122 1121
 						$attachment->attmethod = 1;
1123
-						$attachment->attname = $folderid . ":" . $id . ":" . $attach['partID'];//$key;
1122
+						$attachment->attname = $folderid.":".$id.":".$attach['partID']; //$key;
1124 1123
 					}
1125 1124
 
1126 1125
 					$attachment->displayname = $attach['name'];
1127 1126
 					//error_log(__METHOD__.__LINE__.'->'.$folderid . ":" . $id . ":" . $attach['partID']);
1128 1127
 
1129
-					$attachment->attoid = "";//isset($part->headers['content-id']) ? trim($part->headers['content-id']) : "";
1128
+					$attachment->attoid = ""; //isset($part->headers['content-id']) ? trim($part->headers['content-id']) : "";
1130 1129
 					//$attachment->isinline=0; // if not inline, do not use isinline
1131
-					if (!empty($attach['cid']) && $attach['cid'] <> 'NIL' )
1130
+					if (!empty($attach['cid']) && $attach['cid'] <> 'NIL')
1132 1131
 					{
1133 1132
 						if ($bpReturnType != 4 && $attach['disposition'] == 'inline')
1134 1133
 						{
1135 1134
 							$attachment->isinline = true;
1136 1135
 						}
1137 1136
 						if (Request::GetProtocolVersion() >= 12.0) {
1138
-							$attachment->method=1;
1139
-							$attachment->contentid= str_replace(array("<",">"), "",$attach['cid']);
1137
+							$attachment->method = 1;
1138
+							$attachment->contentid = str_replace(array("<", ">"), "", $attach['cid']);
1140 1139
 						} else {
1141
-							$attachment->attmethod=6;
1142
-							$attachment->attoid = str_replace(array("<",">"), "",$attach['cid']);
1140
+							$attachment->attmethod = 6;
1141
+							$attachment->attoid = str_replace(array("<", ">"), "", $attach['cid']);
1143 1142
 						}
1144 1143
 						//	ZLog::Write(LOGLEVEL_DEBUG, "'".$part->headers['content-id']."'  ".$attachment->contentid);
1145 1144
 						$attachment->contenttype = trim($attach['mimeType']);
@@ -1160,7 +1159,7 @@  discard block
 block discarded – undo
1160 1159
             // Language Code Page ID: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx
1161 1160
             $output->internetcpid = INTERNET_CPID_UTF8;
1162 1161
 
1163
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($output));
1162
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($output));
1164 1163
 //$this->debugLevel=0;
1165 1164
 			return $output;
1166 1165
 		}
@@ -1183,30 +1182,30 @@  discard block
 block discarded – undo
1183 1182
 	{
1184 1183
 		if (!class_exists('calendar_zpush'))
1185 1184
 		{
1186
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(...) no EGroupware calendar installed!");
1185
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."(...) no EGroupware calendar installed!");
1187 1186
 			return null;
1188 1187
 		}
1189 1188
 		if (!($stat = $this->StatMessage($folderid, $requestid)))
1190 1189
 		{
1191
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($requestid, '$folderid', $response) returning FALSE (can NOT stat message)");
1190
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($requestid, '$folderid', $response) returning FALSE (can NOT stat message)");
1192 1191
 			return false;
1193 1192
 		}
1194 1193
 		$ret = false;
1195
-		foreach($this->mail->getMessageAttachments($requestid, $_partID='', $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=true) as $key => $attach)
1194
+		foreach ($this->mail->getMessageAttachments($requestid, $_partID = '', $_structure = null, $fetchEmbeddedImages = true, $fetchTextCalendar = true) as $key => $attach)
1196 1195
 		{
1197 1196
 			if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' &&
1198
-				($attachment = $this->mail->getAttachment($requestid, $attach['partID'],0,false)))
1197
+				($attachment = $this->mail->getAttachment($requestid, $attach['partID'], 0, false)))
1199 1198
 			{
1200
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($requestid, '$folderid', $response) iCal found, calling now backend->MeetingResponse('$attachment[attachment]')");
1199
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($requestid, '$folderid', $response) iCal found, calling now backend->MeetingResponse('$attachment[attachment]')");
1201 1200
 
1202 1201
 				// calling backend again with iCal attachment, to let calendar add the event
1203 1202
 				$ret = $this->backend->MeetingResponse($attachment['attachment'],
1204
-					$this->backend->createID('calendar',$GLOBALS['egw_info']['user']['account_id']),
1203
+					$this->backend->createID('calendar', $GLOBALS['egw_info']['user']['account_id']),
1205 1204
 					$response);
1206 1205
 				break;
1207 1206
 			}
1208 1207
 		}
1209
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($requestid, '$folderid', $response) returning ".array2string($ret));
1208
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($requestid, '$folderid', $response) returning ".array2string($ret));
1210 1209
 		return $ret;
1211 1210
 	}
1212 1211
 
@@ -1220,9 +1219,9 @@  discard block
 block discarded – undo
1220 1219
      * @param string $attname - should contain (folder)id
1221 1220
 	 * @return SyncItemOperationsAttachment-object
1222 1221
 	 */
1223
-	function GetAttachmentData($fid,$attname) {
1224
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1225
-		return $this->_GetAttachmentData($fid,$attname);
1222
+	function GetAttachmentData($fid, $attname) {
1223
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": $fid (attname: '$attname')");
1224
+		return $this->_GetAttachmentData($fid, $attname);
1226 1225
 	}
1227 1226
 
1228 1227
 	/**
@@ -1235,9 +1234,9 @@  discard block
 block discarded – undo
1235 1234
      * @param string $attname - should contain (folder)id
1236 1235
 	 * @return SyncItemOperationsAttachment-object
1237 1236
 	 */
1238
-	function ItemOperationsGetAttachmentData($fid,$attname) {
1239
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1240
-		return $this->_GetAttachmentData($fid,$attname);
1237
+	function ItemOperationsGetAttachmentData($fid, $attname) {
1238
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": $fid (attname: '$attname')");
1239
+		return $this->_GetAttachmentData($fid, $attname);
1241 1240
 	}
1242 1241
 
1243 1242
 	/**
@@ -1249,23 +1248,23 @@  discard block
 block discarded – undo
1249 1248
      * @param string $attname - should contain (folder)id
1250 1249
 	 * @return SyncItemOperationsAttachment-object
1251 1250
 	 */
1252
-	private function _GetAttachmentData($fid,$attname)
1251
+	private function _GetAttachmentData($fid, $attname)
1253 1252
 	{
1254
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')".function_backtrace());
1253
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": $fid (attname: '$attname')".function_backtrace());
1255 1254
 		//error_log(__METHOD__.__LINE__." Fid: $fid (attname: '$attname')");
1256 1255
 		list($folderid, $id, $part) = explode(":", $attname);
1257 1256
 
1258 1257
 		$this->splitID($folderid, $account, $folder);
1259 1258
 
1260
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1259
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
1261 1260
 
1262 1261
 		$this->mail->reopen($folder);
1263
-		$attachment = $this->mail->getAttachment($id,$part,0,false,true,$folder);
1262
+		$attachment = $this->mail->getAttachment($id, $part, 0, false, true, $folder);
1264 1263
 		$SIOattachment = new SyncItemOperationsAttachment();
1265
-		fseek($attachment['attachment'], 0, SEEK_SET);	// z-push requires stream seeked to start
1264
+		fseek($attachment['attachment'], 0, SEEK_SET); // z-push requires stream seeked to start
1266 1265
 		$SIOattachment->data = $attachment['attachment'];
1267 1266
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname') Data:".$attachment['attachment']);
1268
-		if (isset($attachment['type']) )
1267
+		if (isset($attachment['type']))
1269 1268
 			$SIOattachment->contenttype = $attachment['type'];
1270 1269
 
1271 1270
 		unset($attachment);
@@ -1308,17 +1307,17 @@  discard block
 block discarded – undo
1308 1307
 	 */
1309 1308
 	function ChangeMessage($folderid, $id, $message, $contentParameters)
1310 1309
 	{
1311
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." $folderid, $id,".array2string($message).",".array2string($contentParameters));
1310
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." $folderid, $id,".array2string($message).",".array2string($contentParameters));
1312 1311
 		//unset($folderid, $id, $message, $contentParameters);
1313 1312
 		$account = $folder = null;
1314 1313
 		$this->splitID($folderid, $account, $folder);
1315 1314
 		if (isset($message->flag)) {
1316 1315
 			if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2) {
1317
-				$rv = $this->mail->flagMessages((($message->flag->flagstatus == 2) ? "flagged" : "unflagged"), $id,$folder);
1318
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . (($message->flag->flagstatus == 2) ? "flagged" : "unflagged") . "-->". $rv);
1316
+				$rv = $this->mail->flagMessages((($message->flag->flagstatus == 2) ? "flagged" : "unflagged"), $id, $folder);
1317
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." -> set ".array2string($id).' in Folder '.$folder." as ".(($message->flag->flagstatus == 2) ? "flagged" : "unflagged")."-->".$rv);
1319 1318
 			} else {
1320
-				$rv = $this->mail->flagMessages("unflagged", $id,$folder);
1321
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . "unflagged" . "-->". $rv);
1319
+				$rv = $this->mail->flagMessages("unflagged", $id, $folder);
1320
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." -> set ".array2string($id).' in Folder '.$folder." as "."unflagged"."-->".$rv);
1322 1321
 			}
1323 1322
 		}
1324 1323
 		return $this->StatMessage($folderid, $id);
@@ -1340,23 +1339,23 @@  discard block
 block discarded – undo
1340 1339
 	 */
1341 1340
 	public function MoveMessage($folderid, $id, $newfolderid, $contentParameters)
1342 1341
 	{
1343
-		unset($contentParameters);	// not used, but required by function signature
1342
+		unset($contentParameters); // not used, but required by function signature
1344 1343
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-MoveMessage: (sfid: '$folderid'  id: '$id'  dfid: '$newfolderid' )");
1345 1344
 		$account = $srcFolder = $destFolder = null;
1346 1345
 		$this->splitID($folderid, $account, $srcFolder);
1347 1346
 		$this->splitID($newfolderid, $account, $destFolder);
1348 1347
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-MoveMessage: (SourceFolder: '$srcFolder'  id: '$id'  DestFolder: '$destFolder' )");
1349
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1348
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
1350 1349
 		$this->mail->reopen($destFolder);
1351 1350
 		$status = $this->mail->getFolderStatus($destFolder);
1352 1351
 		$uidNext = $status['uidnext'];
1353 1352
 		$this->mail->reopen($srcFolder);
1354 1353
 
1355 1354
 		// move message
1356
-		$rv = $this->mail->moveMessages($destFolder,(array)$id,true,$srcFolder,true);
1357
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.": New Status of $destFolder :".array2string($status).", ReturnValOf moveMessage".array2string($rv)); // this may be true, so try using the nextUID value by examine
1355
+		$rv = $this->mail->moveMessages($destFolder, (array)$id, true, $srcFolder, true);
1356
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.": New Status of $destFolder :".array2string($status).", ReturnValOf moveMessage".array2string($rv)); // this may be true, so try using the nextUID value by examine
1358 1357
 		// return the new id "as string"
1359
-		return ($rv===true ? $uidNext : $rv[$id]) . "";
1358
+		return ($rv === true ? $uidNext : $rv[$id])."";
1360 1359
 	}
1361 1360
 
1362 1361
 	/**
@@ -1364,7 +1363,7 @@  discard block
 block discarded – undo
1364 1363
 	 *
1365 1364
 	 *  @param int $cutoffdate =null timestamp with cutoffdate, default 12 weeks
1366 1365
 	 */
1367
-	public function GetMessageList($folderid, $cutoffdate=NULL)
1366
+	public function GetMessageList($folderid, $cutoffdate = NULL)
1368 1367
 	{
1369 1368
 		if ($cutoffdate > 0)
1370 1369
 		{
@@ -1377,14 +1376,14 @@  discard block
 block discarded – undo
1377 1376
 			{
1378 1377
 				$maximumSyncRangeInDays = $GLOBALS['egw_info']['user']['preferences']['activesync']['mail-maximumSyncRange'];
1379 1378
 			}
1380
-			$cutoffdate = (is_numeric($maximumSyncRangeInDays) ? Api\DateTime::to('now','ts')-(3600*24*$maximumSyncRangeInDays):null);
1381
-			if (is_numeric($maximumSyncRangeInDays)) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' Client set no truncationdate. Using '.$maximumSyncRangeInDays.' days.'.date("d-M-Y", $cutoffdate));
1379
+			$cutoffdate = (is_numeric($maximumSyncRangeInDays) ? Api\DateTime::to('now', 'ts') - (3600 * 24 * $maximumSyncRangeInDays) : null);
1380
+			if (is_numeric($maximumSyncRangeInDays)) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' Client set no truncationdate. Using '.$maximumSyncRangeInDays.' days.'.date("d-M-Y", $cutoffdate));
1382 1381
 		}
1383 1382
 		try {
1384 1383
 			return $this->fetchMessages($folderid, $cutoffdate);
1385 1384
 		} catch (Exception $e)
1386 1385
 		{
1387
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' failed for '.$e->getMessage().($e->details?$e->details:''));
1386
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' failed for '.$e->getMessage().($e->details ? $e->details : ''));
1388 1387
 			return array();
1389 1388
 		}
1390 1389
 	}
@@ -1402,11 +1401,11 @@  discard block
 block discarded – undo
1402 1401
 	 * @param boolean $return_all_headers =false true: additinal contain all headers eg. "subject"
1403 1402
 	 * @return array uid => array StatMessage($folderid, $_id)
1404 1403
 	 */
1405
-	private function fetchMessages($folderid, $cutoffdate=NULL, $_id=NULL, $return_all_headers=false)
1404
+	private function fetchMessages($folderid, $cutoffdate = NULL, $_id = NULL, $return_all_headers = false)
1406 1405
 	{
1407 1406
 		static $headers = array();
1408 1407
 
1409
-		if ($this->debugLevel>1) $gstarttime = microtime (true);
1408
+		if ($this->debugLevel > 1) $gstarttime = microtime(true);
1410 1409
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
1411 1410
 		$rv_messages = array();
1412 1411
 		// if the message is still available within the class, we use it instead of fetching it again
@@ -1417,64 +1416,64 @@  discard block
 block discarded – undo
1417 1416
 		}
1418 1417
 		else
1419 1418
 		{
1420
-			$headers = array();	// clear cache to not use too much memory
1419
+			$headers = array(); // clear cache to not use too much memory
1421 1420
 
1422
-			if ($this->debugLevel>1) $starttime = microtime (true);
1421
+			if ($this->debugLevel > 1) $starttime = microtime(true);
1423 1422
 			$this->_connect($this->account);
1424
-			if ($this->debugLevel>1)
1423
+			if ($this->debugLevel > 1)
1425 1424
 			{
1426 1425
 				$endtime = microtime(true) - $starttime;
1427
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " connect took : ".$endtime.' for account:'.$this->account);
1426
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." connect took : ".$endtime.' for account:'.$this->account);
1428 1427
 			}
1429 1428
 			$messagelist = $_filter = array();
1430 1429
 			// if not connected, any further action must fail
1431
-			if (!empty($cutoffdate)) $_filter = array('status'=>array('UNDELETED'),'range'=>"SINCE",'date'=> date("d-M-Y", $cutoffdate));
1432
-			if ($this->debugLevel>1) $starttime = microtime (true);
1430
+			if (!empty($cutoffdate)) $_filter = array('status'=>array('UNDELETED'), 'range'=>"SINCE", 'date'=> date("d-M-Y", $cutoffdate));
1431
+			if ($this->debugLevel > 1) $starttime = microtime(true);
1433 1432
 			$account = $_folderName = $id = null;
1434
-			$this->splitID($folderid,$account,$_folderName,$id);
1435
-			if ($this->debugLevel>1)
1433
+			$this->splitID($folderid, $account, $_folderName, $id);
1434
+			if ($this->debugLevel > 1)
1436 1435
 			{
1437 1436
 				$endtime = microtime(true) - $starttime;
1438
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " splitID took : ".$endtime.' for FolderID:'.$folderid);
1437
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." splitID took : ".$endtime.' for FolderID:'.$folderid);
1439 1438
 			}
1440
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1441
-			if ($this->debugLevel>1) $starttime = microtime (true);
1442
-			$_numberOfMessages = (empty($cutoffdate)?250:99999);
1443
-			$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=1, $_numberOfMessages, $_sort=0, $_reverse=false, $_filter, $_id);
1444
-			if ($this->debugLevel>1)
1439
+			if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1440
+			if ($this->debugLevel > 1) $starttime = microtime(true);
1441
+			$_numberOfMessages = (empty($cutoffdate) ? 250 : 99999);
1442
+			$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage = 1, $_numberOfMessages, $_sort = 0, $_reverse = false, $_filter, $_id);
1443
+			if ($this->debugLevel > 1)
1445 1444
 			{
1446 1445
 				$endtime = microtime(true) - $starttime;
1447
-				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " getHeaders call took : ".$endtime.' for FolderID:'.$_folderName);
1446
+				ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." getHeaders call took : ".$endtime.' for FolderID:'.$_folderName);
1448 1447
 			}
1449 1448
 		}
1450
-		if ($_id == NULL && $this->debugLevel>1)  ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." found :". count($rv_messages['header']));
1449
+		if ($_id == NULL && $this->debugLevel > 1)  ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." found :".count($rv_messages['header']));
1451 1450
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Result:'.array2string($rv_messages));
1452 1451
 		$messagelist = array();
1453
-		if (!isset($rv_messages['header'])||empty($rv_messages['header'])) return $messagelist;
1452
+		if (!isset($rv_messages['header']) || empty($rv_messages['header'])) return $messagelist;
1454 1453
 		//if ($_returnModHash) $messageFolderHash = array();
1455 1454
 		foreach ((array)$rv_messages['header'] as $k => $vars)
1456 1455
 		{
1457
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']);
1456
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']);
1458 1457
 			$headers[$vars['uid']] = $vars;
1459
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1458
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1460 1459
 			if (!empty($vars['deleted'])) continue; // cut of deleted messages
1461 1460
 			if ($cutoffdate && $vars['date'] < $cutoffdate) continue; // message is out of range for cutoffdate, ignore it
1462
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']);
1461
+			if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']);
1463 1462
 			$mess = $return_all_headers ? $vars : array();
1464 1463
 			$mess["mod"] = self::doFlagsMod($vars).$vars['date'];
1465 1464
 			$mess["id"] = $vars['uid'];
1466 1465
 			// 'seen' aka 'read' is the only flag we want to know about
1467 1466
 			$mess["flags"] = 0;
1468 1467
 			// outlook supports additional flags, set them to 0
1469
-			if($vars["seen"]) $mess["flags"] = 1;
1470
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($mess));
1468
+			if ($vars["seen"]) $mess["flags"] = 1;
1469
+			if ($this->debugLevel > 3) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($mess));
1471 1470
 			$messagelist[$vars['uid']] = $mess;
1472 1471
 			unset($mess);
1473 1472
 		}
1474
-		if ($this->debugLevel>1)
1473
+		if ($this->debugLevel > 1)
1475 1474
 		{
1476 1475
 			$endtime = microtime(true) - $gstarttime;
1477
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " total time used : ".$endtime.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1476
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__." total time used : ".$endtime.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1478 1477
 		}
1479 1478
 		return $messagelist;
1480 1479
 	}
@@ -1525,32 +1524,32 @@  discard block
 block discarded – undo
1525 1524
 	public function getSearchResultsMailbox($_searchquery)
1526 1525
 	{
1527 1526
 		//$this->debugLevel=1;
1528
-		$searchquery=$_searchquery->GetDataArray();
1527
+		$searchquery = $_searchquery->GetDataArray();
1529 1528
 		if (!is_array($searchquery)) return array();
1530
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($searchquery));
1529
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.array2string($searchquery));
1531 1530
 
1532 1531
 		if (isset($searchquery['searchrebuildresults'])) {
1533 1532
 			$rebuildresults = $searchquery['searchrebuildresults'];
1534 1533
 		} else {
1535 1534
 			$rebuildresults = false;
1536 1535
 		}
1537
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'RebuildResults ['.$rebuildresults.']' );
1536
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, 'RebuildResults ['.$rebuildresults.']');
1538 1537
 
1539 1538
 		if (isset($searchquery['deeptraversal'])) {
1540 1539
 			$deeptraversal = $searchquery['deeptraversal'];
1541 1540
 		} else {
1542 1541
 			$deeptraversal = false;
1543 1542
 		}
1544
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'DeepTraversal ['.$deeptraversal.']' );
1543
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, 'DeepTraversal ['.$deeptraversal.']');
1545 1544
 
1546 1545
 		if (isset($searchquery['searchrange'])) {
1547
-			$range = explode("-",$_searchquery->GetSearchRange());
1548
-			$start =$range[0] + 1;
1546
+			$range = explode("-", $_searchquery->GetSearchRange());
1547
+			$start = $range[0] + 1;
1549 1548
 			$limit = $range[1] - $range[0] + 1;
1550 1549
 		} else {
1551 1550
 			$range = false;
1552 1551
 		}
1553
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'Range ['.print_r($range, true).']' );
1552
+		if ($this->debugLevel > 0) ZLog::Write(LOGLEVEL_DEBUG, 'Range ['.print_r($range, true).']');
1554 1553
 
1555 1554
 		//foreach($searchquery['query'] as $k => $value) {
1556 1555
 		//	$query = $value;
@@ -1573,15 +1572,15 @@  discard block
 block discarded – undo
1573 1572
 		}
1574 1573
 		if (!$folderid)
1575 1574
 		{
1576
-			$_folderName = ($this->mail->sessionData['mailbox']?$this->mail->sessionData['mailbox']:'INBOX');
1577
-			$folderid = $this->createID($account=0,$_folderName);
1575
+			$_folderName = ($this->mail->sessionData['mailbox'] ? $this->mail->sessionData['mailbox'] : 'INBOX');
1576
+			$folderid = $this->createID($account = 0, $_folderName);
1578 1577
 		}
1579
-		$rv = $this->splitID($folderid,$account,$_folderName,$id);
1580
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ProfileID:'.self::$profileID.' FolderID:'.$folderid.' Foldername:'.$_folderName);
1578
+		$rv = $this->splitID($folderid, $account, $_folderName, $id);
1579
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' ProfileID:'.self::$profileID.' FolderID:'.$folderid.' Foldername:'.$_folderName);
1581 1580
 		$this->_connect($account);
1582 1581
 		// this should not be needed ???
1583
-		Mail::$supportsORinQuery[self::$profileID]=true; // trigger quicksearch (if possible)
1584
-		$_filter = array('type'=> (Mail::$supportsORinQuery[self::$profileID]?'quick':'subject'),
1582
+		Mail::$supportsORinQuery[self::$profileID] = true; // trigger quicksearch (if possible)
1583
+		$_filter = array('type'=> (Mail::$supportsORinQuery[self::$profileID] ? 'quick' : 'subject'),
1585 1584
 						 'string'=> $searchText,
1586 1585
 						 'status'=>'any'
1587 1586
 						);
@@ -1596,22 +1595,22 @@  discard block
 block discarded – undo
1596 1595
 		 * 		[searchvalueless] => 2015-07-14T15:11:00.000Z , BEFORE
1597 1596
 		 */
1598 1597
 			$_filter['range'] = "BETWEEN";
1599
-			list($sincedate,$crap) = explode('T',$searchquery['searchvaluegreater']);
1600
-			list($beforedate,$crap) = explode('T',$searchquery['searchvalueless']);
1601
-			$_filter['before'] = date("d-M-Y", Api\DateTime::to($beforedate,'ts'));
1602
-			$_filter['since'] = date("d-M-Y", Api\DateTime::to($sincedate,'ts'));
1598
+			list($sincedate, $crap) = explode('T', $searchquery['searchvaluegreater']);
1599
+			list($beforedate, $crap) = explode('T', $searchquery['searchvalueless']);
1600
+			$_filter['before'] = date("d-M-Y", Api\DateTime::to($beforedate, 'ts'));
1601
+			$_filter['since'] = date("d-M-Y", Api\DateTime::to($sincedate, 'ts'));
1603 1602
 		}
1604 1603
 		//$_filter[] = array('type'=>"SINCE",'string'=> date("d-M-Y", $cutoffdate));
1605
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1606
-		$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=($range?$start:1), $_numberOfMessages=($limit?$limit:9999999), $_sort=0, $_reverse=false, $_filter, $_id=NULL);
1604
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1605
+		$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage = ($range ? $start : 1), $_numberOfMessages = ($limit ? $limit : 9999999), $_sort = 0, $_reverse = false, $_filter, $_id = NULL);
1607 1606
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($rv_messages));
1608
-		$list=array();
1607
+		$list = array();
1609 1608
 
1610 1609
 		$cnt = count($rv_messages['header']);
1611 1610
 		//$list['status'] = 1;
1612 1611
 		$list['searchtotal'] = $cnt;
1613 1612
 		$list["range"] = $_searchquery->GetSearchRange();
1614
-		foreach((array)$rv_messages['header'] as $i => $vars)
1613
+		foreach ((array)$rv_messages['header'] as $i => $vars)
1615 1614
 		{
1616 1615
 			$list[] = array(
1617 1616
 				"class" => "Email",
@@ -1631,20 +1630,20 @@  discard block
 block discarded – undo
1631 1630
 	 * @param string $folder
1632 1631
 	 * @return string
1633 1632
 	 */
1634
-	private function getParentID($account,$folder)
1633
+	private function getParentID($account, $folder)
1635 1634
 	{
1636 1635
 		$this->_connect($account);
1637
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
1636
+		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true, false);
1638 1637
 
1639 1638
 		$mailFolder = $this->folders[$folder];
1640 1639
 		if (!isset($mailFolder)) return false;
1641
-		$delimiter = (isset($mailFolder->delimiter)?$mailFolder->delimiter:$this->mail->getHierarchyDelimiter());
1642
-		$parent = explode($delimiter,$folder);
1640
+		$delimiter = (isset($mailFolder->delimiter) ? $mailFolder->delimiter : $this->mail->getHierarchyDelimiter());
1641
+		$parent = explode($delimiter, $folder);
1643 1642
 		array_pop($parent);
1644
-		$parent = implode($delimiter,$parent);
1643
+		$parent = implode($delimiter, $parent);
1645 1644
 
1646 1645
 		$id = $parent && $this->folders[$parent] ? $this->createID($account, $parent) : '0';
1647
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$folder') --> parent=$parent --> $id");
1646
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$folder') --> parent=$parent --> $id");
1648 1647
 		return $id;
1649 1648
 	}
1650 1649
 
@@ -1664,48 +1663,48 @@  discard block
 block discarded – undo
1664 1663
 			$account = $folder = null;
1665 1664
 			$this->splitID($id, $account, $folder);
1666 1665
 		}
1667
-		catch(Exception $e) {
1668
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' failed for '.$e->getMessage());
1669
-			return $folderObj=false;
1666
+		catch (Exception $e) {
1667
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' failed for '.$e->getMessage());
1668
+			return $folderObj = false;
1670 1669
 		}
1671 1670
 		$this->_connect($account);
1672
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
1671
+		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true, false);
1673 1672
 
1674 1673
 		$mailFolder = $this->folders[$folder];
1675
-		if (!isset($mailFolder)) return $folderObj=false;
1674
+		if (!isset($mailFolder)) return $folderObj = false;
1676 1675
 
1677 1676
 		$folderObj = new SyncFolder();
1678 1677
 		$folderObj->serverid = $id;
1679
-		$folderObj->parentid = $this->getParentID($account,$folder);
1678
+		$folderObj->parentid = $this->getParentID($account, $folder);
1680 1679
 		$folderObj->displayname = $mailFolder->shortDisplayName;
1681
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
1680
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
1682 1681
 		// get folder-type
1683
-		foreach($this->folders as $inbox => $mailFolder) break;
1682
+		foreach ($this->folders as $inbox => $mailFolder) break;
1684 1683
 		if ($folder == $inbox)
1685 1684
 		{
1686 1685
 			$folderObj->type = SYNC_FOLDER_TYPE_INBOX;
1687 1686
 		}
1688
-		elseif($this->mail->isDraftFolder($folder, false, true))
1687
+		elseif ($this->mail->isDraftFolder($folder, false, true))
1689 1688
 		{
1690 1689
 			//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' isDraft');
1691 1690
 			$folderObj->type = SYNC_FOLDER_TYPE_DRAFTS;
1692 1691
 			$folderObj->parentid = 0; // required by devices
1693 1692
 		}
1694
-		elseif($this->mail->isTrashFolder($folder, false, true))
1693
+		elseif ($this->mail->isTrashFolder($folder, false, true))
1695 1694
 		{
1696 1695
 			$folderObj->type = SYNC_FOLDER_TYPE_WASTEBASKET;
1697 1696
 			$this->_wasteID = $folder;
1698 1697
 			//error_log(__METHOD__.__LINE__.' TrashFolder:'.$this->_wasteID);
1699 1698
 			$folderObj->parentid = 0; // required by devices
1700 1699
 		}
1701
-		elseif($this->mail->isSentFolder($folder, false, true))
1700
+		elseif ($this->mail->isSentFolder($folder, false, true))
1702 1701
 		{
1703 1702
 			$folderObj->type = SYNC_FOLDER_TYPE_SENTMAIL;
1704 1703
 			$folderObj->parentid = 0; // required by devices
1705 1704
 			$this->_sentID = $folder;
1706 1705
 			//error_log(__METHOD__.__LINE__.' SentFolder:'.$this->_sentID);
1707 1706
 		}
1708
-		elseif($this->mail->isOutbox($folder, false, true))
1707
+		elseif ($this->mail->isOutbox($folder, false, true))
1709 1708
 		{
1710 1709
 			//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' isOutbox');
1711 1710
 			$folderObj->type = SYNC_FOLDER_TYPE_OUTBOX;
@@ -1717,7 +1716,7 @@  discard block
 block discarded – undo
1717 1716
 			$folderObj->type = SYNC_FOLDER_TYPE_USER_MAIL;
1718 1717
 		}
1719 1718
 
1720
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
1719
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
1721 1720
 		return $folderObj;
1722 1721
 	}
1723 1722
 
@@ -1765,18 +1764,18 @@  discard block
 block discarded – undo
1765 1764
 
1766 1765
 		if ($type != 'mail') return false;
1767 1766
 
1768
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1767
+		if (!isset($this->mail)) $this->mail = Mail::getInstance(false, self::$profileID, true, false, true);
1769 1768
 
1770 1769
         $this->mail->reopen($folder);
1771 1770
 
1772
-		if (!($status = $this->mail->getFolderStatus($folder,$ignoreStatusCache=true)))
1771
+		if (!($status = $this->mail->getFolderStatus($folder, $ignoreStatusCache = true)))
1773 1772
 		{
1774
-            ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": could not stat folder $folder ");
1773
+            ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.": could not stat folder $folder ");
1775 1774
             return false;
1776 1775
         }
1777
-		$syncstate = "M:". $status['messages'] ."-R:". $status['recent'] ."-U:". $status['unseen']."-NUID:".$status['uidnext']."-UIDV:".$status['uidvalidity'];
1776
+		$syncstate = "M:".$status['messages']."-R:".$status['recent']."-U:".$status['unseen']."-NUID:".$status['uidnext']."-UIDV:".$status['uidvalidity'];
1778 1777
 
1779
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($folderid, ...) $folder ($account) returning ".array2string($syncstate));
1778
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($folderid, ...) $folder ($account) returning ".array2string($syncstate));
1780 1779
 		return array();
1781 1780
 	}
1782 1781
 
@@ -1789,8 +1788,8 @@  discard block
 block discarded – undo
1789 1788
 	function GetWasteBasket()
1790 1789
 	{
1791 1790
 		$this->_connect($this->account);
1792
-		$id = $this->createID($account=0, $this->_wasteID);
1793
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."() account=$this->account returned $id for folder $this->_wasteID");
1791
+		$id = $this->createID($account = 0, $this->_wasteID);
1792
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__."() account=$this->account returned $id for folder $this->_wasteID");
1794 1793
 		return $id;
1795 1794
 	}
1796 1795
 
@@ -1811,7 +1810,7 @@  discard block
 block discarded – undo
1811 1810
      */
1812 1811
     public function DeleteMessage($folderid, $id, $contentParameters)
1813 1812
 	{
1814
-		unset($contentParameters);	// not used, but required by function signature
1813
+		unset($contentParameters); // not used, but required by function signature
1815 1814
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-DeleteMessage: (fid: '$folderid'  id: '$id' )");
1816 1815
 		/*
1817 1816
 		$this->imap_reopenFolder($folderid);
@@ -1822,7 +1821,7 @@  discard block
 block discarded – undo
1822 1821
 		// we may have to split folderid
1823 1822
 		$account = $folder = null;
1824 1823
 		$this->splitID($folderid, $account, $folder);
1825
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' '.$folderid.'->'.$folder);
1824
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__.' '.$folderid.'->'.$folder);
1826 1825
 		$_messageUID = (array)$id;
1827 1826
 
1828 1827
 		$this->_connect($this->account);
@@ -1834,9 +1833,9 @@  discard block
 block discarded – undo
1834 1833
 		catch (Api\Exception $e)
1835 1834
 		{
1836 1835
 			$error = $e->getMessage();
1837
-			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." $_messageUID, $folder ->".$error);
1836
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.__LINE__." $_messageUID, $folder ->".$error);
1838 1837
 			// if the server thinks the message does not exist report deletion as success
1839
-			if (stripos($error,'[NONEXISTENT]')!==false) return true;
1838
+			if (stripos($error, '[NONEXISTENT]') !== false) return true;
1840 1839
 			return false;
1841 1840
 		}
1842 1841
 
@@ -1870,15 +1869,15 @@  discard block
 block discarded – undo
1870 1869
      */
1871 1870
     public function SetReadFlag($folderid, $id, $flags, $contentParameters)
1872 1871
 	{
1873
-		unset($contentParameters);	// not used, but required by function signature
1872
+		unset($contentParameters); // not used, but required by function signature
1874 1873
 		// ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag: (fid: '$folderid'  id: '$id'  flags: '$flags' )");
1875 1874
 		$account = $folder = null;
1876 1875
 		$this->splitID($folderid, $account, $folder);
1877 1876
 
1878 1877
 		$_messageUID = (array)$id;
1879 1878
 		$this->_connect($this->account);
1880
-		$rv = $this->mail->flagMessages((($flags) ? "read" : "unread"), $_messageUID,$folder);
1881
-		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as " . (($flags) ? "read" : "unread") . "-->". $rv);
1879
+		$rv = $this->mail->flagMessages((($flags) ? "read" : "unread"), $_messageUID, $folder);
1880
+		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as ".(($flags) ? "read" : "unread")."-->".$rv);
1882 1881
 
1883 1882
 		return $rv;
1884 1883
 	}
@@ -1895,7 +1894,7 @@  discard block
 block discarded – undo
1895 1894
 	 */
1896 1895
 	public function ChangeFolder($id, $oldid, $displayname, $type)
1897 1896
 	{
1898
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$id', '$oldid', '$displayname', $type) NOT supported!");
1897
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$id', '$oldid', '$displayname', $type) NOT supported!");
1899 1898
 		return false;
1900 1899
 	}
1901 1900
 
@@ -1910,7 +1909,7 @@  discard block
 block discarded – undo
1910 1909
 	 */
1911 1910
 	public function DeleteFolder($parentid, $id)
1912 1911
 	{
1913
-		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$parentid', '$id') NOT supported!");
1912
+		ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$parentid', '$id') NOT supported!");
1914 1913
 		return false;
1915 1914
 	}
1916 1915
 
@@ -1930,8 +1929,8 @@  discard block
 block discarded – undo
1930 1929
 		$this->_connect($this->account);
1931 1930
 		$account = $folder = null;
1932 1931
 		$this->splitID($folderid, $account, $folder);
1933
-		$rv = $this->mail->flagMessages((($flags->flagstatus == 2) ? "flagged" : "unflagged"), $_messageUID,$folder);
1934
-		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetFlaggedFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as " . (($flags->flagstatus == 2) ? "flagged" : "unflagged") . "-->". $rv);
1932
+		$rv = $this->mail->flagMessages((($flags->flagstatus == 2) ? "flagged" : "unflagged"), $_messageUID, $folder);
1933
+		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetFlaggedFlag -> set ".array2string($_messageUID).' in Folder '.$folder." as ".(($flags->flagstatus == 2) ? "flagged" : "unflagged")."-->".$rv);
1935 1934
 
1936 1935
 		return $rv;
1937 1936
 	}
@@ -1945,17 +1944,17 @@  discard block
 block discarded – undo
1945 1944
 	 * @return string
1946 1945
 	 * @throws Api\Exception\WrongParameter
1947 1946
 	 */
1948
-	private function createID($account,$folder,$id=0)
1947
+	private function createID($account, $folder, $id = 0)
1949 1948
 	{
1950 1949
 		if (!is_numeric($folder))
1951 1950
 		{
1952 1951
 			// convert string $folder in numeric id
1953
-			$folder = $this->folder2hash($account,$f=$folder);
1952
+			$folder = $this->folder2hash($account, $f = $folder);
1954 1953
 		}
1955 1954
 
1956 1955
 		$str = $this->backend->createID($account, $folder, $id);
1957 1956
 
1958
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
1957
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
1959 1958
 
1960 1959
 		return $str;
1961 1960
 	}
@@ -1969,14 +1968,14 @@  discard block
 block discarded – undo
1969 1968
 	 * @param int &$id=null
1970 1969
 	 * @throws Api\Exception\WrongParameter
1971 1970
 	 */
1972
-	private function splitID($str,&$account,&$folder,&$id=null)
1971
+	private function splitID($str, &$account, &$folder, &$id = null)
1973 1972
 	{
1974 1973
 		$this->backend->splitID($str, $account, $folder, $id);
1975 1974
 
1976 1975
 		// convert numeric folder-id back to folder name
1977
-		$folder = $this->hash2folder($account,$f=$folder);
1976
+		$folder = $this->hash2folder($account, $f = $folder);
1978 1977
 
1979
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$str','$account','$folder',$id)");
1978
+		if ($this->debugLevel > 1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__."('$str','$account','$folder',$id)");
1980 1979
 	}
1981 1980
 
1982 1981
 	/**
@@ -1993,9 +1992,9 @@  discard block
 block discarded – undo
1993 1992
 	 * @param string $folder
1994 1993
 	 * @return int
1995 1994
 	 */
1996
-	private function folder2hash($account,$folder)
1995
+	private function folder2hash($account, $folder)
1997 1996
 	{
1998
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
1997
+		if (!isset($this->folderHashes)) $this->readFolderHashes();
1999 1998
 
2000 1999
 		if (($index = array_search($folder, (array)$this->folderHashes[$account])) === false)
2001 2000
 		{
@@ -2016,9 +2015,9 @@  discard block
 block discarded – undo
2016 2015
 	 * @param int $index
2017 2016
 	 * @return string NULL if not used so far
2018 2017
 	 */
2019
-	private function hash2folder($account,$index)
2018
+	private function hash2folder($account, $index)
2020 2019
 	{
2021
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
2020
+		if (!isset($this->folderHashes)) $this->readFolderHashes();
2022 2021
 
2023 2022
 		return isset($this->folderHashes[$account]) ? $this->folderHashes[$account][$index] : null;
2024 2023
 	}
@@ -2055,9 +2054,9 @@  discard block
 block discarded – undo
2055 2054
 			if ((file_exists($file = $this->hashFile()) || file_exists($file = $this->hashFile(true))) &&
2056 2055
 				($hashes = file_get_contents($file)))
2057 2056
 			{
2058
-				$this->folderHashes = json_decode($hashes,true);
2057
+				$this->folderHashes = json_decode($hashes, true);
2059 2058
 				// fallback in case hashes have been serialized instead of being json-encoded
2060
-				if (json_last_error()!=JSON_ERROR_NONE)
2059
+				if (json_last_error() != JSON_ERROR_NONE)
2061 2060
 				{
2062 2061
 					//error_log(__METHOD__.__LINE__." error decoding with json");
2063 2062
 					$this->folderHashes = unserialize($hashes);
@@ -2103,9 +2102,9 @@  discard block
 block discarded – undo
2103 2102
 	 * @param boolean $old =false true: return old / pre-15 hash-file
2104 2103
 	 * @throws Api\Exception\AssertionFailed
2105 2104
 	 */
2106
-	private function hashFile($old=false)
2105
+	private function hashFile($old = false)
2107 2106
 	{
2108
-		if (!($dev_id=Request::GetDeviceID()))
2107
+		if (!($dev_id = Request::GetDeviceID()))
2109 2108
 		{
2110 2109
 			throw new Api\Exception\AssertionFailed(__METHOD__."() no DeviceID set!");
2111 2110
 		}
Please login to merge, or discard this patch.
Braces   +595 added lines, -175 removed lines patch added patch discarded remove patch
@@ -84,29 +84,47 @@  discard block
 block discarded – undo
84 84
 	 */
85 85
 	public function __construct(activesync_backend $backend)
86 86
 	{
87
-		if ($GLOBALS['egw_setup']) return;
87
+		if ($GLOBALS['egw_setup'])
88
+		{
89
+			return;
90
+		}
88 91
 
89 92
 		//$this->debugLevel=2;
90 93
 		$this->backend = $backend;
91 94
 		if (!isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']))
92 95
 		{
93
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Noprefs set: using 0 as default');
96
+			if ($this->debugLevel>1)
97
+			{
98
+				error_log(__METHOD__.__LINE__.' Noprefs set: using 0 as default');
99
+			}
94 100
 			// globals preferences add appname varname value
95 101
 			$GLOBALS['egw']->preferences->add('activesync','mail-ActiveSyncProfileID',0,'user');
96 102
 			// save prefs
97 103
 			$GLOBALS['egw']->preferences->save_repository(true);
98 104
 		}
99
-		if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' ActiveProfileID:'.array2string(self::$profileID));
105
+		if ($this->debugLevel>1)
106
+		{
107
+			error_log(__METHOD__.__LINE__.' ActiveProfileID:'.array2string(self::$profileID));
108
+		}
100 109
 
101 110
 		if (is_null(self::$profileID))
102 111
 		{
103
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' self::ProfileID isNUll:'.array2string(self::$profileID));
112
+			if ($this->debugLevel>1)
113
+			{
114
+				error_log(__METHOD__.__LINE__.' self::ProfileID isNUll:'.array2string(self::$profileID));
115
+			}
104 116
 			self::$profileID =& Api\Cache::getSession('mail','activeSyncProfileID');
105
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' ActiveProfileID (after reading Cache):'.array2string(self::$profileID));
117
+			if ($this->debugLevel>1)
118
+			{
119
+				error_log(__METHOD__.__LINE__.' ActiveProfileID (after reading Cache):'.array2string(self::$profileID));
120
+			}
106 121
 		}
107 122
 		if (isset($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']))
108 123
 		{
109
-			if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Pref for ProfileID:'.array2string($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']));
124
+			if ($this->debugLevel>1)
125
+			{
126
+				error_log(__METHOD__.__LINE__.' Pref for ProfileID:'.array2string($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID']));
127
+			}
110 128
 			if ($GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'] == 'G')
111 129
 			{
112 130
 				self::$profileID = 'G'; // this should trigger the fetch of the first negative profile (or if no negative profile is available the firstb there is)
@@ -116,7 +134,10 @@  discard block
 block discarded – undo
116 134
 				self::$profileID = (int)$GLOBALS['egw_info']['user']['preferences']['activesync']['mail-ActiveSyncProfileID'];
117 135
 			}
118 136
 		}
119
-		if ($this->debugLevel>1) error_log(__METHOD__.__LINE__.' Profile Selected (after reading Prefs):'.array2string(self::$profileID));
137
+		if ($this->debugLevel>1)
138
+		{
139
+			error_log(__METHOD__.__LINE__.' Profile Selected (after reading Prefs):'.array2string(self::$profileID));
140
+		}
120 141
 
121 142
 		// verify we are on an existing profile, if not running in setup (settings can not be static according to interface!)
122 143
 		if (!isset($GLOBALS['egw_setup']))
@@ -129,7 +150,10 @@  discard block
 block discarded – undo
129 150
 				self::$profileID = Mail\Account::get_default_acc_id();
130 151
 			}
131 152
 		}
132
-		if ($this->debugLevel>0) error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.self::$profileID);
153
+		if ($this->debugLevel>0)
154
+		{
155
+			error_log(__METHOD__.'::'.__LINE__.' ProfileSelected:'.self::$profileID);
156
+		}
133 157
 		//$this->debugLevel=0;
134 158
 	}
135 159
 
@@ -229,8 +253,14 @@  discard block
 block discarded – undo
229 253
 				$this->_connect(0,true);
230 254
 				$this->_disconnect();
231 255
 
232
-				if (!$this->_wasteID) $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('trash').'</b>');
233
-				if (!$this->_sentID) $errors[] = lang('No valid %1 folder configured!', '<b>'.lang('send').'</b>');
256
+				if (!$this->_wasteID)
257
+				{
258
+					$errors[] = lang('No valid %1 folder configured!', '<b>'.lang('trash').'</b>');
259
+				}
260
+				if (!$this->_sentID)
261
+				{
262
+					$errors[] = lang('No valid %1 folder configured!', '<b>'.lang('send').'</b>');
263
+				}
234 264
 			}
235 265
 			catch(Exception $e) {
236 266
 				$errors[] = lang('Can not open IMAP connection').': '.$e->getMessage();
@@ -252,8 +282,14 @@  discard block
 block discarded – undo
252 282
 	 */
253 283
 	private function _connect($account=0)
254 284
 	{
255
-		if (!$account) $account = self::$profileID ? self::$profileID : 0;
256
-		if ($this->mail && $this->account != $account) $this->_disconnect();
285
+		if (!$account)
286
+		{
287
+			$account = self::$profileID ? self::$profileID : 0;
288
+		}
289
+		if ($this->mail && $this->account != $account)
290
+		{
291
+			$this->_disconnect();
292
+		}
257 293
 
258 294
 		$this->_wasteID = false;
259 295
 		$this->_sentID = false;
@@ -264,12 +300,18 @@  discard block
 block discarded – undo
264 300
 			// todo: tell mail which account to use
265 301
 			//error_log(__METHOD__.__LINE__.' create object with ProfileID:'.array2string(self::$profileID));
266 302
 			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
267
-			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) self::$profileID = $this->mail->icServer->ImapServerId;
303
+			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId))
304
+			{
305
+				self::$profileID = $this->mail->icServer->ImapServerId;
306
+			}
268 307
 		}
269 308
 		else
270 309
 		{
271 310
 			//error_log(__METHOD__.__LINE__." connect with profileID: ".self::$profileID);
272
-			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId)) self::$profileID = $this->mail->icServer->ImapServerId;
311
+			if (self::$profileID == 0 && isset($this->mail->icServer->ImapServerId) && !empty($this->mail->icServer->ImapServerId))
312
+			{
313
+				self::$profileID = $this->mail->icServer->ImapServerId;
314
+			}
273 315
 		}
274 316
 		$this->mail->openConnection(self::$profileID,false);
275 317
 
@@ -286,8 +328,14 @@  discard block
 block discarded – undo
286 328
 	 */
287 329
 	private function _disconnect()
288 330
 	{
289
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__);
290
-		if ($this->mail) $this->mail->closeConnection();
331
+		if ($this->debugLevel>0)
332
+		{
333
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__);
334
+		}
335
+		if ($this->mail)
336
+		{
337
+			$this->mail->closeConnection();
338
+		}
291 339
 
292 340
 		unset($this->mail);
293 341
 		unset($this->account);
@@ -302,24 +350,43 @@  discard block
 block discarded – undo
302 350
 	public function GetFolderList()
303 351
 	{
304 352
 		$folderlist = array();
305
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
353
+		if ($this->debugLevel>0)
354
+		{
355
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
356
+		}
306 357
 		/*foreach($available_accounts as $account)*/ $account = 0;
307 358
 		{
308 359
 			$this->_connect($account);
309
-			if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false,$_alwaysGetDefaultFolders=true);
310
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($this->folders));
360
+			if (!isset($this->folders))
361
+			{
362
+				$this->folders = $this->mail->getFolderObjects(true,false,$_alwaysGetDefaultFolders=true);
363
+			}
364
+			if ($this->debugLevel>1)
365
+			{
366
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($this->folders));
367
+			}
311 368
 
312
-			foreach ($this->folders as $folder => $folderObj) {
313
-				if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' folder='.$folder);
369
+			foreach ($this->folders as $folder => $folderObj)
370
+			{
371
+				if ($this->debugLevel>1)
372
+				{
373
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' folder='.$folder);
374
+				}
314 375
 				$folderlist[] = $f = array(
315 376
 					'id'     => $this->createID($account,$folder),
316 377
 					'mod'    => $folderObj->shortDisplayName,
317 378
 					'parent' => $this->getParentID($account,$folder),
318 379
 				);
319
-				if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($f));
380
+				if ($this->debugLevel>1)
381
+				{
382
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($f));
383
+				}
320 384
 			}
321 385
 		}
322
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($folderlist));
386
+		if ($this->debugLevel>0)
387
+		{
388
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."() returning ".array2string($folderlist));
389
+		}
323 390
 
324 391
 		return $folderlist;
325 392
 	}
@@ -380,11 +447,17 @@  discard block
 block discarded – undo
380 447
 		$smartdata_task = ($smartdata->replyflag?'reply':($smartdata->forwardflag?'forward':'new'));
381 448
 
382 449
    		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__ . (isset($smartdata->mime) ? $smartdata->mime : ""). "task: ".(isset($smartdata_task) ? $smartdata_task : "")." itemid: ".(isset($smartdata->source->itemid) ? $smartdata->source->itemid : "")." folder: ".(isset($smartdata->source->folderid) ? $smartdata->source->folderid : ""));
383
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata));
450
+		if ($this->debugLevel>0)
451
+		{
452
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): Smartdata = ".array2string($smartdata));
453
+		}
384 454
 		//error_log("IMAP-Sendmail: Smartdata = ".array2string($smartdata));
385 455
 
386 456
 		// initialize our Mail
387
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
457
+		if (!isset($this->mail))
458
+		{
459
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
460
+		}
388 461
 		$activeMailProfiles = $this->mail->getAccountIdentities(self::$profileID);
389 462
 		// use the standardIdentity
390 463
 		$activeMailProfile = Mail::getStandardIdentityForProfile($activeMailProfiles,self::$profileID);
@@ -412,12 +485,18 @@  discard block
 block discarded – undo
412 485
 		$beforeHtml = ($disableRuler ?'&nbsp;<br>':'&nbsp;<br><hr style="border:dotted 1px silver; width:90%; border:dotted 1px silver;">');
413 486
 		$beforePlain = ($disableRuler ?"\r\n\r\n":"\r\n\r\n-- \r\n");
414 487
 		$sigText = Mail::merge($signature,array($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')));
415
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Signature to use:'.$sigText);
488
+		if ($this->debugLevel>0)
489
+		{
490
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Signature to use:'.$sigText);
491
+		}
416 492
 		$sigTextHtml = $beforeHtml.$sigText;
417 493
 		$sigTextPlain = $beforePlain.Api\Mail\Html::convertHTMLToText($sigText);
418 494
 
419 495
 		$force8bit=false;
420
-		if (Api\Translation::detect_encoding($sigTextPlain)!='ascii') $force8bit=true;
496
+		if (Api\Translation::detect_encoding($sigTextPlain)!='ascii')
497
+		{
498
+			$force8bit=true;
499
+		}
421 500
 		// initialize the new Api\Mailer object for sending
422 501
 		$mailObject = new Api\Mailer(self::$profileID);
423 502
 		$this->mail->parseRawMessageIntoMailObject($mailObject,$smartdata->mime,$force8bit);
@@ -428,22 +507,34 @@  discard block
 block discarded – undo
428 507
 
429 508
 		// prepare addressee list; moved the adding of addresses to the mailobject down
430 509
 		// to
431
-		foreach(Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject) {
432
-			if (!$addressObject->valid) continue;
510
+		foreach(Mail::parseAddressList($mailObject->getHeader("To")) as $addressObject)
511
+		{
512
+			if (!$addressObject->valid)
513
+			{
514
+				continue;
515
+			}
433 516
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail To: ".array2string($addressObject) );
434 517
 			//$mailObject->AddAddress($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
435 518
 			$toMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
436 519
 		}
437 520
 		// CC
438
-		foreach(Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject) {
439
-			if (!$addressObject->valid) continue;
521
+		foreach(Mail::parseAddressList($mailObject->getHeader("Cc")) as $addressObject)
522
+		{
523
+			if (!$addressObject->valid)
524
+			{
525
+				continue;
526
+			}
440 527
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail CC: ".array2string($addressObject) );
441 528
 			//$mailObject->AddCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
442 529
 			$ccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
443 530
 		}
444 531
 		// BCC
445
-		foreach($mailObject->getAddresses('bcc') as $addressObject) {
446
-			if (!$addressObject->valid) continue;
532
+		foreach($mailObject->getAddresses('bcc') as $addressObject)
533
+		{
534
+			if (!$addressObject->valid)
535
+			{
536
+				continue;
537
+			}
447 538
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") Header Sentmail BCC: ".array2string($addressObject) );
448 539
 			//$mailObject->AddBCC($addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : ''),$addressObject->personal);
449 540
 			$bccMailAddr[] = imap_rfc822_write_address($addressObject->mailbox, $addressObject->host, $addressObject->personal);
@@ -456,12 +547,14 @@  discard block
 block discarded – undo
456 547
 		$ContentType =$mailObject->getHeader('Content-Type');
457 548
 		//error_log(__METHOD__.__LINE__." Header Sentmail original Header (filtered): " . $k.  " = ".trim($ContentType));
458 549
 		// if the message is a multipart message, then we should use the sent body
459
-		if (preg_match("/multipart/i", $ContentType)) {
550
+		if (preg_match("/multipart/i", $ContentType))
551
+		{
460 552
 			$use_orgbody = true;
461 553
 		}
462 554
 
463 555
 		// save the original content-type header for the body part when forwarding
464
-		if ($smartdata_task == 'forward' && $smartdata->source->itemid && !$use_orgbody) {
556
+		if ($smartdata_task == 'forward' && $smartdata->source->itemid && !$use_orgbody)
557
+		{
465 558
 			//continue; // ignore
466 559
 		}
467 560
 		// horde/egw_ mailer does everything as utf-8, the following should not be needed
@@ -470,7 +563,8 @@  discard block
 block discarded – undo
470 563
 		// if the message is a multipart message, then we should use the sent body
471 564
 		if (($smartdata_task == 'new' || $smartdata_task == 'reply' || $smartdata_task == 'forward') &&
472 565
 			((isset($smartdata->replacemime) && $smartdata->replacemime == true) ||
473
-			$k == "Content-Type" && preg_match("/multipart/i", $ContentType))) {
566
+			$k == "Content-Type" && preg_match("/multipart/i", $ContentType)))
567
+		{
474 568
 			$use_orgbody = true;
475 569
 		}
476 570
 		$Body =  $AltBody = "";
@@ -503,12 +597,19 @@  discard block
 block discarded – undo
503 597
 			$AltBody = preg_replace("/(<|&lt;)*(([\w\.,-.,_.,0-9.]+)@([\w\.,-.,_.,0-9.]+))(>|&gt;)*/i","[$2]",
504 598
 				($html_body = $mailObject->findBody('html')) ? $html_body->getContents() : null);
505 599
 		}
506
-		if ($this->debugLevel>1 && $Body) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as with MessageContentType:". $ContentType.'=>'.$Body);
507
-		if ($this->debugLevel>1 && $AltBody) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:". $ContentType.'=>'.$AltBody);
600
+		if ($this->debugLevel>1 && $Body)
601
+		{
602
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched Body as with MessageContentType:". $ContentType.'=>'.$Body);
603
+		}
604
+		if ($this->debugLevel>1 && $AltBody)
605
+		{
606
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") fetched AltBody as with MessageContentType:". $ContentType.'=>'.$AltBody);
607
+		}
508 608
 		//error_log(__METHOD__.__LINE__.array2string($mailObject));
509 609
 		// if this is a multipart message with a boundary, we must use the original body
510 610
 		//if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' mailObject after Inital Parse:'.array2string($mailObject));
511
-        if ($use_orgbody) {
611
+        if ($use_orgbody)
612
+        {
512 613
     	    ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") use_orgbody = true ContentType:".$ContentType);
513 614
  			// if it is a ClientSideMeetingRequest, we report it as send at all times
514 615
 			if (($cal_body = $mailObject->findBody('calendar')) &&
@@ -518,15 +619,20 @@  discard block
 block discarded – undo
518 619
 				{
519 620
 					$organizer = calendar_ical::getIcalOrganizer($cal_body->getContents());
520 621
 				}
521
-				if ($this->debugLevel) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
622
+				if ($this->debugLevel)
623
+				{
624
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") we have a Client Side Meeting Request from organizer=$organizer");
625
+				}
522 626
 				$ClientSideMeetingRequest = true;
523 627
 			}
524 628
         }
525 629
 		// now handle the addressee list
526 630
 		$toCount = 0;
527 631
 		//error_log(__METHOD__.__LINE__.array2string($toMailAddr));
528
-		foreach((array)$toMailAddr as $address) {
529
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
632
+		foreach((array)$toMailAddr as $address)
633
+		{
634
+			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject)
635
+			{
530 636
 				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
531 637
 				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' &&
532 638
 					calendar_boupdate::email_update_requested($emailAddress, isset($cSMRMethod) ? $cSMRMethod : 'REQUEST',
@@ -540,19 +646,29 @@  discard block
 block discarded – undo
540 646
 			}
541 647
 		}
542 648
 		$ccCount = 0;
543
-		foreach((array)$ccMailAddr as $address) {
544
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
649
+		foreach((array)$ccMailAddr as $address)
650
+		{
651
+			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject)
652
+			{
545 653
 				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
546
-				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
654
+				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress))
655
+				{
656
+					continue;
657
+				}
547 658
 				$mailObject->AddCC($emailAddress, $addressObject->personal);
548 659
 				$ccCount++;
549 660
 			}
550 661
 		}
551 662
 		$bccCount = 0;
552
-		foreach((array)$bccMailAddr as $address) {
553
-			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
663
+		foreach((array)$bccMailAddr as $address)
664
+		{
665
+			foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject)
666
+			{
554 667
 				$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
555
-				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress)) continue;
668
+				if ($ClientSideMeetingRequest === true && $allowSendingInvitations == 'sendifnocalnotif' && calendar_boupdate::email_update_requested($emailAddress))
669
+				{
670
+					continue;
671
+				}
556 672
 				$mailObject->AddBCC($emailAddress, $addressObject->personal);
557 673
 				$bccCount++;
558 674
 			}
@@ -562,7 +678,10 @@  discard block
 block discarded – undo
562 678
 		{
563 679
 			return $ClientSideMeetingRequest && $allowSendingInvitations === 'sendifnocalnotif' && $organizer ? true : 0; // noone to send mail to
564 680
 		}
565
-		if ($ClientSideMeetingRequest === true && $allowSendingInvitations===false) return true;
681
+		if ($ClientSideMeetingRequest === true && $allowSendingInvitations===false)
682
+		{
683
+			return true;
684
+		}
566 685
 		// as we use our mailer (horde mailer) it is detecting / setting the mimetype by itself while creating the mail
567 686
 /*
568 687
 		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' retrieved Body:'.$body);
@@ -585,10 +704,17 @@  discard block
 block discarded – undo
585 704
 			$this->mail->reopen($folder);
586 705
 			$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
587 706
 			$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
588
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
589
-		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
707
+			if ($this->debugLevel>3)
708
+			{
709
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
710
+			}
711
+		    if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html'))
712
+		    {
590 713
 				// may be html
591
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
714
+				if ($this->debugLevel>0)
715
+				{
716
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
717
+				}
592 718
 				$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
593 719
 				$isreply = true;
594 720
 			}
@@ -597,8 +723,12 @@  discard block
 block discarded – undo
597 723
 			// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
598 724
 			$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
599 725
 			$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
600
-			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
601
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
726
+			if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain'))
727
+			{
728
+				if ($this->debugLevel>0)
729
+				{
730
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
731
+				}
602 732
 				$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
603 733
 				$isreply = true;
604 734
 			}
@@ -606,7 +736,10 @@  discard block
 block discarded – undo
606 736
 			{
607 737
 				$isreply = true;
608 738
 				$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
609
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
739
+				if ($this->debugLevel>0)
740
+				{
741
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no Api\Html Body found use modified plaintext body for txt/html: ".$AltBody);
742
+				}
610 743
 			}
611 744
 		}
612 745
 
@@ -620,11 +753,17 @@  discard block
 block discarded – undo
620 753
 			(isset($smartdata->replacemime) && $smartdata->replacemime == false)))
621 754
 		{
622 755
 			//force the default for the forwarding -> asmail
623
-			if (is_array($preferencesArray)) {
756
+			if (is_array($preferencesArray))
757
+			{
624 758
 				if (!array_key_exists('message_forwarding',$preferencesArray)
625 759
 					|| !isset($preferencesArray['message_forwarding'])
626
-					|| empty($preferencesArray['message_forwarding'])) $preferencesArray['message_forwarding'] = 'asmail';
627
-			} else {
760
+					|| empty($preferencesArray['message_forwarding']))
761
+				{
762
+					$preferencesArray['message_forwarding'] = 'asmail';
763
+				}
764
+			}
765
+			else
766
+			{
628 767
 				$preferencesArray['message_forwarding'] = 'asmail';
629 768
 			}
630 769
 			// construct the uid of the message out of the itemid - seems to be the uid, no construction needed
@@ -656,27 +795,44 @@  discard block
 block discarded – undo
656 795
 				$this->mail->reopen($folder);
657 796
 				$bodyStruct = $this->mail->getMessageBody($uid, 'html_only');
658 797
 				$bodyBUFFHtml = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
659
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
660
-				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
798
+				if ($this->debugLevel>0)
799
+				{
800
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$bodyBUFFHtml);
801
+				}
802
+				if ($bodyBUFFHtml != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html'))
803
+				{
661 804
 					// may be html
662
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
805
+					if ($this->debugLevel>0)
806
+					{
807
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:html (fetched with html_only):'.$bodyBUFFHtml);
808
+					}
663 809
 					$AltBody = $AltBody."</br>".$bodyBUFFHtml.$sigTextHtml;
664 810
 					$isforward = true;
665 811
 				}
666 812
 				// plain text Message part
667
-				if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
813
+				if ($this->debugLevel>0)
814
+				{
815
+					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain, fetch text:');
816
+				}
668 817
 				// if the new part of the message is html, we must preserve it, and handle that the original mail is text/plain
669 818
 				$bodyStruct = $this->mail->getMessageBody($uid,'never_display');//'never_display');
670 819
 				$bodyBUFF = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
671
-				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain')) {
672
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
820
+				if ($bodyBUFF != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/plain'))
821
+				{
822
+					if ($this->debugLevel>0)
823
+					{
824
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__.") MIME Body".' Type:plain (fetched with never_display):'.$bodyBUFF);
825
+					}
673 826
 					$Body = $Body."\r\n".$bodyBUFF.$sigTextPlain;
674 827
 					$isforward = true;
675 828
 				}
676 829
 				if (!empty($bodyBUFF) && empty($bodyBUFFHtml) && !empty($AltBody))
677 830
 				{
678 831
 					$AltBody = $AltBody."</br><pre>".nl2br($bodyBUFF).'</pre>'.$sigTextHtml;
679
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
832
+					if ($this->debugLevel>0)
833
+					{
834
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." no html Body found use modified plaintext body for txt/html: ".$AltBody);
835
+					}
680 836
 					$isforward = true;
681 837
 				}
682 838
 				// get all the attachments and add them too.
@@ -689,7 +845,10 @@  discard block
 block discarded – undo
689 845
 					ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' gather Attachments for BodyCreation of/for MessageID:'.$uid.' found:'.count($attachments));
690 846
 					foreach((array)$attachments as $key => $attachment)
691 847
 					{
692
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
848
+						if ($this->debugLevel>0)
849
+						{
850
+							ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attachment));
851
+						}
693 852
 						$attachmentNames .= $attachment['name']."\n";
694 853
 						$attachmentData	= $this->mail->getAttachment($uid, $attachment['partID'],0,false,false,$folder);
695 854
 						/*$x =*/ $mailObject->AddStringAttachment($attachmentData['attachment'], $attachment['name'], $attachment['mimeType']);
@@ -708,20 +867,29 @@  discard block
 block discarded – undo
708 867
 		// now set the body
709 868
 		if ($AltBody && ($html_body = $mailObject->findBody('html')))
710 869
 		{
711
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$AltBody);
870
+			if ($this->debugLevel>1)
871
+			{
872
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$AltBody);
873
+			}
712 874
 			//error_log(__METHOD__.__LINE__.' html:'.$AltBody);
713 875
 			$html_body->setContents($AltBody,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
714 876
 		}
715 877
 		if ($Body && ($text_body = $mailObject->findBody('plain')))
716 878
 		{
717
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$Body);
879
+			if ($this->debugLevel>1)
880
+			{
881
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' -> '.$Body);
882
+			}
718 883
 			//error_log(__METHOD__.__LINE__.' text:'.$Body);
719 884
 			$text_body->setContents($Body,array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
720 885
 		}
721 886
 		//advanced debugging
722 887
 		// Horde SMTP Class uses utf-8 by default.
723 888
         //ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SendMail: parsed message: ". print_r($message,1));
724
-		if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
889
+		if ($this->debugLevel>2)
890
+		{
891
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."(".__LINE__."): MailObject:".array2string($mailObject));
892
+		}
725 893
 
726 894
 		// set a higher timeout for big messages
727 895
 		@set_time_limit(120);
@@ -748,7 +916,9 @@  discard block
 block discarded – undo
748 916
 			if ($this->mail->isDraftFolder($folder) && !$this->mail->isTemplateFolder($folder))
749 917
 			{
750 918
 				$this->mail->deleteMessages(array($uid),$folder);
751
-			} else {
919
+			}
920
+			else
921
+			{
752 922
 				$this->mail->flagMessages("answered", array($uid),$folder);
753 923
 				if ($smartdata_task== "forward")
754 924
 				{
@@ -762,7 +932,8 @@  discard block
 block discarded – undo
762 932
 		{
763 933
 			$asf = false;
764 934
 			$sentFolder = $this->mail->getSentFolder();
765
-			if ($this->_sentID) {
935
+			if ($this->_sentID)
936
+			{
766 937
 				$folderArray[] = $this->_sentID;
767 938
 			}
768 939
 			else if(isset($sentFolder) && $sentFolder != 'none')
@@ -776,28 +947,41 @@  discard block
 block discarded – undo
776 947
 				// we dont try guessing
777 948
 				$asf = true;
778 949
 			}
779
-			if (count($folderArray) > 0) {
780
-				foreach((array)$bccMailAddr as $address) {
781
-					foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject) {
950
+			if (count($folderArray) > 0)
951
+			{
952
+				foreach((array)$bccMailAddr as $address)
953
+				{
954
+					foreach(Mail::parseAddressList((get_magic_quotes_gpc()?stripslashes($address):$address)) as $addressObject)
955
+					{
782 956
 						$emailAddress = $addressObject->mailbox. ($addressObject->host ? '@'.$addressObject->host : '');
783 957
 						$mailAddr[] = array($emailAddress, $addressObject->personal);
784 958
 					}
785 959
 				}
786 960
 				//$BCCmail='';
787
-				if (count($mailAddr)>0) $mailObject->forceBccHeader();
961
+				if (count($mailAddr)>0)
962
+				{
963
+					$mailObject->forceBccHeader();
964
+				}
788 965
 				//$BCCmail = $mailObject->AddrAppend("Bcc",$mailAddr);
789
-				foreach($folderArray as $folderName) {
790
-					if($this->mail->isSentFolder($folderName)) {
966
+				foreach($folderArray as $folderName)
967
+				{
968
+					if($this->mail->isSentFolder($folderName))
969
+					{
791 970
 						$flags = '\\Seen';
792
-					} elseif($this->mail->isDraftFolder($folderName)) {
971
+					}
972
+					elseif($this->mail->isDraftFolder($folderName))
973
+					{
793 974
 						$flags = '\\Draft';
794
-					} else {
975
+					}
976
+					else
977
+					{
795 978
 						$flags = '';
796 979
 					}
797 980
 					$asf = true;
798 981
 					//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.'->'.array2string($this->mail->icServer));
799 982
 					$this->mail->openConnection(self::$profileID,false);
800
-					if ($this->mail->folderExists($folderName)) {
983
+					if ($this->mail->folderExists($folderName))
984
+					{
801 985
 						try
802 986
 						{
803 987
 							$this->mail->appendMessage($folderName,$mailObject->getRaw(), null,
@@ -855,17 +1039,26 @@  discard block
 block discarded – undo
855 1039
 		$bodypreference = $contentparameters->GetBodyPreference(); /* fmbiete's contribution r1528, ZP-320 */
856 1040
 
857 1041
 		// fix for z-push bug returning additional bodypreference type 4, even if only 1 is requested and mimessupport = 0
858
-		if (!$mimesupport && ($key = array_search('4', $bodypreference))) unset($bodypreference[$key]);
1042
+		if (!$mimesupport && ($key = array_search('4', $bodypreference)))
1043
+		{
1044
+			unset($bodypreference[$key]);
1045
+		}
859 1046
 
860 1047
 		//$this->debugLevel=4;
861
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1048
+		if (!isset($this->mail))
1049
+		{
1050
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1051
+		}
862 1052
 		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' FolderID:'.$folderid.' ID:'.$id.' TruncSize:'.$truncsize.' Bodypreference: '.array2string($bodypreference));
863 1053
 		$account = $_folderName = $xid = null;
864 1054
 		$this->splitID($folderid,$account,$_folderName,$xid);
865 1055
 		$this->mail->reopen($_folderName);
866 1056
 		$messages = $this->fetchMessages($folderid, NULL, $id, true);	// true: return all headers
867 1057
 		$headers = $messages[$id];
868
-		if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($headers));
1058
+		if ($this->debugLevel>3)
1059
+		{
1060
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($headers));
1061
+		}
869 1062
 		// StatMessage should reopen the folder in question, so we dont need folderids in the following statements.
870 1063
 		if ($headers)
871 1064
 		{
@@ -875,16 +1068,25 @@  discard block
 block discarded – undo
875 1068
 			//$rawHeaders = $this->mail->getMessageRawHeader($id);
876 1069
 			// simple style
877 1070
 			// start AS12 Stuff (bodypreference === false) case = old behaviour
878
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__. ' for message with ID:'.$id.' with headers:'.array2string($headers));
1071
+			if ($this->debugLevel>0)
1072
+			{
1073
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__. ' for message with ID:'.$id.' with headers:'.array2string($headers));
1074
+			}
879 1075
 
880
-			if ($bodypreference === false) {
1076
+			if ($bodypreference === false)
1077
+			{
881 1078
 				$bodyStruct = $this->mail->getMessageBody($id, 'only_if_no_text', '', null, true,$_folderName);
882 1079
 				$raw_body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
883 1080
 				//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
884
-				if (stripos($raw_body,'<style')!==false) $body = preg_replace("/<style.*?<\/style>/is", "", $raw_body); // in case there is only a html part
1081
+				if (stripos($raw_body,'<style')!==false)
1082
+				{
1083
+					$body = preg_replace("/<style.*?<\/style>/is", "", $raw_body);
1084
+				}
1085
+				// in case there is only a html part
885 1086
 				// remove all other html
886 1087
 				$body = strip_tags($raw_body);
887
-				if(strlen($body) > $truncsize) {
1088
+				if(strlen($body) > $truncsize)
1089
+				{
888 1090
 					$body = Utils::Utf8_truncate($body, $truncsize);
889 1091
 					$output->bodytruncated = 1;
890 1092
 				}
@@ -899,7 +1101,8 @@  discard block
 block discarded – undo
899 1101
 			{
900 1102
 				//Select body type preference
901 1103
 				$bpReturnType = 1;//SYNC_BODYPREFERENCE_PLAIN;
902
-				if ($bodypreference !== false) {
1104
+				if ($bodypreference !== false)
1105
+				{
903 1106
 					// bodypreference can occur multiple times
904 1107
 					// usually we would use Utils::GetBodyPreferenceBestMatch($bodypreference);
905 1108
 					$bpReturnType = Utils::GetBodyPreferenceBestMatch($bodypreference);
@@ -933,25 +1136,49 @@  discard block
 block discarded – undo
933 1136
 					// fetch the body (try to gather data only once)
934 1137
 					$css ='';
935 1138
 					$bodyStruct = $this->mail->getMessageBody($id, 'html_only', '', null, true,$_folderName);
936
-					if ($this->debugLevel>2) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
1139
+					if ($this->debugLevel>2)
1140
+					{
1141
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only Struct:'.array2string($bodyStruct));
1142
+					}
937 1143
 					$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,true,false);
938
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$body);
939
-					if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html')) {
1144
+					if ($this->debugLevel>3)
1145
+					{
1146
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' html_only:'.$body);
1147
+					}
1148
+					if ($body != "" && (is_array($bodyStruct) && $bodyStruct[0]['mimeType']=='text/html'))
1149
+					{
940 1150
 						// may be html
941
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
1151
+						if ($this->debugLevel>0)
1152
+						{
1153
+							ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:html (fetched with html_only)');
1154
+						}
942 1155
 						$css = $this->mail->getStyles($bodyStruct);
943 1156
 						$output->nativebodytype=2;
944
-					} else {
1157
+					}
1158
+					else
1159
+					{
945 1160
 						// plain text Message
946
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
1161
+						if ($this->debugLevel>0)
1162
+						{
1163
+							ZLog::Write(LOGLEVEL_DEBUG, "MIME Body".' Type:plain, fetch text (HTML, if no text available)');
1164
+						}
947 1165
 						$output->nativebodytype=1;
948 1166
 						$bodyStruct = $this->mail->getMessageBody($id,'never_display', '', null, true,$_folderName); //'only_if_no_text');
949
-						if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
1167
+						if ($this->debugLevel>3)
1168
+						{
1169
+							ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' plain text Struct:'.array2string($bodyStruct));
1170
+						}
950 1171
 						$body = $this->mail->getdisplayableBody($this->mail,$bodyStruct,false,false);
951
-						if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' never display html(plain text only):'.$body);
1172
+						if ($this->debugLevel>3)
1173
+						{
1174
+							ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' never display html(plain text only):'.$body);
1175
+						}
952 1176
 					}
953 1177
 					// whatever format decode (using the correct encoding)
954
-					if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype==2?' html ':' plain ').$body);
1178
+					if ($this->debugLevel>3)
1179
+					{
1180
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__."MIME Body".' Type:'.($output->nativebodytype==2?' html ':' plain ').$body);
1181
+					}
955 1182
 					//$body = html_entity_decode($body,ENT_QUOTES,$this->mail->detect_encoding($body));
956 1183
 					// prepare plaintextbody
957 1184
 					$plainBody='';
@@ -972,12 +1199,18 @@  discard block
 block discarded – undo
972 1199
 					// remove all other html
973 1200
 					$plainBody = preg_replace("/<br.*>/is","\r\n",$plainBody);
974 1201
 					$plainBody = strip_tags($plainBody);
975
-					if ($this->debugLevel>3 && $output->nativebodytype==1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Plain Text:'.$plainBody);
1202
+					if ($this->debugLevel>3 && $output->nativebodytype==1)
1203
+					{
1204
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Plain Text:'.$plainBody);
1205
+					}
976 1206
 					//$body = str_replace("\n","\r\n", str_replace("\r","",$body)); // do we need that?
977 1207
 
978
-					if ($bpReturnType==2) //SYNC_BODYPREFERENCE_HTML
1208
+					if ($bpReturnType==2)
1209
+					{
1210
+						//SYNC_BODYPREFERENCE_HTML
979 1211
 					{
980 1212
 						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "HTML Body with requested pref 2");
1213
+					}
981 1214
 						// Send HTML if requested and native type was html
982 1215
 						$output->asbody->type = 2;
983 1216
 						$htmlbody = '<html>'.
@@ -1013,7 +1246,10 @@  discard block
 block discarded – undo
1013 1246
 					else
1014 1247
 					{
1015 1248
 						// Send Plaintext as Fallback or if original body is plainttext
1016
-						if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1249
+						if ($this->debugLevel>0)
1250
+						{
1251
+							ZLog::Write(LOGLEVEL_DEBUG, "Plaintext Body:".$plainBody);
1252
+						}
1017 1253
 						/* we use plainBody (set above) instead
1018 1254
 						$bodyStruct = $this->mail->getMessageBody($id,'only_if_no_text'); //'never_display');
1019 1255
 						$plain = $this->mail->getdisplayableBody($this->mail,$bodyStruct);
@@ -1050,7 +1286,9 @@  discard block
 block discarded – undo
1050 1286
 			{
1051 1287
 				$output->flag->flagstatus = 2;
1052 1288
 				//$output->flag->flagtype = "Flag for Follow up";
1053
-			} else {
1289
+			}
1290
+			else
1291
+			{
1054 1292
 				$output->flag->flagstatus = 0;
1055 1293
 			}
1056 1294
 			if ($headers['answered'])
@@ -1066,10 +1304,20 @@  discard block
 block discarded – undo
1066 1304
 				($headers['priority'] < 3 ? 2 : 1) ;
1067 1305
 			$output->datereceived = $this->mail->_strtotime($headers['date'],'ts',true);
1068 1306
 			$output->to = $headers['to_address'];
1069
-			if ($headers['to']) $output->displayto = $headers['to_address']; //$headers['FETCHED_HEADER']['to_name']
1307
+			if ($headers['to'])
1308
+			{
1309
+				$output->displayto = $headers['to_address'];
1310
+			}
1311
+			//$headers['FETCHED_HEADER']['to_name']
1070 1312
 			$output->from = $headers['sender_address'];
1071
-			if (isset($headers['cc_addresses']) && $headers['cc_addresses']) $output->cc = $headers['cc_addresses'];
1072
-			if (isset($headers['reply_to_address']) && $headers['reply_to_address']) $output->reply_to = $headers['reply_to_address'];
1313
+			if (isset($headers['cc_addresses']) && $headers['cc_addresses'])
1314
+			{
1315
+				$output->cc = $headers['cc_addresses'];
1316
+			}
1317
+			if (isset($headers['reply_to_address']) && $headers['reply_to_address'])
1318
+			{
1319
+				$output->reply_to = $headers['reply_to_address'];
1320
+			}
1073 1321
 
1074 1322
 			$output->messageclass = "IPM.Note";
1075 1323
 			if (stripos($headers['mimetype'],'multipart')!== false &&
@@ -1077,7 +1325,8 @@  discard block
 block discarded – undo
1077 1325
 			{
1078 1326
 				$output->messageclass = "IPM.Note.SMIME.MultipartSigned";
1079 1327
 			}
1080
-			if (Request::GetProtocolVersion() >= 12.0) {
1328
+			if (Request::GetProtocolVersion() >= 12.0)
1329
+			{
1081 1330
 				$output->contentclass = "urn:content-classes:message";
1082 1331
 			}
1083 1332
 
@@ -1090,7 +1339,10 @@  discard block
 block discarded – undo
1090 1339
 				//error_log(__METHOD__.__LINE__.array2string($attachments));
1091 1340
 				foreach ($attachments as $key => $attach)
1092 1341
 				{
1093
-					if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1342
+					if ($this->debugLevel>0)
1343
+					{
1344
+						ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Key:'.$key.'->'.array2string($attach));
1345
+					}
1094 1346
 
1095 1347
 					// pass meeting requests to calendar plugin
1096 1348
 					if (strtolower($attach['mimeType']) == 'text/calendar' && strtolower($attach['method']) == 'request' &&
@@ -1107,17 +1359,24 @@  discard block
 block discarded – undo
1107 1359
 						unset($attachment);
1108 1360
 						continue;	// do NOT add attachment as attachment
1109 1361
 					}
1110
-					if (Request::GetProtocolVersion() >= 12.0) {
1362
+					if (Request::GetProtocolVersion() >= 12.0)
1363
+					{
1111 1364
 						$attachment = new SyncBaseAttachment();
1112 1365
 						if (!isset($output->asattachments) || !is_array($output->asattachments))
1113
-							$output->asattachments = array();
1366
+						{
1367
+													$output->asattachments = array();
1368
+						}
1114 1369
 						$attachment->estimatedDataSize = $attach['size'];
1115 1370
 						$attachment->method = 1;
1116 1371
 						$attachment->filereference = $folderid . ":" . $id . ":" . $attach['partID'];
1117
-					} else {
1372
+					}
1373
+					else
1374
+					{
1118 1375
 						$attachment = new SyncAttachment();
1119 1376
 						if (!isset($output->attachments) || !is_array($output->attachments))
1120
-							$output->attachments = array();
1377
+						{
1378
+													$output->attachments = array();
1379
+						}
1121 1380
 						$attachment->attsize = $attach['size'];
1122 1381
 						$attachment->attmethod = 1;
1123 1382
 						$attachment->attname = $folderid . ":" . $id . ":" . $attach['partID'];//$key;
@@ -1134,10 +1393,13 @@  discard block
 block discarded – undo
1134 1393
 						{
1135 1394
 							$attachment->isinline = true;
1136 1395
 						}
1137
-						if (Request::GetProtocolVersion() >= 12.0) {
1396
+						if (Request::GetProtocolVersion() >= 12.0)
1397
+						{
1138 1398
 							$attachment->method=1;
1139 1399
 							$attachment->contentid= str_replace(array("<",">"), "",$attach['cid']);
1140
-						} else {
1400
+						}
1401
+						else
1402
+						{
1141 1403
 							$attachment->attmethod=6;
1142 1404
 							$attachment->attoid = str_replace(array("<",">"), "",$attach['cid']);
1143 1405
 						}
@@ -1145,9 +1407,12 @@  discard block
 block discarded – undo
1145 1407
 						$attachment->contenttype = trim($attach['mimeType']);
1146 1408
 						//	ZLog::Write(LOGLEVEL_DEBUG, "'".$part->headers['content-type']."'  ".$attachment->contentid);
1147 1409
 					}
1148
-					if (Request::GetProtocolVersion() >= 12.0) {
1410
+					if (Request::GetProtocolVersion() >= 12.0)
1411
+					{
1149 1412
 						array_push($output->asattachments, $attachment);
1150
-					} else {
1413
+					}
1414
+					else
1415
+					{
1151 1416
 						array_push($output->attachments, $attachment);
1152 1417
 					}
1153 1418
 					unset($attachment);
@@ -1160,8 +1425,11 @@  discard block
 block discarded – undo
1160 1425
             // Language Code Page ID: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx
1161 1426
             $output->internetcpid = INTERNET_CPID_UTF8;
1162 1427
 
1163
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($output));
1164
-//$this->debugLevel=0;
1428
+			if ($this->debugLevel>3)
1429
+			{
1430
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($output));
1431
+			}
1432
+			//$this->debugLevel=0;
1165 1433
 			return $output;
1166 1434
 		}
1167 1435
 //$this->debugLevel=0;
@@ -1220,7 +1488,8 @@  discard block
 block discarded – undo
1220 1488
      * @param string $attname - should contain (folder)id
1221 1489
 	 * @return SyncItemOperationsAttachment-object
1222 1490
 	 */
1223
-	function GetAttachmentData($fid,$attname) {
1491
+	function GetAttachmentData($fid,$attname)
1492
+	{
1224 1493
 		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1225 1494
 		return $this->_GetAttachmentData($fid,$attname);
1226 1495
 	}
@@ -1235,7 +1504,8 @@  discard block
 block discarded – undo
1235 1504
      * @param string $attname - should contain (folder)id
1236 1505
 	 * @return SyncItemOperationsAttachment-object
1237 1506
 	 */
1238
-	function ItemOperationsGetAttachmentData($fid,$attname) {
1507
+	function ItemOperationsGetAttachmentData($fid,$attname)
1508
+	{
1239 1509
 		ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname')");
1240 1510
 		return $this->_GetAttachmentData($fid,$attname);
1241 1511
 	}
@@ -1257,7 +1527,10 @@  discard block
 block discarded – undo
1257 1527
 
1258 1528
 		$this->splitID($folderid, $account, $folder);
1259 1529
 
1260
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1530
+		if (!isset($this->mail))
1531
+		{
1532
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1533
+		}
1261 1534
 
1262 1535
 		$this->mail->reopen($folder);
1263 1536
 		$attachment = $this->mail->getAttachment($id,$part,0,false,true,$folder);
@@ -1266,7 +1539,9 @@  discard block
 block discarded – undo
1266 1539
 		$SIOattachment->data = $attachment['attachment'];
1267 1540
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.": $fid (attname: '$attname') Data:".$attachment['attachment']);
1268 1541
 		if (isset($attachment['type']) )
1269
-			$SIOattachment->contenttype = $attachment['type'];
1542
+		{
1543
+					$SIOattachment->contenttype = $attachment['type'];
1544
+		}
1270 1545
 
1271 1546
 		unset($attachment);
1272 1547
 
@@ -1312,11 +1587,15 @@  discard block
 block discarded – undo
1312 1587
 		//unset($folderid, $id, $message, $contentParameters);
1313 1588
 		$account = $folder = null;
1314 1589
 		$this->splitID($folderid, $account, $folder);
1315
-		if (isset($message->flag)) {
1316
-			if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2) {
1590
+		if (isset($message->flag))
1591
+		{
1592
+			if (isset($message->flag->flagstatus) && $message->flag->flagstatus == 2)
1593
+			{
1317 1594
 				$rv = $this->mail->flagMessages((($message->flag->flagstatus == 2) ? "flagged" : "unflagged"), $id,$folder);
1318 1595
 				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . (($message->flag->flagstatus == 2) ? "flagged" : "unflagged") . "-->". $rv);
1319
-			} else {
1596
+			}
1597
+			else
1598
+			{
1320 1599
 				$rv = $this->mail->flagMessages("unflagged", $id,$folder);
1321 1600
 				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." -> set ".array2string($id).' in Folder '.$folder." as " . "unflagged" . "-->". $rv);
1322 1601
 			}
@@ -1346,7 +1625,10 @@  discard block
 block discarded – undo
1346 1625
 		$this->splitID($folderid, $account, $srcFolder);
1347 1626
 		$this->splitID($newfolderid, $account, $destFolder);
1348 1627
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-MoveMessage: (SourceFolder: '$srcFolder'  id: '$id'  DestFolder: '$destFolder' )");
1349
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1628
+		if (!isset($this->mail))
1629
+		{
1630
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
1631
+		}
1350 1632
 		$this->mail->reopen($destFolder);
1351 1633
 		$status = $this->mail->getFolderStatus($destFolder);
1352 1634
 		$uidNext = $status['uidnext'];
@@ -1378,11 +1660,15 @@  discard block
 block discarded – undo
1378 1660
 				$maximumSyncRangeInDays = $GLOBALS['egw_info']['user']['preferences']['activesync']['mail-maximumSyncRange'];
1379 1661
 			}
1380 1662
 			$cutoffdate = (is_numeric($maximumSyncRangeInDays) ? Api\DateTime::to('now','ts')-(3600*24*$maximumSyncRangeInDays):null);
1381
-			if (is_numeric($maximumSyncRangeInDays)) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' Client set no truncationdate. Using '.$maximumSyncRangeInDays.' days.'.date("d-M-Y", $cutoffdate));
1663
+			if (is_numeric($maximumSyncRangeInDays))
1664
+			{
1665
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' Client set no truncationdate. Using '.$maximumSyncRangeInDays.' days.'.date("d-M-Y", $cutoffdate));
1666
+			}
1382 1667
 		}
1383 1668
 		try {
1384 1669
 			return $this->fetchMessages($folderid, $cutoffdate);
1385
-		} catch (Exception $e)
1670
+		}
1671
+		catch (Exception $e)
1386 1672
 		{
1387 1673
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' failed for '.$e->getMessage().($e->details?$e->details:''));
1388 1674
 			return array();
@@ -1406,7 +1692,10 @@  discard block
 block discarded – undo
1406 1692
 	{
1407 1693
 		static $headers = array();
1408 1694
 
1409
-		if ($this->debugLevel>1) $gstarttime = microtime (true);
1695
+		if ($this->debugLevel>1)
1696
+		{
1697
+			$gstarttime = microtime (true);
1698
+		}
1410 1699
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__);
1411 1700
 		$rv_messages = array();
1412 1701
 		// if the message is still available within the class, we use it instead of fetching it again
@@ -1419,7 +1708,10 @@  discard block
 block discarded – undo
1419 1708
 		{
1420 1709
 			$headers = array();	// clear cache to not use too much memory
1421 1710
 
1422
-			if ($this->debugLevel>1) $starttime = microtime (true);
1711
+			if ($this->debugLevel>1)
1712
+			{
1713
+				$starttime = microtime (true);
1714
+			}
1423 1715
 			$this->_connect($this->account);
1424 1716
 			if ($this->debugLevel>1)
1425 1717
 			{
@@ -1428,8 +1720,14 @@  discard block
 block discarded – undo
1428 1720
 			}
1429 1721
 			$messagelist = $_filter = array();
1430 1722
 			// if not connected, any further action must fail
1431
-			if (!empty($cutoffdate)) $_filter = array('status'=>array('UNDELETED'),'range'=>"SINCE",'date'=> date("d-M-Y", $cutoffdate));
1432
-			if ($this->debugLevel>1) $starttime = microtime (true);
1723
+			if (!empty($cutoffdate))
1724
+			{
1725
+				$_filter = array('status'=>array('UNDELETED'),'range'=>"SINCE",'date'=> date("d-M-Y", $cutoffdate));
1726
+			}
1727
+			if ($this->debugLevel>1)
1728
+			{
1729
+				$starttime = microtime (true);
1730
+			}
1433 1731
 			$account = $_folderName = $id = null;
1434 1732
 			$this->splitID($folderid,$account,$_folderName,$id);
1435 1733
 			if ($this->debugLevel>1)
@@ -1437,8 +1735,14 @@  discard block
 block discarded – undo
1437 1735
 				$endtime = microtime(true) - $starttime;
1438 1736
 				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " splitID took : ".$endtime.' for FolderID:'.$folderid);
1439 1737
 			}
1440
-			if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1441
-			if ($this->debugLevel>1) $starttime = microtime (true);
1738
+			if ($this->debugLevel>1)
1739
+			{
1740
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_id).'/'.$id);
1741
+			}
1742
+			if ($this->debugLevel>1)
1743
+			{
1744
+				$starttime = microtime (true);
1745
+			}
1442 1746
 			$_numberOfMessages = (empty($cutoffdate)?250:99999);
1443 1747
 			$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=1, $_numberOfMessages, $_sort=0, $_reverse=false, $_filter, $_id);
1444 1748
 			if ($this->debugLevel>1)
@@ -1447,27 +1751,56 @@  discard block
 block discarded – undo
1447 1751
 				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__. " getHeaders call took : ".$endtime.' for FolderID:'.$_folderName);
1448 1752
 			}
1449 1753
 		}
1450
-		if ($_id == NULL && $this->debugLevel>1)  ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." found :". count($rv_messages['header']));
1754
+		if ($_id == NULL && $this->debugLevel>1)
1755
+		{
1756
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__." found :". count($rv_messages['header']));
1757
+		}
1451 1758
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' Result:'.array2string($rv_messages));
1452 1759
 		$messagelist = array();
1453
-		if (!isset($rv_messages['header'])||empty($rv_messages['header'])) return $messagelist;
1760
+		if (!isset($rv_messages['header'])||empty($rv_messages['header']))
1761
+		{
1762
+			return $messagelist;
1763
+		}
1454 1764
 		//if ($_returnModHash) $messageFolderHash = array();
1455 1765
 		foreach ((array)$rv_messages['header'] as $k => $vars)
1456 1766
 		{
1457
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']);
1767
+			if ($this->debugLevel>3)
1768
+			{
1769
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to process:'.$vars['uid'].' Subject:'.$vars['subject']);
1770
+			}
1458 1771
 			$headers[$vars['uid']] = $vars;
1459
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1460
-			if (!empty($vars['deleted'])) continue; // cut of deleted messages
1461
-			if ($cutoffdate && $vars['date'] < $cutoffdate) continue; // message is out of range for cutoffdate, ignore it
1462
-			if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']);
1772
+			if ($this->debugLevel>3)
1773
+			{
1774
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' MailID:'.$k.'->'.array2string($vars));
1775
+			}
1776
+			if (!empty($vars['deleted']))
1777
+			{
1778
+				continue;
1779
+			}
1780
+			// cut of deleted messages
1781
+			if ($cutoffdate && $vars['date'] < $cutoffdate)
1782
+			{
1783
+				continue;
1784
+			}
1785
+			// message is out of range for cutoffdate, ignore it
1786
+			if ($this->debugLevel>0)
1787
+			{
1788
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.' ID to report:'.$vars['uid'].' Subject:'.$vars['subject']);
1789
+			}
1463 1790
 			$mess = $return_all_headers ? $vars : array();
1464 1791
 			$mess["mod"] = self::doFlagsMod($vars).$vars['date'];
1465 1792
 			$mess["id"] = $vars['uid'];
1466 1793
 			// 'seen' aka 'read' is the only flag we want to know about
1467 1794
 			$mess["flags"] = 0;
1468 1795
 			// outlook supports additional flags, set them to 0
1469
-			if($vars["seen"]) $mess["flags"] = 1;
1470
-			if ($this->debugLevel>3) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($mess));
1796
+			if($vars["seen"])
1797
+			{
1798
+				$mess["flags"] = 1;
1799
+			}
1800
+			if ($this->debugLevel>3)
1801
+			{
1802
+				ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($mess));
1803
+			}
1471 1804
 			$messagelist[$vars['uid']] = $mess;
1472 1805
 			unset($mess);
1473 1806
 		}
@@ -1492,9 +1825,18 @@  discard block
 block discarded – undo
1492 1825
 	static function doFlagsMod($headerFlags)
1493 1826
 	{
1494 1827
 		$flags = 'nnn';
1495
-		if ($headerFlags['flagged']) $flags[0] = 'f';
1496
-		if ($headerFlags['answered']) $flags[1] = 'a';
1497
-		if ($headerFlags['forwarded']) $flags[2] = 'f';
1828
+		if ($headerFlags['flagged'])
1829
+		{
1830
+			$flags[0] = 'f';
1831
+		}
1832
+		if ($headerFlags['answered'])
1833
+		{
1834
+			$flags[1] = 'a';
1835
+		}
1836
+		if ($headerFlags['forwarded'])
1837
+		{
1838
+			$flags[2] = 'f';
1839
+		}
1498 1840
 		//ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.'('.array2string($headerFlags).') returning '.array2string($flags));
1499 1841
 		return $flags;
1500 1842
 	}
@@ -1526,31 +1868,55 @@  discard block
 block discarded – undo
1526 1868
 	{
1527 1869
 		//$this->debugLevel=1;
1528 1870
 		$searchquery=$_searchquery->GetDataArray();
1529
-		if (!is_array($searchquery)) return array();
1530
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($searchquery));
1871
+		if (!is_array($searchquery))
1872
+		{
1873
+			return array();
1874
+		}
1875
+		if ($this->debugLevel>0)
1876
+		{
1877
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($searchquery));
1878
+		}
1531 1879
 
1532
-		if (isset($searchquery['searchrebuildresults'])) {
1880
+		if (isset($searchquery['searchrebuildresults']))
1881
+		{
1533 1882
 			$rebuildresults = $searchquery['searchrebuildresults'];
1534
-		} else {
1883
+		}
1884
+		else
1885
+		{
1535 1886
 			$rebuildresults = false;
1536 1887
 		}
1537
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'RebuildResults ['.$rebuildresults.']' );
1888
+		if ($this->debugLevel>0)
1889
+		{
1890
+			ZLog::Write(LOGLEVEL_DEBUG,  'RebuildResults ['.$rebuildresults.']' );
1891
+		}
1538 1892
 
1539
-		if (isset($searchquery['deeptraversal'])) {
1893
+		if (isset($searchquery['deeptraversal']))
1894
+		{
1540 1895
 			$deeptraversal = $searchquery['deeptraversal'];
1541
-		} else {
1896
+		}
1897
+		else
1898
+		{
1542 1899
 			$deeptraversal = false;
1543 1900
 		}
1544
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'DeepTraversal ['.$deeptraversal.']' );
1901
+		if ($this->debugLevel>0)
1902
+		{
1903
+			ZLog::Write(LOGLEVEL_DEBUG,  'DeepTraversal ['.$deeptraversal.']' );
1904
+		}
1545 1905
 
1546
-		if (isset($searchquery['searchrange'])) {
1906
+		if (isset($searchquery['searchrange']))
1907
+		{
1547 1908
 			$range = explode("-",$_searchquery->GetSearchRange());
1548 1909
 			$start =$range[0] + 1;
1549 1910
 			$limit = $range[1] - $range[0] + 1;
1550
-		} else {
1911
+		}
1912
+		else
1913
+		{
1551 1914
 			$range = false;
1552 1915
 		}
1553
-		if ($this->debugLevel>0) ZLog::Write(LOGLEVEL_DEBUG,  'Range ['.print_r($range, true).']' );
1916
+		if ($this->debugLevel>0)
1917
+		{
1918
+			ZLog::Write(LOGLEVEL_DEBUG,  'Range ['.print_r($range, true).']' );
1919
+		}
1554 1920
 
1555 1921
 		//foreach($searchquery['query'] as $k => $value) {
1556 1922
 		//	$query = $value;
@@ -1602,7 +1968,10 @@  discard block
 block discarded – undo
1602 1968
 			$_filter['since'] = date("d-M-Y", Api\DateTime::to($sincedate,'ts'));
1603 1969
 		}
1604 1970
 		//$_filter[] = array('type'=>"SINCE",'string'=> date("d-M-Y", $cutoffdate));
1605
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1971
+		if ($this->debugLevel>1)
1972
+		{
1973
+			ZLog::Write(LOGLEVEL_DEBUG, __METHOD__.' for Folder:'.$_folderName.' Filter:'.array2string($_filter));
1974
+		}
1606 1975
 		$rv_messages = $this->mail->getHeaders($_folderName, $_startMessage=($range?$start:1), $_numberOfMessages=($limit?$limit:9999999), $_sort=0, $_reverse=false, $_filter, $_id=NULL);
1607 1976
 		//ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__.array2string($rv_messages));
1608 1977
 		$list=array();
@@ -1634,17 +2003,26 @@  discard block
 block discarded – undo
1634 2003
 	private function getParentID($account,$folder)
1635 2004
 	{
1636 2005
 		$this->_connect($account);
1637
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
2006
+		if (!isset($this->folders))
2007
+		{
2008
+			$this->folders = $this->mail->getFolderObjects(true,false);
2009
+		}
1638 2010
 
1639 2011
 		$mailFolder = $this->folders[$folder];
1640
-		if (!isset($mailFolder)) return false;
2012
+		if (!isset($mailFolder))
2013
+		{
2014
+			return false;
2015
+		}
1641 2016
 		$delimiter = (isset($mailFolder->delimiter)?$mailFolder->delimiter:$this->mail->getHierarchyDelimiter());
1642 2017
 		$parent = explode($delimiter,$folder);
1643 2018
 		array_pop($parent);
1644 2019
 		$parent = implode($delimiter,$parent);
1645 2020
 
1646 2021
 		$id = $parent && $this->folders[$parent] ? $this->createID($account, $parent) : '0';
1647
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$folder') --> parent=$parent --> $id");
2022
+		if ($this->debugLevel>1)
2023
+		{
2024
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$folder') --> parent=$parent --> $id");
2025
+		}
1648 2026
 		return $id;
1649 2027
 	}
1650 2028
 
@@ -1658,7 +2036,10 @@  discard block
 block discarded – undo
1658 2036
 	{
1659 2037
 		static $last_id = null;
1660 2038
 		static $folderObj = null;
1661
-		if (isset($last_id) && $last_id === $id) return $folderObj;
2039
+		if (isset($last_id) && $last_id === $id)
2040
+		{
2041
+			return $folderObj;
2042
+		}
1662 2043
 
1663 2044
 		try {
1664 2045
 			$account = $folder = null;
@@ -1669,18 +2050,30 @@  discard block
 block discarded – undo
1669 2050
 			return $folderObj=false;
1670 2051
 		}
1671 2052
 		$this->_connect($account);
1672
-		if (!isset($this->folders)) $this->folders = $this->mail->getFolderObjects(true,false);
2053
+		if (!isset($this->folders))
2054
+		{
2055
+			$this->folders = $this->mail->getFolderObjects(true,false);
2056
+		}
1673 2057
 
1674 2058
 		$mailFolder = $this->folders[$folder];
1675
-		if (!isset($mailFolder)) return $folderObj=false;
2059
+		if (!isset($mailFolder))
2060
+		{
2061
+			return $folderObj=false;
2062
+		}
1676 2063
 
1677 2064
 		$folderObj = new SyncFolder();
1678 2065
 		$folderObj->serverid = $id;
1679 2066
 		$folderObj->parentid = $this->getParentID($account,$folder);
1680 2067
 		$folderObj->displayname = $mailFolder->shortDisplayName;
1681
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
2068
+		if ($this->debugLevel>1)
2069
+		{
2070
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." ID: $id, Account:$account, Folder:$folder");
2071
+		}
1682 2072
 		// get folder-type
1683
-		foreach($this->folders as $inbox => $mailFolder) break;
2073
+		foreach($this->folders as $inbox => $mailFolder)
2074
+		{
2075
+			break;
2076
+		}
1684 2077
 		if ($folder == $inbox)
1685 2078
 		{
1686 2079
 			$folderObj->type = SYNC_FOLDER_TYPE_INBOX;
@@ -1717,7 +2110,10 @@  discard block
 block discarded – undo
1717 2110
 			$folderObj->type = SYNC_FOLDER_TYPE_USER_MAIL;
1718 2111
 		}
1719 2112
 
1720
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
2113
+		if ($this->debugLevel>1)
2114
+		{
2115
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($id) --> $folder --> type=$folderObj->type, parentID=$folderObj->parentid, displayname=$folderObj->displayname");
2116
+		}
1721 2117
 		return $folderObj;
1722 2118
 	}
1723 2119
 
@@ -1761,11 +2157,20 @@  discard block
 block discarded – undo
1761 2157
 	{
1762 2158
 		$account = $folder = null;
1763 2159
 		$this->splitID($folderid, $account, $folder);
1764
-		if (is_numeric($account)) $type = 'mail';
2160
+		if (is_numeric($account))
2161
+		{
2162
+			$type = 'mail';
2163
+		}
1765 2164
 
1766
-		if ($type != 'mail') return false;
2165
+		if ($type != 'mail')
2166
+		{
2167
+			return false;
2168
+		}
1767 2169
 
1768
-		if (!isset($this->mail)) $this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
2170
+		if (!isset($this->mail))
2171
+		{
2172
+			$this->mail = Mail::getInstance(false,self::$profileID,true,false,true);
2173
+		}
1769 2174
 
1770 2175
         $this->mail->reopen($folder);
1771 2176
 
@@ -1810,7 +2215,7 @@  discard block
 block discarded – undo
1810 2215
      * @throws StatusException              could throw specific SYNC_STATUS_* exceptions
1811 2216
      */
1812 2217
     public function DeleteMessage($folderid, $id, $contentParameters)
1813
-	{
2218
+    {
1814 2219
 		unset($contentParameters);	// not used, but required by function signature
1815 2220
 		ZLog::Write(LOGLEVEL_DEBUG, "IMAP-DeleteMessage: (fid: '$folderid'  id: '$id' )");
1816 2221
 		/*
@@ -1836,7 +2241,10 @@  discard block
 block discarded – undo
1836 2241
 			$error = $e->getMessage();
1837 2242
 			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__.__LINE__." $_messageUID, $folder ->".$error);
1838 2243
 			// if the server thinks the message does not exist report deletion as success
1839
-			if (stripos($error,'[NONEXISTENT]')!==false) return true;
2244
+			if (stripos($error,'[NONEXISTENT]')!==false)
2245
+			{
2246
+				return true;
2247
+			}
1840 2248
 			return false;
1841 2249
 		}
1842 2250
 
@@ -1869,7 +2277,7 @@  discard block
 block discarded – undo
1869 2277
      * @throws StatusException              could throw specific SYNC_STATUS_* exceptions
1870 2278
      */
1871 2279
     public function SetReadFlag($folderid, $id, $flags, $contentParameters)
1872
-	{
2280
+    {
1873 2281
 		unset($contentParameters);	// not used, but required by function signature
1874 2282
 		// ZLog::Write(LOGLEVEL_DEBUG, "IMAP-SetReadFlag: (fid: '$folderid'  id: '$id'  flags: '$flags' )");
1875 2283
 		$account = $folder = null;
@@ -1955,7 +2363,10 @@  discard block
 block discarded – undo
1955 2363
 
1956 2364
 		$str = $this->backend->createID($account, $folder, $id);
1957 2365
 
1958
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
2366
+		if ($this->debugLevel>1)
2367
+		{
2368
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."($account,'$f',$id) type=$account, folder=$folder --> '$str'");
2369
+		}
1959 2370
 
1960 2371
 		return $str;
1961 2372
 	}
@@ -1976,7 +2387,10 @@  discard block
 block discarded – undo
1976 2387
 		// convert numeric folder-id back to folder name
1977 2388
 		$folder = $this->hash2folder($account,$f=$folder);
1978 2389
 
1979
-		if ($this->debugLevel>1) ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$str','$account','$folder',$id)");
2390
+		if ($this->debugLevel>1)
2391
+		{
2392
+			ZLog::Write(LOGLEVEL_DEBUG,__METHOD__."('$str','$account','$folder',$id)");
2393
+		}
1980 2394
 	}
1981 2395
 
1982 2396
 	/**
@@ -1995,7 +2409,10 @@  discard block
 block discarded – undo
1995 2409
 	 */
1996 2410
 	private function folder2hash($account,$folder)
1997 2411
 	{
1998
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
2412
+		if(!isset($this->folderHashes))
2413
+		{
2414
+			$this->readFolderHashes();
2415
+		}
1999 2416
 
2000 2417
 		if (($index = array_search($folder, (array)$this->folderHashes[$account])) === false)
2001 2418
 		{
@@ -2018,7 +2435,10 @@  discard block
 block discarded – undo
2018 2435
 	 */
2019 2436
 	private function hash2folder($account,$index)
2020 2437
 	{
2021
-		if(!isset($this->folderHashes)) $this->readFolderHashes();
2438
+		if(!isset($this->folderHashes))
2439
+		{
2440
+			$this->readFolderHashes();
2441
+		}
2022 2442
 
2023 2443
 		return isset($this->folderHashes[$account]) ? $this->folderHashes[$account][$index] : null;
2024 2444
 	}
Please login to merge, or discard this patch.