Completed
Push — master ( 28e3c7...8a6126 )
by Klaus
47:43 queued 26:30
created
api/src/Mail.php 1 patch
Braces   +1775 added lines, -524 removed lines patch added patch discarded remove patch
@@ -198,7 +198,10 @@  discard block
 block discarded – undo
198 198
 	public static function getInstance($_restoreSession=true, &$_profileID=0, $_validate=true, $_oldImapServerObject=false, $_reuseCache=null)
199 199
 	{
200 200
 		//$_restoreSession=false;
201
-		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
201
+		if (is_null($_reuseCache))
202
+		{
203
+			$_reuseCache = $_restoreSession;
204
+		}
202 205
 		//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());
203 206
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_oldImapServerObject));
204 207
 		if ($_oldImapServerObject instanceof Mail\Imap)
@@ -224,9 +227,15 @@  discard block
 block discarded – undo
224 227
 			{
225 228
 				$profileID = Mail\Account::get_default_acc_id();
226 229
 			}
227
-			if ($profileID!=$_profileID) $_restoreSession==false;
230
+			if ($profileID!=$_profileID)
231
+			{
232
+				$_restoreSession==false;
233
+			}
228 234
 			$_profileID=$profileID;
229
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace());
235
+			if (self::$debug)
236
+			{
237
+				error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace());
238
+			}
230 239
 		}
231 240
 		// no validation or restoreSession for old ImapServer Object, just fetch it and return it
232 241
 		if ($_oldImapServerObject===true)
@@ -265,7 +274,8 @@  discard block
 block discarded – undo
265 274
 				// TODO: merge mailprefs into userprefs, for easy treatment
266 275
 				self::$instances[$_profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
267 276
 				self::$instances[$_profileID]->htmlOptions  = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
268
-			} catch (\Exception $e)
277
+			}
278
+			catch (\Exception $e)
269 279
 			{
270 280
 				$newprofileID = Mail\Account::get_default_acc_id();
271 281
 				// try loading the default profile for the user
@@ -283,9 +293,15 @@  discard block
 block discarded – undo
283 293
 			self::storeActiveProfileIDToPref(self::$instances[$_profileID]->icServer, $_profileID, $_validate );
284 294
 		}
285 295
 		self::$instances[$_profileID]->profileID = $_profileID;
286
-		if (!isset(self::$instances[$_profileID]->idna2)) self::$instances[$_profileID]->idna2 = new Horde_Idna;
296
+		if (!isset(self::$instances[$_profileID]->idna2))
297
+		{
298
+			self::$instances[$_profileID]->idna2 = new Horde_Idna;
299
+		}
287 300
 		//if ($_profileID==0); error_log(__METHOD__.' ('.__LINE__.') '.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID);
288
-		if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
301
+		if (is_null(self::$mailConfig))
302
+		{
303
+			self::$mailConfig = Config::read('mail');
304
+		}
289 305
 		return self::$instances[$_profileID];
290 306
 	}
291 307
 
@@ -310,14 +326,20 @@  discard block
 block discarded – undo
310 326
 			}
311 327
 			catch (\Exception $e)
312 328
 			{
313
-				if ($_profileID != Mail\Account::get_default_acc_id()) $_profileID = Mail\Account::get_default_acc_id();
329
+				if ($_profileID != Mail\Account::get_default_acc_id())
330
+				{
331
+					$_profileID = Mail\Account::get_default_acc_id();
332
+				}
314 333
 				error_log(__METHOD__.__LINE__.' '.$e->getMessage());
315 334
 				return false;
316 335
 			}
317 336
 		}
318 337
 		if ($oldProfileID != $_profileID)
319 338
 		{
320
-			if ($oldProfileID && $_profileID==0) $_profileID = $oldProfileID;
339
+			if ($oldProfileID && $_profileID==0)
340
+			{
341
+				$_profileID = $oldProfileID;
342
+			}
321 343
 			$GLOBALS['egw']->preferences->add('mail','ActiveProfileID',$_profileID,'user');
322 344
 			// save prefs
323 345
 			$GLOBALS['egw']->preferences->save_repository(true);
@@ -347,11 +369,17 @@  discard block
 block discarded – undo
347 369
 				{
348 370
 					return $_acc_id;
349 371
 				}
350
-				if (self::$debug) error_log(__METHOD__."($_acc_id) account NOT valid, no imap-host!");
372
+				if (self::$debug)
373
+				{
374
+					error_log(__METHOD__."($_acc_id) account NOT valid, no imap-host!");
375
+				}
351 376
 			}
352 377
 			catch (\Exception $e) {
353 378
 				unset($e);
354
-				if (self::$debug) error_log(__METHOD__."($_acc_id) account NOT found!");
379
+				if (self::$debug)
380
+				{
381
+					error_log(__METHOD__."($_acc_id) account NOT found!");
382
+				}
355 383
 			}
356 384
 		}
357 385
 		// no account specified or specified account not found or not valid
@@ -360,11 +388,17 @@  discard block
 block discarded – undo
360 388
 		{
361 389
 			if (!empty($imap_host) && ($account = Mail\Account::read($acc_id)) && $account->is_imap())
362 390
 			{
363
-				if (self::$debug && $_acc_id) error_log(__METHOD__."($_acc_id) using $acc_id instead");
391
+				if (self::$debug && $_acc_id)
392
+				{
393
+					error_log(__METHOD__."($_acc_id) using $acc_id instead");
394
+				}
364 395
 				return $acc_id;
365 396
 			}
366 397
 		}
367
-		if (self::$debug) error_log(__METHOD__."($_acc_id) NO valid account found!");
398
+		if (self::$debug)
399
+		{
400
+			error_log(__METHOD__."($_acc_id) NO valid account found!");
401
+		}
368 402
 		return 0;
369 403
 	}
370 404
 
@@ -380,10 +414,19 @@  discard block
 block discarded – undo
380 414
 	 */
381 415
 	private function __construct($_displayCharset='utf-8',$_restoreSession=true, $_profileID=0, $_oldImapServerObject=false, $_reuseCache=null)
382 416
 	{
383
-		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
384
-		if (!empty($_displayCharset)) self::$displayCharset = $_displayCharset;
417
+		if (is_null($_reuseCache))
418
+		{
419
+			$_reuseCache = $_restoreSession;
420
+		}
421
+		if (!empty($_displayCharset))
422
+		{
423
+			self::$displayCharset = $_displayCharset;
424
+		}
385 425
 		// not nummeric, we assume we only want an empty class object
386
-		if (!is_numeric($_profileID)) return true;
426
+		if (!is_numeric($_profileID))
427
+		{
428
+			return true;
429
+		}
387 430
 		if ($_restoreSession)
388 431
 		{
389 432
 			//error_log(__METHOD__." Session restore ".function_backtrace());
@@ -398,7 +441,10 @@  discard block
 block discarded – undo
398 441
 			$firstMessage = $this->sessionData['previewMessage'];
399 442
 			$this->sessionData = array();
400 443
 		}
401
-		if (!$_reuseCache) $this->forcePrefReload($_profileID,!$_reuseCache);
444
+		if (!$_reuseCache)
445
+		{
446
+			$this->forcePrefReload($_profileID,!$_reuseCache);
447
+		}
402 448
 		try
403 449
 		{
404 450
 			$this->profileID = self::validateProfileID($_profileID);
@@ -422,7 +468,10 @@  discard block
 block discarded – undo
422 468
 			$_profileID = $this->profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $this->icServer->ImapServerId;
423 469
 		}
424 470
 
425
-		if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
471
+		if (is_null(self::$mailConfig))
472
+		{
473
+			self::$mailConfig = Config::read('mail');
474
+		}
426 475
 	}
427 476
 
428 477
 	/**
@@ -451,7 +500,10 @@  discard block
 block discarded – undo
451 500
 		// unset the mail_preferences session object, to force the reload/rebuild
452 501
 		Cache::setSession('mail','mail_preferences',serialize(array()));
453 502
 		Cache::setSession('emailadmin','session_data',serialize(array()));
454
-		if ($_resetFolderObjects) self::resetFolderObjectCache($_profile_id);
503
+		if ($_resetFolderObjects)
504
+		{
505
+			self::resetFolderObjectCache($_profile_id);
506
+		}
455 507
 	}
456 508
 
457 509
 	/**
@@ -461,7 +513,10 @@  discard block
 block discarded – undo
461 513
 	{
462 514
 		$this->sessionData = array();//Cache::getCache(Cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1);
463 515
 		self::$activeFolderCache = Cache::getCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
464
-		if (!empty(self::$activeFolderCache[$this->profileID])) $this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID];
516
+		if (!empty(self::$activeFolderCache[$this->profileID]))
517
+		{
518
+			$this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID];
519
+		}
465 520
 	}
466 521
 
467 522
 	/**
@@ -470,7 +525,10 @@  discard block
 block discarded – undo
470 525
 	function saveSessionData()
471 526
 	{
472 527
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($this->sessionData)));
473
-		if (!empty($this->sessionData['mailbox'])) self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox'];
528
+		if (!empty($this->sessionData['mailbox']))
529
+		{
530
+			self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox'];
531
+		}
474 532
 		if (isset(self::$activeFolderCache) && is_array(self::$activeFolderCache))
475 533
 		{
476 534
 			Cache::setCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),self::$activeFolderCache, 60*60*10);
@@ -491,8 +549,14 @@  discard block
 block discarded – undo
491 549
 	 */
492 550
 	static function unsetCachedObjects($_profileID=null)
493 551
 	{
494
-		if (is_null($_profileID)) $_profileID = Mail\Account::get_default_acc_id();
495
-		if (is_array($_profileID) && $_profileID['account_id']) $account_id = $_profileID['account_id'];
552
+		if (is_null($_profileID))
553
+		{
554
+			$_profileID = Mail\Account::get_default_acc_id();
555
+		}
556
+		if (is_array($_profileID) && $_profileID['account_id'])
557
+		{
558
+			$account_id = $_profileID['account_id'];
559
+		}
496 560
 		//error_log(__METHOD__.__LINE__.' called with ProfileID:'.array2string($_profileID).' from '.function_backtrace());
497 561
 		if (!is_array($_profileID) && (is_numeric($_profileID) || !(stripos($_profileID,'tracker_')===false)))
498 562
 		{
@@ -525,7 +589,10 @@  discard block
 block discarded – undo
525 589
 				Cache::setCache(Cache::INSTANCE,'email','vacationNotice'.trim($account_id),$vacationCached, $expiration=60*60*24*1);
526 590
 			}
527 591
 
528
-			if (isset(self::$instances[$_profileID])) unset(self::$instances[$_profileID]);
592
+			if (isset(self::$instances[$_profileID]))
593
+			{
594
+				unset(self::$instances[$_profileID]);
595
+			}
529 596
 		}
530 597
 		if (is_array($_profileID) && $_profileID['location'] == 'clear_cache')
531 598
 		{
@@ -554,7 +621,10 @@  discard block
 block discarded – undo
554 621
 	static function resetConnectionErrorCache($_ImapServerId=null,$account_id=null)
555 622
 	{
556 623
 		//error_log(__METHOD__.' ('.__LINE__.') '.' for Profile:'.array2string($_ImapServerId) .' for user:'.trim($account_id));
557
-		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
624
+		if (is_null($account_id))
625
+		{
626
+			$account_id = $GLOBALS['egw_info']['user']['account_id'];
627
+		}
558 628
 		if (is_array($_ImapServerId))
559 629
 		{
560 630
 			// called via hook
@@ -593,7 +663,10 @@  discard block
 block discarded – undo
593 663
 	static function resetFolderObjectCache($_ImapServerId=null,$account_id=null)
594 664
 	{
595 665
 		//error_log(__METHOD__.' ('.__LINE__.') '.' called for Profile:'.array2string($_ImapServerId).'->'.function_backtrace());
596
-		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
666
+		if (is_null($account_id))
667
+		{
668
+			$account_id = $GLOBALS['egw_info']['user']['account_id'];
669
+		}
597 670
 		// on [location] => verify_settings we coud either use [prefs] => Array([ActiveProfileID] => 9, .. as $_ImapServerId
598 671
 		// or treat it as not given. we try that path
599 672
 		if (is_null($_ImapServerId)||is_array($_ImapServerId))
@@ -667,10 +740,14 @@  discard block
 block discarded – undo
667 740
 
668 741
 		$userEMailAdresses = array($acc['ident_email']=>$acc['ident_realname']);
669 742
 
670
-		foreach($identities as $ik => $ident) {
743
+		foreach($identities as $ik => $ident)
744
+		{
671 745
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
672 746
 			$identity = Mail\Account::read_identity($ik);
673
-			if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']])) $userEMailAdresses[$identity['ident_email']] = $identity['ident_realname'];
747
+			if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']]))
748
+			{
749
+				$userEMailAdresses[$identity['ident_email']] = $identity['ident_realname'];
750
+			}
674 751
 		}
675 752
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses));
676 753
 		return $userEMailAdresses;
@@ -688,13 +765,20 @@  discard block
 block discarded – undo
688 765
 		foreach(Mail\Account::search($only_current_user=($_accountToSearch?$_accountToSearch:true), $just_name=true) as $acc_id => $identity_name)
689 766
 		{
690 767
 			$acc = Mail\Account::read($acc_id,($_accountToSearch?$_accountToSearch:null));
691
-			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']);
768
+			if (!$resolve_placeholders)
769
+			{
770
+				$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']);
771
+			}
692 772
 
693
-			foreach(Mail\Account::identities($acc) as $ik => $ident) {
773
+			foreach(Mail\Account::identities($acc) as $ik => $ident)
774
+			{
694 775
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
695 776
 				$identity = Mail\Account::read_identity($ik,$resolve_placeholders);
696 777
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
697
-				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']);
778
+				if (!isset($userEMailAdresses[$identity['ident_id']]))
779
+				{
780
+					$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']);
781
+				}
698 782
 			}
699 783
 		}
700 784
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses));
@@ -714,12 +798,16 @@  discard block
 block discarded – undo
714 798
 			$account = Mail\Account::read($account);
715 799
 		}
716 800
 		$userEMailAdresses = array();
717
-		foreach(Mail\Account::identities($account, true, 'params') as $ik => $ident) {
801
+		foreach(Mail\Account::identities($account, true, 'params') as $ik => $ident)
802
+		{
718 803
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
719 804
 			$identity = Mail\Account::read_identity($ik,true,null,$account);
720 805
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
721 806
 			// standardIdentity has ident_id==acc_id (as it is done within account->identities)
722
-			if (empty($identity['ident_id'])) $identity['ident_id'] = $identity['acc_id'];
807
+			if (empty($identity['ident_id']))
808
+			{
809
+				$identity['ident_id'] = $identity['acc_id'];
810
+			}
723 811
 			if (!isset($userEMailAdresses[$identity['ident_id']]))
724 812
 			{
725 813
 				$userEMailAdresses[$identity['ident_id']] = array('acc_id'=>$identity['acc_id'],
@@ -762,15 +850,25 @@  discard block
 block discarded – undo
762 850
 		// account select box
763 851
 		$selectedID = $this->profileID;
764 852
 		$allAccountData = Mail\Account::search($only_current_user=true, false, null);
765
-		if ($allAccountData) {
853
+		if ($allAccountData)
854
+		{
766 855
 			$rememberFirst=$selectedFound=null;
767 856
 			foreach ($allAccountData as $tmpkey => $icServers)
768 857
 			{
769
-				if (is_null($rememberFirst)) $rememberFirst = $tmpkey;
770
-				if ($tmpkey == $selectedID) $selectedFound=true;
858
+				if (is_null($rememberFirst))
859
+				{
860
+					$rememberFirst = $tmpkey;
861
+				}
862
+				if ($tmpkey == $selectedID)
863
+				{
864
+					$selectedFound=true;
865
+				}
771 866
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($icServers->acc_imap_host));
772 867
 				$host = $icServers->acc_imap_host;
773
-				if (empty($host)) continue;
868
+				if (empty($host))
869
+				{
870
+					continue;
871
+				}
774 872
 				$identities[$icServers->acc_id] = $icServers['ident_realname'].' '.$icServers['ident_org'].' <'.$icServers['ident_email'].'>';
775 873
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($identities[$icServers->acc_id]));
776 874
 			}
@@ -830,7 +928,10 @@  discard block
 block discarded – undo
830 928
 	 */
831 929
 	function reopen($_foldername)
832 930
 	{
833
-		if (self::$debugTimes) $starttime = microtime (true);
931
+		if (self::$debugTimes)
932
+		{
933
+			$starttime = microtime (true);
934
+		}
834 935
 
835 936
 		//error_log(__METHOD__.' ('.__LINE__.') '."('$_foldername') ".function_backtrace());
836 937
 		// TODO: trying to reduce traffic to the IMAP Server here, introduces problems with fetching the bodies of
@@ -840,12 +941,16 @@  discard block
 block discarded – undo
840 941
 		//{
841 942
 			//error_log( __METHOD__.' ('.__LINE__.') '." $_foldername ".function_backtrace());
842 943
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Connected with icServer for Profile:'.$this->profileID.'?'.print_r($this->icServer->_connected,true));
843
-			if ($this->folderIsSelectable($_foldername)) {
944
+			if ($this->folderIsSelectable($_foldername))
945
+			{
844 946
 				$this->icServer->openMailbox($_foldername);
845 947
 			}
846 948
 			$folderOpened = $_foldername;
847 949
 		//}
848
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') ');
950
+		if (self::$debugTimes)
951
+		{
952
+			self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') ');
953
+		}
849 954
 	}
850 955
 
851 956
 
@@ -860,13 +965,22 @@  discard block
 block discarded – undo
860 965
 	{
861 966
 		//error_log( "-------------------------->open connection ".function_backtrace());
862 967
 		//error_log(__METHOD__.' ('.__LINE__.') '.' ->'.array2string($this->icServer));
863
-		if (self::$debugTimes) $starttime = microtime (true);
968
+		if (self::$debugTimes)
969
+		{
970
+			$starttime = microtime (true);
971
+		}
864 972
 		$mailbox=null;
865 973
 		try
866 974
 		{
867
-			if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox'])) $mailbox = $this->sessionData['mailbox'];
868
-			if (empty($mailbox)) $mailbox = $this->icServer->getCurrentMailbox();
869
-/*
975
+			if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox']))
976
+			{
977
+				$mailbox = $this->sessionData['mailbox'];
978
+			}
979
+			if (empty($mailbox))
980
+			{
981
+				$mailbox = $this->icServer->getCurrentMailbox();
982
+			}
983
+			/*
870 984
 			if (isset(Mail\Imap::$supports_keywords[$_icServerID]))
871 985
 			{
872 986
 				$this->icServer->openMailbox($mailbox);
@@ -891,7 +1005,10 @@  discard block
 block discarded – undo
891 1005
 			error_log(__METHOD__.' ('.__LINE__.') '."->open connection for Server with profileID:".$_icServerID." trying to examine ($mailbox) failed!".$e->getMessage());
892 1006
 			throw new Exception(__METHOD__." failed to ".__METHOD__." on Profile to $_icServerID while trying to examine $mailbox:".$e->getMessage());
893 1007
 		}
894
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') ');
1008
+		if (self::$debugTimes)
1009
+		{
1010
+			self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') ');
1011
+		}
895 1012
 	}
896 1013
 
897 1014
 	/**
@@ -903,20 +1020,27 @@  discard block
 block discarded – undo
903 1020
 	function getQuotaRoot()
904 1021
 	{
905 1022
 		static $quota;
906
-		if (isset($quota)) return $quota;
1023
+		if (isset($quota))
1024
+		{
1025
+			return $quota;
1026
+		}
907 1027
 		$this->icServer->getCurrentMailbox();
908
-		if(!$this->icServer->hasCapability('QUOTA')) {
1028
+		if(!$this->icServer->hasCapability('QUOTA'))
1029
+		{
909 1030
 			$quota = false;
910 1031
 			return false;
911 1032
 		}
912 1033
 		$quota = $this->icServer->getStorageQuotaRoot('INBOX');
913 1034
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($quota));
914
-		if(is_array($quota)) {
1035
+		if(is_array($quota))
1036
+		{
915 1037
 			$quota = array(
916 1038
 				'usage'	=> $quota['USED'],
917 1039
 				'limit'	=> $quota['QMAX'],
918 1040
 			);
919
-		} else {
1041
+		}
1042
+		else
1043
+		{
920 1044
 			$quota = false;
921 1045
 		}
922 1046
 		return $quota;
@@ -932,7 +1056,11 @@  discard block
 block discarded – undo
932 1056
 	static function getTimeOut($_use='IMAP')
933 1057
 	{
934 1058
 		$timeout = $GLOBALS['egw_info']['user']['preferences']['mail']['connectionTimeout'];
935
-		if (empty($timeout)) $timeout = ($_use=='SIEVE'?10:20); // this is the default value
1059
+		if (empty($timeout))
1060
+		{
1061
+			$timeout = ($_use=='SIEVE'?10:20);
1062
+		}
1063
+		// this is the default value
936 1064
 		return $timeout;
937 1065
 	}
938 1066
 
@@ -950,9 +1078,13 @@  discard block
 block discarded – undo
950 1078
 		$foldersNameSpace = array();
951 1079
 		$delimiter = $this->getHierarchyDelimiter();
952 1080
 		// TODO: cache by $this->icServer->ImapServerId
953
-		if (is_null($nameSpace)) $nameSpace = $this->icServer->getNameSpaceArray();
1081
+		if (is_null($nameSpace))
1082
+		{
1083
+			$nameSpace = $this->icServer->getNameSpaceArray();
1084
+		}
954 1085
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($nameSpace));
955
-		if (is_array($nameSpace)) {
1086
+		if (is_array($nameSpace))
1087
+		{
956 1088
 			foreach($nameSpace as $type => $singleNameSpaceArray)
957 1089
 			{
958 1090
 				foreach ($singleNameSpaceArray as $singleNameSpace)
@@ -969,7 +1101,9 @@  discard block
 block discarded – undo
969 1101
 						$_foldersNameSpace['prefix_present'] = 'forced';
970 1102
 						// uw-imap server with mailbox prefix or dovecot maybe
971 1103
 						$_foldersNameSpace['prefix'] = 'mail';
972
-					} else {
1104
+					}
1105
+					else
1106
+					{
973 1107
 						$_foldersNameSpace['prefix_present'] = !empty($singleNameSpace['name']);
974 1108
 						$_foldersNameSpace['prefix'] = $singleNameSpace['name'];
975 1109
 					}
@@ -996,7 +1130,10 @@  discard block
 block discarded – undo
996 1130
 		foreach($nameSpace as &$singleNameSpace)
997 1131
 		{
998 1132
 			//if (substr($singleNameSpace['prefix'],0,strlen($folderName))==$folderName) return $singleNameSpace['prefix'];
999
-			if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix']) return $singleNameSpace['prefix'];
1133
+			if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix'])
1134
+			{
1135
+				return $singleNameSpace['prefix'];
1136
+			}
1000 1137
 		}
1001 1138
 		return "";
1002 1139
 	}
@@ -1010,8 +1147,14 @@  discard block
 block discarded – undo
1010 1147
 	function getHierarchyDelimiter($_useCache=true)
1011 1148
 	{
1012 1149
 		static $HierarchyDelimiter = null;
1013
-		if (is_null($HierarchyDelimiter)) $HierarchyDelimiter = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1014
-		if ($_useCache===false) unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1150
+		if (is_null($HierarchyDelimiter))
1151
+		{
1152
+			$HierarchyDelimiter = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1153
+		}
1154
+		if ($_useCache===false)
1155
+		{
1156
+			unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1157
+		}
1015 1158
 		if (isset($HierarchyDelimiter[$this->icServer->ImapServerId])&&!empty($HierarchyDelimiter[$this->icServer->ImapServerId]))
1016 1159
 		{
1017 1160
 			return $HierarchyDelimiter[$this->icServer->ImapServerId];
@@ -1040,14 +1183,19 @@  discard block
 block discarded – undo
1040 1183
 	{
1041 1184
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$this->icServer->ImapServerId.' Connected:'.$this->icServer->_connected);
1042 1185
 		static $_specialUseFolders = null;
1043
-		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);
1186
+		if (is_null($_specialUseFolders)||empty($_specialUseFolders))
1187
+		{
1188
+			$_specialUseFolders = Cache::getCache(Cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1189
+		}
1044 1190
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_trash));
1045 1191
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_sent));
1046 1192
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_draft));
1047 1193
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_template));
1048 1194
 		self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId];
1049 1195
 		if (isset($_specialUseFolders[$this->icServer->ImapServerId]) && !empty($_specialUseFolders[$this->icServer->ImapServerId]))
1050
-			return $_specialUseFolders[$this->icServer->ImapServerId];
1196
+		{
1197
+					return $_specialUseFolders[$this->icServer->ImapServerId];
1198
+		}
1051 1199
 		$_specialUseFolders[$this->icServer->ImapServerId]=array();
1052 1200
 		//if (!empty($this->icServer->acc_folder_trash) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]))
1053 1201
 			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]='Trash';
@@ -1075,7 +1223,8 @@  discard block
 block discarded – undo
1075 1223
 	function folderIsSelectable($folderToSelect)
1076 1224
 	{
1077 1225
 		$retval = true;
1078
-		if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true))) {
1226
+		if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true)))
1227
+		{
1079 1228
 			if (!empty($folderStatus['attributes']) && stripos(array2string($folderStatus['attributes']),'noselect')!==false)
1080 1229
 			{
1081 1230
 				$retval = false;
@@ -1128,18 +1277,27 @@  discard block
 block discarded – undo
1128 1277
 	 */
1129 1278
 	function getFolderStatus($_folderName,$ignoreStatusCache=false,$basicInfoOnly=false,$fetchSubscribedInfo=true)
1130 1279
 	{
1131
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly");
1132
-		if (!is_string($_folderName) || empty($_folderName)) // something is wrong. Do not proceed
1280
+		if (self::$debug)
1281
+		{
1282
+			error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly");
1283
+		}
1284
+		if (!is_string($_folderName) || empty($_folderName))
1285
+		{
1286
+			// something is wrong. Do not proceed
1133 1287
 		{
1134 1288
 			return false;
1135 1289
 		}
1290
+		}
1136 1291
 		static $folderInfoCache = null; // reduce traffic on single request
1137 1292
 		static $folderBasicInfo = null;
1138 1293
 		if (isset($folderBasicInfo[$this->profileID]))
1139 1294
 		{
1140 1295
 			$folderInfoCache = $folderBasicInfo[$this->profileID];
1141 1296
 		}
1142
-		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly) return $folderInfoCache[$_folderName];
1297
+		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly)
1298
+		{
1299
+			return $folderInfoCache[$_folderName];
1300
+		}
1143 1301
 		$retValue = array();
1144 1302
 		$retValue['subscribed'] = false;
1145 1303
 /*
@@ -1157,7 +1315,10 @@  discard block
 block discarded – undo
1157 1315
 			if (is_array($ret))
1158 1316
 			{
1159 1317
 				$retkeys = array_keys($ret);
1160
-				if ($retkeys[0]==$_folderName) $folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1318
+				if ($retkeys[0]==$_folderName)
1319
+				{
1320
+					$folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1321
+				}
1161 1322
 			}
1162 1323
 			else
1163 1324
 			{
@@ -1166,7 +1327,8 @@  discard block
 block discarded – undo
1166 1327
 		}
1167 1328
 		$folderInfo = $folderInfoCache[$_folderName];
1168 1329
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($folderInfo).'->'.function_backtrace());
1169
-		if($ignoreStatusCache||!$folderInfo|| !is_array($folderInfo)) {
1330
+		if($ignoreStatusCache||!$folderInfo|| !is_array($folderInfo))
1331
+		{
1170 1332
 			try
1171 1333
 			{
1172 1334
 				$folderInfo = $this->_getStatus($_folderName,$ignoreStatusCache);
@@ -1196,7 +1358,8 @@  discard block
 block discarded – undo
1196 1358
 		$retValue['shortName']		= array_pop($shortNameParts);
1197 1359
 		$retValue['displayName']	= $_folderName;
1198 1360
 		$retValue['shortDisplayName']	= $retValue['shortName'];
1199
-		if(strtoupper($retValue['shortName']) == 'INBOX') {
1361
+		if(strtoupper($retValue['shortName']) == 'INBOX')
1362
+		{
1200 1363
 			$retValue['displayName']	= lang('INBOX');
1201 1364
 			$retValue['shortDisplayName']	= lang('INBOX');
1202 1365
 		}
@@ -1205,7 +1368,10 @@  discard block
 block discarded – undo
1205 1368
 		{
1206 1369
 			$retValue['displayName'] = $retValue['shortDisplayName'] = lang($retValue['shortName']);
1207 1370
 		}
1208
-		if ($folderInfo) $folderBasicInfo[$this->profileID][$_folderName]=$retValue;
1371
+		if ($folderInfo)
1372
+		{
1373
+			$folderBasicInfo[$this->profileID][$_folderName]=$retValue;
1374
+		}
1209 1375
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.$_folderName.array2string($retValue['attributes']));
1210 1376
 		if ($basicInfoOnly || (isset($retValue['attributes']) && stripos(array2string($retValue['attributes']),'noselect')!==false))
1211 1377
 		{
@@ -1217,24 +1383,34 @@  discard block
 block discarded – undo
1217 1383
 		static $subscribedFolders = null;
1218 1384
 		static $nameSpace = null;
1219 1385
 		static $prefix = null;
1220
-		if (is_null($nameSpace) || empty($nameSpace[$this->profileID])) $nameSpace[$this->profileID] = $this->_getNameSpaces();
1386
+		if (is_null($nameSpace) || empty($nameSpace[$this->profileID]))
1387
+		{
1388
+			$nameSpace[$this->profileID] = $this->_getNameSpaces();
1389
+		}
1221 1390
 		if (!empty($nameSpace[$this->profileID]))
1222 1391
 		{
1223 1392
 			$nsNoPersonal=array();
1224 1393
 			foreach($nameSpace[$this->profileID] as &$ns)
1225 1394
 			{
1226
-				if ($ns['type']!='personal') $nsNoPersonal[]=$ns;
1395
+				if ($ns['type']!='personal')
1396
+				{
1397
+					$nsNoPersonal[]=$ns;
1398
+				}
1227 1399
 			}
1228 1400
 			$nameSpace[$this->profileID]=$nsNoPersonal;
1229 1401
 		}
1230
-		if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName])) $prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName);
1402
+		if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName]))
1403
+		{
1404
+			$prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName);
1405
+		}
1231 1406
 
1232 1407
 		if ($fetchSubscribedInfo && is_null($subscribedFolders) || empty($subscribedFolders[$this->profileID]))
1233 1408
 		{
1234 1409
 			$subscribedFolders[$this->profileID] = $this->icServer->listSubscribedMailboxes();
1235 1410
 		}
1236 1411
 
1237
-		if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID])) {
1412
+		if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID]))
1413
+		{
1238 1414
 			$retValue['subscribed'] = true;
1239 1415
 		}
1240 1416
 
@@ -1253,8 +1429,7 @@  discard block
 block discarded – undo
1253 1429
 				(isset($this->mailPreferences['trustServersUnseenInfo']) &&
1254 1430
 				$this->mailPreferences['trustServersUnseenInfo']==2 &&
1255 1431
 				$prefix[$this->profileID][$_folderName] != '' && stripos($_folderName,$prefix[$this->profileID][$_folderName]) !== false)
1256
-			)
1257
-			{
1432
+			) {
1258 1433
 				//error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($prefix,true).' TS:'.$this->mailPreferences['trustServersUnseenInfo']);
1259 1434
 				// we filter for the combined status of unseen and undeleted, as this is what we show in list
1260 1435
 				try
@@ -1264,13 +1439,19 @@  discard block
 block discarded – undo
1264 1439
 				}
1265 1440
 				catch (\Exception $ee)
1266 1441
 				{
1267
-					if (self::$debug) error_log(__METHOD__." could not fetch/calculate unseen counter for $_folderName Reason:'".$ee->getMessage()."' but requested.");
1442
+					if (self::$debug)
1443
+					{
1444
+						error_log(__METHOD__." could not fetch/calculate unseen counter for $_folderName Reason:'".$ee->getMessage()."' but requested.");
1445
+					}
1268 1446
 				}
1269 1447
 			}
1270 1448
 		}
1271 1449
 		catch (\Exception $e)
1272 1450
 		{
1273
-			if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1451
+			if (self::$debug)
1452
+			{
1453
+				error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1454
+			}
1274 1455
 		}
1275 1456
 
1276 1457
 		return $retValue;
@@ -1295,8 +1476,14 @@  discard block
 block discarded – undo
1295 1476
 	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true, $_fetchPreviews=false)
1296 1477
 	{
1297 1478
 		//self::$debug=true;
1298
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
1299
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName,$_startMessage, $_numberOfMessages, $_sort, $_reverse, ".array2string($_filter).", $_thisUIDOnly");
1479
+		if (self::$debug)
1480
+		{
1481
+			error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
1482
+		}
1483
+		if (self::$debug)
1484
+		{
1485
+			error_log(__METHOD__.' ('.__LINE__.') '."$_folderName,$_startMessage, $_numberOfMessages, $_sort, $_reverse, ".array2string($_filter).", $_thisUIDOnly");
1486
+		}
1300 1487
 		$reverse = (bool)$_reverse;
1301 1488
 		// get the list of messages to fetch
1302 1489
 		$this->reopen($_folderName);
@@ -1317,21 +1504,34 @@  discard block
 block discarded – undo
1317 1504
 				//$_filter['range'] ="$start:$end";
1318 1505
 				//$_filter['range'] ="$_startMessage:*";
1319 1506
 			}
1320
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1321
-			if (self::$debug||self::$debugTimes) $starttime = microtime (true);
1507
+			if (self::$debug)
1508
+			{
1509
+				error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1510
+			}
1511
+			if (self::$debug||self::$debugTimes)
1512
+			{
1513
+				$starttime = microtime (true);
1514
+			}
1322 1515
 			//see this example below for a 12 week datefilter (since)
1323 1516
 			//$_filter = array('status'=>array('UNDELETED'),'type'=>"SINCE",'string'=> date("d-M-Y", $starttime-(3600*24*7*12)));
1324 1517
 			$_sortResult = $this->getSortedList($_folderName, $_sort, $reverse, $_filter, $rByUid, $_cacheResult);
1325 1518
 			$sortResult = $_sortResult['match']->ids;
1326 1519
 			//$modseq = $_sortResult['modseq'];
1327 1520
 			//error_log(__METHOD__.' ('.__LINE__.') '.'Modsequence:'.$modseq);
1328
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1521
+			if (self::$debug||self::$debugTimes)
1522
+			{
1523
+				self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1524
+			}
1329 1525
 
1330
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1526
+			if (self::$debug)
1527
+			{
1528
+				error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1529
+			}
1331 1530
 			#$this->icServer->setDebug(false);
1332 1531
 			#print "</pre>";
1333 1532
 			// nothing found
1334
-			if(!is_array($sortResult) || empty($sortResult)) {
1533
+			if(!is_array($sortResult) || empty($sortResult))
1534
+			{
1335 1535
 				$retValue = array();
1336 1536
 				$retValue['info']['total']	= 0;
1337 1537
 				$retValue['info']['first']	= 0;
@@ -1343,7 +1543,8 @@  discard block
 block discarded – undo
1343 1543
 			#_debug_array($sortResult);
1344 1544
 			#_debug_array(array_slice($sortResult, -5, -2));
1345 1545
 			//error_log("REVERSE: $reverse");
1346
-			if($reverse === true) {
1546
+			if($reverse === true)
1547
+			{
1347 1548
 				if  ($_startMessage<=$total)
1348 1549
 				{
1349 1550
 					$startMessage = $_startMessage-1;
@@ -1355,7 +1556,10 @@  discard block
 block discarded – undo
1355 1556
 					{
1356 1557
 						$numberOfMessages = $total%$_numberOfMessages;
1357 1558
 						//$numberOfMessages = abs($_startMessage-$total-1);
1358
-						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages) $_numberOfMessages = $numberOfMessages;
1559
+						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages)
1560
+						{
1561
+							$_numberOfMessages = $numberOfMessages;
1562
+						}
1359 1563
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total);
1360 1564
 					}
1361 1565
 					$startMessage=($total-$_numberOfMessages)-1;
@@ -1369,19 +1573,36 @@  discard block
 block discarded – undo
1369 1573
 					//$retValue['info']['first'] = $startMessage;
1370 1574
 					//$retValue['info']['last'] = $total;
1371 1575
 				}
1372
-				if($startMessage > 0) {
1373
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1576
+				if($startMessage > 0)
1577
+				{
1578
+					if (self::$debug)
1579
+					{
1580
+						error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1581
+					}
1374 1582
 					$sortResult = array_slice($sortResult, -($_numberOfMessages+$startMessage), -$startMessage);
1375
-				} else {
1376
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1583
+				}
1584
+				else
1585
+				{
1586
+					if (self::$debug)
1587
+					{
1588
+						error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1589
+					}
1377 1590
 					$sortResult = array_slice($sortResult, -($_numberOfMessages+($_startMessage-1)));
1378 1591
 				}
1379 1592
 				$sortResult = array_reverse($sortResult);
1380
-			} else {
1381
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1593
+			}
1594
+			else
1595
+			{
1596
+				if (self::$debug)
1597
+				{
1598
+					error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1599
+				}
1382 1600
 				$sortResult = array_slice($sortResult, $_startMessage-1, $_numberOfMessages);
1383 1601
 			}
1384
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1602
+			if (self::$debug)
1603
+			{
1604
+				error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1605
+			}
1385 1606
 		}
1386 1607
 		else
1387 1608
 		{
@@ -1390,7 +1611,10 @@  discard block
 block discarded – undo
1390 1611
 
1391 1612
 
1392 1613
 		// fetch the data for the selected messages
1393
-		if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1614
+		if (self::$debug||self::$debugTimes)
1615
+		{
1616
+			$starttime = microtime(true);
1617
+		}
1394 1618
 		try
1395 1619
 		{
1396 1620
 			$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -1414,7 +1638,10 @@  discard block
 block discarded – undo
1414 1638
 			$fquery->flags();
1415 1639
 			$fquery->imapDate();// needed to ensure getImapDate fetches the internaldate, not the current time
1416 1640
 			// if $_fetchPreviews is activated fetch part of the messages too
1417
-			if ($_fetchPreviews) $fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0));
1641
+			if ($_fetchPreviews)
1642
+			{
1643
+				$fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0));
1644
+			}
1418 1645
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
1419 1646
 				'ids' => $uidsToFetch,
1420 1647
 			));
@@ -1437,14 +1664,20 @@  discard block
 block discarded – undo
1437 1664
 
1438 1665
 		$cnt = 0;
1439 1666
 
1440
-		foreach((array)$sortResult as $uid) {
1667
+		foreach((array)$sortResult as $uid)
1668
+		{
1441 1669
 			$sortOrder[$uid] = $cnt++;
1442 1670
 		}
1443 1671
 
1444 1672
 		$count = 0;
1445
-		if (is_object($headersNew)) {
1446
-			if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1447
-			foreach($headersNew->ids() as $id) {
1673
+		if (is_object($headersNew))
1674
+		{
1675
+			if (self::$debug||self::$debugTimes)
1676
+			{
1677
+				$starttime = microtime(true);
1678
+			}
1679
+			foreach($headersNew->ids() as $id)
1680
+			{
1448 1681
 				$_headerObject = $headersNew->get($id);
1449 1682
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject));
1450 1683
 				$headerObject = array();
@@ -1457,7 +1690,10 @@  discard block
 block discarded – undo
1457 1690
 				// Get already cached headers, 'fetchHeaders' is a label matchimg above
1458 1691
 				$headerForPrio = $_headerObject->getHeaders('fetchHeaders',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1459 1692
 				// Try to fetch header with key='' as some servers might have no fetchHeaders index. e.g. yandex.com
1460
-				if (empty($headerForPrio)) $headerForPrio = $_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1693
+				if (empty($headerForPrio))
1694
+				{
1695
+					$headerForPrio = $_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1696
+				}
1461 1697
 				//fetch the fullMsg part if all conditions match to be available in case $_headerObject->getHeaders returns
1462 1698
 				//nothing worthwhile (as it does for googlemail accounts, when preview is switched on
1463 1699
 				if ($_fetchPreviews)
@@ -1468,12 +1704,16 @@  discard block
 block discarded – undo
1468 1704
 					if (empty($headerForPrio)||(is_array($headerForPrio)&&count($headerForPrio)===1&&$headerForPrio['']))
1469 1705
 					{
1470 1706
 						$length = strpos($bodyPreview, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
1471
-						if ($length===false) $length = strlen($bodyPreview);
1707
+						if ($length===false)
1708
+						{
1709
+							$length = strlen($bodyPreview);
1710
+						}
1472 1711
 						$headerForPrio =  Horde_Mime_Headers::parseHeaders(substr($bodyPreview, 0,$length))->toArray();
1473 1712
 					}
1474 1713
 				}
1475 1714
 				$headerForPrio = array_change_key_case($headerForPrio, CASE_UPPER);
1476
-				if (self::$debug) {
1715
+				if (self::$debug)
1716
+				{
1477 1717
 					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'));
1478 1718
 					error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerForPrio));
1479 1719
 				}
@@ -1483,11 +1723,16 @@  discard block
 block discarded – undo
1483 1723
 					$total--;
1484 1724
 					continue;
1485 1725
 				}
1486
-				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) ) {
1726
+				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) )
1727
+				{
1487 1728
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['DISPOSITION-NOTIFICATION-TO']));
1488
-				} else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) ) {
1729
+				}
1730
+				else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) )
1731
+				{
1489 1732
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['RETURN-RECEIPT-TO']));
1490
-				} else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) ) {
1733
+				}
1734
+				else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) )
1735
+				{
1491 1736
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['X-CONFIRM-READING-TO']));
1492 1737
 				} /*else $sent_not = "";*/
1493 1738
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
@@ -1518,7 +1763,11 @@  discard block
 block discarded – undo
1518 1763
 						$rfcAddr = self::parseAddressList($ad); // does some fixing of known problems too
1519 1764
 						foreach ($rfcAddr as $_rfcAddr)
1520 1765
 						{
1521
-							if (!$_rfcAddr->valid)	continue; // skip. not a valid address
1766
+							if (!$_rfcAddr->valid)
1767
+							{
1768
+								continue;
1769
+							}
1770
+							// skip. not a valid address
1522 1771
 							$address[] = imap_rfc822_write_address($_rfcAddr->mailbox,$_rfcAddr->host,$_rfcAddr->personal);
1523 1772
 						}
1524 1773
 					}
@@ -1534,7 +1783,10 @@  discard block
 block discarded – undo
1534 1783
 				{
1535 1784
 					// $bodyPreview is populated at the beginning of the loop, as it may be
1536 1785
 					// needed to parse the Headers of the Message
1537
-					if (empty($bodyPreview)) $bodyPreview = $_headerObject->getFullMsg();
1786
+					if (empty($bodyPreview))
1787
+					{
1788
+						$bodyPreview = $_headerObject->getFullMsg();
1789
+					}
1538 1790
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($bodyPreview));
1539 1791
 					$base = Horde_Mime_Part::parseMessage($bodyPreview);
1540 1792
 					foreach($base->partIterator() as $part)
@@ -1547,7 +1799,8 @@  discard block
 block discarded – undo
1547 1799
 												'encode' => Horde_Mime_Part::ENCODE_BINARY,	// otherwise we cant recode charset
1548 1800
 											)), $charset, 'utf-8');
1549 1801
 							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Translation::convert_jsonsafe($buffer),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
1550
-						} elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart')
1802
+						}
1803
+						elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart')
1551 1804
 						{
1552 1805
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part));
1553 1806
 						}
@@ -1563,7 +1816,10 @@  discard block
 block discarded – undo
1563 1816
 				$messageMimeType='';
1564 1817
 				foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
1565 1818
 				{
1566
-					if ($mime_id==0 || $messageMimeType==='') $messageMimeType = $mime_type;
1819
+					if ($mime_id==0 || $messageMimeType==='')
1820
+					{
1821
+						$messageMimeType = $mime_type;
1822
+					}
1567 1823
 					$part = $mailStructureObject->getPart($mime_id);
1568 1824
 					$partdisposition = $part->getDisposition();
1569 1825
 					$partPrimaryType = $part->getPrimaryType();
@@ -1573,7 +1829,8 @@  discard block
 block discarded – undo
1573 1829
 					// bodypreview could be found (multipart/....)
1574 1830
 					if ($_fetchPreviews && empty($headerObject['BODYPREVIEW'])&&($partPrimaryType == 'text') &&
1575 1831
 						((intval($mime_id) === 1) || !$mime_id) &&
1576
-						($partdisposition !== 'attachment')) {
1832
+						($partdisposition !== 'attachment'))
1833
+					{
1577 1834
 							$_structure=$part;
1578 1835
 							$this->fetchPartContents($uid, $_structure, false,true);
1579 1836
 							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
@@ -1595,10 +1852,19 @@  discard block
 block discarded – undo
1595 1852
 					if ($mime_type=='message/rfc822')
1596 1853
 					{
1597 1854
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
1598
-						foreach($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
1855
+						foreach($part->contentTypeMap() as $sub_id => $sub_type)
1856
+						{
1857
+if ($sub_id != $mime_id)
1858
+						{
1859
+							$skipParts[$sub_id] = $sub_type;
1860
+						}
1861
+						}
1599 1862
 					}
1600 1863
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType.' Skip:'.array2string($skipParts));
1601
-					if (array_key_exists($mime_id,$skipParts)) continue;
1864
+					if (array_key_exists($mime_id,$skipParts))
1865
+					{
1866
+						continue;
1867
+					}
1602 1868
 					if ($partdisposition=='attachment' ||
1603 1869
 						($partdisposition=='inline'&&$partPrimaryType == 'image'&&$mime_type=='image/tiff') || // as we are not able to display tiffs
1604 1870
 						($partdisposition=='inline'&&$partPrimaryType == 'image'&&empty($cid)) ||
@@ -1609,7 +1875,10 @@  discard block
 block discarded – undo
1609 1875
 						$headerObject['ATTACHMENTS'][$mime_id]['uid']=$uid;
1610 1876
 						$headerObject['ATTACHMENTS'][$mime_id]['cid'] = $cid;
1611 1877
 						$headerObject['ATTACHMENTS'][$mime_id]['partID']=$mime_id;
1612
-						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1878
+						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))
1879
+						{
1880
+							$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1881
+						}
1613 1882
 						if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'],'winmail.dat') ||
1614 1883
 							$headerObject['ATTACHMENTS'][$mime_id]['mimeType']=='application/ms-tnef')
1615 1884
 						{
@@ -1623,18 +1892,27 @@  discard block
 block discarded – undo
1623 1892
 				//error_log(__METHOD__.' ('.__LINE__.') '.' FindBody (plain):'.array2string($mailStructureObject->findBody('plain')));
1624 1893
 				//error_log(__METHOD__.' ('.__LINE__.') '.' FindBody (html):'.array2string($mailStructureObject->findBody('html')));
1625 1894
 				//if($count == 0) error_log(__METHOD__.array2string($headerObject));
1626
-				if (empty($headerObject['UID'])) continue;
1895
+				if (empty($headerObject['UID']))
1896
+				{
1897
+					continue;
1898
+				}
1627 1899
 				//$uid = ($rByUid ? $headerObject['UID'] : $headerObject['MSG_NUM']);
1628 1900
 				// make dates like "Mon, 23 Apr 2007 10:11:06 UT" working with strtotime
1629
-				if(substr($headerObject['DATE'],-2) === 'UT') {
1901
+				if(substr($headerObject['DATE'],-2) === 'UT')
1902
+				{
1630 1903
 					$headerObject['DATE'] .= 'C';
1631 1904
 				}
1632
-				if(substr($headerObject['INTERNALDATE'],-2) === 'UT') {
1905
+				if(substr($headerObject['INTERNALDATE'],-2) === 'UT')
1906
+				{
1633 1907
 					$headerObject['INTERNALDATE'] .= 'C';
1634 1908
 				}
1635 1909
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$headerObject['SUBJECT'].'->'.$headerObject['DATE'].'<->'.$headerObject['INTERNALDATE'] .'#');
1636 1910
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$this->decode_subject($headerObject['SUBJECT']).'->'.$headerObject['DATE']);
1637
-				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;}
1911
+				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS']))
1912
+				{
1913
+					foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;
1914
+				}
1915
+				}
1638 1916
 				$retValue['header'][$sortOrder[$uid]]['subject']	= $this->decode_subject($headerObject['SUBJECT']);
1639 1917
 				$retValue['header'][$sortOrder[$uid]]['size'] 		= $headerObject['SIZE'];
1640 1918
 				$retValue['header'][$sortOrder[$uid]]['date']		= self::_strtotime(($headerObject['DATE']&&!($headerObject['DATE']=='NIL')?$headerObject['DATE']:$headerObject['INTERNALDATE']),'ts',true);
@@ -1645,22 +1923,31 @@  discard block
 block discarded – undo
1645 1923
 				$retValue['header'][$sortOrder[$uid]]['bodypreview']		= $headerObject['BODYPREVIEW'];
1646 1924
 				$retValue['header'][$sortOrder[$uid]]['priority']		= ($headerObject['PRIORITY']?$headerObject['PRIORITY']:3);
1647 1925
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.array2string($retValue['header'][$sortOrder[$uid]]));
1648
-				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO'])) $retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1649
-				if (is_array($headerObject['FLAGS'])) {
1926
+				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO']))
1927
+				{
1928
+					$retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1929
+				}
1930
+				if (is_array($headerObject['FLAGS']))
1931
+				{
1650 1932
 					$retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]],self::prepareFlagsArray($headerObject));
1651 1933
 				}
1652 1934
 				//error_log(__METHOD__.' ('.__LINE__.') '.$headerObject['SUBJECT'].'->'.array2string($_headerObject->getEnvelope()->__get('from')));
1653
-				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0]) {
1935
+				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0])
1936
+				{
1654 1937
 					$retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0],true);
1655 1938
 				}
1656
-				if(is_array($headerObject['TO']) && $headerObject['TO'][0]) {
1939
+				if(is_array($headerObject['TO']) && $headerObject['TO'][0])
1940
+				{
1657 1941
 					$retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0],true);
1658 1942
 					if (count($headerObject['TO'])>1)
1659 1943
 					{
1660 1944
 						$ki=0;
1661 1945
 						foreach($headerObject['TO'] as $k => $add)
1662 1946
 						{
1663
-							if ($k==0) continue;
1947
+							if ($k==0)
1948
+							{
1949
+								continue;
1950
+							}
1664 1951
 							//error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add));
1665 1952
 							$retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add,true);
1666 1953
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki]));
@@ -1668,7 +1955,8 @@  discard block
 block discarded – undo
1668 1955
 						}
1669 1956
 					}
1670 1957
 				}
1671
-				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0) {
1958
+				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0)
1959
+				{
1672 1960
 					$ki=0;
1673 1961
 					foreach($headerObject['CC'] as $k => $add)
1674 1962
 					{
@@ -1682,27 +1970,41 @@  discard block
 block discarded – undo
1682 1970
 
1683 1971
 				$count++;
1684 1972
 			}
1685
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
1973
+			if (self::$debug||self::$debugTimes)
1974
+			{
1975
+				self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
1976
+			}
1686 1977
 			//self::$debug=false;
1687 1978
 			// sort the messages to the requested displayorder
1688
-			if(is_array($retValue['header'])) {
1979
+			if(is_array($retValue['header']))
1980
+			{
1689 1981
 				$countMessages = $total;
1690
-				if (isset($_filter['range'])) $countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
1982
+				if (isset($_filter['range']))
1983
+				{
1984
+					$countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
1985
+				}
1691 1986
 				ksort($retValue['header']);
1692 1987
 				$retValue['info']['total']	= $total;
1693 1988
 				//if ($_startMessage>$total) $_startMessage = $total-($count-1);
1694 1989
 				$retValue['info']['first']	= $_startMessage;
1695 1990
 				$retValue['info']['last']	= $_startMessage + $count - 1 ;
1696 1991
 				return $retValue;
1697
-			} else {
1992
+			}
1993
+			else
1994
+			{
1698 1995
 				$retValue = array();
1699 1996
 				$retValue['info']['total']	= 0;
1700 1997
 				$retValue['info']['first']	= 0;
1701 1998
 				$retValue['info']['last']	= 0;
1702 1999
 				return $retValue;
1703 2000
 			}
1704
-		} else {
1705
-			if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
2001
+		}
2002
+		else
2003
+		{
2004
+			if ($headersNew == null && empty($_thisUIDOnly))
2005
+			{
2006
+				error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
2007
+			}
1706 2008
 			$retValue = array();
1707 2009
 			$retValue['info']['total']  = 0;
1708 2010
 			$retValue['info']['first']  = 0;
@@ -1719,7 +2021,10 @@  discard block
 block discarded – undo
1719 2021
 	 */
1720 2022
 	static function prepareFlagsArray($headerObject)
1721 2023
 	{
1722
-		if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower',$headerObject['FLAGS']);
2024
+		if (is_array($headerObject['FLAGS']))
2025
+		{
2026
+			$headerFlags = array_map('strtolower',$headerObject['FLAGS']);
2027
+		}
1723 2028
 		$retValue = array();
1724 2029
 		$retValue['recent']		= in_array('\\recent', $headerFlags);
1725 2030
 		$retValue['flagged']	= in_array('\\flagged', $headerFlags);
@@ -1770,24 +2075,43 @@  discard block
 block discarded – undo
1770 2075
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Filter:'.array2string($_filter));
1771 2076
 		$try2useCache = true;
1772 2077
 		static $eMailListContainsDeletedMessages = null;
1773
-		if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2078
+		if (is_null($eMailListContainsDeletedMessages))
2079
+		{
2080
+			$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2081
+		}
1774 2082
 		// this indicates, that there is no Filter set, and the returned set/subset should not contain DELETED Messages, nor filtered for UNDELETED
1775 2083
 		if ($setSession==true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
1776 2084
 		{
1777
-			if (self::$debugTimes) $starttime = microtime(true);
1778
-			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);
2085
+			if (self::$debugTimes)
2086
+			{
2087
+				$starttime = microtime(true);
2088
+			}
2089
+			if (is_null($eMailListContainsDeletedMessages) || empty($eMailListContainsDeletedMessages[$this->profileID]) || empty($eMailListContainsDeletedMessages[$this->profileID][$_folderName]))
2090
+			{
2091
+				$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2092
+			}
1779 2093
 			$deletedMessages = $this->getSortedList($_folderName, 0, $three=1, array('status'=>array('DELETED')),$five=true,false);
1780
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
2094
+			if (self::$debug)
2095
+			{
2096
+				error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
2097
+			}
1781 2098
 			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] =$deletedMessages['count'];
1782 2099
 			Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),$eMailListContainsDeletedMessages, 60*60*1);
1783
-			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']);
2100
+			if (self::$debugTimes)
2101
+			{
2102
+				self::logRunTimes($starttime,null,'setting eMailListContainsDeletedMessages for Profile:'.$this->profileID.' Folder:'.$_folderName.' to '.$eMailListContainsDeletedMessages[$this->profileID][$_folderName],__METHOD__.' ('.__LINE__.') ');
2103
+			}
2104
+			//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']);
1784 2105
 		}
1785 2106
 		$try2useCache = false;
1786 2107
 		//self::$supportsORinQuery[$this->profileID]=true;
1787 2108
 		if (is_null(self::$supportsORinQuery) || !isset(self::$supportsORinQuery[$this->profileID]))
1788 2109
 		{
1789 2110
 			self::$supportsORinQuery = Cache::getCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
1790
-			if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID]=true;
2111
+			if (!isset(self::$supportsORinQuery[$this->profileID]))
2112
+			{
2113
+				self::$supportsORinQuery[$this->profileID]=true;
2114
+			}
1791 2115
 		}
1792 2116
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_filter).' SupportsOrInQuery:'.self::$supportsORinQuery[$this->profileID]);
1793 2117
 		$filter = $this->createIMAPFilter($_folderName, $_filter,self::$supportsORinQuery[$this->profileID]);
@@ -1798,15 +2122,26 @@  discard block
 block discarded – undo
1798 2122
 		}
1799 2123
 		//_debug_array($filter);
1800 2124
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($filter).'#'.array2string($this->icServer->capability()));
1801
-		if($this->icServer->hasCapability('SORT')) {
2125
+		if($this->icServer->hasCapability('SORT'))
2126
+		{
1802 2127
 			// when using an orQuery and we sort by date. sort seems to fail on certain servers => ZIMBRA with Horde_Imap_Client
1803 2128
 			// thus we translate the search request from date to Horde_Imap_Client::SORT_SEQUENCE (which should be the same, if
1804 2129
 			// there is no messing with the dates)
1805 2130
 			//if (self::$supportsORinQuery[$this->profileID]&&$_sort=='date'&&$_filter['type']=='quick'&&!empty($_filter['string']))$_sort='INTERNALDATE';
1806
-			if (self::$debug) error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
2131
+			if (self::$debug)
2132
+			{
2133
+				error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
2134
+			}
1807 2135
 			$sortOrder = $this->_getSortString($_sort, $_reverse);
1808
-			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder)) $_reverse=false; // as we reversed the result already
1809
-			if (self::$debug) error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
2136
+			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder))
2137
+			{
2138
+				$_reverse=false;
2139
+			}
2140
+			// as we reversed the result already
2141
+			if (self::$debug)
2142
+			{
2143
+				error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
2144
+			}
1810 2145
 			try
1811 2146
 			{
1812 2147
 				$sortResult = $this->icServer->search($_folderName, $filter, array(
@@ -1818,7 +2153,10 @@  discard block
 block discarded – undo
1818 2153
 				//error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1819 2154
 				$resultByUid = false;
1820 2155
 				$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1821
-				if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
2156
+				if ($_reverse)
2157
+				{
2158
+					array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
2159
+				}
1822 2160
 				try
1823 2161
 				{
1824 2162
 					$sortResult = $this->icServer->search($_folderName, $filter, array(
@@ -1830,9 +2168,17 @@  discard block
 block discarded – undo
1830 2168
 					$sortResult = self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'];
1831 2169
 				}
1832 2170
 			}
1833
-			if (self::$debug) error_log(__METHOD__.print_r($sortResult,true));
1834
-		} else {
1835
-			if (self::$debug) error_log(__METHOD__." Mailserver has NO SORT Capability");
2171
+			if (self::$debug)
2172
+			{
2173
+				error_log(__METHOD__.print_r($sortResult,true));
2174
+			}
2175
+		}
2176
+		else
2177
+		{
2178
+			if (self::$debug)
2179
+			{
2180
+				error_log(__METHOD__." Mailserver has NO SORT Capability");
2181
+			}
1836 2182
 			//$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1837 2183
 			//if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
1838 2184
 			try
@@ -1846,7 +2192,10 @@  discard block
 block discarded – undo
1846 2192
 				// possible error OR Query. But Horde gives no detailed Info :-(
1847 2193
 				self::$supportsORinQuery[$this->profileID]=false;
1848 2194
 				Cache::setCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),self::$supportsORinQuery,60*60*10);
1849
-				if (self::$debug) error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
2195
+				if (self::$debug)
2196
+				{
2197
+					error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
2198
+				}
1850 2199
 				$filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]);
1851 2200
 				try
1852 2201
 				{
@@ -1857,11 +2206,15 @@  discard block
 block discarded – undo
1857 2206
 				{
1858 2207
 				}
1859 2208
 			}
1860
-			if(is_array($sortResult['match'])) {
2209
+			if(is_array($sortResult['match']))
2210
+			{
1861 2211
 					// not sure that this is going so succeed as $sortResult['match'] is a hordeObject
1862 2212
 					sort($sortResult['match'], SORT_NUMERIC);
1863 2213
 			}
1864
-			if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
2214
+			if (self::$debug)
2215
+			{
2216
+				error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
2217
+			}
1865 2218
 		}
1866 2219
 		if ($setSession)
1867 2220
 		{
@@ -1890,7 +2243,8 @@  discard block
 block discarded – undo
1890 2243
 		$_reverse=false;
1891 2244
 		if (is_numeric($_sort))
1892 2245
 		{
1893
-			switch($_sort) {
2246
+			switch($_sort)
2247
+			{
1894 2248
 				case 2:
1895 2249
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1896 2250
 					break;
@@ -1912,7 +2266,8 @@  discard block
 block discarded – undo
1912 2266
 		}
1913 2267
 		else
1914 2268
 		{
1915
-			switch(strtoupper($_sort)) {
2269
+			switch(strtoupper($_sort))
2270
+			{
1916 2271
 				case 'FROMADDRESS':
1917 2272
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1918 2273
 					break;
@@ -1938,7 +2293,10 @@  discard block
 block discarded – undo
1938 2293
 					break;
1939 2294
 			}
1940 2295
 		}
1941
-		if ($_reverse) array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
2296
+		if ($_reverse)
2297
+		{
2298
+			array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
2299
+		}
1942 2300
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.($_reverse?'REVERSE ':'').$_sort.'->'.$retValue);
1943 2301
 		return $retValue;
1944 2302
 	}
@@ -1957,7 +2315,10 @@  discard block
 block discarded – undo
1957 2315
 		$imapFilter->charset('UTF-8');
1958 2316
 
1959 2317
 		//_debug_array($_criterias);
1960
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2318
+		if (self::$debug)
2319
+		{
2320
+			error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2321
+		}
1961 2322
 		if((!is_array($_criterias) || $_criterias['status']=='any') &&
1962 2323
 			(!isset($_criterias['string']) || empty($_criterias['string'])) &&
1963 2324
 			(!isset($_criterias['range'])|| empty($_criterias['range']) ||
@@ -1972,11 +2333,13 @@  discard block
 block discarded – undo
1972 2333
 		// statusQuery MUST be placed first, as search for subject/mailbody and such is
1973 2334
 		// depending on charset. flagSearch is not BUT messes the charset if called afterwards
1974 2335
 		$statusQueryValid = false;
1975
-		foreach((array)$_criterias['status'] as $k => $criteria) {
2336
+		foreach((array)$_criterias['status'] as $k => $criteria)
2337
+		{
1976 2338
 			$imapStatusFilter = new Horde_Imap_Client_Search_Query();
1977 2339
 			$imapStatusFilter->charset('UTF-8');
1978 2340
 			$criteria = strtoupper($criteria);
1979
-			switch ($criteria) {
2341
+			switch ($criteria)
2342
+			{
1980 2343
 				case 'ANSWERED':
1981 2344
 				case 'DELETED':
1982 2345
 				case 'FLAGGED':
@@ -2059,9 +2422,11 @@  discard block
 block discarded – undo
2059 2422
 		$imapSearchFilter = new Horde_Imap_Client_Search_Query();
2060 2423
 		$imapSearchFilter->charset('UTF-8');
2061 2424
 
2062
-		if(!empty($_criterias['string'])) {
2425
+		if(!empty($_criterias['string']))
2426
+		{
2063 2427
 			$criteria = strtoupper($_criterias['type']);
2064
-			switch ($criteria) {
2428
+			switch ($criteria)
2429
+			{
2065 2430
 				case 'BYDATE':
2066 2431
 				case 'QUICK':
2067 2432
 				case 'QUICKWITHCC':
@@ -2069,9 +2434,12 @@  discard block
 block discarded – undo
2069 2434
 					//$imapSearchFilter->charset('UTF-8');
2070 2435
 					$imapFilter2 = new Horde_Imap_Client_Search_Query();
2071 2436
 					$imapFilter2->charset('UTF-8');
2072
-					if($this->isSentFolder($_folder)) {
2437
+					if($this->isSentFolder($_folder))
2438
+					{
2073 2439
 						$imapFilter2->headerText('TO', $_criterias['string'], $not=false);
2074
-					} else {
2440
+					}
2441
+					else
2442
+					{
2075 2443
 						$imapFilter2->headerText('FROM', $_criterias['string'], $not=false);
2076 2444
 					}
2077 2445
 					if ($_supportsOrInQuery)
@@ -2102,7 +2470,10 @@  discard block
 block discarded – undo
2102 2470
 											'GB'=>1024*1000*1000,'G'=>1024*1000*1000,
2103 2471
 											'TB'=>1024*1000*1000*1000,'T'=>1024*1000*1000*1000);
2104 2472
 						$numberinBytes=(float)$_criterias['string'];
2105
-						if (isset($multipleBy[$unit])) $numberinBytes=(float)$_criterias['string']*$multipleBy[$unit];
2473
+						if (isset($multipleBy[$unit]))
2474
+						{
2475
+							$numberinBytes=(float)$_criterias['string']*$multipleBy[$unit];
2476
+						}
2106 2477
 						//error_log(__METHOD__.__LINE__.'#'.$_criterias['string'].'->'.(float)$_criterias['string'].'#'.$unit.' ='.$numberinBytes);
2107 2478
 						$_criterias['string']=$numberinBytes;
2108 2479
 					}
@@ -2139,8 +2510,14 @@  discard block
 block discarded – undo
2139 2510
 					break;
2140 2511
 			}
2141 2512
 		}
2142
-		if ($statusQueryValid && !$queryValid) $queryValid=true;
2143
-		if ($queryValid) $imapFilter->andSearch($imapSearchFilter);
2513
+		if ($statusQueryValid && !$queryValid)
2514
+		{
2515
+			$queryValid=true;
2516
+		}
2517
+		if ($queryValid)
2518
+		{
2519
+			$imapFilter->andSearch($imapSearchFilter);
2520
+		}
2144 2521
 
2145 2522
 		if (isset($_criterias['range']) && !empty($_criterias['range']))
2146 2523
 		{
@@ -2155,7 +2532,8 @@  discard block
 block discarded – undo
2155 2532
 				unset($_criterias['before']);
2156 2533
 				$criteria=$_criterias['range']='ON';
2157 2534
 			}
2158
-			switch ($criteria) {
2535
+			switch ($criteria)
2536
+			{
2159 2537
 				case 'BETWEEN':
2160 2538
 					//try to be smart about missing
2161 2539
 					//enddate
@@ -2191,8 +2569,14 @@  discard block
 block discarded – undo
2191 2569
 					$rangeValid = true;
2192 2570
 					break;
2193 2571
 			}
2194
-			if ($rangeValid && !$queryValid) $queryValid=true;
2195
-			if ($rangeValid) $imapFilter->andSearch($imapRangeFilter);
2572
+			if ($rangeValid && !$queryValid)
2573
+			{
2574
+				$queryValid=true;
2575
+			}
2576
+			if ($rangeValid)
2577
+			{
2578
+				$imapFilter->andSearch($imapRangeFilter);
2579
+			}
2196 2580
 		}
2197 2581
 		if (self::$debug)
2198 2582
 		{
@@ -2200,10 +2584,13 @@  discard block
 block discarded – undo
2200 2584
 			$query_str = $imapFilter->build();
2201 2585
 			//error_log(__METHOD__.' ('.__LINE__.') '.' '.$query_str['query'].' created by Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2202 2586
 		}
2203
-		if($queryValid==false) {
2587
+		if($queryValid==false)
2588
+		{
2204 2589
 			$imapFilter->flag('DELETED', $set=false);
2205 2590
 			return $imapFilter;
2206
-		} else {
2591
+		}
2592
+		else
2593
+		{
2207 2594
 			return $imapFilter;
2208 2595
 		}
2209 2596
 	}
@@ -2260,7 +2647,10 @@  discard block
 block discarded – undo
2260 2647
 					}
2261 2648
 					$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox,Horde_Idna::decode($_rfcAddr->host),$_rfcAddr->personal);
2262 2649
 				}
2263
-				if (!empty($stringA)) $_string = implode(',',$stringA);
2650
+				if (!empty($stringA))
2651
+				{
2652
+					$_string = implode(',',$stringA);
2653
+				}
2264 2654
 			}
2265 2655
 			if ($_tryIDNConversion==='FORCE')
2266 2656
 			{
@@ -2285,7 +2675,10 @@  discard block
 block discarded – undo
2285 2675
 		{
2286 2676
 			return 'No Subject';
2287 2677
 		}
2288
-		if ($decode) $_string = self::decode_header($_string);
2678
+		if ($decode)
2679
+		{
2680
+			$_string = self::decode_header($_string);
2681
+		}
2289 2682
 		// make sure its utf-8
2290 2683
 		$test = @json_encode($_string);
2291 2684
 		if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
@@ -2323,7 +2716,8 @@  discard block
 block discarded – undo
2323 2716
 	 * @param string _parent the parent foldername
2324 2717
 	 * @return ISO-8859-1 / UTF7-IMAP encoded string
2325 2718
 	 */
2326
-	function _encodeFolderName($_folderName) {
2719
+	function _encodeFolderName($_folderName)
2720
+	{
2327 2721
 		return Translation::convert($_folderName, self::$displayCharset, 'ISO-8859-1');
2328 2722
 		#return Translation::convert($_folderName, self::$displayCharset, 'UTF7-IMAP');
2329 2723
 	}
@@ -2339,21 +2733,36 @@  discard block
 block discarded – undo
2339 2733
 	 */
2340 2734
 	function createFolder($_parent, $_folderName, &$_error)
2341 2735
 	{
2342
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2736
+		if (self::$debug)
2737
+		{
2738
+			error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2739
+		}
2343 2740
 		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2344 2741
 		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2345 2742
 
2346
-		if(empty($parent)) {
2743
+		if(empty($parent))
2744
+		{
2347 2745
 			$newFolderName = $folderName;
2348
-		} else {
2746
+		}
2747
+		else
2748
+		{
2349 2749
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2350 2750
 			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2351 2751
 		}
2352
-		if (empty($newFolderName)) return false;
2353
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2752
+		if (empty($newFolderName))
2753
+		{
2754
+			return false;
2755
+		}
2756
+		if (self::$debug)
2757
+		{
2758
+			error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2759
+		}
2354 2760
 		if ($this->folderExists($newFolderName,true))
2355 2761
 		{
2356
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2762
+			if (self::$debug)
2763
+			{
2764
+				error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2765
+			}
2357 2766
 			return $newFolderName;
2358 2767
 		}
2359 2768
 		try
@@ -2401,13 +2810,19 @@  discard block
 block discarded – undo
2401 2810
 		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2402 2811
 		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2403 2812
 
2404
-		if(empty($parent)) {
2813
+		if(empty($parent))
2814
+		{
2405 2815
 			$newFolderName = $folderName;
2406
-		} else {
2816
+		}
2817
+		else
2818
+		{
2407 2819
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2408 2820
 			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2409 2821
 		}
2410
-		if (self::$debug) error_log("create folder: $newFolderName");
2822
+		if (self::$debug)
2823
+		{
2824
+			error_log("create folder: $newFolderName");
2825
+		}
2411 2826
 		try
2412 2827
 		{
2413 2828
 			$this->icServer->renameMailbox($oldFolderName, $newFolderName);
@@ -2481,8 +2896,14 @@  discard block
 block discarded – undo
2481 2896
 	 */
2482 2897
 	function getFolderObjects($_subscribedOnly=false, $_getCounters=false, $_alwaysGetDefaultFolders=false,$_useCacheIfPossible=true)
2483 2898
 	{
2484
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2485
-		if (self::$debugTimes) $starttime = microtime (true);
2899
+		if (self::$debug)
2900
+		{
2901
+			error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2902
+		}
2903
+		if (self::$debugTimes)
2904
+		{
2905
+			$starttime = microtime (true);
2906
+		}
2486 2907
 		static $folders2return;
2487 2908
 		//$_subscribedOnly=false;
2488 2909
 		// always use static on single request if info is available;
@@ -2490,23 +2911,35 @@  discard block
 block discarded – undo
2490 2911
 		// set $_useCacheIfPossible to false !
2491 2912
 		if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2492 2913
 		{
2493
-			if (self::$debugTimes) self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2914
+			if (self::$debugTimes)
2915
+			{
2916
+				self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2917
+			}
2494 2918
 			return $folders2return[$this->icServer->ImapServerId];
2495 2919
 		}
2496 2920
 
2497 2921
 		if ($_subscribedOnly && $_getCounters===false)
2498 2922
 		{
2499
-			if (is_null($folders2return)) $folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2923
+			if (is_null($folders2return))
2924
+			{
2925
+				$folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2926
+			}
2500 2927
 			if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2501 2928
 			{
2502 2929
 				//error_log(__METHOD__.' ('.__LINE__.') '.' using Cached folderObjects'.array2string($folders2return[$this->icServer->ImapServerId]));
2503
-				if (self::$debugTimes) self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
2930
+				if (self::$debugTimes)
2931
+				{
2932
+					self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
2933
+				}
2504 2934
 				return $folders2return[$this->icServer->ImapServerId];
2505 2935
 			}
2506 2936
 		}
2507 2937
 		// use $folderBasicInfo for holding attributes and other basic folderinfo $folderBasicInfo[$this->icServer->ImapServerId]
2508 2938
 		static $folderBasicInfo;
2509
-		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);
2939
+		if (is_null($folderBasicInfo)||!isset($folderBasicInfo[$this->icServer->ImapServerId]))
2940
+		{
2941
+			$folderBasicInfo = Cache::getCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2942
+		}
2510 2943
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($folderBasicInfo[$this->icServer->ImapServerId])));
2511 2944
 
2512 2945
 		$delimiter = $this->getHierarchyDelimiter();
@@ -2519,7 +2952,8 @@  discard block
 block discarded – undo
2519 2952
 		$inboxData->shortFolderName	= 'INBOX';
2520 2953
 		$inboxData->shortDisplayName	= lang('INBOX');
2521 2954
 		$inboxData->subscribed = true;
2522
-		if($_getCounters == true) {
2955
+		if($_getCounters == true)
2956
+		{
2523 2957
 			$inboxData->counter = $this->getMailBoxCounters('INBOX');
2524 2958
 		}
2525 2959
 		// force unsubscribed by preference showAllFoldersInFolderPane
@@ -2538,12 +2972,14 @@  discard block
 block discarded – undo
2538 2972
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2539 2973
 		if (is_array($nameSpace))
2540 2974
 		{
2541
-			foreach($nameSpace as $k => $singleNameSpace) {
2975
+			foreach($nameSpace as $k => $singleNameSpace)
2976
+			{
2542 2977
 				$type = $singleNameSpace['type'];
2543 2978
 				// the following line (assumption that for the same namespace the delimiter should be equal) may be wrong
2544 2979
 				$foldersNameSpace[$type]['delimiter']  = $singleNameSpace['delimiter'];
2545 2980
 
2546
-				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false) {
2981
+				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false)
2982
+				{
2547 2983
 					// fetch and sort the subscribed folders
2548 2984
 					// we alway fetch the subscribed, as this provides the only way to tell
2549 2985
 					// if a folder is subscribed or not
@@ -2594,8 +3030,12 @@  discard block
 block discarded – undo
2594 3030
 							}
2595 3031
 						}
2596 3032
 						//error_log(__METHOD__.' ('.__LINE__.') '.' '.$type.'->'.array2string($foldersNameSpace[$type]['subscribed']));
2597
-						if (!is_array($foldersNameSpace[$type]['all'])) $foldersNameSpace[$type]['all'] = array();
2598
-						if ($_subscribedOnly == true && !empty($foldersNameSpace[$type]['subscribed'])) {
3033
+						if (!is_array($foldersNameSpace[$type]['all']))
3034
+						{
3035
+							$foldersNameSpace[$type]['all'] = array();
3036
+						}
3037
+						if ($_subscribedOnly == true && !empty($foldersNameSpace[$type]['subscribed']))
3038
+						{
2599 3039
 							continue;
2600 3040
 						}
2601 3041
 
@@ -2625,7 +3065,8 @@  discard block
 block discarded – undo
2625 3065
 					}
2626 3066
 
2627 3067
 					//error_log(__METHOD__.' ('.__LINE__.') '.' '.$type.'->'.array2string($allMailboxesExt));
2628
-					foreach ($allMailboxesExt as $mbx) {
3068
+					foreach ($allMailboxesExt as $mbx)
3069
+					{
2629 3070
 						if (!isset($folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]))
2630 3071
 						{
2631 3072
 							$folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]=array(
@@ -2648,20 +3089,33 @@  discard block
 block discarded – undo
2648 3089
 						if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']])||
2649 3090
 							isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']])||
2650 3091
 							(substr($mbx['MAILBOX'],-1)==$foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'],0,-1)]))
2651
-						) continue;
3092
+						)
3093
+						{
3094
+							continue;
3095
+						}
2652 3096
 
2653 3097
 						//echo '#'.$mbx['MAILBOX'].':'.array2string($mbx)."#<br>";
2654 3098
 						$allMailBoxesExtSorted[$mbx['MAILBOX']] = $mbx;
2655 3099
 					}
2656
-					if (is_array($allMailBoxesExtSorted)) ksort($allMailBoxesExtSorted);
3100
+					if (is_array($allMailBoxesExtSorted))
3101
+					{
3102
+						ksort($allMailBoxesExtSorted);
3103
+					}
2657 3104
 					//_debug_array(array_keys($allMailBoxesExtSorted));
2658 3105
 					$allMailboxes = array();
2659
-					foreach ((array)$allMailBoxesExtSorted as $mbx) {
2660
-						if (!in_array($mbx['MAILBOX'],$allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
3106
+					foreach ((array)$allMailBoxesExtSorted as $mbx)
3107
+					{
3108
+						if (!in_array($mbx['MAILBOX'],$allMailboxes))
3109
+						{
3110
+							$allMailboxes[] = $mbx['MAILBOX'];
3111
+						}
2661 3112
 						//echo "Result:";_debug_array($allMailboxes);
2662 3113
 					}
2663 3114
 					$foldersNameSpace[$type]['all'] = $allMailboxes;
2664
-					if (is_array($foldersNameSpace[$type]['all'])) sort($foldersNameSpace[$type]['all']);
3115
+					if (is_array($foldersNameSpace[$type]['all']))
3116
+					{
3117
+						sort($foldersNameSpace[$type]['all']);
3118
+					}
2665 3119
 				}
2666 3120
 			}
2667 3121
 		}
@@ -2670,24 +3124,50 @@  discard block
 block discarded – undo
2670 3124
 		//echo "<br>FolderNameSpace To Process:";_debug_array($foldersNameSpace);
2671 3125
 		$autoFolderObjects = $folders = array();
2672 3126
 		$autofolder_exists = array();
2673
-		foreach( array('personal', 'others', 'shared') as $type) {
2674
-			if(isset($foldersNameSpace[$type])) {
2675
-				if($_subscribedOnly) {
2676
-					if( !empty($foldersNameSpace[$type]['subscribed']) ) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
2677
-				} else {
2678
-					if( !empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
2679
-				}
2680
-				foreach((array)$listOfFolders as $folderName) {
3127
+		foreach( array('personal', 'others', 'shared') as $type)
3128
+		{
3129
+			if(isset($foldersNameSpace[$type]))
3130
+			{
3131
+				if($_subscribedOnly)
3132
+				{
3133
+					if( !empty($foldersNameSpace[$type]['subscribed']) )
3134
+					{
3135
+						$listOfFolders = $foldersNameSpace[$type]['subscribed'];
3136
+					}
3137
+				}
3138
+				else
3139
+				{
3140
+					if( !empty($foldersNameSpace[$type]['all']))
3141
+					{
3142
+						$listOfFolders = $foldersNameSpace[$type]['all'];
3143
+					}
3144
+				}
3145
+				foreach((array)$listOfFolders as $folderName)
3146
+				{
2681 3147
 					//echo "<br>FolderToCheck:$folderName<br>";
2682 3148
 					//error_log(__METHOD__.__LINE__.'#Delimiter:'.$delimiter.':#'.$folderName);
2683
-					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue;//when subscribedonly, we fetch all folders in one go.
2684
-					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
3149
+					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all']))
3150
+					{
3151
+						continue;
3152
+					}
3153
+					//when subscribedonly, we fetch all folders in one go.
3154
+					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all'])))
3155
+					{
2685 3156
 						#echo "$folderName failed to be here <br>";
2686 3157
 						continue;
2687 3158
 					}
2688
-					if (isset($folders[$folderName])) continue;
2689
-					if (isset($autoFolderObjects[$folderName])) continue;
2690
-					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter'];
3159
+					if (isset($folders[$folderName]))
3160
+					{
3161
+						continue;
3162
+					}
3163
+					if (isset($autoFolderObjects[$folderName]))
3164
+					{
3165
+						continue;
3166
+					}
3167
+					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter'])
3168
+					{
3169
+						$delimiter = $foldersNameSpace[$type]['delimiter'];
3170
+					}
2691 3171
 					$folderParts = explode($delimiter, $folderName);
2692 3172
 					$shortName = array_pop($folderParts);
2693 3173
 
@@ -2695,17 +3175,20 @@  discard block
 block discarded – undo
2695 3175
 					$folderObject->delimiter	= $delimiter;
2696 3176
 					$folderObject->folderName	= $folderName;
2697 3177
 					$folderObject->shortFolderName	= $shortName;
2698
-					if(!$_subscribedOnly) {
3178
+					if(!$_subscribedOnly)
3179
+					{
2699 3180
 						#echo $folderName."->".$type."<br>";
2700 3181
 						#_debug_array($foldersNameSpace[$type]['subscribed']);
2701 3182
 						$folderObject->subscribed = in_array($folderName, (array)$foldersNameSpace[$type]['subscribed']);
2702 3183
 					}
2703 3184
 
2704
-					if($_getCounters == true) {
3185
+					if($_getCounters == true)
3186
+					{
2705 3187
 						//error_log(__METHOD__.' ('.__LINE__.') '.' getCounter forFolder:'.$folderName);
2706 3188
 						$folderObject->counter = $this->getMailBoxCounters($folderName);
2707 3189
 					}
2708
-					if(strtoupper($folderName) == 'INBOX') {
3190
+					if(strtoupper($folderName) == 'INBOX')
3191
+					{
2709 3192
 						$folderName = 'INBOX';
2710 3193
 						$folderObject->folderName	= 'INBOX';
2711 3194
 						$folderObject->shortFolderName	= 'INBOX';
@@ -2713,24 +3196,34 @@  discard block
 block discarded – undo
2713 3196
 						$folderObject->shortDisplayName = lang('INBOX');
2714 3197
 						$folderObject->subscribed	= true;
2715 3198
 					// translate the automatic Folders (Sent, Drafts, ...) like the INBOX
2716
-					} elseif (in_array($shortName,self::$autoFolders)) {
3199
+					}
3200
+					elseif (in_array($shortName,self::$autoFolders))
3201
+					{
2717 3202
 						$tmpfolderparts = explode($delimiter,$folderObject->folderName);
2718 3203
 						array_pop($tmpfolderparts);
2719 3204
 						$folderObject->displayName = implode($delimiter,$tmpfolderparts).$delimiter.lang($shortName);
2720 3205
 						$folderObject->shortDisplayName = lang($shortName);
2721 3206
 						unset($tmpfolderparts);
2722
-					} else {
3207
+					}
3208
+					else
3209
+					{
2723 3210
 						$folderObject->displayName = $folderObject->folderName;
2724 3211
 						$folderObject->shortDisplayName = $shortName;
2725 3212
 					}
2726 3213
 					//$folderName = $folderName;
2727
-					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false) {
3214
+					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false)
3215
+					{
2728 3216
 						$autoFolderObjects[$folderName] = $folderObject;
2729
-					} else {
3217
+					}
3218
+					else
3219
+					{
2730 3220
 						$folders[$folderName] = $folderObject;
2731 3221
 					}
2732 3222
 					//error_log(__METHOD__.' ('.__LINE__.') '.':'.$folderObject->folderName);
2733
-					if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders ();
3223
+					if (!isset(self::$specialUseFolders))
3224
+					{
3225
+						$this->getSpecialUseFolders ();
3226
+					}
2734 3227
 					if (isset(self::$specialUseFolders[$folderName]))
2735 3228
 					{
2736 3229
 						$autofolder_exists[$folderName] = self::$specialUseFolders[$folderName];
@@ -2738,7 +3231,8 @@  discard block
 block discarded – undo
2738 3231
 				}
2739 3232
 			}
2740 3233
 		}
2741
-		if (is_array($autoFolderObjects) && !empty($autoFolderObjects)) {
3234
+		if (is_array($autoFolderObjects) && !empty($autoFolderObjects))
3235
+		{
2742 3236
 			uasort($autoFolderObjects,array($this,"sortByAutoFolderPos"));
2743 3237
 		}
2744 3238
 		// check if some standard folders are missing and need to be created
@@ -2747,7 +3241,10 @@  discard block
 block discarded – undo
2747 3241
 			// if new folders have been created, re-read folders ignoring the cache
2748 3242
 			return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false);	// false = do NOT use cache
2749 3243
 		}
2750
-		if (is_array($folders)) uasort($folders,array($this,"sortByDisplayName"));
3244
+		if (is_array($folders))
3245
+		{
3246
+			uasort($folders,array($this,"sortByDisplayName"));
3247
+		}
2751 3248
 		//$folders2return = array_merge($autoFolderObjects,$folders);
2752 3249
 		//_debug_array($folders2return); #exit;
2753 3250
 		$folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject,(array)$autoFolderObjects,(array)$folders);
@@ -2759,7 +3256,10 @@  discard block
 block discarded – undo
2759 3256
 			Cache::setCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$folders2return,$expiration=60*60*1);
2760 3257
 		}
2761 3258
 		Cache::setCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderBasicInfo,$expiration=60*60*1);
2762
-		if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
3259
+		if (self::$debugTimes)
3260
+		{
3261
+			self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
3262
+		}
2763 3263
 		return $folders2return[$this->icServer->ImapServerId];
2764 3264
 	}
2765 3265
 
@@ -2787,31 +3287,44 @@  discard block
 block discarded – undo
2787 3287
 
2788 3288
 		$folders = $nameSpace =  array();
2789 3289
 		$nameSpaceTmp = $this->_getNameSpaces();
2790
-		foreach($nameSpaceTmp as $k => $singleNameSpace) {
3290
+		foreach($nameSpaceTmp as $k => $singleNameSpace)
3291
+		{
2791 3292
 			$nameSpace[$singleNameSpace['type']]=$singleNameSpace;
2792 3293
 		}
2793 3294
 		unset($nameSpaceTmp);
2794 3295
 
2795 3296
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2796 3297
 		// Get special use folders
2797
-		if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders (); // Set self::$specialUseFolders
3298
+		if (!isset(self::$specialUseFolders))
3299
+		{
3300
+			$this->getSpecialUseFolders ();
3301
+		}
3302
+		// Set self::$specialUseFolders
2798 3303
 		// topLevelQueries generally ignore the $_search param. Except for Config::examineNamespace
2799
-		if ($_onlyTopLevel) // top level leaves
3304
+		if ($_onlyTopLevel)
3305
+		{
3306
+			// top level leaves
2800 3307
 		{
2801 3308
 			// Get top mailboxes of icServer
2802 3309
 			$topFolders = $this->icServer->getMailboxes("", 2, true);
3310
+		}
2803 3311
 			// Trigger examination of namespace to retrieve
2804 3312
 			// folders located in other and shared; needed only for some servers
2805
-			if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
3313
+			if (is_null(self::$mailConfig))
3314
+			{
3315
+				self::$mailConfig = Config::read('mail');
3316
+			}
2806 3317
 			if (self::$mailConfig['examineNamespace'])
2807 3318
 			{
2808 3319
 				$prefixes=array();
2809 3320
 				if (is_array($nameSpace))
2810 3321
 				{
2811
-					foreach($nameSpace as $k => $singleNameSpace) {
3322
+					foreach($nameSpace as $k => $singleNameSpace)
3323
+					{
2812 3324
 						$type = $singleNameSpace['type'];
2813 3325
 
2814
-						if(is_array($singleNameSpace) && $singleNameSpace['prefix']){
3326
+						if(is_array($singleNameSpace) && $singleNameSpace['prefix'])
3327
+						{
2815 3328
 							$prefixes[$type] = $singleNameSpace['prefix'];
2816 3329
 							//regard extra care for nameSpacequeries when configured AND respect $_search
2817 3330
 							$result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search==0?0:2, true);
@@ -2887,7 +3400,10 @@  discard block
 block discarded – undo
2887 3400
 							$nFolders [$path] = $folder;
2888 3401
 						}
2889 3402
 					}
2890
-					if (is_array($aFolders)) uasort ($aFolders, array($this,'sortByAutofolder'));
3403
+					if (is_array($aFolders))
3404
+					{
3405
+						uasort ($aFolders, array($this,'sortByAutofolder'));
3406
+					}
2891 3407
 					//ksort($aFolders);
2892 3408
 
2893 3409
 					// Sort none auto folders base on mailbox name
@@ -2897,12 +3413,17 @@  discard block
 block discarded – undo
2897 3413
 				}
2898 3414
 				else
2899 3415
 				{
2900
-					if (is_array($subFolders)) ksort($subFolders);
3416
+					if (is_array($subFolders))
3417
+					{
3418
+						ksort($subFolders);
3419
+					}
2901 3420
 				}
2902 3421
 				$folders = array_merge($folders,(array)$mainFolder, (array)$subFolders);
2903 3422
 			}
2904 3423
 		}
2905
-		elseif ($_nodePath) // single node
3424
+		elseif ($_nodePath)
3425
+		{
3426
+			// single node
2906 3427
 		{
2907 3428
 			switch ($_search)
2908 3429
 			{
@@ -2910,6 +3431,7 @@  discard block
 block discarded – undo
2910 3431
 				case 0:
2911 3432
 				case 2:
2912 3433
 					$path = $_nodePath.''.$delimiter;
3434
+		}
2913 3435
 					break;
2914 3436
 				// Node itself
2915 3437
 				// shouldn't contain next level delimiter
@@ -2928,11 +3450,14 @@  discard block
 block discarded – undo
2928 3450
 
2929 3451
 			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
2930 3452
 		}
2931
-		elseif(!$_nodePath) // all
3453
+		elseif(!$_nodePath)
3454
+		{
3455
+			// all
2932 3456
 		{
2933 3457
 			if ($_subscribedOnly)
2934 3458
 			{
2935 3459
 				$folders = $this->icServer->listSubscribedMailboxes('', 0, true);
3460
+		}
2936 3461
 			}
2937 3462
 			else
2938 3463
 			{
@@ -2944,7 +3469,10 @@  discard block
 block discarded – undo
2944 3469
 		{
2945 3470
 			// SORTING FOLDERS
2946 3471
 			//self::$debugTimes=true;
2947
-			if (self::$debugTimes) $starttime = microtime (true);
3472
+			if (self::$debugTimes)
3473
+			{
3474
+				$starttime = microtime (true);
3475
+			}
2948 3476
 			// Merge of all auto folders and specialusefolders
2949 3477
 			$autoFoldersTmp = array_unique((array_merge(self::$autoFolders, array_values(self::$specialUseFolders))));
2950 3478
 			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
@@ -2954,73 +3482,103 @@  discard block
 block discarded – undo
2954 3482
 			$isGoogleMail=false;
2955 3483
 			foreach($autoFoldersTmp as $afk=>$aF)
2956 3484
 			{
2957
-				if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
3485
+				if (!isset($mySpecialUseFolders[$aF]) && $aF)
3486
+				{
3487
+					$mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
3488
+				}
2958 3489
 				//error_log($afk.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
2959 3490
 			}
2960 3491
 			//error_log(array2string($mySpecialUseFolders));
2961
-			foreach ($tmpFolders as $k => $f) {
3492
+			foreach ($tmpFolders as $k => $f)
3493
+			{
2962 3494
 				$sorted=false;
2963
-				if (strtoupper(substr($k,0,5))=='INBOX') {
2964
-					if (strtoupper($k)=='INBOX') {
3495
+				if (strtoupper(substr($k,0,5))=='INBOX')
3496
+				{
3497
+					if (strtoupper($k)=='INBOX')
3498
+					{
2965 3499
 						//error_log(__METHOD__.__LINE__.':'.strtoupper(substr($k,0,5)).':'.$k);
2966 3500
 						$inboxFolderObject[$k]=$f;
2967 3501
 						unset($folders[$k]);
2968 3502
 						$sorted=true;
2969
-					} else {
3503
+					}
3504
+					else
3505
+					{
2970 3506
 						$isAutoFolder=false;
2971 3507
 						foreach($autoFoldersTmp as $afk=>$aF)
2972 3508
 						{
2973 3509
 							//error_log(__METHOD__.__LINE__.$k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
2974 3510
 							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
2975 3511
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
2976
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3512
+								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3513
+							{
3514
+								// k is parent of an autofolder
2977 3515
 							{
2978 3516
 								//error_log(__METHOD__.__LINE__.$k.'->'.$mySpecialUseFolders[$aF]);
2979 3517
 								$isAutoFolder=true;
3518
+							}
2980 3519
 								$autoFolderObjects[$k]=$f;
2981 3520
 								break;
2982 3521
 							}
2983 3522
 						}
2984
-						if ($isAutoFolder==false) $inboxSubFolderObjects[$k]=$f;
3523
+						if ($isAutoFolder==false)
3524
+						{
3525
+							$inboxSubFolderObjects[$k]=$f;
3526
+						}
2985 3527
 						unset($folders[$k]);
2986 3528
 						$sorted=true;
2987 3529
 					}
2988
-				} elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]') {
3530
+				}
3531
+				elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]')
3532
+				{
2989 3533
 					$isGoogleMail=true;
2990
-					if (strtoupper($k)=='[GOOGLE MAIL]') {
3534
+					if (strtoupper($k)=='[GOOGLE MAIL]')
3535
+					{
2991 3536
 						$googleMailFolderObject[$k]=$f;
2992 3537
 						unset($folders[$k]);
2993 3538
 						$sorted=true;
2994
-					} else {
3539
+					}
3540
+					else
3541
+					{
2995 3542
 						$isAutoFolder=false;
2996 3543
 						foreach($autoFoldersTmp as $afk=>$aF)
2997 3544
 						{
2998 3545
 							//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
2999 3546
 							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3000 3547
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3001
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3548
+								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3549
+							{
3550
+								// k is parent of an autofolder
3002 3551
 							{
3003 3552
 								//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3004 3553
 								$isAutoFolder=true;
3554
+							}
3005 3555
 								$googleAutoFolderObjects[$k]=$f;
3006 3556
 								break;
3007 3557
 							}
3008 3558
 						}
3009
-						if ($isAutoFolder==false) $googleSubFolderObjects[$k]=$f;
3559
+						if ($isAutoFolder==false)
3560
+						{
3561
+							$googleSubFolderObjects[$k]=$f;
3562
+						}
3010 3563
 						unset($folders[$k]);
3011 3564
 						$sorted=true;
3012 3565
 					}
3013
-				} else {
3566
+				}
3567
+				else
3568
+				{
3014 3569
 					$isAutoFolder=false;
3015 3570
 					foreach($autoFoldersTmp as $afk=>$aF)
3016 3571
 					{
3017 3572
 						//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3018 3573
 						if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3019 3574
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3020
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3575
+								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3576
+						{
3577
+							// k is parent of an autofolder
3021 3578
 						{
3022 3579
 							//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3023 3580
 							$isAutoFolder=true;
3581
+						}
3024 3582
 							$autoFolderObjects[$k]=$f;
3025 3583
 							unset($folders[$k]);
3026 3584
 							$sorted=true;
@@ -3036,7 +3594,8 @@  discard block
 block discarded – undo
3036 3594
 						if ($nameSpace[$type]['prefix_present']&&$nameSpace[$type]['prefix'])
3037 3595
 						{
3038 3596
 							if (substr($k,0,strlen($nameSpace[$type]['prefix']))==$nameSpace[$type]['prefix']||
3039
-								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1)) {
3597
+								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1))
3598
+							{
3040 3599
 								//error_log(__METHOD__.__LINE__.':'.substr($k,0,strlen($nameSpace[$type]['prefix'])).':'.$k);
3041 3600
 								$typeFolderObject[$type][$k]=$f;
3042 3601
 								unset($folders[$k]);
@@ -3063,9 +3622,12 @@  discard block
 block discarded – undo
3063 3622
 				}
3064 3623
 			}
3065 3624
 			//error_log(__METHOD__.__LINE__.array2string($autoFolderObjects));
3066
-			if (!$isGoogleMail) {
3625
+			if (!$isGoogleMail)
3626
+			{
3067 3627
 				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$inboxSubFolderObjects,(array)$folders,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3068
-			} else {
3628
+			}
3629
+			else
3630
+			{
3069 3631
 				// avoid calling sortByAutoFolder as it is not regarding subfolders
3070 3632
 				$gAutoFolderObjectsTmp = $googleAutoFolderObjects;
3071 3633
 				unset($googleAutoFolderObjects);
@@ -3082,7 +3644,10 @@  discard block
 block discarded – undo
3082 3644
 				}
3083 3645
 				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$folders,(array)$googleMailFolderObject,$googleAutoFolderObjects,$googleSubFolderObjects,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3084 3646
 			}
3085
-			if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3647
+			if (self::$debugTimes)
3648
+			{
3649
+				self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3650
+			}
3086 3651
 			//self::$debugTimes=false;
3087 3652
 		}
3088 3653
 		// Get counter information and add them to each fetched folders array
@@ -3132,7 +3697,13 @@  discard block
 block discarded – undo
3132 3697
 		$rv = false;
3133 3698
 		foreach ($haystack as $k => $v)
3134 3699
 		{
3135
-			foreach($v as &$sv) {if (trim($sv)==trim($needle)) return $k;}
3700
+			foreach($v as &$sv)
3701
+			{
3702
+if (trim($sv)==trim($needle))
3703
+			{
3704
+				return $k;
3705
+			}
3706
+			}
3136 3707
 		}
3137 3708
 		return $rv;
3138 3709
 	}
@@ -3159,7 +3730,10 @@  discard block
 block discarded – undo
3159 3730
 	 */
3160 3731
 	static function pathToFolderData ($_path, $_hDelimiter)
3161 3732
 	{
3162
-		if (!strpos($_path, self::DELIMITER)) $_path = self::DELIMITER.$_path;
3733
+		if (!strpos($_path, self::DELIMITER))
3734
+		{
3735
+			$_path = self::DELIMITER.$_path;
3736
+		}
3163 3737
 		list(,$path) = explode(self::DELIMITER, $_path);
3164 3738
 		$path_chain = $parts = explode($_hDelimiter, $path);
3165 3739
 		$name = array_pop($parts);
@@ -3188,7 +3762,10 @@  discard block
 block discarded – undo
3188 3762
 		$b = self::pathToFolderData($_b['MAILBOX'], $_b['delimiter']);
3189 3763
 		$pos1 = array_search(trim($a['name']),self::$autoFolders);
3190 3764
 		$pos2 = array_search(trim($b['name']),self::$autoFolders);
3191
-		if ($pos1 == $pos2) return 0;
3765
+		if ($pos1 == $pos2)
3766
+		{
3767
+			return 0;
3768
+		}
3192 3769
 		return ($pos1 < $pos2) ? -1 : 1;
3193 3770
 	}
3194 3771
 
@@ -3219,7 +3796,10 @@  discard block
 block discarded – undo
3219 3796
 		// 0, 1 und -1
3220 3797
 		$pos1 = array_search(trim($a->shortFolderName),self::$autoFolders);
3221 3798
 		$pos2 = array_search(trim($b->shortFolderName),self::$autoFolders);
3222
-		if ($pos1 == $pos2) return 0;
3799
+		if ($pos1 == $pos2)
3800
+		{
3801
+			return 0;
3802
+		}
3223 3803
 		return ($pos1 < $pos2) ? -1 : 1;
3224 3804
 	}
3225 3805
 
@@ -3240,11 +3820,18 @@  discard block
 block discarded – undo
3240 3820
 		}
3241 3821
 		catch (\Exception $e)
3242 3822
 		{
3243
-			if (self::$debug) error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3823
+			if (self::$debug)
3824
+			{
3825
+				error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3826
+			}
3244 3827
 			return false;
3245 3828
 		}
3246
-		if(is_array($folderStatus)) {
3247
-			if ($_returnObject===false) return $folderStatus;
3829
+		if(is_array($folderStatus))
3830
+		{
3831
+			if ($_returnObject===false)
3832
+			{
3833
+				return $folderStatus;
3834
+			}
3248 3835
 			$status =  new \stdClass;
3249 3836
 			$status->messages   = $folderStatus['MESSAGES'];
3250 3837
 			$status->unseen     = $folderStatus['UNSEEN'];
@@ -3271,7 +3858,8 @@  discard block
 block discarded – undo
3271 3858
 	{
3272 3859
 		#echo __METHOD__." retrieve SubFolders for $_mailbox$delimiter <br>";
3273 3860
 		$maxreclevel=25;
3274
-		if ($reclevel > $maxreclevel) {
3861
+		if ($reclevel > $maxreclevel)
3862
+		{
3275 3863
 			error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
3276 3864
 			return array();
3277 3865
 		}
@@ -3285,7 +3873,8 @@  discard block
 block discarded – undo
3285 3873
 //error_log(__METHOD__.' ('.__LINE__.') '.' Delimiter:'.array2string($delimiter));
3286 3874
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx));
3287 3875
 		// Example: Array([INBOX/GaGa] => Array([MAILBOX] => INBOX/GaGa[ATTRIBUTES] => Array([0] => \\unmarked)[delimiter] => /))
3288
-		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"]))) {
3876
+		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"])))
3877
+		{
3289 3878
 			// if there are children fetch them
3290 3879
 			//echo $mbx[$mbxkeys[0]]['MAILBOX']."<br>";
3291 3880
 
@@ -3293,7 +3882,8 @@  discard block
 block discarded – undo
3293 3882
 			//$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'],2,false);
3294 3883
 			//_debug_array($buff);
3295 3884
 			$allMailboxes = array();
3296
-			foreach ($buff as $mbxname) {
3885
+			foreach ($buff as $mbxname)
3886
+			{
3297 3887
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbxname));
3298 3888
 				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname['MAILBOX']);
3299 3889
 				#echo "About to recur in level $reclevel:".$mbxname."<br>";
@@ -3302,9 +3892,14 @@  discard block
 block discarded – undo
3302 3892
 					$allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel));
3303 3893
 				}
3304 3894
 			}
3305
-			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'];
3895
+			if (!(in_array('\NoSelect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"])))
3896
+			{
3897
+				$allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX'];
3898
+			}
3306 3899
 			return $allMailboxes;
3307
-		} else {
3900
+		}
3901
+		else
3902
+		{
3308 3903
 			return array($_mailbox);
3309 3904
 		}
3310 3905
 	}
@@ -3328,14 +3923,21 @@  discard block
 block discarded – undo
3328 3923
 			'Outbox'   => array('profileKey'=>'acc_folder_outbox','autoFolderName'=>'Outbox'),
3329 3924
 			'Archive'   => array('profileKey'=>'acc_folder_archive','autoFolderName'=>'Archive'),
3330 3925
 		);
3331
-		if ($_type == 'Templates') $_type = 'Template';	// for some reason self::$autofolders uses 'Templates'!
3926
+		if ($_type == 'Templates')
3927
+		{
3928
+			$_type = 'Template';
3929
+		}
3930
+		// for some reason self::$autofolders uses 'Templates'!
3332 3931
 		$created = false;
3333 3932
 		if (!isset($types[$_type]))
3334 3933
 		{
3335 3934
 			error_log(__METHOD__.' ('.__LINE__.') '.' '.$_type.' not supported for '.__METHOD__);
3336 3935
 			return false;
3337 3936
 		}
3338
-		if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders)) self::$specialUseFolders = $this->getSpecialUseFolders();
3937
+		if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders))
3938
+		{
3939
+			self::$specialUseFolders = $this->getSpecialUseFolders();
3940
+		}
3339 3941
 
3340 3942
 		//highest precedence
3341 3943
 		try
@@ -3345,25 +3947,39 @@  discard block
 block discarded – undo
3345 3947
 		catch (\Exception $e)
3346 3948
 		{
3347 3949
 			// we know that outbox is not supported, but we use this here, as we autocreate expected SpecialUseFolders in this function
3348
-			if ($_type != 'Outbox') error_log(__METHOD__.' ('.__LINE__.') '.' Failed to retrieve Folder'.$_folderName." for ".array2string($types[$_type]).":".$e->getMessage());
3950
+			if ($_type != 'Outbox')
3951
+			{
3952
+				error_log(__METHOD__.' ('.__LINE__.') '.' Failed to retrieve Folder'.$_folderName." for ".array2string($types[$_type]).":".$e->getMessage());
3953
+			}
3349 3954
 			$_folderName = false;
3350 3955
 		}
3351 3956
 		// do not try to autocreate configured Archive-Folder. Return false if configured folder does not exist
3352
-		if ($_type == 'Archive') {
3353
-			if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
3957
+		if ($_type == 'Archive')
3958
+		{
3959
+			if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true))
3960
+			{
3354 3961
 				return false;
3355
-			} else {
3962
+			}
3963
+			else
3964
+			{
3356 3965
 				return $_folderName;
3357 3966
 			}
3358 3967
 
3359 3968
 		}
3360 3969
 		// does the folder exist??? (is configured/preset, but non-existent)
3361
-		if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
3970
+		if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true))
3971
+		{
3362 3972
 			try
3363 3973
 			{
3364 3974
 				$error = null;
3365
-				if (($_folderName = $this->createFolder('', $_folderName, $error))) $created = true;
3366
-				if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
3975
+				if (($_folderName = $this->createFolder('', $_folderName, $error)))
3976
+				{
3977
+					$created = true;
3978
+				}
3979
+				if ($error)
3980
+				{
3981
+					error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
3982
+				}
3367 3983
 			}
3368 3984
 			catch(Exception $e)
3369 3985
 			{
@@ -3372,9 +3988,16 @@  discard block
 block discarded – undo
3372 3988
 			}
3373 3989
 		}
3374 3990
 		// not sure yet if false is the correct behavior on none
3375
-		if ($_folderName =='none') return 'none' ; //false;
3991
+		if ($_folderName =='none')
3992
+		{
3993
+			return 'none' ;
3994
+		}
3995
+		//false;
3376 3996
 		//no (valid) folder found yet; try specialUseFolders
3377
-		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders))) $_folderName = $f;
3997
+		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders)))
3998
+		{
3999
+			$_folderName = $f;
4000
+		}
3378 4001
 		//no specialUseFolder; try some Defaults
3379 4002
 		if (empty($_folderName) && isset($types[$_type]))
3380 4003
 		{
@@ -3400,7 +4023,10 @@  discard block
 block discarded – undo
3400 4023
 					$error = null;
3401 4024
 					$this->createFolder('', $prefix.$types[$_type]['autoFolderName'],$error);
3402 4025
 					$_folderName = $prefix.$types[$_type]['autoFolderName'];
3403
-					if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4026
+					if ($error)
4027
+					{
4028
+						error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4029
+					}
3404 4030
 				}
3405 4031
 				catch(Exception $e)
3406 4032
 				{
@@ -3502,17 +4128,22 @@  discard block
 block discarded – undo
3502 4128
 	function isSentFolder($_folderName, $_checkexistance=TRUE)
3503 4129
 	{
3504 4130
 		$sentFolder = $this->getSentFolder($_checkexistance);
3505
-		if(empty($sentFolder)) {
4131
+		if(empty($sentFolder))
4132
+		{
3506 4133
 			return false;
3507 4134
 		}
3508 4135
 		// does the folder exist???
3509
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4136
+		if ($_checkexistance && !$this->folderExists($_folderName))
4137
+		{
3510 4138
 			return false;
3511 4139
 		}
3512 4140
 
3513
-		if(false !== stripos($_folderName, $sentFolder)) {
4141
+		if(false !== stripos($_folderName, $sentFolder))
4142
+		{
3514 4143
 			return true;
3515
-		} else {
4144
+		}
4145
+		else
4146
+		{
3516 4147
 			return false;
3517 4148
 		}
3518 4149
 	}
@@ -3525,15 +4156,20 @@  discard block
 block discarded – undo
3525 4156
 	 */
3526 4157
 	function isOutbox($_folderName, $_checkexistance=TRUE)
3527 4158
 	{
3528
-		if (stripos($_folderName, 'Outbox')===false) {
4159
+		if (stripos($_folderName, 'Outbox')===false)
4160
+		{
3529 4161
 			return false;
3530 4162
 		}
3531 4163
 		// does the folder exist???
3532
-		if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName)) {
4164
+		if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName))
4165
+		{
3533 4166
 			$outboxFolder = $this->getOutboxFolder($_checkexistance);
3534
-			if(false !== stripos($_folderName, $outboxFolder)) {
4167
+			if(false !== stripos($_folderName, $outboxFolder))
4168
+			{
3535 4169
 				return true;
3536
-			} else {
4170
+			}
4171
+			else
4172
+			{
3537 4173
 				return false;
3538 4174
 			}
3539 4175
 		}
@@ -3549,17 +4185,25 @@  discard block
 block discarded – undo
3549 4185
 	function isDraftFolder($_folderName, $_checkexistance=TRUE)
3550 4186
 	{
3551 4187
 		$draftFolder = $this->getDraftFolder($_checkexistance);
3552
-		if(empty($draftFolder)) {
4188
+		if(empty($draftFolder))
4189
+		{
3553 4190
 			return false;
3554 4191
 		}
3555 4192
 		// does the folder exist???
3556
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4193
+		if ($_checkexistance && !$this->folderExists($_folderName))
4194
+		{
3557 4195
 			return false;
3558 4196
 		}
3559
-		if (is_a($_folderName,"Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8;
3560
-		if(false !== stripos($_folderName, $draftFolder)) {
4197
+		if (is_a($_folderName,"Horde_Imap_Client_Mailbox"))
4198
+		{
4199
+			$_folderName = $_folderName->utf8;
4200
+		}
4201
+		if(false !== stripos($_folderName, $draftFolder))
4202
+		{
3561 4203
 			return true;
3562
-		} else {
4204
+		}
4205
+		else
4206
+		{
3563 4207
 			return false;
3564 4208
 		}
3565 4209
 	}
@@ -3573,17 +4217,22 @@  discard block
 block discarded – undo
3573 4217
 	function isTrashFolder($_folderName, $_checkexistance=TRUE)
3574 4218
 	{
3575 4219
 		$trashFolder = $this->getTrashFolder($_checkexistance);
3576
-		if(empty($trashFolder)) {
4220
+		if(empty($trashFolder))
4221
+		{
3577 4222
 			return false;
3578 4223
 		}
3579 4224
 		// does the folder exist???
3580
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4225
+		if ($_checkexistance && !$this->folderExists($_folderName))
4226
+		{
3581 4227
 			return false;
3582 4228
 		}
3583 4229
 
3584
-		if(false !== stripos($_folderName, $trashFolder)) {
4230
+		if(false !== stripos($_folderName, $trashFolder))
4231
+		{
3585 4232
 			return true;
3586
-		} else {
4233
+		}
4234
+		else
4235
+		{
3587 4236
 			return false;
3588 4237
 		}
3589 4238
 	}
@@ -3597,17 +4246,22 @@  discard block
 block discarded – undo
3597 4246
 	function isTemplateFolder($_folderName, $_checkexistance=TRUE)
3598 4247
 	{
3599 4248
 		$templateFolder = $this->getTemplateFolder($_checkexistance);
3600
-		if(empty($templateFolder)) {
4249
+		if(empty($templateFolder))
4250
+		{
3601 4251
 			return false;
3602 4252
 		}
3603 4253
 		// does the folder exist???
3604
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4254
+		if ($_checkexistance && !$this->folderExists($_folderName))
4255
+		{
3605 4256
 			return false;
3606 4257
 		}
3607 4258
 
3608
-		if(false !== stripos($_folderName, $templateFolder)) {
4259
+		if(false !== stripos($_folderName, $templateFolder))
4260
+		{
3609 4261
 			return true;
3610
-		} else {
4262
+		}
4263
+		else
4264
+		{
3611 4265
 			return false;
3612 4266
 		}
3613 4267
 	}
@@ -3625,15 +4279,27 @@  discard block
 block discarded – undo
3625 4279
 		if (empty($_folder))
3626 4280
 		{
3627 4281
 			// this error is more or less without significance, unless we force the check
3628
-			if ($_forceCheck===true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
4282
+			if ($_forceCheck===true)
4283
+			{
4284
+				error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
4285
+			}
3629 4286
 			return false;
3630 4287
 		}
3631 4288
 		// when check is not enforced , we assume a folder represented as Horde_Imap_Client_Mailbox as existing folder
3632
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false) return true;
3633
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")) $_folder =  $_folder->utf8;
4289
+		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false)
4290
+		{
4291
+			return true;
4292
+		}
4293
+		if (is_a($_folder,"Horde_Imap_Client_Mailbox"))
4294
+		{
4295
+			$_folder =  $_folder->utf8;
4296
+		}
3634 4297
 		// reduce traffic within the Instance per User; Expire every 5 hours
3635 4298
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Called with Folder:'.$_folder.function_backtrace());
3636
-		if (is_null($folderInfo)) $folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
4299
+		if (is_null($folderInfo))
4300
+		{
4301
+			$folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
4302
+		}
3637 4303
 		//error_log(__METHOD__.' ('.__LINE__.') '.'Cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID.($forceCheck?'(forcedCheck)':'').':'.array2string($folderInfo));
3638 4304
 		if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck===false)
3639 4305
 		{
@@ -3651,7 +4317,8 @@  discard block
 block discarded – undo
3651 4317
 
3652 4318
 		// does the folder exist???
3653 4319
 		//error_log(__METHOD__."->Connected?".$this->icServer->_connected.", ".$_folder.", ".($forceCheck?' forceCheck activated':'dont check on server'));
3654
-		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
4320
+		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder]))
4321
+		{
3655 4322
 			//error_log(__METHOD__."->NotConnected and forceCheck with profile:".$this->profileID);
3656 4323
 			//return false;
3657 4324
 			//try to connect
@@ -3691,9 +4358,12 @@  discard block
 block discarded – undo
3691 4358
 
3692 4359
 		$this->icServer->openMailbox($folderName);
3693 4360
 
3694
-		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") {
4361
+		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash")
4362
+		{
3695 4363
 			$this->deleteMessages('all',$folderName,'remove_immediately');
3696
-		} else {
4364
+		}
4365
+		else
4366
+		{
3697 4367
 			$this->icServer->expunge($folderName);
3698 4368
 		}
3699 4369
 	}
@@ -3712,10 +4382,16 @@  discard block
 block discarded – undo
3712 4382
 	{
3713 4383
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.array2string($_folder).', '.$_forceDeleteMethod);
3714 4384
 		$oldMailbox = '';
3715
-		if (is_null($_folder) || empty($_folder)) $_folder = $this->sessionData['mailbox'];
4385
+		if (is_null($_folder) || empty($_folder))
4386
+		{
4387
+			$_folder = $this->sessionData['mailbox'];
4388
+		}
3716 4389
 		if (empty($_messageUID))
3717 4390
 		{
3718
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4391
+			if (self::$debug)
4392
+			{
4393
+				error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4394
+			}
3719 4395
 			return false;
3720 4396
 		}
3721 4397
 		elseif ($_messageUID==='all')
@@ -3725,32 +4401,48 @@  discard block
 block discarded – undo
3725 4401
 		else
3726 4402
 		{
3727 4403
 			$uidsToDelete = new Horde_Imap_Client_Ids();
3728
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4404
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4405
+			{
4406
+				$_messageUID = (array)$_messageUID;
4407
+			}
3729 4408
 			$uidsToDelete->add($_messageUID);
3730 4409
 		}
3731 4410
 		$deleteOptions = $_forceDeleteMethod; // use forceDeleteMethod if not "no", or unknown method
3732
-		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");
4411
+		if ($_forceDeleteMethod === 'no' || !in_array($_forceDeleteMethod,array('move_to_trash',"mark_as_deleted","remove_immediately")))
4412
+		{
4413
+			$deleteOptions  = ($this->mailPreferences['deleteOptions']?$this->mailPreferences['deleteOptions']:"mark_as_deleted");
4414
+		}
3733 4415
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3734 4416
 		$trashFolder    = $this->getTrashFolder();
3735 4417
 		$draftFolder	= $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder'];
3736 4418
 		$templateFolder = $this->getTemplateFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['templateFolder'];
3737 4419
 		if((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") ||
3738
-		   (strtolower($_folder) == strtolower($draftFolder))) {
4420
+		   (strtolower($_folder) == strtolower($draftFolder)))
4421
+		{
3739 4422
 			$deleteOptions = "remove_immediately";
3740 4423
 		}
3741
-		if($this->icServer->getCurrentMailbox() != $_folder) {
4424
+		if($this->icServer->getCurrentMailbox() != $_folder)
4425
+		{
3742 4426
 			$oldMailbox = $this->icServer->getCurrentMailbox();
3743 4427
 			$this->icServer->openMailbox($_folder);
3744 4428
 		}
3745 4429
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3746 4430
 		$updateCache = false;
3747
-		switch($deleteOptions) {
4431
+		switch($deleteOptions)
4432
+		{
3748 4433
 			case "move_to_trash":
3749 4434
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3750 4435
 				$updateCache = true;
3751
-				if(!empty($trashFolder)) {
3752
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
3753
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
4436
+				if(!empty($trashFolder))
4437
+				{
4438
+					if (self::$debug)
4439
+					{
4440
+						error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
4441
+					}
4442
+					if (self::$debug)
4443
+					{
4444
+						error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
4445
+					}
3754 4446
 					// copy messages
3755 4447
 					try
3756 4448
 					{
@@ -3766,7 +4458,10 @@  discard block
 block discarded – undo
3766 4458
 			case "mark_as_deleted":
3767 4459
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3768 4460
 				// mark messages as deleted
3769
-				if (is_null($_messageUID)) $_messageUID='all';
4461
+				if (is_null($_messageUID))
4462
+				{
4463
+					$_messageUID='all';
4464
+				}
3770 4465
 				foreach((array)$_messageUID as $key =>$uid)
3771 4466
 				{
3772 4467
 					//flag messages, that are flagged for deletion as seen too
@@ -3774,7 +4469,10 @@  discard block
 block discarded – undo
3774 4469
 					$flags = $this->getFlags($uid);
3775 4470
 					$this->flagMessages('delete', $uid, $_folder);
3776 4471
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
3777
-					if (strpos( array2string($flags),'Deleted')!==false) $undelete[] = $uid;
4472
+					if (strpos( array2string($flags),'Deleted')!==false)
4473
+					{
4474
+						$undelete[] = $uid;
4475
+					}
3778 4476
 					unset($flags);
3779 4477
 				}
3780 4478
 				foreach((array)$undelete as $key =>$uid)
@@ -3786,7 +4484,10 @@  discard block
 block discarded – undo
3786 4484
 			case "remove_immediately":
3787 4485
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3788 4486
 				$updateCache = true;
3789
-				if (is_null($_messageUID)) $_messageUID='all';
4487
+				if (is_null($_messageUID))
4488
+				{
4489
+					$_messageUID='all';
4490
+				}
3790 4491
 				if (is_object($_messageUID))
3791 4492
 				{
3792 4493
 					$this->flagMessages('delete', $_messageUID, $_folder);
@@ -3803,7 +4504,8 @@  discard block
 block discarded – undo
3803 4504
 				$this->icServer->expunge($_folder);
3804 4505
 				break;
3805 4506
 		}
3806
-		if($oldMailbox != '') {
4507
+		if($oldMailbox != '')
4508
+		{
3807 4509
 			$this->icServer->openMailbox($oldMailbox);
3808 4510
 		}
3809 4511
 
@@ -3817,11 +4519,15 @@  discard block
 block discarded – undo
3817 4519
 	 *
3818 4520
 	 * @return null/array flags
3819 4521
 	 */
3820
-	function getFlags ($_messageUID) {
4522
+	function getFlags ($_messageUID)
4523
+	{
3821 4524
 		try
3822 4525
 		{
3823 4526
 			$uidsToFetch = new Horde_Imap_Client_Ids();
3824
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4527
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4528
+			{
4529
+				$_messageUID = (array)$_messageUID;
4530
+			}
3825 4531
 			$uidsToFetch->add($_messageUID);
3826 4532
 			$_folderName = $this->icServer->getCurrentMailbox();
3827 4533
 			$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -3829,8 +4535,10 @@  discard block
 block discarded – undo
3829 4535
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
3830 4536
 				'ids' => $uidsToFetch,
3831 4537
 			));
3832
-			if (is_object($headersNew)) {
3833
-				foreach($headersNew->ids() as $id) {
4538
+			if (is_object($headersNew))
4539
+			{
4540
+				foreach($headersNew->ids() as $id)
4541
+				{
3834 4542
 					$_headerObject = $headersNew->get($id);
3835 4543
 					$flags = $_headerObject->getFlags();
3836 4544
 				}
@@ -3855,10 +4563,16 @@  discard block
 block discarded – undo
3855 4563
 	 */
3856 4564
 	function getNotifyFlags ($_messageUID, $flags=null)
3857 4565
 	{
3858
-		if (self::$debug) error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
4566
+		if (self::$debug)
4567
+		{
4568
+			error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
4569
+		}
3859 4570
 		try
3860 4571
 		{
3861
-			if($flags===null) $flags =  $this->getFlags($_messageUID);
4572
+			if($flags===null)
4573
+			{
4574
+				$flags =  $this->getFlags($_messageUID);
4575
+			}
3862 4576
 		}
3863 4577
 		catch (\Exception $e)
3864 4578
 		{
@@ -3866,10 +4580,14 @@  discard block
 block discarded – undo
3866 4580
 		}
3867 4581
 
3868 4582
 		if ( stripos( array2string($flags),'MDNSent')!==false)
3869
-			return true;
4583
+		{
4584
+					return true;
4585
+		}
3870 4586
 
3871 4587
 		if ( stripos( array2string($flags),'MDNnotSent')!==false)
3872
-			return false;
4588
+		{
4589
+					return false;
4590
+		}
3873 4591
 
3874 4592
 		return null;
3875 4593
 	}
@@ -3890,7 +4608,10 @@  discard block
 block discarded – undo
3890 4608
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",$_folder /".$this->sessionData['mailbox']);
3891 4609
 		if (empty($_messageUID))
3892 4610
 		{
3893
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4611
+			if (self::$debug)
4612
+			{
4613
+				error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4614
+			}
3894 4615
 			return false;
3895 4616
 		}
3896 4617
 		$this->icServer->openMailbox(($_folder?$_folder:$this->sessionData['mailbox']));
@@ -3898,7 +4619,10 @@  discard block
 block discarded – undo
3898 4619
 		if (is_array($_messageUID)&& count($_messageUID)>50)
3899 4620
 		{
3900 4621
 			$count = $this->getMailBoxCounters($folder,true);
3901
-			if ($count->messages == count($_messageUID)) $_messageUID='all';
4622
+			if ($count->messages == count($_messageUID))
4623
+			{
4624
+				$_messageUID='all';
4625
+			}
3902 4626
 		}
3903 4627
 
3904 4628
 		if ($_messageUID==='all')
@@ -3907,7 +4631,10 @@  discard block
 block discarded – undo
3907 4631
 		}
3908 4632
 		else
3909 4633
 		{
3910
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4634
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4635
+			{
4636
+				$_messageUID = (array)$_messageUID;
4637
+			}
3911 4638
 			$messageUIDs = array_chunk($_messageUID,50,true);
3912 4639
 		}
3913 4640
 		try
@@ -3923,7 +4650,8 @@  discard block
 block discarded – undo
3923 4650
 					$uidsToModify = new Horde_Imap_Client_Ids();
3924 4651
 					$uidsToModify->add($uids);
3925 4652
 				}
3926
-				switch($_flag) {
4653
+				switch($_flag)
4654
+				{
3927 4655
 					case "delete":
3928 4656
 						$ret = $this->icServer->store($folder, array('add'=>array('\\Deleted'), 'ids'=> $uidsToModify));
3929 4657
 						break;
@@ -4009,7 +4737,10 @@  discard block
 block discarded – undo
4009 4737
 		{
4010 4738
 			error_log(__METHOD__.__LINE__.' Error, could not flag messages in folder '.$folder.' Reason:'.$e->getMessage());
4011 4739
 		}
4012
-		if ($folder instanceof Horde_Imap_Client_Mailbox) $_folder = $folder->utf8;
4740
+		if ($folder instanceof Horde_Imap_Client_Mailbox)
4741
+		{
4742
+			$_folder = $folder->utf8;
4743
+		}
4013 4744
 		//error_log(__METHOD__.__LINE__.'#'.$this->icServer->ImapServerId.'#'.array2string($_folder).'#');
4014 4745
 		self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])]['uidValidity'] = 0;
4015 4746
 
@@ -4038,7 +4769,10 @@  discard block
 block discarded – undo
4038 4769
 		//$deleteOptions  = $GLOBALS['egw_info']["user"]["preferences"]["mail"]["deleteOptions"];
4039 4770
 		if (empty($_messageUID))
4040 4771
 		{
4041
-			if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4772
+			if (self::$debug)
4773
+			{
4774
+				error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4775
+			}
4042 4776
 			return false;
4043 4777
 		}
4044 4778
 		elseif ($_messageUID==='all')
@@ -4050,7 +4784,10 @@  discard block
 block discarded – undo
4050 4784
 		{
4051 4785
 			//error_log(__METHOD__." Message(s): ".implode(',',$_messageUID));
4052 4786
 			$uidsToMove = new Horde_Imap_Client_Ids();
4053
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4787
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4788
+			{
4789
+				$_messageUID = (array)$_messageUID;
4790
+			}
4054 4791
 			$uidsToMove->add($_messageUID);
4055 4792
 		}
4056 4793
 		$sourceFolder = (!empty($currentFolder)?$currentFolder: $this->sessionData['mailbox']);
@@ -4072,12 +4809,14 @@  discard block
 block discarded – undo
4072 4809
 
4073 4810
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' mailheaders:'.array2string($headersNew));
4074 4811
 
4075
-			if (is_object($headersNew)) {
4812
+			if (is_object($headersNew))
4813
+			{
4076 4814
 				$c=0;
4077 4815
 				$retUid = new Horde_Imap_Client_Ids();
4078 4816
 				// we copy chunks of 5 to avoid too much memory and/or server stress
4079 4817
 				// some servers seem not to allow/support the appendig of multiple messages. so we are down to one
4080
-				foreach($headersNew as &$_headerObject) {
4818
+				foreach($headersNew as &$_headerObject)
4819
+				{
4081 4820
 					$c++;
4082 4821
 					$flags = $_headerObject->getFlags(); //unseen status seems to be lost when retrieving the full message
4083 4822
 					$date = $_headerObject->getImapDate();
@@ -4161,7 +4900,11 @@  discard block
 block discarded – undo
4161 4900
 	{
4162 4901
 		try {
4163 4902
 			$date = new DateTime($_date);	// parse date & time including timezone (throws exception, if not parsable)
4164
-			if ($convert2usertime) $date->setUser();	// convert to user-time
4903
+			if ($convert2usertime)
4904
+			{
4905
+				$date->setUser();
4906
+			}
4907
+			// convert to user-time
4165 4908
 			$date2return = $date->format($format);
4166 4909
 		}
4167 4910
 		catch(\Exception $e)
@@ -4193,9 +4936,15 @@  discard block
 block discarded – undo
4193 4936
 	static function htmlentities($_string, $_charset=false)
4194 4937
 	{
4195 4938
 		//setting the charset (if not given)
4196
-		if ($_charset===false) $_charset = self::$displayCharset;
4939
+		if ($_charset===false)
4940
+		{
4941
+			$_charset = self::$displayCharset;
4942
+		}
4197 4943
 		$string = @htmlentities($_string, ENT_QUOTES, $_charset, false);
4198
-		if (empty($string) && !empty($_string)) $string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
4944
+		if (empty($string) && !empty($_string))
4945
+		{
4946
+			$string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
4947
+		}
4199 4948
 		return $string;
4200 4949
 	}
4201 4950
 
@@ -4215,18 +4964,41 @@  discard block
 block discarded – undo
4215 4964
 		$_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>'),
4216 4965
 							 array('&amp;',    '<BR>',           '<BR>',             '<BR>',             '</font></td>','<td>',    '',         '',           '',  ''),$_html);
4217 4966
 		//$_html = str_replace(array('&amp;amp;'),array('&amp;'),$_html);
4218
-		if (stripos($_html,'style')!==false) Mail\Html::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags
4219
-		if (stripos($_html,'head')!==false) Mail\Html::replaceTagsCompletley($_html,'head'); // Strip out stuff in head
4967
+		if (stripos($_html,'style')!==false)
4968
+		{
4969
+			Mail\Html::replaceTagsCompletley($_html,'style');
4970
+		}
4971
+		// clean out empty or pagewide style definitions / left over tags
4972
+		if (stripos($_html,'head')!==false)
4973
+		{
4974
+			Mail\Html::replaceTagsCompletley($_html,'head');
4975
+		}
4976
+		// Strip out stuff in head
4220 4977
 		//if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false) Mail\Html::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false); // Strip out stuff in ifs
4221 4978
 		//if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false) Mail\Html::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false); // Strip out stuff in ifs
4222 4979
 		//error_log(__METHOD__.' ('.__LINE__.') '.$_html);
4223 4980
 
4224
-		if (get_magic_quotes_gpc() === 1) $_html = stripslashes($_html);
4981
+		if (get_magic_quotes_gpc() === 1)
4982
+		{
4983
+			$_html = stripslashes($_html);
4984
+		}
4225 4985
 		// Strip out doctype in head, as htmlLawed cannot handle it TODO: Consider extracting it and adding it afterwards
4226
-		if (stripos($_html,'!doctype')!==false) Mail\Html::replaceTagsCompletley($_html,'!doctype');
4227
-		if (stripos($_html,'?xml:namespace')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
4228
-		if (stripos($_html,'?xml version')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false);
4229
-		if (strpos($_html,'!CURSOR')!==false) Mail\Html::replaceTagsCompletley($_html,'!CURSOR');
4986
+		if (stripos($_html,'!doctype')!==false)
4987
+		{
4988
+			Mail\Html::replaceTagsCompletley($_html,'!doctype');
4989
+		}
4990
+		if (stripos($_html,'?xml:namespace')!==false)
4991
+		{
4992
+			Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
4993
+		}
4994
+		if (stripos($_html,'?xml version')!==false)
4995
+		{
4996
+			Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false);
4997
+		}
4998
+		if (strpos($_html,'!CURSOR')!==false)
4999
+		{
5000
+			Mail\Html::replaceTagsCompletley($_html,'!CURSOR');
5001
+		}
4230 5002
 		// htmLawed filter only the 'body'
4231 5003
 		//preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $_html, $matches);
4232 5004
 		//if ($matches[2])
@@ -4265,8 +5037,10 @@  discard block
 block discarded – undo
4265 5037
 		//$charSet = 'iso-8859-1';//self::$displayCharset; //'iso-8859-1'; // self::displayCharset seems to be asmarter fallback than iso-8859-1
4266 5038
 		$CharsetFound=false;
4267 5039
 		//echo "#".$_mimePartObject->encoding.'#<br>';
4268
-		if(is_array($_mimePartObject->parameters)) {
4269
-			if(isset($_mimePartObject->parameters['CHARSET'])) {
5040
+		if(is_array($_mimePartObject->parameters))
5041
+		{
5042
+			if(isset($_mimePartObject->parameters['CHARSET']))
5043
+			{
4270 5044
 				$charSet = $_mimePartObject->parameters['CHARSET'];
4271 5045
 				$CharsetFound=true;
4272 5046
 			}
@@ -4287,7 +5061,10 @@  discard block
 block discarded – undo
4287 5061
 	function decodeMimePart($_mimeMessage, $_encoding, $_charset = '')
4288 5062
 	{
4289 5063
 		// decode the part
4290
-		if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
5064
+		if (self::$debug)
5065
+		{
5066
+			error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
5067
+		}
4291 5068
 		switch (strtoupper($_encoding))
4292 5069
 		{
4293 5070
 			case 'BASE64':
@@ -4327,13 +5104,19 @@  discard block
 block discarded – undo
4327 5104
 		// sometimes there are 3 parts, when there is an ics/ical attached/included-> we want to show that
4328 5105
 		// as attachment AND as abstracted ical information (we use our notification style here).
4329 5106
 		$partText = $partCalendar = $partHTML = null;
4330
-		if (self::$debug) _debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
5107
+		if (self::$debug)
5108
+		{
5109
+			_debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
5110
+		}
4331 5111
 		//error_log(__METHOD__.' ('.__LINE__.') ');
4332 5112
 		$ignore_first_part = true;
4333 5113
 		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4334 5114
 		{
4335 5115
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type"." ignoreFirstPart:".$ignore_first_part);
4336
-			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5116
+			if (self::$debug)
5117
+			{
5118
+				echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5119
+			}
4337 5120
 
4338 5121
 			if ($ignore_first_part)
4339 5122
 			{
@@ -4349,11 +5132,17 @@  discard block
 block discarded – undo
4349 5132
 					switch($mimePart->getSubType())
4350 5133
 					{
4351 5134
 						case 'plain':
4352
-							if ($mimePart->getBytes() > 0) $partText = $mimePart;
5135
+							if ($mimePart->getBytes() > 0)
5136
+							{
5137
+								$partText = $mimePart;
5138
+							}
4353 5139
 							break;
4354 5140
 
4355 5141
 						case 'html':
4356
-							if ($mimePart->getBytes() > 0)  $partHTML = $mimePart;
5142
+							if ($mimePart->getBytes() > 0)
5143
+							{
5144
+								$partHTML = $mimePart;
5145
+							}
4357 5146
 							break;
4358 5147
 					}
4359 5148
 					break;
@@ -4366,7 +5155,10 @@  discard block
 block discarded – undo
4366 5155
 							if (count($mimePart->getParts()) > 1)
4367 5156
 							{
4368 5157
 								// in a multipart alternative we treat the multipart/related as html part
4369
-								if (self::$debug) error_log(__METHOD__." process MULTIPART/".$mimePart->getSubType()." with array as subparts");
5158
+								if (self::$debug)
5159
+								{
5160
+									error_log(__METHOD__." process MULTIPART/".$mimePart->getSubType()." with array as subparts");
5161
+								}
4370 5162
 								$partHTML = $mimePart;
4371 5163
 								break 3; // GET OUT OF LOOP, will be processed according to type
4372 5164
 							}
@@ -4447,9 +5239,15 @@  discard block
 block discarded – undo
4447 5239
 	 */
4448 5240
 	function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts=array())
4449 5241
 	{
4450
-		if (self::$debug) echo __METHOD__."$_uid, $_htmlMode<br>";
5242
+		if (self::$debug)
5243
+		{
5244
+			echo __METHOD__."$_uid, $_htmlMode<br>";
5245
+		}
4451 5246
 		$bodyPart = array();
4452
-		if (self::$debug) _debug_array($_structure);
5247
+		if (self::$debug)
5248
+		{
5249
+			_debug_array($_structure);
5250
+		}
4453 5251
 
4454 5252
 		$ignore_first_part = true;
4455 5253
 		//$skipParts = array();
@@ -4457,7 +5255,10 @@  discard block
 block discarded – undo
4457 5255
 		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4458 5256
 		{
4459 5257
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type");
4460
-			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5258
+			if (self::$debug)
5259
+			{
5260
+				echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5261
+			}
4461 5262
 			if ($ignore_first_part)
4462 5263
 			{
4463 5264
 				$ignore_first_part = false;
@@ -4475,7 +5276,10 @@  discard block
 block discarded – undo
4475 5276
 			switch($part->getPrimaryType())
4476 5277
 			{
4477 5278
 				case 'multipart':
4478
-					if ($part->getDisposition() == 'attachment') continue;
5279
+					if ($part->getDisposition() == 'attachment')
5280
+					{
5281
+						continue;
5282
+					}
4479 5283
 					switch($part->getSubType())
4480 5284
 					{
4481 5285
 						case 'alternative':
@@ -4540,7 +5344,9 @@  discard block
 block discarded – undo
4540 5344
 					if($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment')
4541 5345
 					{
4542 5346
 						$skipParts[$mime_id.'.0'] = $mime_type;
4543
-						foreach($part->contentTypeMap() as $sub_id => $sub_type){ $skipParts[$sub_id] = $sub_type;}
5347
+						foreach($part->contentTypeMap() as $sub_id => $sub_type)
5348
+						{
5349
+$skipParts[$sub_id] = $sub_type;}
4544 5350
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$_uid.' Part:'.$mime_id.':'.array2string($skipParts));
4545 5351
 						//break 2;
4546 5352
 					}
@@ -4583,7 +5389,10 @@  discard block
 block discarded – undo
4583 5389
 	 */
4584 5390
 	function getBodyPart($_uid, $_partID=null, $_folder=null, $_preserveSeen=false, $_stream=false, &$_encoding=null, $_tryDecodingServerside=true)
4585 5391
 	{
4586
-		if (self::$debug) error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
5392
+		if (self::$debug)
5393
+		{
5394
+			error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
5395
+		}
4587 5396
 
4588 5397
 		if (empty($_folder))
4589 5398
 		{
@@ -4592,7 +5401,10 @@  discard block
 block discarded – undo
4592 5401
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_folder).'/'.$this->icServer->getCurrentMailbox().'/'. $this->sessionData['mailbox']);
4593 5402
 		// querying contents of body part
4594 5403
 		$uidsToFetch = new Horde_Imap_Client_Ids();
4595
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5404
+		if (!(is_object($_uid) || is_array($_uid)))
5405
+		{
5406
+			$_uid = (array)$_uid;
5407
+		}
4596 5408
 		$uidsToFetch->add($_uid);
4597 5409
 
4598 5410
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -4600,9 +5412,12 @@  discard block
 block discarded – undo
4600 5412
 			'peek' => $_preserveSeen,
4601 5413
 			'decode' => true,	// try decode on server, does NOT neccessary work
4602 5414
 		);
4603
-		if ($_tryDecodingServerside===false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
5415
+		if ($_tryDecodingServerside===false)
5416
+		{
5417
+			// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
4604 5418
 		{
4605 5419
 			$_tryDecodingServerside=false;
5420
+		}
4606 5421
 			$fetchParams = array(
4607 5422
 				'peek' => $_preserveSeen,
4608 5423
 			);
@@ -4644,7 +5459,10 @@  discard block
 block discarded – undo
4644 5459
 	{
4645 5460
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_uid.':'.array2string($_structure).' '.function_backtrace());
4646 5461
 		$bodyPart = array();
4647
-		if (self::$debug) _debug_array(array($_structure,function_backtrace()));
5462
+		if (self::$debug)
5463
+		{
5464
+			_debug_array(array($_structure,function_backtrace()));
5465
+		}
4648 5466
 
4649 5467
 		if($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text')))
4650 5468
 		{
@@ -4694,8 +5512,12 @@  discard block
 block discarded – undo
4694 5512
 	 */
4695 5513
 	function getMessageBody($_uid, $_htmlOptions='', $_partID=null, Horde_Mime_Part $_structure=null, $_preserveSeen = false, $_folder = '')
4696 5514
 	{
4697
-		if (self::$debug) echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
4698
-		if($_htmlOptions != '') {
5515
+		if (self::$debug)
5516
+		{
5517
+			echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
5518
+		}
5519
+		if($_htmlOptions != '')
5520
+		{
4699 5521
 			$this->htmlOptions = $_htmlOptions;
4700 5522
 		}
4701 5523
 		if (empty($_folder))
@@ -4784,7 +5606,9 @@  discard block
 block discarded – undo
4784 5606
 						default:
4785 5607
 							$bodyPart = array($this->getTextPart($_uid, $_structure, $this->htmlOptions, $_preserveSeen));
4786 5608
 					}
4787
-				} else {
5609
+				}
5610
+				else
5611
+				{
4788 5612
 					// what if the structure->disposition is attachment ,...
4789 5613
 				}
4790 5614
 				return self::normalizeBodyParts($bodyPart);
@@ -4795,13 +5619,18 @@  discard block
 block discarded – undo
4795 5619
 				{
4796 5620
 					case 'rfc822':
4797 5621
 						$newStructure = $_structure->getParts();
4798
-						if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
5622
+						if (self::$debug)
5623
+						{
5624
+echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
4799 5625
 						return self::normalizeBodyParts($this->getMessageBody($_uid, $_htmlOptions, $newStructure[0]->getMimeId(), $newStructure[0], $_preserveSeen, $_folder));
4800 5626
 				}
4801 5627
 				break;
4802 5628
 
4803 5629
 			default:
4804
-				if (self::$debug) _debug_array($_structure);
5630
+				if (self::$debug)
5631
+				{
5632
+					_debug_array($_structure);
5633
+				}
4805 5634
 				return array(
4806 5635
 					array(
4807 5636
 						'body'		=> lang('The mimeparser can not parse this message.').$_structure->getType(),
@@ -4825,9 +5654,12 @@  discard block
 block discarded – undo
4825 5654
 		{
4826 5655
 			foreach($_bodyParts as $singleBodyPart)
4827 5656
 			{
4828
-				if (!isset($singleBodyPart['body'])) {
5657
+				if (!isset($singleBodyPart['body']))
5658
+				{
4829 5659
 					$buff = self::normalizeBodyParts($singleBodyPart);
4830
-					foreach ((array)$buff as $val) { $body2return[] = $val;}
5660
+					foreach ((array)$buff as $val)
5661
+					{
5662
+$body2return[] = $val;}
4831 5663
 					continue;
4832 5664
 				}
4833 5665
 				$body2return[] = $singleBodyPart;
@@ -4853,13 +5685,20 @@  discard block
 block discarded – undo
4853 5685
 		$message='';
4854 5686
 		for($i=0; $i<count($bodyParts); $i++)
4855 5687
 		{
4856
-			if (!isset($bodyParts[$i]['body'])) {
5688
+			if (!isset($bodyParts[$i]['body']))
5689
+			{
4857 5690
 				$bodyParts[$i]['body'] = self::getdisplayableBody($mailClass, $bodyParts[$i], $preserveHTML, $useTidy);
4858 5691
 				$message .= empty($bodyParts[$i]['body'])?'':$bodyParts[$i]['body'];
4859 5692
 				continue;
4860 5693
 			}
4861
-			if (isset($bodyParts[$i]['error'])) continue;
4862
-			if (empty($bodyParts[$i]['body'])) continue;
5694
+			if (isset($bodyParts[$i]['error']))
5695
+			{
5696
+				continue;
5697
+			}
5698
+			if (empty($bodyParts[$i]['body']))
5699
+			{
5700
+				continue;
5701
+			}
4863 5702
 			// some characterreplacements, as they fail to translate
4864 5703
 			$sar = array(
4865 5704
 				'@(\x84|\x93|\x94)@',
@@ -4886,13 +5725,17 @@  discard block
 block discarded – undo
4886 5725
 				$bodyParts[$i]['body'] = preg_replace($sar,$rar,$bodyParts[$i]['body']);
4887 5726
 			}
4888 5727
 
4889
-			if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
5728
+			if ($bodyParts[$i]['charSet']===false)
5729
+			{
5730
+				$bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
5731
+			}
4890 5732
 			// add line breaks to $bodyParts
4891 5733
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
4892 5734
 			$newBody  = Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
4893 5735
 			//error_log(__METHOD__.' ('.__LINE__.') '.' MimeType:'.$bodyParts[$i]['mimeType'].'->'.$newBody);
4894 5736
 			$mailClass->activeMimeType = 'text/plain';
4895
-			if ($bodyParts[$i]['mimeType'] == 'text/html') {
5737
+			if ($bodyParts[$i]['mimeType'] == 'text/html')
5738
+			{
4896 5739
 				$mailClass->activeMimeType = $bodyParts[$i]['mimeType'];
4897 5740
 				if (!$preserveHTML)
4898 5741
 				{
@@ -4938,15 +5781,28 @@  discard block
 block discarded – undo
4938 5781
 						// as we switched off HTMLaweds tidy functionality
4939 5782
 						$newBody = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<BR>','<BR>','<BR>'),$newBody);
4940 5783
 						$newBody = $htmLawed->run($newBody,self::$htmLawed_config);
4941
-						if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3];
5784
+						if ($hasOther && $preserveHTML)
5785
+						{
5786
+							$newBody = $matches[1]. $newBody. $matches[3];
5787
+						}
4942 5788
 						$alreadyHtmlLawed=true;
4943 5789
 					}
4944 5790
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after purify:'.$newBody);
4945
-					if ($preserveHTML==false) $newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true);
5791
+					if ($preserveHTML==false)
5792
+					{
5793
+						$newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true);
5794
+					}
4946 5795
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after convertHTMLToText:'.$newBody);
4947
-					if ($preserveHTML==false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n
5796
+					if ($preserveHTML==false)
5797
+					{
5798
+						$newBody = nl2br($newBody);
5799
+					}
5800
+					// we need this, as htmLawed removes \r\n
4948 5801
 					/*if (!$alreadyHtmlLawed) */ $mailClass->getCleanHTML($newBody); // remove stuff we regard as unwanted
4949
-					if ($preserveHTML==false) $newBody = str_replace("<br />","\r\n",$newBody);
5802
+					if ($preserveHTML==false)
5803
+					{
5804
+						$newBody = str_replace("<br />","\r\n",$newBody);
5805
+					}
4950 5806
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after getClean:'.$newBody);
4951 5807
 				}
4952 5808
 				$message .= $newBody;
@@ -4983,12 +5839,12 @@  discard block
 block discarded – undo
4983 5839
 				  substr($line,0,strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
4984 5840
 				 )
4985 5841
 				)
4986
-			   )
4987
-			{
5842
+			   ) {
4988 5843
 				$s=explode(" ", $line);
4989 5844
 				$line = "";
4990 5845
 				$linecnt = 0;
4991
-				foreach ($s as &$v) {
5846
+				foreach ($s as &$v)
5847
+				{
4992 5848
 					$cnt = strlen($v);
4993 5849
 					// only break long words within the wordboundaries,
4994 5850
 					// but it may destroy links, so we check for href and dont do it if we find one
@@ -4998,14 +5854,20 @@  discard block
 block discarded – undo
4998 5854
 						$v=wordwrap($v, $allowedLength, $cut, true);
4999 5855
 					}
5000 5856
 					// the rest should be broken at the start of the new word that exceeds the limit
5001
-					if ($linecnt+$cnt > $allowedLength) {
5857
+					if ($linecnt+$cnt > $allowedLength)
5858
+					{
5002 5859
 						$v=$cut.$v;
5003 5860
 						#$linecnt = 0;
5004 5861
 						$linecnt =strlen($v)-strlen($cut);
5005
-					} else {
5862
+					}
5863
+					else
5864
+					{
5006 5865
 						$linecnt += $cnt;
5007 5866
 					}
5008
-					if (strlen($v)) $line .= (strlen($line) ? " " : "").$v;
5867
+					if (strlen($v))
5868
+					{
5869
+						$line .= (strlen($line) ? " " : "").$v;
5870
+					}
5009 5871
 				}
5010 5872
 			}
5011 5873
 			$newStr .= $line . "\n";
@@ -5026,11 +5888,18 @@  discard block
 block discarded – undo
5026 5888
 	function getMessageEnvelope($_uid, $_partID = '',$decode=false, $_folder='', $_useHeaderInsteadOfEnvelope=false)
5027 5889
 	{
5028 5890
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder".function_backtrace());
5029
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5891
+		if (empty($_folder))
5892
+		{
5893
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5894
+		}
5030 5895
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder");
5031
-		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false) {
5896
+		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false)
5897
+		{
5032 5898
 			$uidsToFetch = new Horde_Imap_Client_Ids();
5033
-			if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5899
+			if (!(is_object($_uid) || is_array($_uid)))
5900
+			{
5901
+				$_uid = (array)$_uid;
5902
+			}
5034 5903
 			$uidsToFetch->add($_uid);
5035 5904
 
5036 5905
 			$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5040,8 +5909,10 @@  discard block
 block discarded – undo
5040 5909
 			$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5041 5910
 				'ids' => $uidsToFetch,
5042 5911
 			));
5043
-			if (is_object($headersNew)) {
5044
-				foreach($headersNew as &$_headerObject) {
5912
+			if (is_object($headersNew))
5913
+			{
5914
+				foreach($headersNew as &$_headerObject)
5915
+				{
5045 5916
 					$env = $_headerObject->getEnvelope();
5046 5917
 					//_debug_array($envFields->singleFields());
5047 5918
 					$singleFields = $envFields->singleFields();
@@ -5058,7 +5929,10 @@  discard block
 block discarded – undo
5058 5929
 								//error_log(__METHOD__.' ('.__LINE__.') '.$v.'->'.array2string($env->$v->addresses));
5059 5930
 								$envelope[$v]=$env->$v->addresses;
5060 5931
 								$address = array();
5061
-								if (!is_array($envelope[$v])) break;
5932
+								if (!is_array($envelope[$v]))
5933
+								{
5934
+									break;
5935
+								}
5062 5936
 								foreach ($envelope[$v] as $k => $ad)
5063 5937
 								{
5064 5938
 									if (stripos($ad,'@')===false)
@@ -5095,7 +5969,9 @@  discard block
 block discarded – undo
5095 5969
 				}
5096 5970
 			}
5097 5971
 			return $envelope;
5098
-		} else {
5972
+		}
5973
+		else
5974
+		{
5099 5975
 
5100 5976
 			$headers = $this->getMessageHeader($_uid, $_partID, true,true,$_folder);
5101 5977
 
@@ -5106,19 +5982,43 @@  discard block
 block discarded – undo
5106 5982
 				'SUBJECT'	=> ($decode ? self::decode_header($headers['SUBJECT']):$headers['SUBJECT']),
5107 5983
 				'MESSAGE_ID'	=> $headers['MESSAGE-ID']
5108 5984
 			);
5109
-			if (isset($headers['IN-REPLY-TO'])) $newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
5110
-			if (isset($headers['REFERENCES'])) $newData['REFERENCES'] = $headers['REFERENCES'];
5111
-			if (isset($headers['THREAD-TOPIC'])) $newData['THREAD-TOPIC'] = $headers['THREAD-TOPIC'];
5112
-			if (isset($headers['THREAD-INDEX'])) $newData['THREAD-INDEX'] = $headers['THREAD-INDEX'];
5113
-			if (isset($headers['LIST-ID'])) $newData['LIST-ID'] = $headers['LIST-ID'];
5114
-			if (isset($headers['SIZE'])) $newData['SIZE'] = $headers['SIZE'];
5985
+			if (isset($headers['IN-REPLY-TO']))
5986
+			{
5987
+				$newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
5988
+			}
5989
+			if (isset($headers['REFERENCES']))
5990
+			{
5991
+				$newData['REFERENCES'] = $headers['REFERENCES'];
5992
+			}
5993
+			if (isset($headers['THREAD-TOPIC']))
5994
+			{
5995
+				$newData['THREAD-TOPIC'] = $headers['THREAD-TOPIC'];
5996
+			}
5997
+			if (isset($headers['THREAD-INDEX']))
5998
+			{
5999
+				$newData['THREAD-INDEX'] = $headers['THREAD-INDEX'];
6000
+			}
6001
+			if (isset($headers['LIST-ID']))
6002
+			{
6003
+				$newData['LIST-ID'] = $headers['LIST-ID'];
6004
+			}
6005
+			if (isset($headers['SIZE']))
6006
+			{
6007
+				$newData['SIZE'] = $headers['SIZE'];
6008
+			}
5115 6009
 			//_debug_array($newData);
5116 6010
 			$recepientList = array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO');
5117
-			foreach($recepientList as $recepientType) {
5118
-				if(isset($headers[$recepientType])) {
5119
-					if ($decode) $headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
6011
+			foreach($recepientList as $recepientType)
6012
+			{
6013
+				if(isset($headers[$recepientType]))
6014
+				{
6015
+					if ($decode)
6016
+					{
6017
+						$headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
6018
+					}
5120 6019
 					//error_log(__METHOD__.__LINE__." ".$recepientType."->".array2string($headers[$recepientType]));
5121
-					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress) {
6020
+					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress)
6021
+					{
5122 6022
 						$addressData = array(
5123 6023
 							'PERSONAL_NAME'		=> $singleAddress->personal ? $singleAddress->personal : 'NIL',
5124 6024
 							'AT_DOMAIN_LIST'	=> $singleAddress->adl ? $singleAddress->adl : 'NIL',
@@ -5126,17 +6026,25 @@  discard block
 block discarded – undo
5126 6026
 							'HOST_NAME'		=> $singleAddress->host ? $singleAddress->host : 'NIL',
5127 6027
 							'EMAIL'			=> $singleAddress->host ? $singleAddress->mailbox.'@'.$singleAddress->host : $singleAddress->mailbox,
5128 6028
 						);
5129
-						if($addressData['PERSONAL_NAME'] != 'NIL') {
6029
+						if($addressData['PERSONAL_NAME'] != 'NIL')
6030
+						{
5130 6031
 							$addressData['RFC822_EMAIL'] = imap_rfc822_write_address($singleAddress->mailbox, $singleAddress->host, $singleAddress->personal);
5131
-						} else {
6032
+						}
6033
+						else
6034
+						{
5132 6035
 							$addressData['RFC822_EMAIL'] = 'NIL';
5133 6036
 						}
5134 6037
 						$newData[$recepientType][] = ($addressData['RFC822_EMAIL']!='NIL'?$addressData['RFC822_EMAIL']:$addressData['EMAIL']);//$addressData;
5135 6038
 					}
5136
-				} else {
5137
-					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') {
6039
+				}
6040
+				else
6041
+				{
6042
+					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO')
6043
+					{
5138 6044
 						$newData[$recepientType] = $newData['FROM'];
5139
-					} else {
6045
+					}
6046
+					else
6047
+					{
5140 6048
 						$newData[$recepientType] = array();
5141 6049
 					}
5142 6050
 				}
@@ -5159,9 +6067,15 @@  discard block
 block discarded – undo
5159 6067
 	function getMessageHeader($_uid, $_partID = '',$decode=false, $preserveUnSeen=false, $_folder='')
5160 6068
 	{
5161 6069
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$_uid.', '.$_partID.', '.$decode.', '.$preserveUnSeen.', '.$_folder);
5162
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6070
+		if (empty($_folder))
6071
+		{
6072
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6073
+		}
5163 6074
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5164
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6075
+		if (!(is_object($_uid) || is_array($_uid)))
6076
+		{
6077
+			$_uid = (array)$_uid;
6078
+		}
5165 6079
 		$uidsToFetch->add($_uid);
5166 6080
 
5167 6081
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5179,7 +6093,8 @@  discard block
 block discarded – undo
5179 6093
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5180 6094
 			'ids' => $uidsToFetch,
5181 6095
 		));
5182
-		if (is_object($headersNew)) {
6096
+		if (is_object($headersNew))
6097
+		{
5183 6098
 			foreach($headersNew as $_fetchObject)
5184 6099
 			{
5185 6100
 				$headers = $_fetchObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
@@ -5201,11 +6116,17 @@  discard block
 block discarded – undo
5201 6116
 			}
5202 6117
 			if ($decode === 'object')
5203 6118
 			{
5204
-				if (is_object($headers)) $headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
6119
+				if (is_object($headers))
6120
+				{
6121
+					$headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
6122
+				}
5205 6123
 				return $headers;
5206 6124
 			}
5207 6125
 			$retValue = is_object($headers) ? $headers->toArray():array();
5208
-			if ($size) $retValue['size'] = $size;
6126
+			if ($size)
6127
+			{
6128
+				$retValue['size'] = $size;
6129
+			}
5209 6130
 		}
5210 6131
 		$retValue = array_change_key_case($retValue,CASE_UPPER);
5211 6132
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue));
@@ -5237,10 +6158,16 @@  discard block
 block discarded – undo
5237 6158
 	function getMessageRawHeader($_uid, $_partID = '', $_folder = '')
5238 6159
 	{
5239 6160
 		static $rawHeaders;
5240
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6161
+		if (empty($_folder))
6162
+		{
6163
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6164
+		}
5241 6165
 		//error_log(__METHOD__.' ('.__LINE__.') '." Try Using Cache for raw Header $_uid, $_partID in Folder $_folder");
5242 6166
 
5243
-		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);
6167
+		if (is_null($rawHeaders)||!is_array($rawHeaders))
6168
+		{
6169
+			$rawHeaders = Cache::getCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
6170
+		}
5244 6171
 		if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5245 6172
 		{
5246 6173
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Header $_uid, $_partID in Folder $_folder");
@@ -5248,7 +6175,10 @@  discard block
 block discarded – undo
5248 6175
 		}
5249 6176
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5250 6177
 		$uid = $_uid;
5251
-		if (!(is_object($_uid) || is_array($_uid))) $uid = (array)$_uid;
6178
+		if (!(is_object($_uid) || is_array($_uid)))
6179
+		{
6180
+			$uid = (array)$_uid;
6181
+		}
5252 6182
 		$uidsToFetch->add($uid);
5253 6183
 
5254 6184
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5264,8 +6194,10 @@  discard block
 block discarded – undo
5264 6194
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5265 6195
 			'ids' => $uidsToFetch,
5266 6196
 		));
5267
-		if (is_object($headersNew)) {
5268
-			foreach($headersNew as &$_headerObject) {
6197
+		if (is_object($headersNew))
6198
+		{
6199
+			foreach($headersNew as &$_headerObject)
6200
+			{
5269 6201
 				$retValue = $_headerObject->getHeaderText();
5270 6202
 				if ($_partID != '')
5271 6203
 				{
@@ -5293,22 +6225,33 @@  discard block
 block discarded – undo
5293 6225
 	static function &getStyles($_bodyParts)
5294 6226
 	{
5295 6227
 		$style = '';
5296
-		if (empty($_bodyParts)) return "";
5297
-		foreach((array)$_bodyParts as $singleBodyPart) {
5298
-			if (!isset($singleBodyPart['body'])) {
6228
+		if (empty($_bodyParts))
6229
+		{
6230
+			return "";
6231
+		}
6232
+		foreach((array)$_bodyParts as $singleBodyPart)
6233
+		{
6234
+			if (!isset($singleBodyPart['body']))
6235
+			{
5299 6236
 				$singleBodyPart['body'] = self::getStyles($singleBodyPart);
5300 6237
 				$style .= $singleBodyPart['body'];
5301 6238
 				continue;
5302 6239
 			}
5303 6240
 
5304
-			if ($singleBodyPart['charSet']===false) $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
6241
+			if ($singleBodyPart['charSet']===false)
6242
+			{
6243
+				$singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
6244
+			}
5305 6245
 			$singleBodyPart['body'] = Translation::convert(
5306 6246
 				$singleBodyPart['body'],
5307 6247
 				strtolower($singleBodyPart['charSet'])
5308 6248
 			);
5309 6249
 			$ct = 0;
5310 6250
 			$newStyle=array();
5311
-			if (stripos($singleBodyPart['body'],'<style')!==false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
6251
+			if (stripos($singleBodyPart['body'],'<style')!==false)
6252
+			{
6253
+				$ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
6254
+			}
5312 6255
 			if ($ct>0)
5313 6256
 			{
5314 6257
 				//error_log(__METHOD__.' ('.__LINE__.') '.'#'.$ct.'#'.array2string($newStyle));
@@ -5340,7 +6283,11 @@  discard block
 block discarded – undo
5340 6283
 		// CSS Security
5341 6284
 		// http://code.google.com/p/browsersec/wiki/Part1#Cascading_stylesheets
5342 6285
 		$css = preg_replace('/(javascript|expression|-moz-binding)/i','',$style);
5343
-		if (stripos($css,'script')!==false) Mail\Html::replaceTagsCompletley($css,'script'); // Strip out script that may be included
6286
+		if (stripos($css,'script')!==false)
6287
+		{
6288
+			Mail\Html::replaceTagsCompletley($css,'script');
6289
+		}
6290
+		// Strip out script that may be included
5344 6291
 		// 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
5345 6292
 		// as the comments as <!-- styledefinition --> in stylesheet are outdated, and ck-editor does not understand it, we remove it
5346 6293
 		$css = str_replace(array(':','<!--','-->'),array(': ','',''),$css);
@@ -5361,8 +6308,14 @@  discard block
 block discarded – undo
5361 6308
 	{
5362 6309
 		//TODO: caching einbauen static!
5363 6310
 		static $rawBody;
5364
-		if (is_null($rawBody)) $rawBody = array();
5365
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6311
+		if (is_null($rawBody))
6312
+		{
6313
+			$rawBody = array();
6314
+		}
6315
+		if (empty($_folder))
6316
+		{
6317
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6318
+		}
5366 6319
 		if (isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5367 6320
 		{
5368 6321
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Body $_uid, $_partID in Folder $_folder");
@@ -5371,7 +6324,10 @@  discard block
 block discarded – undo
5371 6324
 
5372 6325
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5373 6326
 		$uid = $_uid;
5374
-		if (!(is_object($_uid) || is_array($_uid))) $uid = (array)$_uid;
6327
+		if (!(is_object($_uid) || is_array($_uid)))
6328
+		{
6329
+			$uid = (array)$_uid;
6330
+		}
5375 6331
 		$uidsToFetch->add($uid);
5376 6332
 
5377 6333
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5384,8 +6340,10 @@  discard block
 block discarded – undo
5384 6340
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5385 6341
 			'ids' => $uidsToFetch,
5386 6342
 		));
5387
-		if (is_object($headersNew)) {
5388
-			foreach($headersNew as &$_headerObject) {
6343
+		if (is_object($headersNew))
6344
+		{
6345
+			foreach($headersNew as &$_headerObject)
6346
+			{
5389 6347
 				$body = $_headerObject->getFullMsg();
5390 6348
 				if ($_partID != '')
5391 6349
 				{
@@ -5418,14 +6376,20 @@  discard block
 block discarded – undo
5418 6376
 	 */
5419 6377
 	function getStructure($_uid, $_partID=null, $_folder=null, $_preserveSeen=false)
5420 6378
 	{
5421
-		if (self::$debug) error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
6379
+		if (self::$debug)
6380
+		{
6381
+			error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
6382
+		}
5422 6383
 
5423 6384
 		if (empty($_folder))
5424 6385
 		{
5425 6386
 			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5426 6387
 		}
5427 6388
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5428
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6389
+		if (!(is_object($_uid) || is_array($_uid)))
6390
+		{
6391
+			$_uid = (array)$_uid;
6392
+		}
5429 6393
 		$uidsToFetch->add($_uid);
5430 6394
 		try
5431 6395
 		{
@@ -5434,7 +6398,10 @@  discard block
 block discarded – undo
5434 6398
 	//		$fquery->envelope();
5435 6399
 	//		$fquery->size();
5436 6400
 			$_fquery->structure();
5437
-			if ($_partID) $_fquery->bodyPart($_partID, array('peek' => $_preserveSeen));
6401
+			if ($_partID)
6402
+			{
6403
+				$_fquery->bodyPart($_partID, array('peek' => $_preserveSeen));
6404
+			}
5438 6405
 
5439 6406
 			$mail = $this->icServer->fetch($_folder, $_fquery, array(
5440 6407
 				'ids' => $uidsToFetch,
@@ -5465,16 +6432,28 @@  discard block
 block discarded – undo
5465 6432
 	 */
5466 6433
 	function getMessageAttachments($_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folder='')
5467 6434
 	{
5468
-		if (self::$debug) error_log( __METHOD__.":$_uid, $_partID");
5469
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6435
+		if (self::$debug)
6436
+		{
6437
+			error_log( __METHOD__.":$_uid, $_partID");
6438
+		}
6439
+		if (empty($_folder))
6440
+		{
6441
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6442
+		}
5470 6443
 		$attachments = array();
5471 6444
 		if (!isset($_structure))
5472 6445
 		{
5473 6446
 			$_structure = $this->getStructure($_uid, $_partID,$_folder,true);
5474 6447
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.print_r($_structure->contentTypeMap(),true));
5475 6448
 		}
5476
-		if (!$_structure || !$_structure->contentTypeMap()) return array();
5477
-		if (!empty($_partID)) $_structure = $_structure->getPart($_partID);
6449
+		if (!$_structure || !$_structure->contentTypeMap())
6450
+		{
6451
+			return array();
6452
+		}
6453
+		if (!empty($_partID))
6454
+		{
6455
+			$_structure = $_structure->getPart($_partID);
6456
+		}
5478 6457
 		$skipParts = array();
5479 6458
 		$tnefParts = array();
5480 6459
 		$skip = 0;
@@ -5503,7 +6482,13 @@  discard block
 block discarded – undo
5503 6482
 			if ($mime_type=='message/rfc822' && $_partID!=$mime_id)
5504 6483
 			{
5505 6484
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
5506
-				foreach($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
6485
+				foreach($part->contentTypeMap() as $sub_id => $sub_type)
6486
+				{
6487
+if ($sub_id != $mime_id)
6488
+				{
6489
+					$skipParts[$sub_id] = $sub_type;
6490
+				}
6491
+				}
5507 6492
 			}
5508 6493
 			if (empty($partDisposition) && $partPrimaryType != 'multipart' && $partPrimaryType != 'text')
5509 6494
 			{
@@ -5514,7 +6499,10 @@  discard block
 block discarded – undo
5514 6499
 				$partDisposition='attachment';
5515 6500
 			}
5516 6501
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($skipParts));
5517
-			if (array_key_exists($mime_id,$skipParts)) continue;
6502
+			if (array_key_exists($mime_id,$skipParts))
6503
+			{
6504
+				continue;
6505
+			}
5518 6506
 
5519 6507
 			if ($partDisposition == 'attachment' ||
5520 6508
 				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId()=='') ||
@@ -5525,23 +6513,41 @@  discard block
 block discarded – undo
5525 6513
 			{
5526 6514
 				// if type is message/rfc822 and _partID is given, and MimeID equals partID
5527 6515
 				// we attempt to fetch "ourselves"
5528
-				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message') continue;
6516
+				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message')
6517
+				{
6518
+					continue;
6519
+				}
5529 6520
 				$attachment = $part->getAllDispositionParameters();
5530 6521
 				$attachment['disposition'] = $part->getDisposition();
5531 6522
 				$attachment['mimeType'] = $mime_type;
5532 6523
 				$attachment['uid'] = $_uid;
5533 6524
 				$attachment['partID'] = $mime_id;
5534
-				if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
6525
+				if (!isset($attachment['name'])||empty($attachment['name']))
6526
+				{
6527
+					$attachment['name'] = $part->getName();
6528
+				}
5535 6529
 				if ($fetchTextCalendar)
5536 6530
 				{
5537 6531
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part->getAllContentTypeParameters()));
5538 6532
 					$method = $part->getContentTypeParameter('method');
5539
-					if ($method) $attachment['method'] = $method;
5540
-					if (!isset($attachment['name'])) $attachment['name'] = 'event.ics';
6533
+					if ($method)
6534
+					{
6535
+						$attachment['method'] = $method;
6536
+					}
6537
+					if (!isset($attachment['name']))
6538
+					{
6539
+						$attachment['name'] = 'event.ics';
6540
+					}
5541 6541
 				}
5542 6542
 				$attachment['size'] = $part->getBytes();
5543
-				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5544
-				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);
6543
+				if (($cid = $part->getContentId()))
6544
+				{
6545
+					$attachment['cid'] = $cid;
6546
+				}
6547
+				if (empty($attachment['name']))
6548
+				{
6549
+					$attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($mime_type);
6550
+				}
5545 6551
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($attachment));
5546 6552
 				//typical winmail.dat attachment is
5547 6553
 				//Array([size] => 1462762[filename] => winmail.dat[mimeType] => application/ms-tnef[uid] => 100[partID] => 2[name] => winmail.dat)
@@ -5577,14 +6583,26 @@  discard block
 block discarded – undo
5577 6583
 						$attachment['uid'] = $tnp['uid'];
5578 6584
 						$attachment['partID'] = $tnp['partID'];
5579 6585
 						$attachment['is_winmail'] = $tnp['uid'].'@'.$tnp['partID'].'@'.$mime_id;
5580
-						if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
6586
+						if (!isset($attachment['name'])||empty($attachment['name']))
6587
+						{
6588
+							$attachment['name'] = $part->getName();
6589
+						}
5581 6590
 						$attachment['size'] = $part->getBytes();
5582
-						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5583
-						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']);
6591
+						if (($cid = $part->getContentId()))
6592
+						{
6593
+							$attachment['cid'] = $cid;
6594
+						}
6595
+						if (empty($attachment['name']))
6596
+						{
6597
+							$attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
6598
+						}
5584 6599
 						$attachments[] = $attachment;
5585 6600
 					}
5586 6601
 				}
5587
-				if ($tnefResolved===false) $attachments[]=$tnp;
6602
+				if ($tnefResolved===false)
6603
+				{
6604
+					$attachments[]=$tnp;
6605
+				}
5588 6606
 			}
5589 6607
 		}
5590 6608
 		//error_log(__METHOD__.__LINE__.array2string($attachments));
@@ -5688,8 +6706,14 @@  discard block
 block discarded – undo
5688 6706
 
5689 6707
 				$attachment = $part->getAllDispositionParameters();
5690 6708
 				$attachment['mimeType'] = $part->getType();
5691
-				if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5692
-				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
6709
+				if (!isset($attachment['filename'])||empty($attachment['filename']))
6710
+				{
6711
+					$attachment['filename'] = $part->getName();
6712
+				}
6713
+				if (($cid = $part->getContentId()))
6714
+				{
6715
+					$attachment['cid'] = $cid;
6716
+				}
5693 6717
 				if (empty($attachment['filename']))
5694 6718
 				{
5695 6719
 					$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?
@@ -5701,7 +6725,10 @@  discard block
 block discarded – undo
5701 6725
 				$attachments[$_uid.'@'.$_partID.'@'.$mime_id] = $attachment;
5702 6726
 			}
5703 6727
 		}
5704
-		if (!is_array($attachments)) return false;
6728
+		if (!is_array($attachments))
6729
+		{
6730
+			return false;
6731
+		}
5705 6732
 		return $attachments;
5706 6733
 	}
5707 6734
 
@@ -5720,10 +6747,16 @@  discard block
 block discarded – undo
5720 6747
 	function getAttachment($_uid, $_partID, $_winmail_nr=0, $_returnPart=true, $_stream=false, $_folder=null)
5721 6748
 	{
5722 6749
 		//error_log(__METHOD__.__LINE__."Uid:$_uid, PartId:$_partID, WinMailNr:$_winmail_nr, ReturnPart:$_returnPart, Stream:$_stream, Folder:$_folder".function_backtrace());
5723
-		if (!isset($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6750
+		if (!isset($_folder))
6751
+		{
6752
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6753
+		}
5724 6754
 
5725 6755
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5726
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6756
+		if (!(is_object($_uid) || is_array($_uid)))
6757
+		{
6758
+			$_uid = (array)$_uid;
6759
+		}
5727 6760
 		$uidsToFetch->add($_uid);
5728 6761
 
5729 6762
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5732,8 +6765,10 @@  discard block
 block discarded – undo
5732 6765
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5733 6766
 			'ids' => $uidsToFetch,
5734 6767
 		));
5735
-		if (is_object($headersNew)) {
5736
-			foreach($headersNew as $id=>$_headerObject) {
6768
+		if (is_object($headersNew))
6769
+		{
6770
+			foreach($headersNew as $id=>$_headerObject)
6771
+			{
5737 6772
 				$body = $_headerObject->getFullMsg();
5738 6773
 				if ($_partID != '')
5739 6774
 				{
@@ -5747,7 +6782,10 @@  discard block
 block discarded – undo
5747 6782
 					}
5748 6783
 					// if $partDisposition is empty, we assume attachment, and hope that the function
5749 6784
 					// itself is only triggered to fetch attachments
5750
-					if (empty($partDisposition)) $partDisposition='attachment';
6785
+					if (empty($partDisposition))
6786
+					{
6787
+						$partDisposition='attachment';
6788
+					}
5751 6789
 					if ($part && ($partDisposition=='attachment' || $partDisposition=='inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar')))
5752 6790
 					{
5753 6791
 						//$headerObject=$part->getAllDispositionParameters();//not used anywhere around here
@@ -5756,13 +6794,19 @@  discard block
 block discarded – undo
5756 6794
 						$charset = $part->getContentTypeParameter('charset');
5757 6795
 						//$structure_bytes = $part->getBytes(); $structure_partID=$part->getMimeId(); error_log(__METHOD__.__LINE__." fetchPartContents(".array2string($_uid).", $structure_partID, $_stream, $_preserveSeen,$structure_mime)" );
5758 6796
 						$this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen=true,$structure_mime);
5759
-						if ($_returnPart) return $part;
6797
+						if ($_returnPart)
6798
+						{
6799
+							return $part;
6800
+						}
5760 6801
 					}
5761 6802
 				}
5762 6803
 			}
5763 6804
 		}
5764 6805
 		$ext = MimeMagic::mime2ext($structure_mime);
5765
-		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false) $filename = trim($filename).'.'.$ext;
6806
+		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false)
6807
+		{
6808
+			$filename = trim($filename).'.'.$ext;
6809
+		}
5766 6810
 		if (!$part)
5767 6811
 		{
5768 6812
 			throw new Exception\WrongParameter("Error: Could not fetch attachment for Uid=".array2string($_uid).", PartId=$_partID, WinMailNr=$_winmail_nr, folder=$_folder");
@@ -5778,7 +6822,10 @@  discard block
 block discarded – undo
5778 6822
 		);
5779 6823
 
5780 6824
 		// try guessing the mimetype, if we get the application/octet-stream
5781
-		if (strtolower($attachmentData['type']) == 'application/octet-stream') $attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']);
6825
+		if (strtolower($attachmentData['type']) == 'application/octet-stream')
6826
+		{
6827
+			$attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']);
6828
+		}
5782 6829
 		# if the attachment holds a winmail number and is a winmail.dat then we have to handle that.
5783 6830
 		if ( $filename == 'winmail.dat' && $_winmail_nr)
5784 6831
 		{
@@ -5801,9 +6848,18 @@  discard block
 block discarded – undo
5801 6848
 					if ($_winmail_nr == $wantedPart.'@'.$mime_id)
5802 6849
 					{
5803 6850
 						//error_log(__METHOD__.__LINE__.'#'.$structure_mime.'#'.$filename.'#'.array2string($attachment));
5804
-						if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5805
-						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5806
-						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']);
6851
+						if (!isset($attachment['filename'])||empty($attachment['filename']))
6852
+						{
6853
+							$attachment['filename'] = $part->getName();
6854
+						}
6855
+						if (($cid = $part->getContentId()))
6856
+						{
6857
+							$attachment['cid'] = $cid;
6858
+						}
6859
+						if (empty($attachment['filename']))
6860
+						{
6861
+							$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
6862
+						}
5807 6863
 						$wmattach = $attachment;
5808 6864
 						$wmattach['attachment'] = $part->getContents(array('stream'=>$_stream));
5809 6865
 
@@ -5813,7 +6869,10 @@  discard block
 block discarded – undo
5813 6869
 			if ($tnefResolved)
5814 6870
 			{
5815 6871
 				$ext = MimeMagic::mime2ext($wmattach['mimeType']);
5816
-				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
6872
+				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false)
6873
+				{
6874
+					$wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
6875
+				}
5817 6876
 				$attachmentData = array(
5818 6877
 					'type'       => $wmattach['mimeType'],
5819 6878
 					'filename'   => $wmattach['filename'],
@@ -5843,7 +6902,10 @@  discard block
 block discarded – undo
5843 6902
 		static $uid=null, $part=null, $structure=null;
5844 6903
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_cid, $_part");
5845 6904
 
5846
-		if(empty($_cid)) return false;
6905
+		if(empty($_cid))
6906
+		{
6907
+			return false;
6908
+		}
5847 6909
 
5848 6910
 		if ($_uid != $uid || $_part != $part)
5849 6911
 		{
@@ -5868,13 +6930,19 @@  discard block
 block discarded – undo
5868 6930
 					$attachment = $part;
5869 6931
 				}
5870 6932
 				// everything else we only consider after we checked all
5871
-				if (!isset($attachment)) $attachment = $part;
6933
+				if (!isset($attachment))
6934
+				{
6935
+					$attachment = $part;
6936
+				}
5872 6937
 				// do we want content fetched, can be done later, if not needed
5873 6938
 				if (isset($_stream))
5874 6939
 				{
5875 6940
 					$this->fetchPartContents($_uid, $attachment, $_stream);
5876 6941
 				}
5877
-				if (isset($attachment)) break;
6942
+				if (isset($attachment))
6943
+				{
6944
+					break;
6945
+				}
5878 6946
 			}
5879 6947
 		}
5880 6948
 		// set name as filename, if not set
@@ -5905,10 +6973,17 @@  discard block
 block discarded – undo
5905 6973
 	 */
5906 6974
 	public function fetchPartContents($_uid, Horde_Mime_Part $part=null, $_stream=false, $_preserveSeen=false, $_mimetype=null)
5907 6975
 	{
5908
-		if (is_null($part)) return null;//new Horde_Mime_Part;
6976
+		if (is_null($part))
6977
+		{
6978
+			return null;
6979
+		}
6980
+		//new Horde_Mime_Part;
5909 6981
 		$encoding = null;
5910 6982
 		$fetchAsBinary = true;
5911
-		if ($_mimetype && strtolower($_mimetype)=='message/rfc822') $fetchAsBinary = false;
6983
+		if ($_mimetype && strtolower($_mimetype)=='message/rfc822')
6984
+		{
6985
+			$fetchAsBinary = false;
6986
+		}
5912 6987
 		// we need to set content on structure to decode transfer encoding
5913 6988
 		$part->setContents(
5914 6989
 			$this->getBodyPart($_uid, $part->getMimeId(), null, $_preserveSeen, $_stream, $encoding, $fetchAsBinary),
@@ -5945,7 +7020,10 @@  discard block
 block discarded – undo
5945 7020
 		// the recent flag is the default enforced here ; as we assume the _flags is always set,
5946 7021
 		// we default it to hordes default (Recent) (, other wise we should not pass the parameter
5947 7022
 		// for flags at all)
5948
-		if (empty($_flags)) $_flags = '\\Recent';
7023
+		if (empty($_flags))
7024
+		{
7025
+			$_flags = '\\Recent';
7026
+		}
5949 7027
 		//if (!is_array($_flags) && stripos($_flags,',')!==false) $_flags=explode(',',$_flags);
5950 7028
 		//if (!is_array($_flags)) $_flags = (array) $_flags;
5951 7029
 		try
@@ -5962,18 +7040,27 @@  discard block
 block discarded – undo
5962 7040
 		}
5963 7041
 		catch (\Exception $e)
5964 7042
 		{
5965
-			if (self::$debug) error_log("Could not append Message: ".$e->getMessage());
7043
+			if (self::$debug)
7044
+			{
7045
+				error_log("Could not append Message: ".$e->getMessage());
7046
+			}
5966 7047
 			throw new Exception\WrongUserinput(lang("Could not append Message:").' '.$e->getMessage().': '.$e->details);
5967 7048
 			//return false;
5968 7049
 		}
5969 7050
 		//error_log(__METHOD__.' ('.__LINE__.') '.' appended UID:'.$messageid);
5970 7051
 		//$messageid = true; // for debug reasons only
5971
-		if ($messageid === true || empty($messageid)) // try to figure out the message uid
7052
+		if ($messageid === true || empty($messageid))
7053
+		{
7054
+			// try to figure out the message uid
5972 7055
 		{
5973 7056
 			$list = $this->getHeaders($_folderName, $_startMessage=1, 1, 'INTERNALDATE', true, array(),null, false);
7057
+		}
5974 7058
 			if ($list)
5975 7059
 			{
5976
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
7060
+				if (self::$debug)
7061
+				{
7062
+					error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
7063
+				}
5977 7064
 				$messageid = $list['header'][0]['uid'];
5978 7065
 			}
5979 7066
 		}
@@ -6014,7 +7101,10 @@  discard block
 block discarded – undo
6014 7101
 	{
6015 7102
 			//echo __METHOD__." called for $uid,$partid <br>";
6016 7103
 			$headers = $mailClass->getMessageHeader($uid,$partid,true,false,$mailbox);
6017
-			if (empty($headers)) return false;
7104
+			if (empty($headers))
7105
+			{
7106
+				return false;
7107
+			}
6018 7108
 			// dont force retrieval of the textpart, let mailClass preferences decide
6019 7109
 			$bodyParts = $mailClass->getMessageBody($uid,($preserveHTML?'always_display':'only_if_no_text'),$partid,null,false,$mailbox);
6020 7110
 			// if we do not want HTML but there is no TextRepresentation with the message itself, try converting
@@ -6032,15 +7122,30 @@  discard block
 block discarded – undo
6032 7122
 			//error_log(array2string($bodyParts));
6033 7123
 			$attachments = $includeAttachments?$mailClass->getMessageAttachments($uid,$partid,null,true,false,true,$mailbox):array();
6034 7124
 
6035
-			if ($mailClass->isSentFolder($mailbox)) $mailaddress = $headers['TO'];
6036
-			elseif (isset($headers['FROM'])) $mailaddress = $headers['FROM'];
6037
-			elseif (isset($headers['SENDER'])) $mailaddress = $headers['SENDER'];
6038
-			if (isset($headers['CC'])) $mailaddress .= ','.$headers['CC'];
7125
+			if ($mailClass->isSentFolder($mailbox))
7126
+			{
7127
+				$mailaddress = $headers['TO'];
7128
+			}
7129
+			elseif (isset($headers['FROM']))
7130
+			{
7131
+				$mailaddress = $headers['FROM'];
7132
+			}
7133
+			elseif (isset($headers['SENDER']))
7134
+			{
7135
+				$mailaddress = $headers['SENDER'];
7136
+			}
7137
+			if (isset($headers['CC']))
7138
+			{
7139
+				$mailaddress .= ','.$headers['CC'];
7140
+			}
6039 7141
 			//_debug_array(array($headers,$mailaddress));
6040 7142
 			$subject = $headers['SUBJECT'];
6041 7143
 
6042 7144
 			$message = self::getdisplayableBody($mailClass, $bodyParts, $preserveHTML);
6043
-			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain') $message = '<pre>'.$message.'</pre>';
7145
+			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain')
7146
+			{
7147
+				$message = '<pre>'.$message.'</pre>';
7148
+			}
6044 7149
 			$headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '',$preserveHTML) : '');
6045 7150
 			$message = $headdata.$message;
6046 7151
 			//echo __METHOD__.'<br>';
@@ -6091,7 +7196,8 @@  discard block
 block discarded – undo
6091 7196
 							$attachments[$num]['attachment'] = $c->getContents();
6092 7197
 						}
6093 7198
 						// no attempt to convert, if we dont know about the charset
6094
-						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset'])) {
7199
+						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset']))
7200
+						{
6095 7201
 							// we do not try guessing the charset, if it is not set
6096 7202
 							//if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = Translation::detect_encoding($attachments[$num]['attachment']);
6097 7203
 							Translation::convert($attachments[$num]['attachment'],$attachments[$num]['charset']);
@@ -6112,7 +7218,10 @@  discard block
 block discarded – undo
6112 7218
 						unset($attachments[$num]['attachment']);
6113 7219
 					}
6114 7220
 				}
6115
-				if (is_array($attachedMessages)) $attachments = array_merge($attachments,$attachedMessages);
7221
+				if (is_array($attachedMessages))
7222
+				{
7223
+					$attachments = array_merge($attachments,$attachedMessages);
7224
+				}
6116 7225
 			}
6117 7226
 			return array(
6118 7227
 					'mailaddress'=>$mailaddress,
@@ -6134,10 +7243,17 @@  discard block
 block discarded – undo
6134 7243
 	{
6135 7244
 		$c = 0;
6136 7245
 		// use the standardIdentity
6137
-		foreach($_identities as $key => $acc) {
6138
-			if ($c==0) $identity = $acc;
7246
+		foreach($_identities as $key => $acc)
7247
+		{
7248
+			if ($c==0)
7249
+			{
7250
+				$identity = $acc;
7251
+			}
6139 7252
 			//error_log(__METHOD__.__LINE__." $key == $_profile_id ");
6140
-			if ($key==$_profile_id) $identity = $acc;
7253
+			if ($key==$_profile_id)
7254
+			{
7255
+				$identity = $acc;
7256
+			}
6141 7257
 			$c++;
6142 7258
 		}
6143 7259
 		return $identity;
@@ -6153,20 +7269,53 @@  discard block
 block discarded – undo
6153 7269
 	{
6154 7270
 		$headdata = null;
6155 7271
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($header).function_backtrace());
6156
-		if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
6157
-		if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
6158
-		if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
6159
-		if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
6160
-		if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
6161
-		if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
6162
-		if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
6163
-		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
6164
-		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
7272
+		if ($header['SUBJECT'])
7273
+		{
7274
+			$headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
7275
+		}
7276
+		if ($header['FROM'])
7277
+		{
7278
+			$headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
7279
+		}
7280
+		if ($header['SENDER'])
7281
+		{
7282
+			$headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
7283
+		}
7284
+		if ($header['TO'])
7285
+		{
7286
+			$headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
7287
+		}
7288
+		if ($header['CC'])
7289
+		{
7290
+			$headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
7291
+		}
7292
+		if ($header['BCC'])
7293
+		{
7294
+			$headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
7295
+		}
7296
+		if ($header['DATE'])
7297
+		{
7298
+			$headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
7299
+		}
7300
+		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal')
7301
+		{
7302
+			$headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
7303
+		}
7304
+		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal')
7305
+		{
7306
+			$headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
7307
+		}
6165 7308
 		//if ($mailcontent['headers']['ORGANIZATION']) $headdata .= lang('organization').': '.$mailcontent['headers']['ORGANIZATION']."\
6166 7309
 		if (!empty($headdata))
6167 7310
 		{
6168
-			if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
6169
-			if (empty($headline)) $headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
7311
+			if (!empty($headline) && $headline != 'SUPPRESS')
7312
+			{
7313
+				$headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
7314
+			}
7315
+			if (empty($headline))
7316
+			{
7317
+				$headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
7318
+			}
6170 7319
 			$headdata .= ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'');
6171 7320
 		}
6172 7321
 		else
@@ -6200,12 +7349,15 @@  discard block
 block discarded – undo
6200 7349
 		$returnAddr ='';
6201 7350
 		if (is_array($rfcAddressArray))
6202 7351
 		{
6203
-			foreach((array)$rfcAddressArray as $addressData) {
7352
+			foreach((array)$rfcAddressArray as $addressData)
7353
+			{
6204 7354
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressData));
6205
-				if($addressData['MAILBOX_NAME'] == 'NIL') {
7355
+				if($addressData['MAILBOX_NAME'] == 'NIL')
7356
+				{
6206 7357
 					continue;
6207 7358
 				}
6208
-				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') {
7359
+				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients')
7360
+				{
6209 7361
 					continue;
6210 7362
 				}
6211 7363
 				if ($addressData['RFC822_EMAIL'])
@@ -6219,7 +7371,10 @@  discard block
 block discarded – undo
6219 7371
 				}
6220 7372
 				$addressObject = $addressObjectA[0];
6221 7373
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressObject));
6222
-				if (!$addressObject->valid) continue;
7374
+				if (!$addressObject->valid)
7375
+				{
7376
+					continue;
7377
+				}
6223 7378
 				//$mb =(string)$addressObject->mailbox;
6224 7379
 				//$h = (string)$addressObject->host;
6225 7380
 				//$p = (string)$addressObject->personal;
@@ -6236,7 +7391,10 @@  discard block
 block discarded – undo
6236 7391
 			// do not mess with strings, return them untouched /* ToDo: validate string as Address */
6237 7392
 			$rfcAddressArray = self::decode_header($rfcAddressArray,true);
6238 7393
 			$rfcAddressArray = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$rfcAddressArray);
6239
-			if (is_string($rfcAddressArray)) return $rfcAddressArray;
7394
+			if (is_string($rfcAddressArray))
7395
+			{
7396
+				return $rfcAddressArray;
7397
+			}
6240 7398
 		}
6241 7399
 		return $returnAddr;
6242 7400
 	}
@@ -6253,10 +7411,19 @@  discard block
 block discarded – undo
6253 7411
 	{
6254 7412
 		$mergeobj = new Contacts\Merge();
6255 7413
 
6256
-		if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
7414
+		if (empty($mimetype))
7415
+		{
7416
+			$mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
7417
+		}
6257 7418
 		$rv = $mergeobj->merge_string($content,$ids,$err='',$mimetype, array(), self::$displayCharset);
6258
-		if (empty($rv) && !empty($content) && !empty($err)) $rv = $content;
6259
-		if (!empty($err) && !empty($content) && !empty($ids)) error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
7419
+		if (empty($rv) && !empty($content) && !empty($err))
7420
+		{
7421
+			$rv = $content;
7422
+		}
7423
+		if (!empty($err) && !empty($content) && !empty($ids))
7424
+		{
7425
+			error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
7426
+		}
6260 7427
 		return $rv;
6261 7428
 	}
6262 7429
 
@@ -6293,13 +7460,15 @@  discard block
 block discarded – undo
6293 7460
 			settype($bytes, 'integer');
6294 7461
 			$bytes /= 10;
6295 7462
 		}
6296
-		else
6297
-			settype($bytes, 'integer');
7463
+		else {
7464
+					settype($bytes, 'integer');
7465
+		}
6298 7466
 
6299 7467
 		return $bytes . ' ' . $type ;
6300 7468
 	}
6301 7469
 
6302
-	static function detect_qp(&$sting) {
7470
+	static function detect_qp(&$sting)
7471
+	{
6303 7472
 		$needle = '/(=[0-9][A-F])|(=[A-F][0-9])|(=[A-F][A-F])|(=[0-9][0-9])/';
6304 7473
 		return preg_match("$needle",$string);
6305 7474
 	}
@@ -6316,9 +7485,15 @@  discard block
 block discarded – undo
6316 7485
 	 */
6317 7486
 	static function logRunTimes($_starttime,$_endtime=null,$_message='',$_methodNline='')
6318 7487
 	{
6319
-		if (is_null($_endtime)) $_endtime = microtime(true);
7488
+		if (is_null($_endtime))
7489
+		{
7490
+			$_endtime = microtime(true);
7491
+		}
6320 7492
 		$usagetime = microtime(true) - $_starttime;
6321
-		if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
7493
+		if (self::$debugTimes)
7494
+		{
7495
+			error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
7496
+		}
6322 7497
 	}
6323 7498
 
6324 7499
 	/**
@@ -6333,7 +7508,10 @@  discard block
 block discarded – undo
6333 7508
 	 */
6334 7509
 	static function checkFileBasics(&$_formData, $IDtoAddToFileName='', $reqMimeType='message/rfc822')
6335 7510
 	{
6336
-		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data') return $_formData['file'];
7511
+		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data')
7512
+		{
7513
+			return $_formData['file'];
7514
+		}
6337 7515
 
6338 7516
 		//error_log(__METHOD__.__FILE__.array2string($_formData).' Id:'.$IDtoAddToFileName.' ReqMimeType:'.$reqMimeType);
6339 7517
 		$importfailed = $tmpFileName = false;
@@ -6382,8 +7560,15 @@  discard block
 block discarded – undo
6382 7560
 			{
6383 7561
 				$buff = explode('.',$_formData['name']);
6384 7562
 				$suffix = '';
6385
-				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
6386
-				if (!empty($suffix)) $sfxMimeType = MimeMagic::ext2mime($suffix);
7563
+				if (is_array($buff))
7564
+				{
7565
+					$suffix = array_pop($buff);
7566
+				}
7567
+				// take the last extension to check with ext2mime
7568
+				if (!empty($suffix))
7569
+				{
7570
+					$sfxMimeType = MimeMagic::ext2mime($suffix);
7571
+				}
6387 7572
 				if (!empty($suffix) && !empty($sfxMimeType) &&
6388 7573
 					(strlen(trim($_formData['type']))==0 || (strtolower(trim($_formData['type'])) != $sfxMimeType)))
6389 7574
 				{
@@ -6431,7 +7616,9 @@  discard block
 block discarded – undo
6431 7616
 			{
6432 7617
 				rename($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmpFileName);
6433 7618
 			}
6434
-		} else {
7619
+		}
7620
+		else
7621
+		{
6435 7622
 			//error_log("Import of message ".$_formData['file']." failes to meet basic restrictions");
6436 7623
 			$importfailed = true;
6437 7624
 			$alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.",$_formData['name']);
@@ -6477,21 +7664,32 @@  discard block
 block discarded – undo
6477 7664
 				if (substr($url, 0, 5) !== 'data:')
6478 7665
 				{
6479 7666
 					$filename = basename($url);
6480
-					if (($directory = dirname($url)) == '.') $directory = '';
7667
+					if (($directory = dirname($url)) == '.')
7668
+					{
7669
+						$directory = '';
7670
+					}
6481 7671
 					$ext = pathinfo($filename, PATHINFO_EXTENSION);
6482 7672
 					$mimeType  = MimeMagic::ext2mime($ext);
6483
-					if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
7673
+					if ( strlen($directory) > 1 && substr($directory,-1) != '/')
7674
+					{
7675
+$directory .= '/'; }
6484 7676
 					$myUrl = $directory.$filename;
6485
-					if ($myUrl[0]=='/') // local path -> we only allow path's that are available via http/https (or vfs)
7677
+					if ($myUrl[0]=='/')
7678
+					{
7679
+						// local path -> we only allow path's that are available via http/https (or vfs)
6486 7680
 					{
6487 7681
 						$basedir = ($_SERVER['HTTPS']?'https://':'http://'.$_SERVER['HTTP_HOST']);
6488 7682
 					}
7683
+					}
6489 7684
 					// use vfs instead of url containing webdav.php
6490 7685
 					// ToDo: we should test if the webdav url is of our own scope, as we cannot handle foreign
6491 7686
 					// webdav.php urls as vfs
6492
-					if (strpos($myUrl,'/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it.
7687
+					if (strpos($myUrl,'/webdav.php') !== false)
7688
+					{
7689
+						// we have a webdav link, so we build a vfs/sqlfs link of it.
6493 7690
 					{
6494 7691
 						Vfs::load_wrapper('vfs');
7692
+					}
6495 7693
 						list(,$myUrl) = explode('/webdav.php',$myUrl,2);
6496 7694
 						$basedir = 'vfs://default';
6497 7695
 						$needTempFile = false;
@@ -6520,8 +7718,13 @@  discard block
 block discarded – undo
6520 7718
 						}
6521 7719
 					}
6522 7720
 
6523
-					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/') { $basedir .= '/'; }
6524
-					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl));
7721
+					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/')
7722
+					{
7723
+$basedir .= '/'; }
7724
+					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http")
7725
+					{
7726
+						$data = file_get_contents($basedir.urldecode($myUrl));
7727
+					}
6525 7728
 				}
6526 7729
 				if (substr($url,0,strlen('data:'))=='data:')
6527 7730
 				{
@@ -6622,7 +7825,10 @@  discard block
 block discarded – undo
6622 7825
 				$_folder = $this->getSentFolder();
6623 7826
 			}
6624 7827
 			$delimiter = $this->getHierarchyDelimiter();
6625
-			if($_folder=='INBOX'.$delimiter) $_folder='INBOX';
7828
+			if($_folder=='INBOX'.$delimiter)
7829
+			{
7830
+				$_folder='INBOX';
7831
+			}
6626 7832
 			if ($importfailed === false)
6627 7833
 			{
6628 7834
 				$Subject = $mailObject->getHeader('Subject');
@@ -6651,7 +7857,9 @@  discard block
 block discarded – undo
6651 7857
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Id To Merge:'.$val);
6652 7858
 					if (/*$GLOBALS['egw_info']['flags']['currentapp'] == 'addressbook' &&*/
6653 7859
 						count($SendAndMergeTocontacts) > 1 && $val &&
6654
-						(is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))) // do the merge
7860
+						(is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)))
7861
+					{
7862
+						// do the merge
6655 7863
 					{
6656 7864
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6657 7865
 
@@ -6660,6 +7868,7 @@  discard block
 block discarded – undo
6660 7868
 						{
6661 7869
 							//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));
6662 7870
 							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset);
7871
+					}
6663 7872
 							$mailObject->addAddress($merged,'',$type);
6664 7873
 							if($type == 'to')
6665 7874
 							{
@@ -6691,9 +7900,15 @@  discard block
 block discarded – undo
6691 7900
 						$mailObject->clearCustomHeaders();
6692 7901
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6693 7902
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6694
-						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));
7903
+						if($text_body)
7904
+						{
7905
+							$text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7906
+						}
6695 7907
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6696
-						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));
7908
+						if($html_body)
7909
+						{
7910
+							$html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7911
+						}
6697 7912
 
6698 7913
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6699 7914
 						// set a higher timeout for big messages
@@ -6708,9 +7923,12 @@  discard block
 block discarded – undo
6708 7923
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($errorInfo));
6709 7924
 						}
6710 7925
 					}
6711
-					elseif (!$k)	// 1. entry, further entries will fail for apps other then addressbook
7926
+					elseif (!$k)
7927
+					{
7928
+						// 1. entry, further entries will fail for apps other then addressbook
6712 7929
 					{
6713 7930
 						$openAsDraft = true;
7931
+					}
6714 7932
 						$mailObject->removeHeader('Message-ID');
6715 7933
 						$mailObject->removeHeader('Date');
6716 7934
 						$mailObject->clearCustomHeaders();
@@ -6725,9 +7943,12 @@  discard block
 block discarded – undo
6725 7943
 
6726 7944
 						// No addresses from placeholders?  Treat it as just a contact ID
6727 7945
 						if (count($mailObject->getAddresses('to',true)) == 0 &&
6728
-							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)) // do the merge
7946
+							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))
7947
+						{
7948
+							// do the merge
6729 7949
 						{
6730 7950
 							$contact = $bo_merge->contacts->read($val);
7951
+						}
6731 7952
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($contact));
6732 7953
 							$email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
6733 7954
 							$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
@@ -6738,9 +7959,15 @@  discard block
 block discarded – undo
6738 7959
 						}
6739 7960
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6740 7961
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6741
-						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));
7962
+						if (!empty($Body))
7963
+						{
7964
+							$text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7965
+						}
6742 7966
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6743
-						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));
7967
+						if (!empty($AltBody))
7968
+						{
7969
+							$html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7970
+						}
6744 7971
 						$_folder = $this->getDraftFolder();
6745 7972
 					}
6746 7973
 					if ($sendOK || $openAsDraft)
@@ -6748,11 +7975,15 @@  discard block
 block discarded – undo
6748 7975
 						if ($this->folderExists($_folder,true))
6749 7976
 						{
6750 7977
 						    if($this->isSentFolder($_folder))
6751
-							{
7978
+						    {
6752 7979
 						        $flags = '\\Seen';
6753
-						    } elseif($this->isDraftFolder($_folder)) {
7980
+						    }
7981
+						    elseif($this->isDraftFolder($_folder))
7982
+						    {
6754 7983
 						        $flags = '\\Draft';
6755
-						    } else {
7984
+						    }
7985
+						    else
7986
+						    {
6756 7987
 						        $flags = '';
6757 7988
 						    }
6758 7989
 							$savefailed = false;
@@ -6786,7 +8017,10 @@  discard block
 block discarded – undo
6786 8017
 						}
6787 8018
 						else
6788 8019
 						{
6789
-							if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
8020
+							if (!$openComposeWindow)
8021
+							{
8022
+								$processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
8023
+							}
6790 8024
 						}
6791 8025
 					}
6792 8026
 					if (!is_null($sendOK) && $sendOK===false && is_null($openComposeWindow))
@@ -6834,7 +8068,10 @@  discard block
 block discarded – undo
6834 8068
 				$tmpFileName = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($tmpFileName);
6835 8069
 				break;
6836 8070
 		}
6837
-		if (!isset($message)) $message = fopen($tmpFileName, 'r');
8071
+		if (!isset($message))
8072
+		{
8073
+			$message = fopen($tmpFileName, 'r');
8074
+		}
6838 8075
 
6839 8076
 		if (!$message)
6840 8077
 		{
@@ -6865,7 +8102,10 @@  discard block
 block discarded – undo
6865 8102
 				(fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192));
6866 8103
 
6867 8104
 			$length = strpos($start, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
6868
-			if ($length===false) $length = strlen($start);
8105
+			if ($length===false)
8106
+			{
8107
+				$length = strlen($start);
8108
+			}
6869 8109
 			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0,$length));
6870 8110
 
6871 8111
 			foreach($headers->toArray(array('nowrap' => true)) as $header => $value)
@@ -6894,7 +8134,10 @@  discard block
 block discarded – undo
6894 8134
 		}
6895 8135
 		else
6896 8136
 		{
6897
-			if (($type = gettype($message)) == 'object') $type = get_class ($message);
8137
+			if (($type = gettype($message)) == 'object')
8138
+			{
8139
+				$type = get_class ($message);
8140
+			}
6898 8141
 			throw new Exception\WrongParameter('Wrong parameter type for message: '.$type);
6899 8142
 		}
6900 8143
 	}
@@ -6918,7 +8161,9 @@  discard block
 block discarded – undo
6918 8161
 			$matches = array();
6919 8162
 			preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/",$addresses,$matches);
6920 8163
 			//error_log(__METHOD__.__LINE__.array2string($matches));
6921
-			foreach ($matches[0] as &$match) {$match = trim($match,', ');}
8164
+			foreach ($matches[0] as &$match)
8165
+			{
8166
+$match = trim($match,', ');}
6922 8167
 			$addresses = implode(',',$matches[0]);
6923 8168
 			//error_log(__METHOD__.__LINE__.array2string($addresses));
6924 8169
 			$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
@@ -6949,7 +8194,10 @@  discard block
 block discarded – undo
6949 8194
 			}
6950 8195
 			else
6951 8196
 			{
6952
-				if ($previousFailed && $remember) $adr->personal = $remember. ' ' . $adr->personal;
8197
+				if ($previousFailed && $remember)
8198
+				{
8199
+					$adr->personal = $remember. ' ' . $adr->personal;
8200
+				}
6953 8201
 				$remember = '';
6954 8202
 				$previousFailed=false;
6955 8203
 				//error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal");
@@ -6971,7 +8219,10 @@  discard block
 block discarded – undo
6971 8219
 	{
6972 8220
 		$acc = Mail\Account::read($this->profileID);
6973 8221
 		$identity = Mail\Account::read_identity($acc['ident_id'], true, null, $acc);
6974
-		if (self::$debug) error_log(__METHOD__.__LINE__.array2string($identity));
8222
+		if (self::$debug)
8223
+		{
8224
+			error_log(__METHOD__.__LINE__.array2string($identity));
8225
+		}
6975 8226
 		$headers = $this->getMessageHeader($uid, '', 'object', true, $_folder);
6976 8227
 
6977 8228
 		$mdn = new Horde_Mime_Mdn($headers);
Please login to merge, or discard this patch.