Completed
Push — master ( 0bd975...40d1e5 )
by Klaus
19:57
created
api/src/Mail.php 1 patch
Braces   +1778 added lines, -527 removed lines patch added patch discarded remove patch
@@ -199,7 +199,10 @@  discard block
 block discarded – undo
199 199
 	public static function getInstance($_restoreSession=true, &$_profileID=0, $_validate=true, $_oldImapServerObject=false, $_reuseCache=null)
200 200
 	{
201 201
 		//$_restoreSession=false;
202
-		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
202
+		if (is_null($_reuseCache))
203
+		{
204
+			$_reuseCache = $_restoreSession;
205
+		}
203 206
 		//error_log(__METHOD__.' ('.__LINE__.') '.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID.'/'.Mail\Account::get_default_acc_id().' for user:'.$GLOBALS['egw_info']['user']['account_lid'].' called from:'.function_backtrace());
204 207
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_oldImapServerObject));
205 208
 		if (isset(self::$profileDefunct[$_profileID]) && self::$profileDefunct[$_profileID]===true)
@@ -229,9 +232,15 @@  discard block
 block discarded – undo
229 232
 			{
230 233
 				$profileID = Mail\Account::get_default_acc_id();
231 234
 			}
232
-			if ($profileID!=$_profileID) $_restoreSession==false;
235
+			if ($profileID!=$_profileID)
236
+			{
237
+				$_restoreSession==false;
238
+			}
233 239
 			$_profileID=$profileID;
234
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace());
240
+			if (self::$debug)
241
+			{
242
+				error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace());
243
+			}
235 244
 		}
236 245
 		// no validation or restoreSession for old ImapServer Object, just fetch it and return it
237 246
 		if ($_oldImapServerObject===true)
@@ -270,7 +279,8 @@  discard block
 block discarded – undo
270 279
 				// TODO: merge mailprefs into userprefs, for easy treatment
271 280
 				self::$instances[$_profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
272 281
 				self::$instances[$_profileID]->htmlOptions  = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
273
-			} catch (\Exception $e)
282
+			}
283
+			catch (\Exception $e)
274 284
 			{
275 285
 				$newprofileID = Mail\Account::get_default_acc_id();
276 286
 				// try loading the default profile for the user
@@ -288,9 +298,15 @@  discard block
 block discarded – undo
288 298
 			self::storeActiveProfileIDToPref(self::$instances[$_profileID]->icServer, $_profileID, $_validate );
289 299
 		}
290 300
 		self::$instances[$_profileID]->profileID = $_profileID;
291
-		if (!isset(self::$instances[$_profileID]->idna2)) self::$instances[$_profileID]->idna2 = new Horde_Idna;
301
+		if (!isset(self::$instances[$_profileID]->idna2))
302
+		{
303
+			self::$instances[$_profileID]->idna2 = new Horde_Idna;
304
+		}
292 305
 		//if ($_profileID==0); error_log(__METHOD__.' ('.__LINE__.') '.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID);
293
-		if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
306
+		if (is_null(self::$mailConfig))
307
+		{
308
+			self::$mailConfig = Config::read('mail');
309
+		}
294 310
 		return self::$instances[$_profileID];
295 311
 	}
296 312
 
@@ -315,14 +331,20 @@  discard block
 block discarded – undo
315 331
 			}
316 332
 			catch (\Exception $e)
317 333
 			{
318
-				if ($_profileID != Mail\Account::get_default_acc_id()) $_profileID = Mail\Account::get_default_acc_id();
334
+				if ($_profileID != Mail\Account::get_default_acc_id())
335
+				{
336
+					$_profileID = Mail\Account::get_default_acc_id();
337
+				}
319 338
 				error_log(__METHOD__.__LINE__.' '.$e->getMessage());
320 339
 				return false;
321 340
 			}
322 341
 		}
323 342
 		if ($oldProfileID != $_profileID)
324 343
 		{
325
-			if ($oldProfileID && $_profileID==0) $_profileID = $oldProfileID;
344
+			if ($oldProfileID && $_profileID==0)
345
+			{
346
+				$_profileID = $oldProfileID;
347
+			}
326 348
 			$GLOBALS['egw']->preferences->add('mail','ActiveProfileID',$_profileID,'user');
327 349
 			// save prefs
328 350
 			$GLOBALS['egw']->preferences->save_repository(true);
@@ -352,11 +374,17 @@  discard block
 block discarded – undo
352 374
 				{
353 375
 					return $_acc_id;
354 376
 				}
355
-				if (self::$debug) error_log(__METHOD__."($_acc_id) account NOT valid, no imap-host!");
377
+				if (self::$debug)
378
+				{
379
+					error_log(__METHOD__."($_acc_id) account NOT valid, no imap-host!");
380
+				}
356 381
 			}
357 382
 			catch (\Exception $e) {
358 383
 				unset($e);
359
-				if (self::$debug) error_log(__METHOD__."($_acc_id) account NOT found!");
384
+				if (self::$debug)
385
+				{
386
+					error_log(__METHOD__."($_acc_id) account NOT found!");
387
+				}
360 388
 			}
361 389
 		}
362 390
 		// no account specified or specified account not found or not valid
@@ -365,11 +393,17 @@  discard block
 block discarded – undo
365 393
 		{
366 394
 			if (!empty($imap_host) && ($account = Mail\Account::read($acc_id)) && $account->is_imap())
367 395
 			{
368
-				if (self::$debug && $_acc_id) error_log(__METHOD__."($_acc_id) using $acc_id instead");
396
+				if (self::$debug && $_acc_id)
397
+				{
398
+					error_log(__METHOD__."($_acc_id) using $acc_id instead");
399
+				}
369 400
 				return $acc_id;
370 401
 			}
371 402
 		}
372
-		if (self::$debug) error_log(__METHOD__."($_acc_id) NO valid account found!");
403
+		if (self::$debug)
404
+		{
405
+			error_log(__METHOD__."($_acc_id) NO valid account found!");
406
+		}
373 407
 		return 0;
374 408
 	}
375 409
 
@@ -385,10 +419,19 @@  discard block
 block discarded – undo
385 419
 	 */
386 420
 	private function __construct($_displayCharset='utf-8',$_restoreSession=true, $_profileID=0, $_oldImapServerObject=false, $_reuseCache=null)
387 421
 	{
388
-		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
389
-		if (!empty($_displayCharset)) self::$displayCharset = $_displayCharset;
422
+		if (is_null($_reuseCache))
423
+		{
424
+			$_reuseCache = $_restoreSession;
425
+		}
426
+		if (!empty($_displayCharset))
427
+		{
428
+			self::$displayCharset = $_displayCharset;
429
+		}
390 430
 		// not nummeric, we assume we only want an empty class object
391
-		if (!is_numeric($_profileID)) return true;
431
+		if (!is_numeric($_profileID))
432
+		{
433
+			return true;
434
+		}
392 435
 		if ($_restoreSession)
393 436
 		{
394 437
 			//error_log(__METHOD__." Session restore ".function_backtrace());
@@ -403,7 +446,10 @@  discard block
 block discarded – undo
403 446
 			$firstMessage = $this->sessionData['previewMessage'];
404 447
 			$this->sessionData = array();
405 448
 		}
406
-		if (!$_reuseCache) $this->forcePrefReload($_profileID,!$_reuseCache);
449
+		if (!$_reuseCache)
450
+		{
451
+			$this->forcePrefReload($_profileID,!$_reuseCache);
452
+		}
407 453
 		try
408 454
 		{
409 455
 			$this->profileID = self::validateProfileID($_profileID);
@@ -427,7 +473,10 @@  discard block
 block discarded – undo
427 473
 			$_profileID = $this->profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $this->icServer->ImapServerId;
428 474
 		}
429 475
 
430
-		if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
476
+		if (is_null(self::$mailConfig))
477
+		{
478
+			self::$mailConfig = Config::read('mail');
479
+		}
431 480
 	}
432 481
 
433 482
 	/**
@@ -456,7 +505,10 @@  discard block
 block discarded – undo
456 505
 		// unset the mail_preferences session object, to force the reload/rebuild
457 506
 		Cache::setSession('mail','mail_preferences',serialize(array()));
458 507
 		Cache::setSession('emailadmin','session_data',serialize(array()));
459
-		if ($_resetFolderObjects) self::resetFolderObjectCache($_profile_id);
508
+		if ($_resetFolderObjects)
509
+		{
510
+			self::resetFolderObjectCache($_profile_id);
511
+		}
460 512
 	}
461 513
 
462 514
 	/**
@@ -466,7 +518,10 @@  discard block
 block discarded – undo
466 518
 	{
467 519
 		$this->sessionData = array();//Cache::getCache(Cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1);
468 520
 		self::$activeFolderCache = Cache::getCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
469
-		if (!empty(self::$activeFolderCache[$this->profileID])) $this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID];
521
+		if (!empty(self::$activeFolderCache[$this->profileID]))
522
+		{
523
+			$this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID];
524
+		}
470 525
 	}
471 526
 
472 527
 	/**
@@ -475,7 +530,10 @@  discard block
 block discarded – undo
475 530
 	function saveSessionData()
476 531
 	{
477 532
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($this->sessionData)));
478
-		if (!empty($this->sessionData['mailbox'])) self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox'];
533
+		if (!empty($this->sessionData['mailbox']))
534
+		{
535
+			self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox'];
536
+		}
479 537
 		if (isset(self::$activeFolderCache) && is_array(self::$activeFolderCache))
480 538
 		{
481 539
 			Cache::setCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),self::$activeFolderCache, 60*60*10);
@@ -496,8 +554,14 @@  discard block
 block discarded – undo
496 554
 	 */
497 555
 	static function unsetCachedObjects($_profileID=null)
498 556
 	{
499
-		if (is_null($_profileID)) $_profileID = Mail\Account::get_default_acc_id();
500
-		if (is_array($_profileID) && $_profileID['account_id']) $account_id = $_profileID['account_id'];
557
+		if (is_null($_profileID))
558
+		{
559
+			$_profileID = Mail\Account::get_default_acc_id();
560
+		}
561
+		if (is_array($_profileID) && $_profileID['account_id'])
562
+		{
563
+			$account_id = $_profileID['account_id'];
564
+		}
501 565
 		//error_log(__METHOD__.__LINE__.' called with ProfileID:'.array2string($_profileID).' from '.function_backtrace());
502 566
 		if (!is_array($_profileID) && (is_numeric($_profileID) || !(stripos($_profileID,'tracker_')===false)))
503 567
 		{
@@ -530,7 +594,10 @@  discard block
 block discarded – undo
530 594
 				Cache::setCache(Cache::INSTANCE,'email','vacationNotice'.trim($account_id),$vacationCached, $expiration=60*60*24*1);
531 595
 			}
532 596
 
533
-			if (isset(self::$instances[$_profileID])) unset(self::$instances[$_profileID]);
597
+			if (isset(self::$instances[$_profileID]))
598
+			{
599
+				unset(self::$instances[$_profileID]);
600
+			}
534 601
 		}
535 602
 		if (is_array($_profileID) && $_profileID['location'] == 'clear_cache')
536 603
 		{
@@ -559,7 +626,10 @@  discard block
 block discarded – undo
559 626
 	static function resetConnectionErrorCache($_ImapServerId=null,$account_id=null)
560 627
 	{
561 628
 		//error_log(__METHOD__.' ('.__LINE__.') '.' for Profile:'.array2string($_ImapServerId) .' for user:'.trim($account_id));
562
-		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
629
+		if (is_null($account_id))
630
+		{
631
+			$account_id = $GLOBALS['egw_info']['user']['account_id'];
632
+		}
563 633
 		if (is_array($_ImapServerId))
564 634
 		{
565 635
 			// called via hook
@@ -598,7 +668,10 @@  discard block
 block discarded – undo
598 668
 	static function resetFolderObjectCache($_ImapServerId=null,$account_id=null)
599 669
 	{
600 670
 		//error_log(__METHOD__.' ('.__LINE__.') '.' called for Profile:'.array2string($_ImapServerId).'->'.function_backtrace());
601
-		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
671
+		if (is_null($account_id))
672
+		{
673
+			$account_id = $GLOBALS['egw_info']['user']['account_id'];
674
+		}
602 675
 		// on [location] => verify_settings we coud either use [prefs] => Array([ActiveProfileID] => 9, .. as $_ImapServerId
603 676
 		// or treat it as not given. we try that path
604 677
 		if (is_null($_ImapServerId)||is_array($_ImapServerId))
@@ -672,10 +745,14 @@  discard block
 block discarded – undo
672 745
 
673 746
 		$userEMailAdresses = array($acc['ident_email']=>$acc['ident_realname']);
674 747
 
675
-		foreach($identities as $ik => $ident) {
748
+		foreach($identities as $ik => $ident)
749
+		{
676 750
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
677 751
 			$identity = Mail\Account::read_identity($ik);
678
-			if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']])) $userEMailAdresses[$identity['ident_email']] = $identity['ident_realname'];
752
+			if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']]))
753
+			{
754
+				$userEMailAdresses[$identity['ident_email']] = $identity['ident_realname'];
755
+			}
679 756
 		}
680 757
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses));
681 758
 		return $userEMailAdresses;
@@ -693,13 +770,20 @@  discard block
 block discarded – undo
693 770
 		foreach(Mail\Account::search($only_current_user=($_accountToSearch?$_accountToSearch:true), $just_name=true) as $acc_id => $identity_name)
694 771
 		{
695 772
 			$acc = Mail\Account::read($acc_id,($_accountToSearch?$_accountToSearch:null));
696
-			if (!$resolve_placeholders) $userEMailAdresses[$acc['ident_id']] = array('acc_id'=>$acc_id,'ident_id'=>$acc['ident_id'],'ident_email'=>$acc['ident_email'],'ident_org'=>$acc['ident_org'],'ident_realname'=>$acc['ident_realname'],'ident_signature'=>$acc['ident_signature'],'ident_name'=>$acc['ident_name']);
773
+			if (!$resolve_placeholders)
774
+			{
775
+				$userEMailAdresses[$acc['ident_id']] = array('acc_id'=>$acc_id,'ident_id'=>$acc['ident_id'],'ident_email'=>$acc['ident_email'],'ident_org'=>$acc['ident_org'],'ident_realname'=>$acc['ident_realname'],'ident_signature'=>$acc['ident_signature'],'ident_name'=>$acc['ident_name']);
776
+			}
697 777
 
698
-			foreach(Mail\Account::identities($acc) as $ik => $ident) {
778
+			foreach(Mail\Account::identities($acc) as $ik => $ident)
779
+			{
699 780
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
700 781
 				$identity = Mail\Account::read_identity($ik,$resolve_placeholders);
701 782
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
702
-				if (!isset($userEMailAdresses[$identity['ident_id']])) $userEMailAdresses[$identity['ident_id']] = array('acc_id'=>$acc_id,'ident_id'=>$identity['ident_id'],'ident_email'=>$identity['ident_email'],'ident_org'=>$identity['ident_org'],'ident_realname'=>$identity['ident_realname'],'ident_signature'=>$identity['ident_signature'],'ident_name'=>$identity['ident_name']);
783
+				if (!isset($userEMailAdresses[$identity['ident_id']]))
784
+				{
785
+					$userEMailAdresses[$identity['ident_id']] = array('acc_id'=>$acc_id,'ident_id'=>$identity['ident_id'],'ident_email'=>$identity['ident_email'],'ident_org'=>$identity['ident_org'],'ident_realname'=>$identity['ident_realname'],'ident_signature'=>$identity['ident_signature'],'ident_name'=>$identity['ident_name']);
786
+				}
703 787
 			}
704 788
 		}
705 789
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses));
@@ -719,12 +803,16 @@  discard block
 block discarded – undo
719 803
 			$account = Mail\Account::read($account);
720 804
 		}
721 805
 		$userEMailAdresses = array();
722
-		foreach(Mail\Account::identities($account, true, 'params') as $ik => $ident) {
806
+		foreach(Mail\Account::identities($account, true, 'params') as $ik => $ident)
807
+		{
723 808
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
724 809
 			$identity = Mail\Account::read_identity($ik,true,null,$account);
725 810
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
726 811
 			// standardIdentity has ident_id==acc_id (as it is done within account->identities)
727
-			if (empty($identity['ident_id'])) $identity['ident_id'] = $identity['acc_id'];
812
+			if (empty($identity['ident_id']))
813
+			{
814
+				$identity['ident_id'] = $identity['acc_id'];
815
+			}
728 816
 			if (!isset($userEMailAdresses[$identity['ident_id']]))
729 817
 			{
730 818
 				$userEMailAdresses[$identity['ident_id']] = array('acc_id'=>$identity['acc_id'],
@@ -767,15 +855,25 @@  discard block
 block discarded – undo
767 855
 		// account select box
768 856
 		$selectedID = $this->profileID;
769 857
 		$allAccountData = Mail\Account::search($only_current_user=true, false, null);
770
-		if ($allAccountData) {
858
+		if ($allAccountData)
859
+		{
771 860
 			$rememberFirst=$selectedFound=null;
772 861
 			foreach ($allAccountData as $tmpkey => $icServers)
773 862
 			{
774
-				if (is_null($rememberFirst)) $rememberFirst = $tmpkey;
775
-				if ($tmpkey == $selectedID) $selectedFound=true;
863
+				if (is_null($rememberFirst))
864
+				{
865
+					$rememberFirst = $tmpkey;
866
+				}
867
+				if ($tmpkey == $selectedID)
868
+				{
869
+					$selectedFound=true;
870
+				}
776 871
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($icServers->acc_imap_host));
777 872
 				$host = $icServers->acc_imap_host;
778
-				if (empty($host)) continue;
873
+				if (empty($host))
874
+				{
875
+					continue;
876
+				}
779 877
 				$identities[$icServers->acc_id] = $icServers['ident_realname'].' '.$icServers['ident_org'].' <'.$icServers['ident_email'].'>';
780 878
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($identities[$icServers->acc_id]));
781 879
 			}
@@ -835,7 +933,10 @@  discard block
 block discarded – undo
835 933
 	 */
836 934
 	function reopen($_foldername)
837 935
 	{
838
-		if (self::$debugTimes) $starttime = microtime (true);
936
+		if (self::$debugTimes)
937
+		{
938
+			$starttime = microtime (true);
939
+		}
839 940
 
840 941
 		//error_log(__METHOD__.' ('.__LINE__.') '."('$_foldername') ".function_backtrace());
841 942
 		// TODO: trying to reduce traffic to the IMAP Server here, introduces problems with fetching the bodies of
@@ -845,12 +946,16 @@  discard block
 block discarded – undo
845 946
 		//{
846 947
 			//error_log( __METHOD__.' ('.__LINE__.') '." $_foldername ".function_backtrace());
847 948
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Connected with icServer for Profile:'.$this->profileID.'?'.print_r($this->icServer->_connected,true));
848
-			if ($this->folderIsSelectable($_foldername)) {
949
+			if ($this->folderIsSelectable($_foldername))
950
+			{
849 951
 				$this->icServer->openMailbox($_foldername);
850 952
 			}
851 953
 			$folderOpened = $_foldername;
852 954
 		//}
853
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') ');
955
+		if (self::$debugTimes)
956
+		{
957
+			self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') ');
958
+		}
854 959
 	}
855 960
 
856 961
 
@@ -865,13 +970,22 @@  discard block
 block discarded – undo
865 970
 	{
866 971
 		//error_log( "-------------------------->open connection ".function_backtrace());
867 972
 		//error_log(__METHOD__.' ('.__LINE__.') '.' ->'.array2string($this->icServer));
868
-		if (self::$debugTimes) $starttime = microtime (true);
973
+		if (self::$debugTimes)
974
+		{
975
+			$starttime = microtime (true);
976
+		}
869 977
 		$mailbox=null;
870 978
 		try
871 979
 		{
872
-			if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox'])) $mailbox = $this->sessionData['mailbox'];
873
-			if (empty($mailbox)) $mailbox = $this->icServer->getCurrentMailbox();
874
-/*
980
+			if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox']))
981
+			{
982
+				$mailbox = $this->sessionData['mailbox'];
983
+			}
984
+			if (empty($mailbox))
985
+			{
986
+				$mailbox = $this->icServer->getCurrentMailbox();
987
+			}
988
+			/*
875 989
 			if (isset(Mail\Imap::$supports_keywords[$_icServerID]))
876 990
 			{
877 991
 				$this->icServer->openMailbox($mailbox);
@@ -896,7 +1010,10 @@  discard block
 block discarded – undo
896 1010
 			error_log(__METHOD__.' ('.__LINE__.') '."->open connection for Server with profileID:".$_icServerID." trying to examine ($mailbox) failed!".$e->getMessage());
897 1011
 			throw new Exception(__METHOD__." failed to ".__METHOD__." on Profile to $_icServerID while trying to examine $mailbox:".$e->getMessage());
898 1012
 		}
899
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') ');
1013
+		if (self::$debugTimes)
1014
+		{
1015
+			self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') ');
1016
+		}
900 1017
 	}
901 1018
 
902 1019
 	/**
@@ -908,7 +1025,10 @@  discard block
 block discarded – undo
908 1025
 	function getQuotaRoot()
909 1026
 	{
910 1027
 		static $quota;
911
-		if (isset($quota)) return $quota;
1028
+		if (isset($quota))
1029
+		{
1030
+			return $quota;
1031
+		}
912 1032
 		if (isset(self::$profileDefunct[$this->profileID]) && self::$profileDefunct[$this->profileID]===true)
913 1033
 		{
914 1034
 			// something is wrong. Do not proceed. either no folder or profile is marked as defunct for this request
@@ -917,7 +1037,8 @@  discard block
 block discarded – undo
917 1037
 		try
918 1038
 		{
919 1039
 			$this->icServer->getCurrentMailbox();
920
-			if(!$this->icServer->hasCapability('QUOTA')) {
1040
+			if(!$this->icServer->hasCapability('QUOTA'))
1041
+			{
921 1042
 				$quota = false;
922 1043
 				return false;
923 1044
 			}
@@ -934,12 +1055,15 @@  discard block
 block discarded – undo
934 1055
 			}
935 1056
 		}
936 1057
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($quota));
937
-		if(is_array($quota)) {
1058
+		if(is_array($quota))
1059
+		{
938 1060
 			$quota = array(
939 1061
 				'usage'	=> $quota['USED'],
940 1062
 				'limit'	=> $quota['QMAX'],
941 1063
 			);
942
-		} else {
1064
+		}
1065
+		else
1066
+		{
943 1067
 			$quota = false;
944 1068
 		}
945 1069
 		return $quota;
@@ -955,7 +1079,11 @@  discard block
 block discarded – undo
955 1079
 	static function getTimeOut($_use='IMAP')
956 1080
 	{
957 1081
 		$timeout = $GLOBALS['egw_info']['user']['preferences']['mail']['connectionTimeout'];
958
-		if (empty($timeout)) $timeout = ($_use=='SIEVE'?10:20); // this is the default value
1082
+		if (empty($timeout))
1083
+		{
1084
+			$timeout = ($_use=='SIEVE'?10:20);
1085
+		}
1086
+		// this is the default value
959 1087
 		return $timeout;
960 1088
 	}
961 1089
 
@@ -973,9 +1101,13 @@  discard block
 block discarded – undo
973 1101
 		$foldersNameSpace = array();
974 1102
 		$delimiter = $this->getHierarchyDelimiter();
975 1103
 		// TODO: cache by $this->icServer->ImapServerId
976
-		if (is_null($nameSpace)) $nameSpace = $this->icServer->getNameSpaceArray();
1104
+		if (is_null($nameSpace))
1105
+		{
1106
+			$nameSpace = $this->icServer->getNameSpaceArray();
1107
+		}
977 1108
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($nameSpace));
978
-		if (is_array($nameSpace)) {
1109
+		if (is_array($nameSpace))
1110
+		{
979 1111
 			foreach($nameSpace as $type => $singleNameSpaceArray)
980 1112
 			{
981 1113
 				foreach ($singleNameSpaceArray as $singleNameSpace)
@@ -992,7 +1124,9 @@  discard block
 block discarded – undo
992 1124
 						$_foldersNameSpace['prefix_present'] = 'forced';
993 1125
 						// uw-imap server with mailbox prefix or dovecot maybe
994 1126
 						$_foldersNameSpace['prefix'] = 'mail';
995
-					} else {
1127
+					}
1128
+					else
1129
+					{
996 1130
 						$_foldersNameSpace['prefix_present'] = !empty($singleNameSpace['name']);
997 1131
 						$_foldersNameSpace['prefix'] = $singleNameSpace['name'];
998 1132
 					}
@@ -1019,7 +1153,10 @@  discard block
 block discarded – undo
1019 1153
 		foreach($nameSpace as &$singleNameSpace)
1020 1154
 		{
1021 1155
 			//if (substr($singleNameSpace['prefix'],0,strlen($folderName))==$folderName) return $singleNameSpace['prefix'];
1022
-			if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix']) return $singleNameSpace['prefix'];
1156
+			if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix'])
1157
+			{
1158
+				return $singleNameSpace['prefix'];
1159
+			}
1023 1160
 		}
1024 1161
 		return "";
1025 1162
 	}
@@ -1033,8 +1170,14 @@  discard block
 block discarded – undo
1033 1170
 	function getHierarchyDelimiter($_useCache=true)
1034 1171
 	{
1035 1172
 		static $HierarchyDelimiter = null;
1036
-		if (is_null($HierarchyDelimiter)) $HierarchyDelimiter = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1037
-		if ($_useCache===false) unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1173
+		if (is_null($HierarchyDelimiter))
1174
+		{
1175
+			$HierarchyDelimiter = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1176
+		}
1177
+		if ($_useCache===false)
1178
+		{
1179
+			unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1180
+		}
1038 1181
 		if (isset($HierarchyDelimiter[$this->icServer->ImapServerId])&&!empty($HierarchyDelimiter[$this->icServer->ImapServerId]))
1039 1182
 		{
1040 1183
 			return $HierarchyDelimiter[$this->icServer->ImapServerId];
@@ -1047,7 +1190,10 @@  discard block
 block discarded – undo
1047 1190
 		}
1048 1191
 		catch(\Exception $e)
1049 1192
 		{
1050
-			if ($e->getCode()==102) self::$profileDefunct[$this->profileID]=true;
1193
+			if ($e->getCode()==102)
1194
+			{
1195
+				self::$profileDefunct[$this->profileID]=true;
1196
+			}
1051 1197
 			unset($e);
1052 1198
 			$HierarchyDelimiter[$this->icServer->ImapServerId] = '/';
1053 1199
 		}
@@ -1064,14 +1210,19 @@  discard block
 block discarded – undo
1064 1210
 	{
1065 1211
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$this->icServer->ImapServerId.' Connected:'.$this->icServer->_connected);
1066 1212
 		static $_specialUseFolders = null;
1067
-		if (is_null($_specialUseFolders)||empty($_specialUseFolders)) $_specialUseFolders = Cache::getCache(Cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1213
+		if (is_null($_specialUseFolders)||empty($_specialUseFolders))
1214
+		{
1215
+			$_specialUseFolders = Cache::getCache(Cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1216
+		}
1068 1217
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_trash));
1069 1218
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_sent));
1070 1219
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_draft));
1071 1220
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_template));
1072 1221
 		self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId];
1073 1222
 		if (isset($_specialUseFolders[$this->icServer->ImapServerId]) && !empty($_specialUseFolders[$this->icServer->ImapServerId]))
1074
-			return $_specialUseFolders[$this->icServer->ImapServerId];
1223
+		{
1224
+					return $_specialUseFolders[$this->icServer->ImapServerId];
1225
+		}
1075 1226
 		$_specialUseFolders[$this->icServer->ImapServerId]=array();
1076 1227
 		//if (!empty($this->icServer->acc_folder_trash) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]))
1077 1228
 			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]='Trash';
@@ -1099,7 +1250,8 @@  discard block
 block discarded – undo
1099 1250
 	function folderIsSelectable($folderToSelect)
1100 1251
 	{
1101 1252
 		$retval = true;
1102
-		if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true))) {
1253
+		if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true)))
1254
+		{
1103 1255
 			if (!empty($folderStatus['attributes']) && stripos(array2string($folderStatus['attributes']),'noselect')!==false)
1104 1256
 			{
1105 1257
 				$retval = false;
@@ -1152,7 +1304,10 @@  discard block
 block discarded – undo
1152 1304
 	 */
1153 1305
 	function getFolderStatus($_folderName,$ignoreStatusCache=false,$basicInfoOnly=false,$fetchSubscribedInfo=true)
1154 1306
 	{
1155
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly");
1307
+		if (self::$debug)
1308
+		{
1309
+			error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly");
1310
+		}
1156 1311
 		if (!is_string($_folderName) || empty($_folderName)||(isset(self::$profileDefunct[$this->profileID]) && self::$profileDefunct[$this->profileID]===true))
1157 1312
 		{
1158 1313
 			// something is wrong. Do not proceed. either no folder or profile is marked as defunct for this request
@@ -1164,7 +1319,10 @@  discard block
 block discarded – undo
1164 1319
 		{
1165 1320
 			$folderInfoCache = $folderBasicInfo[$this->profileID];
1166 1321
 		}
1167
-		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly) return $folderInfoCache[$_folderName];
1322
+		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly)
1323
+		{
1324
+			return $folderInfoCache[$_folderName];
1325
+		}
1168 1326
 		$retValue = array();
1169 1327
 		$retValue['subscribed'] = false;
1170 1328
 /*
@@ -1192,7 +1350,10 @@  discard block
 block discarded – undo
1192 1350
 			if (is_array($ret))
1193 1351
 			{
1194 1352
 				$retkeys = array_keys($ret);
1195
-				if ($retkeys[0]==$_folderName) $folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1353
+				if ($retkeys[0]==$_folderName)
1354
+				{
1355
+					$folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1356
+				}
1196 1357
 			}
1197 1358
 			else
1198 1359
 			{
@@ -1201,7 +1362,8 @@  discard block
 block discarded – undo
1201 1362
 		}
1202 1363
 		$folderInfo = $folderInfoCache[$_folderName];
1203 1364
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($folderInfo).'->'.function_backtrace());
1204
-		if($ignoreStatusCache||!$folderInfo|| !is_array($folderInfo)) {
1365
+		if($ignoreStatusCache||!$folderInfo|| !is_array($folderInfo))
1366
+		{
1205 1367
 			try
1206 1368
 			{
1207 1369
 				$folderInfo = $this->_getStatus($_folderName,$ignoreStatusCache);
@@ -1235,7 +1397,8 @@  discard block
 block discarded – undo
1235 1397
 		$retValue['shortName']		= array_pop($shortNameParts);
1236 1398
 		$retValue['displayName']	= $_folderName;
1237 1399
 		$retValue['shortDisplayName']	= $retValue['shortName'];
1238
-		if(strtoupper($retValue['shortName']) == 'INBOX') {
1400
+		if(strtoupper($retValue['shortName']) == 'INBOX')
1401
+		{
1239 1402
 			$retValue['displayName']	= lang('INBOX');
1240 1403
 			$retValue['shortDisplayName']	= lang('INBOX');
1241 1404
 		}
@@ -1244,7 +1407,10 @@  discard block
 block discarded – undo
1244 1407
 		{
1245 1408
 			$retValue['displayName'] = $retValue['shortDisplayName'] = lang($retValue['shortName']);
1246 1409
 		}
1247
-		if ($folderInfo) $folderBasicInfo[$this->profileID][$_folderName]=$retValue;
1410
+		if ($folderInfo)
1411
+		{
1412
+			$folderBasicInfo[$this->profileID][$_folderName]=$retValue;
1413
+		}
1248 1414
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.$_folderName.array2string($retValue['attributes']));
1249 1415
 		if ($basicInfoOnly || (isset($retValue['attributes']) && stripos(array2string($retValue['attributes']),'noselect')!==false))
1250 1416
 		{
@@ -1256,24 +1422,34 @@  discard block
 block discarded – undo
1256 1422
 		static $subscribedFolders = null;
1257 1423
 		static $nameSpace = null;
1258 1424
 		static $prefix = null;
1259
-		if (is_null($nameSpace) || empty($nameSpace[$this->profileID])) $nameSpace[$this->profileID] = $this->_getNameSpaces();
1425
+		if (is_null($nameSpace) || empty($nameSpace[$this->profileID]))
1426
+		{
1427
+			$nameSpace[$this->profileID] = $this->_getNameSpaces();
1428
+		}
1260 1429
 		if (!empty($nameSpace[$this->profileID]))
1261 1430
 		{
1262 1431
 			$nsNoPersonal=array();
1263 1432
 			foreach($nameSpace[$this->profileID] as &$ns)
1264 1433
 			{
1265
-				if ($ns['type']!='personal') $nsNoPersonal[]=$ns;
1434
+				if ($ns['type']!='personal')
1435
+				{
1436
+					$nsNoPersonal[]=$ns;
1437
+				}
1266 1438
 			}
1267 1439
 			$nameSpace[$this->profileID]=$nsNoPersonal;
1268 1440
 		}
1269
-		if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName])) $prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName);
1441
+		if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName]))
1442
+		{
1443
+			$prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName);
1444
+		}
1270 1445
 
1271 1446
 		if ($fetchSubscribedInfo && is_null($subscribedFolders) || empty($subscribedFolders[$this->profileID]))
1272 1447
 		{
1273 1448
 			$subscribedFolders[$this->profileID] = $this->icServer->listSubscribedMailboxes();
1274 1449
 		}
1275 1450
 
1276
-		if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID])) {
1451
+		if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID]))
1452
+		{
1277 1453
 			$retValue['subscribed'] = true;
1278 1454
 		}
1279 1455
 
@@ -1292,8 +1468,7 @@  discard block
 block discarded – undo
1292 1468
 				(isset($this->mailPreferences['trustServersUnseenInfo']) &&
1293 1469
 				$this->mailPreferences['trustServersUnseenInfo']==2 &&
1294 1470
 				$prefix[$this->profileID][$_folderName] != '' && stripos($_folderName,$prefix[$this->profileID][$_folderName]) !== false)
1295
-			)
1296
-			{
1471
+			) {
1297 1472
 				//error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($prefix,true).' TS:'.$this->mailPreferences['trustServersUnseenInfo']);
1298 1473
 				// we filter for the combined status of unseen and undeleted, as this is what we show in list
1299 1474
 				try
@@ -1304,13 +1479,19 @@  discard block
 block discarded – undo
1304 1479
 				}
1305 1480
 				catch (\Exception $ee)
1306 1481
 				{
1307
-					if (self::$debug) error_log(__METHOD__." could not fetch/calculate unseen counter for $_folderName Reason:'".$ee->getMessage()."' but requested.");
1482
+					if (self::$debug)
1483
+					{
1484
+						error_log(__METHOD__." could not fetch/calculate unseen counter for $_folderName Reason:'".$ee->getMessage()."' but requested.");
1485
+					}
1308 1486
 				}
1309 1487
 			}
1310 1488
 		}
1311 1489
 		catch (\Exception $e)
1312 1490
 		{
1313
-			if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1491
+			if (self::$debug)
1492
+			{
1493
+				error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1494
+			}
1314 1495
 		}
1315 1496
 
1316 1497
 		return $retValue;
@@ -1335,8 +1516,14 @@  discard block
 block discarded – undo
1335 1516
 	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true, $_fetchPreviews=false)
1336 1517
 	{
1337 1518
 		//self::$debug=true;
1338
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
1339
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName,$_startMessage, $_numberOfMessages, $_sort, $_reverse, ".array2string($_filter).", $_thisUIDOnly");
1519
+		if (self::$debug)
1520
+		{
1521
+			error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
1522
+		}
1523
+		if (self::$debug)
1524
+		{
1525
+			error_log(__METHOD__.' ('.__LINE__.') '."$_folderName,$_startMessage, $_numberOfMessages, $_sort, $_reverse, ".array2string($_filter).", $_thisUIDOnly");
1526
+		}
1340 1527
 		$reverse = (bool)$_reverse;
1341 1528
 		// get the list of messages to fetch
1342 1529
 		$this->reopen($_folderName);
@@ -1357,21 +1544,34 @@  discard block
 block discarded – undo
1357 1544
 				//$_filter['range'] ="$start:$end";
1358 1545
 				//$_filter['range'] ="$_startMessage:*";
1359 1546
 			}
1360
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1361
-			if (self::$debug||self::$debugTimes) $starttime = microtime (true);
1547
+			if (self::$debug)
1548
+			{
1549
+				error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1550
+			}
1551
+			if (self::$debug||self::$debugTimes)
1552
+			{
1553
+				$starttime = microtime (true);
1554
+			}
1362 1555
 			//see this example below for a 12 week datefilter (since)
1363 1556
 			//$_filter = array('status'=>array('UNDELETED'),'type'=>"SINCE",'string'=> date("d-M-Y", $starttime-(3600*24*7*12)));
1364 1557
 			$_sortResult = $this->getSortedList($_folderName, $_sort, $reverse, $_filter, $rByUid, $_cacheResult);
1365 1558
 			$sortResult = $_sortResult['match']->ids;
1366 1559
 			//$modseq = $_sortResult['modseq'];
1367 1560
 			//error_log(__METHOD__.' ('.__LINE__.') '.'Modsequence:'.$modseq);
1368
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1561
+			if (self::$debug||self::$debugTimes)
1562
+			{
1563
+				self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1564
+			}
1369 1565
 
1370
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1566
+			if (self::$debug)
1567
+			{
1568
+				error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1569
+			}
1371 1570
 			#$this->icServer->setDebug(false);
1372 1571
 			#print "</pre>";
1373 1572
 			// nothing found
1374
-			if(!is_array($sortResult) || empty($sortResult)) {
1573
+			if(!is_array($sortResult) || empty($sortResult))
1574
+			{
1375 1575
 				$retValue = array();
1376 1576
 				$retValue['info']['total']	= 0;
1377 1577
 				$retValue['info']['first']	= 0;
@@ -1383,7 +1583,8 @@  discard block
 block discarded – undo
1383 1583
 			#_debug_array($sortResult);
1384 1584
 			#_debug_array(array_slice($sortResult, -5, -2));
1385 1585
 			//error_log("REVERSE: $reverse");
1386
-			if($reverse === true) {
1586
+			if($reverse === true)
1587
+			{
1387 1588
 				if  ($_startMessage<=$total)
1388 1589
 				{
1389 1590
 					$startMessage = $_startMessage-1;
@@ -1395,7 +1596,10 @@  discard block
 block discarded – undo
1395 1596
 					{
1396 1597
 						$numberOfMessages = $total%$_numberOfMessages;
1397 1598
 						//$numberOfMessages = abs($_startMessage-$total-1);
1398
-						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages) $_numberOfMessages = $numberOfMessages;
1599
+						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages)
1600
+						{
1601
+							$_numberOfMessages = $numberOfMessages;
1602
+						}
1399 1603
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total);
1400 1604
 					}
1401 1605
 					$startMessage=($total-$_numberOfMessages)-1;
@@ -1409,19 +1613,36 @@  discard block
 block discarded – undo
1409 1613
 					//$retValue['info']['first'] = $startMessage;
1410 1614
 					//$retValue['info']['last'] = $total;
1411 1615
 				}
1412
-				if($startMessage > 0) {
1413
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1616
+				if($startMessage > 0)
1617
+				{
1618
+					if (self::$debug)
1619
+					{
1620
+						error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1621
+					}
1414 1622
 					$sortResult = array_slice($sortResult, -($_numberOfMessages+$startMessage), -$startMessage);
1415
-				} else {
1416
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1623
+				}
1624
+				else
1625
+				{
1626
+					if (self::$debug)
1627
+					{
1628
+						error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1629
+					}
1417 1630
 					$sortResult = array_slice($sortResult, -($_numberOfMessages+($_startMessage-1)));
1418 1631
 				}
1419 1632
 				$sortResult = array_reverse($sortResult);
1420
-			} else {
1421
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1633
+			}
1634
+			else
1635
+			{
1636
+				if (self::$debug)
1637
+				{
1638
+					error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1639
+				}
1422 1640
 				$sortResult = array_slice($sortResult, $_startMessage-1, $_numberOfMessages);
1423 1641
 			}
1424
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1642
+			if (self::$debug)
1643
+			{
1644
+				error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1645
+			}
1425 1646
 		}
1426 1647
 		else
1427 1648
 		{
@@ -1430,7 +1651,10 @@  discard block
 block discarded – undo
1430 1651
 
1431 1652
 
1432 1653
 		// fetch the data for the selected messages
1433
-		if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1654
+		if (self::$debug||self::$debugTimes)
1655
+		{
1656
+			$starttime = microtime(true);
1657
+		}
1434 1658
 		try
1435 1659
 		{
1436 1660
 			$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -1454,7 +1678,10 @@  discard block
 block discarded – undo
1454 1678
 			$fquery->flags();
1455 1679
 			$fquery->imapDate();// needed to ensure getImapDate fetches the internaldate, not the current time
1456 1680
 			// if $_fetchPreviews is activated fetch part of the messages too
1457
-			if ($_fetchPreviews) $fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0));
1681
+			if ($_fetchPreviews)
1682
+			{
1683
+				$fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0));
1684
+			}
1458 1685
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
1459 1686
 				'ids' => $uidsToFetch,
1460 1687
 			));
@@ -1477,14 +1704,20 @@  discard block
 block discarded – undo
1477 1704
 
1478 1705
 		$cnt = 0;
1479 1706
 
1480
-		foreach((array)$sortResult as $uid) {
1707
+		foreach((array)$sortResult as $uid)
1708
+		{
1481 1709
 			$sortOrder[$uid] = $cnt++;
1482 1710
 		}
1483 1711
 
1484 1712
 		$count = 0;
1485
-		if (is_object($headersNew)) {
1486
-			if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1487
-			foreach($headersNew->ids() as $id) {
1713
+		if (is_object($headersNew))
1714
+		{
1715
+			if (self::$debug||self::$debugTimes)
1716
+			{
1717
+				$starttime = microtime(true);
1718
+			}
1719
+			foreach($headersNew->ids() as $id)
1720
+			{
1488 1721
 				$_headerObject = $headersNew->get($id);
1489 1722
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject));
1490 1723
 				$headerObject = array();
@@ -1497,7 +1730,10 @@  discard block
 block discarded – undo
1497 1730
 				// Get already cached headers, 'fetchHeaders' is a label matchimg above
1498 1731
 				$headerForPrio = $_headerObject->getHeaders('fetchHeaders',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1499 1732
 				// Try to fetch header with key='' as some servers might have no fetchHeaders index. e.g. yandex.com
1500
-				if (empty($headerForPrio)) $headerForPrio = $_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1733
+				if (empty($headerForPrio))
1734
+				{
1735
+					$headerForPrio = $_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1736
+				}
1501 1737
 				//fetch the fullMsg part if all conditions match to be available in case $_headerObject->getHeaders returns
1502 1738
 				//nothing worthwhile (as it does for googlemail accounts, when preview is switched on
1503 1739
 				if ($_fetchPreviews)
@@ -1508,12 +1744,16 @@  discard block
 block discarded – undo
1508 1744
 					if (empty($headerForPrio)||(is_array($headerForPrio)&&count($headerForPrio)===1&&$headerForPrio['']))
1509 1745
 					{
1510 1746
 						$length = strpos($bodyPreview, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
1511
-						if ($length===false) $length = strlen($bodyPreview);
1747
+						if ($length===false)
1748
+						{
1749
+							$length = strlen($bodyPreview);
1750
+						}
1512 1751
 						$headerForPrio =  Horde_Mime_Headers::parseHeaders(substr($bodyPreview, 0,$length))->toArray();
1513 1752
 					}
1514 1753
 				}
1515 1754
 				$headerForPrio = array_change_key_case($headerForPrio, CASE_UPPER);
1516
-				if (self::$debug) {
1755
+				if (self::$debug)
1756
+				{
1517 1757
 					error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject).'UID:'.$_headerObject->getUid().' Size:'.$_headerObject->getSize().' Date:'.$_headerObject->getImapDate().'/'.DateTime::to($_headerObject->getImapDate(),'Y-m-d H:i:s'));
1518 1758
 					error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerForPrio));
1519 1759
 				}
@@ -1523,11 +1763,16 @@  discard block
 block discarded – undo
1523 1763
 					$total--;
1524 1764
 					continue;
1525 1765
 				}
1526
-				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) ) {
1766
+				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) )
1767
+				{
1527 1768
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['DISPOSITION-NOTIFICATION-TO']));
1528
-				} else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) ) {
1769
+				}
1770
+				else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) )
1771
+				{
1529 1772
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['RETURN-RECEIPT-TO']));
1530
-				} else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) ) {
1773
+				}
1774
+				else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) )
1775
+				{
1531 1776
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['X-CONFIRM-READING-TO']));
1532 1777
 				} /*else $sent_not = "";*/
1533 1778
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
@@ -1558,7 +1803,11 @@  discard block
 block discarded – undo
1558 1803
 						$rfcAddr = self::parseAddressList($ad); // does some fixing of known problems too
1559 1804
 						foreach ($rfcAddr as $_rfcAddr)
1560 1805
 						{
1561
-							if (!$_rfcAddr->valid)	continue; // skip. not a valid address
1806
+							if (!$_rfcAddr->valid)
1807
+							{
1808
+								continue;
1809
+							}
1810
+							// skip. not a valid address
1562 1811
 							$address[] = imap_rfc822_write_address($_rfcAddr->mailbox,$_rfcAddr->host,$_rfcAddr->personal);
1563 1812
 						}
1564 1813
 					}
@@ -1574,7 +1823,10 @@  discard block
 block discarded – undo
1574 1823
 				{
1575 1824
 					// $bodyPreview is populated at the beginning of the loop, as it may be
1576 1825
 					// needed to parse the Headers of the Message
1577
-					if (empty($bodyPreview)) $bodyPreview = $_headerObject->getFullMsg();
1826
+					if (empty($bodyPreview))
1827
+					{
1828
+						$bodyPreview = $_headerObject->getFullMsg();
1829
+					}
1578 1830
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($bodyPreview));
1579 1831
 					$base = Horde_Mime_Part::parseMessage($bodyPreview);
1580 1832
 					foreach($base->partIterator() as $part)
@@ -1587,7 +1839,8 @@  discard block
 block discarded – undo
1587 1839
 												'encode' => Horde_Mime_Part::ENCODE_BINARY,	// otherwise we cant recode charset
1588 1840
 											)), $charset, 'utf-8');
1589 1841
 							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Translation::convert_jsonsafe($buffer),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
1590
-						} elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart')
1842
+						}
1843
+						elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart')
1591 1844
 						{
1592 1845
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part));
1593 1846
 						}
@@ -1603,7 +1856,10 @@  discard block
 block discarded – undo
1603 1856
 				$messageMimeType='';
1604 1857
 				foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
1605 1858
 				{
1606
-					if ($mime_id==0 || $messageMimeType==='') $messageMimeType = $mime_type;
1859
+					if ($mime_id==0 || $messageMimeType==='')
1860
+					{
1861
+						$messageMimeType = $mime_type;
1862
+					}
1607 1863
 					$part = $mailStructureObject->getPart($mime_id);
1608 1864
 					$partdisposition = $part->getDisposition();
1609 1865
 					$partPrimaryType = $part->getPrimaryType();
@@ -1613,7 +1869,8 @@  discard block
 block discarded – undo
1613 1869
 					// bodypreview could be found (multipart/....)
1614 1870
 					if ($_fetchPreviews && empty($headerObject['BODYPREVIEW'])&&($partPrimaryType == 'text') &&
1615 1871
 						((intval($mime_id) === 1) || !$mime_id) &&
1616
-						($partdisposition !== 'attachment')) {
1872
+						($partdisposition !== 'attachment'))
1873
+					{
1617 1874
 							$_structure=$part;
1618 1875
 							$this->fetchPartContents($uid, $_structure, false,true);
1619 1876
 							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
@@ -1635,10 +1892,19 @@  discard block
 block discarded – undo
1635 1892
 					if ($mime_type=='message/rfc822')
1636 1893
 					{
1637 1894
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
1638
-						foreach($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
1895
+						foreach($part->contentTypeMap() as $sub_id => $sub_type)
1896
+						{
1897
+if ($sub_id != $mime_id)
1898
+						{
1899
+							$skipParts[$sub_id] = $sub_type;
1900
+						}
1901
+						}
1639 1902
 					}
1640 1903
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType.' Skip:'.array2string($skipParts));
1641
-					if (array_key_exists($mime_id,$skipParts)) continue;
1904
+					if (array_key_exists($mime_id,$skipParts))
1905
+					{
1906
+						continue;
1907
+					}
1642 1908
 					if ($partdisposition=='attachment' ||
1643 1909
 						($partdisposition=='inline'&&$partPrimaryType == 'image'&&$mime_type=='image/tiff') || // as we are not able to display tiffs
1644 1910
 						($partdisposition=='inline'&&$partPrimaryType == 'image'&&empty($cid)) ||
@@ -1649,7 +1915,10 @@  discard block
 block discarded – undo
1649 1915
 						$headerObject['ATTACHMENTS'][$mime_id]['uid']=$uid;
1650 1916
 						$headerObject['ATTACHMENTS'][$mime_id]['cid'] = $cid;
1651 1917
 						$headerObject['ATTACHMENTS'][$mime_id]['partID']=$mime_id;
1652
-						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1918
+						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))
1919
+						{
1920
+							$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1921
+						}
1653 1922
 						if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'],'winmail.dat') ||
1654 1923
 							$headerObject['ATTACHMENTS'][$mime_id]['mimeType']=='application/ms-tnef')
1655 1924
 						{
@@ -1663,18 +1932,27 @@  discard block
 block discarded – undo
1663 1932
 				//error_log(__METHOD__.' ('.__LINE__.') '.' FindBody (plain):'.array2string($mailStructureObject->findBody('plain')));
1664 1933
 				//error_log(__METHOD__.' ('.__LINE__.') '.' FindBody (html):'.array2string($mailStructureObject->findBody('html')));
1665 1934
 				//if($count == 0) error_log(__METHOD__.array2string($headerObject));
1666
-				if (empty($headerObject['UID'])) continue;
1935
+				if (empty($headerObject['UID']))
1936
+				{
1937
+					continue;
1938
+				}
1667 1939
 				//$uid = ($rByUid ? $headerObject['UID'] : $headerObject['MSG_NUM']);
1668 1940
 				// make dates like "Mon, 23 Apr 2007 10:11:06 UT" working with strtotime
1669
-				if(substr($headerObject['DATE'],-2) === 'UT') {
1941
+				if(substr($headerObject['DATE'],-2) === 'UT')
1942
+				{
1670 1943
 					$headerObject['DATE'] .= 'C';
1671 1944
 				}
1672
-				if(substr($headerObject['INTERNALDATE'],-2) === 'UT') {
1945
+				if(substr($headerObject['INTERNALDATE'],-2) === 'UT')
1946
+				{
1673 1947
 					$headerObject['INTERNALDATE'] .= 'C';
1674 1948
 				}
1675 1949
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$headerObject['SUBJECT'].'->'.$headerObject['DATE'].'<->'.$headerObject['INTERNALDATE'] .'#');
1676 1950
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$this->decode_subject($headerObject['SUBJECT']).'->'.$headerObject['DATE']);
1677
-				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;}
1951
+				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS']))
1952
+				{
1953
+					foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;
1954
+				}
1955
+				}
1678 1956
 				$retValue['header'][$sortOrder[$uid]]['subject']	= $this->decode_subject($headerObject['SUBJECT']);
1679 1957
 				$retValue['header'][$sortOrder[$uid]]['size'] 		= $headerObject['SIZE'];
1680 1958
 				$retValue['header'][$sortOrder[$uid]]['date']		= self::_strtotime(($headerObject['DATE']&&!($headerObject['DATE']=='NIL')?$headerObject['DATE']:$headerObject['INTERNALDATE']),'ts',true);
@@ -1685,22 +1963,31 @@  discard block
 block discarded – undo
1685 1963
 				$retValue['header'][$sortOrder[$uid]]['bodypreview']		= $headerObject['BODYPREVIEW'];
1686 1964
 				$retValue['header'][$sortOrder[$uid]]['priority']		= ($headerObject['PRIORITY']?$headerObject['PRIORITY']:3);
1687 1965
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.array2string($retValue['header'][$sortOrder[$uid]]));
1688
-				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO'])) $retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1689
-				if (is_array($headerObject['FLAGS'])) {
1966
+				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO']))
1967
+				{
1968
+					$retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1969
+				}
1970
+				if (is_array($headerObject['FLAGS']))
1971
+				{
1690 1972
 					$retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]],self::prepareFlagsArray($headerObject));
1691 1973
 				}
1692 1974
 				//error_log(__METHOD__.' ('.__LINE__.') '.$headerObject['SUBJECT'].'->'.array2string($_headerObject->getEnvelope()->__get('from')));
1693
-				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0]) {
1975
+				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0])
1976
+				{
1694 1977
 					$retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0],true);
1695 1978
 				}
1696
-				if(is_array($headerObject['TO']) && $headerObject['TO'][0]) {
1979
+				if(is_array($headerObject['TO']) && $headerObject['TO'][0])
1980
+				{
1697 1981
 					$retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0],true);
1698 1982
 					if (count($headerObject['TO'])>1)
1699 1983
 					{
1700 1984
 						$ki=0;
1701 1985
 						foreach($headerObject['TO'] as $k => $add)
1702 1986
 						{
1703
-							if ($k==0) continue;
1987
+							if ($k==0)
1988
+							{
1989
+								continue;
1990
+							}
1704 1991
 							//error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add));
1705 1992
 							$retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add,true);
1706 1993
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki]));
@@ -1708,7 +1995,8 @@  discard block
 block discarded – undo
1708 1995
 						}
1709 1996
 					}
1710 1997
 				}
1711
-				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0) {
1998
+				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0)
1999
+				{
1712 2000
 					$ki=0;
1713 2001
 					foreach($headerObject['CC'] as $k => $add)
1714 2002
 					{
@@ -1722,27 +2010,41 @@  discard block
 block discarded – undo
1722 2010
 
1723 2011
 				$count++;
1724 2012
 			}
1725
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
2013
+			if (self::$debug||self::$debugTimes)
2014
+			{
2015
+				self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
2016
+			}
1726 2017
 			//self::$debug=false;
1727 2018
 			// sort the messages to the requested displayorder
1728
-			if(is_array($retValue['header'])) {
2019
+			if(is_array($retValue['header']))
2020
+			{
1729 2021
 				$countMessages = $total;
1730
-				if (isset($_filter['range'])) $countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
2022
+				if (isset($_filter['range']))
2023
+				{
2024
+					$countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
2025
+				}
1731 2026
 				ksort($retValue['header']);
1732 2027
 				$retValue['info']['total']	= $total;
1733 2028
 				//if ($_startMessage>$total) $_startMessage = $total-($count-1);
1734 2029
 				$retValue['info']['first']	= $_startMessage;
1735 2030
 				$retValue['info']['last']	= $_startMessage + $count - 1 ;
1736 2031
 				return $retValue;
1737
-			} else {
2032
+			}
2033
+			else
2034
+			{
1738 2035
 				$retValue = array();
1739 2036
 				$retValue['info']['total']	= 0;
1740 2037
 				$retValue['info']['first']	= 0;
1741 2038
 				$retValue['info']['last']	= 0;
1742 2039
 				return $retValue;
1743 2040
 			}
1744
-		} else {
1745
-			if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
2041
+		}
2042
+		else
2043
+		{
2044
+			if ($headersNew == null && empty($_thisUIDOnly))
2045
+			{
2046
+				error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
2047
+			}
1746 2048
 			$retValue = array();
1747 2049
 			$retValue['info']['total']  = 0;
1748 2050
 			$retValue['info']['first']  = 0;
@@ -1759,7 +2061,10 @@  discard block
 block discarded – undo
1759 2061
 	 */
1760 2062
 	static function prepareFlagsArray($headerObject)
1761 2063
 	{
1762
-		if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower',$headerObject['FLAGS']);
2064
+		if (is_array($headerObject['FLAGS']))
2065
+		{
2066
+			$headerFlags = array_map('strtolower',$headerObject['FLAGS']);
2067
+		}
1763 2068
 		$retValue = array();
1764 2069
 		$retValue['recent']		= in_array('\\recent', $headerFlags);
1765 2070
 		$retValue['flagged']	= in_array('\\flagged', $headerFlags);
@@ -1810,25 +2115,44 @@  discard block
 block discarded – undo
1810 2115
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Filter:'.array2string($_filter));
1811 2116
 		$try2useCache = true;
1812 2117
 		static $eMailListContainsDeletedMessages = null;
1813
-		if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2118
+		if (is_null($eMailListContainsDeletedMessages))
2119
+		{
2120
+			$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2121
+		}
1814 2122
 		// this indicates, that there is no Filter set, and the returned set/subset should not contain DELETED Messages, nor filtered for UNDELETED
1815 2123
 		if ($setSession==true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
1816 2124
 		{
1817
-			if (self::$debugTimes) $starttime = microtime(true);
1818
-			if (is_null($eMailListContainsDeletedMessages) || empty($eMailListContainsDeletedMessages[$this->profileID]) || empty($eMailListContainsDeletedMessages[$this->profileID][$_folderName])) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
1819
-			$five=true;
1820
-			$deletedMessages = $this->getSortedList($_folderName, 0, $three=1, array('status'=>array('DELETED')),$five,false);
1821
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
1822
-			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] =$deletedMessages['count'];
2125
+			if (self::$debugTimes)
2126
+			{
2127
+				$starttime = microtime(true);
2128
+			}
2129
+			if (is_null($eMailListContainsDeletedMessages) || empty($eMailListContainsDeletedMessages[$this->profileID]) || empty($eMailListContainsDeletedMessages[$this->profileID][$_folderName]))
2130
+			{
2131
+				$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2132
+			}
2133
+			$five=true;
2134
+			$deletedMessages = $this->getSortedList($_folderName, 0, $three=1, array('status'=>array('DELETED')),$five,false);
2135
+			if (self::$debug)
2136
+			{
2137
+				error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
2138
+			}
2139
+			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] =$deletedMessages['count'];
1823 2140
 			Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),$eMailListContainsDeletedMessages, 60*60*1);
1824
-			if (self::$debugTimes) self::logRunTimes($starttime,null,'setting eMailListContainsDeletedMessages for Profile:'.$this->profileID.' Folder:'.$_folderName.' to '.$eMailListContainsDeletedMessages[$this->profileID][$_folderName],__METHOD__.' ('.__LINE__.') ');			//error_log(__METHOD__.' ('.__LINE__.') '.' Profile:'.$this->profileID.' Folder:'.$_folderName.' -> EXISTS/SessStat:'.array2string($folderStatus['MESSAGES']).'/'.self::$folderStatusCache[$this->profileID][$_folderName]['messages'].' ListContDelMsg/SessDeleted:'.$eMailListContainsDeletedMessages[$this->profileID][$_folderName].'/'.self::$folderStatusCache[$this->profileID][$_folderName]['deleted']);
2141
+			if (self::$debugTimes)
2142
+			{
2143
+				self::logRunTimes($starttime,null,'setting eMailListContainsDeletedMessages for Profile:'.$this->profileID.' Folder:'.$_folderName.' to '.$eMailListContainsDeletedMessages[$this->profileID][$_folderName],__METHOD__.' ('.__LINE__.') ');
2144
+			}
2145
+			//error_log(__METHOD__.' ('.__LINE__.') '.' Profile:'.$this->profileID.' Folder:'.$_folderName.' -> EXISTS/SessStat:'.array2string($folderStatus['MESSAGES']).'/'.self::$folderStatusCache[$this->profileID][$_folderName]['messages'].' ListContDelMsg/SessDeleted:'.$eMailListContainsDeletedMessages[$this->profileID][$_folderName].'/'.self::$folderStatusCache[$this->profileID][$_folderName]['deleted']);
1825 2146
 		}
1826 2147
 		$try2useCache = false;
1827 2148
 		//self::$supportsORinQuery[$this->profileID]=true;
1828 2149
 		if (is_null(self::$supportsORinQuery) || !isset(self::$supportsORinQuery[$this->profileID]))
1829 2150
 		{
1830 2151
 			self::$supportsORinQuery = Cache::getCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
1831
-			if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID]=true;
2152
+			if (!isset(self::$supportsORinQuery[$this->profileID]))
2153
+			{
2154
+				self::$supportsORinQuery[$this->profileID]=true;
2155
+			}
1832 2156
 		}
1833 2157
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_filter).' SupportsOrInQuery:'.self::$supportsORinQuery[$this->profileID]);
1834 2158
 		$filter = $this->createIMAPFilter($_folderName, $_filter,self::$supportsORinQuery[$this->profileID]);
@@ -1839,15 +2163,26 @@  discard block
 block discarded – undo
1839 2163
 		}
1840 2164
 		//_debug_array($filter);
1841 2165
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($filter).'#'.array2string($this->icServer->capability()));
1842
-		if($this->icServer->hasCapability('SORT')) {
2166
+		if($this->icServer->hasCapability('SORT'))
2167
+		{
1843 2168
 			// when using an orQuery and we sort by date. sort seems to fail on certain servers => ZIMBRA with Horde_Imap_Client
1844 2169
 			// thus we translate the search request from date to Horde_Imap_Client::SORT_SEQUENCE (which should be the same, if
1845 2170
 			// there is no messing with the dates)
1846 2171
 			//if (self::$supportsORinQuery[$this->profileID]&&$_sort=='date'&&$_filter['type']=='quick'&&!empty($_filter['string']))$_sort='INTERNALDATE';
1847
-			if (self::$debug) error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
2172
+			if (self::$debug)
2173
+			{
2174
+				error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
2175
+			}
1848 2176
 			$sortOrder = $this->_getSortString($_sort, $_reverse);
1849
-			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder)) $_reverse=false; // as we reversed the result already
1850
-			if (self::$debug) error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
2177
+			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder))
2178
+			{
2179
+				$_reverse=false;
2180
+			}
2181
+			// as we reversed the result already
2182
+			if (self::$debug)
2183
+			{
2184
+				error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
2185
+			}
1851 2186
 			try
1852 2187
 			{
1853 2188
 				$sortResult = $this->icServer->search($_folderName, $filter, array(
@@ -1859,7 +2194,10 @@  discard block
 block discarded – undo
1859 2194
 				//error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1860 2195
 				$resultByUid = false;
1861 2196
 				$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1862
-				if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
2197
+				if ($_reverse)
2198
+				{
2199
+					array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
2200
+				}
1863 2201
 				try
1864 2202
 				{
1865 2203
 					$sortResult = $this->icServer->search($_folderName, $filter, array(
@@ -1871,9 +2209,17 @@  discard block
 block discarded – undo
1871 2209
 					$sortResult = self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'];
1872 2210
 				}
1873 2211
 			}
1874
-			if (self::$debug) error_log(__METHOD__.print_r($sortResult,true));
1875
-		} else {
1876
-			if (self::$debug) error_log(__METHOD__." Mailserver has NO SORT Capability");
2212
+			if (self::$debug)
2213
+			{
2214
+				error_log(__METHOD__.print_r($sortResult,true));
2215
+			}
2216
+		}
2217
+		else
2218
+		{
2219
+			if (self::$debug)
2220
+			{
2221
+				error_log(__METHOD__." Mailserver has NO SORT Capability");
2222
+			}
1877 2223
 			//$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1878 2224
 			//if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
1879 2225
 			try
@@ -1887,7 +2233,10 @@  discard block
 block discarded – undo
1887 2233
 				// possible error OR Query. But Horde gives no detailed Info :-(
1888 2234
 				self::$supportsORinQuery[$this->profileID]=false;
1889 2235
 				Cache::setCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),self::$supportsORinQuery,60*60*10);
1890
-				if (self::$debug) error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
2236
+				if (self::$debug)
2237
+				{
2238
+					error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
2239
+				}
1891 2240
 				$filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]);
1892 2241
 				try
1893 2242
 				{
@@ -1898,11 +2247,15 @@  discard block
 block discarded – undo
1898 2247
 				{
1899 2248
 				}
1900 2249
 			}
1901
-			if(is_array($sortResult['match'])) {
2250
+			if(is_array($sortResult['match']))
2251
+			{
1902 2252
 					// not sure that this is going so succeed as $sortResult['match'] is a hordeObject
1903 2253
 					sort($sortResult['match'], SORT_NUMERIC);
1904 2254
 			}
1905
-			if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
2255
+			if (self::$debug)
2256
+			{
2257
+				error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
2258
+			}
1906 2259
 		}
1907 2260
 		if ($setSession)
1908 2261
 		{
@@ -1931,7 +2284,8 @@  discard block
 block discarded – undo
1931 2284
 		$_reverse=false;
1932 2285
 		if (is_numeric($_sort))
1933 2286
 		{
1934
-			switch($_sort) {
2287
+			switch($_sort)
2288
+			{
1935 2289
 				case 2:
1936 2290
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1937 2291
 					break;
@@ -1953,7 +2307,8 @@  discard block
 block discarded – undo
1953 2307
 		}
1954 2308
 		else
1955 2309
 		{
1956
-			switch(strtoupper($_sort)) {
2310
+			switch(strtoupper($_sort))
2311
+			{
1957 2312
 				case 'FROMADDRESS':
1958 2313
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1959 2314
 					break;
@@ -1979,7 +2334,10 @@  discard block
 block discarded – undo
1979 2334
 					break;
1980 2335
 			}
1981 2336
 		}
1982
-		if ($_reverse) array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
2337
+		if ($_reverse)
2338
+		{
2339
+			array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
2340
+		}
1983 2341
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.($_reverse?'REVERSE ':'').$_sort.'->'.$retValue);
1984 2342
 		return $retValue;
1985 2343
 	}
@@ -1998,7 +2356,10 @@  discard block
 block discarded – undo
1998 2356
 		$imapFilter->charset('UTF-8');
1999 2357
 
2000 2358
 		//_debug_array($_criterias);
2001
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2359
+		if (self::$debug)
2360
+		{
2361
+			error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2362
+		}
2002 2363
 		if((!is_array($_criterias) || $_criterias['status']=='any') &&
2003 2364
 			(!isset($_criterias['string']) || empty($_criterias['string'])) &&
2004 2365
 			(!isset($_criterias['range'])|| empty($_criterias['range']) ||
@@ -2013,11 +2374,13 @@  discard block
 block discarded – undo
2013 2374
 		// statusQuery MUST be placed first, as search for subject/mailbody and such is
2014 2375
 		// depending on charset. flagSearch is not BUT messes the charset if called afterwards
2015 2376
 		$statusQueryValid = false;
2016
-		foreach((array)$_criterias['status'] as $k => $criteria) {
2377
+		foreach((array)$_criterias['status'] as $k => $criteria)
2378
+		{
2017 2379
 			$imapStatusFilter = new Horde_Imap_Client_Search_Query();
2018 2380
 			$imapStatusFilter->charset('UTF-8');
2019 2381
 			$criteria = strtoupper($criteria);
2020
-			switch ($criteria) {
2382
+			switch ($criteria)
2383
+			{
2021 2384
 				case 'ANSWERED':
2022 2385
 				case 'DELETED':
2023 2386
 				case 'FLAGGED':
@@ -2100,9 +2463,11 @@  discard block
 block discarded – undo
2100 2463
 		$imapSearchFilter = new Horde_Imap_Client_Search_Query();
2101 2464
 		$imapSearchFilter->charset('UTF-8');
2102 2465
 
2103
-		if(!empty($_criterias['string'])) {
2466
+		if(!empty($_criterias['string']))
2467
+		{
2104 2468
 			$criteria = strtoupper($_criterias['type']);
2105
-			switch ($criteria) {
2469
+			switch ($criteria)
2470
+			{
2106 2471
 				case 'BYDATE':
2107 2472
 				case 'QUICK':
2108 2473
 				case 'QUICKWITHCC':
@@ -2110,9 +2475,12 @@  discard block
 block discarded – undo
2110 2475
 					//$imapSearchFilter->charset('UTF-8');
2111 2476
 					$imapFilter2 = new Horde_Imap_Client_Search_Query();
2112 2477
 					$imapFilter2->charset('UTF-8');
2113
-					if($this->isSentFolder($_folder)) {
2478
+					if($this->isSentFolder($_folder))
2479
+					{
2114 2480
 						$imapFilter2->headerText('TO', $_criterias['string'], $not=false);
2115
-					} else {
2481
+					}
2482
+					else
2483
+					{
2116 2484
 						$imapFilter2->headerText('FROM', $_criterias['string'], $not=false);
2117 2485
 					}
2118 2486
 					if ($_supportsOrInQuery)
@@ -2143,7 +2511,10 @@  discard block
 block discarded – undo
2143 2511
 											'GB'=>1024*1000*1000,'G'=>1024*1000*1000,
2144 2512
 											'TB'=>1024*1000*1000*1000,'T'=>1024*1000*1000*1000);
2145 2513
 						$numberinBytes=(float)$_criterias['string'];
2146
-						if (isset($multipleBy[$unit])) $numberinBytes=(float)$_criterias['string']*$multipleBy[$unit];
2514
+						if (isset($multipleBy[$unit]))
2515
+						{
2516
+							$numberinBytes=(float)$_criterias['string']*$multipleBy[$unit];
2517
+						}
2147 2518
 						//error_log(__METHOD__.__LINE__.'#'.$_criterias['string'].'->'.(float)$_criterias['string'].'#'.$unit.' ='.$numberinBytes);
2148 2519
 						$_criterias['string']=$numberinBytes;
2149 2520
 					}
@@ -2180,8 +2551,14 @@  discard block
 block discarded – undo
2180 2551
 					break;
2181 2552
 			}
2182 2553
 		}
2183
-		if ($statusQueryValid && !$queryValid) $queryValid=true;
2184
-		if ($queryValid) $imapFilter->andSearch($imapSearchFilter);
2554
+		if ($statusQueryValid && !$queryValid)
2555
+		{
2556
+			$queryValid=true;
2557
+		}
2558
+		if ($queryValid)
2559
+		{
2560
+			$imapFilter->andSearch($imapSearchFilter);
2561
+		}
2185 2562
 
2186 2563
 		if (isset($_criterias['range']) && !empty($_criterias['range']))
2187 2564
 		{
@@ -2196,7 +2573,8 @@  discard block
 block discarded – undo
2196 2573
 				unset($_criterias['before']);
2197 2574
 				$criteria=$_criterias['range']='ON';
2198 2575
 			}
2199
-			switch ($criteria) {
2576
+			switch ($criteria)
2577
+			{
2200 2578
 				case 'BETWEEN':
2201 2579
 					//try to be smart about missing
2202 2580
 					//enddate
@@ -2232,8 +2610,14 @@  discard block
 block discarded – undo
2232 2610
 					$rangeValid = true;
2233 2611
 					break;
2234 2612
 			}
2235
-			if ($rangeValid && !$queryValid) $queryValid=true;
2236
-			if ($rangeValid) $imapFilter->andSearch($imapRangeFilter);
2613
+			if ($rangeValid && !$queryValid)
2614
+			{
2615
+				$queryValid=true;
2616
+			}
2617
+			if ($rangeValid)
2618
+			{
2619
+				$imapFilter->andSearch($imapRangeFilter);
2620
+			}
2237 2621
 		}
2238 2622
 		if (self::$debug)
2239 2623
 		{
@@ -2241,10 +2625,13 @@  discard block
 block discarded – undo
2241 2625
 			$query_str = $imapFilter->build();
2242 2626
 			//error_log(__METHOD__.' ('.__LINE__.') '.' '.$query_str['query'].' created by Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2243 2627
 		}
2244
-		if($queryValid==false) {
2628
+		if($queryValid==false)
2629
+		{
2245 2630
 			$imapFilter->flag('DELETED', $set=false);
2246 2631
 			return $imapFilter;
2247
-		} else {
2632
+		}
2633
+		else
2634
+		{
2248 2635
 			return $imapFilter;
2249 2636
 		}
2250 2637
 	}
@@ -2301,7 +2688,10 @@  discard block
 block discarded – undo
2301 2688
 					}
2302 2689
 					$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox,Horde_Idna::decode($_rfcAddr->host),$_rfcAddr->personal);
2303 2690
 				}
2304
-				if (!empty($stringA)) $_string = implode(',',$stringA);
2691
+				if (!empty($stringA))
2692
+				{
2693
+					$_string = implode(',',$stringA);
2694
+				}
2305 2695
 			}
2306 2696
 			if ($_tryIDNConversion==='FORCE')
2307 2697
 			{
@@ -2326,7 +2716,10 @@  discard block
 block discarded – undo
2326 2716
 		{
2327 2717
 			return 'No Subject';
2328 2718
 		}
2329
-		if ($decode) $_string = self::decode_header($_string);
2719
+		if ($decode)
2720
+		{
2721
+			$_string = self::decode_header($_string);
2722
+		}
2330 2723
 		// make sure its utf-8
2331 2724
 		$test = @json_encode($_string);
2332 2725
 		if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
@@ -2364,7 +2757,8 @@  discard block
 block discarded – undo
2364 2757
 	 * @param string _parent the parent foldername
2365 2758
 	 * @return ISO-8859-1 / UTF7-IMAP encoded string
2366 2759
 	 */
2367
-	function _encodeFolderName($_folderName) {
2760
+	function _encodeFolderName($_folderName)
2761
+	{
2368 2762
 		return Translation::convert($_folderName, self::$displayCharset, 'ISO-8859-1');
2369 2763
 		#return Translation::convert($_folderName, self::$displayCharset, 'UTF7-IMAP');
2370 2764
 	}
@@ -2380,21 +2774,36 @@  discard block
 block discarded – undo
2380 2774
 	 */
2381 2775
 	function createFolder($_parent, $_folderName, &$_error)
2382 2776
 	{
2383
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2777
+		if (self::$debug)
2778
+		{
2779
+			error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2780
+		}
2384 2781
 		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2385 2782
 		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2386 2783
 
2387
-		if(empty($parent)) {
2784
+		if(empty($parent))
2785
+		{
2388 2786
 			$newFolderName = $folderName;
2389
-		} else {
2787
+		}
2788
+		else
2789
+		{
2390 2790
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2391 2791
 			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2392 2792
 		}
2393
-		if (empty($newFolderName)) return false;
2394
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2793
+		if (empty($newFolderName))
2794
+		{
2795
+			return false;
2796
+		}
2797
+		if (self::$debug)
2798
+		{
2799
+			error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2800
+		}
2395 2801
 		if ($this->folderExists($newFolderName,true))
2396 2802
 		{
2397
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2803
+			if (self::$debug)
2804
+			{
2805
+				error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2806
+			}
2398 2807
 			return $newFolderName;
2399 2808
 		}
2400 2809
 		try
@@ -2442,13 +2851,19 @@  discard block
 block discarded – undo
2442 2851
 		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2443 2852
 		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2444 2853
 
2445
-		if(empty($parent)) {
2854
+		if(empty($parent))
2855
+		{
2446 2856
 			$newFolderName = $folderName;
2447
-		} else {
2857
+		}
2858
+		else
2859
+		{
2448 2860
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2449 2861
 			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2450 2862
 		}
2451
-		if (self::$debug) error_log("create folder: $newFolderName");
2863
+		if (self::$debug)
2864
+		{
2865
+			error_log("create folder: $newFolderName");
2866
+		}
2452 2867
 		try
2453 2868
 		{
2454 2869
 			$this->icServer->renameMailbox($oldFolderName, $newFolderName);
@@ -2522,8 +2937,14 @@  discard block
 block discarded – undo
2522 2937
 	 */
2523 2938
 	function getFolderObjects($_subscribedOnly=false, $_getCounters=false, $_alwaysGetDefaultFolders=false,$_useCacheIfPossible=true)
2524 2939
 	{
2525
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2526
-		if (self::$debugTimes) $starttime = microtime (true);
2940
+		if (self::$debug)
2941
+		{
2942
+			error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2943
+		}
2944
+		if (self::$debugTimes)
2945
+		{
2946
+			$starttime = microtime (true);
2947
+		}
2527 2948
 		static $folders2return;
2528 2949
 		//$_subscribedOnly=false;
2529 2950
 		// always use static on single request if info is available;
@@ -2531,23 +2952,35 @@  discard block
 block discarded – undo
2531 2952
 		// set $_useCacheIfPossible to false !
2532 2953
 		if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2533 2954
 		{
2534
-			if (self::$debugTimes) self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2955
+			if (self::$debugTimes)
2956
+			{
2957
+				self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2958
+			}
2535 2959
 			return $folders2return[$this->icServer->ImapServerId];
2536 2960
 		}
2537 2961
 
2538 2962
 		if ($_subscribedOnly && $_getCounters===false)
2539 2963
 		{
2540
-			if (is_null($folders2return)) $folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2964
+			if (is_null($folders2return))
2965
+			{
2966
+				$folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2967
+			}
2541 2968
 			if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2542 2969
 			{
2543 2970
 				//error_log(__METHOD__.' ('.__LINE__.') '.' using Cached folderObjects'.array2string($folders2return[$this->icServer->ImapServerId]));
2544
-				if (self::$debugTimes) self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
2971
+				if (self::$debugTimes)
2972
+				{
2973
+					self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
2974
+				}
2545 2975
 				return $folders2return[$this->icServer->ImapServerId];
2546 2976
 			}
2547 2977
 		}
2548 2978
 		// use $folderBasicInfo for holding attributes and other basic folderinfo $folderBasicInfo[$this->icServer->ImapServerId]
2549 2979
 		static $folderBasicInfo;
2550
-		if (is_null($folderBasicInfo)||!isset($folderBasicInfo[$this->icServer->ImapServerId])) $folderBasicInfo = Cache::getCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2980
+		if (is_null($folderBasicInfo)||!isset($folderBasicInfo[$this->icServer->ImapServerId]))
2981
+		{
2982
+			$folderBasicInfo = Cache::getCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2983
+		}
2551 2984
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($folderBasicInfo[$this->icServer->ImapServerId])));
2552 2985
 
2553 2986
 		$delimiter = $this->getHierarchyDelimiter();
@@ -2560,7 +2993,8 @@  discard block
 block discarded – undo
2560 2993
 		$inboxData->shortFolderName	= 'INBOX';
2561 2994
 		$inboxData->shortDisplayName	= lang('INBOX');
2562 2995
 		$inboxData->subscribed = true;
2563
-		if($_getCounters == true) {
2996
+		if($_getCounters == true)
2997
+		{
2564 2998
 			$inboxData->counter = $this->getMailBoxCounters('INBOX');
2565 2999
 		}
2566 3000
 		// force unsubscribed by preference showAllFoldersInFolderPane
@@ -2579,12 +3013,14 @@  discard block
 block discarded – undo
2579 3013
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2580 3014
 		if (is_array($nameSpace))
2581 3015
 		{
2582
-			foreach($nameSpace as $k => $singleNameSpace) {
3016
+			foreach($nameSpace as $k => $singleNameSpace)
3017
+			{
2583 3018
 				$type = $singleNameSpace['type'];
2584 3019
 				// the following line (assumption that for the same namespace the delimiter should be equal) may be wrong
2585 3020
 				$foldersNameSpace[$type]['delimiter']  = $singleNameSpace['delimiter'];
2586 3021
 
2587
-				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false) {
3022
+				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false)
3023
+				{
2588 3024
 					// fetch and sort the subscribed folders
2589 3025
 					// we alway fetch the subscribed, as this provides the only way to tell
2590 3026
 					// if a folder is subscribed or not
@@ -2635,8 +3071,12 @@  discard block
 block discarded – undo
2635 3071
 							}
2636 3072
 						}
2637 3073
 						//error_log(__METHOD__.' ('.__LINE__.') '.' '.$type.'->'.array2string($foldersNameSpace[$type]['subscribed']));
2638
-						if (!is_array($foldersNameSpace[$type]['all'])) $foldersNameSpace[$type]['all'] = array();
2639
-						if ($_subscribedOnly == true && !empty($foldersNameSpace[$type]['subscribed'])) {
3074
+						if (!is_array($foldersNameSpace[$type]['all']))
3075
+						{
3076
+							$foldersNameSpace[$type]['all'] = array();
3077
+						}
3078
+						if ($_subscribedOnly == true && !empty($foldersNameSpace[$type]['subscribed']))
3079
+						{
2640 3080
 							continue;
2641 3081
 						}
2642 3082
 
@@ -2666,7 +3106,8 @@  discard block
 block discarded – undo
2666 3106
 					}
2667 3107
 
2668 3108
 					//error_log(__METHOD__.' ('.__LINE__.') '.' '.$type.'->'.array2string($allMailboxesExt));
2669
-					foreach ($allMailboxesExt as $mbx) {
3109
+					foreach ($allMailboxesExt as $mbx)
3110
+					{
2670 3111
 						if (!isset($folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]))
2671 3112
 						{
2672 3113
 							$folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]=array(
@@ -2689,20 +3130,33 @@  discard block
 block discarded – undo
2689 3130
 						if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']])||
2690 3131
 							isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']])||
2691 3132
 							(substr($mbx['MAILBOX'],-1)==$foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'],0,-1)]))
2692
-						) continue;
3133
+						)
3134
+						{
3135
+							continue;
3136
+						}
2693 3137
 
2694 3138
 						//echo '#'.$mbx['MAILBOX'].':'.array2string($mbx)."#<br>";
2695 3139
 						$allMailBoxesExtSorted[$mbx['MAILBOX']] = $mbx;
2696 3140
 					}
2697
-					if (is_array($allMailBoxesExtSorted)) ksort($allMailBoxesExtSorted);
3141
+					if (is_array($allMailBoxesExtSorted))
3142
+					{
3143
+						ksort($allMailBoxesExtSorted);
3144
+					}
2698 3145
 					//_debug_array(array_keys($allMailBoxesExtSorted));
2699 3146
 					$allMailboxes = array();
2700
-					foreach ((array)$allMailBoxesExtSorted as $mbx) {
2701
-						if (!in_array($mbx['MAILBOX'],$allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
3147
+					foreach ((array)$allMailBoxesExtSorted as $mbx)
3148
+					{
3149
+						if (!in_array($mbx['MAILBOX'],$allMailboxes))
3150
+						{
3151
+							$allMailboxes[] = $mbx['MAILBOX'];
3152
+						}
2702 3153
 						//echo "Result:";_debug_array($allMailboxes);
2703 3154
 					}
2704 3155
 					$foldersNameSpace[$type]['all'] = $allMailboxes;
2705
-					if (is_array($foldersNameSpace[$type]['all'])) sort($foldersNameSpace[$type]['all']);
3156
+					if (is_array($foldersNameSpace[$type]['all']))
3157
+					{
3158
+						sort($foldersNameSpace[$type]['all']);
3159
+					}
2706 3160
 				}
2707 3161
 			}
2708 3162
 		}
@@ -2711,24 +3165,50 @@  discard block
 block discarded – undo
2711 3165
 		//echo "<br>FolderNameSpace To Process:";_debug_array($foldersNameSpace);
2712 3166
 		$autoFolderObjects = $folders = array();
2713 3167
 		$autofolder_exists = array();
2714
-		foreach( array('personal', 'others', 'shared') as $type) {
2715
-			if(isset($foldersNameSpace[$type])) {
2716
-				if($_subscribedOnly) {
2717
-					if( !empty($foldersNameSpace[$type]['subscribed']) ) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
2718
-				} else {
2719
-					if( !empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
2720
-				}
2721
-				foreach((array)$listOfFolders as $folderName) {
3168
+		foreach( array('personal', 'others', 'shared') as $type)
3169
+		{
3170
+			if(isset($foldersNameSpace[$type]))
3171
+			{
3172
+				if($_subscribedOnly)
3173
+				{
3174
+					if( !empty($foldersNameSpace[$type]['subscribed']) )
3175
+					{
3176
+						$listOfFolders = $foldersNameSpace[$type]['subscribed'];
3177
+					}
3178
+				}
3179
+				else
3180
+				{
3181
+					if( !empty($foldersNameSpace[$type]['all']))
3182
+					{
3183
+						$listOfFolders = $foldersNameSpace[$type]['all'];
3184
+					}
3185
+				}
3186
+				foreach((array)$listOfFolders as $folderName)
3187
+				{
2722 3188
 					//echo "<br>FolderToCheck:$folderName<br>";
2723 3189
 					//error_log(__METHOD__.__LINE__.'#Delimiter:'.$delimiter.':#'.$folderName);
2724
-					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue;//when subscribedonly, we fetch all folders in one go.
2725
-					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
3190
+					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all']))
3191
+					{
3192
+						continue;
3193
+					}
3194
+					//when subscribedonly, we fetch all folders in one go.
3195
+					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all'])))
3196
+					{
2726 3197
 						#echo "$folderName failed to be here <br>";
2727 3198
 						continue;
2728 3199
 					}
2729
-					if (isset($folders[$folderName])) continue;
2730
-					if (isset($autoFolderObjects[$folderName])) continue;
2731
-					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter'];
3200
+					if (isset($folders[$folderName]))
3201
+					{
3202
+						continue;
3203
+					}
3204
+					if (isset($autoFolderObjects[$folderName]))
3205
+					{
3206
+						continue;
3207
+					}
3208
+					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter'])
3209
+					{
3210
+						$delimiter = $foldersNameSpace[$type]['delimiter'];
3211
+					}
2732 3212
 					$folderParts = explode($delimiter, $folderName);
2733 3213
 					$shortName = array_pop($folderParts);
2734 3214
 
@@ -2736,17 +3216,20 @@  discard block
 block discarded – undo
2736 3216
 					$folderObject->delimiter	= $delimiter;
2737 3217
 					$folderObject->folderName	= $folderName;
2738 3218
 					$folderObject->shortFolderName	= $shortName;
2739
-					if(!$_subscribedOnly) {
3219
+					if(!$_subscribedOnly)
3220
+					{
2740 3221
 						#echo $folderName."->".$type."<br>";
2741 3222
 						#_debug_array($foldersNameSpace[$type]['subscribed']);
2742 3223
 						$folderObject->subscribed = in_array($folderName, (array)$foldersNameSpace[$type]['subscribed']);
2743 3224
 					}
2744 3225
 
2745
-					if($_getCounters == true) {
3226
+					if($_getCounters == true)
3227
+					{
2746 3228
 						//error_log(__METHOD__.' ('.__LINE__.') '.' getCounter forFolder:'.$folderName);
2747 3229
 						$folderObject->counter = $this->getMailBoxCounters($folderName);
2748 3230
 					}
2749
-					if(strtoupper($folderName) == 'INBOX') {
3231
+					if(strtoupper($folderName) == 'INBOX')
3232
+					{
2750 3233
 						$folderName = 'INBOX';
2751 3234
 						$folderObject->folderName	= 'INBOX';
2752 3235
 						$folderObject->shortFolderName	= 'INBOX';
@@ -2754,24 +3237,34 @@  discard block
 block discarded – undo
2754 3237
 						$folderObject->shortDisplayName = lang('INBOX');
2755 3238
 						$folderObject->subscribed	= true;
2756 3239
 					// translate the automatic Folders (Sent, Drafts, ...) like the INBOX
2757
-					} elseif (in_array($shortName,self::$autoFolders)) {
3240
+					}
3241
+					elseif (in_array($shortName,self::$autoFolders))
3242
+					{
2758 3243
 						$tmpfolderparts = explode($delimiter,$folderObject->folderName);
2759 3244
 						array_pop($tmpfolderparts);
2760 3245
 						$folderObject->displayName = implode($delimiter,$tmpfolderparts).$delimiter.lang($shortName);
2761 3246
 						$folderObject->shortDisplayName = lang($shortName);
2762 3247
 						unset($tmpfolderparts);
2763
-					} else {
3248
+					}
3249
+					else
3250
+					{
2764 3251
 						$folderObject->displayName = $folderObject->folderName;
2765 3252
 						$folderObject->shortDisplayName = $shortName;
2766 3253
 					}
2767 3254
 					//$folderName = $folderName;
2768
-					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false) {
3255
+					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false)
3256
+					{
2769 3257
 						$autoFolderObjects[$folderName] = $folderObject;
2770
-					} else {
3258
+					}
3259
+					else
3260
+					{
2771 3261
 						$folders[$folderName] = $folderObject;
2772 3262
 					}
2773 3263
 					//error_log(__METHOD__.' ('.__LINE__.') '.':'.$folderObject->folderName);
2774
-					if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders ();
3264
+					if (!isset(self::$specialUseFolders))
3265
+					{
3266
+						$this->getSpecialUseFolders ();
3267
+					}
2775 3268
 					if (isset(self::$specialUseFolders[$folderName]))
2776 3269
 					{
2777 3270
 						$autofolder_exists[$folderName] = self::$specialUseFolders[$folderName];
@@ -2779,7 +3272,8 @@  discard block
 block discarded – undo
2779 3272
 				}
2780 3273
 			}
2781 3274
 		}
2782
-		if (is_array($autoFolderObjects) && !empty($autoFolderObjects)) {
3275
+		if (is_array($autoFolderObjects) && !empty($autoFolderObjects))
3276
+		{
2783 3277
 			uasort($autoFolderObjects,array($this,"sortByAutoFolderPos"));
2784 3278
 		}
2785 3279
 		// check if some standard folders are missing and need to be created
@@ -2788,7 +3282,10 @@  discard block
 block discarded – undo
2788 3282
 			// if new folders have been created, re-read folders ignoring the cache
2789 3283
 			return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false);	// false = do NOT use cache
2790 3284
 		}
2791
-		if (is_array($folders)) uasort($folders,array($this,"sortByDisplayName"));
3285
+		if (is_array($folders))
3286
+		{
3287
+			uasort($folders,array($this,"sortByDisplayName"));
3288
+		}
2792 3289
 		//$folders2return = array_merge($autoFolderObjects,$folders);
2793 3290
 		//_debug_array($folders2return); #exit;
2794 3291
 		$folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject,(array)$autoFolderObjects,(array)$folders);
@@ -2800,7 +3297,10 @@  discard block
 block discarded – undo
2800 3297
 			Cache::setCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$folders2return,$expiration=60*60*1);
2801 3298
 		}
2802 3299
 		Cache::setCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderBasicInfo,$expiration=60*60*1);
2803
-		if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
3300
+		if (self::$debugTimes)
3301
+		{
3302
+			self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
3303
+		}
2804 3304
 		return $folders2return[$this->icServer->ImapServerId];
2805 3305
 	}
2806 3306
 
@@ -2828,31 +3328,44 @@  discard block
 block discarded – undo
2828 3328
 
2829 3329
 		$folders = $nameSpace =  array();
2830 3330
 		$nameSpaceTmp = $this->_getNameSpaces();
2831
-		foreach($nameSpaceTmp as $k => $singleNameSpace) {
3331
+		foreach($nameSpaceTmp as $k => $singleNameSpace)
3332
+		{
2832 3333
 			$nameSpace[$singleNameSpace['type']]=$singleNameSpace;
2833 3334
 		}
2834 3335
 		unset($nameSpaceTmp);
2835 3336
 
2836 3337
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2837 3338
 		// Get special use folders
2838
-		if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders (); // Set self::$specialUseFolders
3339
+		if (!isset(self::$specialUseFolders))
3340
+		{
3341
+			$this->getSpecialUseFolders ();
3342
+		}
3343
+		// Set self::$specialUseFolders
2839 3344
 		// topLevelQueries generally ignore the $_search param. Except for Config::examineNamespace
2840
-		if ($_onlyTopLevel) // top level leaves
3345
+		if ($_onlyTopLevel)
3346
+		{
3347
+			// top level leaves
2841 3348
 		{
2842 3349
 			// Get top mailboxes of icServer
2843 3350
 			$topFolders = $this->icServer->getMailboxes("", 2, true);
3351
+		}
2844 3352
 			// Trigger examination of namespace to retrieve
2845 3353
 			// folders located in other and shared; needed only for some servers
2846
-			if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
3354
+			if (is_null(self::$mailConfig))
3355
+			{
3356
+				self::$mailConfig = Config::read('mail');
3357
+			}
2847 3358
 			if (self::$mailConfig['examineNamespace'])
2848 3359
 			{
2849 3360
 				$prefixes=array();
2850 3361
 				if (is_array($nameSpace))
2851 3362
 				{
2852
-					foreach($nameSpace as $k => $singleNameSpace) {
3363
+					foreach($nameSpace as $k => $singleNameSpace)
3364
+					{
2853 3365
 						$type = $singleNameSpace['type'];
2854 3366
 
2855
-						if(is_array($singleNameSpace) && $singleNameSpace['prefix']){
3367
+						if(is_array($singleNameSpace) && $singleNameSpace['prefix'])
3368
+						{
2856 3369
 							$prefixes[$type] = $singleNameSpace['prefix'];
2857 3370
 							//regard extra care for nameSpacequeries when configured AND respect $_search
2858 3371
 							$result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search==0?0:2, true);
@@ -2928,7 +3441,10 @@  discard block
 block discarded – undo
2928 3441
 							$nFolders [$path] = $folder;
2929 3442
 						}
2930 3443
 					}
2931
-					if (is_array($aFolders)) uasort ($aFolders, array($this,'sortByAutofolder'));
3444
+					if (is_array($aFolders))
3445
+					{
3446
+						uasort ($aFolders, array($this,'sortByAutofolder'));
3447
+					}
2932 3448
 					//ksort($aFolders);
2933 3449
 
2934 3450
 					// Sort none auto folders base on mailbox name
@@ -2938,12 +3454,17 @@  discard block
 block discarded – undo
2938 3454
 				}
2939 3455
 				else
2940 3456
 				{
2941
-					if (is_array($subFolders)) ksort($subFolders);
3457
+					if (is_array($subFolders))
3458
+					{
3459
+						ksort($subFolders);
3460
+					}
2942 3461
 				}
2943 3462
 				$folders = array_merge($folders,(array)$mainFolder, (array)$subFolders);
2944 3463
 			}
2945 3464
 		}
2946
-		elseif ($_nodePath) // single node
3465
+		elseif ($_nodePath)
3466
+		{
3467
+			// single node
2947 3468
 		{
2948 3469
 			switch ($_search)
2949 3470
 			{
@@ -2951,6 +3472,7 @@  discard block
 block discarded – undo
2951 3472
 				case 0:
2952 3473
 				case 2:
2953 3474
 					$path = $_nodePath.''.$delimiter;
3475
+		}
2954 3476
 					break;
2955 3477
 				// Node itself
2956 3478
 				// shouldn't contain next level delimiter
@@ -2969,11 +3491,14 @@  discard block
 block discarded – undo
2969 3491
 
2970 3492
 			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
2971 3493
 		}
2972
-		elseif(!$_nodePath) // all
3494
+		elseif(!$_nodePath)
3495
+		{
3496
+			// all
2973 3497
 		{
2974 3498
 			if ($_subscribedOnly)
2975 3499
 			{
2976 3500
 				$folders = $this->icServer->listSubscribedMailboxes('', 0, true);
3501
+		}
2977 3502
 			}
2978 3503
 			else
2979 3504
 			{
@@ -2985,7 +3510,10 @@  discard block
 block discarded – undo
2985 3510
 		{
2986 3511
 			// SORTING FOLDERS
2987 3512
 			//self::$debugTimes=true;
2988
-			if (self::$debugTimes) $starttime = microtime (true);
3513
+			if (self::$debugTimes)
3514
+			{
3515
+				$starttime = microtime (true);
3516
+			}
2989 3517
 			// Merge of all auto folders and specialusefolders
2990 3518
 			$autoFoldersTmp = array_unique((array_merge(self::$autoFolders, array_values(self::$specialUseFolders))));
2991 3519
 			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
@@ -2995,73 +3523,103 @@  discard block
 block discarded – undo
2995 3523
 			$isGoogleMail=false;
2996 3524
 			foreach($autoFoldersTmp as $afk=>$aF)
2997 3525
 			{
2998
-				if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
3526
+				if (!isset($mySpecialUseFolders[$aF]) && $aF)
3527
+				{
3528
+					$mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
3529
+				}
2999 3530
 				//error_log($afk.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3000 3531
 			}
3001 3532
 			//error_log(array2string($mySpecialUseFolders));
3002
-			foreach ($tmpFolders as $k => $f) {
3533
+			foreach ($tmpFolders as $k => $f)
3534
+			{
3003 3535
 				$sorted=false;
3004
-				if (strtoupper(substr($k,0,5))=='INBOX') {
3005
-					if (strtoupper($k)=='INBOX') {
3536
+				if (strtoupper(substr($k,0,5))=='INBOX')
3537
+				{
3538
+					if (strtoupper($k)=='INBOX')
3539
+					{
3006 3540
 						//error_log(__METHOD__.__LINE__.':'.strtoupper(substr($k,0,5)).':'.$k);
3007 3541
 						$inboxFolderObject[$k]=$f;
3008 3542
 						unset($folders[$k]);
3009 3543
 						$sorted=true;
3010
-					} else {
3544
+					}
3545
+					else
3546
+					{
3011 3547
 						$isAutoFolder=false;
3012 3548
 						foreach($autoFoldersTmp as $afk=>$aF)
3013 3549
 						{
3014 3550
 							//error_log(__METHOD__.__LINE__.$k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3015 3551
 							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3016 3552
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3017
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3553
+								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3554
+							{
3555
+								// k is parent of an autofolder
3018 3556
 							{
3019 3557
 								//error_log(__METHOD__.__LINE__.$k.'->'.$mySpecialUseFolders[$aF]);
3020 3558
 								$isAutoFolder=true;
3559
+							}
3021 3560
 								$autoFolderObjects[$k]=$f;
3022 3561
 								break;
3023 3562
 							}
3024 3563
 						}
3025
-						if ($isAutoFolder==false) $inboxSubFolderObjects[$k]=$f;
3564
+						if ($isAutoFolder==false)
3565
+						{
3566
+							$inboxSubFolderObjects[$k]=$f;
3567
+						}
3026 3568
 						unset($folders[$k]);
3027 3569
 						$sorted=true;
3028 3570
 					}
3029
-				} elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]') {
3571
+				}
3572
+				elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]')
3573
+				{
3030 3574
 					$isGoogleMail=true;
3031
-					if (strtoupper($k)=='[GOOGLE MAIL]') {
3575
+					if (strtoupper($k)=='[GOOGLE MAIL]')
3576
+					{
3032 3577
 						$googleMailFolderObject[$k]=$f;
3033 3578
 						unset($folders[$k]);
3034 3579
 						$sorted=true;
3035
-					} else {
3580
+					}
3581
+					else
3582
+					{
3036 3583
 						$isAutoFolder=false;
3037 3584
 						foreach($autoFoldersTmp as $afk=>$aF)
3038 3585
 						{
3039 3586
 							//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3040 3587
 							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3041 3588
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3042
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3589
+								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3590
+							{
3591
+								// k is parent of an autofolder
3043 3592
 							{
3044 3593
 								//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3045 3594
 								$isAutoFolder=true;
3595
+							}
3046 3596
 								$googleAutoFolderObjects[$k]=$f;
3047 3597
 								break;
3048 3598
 							}
3049 3599
 						}
3050
-						if ($isAutoFolder==false) $googleSubFolderObjects[$k]=$f;
3600
+						if ($isAutoFolder==false)
3601
+						{
3602
+							$googleSubFolderObjects[$k]=$f;
3603
+						}
3051 3604
 						unset($folders[$k]);
3052 3605
 						$sorted=true;
3053 3606
 					}
3054
-				} else {
3607
+				}
3608
+				else
3609
+				{
3055 3610
 					$isAutoFolder=false;
3056 3611
 					foreach($autoFoldersTmp as $afk=>$aF)
3057 3612
 					{
3058 3613
 						//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3059 3614
 						if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3060 3615
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3061
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3616
+								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3617
+						{
3618
+							// k is parent of an autofolder
3062 3619
 						{
3063 3620
 							//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3064 3621
 							$isAutoFolder=true;
3622
+						}
3065 3623
 							$autoFolderObjects[$k]=$f;
3066 3624
 							unset($folders[$k]);
3067 3625
 							$sorted=true;
@@ -3077,7 +3635,8 @@  discard block
 block discarded – undo
3077 3635
 						if ($nameSpace[$type]['prefix_present']&&$nameSpace[$type]['prefix'])
3078 3636
 						{
3079 3637
 							if (substr($k,0,strlen($nameSpace[$type]['prefix']))==$nameSpace[$type]['prefix']||
3080
-								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1)) {
3638
+								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1))
3639
+							{
3081 3640
 								//error_log(__METHOD__.__LINE__.':'.substr($k,0,strlen($nameSpace[$type]['prefix'])).':'.$k);
3082 3641
 								$typeFolderObject[$type][$k]=$f;
3083 3642
 								unset($folders[$k]);
@@ -3104,9 +3663,12 @@  discard block
 block discarded – undo
3104 3663
 				}
3105 3664
 			}
3106 3665
 			//error_log(__METHOD__.__LINE__.array2string($autoFolderObjects));
3107
-			if (!$isGoogleMail) {
3666
+			if (!$isGoogleMail)
3667
+			{
3108 3668
 				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$inboxSubFolderObjects,(array)$folders,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3109
-			} else {
3669
+			}
3670
+			else
3671
+			{
3110 3672
 				// avoid calling sortByAutoFolder as it is not regarding subfolders
3111 3673
 				$gAutoFolderObjectsTmp = $googleAutoFolderObjects;
3112 3674
 				unset($googleAutoFolderObjects);
@@ -3123,7 +3685,10 @@  discard block
 block discarded – undo
3123 3685
 				}
3124 3686
 				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$folders,(array)$googleMailFolderObject,$googleAutoFolderObjects,$googleSubFolderObjects,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3125 3687
 			}
3126
-			if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3688
+			if (self::$debugTimes)
3689
+			{
3690
+				self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3691
+			}
3127 3692
 			//self::$debugTimes=false;
3128 3693
 		}
3129 3694
 		// Get counter information and add them to each fetched folders array
@@ -3173,7 +3738,13 @@  discard block
 block discarded – undo
3173 3738
 		$rv = false;
3174 3739
 		foreach ($haystack as $k => $v)
3175 3740
 		{
3176
-			foreach($v as &$sv) {if (trim($sv)==trim($needle)) return $k;}
3741
+			foreach($v as &$sv)
3742
+			{
3743
+if (trim($sv)==trim($needle))
3744
+			{
3745
+				return $k;
3746
+			}
3747
+			}
3177 3748
 		}
3178 3749
 		return $rv;
3179 3750
 	}
@@ -3200,7 +3771,10 @@  discard block
 block discarded – undo
3200 3771
 	 */
3201 3772
 	static function pathToFolderData ($_path, $_hDelimiter)
3202 3773
 	{
3203
-		if (!strpos($_path, self::DELIMITER)) $_path = self::DELIMITER.$_path;
3774
+		if (!strpos($_path, self::DELIMITER))
3775
+		{
3776
+			$_path = self::DELIMITER.$_path;
3777
+		}
3204 3778
 		list(,$path) = explode(self::DELIMITER, $_path);
3205 3779
 		$path_chain = $parts = explode($_hDelimiter, $path);
3206 3780
 		$name = array_pop($parts);
@@ -3229,7 +3803,10 @@  discard block
 block discarded – undo
3229 3803
 		$b = self::pathToFolderData($_b['MAILBOX'], $_b['delimiter']);
3230 3804
 		$pos1 = array_search(trim($a['name']),self::$autoFolders);
3231 3805
 		$pos2 = array_search(trim($b['name']),self::$autoFolders);
3232
-		if ($pos1 == $pos2) return 0;
3806
+		if ($pos1 == $pos2)
3807
+		{
3808
+			return 0;
3809
+		}
3233 3810
 		return ($pos1 < $pos2) ? -1 : 1;
3234 3811
 	}
3235 3812
 
@@ -3260,7 +3837,10 @@  discard block
 block discarded – undo
3260 3837
 		// 0, 1 und -1
3261 3838
 		$pos1 = array_search(trim($a->shortFolderName),self::$autoFolders);
3262 3839
 		$pos2 = array_search(trim($b->shortFolderName),self::$autoFolders);
3263
-		if ($pos1 == $pos2) return 0;
3840
+		if ($pos1 == $pos2)
3841
+		{
3842
+			return 0;
3843
+		}
3264 3844
 		return ($pos1 < $pos2) ? -1 : 1;
3265 3845
 	}
3266 3846
 
@@ -3281,11 +3861,18 @@  discard block
 block discarded – undo
3281 3861
 		}
3282 3862
 		catch (\Exception $e)
3283 3863
 		{
3284
-			if (self::$debug) error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3864
+			if (self::$debug)
3865
+			{
3866
+				error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3867
+			}
3285 3868
 			return false;
3286 3869
 		}
3287
-		if(is_array($folderStatus)) {
3288
-			if ($_returnObject===false) return $folderStatus;
3870
+		if(is_array($folderStatus))
3871
+		{
3872
+			if ($_returnObject===false)
3873
+			{
3874
+				return $folderStatus;
3875
+			}
3289 3876
 			$status =  new \stdClass;
3290 3877
 			$status->messages   = $folderStatus['MESSAGES'];
3291 3878
 			$status->unseen     = $folderStatus['UNSEEN'];
@@ -3312,7 +3899,8 @@  discard block
 block discarded – undo
3312 3899
 	{
3313 3900
 		#echo __METHOD__." retrieve SubFolders for $_mailbox$delimiter <br>";
3314 3901
 		$maxreclevel=25;
3315
-		if ($reclevel > $maxreclevel) {
3902
+		if ($reclevel > $maxreclevel)
3903
+		{
3316 3904
 			error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
3317 3905
 			return array();
3318 3906
 		}
@@ -3326,7 +3914,8 @@  discard block
 block discarded – undo
3326 3914
 //error_log(__METHOD__.' ('.__LINE__.') '.' Delimiter:'.array2string($delimiter));
3327 3915
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx));
3328 3916
 		// Example: Array([INBOX/GaGa] => Array([MAILBOX] => INBOX/GaGa[ATTRIBUTES] => Array([0] => \\unmarked)[delimiter] => /))
3329
-		if (is_array($mbx[$mbxkeys[0]]["ATTRIBUTES"]) && (in_array('\HasChildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Haschildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\haschildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]))) {
3917
+		if (is_array($mbx[$mbxkeys[0]]["ATTRIBUTES"]) && (in_array('\HasChildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Haschildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\haschildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"])))
3918
+		{
3330 3919
 			// if there are children fetch them
3331 3920
 			//echo $mbx[$mbxkeys[0]]['MAILBOX']."<br>";
3332 3921
 
@@ -3334,7 +3923,8 @@  discard block
 block discarded – undo
3334 3923
 			//$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'],2,false);
3335 3924
 			//_debug_array($buff);
3336 3925
 			$allMailboxes = array();
3337
-			foreach ($buff as $mbxname) {
3926
+			foreach ($buff as $mbxname)
3927
+			{
3338 3928
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbxname));
3339 3929
 				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname['MAILBOX']);
3340 3930
 				#echo "About to recur in level $reclevel:".$mbxname."<br>";
@@ -3343,9 +3933,14 @@  discard block
 block discarded – undo
3343 3933
 					$allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel));
3344 3934
 				}
3345 3935
 			}
3346
-			if (!(in_array('\NoSelect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]))) $allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX'];
3936
+			if (!(in_array('\NoSelect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"])))
3937
+			{
3938
+				$allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX'];
3939
+			}
3347 3940
 			return $allMailboxes;
3348
-		} else {
3941
+		}
3942
+		else
3943
+		{
3349 3944
 			return array($_mailbox);
3350 3945
 		}
3351 3946
 	}
@@ -3369,14 +3964,21 @@  discard block
 block discarded – undo
3369 3964
 			'Outbox'   => array('profileKey'=>'acc_folder_outbox','autoFolderName'=>'Outbox'),
3370 3965
 			'Archive'   => array('profileKey'=>'acc_folder_archive','autoFolderName'=>'Archive'),
3371 3966
 		);
3372
-		if ($_type == 'Templates') $_type = 'Template';	// for some reason self::$autofolders uses 'Templates'!
3967
+		if ($_type == 'Templates')
3968
+		{
3969
+			$_type = 'Template';
3970
+		}
3971
+		// for some reason self::$autofolders uses 'Templates'!
3373 3972
 		$created = false;
3374 3973
 		if (!isset($types[$_type]))
3375 3974
 		{
3376 3975
 			error_log(__METHOD__.' ('.__LINE__.') '.' '.$_type.' not supported for '.__METHOD__);
3377 3976
 			return false;
3378 3977
 		}
3379
-		if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders)) self::$specialUseFolders = $this->getSpecialUseFolders();
3978
+		if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders))
3979
+		{
3980
+			self::$specialUseFolders = $this->getSpecialUseFolders();
3981
+		}
3380 3982
 
3381 3983
 		//highest precedence
3382 3984
 		try
@@ -3386,25 +3988,39 @@  discard block
 block discarded – undo
3386 3988
 		catch (\Exception $e)
3387 3989
 		{
3388 3990
 			// we know that outbox is not supported, but we use this here, as we autocreate expected SpecialUseFolders in this function
3389
-			if ($_type != 'Outbox') error_log(__METHOD__.' ('.__LINE__.') '.' Failed to retrieve Folder'.$_folderName." for ".array2string($types[$_type]).":".$e->getMessage());
3991
+			if ($_type != 'Outbox')
3992
+			{
3993
+				error_log(__METHOD__.' ('.__LINE__.') '.' Failed to retrieve Folder'.$_folderName." for ".array2string($types[$_type]).":".$e->getMessage());
3994
+			}
3390 3995
 			$_folderName = false;
3391 3996
 		}
3392 3997
 		// do not try to autocreate configured Archive-Folder. Return false if configured folder does not exist
3393
-		if ($_type == 'Archive') {
3394
-			if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
3998
+		if ($_type == 'Archive')
3999
+		{
4000
+			if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true))
4001
+			{
3395 4002
 				return false;
3396
-			} else {
4003
+			}
4004
+			else
4005
+			{
3397 4006
 				return $_folderName;
3398 4007
 			}
3399 4008
 
3400 4009
 		}
3401 4010
 		// does the folder exist??? (is configured/preset, but non-existent)
3402
-		if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
4011
+		if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true))
4012
+		{
3403 4013
 			try
3404 4014
 			{
3405 4015
 				$error = null;
3406
-				if (($_folderName = $this->createFolder('', $_folderName, $error))) $created = true;
3407
-				if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4016
+				if (($_folderName = $this->createFolder('', $_folderName, $error)))
4017
+				{
4018
+					$created = true;
4019
+				}
4020
+				if ($error)
4021
+				{
4022
+					error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4023
+				}
3408 4024
 			}
3409 4025
 			catch(Exception $e)
3410 4026
 			{
@@ -3413,9 +4029,16 @@  discard block
 block discarded – undo
3413 4029
 			}
3414 4030
 		}
3415 4031
 		// not sure yet if false is the correct behavior on none
3416
-		if ($_folderName =='none') return 'none' ; //false;
4032
+		if ($_folderName =='none')
4033
+		{
4034
+			return 'none' ;
4035
+		}
4036
+		//false;
3417 4037
 		//no (valid) folder found yet; try specialUseFolders
3418
-		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders))) $_folderName = $f;
4038
+		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders)))
4039
+		{
4040
+			$_folderName = $f;
4041
+		}
3419 4042
 		//no specialUseFolder; try some Defaults
3420 4043
 		if (empty($_folderName) && isset($types[$_type]))
3421 4044
 		{
@@ -3441,7 +4064,10 @@  discard block
 block discarded – undo
3441 4064
 					$error = null;
3442 4065
 					$this->createFolder('', $prefix.$types[$_type]['autoFolderName'],$error);
3443 4066
 					$_folderName = $prefix.$types[$_type]['autoFolderName'];
3444
-					if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4067
+					if ($error)
4068
+					{
4069
+						error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4070
+					}
3445 4071
 				}
3446 4072
 				catch(Exception $e)
3447 4073
 				{
@@ -3543,17 +4169,22 @@  discard block
 block discarded – undo
3543 4169
 	function isSentFolder($_folderName, $_checkexistance=TRUE)
3544 4170
 	{
3545 4171
 		$sentFolder = $this->getSentFolder($_checkexistance);
3546
-		if(empty($sentFolder)) {
4172
+		if(empty($sentFolder))
4173
+		{
3547 4174
 			return false;
3548 4175
 		}
3549 4176
 		// does the folder exist???
3550
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4177
+		if ($_checkexistance && !$this->folderExists($_folderName))
4178
+		{
3551 4179
 			return false;
3552 4180
 		}
3553 4181
 
3554
-		if(false !== stripos($_folderName, $sentFolder)) {
4182
+		if(false !== stripos($_folderName, $sentFolder))
4183
+		{
3555 4184
 			return true;
3556
-		} else {
4185
+		}
4186
+		else
4187
+		{
3557 4188
 			return false;
3558 4189
 		}
3559 4190
 	}
@@ -3566,15 +4197,20 @@  discard block
 block discarded – undo
3566 4197
 	 */
3567 4198
 	function isOutbox($_folderName, $_checkexistance=TRUE)
3568 4199
 	{
3569
-		if (stripos($_folderName, 'Outbox')===false) {
4200
+		if (stripos($_folderName, 'Outbox')===false)
4201
+		{
3570 4202
 			return false;
3571 4203
 		}
3572 4204
 		// does the folder exist???
3573
-		if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName)) {
4205
+		if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName))
4206
+		{
3574 4207
 			$outboxFolder = $this->getOutboxFolder($_checkexistance);
3575
-			if(false !== stripos($_folderName, $outboxFolder)) {
4208
+			if(false !== stripos($_folderName, $outboxFolder))
4209
+			{
3576 4210
 				return true;
3577
-			} else {
4211
+			}
4212
+			else
4213
+			{
3578 4214
 				return false;
3579 4215
 			}
3580 4216
 		}
@@ -3590,17 +4226,25 @@  discard block
 block discarded – undo
3590 4226
 	function isDraftFolder($_folderName, $_checkexistance=TRUE)
3591 4227
 	{
3592 4228
 		$draftFolder = $this->getDraftFolder($_checkexistance);
3593
-		if(empty($draftFolder)) {
4229
+		if(empty($draftFolder))
4230
+		{
3594 4231
 			return false;
3595 4232
 		}
3596 4233
 		// does the folder exist???
3597
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4234
+		if ($_checkexistance && !$this->folderExists($_folderName))
4235
+		{
3598 4236
 			return false;
3599 4237
 		}
3600
-		if (is_a($_folderName,"Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8;
3601
-		if(false !== stripos($_folderName, $draftFolder)) {
4238
+		if (is_a($_folderName,"Horde_Imap_Client_Mailbox"))
4239
+		{
4240
+			$_folderName = $_folderName->utf8;
4241
+		}
4242
+		if(false !== stripos($_folderName, $draftFolder))
4243
+		{
3602 4244
 			return true;
3603
-		} else {
4245
+		}
4246
+		else
4247
+		{
3604 4248
 			return false;
3605 4249
 		}
3606 4250
 	}
@@ -3614,17 +4258,22 @@  discard block
 block discarded – undo
3614 4258
 	function isTrashFolder($_folderName, $_checkexistance=TRUE)
3615 4259
 	{
3616 4260
 		$trashFolder = $this->getTrashFolder($_checkexistance);
3617
-		if(empty($trashFolder)) {
4261
+		if(empty($trashFolder))
4262
+		{
3618 4263
 			return false;
3619 4264
 		}
3620 4265
 		// does the folder exist???
3621
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4266
+		if ($_checkexistance && !$this->folderExists($_folderName))
4267
+		{
3622 4268
 			return false;
3623 4269
 		}
3624 4270
 
3625
-		if(false !== stripos($_folderName, $trashFolder)) {
4271
+		if(false !== stripos($_folderName, $trashFolder))
4272
+		{
3626 4273
 			return true;
3627
-		} else {
4274
+		}
4275
+		else
4276
+		{
3628 4277
 			return false;
3629 4278
 		}
3630 4279
 	}
@@ -3638,17 +4287,22 @@  discard block
 block discarded – undo
3638 4287
 	function isTemplateFolder($_folderName, $_checkexistance=TRUE)
3639 4288
 	{
3640 4289
 		$templateFolder = $this->getTemplateFolder($_checkexistance);
3641
-		if(empty($templateFolder)) {
4290
+		if(empty($templateFolder))
4291
+		{
3642 4292
 			return false;
3643 4293
 		}
3644 4294
 		// does the folder exist???
3645
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4295
+		if ($_checkexistance && !$this->folderExists($_folderName))
4296
+		{
3646 4297
 			return false;
3647 4298
 		}
3648 4299
 
3649
-		if(false !== stripos($_folderName, $templateFolder)) {
4300
+		if(false !== stripos($_folderName, $templateFolder))
4301
+		{
3650 4302
 			return true;
3651
-		} else {
4303
+		}
4304
+		else
4305
+		{
3652 4306
 			return false;
3653 4307
 		}
3654 4308
 	}
@@ -3666,15 +4320,27 @@  discard block
 block discarded – undo
3666 4320
 		if (empty($_folder))
3667 4321
 		{
3668 4322
 			// this error is more or less without significance, unless we force the check
3669
-			if ($_forceCheck===true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
4323
+			if ($_forceCheck===true)
4324
+			{
4325
+				error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
4326
+			}
3670 4327
 			return false;
3671 4328
 		}
3672 4329
 		// when check is not enforced , we assume a folder represented as Horde_Imap_Client_Mailbox as existing folder
3673
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false) return true;
3674
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")) $_folder =  $_folder->utf8;
4330
+		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false)
4331
+		{
4332
+			return true;
4333
+		}
4334
+		if (is_a($_folder,"Horde_Imap_Client_Mailbox"))
4335
+		{
4336
+			$_folder =  $_folder->utf8;
4337
+		}
3675 4338
 		// reduce traffic within the Instance per User; Expire every 5 hours
3676 4339
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Called with Folder:'.$_folder.function_backtrace());
3677
-		if (is_null($folderInfo)) $folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
4340
+		if (is_null($folderInfo))
4341
+		{
4342
+			$folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
4343
+		}
3678 4344
 		//error_log(__METHOD__.' ('.__LINE__.') '.'Cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID.($forceCheck?'(forcedCheck)':'').':'.array2string($folderInfo));
3679 4345
 		if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck===false)
3680 4346
 		{
@@ -3692,7 +4358,8 @@  discard block
 block discarded – undo
3692 4358
 
3693 4359
 		// does the folder exist???
3694 4360
 		//error_log(__METHOD__."->Connected?".$this->icServer->_connected.", ".$_folder.", ".($forceCheck?' forceCheck activated':'dont check on server'));
3695
-		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
4361
+		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder]))
4362
+		{
3696 4363
 			//error_log(__METHOD__."->NotConnected and forceCheck with profile:".$this->profileID);
3697 4364
 			//return false;
3698 4365
 			//try to connect
@@ -3733,9 +4400,12 @@  discard block
 block discarded – undo
3733 4400
 
3734 4401
 		$this->icServer->openMailbox($folderName);
3735 4402
 
3736
-		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") {
4403
+		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash")
4404
+		{
3737 4405
 			$this->deleteMessages('all',$folderName,'remove_immediately');
3738
-		} else {
4406
+		}
4407
+		else
4408
+		{
3739 4409
 			$this->icServer->expunge($folderName);
3740 4410
 		}
3741 4411
 	}
@@ -3754,10 +4424,16 @@  discard block
 block discarded – undo
3754 4424
 	{
3755 4425
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.array2string($_folder).', '.$_forceDeleteMethod);
3756 4426
 		$oldMailbox = '';
3757
-		if (is_null($_folder) || empty($_folder)) $_folder = $this->sessionData['mailbox'];
4427
+		if (is_null($_folder) || empty($_folder))
4428
+		{
4429
+			$_folder = $this->sessionData['mailbox'];
4430
+		}
3758 4431
 		if (empty($_messageUID))
3759 4432
 		{
3760
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4433
+			if (self::$debug)
4434
+			{
4435
+				error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4436
+			}
3761 4437
 			return false;
3762 4438
 		}
3763 4439
 		elseif ($_messageUID==='all')
@@ -3767,32 +4443,48 @@  discard block
 block discarded – undo
3767 4443
 		else
3768 4444
 		{
3769 4445
 			$uidsToDelete = new Horde_Imap_Client_Ids();
3770
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4446
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4447
+			{
4448
+				$_messageUID = (array)$_messageUID;
4449
+			}
3771 4450
 			$uidsToDelete->add($_messageUID);
3772 4451
 		}
3773 4452
 		$deleteOptions = $_forceDeleteMethod; // use forceDeleteMethod if not "no", or unknown method
3774
-		if ($_forceDeleteMethod === 'no' || !in_array($_forceDeleteMethod,array('move_to_trash',"mark_as_deleted","remove_immediately"))) $deleteOptions  = ($this->mailPreferences['deleteOptions']?$this->mailPreferences['deleteOptions']:"mark_as_deleted");
4453
+		if ($_forceDeleteMethod === 'no' || !in_array($_forceDeleteMethod,array('move_to_trash',"mark_as_deleted","remove_immediately")))
4454
+		{
4455
+			$deleteOptions  = ($this->mailPreferences['deleteOptions']?$this->mailPreferences['deleteOptions']:"mark_as_deleted");
4456
+		}
3775 4457
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3776 4458
 		$trashFolder    = $this->getTrashFolder();
3777 4459
 		$draftFolder	= $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder'];
3778 4460
 		$templateFolder = $this->getTemplateFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['templateFolder'];
3779 4461
 		if((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") ||
3780
-		   (strtolower($_folder) == strtolower($draftFolder))) {
4462
+		   (strtolower($_folder) == strtolower($draftFolder)))
4463
+		{
3781 4464
 			$deleteOptions = "remove_immediately";
3782 4465
 		}
3783
-		if($this->icServer->getCurrentMailbox() != $_folder) {
4466
+		if($this->icServer->getCurrentMailbox() != $_folder)
4467
+		{
3784 4468
 			$oldMailbox = $this->icServer->getCurrentMailbox();
3785 4469
 			$this->icServer->openMailbox($_folder);
3786 4470
 		}
3787 4471
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3788 4472
 		$updateCache = false;
3789
-		switch($deleteOptions) {
4473
+		switch($deleteOptions)
4474
+		{
3790 4475
 			case "move_to_trash":
3791 4476
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3792 4477
 				$updateCache = true;
3793
-				if(!empty($trashFolder)) {
3794
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
3795
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
4478
+				if(!empty($trashFolder))
4479
+				{
4480
+					if (self::$debug)
4481
+					{
4482
+						error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
4483
+					}
4484
+					if (self::$debug)
4485
+					{
4486
+						error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
4487
+					}
3796 4488
 					// copy messages
3797 4489
 					try
3798 4490
 					{
@@ -3808,7 +4500,10 @@  discard block
 block discarded – undo
3808 4500
 			case "mark_as_deleted":
3809 4501
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3810 4502
 				// mark messages as deleted
3811
-				if (is_null($_messageUID)) $_messageUID='all';
4503
+				if (is_null($_messageUID))
4504
+				{
4505
+					$_messageUID='all';
4506
+				}
3812 4507
 				foreach((array)$_messageUID as $key =>$uid)
3813 4508
 				{
3814 4509
 					//flag messages, that are flagged for deletion as seen too
@@ -3816,7 +4511,10 @@  discard block
 block discarded – undo
3816 4511
 					$flags = $this->getFlags($uid);
3817 4512
 					$this->flagMessages('delete', $uid, $_folder);
3818 4513
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
3819
-					if (strpos( array2string($flags),'Deleted')!==false) $undelete[] = $uid;
4514
+					if (strpos( array2string($flags),'Deleted')!==false)
4515
+					{
4516
+						$undelete[] = $uid;
4517
+					}
3820 4518
 					unset($flags);
3821 4519
 				}
3822 4520
 				foreach((array)$undelete as $key =>$uid)
@@ -3828,7 +4526,10 @@  discard block
 block discarded – undo
3828 4526
 			case "remove_immediately":
3829 4527
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3830 4528
 				$updateCache = true;
3831
-				if (is_null($_messageUID)) $_messageUID='all';
4529
+				if (is_null($_messageUID))
4530
+				{
4531
+					$_messageUID='all';
4532
+				}
3832 4533
 				if (is_object($_messageUID))
3833 4534
 				{
3834 4535
 					$this->flagMessages('delete', $_messageUID, $_folder);
@@ -3845,7 +4546,8 @@  discard block
 block discarded – undo
3845 4546
 				$this->icServer->expunge($_folder);
3846 4547
 				break;
3847 4548
 		}
3848
-		if($oldMailbox != '') {
4549
+		if($oldMailbox != '')
4550
+		{
3849 4551
 			$this->icServer->openMailbox($oldMailbox);
3850 4552
 		}
3851 4553
 
@@ -3859,11 +4561,15 @@  discard block
 block discarded – undo
3859 4561
 	 *
3860 4562
 	 * @return null/array flags
3861 4563
 	 */
3862
-	function getFlags ($_messageUID) {
4564
+	function getFlags ($_messageUID)
4565
+	{
3863 4566
 		try
3864 4567
 		{
3865 4568
 			$uidsToFetch = new Horde_Imap_Client_Ids();
3866
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4569
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4570
+			{
4571
+				$_messageUID = (array)$_messageUID;
4572
+			}
3867 4573
 			$uidsToFetch->add($_messageUID);
3868 4574
 			$_folderName = $this->icServer->getCurrentMailbox();
3869 4575
 			$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -3871,8 +4577,10 @@  discard block
 block discarded – undo
3871 4577
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
3872 4578
 				'ids' => $uidsToFetch,
3873 4579
 			));
3874
-			if (is_object($headersNew)) {
3875
-				foreach($headersNew->ids() as $id) {
4580
+			if (is_object($headersNew))
4581
+			{
4582
+				foreach($headersNew->ids() as $id)
4583
+				{
3876 4584
 					$_headerObject = $headersNew->get($id);
3877 4585
 					$flags = $_headerObject->getFlags();
3878 4586
 				}
@@ -3897,10 +4605,16 @@  discard block
 block discarded – undo
3897 4605
 	 */
3898 4606
 	function getNotifyFlags ($_messageUID, $flags=null)
3899 4607
 	{
3900
-		if (self::$debug) error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
4608
+		if (self::$debug)
4609
+		{
4610
+			error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
4611
+		}
3901 4612
 		try
3902 4613
 		{
3903
-			if($flags===null) $flags =  $this->getFlags($_messageUID);
4614
+			if($flags===null)
4615
+			{
4616
+				$flags =  $this->getFlags($_messageUID);
4617
+			}
3904 4618
 		}
3905 4619
 		catch (\Exception $e)
3906 4620
 		{
@@ -3908,10 +4622,14 @@  discard block
 block discarded – undo
3908 4622
 		}
3909 4623
 
3910 4624
 		if ( stripos( array2string($flags),'MDNSent')!==false)
3911
-			return true;
4625
+		{
4626
+					return true;
4627
+		}
3912 4628
 
3913 4629
 		if ( stripos( array2string($flags),'MDNnotSent')!==false)
3914
-			return false;
4630
+		{
4631
+					return false;
4632
+		}
3915 4633
 
3916 4634
 		return null;
3917 4635
 	}
@@ -3932,7 +4650,10 @@  discard block
 block discarded – undo
3932 4650
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",$_folder /".$this->sessionData['mailbox']);
3933 4651
 		if (empty($_messageUID))
3934 4652
 		{
3935
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4653
+			if (self::$debug)
4654
+			{
4655
+				error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4656
+			}
3936 4657
 			return false;
3937 4658
 		}
3938 4659
 		$this->icServer->openMailbox(($_folder?$_folder:$this->sessionData['mailbox']));
@@ -3940,7 +4661,10 @@  discard block
 block discarded – undo
3940 4661
 		if (is_array($_messageUID)&& count($_messageUID)>50)
3941 4662
 		{
3942 4663
 			$count = $this->getMailBoxCounters($folder,true);
3943
-			if ($count->messages == count($_messageUID)) $_messageUID='all';
4664
+			if ($count->messages == count($_messageUID))
4665
+			{
4666
+				$_messageUID='all';
4667
+			}
3944 4668
 		}
3945 4669
 
3946 4670
 		if ($_messageUID==='all')
@@ -3949,7 +4673,10 @@  discard block
 block discarded – undo
3949 4673
 		}
3950 4674
 		else
3951 4675
 		{
3952
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4676
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4677
+			{
4678
+				$_messageUID = (array)$_messageUID;
4679
+			}
3953 4680
 			$messageUIDs = array_chunk($_messageUID,50,true);
3954 4681
 		}
3955 4682
 		try
@@ -3965,7 +4692,8 @@  discard block
 block discarded – undo
3965 4692
 					$uidsToModify = new Horde_Imap_Client_Ids();
3966 4693
 					$uidsToModify->add($uids);
3967 4694
 				}
3968
-				switch($_flag) {
4695
+				switch($_flag)
4696
+				{
3969 4697
 					case "delete":
3970 4698
 						$ret = $this->icServer->store($folder, array('add'=>array('\\Deleted'), 'ids'=> $uidsToModify));
3971 4699
 						break;
@@ -4051,7 +4779,10 @@  discard block
 block discarded – undo
4051 4779
 		{
4052 4780
 			error_log(__METHOD__.__LINE__.' Error, could not flag messages in folder '.$folder.' Reason:'.$e->getMessage());
4053 4781
 		}
4054
-		if ($folder instanceof Horde_Imap_Client_Mailbox) $_folder = $folder->utf8;
4782
+		if ($folder instanceof Horde_Imap_Client_Mailbox)
4783
+		{
4784
+			$_folder = $folder->utf8;
4785
+		}
4055 4786
 		//error_log(__METHOD__.__LINE__.'#'.$this->icServer->ImapServerId.'#'.array2string($_folder).'#');
4056 4787
 		self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])]['uidValidity'] = 0;
4057 4788
 
@@ -4080,7 +4811,10 @@  discard block
 block discarded – undo
4080 4811
 		//$deleteOptions  = $GLOBALS['egw_info']["user"]["preferences"]["mail"]["deleteOptions"];
4081 4812
 		if (empty($_messageUID))
4082 4813
 		{
4083
-			if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4814
+			if (self::$debug)
4815
+			{
4816
+				error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4817
+			}
4084 4818
 			return false;
4085 4819
 		}
4086 4820
 		elseif ($_messageUID==='all')
@@ -4092,7 +4826,10 @@  discard block
 block discarded – undo
4092 4826
 		{
4093 4827
 			//error_log(__METHOD__." Message(s): ".implode(',',$_messageUID));
4094 4828
 			$uidsToMove = new Horde_Imap_Client_Ids();
4095
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4829
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4830
+			{
4831
+				$_messageUID = (array)$_messageUID;
4832
+			}
4096 4833
 			$uidsToMove->add($_messageUID);
4097 4834
 		}
4098 4835
 		$sourceFolder = (!empty($currentFolder)?$currentFolder: $this->sessionData['mailbox']);
@@ -4114,12 +4851,14 @@  discard block
 block discarded – undo
4114 4851
 
4115 4852
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' mailheaders:'.array2string($headersNew));
4116 4853
 
4117
-			if (is_object($headersNew)) {
4854
+			if (is_object($headersNew))
4855
+			{
4118 4856
 				$c=0;
4119 4857
 				$retUid = new Horde_Imap_Client_Ids();
4120 4858
 				// we copy chunks of 5 to avoid too much memory and/or server stress
4121 4859
 				// some servers seem not to allow/support the appendig of multiple messages. so we are down to one
4122
-				foreach($headersNew as &$_headerObject) {
4860
+				foreach($headersNew as &$_headerObject)
4861
+				{
4123 4862
 					$c++;
4124 4863
 					$flags = $_headerObject->getFlags(); //unseen status seems to be lost when retrieving the full message
4125 4864
 					$date = $_headerObject->getImapDate();
@@ -4203,7 +4942,11 @@  discard block
 block discarded – undo
4203 4942
 	{
4204 4943
 		try {
4205 4944
 			$date = new DateTime($_date);	// parse date & time including timezone (throws exception, if not parsable)
4206
-			if ($convert2usertime) $date->setUser();	// convert to user-time
4945
+			if ($convert2usertime)
4946
+			{
4947
+				$date->setUser();
4948
+			}
4949
+			// convert to user-time
4207 4950
 			$date2return = $date->format($format);
4208 4951
 		}
4209 4952
 		catch(\Exception $e)
@@ -4235,9 +4978,15 @@  discard block
 block discarded – undo
4235 4978
 	static function htmlentities($_string, $_charset=false)
4236 4979
 	{
4237 4980
 		//setting the charset (if not given)
4238
-		if ($_charset===false) $_charset = self::$displayCharset;
4981
+		if ($_charset===false)
4982
+		{
4983
+			$_charset = self::$displayCharset;
4984
+		}
4239 4985
 		$string = @htmlentities($_string, ENT_QUOTES, $_charset, false);
4240
-		if (empty($string) && !empty($_string)) $string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
4986
+		if (empty($string) && !empty($_string))
4987
+		{
4988
+			$string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
4989
+		}
4241 4990
 		return $string;
4242 4991
 	}
4243 4992
 
@@ -4257,18 +5006,41 @@  discard block
 block discarded – undo
4257 5006
 		$_html = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>','</td></font>','<br><td>','<tr></tr>','<o:p></o:p>','<o:p>','</o:p>'),
4258 5007
 							 array('&amp;',    '<BR>',           '<BR>',             '<BR>',             '</font></td>','<td>',    '',         '',           '',  ''),$_html);
4259 5008
 		//$_html = str_replace(array('&amp;amp;'),array('&amp;'),$_html);
4260
-		if (stripos($_html,'style')!==false) Mail\Html::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags
4261
-		if (stripos($_html,'head')!==false) Mail\Html::replaceTagsCompletley($_html,'head'); // Strip out stuff in head
5009
+		if (stripos($_html,'style')!==false)
5010
+		{
5011
+			Mail\Html::replaceTagsCompletley($_html,'style');
5012
+		}
5013
+		// clean out empty or pagewide style definitions / left over tags
5014
+		if (stripos($_html,'head')!==false)
5015
+		{
5016
+			Mail\Html::replaceTagsCompletley($_html,'head');
5017
+		}
5018
+		// Strip out stuff in head
4262 5019
 		//if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false) Mail\Html::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false); // Strip out stuff in ifs
4263 5020
 		//if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false) Mail\Html::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false); // Strip out stuff in ifs
4264 5021
 		//error_log(__METHOD__.' ('.__LINE__.') '.$_html);
4265 5022
 
4266
-		if (get_magic_quotes_gpc() === 1) $_html = stripslashes($_html);
5023
+		if (get_magic_quotes_gpc() === 1)
5024
+		{
5025
+			$_html = stripslashes($_html);
5026
+		}
4267 5027
 		// Strip out doctype in head, as htmlLawed cannot handle it TODO: Consider extracting it and adding it afterwards
4268
-		if (stripos($_html,'!doctype')!==false) Mail\Html::replaceTagsCompletley($_html,'!doctype');
4269
-		if (stripos($_html,'?xml:namespace')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
4270
-		if (stripos($_html,'?xml version')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false);
4271
-		if (strpos($_html,'!CURSOR')!==false) Mail\Html::replaceTagsCompletley($_html,'!CURSOR');
5028
+		if (stripos($_html,'!doctype')!==false)
5029
+		{
5030
+			Mail\Html::replaceTagsCompletley($_html,'!doctype');
5031
+		}
5032
+		if (stripos($_html,'?xml:namespace')!==false)
5033
+		{
5034
+			Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
5035
+		}
5036
+		if (stripos($_html,'?xml version')!==false)
5037
+		{
5038
+			Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false);
5039
+		}
5040
+		if (strpos($_html,'!CURSOR')!==false)
5041
+		{
5042
+			Mail\Html::replaceTagsCompletley($_html,'!CURSOR');
5043
+		}
4272 5044
 		// htmLawed filter only the 'body'
4273 5045
 		//preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $_html, $matches);
4274 5046
 		//if ($matches[2])
@@ -4307,8 +5079,10 @@  discard block
 block discarded – undo
4307 5079
 		//$charSet = 'iso-8859-1';//self::$displayCharset; //'iso-8859-1'; // self::displayCharset seems to be asmarter fallback than iso-8859-1
4308 5080
 		$CharsetFound=false;
4309 5081
 		//echo "#".$_mimePartObject->encoding.'#<br>';
4310
-		if(is_array($_mimePartObject->parameters)) {
4311
-			if(isset($_mimePartObject->parameters['CHARSET'])) {
5082
+		if(is_array($_mimePartObject->parameters))
5083
+		{
5084
+			if(isset($_mimePartObject->parameters['CHARSET']))
5085
+			{
4312 5086
 				$charSet = $_mimePartObject->parameters['CHARSET'];
4313 5087
 				$CharsetFound=true;
4314 5088
 			}
@@ -4329,7 +5103,10 @@  discard block
 block discarded – undo
4329 5103
 	function decodeMimePart($_mimeMessage, $_encoding, $_charset = '')
4330 5104
 	{
4331 5105
 		// decode the part
4332
-		if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
5106
+		if (self::$debug)
5107
+		{
5108
+			error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
5109
+		}
4333 5110
 		switch (strtoupper($_encoding))
4334 5111
 		{
4335 5112
 			case 'BASE64':
@@ -4369,13 +5146,19 @@  discard block
 block discarded – undo
4369 5146
 		// sometimes there are 3 parts, when there is an ics/ical attached/included-> we want to show that
4370 5147
 		// as attachment AND as abstracted ical information (we use our notification style here).
4371 5148
 		$partText = $partCalendar = $partHTML = null;
4372
-		if (self::$debug) _debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
5149
+		if (self::$debug)
5150
+		{
5151
+			_debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
5152
+		}
4373 5153
 		//error_log(__METHOD__.' ('.__LINE__.') ');
4374 5154
 		$ignore_first_part = true;
4375 5155
 		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4376 5156
 		{
4377 5157
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type"." ignoreFirstPart:".$ignore_first_part);
4378
-			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5158
+			if (self::$debug)
5159
+			{
5160
+				echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5161
+			}
4379 5162
 
4380 5163
 			if ($ignore_first_part)
4381 5164
 			{
@@ -4391,11 +5174,17 @@  discard block
 block discarded – undo
4391 5174
 					switch($mimePart->getSubType())
4392 5175
 					{
4393 5176
 						case 'plain':
4394
-							if ($mimePart->getBytes() > 0) $partText = $mimePart;
5177
+							if ($mimePart->getBytes() > 0)
5178
+							{
5179
+								$partText = $mimePart;
5180
+							}
4395 5181
 							break;
4396 5182
 
4397 5183
 						case 'html':
4398
-							if ($mimePart->getBytes() > 0)  $partHTML = $mimePart;
5184
+							if ($mimePart->getBytes() > 0)
5185
+							{
5186
+								$partHTML = $mimePart;
5187
+							}
4399 5188
 							break;
4400 5189
 					}
4401 5190
 					break;
@@ -4408,7 +5197,10 @@  discard block
 block discarded – undo
4408 5197
 							if (count($mimePart->getParts()) > 1)
4409 5198
 							{
4410 5199
 								// in a multipart alternative we treat the multipart/related as html part
4411
-								if (self::$debug) error_log(__METHOD__." process MULTIPART/".$mimePart->getSubType()." with array as subparts");
5200
+								if (self::$debug)
5201
+								{
5202
+									error_log(__METHOD__." process MULTIPART/".$mimePart->getSubType()." with array as subparts");
5203
+								}
4412 5204
 								$partHTML = $mimePart;
4413 5205
 								break 3; // GET OUT OF LOOP, will be processed according to type
4414 5206
 							}
@@ -4489,9 +5281,15 @@  discard block
 block discarded – undo
4489 5281
 	 */
4490 5282
 	function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts=array())
4491 5283
 	{
4492
-		if (self::$debug) echo __METHOD__."$_uid, $_htmlMode<br>";
5284
+		if (self::$debug)
5285
+		{
5286
+			echo __METHOD__."$_uid, $_htmlMode<br>";
5287
+		}
4493 5288
 		$bodyPart = array();
4494
-		if (self::$debug) _debug_array($_structure);
5289
+		if (self::$debug)
5290
+		{
5291
+			_debug_array($_structure);
5292
+		}
4495 5293
 
4496 5294
 		$ignore_first_part = true;
4497 5295
 		//$skipParts = array();
@@ -4499,7 +5297,10 @@  discard block
 block discarded – undo
4499 5297
 		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4500 5298
 		{
4501 5299
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type");
4502
-			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5300
+			if (self::$debug)
5301
+			{
5302
+				echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5303
+			}
4503 5304
 			if ($ignore_first_part)
4504 5305
 			{
4505 5306
 				$ignore_first_part = false;
@@ -4517,7 +5318,10 @@  discard block
 block discarded – undo
4517 5318
 			switch($part->getPrimaryType())
4518 5319
 			{
4519 5320
 				case 'multipart':
4520
-					if ($part->getDisposition() == 'attachment') continue;
5321
+					if ($part->getDisposition() == 'attachment')
5322
+					{
5323
+						continue;
5324
+					}
4521 5325
 					switch($part->getSubType())
4522 5326
 					{
4523 5327
 						case 'alternative':
@@ -4582,7 +5386,9 @@  discard block
 block discarded – undo
4582 5386
 					if($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment')
4583 5387
 					{
4584 5388
 						$skipParts[$mime_id.'.0'] = $mime_type;
4585
-						foreach($part->contentTypeMap() as $sub_id => $sub_type){ $skipParts[$sub_id] = $sub_type;}
5389
+						foreach($part->contentTypeMap() as $sub_id => $sub_type)
5390
+						{
5391
+$skipParts[$sub_id] = $sub_type;}
4586 5392
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$_uid.' Part:'.$mime_id.':'.array2string($skipParts));
4587 5393
 						//break 2;
4588 5394
 					}
@@ -4625,7 +5431,10 @@  discard block
 block discarded – undo
4625 5431
 	 */
4626 5432
 	function getBodyPart($_uid, $_partID=null, $_folder=null, $_preserveSeen=false, $_stream=false, &$_encoding=null, $_tryDecodingServerside=true)
4627 5433
 	{
4628
-		if (self::$debug) error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
5434
+		if (self::$debug)
5435
+		{
5436
+			error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
5437
+		}
4629 5438
 
4630 5439
 		if (empty($_folder))
4631 5440
 		{
@@ -4634,7 +5443,10 @@  discard block
 block discarded – undo
4634 5443
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_folder).'/'.$this->icServer->getCurrentMailbox().'/'. $this->sessionData['mailbox']);
4635 5444
 		// querying contents of body part
4636 5445
 		$uidsToFetch = new Horde_Imap_Client_Ids();
4637
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5446
+		if (!(is_object($_uid) || is_array($_uid)))
5447
+		{
5448
+			$_uid = (array)$_uid;
5449
+		}
4638 5450
 		$uidsToFetch->add($_uid);
4639 5451
 
4640 5452
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -4642,9 +5454,12 @@  discard block
 block discarded – undo
4642 5454
 			'peek' => $_preserveSeen,
4643 5455
 			'decode' => true,	// try decode on server, does NOT neccessary work
4644 5456
 		);
4645
-		if ($_tryDecodingServerside===false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
5457
+		if ($_tryDecodingServerside===false)
5458
+		{
5459
+			// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
4646 5460
 		{
4647 5461
 			$_tryDecodingServerside=false;
5462
+		}
4648 5463
 			$fetchParams = array(
4649 5464
 				'peek' => $_preserveSeen,
4650 5465
 			);
@@ -4686,7 +5501,10 @@  discard block
 block discarded – undo
4686 5501
 	{
4687 5502
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_uid.':'.array2string($_structure).' '.function_backtrace());
4688 5503
 		$bodyPart = array();
4689
-		if (self::$debug) _debug_array(array($_structure,function_backtrace()));
5504
+		if (self::$debug)
5505
+		{
5506
+			_debug_array(array($_structure,function_backtrace()));
5507
+		}
4690 5508
 
4691 5509
 		if($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text')))
4692 5510
 		{
@@ -4736,8 +5554,12 @@  discard block
 block discarded – undo
4736 5554
 	 */
4737 5555
 	function getMessageBody($_uid, $_htmlOptions='', $_partID=null, Horde_Mime_Part $_structure=null, $_preserveSeen = false, $_folder = '')
4738 5556
 	{
4739
-		if (self::$debug) echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
4740
-		if($_htmlOptions != '') {
5557
+		if (self::$debug)
5558
+		{
5559
+			echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
5560
+		}
5561
+		if($_htmlOptions != '')
5562
+		{
4741 5563
 			$this->htmlOptions = $_htmlOptions;
4742 5564
 		}
4743 5565
 		if (empty($_folder))
@@ -4826,7 +5648,9 @@  discard block
 block discarded – undo
4826 5648
 						default:
4827 5649
 							$bodyPart = array($this->getTextPart($_uid, $_structure, $this->htmlOptions, $_preserveSeen));
4828 5650
 					}
4829
-				} else {
5651
+				}
5652
+				else
5653
+				{
4830 5654
 					// what if the structure->disposition is attachment ,...
4831 5655
 				}
4832 5656
 				return self::normalizeBodyParts($bodyPart);
@@ -4837,13 +5661,18 @@  discard block
 block discarded – undo
4837 5661
 				{
4838 5662
 					case 'rfc822':
4839 5663
 						$newStructure = $_structure->getParts();
4840
-						if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
5664
+						if (self::$debug)
5665
+						{
5666
+echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
4841 5667
 						return self::normalizeBodyParts($this->getMessageBody($_uid, $_htmlOptions, $newStructure[0]->getMimeId(), $newStructure[0], $_preserveSeen, $_folder));
4842 5668
 				}
4843 5669
 				break;
4844 5670
 
4845 5671
 			default:
4846
-				if (self::$debug) _debug_array($_structure);
5672
+				if (self::$debug)
5673
+				{
5674
+					_debug_array($_structure);
5675
+				}
4847 5676
 				return array(
4848 5677
 					array(
4849 5678
 						'body'		=> lang('The mimeparser can not parse this message.').$_structure->getType(),
@@ -4867,9 +5696,12 @@  discard block
 block discarded – undo
4867 5696
 		{
4868 5697
 			foreach($_bodyParts as $singleBodyPart)
4869 5698
 			{
4870
-				if (!isset($singleBodyPart['body'])) {
5699
+				if (!isset($singleBodyPart['body']))
5700
+				{
4871 5701
 					$buff = self::normalizeBodyParts($singleBodyPart);
4872
-					foreach ((array)$buff as $val) { $body2return[] = $val;}
5702
+					foreach ((array)$buff as $val)
5703
+					{
5704
+$body2return[] = $val;}
4873 5705
 					continue;
4874 5706
 				}
4875 5707
 				$body2return[] = $singleBodyPart;
@@ -4895,13 +5727,20 @@  discard block
 block discarded – undo
4895 5727
 		$message='';
4896 5728
 		for($i=0; $i<count($bodyParts); $i++)
4897 5729
 		{
4898
-			if (!isset($bodyParts[$i]['body'])) {
5730
+			if (!isset($bodyParts[$i]['body']))
5731
+			{
4899 5732
 				$bodyParts[$i]['body'] = self::getdisplayableBody($mailClass, $bodyParts[$i], $preserveHTML, $useTidy);
4900 5733
 				$message .= empty($bodyParts[$i]['body'])?'':$bodyParts[$i]['body'];
4901 5734
 				continue;
4902 5735
 			}
4903
-			if (isset($bodyParts[$i]['error'])) continue;
4904
-			if (empty($bodyParts[$i]['body'])) continue;
5736
+			if (isset($bodyParts[$i]['error']))
5737
+			{
5738
+				continue;
5739
+			}
5740
+			if (empty($bodyParts[$i]['body']))
5741
+			{
5742
+				continue;
5743
+			}
4905 5744
 			// some characterreplacements, as they fail to translate
4906 5745
 			$sar = array(
4907 5746
 				'@(\x84|\x93|\x94)@',
@@ -4928,13 +5767,17 @@  discard block
 block discarded – undo
4928 5767
 				$bodyParts[$i]['body'] = preg_replace($sar,$rar,$bodyParts[$i]['body']);
4929 5768
 			}
4930 5769
 
4931
-			if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
5770
+			if ($bodyParts[$i]['charSet']===false)
5771
+			{
5772
+				$bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
5773
+			}
4932 5774
 			// add line breaks to $bodyParts
4933 5775
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
4934 5776
 			$newBody  = Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
4935 5777
 			//error_log(__METHOD__.' ('.__LINE__.') '.' MimeType:'.$bodyParts[$i]['mimeType'].'->'.$newBody);
4936 5778
 			$mailClass->activeMimeType = 'text/plain';
4937
-			if ($bodyParts[$i]['mimeType'] == 'text/html') {
5779
+			if ($bodyParts[$i]['mimeType'] == 'text/html')
5780
+			{
4938 5781
 				$mailClass->activeMimeType = $bodyParts[$i]['mimeType'];
4939 5782
 				if (!$preserveHTML)
4940 5783
 				{
@@ -4980,15 +5823,28 @@  discard block
 block discarded – undo
4980 5823
 						// as we switched off HTMLaweds tidy functionality
4981 5824
 						$newBody = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<BR>','<BR>','<BR>'),$newBody);
4982 5825
 						$newBody = $htmLawed->run($newBody,self::$htmLawed_config);
4983
-						if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3];
5826
+						if ($hasOther && $preserveHTML)
5827
+						{
5828
+							$newBody = $matches[1]. $newBody. $matches[3];
5829
+						}
4984 5830
 						$alreadyHtmlLawed=true;
4985 5831
 					}
4986 5832
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after purify:'.$newBody);
4987
-					if ($preserveHTML==false) $newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true);
5833
+					if ($preserveHTML==false)
5834
+					{
5835
+						$newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true);
5836
+					}
4988 5837
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after convertHTMLToText:'.$newBody);
4989
-					if ($preserveHTML==false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n
5838
+					if ($preserveHTML==false)
5839
+					{
5840
+						$newBody = nl2br($newBody);
5841
+					}
5842
+					// we need this, as htmLawed removes \r\n
4990 5843
 					/*if (!$alreadyHtmlLawed) */ $mailClass->getCleanHTML($newBody); // remove stuff we regard as unwanted
4991
-					if ($preserveHTML==false) $newBody = str_replace("<br />","\r\n",$newBody);
5844
+					if ($preserveHTML==false)
5845
+					{
5846
+						$newBody = str_replace("<br />","\r\n",$newBody);
5847
+					}
4992 5848
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after getClean:'.$newBody);
4993 5849
 				}
4994 5850
 				$message .= $newBody;
@@ -5025,12 +5881,12 @@  discard block
 block discarded – undo
5025 5881
 				  substr($line,0,strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
5026 5882
 				 )
5027 5883
 				)
5028
-			   )
5029
-			{
5884
+			   ) {
5030 5885
 				$s=explode(" ", $line);
5031 5886
 				$line = "";
5032 5887
 				$linecnt = 0;
5033
-				foreach ($s as &$v) {
5888
+				foreach ($s as &$v)
5889
+				{
5034 5890
 					$cnt = strlen($v);
5035 5891
 					// only break long words within the wordboundaries,
5036 5892
 					// but it may destroy links, so we check for href and dont do it if we find one
@@ -5040,14 +5896,20 @@  discard block
 block discarded – undo
5040 5896
 						$v=wordwrap($v, $allowedLength, $cut, true);
5041 5897
 					}
5042 5898
 					// the rest should be broken at the start of the new word that exceeds the limit
5043
-					if ($linecnt+$cnt > $allowedLength) {
5899
+					if ($linecnt+$cnt > $allowedLength)
5900
+					{
5044 5901
 						$v=$cut.$v;
5045 5902
 						#$linecnt = 0;
5046 5903
 						$linecnt =strlen($v)-strlen($cut);
5047
-					} else {
5904
+					}
5905
+					else
5906
+					{
5048 5907
 						$linecnt += $cnt;
5049 5908
 					}
5050
-					if (strlen($v)) $line .= (strlen($line) ? " " : "").$v;
5909
+					if (strlen($v))
5910
+					{
5911
+						$line .= (strlen($line) ? " " : "").$v;
5912
+					}
5051 5913
 				}
5052 5914
 			}
5053 5915
 			$newStr .= $line . "\n";
@@ -5068,11 +5930,18 @@  discard block
 block discarded – undo
5068 5930
 	function getMessageEnvelope($_uid, $_partID = '',$decode=false, $_folder='', $_useHeaderInsteadOfEnvelope=false)
5069 5931
 	{
5070 5932
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder".function_backtrace());
5071
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5933
+		if (empty($_folder))
5934
+		{
5935
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5936
+		}
5072 5937
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder");
5073
-		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false) {
5938
+		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false)
5939
+		{
5074 5940
 			$uidsToFetch = new Horde_Imap_Client_Ids();
5075
-			if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5941
+			if (!(is_object($_uid) || is_array($_uid)))
5942
+			{
5943
+				$_uid = (array)$_uid;
5944
+			}
5076 5945
 			$uidsToFetch->add($_uid);
5077 5946
 
5078 5947
 			$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5082,8 +5951,10 @@  discard block
 block discarded – undo
5082 5951
 			$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5083 5952
 				'ids' => $uidsToFetch,
5084 5953
 			));
5085
-			if (is_object($headersNew)) {
5086
-				foreach($headersNew as &$_headerObject) {
5954
+			if (is_object($headersNew))
5955
+			{
5956
+				foreach($headersNew as &$_headerObject)
5957
+				{
5087 5958
 					$env = $_headerObject->getEnvelope();
5088 5959
 					//_debug_array($envFields->singleFields());
5089 5960
 					$singleFields = $envFields->singleFields();
@@ -5100,7 +5971,10 @@  discard block
 block discarded – undo
5100 5971
 								//error_log(__METHOD__.' ('.__LINE__.') '.$v.'->'.array2string($env->$v->addresses));
5101 5972
 								$envelope[$v]=$env->$v->addresses;
5102 5973
 								$address = array();
5103
-								if (!is_array($envelope[$v])) break;
5974
+								if (!is_array($envelope[$v]))
5975
+								{
5976
+									break;
5977
+								}
5104 5978
 								foreach ($envelope[$v] as $k => $ad)
5105 5979
 								{
5106 5980
 									if (stripos($ad,'@')===false)
@@ -5137,7 +6011,9 @@  discard block
 block discarded – undo
5137 6011
 				}
5138 6012
 			}
5139 6013
 			return $envelope;
5140
-		} else {
6014
+		}
6015
+		else
6016
+		{
5141 6017
 
5142 6018
 			$headers = $this->getMessageHeader($_uid, $_partID, true,true,$_folder);
5143 6019
 
@@ -5148,19 +6024,43 @@  discard block
 block discarded – undo
5148 6024
 				'SUBJECT'	=> ($decode ? self::decode_header($headers['SUBJECT']):$headers['SUBJECT']),
5149 6025
 				'MESSAGE_ID'	=> $headers['MESSAGE-ID']
5150 6026
 			);
5151
-			if (isset($headers['IN-REPLY-TO'])) $newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
5152
-			if (isset($headers['REFERENCES'])) $newData['REFERENCES'] = $headers['REFERENCES'];
5153
-			if (isset($headers['THREAD-TOPIC'])) $newData['THREAD-TOPIC'] = $headers['THREAD-TOPIC'];
5154
-			if (isset($headers['THREAD-INDEX'])) $newData['THREAD-INDEX'] = $headers['THREAD-INDEX'];
5155
-			if (isset($headers['LIST-ID'])) $newData['LIST-ID'] = $headers['LIST-ID'];
5156
-			if (isset($headers['SIZE'])) $newData['SIZE'] = $headers['SIZE'];
6027
+			if (isset($headers['IN-REPLY-TO']))
6028
+			{
6029
+				$newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
6030
+			}
6031
+			if (isset($headers['REFERENCES']))
6032
+			{
6033
+				$newData['REFERENCES'] = $headers['REFERENCES'];
6034
+			}
6035
+			if (isset($headers['THREAD-TOPIC']))
6036
+			{
6037
+				$newData['THREAD-TOPIC'] = $headers['THREAD-TOPIC'];
6038
+			}
6039
+			if (isset($headers['THREAD-INDEX']))
6040
+			{
6041
+				$newData['THREAD-INDEX'] = $headers['THREAD-INDEX'];
6042
+			}
6043
+			if (isset($headers['LIST-ID']))
6044
+			{
6045
+				$newData['LIST-ID'] = $headers['LIST-ID'];
6046
+			}
6047
+			if (isset($headers['SIZE']))
6048
+			{
6049
+				$newData['SIZE'] = $headers['SIZE'];
6050
+			}
5157 6051
 			//_debug_array($newData);
5158 6052
 			$recepientList = array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO');
5159
-			foreach($recepientList as $recepientType) {
5160
-				if(isset($headers[$recepientType])) {
5161
-					if ($decode) $headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
6053
+			foreach($recepientList as $recepientType)
6054
+			{
6055
+				if(isset($headers[$recepientType]))
6056
+				{
6057
+					if ($decode)
6058
+					{
6059
+						$headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
6060
+					}
5162 6061
 					//error_log(__METHOD__.__LINE__." ".$recepientType."->".array2string($headers[$recepientType]));
5163
-					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress) {
6062
+					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress)
6063
+					{
5164 6064
 						$addressData = array(
5165 6065
 							'PERSONAL_NAME'		=> $singleAddress->personal ? $singleAddress->personal : 'NIL',
5166 6066
 							'AT_DOMAIN_LIST'	=> $singleAddress->adl ? $singleAddress->adl : 'NIL',
@@ -5168,17 +6068,25 @@  discard block
 block discarded – undo
5168 6068
 							'HOST_NAME'		=> $singleAddress->host ? $singleAddress->host : 'NIL',
5169 6069
 							'EMAIL'			=> $singleAddress->host ? $singleAddress->mailbox.'@'.$singleAddress->host : $singleAddress->mailbox,
5170 6070
 						);
5171
-						if($addressData['PERSONAL_NAME'] != 'NIL') {
6071
+						if($addressData['PERSONAL_NAME'] != 'NIL')
6072
+						{
5172 6073
 							$addressData['RFC822_EMAIL'] = imap_rfc822_write_address($singleAddress->mailbox, $singleAddress->host, $singleAddress->personal);
5173
-						} else {
6074
+						}
6075
+						else
6076
+						{
5174 6077
 							$addressData['RFC822_EMAIL'] = 'NIL';
5175 6078
 						}
5176 6079
 						$newData[$recepientType][] = ($addressData['RFC822_EMAIL']!='NIL'?$addressData['RFC822_EMAIL']:$addressData['EMAIL']);//$addressData;
5177 6080
 					}
5178
-				} else {
5179
-					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') {
6081
+				}
6082
+				else
6083
+				{
6084
+					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO')
6085
+					{
5180 6086
 						$newData[$recepientType] = $newData['FROM'];
5181
-					} else {
6087
+					}
6088
+					else
6089
+					{
5182 6090
 						$newData[$recepientType] = array();
5183 6091
 					}
5184 6092
 				}
@@ -5201,9 +6109,15 @@  discard block
 block discarded – undo
5201 6109
 	function getMessageHeader($_uid, $_partID = '',$decode=false, $preserveUnSeen=false, $_folder='')
5202 6110
 	{
5203 6111
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$_uid.', '.$_partID.', '.$decode.', '.$preserveUnSeen.', '.$_folder);
5204
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6112
+		if (empty($_folder))
6113
+		{
6114
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6115
+		}
5205 6116
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5206
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6117
+		if (!(is_object($_uid) || is_array($_uid)))
6118
+		{
6119
+			$_uid = (array)$_uid;
6120
+		}
5207 6121
 		$uidsToFetch->add($_uid);
5208 6122
 
5209 6123
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5221,7 +6135,8 @@  discard block
 block discarded – undo
5221 6135
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5222 6136
 			'ids' => $uidsToFetch,
5223 6137
 		));
5224
-		if (is_object($headersNew)) {
6138
+		if (is_object($headersNew))
6139
+		{
5225 6140
 			foreach($headersNew as $_fetchObject)
5226 6141
 			{
5227 6142
 				$headers = $_fetchObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
@@ -5243,11 +6158,17 @@  discard block
 block discarded – undo
5243 6158
 			}
5244 6159
 			if ($decode === 'object')
5245 6160
 			{
5246
-				if (is_object($headers)) $headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
6161
+				if (is_object($headers))
6162
+				{
6163
+					$headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
6164
+				}
5247 6165
 				return $headers;
5248 6166
 			}
5249 6167
 			$retValue = is_object($headers) ? $headers->toArray():array();
5250
-			if ($size) $retValue['size'] = $size;
6168
+			if ($size)
6169
+			{
6170
+				$retValue['size'] = $size;
6171
+			}
5251 6172
 		}
5252 6173
 		$retValue = array_change_key_case($retValue,CASE_UPPER);
5253 6174
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue));
@@ -5279,10 +6200,16 @@  discard block
 block discarded – undo
5279 6200
 	function getMessageRawHeader($_uid, $_partID = '', $_folder = '')
5280 6201
 	{
5281 6202
 		static $rawHeaders;
5282
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6203
+		if (empty($_folder))
6204
+		{
6205
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6206
+		}
5283 6207
 		//error_log(__METHOD__.' ('.__LINE__.') '." Try Using Cache for raw Header $_uid, $_partID in Folder $_folder");
5284 6208
 
5285
-		if (is_null($rawHeaders)||!is_array($rawHeaders)) $rawHeaders = Cache::getCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
6209
+		if (is_null($rawHeaders)||!is_array($rawHeaders))
6210
+		{
6211
+			$rawHeaders = Cache::getCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
6212
+		}
5286 6213
 		if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5287 6214
 		{
5288 6215
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Header $_uid, $_partID in Folder $_folder");
@@ -5290,7 +6217,10 @@  discard block
 block discarded – undo
5290 6217
 		}
5291 6218
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5292 6219
 		$uid = $_uid;
5293
-		if (!(is_object($_uid) || is_array($_uid))) $uid = (array)$_uid;
6220
+		if (!(is_object($_uid) || is_array($_uid)))
6221
+		{
6222
+			$uid = (array)$_uid;
6223
+		}
5294 6224
 		$uidsToFetch->add($uid);
5295 6225
 
5296 6226
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5306,8 +6236,10 @@  discard block
 block discarded – undo
5306 6236
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5307 6237
 			'ids' => $uidsToFetch,
5308 6238
 		));
5309
-		if (is_object($headersNew)) {
5310
-			foreach($headersNew as &$_headerObject) {
6239
+		if (is_object($headersNew))
6240
+		{
6241
+			foreach($headersNew as &$_headerObject)
6242
+			{
5311 6243
 				$retValue = $_headerObject->getHeaderText();
5312 6244
 				if ($_partID != '')
5313 6245
 				{
@@ -5335,22 +6267,33 @@  discard block
 block discarded – undo
5335 6267
 	static function &getStyles($_bodyParts)
5336 6268
 	{
5337 6269
 		$style = '';
5338
-		if (empty($_bodyParts)) return "";
5339
-		foreach((array)$_bodyParts as $singleBodyPart) {
5340
-			if (!isset($singleBodyPart['body'])) {
6270
+		if (empty($_bodyParts))
6271
+		{
6272
+			return "";
6273
+		}
6274
+		foreach((array)$_bodyParts as $singleBodyPart)
6275
+		{
6276
+			if (!isset($singleBodyPart['body']))
6277
+			{
5341 6278
 				$singleBodyPart['body'] = self::getStyles($singleBodyPart);
5342 6279
 				$style .= $singleBodyPart['body'];
5343 6280
 				continue;
5344 6281
 			}
5345 6282
 
5346
-			if ($singleBodyPart['charSet']===false) $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
6283
+			if ($singleBodyPart['charSet']===false)
6284
+			{
6285
+				$singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
6286
+			}
5347 6287
 			$singleBodyPart['body'] = Translation::convert(
5348 6288
 				$singleBodyPart['body'],
5349 6289
 				strtolower($singleBodyPart['charSet'])
5350 6290
 			);
5351 6291
 			$ct = 0;
5352 6292
 			$newStyle=array();
5353
-			if (stripos($singleBodyPart['body'],'<style')!==false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
6293
+			if (stripos($singleBodyPart['body'],'<style')!==false)
6294
+			{
6295
+				$ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
6296
+			}
5354 6297
 			if ($ct>0)
5355 6298
 			{
5356 6299
 				//error_log(__METHOD__.' ('.__LINE__.') '.'#'.$ct.'#'.array2string($newStyle));
@@ -5382,7 +6325,11 @@  discard block
 block discarded – undo
5382 6325
 		// CSS Security
5383 6326
 		// http://code.google.com/p/browsersec/wiki/Part1#Cascading_stylesheets
5384 6327
 		$css = preg_replace('/(javascript|expression|-moz-binding)/i','',$style);
5385
-		if (stripos($css,'script')!==false) Mail\Html::replaceTagsCompletley($css,'script'); // Strip out script that may be included
6328
+		if (stripos($css,'script')!==false)
6329
+		{
6330
+			Mail\Html::replaceTagsCompletley($css,'script');
6331
+		}
6332
+		// Strip out script that may be included
5386 6333
 		// we need this, as styledefinitions are enclosed with curly brackets; and template stuff tries to replace everything between curly brackets that is having no horizontal whitespace
5387 6334
 		// as the comments as <!-- styledefinition --> in stylesheet are outdated, and ck-editor does not understand it, we remove it
5388 6335
 		$css = str_replace(array(':','<!--','-->'),array(': ','',''),$css);
@@ -5403,8 +6350,14 @@  discard block
 block discarded – undo
5403 6350
 	{
5404 6351
 		//TODO: caching einbauen static!
5405 6352
 		static $rawBody;
5406
-		if (is_null($rawBody)) $rawBody = array();
5407
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6353
+		if (is_null($rawBody))
6354
+		{
6355
+			$rawBody = array();
6356
+		}
6357
+		if (empty($_folder))
6358
+		{
6359
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6360
+		}
5408 6361
 		if (isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5409 6362
 		{
5410 6363
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Body $_uid, $_partID in Folder $_folder");
@@ -5413,7 +6366,10 @@  discard block
 block discarded – undo
5413 6366
 
5414 6367
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5415 6368
 		$uid = $_uid;
5416
-		if (!(is_object($_uid) || is_array($_uid))) $uid = (array)$_uid;
6369
+		if (!(is_object($_uid) || is_array($_uid)))
6370
+		{
6371
+			$uid = (array)$_uid;
6372
+		}
5417 6373
 		$uidsToFetch->add($uid);
5418 6374
 
5419 6375
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5426,8 +6382,10 @@  discard block
 block discarded – undo
5426 6382
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5427 6383
 			'ids' => $uidsToFetch,
5428 6384
 		));
5429
-		if (is_object($headersNew)) {
5430
-			foreach($headersNew as &$_headerObject) {
6385
+		if (is_object($headersNew))
6386
+		{
6387
+			foreach($headersNew as &$_headerObject)
6388
+			{
5431 6389
 				$body = $_headerObject->getFullMsg();
5432 6390
 				if ($_partID != '')
5433 6391
 				{
@@ -5460,14 +6418,20 @@  discard block
 block discarded – undo
5460 6418
 	 */
5461 6419
 	function getStructure($_uid, $_partID=null, $_folder=null, $_preserveSeen=false)
5462 6420
 	{
5463
-		if (self::$debug) error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
6421
+		if (self::$debug)
6422
+		{
6423
+			error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
6424
+		}
5464 6425
 
5465 6426
 		if (empty($_folder))
5466 6427
 		{
5467 6428
 			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5468 6429
 		}
5469 6430
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5470
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6431
+		if (!(is_object($_uid) || is_array($_uid)))
6432
+		{
6433
+			$_uid = (array)$_uid;
6434
+		}
5471 6435
 		$uidsToFetch->add($_uid);
5472 6436
 		try
5473 6437
 		{
@@ -5476,7 +6440,10 @@  discard block
 block discarded – undo
5476 6440
 	//		$fquery->envelope();
5477 6441
 	//		$fquery->size();
5478 6442
 			$_fquery->structure();
5479
-			if ($_partID) $_fquery->bodyPart($_partID, array('peek' => $_preserveSeen));
6443
+			if ($_partID)
6444
+			{
6445
+				$_fquery->bodyPart($_partID, array('peek' => $_preserveSeen));
6446
+			}
5480 6447
 
5481 6448
 			$mail = $this->icServer->fetch($_folder, $_fquery, array(
5482 6449
 				'ids' => $uidsToFetch,
@@ -5507,16 +6474,28 @@  discard block
 block discarded – undo
5507 6474
 	 */
5508 6475
 	function getMessageAttachments($_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folder='')
5509 6476
 	{
5510
-		if (self::$debug) error_log( __METHOD__.":$_uid, $_partID");
5511
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6477
+		if (self::$debug)
6478
+		{
6479
+			error_log( __METHOD__.":$_uid, $_partID");
6480
+		}
6481
+		if (empty($_folder))
6482
+		{
6483
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6484
+		}
5512 6485
 		$attachments = array();
5513 6486
 		if (!isset($_structure))
5514 6487
 		{
5515 6488
 			$_structure = $this->getStructure($_uid, $_partID,$_folder,true);
5516 6489
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.print_r($_structure->contentTypeMap(),true));
5517 6490
 		}
5518
-		if (!$_structure || !$_structure->contentTypeMap()) return array();
5519
-		if (!empty($_partID)) $_structure = $_structure->getPart($_partID);
6491
+		if (!$_structure || !$_structure->contentTypeMap())
6492
+		{
6493
+			return array();
6494
+		}
6495
+		if (!empty($_partID))
6496
+		{
6497
+			$_structure = $_structure->getPart($_partID);
6498
+		}
5520 6499
 		$skipParts = array();
5521 6500
 		$tnefParts = array();
5522 6501
 		$skip = 0;
@@ -5545,7 +6524,13 @@  discard block
 block discarded – undo
5545 6524
 			if ($mime_type=='message/rfc822' && $_partID!=$mime_id)
5546 6525
 			{
5547 6526
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
5548
-				foreach($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
6527
+				foreach($part->contentTypeMap() as $sub_id => $sub_type)
6528
+				{
6529
+if ($sub_id != $mime_id)
6530
+				{
6531
+					$skipParts[$sub_id] = $sub_type;
6532
+				}
6533
+				}
5549 6534
 			}
5550 6535
 			if (empty($partDisposition) && $partPrimaryType != 'multipart' && $partPrimaryType != 'text')
5551 6536
 			{
@@ -5556,7 +6541,10 @@  discard block
 block discarded – undo
5556 6541
 				$partDisposition='attachment';
5557 6542
 			}
5558 6543
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($skipParts));
5559
-			if (array_key_exists($mime_id,$skipParts)) continue;
6544
+			if (array_key_exists($mime_id,$skipParts))
6545
+			{
6546
+				continue;
6547
+			}
5560 6548
 
5561 6549
 			if ($partDisposition == 'attachment' ||
5562 6550
 				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId()=='') ||
@@ -5567,23 +6555,41 @@  discard block
 block discarded – undo
5567 6555
 			{
5568 6556
 				// if type is message/rfc822 and _partID is given, and MimeID equals partID
5569 6557
 				// we attempt to fetch "ourselves"
5570
-				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message') continue;
6558
+				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message')
6559
+				{
6560
+					continue;
6561
+				}
5571 6562
 				$attachment = $part->getAllDispositionParameters();
5572 6563
 				$attachment['disposition'] = $part->getDisposition();
5573 6564
 				$attachment['mimeType'] = $mime_type;
5574 6565
 				$attachment['uid'] = $_uid;
5575 6566
 				$attachment['partID'] = $mime_id;
5576
-				if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
6567
+				if (!isset($attachment['name'])||empty($attachment['name']))
6568
+				{
6569
+					$attachment['name'] = $part->getName();
6570
+				}
5577 6571
 				if ($fetchTextCalendar)
5578 6572
 				{
5579 6573
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part->getAllContentTypeParameters()));
5580 6574
 					$method = $part->getContentTypeParameter('method');
5581
-					if ($method) $attachment['method'] = $method;
5582
-					if (!isset($attachment['name'])) $attachment['name'] = 'event.ics';
6575
+					if ($method)
6576
+					{
6577
+						$attachment['method'] = $method;
6578
+					}
6579
+					if (!isset($attachment['name']))
6580
+					{
6581
+						$attachment['name'] = 'event.ics';
6582
+					}
5583 6583
 				}
5584 6584
 				$attachment['size'] = $part->getBytes();
5585
-				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5586
-				if (empty($attachment['name'])) $attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($mime_type);
6585
+				if (($cid = $part->getContentId()))
6586
+				{
6587
+					$attachment['cid'] = $cid;
6588
+				}
6589
+				if (empty($attachment['name']))
6590
+				{
6591
+					$attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($mime_type);
6592
+				}
5587 6593
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($attachment));
5588 6594
 				//typical winmail.dat attachment is
5589 6595
 				//Array([size] => 1462762[filename] => winmail.dat[mimeType] => application/ms-tnef[uid] => 100[partID] => 2[name] => winmail.dat)
@@ -5619,14 +6625,26 @@  discard block
 block discarded – undo
5619 6625
 						$attachment['uid'] = $tnp['uid'];
5620 6626
 						$attachment['partID'] = $tnp['partID'];
5621 6627
 						$attachment['is_winmail'] = $tnp['uid'].'@'.$tnp['partID'].'@'.$mime_id;
5622
-						if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
6628
+						if (!isset($attachment['name'])||empty($attachment['name']))
6629
+						{
6630
+							$attachment['name'] = $part->getName();
6631
+						}
5623 6632
 						$attachment['size'] = $part->getBytes();
5624
-						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5625
-						if (empty($attachment['name'])) $attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
6633
+						if (($cid = $part->getContentId()))
6634
+						{
6635
+							$attachment['cid'] = $cid;
6636
+						}
6637
+						if (empty($attachment['name']))
6638
+						{
6639
+							$attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
6640
+						}
5626 6641
 						$attachments[] = $attachment;
5627 6642
 					}
5628 6643
 				}
5629
-				if ($tnefResolved===false) $attachments[]=$tnp;
6644
+				if ($tnefResolved===false)
6645
+				{
6646
+					$attachments[]=$tnp;
6647
+				}
5630 6648
 			}
5631 6649
 		}
5632 6650
 		//error_log(__METHOD__.__LINE__.array2string($attachments));
@@ -5730,8 +6748,14 @@  discard block
 block discarded – undo
5730 6748
 
5731 6749
 				$attachment = $part->getAllDispositionParameters();
5732 6750
 				$attachment['mimeType'] = $part->getType();
5733
-				if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5734
-				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
6751
+				if (!isset($attachment['filename'])||empty($attachment['filename']))
6752
+				{
6753
+					$attachment['filename'] = $part->getName();
6754
+				}
6755
+				if (($cid = $part->getContentId()))
6756
+				{
6757
+					$attachment['cid'] = $cid;
6758
+				}
5735 6759
 				if (empty($attachment['filename']))
5736 6760
 				{
5737 6761
 					$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?
@@ -5743,7 +6767,10 @@  discard block
 block discarded – undo
5743 6767
 				$attachments[$_uid.'@'.$_partID.'@'.$mime_id] = $attachment;
5744 6768
 			}
5745 6769
 		}
5746
-		if (!is_array($attachments)) return false;
6770
+		if (!is_array($attachments))
6771
+		{
6772
+			return false;
6773
+		}
5747 6774
 		return $attachments;
5748 6775
 	}
5749 6776
 
@@ -5762,10 +6789,16 @@  discard block
 block discarded – undo
5762 6789
 	function getAttachment($_uid, $_partID, $_winmail_nr=0, $_returnPart=true, $_stream=false, $_folder=null)
5763 6790
 	{
5764 6791
 		//error_log(__METHOD__.__LINE__."Uid:$_uid, PartId:$_partID, WinMailNr:$_winmail_nr, ReturnPart:$_returnPart, Stream:$_stream, Folder:$_folder".function_backtrace());
5765
-		if (!isset($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6792
+		if (!isset($_folder))
6793
+		{
6794
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6795
+		}
5766 6796
 
5767 6797
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5768
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6798
+		if (!(is_object($_uid) || is_array($_uid)))
6799
+		{
6800
+			$_uid = (array)$_uid;
6801
+		}
5769 6802
 		$uidsToFetch->add($_uid);
5770 6803
 
5771 6804
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5774,8 +6807,10 @@  discard block
 block discarded – undo
5774 6807
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5775 6808
 			'ids' => $uidsToFetch,
5776 6809
 		));
5777
-		if (is_object($headersNew)) {
5778
-			foreach($headersNew as $id=>$_headerObject) {
6810
+		if (is_object($headersNew))
6811
+		{
6812
+			foreach($headersNew as $id=>$_headerObject)
6813
+			{
5779 6814
 				$body = $_headerObject->getFullMsg();
5780 6815
 				if ($_partID != '')
5781 6816
 				{
@@ -5789,7 +6824,10 @@  discard block
 block discarded – undo
5789 6824
 					}
5790 6825
 					// if $partDisposition is empty, we assume attachment, and hope that the function
5791 6826
 					// itself is only triggered to fetch attachments
5792
-					if (empty($partDisposition)) $partDisposition='attachment';
6827
+					if (empty($partDisposition))
6828
+					{
6829
+						$partDisposition='attachment';
6830
+					}
5793 6831
 					if ($part && ($partDisposition=='attachment' || $partDisposition=='inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar')))
5794 6832
 					{
5795 6833
 						//$headerObject=$part->getAllDispositionParameters();//not used anywhere around here
@@ -5798,13 +6836,19 @@  discard block
 block discarded – undo
5798 6836
 						$charset = $part->getContentTypeParameter('charset');
5799 6837
 						//$structure_bytes = $part->getBytes(); $structure_partID=$part->getMimeId(); error_log(__METHOD__.__LINE__." fetchPartContents(".array2string($_uid).", $structure_partID, $_stream, $_preserveSeen,$structure_mime)" );
5800 6838
 						$this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen=true,$structure_mime);
5801
-						if ($_returnPart) return $part;
6839
+						if ($_returnPart)
6840
+						{
6841
+							return $part;
6842
+						}
5802 6843
 					}
5803 6844
 				}
5804 6845
 			}
5805 6846
 		}
5806 6847
 		$ext = MimeMagic::mime2ext($structure_mime);
5807
-		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false) $filename = trim($filename).'.'.$ext;
6848
+		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false)
6849
+		{
6850
+			$filename = trim($filename).'.'.$ext;
6851
+		}
5808 6852
 		if (!$part)
5809 6853
 		{
5810 6854
 			throw new Exception\WrongParameter("Error: Could not fetch attachment for Uid=".array2string($_uid).", PartId=$_partID, WinMailNr=$_winmail_nr, folder=$_folder");
@@ -5820,7 +6864,10 @@  discard block
 block discarded – undo
5820 6864
 		);
5821 6865
 
5822 6866
 		// try guessing the mimetype, if we get the application/octet-stream
5823
-		if (strtolower($attachmentData['type']) == 'application/octet-stream') $attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']);
6867
+		if (strtolower($attachmentData['type']) == 'application/octet-stream')
6868
+		{
6869
+			$attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']);
6870
+		}
5824 6871
 		# if the attachment holds a winmail number and is a winmail.dat then we have to handle that.
5825 6872
 		if ( $filename == 'winmail.dat' && $_winmail_nr)
5826 6873
 		{
@@ -5843,9 +6890,18 @@  discard block
 block discarded – undo
5843 6890
 					if ($_winmail_nr == $wantedPart.'@'.$mime_id)
5844 6891
 					{
5845 6892
 						//error_log(__METHOD__.__LINE__.'#'.$structure_mime.'#'.$filename.'#'.array2string($attachment));
5846
-						if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5847
-						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5848
-						if (empty($attachment['filename'])) $attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
6893
+						if (!isset($attachment['filename'])||empty($attachment['filename']))
6894
+						{
6895
+							$attachment['filename'] = $part->getName();
6896
+						}
6897
+						if (($cid = $part->getContentId()))
6898
+						{
6899
+							$attachment['cid'] = $cid;
6900
+						}
6901
+						if (empty($attachment['filename']))
6902
+						{
6903
+							$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
6904
+						}
5849 6905
 						$wmattach = $attachment;
5850 6906
 						$wmattach['attachment'] = $part->getContents(array('stream'=>$_stream));
5851 6907
 
@@ -5855,7 +6911,10 @@  discard block
 block discarded – undo
5855 6911
 			if ($tnefResolved)
5856 6912
 			{
5857 6913
 				$ext = MimeMagic::mime2ext($wmattach['mimeType']);
5858
-				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
6914
+				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false)
6915
+				{
6916
+					$wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
6917
+				}
5859 6918
 				$attachmentData = array(
5860 6919
 					'type'       => $wmattach['mimeType'],
5861 6920
 					'filename'   => $wmattach['filename'],
@@ -5885,7 +6944,10 @@  discard block
 block discarded – undo
5885 6944
 		static $uid=null, $part=null, $structure=null;
5886 6945
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_cid, $_part");
5887 6946
 
5888
-		if(empty($_cid)) return false;
6947
+		if(empty($_cid))
6948
+		{
6949
+			return false;
6950
+		}
5889 6951
 
5890 6952
 		if ($_uid != $uid || $_part != $part)
5891 6953
 		{
@@ -5910,13 +6972,19 @@  discard block
 block discarded – undo
5910 6972
 					$attachment = $part;
5911 6973
 				}
5912 6974
 				// everything else we only consider after we checked all
5913
-				if (!isset($attachment)) $attachment = $part;
6975
+				if (!isset($attachment))
6976
+				{
6977
+					$attachment = $part;
6978
+				}
5914 6979
 				// do we want content fetched, can be done later, if not needed
5915 6980
 				if (isset($_stream))
5916 6981
 				{
5917 6982
 					$this->fetchPartContents($_uid, $attachment, $_stream);
5918 6983
 				}
5919
-				if (isset($attachment)) break;
6984
+				if (isset($attachment))
6985
+				{
6986
+					break;
6987
+				}
5920 6988
 			}
5921 6989
 		}
5922 6990
 		// set name as filename, if not set
@@ -5947,10 +7015,17 @@  discard block
 block discarded – undo
5947 7015
 	 */
5948 7016
 	public function fetchPartContents($_uid, Horde_Mime_Part $part=null, $_stream=false, $_preserveSeen=false, $_mimetype=null)
5949 7017
 	{
5950
-		if (is_null($part)) return null;//new Horde_Mime_Part;
7018
+		if (is_null($part))
7019
+		{
7020
+			return null;
7021
+		}
7022
+		//new Horde_Mime_Part;
5951 7023
 		$encoding = null;
5952 7024
 		$fetchAsBinary = true;
5953
-		if ($_mimetype && strtolower($_mimetype)=='message/rfc822') $fetchAsBinary = false;
7025
+		if ($_mimetype && strtolower($_mimetype)=='message/rfc822')
7026
+		{
7027
+			$fetchAsBinary = false;
7028
+		}
5954 7029
 		// we need to set content on structure to decode transfer encoding
5955 7030
 		$part->setContents(
5956 7031
 			$this->getBodyPart($_uid, $part->getMimeId(), null, $_preserveSeen, $_stream, $encoding, $fetchAsBinary),
@@ -5987,7 +7062,10 @@  discard block
 block discarded – undo
5987 7062
 		// the recent flag is the default enforced here ; as we assume the _flags is always set,
5988 7063
 		// we default it to hordes default (Recent) (, other wise we should not pass the parameter
5989 7064
 		// for flags at all)
5990
-		if (empty($_flags)) $_flags = '\\Recent';
7065
+		if (empty($_flags))
7066
+		{
7067
+			$_flags = '\\Recent';
7068
+		}
5991 7069
 		//if (!is_array($_flags) && stripos($_flags,',')!==false) $_flags=explode(',',$_flags);
5992 7070
 		//if (!is_array($_flags)) $_flags = (array) $_flags;
5993 7071
 		try
@@ -6004,18 +7082,27 @@  discard block
 block discarded – undo
6004 7082
 		}
6005 7083
 		catch (\Exception $e)
6006 7084
 		{
6007
-			if (self::$debug) error_log("Could not append Message: ".$e->getMessage());
7085
+			if (self::$debug)
7086
+			{
7087
+				error_log("Could not append Message: ".$e->getMessage());
7088
+			}
6008 7089
 			throw new Exception\WrongUserinput(lang("Could not append Message:").' '.$e->getMessage().': '.$e->details);
6009 7090
 			//return false;
6010 7091
 		}
6011 7092
 		//error_log(__METHOD__.' ('.__LINE__.') '.' appended UID:'.$messageid);
6012 7093
 		//$messageid = true; // for debug reasons only
6013
-		if ($messageid === true || empty($messageid)) // try to figure out the message uid
7094
+		if ($messageid === true || empty($messageid))
7095
+		{
7096
+			// try to figure out the message uid
6014 7097
 		{
6015 7098
 			$list = $this->getHeaders($_folderName, $_startMessage=1, 1, 'INTERNALDATE', true, array(),null, false);
7099
+		}
6016 7100
 			if ($list)
6017 7101
 			{
6018
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
7102
+				if (self::$debug)
7103
+				{
7104
+					error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
7105
+				}
6019 7106
 				$messageid = $list['header'][0]['uid'];
6020 7107
 			}
6021 7108
 		}
@@ -6056,7 +7143,10 @@  discard block
 block discarded – undo
6056 7143
 	{
6057 7144
 			//echo __METHOD__." called for $uid,$partid <br>";
6058 7145
 			$headers = $mailClass->getMessageHeader($uid,$partid,true,false,$mailbox);
6059
-			if (empty($headers)) return false;
7146
+			if (empty($headers))
7147
+			{
7148
+				return false;
7149
+			}
6060 7150
 			// dont force retrieval of the textpart, let mailClass preferences decide
6061 7151
 			$bodyParts = $mailClass->getMessageBody($uid,($preserveHTML?'always_display':'only_if_no_text'),$partid,null,false,$mailbox);
6062 7152
 			// if we do not want HTML but there is no TextRepresentation with the message itself, try converting
@@ -6074,15 +7164,30 @@  discard block
 block discarded – undo
6074 7164
 			//error_log(array2string($bodyParts));
6075 7165
 			$attachments = $includeAttachments?$mailClass->getMessageAttachments($uid,$partid,null,true,false,true,$mailbox):array();
6076 7166
 
6077
-			if ($mailClass->isSentFolder($mailbox)) $mailaddress = $headers['TO'];
6078
-			elseif (isset($headers['FROM'])) $mailaddress = $headers['FROM'];
6079
-			elseif (isset($headers['SENDER'])) $mailaddress = $headers['SENDER'];
6080
-			if (isset($headers['CC'])) $mailaddress .= ','.$headers['CC'];
7167
+			if ($mailClass->isSentFolder($mailbox))
7168
+			{
7169
+				$mailaddress = $headers['TO'];
7170
+			}
7171
+			elseif (isset($headers['FROM']))
7172
+			{
7173
+				$mailaddress = $headers['FROM'];
7174
+			}
7175
+			elseif (isset($headers['SENDER']))
7176
+			{
7177
+				$mailaddress = $headers['SENDER'];
7178
+			}
7179
+			if (isset($headers['CC']))
7180
+			{
7181
+				$mailaddress .= ','.$headers['CC'];
7182
+			}
6081 7183
 			//_debug_array(array($headers,$mailaddress));
6082 7184
 			$subject = $headers['SUBJECT'];
6083 7185
 
6084 7186
 			$message = self::getdisplayableBody($mailClass, $bodyParts, $preserveHTML);
6085
-			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain') $message = '<pre>'.$message.'</pre>';
7187
+			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain')
7188
+			{
7189
+				$message = '<pre>'.$message.'</pre>';
7190
+			}
6086 7191
 			$headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '',$preserveHTML) : '');
6087 7192
 			$message = $headdata.$message;
6088 7193
 			//echo __METHOD__.'<br>';
@@ -6133,7 +7238,8 @@  discard block
 block discarded – undo
6133 7238
 							$attachments[$num]['attachment'] = $c->getContents();
6134 7239
 						}
6135 7240
 						// no attempt to convert, if we dont know about the charset
6136
-						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset'])) {
7241
+						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset']))
7242
+						{
6137 7243
 							// we do not try guessing the charset, if it is not set
6138 7244
 							//if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = Translation::detect_encoding($attachments[$num]['attachment']);
6139 7245
 							Translation::convert($attachments[$num]['attachment'],$attachments[$num]['charset']);
@@ -6154,7 +7260,10 @@  discard block
 block discarded – undo
6154 7260
 						unset($attachments[$num]['attachment']);
6155 7261
 					}
6156 7262
 				}
6157
-				if (is_array($attachedMessages)) $attachments = array_merge($attachments,$attachedMessages);
7263
+				if (is_array($attachedMessages))
7264
+				{
7265
+					$attachments = array_merge($attachments,$attachedMessages);
7266
+				}
6158 7267
 			}
6159 7268
 			return array(
6160 7269
 					'mailaddress'=>$mailaddress,
@@ -6176,10 +7285,17 @@  discard block
 block discarded – undo
6176 7285
 	{
6177 7286
 		$c = 0;
6178 7287
 		// use the standardIdentity
6179
-		foreach($_identities as $key => $acc) {
6180
-			if ($c==0) $identity = $acc;
7288
+		foreach($_identities as $key => $acc)
7289
+		{
7290
+			if ($c==0)
7291
+			{
7292
+				$identity = $acc;
7293
+			}
6181 7294
 			//error_log(__METHOD__.__LINE__." $key == $_profile_id ");
6182
-			if ($key==$_profile_id) $identity = $acc;
7295
+			if ($key==$_profile_id)
7296
+			{
7297
+				$identity = $acc;
7298
+			}
6183 7299
 			$c++;
6184 7300
 		}
6185 7301
 		return $identity;
@@ -6195,20 +7311,53 @@  discard block
 block discarded – undo
6195 7311
 	{
6196 7312
 		$headdata = null;
6197 7313
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($header).function_backtrace());
6198
-		if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
6199
-		if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
6200
-		if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
6201
-		if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
6202
-		if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
6203
-		if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
6204
-		if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
6205
-		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
6206
-		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
7314
+		if ($header['SUBJECT'])
7315
+		{
7316
+			$headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
7317
+		}
7318
+		if ($header['FROM'])
7319
+		{
7320
+			$headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
7321
+		}
7322
+		if ($header['SENDER'])
7323
+		{
7324
+			$headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
7325
+		}
7326
+		if ($header['TO'])
7327
+		{
7328
+			$headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
7329
+		}
7330
+		if ($header['CC'])
7331
+		{
7332
+			$headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
7333
+		}
7334
+		if ($header['BCC'])
7335
+		{
7336
+			$headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
7337
+		}
7338
+		if ($header['DATE'])
7339
+		{
7340
+			$headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
7341
+		}
7342
+		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal')
7343
+		{
7344
+			$headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
7345
+		}
7346
+		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal')
7347
+		{
7348
+			$headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
7349
+		}
6207 7350
 		//if ($mailcontent['headers']['ORGANIZATION']) $headdata .= lang('organization').': '.$mailcontent['headers']['ORGANIZATION']."\
6208 7351
 		if (!empty($headdata))
6209 7352
 		{
6210
-			if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
6211
-			if (empty($headline)) $headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
7353
+			if (!empty($headline) && $headline != 'SUPPRESS')
7354
+			{
7355
+				$headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
7356
+			}
7357
+			if (empty($headline))
7358
+			{
7359
+				$headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
7360
+			}
6212 7361
 			$headdata .= ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'');
6213 7362
 		}
6214 7363
 		else
@@ -6242,12 +7391,15 @@  discard block
 block discarded – undo
6242 7391
 		$returnAddr ='';
6243 7392
 		if (is_array($rfcAddressArray))
6244 7393
 		{
6245
-			foreach((array)$rfcAddressArray as $addressData) {
7394
+			foreach((array)$rfcAddressArray as $addressData)
7395
+			{
6246 7396
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressData));
6247
-				if($addressData['MAILBOX_NAME'] == 'NIL') {
7397
+				if($addressData['MAILBOX_NAME'] == 'NIL')
7398
+				{
6248 7399
 					continue;
6249 7400
 				}
6250
-				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') {
7401
+				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients')
7402
+				{
6251 7403
 					continue;
6252 7404
 				}
6253 7405
 				if ($addressData['RFC822_EMAIL'])
@@ -6261,7 +7413,10 @@  discard block
 block discarded – undo
6261 7413
 				}
6262 7414
 				$addressObject = $addressObjectA[0];
6263 7415
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressObject));
6264
-				if (!$addressObject->valid) continue;
7416
+				if (!$addressObject->valid)
7417
+				{
7418
+					continue;
7419
+				}
6265 7420
 				//$mb =(string)$addressObject->mailbox;
6266 7421
 				//$h = (string)$addressObject->host;
6267 7422
 				//$p = (string)$addressObject->personal;
@@ -6278,7 +7433,10 @@  discard block
 block discarded – undo
6278 7433
 			// do not mess with strings, return them untouched /* ToDo: validate string as Address */
6279 7434
 			$rfcAddressArray = self::decode_header($rfcAddressArray,true);
6280 7435
 			$rfcAddressArray = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$rfcAddressArray);
6281
-			if (is_string($rfcAddressArray)) return $rfcAddressArray;
7436
+			if (is_string($rfcAddressArray))
7437
+			{
7438
+				return $rfcAddressArray;
7439
+			}
6282 7440
 		}
6283 7441
 		return $returnAddr;
6284 7442
 	}
@@ -6295,10 +7453,19 @@  discard block
 block discarded – undo
6295 7453
 	{
6296 7454
 		$mergeobj = new Contacts\Merge();
6297 7455
 
6298
-		if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
7456
+		if (empty($mimetype))
7457
+		{
7458
+			$mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
7459
+		}
6299 7460
 		$rv = $mergeobj->merge_string($content,$ids,$err='',$mimetype, array(), self::$displayCharset);
6300
-		if (empty($rv) && !empty($content) && !empty($err)) $rv = $content;
6301
-		if (!empty($err) && !empty($content) && !empty($ids)) error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
7461
+		if (empty($rv) && !empty($content) && !empty($err))
7462
+		{
7463
+			$rv = $content;
7464
+		}
7465
+		if (!empty($err) && !empty($content) && !empty($ids))
7466
+		{
7467
+			error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
7468
+		}
6302 7469
 		return $rv;
6303 7470
 	}
6304 7471
 
@@ -6335,13 +7502,15 @@  discard block
 block discarded – undo
6335 7502
 			settype($bytes, 'integer');
6336 7503
 			$bytes /= 10;
6337 7504
 		}
6338
-		else
6339
-			settype($bytes, 'integer');
7505
+		else {
7506
+					settype($bytes, 'integer');
7507
+		}
6340 7508
 
6341 7509
 		return $bytes . ' ' . $type ;
6342 7510
 	}
6343 7511
 
6344
-	static function detect_qp(&$sting) {
7512
+	static function detect_qp(&$sting)
7513
+	{
6345 7514
 		$needle = '/(=[0-9][A-F])|(=[A-F][0-9])|(=[A-F][A-F])|(=[0-9][0-9])/';
6346 7515
 		return preg_match("$needle",$string);
6347 7516
 	}
@@ -6358,9 +7527,15 @@  discard block
 block discarded – undo
6358 7527
 	 */
6359 7528
 	static function logRunTimes($_starttime,$_endtime=null,$_message='',$_methodNline='')
6360 7529
 	{
6361
-		if (is_null($_endtime)) $_endtime = microtime(true);
7530
+		if (is_null($_endtime))
7531
+		{
7532
+			$_endtime = microtime(true);
7533
+		}
6362 7534
 		$usagetime = microtime(true) - $_starttime;
6363
-		if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
7535
+		if (self::$debugTimes)
7536
+		{
7537
+			error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
7538
+		}
6364 7539
 	}
6365 7540
 
6366 7541
 	/**
@@ -6375,7 +7550,10 @@  discard block
 block discarded – undo
6375 7550
 	 */
6376 7551
 	static function checkFileBasics(&$_formData, $IDtoAddToFileName='', $reqMimeType='message/rfc822')
6377 7552
 	{
6378
-		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data') return $_formData['file'];
7553
+		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data')
7554
+		{
7555
+			return $_formData['file'];
7556
+		}
6379 7557
 
6380 7558
 		//error_log(__METHOD__.__FILE__.array2string($_formData).' Id:'.$IDtoAddToFileName.' ReqMimeType:'.$reqMimeType);
6381 7559
 		$importfailed = $tmpFileName = false;
@@ -6424,8 +7602,15 @@  discard block
 block discarded – undo
6424 7602
 			{
6425 7603
 				$buff = explode('.',$_formData['name']);
6426 7604
 				$suffix = '';
6427
-				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
6428
-				if (!empty($suffix)) $sfxMimeType = MimeMagic::ext2mime($suffix);
7605
+				if (is_array($buff))
7606
+				{
7607
+					$suffix = array_pop($buff);
7608
+				}
7609
+				// take the last extension to check with ext2mime
7610
+				if (!empty($suffix))
7611
+				{
7612
+					$sfxMimeType = MimeMagic::ext2mime($suffix);
7613
+				}
6429 7614
 				if (!empty($suffix) && !empty($sfxMimeType) &&
6430 7615
 					(strlen(trim($_formData['type']))==0 || (strtolower(trim($_formData['type'])) != $sfxMimeType)))
6431 7616
 				{
@@ -6473,7 +7658,9 @@  discard block
 block discarded – undo
6473 7658
 			{
6474 7659
 				rename($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmpFileName);
6475 7660
 			}
6476
-		} else {
7661
+		}
7662
+		else
7663
+		{
6477 7664
 			//error_log("Import of message ".$_formData['file']." failes to meet basic restrictions");
6478 7665
 			$importfailed = true;
6479 7666
 			$alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.",$_formData['name']);
@@ -6519,21 +7706,32 @@  discard block
 block discarded – undo
6519 7706
 				if (substr($url, 0, 5) !== 'data:')
6520 7707
 				{
6521 7708
 					$filename = basename($url);
6522
-					if (($directory = dirname($url)) == '.') $directory = '';
7709
+					if (($directory = dirname($url)) == '.')
7710
+					{
7711
+						$directory = '';
7712
+					}
6523 7713
 					$ext = pathinfo($filename, PATHINFO_EXTENSION);
6524 7714
 					$mimeType  = MimeMagic::ext2mime($ext);
6525
-					if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
7715
+					if ( strlen($directory) > 1 && substr($directory,-1) != '/')
7716
+					{
7717
+$directory .= '/'; }
6526 7718
 					$myUrl = $directory.$filename;
6527
-					if ($myUrl[0]=='/') // local path -> we only allow path's that are available via http/https (or vfs)
7719
+					if ($myUrl[0]=='/')
7720
+					{
7721
+						// local path -> we only allow path's that are available via http/https (or vfs)
6528 7722
 					{
6529 7723
 						$basedir = ($_SERVER['HTTPS']?'https://':'http://'.$_SERVER['HTTP_HOST']);
6530 7724
 					}
7725
+					}
6531 7726
 					// use vfs instead of url containing webdav.php
6532 7727
 					// ToDo: we should test if the webdav url is of our own scope, as we cannot handle foreign
6533 7728
 					// webdav.php urls as vfs
6534
-					if (strpos($myUrl,'/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it.
7729
+					if (strpos($myUrl,'/webdav.php') !== false)
7730
+					{
7731
+						// we have a webdav link, so we build a vfs/sqlfs link of it.
6535 7732
 					{
6536 7733
 						Vfs::load_wrapper('vfs');
7734
+					}
6537 7735
 						list(,$myUrl) = explode('/webdav.php',$myUrl,2);
6538 7736
 						$basedir = 'vfs://default';
6539 7737
 						$needTempFile = false;
@@ -6562,8 +7760,13 @@  discard block
 block discarded – undo
6562 7760
 						}
6563 7761
 					}
6564 7762
 
6565
-					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/') { $basedir .= '/'; }
6566
-					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl));
7763
+					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/')
7764
+					{
7765
+$basedir .= '/'; }
7766
+					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http")
7767
+					{
7768
+						$data = file_get_contents($basedir.urldecode($myUrl));
7769
+					}
6567 7770
 				}
6568 7771
 				if (substr($url,0,strlen('data:'))=='data:')
6569 7772
 				{
@@ -6664,7 +7867,10 @@  discard block
 block discarded – undo
6664 7867
 				$_folder = $this->getSentFolder();
6665 7868
 			}
6666 7869
 			$delimiter = $this->getHierarchyDelimiter();
6667
-			if($_folder=='INBOX'.$delimiter) $_folder='INBOX';
7870
+			if($_folder=='INBOX'.$delimiter)
7871
+			{
7872
+				$_folder='INBOX';
7873
+			}
6668 7874
 			if ($importfailed === false)
6669 7875
 			{
6670 7876
 				$Subject = $mailObject->getHeader('Subject');
@@ -6693,7 +7899,9 @@  discard block
 block discarded – undo
6693 7899
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Id To Merge:'.$val);
6694 7900
 					if (/*$GLOBALS['egw_info']['flags']['currentapp'] == 'addressbook' &&*/
6695 7901
 						count($SendAndMergeTocontacts) > 1 && $val &&
6696
-						(is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))) // do the merge
7902
+						(is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)))
7903
+					{
7904
+						// do the merge
6697 7905
 					{
6698 7906
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6699 7907
 
@@ -6702,6 +7910,7 @@  discard block
 block discarded – undo
6702 7910
 						{
6703 7911
 							//error_log('ID ' . $val . ' ' .$type . ': ' . $mailObject->getHeader(Mailer::$type2header[$type]) . ' -> ' .$bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset));
6704 7912
 							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset);
7913
+					}
6705 7914
 							$mailObject->addAddress($merged,'',$type);
6706 7915
 							if($type == 'to')
6707 7916
 							{
@@ -6733,9 +7942,15 @@  discard block
 block discarded – undo
6733 7942
 						$mailObject->clearCustomHeaders();
6734 7943
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6735 7944
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6736
-						if($text_body) $text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7945
+						if($text_body)
7946
+						{
7947
+							$text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7948
+						}
6737 7949
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6738
-						if($html_body) $html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7950
+						if($html_body)
7951
+						{
7952
+							$html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7953
+						}
6739 7954
 
6740 7955
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6741 7956
 						// set a higher timeout for big messages
@@ -6750,9 +7965,12 @@  discard block
 block discarded – undo
6750 7965
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($errorInfo));
6751 7966
 						}
6752 7967
 					}
6753
-					elseif (!$k)	// 1. entry, further entries will fail for apps other then addressbook
7968
+					elseif (!$k)
7969
+					{
7970
+						// 1. entry, further entries will fail for apps other then addressbook
6754 7971
 					{
6755 7972
 						$openAsDraft = true;
7973
+					}
6756 7974
 						$mailObject->removeHeader('Message-ID');
6757 7975
 						$mailObject->removeHeader('Date');
6758 7976
 						$mailObject->clearCustomHeaders();
@@ -6767,9 +7985,12 @@  discard block
 block discarded – undo
6767 7985
 
6768 7986
 						// No addresses from placeholders?  Treat it as just a contact ID
6769 7987
 						if (count($mailObject->getAddresses('to',true)) == 0 &&
6770
-							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)) // do the merge
7988
+							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))
7989
+						{
7990
+							// do the merge
6771 7991
 						{
6772 7992
 							$contact = $bo_merge->contacts->read($val);
7993
+						}
6773 7994
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($contact));
6774 7995
 							$email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
6775 7996
 							$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
@@ -6780,9 +8001,15 @@  discard block
 block discarded – undo
6780 8001
 						}
6781 8002
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6782 8003
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6783
-						if (!empty($Body)) $text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
8004
+						if (!empty($Body))
8005
+						{
8006
+							$text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
8007
+						}
6784 8008
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6785
-						if (!empty($AltBody)) $html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
8009
+						if (!empty($AltBody))
8010
+						{
8011
+							$html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
8012
+						}
6786 8013
 						$_folder = $this->getDraftFolder();
6787 8014
 					}
6788 8015
 					if ($sendOK || $openAsDraft)
@@ -6790,11 +8017,15 @@  discard block
 block discarded – undo
6790 8017
 						if ($this->folderExists($_folder,true))
6791 8018
 						{
6792 8019
 						    if($this->isSentFolder($_folder))
6793
-							{
8020
+						    {
6794 8021
 						        $flags = '\\Seen';
6795
-						    } elseif($this->isDraftFolder($_folder)) {
8022
+						    }
8023
+						    elseif($this->isDraftFolder($_folder))
8024
+						    {
6796 8025
 						        $flags = '\\Draft';
6797
-						    } else {
8026
+						    }
8027
+						    else
8028
+						    {
6798 8029
 						        $flags = '';
6799 8030
 						    }
6800 8031
 							$savefailed = false;
@@ -6828,7 +8059,10 @@  discard block
 block discarded – undo
6828 8059
 						}
6829 8060
 						else
6830 8061
 						{
6831
-							if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
8062
+							if (!$openComposeWindow)
8063
+							{
8064
+								$processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
8065
+							}
6832 8066
 						}
6833 8067
 					}
6834 8068
 					if (!is_null($sendOK) && $sendOK===false && is_null($openComposeWindow))
@@ -6876,7 +8110,10 @@  discard block
 block discarded – undo
6876 8110
 				$tmpFileName = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($tmpFileName);
6877 8111
 				break;
6878 8112
 		}
6879
-		if (!isset($message)) $message = fopen($tmpFileName, 'r');
8113
+		if (!isset($message))
8114
+		{
8115
+			$message = fopen($tmpFileName, 'r');
8116
+		}
6880 8117
 
6881 8118
 		if (!$message)
6882 8119
 		{
@@ -6907,7 +8144,10 @@  discard block
 block discarded – undo
6907 8144
 				(fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192));
6908 8145
 
6909 8146
 			$length = strpos($start, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
6910
-			if ($length===false) $length = strlen($start);
8147
+			if ($length===false)
8148
+			{
8149
+				$length = strlen($start);
8150
+			}
6911 8151
 			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0,$length));
6912 8152
 
6913 8153
 			foreach($headers->toArray(array('nowrap' => true)) as $header => $value)
@@ -6936,7 +8176,10 @@  discard block
 block discarded – undo
6936 8176
 		}
6937 8177
 		else
6938 8178
 		{
6939
-			if (($type = gettype($message)) == 'object') $type = get_class ($message);
8179
+			if (($type = gettype($message)) == 'object')
8180
+			{
8181
+				$type = get_class ($message);
8182
+			}
6940 8183
 			throw new Exception\WrongParameter('Wrong parameter type for message: '.$type);
6941 8184
 		}
6942 8185
 	}
@@ -6960,7 +8203,9 @@  discard block
 block discarded – undo
6960 8203
 			$matches = array();
6961 8204
 			preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/",$addresses,$matches);
6962 8205
 			//error_log(__METHOD__.__LINE__.array2string($matches));
6963
-			foreach ($matches[0] as &$match) {$match = trim($match,', ');}
8206
+			foreach ($matches[0] as &$match)
8207
+			{
8208
+$match = trim($match,', ');}
6964 8209
 			$addresses = implode(',',$matches[0]);
6965 8210
 			//error_log(__METHOD__.__LINE__.array2string($addresses));
6966 8211
 			$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
@@ -6991,7 +8236,10 @@  discard block
 block discarded – undo
6991 8236
 			}
6992 8237
 			else
6993 8238
 			{
6994
-				if ($previousFailed && $remember) $adr->personal = $remember. ' ' . $adr->personal;
8239
+				if ($previousFailed && $remember)
8240
+				{
8241
+					$adr->personal = $remember. ' ' . $adr->personal;
8242
+				}
6995 8243
 				$remember = '';
6996 8244
 				$previousFailed=false;
6997 8245
 				//error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal");
@@ -7013,7 +8261,10 @@  discard block
 block discarded – undo
7013 8261
 	{
7014 8262
 		$acc = Mail\Account::read($this->profileID);
7015 8263
 		$identity = Mail\Account::read_identity($acc['ident_id'], true, null, $acc);
7016
-		if (self::$debug) error_log(__METHOD__.__LINE__.array2string($identity));
8264
+		if (self::$debug)
8265
+		{
8266
+			error_log(__METHOD__.__LINE__.array2string($identity));
8267
+		}
7017 8268
 		$headers = $this->getMessageHeader($uid, '', 'object', true, $_folder);
7018 8269
 
7019 8270
 		$mdn = new Horde_Mime_Mdn($headers);
Please login to merge, or discard this patch.