Completed
Push — 14.2 ( e07840...cec2da )
by Ralf
83:18 queued 52:04
created
emailadmin/inc/class.emailadmin_imap.inc.php 4 patches
Doc Comments   +8 added lines, -7 removed lines patch added patch discarded remove patch
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 	 * Construtor
133 133
 	 *
134 134
 	 * @param array
135
-	 * @param bool|int|string $_adminConnection create admin connection if true or account_id or imap username
135
+	 * @param boolean|string $_adminConnection create admin connection if true or account_id or imap username
136 136
 	 * @param int $_timeout =null timeout in secs, if none given fmail pref or default of 20 is used
137 137
 	 * @return void
138 138
 	 */
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
 	/**
451 451
 	 * getSpecialUseFolders
452 452
 	 *
453
-	 * @return current mailbox, or if none check on INBOX, and return upon existance
453
+	 * @return string mailbox, or if none check on INBOX, and return upon existance
454 454
 	 */
455 455
 	function getCurrentMailbox()
456 456
 	{
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
 	 * Returns an array containing the names of the selected mailboxes
569 569
 	 *
570 570
 	 * @param   string  $reference          base mailbox to start the search (default is current mailbox)
571
-	 * @param   string  $restriction_search false or 0 means return all mailboxes
571
+	 * @param   integer  $restriction_search false or 0 means return all mailboxes
572 572
 	 *                                      true or 1 return only the mailbox that contains that exact name
573 573
 	 *                                      2 return all mailboxes in that hierarchy level
574 574
 	 * @param   string  $returnAttributes   true means return an assoc array containing mailbox names and mailbox attributes
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
 	 * Returns an array containing the names of the subscribed selected mailboxes
653 653
 	 *
654 654
 	 * @param   string  $reference          base mailbox to start the search
655
-	 * @param   string  $restriction_search false or 0 means return all mailboxes
655
+	 * @param   integer  $restriction_search false or 0 means return all mailboxes
656 656
 	 *                                      true or 1 return only the mailbox that contains that exact name
657 657
 	 *                                      2 return all mailboxes in that hierarchy level
658 658
 	 * @param   string  $returnAttributes   true means return an assoc array containing mailbox names and mailbox attributes
@@ -720,7 +720,7 @@  discard block
 block discarded – undo
720 720
 	 * Returns an array containing the names of the selected unsubscribed mailboxes
721 721
 	 *
722 722
 	 * @param   string  $reference          base mailbox to start the search
723
-	 * @param   string  $restriction_search false or 0 means return all mailboxes
723
+	 * @param   integer  $restriction_search false or 0 means return all mailboxes
724 724
 	 *                                      true or 1 return only the mailbox that contains that exact name
725 725
 	 *                                      2 return all mailboxes in that hierarchy level
726 726
 	 *
@@ -898,6 +898,7 @@  discard block
 block discarded – undo
898 898
 	 *
899 899
 	 * @var array $_nameSpace
900 900
 	 * @var string $_folderName
901
+	 * @param string $_folderName
901 902
 	 * @return string the prefix (may be an empty string)
902 903
 	 */
903 904
 	static function getFolderPrefixFromNamespace($_nameSpace, $_folderName)
@@ -916,7 +917,7 @@  discard block
 block discarded – undo
916 917
 	 * @param string $_mailbox
917 918
 	 * @param string $delimiter
918 919
 	 * @param string $prefix
919
-	 * @param string $reclevel = 0, counter to keep track of the current recursionlevel
920
+	 * @param integer $reclevel = 0, counter to keep track of the current recursionlevel
920 921
 	 * @return array of mailboxes
921 922
 	 */
922 923
 	function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel=0)
@@ -1355,7 +1356,7 @@  discard block
 block discarded – undo
1355 1356
 	/**
1356 1357
 	 * Get vacation message for given user
1357 1358
 	 *
1358
-	 * @param int|string $_euser nummeric account_id or imap username
1359
+	 * @param string|null $_euser nummeric account_id or imap username
1359 1360
 	 * @param string $_scriptName =null
1360 1361
 	 * @throws Exception on connection error or authentication failure
1361 1362
 	 * @return array
Please login to merge, or discard this patch.
Switch Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -580,16 +580,16 @@  discard block
 block discarded – undo
580 580
 		$mailbox = '';
581 581
 		if ( is_int( $restriction_search ) ){
582 582
 			switch ( $restriction_search ) {
583
-			case 0:
584
-				$searchstring = $reference."*";
585
-				break;
586
-			case 1:
587
-				$mailbox = $searchstring = $reference;
588
-				//$reference = '%';
589
-				break;
590
-			case 2:
591
-				$searchstring = $reference."%";
592
-				break;
583
+				case 0:
584
+					$searchstring = $reference."*";
585
+					break;
586
+				case 1:
587
+					$mailbox = $searchstring = $reference;
588
+					//$reference = '%';
589
+					break;
590
+				case 2:
591
+					$searchstring = $reference."%";
592
+					break;
593 593
 			}
594 594
 		}else{
595 595
 			if ( is_string( $restriction_search ) ){
@@ -664,16 +664,16 @@  discard block
 block discarded – undo
664 664
 		$mailbox = '';
665 665
 		if ( is_int( $restriction_search ) ){
666 666
 			switch ( $restriction_search ) {
667
-			case 0:
668
-				$searchstring = $reference."*";
669
-				break;
670
-			case 1:
671
-				$mailbox = $searchstring = $reference;
672
-				//$reference = '%';
673
-				break;
674
-			case 2:
675
-				$searchstring = $reference."%";
676
-				break;
667
+				case 0:
668
+					$searchstring = $reference."*";
669
+					break;
670
+				case 1:
671
+					$mailbox = $searchstring = $reference;
672
+					//$reference = '%';
673
+					break;
674
+				case 2:
675
+					$searchstring = $reference."%";
676
+					break;
677 677
 			}
678 678
 		}else{
679 679
 			if ( is_string( $restriction_search ) ){
@@ -730,16 +730,16 @@  discard block
 block discarded – undo
730 730
 
731 731
 		if ( is_int( $restriction_search ) ){
732 732
 			switch ( $restriction_search ) {
733
-			case 0:
734
-				$mailbox = $reference."*";
735
-				break;
736
-			case 1:
737
-				$mailbox = $reference;
738
-				$reference = '%';
739
-				break;
740
-			case 2:
741
-				$mailbox = "%";
742
-				break;
733
+				case 0:
734
+					$mailbox = $reference."*";
735
+					break;
736
+				case 1:
737
+					$mailbox = $reference;
738
+					$reference = '%';
739
+					break;
740
+				case 2:
741
+					$mailbox = "%";
742
+					break;
743 743
 			}
744 744
 		}else{
745 745
 			if ( is_string( $restriction_search ) ){
Please login to merge, or discard this patch.
Spacing   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	static public $default_params = array(
59 59
 		//'debug' => '/tmp/imap.log', // uncomment to log communitcation with IMAP server
60 60
 		//'debug_literal' => true,    // uncomment to log mail contents returned by IMAP server
61
-		'cache' => true,              // default caching via emailadmin_horde_cache / egw_cache
61
+		'cache' => true, // default caching via emailadmin_horde_cache / egw_cache
62 62
 	);
63 63
 
64 64
 	/**
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 	 * @param int $_timeout =null timeout in secs, if none given fmail pref or default of 20 is used
137 137
 	 * @return void
138 138
 	 */
139
-	function __construct(array $params, $_adminConnection=false, $_timeout=null)
139
+	function __construct(array $params, $_adminConnection = false, $_timeout = null)
140 140
 	{
141 141
 		if (function_exists('mb_convert_encoding'))
142 142
 		{
@@ -148,18 +148,18 @@  discard block
 block discarded – undo
148 148
 		$this->loginType = $this->params['acc_imap_logintype'];
149 149
 		$this->domainName = $this->params['acc_domain'];
150 150
 
151
-		if (is_null($_timeout)) $_timeout = $this->params['acc_imap_timeout']?$this->params['acc_imap_timeout']:self::getTimeOut ();
151
+		if (is_null($_timeout)) $_timeout = $this->params['acc_imap_timeout'] ? $this->params['acc_imap_timeout'] : self::getTimeOut();
152 152
 
153
-		switch($this->params['acc_imap_ssl'] & ~emailadmin_account::SSL_VERIFY)
153
+		switch ($this->params['acc_imap_ssl']&~emailadmin_account::SSL_VERIFY)
154 154
 		{
155 155
 			case emailadmin_account::SSL_STARTTLS:
156
-				$secure = 'tls';	// Horde uses 'tls' for STARTTLS, not ssl connection with tls version >= 1 and no sslv2/3
156
+				$secure = 'tls'; // Horde uses 'tls' for STARTTLS, not ssl connection with tls version >= 1 and no sslv2/3
157 157
 				break;
158 158
 			case emailadmin_account::SSL_SSL:
159 159
 				$secure = 'ssl';
160 160
 				break;
161 161
 			case emailadmin_account::SSL_TLS:
162
-				$secure = 'tlsv1';	// since Horde_Imap_Client-1.16.0 requiring Horde_Socket_Client-1.1.0
162
+				$secure = 'tlsv1'; // since Horde_Imap_Client-1.16.0 requiring Horde_Socket_Client-1.1.0
163 163
 				break;
164 164
 		}
165 165
 		// Horde use locale for translation of error messages
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 			'port' => $this->params['acc_imap_port'],
180 180
 			'secure' => $secure,
181 181
 			'timeout' => $_timeout,
182
-		)+self::$default_params;
182
+		) + self::$default_params;
183 183
 
184 184
 		if ($parent_params['cache'] === true)
185 185
 		{
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 				// as we have no way to tell this apart we ignore BINARY this affects
204 204
 				// Horde_Imap_Client_Fetch_Query::bodyPart for its fetch parameter decode=true is ignored
205 205
 				// (other functionality depending on BINARY is, of cause, affected too)
206
-				$parent_params['capability_ignore']= array_merge((array)$parent_params['capability_ignore'],array('BINARY'));
206
+				$parent_params['capability_ignore'] = array_merge((array)$parent_params['capability_ignore'], array('BINARY'));
207 207
 				break;
208 208
 		}
209 209
 		parent::__construct($parent_params);
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 	 *
217 217
 	 * @param string $_username =true create an admin connection for given user or $this->acc_imap_username
218 218
 	 */
219
-	function adminConnection($_username=true)
219
+	function adminConnection($_username = true)
220 220
 	{
221 221
 		if ($this->isAdminConnection !== $_username)
222 222
 		{
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 	 * @param string $_username =null create an admin connection for given user or $this->acc_imap_username
234 234
 	 * @throws Horde_IMAP_Client_Exception
235 235
 	 */
236
-	public function checkAdminConnection($_username=true)
236
+	public function checkAdminConnection($_username = true)
237 237
 	{
238 238
 		if ($this->acc_imap_administration)
239 239
 		{
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 	 */
251 251
 	public function __get($name)
252 252
 	{
253
-		switch($name)
253
+		switch ($name)
254 254
 		{
255 255
 			case 'acc_imap_administration':
256 256
 				return !empty($this->params['acc_imap_admin_username']);
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 				{
269 269
 					return $this->$name;
270 270
 				}
271
-				if (array_key_exists($name,$this->params))
271
+				if (array_key_exists($name, $this->params))
272 272
 				{
273 273
 					return $this->params[$name];
274 274
 				}
@@ -289,9 +289,9 @@  discard block
 block discarded – undo
289 289
 	 * @deprecated allready called by constructor automatic, parameters must be passed to constructor!
290 290
 	 * @return boolean|PEAR_Error true on success, PEAR_Error of false on failure
291 291
 	 */
292
-	function openConnection($_adminConnection=false, $_timeout=null)
292
+	function openConnection($_adminConnection = false, $_timeout = null)
293 293
 	{
294
-		unset($_timeout);	// not used
294
+		unset($_timeout); // not used
295 295
 		if ($_adminConnection !== $this->params['adminConnection'])
296 296
 		{
297 297
 			throw new egw_exception_wrong_parameter('need to set parameters on calling emailadmin_account->imapServer()!');
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 	 * @param string _use decide if the use is for IMAP or SIEVE, by now only the default differs
305 305
 	 * @return int - timeout (either set or default 20/10)
306 306
 	 */
307
-	static function getTimeOut($_use='IMAP')
307
+	static function getTimeOut($_use = 'IMAP')
308 308
 	{
309 309
 		$timeout = $GLOBALS['egw_info']['user']['preferences']['mail']['connectionTimeout'];
310 310
 		if (empty($timeout) || !($timeout > 0)) $timeout = $_use == 'SIEVE' ? 10 : 20; // this is the default value
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 	 */
330 330
 	function addAccount($_hookValues)
331 331
 	{
332
-		unset($_hookValues);	// not used
332
+		unset($_hookValues); // not used
333 333
 		return true;
334 334
 	}
335 335
 
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 	 */
342 342
 	function updateAccount($_hookValues)
343 343
 	{
344
-		unset($_hookValues);	// not used
344
+		unset($_hookValues); // not used
345 345
 		return true;
346 346
 	}
347 347
 
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 	 */
354 354
 	function deleteAccount($_hookValues)
355 355
 	{
356
-		unset($_hookValues);	// not used
356
+		unset($_hookValues); // not used
357 357
 		return true;
358 358
 	}
359 359
 
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 	 */
371 371
 	function encodeFolderName($_folderName)
372 372
 	{
373
-		if($this->mbAvailable) {
373
+		if ($this->mbAvailable) {
374 374
 			return mb_convert_encoding($_folderName, "UTF7-IMAP", translation::charset());
375 375
 		}
376 376
 
@@ -387,17 +387,17 @@  discard block
 block discarded – undo
387 387
 	 */
388 388
 	function getMailbox($mailbox)
389 389
 	{
390
-		$mailboxes = $this->listMailboxes($mailbox,Horde_Imap_Client::MBOX_ALL);
391
-		if (empty($mailboxes)) $mailboxes = $this->listMailboxes($mailbox,Horde_Imap_Client::MBOX_UNSUBSCRIBED);
390
+		$mailboxes = $this->listMailboxes($mailbox, Horde_Imap_Client::MBOX_ALL);
391
+		if (empty($mailboxes)) $mailboxes = $this->listMailboxes($mailbox, Horde_Imap_Client::MBOX_UNSUBSCRIBED);
392 392
 		//error_log(__METHOD__.__LINE__.'->'.$mailbox.'/'.array2string($mailboxes));
393 393
 		$mboxes = new Horde_Imap_Client_Mailbox_List($mailboxes);
394 394
 		//_debug_array($mboxes->count());
395 395
 		foreach ($mboxes->getIterator() as $k =>$box)
396 396
 		{
397 397
 			//error_log(__METHOD__.__LINE__.'->'.$k);
398
-			if ($k!='user' && $k != '' && $k==$mailbox) return $box['mailbox']; //_debug_array(array($k => $client->status($k)));
398
+			if ($k != 'user' && $k != '' && $k == $mailbox) return $box['mailbox']; //_debug_array(array($k => $client->status($k)));
399 399
 		}
400
-		return ($this->mailboxExist($mailbox)?$mailbox:false);
400
+		return ($this->mailboxExist($mailbox) ? $mailbox : false);
401 401
 	}
402 402
 
403 403
 	/**
@@ -413,23 +413,23 @@  discard block
 block discarded – undo
413 413
 			//error_log(__METHOD__.__LINE__.':'.$mailbox);
414 414
 			$currentMailbox = $this->currentMailbox();
415 415
 		}
416
-		catch(Exception $e)
416
+		catch (Exception $e)
417 417
 		{
418 418
 			//error_log(__METHOD__.__LINE__.' failed detecting currentMailbox:'.$currentMailbox.':'.$e->getMessage());
419
-			$currentMailbox=null;
419
+			$currentMailbox = null;
420 420
 			unset($e);
421 421
 		}
422 422
 		try
423 423
 		{
424 424
 			//error_log(__METHOD__.__LINE__.':'.$mailbox);
425 425
 			$this->openMailbox($mailbox);
426
-			$returnvalue=true;
426
+			$returnvalue = true;
427 427
 		}
428
-		catch(Exception $e)
428
+		catch (Exception $e)
429 429
 		{
430 430
 			//error_log(__METHOD__.__LINE__.' failed opening:'.$mailbox.':'.$e->getMessage().' Called by:'.function_backtrace());
431 431
 			unset($e);
432
-			$returnvalue=false;
432
+			$returnvalue = false;
433 433
 		}
434 434
 		if (!empty($currentMailbox) && $currentMailbox['mailbox'] != $mailbox)
435 435
 		{
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
 				//error_log(__METHOD__.__LINE__.':'.$currentMailbox .'<->'.$mailbox);
439 439
 				$this->openMailbox($currentMailbox['mailbox']);
440 440
 			}
441
-			catch(Exception $e)
441
+			catch (Exception $e)
442 442
 			{
443 443
 				//error_log(__METHOD__.__LINE__.' failed reopening:'.$currentMailbox.':'.$e->getMessage());
444 444
 				unset($e);
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
 		{
459 459
 			$mailbox = $this->currentMailbox();
460 460
 		}
461
-		catch(Exception $e)
461
+		catch (Exception $e)
462 462
 		{
463 463
 			error_log(__METHOD__.' ('.__LINE__.') failed fetching currentMailbox:'.$e->getMessage());
464 464
 			//throw new egw_exception(__METHOD__.' ('.__LINE__.") failed to ".__METHOD__." :".$e->getMessage());
@@ -476,16 +476,16 @@  discard block
 block discarded – undo
476 476
 	 */
477 477
 	function getSpecialUseFolders()
478 478
 	{
479
-		$mailboxes = $this->getMailboxes('',0,true);
479
+		$mailboxes = $this->getMailboxes('', 0, true);
480 480
 		$suF = array();
481 481
 		foreach ($mailboxes as $box)
482 482
 		{
483
-			if ($box['MAILBOX']!='user' && $box['MAILBOX'] != '')
483
+			if ($box['MAILBOX'] != 'user' && $box['MAILBOX'] != '')
484 484
 			{
485 485
 				//error_log(__METHOD__.__LINE__.$k.'->'.array2string($box));
486
-				if (isset($box['ATTRIBUTES'])&&!empty($box['ATTRIBUTES'])&&
487
-					stripos(strtolower(array2string($box['ATTRIBUTES'])),'\noselect')=== false&&
488
-					stripos(strtolower(array2string($box['ATTRIBUTES'])),'\nonexistent')=== false)
486
+				if (isset($box['ATTRIBUTES']) && !empty($box['ATTRIBUTES']) &&
487
+					stripos(strtolower(array2string($box['ATTRIBUTES'])), '\noselect') === false &&
488
+					stripos(strtolower(array2string($box['ATTRIBUTES'])), '\nonexistent') === false)
489 489
 				{
490 490
 					$suF[$box['MAILBOX']] = $box;
491 491
 				}
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
 			$status = $this->status($mailbox);
508 508
 			foreach ($status as $key => $v)
509 509
 			{
510
-				$_status[strtoupper($key)]=$v;
510
+				$_status[strtoupper($key)] = $v;
511 511
 			}
512 512
 			return $_status;
513 513
 		}
@@ -525,9 +525,9 @@  discard block
 block discarded – undo
525 525
 	 * @param ignoreStatusCache bool ignore the cache used for counters
526 526
 	 * @return array with counters
527 527
 	 */
528
-	function getStatus($mailbox, $ignoreStatusCache=false)
528
+	function getStatus($mailbox, $ignoreStatusCache = false)
529 529
 	{
530
-		$mailboxes = $this->listMailboxes($mailbox,Horde_Imap_Client::MBOX_ALL,array(
530
+		$mailboxes = $this->listMailboxes($mailbox, Horde_Imap_Client::MBOX_ALL, array(
531 531
 				'attributes'=>true,
532 532
 				'children'=>true, //child info
533 533
 				'delimiter'=>true,
@@ -541,16 +541,16 @@  discard block
 block discarded – undo
541 541
 		//error_log(__METHOD__.__LINE__.array2string($mboxes->count()));
542 542
 		foreach ($mboxes->getIterator() as $k =>$box)
543 543
 		{
544
-			if ($k!='user' && $k != '' && $k==$mailbox)
544
+			if ($k != 'user' && $k != '' && $k == $mailbox)
545 545
 			{
546
-				if (stripos(array2string($box['attributes']),'\noselect')=== false)
546
+				if (stripos(array2string($box['attributes']), '\noselect') === false)
547 547
 				{
548 548
 					$status = $this->status($k, $flags);
549 549
 					foreach ($status as $key => $v)
550 550
 					{
551
-						$_status[strtoupper($key)]=$v;
551
+						$_status[strtoupper($key)] = $v;
552 552
 					}
553
-					$_status['HIERACHY_DELIMITER'] = $_status['delimiter'] = ($box['delimiter']?$box['delimiter']:$this->getDelimiter('personal'));
553
+					$_status['HIERACHY_DELIMITER'] = $_status['delimiter'] = ($box['delimiter'] ? $box['delimiter'] : $this->getDelimiter('personal'));
554 554
 					$_status['ATTRIBUTES'] = $box['attributes'];
555 555
 					//error_log(__METHOD__.__LINE__.$k.'->'.array2string($_status));
556 556
 					return $_status;
@@ -576,14 +576,14 @@  discard block
 block discarded – undo
576 576
 	 *
577 577
 	 * @return  mixed   array of mailboxes
578 578
 	 */
579
-	function getMailboxes($reference = ''  , $restriction_search = 0, $returnAttributes = false)
579
+	function getMailboxes($reference = '', $restriction_search = 0, $returnAttributes = false)
580 580
 	{
581
-		if ( is_bool($restriction_search) ){
582
-			$restriction_search = (int) $restriction_search;
581
+		if (is_bool($restriction_search)) {
582
+			$restriction_search = (int)$restriction_search;
583 583
 		}
584 584
 		$mailbox = '';
585
-		if ( is_int( $restriction_search ) ){
586
-			switch ( $restriction_search ) {
585
+		if (is_int($restriction_search)) {
586
+			switch ($restriction_search) {
587 587
 			case 0:
588 588
 				$searchstring = $reference."*";
589 589
 				break;
@@ -595,8 +595,8 @@  discard block
 block discarded – undo
595 595
 				$searchstring = $reference."%";
596 596
 				break;
597 597
 			}
598
-		}else{
599
-			if ( is_string( $restriction_search ) ){
598
+		} else {
599
+			if (is_string($restriction_search)) {
600 600
 				$mailbox = $searchstring = $restriction_search;
601 601
 			}
602 602
 		}
@@ -609,35 +609,35 @@  discard block
 block discarded – undo
609 609
 				'special_use'=>true,
610 610
 				'sort'=>true,
611 611
 			);
612
-		if ($returnAttributes==false)
612
+		if ($returnAttributes == false)
613 613
 		{
614 614
 			unset($options['attributes']);
615 615
 			unset($options['children']);
616 616
 			unset($options['special_use']);
617 617
 		}
618
-		$mailboxes = $this->listMailboxes($searchstring,Horde_Imap_Client::MBOX_ALL, $options);
618
+		$mailboxes = $this->listMailboxes($searchstring, Horde_Imap_Client::MBOX_ALL, $options);
619 619
 		//$mboxes = new Horde_Imap_Client_Mailbox_List($mailboxes);
620 620
 		//_debug_array($mboxes->count());
621 621
 		foreach ((array)$mailboxes as $k =>$box)
622 622
 		{
623 623
 			//error_log(__METHOD__.__LINE__.' Box:'.$k.'->'.array2string($box));
624
-			$ret[$k]=array('MAILBOX'=>$k,'ATTRIBUTES'=>$box['attributes'],'delimiter'=>($box['delimiter']?$box['delimiter']:$this->getDelimiter('personal')),'SUBSCRIBED'=>true);
624
+			$ret[$k] = array('MAILBOX'=>$k, 'ATTRIBUTES'=>$box['attributes'], 'delimiter'=>($box['delimiter'] ? $box['delimiter'] : $this->getDelimiter('personal')), 'SUBSCRIBED'=>true);
625 625
 		}
626 626
 		// for unknown reasons on ALL, UNSUBSCRIBED are not returned
627 627
 		//always fetch unsubscribed, think about only fetching it when $options['attributes'] is set
628 628
 		//but then allMailboxes are not all, ....
629 629
 		//if (!empty($mailbox) && !isset($ret[$mailbox]))
630 630
 		{
631
-			$unsub_mailboxes = $this->listMailboxes($searchstring,Horde_Imap_Client::MBOX_UNSUBSCRIBED, $options);
631
+			$unsub_mailboxes = $this->listMailboxes($searchstring, Horde_Imap_Client::MBOX_UNSUBSCRIBED, $options);
632 632
 			//$mboxes = new Horde_Imap_Client_Mailbox_List($mailboxes);
633 633
 			//_debug_array($mboxes->count());
634 634
 			//error_log(__METHOD__.__LINE__.' '.$mailbox.':'.count((array)$mailboxes).'->'.function_backtrace());
635 635
 			foreach ((array)$unsub_mailboxes as $k =>$box)
636 636
 			{
637 637
 				//error_log(__METHOD__.__LINE__.' Box:'.$k.' already In?'.array_key_exists($k,$boxexists).'->'.array2string($box));
638
-				if(!array_key_exists($k,$ret))
638
+				if (!array_key_exists($k, $ret))
639 639
 				{
640
-					$ret[$k]=array('MAILBOX'=>$k,'ATTRIBUTES'=>$box['attributes'],'delimiter'=>($box['delimiter']?$box['delimiter']:$this->getDelimiter('personal')),'SUBSCRIBED'=>false);
640
+					$ret[$k] = array('MAILBOX'=>$k, 'ATTRIBUTES'=>$box['attributes'], 'delimiter'=>($box['delimiter'] ? $box['delimiter'] : $this->getDelimiter('personal')), 'SUBSCRIBED'=>false);
641 641
 				}
642 642
 				else
643 643
 				{
@@ -660,14 +660,14 @@  discard block
 block discarded – undo
660 660
 	 *
661 661
 	 * @return  mixed   array of mailboxes
662 662
 	 */
663
-	function listSubscribedMailboxes($reference = ''  , $restriction_search = 0, $returnAttributes = false)
663
+	function listSubscribedMailboxes($reference = '', $restriction_search = 0, $returnAttributes = false)
664 664
 	{
665
-		if ( is_bool($restriction_search) ){
666
-			$restriction_search = (int) $restriction_search;
665
+		if (is_bool($restriction_search)) {
666
+			$restriction_search = (int)$restriction_search;
667 667
 		}
668 668
 		$mailbox = '';
669
-		if ( is_int( $restriction_search ) ){
670
-			switch ( $restriction_search ) {
669
+		if (is_int($restriction_search)) {
670
+			switch ($restriction_search) {
671 671
 			case 0:
672 672
 				$searchstring = $reference."*";
673 673
 				break;
@@ -679,8 +679,8 @@  discard block
 block discarded – undo
679 679
 				$searchstring = $reference."%";
680 680
 				break;
681 681
 			}
682
-		}else{
683
-			if ( is_string( $restriction_search ) ){
682
+		} else {
683
+			if (is_string($restriction_search)) {
684 684
 				$mailbox = $searchstring = $restriction_search;
685 685
 			}
686 686
 		}
@@ -692,25 +692,25 @@  discard block
 block discarded – undo
692 692
 				'special_use'=>true,
693 693
 				'sort'=>true,
694 694
 			);
695
-		if ($returnAttributes==false)
695
+		if ($returnAttributes == false)
696 696
 		{
697 697
 			unset($options['attributes']);
698 698
 			unset($options['children']);
699 699
 			unset($options['special_use']);
700 700
 		}
701
-		$mailboxes = $this->listMailboxes($searchstring,Horde_Imap_Client::MBOX_SUBSCRIBED_EXISTS, $options);
701
+		$mailboxes = $this->listMailboxes($searchstring, Horde_Imap_Client::MBOX_SUBSCRIBED_EXISTS, $options);
702 702
 		//$mboxes = new Horde_Imap_Client_Mailbox_List($mailboxes);
703 703
 		//_debug_array($mboxes->count());
704 704
 		foreach ((array)$mailboxes as $k =>$box)
705 705
 		{
706 706
 			//error_log(__METHOD__.__LINE__.' Searched for:'.$mailbox.' got Box:'.$k.'->'.array2string($box).function_backtrace());
707
-			if ($returnAttributes==false)
707
+			if ($returnAttributes == false)
708 708
 			{
709
-				$ret[]=$k;
709
+				$ret[] = $k;
710 710
 			}
711 711
 			else
712 712
 			{
713
-				$ret[$k]=array('MAILBOX'=>$k,'ATTRIBUTES'=>$box['attributes'],'delimiter'=>($box['delimiter']?$box['delimiter']:$this->getDelimiter('personal')),'SUBSCRIBED'=>true);
713
+				$ret[$k] = array('MAILBOX'=>$k, 'ATTRIBUTES'=>$box['attributes'], 'delimiter'=>($box['delimiter'] ? $box['delimiter'] : $this->getDelimiter('personal')), 'SUBSCRIBED'=>true);
714 714
 			}
715 715
 		}
716 716
 		return $ret;
@@ -726,14 +726,14 @@  discard block
 block discarded – undo
726 726
 	 *
727 727
 	 * @return  mixed   array of mailboxes
728 728
 	 */
729
-	function listUnSubscribedMailboxes($reference = ''  , $restriction_search = 0)
729
+	function listUnSubscribedMailboxes($reference = '', $restriction_search = 0)
730 730
 	{
731
-		if ( is_bool($restriction_search) ){
732
-			$restriction_search = (int) $restriction_search;
731
+		if (is_bool($restriction_search)) {
732
+			$restriction_search = (int)$restriction_search;
733 733
 		}
734 734
 
735
-		if ( is_int( $restriction_search ) ){
736
-			switch ( $restriction_search ) {
735
+		if (is_int($restriction_search)) {
736
+			switch ($restriction_search) {
737 737
 			case 0:
738 738
 				$mailbox = $reference."*";
739 739
 				break;
@@ -745,8 +745,8 @@  discard block
 block discarded – undo
745 745
 				$mailbox = "%";
746 746
 				break;
747 747
 			}
748
-		}else{
749
-			if ( is_string( $restriction_search ) ){
748
+		} else {
749
+			if (is_string($restriction_search)) {
750 750
 				$mailbox = $restriction_search;
751 751
 			}
752 752
 		}
@@ -755,17 +755,17 @@  discard block
 block discarded – undo
755 755
 			'sort'=>true,
756 756
 			//'flat'=>true,
757 757
 		);
758
-		$mailboxes = $this->listMailboxes($mailbox,Horde_Imap_Client::MBOX_SUBSCRIBED_EXISTS, $options);
758
+		$mailboxes = $this->listMailboxes($mailbox, Horde_Imap_Client::MBOX_SUBSCRIBED_EXISTS, $options);
759 759
 		foreach ($mailboxes as $box)
760 760
 		{
761 761
 			//error_log(__METHOD__.__LINE__.' Box:'.$k.'->'.array2string($box['mailbox']->utf8));
762
-			$sret[]=$box['mailbox']->utf8;
762
+			$sret[] = $box['mailbox']->utf8;
763 763
 		}
764
-		$unsubscribed = $this->listMailboxes($mailbox,Horde_Imap_Client::MBOX_UNSUBSCRIBED, $options);
764
+		$unsubscribed = $this->listMailboxes($mailbox, Horde_Imap_Client::MBOX_UNSUBSCRIBED, $options);
765 765
 		foreach ($unsubscribed as $box)
766 766
 		{
767 767
 			//error_log(__METHOD__.__LINE__.' Box:'.$k.'->'.array2string($box['mailbox']->utf8));
768
-			if (!in_array($box['mailbox']->utf8,$sret) && $box['mailbox']->utf8!='INBOX') $ret[]=$box['mailbox']->utf8;
768
+			if (!in_array($box['mailbox']->utf8, $sret) && $box['mailbox']->utf8 != 'INBOX') $ret[] = $box['mailbox']->utf8;
769 769
 		}
770 770
 		return $ret;
771 771
 	}
@@ -777,12 +777,12 @@  discard block
 block discarded – undo
777 777
 	 * @param int $flags =null default Horde_Imap_Client::STATUS_ALL | Horde_Imap_Client::STATUS_FLAGS | Horde_Imap_Client::STATUS_PERMFLAGS
778 778
 	 * @return array of counters for mailbox
779 779
 	 */
780
-	function examineMailbox($mailbox, $flags=null)
780
+	function examineMailbox($mailbox, $flags = null)
781 781
 	{
782
-		if ($mailbox=='') return false;
782
+		if ($mailbox == '') return false;
783 783
 		$mailboxes = $this->listMailboxes($mailbox);
784 784
 
785
-		if (is_null($flags)) $flags = Horde_Imap_Client::STATUS_ALL | Horde_Imap_Client::STATUS_FLAGS | Horde_Imap_Client::STATUS_PERMFLAGS;
785
+		if (is_null($flags)) $flags = Horde_Imap_Client::STATUS_ALL|Horde_Imap_Client::STATUS_FLAGS|Horde_Imap_Client::STATUS_PERMFLAGS;
786 786
 
787 787
 		$mboxes = new Horde_Imap_Client_Mailbox_List($mailboxes);
788 788
 		//_debug_array($mboxes->count());
@@ -790,18 +790,18 @@  discard block
 block discarded – undo
790 790
 		{
791 791
 			//error_log(__METHOD__.__LINE__.array2string($box));
792 792
 			unset($box);
793
-			if ($k!='user' && $k != '' && $k==$mailbox)
793
+			if ($k != 'user' && $k != '' && $k == $mailbox)
794 794
 			{
795 795
 				$status = $this->status($k, $flags);
796 796
 				//error_log(__METHOD__.__LINE__.array2string($status));
797 797
 				foreach ($status as $key => $v)
798 798
 				{
799
-					$_status[strtoupper($key)]=$v;
799
+					$_status[strtoupper($key)] = $v;
800 800
 				}
801
-				if ($flags & (Horde_Imap_Client::STATUS_FLAGS|Horde_Imap_Client::STATUS_PERMFLAGS))
801
+				if ($flags&(Horde_Imap_Client::STATUS_FLAGS|Horde_Imap_Client::STATUS_PERMFLAGS))
802 802
 				{
803 803
 					self::$supports_keywords[$this->ImapServerId] = stripos(implode('', $status['flags']), '$label') !== false ||
804
-						in_array('\\*', $status['permflags']);	// arbitrary keyswords also allow keywords
804
+						in_array('\\*', $status['permflags']); // arbitrary keyswords also allow keywords
805 805
 				}
806 806
 				return $_status;
807 807
 			}
@@ -840,7 +840,7 @@  discard block
 block discarded – undo
840 840
 	 */
841 841
 	function hasCapability($capability)
842 842
 	{
843
-		if ($capability=='SUPPORTS_KEYWORDS')
843
+		if ($capability == 'SUPPORTS_KEYWORDS')
844 844
 		{
845 845
 			// if pseudo-flag is not set, call examineMailbox now to set it (no STATUS_ALL = counters necessary)
846 846
 			if (!isset(self::$supports_keywords[$this->ImapServerId]))
@@ -852,7 +852,7 @@  discard block
 block discarded – undo
852 852
 				catch (Exception $e)
853 853
 				{
854 854
 					error_log(__METHOD__.__LINE__.' (examineServer for detection) '.$capability.'->'.array2string(self::$supports_keywords).' failed '.function_backtrace());
855
-					self::$supports_keywords[$this->ImapServerId]=false;
855
+					self::$supports_keywords[$this->ImapServerId] = false;
856 856
 				}
857 857
 			}
858 858
 			//error_log(__METHOD__.__LINE__.' '.$capability.'->'.array2string(self::$supports_keywords).' '.function_backtrace());
@@ -902,9 +902,9 @@  discard block
 block discarded – undo
902 902
 	 */
903 903
 	static function getFolderPrefixFromNamespace($_nameSpace, $_folderName)
904 904
 	{
905
-		foreach($_nameSpace as &$singleNameSpace)
905
+		foreach ($_nameSpace as &$singleNameSpace)
906 906
 		{
907
-			if (substr($_folderName,0,strlen($singleNameSpace['prefix'])) == $singleNameSpace['prefix']) return $singleNameSpace['prefix'];
907
+			if (substr($_folderName, 0, strlen($singleNameSpace['prefix'])) == $singleNameSpace['prefix']) return $singleNameSpace['prefix'];
908 908
 		}
909 909
 		return "";
910 910
 	}
@@ -919,33 +919,33 @@  discard block
 block discarded – undo
919 919
 	 * @param string $reclevel = 0, counter to keep track of the current recursionlevel
920 920
 	 * @return array of mailboxes
921 921
 	 */
922
-	function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel=0)
922
+	function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel = 0)
923 923
 	{
924 924
 		if ($reclevel > 25) {
925
-			error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
925
+			error_log(__METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
926 926
 			return array();
927 927
 		}
928 928
 		$reclevel++;
929 929
 		// clean up double delimiters
930
-		$mailbox = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$_mailbox);
930
+		$mailbox = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter : $delimiter).'+~s', $delimiter, $_mailbox);
931 931
 		//get that mailbox in question
932
-		$mbx = $this->getMailboxes($mailbox,1,true);
932
+		$mbx = $this->getMailboxes($mailbox, 1, true);
933 933
 		$mbxkeys = array_keys($mbx);
934 934
 
935 935
 		// Example: Array([INBOX/GaGa] => Array([MAILBOX] => INBOX/GaGa[ATTRIBUTES] => Array([0] => \\unmarked)[delimiter] => /))
936
-		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"])))
936
+		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"])))
937 937
 		{
938
-			$buff = $this->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'].($mbx[$mbxkeys[0]]['MAILBOX'] == $prefix ? '':$delimiter),2,false);
938
+			$buff = $this->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'].($mbx[$mbxkeys[0]]['MAILBOX'] == $prefix ? '' : $delimiter), 2, false);
939 939
 			$allMailboxes = array();
940 940
 			foreach ($buff as $mbxname) {
941
-				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname['MAILBOX']);
941
+				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter : $delimiter).'+~s', $delimiter, $mbxname['MAILBOX']);
942 942
 				#echo "About to recur in level $reclevel:".$mbxname."<br>";
943
-				if ( $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'] && $mbxname != $prefix  && $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'].$delimiter)
943
+				if ($mbxname != $mbx[$mbxkeys[0]]['MAILBOX'] && $mbxname != $prefix && $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'].$delimiter)
944 944
 				{
945 945
 					$allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel));
946 946
 				}
947 947
 			}
948
-			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'];
948
+			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'];
949 949
 			return $allMailboxes;
950 950
 		}
951 951
 		else
@@ -964,24 +964,24 @@  discard block
 block discarded – undo
964 964
 	 */
965 965
 	function getNameSpace()
966 966
 	{
967
-		static $nameSpace=null;
967
+		static $nameSpace = null;
968 968
 		$foldersNameSpace = array();
969 969
 		$delimiter = $this->getDelimiter();
970
-		if (empty($delimiter)) $delimiter='/';
970
+		if (empty($delimiter)) $delimiter = '/';
971 971
 		if (is_null($nameSpace)) $nameSpace = $this->getNameSpaceArray();
972 972
 		if (is_array($nameSpace)) {
973
-			foreach($nameSpace as $type => $singleNameSpaceArray)
973
+			foreach ($nameSpace as $type => $singleNameSpaceArray)
974 974
 			{
975 975
 				foreach ($singleNameSpaceArray as $singleNameSpace)
976 976
 				{
977 977
 					$_foldersNameSpace = array();
978
-					if($type == 'personal' && $singleNameSpace['name'] == '#mh/' && ($this->folderExists('Mail')||$this->folderExists('INBOX')))
978
+					if ($type == 'personal' && $singleNameSpace['name'] == '#mh/' && ($this->folderExists('Mail') || $this->folderExists('INBOX')))
979 979
 					{
980 980
 						$_foldersNameSpace['prefix_present'] = 'forced';
981 981
 						// uw-imap server with mailbox prefix or dovecot maybe
982
-						$_foldersNameSpace['prefix'] = ($this->folderExists('Mail')?'Mail':(!empty($singleNameSpace['name'])?$singleNameSpace['name']:''));
982
+						$_foldersNameSpace['prefix'] = ($this->folderExists('Mail') ? 'Mail' : (!empty($singleNameSpace['name']) ? $singleNameSpace['name'] : ''));
983 983
 					}
984
-					elseif($type == 'personal' && ($singleNameSpace['name'] == '#mh/') && $this->folderExists('mail'))
984
+					elseif ($type == 'personal' && ($singleNameSpace['name'] == '#mh/') && $this->folderExists('mail'))
985 985
 					{
986 986
 						$_foldersNameSpace['prefix_present'] = 'forced';
987 987
 						// uw-imap server with mailbox prefix or dovecot maybe
@@ -990,9 +990,9 @@  discard block
 block discarded – undo
990 990
 						$_foldersNameSpace['prefix_present'] = !empty($singleNameSpace['name']);
991 991
 						$_foldersNameSpace['prefix'] = $singleNameSpace['name'];
992 992
 					}
993
-					$_foldersNameSpace['delimiter'] = ($singleNameSpace['delimiter']?$singleNameSpace['delimiter']:$delimiter);
993
+					$_foldersNameSpace['delimiter'] = ($singleNameSpace['delimiter'] ? $singleNameSpace['delimiter'] : $delimiter);
994 994
 					$_foldersNameSpace['type'] = $type;
995
-					$foldersNameSpace[] =$_foldersNameSpace;
995
+					$foldersNameSpace[] = $_foldersNameSpace;
996 996
 				}
997 997
 			}
998 998
 		}
@@ -1004,29 +1004,29 @@  discard block
 block discarded – undo
1004 1004
 	 * @param mixed _type (1=personal, 2=user/other, 3=shared)
1005 1005
 	 * @return string the delimimiter
1006 1006
 	 */
1007
-	function getDelimiter($_type=1)
1007
+	function getDelimiter($_type = 1)
1008 1008
 	{
1009 1009
 		switch ($_type)
1010 1010
 		{
1011 1011
 			case 'user':
1012 1012
 			case 'other':
1013 1013
 			case 2:
1014
-				$type=2;
1014
+				$type = 2;
1015 1015
 				break;
1016 1016
 			case 'shared':
1017 1017
 			case '':
1018 1018
 			case 3:
1019
-				$type=3;
1019
+				$type = 3;
1020 1020
 				break;
1021 1021
 			case 'personal':
1022 1022
 			case 1:
1023 1023
 			default:
1024
-				$type=1;
1024
+				$type = 1;
1025 1025
 		}
1026 1026
 		$namespaces = $this->getNamespaces();
1027 1027
 		foreach ($namespaces as $nsp)
1028 1028
 		{
1029
-			if ($nsp['type']==$type && $nsp['delimiter']) return $nsp['delimiter'];
1029
+			if ($nsp['type'] == $type && $nsp['delimiter']) return $nsp['delimiter'];
1030 1030
 		}
1031 1031
 		return "/";
1032 1032
 	}
@@ -1063,11 +1063,11 @@  discard block
 block discarded – undo
1063 1063
 		switch ($this->loginType)
1064 1064
 		{
1065 1065
 			case 'email':
1066
-				$accountemail = $GLOBALS['egw']->accounts->id2name($accountID,'account_email');
1066
+				$accountemail = $GLOBALS['egw']->accounts->id2name($accountID, 'account_email');
1067 1067
 				//$accountemail = $GLOBALS['egw']->accounts->read($GLOBALS['egw']->accounts->name2id($_username,'account_email'));
1068 1068
 				if (!empty($accountemail))
1069 1069
 				{
1070
-					list($lusername,$domain) = explode('@',$accountemail,2);
1070
+					list($lusername, $domain) = explode('@', $accountemail, 2);
1071 1071
 					if (strtolower($domain) == strtolower($this->domainName) && !empty($lusername))
1072 1072
 					{
1073 1073
 						$_username = $lusername;
@@ -1086,8 +1086,8 @@  discard block
 block discarded – undo
1086 1086
 				if (empty($this->loginType))
1087 1087
 				{
1088 1088
 					// try to figure out by params['acc_imap_username']
1089
-					list($lusername,$domain) = explode('@',$this->params['acc_imap_username'],2);
1090
-					if (strpos($_username,'@')===false && !empty($domain) && !empty($lusername))
1089
+					list($lusername, $domain) = explode('@', $this->params['acc_imap_username'], 2);
1090
+					if (strpos($_username, '@') === false && !empty($domain) && !empty($lusername))
1091 1091
 					{
1092 1092
 						$_username = $_username.'@'.$domain;
1093 1093
 					}
@@ -1131,20 +1131,20 @@  discard block
 block discarded – undo
1131 1131
 	 * @param string $_folderName=''
1132 1132
 	 * @return string utf-7 encoded (done in getMailboxName)
1133 1133
 	 */
1134
-	function getUserMailboxString($_username, $_folderName='')
1134
+	function getUserMailboxString($_username, $_folderName = '')
1135 1135
 	{
1136 1136
 		$nameSpaces = $this->getNameSpaceArray();
1137 1137
 
1138
-		if(!isset($nameSpaces['others'])) {
1138
+		if (!isset($nameSpaces['others'])) {
1139 1139
 			return false;
1140 1140
 		}
1141 1141
 
1142 1142
 		$username = $this->getMailBoxUserName($_username);
1143
-		if($this->loginType == 'vmailmgr' || $this->loginType == 'email' || $this->loginType == 'uidNumber') {
1144
-			$username .= '@'. $this->domainName;
1143
+		if ($this->loginType == 'vmailmgr' || $this->loginType == 'email' || $this->loginType == 'uidNumber') {
1144
+			$username .= '@'.$this->domainName;
1145 1145
 		}
1146 1146
 
1147
-		$mailboxString = $nameSpaces['others'][0]['name'] . $username . (!empty($_folderName) ? ($nameSpaces['others'][0]['delimiter']?$nameSpaces['others'][0]['delimiter']:'/') . $_folderName : '');
1147
+		$mailboxString = $nameSpaces['others'][0]['name'].$username.(!empty($_folderName) ? ($nameSpaces['others'][0]['delimiter'] ? $nameSpaces['others'][0]['delimiter'] : '/').$_folderName : '');
1148 1148
 
1149 1149
 		return $mailboxString;
1150 1150
 	}
@@ -1163,7 +1163,7 @@  discard block
 block discarded – undo
1163 1163
 		);
1164 1164
 		//error_log(__METHOD__.__LINE__.array2string($types));
1165 1165
 		$result = array();
1166
-		foreach($this->getNamespaces() as $data)
1166
+		foreach ($this->getNamespaces() as $data)
1167 1167
 		{
1168 1168
 			//error_log(__METHOD__.__LINE__.array2string($data));
1169 1169
 			if (isset($types[$data['type']]))
@@ -1173,7 +1173,7 @@  discard block
 block discarded – undo
1173 1173
 					'name' => $data['name'],
1174 1174
 					'prefix' => $data['name'],
1175 1175
 					'prefix_present' => !empty($data['name']),
1176
-					'delimiter' => ($data['delimiter']?$data['delimiter']:'/'),
1176
+					'delimiter' => ($data['delimiter'] ? $data['delimiter'] : '/'),
1177 1177
 				);
1178 1178
 			}
1179 1179
 		}
@@ -1194,7 +1194,7 @@  discard block
 block discarded – undo
1194 1194
 		{
1195 1195
 			if ($qInfo['storage'])
1196 1196
 			{
1197
-				return array('USED'=>$qInfo['storage']['usage'],'QMAX'=>$qInfo['storage']['limit']);
1197
+				return array('USED'=>$qInfo['storage']['usage'], 'QMAX'=>$qInfo['storage']['limit']);
1198 1198
 			}
1199 1199
 		}
1200 1200
 		return false;
@@ -1208,7 +1208,7 @@  discard block
 block discarded – undo
1208 1208
 	 * @param string $_what - what to retrieve either limit/QMAX, usage/USED or ALL is supported
1209 1209
 	 * @return int|array|boolean the quota for specified user (by what) or array with values for "limit" and "usage", or false
1210 1210
 	 */
1211
-	function getQuotaByUser($_username, $_what='QMAX')
1211
+	function getQuotaByUser($_username, $_what = 'QMAX')
1212 1212
 	{
1213 1213
 		$mailboxName = $this->getUserMailboxString($_username);
1214 1214
 		$storageQuota = $this->getQuotaRoot($mailboxName);
@@ -1217,7 +1217,7 @@  discard block
 block discarded – undo
1217 1217
 		if (is_array($storageQuota) && isset($storageQuota[$mailboxName]) && is_array($storageQuota[$mailboxName]) &&
1218 1218
 			isset($storageQuota[$mailboxName]['storage']) && is_array($storageQuota[$mailboxName]['storage']))
1219 1219
 		{
1220
-			switch($_what)
1220
+			switch ($_what)
1221 1221
 			{
1222 1222
 				case 'QMAX':
1223 1223
 					$_what = 'limit';
@@ -1243,7 +1243,7 @@  discard block
 block discarded – undo
1243 1243
 	 */
1244 1244
 	function getUserData($_username)
1245 1245
 	{
1246
-		unset($_username);	// not used
1246
+		unset($_username); // not used
1247 1247
 		return array();
1248 1248
 	}
1249 1249
 
@@ -1256,7 +1256,7 @@  discard block
 block discarded – undo
1256 1256
 	 */
1257 1257
 	function setUserData($_username, $_quota)
1258 1258
 	{
1259
-		unset($_username, $_quota);	// not used
1259
+		unset($_username, $_quota); // not used
1260 1260
 		return true;
1261 1261
 	}
1262 1262
 
@@ -1290,10 +1290,10 @@  discard block
 block discarded – undo
1290 1290
 	 * @param array $params
1291 1291
 	 * @throws Exception
1292 1292
 	 */
1293
-	public function __call($name,array $params=null)
1293
+	public function __call($name, array $params = null)
1294 1294
 	{
1295 1295
 		if ($this->debug) error_log(__METHOD__.'->'.$name.' with params:'.array2string($params));
1296
-		switch($name)
1296
+		switch ($name)
1297 1297
 		{
1298 1298
 			case 'installScript':
1299 1299
 			case 'getScript':
@@ -1310,11 +1310,11 @@  discard block
 block discarded – undo
1310 1310
 					{
1311 1311
 						PEAR::setErrorHandling(PEAR_ERROR_EXCEPTION);
1312 1312
 						$this->sieve = new emailadmin_sieve($this);
1313
-						$this->error =& $this->sieve->error;
1313
+						$this->error = & $this->sieve->error;
1314 1314
 					}
1315
-					$ret = call_user_func_array(array($this->sieve,$name),$params);
1315
+					$ret = call_user_func_array(array($this->sieve, $name), $params);
1316 1316
 				}
1317
-				catch(Exception $e) {
1317
+				catch (Exception $e) {
1318 1318
 					throw new PEAR_Exception('Error in Sieve: '.$e->getMessage(), $e);
1319 1319
 				}
1320 1320
 				//error_log(__CLASS__.'->'.$name.'('.array2string($params).') returns '.array2string($ret));
@@ -1331,7 +1331,7 @@  discard block
 block discarded – undo
1331 1331
 	 * @param string $_scriptName =null
1332 1332
 	 * @return boolean
1333 1333
 	 */
1334
-	public function setVacationUser($_euser, array $_vacation, $_scriptName=null)
1334
+	public function setVacationUser($_euser, array $_vacation, $_scriptName = null)
1335 1335
 	{
1336 1336
 		if ($this->debug) error_log(__METHOD__.' User:'.array2string($_euser).' Scriptname:'.array2string($_scriptName).' VacationMessage:'.array2string($_vacation));
1337 1337
 
@@ -1344,8 +1344,8 @@  discard block
 block discarded – undo
1344 1344
 			$this->adminConnection($_euser);
1345 1345
 			PEAR::setErrorHandling(PEAR_ERROR_EXCEPTION);
1346 1346
 			$this->sieve = new emailadmin_sieve($this, $_euser, $_scriptName);
1347
-			$this->scriptName =& $this->sieve->scriptName;
1348
-			$this->error =& $this->sieve->error;
1347
+			$this->scriptName = & $this->sieve->scriptName;
1348
+			$this->error = & $this->sieve->error;
1349 1349
 		}
1350 1350
 		$ret = $this->setVacation($_vacation, $_scriptName);
1351 1351
 
@@ -1360,7 +1360,7 @@  discard block
 block discarded – undo
1360 1360
 	 * @throws Exception on connection error or authentication failure
1361 1361
 	 * @return array
1362 1362
 	 */
1363
-	public function getVacationUser($_euser, $_scriptName=null)
1363
+	public function getVacationUser($_euser, $_scriptName = null)
1364 1364
 	{
1365 1365
 		if ($this->debug) error_log(__METHOD__.' User:'.array2string($_euser));
1366 1366
 
@@ -1373,8 +1373,8 @@  discard block
 block discarded – undo
1373 1373
 			$this->adminConnection($_euser);
1374 1374
 			PEAR::setErrorHandling(PEAR_ERROR_EXCEPTION);
1375 1375
 			$this->sieve = new emailadmin_sieve($this, $_euser, $_scriptName);
1376
-			$this->error =& $this->sieve->error;
1377
-			$this->scriptName =& $this->sieve->scriptName;
1376
+			$this->error = & $this->sieve->error;
1377
+			$this->scriptName = & $this->sieve->scriptName;
1378 1378
 		}
1379 1379
 		return $this->sieve->getVacation();
1380 1380
 	}
@@ -1394,7 +1394,7 @@  discard block
 block discarded – undo
1394 1394
 	 */
1395 1395
 	public function init_static()
1396 1396
 	{
1397
-		self::$supports_keywords =& egw_cache::getSession (__CLASS__, 'supports_keywords');
1397
+		self::$supports_keywords = & egw_cache::getSession(__CLASS__, 'supports_keywords');
1398 1398
 	}
1399 1399
 }
1400 1400
 emailadmin_imap::init_static();
Please login to merge, or discard this patch.
Braces   +130 added lines, -42 removed lines patch added patch discarded remove patch
@@ -156,7 +156,10 @@  discard block
 block discarded – undo
156 156
 		$this->loginType = $this->params['acc_imap_logintype'];
157 157
 		$this->domainName = $this->params['acc_domain'];
158 158
 
159
-		if (is_null($_timeout)) $_timeout = $this->params['acc_imap_timeout']?$this->params['acc_imap_timeout']:self::getTimeOut ();
159
+		if (is_null($_timeout))
160
+		{
161
+			$_timeout = $this->params['acc_imap_timeout']?$this->params['acc_imap_timeout']:self::getTimeOut ();
162
+		}
160 163
 
161 164
 		// Horde use locale for translation of error messages
162 165
 		Api\Preferences::setlocale(LC_MESSAGES);
@@ -167,7 +170,10 @@  discard block
 block discarded – undo
167 170
 		{
168 171
 			$username = $this->getMailBoxUserName($username);
169 172
 		}
170
-		if ($_adminConnection) $this->adminConnection($username);
173
+		if ($_adminConnection)
174
+		{
175
+			$this->adminConnection($username);
176
+		}
171 177
 		$parent_params = array(
172 178
 			'username' => $this->params[$_adminConnection ? 'acc_imap_admin_username' : 'acc_imap_username'],
173 179
 			'password' => $this->params[$_adminConnection ? 'acc_imap_admin_password' : 'acc_imap_password'],
@@ -303,7 +309,11 @@  discard block
 block discarded – undo
303 309
 	static function getTimeOut($_use='IMAP')
304 310
 	{
305 311
 		$timeout = $GLOBALS['egw_info']['user']['preferences']['mail']['connectionTimeout'];
306
-		if (empty($timeout) || !($timeout > 0)) $timeout = $_use == 'SIEVE' ? 10 : 20; // this is the default value
312
+		if (empty($timeout) || !($timeout > 0))
313
+		{
314
+			$timeout = $_use == 'SIEVE' ? 10 : 20;
315
+		}
316
+		// this is the default value
307 317
 		return $timeout;
308 318
 	}
309 319
 
@@ -366,7 +376,8 @@  discard block
 block discarded – undo
366 376
 	 */
367 377
 	function encodeFolderName($_folderName)
368 378
 	{
369
-		if($this->mbAvailable) {
379
+		if($this->mbAvailable)
380
+		{
370 381
 			return mb_convert_encoding($_folderName, "UTF7-IMAP", Api\Translation::charset());
371 382
 		}
372 383
 
@@ -384,14 +395,21 @@  discard block
 block discarded – undo
384 395
 	function getMailbox($mailbox)
385 396
 	{
386 397
 		$mailboxes = $this->listMailboxes($mailbox,Horde_Imap_Client::MBOX_ALL);
387
-		if (empty($mailboxes)) $mailboxes = $this->listMailboxes($mailbox,Horde_Imap_Client::MBOX_UNSUBSCRIBED);
398
+		if (empty($mailboxes))
399
+		{
400
+			$mailboxes = $this->listMailboxes($mailbox,Horde_Imap_Client::MBOX_UNSUBSCRIBED);
401
+		}
388 402
 		//error_log(__METHOD__.__LINE__.'->'.$mailbox.'/'.array2string($mailboxes));
389 403
 		$mboxes = new Horde_Imap_Client_Mailbox_List($mailboxes);
390 404
 		//_debug_array($mboxes->count());
391 405
 		foreach ($mboxes->getIterator() as $k =>$box)
392 406
 		{
393 407
 			//error_log(__METHOD__.__LINE__.'->'.$k);
394
-			if ($k!='user' && $k != '' && $k==$mailbox) return $box['mailbox']; //_debug_array(array($k => $client->status($k)));
408
+			if ($k!='user' && $k != '' && $k==$mailbox)
409
+			{
410
+				return $box['mailbox'];
411
+			}
412
+			//_debug_array(array($k => $client->status($k)));
395 413
 		}
396 414
 		return ($this->mailboxExist($mailbox)?$mailbox:false);
397 415
 	}
@@ -460,8 +478,14 @@  discard block
 block discarded – undo
460 478
 			//throw new egw_exception(__METHOD__.' ('.__LINE__.") failed to ".__METHOD__." :".$e->getMessage());
461 479
 			unset($e);
462 480
 		}
463
-		if (!empty($mailbox)) return $mailbox['mailbox'];
464
-		if (empty($mailbox) && $this->mailboxExist('INBOX')) return 'INBOX';
481
+		if (!empty($mailbox))
482
+		{
483
+			return $mailbox['mailbox'];
484
+		}
485
+		if (empty($mailbox) && $this->mailboxExist('INBOX'))
486
+		{
487
+			return 'INBOX';
488
+		}
465 489
 		return null;
466 490
 	}
467 491
 
@@ -531,7 +555,10 @@  discard block
 block discarded – undo
531 555
 			));
532 556
 
533 557
 		$flags = Horde_Imap_Client::STATUS_ALL;
534
-		if ($ignoreStatusCache) $flags |= Horde_Imap_Client::STATUS_FORCE_REFRESH;
558
+		if ($ignoreStatusCache)
559
+		{
560
+			$flags |= Horde_Imap_Client::STATUS_FORCE_REFRESH;
561
+		}
535 562
 
536 563
 		$mboxes = new Horde_Imap_Client_Mailbox_List($mailboxes);
537 564
 		//error_log(__METHOD__.__LINE__.array2string($mboxes->count()));
@@ -574,12 +601,15 @@  discard block
 block discarded – undo
574 601
 	 */
575 602
 	function getMailboxes($reference = ''  , $restriction_search = 0, $returnAttributes = false)
576 603
 	{
577
-		if ( is_bool($restriction_search) ){
604
+		if ( is_bool($restriction_search) )
605
+		{
578 606
 			$restriction_search = (int) $restriction_search;
579 607
 		}
580 608
 		$mailbox = '';
581
-		if ( is_int( $restriction_search ) ){
582
-			switch ( $restriction_search ) {
609
+		if ( is_int( $restriction_search ) )
610
+		{
611
+			switch ( $restriction_search )
612
+			{
583 613
 			case 0:
584 614
 				$searchstring = $reference."*";
585 615
 				break;
@@ -591,8 +621,11 @@  discard block
 block discarded – undo
591 621
 				$searchstring = $reference."%";
592 622
 				break;
593 623
 			}
594
-		}else{
595
-			if ( is_string( $restriction_search ) ){
624
+		}
625
+		else
626
+		{
627
+			if ( is_string( $restriction_search ) )
628
+			{
596 629
 				$mailbox = $searchstring = $restriction_search;
597 630
 			}
598 631
 		}
@@ -658,12 +691,15 @@  discard block
 block discarded – undo
658 691
 	 */
659 692
 	function listSubscribedMailboxes($reference = ''  , $restriction_search = 0, $returnAttributes = false)
660 693
 	{
661
-		if ( is_bool($restriction_search) ){
694
+		if ( is_bool($restriction_search) )
695
+		{
662 696
 			$restriction_search = (int) $restriction_search;
663 697
 		}
664 698
 		$mailbox = '';
665
-		if ( is_int( $restriction_search ) ){
666
-			switch ( $restriction_search ) {
699
+		if ( is_int( $restriction_search ) )
700
+		{
701
+			switch ( $restriction_search )
702
+			{
667 703
 			case 0:
668 704
 				$searchstring = $reference."*";
669 705
 				break;
@@ -675,8 +711,11 @@  discard block
 block discarded – undo
675 711
 				$searchstring = $reference."%";
676 712
 				break;
677 713
 			}
678
-		}else{
679
-			if ( is_string( $restriction_search ) ){
714
+		}
715
+		else
716
+		{
717
+			if ( is_string( $restriction_search ) )
718
+			{
680 719
 				$mailbox = $searchstring = $restriction_search;
681 720
 			}
682 721
 		}
@@ -724,12 +763,15 @@  discard block
 block discarded – undo
724 763
 	 */
725 764
 	function listUnSubscribedMailboxes($reference = ''  , $restriction_search = 0)
726 765
 	{
727
-		if ( is_bool($restriction_search) ){
766
+		if ( is_bool($restriction_search) )
767
+		{
728 768
 			$restriction_search = (int) $restriction_search;
729 769
 		}
730 770
 
731
-		if ( is_int( $restriction_search ) ){
732
-			switch ( $restriction_search ) {
771
+		if ( is_int( $restriction_search ) )
772
+		{
773
+			switch ( $restriction_search )
774
+			{
733 775
 			case 0:
734 776
 				$mailbox = $reference."*";
735 777
 				break;
@@ -741,8 +783,11 @@  discard block
 block discarded – undo
741 783
 				$mailbox = "%";
742 784
 				break;
743 785
 			}
744
-		}else{
745
-			if ( is_string( $restriction_search ) ){
786
+		}
787
+		else
788
+		{
789
+			if ( is_string( $restriction_search ) )
790
+			{
746 791
 				$mailbox = $restriction_search;
747 792
 			}
748 793
 		}
@@ -761,7 +806,10 @@  discard block
 block discarded – undo
761 806
 		foreach ($unsubscribed as $box)
762 807
 		{
763 808
 			//error_log(__METHOD__.__LINE__.' Box:'.$k.'->'.array2string($box['mailbox']->utf8));
764
-			if (!in_array($box['mailbox']->utf8,$sret) && $box['mailbox']->utf8!='INBOX') $ret[]=$box['mailbox']->utf8;
809
+			if (!in_array($box['mailbox']->utf8,$sret) && $box['mailbox']->utf8!='INBOX')
810
+			{
811
+				$ret[]=$box['mailbox']->utf8;
812
+			}
765 813
 		}
766 814
 		return $ret;
767 815
 	}
@@ -775,10 +823,16 @@  discard block
 block discarded – undo
775 823
 	 */
776 824
 	function examineMailbox($mailbox, $flags=null)
777 825
 	{
778
-		if ($mailbox=='') return false;
826
+		if ($mailbox=='')
827
+		{
828
+			return false;
829
+		}
779 830
 		$mailboxes = $this->listMailboxes($mailbox);
780 831
 
781
-		if (is_null($flags)) $flags = Horde_Imap_Client::STATUS_ALL | Horde_Imap_Client::STATUS_FLAGS | Horde_Imap_Client::STATUS_PERMFLAGS;
832
+		if (is_null($flags))
833
+		{
834
+			$flags = Horde_Imap_Client::STATUS_ALL | Horde_Imap_Client::STATUS_FLAGS | Horde_Imap_Client::STATUS_PERMFLAGS;
835
+		}
782 836
 
783 837
 		$mboxes = new Horde_Imap_Client_Mailbox_List($mailboxes);
784 838
 		//_debug_array($mboxes->count());
@@ -860,7 +914,10 @@  discard block
 block discarded – undo
860 914
 		}
861 915
 		catch (\Exception $e)
862 916
 		{
863
-			if ($this->debug) error_log(__METHOD__.__LINE__.' error querying for capability:'.$capability.' ->'.$e->getMessage());
917
+			if ($this->debug)
918
+			{
919
+				error_log(__METHOD__.__LINE__.' error querying for capability:'.$capability.' ->'.$e->getMessage());
920
+			}
864 921
 			return false;
865 922
 		}
866 923
 		if (!is_array($cap))
@@ -900,7 +957,10 @@  discard block
 block discarded – undo
900 957
 	{
901 958
 		foreach($_nameSpace as &$singleNameSpace)
902 959
 		{
903
-			if (substr($_folderName,0,strlen($singleNameSpace['prefix'])) == $singleNameSpace['prefix']) return $singleNameSpace['prefix'];
960
+			if (substr($_folderName,0,strlen($singleNameSpace['prefix'])) == $singleNameSpace['prefix'])
961
+			{
962
+				return $singleNameSpace['prefix'];
963
+			}
904 964
 		}
905 965
 		return "";
906 966
 	}
@@ -917,7 +977,8 @@  discard block
 block discarded – undo
917 977
 	 */
918 978
 	function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel=0)
919 979
 	{
920
-		if ($reclevel > 25) {
980
+		if ($reclevel > 25)
981
+		{
921 982
 			error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
922 983
 			return array();
923 984
 		}
@@ -933,7 +994,8 @@  discard block
 block discarded – undo
933 994
 		{
934 995
 			$buff = $this->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'].($mbx[$mbxkeys[0]]['MAILBOX'] == $prefix ? '':$delimiter),2,false);
935 996
 			$allMailboxes = array();
936
-			foreach ($buff as $mbxname) {
997
+			foreach ($buff as $mbxname)
998
+			{
937 999
 				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname['MAILBOX']);
938 1000
 				#echo "About to recur in level $reclevel:".$mbxname."<br>";
939 1001
 				if ( $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'] && $mbxname != $prefix  && $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'].$delimiter)
@@ -941,7 +1003,10 @@  discard block
 block discarded – undo
941 1003
 					$allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel));
942 1004
 				}
943 1005
 			}
944
-			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'];
1006
+			if (!(in_array('\NoSelect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"])))
1007
+			{
1008
+				$allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX'];
1009
+			}
945 1010
 			return $allMailboxes;
946 1011
 		}
947 1012
 		else
@@ -963,9 +1028,16 @@  discard block
 block discarded – undo
963 1028
 		static $nameSpace=null;
964 1029
 		$foldersNameSpace = array();
965 1030
 		$delimiter = $this->getDelimiter();
966
-		if (empty($delimiter)) $delimiter='/';
967
-		if (is_null($nameSpace)) $nameSpace = $this->getNameSpaceArray();
968
-		if (is_array($nameSpace)) {
1031
+		if (empty($delimiter))
1032
+		{
1033
+			$delimiter='/';
1034
+		}
1035
+		if (is_null($nameSpace))
1036
+		{
1037
+			$nameSpace = $this->getNameSpaceArray();
1038
+		}
1039
+		if (is_array($nameSpace))
1040
+		{
969 1041
 			foreach($nameSpace as $type => $singleNameSpaceArray)
970 1042
 			{
971 1043
 				foreach ($singleNameSpaceArray as $singleNameSpace)
@@ -982,7 +1054,9 @@  discard block
 block discarded – undo
982 1054
 						$_foldersNameSpace['prefix_present'] = 'forced';
983 1055
 						// uw-imap server with mailbox prefix or dovecot maybe
984 1056
 						$_foldersNameSpace['prefix'] = 'mail';
985
-					} else {
1057
+					}
1058
+					else
1059
+					{
986 1060
 						$_foldersNameSpace['prefix_present'] = !empty($singleNameSpace['name']);
987 1061
 						$_foldersNameSpace['prefix'] = $singleNameSpace['name'];
988 1062
 					}
@@ -1022,7 +1096,10 @@  discard block
 block discarded – undo
1022 1096
 		$namespaces = $this->getNamespaces();
1023 1097
 		foreach ($namespaces as $nsp)
1024 1098
 		{
1025
-			if ($nsp['type']==$type && $nsp['delimiter']) return $nsp['delimiter'];
1099
+			if ($nsp['type']==$type && $nsp['delimiter'])
1100
+			{
1101
+				return $nsp['delimiter'];
1102
+			}
1026 1103
 		}
1027 1104
 		return "/";
1028 1105
 	}
@@ -1131,12 +1208,14 @@  discard block
 block discarded – undo
1131 1208
 	{
1132 1209
 		$nameSpaces = $this->getNameSpaceArray();
1133 1210
 
1134
-		if(!isset($nameSpaces['others'])) {
1211
+		if(!isset($nameSpaces['others']))
1212
+		{
1135 1213
 			return false;
1136 1214
 		}
1137 1215
 
1138 1216
 		$username = $this->getMailBoxUserName($_username);
1139
-		if($this->loginType == 'vmailmgr' || $this->loginType == 'email' || $this->loginType == 'uidNumber') {
1217
+		if($this->loginType == 'vmailmgr' || $this->loginType == 'email' || $this->loginType == 'uidNumber')
1218
+		{
1140 1219
 			$username .= '@'. $this->domainName;
1141 1220
 		}
1142 1221
 
@@ -1288,7 +1367,10 @@  discard block
 block discarded – undo
1288 1367
 	 */
1289 1368
 	public function __call($name,array $params=null)
1290 1369
 	{
1291
-		if ($this->debug) error_log(__METHOD__.'->'.$name.' with params:'.array2string($params));
1370
+		if ($this->debug)
1371
+		{
1372
+			error_log(__METHOD__.'->'.$name.' with params:'.array2string($params));
1373
+		}
1292 1374
 		switch($name)
1293 1375
 		{
1294 1376
 			case 'installScript':
@@ -1323,7 +1405,10 @@  discard block
 block discarded – undo
1323 1405
 	 */
1324 1406
 	public function setVacationUser($_euser, array $_vacation, $_scriptName=null)
1325 1407
 	{
1326
-		if ($this->debug) error_log(__METHOD__.' User:'.array2string($_euser).' Scriptname:'.array2string($_scriptName).' VacationMessage:'.array2string($_vacation));
1408
+		if ($this->debug)
1409
+		{
1410
+			error_log(__METHOD__.' User:'.array2string($_euser).' Scriptname:'.array2string($_scriptName).' VacationMessage:'.array2string($_vacation));
1411
+		}
1327 1412
 
1328 1413
 		if (is_numeric($_euser))
1329 1414
 		{
@@ -1351,7 +1436,10 @@  discard block
 block discarded – undo
1351 1436
 	 */
1352 1437
 	public function getVacationUser($_euser, $_scriptName=null)
1353 1438
 	{
1354
-		if ($this->debug) error_log(__METHOD__.' User:'.array2string($_euser));
1439
+		if ($this->debug)
1440
+		{
1441
+			error_log(__METHOD__.' User:'.array2string($_euser));
1442
+		}
1355 1443
 
1356 1444
 		if (is_numeric($_euser))
1357 1445
 		{
Please login to merge, or discard this patch.
emailadmin/inc/class.emailadmin_imapbase.inc.php 4 patches
Doc Comments   +15 added lines, -11 removed lines patch added patch discarded remove patch
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 	 * forceEAProfileLoad
411 411
 	 * used to force the load of a specific emailadmin profile; we assume administrative use only (as of now)
412 412
 	 * @param int $_profile_id
413
-	 * @return object instance of emailadmin_imapbase (by reference)
413
+	 * @return emailadmin_imapbase instance of emailadmin_imapbase (by reference)
414 414
 	 */
415 415
 	public static function &forceEAProfileLoad($_profile_id)
416 416
 	{
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
 	/**
685 685
 	 * Get all identities of given mailaccount
686 686
 	 *
687
-	 * @param int|emailadmin_account $account account-object or acc_id
687
+	 * @param integer $account account-object or acc_id
688 688
 	 * @return array - array(email=>realname)
689 689
 	 */
690 690
 	function getAccountIdentities($account) {
@@ -1794,6 +1794,7 @@  discard block
 block discarded – undo
1794 1794
 	 *
1795 1795
 	 * @param mixed _sort the integer sort order / or a valid and handeled SORTSTRING (right now: UID/ARRIVAL/INTERNALDATE (->ARRIVAL))
1796 1796
 	 * @param bool _reverse wether to add REVERSE to the Sort String or not
1797
+	 * @param integer $_sort
1797 1798
 	 * @return the sort sequence for horde search
1798 1799
 	 */
1799 1800
 	function _getSortString($_sort, $_reverse=false)
@@ -2229,7 +2230,7 @@  discard block
 block discarded – undo
2229 2230
 	 * @param string _parent the parent foldername
2230 2231
 	 * @param string _folderName the new foldername
2231 2232
 	 *
2232
-	 * @return mixed name of the newly created folder or false on error
2233
+	 * @return string name of the newly created folder or false on error
2233 2234
 	 * @throws egw_exception
2234 2235
 	 */
2235 2236
 	function renameFolder($_oldFolderName, $_parent, $_folderName)
@@ -3073,7 +3074,7 @@  discard block
 block discarded – undo
3073 3074
 	 * @param string $_mailbox
3074 3075
 	 * @param string $delimiter
3075 3076
 	 * @param string $prefix
3076
-	 * @param string $reclevel 0, counter to keep track of the current recursionlevel
3077
+	 * @param integer $reclevel 0, counter to keep track of the current recursionlevel
3077 3078
 	 * @return array of mailboxes
3078 3079
 	 */
3079 3080
 	function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel=0)
@@ -3123,7 +3124,7 @@  discard block
 block discarded – undo
3123 3124
 	 * abstraction layer for getDraftFolder, getTemplateFolder, getTrashFolder and getSentFolder
3124 3125
 	 * @param string $_type the type to fetch (Drafts|Template|Trash|Sent)
3125 3126
 	 * @param boolean $_checkexistance trigger check for existance
3126
-	 * @param boolean& $created =null on return true: if folder was just created, false if not
3127
+	 * @param boolean $created =null on return true: if folder was just created, false if not
3127 3128
 	 * @return mixed string or false
3128 3129
 	 */
3129 3130
 	function _getSpecialUseFolder($_type, $_checkexistance=TRUE, &$created=null)
@@ -3245,7 +3246,7 @@  discard block
 block discarded – undo
3245 3246
 	/**
3246 3247
 	 * getTemplateFolder wrapper for _getSpecialUseFolder Type Template
3247 3248
 	 * @param boolean $_checkexistance trigger check for existance
3248
-	 * @return mixed string or false
3249
+	 * @return string string or false
3249 3250
 	 */
3250 3251
 	function getTemplateFolder($_checkexistance=TRUE)
3251 3252
 	{
@@ -3275,7 +3276,7 @@  discard block
 block discarded – undo
3275 3276
 	/**
3276 3277
 	 * getOutboxFolder wrapper for _getSpecialUseFolder Type Outbox
3277 3278
 	 * @param boolean $_checkexistance trigger check for existance
3278
-	 * @return mixed string or false
3279
+	 * @return string string or false
3279 3280
 	 */
3280 3281
 	function getOutboxFolder($_checkexistance=TRUE)
3281 3282
 	{
@@ -4104,7 +4105,7 @@  discard block
 block discarded – undo
4104 4105
 	/**
4105 4106
 	 * get part of the message, if its stucture is indicating its of multipart alternative style
4106 4107
 	 * a wrapper for multipartmixed
4107
-	 * @param string/int $_uid the messageuid,
4108
+	 * @param integer $_uid the messageuid,
4108 4109
 	 * @param Horde_Mime_Part $_structure structure for parsing
4109 4110
 	 * @param string $_htmlMode how to display a message, html, plain text, ...
4110 4111
 	 * @param boolean $_preserveSeen flag to preserve the seenflag by using body.peek
@@ -4754,6 +4755,9 @@  discard block
 block discarded – undo
4754 4755
 		return $message;
4755 4756
 	}
4756 4757
 
4758
+	/**
4759
+	 * @param integer $cols
4760
+	 */
4757 4761
 	static function wordwrap($str, $cols, $cut, $dontbreaklinesstartingwith=false)
4758 4762
 	{
4759 4763
 		$lines = explode("\n", $str);
@@ -5194,7 +5198,6 @@  discard block
 block discarded – undo
5194 5198
 	 * @param string $_partID = null
5195 5199
 	 * @param string $_folder = null
5196 5200
 	 * @param boolean $_preserveSeen = false flag to preserve the seenflag by using body.peek
5197
-	 * @param Horde_Imap_Client_Fetch_Query $fquery=null default query just structure
5198 5201
 	 * @return Horde_Mime_Part
5199 5202
 	 */
5200 5203
 	function getStructure($_uid, $_partID=null, $_folder=null, $_preserveSeen=false)
@@ -5773,6 +5776,7 @@  discard block
 block discarded – undo
5773 5776
 	 * @param preserveHTML flag to pass through to getdisplayableBody
5774 5777
 	 * @param addHeaderSection flag to be able to supress headersection
5775 5778
 	 * @param includeAttachments flag to be able to supress possible attachments
5779
+	 * @param emailadmin_imapbase $mailClass
5776 5780
 	 * @return array/bool with 'mailaddress'=>$mailaddress,
5777 5781
 	 *				'subject'=>$subject,
5778 5782
 	 *				'message'=>$message,
@@ -6226,7 +6230,7 @@  discard block
 block discarded – undo
6226 6230
 	 *
6227 6231
 	 * @param egw_mailer $_mailObject instance of the egw_mailer/phpmailer Object to be used
6228 6232
 	 * @param string $_html2parse the html to parse and to be altered, if conditions meet
6229
-	 * @param $mail_bo mail bo object
6233
+	 * @param mail_bo $mail_bo mail bo object
6230 6234
 	 * @return void
6231 6235
 	 */
6232 6236
 	static function processURL2InlineImages($_mailObject, &$_html2parse, $mail_bo)
@@ -6585,7 +6589,7 @@  discard block
 block discarded – undo
6585 6589
 	/**
6586 6590
 	 * Parses a message/rfc mail from file to the mailobject
6587 6591
 	 *
6588
-	 * @param object $mailer instance of the SMTP Mailer Object
6592
+	 * @param egw_mailer $mailer instance of the SMTP Mailer Object
6589 6593
 	 * @param string $tmpFileName string that points/leads to the file to be imported
6590 6594
 	 * @throws egw_exception_not_found if $fle is not found
6591 6595
 	 */
Please login to merge, or discard this patch.
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -6730,14 +6730,14 @@
 block discarded – undo
6730 6730
 					{
6731 6731
 						if ($this->folderExists($_folder,true))
6732 6732
 						{
6733
-						    if($this->isSentFolder($_folder))
6733
+							if($this->isSentFolder($_folder))
6734 6734
 							{
6735
-						        $flags = '\\Seen';
6736
-						    } elseif($this->isDraftFolder($_folder)) {
6737
-						        $flags = '\\Draft';
6738
-						    } else {
6739
-						        $flags = '';
6740
-						    }
6735
+								$flags = '\\Seen';
6736
+							} elseif($this->isDraftFolder($_folder)) {
6737
+								$flags = '\\Draft';
6738
+							} else {
6739
+								$flags = '';
6740
+							}
6741 6741
 							$savefailed = false;
6742 6742
 							try
6743 6743
 							{
Please login to merge, or discard this patch.
Braces   +1738 added lines, -515 removed lines patch added patch discarded remove patch
@@ -178,7 +178,10 @@  discard block
 block discarded – undo
178 178
 	public static function getInstance($_restoreSession=true, &$_profileID=0, $_validate=true, $_oldImapServerObject=false, $_reuseCache=null)
179 179
 	{
180 180
 		//$_restoreSession=false;
181
-		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
181
+		if (is_null($_reuseCache))
182
+		{
183
+			$_reuseCache = $_restoreSession;
184
+		}
182 185
 		//error_log(__METHOD__.' ('.__LINE__.') '.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID.'/'.emailadmin_account::get_default_acc_id().' for user:'.$GLOBALS['egw_info']['user']['account_lid'].' called from:'.function_backtrace());
183 186
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_oldImapServerObject));
184 187
 		if ($_oldImapServerObject instanceof emailadmin_imap)
@@ -204,9 +207,15 @@  discard block
 block discarded – undo
204 207
 			{
205 208
 				$profileID = emailadmin_account::get_default_acc_id();
206 209
 			}
207
-			if ($profileID!=$_profileID) $_restoreSession==false;
210
+			if ($profileID!=$_profileID)
211
+			{
212
+				$_restoreSession==false;
213
+			}
208 214
 			$_profileID=$profileID;
209
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace());
215
+			if (self::$debug)
216
+			{
217
+				error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace());
218
+			}
210 219
 		}
211 220
 		// no validation or restoreSession for old ImapServer Object, just fetch it and return it
212 221
 		if ($_oldImapServerObject===true)
@@ -245,7 +254,8 @@  discard block
 block discarded – undo
245 254
 				// TODO: merge mailprefs into userprefs, for easy treatment
246 255
 				self::$instances[$_profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
247 256
 				self::$instances[$_profileID]->htmlOptions  = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
248
-			} catch (egw_exception $e)
257
+			}
258
+			catch (egw_exception $e)
249 259
 			{
250 260
 				$newprofileID = emailadmin_account::get_default_acc_id();
251 261
 				// try loading the default profile for the user
@@ -263,9 +273,15 @@  discard block
 block discarded – undo
263 273
 			self::storeActiveProfileIDToPref(self::$instances[$_profileID]->icServer, $_profileID, $_validate );
264 274
 		}
265 275
 		self::$instances[$_profileID]->profileID = $_profileID;
266
-		if (!isset(self::$instances[$_profileID]->idna2)) self::$instances[$_profileID]->idna2 = new egw_idna;
276
+		if (!isset(self::$instances[$_profileID]->idna2))
277
+		{
278
+			self::$instances[$_profileID]->idna2 = new egw_idna;
279
+		}
267 280
 		//if ($_profileID==0); error_log(__METHOD__.' ('.__LINE__.') '.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID);
268
-		if (is_null(self::$mailConfig)) self::$mailConfig = config::read('mail');
281
+		if (is_null(self::$mailConfig))
282
+		{
283
+			self::$mailConfig = config::read('mail');
284
+		}
269 285
 		return self::$instances[$_profileID];
270 286
 	}
271 287
 
@@ -290,14 +306,20 @@  discard block
 block discarded – undo
290 306
 			}
291 307
 			catch (Exception $e)
292 308
 			{
293
-				if ($_profileID != emailadmin_account::get_default_acc_id()) $_profileID = emailadmin_account::get_default_acc_id();
309
+				if ($_profileID != emailadmin_account::get_default_acc_id())
310
+				{
311
+					$_profileID = emailadmin_account::get_default_acc_id();
312
+				}
294 313
 				error_log(__METHOD__.__LINE__.' '.$e->getMessage());
295 314
 				return false;
296 315
 			}
297 316
 		}
298 317
 		if ($oldProfileID != $_profileID)
299 318
 		{
300
-			if ($oldProfileID && $_profileID==0) $_profileID = $oldProfileID;
319
+			if ($oldProfileID && $_profileID==0)
320
+			{
321
+				$_profileID = $oldProfileID;
322
+			}
301 323
 			$GLOBALS['egw']->preferences->add('mail','ActiveProfileID',$_profileID,'user');
302 324
 			// save prefs
303 325
 			$GLOBALS['egw']->preferences->save_repository(true);
@@ -327,11 +349,17 @@  discard block
 block discarded – undo
327 349
 				{
328 350
 					return $_acc_id;
329 351
 				}
330
-				if (self::$debug) error_log(__METHOD__."($_acc_id) account NOT valid, no imap-host!");
352
+				if (self::$debug)
353
+				{
354
+					error_log(__METHOD__."($_acc_id) account NOT valid, no imap-host!");
355
+				}
331 356
 			}
332 357
 			catch (Exception $e) {
333 358
 				unset($e);
334
-				if (self::$debug) error_log(__METHOD__."($_acc_id) account NOT found!");
359
+				if (self::$debug)
360
+				{
361
+					error_log(__METHOD__."($_acc_id) account NOT found!");
362
+				}
335 363
 			}
336 364
 		}
337 365
 		// no account specified or specified account not found or not valid
@@ -340,11 +368,17 @@  discard block
 block discarded – undo
340 368
 		{
341 369
 			if (!empty($imap_host) && ($account = emailadmin_account::read($acc_id)) && $account->is_imap())
342 370
 			{
343
-				if (self::$debug && $_acc_id) error_log(__METHOD__."($_acc_id) using $acc_id instead");
371
+				if (self::$debug && $_acc_id)
372
+				{
373
+					error_log(__METHOD__."($_acc_id) using $acc_id instead");
374
+				}
344 375
 				return $acc_id;
345 376
 			}
346 377
 		}
347
-		if (self::$debug) error_log(__METHOD__."($_acc_id) NO valid account found!");
378
+		if (self::$debug)
379
+		{
380
+			error_log(__METHOD__."($_acc_id) NO valid account found!");
381
+		}
348 382
 		return 0;
349 383
 	}
350 384
 
@@ -360,10 +394,19 @@  discard block
 block discarded – undo
360 394
 	 */
361 395
 	private function __construct($_displayCharset='utf-8',$_restoreSession=true, $_profileID=0, $_oldImapServerObject=false, $_reuseCache=null)
362 396
 	{
363
-		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
364
-		if (!empty($_displayCharset)) self::$displayCharset = $_displayCharset;
397
+		if (is_null($_reuseCache))
398
+		{
399
+			$_reuseCache = $_restoreSession;
400
+		}
401
+		if (!empty($_displayCharset))
402
+		{
403
+			self::$displayCharset = $_displayCharset;
404
+		}
365 405
 		// not nummeric, we assume we only want an empty class object
366
-		if (!is_numeric($_profileID)) return true;
406
+		if (!is_numeric($_profileID))
407
+		{
408
+			return true;
409
+		}
367 410
 		if ($_restoreSession)
368 411
 		{
369 412
 			//error_log(__METHOD__." Session restore ".function_backtrace());
@@ -378,7 +421,10 @@  discard block
 block discarded – undo
378 421
 			$firstMessage = $this->sessionData['previewMessage'];
379 422
 			$this->sessionData = array();
380 423
 		}
381
-		if (!$_reuseCache) $this->forcePrefReload($_profileID,!$_reuseCache);
424
+		if (!$_reuseCache)
425
+		{
426
+			$this->forcePrefReload($_profileID,!$_reuseCache);
427
+		}
382 428
 		try
383 429
 		{
384 430
 			$this->profileID = self::validateProfileID($_profileID);
@@ -402,8 +448,14 @@  discard block
 block discarded – undo
402 448
 			$_profileID = $this->profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $this->icServer->ImapServerId;
403 449
 		}
404 450
 
405
-		if (is_null(self::$mailConfig)) self::$mailConfig = config::read('mail');
406
-		if (!isset(self::$idna2)) self::$idna2 = new egw_idna;
451
+		if (is_null(self::$mailConfig))
452
+		{
453
+			self::$mailConfig = config::read('mail');
454
+		}
455
+		if (!isset(self::$idna2))
456
+		{
457
+			self::$idna2 = new egw_idna;
458
+		}
407 459
 	}
408 460
 
409 461
 	/**
@@ -432,7 +484,10 @@  discard block
 block discarded – undo
432 484
 		// unset the mail_preferences session object, to force the reload/rebuild
433 485
 		$GLOBALS['egw']->session->appsession('mail_preferences','mail',serialize(array()));
434 486
 		$GLOBALS['egw']->session->appsession('session_data','emailadmin',serialize(array()));
435
-		if ($_resetFolderObjects) emailadmin_imapbase::resetFolderObjectCache($_profile_id);
487
+		if ($_resetFolderObjects)
488
+		{
489
+			emailadmin_imapbase::resetFolderObjectCache($_profile_id);
490
+		}
436 491
 	}
437 492
 
438 493
 	/**
@@ -442,7 +497,10 @@  discard block
 block discarded – undo
442 497
 	{
443 498
 		$this->sessionData = array();//egw_cache::getCache(egw_cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1);
444 499
 		self::$activeFolderCache = egw_cache::getCache(egw_cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
445
-		if (!empty(self::$activeFolderCache[$this->profileID])) $this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID];
500
+		if (!empty(self::$activeFolderCache[$this->profileID]))
501
+		{
502
+			$this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID];
503
+		}
446 504
 	}
447 505
 
448 506
 	/**
@@ -451,7 +509,10 @@  discard block
 block discarded – undo
451 509
 	function saveSessionData()
452 510
 	{
453 511
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($this->sessionData)));
454
-		if (!empty($this->sessionData['mailbox'])) self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox'];
512
+		if (!empty($this->sessionData['mailbox']))
513
+		{
514
+			self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox'];
515
+		}
455 516
 		if (isset(self::$activeFolderCache) && is_array(self::$activeFolderCache))
456 517
 		{
457 518
 			egw_cache::setCache(egw_cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),self::$activeFolderCache, 60*60*10);
@@ -472,8 +533,14 @@  discard block
 block discarded – undo
472 533
 	 */
473 534
 	static function unsetCachedObjects($_profileID=null)
474 535
 	{
475
-		if (is_null($_profileID)) $_profileID = emailadmin_account::get_default_acc_id();
476
-		if (is_array($_profileID) && $_profileID['account_id']) $account_id = $_profileID['account_id'];
536
+		if (is_null($_profileID))
537
+		{
538
+			$_profileID = emailadmin_account::get_default_acc_id();
539
+		}
540
+		if (is_array($_profileID) && $_profileID['account_id'])
541
+		{
542
+			$account_id = $_profileID['account_id'];
543
+		}
477 544
 		//error_log(__METHOD__.__LINE__.' called with ProfileID:'.array2string($_profileID).' from '.function_backtrace());
478 545
 		if (!is_array($_profileID) && (is_numeric($_profileID) || !(stripos($_profileID,'tracker_')===false)))
479 546
 		{
@@ -506,7 +573,10 @@  discard block
 block discarded – undo
506 573
 				egw_cache::setCache(egw_cache::INSTANCE,'email','vacationNotice'.trim($account_id),$vacationCached, $expiration=60*60*24*1);
507 574
 			}
508 575
 
509
-			if (isset(self::$instances[$_profileID])) unset(self::$instances[$_profileID]);
576
+			if (isset(self::$instances[$_profileID]))
577
+			{
578
+				unset(self::$instances[$_profileID]);
579
+			}
510 580
 		}
511 581
 		if (is_array($_profileID) && $_profileID['location'] == 'clear_cache')
512 582
 		{
@@ -535,7 +605,10 @@  discard block
 block discarded – undo
535 605
 	static function resetConnectionErrorCache($_ImapServerId=null,$account_id=null)
536 606
 	{
537 607
 		//error_log(__METHOD__.' ('.__LINE__.') '.' for Profile:'.array2string($_ImapServerId) .' for user:'.trim($account_id));
538
-		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
608
+		if (is_null($account_id))
609
+		{
610
+			$account_id = $GLOBALS['egw_info']['user']['account_id'];
611
+		}
539 612
 		if (is_array($_ImapServerId))
540 613
 		{
541 614
 			// called via hook
@@ -574,7 +647,10 @@  discard block
 block discarded – undo
574 647
 	static function resetFolderObjectCache($_ImapServerId=null,$account_id=null)
575 648
 	{
576 649
 		//error_log(__METHOD__.' ('.__LINE__.') '.' called for Profile:'.array2string($_ImapServerId).'->'.function_backtrace());
577
-		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
650
+		if (is_null($account_id))
651
+		{
652
+			$account_id = $GLOBALS['egw_info']['user']['account_id'];
653
+		}
578 654
 		// on [location] => verify_settings we coud either use [prefs] => Array([ActiveProfileID] => 9, .. as $_ImapServerId
579 655
 		// or treat it as not given. we try that path
580 656
 		if (is_null($_ImapServerId)||is_array($_ImapServerId))
@@ -640,17 +716,22 @@  discard block
 block discarded – undo
640 716
 	 * @param string $_profileID the ID of the mailaccount to check for identities, if null current mail-account is used
641 717
 	 * @return array - array(email=>realname)
642 718
 	 */
643
-	function getUserEMailAddresses($_profileID=null) {
719
+	function getUserEMailAddresses($_profileID=null)
720
+	{
644 721
 		$acc = emailadmin_account::read((!empty($_profileID)?$_profileID:$this->profileID));
645 722
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.array2string($acc));
646 723
 		$identities = $acc->identities();
647 724
 
648 725
 		$userEMailAdresses = array($acc['ident_email']=>$acc['ident_realname']);
649 726
 
650
-		foreach($identities as $ik => $ident) {
727
+		foreach($identities as $ik => $ident)
728
+		{
651 729
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
652 730
 			$identity = emailadmin_account::read_identity($ik);
653
-			if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']])) $userEMailAdresses[$identity['ident_email']] = $identity['ident_realname'];
731
+			if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']]))
732
+			{
733
+				$userEMailAdresses[$identity['ident_email']] = $identity['ident_realname'];
734
+			}
654 735
 		}
655 736
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses));
656 737
 		return $userEMailAdresses;
@@ -662,19 +743,27 @@  discard block
 block discarded – undo
662 743
 	 * @param boolean $resolve_placeholders wether or not resolve possible placeholders in identities
663 744
 	 * @return array - array(email=>realname)
664 745
 	 */
665
-	static function getAllIdentities($_accountToSearch=null,$resolve_placeholders=false) {
746
+	static function getAllIdentities($_accountToSearch=null,$resolve_placeholders=false)
747
+	{
666 748
 		$userEMailAdresses = array();
667 749
 		foreach(emailadmin_account::search($only_current_user=($_accountToSearch?$_accountToSearch:true), $just_name=true) as $acc_id => $identity_name)
668 750
 		{
669 751
 			$acc = emailadmin_account::read($acc_id,($_accountToSearch?$_accountToSearch:null));
670
-			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']);
752
+			if (!$resolve_placeholders)
753
+			{
754
+				$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']);
755
+			}
671 756
 			$identities = $acc->identities($acc_id);
672 757
 
673
-			foreach($identities as $ik => $ident) {
758
+			foreach($identities as $ik => $ident)
759
+			{
674 760
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
675 761
 				$identity = emailadmin_account::read_identity($ik,$resolve_placeholders);
676 762
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
677
-				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']);
763
+				if (!isset($userEMailAdresses[$identity['ident_id']]))
764
+				{
765
+					$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']);
766
+				}
678 767
 			}
679 768
 		}
680 769
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses));
@@ -687,19 +776,24 @@  discard block
 block discarded – undo
687 776
 	 * @param int|emailadmin_account $account account-object or acc_id
688 777
 	 * @return array - array(email=>realname)
689 778
 	 */
690
-	function getAccountIdentities($account) {
779
+	function getAccountIdentities($account)
780
+	{
691 781
 		if (!$account instanceof emailadmin_account)
692 782
 		{
693 783
 			$account = emailadmin_account::read($account);
694 784
 		}
695 785
 		$userEMailAdresses = array();
696 786
 		$identities = $account->identities(null, true, 'params');
697
-		foreach($identities as $ik => $ident) {
787
+		foreach($identities as $ik => $ident)
788
+		{
698 789
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
699 790
 			$identity = emailadmin_account::read_identity($ik,true,null,$account);
700 791
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
701 792
 			// standardIdentity has ident_id==acc_id (as it is done within account->identities)
702
-			if (empty($identity['ident_id'])) $identity['ident_id'] = $identity['acc_id'];
793
+			if (empty($identity['ident_id']))
794
+			{
795
+				$identity['ident_id'] = $identity['acc_id'];
796
+			}
703 797
 			if (!isset($userEMailAdresses[$identity['ident_id']]))
704 798
 			{
705 799
 				$userEMailAdresses[$identity['ident_id']] = array('acc_id'=>$identity['acc_id'],
@@ -719,7 +813,8 @@  discard block
 block discarded – undo
719 813
 	 * getDefaultIdentity - function to gather the default identitiy connected to the current mailaccount
720 814
 	 * @return int - id of the identity
721 815
 	 */
722
-	function getDefaultIdentity() {
816
+	function getDefaultIdentity()
817
+	{
723 818
 		// retrieve the signature accociated with the identity
724 819
 		$id = $this->getIdentitiesWithAccounts($_accountData=array());
725 820
 		$acc = emailadmin_account::read($this->profileID);
@@ -741,15 +836,25 @@  discard block
 block discarded – undo
741 836
 		// account select box
742 837
 		$selectedID = $this->profileID;
743 838
 		$allAccountData = emailadmin_account::search($only_current_user=true, false, null);
744
-		if ($allAccountData) {
839
+		if ($allAccountData)
840
+		{
745 841
 			$rememberFirst=$selectedFound=null;
746 842
 			foreach ($allAccountData as $tmpkey => $icServers)
747 843
 			{
748
-				if (is_null($rememberFirst)) $rememberFirst = $tmpkey;
749
-				if ($tmpkey == $selectedID) $selectedFound=true;
844
+				if (is_null($rememberFirst))
845
+				{
846
+					$rememberFirst = $tmpkey;
847
+				}
848
+				if ($tmpkey == $selectedID)
849
+				{
850
+					$selectedFound=true;
851
+				}
750 852
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($icServers->acc_imap_host));
751 853
 				$host = $icServers->acc_imap_host;
752
-				if (empty($host)) continue;
854
+				if (empty($host))
855
+				{
856
+					continue;
857
+				}
753 858
 				$identities[$icServers->acc_id] = $icServers['ident_realname'].' '.$icServers['ident_org'].' <'.$icServers['ident_email'].'>';
754 859
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($identities[$icServers->acc_id]));
755 860
 			}
@@ -794,7 +899,8 @@  discard block
 block discarded – undo
794 899
 	 *
795 900
 	 * @return void
796 901
 	 */
797
-	function closeConnection() {
902
+	function closeConnection()
903
+	{
798 904
 		//if ($icServer->_connected) error_log(__METHOD__.' ('.__LINE__.') '.' disconnect from Server');
799 905
 		//error_log(__METHOD__."() ".function_backtrace());
800 906
 		$this->icServer->disconnect();
@@ -808,7 +914,10 @@  discard block
 block discarded – undo
808 914
 	 */
809 915
 	function reopen($_foldername)
810 916
 	{
811
-		if (self::$debugTimes) $starttime = microtime (true);
917
+		if (self::$debugTimes)
918
+		{
919
+			$starttime = microtime (true);
920
+		}
812 921
 
813 922
 		//error_log(__METHOD__.' ('.__LINE__.') '."('$_foldername') ".function_backtrace());
814 923
 		// TODO: trying to reduce traffic to the IMAP Server here, introduces problems with fetching the bodies of
@@ -818,12 +927,16 @@  discard block
 block discarded – undo
818 927
 		//{
819 928
 			//error_log( __METHOD__.' ('.__LINE__.') '." $_foldername ".function_backtrace());
820 929
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Connected with icServer for Profile:'.$this->profileID.'?'.print_r($this->icServer->_connected,true));
821
-			if ($this->folderIsSelectable($_foldername)) {
930
+			if ($this->folderIsSelectable($_foldername))
931
+			{
822 932
 				$tretval = $this->icServer->openMailbox($_foldername);
823 933
 			}
824 934
 			$folderOpened = $_foldername;
825 935
 		//}
826
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') ');
936
+		if (self::$debugTimes)
937
+		{
938
+			self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') ');
939
+		}
827 940
 	}
828 941
 
829 942
 
@@ -838,13 +951,22 @@  discard block
 block discarded – undo
838 951
 	{
839 952
 		//error_log( "-------------------------->open connection ".function_backtrace());
840 953
 		//error_log(__METHOD__.' ('.__LINE__.') '.' ->'.array2string($this->icServer));
841
-		if (self::$debugTimes) $starttime = microtime (true);
954
+		if (self::$debugTimes)
955
+		{
956
+			$starttime = microtime (true);
957
+		}
842 958
 		$mailbox=null;
843 959
 		try
844 960
 		{
845
-			if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox'])) $mailbox = $this->sessionData['mailbox'];
846
-			if (empty($mailbox)) $mailbox = $this->icServer->getCurrentMailbox();
847
-/*
961
+			if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox']))
962
+			{
963
+				$mailbox = $this->sessionData['mailbox'];
964
+			}
965
+			if (empty($mailbox))
966
+			{
967
+				$mailbox = $this->icServer->getCurrentMailbox();
968
+			}
969
+			/*
848 970
 			if (isset(emailadmin_imap::$supports_keywords[$_icServerID]))
849 971
 			{
850 972
 				$this->icServer->openMailbox($mailbox);
@@ -869,7 +991,10 @@  discard block
 block discarded – undo
869 991
 			error_log(__METHOD__.' ('.__LINE__.') '."->open connection for Server with profileID:".$_icServerID." failed!".$e->getMessage());
870 992
 			throw new egw_exception(__METHOD__." failed to ".__METHOD__." on Profile to $_icServerID :".$e->getMessage());
871 993
 		}
872
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') ');
994
+		if (self::$debugTimes)
995
+		{
996
+			self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') ');
997
+		}
873 998
 	}
874 999
 
875 1000
 	/**
@@ -881,20 +1006,27 @@  discard block
 block discarded – undo
881 1006
 	function getQuotaRoot()
882 1007
 	{
883 1008
 		static $quota;
884
-		if (isset($quota)) return $quota;
1009
+		if (isset($quota))
1010
+		{
1011
+			return $quota;
1012
+		}
885 1013
 		$this->icServer->getCurrentMailbox();
886
-		if(!$this->icServer->hasCapability('QUOTA')) {
1014
+		if(!$this->icServer->hasCapability('QUOTA'))
1015
+		{
887 1016
 			$quota = false;
888 1017
 			return false;
889 1018
 		}
890 1019
 		$quota = $this->icServer->getStorageQuotaRoot('INBOX');
891 1020
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($quota));
892
-		if(is_array($quota)) {
1021
+		if(is_array($quota))
1022
+		{
893 1023
 			$quota = array(
894 1024
 				'usage'	=> $quota['USED'],
895 1025
 				'limit'	=> $quota['QMAX'],
896 1026
 			);
897
-		} else {
1027
+		}
1028
+		else
1029
+		{
898 1030
 			$quota = false;
899 1031
 		}
900 1032
 		return $quota;
@@ -910,7 +1042,11 @@  discard block
 block discarded – undo
910 1042
 	static function getTimeOut($_use='IMAP')
911 1043
 	{
912 1044
 		$timeout = $GLOBALS['egw_info']['user']['preferences']['mail']['connectionTimeout'];
913
-		if (empty($timeout)) $timeout = ($_use=='SIEVE'?10:20); // this is the default value
1045
+		if (empty($timeout))
1046
+		{
1047
+			$timeout = ($_use=='SIEVE'?10:20);
1048
+		}
1049
+		// this is the default value
914 1050
 		return $timeout;
915 1051
 	}
916 1052
 
@@ -926,9 +1062,13 @@  discard block
 block discarded – undo
926 1062
 		$foldersNameSpace = array();
927 1063
 		$delimiter = $this->getHierarchyDelimiter();
928 1064
 		// TODO: cache by $this->icServer->ImapServerId
929
-		if (is_null($nameSpace)) $nameSpace = $this->icServer->getNameSpaceArray();
1065
+		if (is_null($nameSpace))
1066
+		{
1067
+			$nameSpace = $this->icServer->getNameSpaceArray();
1068
+		}
930 1069
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($nameSpace));
931
-		if (is_array($nameSpace)) {
1070
+		if (is_array($nameSpace))
1071
+		{
932 1072
 			foreach($nameSpace as $type => $singleNameSpaceArray)
933 1073
 			{
934 1074
 				foreach ($singleNameSpaceArray as $k => $singleNameSpace)
@@ -945,7 +1085,9 @@  discard block
 block discarded – undo
945 1085
 						$_foldersNameSpace['prefix_present'] = 'forced';
946 1086
 						// uw-imap server with mailbox prefix or dovecot maybe
947 1087
 						$_foldersNameSpace['prefix'] = 'mail';
948
-					} else {
1088
+					}
1089
+					else
1090
+					{
949 1091
 						$_foldersNameSpace['prefix_present'] = !empty($singleNameSpace['name']);
950 1092
 						$_foldersNameSpace['prefix'] = $singleNameSpace['name'];
951 1093
 					}
@@ -971,7 +1113,10 @@  discard block
 block discarded – undo
971 1113
 		foreach($nameSpace as &$singleNameSpace)
972 1114
 		{
973 1115
 			//if (substr($singleNameSpace['prefix'],0,strlen($folderName))==$folderName) return $singleNameSpace['prefix'];
974
-			if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix']) return $singleNameSpace['prefix'];
1116
+			if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix'])
1117
+			{
1118
+				return $singleNameSpace['prefix'];
1119
+			}
975 1120
 		}
976 1121
 		return "";
977 1122
 	}
@@ -984,8 +1129,14 @@  discard block
 block discarded – undo
984 1129
 	function getHierarchyDelimiter($_useCache=true)
985 1130
 	{
986 1131
 		static $HierarchyDelimiter;
987
-		if (is_null($HierarchyDelimiter)) $HierarchyDelimiter = egw_cache::getCache(egw_cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
988
-		if ($_useCache===false) unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1132
+		if (is_null($HierarchyDelimiter))
1133
+		{
1134
+			$HierarchyDelimiter = egw_cache::getCache(egw_cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1135
+		}
1136
+		if ($_useCache===false)
1137
+		{
1138
+			unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1139
+		}
989 1140
 		if (isset($HierarchyDelimiter[$this->icServer->ImapServerId])&&!empty($HierarchyDelimiter[$this->icServer->ImapServerId]))
990 1141
 		{
991 1142
 			return $HierarchyDelimiter[$this->icServer->ImapServerId];
@@ -1013,14 +1164,19 @@  discard block
 block discarded – undo
1013 1164
 	{
1014 1165
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$this->icServer->ImapServerId.' Connected:'.$this->icServer->_connected);
1015 1166
 		static $_specialUseFolders;
1016
-		if (is_null($_specialUseFolders)||empty($_specialUseFolders)) $_specialUseFolders = egw_cache::getCache(egw_cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1167
+		if (is_null($_specialUseFolders)||empty($_specialUseFolders))
1168
+		{
1169
+			$_specialUseFolders = egw_cache::getCache(egw_cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1170
+		}
1017 1171
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_trash));
1018 1172
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_sent));
1019 1173
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_draft));
1020 1174
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_template));
1021 1175
 		self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId];
1022 1176
 		if (isset($_specialUseFolders[$this->icServer->ImapServerId]) && !empty($_specialUseFolders[$this->icServer->ImapServerId]))
1023
-			return $_specialUseFolders[$this->icServer->ImapServerId];
1177
+		{
1178
+					return $_specialUseFolders[$this->icServer->ImapServerId];
1179
+		}
1024 1180
 		$_specialUseFolders[$this->icServer->ImapServerId]=array();
1025 1181
 		//if (!empty($this->icServer->acc_folder_trash) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]))
1026 1182
 			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]='Trash';
@@ -1049,7 +1205,8 @@  discard block
 block discarded – undo
1049 1205
 	function folderIsSelectable($folderToSelect)
1050 1206
 	{
1051 1207
 		$retval = true;
1052
-		if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true))) {
1208
+		if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true)))
1209
+		{
1053 1210
 			if (!empty($folderStatus['attributes']) && stripos(array2string($folderStatus['attributes']),'noselect')!==false)
1054 1211
 			{
1055 1212
 				$retval = false;
@@ -1102,18 +1259,27 @@  discard block
 block discarded – undo
1102 1259
 	 */
1103 1260
 	function getFolderStatus($_folderName,$ignoreStatusCache=false,$basicInfoOnly=false,$fetchSubscribedInfo=true)
1104 1261
 	{
1105
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly");
1106
-		if (!is_string($_folderName) || empty($_folderName)) // something is wrong. Do not proceed
1262
+		if (self::$debug)
1263
+		{
1264
+			error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly");
1265
+		}
1266
+		if (!is_string($_folderName) || empty($_folderName))
1267
+		{
1268
+			// something is wrong. Do not proceed
1107 1269
 		{
1108 1270
 			return false;
1109 1271
 		}
1272
+		}
1110 1273
 		static $folderInfoCache; // reduce traffic on single request
1111 1274
 		static $folderBasicInfo;
1112 1275
 		if (isset($folderBasicInfo[$this->profileID]))
1113 1276
 		{
1114 1277
 			$folderInfoCache = $folderBasicInfo[$this->profileID];
1115 1278
 		}
1116
-		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly) return $folderInfoCache[$_folderName];
1279
+		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly)
1280
+		{
1281
+			return $folderInfoCache[$_folderName];
1282
+		}
1117 1283
 		$retValue = array();
1118 1284
 		$retValue['subscribed'] = false;
1119 1285
 /*
@@ -1131,7 +1297,10 @@  discard block
 block discarded – undo
1131 1297
 			if (is_array($ret))
1132 1298
 			{
1133 1299
 				$retkeys = array_keys($ret);
1134
-				if ($retkeys[0]==$_folderName) $folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1300
+				if ($retkeys[0]==$_folderName)
1301
+				{
1302
+					$folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1303
+				}
1135 1304
 			}
1136 1305
 			else
1137 1306
 			{
@@ -1140,7 +1309,8 @@  discard block
 block discarded – undo
1140 1309
 		}
1141 1310
 		$folderInfo = $folderInfoCache[$_folderName];
1142 1311
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($folderInfo).'->'.function_backtrace());
1143
-		if(!$folderInfo|| !is_array($folderInfo)) {
1312
+		if(!$folderInfo|| !is_array($folderInfo))
1313
+		{
1144 1314
 			try
1145 1315
 			{
1146 1316
 				$folderInfo = $this->_getStatus($_folderName,$ignoreStatusCache);
@@ -1170,7 +1340,8 @@  discard block
 block discarded – undo
1170 1340
 		$retValue['shortName']		= array_pop($shortNameParts);
1171 1341
 		$retValue['displayName']	= $_folderName;
1172 1342
 		$retValue['shortDisplayName']	= $retValue['shortName'];
1173
-		if(strtoupper($retValue['shortName']) == 'INBOX') {
1343
+		if(strtoupper($retValue['shortName']) == 'INBOX')
1344
+		{
1174 1345
 			$retValue['displayName']	= lang('INBOX');
1175 1346
 			$retValue['shortDisplayName']	= lang('INBOX');
1176 1347
 		}
@@ -1179,7 +1350,10 @@  discard block
 block discarded – undo
1179 1350
 		{
1180 1351
 			$retValue['displayName'] = $retValue['shortDisplayName'] = lang($retValue['shortName']);
1181 1352
 		}
1182
-		if ($folderInfo) $folderBasicInfo[$this->profileID][$_folderName]=$retValue;
1353
+		if ($folderInfo)
1354
+		{
1355
+			$folderBasicInfo[$this->profileID][$_folderName]=$retValue;
1356
+		}
1183 1357
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.$_folderName.array2string($retValue['attributes']));
1184 1358
 		if ($basicInfoOnly || (isset($retValue['attributes']) && stripos(array2string($retValue['attributes']),'noselect')!==false))
1185 1359
 		{
@@ -1191,24 +1365,34 @@  discard block
 block discarded – undo
1191 1365
 		static $subscribedFolders;
1192 1366
 		static $nameSpace;
1193 1367
 		static $prefix;
1194
-		if (is_null($nameSpace) || empty($nameSpace[$this->profileID])) $nameSpace[$this->profileID] = $this->_getNameSpaces();
1368
+		if (is_null($nameSpace) || empty($nameSpace[$this->profileID]))
1369
+		{
1370
+			$nameSpace[$this->profileID] = $this->_getNameSpaces();
1371
+		}
1195 1372
 		if (!empty($nameSpace[$this->profileID]))
1196 1373
 		{
1197 1374
 			$nsNoPersonal=array();
1198 1375
 			foreach($nameSpace[$this->profileID] as &$ns)
1199 1376
 			{
1200
-				if ($ns['type']!='personal') $nsNoPersonal[]=$ns;
1377
+				if ($ns['type']!='personal')
1378
+				{
1379
+					$nsNoPersonal[]=$ns;
1380
+				}
1201 1381
 			}
1202 1382
 			$nameSpace[$this->profileID]=$nsNoPersonal;
1203 1383
 		}
1204
-		if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName])) $prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName);
1384
+		if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName]))
1385
+		{
1386
+			$prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName);
1387
+		}
1205 1388
 
1206 1389
 		if ($fetchSubscribedInfo && is_null($subscribedFolders) || empty($subscribedFolders[$this->profileID]))
1207 1390
 		{
1208 1391
 			$subscribedFolders[$this->profileID] = $this->icServer->listSubscribedMailboxes();
1209 1392
 		}
1210 1393
 
1211
-		if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID])) {
1394
+		if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID]))
1395
+		{
1212 1396
 			$retValue['subscribed'] = true;
1213 1397
 		}
1214 1398
 
@@ -1227,8 +1411,7 @@  discard block
 block discarded – undo
1227 1411
 				(isset($this->mailPreferences['trustServersUnseenInfo']) &&
1228 1412
 				$this->mailPreferences['trustServersUnseenInfo']==2 &&
1229 1413
 				$prefix[$this->profileID][$_folderName] != '' && stripos($_folderName,$prefix[$this->profileID][$_folderName]) !== false)
1230
-			)
1231
-			{
1414
+			) {
1232 1415
 				//error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($prefix,true).' TS:'.$this->mailPreferences['trustServersUnseenInfo']);
1233 1416
 				// we filter for the combined status of unseen and undeleted, as this is what we show in list
1234 1417
 				try
@@ -1238,13 +1421,19 @@  discard block
 block discarded – undo
1238 1421
 				}
1239 1422
 				catch (Exception $ee)
1240 1423
 				{
1241
-					if (self::$debug) error_log(__METHOD__." could not fetch/calculate unseen counter for $_folderName Reason:'".$ee->getMessage()."' but requested.");
1424
+					if (self::$debug)
1425
+					{
1426
+						error_log(__METHOD__." could not fetch/calculate unseen counter for $_folderName Reason:'".$ee->getMessage()."' but requested.");
1427
+					}
1242 1428
 				}
1243 1429
 			}
1244 1430
 		}
1245 1431
 		catch (Exception $e)
1246 1432
 		{
1247
-			if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1433
+			if (self::$debug)
1434
+			{
1435
+				error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1436
+			}
1248 1437
 		}
1249 1438
 
1250 1439
 		return $retValue;
@@ -1268,8 +1457,14 @@  discard block
 block discarded – undo
1268 1457
 	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true)
1269 1458
 	{
1270 1459
 		//self::$debug=true;
1271
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
1272
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName,$_startMessage, $_numberOfMessages, $_sort, $_reverse, ".array2string($_filter).", $_thisUIDOnly");
1460
+		if (self::$debug)
1461
+		{
1462
+			error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
1463
+		}
1464
+		if (self::$debug)
1465
+		{
1466
+			error_log(__METHOD__.' ('.__LINE__.') '."$_folderName,$_startMessage, $_numberOfMessages, $_sort, $_reverse, ".array2string($_filter).", $_thisUIDOnly");
1467
+		}
1273 1468
 		$reverse = (bool)$_reverse;
1274 1469
 		// get the list of messages to fetch
1275 1470
 		$this->reopen($_folderName);
@@ -1290,21 +1485,34 @@  discard block
 block discarded – undo
1290 1485
 				//$_filter['range'] ="$start:$end";
1291 1486
 				//$_filter['range'] ="$_startMessage:*";
1292 1487
 			}
1293
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1294
-			if (self::$debug||self::$debugTimes) $starttime = microtime (true);
1488
+			if (self::$debug)
1489
+			{
1490
+				error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1491
+			}
1492
+			if (self::$debug||self::$debugTimes)
1493
+			{
1494
+				$starttime = microtime (true);
1495
+			}
1295 1496
 			//see this example below for a 12 week datefilter (since)
1296 1497
 			//$_filter = array('status'=>array('UNDELETED'),'type'=>"SINCE",'string'=> date("d-M-Y", $starttime-(3600*24*7*12)));
1297 1498
 			$_sortResult = $this->getSortedList($_folderName, $_sort, $reverse, $_filter, $rByUid, $_cacheResult);
1298 1499
 			$sortResult = $_sortResult['match']->ids;
1299 1500
 			//$modseq = $_sortResult['modseq'];
1300 1501
 			//error_log(__METHOD__.' ('.__LINE__.') '.'Modsequence:'.$modseq);
1301
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1502
+			if (self::$debug||self::$debugTimes)
1503
+			{
1504
+				self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1505
+			}
1302 1506
 
1303
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1507
+			if (self::$debug)
1508
+			{
1509
+				error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1510
+			}
1304 1511
 			#$this->icServer->setDebug(false);
1305 1512
 			#print "</pre>";
1306 1513
 			// nothing found
1307
-			if(!is_array($sortResult) || empty($sortResult)) {
1514
+			if(!is_array($sortResult) || empty($sortResult))
1515
+			{
1308 1516
 				$retValue = array();
1309 1517
 				$retValue['info']['total']	= 0;
1310 1518
 				$retValue['info']['first']	= 0;
@@ -1316,7 +1524,8 @@  discard block
 block discarded – undo
1316 1524
 			#_debug_array($sortResult);
1317 1525
 			#_debug_array(array_slice($sortResult, -5, -2));
1318 1526
 			//error_log("REVERSE: $reverse");
1319
-			if($reverse === true) {
1527
+			if($reverse === true)
1528
+			{
1320 1529
 				if  ($_startMessage<=$total)
1321 1530
 				{
1322 1531
 					$startMessage = $_startMessage-1;
@@ -1328,7 +1537,10 @@  discard block
 block discarded – undo
1328 1537
 					{
1329 1538
 						$numberOfMessages = $total%$_numberOfMessages;
1330 1539
 						//$numberOfMessages = abs($_startMessage-$total-1);
1331
-						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages) $_numberOfMessages = $numberOfMessages;
1540
+						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages)
1541
+						{
1542
+							$_numberOfMessages = $numberOfMessages;
1543
+						}
1332 1544
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total);
1333 1545
 					}
1334 1546
 					$startMessage=($total-$_numberOfMessages)-1;
@@ -1342,19 +1554,36 @@  discard block
 block discarded – undo
1342 1554
 					//$retValue['info']['first'] = $startMessage;
1343 1555
 					//$retValue['info']['last'] = $total;
1344 1556
 				}
1345
-				if($startMessage > 0) {
1346
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1557
+				if($startMessage > 0)
1558
+				{
1559
+					if (self::$debug)
1560
+					{
1561
+						error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1562
+					}
1347 1563
 					$sortResult = array_slice($sortResult, -($_numberOfMessages+$startMessage), -$startMessage);
1348
-				} else {
1349
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1564
+				}
1565
+				else
1566
+				{
1567
+					if (self::$debug)
1568
+					{
1569
+						error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1570
+					}
1350 1571
 					$sortResult = array_slice($sortResult, -($_numberOfMessages+($_startMessage-1)));
1351 1572
 				}
1352 1573
 				$sortResult = array_reverse($sortResult);
1353
-			} else {
1354
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1574
+			}
1575
+			else
1576
+			{
1577
+				if (self::$debug)
1578
+				{
1579
+					error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1580
+				}
1355 1581
 				$sortResult = array_slice($sortResult, $_startMessage-1, $_numberOfMessages);
1356 1582
 			}
1357
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1583
+			if (self::$debug)
1584
+			{
1585
+				error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1586
+			}
1358 1587
 		}
1359 1588
 		else
1360 1589
 		{
@@ -1363,7 +1592,10 @@  discard block
 block discarded – undo
1363 1592
 
1364 1593
 
1365 1594
 		// fetch the data for the selected messages
1366
-		if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1595
+		if (self::$debug||self::$debugTimes)
1596
+		{
1597
+			$starttime = microtime(true);
1598
+		}
1367 1599
 		try
1368 1600
 		{
1369 1601
 			$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -1408,14 +1640,20 @@  discard block
 block discarded – undo
1408 1640
 
1409 1641
 		$count = 0;
1410 1642
 
1411
-		foreach((array)$sortResult as $uid) {
1643
+		foreach((array)$sortResult as $uid)
1644
+		{
1412 1645
 			$sortOrder[$uid] = $count++;
1413 1646
 		}
1414 1647
 
1415 1648
 		$count = 0;
1416
-		if (is_object($headersNew)) {
1417
-			if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1418
-			foreach($headersNew->ids() as $id) {
1649
+		if (is_object($headersNew))
1650
+		{
1651
+			if (self::$debug||self::$debugTimes)
1652
+			{
1653
+				$starttime = microtime(true);
1654
+			}
1655
+			foreach($headersNew->ids() as $id)
1656
+			{
1419 1657
 				$_headerObject = $headersNew->get($id);
1420 1658
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject));
1421 1659
 				$headerObject = array();
@@ -1427,8 +1665,12 @@  discard block
 block discarded – undo
1427 1665
 				// Get already cached headers, 'fetchHeaders' is a label matchimg above
1428 1666
 				$headerForPrio = array_change_key_case($_headerObject->getHeaders('fetchHeaders',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
1429 1667
 				// Try to fetch header with key='' as some servers might have no fetchHeaders index. e.g. yandex.com
1430
-				if (empty($headerForPrio)) $headerForPrio = array_change_key_case($_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
1431
-				if (self::$debug) {
1668
+				if (empty($headerForPrio))
1669
+				{
1670
+					$headerForPrio = array_change_key_case($_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
1671
+				}
1672
+				if (self::$debug)
1673
+				{
1432 1674
 					error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject).'UID:'.$_headerObject->getUid().' Size:'.$_headerObject->getSize().' Date:'.$_headerObject->getImapDate().'/'.egw_time::to($_headerObject->getImapDate(),'Y-m-d H:i:s'));
1433 1675
 					error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerForPrio));
1434 1676
 				}
@@ -1439,11 +1681,16 @@  discard block
 block discarded – undo
1439 1681
 					$total--;
1440 1682
 					continue;
1441 1683
 				}
1442
-				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) ) {
1684
+				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) )
1685
+				{
1443 1686
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['DISPOSITION-NOTIFICATION-TO']));
1444
-				} else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) ) {
1687
+				}
1688
+				else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) )
1689
+				{
1445 1690
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['RETURN-RECEIPT-TO']));
1446
-				} else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) ) {
1691
+				}
1692
+				else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) )
1693
+				{
1447 1694
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['X-CONFIRM-READING-TO']));
1448 1695
 				} /*else $sent_not = "";*/
1449 1696
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
@@ -1475,7 +1722,11 @@  discard block
 block discarded – undo
1475 1722
 						$rfcAddr = self::parseAddressList($ad); // does some fixing of known problems too
1476 1723
 						foreach ($rfcAddr as $_rfcAddr)
1477 1724
 						{
1478
-							if (!$_rfcAddr->valid)	continue; // skip. not a valid address
1725
+							if (!$_rfcAddr->valid)
1726
+							{
1727
+								continue;
1728
+							}
1729
+							// skip. not a valid address
1479 1730
 							$address[] = imap_rfc822_write_address($_rfcAddr->mailbox,$_rfcAddr->host,$_rfcAddr->personal);
1480 1731
 						}
1481 1732
 					}
@@ -1491,7 +1742,10 @@  discard block
 block discarded – undo
1491 1742
 				$messageMimeType='';
1492 1743
 				foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
1493 1744
 				{
1494
-					if ($mime_id==0 || $messageMimeType==='') $messageMimeType = $mime_type;
1745
+					if ($mime_id==0 || $messageMimeType==='')
1746
+					{
1747
+						$messageMimeType = $mime_type;
1748
+					}
1495 1749
 					$part = $mailStructureObject->getPart($mime_id);
1496 1750
 					$partdisposition = $part->getDisposition();
1497 1751
 					$partPrimaryType = $part->getPrimaryType();
@@ -1507,10 +1761,19 @@  discard block
 block discarded – undo
1507 1761
 					if ($mime_type=='message/rfc822')
1508 1762
 					{
1509 1763
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
1510
-						foreach($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
1764
+						foreach($part->contentTypeMap() as $sub_id => $sub_type)
1765
+						{
1766
+if ($sub_id != $mime_id)
1767
+						{
1768
+							$skipParts[$sub_id] = $sub_type;
1769
+						}
1770
+						}
1511 1771
 					}
1512 1772
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType.' Skip:'.array2string($skipParts));
1513
-					if (array_key_exists($mime_id,$skipParts)) continue;
1773
+					if (array_key_exists($mime_id,$skipParts))
1774
+					{
1775
+						continue;
1776
+					}
1514 1777
 					if ($partdisposition=='attachment' ||
1515 1778
 						($partdisposition=='inline'&&$partPrimaryType == 'image'&&$mime_type=='image/tiff') || // as we are not able to display tiffs
1516 1779
 						($partdisposition=='inline'&&$partPrimaryType == 'image'&&empty($cid)) ||
@@ -1521,7 +1784,10 @@  discard block
 block discarded – undo
1521 1784
 						$headerObject['ATTACHMENTS'][$mime_id]['uid']=$uid;
1522 1785
 						$headerObject['ATTACHMENTS'][$mime_id]['cid'] = $cid;
1523 1786
 						$headerObject['ATTACHMENTS'][$mime_id]['partID']=$mime_id;
1524
-						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1787
+						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))
1788
+						{
1789
+							$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1790
+						}
1525 1791
 						if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'],'winmail.dat') ||
1526 1792
 							$headerObject['ATTACHMENTS'][$mime_id]['mimeType']=='application/ms-tnef')
1527 1793
 						{
@@ -1535,18 +1801,27 @@  discard block
 block discarded – undo
1535 1801
 				//error_log(__METHOD__.' ('.__LINE__.') '.' FindBody (plain):'.array2string($mailStructureObject->findBody('plain')));
1536 1802
 				//error_log(__METHOD__.' ('.__LINE__.') '.' FindBody (html):'.array2string($mailStructureObject->findBody('html')));
1537 1803
 				//if($count == 0) error_log(__METHOD__.array2string($headerObject));
1538
-				if (empty($headerObject['UID'])) continue;
1804
+				if (empty($headerObject['UID']))
1805
+				{
1806
+					continue;
1807
+				}
1539 1808
 				//$uid = ($rByUid ? $headerObject['UID'] : $headerObject['MSG_NUM']);
1540 1809
 				// make dates like "Mon, 23 Apr 2007 10:11:06 UT" working with strtotime
1541
-				if(substr($headerObject['DATE'],-2) === 'UT') {
1810
+				if(substr($headerObject['DATE'],-2) === 'UT')
1811
+				{
1542 1812
 					$headerObject['DATE'] .= 'C';
1543 1813
 				}
1544
-				if(substr($headerObject['INTERNALDATE'],-2) === 'UT') {
1814
+				if(substr($headerObject['INTERNALDATE'],-2) === 'UT')
1815
+				{
1545 1816
 					$headerObject['INTERNALDATE'] .= 'C';
1546 1817
 				}
1547 1818
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$headerObject['SUBJECT'].'->'.$headerObject['DATE'].'<->'.$headerObject['INTERNALDATE'] .'#');
1548 1819
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$this->decode_subject($headerObject['SUBJECT']).'->'.$headerObject['DATE']);
1549
-				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;}
1820
+				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS']))
1821
+				{
1822
+					foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;
1823
+				}
1824
+				}
1550 1825
 				$retValue['header'][$sortOrder[$uid]]['subject']	= $this->decode_subject($headerObject['SUBJECT']);
1551 1826
 				$retValue['header'][$sortOrder[$uid]]['size'] 		= $headerObject['SIZE'];
1552 1827
 				$retValue['header'][$sortOrder[$uid]]['date']		= self::_strtotime(($headerObject['DATE']&&!($headerObject['DATE']=='NIL')?$headerObject['DATE']:$headerObject['INTERNALDATE']),'ts',true);
@@ -1556,22 +1831,31 @@  discard block
 block discarded – undo
1556 1831
 				$retValue['header'][$sortOrder[$uid]]['uid']		= $headerObject['UID'];
1557 1832
 				$retValue['header'][$sortOrder[$uid]]['priority']		= ($headerObject['PRIORITY']?$headerObject['PRIORITY']:3);
1558 1833
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.array2string($retValue['header'][$sortOrder[$uid]]));
1559
-				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO'])) $retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1560
-				if (is_array($headerObject['FLAGS'])) {
1834
+				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO']))
1835
+				{
1836
+					$retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1837
+				}
1838
+				if (is_array($headerObject['FLAGS']))
1839
+				{
1561 1840
 					$retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]],self::prepareFlagsArray($headerObject));
1562 1841
 				}
1563 1842
 				//error_log(__METHOD__.' ('.__LINE__.') '.$headerObject['SUBJECT'].'->'.array2string($_headerObject->getEnvelope()->__get('from')));
1564
-				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0]) {
1843
+				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0])
1844
+				{
1565 1845
 					$retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0],true);
1566 1846
 				}
1567
-				if(is_array($headerObject['TO']) && $headerObject['TO'][0]) {
1847
+				if(is_array($headerObject['TO']) && $headerObject['TO'][0])
1848
+				{
1568 1849
 					$retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0],true);
1569 1850
 					if (count($headerObject['TO'])>1)
1570 1851
 					{
1571 1852
 						$ki=0;
1572 1853
 						foreach($headerObject['TO'] as $k => $add)
1573 1854
 						{
1574
-							if ($k==0) continue;
1855
+							if ($k==0)
1856
+							{
1857
+								continue;
1858
+							}
1575 1859
 							//error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add));
1576 1860
 							$retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add,true);
1577 1861
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki]));
@@ -1579,7 +1863,8 @@  discard block
 block discarded – undo
1579 1863
 						}
1580 1864
 					}
1581 1865
 				}
1582
-				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0) {
1866
+				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0)
1867
+				{
1583 1868
 					$ki=0;
1584 1869
 					foreach($headerObject['CC'] as $k => $add)
1585 1870
 					{
@@ -1593,27 +1878,41 @@  discard block
 block discarded – undo
1593 1878
 
1594 1879
 				$count++;
1595 1880
 			}
1596
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
1881
+			if (self::$debug||self::$debugTimes)
1882
+			{
1883
+				self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
1884
+			}
1597 1885
 			//self::$debug=false;
1598 1886
 			// sort the messages to the requested displayorder
1599
-			if(is_array($retValue['header'])) {
1887
+			if(is_array($retValue['header']))
1888
+			{
1600 1889
 				$countMessages = $total;
1601
-				if (isset($_filter['range'])) $countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
1890
+				if (isset($_filter['range']))
1891
+				{
1892
+					$countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
1893
+				}
1602 1894
 				ksort($retValue['header']);
1603 1895
 				$retValue['info']['total']	= $total;
1604 1896
 				//if ($_startMessage>$total) $_startMessage = $total-($count-1);
1605 1897
 				$retValue['info']['first']	= $_startMessage;
1606 1898
 				$retValue['info']['last']	= $_startMessage + $count - 1 ;
1607 1899
 				return $retValue;
1608
-			} else {
1900
+			}
1901
+			else
1902
+			{
1609 1903
 				$retValue = array();
1610 1904
 				$retValue['info']['total']	= 0;
1611 1905
 				$retValue['info']['first']	= 0;
1612 1906
 				$retValue['info']['last']	= 0;
1613 1907
 				return $retValue;
1614 1908
 			}
1615
-		} else {
1616
-			if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
1909
+		}
1910
+		else
1911
+		{
1912
+			if ($headersNew == null && empty($_thisUIDOnly))
1913
+			{
1914
+				error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
1915
+			}
1617 1916
 			$retValue = array();
1618 1917
 			$retValue['info']['total']  = 0;
1619 1918
 			$retValue['info']['first']  = 0;
@@ -1630,7 +1929,10 @@  discard block
 block discarded – undo
1630 1929
 	 */
1631 1930
 	static function prepareFlagsArray($headerObject)
1632 1931
 	{
1633
-		if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower',$headerObject['FLAGS']);
1932
+		if (is_array($headerObject['FLAGS']))
1933
+		{
1934
+			$headerFlags = array_map('strtolower',$headerObject['FLAGS']);
1935
+		}
1634 1936
 		$retValue = array();
1635 1937
 		$retValue['recent']		= in_array('\\recent', $headerFlags);
1636 1938
 		$retValue['flagged']	= in_array('\\flagged', $headerFlags);
@@ -1681,24 +1983,43 @@  discard block
 block discarded – undo
1681 1983
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Filter:'.array2string($_filter));
1682 1984
 		$try2useCache = true;
1683 1985
 		static $eMailListContainsDeletedMessages;
1684
-		if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = egw_cache::getCache(egw_cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
1986
+		if (is_null($eMailListContainsDeletedMessages))
1987
+		{
1988
+			$eMailListContainsDeletedMessages = egw_cache::getCache(egw_cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
1989
+		}
1685 1990
 		// this indicates, that there is no Filter set, and the returned set/subset should not contain DELETED Messages, nor filtered for UNDELETED
1686 1991
 		if ($setSession==true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
1687 1992
 		{
1688
-			if (self::$debugTimes) $starttime = microtime(true);
1689
-			if (is_null($eMailListContainsDeletedMessages) || empty($eMailListContainsDeletedMessages[$this->profileID]) || empty($eMailListContainsDeletedMessages[$this->profileID][$_folderName])) $eMailListContainsDeletedMessages = egw_cache::getCache(egw_cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
1993
+			if (self::$debugTimes)
1994
+			{
1995
+				$starttime = microtime(true);
1996
+			}
1997
+			if (is_null($eMailListContainsDeletedMessages) || empty($eMailListContainsDeletedMessages[$this->profileID]) || empty($eMailListContainsDeletedMessages[$this->profileID][$_folderName]))
1998
+			{
1999
+				$eMailListContainsDeletedMessages = egw_cache::getCache(egw_cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2000
+			}
1690 2001
 			$deletedMessages = $this->getSortedList($_folderName, 0, $three=1, array('status'=>array('DELETED')),$five=true,false);
1691
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
2002
+			if (self::$debug)
2003
+			{
2004
+				error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
2005
+			}
1692 2006
 			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] =$deletedMessages['count'];
1693 2007
 			egw_cache::setCache(egw_cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),$eMailListContainsDeletedMessages, 60*60*1);
1694
-			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']);
2008
+			if (self::$debugTimes)
2009
+			{
2010
+				self::logRunTimes($starttime,null,'setting eMailListContainsDeletedMessages for Profile:'.$this->profileID.' Folder:'.$_folderName.' to '.$eMailListContainsDeletedMessages[$this->profileID][$_folderName],__METHOD__.' ('.__LINE__.') ');
2011
+			}
2012
+			//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']);
1695 2013
 		}
1696 2014
 		$try2useCache = false;
1697 2015
 		//self::$supportsORinQuery[$this->profileID]=true;
1698 2016
 		if (is_null(self::$supportsORinQuery) || !isset(self::$supportsORinQuery[$this->profileID]))
1699 2017
 		{
1700 2018
 			self::$supportsORinQuery = egw_cache::getCache(egw_cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
1701
-			if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID]=true;
2019
+			if (!isset(self::$supportsORinQuery[$this->profileID]))
2020
+			{
2021
+				self::$supportsORinQuery[$this->profileID]=true;
2022
+			}
1702 2023
 		}
1703 2024
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_filter).' SupportsOrInQuery:'.self::$supportsORinQuery[$this->profileID]);
1704 2025
 		$filter = $this->createIMAPFilter($_folderName, $_filter,self::$supportsORinQuery[$this->profileID]);
@@ -1709,15 +2030,26 @@  discard block
 block discarded – undo
1709 2030
 		}
1710 2031
 		//_debug_array($filter);
1711 2032
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($filter).'#'.array2string($this->icServer->capability()));
1712
-		if($this->icServer->hasCapability('SORT')) {
2033
+		if($this->icServer->hasCapability('SORT'))
2034
+		{
1713 2035
 			// when using an orQuery and we sort by date. sort seems to fail on certain servers => ZIMBRA with Horde_Imap_Client
1714 2036
 			// thus we translate the search request from date to Horde_Imap_Client::SORT_SEQUENCE (which should be the same, if
1715 2037
 			// there is no messing with the dates)
1716 2038
 			//if (self::$supportsORinQuery[$this->profileID]&&$_sort=='date'&&$_filter['type']=='quick'&&!empty($_filter['string']))$_sort='INTERNALDATE';
1717
-			if (self::$debug) error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
2039
+			if (self::$debug)
2040
+			{
2041
+				error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
2042
+			}
1718 2043
 			$sortOrder = $this->_getSortString($_sort, $_reverse);
1719
-			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder)) $_reverse=false; // as we reversed the result already
1720
-			if (self::$debug) error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
2044
+			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder))
2045
+			{
2046
+				$_reverse=false;
2047
+			}
2048
+			// as we reversed the result already
2049
+			if (self::$debug)
2050
+			{
2051
+				error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
2052
+			}
1721 2053
 			try
1722 2054
 			{
1723 2055
 				$sortResult = $this->icServer->search($_folderName, $filter, array(
@@ -1729,7 +2061,10 @@  discard block
 block discarded – undo
1729 2061
 				//error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1730 2062
 				$resultByUid = false;
1731 2063
 				$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1732
-				if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
2064
+				if ($_reverse)
2065
+				{
2066
+					array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
2067
+				}
1733 2068
 				try
1734 2069
 				{
1735 2070
 					$sortResult = $this->icServer->search($_folderName, $filter, array(
@@ -1741,9 +2076,17 @@  discard block
 block discarded – undo
1741 2076
 					$sortResult = self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'];
1742 2077
 				}
1743 2078
 			}
1744
-			if (self::$debug) error_log(__METHOD__.print_r($sortResult,true));
1745
-		} else {
1746
-			if (self::$debug) error_log(__METHOD__." Mailserver has NO SORT Capability");
2079
+			if (self::$debug)
2080
+			{
2081
+				error_log(__METHOD__.print_r($sortResult,true));
2082
+			}
2083
+		}
2084
+		else
2085
+		{
2086
+			if (self::$debug)
2087
+			{
2088
+				error_log(__METHOD__." Mailserver has NO SORT Capability");
2089
+			}
1747 2090
 			//$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1748 2091
 			//if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
1749 2092
 			try
@@ -1757,7 +2100,10 @@  discard block
 block discarded – undo
1757 2100
 				// possible error OR Query. But Horde gives no detailed Info :-(
1758 2101
 				self::$supportsORinQuery[$this->profileID]=false;
1759 2102
 				egw_cache::setCache(egw_cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),self::$supportsORinQuery,60*60*10);
1760
-				if (self::$debug) error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
2103
+				if (self::$debug)
2104
+				{
2105
+					error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
2106
+				}
1761 2107
 				$filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]);
1762 2108
 				try
1763 2109
 				{
@@ -1768,11 +2114,15 @@  discard block
 block discarded – undo
1768 2114
 				{
1769 2115
 				}
1770 2116
 			}
1771
-			if(is_array($sortResult['match'])) {
2117
+			if(is_array($sortResult['match']))
2118
+			{
1772 2119
 					// not sure that this is going so succeed as $sortResult['match'] is a hordeObject
1773 2120
 					sort($sortResult['match'], SORT_NUMERIC);
1774 2121
 			}
1775
-			if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
2122
+			if (self::$debug)
2123
+			{
2124
+				error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
2125
+			}
1776 2126
 		}
1777 2127
 		if ($setSession)
1778 2128
 		{
@@ -1801,7 +2151,8 @@  discard block
 block discarded – undo
1801 2151
 		$_reverse=false;
1802 2152
 		if (is_numeric($_sort))
1803 2153
 		{
1804
-			switch($_sort) {
2154
+			switch($_sort)
2155
+			{
1805 2156
 				case 2:
1806 2157
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1807 2158
 					break;
@@ -1823,7 +2174,8 @@  discard block
 block discarded – undo
1823 2174
 		}
1824 2175
 		else
1825 2176
 		{
1826
-			switch(strtoupper($_sort)) {
2177
+			switch(strtoupper($_sort))
2178
+			{
1827 2179
 				case 'FROMADDRESS':
1828 2180
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1829 2181
 					break;
@@ -1849,7 +2201,10 @@  discard block
 block discarded – undo
1849 2201
 					break;
1850 2202
 			}
1851 2203
 		}
1852
-		if ($_reverse) array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
2204
+		if ($_reverse)
2205
+		{
2206
+			array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
2207
+		}
1853 2208
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.($_reverse?'REVERSE ':'').$_sort.'->'.$retValue);
1854 2209
 		return $retValue;
1855 2210
 	}
@@ -1868,8 +2223,12 @@  discard block
 block discarded – undo
1868 2223
 		$imapFilter->charset('UTF-8');
1869 2224
 
1870 2225
 		//_debug_array($_criterias);
1871
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
1872
-		if((!is_array($_criterias) || $_criterias['status']=='any') && (!isset($_criterias['string']) || empty($_criterias['string']))) {
2226
+		if (self::$debug)
2227
+		{
2228
+			error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2229
+		}
2230
+		if((!is_array($_criterias) || $_criterias['status']=='any') && (!isset($_criterias['string']) || empty($_criterias['string'])))
2231
+		{
1873 2232
 			$imapFilter->flag('DELETED', $set=false);
1874 2233
 			return $imapFilter;
1875 2234
 		}
@@ -1877,11 +2236,13 @@  discard block
 block discarded – undo
1877 2236
 		// statusQuery MUST be placed first, as search for subject/mailbody and such is
1878 2237
 		// depending on charset. flagSearch is not BUT messes the charset if called afterwards
1879 2238
 		$statusQueryValid = false;
1880
-		foreach((array)$_criterias['status'] as $k => $criteria) {
2239
+		foreach((array)$_criterias['status'] as $k => $criteria)
2240
+		{
1881 2241
 			$imapStatusFilter = new Horde_Imap_Client_Search_Query();
1882 2242
 			$imapStatusFilter->charset('UTF-8');
1883 2243
 			$criteria = strtoupper($criteria);
1884
-			switch ($criteria) {
2244
+			switch ($criteria)
2245
+			{
1885 2246
 				case 'ANSWERED':
1886 2247
 				case 'DELETED':
1887 2248
 				case 'FLAGGED':
@@ -1964,17 +2325,22 @@  discard block
 block discarded – undo
1964 2325
 		$imapSearchFilter = new Horde_Imap_Client_Search_Query();
1965 2326
 		$imapSearchFilter->charset('UTF-8');
1966 2327
 
1967
-		if(!empty($_criterias['string'])) {
2328
+		if(!empty($_criterias['string']))
2329
+		{
1968 2330
 			$criteria = strtoupper($_criterias['type']);
1969
-			switch ($criteria) {
2331
+			switch ($criteria)
2332
+			{
1970 2333
 				case 'QUICK':
1971 2334
 					$imapSearchFilter->headerText('SUBJECT', $_criterias['string'], $not=false);
1972 2335
 					//$imapSearchFilter->charset('UTF-8');
1973 2336
 					$imapFilter2 = new Horde_Imap_Client_Search_Query();
1974 2337
 					$imapFilter2->charset('UTF-8');
1975
-					if($this->isSentFolder($_folder)) {
2338
+					if($this->isSentFolder($_folder))
2339
+					{
1976 2340
 						$imapFilter2->headerText('TO', $_criterias['string'], $not=false);
1977
-					} else {
2341
+					}
2342
+					else
2343
+					{
1978 2344
 						$imapFilter2->headerText('FROM', $_criterias['string'], $not=false);
1979 2345
 					}
1980 2346
 					if ($_supportsOrInQuery)
@@ -2016,8 +2382,14 @@  discard block
 block discarded – undo
2016 2382
 					break;
2017 2383
 			}
2018 2384
 		}
2019
-		if ($statusQueryValid && !$queryValid) $queryValid=true;
2020
-		if ($queryValid) $imapFilter->andSearch($imapSearchFilter);
2385
+		if ($statusQueryValid && !$queryValid)
2386
+		{
2387
+			$queryValid=true;
2388
+		}
2389
+		if ($queryValid)
2390
+		{
2391
+			$imapFilter->andSearch($imapSearchFilter);
2392
+		}
2021 2393
 
2022 2394
 		if (isset($_criterias['range']) && !empty($_criterias['range']))
2023 2395
 		{
@@ -2029,10 +2401,13 @@  discard block
 block discarded – undo
2029 2401
 			$query_str = $imapFilter->build();
2030 2402
 			error_log(__METHOD__.' ('.__LINE__.') '.' '.$query_str['query']);
2031 2403
 		}
2032
-		if($queryValid==false) {
2404
+		if($queryValid==false)
2405
+		{
2033 2406
 			$imapFilter->flag('DELETED', $set=false);
2034 2407
 			return $imapFilter;
2035
-		} else {
2408
+		}
2409
+		else
2410
+		{
2036 2411
 			return $imapFilter;
2037 2412
 		}
2038 2413
 	}
@@ -2078,7 +2453,10 @@  discard block
 block discarded – undo
2078 2453
 			if ($_tryIDNConversion===true && stripos($_string,'@')!==false)
2079 2454
 			{
2080 2455
 				$rfcAddr = self::parseAddressList($_string);
2081
-				if (!isset(self::$idna2)) self::$idna2 = new egw_idna;
2456
+				if (!isset(self::$idna2))
2457
+				{
2458
+					self::$idna2 = new egw_idna;
2459
+				}
2082 2460
 				if (isset(self::$idna2))
2083 2461
 				{
2084 2462
 					$stringA = array();
@@ -2092,12 +2470,18 @@  discard block
 block discarded – undo
2092 2470
 						}
2093 2471
 						$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox,self::$idna2->decode($_rfcAddr->host),$_rfcAddr->personal);
2094 2472
 					}
2095
-					if (!empty($stringA)) $_string = implode(',',$stringA);
2473
+					if (!empty($stringA))
2474
+					{
2475
+						$_string = implode(',',$stringA);
2476
+					}
2096 2477
 				}
2097 2478
 			}
2098 2479
 			if ($_tryIDNConversion==='FORCE')
2099 2480
 			{
2100
-				if (!isset(self::$idna2)) self::$idna2 = new egw_idna;
2481
+				if (!isset(self::$idna2))
2482
+				{
2483
+					self::$idna2 = new egw_idna;
2484
+				}
2101 2485
 				if (isset(self::$idna2))
2102 2486
 				{
2103 2487
 					//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_string.'='.self::$idna2->decode($_string));
@@ -2122,7 +2506,10 @@  discard block
 block discarded – undo
2122 2506
 		{
2123 2507
 			return 'No Subject';
2124 2508
 		}
2125
-		if ($decode) $_string = self::decode_header($_string);
2509
+		if ($decode)
2510
+		{
2511
+			$_string = self::decode_header($_string);
2512
+		}
2126 2513
 		// make sure its utf-8
2127 2514
 		$test = @json_encode($_string);
2128 2515
 		if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
@@ -2160,7 +2547,8 @@  discard block
 block discarded – undo
2160 2547
 	 * @param string _parent the parent foldername
2161 2548
 	 * @return ISO-8859-1 / UTF7-IMAP encoded string
2162 2549
 	 */
2163
-	function _encodeFolderName($_folderName) {
2550
+	function _encodeFolderName($_folderName)
2551
+	{
2164 2552
 		return translation::convert($_folderName, self::$displayCharset, 'ISO-8859-1');
2165 2553
 		#return translation::convert($_folderName, self::$displayCharset, 'UTF7-IMAP');
2166 2554
 	}
@@ -2176,21 +2564,36 @@  discard block
 block discarded – undo
2176 2564
 	 */
2177 2565
 	function createFolder($_parent, $_folderName, &$_error)
2178 2566
 	{
2179
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2567
+		if (self::$debug)
2568
+		{
2569
+			error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2570
+		}
2180 2571
 		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2181 2572
 		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2182 2573
 
2183
-		if(empty($parent)) {
2574
+		if(empty($parent))
2575
+		{
2184 2576
 			$newFolderName = $folderName;
2185
-		} else {
2577
+		}
2578
+		else
2579
+		{
2186 2580
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2187 2581
 			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2188 2582
 		}
2189
-		if (empty($newFolderName)) return false;
2190
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2583
+		if (empty($newFolderName))
2584
+		{
2585
+			return false;
2586
+		}
2587
+		if (self::$debug)
2588
+		{
2589
+			error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2590
+		}
2191 2591
 		if ($this->folderExists($newFolderName,true))
2192 2592
 		{
2193
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2593
+			if (self::$debug)
2594
+			{
2595
+				error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2596
+			}
2194 2597
 			return $newFolderName;
2195 2598
 		}
2196 2599
 		try
@@ -2238,13 +2641,19 @@  discard block
 block discarded – undo
2238 2641
 		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2239 2642
 		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2240 2643
 
2241
-		if(empty($parent)) {
2644
+		if(empty($parent))
2645
+		{
2242 2646
 			$newFolderName = $folderName;
2243
-		} else {
2647
+		}
2648
+		else
2649
+		{
2244 2650
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2245 2651
 			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2246 2652
 		}
2247
-		if (self::$debug) error_log("create folder: $newFolderName");
2653
+		if (self::$debug)
2654
+		{
2655
+			error_log("create folder: $newFolderName");
2656
+		}
2248 2657
 		try
2249 2658
 		{
2250 2659
 			$this->icServer->renameMailbox($oldFolderName, $newFolderName);
@@ -2318,8 +2727,14 @@  discard block
 block discarded – undo
2318 2727
 	 */
2319 2728
 	function getFolderObjects($_subscribedOnly=false, $_getCounters=false, $_alwaysGetDefaultFolders=false,$_useCacheIfPossible=true)
2320 2729
 	{
2321
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2322
-		if (self::$debugTimes) $starttime = microtime (true);
2730
+		if (self::$debug)
2731
+		{
2732
+			error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2733
+		}
2734
+		if (self::$debugTimes)
2735
+		{
2736
+			$starttime = microtime (true);
2737
+		}
2323 2738
 		static $folders2return;
2324 2739
 		//$_subscribedOnly=false;
2325 2740
 		// always use static on single request if info is available;
@@ -2327,23 +2742,35 @@  discard block
 block discarded – undo
2327 2742
 		// set $_useCacheIfPossible to false !
2328 2743
 		if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2329 2744
 		{
2330
-			if (self::$debugTimes) self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2745
+			if (self::$debugTimes)
2746
+			{
2747
+				self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2748
+			}
2331 2749
 			return $folders2return[$this->icServer->ImapServerId];
2332 2750
 		}
2333 2751
 
2334 2752
 		if ($_subscribedOnly && $_getCounters===false)
2335 2753
 		{
2336
-			if (is_null($folders2return)) $folders2return = egw_cache::getCache(egw_cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2754
+			if (is_null($folders2return))
2755
+			{
2756
+				$folders2return = egw_cache::getCache(egw_cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2757
+			}
2337 2758
 			if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2338 2759
 			{
2339 2760
 				//error_log(__METHOD__.' ('.__LINE__.') '.' using Cached folderObjects'.array2string($folders2return[$this->icServer->ImapServerId]));
2340
-				if (self::$debugTimes) self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
2761
+				if (self::$debugTimes)
2762
+				{
2763
+					self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
2764
+				}
2341 2765
 				return $folders2return[$this->icServer->ImapServerId];
2342 2766
 			}
2343 2767
 		}
2344 2768
 		// use $folderBasicInfo for holding attributes and other basic folderinfo $folderBasicInfo[$this->icServer->ImapServerId]
2345 2769
 		static $folderBasicInfo;
2346
-		if (is_null($folderBasicInfo)||!isset($folderBasicInfo[$this->icServer->ImapServerId])) $folderBasicInfo = egw_cache::getCache(egw_cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2770
+		if (is_null($folderBasicInfo)||!isset($folderBasicInfo[$this->icServer->ImapServerId]))
2771
+		{
2772
+			$folderBasicInfo = egw_cache::getCache(egw_cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2773
+		}
2347 2774
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($folderBasicInfo[$this->icServer->ImapServerId])));
2348 2775
 
2349 2776
 		$delimiter = $this->getHierarchyDelimiter();
@@ -2356,7 +2783,8 @@  discard block
 block discarded – undo
2356 2783
 		$inboxData->shortFolderName	= 'INBOX';
2357 2784
 		$inboxData->shortDisplayName	= lang('INBOX');
2358 2785
 		$inboxData->subscribed = true;
2359
-		if($_getCounters == true) {
2786
+		if($_getCounters == true)
2787
+		{
2360 2788
 			$inboxData->counter = $this->getMailBoxCounters('INBOX');
2361 2789
 		}
2362 2790
 		// force unsubscribed by preference showAllFoldersInFolderPane
@@ -2375,12 +2803,14 @@  discard block
 block discarded – undo
2375 2803
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2376 2804
 		if (is_array($nameSpace))
2377 2805
 		{
2378
-			foreach($nameSpace as $k => $singleNameSpace) {
2806
+			foreach($nameSpace as $k => $singleNameSpace)
2807
+			{
2379 2808
 				$type = $singleNameSpace['type'];
2380 2809
 				// the following line (assumption that for the same namespace the delimiter should be equal) may be wrong
2381 2810
 				$foldersNameSpace[$type]['delimiter']  = $singleNameSpace['delimiter'];
2382 2811
 
2383
-				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false) {
2812
+				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false)
2813
+				{
2384 2814
 					// fetch and sort the subscribed folders
2385 2815
 					// we alway fetch the subscribed, as this provides the only way to tell
2386 2816
 					// if a folder is subscribed or not
@@ -2431,8 +2861,12 @@  discard block
 block discarded – undo
2431 2861
 							}
2432 2862
 						}
2433 2863
 						//error_log(__METHOD__.' ('.__LINE__.') '.' '.$type.'->'.array2string($foldersNameSpace[$type]['subscribed']));
2434
-						if (!is_array($foldersNameSpace[$type]['all'])) $foldersNameSpace[$type]['all'] = array();
2435
-						if ($_subscribedOnly == true && !empty($foldersNameSpace[$type]['subscribed'])) {
2864
+						if (!is_array($foldersNameSpace[$type]['all']))
2865
+						{
2866
+							$foldersNameSpace[$type]['all'] = array();
2867
+						}
2868
+						if ($_subscribedOnly == true && !empty($foldersNameSpace[$type]['subscribed']))
2869
+						{
2436 2870
 							continue;
2437 2871
 						}
2438 2872
 
@@ -2462,7 +2896,8 @@  discard block
 block discarded – undo
2462 2896
 					}
2463 2897
 
2464 2898
 					//error_log(__METHOD__.' ('.__LINE__.') '.' '.$type.'->'.array2string($allMailboxesExt));
2465
-					foreach ($allMailboxesExt as $mbx) {
2899
+					foreach ($allMailboxesExt as $mbx)
2900
+					{
2466 2901
 						if (!isset($folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]))
2467 2902
 						{
2468 2903
 							$folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]=array(
@@ -2485,20 +2920,33 @@  discard block
 block discarded – undo
2485 2920
 						if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']])||
2486 2921
 							isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']])||
2487 2922
 							(substr($mbx['MAILBOX'],-1)==$foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'],0,-1)]))
2488
-						) continue;
2923
+						)
2924
+						{
2925
+							continue;
2926
+						}
2489 2927
 
2490 2928
 						//echo '#'.$mbx['MAILBOX'].':'.array2string($mbx)."#<br>";
2491 2929
 						$allMailBoxesExtSorted[$mbx['MAILBOX']] = $mbx;
2492 2930
 					}
2493
-					if (is_array($allMailBoxesExtSorted)) ksort($allMailBoxesExtSorted);
2931
+					if (is_array($allMailBoxesExtSorted))
2932
+					{
2933
+						ksort($allMailBoxesExtSorted);
2934
+					}
2494 2935
 					//_debug_array(array_keys($allMailBoxesExtSorted));
2495 2936
 					$allMailboxes = array();
2496
-					foreach ((array)$allMailBoxesExtSorted as $mbx) {
2497
-						if (!in_array($mbx['MAILBOX'],$allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
2937
+					foreach ((array)$allMailBoxesExtSorted as $mbx)
2938
+					{
2939
+						if (!in_array($mbx['MAILBOX'],$allMailboxes))
2940
+						{
2941
+							$allMailboxes[] = $mbx['MAILBOX'];
2942
+						}
2498 2943
 						//echo "Result:";_debug_array($allMailboxes);
2499 2944
 					}
2500 2945
 					$foldersNameSpace[$type]['all'] = $allMailboxes;
2501
-					if (is_array($foldersNameSpace[$type]['all'])) sort($foldersNameSpace[$type]['all']);
2946
+					if (is_array($foldersNameSpace[$type]['all']))
2947
+					{
2948
+						sort($foldersNameSpace[$type]['all']);
2949
+					}
2502 2950
 				}
2503 2951
 			}
2504 2952
 		}
@@ -2507,24 +2955,50 @@  discard block
 block discarded – undo
2507 2955
 		//echo "<br>FolderNameSpace To Process:";_debug_array($foldersNameSpace);
2508 2956
 		$autoFolderObjects = $folders = array();
2509 2957
 		$autofolder_exists = array();
2510
-		foreach( array('personal', 'others', 'shared') as $type) {
2511
-			if(isset($foldersNameSpace[$type])) {
2512
-				if($_subscribedOnly) {
2513
-					if( !empty($foldersNameSpace[$type]['subscribed']) ) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
2514
-				} else {
2515
-					if( !empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
2516
-				}
2517
-				foreach((array)$listOfFolders as $folderName) {
2958
+		foreach( array('personal', 'others', 'shared') as $type)
2959
+		{
2960
+			if(isset($foldersNameSpace[$type]))
2961
+			{
2962
+				if($_subscribedOnly)
2963
+				{
2964
+					if( !empty($foldersNameSpace[$type]['subscribed']) )
2965
+					{
2966
+						$listOfFolders = $foldersNameSpace[$type]['subscribed'];
2967
+					}
2968
+				}
2969
+				else
2970
+				{
2971
+					if( !empty($foldersNameSpace[$type]['all']))
2972
+					{
2973
+						$listOfFolders = $foldersNameSpace[$type]['all'];
2974
+					}
2975
+				}
2976
+				foreach((array)$listOfFolders as $folderName)
2977
+				{
2518 2978
 					//echo "<br>FolderToCheck:$folderName<br>";
2519 2979
 					//error_log(__METHOD__.__LINE__.'#Delimiter:'.$delimiter.':#'.$folderName);
2520
-					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue;//when subscribedonly, we fetch all folders in one go.
2521
-					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
2980
+					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all']))
2981
+					{
2982
+						continue;
2983
+					}
2984
+					//when subscribedonly, we fetch all folders in one go.
2985
+					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all'])))
2986
+					{
2522 2987
 						#echo "$folderName failed to be here <br>";
2523 2988
 						continue;
2524 2989
 					}
2525
-					if (isset($folders[$folderName])) continue;
2526
-					if (isset($autoFolderObjects[$folderName])) continue;
2527
-					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter'];
2990
+					if (isset($folders[$folderName]))
2991
+					{
2992
+						continue;
2993
+					}
2994
+					if (isset($autoFolderObjects[$folderName]))
2995
+					{
2996
+						continue;
2997
+					}
2998
+					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter'])
2999
+					{
3000
+						$delimiter = $foldersNameSpace[$type]['delimiter'];
3001
+					}
2528 3002
 					$folderParts = explode($delimiter, $folderName);
2529 3003
 					$shortName = array_pop($folderParts);
2530 3004
 
@@ -2532,17 +3006,20 @@  discard block
 block discarded – undo
2532 3006
 					$folderObject->delimiter	= $delimiter;
2533 3007
 					$folderObject->folderName	= $folderName;
2534 3008
 					$folderObject->shortFolderName	= $shortName;
2535
-					if(!$_subscribedOnly) {
3009
+					if(!$_subscribedOnly)
3010
+					{
2536 3011
 						#echo $folderName."->".$type."<br>";
2537 3012
 						#_debug_array($foldersNameSpace[$type]['subscribed']);
2538 3013
 						$folderObject->subscribed = in_array($folderName, (array)$foldersNameSpace[$type]['subscribed']);
2539 3014
 					}
2540 3015
 
2541
-					if($_getCounters == true) {
3016
+					if($_getCounters == true)
3017
+					{
2542 3018
 						//error_log(__METHOD__.' ('.__LINE__.') '.' getCounter forFolder:'.$folderName);
2543 3019
 						$folderObject->counter = $this->getMailBoxCounters($folderName);
2544 3020
 					}
2545
-					if(strtoupper($folderName) == 'INBOX') {
3021
+					if(strtoupper($folderName) == 'INBOX')
3022
+					{
2546 3023
 						$folderName = 'INBOX';
2547 3024
 						$folderObject->folderName	= 'INBOX';
2548 3025
 						$folderObject->shortFolderName	= 'INBOX';
@@ -2550,24 +3027,34 @@  discard block
 block discarded – undo
2550 3027
 						$folderObject->shortDisplayName = lang('INBOX');
2551 3028
 						$folderObject->subscribed	= true;
2552 3029
 					// translate the automatic Folders (Sent, Drafts, ...) like the INBOX
2553
-					} elseif (in_array($shortName,self::$autoFolders)) {
3030
+					}
3031
+					elseif (in_array($shortName,self::$autoFolders))
3032
+					{
2554 3033
 						$tmpfolderparts = explode($delimiter,$folderObject->folderName);
2555 3034
 						array_pop($tmpfolderparts);
2556 3035
 						$folderObject->displayName = implode($delimiter,$tmpfolderparts).$delimiter.lang($shortName);
2557 3036
 						$folderObject->shortDisplayName = lang($shortName);
2558 3037
 						unset($tmpfolderparts);
2559
-					} else {
3038
+					}
3039
+					else
3040
+					{
2560 3041
 						$folderObject->displayName = $folderObject->folderName;
2561 3042
 						$folderObject->shortDisplayName = $shortName;
2562 3043
 					}
2563 3044
 					//$folderName = $folderName;
2564
-					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false) {
3045
+					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false)
3046
+					{
2565 3047
 						$autoFolderObjects[$folderName] = $folderObject;
2566
-					} else {
3048
+					}
3049
+					else
3050
+					{
2567 3051
 						$folders[$folderName] = $folderObject;
2568 3052
 					}
2569 3053
 					//error_log(__METHOD__.' ('.__LINE__.') '.':'.$folderObject->folderName);
2570
-					if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders ();
3054
+					if (!isset(self::$specialUseFolders))
3055
+					{
3056
+						$this->getSpecialUseFolders ();
3057
+					}
2571 3058
 					if (isset(self::$specialUseFolders[$folderName]))
2572 3059
 					{
2573 3060
 						$autofolder_exists[$folderName] = self::$specialUseFolders[$folderName];
@@ -2575,7 +3062,8 @@  discard block
 block discarded – undo
2575 3062
 				}
2576 3063
 			}
2577 3064
 		}
2578
-		if (is_array($autoFolderObjects) && !empty($autoFolderObjects)) {
3065
+		if (is_array($autoFolderObjects) && !empty($autoFolderObjects))
3066
+		{
2579 3067
 			uasort($autoFolderObjects,array($this,"sortByAutoFolderPos"));
2580 3068
 		}
2581 3069
 		// check if some standard folders are missing and need to be created
@@ -2584,7 +3072,10 @@  discard block
 block discarded – undo
2584 3072
 			// if new folders have been created, re-read folders ignoring the cache
2585 3073
 			return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false);	// false = do NOT use cache
2586 3074
 		}
2587
-		if (is_array($folders)) uasort($folders,array($this,"sortByDisplayName"));
3075
+		if (is_array($folders))
3076
+		{
3077
+			uasort($folders,array($this,"sortByDisplayName"));
3078
+		}
2588 3079
 		//$folders2return = array_merge($autoFolderObjects,$folders);
2589 3080
 		//_debug_array($folders2return); #exit;
2590 3081
 		$folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject,(array)$autoFolderObjects,(array)$folders);
@@ -2596,7 +3087,10 @@  discard block
 block discarded – undo
2596 3087
 			egw_cache::setCache(egw_cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$folders2return,$expiration=60*60*1);
2597 3088
 		}
2598 3089
 		egw_cache::setCache(egw_cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderBasicInfo,$expiration=60*60*1);
2599
-		if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
3090
+		if (self::$debugTimes)
3091
+		{
3092
+			self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
3093
+		}
2600 3094
 		return $folders2return[$this->icServer->ImapServerId];
2601 3095
 	}
2602 3096
 
@@ -2624,31 +3118,44 @@  discard block
 block discarded – undo
2624 3118
 
2625 3119
 		$folders = $nameSpace =  array();
2626 3120
 		$nameSpaceTmp = $this->_getNameSpaces();
2627
-		foreach($nameSpaceTmp as $k => $singleNameSpace) {
3121
+		foreach($nameSpaceTmp as $k => $singleNameSpace)
3122
+		{
2628 3123
 			$nameSpace[$singleNameSpace['type']]=$singleNameSpace;
2629 3124
 		}
2630 3125
 		unset($nameSpaceTmp);
2631 3126
 
2632 3127
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2633 3128
 		// Get special use folders
2634
-		if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders (); // Set self::$specialUseFolders
3129
+		if (!isset(self::$specialUseFolders))
3130
+		{
3131
+			$this->getSpecialUseFolders ();
3132
+		}
3133
+		// Set self::$specialUseFolders
2635 3134
 		// topLevelQueries generally ignore the $_search param. Except for Config::examineNamespace
2636
-		if ($_onlyTopLevel) // top level leaves
3135
+		if ($_onlyTopLevel)
3136
+		{
3137
+			// top level leaves
2637 3138
 		{
2638 3139
 			// Get top mailboxes of icServer
2639 3140
 			$topFolders = $this->icServer->getMailboxes("", 2, true);
3141
+		}
2640 3142
 			// Trigger examination of namespace to retrieve
2641 3143
 			// folders located in other and shared; needed only for some servers
2642
-			if (is_null(self::$mailConfig)) self::$mailConfig = config::read('mail');
3144
+			if (is_null(self::$mailConfig))
3145
+			{
3146
+				self::$mailConfig = config::read('mail');
3147
+			}
2643 3148
 			if (self::$mailConfig['examineNamespace'])
2644 3149
 			{
2645 3150
 				$prefixes=array();
2646 3151
 				if (is_array($nameSpace))
2647 3152
 				{
2648
-					foreach($nameSpace as $k => $singleNameSpace) {
3153
+					foreach($nameSpace as $k => $singleNameSpace)
3154
+					{
2649 3155
 						$type = $singleNameSpace['type'];
2650 3156
 
2651
-						if(is_array($singleNameSpace) && $singleNameSpace['prefix']){
3157
+						if(is_array($singleNameSpace) && $singleNameSpace['prefix'])
3158
+						{
2652 3159
 							$prefixes[$type] = $singleNameSpace['prefix'];
2653 3160
 							//regard extra care for nameSpacequeries when configured AND respect $_search
2654 3161
 							$result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search==0?0:2, true);
@@ -2724,7 +3231,10 @@  discard block
 block discarded – undo
2724 3231
 							$nFolders [$path] = $folder;
2725 3232
 						}
2726 3233
 					}
2727
-					if (is_array($aFolders)) uasort ($aFolders, array($this,'sortByAutofolder'));
3234
+					if (is_array($aFolders))
3235
+					{
3236
+						uasort ($aFolders, array($this,'sortByAutofolder'));
3237
+					}
2728 3238
 					//ksort($aFolders);
2729 3239
 
2730 3240
 					// Sort none auto folders base on mailbox name
@@ -2734,12 +3244,17 @@  discard block
 block discarded – undo
2734 3244
 				}
2735 3245
 				else
2736 3246
 				{
2737
-					if (is_array($subFolders)) ksort($subFolders);
3247
+					if (is_array($subFolders))
3248
+					{
3249
+						ksort($subFolders);
3250
+					}
2738 3251
 				}
2739 3252
 				$folders = array_merge($folders,(array)$mainFolder, (array)$subFolders);
2740 3253
 			}
2741 3254
 		}
2742
-		elseif ($_nodePath) // single node
3255
+		elseif ($_nodePath)
3256
+		{
3257
+			// single node
2743 3258
 		{
2744 3259
 			switch ($_search)
2745 3260
 			{
@@ -2747,6 +3262,7 @@  discard block
 block discarded – undo
2747 3262
 				case 0:
2748 3263
 				case 2:
2749 3264
 					$path = $_nodePath.''.$delimiter;
3265
+		}
2750 3266
 					break;
2751 3267
 				// Node itself
2752 3268
 				// shouldn't contain next level delimiter
@@ -2765,11 +3281,14 @@  discard block
 block discarded – undo
2765 3281
 
2766 3282
 			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
2767 3283
 		}
2768
-		elseif(!$_nodePath) // all
3284
+		elseif(!$_nodePath)
3285
+		{
3286
+			// all
2769 3287
 		{
2770 3288
 			if ($_subscribedOnly)
2771 3289
 			{
2772 3290
 				$folders = $this->icServer->listSubscribedMailboxes('', 0, true);
3291
+		}
2773 3292
 			}
2774 3293
 			else
2775 3294
 			{
@@ -2781,7 +3300,10 @@  discard block
 block discarded – undo
2781 3300
 		{
2782 3301
 			// SORTING FOLDERS
2783 3302
 			//self::$debugTimes=true;
2784
-			if (self::$debugTimes) $starttime = microtime (true);
3303
+			if (self::$debugTimes)
3304
+			{
3305
+				$starttime = microtime (true);
3306
+			}
2785 3307
 			// Merge of all auto folders and specialusefolders
2786 3308
 			$autoFoldersTmp = array_unique((array_merge(self::$autoFolders, array_values(self::$specialUseFolders))));
2787 3309
 			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
@@ -2791,19 +3313,27 @@  discard block
 block discarded – undo
2791 3313
 			$isGoogleMail=false;
2792 3314
 			foreach($autoFoldersTmp as $afk=>$aF)
2793 3315
 			{
2794
-				if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
3316
+				if (!isset($mySpecialUseFolders[$aF]) && $aF)
3317
+				{
3318
+					$mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
3319
+				}
2795 3320
 				//error_log($afk.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
2796 3321
 			}
2797 3322
 			//error_log(array2string($mySpecialUseFolders));
2798
-			foreach ($tmpFolders as $k => $f) {
3323
+			foreach ($tmpFolders as $k => $f)
3324
+			{
2799 3325
 				$sorted=false;
2800
-				if (strtoupper(substr($k,0,5))=='INBOX') {
2801
-					if (strtoupper($k)=='INBOX') {
3326
+				if (strtoupper(substr($k,0,5))=='INBOX')
3327
+				{
3328
+					if (strtoupper($k)=='INBOX')
3329
+					{
2802 3330
 						//error_log(__METHOD__.__LINE__.':'.strtoupper(substr($k,0,5)).':'.$k);
2803 3331
 						$inboxFolderObject[$k]=$f;
2804 3332
 						unset($folders[$k]);
2805 3333
 						$sorted=true;
2806
-					} else {
3334
+					}
3335
+					else
3336
+					{
2807 3337
 						$isAutoFolder=false;
2808 3338
 						foreach($autoFoldersTmp as $afk=>$aF)
2809 3339
 						{
@@ -2817,17 +3347,25 @@  discard block
 block discarded – undo
2817 3347
 								break;
2818 3348
 							}
2819 3349
 						}
2820
-						if ($isAutoFolder==false) $inboxSubFolderObjects[$k]=$f;
3350
+						if ($isAutoFolder==false)
3351
+						{
3352
+							$inboxSubFolderObjects[$k]=$f;
3353
+						}
2821 3354
 						unset($folders[$k]);
2822 3355
 						$sorted=true;
2823 3356
 					}
2824
-				} elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]') {
3357
+				}
3358
+				elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]')
3359
+				{
2825 3360
 					$isGoogleMail=true;
2826
-					if (strtoupper($k)=='[GOOGLE MAIL]') {
3361
+					if (strtoupper($k)=='[GOOGLE MAIL]')
3362
+					{
2827 3363
 						$googleMailFolderObject[$k]=$f;
2828 3364
 						unset($folders[$k]);
2829 3365
 						$sorted=true;
2830
-					} else {
3366
+					}
3367
+					else
3368
+					{
2831 3369
 						$isAutoFolder=false;
2832 3370
 						foreach($autoFoldersTmp as $afk=>$aF)
2833 3371
 						{
@@ -2841,11 +3379,16 @@  discard block
 block discarded – undo
2841 3379
 								break;
2842 3380
 							}
2843 3381
 						}
2844
-						if ($isAutoFolder==false) $googleSubFolderObjects[$k]=$f;
3382
+						if ($isAutoFolder==false)
3383
+						{
3384
+							$googleSubFolderObjects[$k]=$f;
3385
+						}
2845 3386
 						unset($folders[$k]);
2846 3387
 						$sorted=true;
2847 3388
 					}
2848
-				} else {
3389
+				}
3390
+				else
3391
+				{
2849 3392
 					$isAutoFolder=false;
2850 3393
 					foreach($autoFoldersTmp as $afk=>$aF)
2851 3394
 					{
@@ -2870,7 +3413,8 @@  discard block
 block discarded – undo
2870 3413
 						if ($nameSpace[$type]['prefix_present']&&$nameSpace[$type]['prefix'])
2871 3414
 						{
2872 3415
 							if (substr($k,0,strlen($nameSpace[$type]['prefix']))==$nameSpace[$type]['prefix']||
2873
-								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1)) {
3416
+								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1))
3417
+							{
2874 3418
 								//error_log(__METHOD__.__LINE__.':'.substr($k,0,strlen($nameSpace[$type]['prefix'])).':'.$k);
2875 3419
 								$typeFolderObject[$type][$k]=$f;
2876 3420
 								unset($folders[$k]);
@@ -2895,9 +3439,12 @@  discard block
 block discarded – undo
2895 3439
 				}
2896 3440
 			}
2897 3441
 			//error_log(__METHOD__.__LINE__.array2string($autoFolderObjects));
2898
-			if (!$isGoogleMail) {
3442
+			if (!$isGoogleMail)
3443
+			{
2899 3444
 				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$inboxSubFolderObjects,(array)$folders,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
2900
-			} else {
3445
+			}
3446
+			else
3447
+			{
2901 3448
 				// avoid calling sortByAutoFolder as it is not regarding subfolders
2902 3449
 				$gAutoFolderObjectsTmp = $googleAutoFolderObjects;
2903 3450
 				unset($googleAutoFolderObjects);
@@ -2914,7 +3461,10 @@  discard block
 block discarded – undo
2914 3461
 				}
2915 3462
 				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$folders,(array)$googleMailFolderObject,$googleAutoFolderObjects,$googleSubFolderObjects,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
2916 3463
 			}
2917
-			if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3464
+			if (self::$debugTimes)
3465
+			{
3466
+				self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3467
+			}
2918 3468
 			//self::$debugTimes=false;
2919 3469
 		}
2920 3470
 		// Get counter information and add them to each fetched folders array
@@ -2964,7 +3514,13 @@  discard block
 block discarded – undo
2964 3514
 		$rv = false;
2965 3515
 		foreach ($haystack as $k => $v)
2966 3516
 		{
2967
-			foreach($v as &$sv) {if (trim($sv)==trim($needle)) return $k;}
3517
+			foreach($v as &$sv)
3518
+			{
3519
+if (trim($sv)==trim($needle))
3520
+			{
3521
+				return $k;
3522
+			}
3523
+			}
2968 3524
 		}
2969 3525
 		return $rv;
2970 3526
 	}
@@ -2997,7 +3553,10 @@  discard block
 block discarded – undo
2997 3553
 		$b = mail_tree::pathToFolderData($b['MAILBOX'], $b['delimiter']);
2998 3554
 		$pos1 = array_search(trim($a['name']),self::$autoFolders);
2999 3555
 		$pos2 = array_search(trim($b['name']),self::$autoFolders);
3000
-		if ($pos1 == $pos2) return 0;
3556
+		if ($pos1 == $pos2)
3557
+		{
3558
+			return 0;
3559
+		}
3001 3560
 		return ($pos1 < $pos2) ? -1 : 1;
3002 3561
 	}
3003 3562
 
@@ -3028,7 +3587,10 @@  discard block
 block discarded – undo
3028 3587
 		// 0, 1 und -1
3029 3588
 		$pos1 = array_search(trim($a->shortFolderName),self::$autoFolders);
3030 3589
 		$pos2 = array_search(trim($b->shortFolderName),self::$autoFolders);
3031
-		if ($pos1 == $pos2) return 0;
3590
+		if ($pos1 == $pos2)
3591
+		{
3592
+			return 0;
3593
+		}
3032 3594
 		return ($pos1 < $pos2) ? -1 : 1;
3033 3595
 	}
3034 3596
 
@@ -3049,11 +3611,18 @@  discard block
 block discarded – undo
3049 3611
 		}
3050 3612
 		catch (Exception $e)
3051 3613
 		{
3052
-			if (self::$debug) error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3614
+			if (self::$debug)
3615
+			{
3616
+				error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3617
+			}
3053 3618
 			return false;
3054 3619
 		}
3055
-		if(is_array($folderStatus)) {
3056
-			if ($_returnObject===false) return $folderStatus;
3620
+		if(is_array($folderStatus))
3621
+		{
3622
+			if ($_returnObject===false)
3623
+			{
3624
+				return $folderStatus;
3625
+			}
3057 3626
 			$status =  new stdClass;
3058 3627
 			$status->messages   = $folderStatus['MESSAGES'];
3059 3628
 			$status->unseen     = $folderStatus['UNSEEN'];
@@ -3080,7 +3649,8 @@  discard block
 block discarded – undo
3080 3649
 	{
3081 3650
 		#echo __METHOD__." retrieve SubFolders for $_mailbox$delimiter <br>";
3082 3651
 		$maxreclevel=25;
3083
-		if ($reclevel > $maxreclevel) {
3652
+		if ($reclevel > $maxreclevel)
3653
+		{
3084 3654
 			error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
3085 3655
 			return array();
3086 3656
 		}
@@ -3094,7 +3664,8 @@  discard block
 block discarded – undo
3094 3664
 //error_log(__METHOD__.' ('.__LINE__.') '.' Delimiter:'.array2string($delimiter));
3095 3665
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx));
3096 3666
 		// Example: Array([INBOX/GaGa] => Array([MAILBOX] => INBOX/GaGa[ATTRIBUTES] => Array([0] => \\unmarked)[delimiter] => /))
3097
-		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"]))) {
3667
+		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"])))
3668
+		{
3098 3669
 			// if there are children fetch them
3099 3670
 			//echo $mbx[$mbxkeys[0]]['MAILBOX']."<br>";
3100 3671
 
@@ -3102,7 +3673,8 @@  discard block
 block discarded – undo
3102 3673
 			//$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'],2,false);
3103 3674
 			//_debug_array($buff);
3104 3675
 			$allMailboxes = array();
3105
-			foreach ($buff as $mbxname) {
3676
+			foreach ($buff as $mbxname)
3677
+			{
3106 3678
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbxname));
3107 3679
 				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname['MAILBOX']);
3108 3680
 				#echo "About to recur in level $reclevel:".$mbxname."<br>";
@@ -3111,9 +3683,14 @@  discard block
 block discarded – undo
3111 3683
 					$allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel));
3112 3684
 				}
3113 3685
 			}
3114
-			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'];
3686
+			if (!(in_array('\NoSelect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"])))
3687
+			{
3688
+				$allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX'];
3689
+			}
3115 3690
 			return $allMailboxes;
3116
-		} else {
3691
+		}
3692
+		else
3693
+		{
3117 3694
 			return array($_mailbox);
3118 3695
 		}
3119 3696
 	}
@@ -3136,14 +3713,21 @@  discard block
 block discarded – undo
3136 3713
 			'Junk'     => array('profileKey'=>'acc_folder_junk','autoFolderName'=>'Junk'),
3137 3714
 			'Outbox'   => array('profileKey'=>'acc_folder_outbox','autoFolderName'=>'Outbox'),
3138 3715
 		);
3139
-		if ($_type == 'Templates') $_type = 'Template';	// for some reason self::$autofolders uses 'Templates'!
3716
+		if ($_type == 'Templates')
3717
+		{
3718
+			$_type = 'Template';
3719
+		}
3720
+		// for some reason self::$autofolders uses 'Templates'!
3140 3721
 		$created = false;
3141 3722
 		if (!isset($types[$_type]))
3142 3723
 		{
3143 3724
 			error_log(__METHOD__.' ('.__LINE__.') '.' '.$_type.' not supported for '.__METHOD__);
3144 3725
 			return false;
3145 3726
 		}
3146
-		if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders)) self::$specialUseFolders = $this->getSpecialUseFolders();
3727
+		if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders))
3728
+		{
3729
+			self::$specialUseFolders = $this->getSpecialUseFolders();
3730
+		}
3147 3731
 
3148 3732
 		//highest precedence
3149 3733
 		try
@@ -3153,16 +3737,26 @@  discard block
 block discarded – undo
3153 3737
 		catch (Exception $e)
3154 3738
 		{
3155 3739
 			// we know that outbox is not supported, but we use this here, as we autocreate expected SpecialUseFolders in this function
3156
-			if ($_type != 'Outbox') error_log(__METHOD__.' ('.__LINE__.') '.' Failed to retrieve Folder'.$_folderName." for ".array2string($types[$_type]).":".$e->getMessage());
3740
+			if ($_type != 'Outbox')
3741
+			{
3742
+				error_log(__METHOD__.' ('.__LINE__.') '.' Failed to retrieve Folder'.$_folderName." for ".array2string($types[$_type]).":".$e->getMessage());
3743
+			}
3157 3744
 			$_folderName = false;
3158 3745
 		}
3159 3746
 		// does the folder exist??? (is configured/preset, but non-existent)
3160
-		if ($_folderName && $_checkexistance && $_folderName !='none' && !$this->folderExists($_folderName,true)) {
3747
+		if ($_folderName && $_checkexistance && $_folderName !='none' && !$this->folderExists($_folderName,true))
3748
+		{
3161 3749
 			try
3162 3750
 			{
3163 3751
 				$error = null;
3164
-				if (($_folderName = $this->createFolder('', $_folderName, $error))) $created = true;
3165
-				if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
3752
+				if (($_folderName = $this->createFolder('', $_folderName, $error)))
3753
+				{
3754
+					$created = true;
3755
+				}
3756
+				if ($error)
3757
+				{
3758
+					error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
3759
+				}
3166 3760
 			}
3167 3761
 			catch(Exception $e)
3168 3762
 			{
@@ -3171,9 +3765,16 @@  discard block
 block discarded – undo
3171 3765
 			}
3172 3766
 		}
3173 3767
 		// not sure yet if false is the correct behavior on none
3174
-		if ($_folderName =='none') return 'none' ; //false;
3768
+		if ($_folderName =='none')
3769
+		{
3770
+			return 'none' ;
3771
+		}
3772
+		//false;
3175 3773
 		//no (valid) folder found yet; try specialUseFolders
3176
-		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders))) $_folderName = $f;
3774
+		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders)))
3775
+		{
3776
+			$_folderName = $f;
3777
+		}
3177 3778
 		//no specialUseFolder; try some Defaults
3178 3779
 		if (empty($_folderName) && isset($types[$_type]))
3179 3780
 		{
@@ -3199,7 +3800,10 @@  discard block
 block discarded – undo
3199 3800
 					$error = null;
3200 3801
 					$this->createFolder('', $prefix.$types[$_type]['autoFolderName'],$error);
3201 3802
 					$_folderName = $prefix.$types[$_type]['autoFolderName'];
3202
-					if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
3803
+					if ($error)
3804
+					{
3805
+						error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
3806
+					}
3203 3807
 				}
3204 3808
 				catch(Exception $e)
3205 3809
 				{
@@ -3291,17 +3895,22 @@  discard block
 block discarded – undo
3291 3895
 	function isSentFolder($_folderName, $_checkexistance=TRUE)
3292 3896
 	{
3293 3897
 		$sentFolder = $this->getSentFolder($_checkexistance);
3294
-		if(empty($sentFolder)) {
3898
+		if(empty($sentFolder))
3899
+		{
3295 3900
 			return false;
3296 3901
 		}
3297 3902
 		// does the folder exist???
3298
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
3903
+		if ($_checkexistance && !$this->folderExists($_folderName))
3904
+		{
3299 3905
 			return false;
3300 3906
 		}
3301 3907
 
3302
-		if(false !== stripos($_folderName, $sentFolder)) {
3908
+		if(false !== stripos($_folderName, $sentFolder))
3909
+		{
3303 3910
 			return true;
3304
-		} else {
3911
+		}
3912
+		else
3913
+		{
3305 3914
 			return false;
3306 3915
 		}
3307 3916
 	}
@@ -3314,15 +3923,20 @@  discard block
 block discarded – undo
3314 3923
 	 */
3315 3924
 	function isOutbox($_folderName, $_checkexistance=TRUE)
3316 3925
 	{
3317
-		if (stripos($_folderName, 'Outbox')===false) {
3926
+		if (stripos($_folderName, 'Outbox')===false)
3927
+		{
3318 3928
 			return false;
3319 3929
 		}
3320 3930
 		// does the folder exist???
3321
-		if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName)) {
3931
+		if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName))
3932
+		{
3322 3933
 			$outboxFolder = $this->getOutboxFolder($_checkexistance);
3323
-			if(false !== stripos($_folderName, $outboxFolder)) {
3934
+			if(false !== stripos($_folderName, $outboxFolder))
3935
+			{
3324 3936
 				return true;
3325
-			} else {
3937
+			}
3938
+			else
3939
+			{
3326 3940
 				return false;
3327 3941
 			}
3328 3942
 		}
@@ -3338,17 +3952,25 @@  discard block
 block discarded – undo
3338 3952
 	function isDraftFolder($_folderName, $_checkexistance=TRUE)
3339 3953
 	{
3340 3954
 		$draftFolder = $this->getDraftFolder($_checkexistance);
3341
-		if(empty($draftFolder)) {
3955
+		if(empty($draftFolder))
3956
+		{
3342 3957
 			return false;
3343 3958
 		}
3344 3959
 		// does the folder exist???
3345
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
3960
+		if ($_checkexistance && !$this->folderExists($_folderName))
3961
+		{
3346 3962
 			return false;
3347 3963
 		}
3348
-		if (is_a($_folderName,"Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8;
3349
-		if(false !== stripos($_folderName, $draftFolder)) {
3964
+		if (is_a($_folderName,"Horde_Imap_Client_Mailbox"))
3965
+		{
3966
+			$_folderName = $_folderName->utf8;
3967
+		}
3968
+		if(false !== stripos($_folderName, $draftFolder))
3969
+		{
3350 3970
 			return true;
3351
-		} else {
3971
+		}
3972
+		else
3973
+		{
3352 3974
 			return false;
3353 3975
 		}
3354 3976
 	}
@@ -3362,17 +3984,22 @@  discard block
 block discarded – undo
3362 3984
 	function isTrashFolder($_folderName, $_checkexistance=TRUE)
3363 3985
 	{
3364 3986
 		$trashFolder = $this->getTrashFolder($_checkexistance);
3365
-		if(empty($trashFolder)) {
3987
+		if(empty($trashFolder))
3988
+		{
3366 3989
 			return false;
3367 3990
 		}
3368 3991
 		// does the folder exist???
3369
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
3992
+		if ($_checkexistance && !$this->folderExists($_folderName))
3993
+		{
3370 3994
 			return false;
3371 3995
 		}
3372 3996
 
3373
-		if(false !== stripos($_folderName, $trashFolder)) {
3997
+		if(false !== stripos($_folderName, $trashFolder))
3998
+		{
3374 3999
 			return true;
3375
-		} else {
4000
+		}
4001
+		else
4002
+		{
3376 4003
 			return false;
3377 4004
 		}
3378 4005
 	}
@@ -3386,17 +4013,22 @@  discard block
 block discarded – undo
3386 4013
 	function isTemplateFolder($_folderName, $_checkexistance=TRUE)
3387 4014
 	{
3388 4015
 		$templateFolder = $this->getTemplateFolder($_checkexistance);
3389
-		if(empty($templateFolder)) {
4016
+		if(empty($templateFolder))
4017
+		{
3390 4018
 			return false;
3391 4019
 		}
3392 4020
 		// does the folder exist???
3393
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4021
+		if ($_checkexistance && !$this->folderExists($_folderName))
4022
+		{
3394 4023
 			return false;
3395 4024
 		}
3396 4025
 
3397
-		if(false !== stripos($_folderName, $templateFolder)) {
4026
+		if(false !== stripos($_folderName, $templateFolder))
4027
+		{
3398 4028
 			return true;
3399
-		} else {
4029
+		}
4030
+		else
4031
+		{
3400 4032
 			return false;
3401 4033
 		}
3402 4034
 	}
@@ -3414,15 +4046,27 @@  discard block
 block discarded – undo
3414 4046
 		if (empty($_folder))
3415 4047
 		{
3416 4048
 			// this error is more or less without significance, unless we force the check
3417
-			if ($_forceCheck===true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
4049
+			if ($_forceCheck===true)
4050
+			{
4051
+				error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
4052
+			}
3418 4053
 			return false;
3419 4054
 		}
3420 4055
 		// when check is not enforced , we assume a folder represented as Horde_Imap_Client_Mailbox as existing folder
3421
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false) return true;
3422
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")) $_folder =  $_folder->utf8;
4056
+		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false)
4057
+		{
4058
+			return true;
4059
+		}
4060
+		if (is_a($_folder,"Horde_Imap_Client_Mailbox"))
4061
+		{
4062
+			$_folder =  $_folder->utf8;
4063
+		}
3423 4064
 		// reduce traffic within the Instance per User; Expire every 5 hours
3424 4065
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Called with Folder:'.$_folder.function_backtrace());
3425
-		if (is_null($folderInfo)) $folderInfo = egw_cache::getCache(egw_cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
4066
+		if (is_null($folderInfo))
4067
+		{
4068
+			$folderInfo = egw_cache::getCache(egw_cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
4069
+		}
3426 4070
 		//error_log(__METHOD__.' ('.__LINE__.') '.'Cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID.($forceCheck?'(forcedCheck)':'').':'.array2string($folderInfo));
3427 4071
 		if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck===false)
3428 4072
 		{
@@ -3440,7 +4084,8 @@  discard block
 block discarded – undo
3440 4084
 
3441 4085
 		// does the folder exist???
3442 4086
 		//error_log(__METHOD__."->Connected?".$this->icServer->_connected.", ".$_folder.", ".($forceCheck?' forceCheck activated':'dont check on server'));
3443
-		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
4087
+		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder]))
4088
+		{
3444 4089
 			//error_log(__METHOD__."->NotConnected and forceCheck with profile:".$this->profileID);
3445 4090
 			//return false;
3446 4091
 			//try to connect
@@ -3480,9 +4125,12 @@  discard block
 block discarded – undo
3480 4125
 
3481 4126
 		$this->icServer->openMailbox($folderName);
3482 4127
 
3483
-		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") {
4128
+		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash")
4129
+		{
3484 4130
 			$this->deleteMessages('all',$folderName,'remove_immediately');
3485
-		} else {
4131
+		}
4132
+		else
4133
+		{
3486 4134
 			$this->icServer->expunge($folderName);
3487 4135
 		}
3488 4136
 	}
@@ -3501,10 +4149,16 @@  discard block
 block discarded – undo
3501 4149
 	{
3502 4150
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.array2string($_folder).', '.$_forceDeleteMethod);
3503 4151
 		$oldMailbox = '';
3504
-		if (is_null($_folder) || empty($_folder)) $_folder = $this->sessionData['mailbox'];
4152
+		if (is_null($_folder) || empty($_folder))
4153
+		{
4154
+			$_folder = $this->sessionData['mailbox'];
4155
+		}
3505 4156
 		if (empty($_messageUID))
3506 4157
 		{
3507
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4158
+			if (self::$debug)
4159
+			{
4160
+				error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4161
+			}
3508 4162
 			return false;
3509 4163
 		}
3510 4164
 		elseif ($_messageUID==='all')
@@ -3514,32 +4168,48 @@  discard block
 block discarded – undo
3514 4168
 		else
3515 4169
 		{
3516 4170
 			$uidsToDelete = new Horde_Imap_Client_Ids();
3517
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4171
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4172
+			{
4173
+				$_messageUID = (array)$_messageUID;
4174
+			}
3518 4175
 			$uidsToDelete->add($_messageUID);
3519 4176
 		}
3520 4177
 		$deleteOptions = $_forceDeleteMethod; // use forceDeleteMethod if not "no", or unknown method
3521
-		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");
4178
+		if ($_forceDeleteMethod === 'no' || !in_array($_forceDeleteMethod,array('move_to_trash',"mark_as_deleted","remove_immediately")))
4179
+		{
4180
+			$deleteOptions  = ($this->mailPreferences['deleteOptions']?$this->mailPreferences['deleteOptions']:"mark_as_deleted");
4181
+		}
3522 4182
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3523 4183
 		$trashFolder    = $this->getTrashFolder();
3524 4184
 		$draftFolder	= $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder'];
3525 4185
 		$templateFolder = $this->getTemplateFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['templateFolder'];
3526 4186
 		if((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") ||
3527
-		   (strtolower($_folder) == strtolower($draftFolder))) {
4187
+		   (strtolower($_folder) == strtolower($draftFolder)))
4188
+		{
3528 4189
 			$deleteOptions = "remove_immediately";
3529 4190
 		}
3530
-		if($this->icServer->getCurrentMailbox() != $_folder) {
4191
+		if($this->icServer->getCurrentMailbox() != $_folder)
4192
+		{
3531 4193
 			$oldMailbox = $this->icServer->getCurrentMailbox();
3532 4194
 			$this->icServer->openMailbox($_folder);
3533 4195
 		}
3534 4196
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3535 4197
 		$updateCache = false;
3536
-		switch($deleteOptions) {
4198
+		switch($deleteOptions)
4199
+		{
3537 4200
 			case "move_to_trash":
3538 4201
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3539 4202
 				$updateCache = true;
3540
-				if(!empty($trashFolder)) {
3541
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
3542
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
4203
+				if(!empty($trashFolder))
4204
+				{
4205
+					if (self::$debug)
4206
+					{
4207
+						error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
4208
+					}
4209
+					if (self::$debug)
4210
+					{
4211
+						error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
4212
+					}
3543 4213
 					// copy messages
3544 4214
 					try
3545 4215
 					{
@@ -3555,7 +4225,10 @@  discard block
 block discarded – undo
3555 4225
 			case "mark_as_deleted":
3556 4226
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3557 4227
 				// mark messages as deleted
3558
-				if (is_null($_messageUID)) $_messageUID='all';
4228
+				if (is_null($_messageUID))
4229
+				{
4230
+					$_messageUID='all';
4231
+				}
3559 4232
 				foreach((array)$_messageUID as $key =>$uid)
3560 4233
 				{
3561 4234
 					//flag messages, that are flagged for deletion as seen too
@@ -3563,7 +4236,10 @@  discard block
 block discarded – undo
3563 4236
 					$flags = $this->getFlags($uid);
3564 4237
 					$this->flagMessages('delete', $uid, $_folder);
3565 4238
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
3566
-					if (strpos( array2string($flags),'Deleted')!==false) $undelete[] = $uid;
4239
+					if (strpos( array2string($flags),'Deleted')!==false)
4240
+					{
4241
+						$undelete[] = $uid;
4242
+					}
3567 4243
 					unset($flags);
3568 4244
 				}
3569 4245
 				foreach((array)$undelete as $key =>$uid)
@@ -3575,7 +4251,10 @@  discard block
 block discarded – undo
3575 4251
 			case "remove_immediately":
3576 4252
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3577 4253
 				$updateCache = true;
3578
-				if (is_null($_messageUID)) $_messageUID='all';
4254
+				if (is_null($_messageUID))
4255
+				{
4256
+					$_messageUID='all';
4257
+				}
3579 4258
 				if (is_object($_messageUID))
3580 4259
 				{
3581 4260
 					$this->flagMessages('delete', $_messageUID, $_folder);
@@ -3592,7 +4271,8 @@  discard block
 block discarded – undo
3592 4271
 				$this->icServer->expunge($_folder);
3593 4272
 				break;
3594 4273
 		}
3595
-		if($oldMailbox != '') {
4274
+		if($oldMailbox != '')
4275
+		{
3596 4276
 			$this->icServer->openMailbox($oldMailbox);
3597 4277
 		}
3598 4278
 
@@ -3606,11 +4286,15 @@  discard block
 block discarded – undo
3606 4286
 	 *
3607 4287
 	 * @return null/array flags
3608 4288
 	 */
3609
-	function getFlags ($_messageUID) {
4289
+	function getFlags ($_messageUID)
4290
+	{
3610 4291
 		try
3611 4292
 		{
3612 4293
 			$uidsToFetch = new Horde_Imap_Client_Ids();
3613
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4294
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4295
+			{
4296
+				$_messageUID = (array)$_messageUID;
4297
+			}
3614 4298
 			$uidsToFetch->add($_messageUID);
3615 4299
 			$_folderName = $this->icServer->getCurrentMailbox();
3616 4300
 			$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -3618,8 +4302,10 @@  discard block
 block discarded – undo
3618 4302
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
3619 4303
 				'ids' => $uidsToFetch,
3620 4304
 			));
3621
-			if (is_object($headersNew)) {
3622
-				foreach($headersNew->ids() as $id) {
4305
+			if (is_object($headersNew))
4306
+			{
4307
+				foreach($headersNew->ids() as $id)
4308
+				{
3623 4309
 					$_headerObject = $headersNew->get($id);
3624 4310
 					$flags = $_headerObject->getFlags();
3625 4311
 				}
@@ -3644,10 +4330,16 @@  discard block
 block discarded – undo
3644 4330
 	 */
3645 4331
 	function getNotifyFlags ($_messageUID, $flags=null)
3646 4332
 	{
3647
-		if (self::$debug) error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
4333
+		if (self::$debug)
4334
+		{
4335
+			error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
4336
+		}
3648 4337
 		try
3649 4338
 		{
3650
-			if($flags===null) $flags =  $this->getFlags($_messageUID);
4339
+			if($flags===null)
4340
+			{
4341
+				$flags =  $this->getFlags($_messageUID);
4342
+			}
3651 4343
 		}
3652 4344
 		catch (Exception $e)
3653 4345
 		{
@@ -3655,10 +4347,14 @@  discard block
 block discarded – undo
3655 4347
 		}
3656 4348
 
3657 4349
 		if ( stripos( array2string($flags),'MDNSent')!==false)
3658
-			return true;
4350
+		{
4351
+					return true;
4352
+		}
3659 4353
 
3660 4354
 		if ( stripos( array2string($flags),'MDNnotSent')!==false)
3661
-			return false;
4355
+		{
4356
+					return false;
4357
+		}
3662 4358
 
3663 4359
 		return null;
3664 4360
 	}
@@ -3679,7 +4375,10 @@  discard block
 block discarded – undo
3679 4375
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",$_folder /".$this->sessionData['mailbox']);
3680 4376
 		if (empty($_messageUID))
3681 4377
 		{
3682
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4378
+			if (self::$debug)
4379
+			{
4380
+				error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4381
+			}
3683 4382
 			return false;
3684 4383
 		}
3685 4384
 		$this->icServer->openMailbox(($_folder?$_folder:$this->sessionData['mailbox']));
@@ -3687,7 +4386,10 @@  discard block
 block discarded – undo
3687 4386
 		if (is_array($_messageUID)&& count($_messageUID)>50)
3688 4387
 		{
3689 4388
 			$count = $this->getMailBoxCounters($folder,true);
3690
-			if ($count->messages == count($_messageUID)) $_messageUID='all';
4389
+			if ($count->messages == count($_messageUID))
4390
+			{
4391
+				$_messageUID='all';
4392
+			}
3691 4393
 		}
3692 4394
 
3693 4395
 		if ($_messageUID==='all')
@@ -3696,7 +4398,10 @@  discard block
 block discarded – undo
3696 4398
 		}
3697 4399
 		else
3698 4400
 		{
3699
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4401
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4402
+			{
4403
+				$_messageUID = (array)$_messageUID;
4404
+			}
3700 4405
 			$messageUIDs = array_chunk($_messageUID,50,true);
3701 4406
 		}
3702 4407
 		try
@@ -3712,7 +4417,8 @@  discard block
 block discarded – undo
3712 4417
 					$uidsToModify = new Horde_Imap_Client_Ids();
3713 4418
 					$uidsToModify->add($uids);
3714 4419
 				}
3715
-				switch($_flag) {
4420
+				switch($_flag)
4421
+				{
3716 4422
 					case "delete":
3717 4423
 						$ret = $this->icServer->store($folder, array('add'=>array('\\Deleted'), 'ids'=> $uidsToModify));
3718 4424
 						break;
@@ -3798,7 +4504,10 @@  discard block
 block discarded – undo
3798 4504
 		{
3799 4505
 			error_log(__METHOD__.__LINE__.' Error, could not flag messages in folder '.$folder.' Reason:'.$e->getMessage());
3800 4506
 		}
3801
-		if ($folder instanceof Horde_Imap_Client_Mailbox) $_folder = $folder->utf8;
4507
+		if ($folder instanceof Horde_Imap_Client_Mailbox)
4508
+		{
4509
+			$_folder = $folder->utf8;
4510
+		}
3802 4511
 		//error_log(__METHOD__.__LINE__.'#'.$this->icServer->ImapServerId.'#'.array2string($_folder).'#');
3803 4512
 		self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])]['uidValidity'] = 0;
3804 4513
 
@@ -3827,7 +4536,10 @@  discard block
 block discarded – undo
3827 4536
 		//$deleteOptions  = $GLOBALS['egw_info']["user"]["preferences"]["mail"]["deleteOptions"];
3828 4537
 		if (empty($_messageUID))
3829 4538
 		{
3830
-			if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4539
+			if (self::$debug)
4540
+			{
4541
+				error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4542
+			}
3831 4543
 			return false;
3832 4544
 		}
3833 4545
 		elseif ($_messageUID==='all')
@@ -3839,7 +4551,10 @@  discard block
 block discarded – undo
3839 4551
 		{
3840 4552
 			//error_log(__METHOD__." Message(s): ".implode(',',$_messageUID));
3841 4553
 			$uidsToMove = new Horde_Imap_Client_Ids();
3842
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4554
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4555
+			{
4556
+				$_messageUID = (array)$_messageUID;
4557
+			}
3843 4558
 			$uidsToMove->add($_messageUID);
3844 4559
 		}
3845 4560
 		$sourceFolder = (!empty($currentFolder)?$currentFolder: $this->sessionData['mailbox']);
@@ -3861,12 +4576,14 @@  discard block
 block discarded – undo
3861 4576
 
3862 4577
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' mailheaders:'.array2string($headersNew));
3863 4578
 
3864
-			if (is_object($headersNew)) {
4579
+			if (is_object($headersNew))
4580
+			{
3865 4581
 				$c=0;
3866 4582
 				$retUid = new Horde_Imap_Client_Ids();
3867 4583
 				// we copy chunks of 5 to avoid too much memory and/or server stress
3868 4584
 				// some servers seem not to allow/support the appendig of multiple messages. so we are down to one
3869
-				foreach($headersNew as &$_headerObject) {
4585
+				foreach($headersNew as &$_headerObject)
4586
+				{
3870 4587
 					$c++;
3871 4588
 					$flags = $_headerObject->getFlags(); //unseen status seems to be lost when retrieving the full message
3872 4589
 					$date = $_headerObject->getImapDate();
@@ -3950,7 +4667,11 @@  discard block
 block discarded – undo
3950 4667
 	{
3951 4668
 		try {
3952 4669
 			$date = new egw_time($_date);	// parse date & time including timezone (throws exception, if not parsable)
3953
-			if ($convert2usertime) $date->setUser();	// convert to user-time
4670
+			if ($convert2usertime)
4671
+			{
4672
+				$date->setUser();
4673
+			}
4674
+			// convert to user-time
3954 4675
 			$date2return = $date->format($format);
3955 4676
 		}
3956 4677
 		catch(Exception $e)
@@ -3982,9 +4703,15 @@  discard block
 block discarded – undo
3982 4703
 	static function htmlentities($_string, $_charset=false)
3983 4704
 	{
3984 4705
 		//setting the charset (if not given)
3985
-		if ($_charset===false) $_charset = self::$displayCharset;
4706
+		if ($_charset===false)
4707
+		{
4708
+			$_charset = self::$displayCharset;
4709
+		}
3986 4710
 		$string = @htmlentities($_string, ENT_QUOTES, $_charset, false);
3987
-		if (empty($string) && !empty($_string)) $string = @htmlentities(translation::convert($_string,translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
4711
+		if (empty($string) && !empty($_string))
4712
+		{
4713
+			$string = @htmlentities(translation::convert($_string,translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
4714
+		}
3988 4715
 		return $string;
3989 4716
 	}
3990 4717
 
@@ -4004,18 +4731,41 @@  discard block
 block discarded – undo
4004 4731
 		$_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>'),
4005 4732
 							 array('&amp;',    '<BR>',           '<BR>',             '<BR>',             '</font></td>','<td>',    '',         '',           '',  ''),$_html);
4006 4733
 		//$_html = str_replace(array('&amp;amp;'),array('&amp;'),$_html);
4007
-		if (stripos($_html,'style')!==false) translation::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags
4008
-		if (stripos($_html,'head')!==false) translation::replaceTagsCompletley($_html,'head'); // Strip out stuff in head
4734
+		if (stripos($_html,'style')!==false)
4735
+		{
4736
+			translation::replaceTagsCompletley($_html,'style');
4737
+		}
4738
+		// clean out empty or pagewide style definitions / left over tags
4739
+		if (stripos($_html,'head')!==false)
4740
+		{
4741
+			translation::replaceTagsCompletley($_html,'head');
4742
+		}
4743
+		// Strip out stuff in head
4009 4744
 		//if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false) translation::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false); // Strip out stuff in ifs
4010 4745
 		//if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false) translation::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false); // Strip out stuff in ifs
4011 4746
 		//error_log(__METHOD__.' ('.__LINE__.') '.$_html);
4012 4747
 
4013
-		if (get_magic_quotes_gpc() === 1) $_html = stripslashes($_html);
4748
+		if (get_magic_quotes_gpc() === 1)
4749
+		{
4750
+			$_html = stripslashes($_html);
4751
+		}
4014 4752
 		// Strip out doctype in head, as htmlLawed cannot handle it TODO: Consider extracting it and adding it afterwards
4015
-		if (stripos($_html,'!doctype')!==false) translation::replaceTagsCompletley($_html,'!doctype');
4016
-		if (stripos($_html,'?xml:namespace')!==false) translation::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
4017
-		if (stripos($_html,'?xml version')!==false) translation::replaceTagsCompletley($_html,'\?xml version','\?>',false);
4018
-		if (strpos($_html,'!CURSOR')!==false) translation::replaceTagsCompletley($_html,'!CURSOR');
4753
+		if (stripos($_html,'!doctype')!==false)
4754
+		{
4755
+			translation::replaceTagsCompletley($_html,'!doctype');
4756
+		}
4757
+		if (stripos($_html,'?xml:namespace')!==false)
4758
+		{
4759
+			translation::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
4760
+		}
4761
+		if (stripos($_html,'?xml version')!==false)
4762
+		{
4763
+			translation::replaceTagsCompletley($_html,'\?xml version','\?>',false);
4764
+		}
4765
+		if (strpos($_html,'!CURSOR')!==false)
4766
+		{
4767
+			translation::replaceTagsCompletley($_html,'!CURSOR');
4768
+		}
4019 4769
 		// htmLawed filter only the 'body'
4020 4770
 		//preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $_html, $matches);
4021 4771
 		//if ($matches[2])
@@ -4054,8 +4804,10 @@  discard block
 block discarded – undo
4054 4804
 		//$charSet = 'iso-8859-1';//self::$displayCharset; //'iso-8859-1'; // self::displayCharset seems to be asmarter fallback than iso-8859-1
4055 4805
 		$CharsetFound=false;
4056 4806
 		//echo "#".$_mimePartObject->encoding.'#<br>';
4057
-		if(is_array($_mimePartObject->parameters)) {
4058
-			if(isset($_mimePartObject->parameters['CHARSET'])) {
4807
+		if(is_array($_mimePartObject->parameters))
4808
+		{
4809
+			if(isset($_mimePartObject->parameters['CHARSET']))
4810
+			{
4059 4811
 				$charSet = $_mimePartObject->parameters['CHARSET'];
4060 4812
 				$CharsetFound=true;
4061 4813
 			}
@@ -4076,7 +4828,10 @@  discard block
 block discarded – undo
4076 4828
 	function decodeMimePart($_mimeMessage, $_encoding, $_charset = '')
4077 4829
 	{
4078 4830
 		// decode the part
4079
-		if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
4831
+		if (self::$debug)
4832
+		{
4833
+			error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
4834
+		}
4080 4835
 		switch (strtoupper($_encoding))
4081 4836
 		{
4082 4837
 			case 'BASE64':
@@ -4116,13 +4871,19 @@  discard block
 block discarded – undo
4116 4871
 		// sometimes there are 3 parts, when there is an ics/ical attached/included-> we want to show that
4117 4872
 		// as attachment AND as abstracted ical information (we use our notification style here).
4118 4873
 		$partText = $partCalendar = $partHTML = null;
4119
-		if (self::$debug) _debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
4874
+		if (self::$debug)
4875
+		{
4876
+			_debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
4877
+		}
4120 4878
 		//error_log(__METHOD__.' ('.__LINE__.') ');
4121 4879
 		$ignore_first_part = true;
4122 4880
 		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4123 4881
 		{
4124 4882
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type"." ignoreFirstPart:".$ignore_first_part);
4125
-			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
4883
+			if (self::$debug)
4884
+			{
4885
+				echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
4886
+			}
4126 4887
 
4127 4888
 			if ($ignore_first_part)
4128 4889
 			{
@@ -4138,11 +4899,17 @@  discard block
 block discarded – undo
4138 4899
 					switch($mimePart->getSubType())
4139 4900
 					{
4140 4901
 						case 'plain':
4141
-							if ($mimePart->getBytes() > 0) $partText = $mimePart;
4902
+							if ($mimePart->getBytes() > 0)
4903
+							{
4904
+								$partText = $mimePart;
4905
+							}
4142 4906
 							break;
4143 4907
 
4144 4908
 						case 'html':
4145
-							if ($mimePart->getBytes() > 0)  $partHTML = $mimePart;
4909
+							if ($mimePart->getBytes() > 0)
4910
+							{
4911
+								$partHTML = $mimePart;
4912
+							}
4146 4913
 							break;
4147 4914
 					}
4148 4915
 					break;
@@ -4155,7 +4922,10 @@  discard block
 block discarded – undo
4155 4922
 							if (count($mimePart->getParts()) > 1)
4156 4923
 							{
4157 4924
 								// in a multipart alternative we treat the multipart/related as html part
4158
-								if (self::$debug) error_log(__METHOD__." process MULTIPART/".$mimePart->getSubType()." with array as subparts");
4925
+								if (self::$debug)
4926
+								{
4927
+									error_log(__METHOD__." process MULTIPART/".$mimePart->getSubType()." with array as subparts");
4928
+								}
4159 4929
 								$partHTML = $mimePart;
4160 4930
 								break 3; // GET OUT OF LOOP, will be processed according to type
4161 4931
 							}
@@ -4236,9 +5006,15 @@  discard block
 block discarded – undo
4236 5006
 	 */
4237 5007
 	function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts=array())
4238 5008
 	{
4239
-		if (self::$debug) echo __METHOD__."$_uid, $_htmlMode<br>";
5009
+		if (self::$debug)
5010
+		{
5011
+			echo __METHOD__."$_uid, $_htmlMode<br>";
5012
+		}
4240 5013
 		$bodyPart = array();
4241
-		if (self::$debug) _debug_array($_structure);
5014
+		if (self::$debug)
5015
+		{
5016
+			_debug_array($_structure);
5017
+		}
4242 5018
 
4243 5019
 		$ignore_first_part = true;
4244 5020
 		//$skipParts = array();
@@ -4246,7 +5022,10 @@  discard block
 block discarded – undo
4246 5022
 		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4247 5023
 		{
4248 5024
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type");
4249
-			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5025
+			if (self::$debug)
5026
+			{
5027
+				echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5028
+			}
4250 5029
 			if ($ignore_first_part)
4251 5030
 			{
4252 5031
 				$ignore_first_part = false;
@@ -4264,7 +5043,10 @@  discard block
 block discarded – undo
4264 5043
 			switch($part->getPrimaryType())
4265 5044
 			{
4266 5045
 				case 'multipart':
4267
-					if ($part->getDisposition() == 'attachment') continue;
5046
+					if ($part->getDisposition() == 'attachment')
5047
+					{
5048
+						continue;
5049
+					}
4268 5050
 					switch($part->getSubType())
4269 5051
 					{
4270 5052
 						case 'alternative':
@@ -4329,7 +5111,9 @@  discard block
 block discarded – undo
4329 5111
 					if($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment')
4330 5112
 					{
4331 5113
 						$skipParts[$mime_id.'.0'] = $mime_type;
4332
-						foreach($part->contentTypeMap() as $sub_id => $sub_type){ $skipParts[$sub_id] = $sub_type;}
5114
+						foreach($part->contentTypeMap() as $sub_id => $sub_type)
5115
+						{
5116
+$skipParts[$sub_id] = $sub_type;}
4333 5117
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$_uid.' Part:'.$mime_id.':'.array2string($skipParts));
4334 5118
 						//break 2;
4335 5119
 					}
@@ -4372,7 +5156,10 @@  discard block
 block discarded – undo
4372 5156
 	 */
4373 5157
 	function getBodyPart($_uid, $_partID=null, $_folder=null, $_preserveSeen=false, $_stream=false, &$_encoding=null, $_tryDecodingServerside=true)
4374 5158
 	{
4375
-		if (self::$debug) error_log( __METHOD__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen)");
5159
+		if (self::$debug)
5160
+		{
5161
+			error_log( __METHOD__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen)");
5162
+		}
4376 5163
 
4377 5164
 		if (empty($_folder))
4378 5165
 		{
@@ -4381,7 +5168,10 @@  discard block
 block discarded – undo
4381 5168
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_folder).'/'.$this->icServer->getCurrentMailbox().'/'. $this->sessionData['mailbox']);
4382 5169
 		// querying contents of body part
4383 5170
 		$uidsToFetch = new Horde_Imap_Client_Ids();
4384
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5171
+		if (!(is_object($_uid) || is_array($_uid)))
5172
+		{
5173
+			$_uid = (array)$_uid;
5174
+		}
4385 5175
 		$uidsToFetch->add($_uid);
4386 5176
 
4387 5177
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -4389,9 +5179,12 @@  discard block
 block discarded – undo
4389 5179
 			'peek' => $_preserveSeen,
4390 5180
 			'decode' => true,	// try decode on server, does NOT neccessary work
4391 5181
 		);
4392
-		if ($_tryDecodingServerside===false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
5182
+		if ($_tryDecodingServerside===false)
5183
+		{
5184
+			// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
4393 5185
 		{
4394 5186
 			$_tryDecodingServerside=false;
5187
+		}
4395 5188
 			$fetchParams = array(
4396 5189
 				'peek' => $_preserveSeen,
4397 5190
 			);
@@ -4433,7 +5226,10 @@  discard block
 block discarded – undo
4433 5226
 	{
4434 5227
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_uid.':'.array2string($_structure).' '.function_backtrace());
4435 5228
 		$bodyPart = array();
4436
-		if (self::$debug) _debug_array(array($_structure,function_backtrace()));
5229
+		if (self::$debug)
5230
+		{
5231
+			_debug_array(array($_structure,function_backtrace()));
5232
+		}
4437 5233
 
4438 5234
 		if($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text')))
4439 5235
 		{
@@ -4483,8 +5279,12 @@  discard block
 block discarded – undo
4483 5279
 	 */
4484 5280
 	function getMessageBody($_uid, $_htmlOptions='', $_partID=null, Horde_Mime_Part $_structure=null, $_preserveSeen = false, $_folder = '')
4485 5281
 	{
4486
-		if (self::$debug) echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
4487
-		if($_htmlOptions != '') {
5282
+		if (self::$debug)
5283
+		{
5284
+			echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
5285
+		}
5286
+		if($_htmlOptions != '')
5287
+		{
4488 5288
 			$this->htmlOptions = $_htmlOptions;
4489 5289
 		}
4490 5290
 		if (empty($_folder))
@@ -4573,7 +5373,9 @@  discard block
 block discarded – undo
4573 5373
 						default:
4574 5374
 							$bodyPart = array($this->getTextPart($_uid, $_structure, $this->htmlOptions, $_preserveSeen));
4575 5375
 					}
4576
-				} else {
5376
+				}
5377
+				else
5378
+				{
4577 5379
 					// what if the structure->disposition is attachment ,...
4578 5380
 				}
4579 5381
 				return self::normalizeBodyParts($bodyPart);
@@ -4584,13 +5386,18 @@  discard block
 block discarded – undo
4584 5386
 				{
4585 5387
 					case 'rfc822':
4586 5388
 						$newStructure = $_structure->getParts();
4587
-						if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
5389
+						if (self::$debug)
5390
+						{
5391
+echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
4588 5392
 						return self::normalizeBodyParts($this->getMessageBody($_uid, $_htmlOptions, $newStructure[0]->getMimeId(), $newStructure[0], $_preserveSeen, $_folder));
4589 5393
 				}
4590 5394
 				break;
4591 5395
 
4592 5396
 			default:
4593
-				if (self::$debug) _debug_array($_structure);
5397
+				if (self::$debug)
5398
+				{
5399
+					_debug_array($_structure);
5400
+				}
4594 5401
 				return array(
4595 5402
 					array(
4596 5403
 						'body'		=> lang('The mimeparser can not parse this message.').$_structure->getType(),
@@ -4614,9 +5421,12 @@  discard block
 block discarded – undo
4614 5421
 		{
4615 5422
 			foreach($_bodyParts as $singleBodyPart)
4616 5423
 			{
4617
-				if (!isset($singleBodyPart['body'])) {
5424
+				if (!isset($singleBodyPart['body']))
5425
+				{
4618 5426
 					$buff = self::normalizeBodyParts($singleBodyPart);
4619
-					foreach ((array)$buff as $val) { $body2return[] = $val;}
5427
+					foreach ((array)$buff as $val)
5428
+					{
5429
+$body2return[] = $val;}
4620 5430
 					continue;
4621 5431
 				}
4622 5432
 				$body2return[] = $singleBodyPart;
@@ -4642,13 +5452,20 @@  discard block
 block discarded – undo
4642 5452
 		$message='';
4643 5453
 		for($i=0; $i<count($bodyParts); $i++)
4644 5454
 		{
4645
-			if (!isset($bodyParts[$i]['body'])) {
5455
+			if (!isset($bodyParts[$i]['body']))
5456
+			{
4646 5457
 				$bodyParts[$i]['body'] = self::getdisplayableBody($mailClass, $bodyParts[$i], $preserveHTML, $useTidy);
4647 5458
 				$message .= empty($bodyParts[$i]['body'])?'':$bodyParts[$i]['body'];
4648 5459
 				continue;
4649 5460
 			}
4650
-			if (isset($bodyParts[$i]['error'])) continue;
4651
-			if (empty($bodyParts[$i]['body'])) continue;
5461
+			if (isset($bodyParts[$i]['error']))
5462
+			{
5463
+				continue;
5464
+			}
5465
+			if (empty($bodyParts[$i]['body']))
5466
+			{
5467
+				continue;
5468
+			}
4652 5469
 			// some characterreplacements, as they fail to translate
4653 5470
 			$sar = array(
4654 5471
 				'@(\x84|\x93|\x94)@',
@@ -4675,13 +5492,17 @@  discard block
 block discarded – undo
4675 5492
 				$bodyParts[$i]['body'] = preg_replace($sar,$rar,$bodyParts[$i]['body']);
4676 5493
 			}
4677 5494
 
4678
-			if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = translation::detect_encoding($bodyParts[$i]['body']);
5495
+			if ($bodyParts[$i]['charSet']===false)
5496
+			{
5497
+				$bodyParts[$i]['charSet'] = translation::detect_encoding($bodyParts[$i]['body']);
5498
+			}
4679 5499
 			// add line breaks to $bodyParts
4680 5500
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
4681 5501
 			$newBody  = translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
4682 5502
 			//error_log(__METHOD__.' ('.__LINE__.') '.' MimeType:'.$bodyParts[$i]['mimeType'].'->'.$newBody);
4683 5503
 			$mailClass->activeMimeType = 'text/plain';
4684
-			if ($bodyParts[$i]['mimeType'] == 'text/html') {
5504
+			if ($bodyParts[$i]['mimeType'] == 'text/html')
5505
+			{
4685 5506
 				$mailClass->activeMimeType = $bodyParts[$i]['mimeType'];
4686 5507
 				if (!$preserveHTML)
4687 5508
 				{
@@ -4727,15 +5548,28 @@  discard block
 block discarded – undo
4727 5548
 						// as we switched off HTMLaweds tidy functionality
4728 5549
 						$newBody = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<BR>','<BR>','<BR>'),$newBody);
4729 5550
 						$newBody = $htmLawed->egw_htmLawed($newBody,self::$htmLawed_config);
4730
-						if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3];
5551
+						if ($hasOther && $preserveHTML)
5552
+						{
5553
+							$newBody = $matches[1]. $newBody. $matches[3];
5554
+						}
4731 5555
 						$alreadyHtmlLawed=true;
4732 5556
 					}
4733 5557
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after purify:'.$newBody);
4734
-					if ($preserveHTML==false) $newBody = translation::convertHTMLToText($newBody,self::$displayCharset,true,true);
5558
+					if ($preserveHTML==false)
5559
+					{
5560
+						$newBody = translation::convertHTMLToText($newBody,self::$displayCharset,true,true);
5561
+					}
4735 5562
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after convertHTMLToText:'.$newBody);
4736
-					if ($preserveHTML==false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n
5563
+					if ($preserveHTML==false)
5564
+					{
5565
+						$newBody = nl2br($newBody);
5566
+					}
5567
+					// we need this, as htmLawed removes \r\n
4737 5568
 					/*if (!$alreadyHtmlLawed) */ $mailClass->getCleanHTML($newBody); // remove stuff we regard as unwanted
4738
-					if ($preserveHTML==false) $newBody = str_replace("<br />","\r\n",$newBody);
5569
+					if ($preserveHTML==false)
5570
+					{
5571
+						$newBody = str_replace("<br />","\r\n",$newBody);
5572
+					}
4739 5573
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after getClean:'.$newBody);
4740 5574
 				}
4741 5575
 				$message .= $newBody;
@@ -4772,12 +5606,12 @@  discard block
 block discarded – undo
4772 5606
 				  substr($line,0,strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
4773 5607
 				 )
4774 5608
 				)
4775
-			   )
4776
-			{
5609
+			   ) {
4777 5610
 				$s=explode(" ", $line);
4778 5611
 				$line = "";
4779 5612
 				$linecnt = 0;
4780
-				foreach ($s as &$v) {
5613
+				foreach ($s as &$v)
5614
+				{
4781 5615
 					$cnt = strlen($v);
4782 5616
 					// only break long words within the wordboundaries,
4783 5617
 					// but it may destroy links, so we check for href and dont do it if we find one
@@ -4787,14 +5621,20 @@  discard block
 block discarded – undo
4787 5621
 						$v=wordwrap($v, $allowedLength, $cut, true);
4788 5622
 					}
4789 5623
 					// the rest should be broken at the start of the new word that exceeds the limit
4790
-					if ($linecnt+$cnt > $allowedLength) {
5624
+					if ($linecnt+$cnt > $allowedLength)
5625
+					{
4791 5626
 						$v=$cut.$v;
4792 5627
 						#$linecnt = 0;
4793 5628
 						$linecnt =strlen($v)-strlen($cut);
4794
-					} else {
5629
+					}
5630
+					else
5631
+					{
4795 5632
 						$linecnt += $cnt;
4796 5633
 					}
4797
-					if (strlen($v)) $line .= (strlen($line) ? " " : "").$v;
5634
+					if (strlen($v))
5635
+					{
5636
+						$line .= (strlen($line) ? " " : "").$v;
5637
+					}
4798 5638
 				}
4799 5639
 			}
4800 5640
 			$newStr .= $line . "\n";
@@ -4815,11 +5655,18 @@  discard block
 block discarded – undo
4815 5655
 	function getMessageEnvelope($_uid, $_partID = '',$decode=false, $_folder='', $_useHeaderInsteadOfEnvelope=false)
4816 5656
 	{
4817 5657
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder".function_backtrace());
4818
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5658
+		if (empty($_folder))
5659
+		{
5660
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5661
+		}
4819 5662
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder");
4820
-		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false) {
5663
+		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false)
5664
+		{
4821 5665
 			$uidsToFetch = new Horde_Imap_Client_Ids();
4822
-			if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5666
+			if (!(is_object($_uid) || is_array($_uid)))
5667
+			{
5668
+				$_uid = (array)$_uid;
5669
+			}
4823 5670
 			$uidsToFetch->add($_uid);
4824 5671
 
4825 5672
 			$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -4828,8 +5675,10 @@  discard block
 block discarded – undo
4828 5675
 			$headersNew = $this->icServer->fetch($_folder, $fquery, array(
4829 5676
 				'ids' => $uidsToFetch,
4830 5677
 			));
4831
-			if (is_object($headersNew)) {
4832
-				foreach($headersNew as &$_headerObject) {
5678
+			if (is_object($headersNew))
5679
+			{
5680
+				foreach($headersNew as &$_headerObject)
5681
+				{
4833 5682
 					$env = $_headerObject->getEnvelope();
4834 5683
 					//_debug_array($envFields->singleFields());
4835 5684
 					$singleFields = $envFields->singleFields();
@@ -4846,7 +5695,10 @@  discard block
 block discarded – undo
4846 5695
 								//error_log(__METHOD__.' ('.__LINE__.') '.$v.'->'.array2string($env->$v->addresses));
4847 5696
 								$envelope[$v]=$env->$v->addresses;
4848 5697
 								$address = array();
4849
-								if (!is_array($envelope[$v])) break;
5698
+								if (!is_array($envelope[$v]))
5699
+								{
5700
+									break;
5701
+								}
4850 5702
 								foreach ($envelope[$v] as $k => $ad)
4851 5703
 								{
4852 5704
 									if (stripos($ad,'@')===false)
@@ -4882,7 +5734,9 @@  discard block
 block discarded – undo
4882 5734
 				}
4883 5735
 			}
4884 5736
 			return $envelope;
4885
-		} else {
5737
+		}
5738
+		else
5739
+		{
4886 5740
 
4887 5741
 			$headers = $this->getMessageHeader($_uid, $_partID, true,true,$_folder);
4888 5742
 
@@ -4893,18 +5747,39 @@  discard block
 block discarded – undo
4893 5747
 				'SUBJECT'	=> ($decode ? self::decode_header($headers['SUBJECT']):$headers['SUBJECT']),
4894 5748
 				'MESSAGE_ID'	=> $headers['MESSAGE-ID']
4895 5749
 			);
4896
-			if (isset($headers['IN-REPLY-TO'])) $newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
4897
-			if (isset($headers['REFERENCES'])) $newData['REFERENCES'] = $headers['REFERENCES'];
4898
-			if (isset($headers['THREAD-TOPIC'])) $newData['THREAD-TOPIC'] = $headers['THREAD-TOPIC'];
4899
-			if (isset($headers['THREAD-INDEX'])) $newData['THREAD-INDEX'] = $headers['THREAD-INDEX'];
4900
-			if (isset($headers['LIST-ID'])) $newData['LIST-ID'] = $headers['LIST-ID'];
5750
+			if (isset($headers['IN-REPLY-TO']))
5751
+			{
5752
+				$newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
5753
+			}
5754
+			if (isset($headers['REFERENCES']))
5755
+			{
5756
+				$newData['REFERENCES'] = $headers['REFERENCES'];
5757
+			}
5758
+			if (isset($headers['THREAD-TOPIC']))
5759
+			{
5760
+				$newData['THREAD-TOPIC'] = $headers['THREAD-TOPIC'];
5761
+			}
5762
+			if (isset($headers['THREAD-INDEX']))
5763
+			{
5764
+				$newData['THREAD-INDEX'] = $headers['THREAD-INDEX'];
5765
+			}
5766
+			if (isset($headers['LIST-ID']))
5767
+			{
5768
+				$newData['LIST-ID'] = $headers['LIST-ID'];
5769
+			}
4901 5770
 			//_debug_array($newData);
4902 5771
 			$recepientList = array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO');
4903
-			foreach($recepientList as $recepientType) {
4904
-				if(isset($headers[$recepientType])) {
4905
-					if ($decode) $headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
5772
+			foreach($recepientList as $recepientType)
5773
+			{
5774
+				if(isset($headers[$recepientType]))
5775
+				{
5776
+					if ($decode)
5777
+					{
5778
+						$headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
5779
+					}
4906 5780
 					//error_log(__METHOD__.__LINE__." ".$recepientType."->".array2string($headers[$recepientType]));
4907
-					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress) {
5781
+					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress)
5782
+					{
4908 5783
 						$addressData = array(
4909 5784
 							'PERSONAL_NAME'		=> $singleAddress->personal ? $singleAddress->personal : 'NIL',
4910 5785
 							'AT_DOMAIN_LIST'	=> $singleAddress->adl ? $singleAddress->adl : 'NIL',
@@ -4912,17 +5787,25 @@  discard block
 block discarded – undo
4912 5787
 							'HOST_NAME'		=> $singleAddress->host ? $singleAddress->host : 'NIL',
4913 5788
 							'EMAIL'			=> $singleAddress->host ? $singleAddress->mailbox.'@'.$singleAddress->host : $singleAddress->mailbox,
4914 5789
 						);
4915
-						if($addressData['PERSONAL_NAME'] != 'NIL') {
5790
+						if($addressData['PERSONAL_NAME'] != 'NIL')
5791
+						{
4916 5792
 							$addressData['RFC822_EMAIL'] = imap_rfc822_write_address($singleAddress->mailbox, $singleAddress->host, $singleAddress->personal);
4917
-						} else {
5793
+						}
5794
+						else
5795
+						{
4918 5796
 							$addressData['RFC822_EMAIL'] = 'NIL';
4919 5797
 						}
4920 5798
 						$newData[$recepientType][] = ($addressData['RFC822_EMAIL']!='NIL'?$addressData['RFC822_EMAIL']:$addressData['EMAIL']);//$addressData;
4921 5799
 					}
4922
-				} else {
4923
-					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') {
5800
+				}
5801
+				else
5802
+				{
5803
+					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO')
5804
+					{
4924 5805
 						$newData[$recepientType] = $newData['FROM'];
4925
-					} else {
5806
+					}
5807
+					else
5808
+					{
4926 5809
 						$newData[$recepientType] = array();
4927 5810
 					}
4928 5811
 				}
@@ -4945,9 +5828,15 @@  discard block
 block discarded – undo
4945 5828
 	function getMessageHeader($_uid, $_partID = '',$decode=false, $preserveUnSeen=false, $_folder='')
4946 5829
 	{
4947 5830
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$_uid.', '.$_partID.', '.$decode.', '.$preserveUnSeen.', '.$_folder);
4948
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5831
+		if (empty($_folder))
5832
+		{
5833
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5834
+		}
4949 5835
 		$uidsToFetch = new Horde_Imap_Client_Ids();
4950
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5836
+		if (!(is_object($_uid) || is_array($_uid)))
5837
+		{
5838
+			$_uid = (array)$_uid;
5839
+		}
4951 5840
 		$uidsToFetch->add($_uid);
4952 5841
 
4953 5842
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -4963,7 +5852,8 @@  discard block
 block discarded – undo
4963 5852
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
4964 5853
 			'ids' => $uidsToFetch,
4965 5854
 		));
4966
-		if (is_object($headersNew)) {
5855
+		if (is_object($headersNew))
5856
+		{
4967 5857
 			foreach($headersNew as $_fetchObject)
4968 5858
 			{
4969 5859
 				$headers = $_fetchObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
@@ -4983,7 +5873,10 @@  discard block
 block discarded – undo
4983 5873
 			}
4984 5874
 			if ($decode === 'object')
4985 5875
 			{
4986
-				if (is_object($headers)) $headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
5876
+				if (is_object($headers))
5877
+				{
5878
+					$headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
5879
+				}
4987 5880
 				return $headers;
4988 5881
 			}
4989 5882
 			$retValue = is_object($headers) ? $headers->toArray():array();
@@ -5018,10 +5911,16 @@  discard block
 block discarded – undo
5018 5911
 	function getMessageRawHeader($_uid, $_partID = '', $_folder = '')
5019 5912
 	{
5020 5913
 		static $rawHeaders;
5021
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5914
+		if (empty($_folder))
5915
+		{
5916
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5917
+		}
5022 5918
 		//error_log(__METHOD__.' ('.__LINE__.') '." Try Using Cache for raw Header $_uid, $_partID in Folder $_folder");
5023 5919
 
5024
-		if (is_null($rawHeaders)||!is_array($rawHeaders)) $rawHeaders = egw_cache::getCache(egw_cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
5920
+		if (is_null($rawHeaders)||!is_array($rawHeaders))
5921
+		{
5922
+			$rawHeaders = egw_cache::getCache(egw_cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
5923
+		}
5025 5924
 		if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5026 5925
 		{
5027 5926
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Header $_uid, $_partID in Folder $_folder");
@@ -5029,7 +5928,10 @@  discard block
 block discarded – undo
5029 5928
 		}
5030 5929
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5031 5930
 		$uid = $_uid;
5032
-		if (!(is_object($_uid) || is_array($_uid))) $uid = (array)$_uid;
5931
+		if (!(is_object($_uid) || is_array($_uid)))
5932
+		{
5933
+			$uid = (array)$_uid;
5934
+		}
5033 5935
 		$uidsToFetch->add($uid);
5034 5936
 
5035 5937
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5045,8 +5947,10 @@  discard block
 block discarded – undo
5045 5947
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5046 5948
 			'ids' => $uidsToFetch,
5047 5949
 		));
5048
-		if (is_object($headersNew)) {
5049
-			foreach($headersNew as &$_headerObject) {
5950
+		if (is_object($headersNew))
5951
+		{
5952
+			foreach($headersNew as &$_headerObject)
5953
+			{
5050 5954
 				$retValue = $_headerObject->getHeaderText();
5051 5955
 				if ($_partID != '')
5052 5956
 				{
@@ -5074,22 +5978,33 @@  discard block
 block discarded – undo
5074 5978
 	static function &getStyles($_bodyParts)
5075 5979
 	{
5076 5980
 		$style = '';
5077
-		if (empty($_bodyParts)) return "";
5078
-		foreach((array)$_bodyParts as $singleBodyPart) {
5079
-			if (!isset($singleBodyPart['body'])) {
5981
+		if (empty($_bodyParts))
5982
+		{
5983
+			return "";
5984
+		}
5985
+		foreach((array)$_bodyParts as $singleBodyPart)
5986
+		{
5987
+			if (!isset($singleBodyPart['body']))
5988
+			{
5080 5989
 				$singleBodyPart['body'] = self::getStyles($singleBodyPart);
5081 5990
 				$style .= $singleBodyPart['body'];
5082 5991
 				continue;
5083 5992
 			}
5084 5993
 
5085
-			if ($singleBodyPart['charSet']===false) $singleBodyPart['charSet'] = translation::detect_encoding($singleBodyPart['body']);
5994
+			if ($singleBodyPart['charSet']===false)
5995
+			{
5996
+				$singleBodyPart['charSet'] = translation::detect_encoding($singleBodyPart['body']);
5997
+			}
5086 5998
 			$singleBodyPart['body'] = translation::convert(
5087 5999
 				$singleBodyPart['body'],
5088 6000
 				strtolower($singleBodyPart['charSet'])
5089 6001
 			);
5090 6002
 			$ct = 0;
5091 6003
 			$newStyle=array();
5092
-			if (stripos($singleBodyPart['body'],'<style')!==false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
6004
+			if (stripos($singleBodyPart['body'],'<style')!==false)
6005
+			{
6006
+				$ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
6007
+			}
5093 6008
 			if ($ct>0)
5094 6009
 			{
5095 6010
 				//error_log(__METHOD__.' ('.__LINE__.') '.'#'.$ct.'#'.array2string($newStyle));
@@ -5121,7 +6036,11 @@  discard block
 block discarded – undo
5121 6036
 		// CSS Security
5122 6037
 		// http://code.google.com/p/browsersec/wiki/Part1#Cascading_stylesheets
5123 6038
 		$css = preg_replace('/(javascript|expression|-moz-binding)/i','',$style);
5124
-		if (stripos($css,'script')!==false) translation::replaceTagsCompletley($css,'script'); // Strip out script that may be included
6039
+		if (stripos($css,'script')!==false)
6040
+		{
6041
+			translation::replaceTagsCompletley($css,'script');
6042
+		}
6043
+		// Strip out script that may be included
5125 6044
 		// 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
5126 6045
 		// as the comments as <!-- styledefinition --> in stylesheet are outdated, and ck-editor does not understand it, we remove it
5127 6046
 		$css = str_replace(array(':','<!--','-->'),array(': ','',''),$css);
@@ -5142,8 +6061,14 @@  discard block
 block discarded – undo
5142 6061
 	{
5143 6062
 		//TODO: caching einbauen static!
5144 6063
 		static $rawBody;
5145
-		if (is_null($rawBody)) $rawBody = array();
5146
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6064
+		if (is_null($rawBody))
6065
+		{
6066
+			$rawBody = array();
6067
+		}
6068
+		if (empty($_folder))
6069
+		{
6070
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6071
+		}
5147 6072
 		if (isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5148 6073
 		{
5149 6074
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Body $_uid, $_partID in Folder $_folder");
@@ -5152,7 +6077,10 @@  discard block
 block discarded – undo
5152 6077
 
5153 6078
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5154 6079
 		$uid = $_uid;
5155
-		if (!(is_object($_uid) || is_array($_uid))) $uid = (array)$_uid;
6080
+		if (!(is_object($_uid) || is_array($_uid)))
6081
+		{
6082
+			$uid = (array)$_uid;
6083
+		}
5156 6084
 		$uidsToFetch->add($uid);
5157 6085
 
5158 6086
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5165,8 +6093,10 @@  discard block
 block discarded – undo
5165 6093
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5166 6094
 			'ids' => $uidsToFetch,
5167 6095
 		));
5168
-		if (is_object($headersNew)) {
5169
-			foreach($headersNew as &$_headerObject) {
6096
+		if (is_object($headersNew))
6097
+		{
6098
+			foreach($headersNew as &$_headerObject)
6099
+			{
5170 6100
 				$body = $_headerObject->getFullMsg();
5171 6101
 				if ($_partID != '')
5172 6102
 				{
@@ -5199,14 +6129,20 @@  discard block
 block discarded – undo
5199 6129
 	 */
5200 6130
 	function getStructure($_uid, $_partID=null, $_folder=null, $_preserveSeen=false)
5201 6131
 	{
5202
-		if (self::$debug) error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
6132
+		if (self::$debug)
6133
+		{
6134
+			error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
6135
+		}
5203 6136
 
5204 6137
 		if (empty($_folder))
5205 6138
 		{
5206 6139
 			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5207 6140
 		}
5208 6141
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5209
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6142
+		if (!(is_object($_uid) || is_array($_uid)))
6143
+		{
6144
+			$_uid = (array)$_uid;
6145
+		}
5210 6146
 		$uidsToFetch->add($_uid);
5211 6147
 		try
5212 6148
 		{
@@ -5215,7 +6151,10 @@  discard block
 block discarded – undo
5215 6151
 	//		$fquery->envelope();
5216 6152
 	//		$fquery->size();
5217 6153
 			$_fquery->structure();
5218
-			if ($_partID) $_fquery->bodyPart($_partID, array('peek' => $_preserveSeen));
6154
+			if ($_partID)
6155
+			{
6156
+				$_fquery->bodyPart($_partID, array('peek' => $_preserveSeen));
6157
+			}
5219 6158
 
5220 6159
 			$mail = $this->icServer->fetch($_folder, $_fquery, array(
5221 6160
 				'ids' => $uidsToFetch,
@@ -5246,16 +6185,28 @@  discard block
 block discarded – undo
5246 6185
 	 */
5247 6186
 	function getMessageAttachments($_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folder='')
5248 6187
 	{
5249
-		if (self::$debug) error_log( __METHOD__.":$_uid, $_partID");
5250
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6188
+		if (self::$debug)
6189
+		{
6190
+			error_log( __METHOD__.":$_uid, $_partID");
6191
+		}
6192
+		if (empty($_folder))
6193
+		{
6194
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6195
+		}
5251 6196
 		$attachments = array();
5252 6197
 		if (!isset($_structure))
5253 6198
 		{
5254 6199
 			$_structure = $this->getStructure($_uid, $_partID,$_folder,true);
5255 6200
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.print_r($_structure->contentTypeMap(),true));
5256 6201
 		}
5257
-		if (!$_structure || !$_structure->contentTypeMap()) return array();
5258
-		if (!empty($_partID)) $_structure = $_structure->getPart($_partID);
6202
+		if (!$_structure || !$_structure->contentTypeMap())
6203
+		{
6204
+			return array();
6205
+		}
6206
+		if (!empty($_partID))
6207
+		{
6208
+			$_structure = $_structure->getPart($_partID);
6209
+		}
5259 6210
 		$skipParts = array();
5260 6211
 		$tnefParts = array();
5261 6212
 		$skip = 0;
@@ -5273,7 +6224,13 @@  discard block
 block discarded – undo
5273 6224
 			if ($mime_type=='message/rfc822' && $_partID!=$mime_id)
5274 6225
 			{
5275 6226
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
5276
-				foreach($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
6227
+				foreach($part->contentTypeMap() as $sub_id => $sub_type)
6228
+				{
6229
+if ($sub_id != $mime_id)
6230
+				{
6231
+					$skipParts[$sub_id] = $sub_type;
6232
+				}
6233
+				}
5277 6234
 			}
5278 6235
 			if (empty($partDisposition) && $partPrimaryType != 'multipart' && $partPrimaryType != 'text')
5279 6236
 			{
@@ -5284,7 +6241,10 @@  discard block
 block discarded – undo
5284 6241
 				$partDisposition='attachment';
5285 6242
 			}
5286 6243
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($skipParts));
5287
-			if (array_key_exists($mime_id,$skipParts)) continue;
6244
+			if (array_key_exists($mime_id,$skipParts))
6245
+			{
6246
+				continue;
6247
+			}
5288 6248
 
5289 6249
 			if ($partDisposition == 'attachment' ||
5290 6250
 				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId()=='') ||
@@ -5295,23 +6255,41 @@  discard block
 block discarded – undo
5295 6255
 			{
5296 6256
 				// if type is message/rfc822 and _partID is given, and MimeID equals partID
5297 6257
 				// we attempt to fetch "ourselves"
5298
-				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message') continue;
6258
+				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message')
6259
+				{
6260
+					continue;
6261
+				}
5299 6262
 				$attachment = $part->getAllDispositionParameters();
5300 6263
 
5301 6264
 				$attachment['mimeType'] = $mime_type;
5302 6265
 				$attachment['uid'] = $_uid;
5303 6266
 				$attachment['partID'] = $mime_id;
5304
-				if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
6267
+				if (!isset($attachment['name'])||empty($attachment['name']))
6268
+				{
6269
+					$attachment['name'] = $part->getName();
6270
+				}
5305 6271
 				if ($fetchTextCalendar)
5306 6272
 				{
5307 6273
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part->getAllContentTypeParameters()));
5308 6274
 					$method = $part->getContentTypeParameter('method');
5309
-					if ($method) $attachment['method'] = $method;
5310
-					if (!isset($attachment['name'])) $attachment['name'] = 'event.ics';
6275
+					if ($method)
6276
+					{
6277
+						$attachment['method'] = $method;
6278
+					}
6279
+					if (!isset($attachment['name']))
6280
+					{
6281
+						$attachment['name'] = 'event.ics';
6282
+					}
5311 6283
 				}
5312 6284
 				$attachment['size'] = $part->getBytes();
5313
-				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5314
-				if (empty($attachment['name'])) $attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.mime_magic::mime2ext($mime_type);
6285
+				if (($cid = $part->getContentId()))
6286
+				{
6287
+					$attachment['cid'] = $cid;
6288
+				}
6289
+				if (empty($attachment['name']))
6290
+				{
6291
+					$attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.mime_magic::mime2ext($mime_type);
6292
+				}
5315 6293
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($attachment));
5316 6294
 				//typical winmail.dat attachment is
5317 6295
 				//Array([size] => 1462762[filename] => winmail.dat[mimeType] => application/ms-tnef[uid] => 100[partID] => 2[name] => winmail.dat)
@@ -5347,14 +6325,26 @@  discard block
 block discarded – undo
5347 6325
 						$attachment['uid'] = $tnp['uid'];
5348 6326
 						$attachment['partID'] = $tnp['partID'];
5349 6327
 						$attachment['is_winmail'] = $tnp['uid'].'@'.$tnp['partID'].'@'.$mime_id;
5350
-						if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
6328
+						if (!isset($attachment['name'])||empty($attachment['name']))
6329
+						{
6330
+							$attachment['name'] = $part->getName();
6331
+						}
5351 6332
 						$attachment['size'] = $part->getBytes();
5352
-						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5353
-						if (empty($attachment['name'])) $attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.mime_magic::mime2ext($attachment['mimeType']);
6333
+						if (($cid = $part->getContentId()))
6334
+						{
6335
+							$attachment['cid'] = $cid;
6336
+						}
6337
+						if (empty($attachment['name']))
6338
+						{
6339
+							$attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.mime_magic::mime2ext($attachment['mimeType']);
6340
+						}
5354 6341
 						$attachments[] = $attachment;
5355 6342
 					}
5356 6343
 				}
5357
-				if ($tnefResolved===false) $attachments[]=$tnp;
6344
+				if ($tnefResolved===false)
6345
+				{
6346
+					$attachments[]=$tnp;
6347
+				}
5358 6348
 			}
5359 6349
 		}
5360 6350
 		//error_log(__METHOD__.__LINE__.array2string($attachments));
@@ -5457,8 +6447,14 @@  discard block
 block discarded – undo
5457 6447
 
5458 6448
 				$attachment = $part->getAllDispositionParameters();
5459 6449
 				$attachment['mimeType'] = $part->getType();
5460
-				if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5461
-				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
6450
+				if (!isset($attachment['filename'])||empty($attachment['filename']))
6451
+				{
6452
+					$attachment['filename'] = $part->getName();
6453
+				}
6454
+				if (($cid = $part->getContentId()))
6455
+				{
6456
+					$attachment['cid'] = $cid;
6457
+				}
5462 6458
 				if (empty($attachment['filename']))
5463 6459
 				{
5464 6460
 					$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?
@@ -5470,7 +6466,10 @@  discard block
 block discarded – undo
5470 6466
 				$attachments[$_uid.'@'.$_partID.'@'.$mime_id] = $attachment;
5471 6467
 			}
5472 6468
 		}
5473
-		if (!is_array($attachments)) return false;
6469
+		if (!is_array($attachments))
6470
+		{
6471
+			return false;
6472
+		}
5474 6473
 		return $attachments;
5475 6474
 	}
5476 6475
 
@@ -5489,10 +6488,16 @@  discard block
 block discarded – undo
5489 6488
 	function getAttachment($_uid, $_partID, $_winmail_nr=0, $_returnPart=true, $_stream=false, $_folder=null)
5490 6489
 	{
5491 6490
 		//error_log(__METHOD__.__LINE__."Uid:$_uid, PartId:$_partID, WinMailNr:$_winmail_nr, ReturnPart:$_returnPart, Stream:$_stream, Folder:$_folder".function_backtrace());
5492
-		if (!isset($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6491
+		if (!isset($_folder))
6492
+		{
6493
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6494
+		}
5493 6495
 
5494 6496
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5495
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6497
+		if (!(is_object($_uid) || is_array($_uid)))
6498
+		{
6499
+			$_uid = (array)$_uid;
6500
+		}
5496 6501
 		$uidsToFetch->add($_uid);
5497 6502
 
5498 6503
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5501,8 +6506,10 @@  discard block
 block discarded – undo
5501 6506
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5502 6507
 			'ids' => $uidsToFetch,
5503 6508
 		));
5504
-		if (is_object($headersNew)) {
5505
-			foreach($headersNew as $id=>$_headerObject) {
6509
+		if (is_object($headersNew))
6510
+		{
6511
+			foreach($headersNew as $id=>$_headerObject)
6512
+			{
5506 6513
 				$body = $_headerObject->getFullMsg();
5507 6514
 				if ($_partID != '')
5508 6515
 				{
@@ -5516,7 +6523,10 @@  discard block
 block discarded – undo
5516 6523
 					}
5517 6524
 					// if $partDisposition is empty, we assume attachment, and hope that the function
5518 6525
 					// itself is only triggered to fetch attachments
5519
-					if (empty($partDisposition)) $partDisposition='attachment';
6526
+					if (empty($partDisposition))
6527
+					{
6528
+						$partDisposition='attachment';
6529
+					}
5520 6530
 					if ($part && ($partDisposition=='attachment' || $partDisposition=='inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar')))
5521 6531
 					{
5522 6532
 						//$headerObject=$part->getAllDispositionParameters();//not used anywhere around here
@@ -5525,13 +6535,19 @@  discard block
 block discarded – undo
5525 6535
 						$charset = $part->getContentTypeParameter('charset');
5526 6536
 						//$structure_bytes = $part->getBytes(); $structure_partID=$part->getMimeId(); error_log(__METHOD__.__LINE__." fetchPartContents(".array2string($_uid).", $structure_partID, $_stream, $_preserveSeen,$structure_mime)" );
5527 6537
 						$this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen=true,$structure_mime);
5528
-						if ($_returnPart) return $part;
6538
+						if ($_returnPart)
6539
+						{
6540
+							return $part;
6541
+						}
5529 6542
 					}
5530 6543
 				}
5531 6544
 			}
5532 6545
 		}
5533 6546
 		$ext = mime_magic::mime2ext($structure_mime);
5534
-		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false) $filename = trim($filename).'.'.$ext;
6547
+		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false)
6548
+		{
6549
+			$filename = trim($filename).'.'.$ext;
6550
+		}
5535 6551
 		if (!$part)
5536 6552
 		{
5537 6553
 			throw new egw_exception_wrong_parameter("Error: Could not fetch attachment for Uid=".array2string($_uid).", PartId=$_partID, WinMailNr=$_winmail_nr, folder=$_folder");
@@ -5547,7 +6563,10 @@  discard block
 block discarded – undo
5547 6563
 		);
5548 6564
 
5549 6565
 		// try guessing the mimetype, if we get the application/octet-stream
5550
-		if (strtolower($attachmentData['type']) == 'application/octet-stream') $attachmentData['type'] = mime_magic::filename2mime($attachmentData['filename']);
6566
+		if (strtolower($attachmentData['type']) == 'application/octet-stream')
6567
+		{
6568
+			$attachmentData['type'] = mime_magic::filename2mime($attachmentData['filename']);
6569
+		}
5551 6570
 		# if the attachment holds a winmail number and is a winmail.dat then we have to handle that.
5552 6571
 		if ( $filename == 'winmail.dat' && $_winmail_nr)
5553 6572
 		{
@@ -5570,9 +6589,18 @@  discard block
 block discarded – undo
5570 6589
 					if ($_winmail_nr == $wantedPart.'@'.$mime_id)
5571 6590
 					{
5572 6591
 						//error_log(__METHOD__.__LINE__.'#'.$structure_mime.'#'.$filename.'#'.array2string($attachment));
5573
-						if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5574
-						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5575
-						if (empty($attachment['filename'])) $attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.mime_magic::mime2ext($attachment['mimeType']);
6592
+						if (!isset($attachment['filename'])||empty($attachment['filename']))
6593
+						{
6594
+							$attachment['filename'] = $part->getName();
6595
+						}
6596
+						if (($cid = $part->getContentId()))
6597
+						{
6598
+							$attachment['cid'] = $cid;
6599
+						}
6600
+						if (empty($attachment['filename']))
6601
+						{
6602
+							$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.mime_magic::mime2ext($attachment['mimeType']);
6603
+						}
5576 6604
 						$wmattach = $attachment;
5577 6605
 						$wmattach['attachment'] = $part->getContents(array('stream'=>$_stream));
5578 6606
 
@@ -5582,7 +6610,10 @@  discard block
 block discarded – undo
5582 6610
 			if ($tnefResolved)
5583 6611
 			{
5584 6612
 				$ext = mime_magic::mime2ext($wmattach['mimeType']);
5585
-				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
6613
+				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false)
6614
+				{
6615
+					$wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
6616
+				}
5586 6617
 				$attachmentData = array(
5587 6618
 					'type'       => $wmattach['mimeType'],
5588 6619
 					'filename'   => $wmattach['filename'],
@@ -5612,7 +6643,10 @@  discard block
 block discarded – undo
5612 6643
 		static $uid=null, $part=null, $structure=null;
5613 6644
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_cid, $_part");
5614 6645
 
5615
-		if(empty($_cid)) return false;
6646
+		if(empty($_cid))
6647
+		{
6648
+			return false;
6649
+		}
5616 6650
 
5617 6651
 		if ($_uid != $uid || $_part != $part)
5618 6652
 		{
@@ -5637,13 +6671,19 @@  discard block
 block discarded – undo
5637 6671
 					$attachment = $part;
5638 6672
 				}
5639 6673
 				// everything else we only consider after we checked all
5640
-				if (!isset($attachment)) $attachment = $part;
6674
+				if (!isset($attachment))
6675
+				{
6676
+					$attachment = $part;
6677
+				}
5641 6678
 				// do we want content fetched, can be done later, if not needed
5642 6679
 				if (isset($_stream))
5643 6680
 				{
5644 6681
 					$this->fetchPartContents($_uid, $attachment, $_stream);
5645 6682
 				}
5646
-				if (isset($attachment)) break;
6683
+				if (isset($attachment))
6684
+				{
6685
+					break;
6686
+				}
5647 6687
 			}
5648 6688
 		}
5649 6689
 		// set name as filename, if not set
@@ -5674,10 +6714,17 @@  discard block
 block discarded – undo
5674 6714
 	 */
5675 6715
 	public function fetchPartContents($_uid, Horde_Mime_Part $part=null, $_stream=false, $_preserveSeen=false, $_mimetype=null)
5676 6716
 	{
5677
-		if (is_null($part)) return null;//new Horde_Mime_Part;
6717
+		if (is_null($part))
6718
+		{
6719
+			return null;
6720
+		}
6721
+		//new Horde_Mime_Part;
5678 6722
 		$encoding = null;
5679 6723
 		$fetchAsBinary = true;
5680
-		if ($_mimetype && strtolower($_mimetype)=='message/rfc822') $fetchAsBinary = false;
6724
+		if ($_mimetype && strtolower($_mimetype)=='message/rfc822')
6725
+		{
6726
+			$fetchAsBinary = false;
6727
+		}
5681 6728
 		// we need to set content on structure to decode transfer encoding
5682 6729
 		$part->setContents(
5683 6730
 			$this->getBodyPart($_uid, $part->getMimeId(), null, $_preserveSeen, $_stream, $encoding, $fetchAsBinary),
@@ -5714,7 +6761,10 @@  discard block
 block discarded – undo
5714 6761
 		// the recent flag is the default enforced here ; as we assume the _flags is always set,
5715 6762
 		// we default it to hordes default (Recent) (, other wise we should not pass the parameter
5716 6763
 		// for flags at all)
5717
-		if (empty($_flags)) $_flags = '\\Recent';
6764
+		if (empty($_flags))
6765
+		{
6766
+			$_flags = '\\Recent';
6767
+		}
5718 6768
 		//if (!is_array($_flags) && stripos($_flags,',')!==false) $_flags=explode(',',$_flags);
5719 6769
 		//if (!is_array($_flags)) $_flags = (array) $_flags;
5720 6770
 		try
@@ -5731,18 +6781,27 @@  discard block
 block discarded – undo
5731 6781
 		}
5732 6782
 		catch (Exception $e)
5733 6783
 		{
5734
-			if (self::$debug) error_log("Could not append Message: ".$e->getMessage());
6784
+			if (self::$debug)
6785
+			{
6786
+				error_log("Could not append Message: ".$e->getMessage());
6787
+			}
5735 6788
 			throw new egw_exception_wrong_userinput(lang("Could not append Message:").' '.$e->getMessage().': '.$e->details);
5736 6789
 			//return false;
5737 6790
 		}
5738 6791
 		//error_log(__METHOD__.' ('.__LINE__.') '.' appended UID:'.$messageid);
5739 6792
 		//$messageid = true; // for debug reasons only
5740
-		if ($messageid === true || empty($messageid)) // try to figure out the message uid
6793
+		if ($messageid === true || empty($messageid))
6794
+		{
6795
+			// try to figure out the message uid
5741 6796
 		{
5742 6797
 			$list = $this->getHeaders($_folderName, $_startMessage=1, 1, 'INTERNALDATE', true, array(),null, false);
6798
+		}
5743 6799
 			if ($list)
5744 6800
 			{
5745
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
6801
+				if (self::$debug)
6802
+				{
6803
+					error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
6804
+				}
5746 6805
 				$messageid = $list['header'][0]['uid'];
5747 6806
 			}
5748 6807
 		}
@@ -5783,7 +6842,10 @@  discard block
 block discarded – undo
5783 6842
 	{
5784 6843
 			//echo __METHOD__." called for $uid,$partid <br>";
5785 6844
 			$headers = $mailClass->getMessageHeader($uid,$partid,true,false,$mailbox);
5786
-			if (empty($headers)) return false;
6845
+			if (empty($headers))
6846
+			{
6847
+				return false;
6848
+			}
5787 6849
 			// dont force retrieval of the textpart, let mailClass preferences decide
5788 6850
 			$bodyParts = $mailClass->getMessageBody($uid,($preserveHTML?'always_display':'only_if_no_text'),$partid,null,false,$mailbox);
5789 6851
 			// if we do not want HTML but there is no TextRepresentation with the message itself, try converting
@@ -5801,15 +6863,30 @@  discard block
 block discarded – undo
5801 6863
 			//error_log(array2string($bodyParts));
5802 6864
 			$attachments = $includeAttachments?$mailClass->getMessageAttachments($uid,$partid,null,true,false,true,$mailbox):array();
5803 6865
 
5804
-			if ($mailClass->isSentFolder($mailbox)) $mailaddress = $headers['TO'];
5805
-			elseif (isset($headers['FROM'])) $mailaddress = $headers['FROM'];
5806
-			elseif (isset($headers['SENDER'])) $mailaddress = $headers['SENDER'];
5807
-			if (isset($headers['CC'])) $mailaddress .= ','.$headers['CC'];
6866
+			if ($mailClass->isSentFolder($mailbox))
6867
+			{
6868
+				$mailaddress = $headers['TO'];
6869
+			}
6870
+			elseif (isset($headers['FROM']))
6871
+			{
6872
+				$mailaddress = $headers['FROM'];
6873
+			}
6874
+			elseif (isset($headers['SENDER']))
6875
+			{
6876
+				$mailaddress = $headers['SENDER'];
6877
+			}
6878
+			if (isset($headers['CC']))
6879
+			{
6880
+				$mailaddress .= ','.$headers['CC'];
6881
+			}
5808 6882
 			//_debug_array(array($headers,$mailaddress));
5809 6883
 			$subject = $headers['SUBJECT'];
5810 6884
 
5811 6885
 			$message = self::getdisplayableBody($mailClass, $bodyParts, $preserveHTML);
5812
-			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain') $message = '<pre>'.$message.'</pre>';
6886
+			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain')
6887
+			{
6888
+				$message = '<pre>'.$message.'</pre>';
6889
+			}
5813 6890
 			$headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '',$preserveHTML) : '');
5814 6891
 			$message = $headdata.$message;
5815 6892
 			//echo __METHOD__.'<br>';
@@ -5860,7 +6937,8 @@  discard block
 block discarded – undo
5860 6937
 							$attachments[$num]['attachment'] = $c->getContents();
5861 6938
 						}
5862 6939
 						// no attempt to convert, if we dont know about the charset
5863
-						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset'])) {
6940
+						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset']))
6941
+						{
5864 6942
 							// we do not try guessing the charset, if it is not set
5865 6943
 							//if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = translation::detect_encoding($attachments[$num]['attachment']);
5866 6944
 							translation::convert($attachments[$num]['attachment'],$attachments[$num]['charset']);
@@ -5881,7 +6959,10 @@  discard block
 block discarded – undo
5881 6959
 						unset($attachments[$num]['attachment']);
5882 6960
 					}
5883 6961
 				}
5884
-				if (is_array($attachedMessages)) $attachments = array_merge($attachments,$attachedMessages);
6962
+				if (is_array($attachedMessages))
6963
+				{
6964
+					$attachments = array_merge($attachments,$attachedMessages);
6965
+				}
5885 6966
 			}
5886 6967
 			return array(
5887 6968
 					'mailaddress'=>$mailaddress,
@@ -5903,10 +6984,17 @@  discard block
 block discarded – undo
5903 6984
 	{
5904 6985
 		$c = 0;
5905 6986
 		// use the standardIdentity
5906
-		foreach($_identities as $key => $acc) {
5907
-			if ($c==0) $identity = $acc;
6987
+		foreach($_identities as $key => $acc)
6988
+		{
6989
+			if ($c==0)
6990
+			{
6991
+				$identity = $acc;
6992
+			}
5908 6993
 			//error_log(__METHOD__.__LINE__." $key == $_profile_id ");
5909
-			if ($key==$_profile_id) $identity = $acc;
6994
+			if ($key==$_profile_id)
6995
+			{
6996
+				$identity = $acc;
6997
+			}
5910 6998
 			$c++;
5911 6999
 		}
5912 7000
 		return $identity;
@@ -5922,20 +7010,53 @@  discard block
 block discarded – undo
5922 7010
 	{
5923 7011
 		$headdata = null;
5924 7012
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($header).function_backtrace());
5925
-		if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
5926
-		if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
5927
-		if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
5928
-		if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
5929
-		if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
5930
-		if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
5931
-		if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
5932
-		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
5933
-		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
7013
+		if ($header['SUBJECT'])
7014
+		{
7015
+			$headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
7016
+		}
7017
+		if ($header['FROM'])
7018
+		{
7019
+			$headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
7020
+		}
7021
+		if ($header['SENDER'])
7022
+		{
7023
+			$headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
7024
+		}
7025
+		if ($header['TO'])
7026
+		{
7027
+			$headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
7028
+		}
7029
+		if ($header['CC'])
7030
+		{
7031
+			$headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
7032
+		}
7033
+		if ($header['BCC'])
7034
+		{
7035
+			$headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
7036
+		}
7037
+		if ($header['DATE'])
7038
+		{
7039
+			$headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
7040
+		}
7041
+		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal')
7042
+		{
7043
+			$headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
7044
+		}
7045
+		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal')
7046
+		{
7047
+			$headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
7048
+		}
5934 7049
 		//if ($mailcontent['headers']['ORGANIZATION']) $headdata .= lang('organization').': '.$mailcontent['headers']['ORGANIZATION']."\
5935 7050
 		if (!empty($headdata))
5936 7051
 		{
5937
-			if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
5938
-			if (empty($headline)) $headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
7052
+			if (!empty($headline) && $headline != 'SUPPRESS')
7053
+			{
7054
+				$headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
7055
+			}
7056
+			if (empty($headline))
7057
+			{
7058
+				$headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
7059
+			}
5939 7060
 			$headdata .= ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'');
5940 7061
 		}
5941 7062
 		else
@@ -5969,12 +7090,15 @@  discard block
 block discarded – undo
5969 7090
 		$returnAddr ='';
5970 7091
 		if (is_array($rfcAddressArray))
5971 7092
 		{
5972
-			foreach((array)$rfcAddressArray as $addressData) {
7093
+			foreach((array)$rfcAddressArray as $addressData)
7094
+			{
5973 7095
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressData));
5974
-				if($addressData['MAILBOX_NAME'] == 'NIL') {
7096
+				if($addressData['MAILBOX_NAME'] == 'NIL')
7097
+				{
5975 7098
 					continue;
5976 7099
 				}
5977
-				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') {
7100
+				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients')
7101
+				{
5978 7102
 					continue;
5979 7103
 				}
5980 7104
 				if ($addressData['RFC822_EMAIL'])
@@ -5988,7 +7112,10 @@  discard block
 block discarded – undo
5988 7112
 				}
5989 7113
 				$addressObject = $addressObjectA[0];
5990 7114
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressObject));
5991
-				if (!$addressObject->valid) continue;
7115
+				if (!$addressObject->valid)
7116
+				{
7117
+					continue;
7118
+				}
5992 7119
 				//$mb =(string)$addressObject->mailbox;
5993 7120
 				//$h = (string)$addressObject->host;
5994 7121
 				//$p = (string)$addressObject->personal;
@@ -6005,7 +7132,10 @@  discard block
 block discarded – undo
6005 7132
 			// do not mess with strings, return them untouched /* ToDo: validate string as Address */
6006 7133
 			$rfcAddressArray = self::decode_header($rfcAddressArray,true);
6007 7134
 			$rfcAddressArray = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$rfcAddressArray);
6008
-			if (is_string($rfcAddressArray)) return $rfcAddressArray;
7135
+			if (is_string($rfcAddressArray))
7136
+			{
7137
+				return $rfcAddressArray;
7138
+			}
6009 7139
 		}
6010 7140
 		return $returnAddr;
6011 7141
 	}
@@ -6022,10 +7152,19 @@  discard block
 block discarded – undo
6022 7152
 	{
6023 7153
 		$mergeobj = new addressbook_merge();
6024 7154
 
6025
-		if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
7155
+		if (empty($mimetype))
7156
+		{
7157
+			$mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
7158
+		}
6026 7159
 		$rv = $mergeobj->merge_string($content,$ids,$err='',$mimetype, array(), self::$displayCharset);
6027
-		if (empty($rv) && !empty($content) && !empty($err)) $rv = $content;
6028
-		if (!empty($err) && !empty($content) && !empty($ids)) error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
7160
+		if (empty($rv) && !empty($content) && !empty($err))
7161
+		{
7162
+			$rv = $content;
7163
+		}
7164
+		if (!empty($err) && !empty($content) && !empty($ids))
7165
+		{
7166
+			error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
7167
+		}
6029 7168
 		return $rv;
6030 7169
 	}
6031 7170
 
@@ -6062,13 +7201,15 @@  discard block
 block discarded – undo
6062 7201
 			settype($bytes, 'integer');
6063 7202
 			$bytes /= 10;
6064 7203
 		}
6065
-		else
6066
-			settype($bytes, 'integer');
7204
+		else {
7205
+					settype($bytes, 'integer');
7206
+		}
6067 7207
 
6068 7208
 		return $bytes . ' ' . $type ;
6069 7209
 	}
6070 7210
 
6071
-	static function detect_qp(&$sting) {
7211
+	static function detect_qp(&$sting)
7212
+	{
6072 7213
 		$needle = '/(=[0-9][A-F])|(=[A-F][0-9])|(=[A-F][A-F])|(=[0-9][0-9])/';
6073 7214
 		return preg_match("$needle",$string);
6074 7215
 	}
@@ -6085,9 +7226,15 @@  discard block
 block discarded – undo
6085 7226
 	 */
6086 7227
 	static function logRunTimes($_starttime,$_endtime=null,$_message='',$_methodNline='')
6087 7228
 	{
6088
-		if (is_null($_endtime)) $_endtime = microtime(true);
7229
+		if (is_null($_endtime))
7230
+		{
7231
+			$_endtime = microtime(true);
7232
+		}
6089 7233
 		$usagetime = microtime(true) - $_starttime;
6090
-		if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
7234
+		if (self::$debugTimes)
7235
+		{
7236
+			error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
7237
+		}
6091 7238
 	}
6092 7239
 
6093 7240
 	/**
@@ -6102,7 +7249,10 @@  discard block
 block discarded – undo
6102 7249
 	 */
6103 7250
 	static function checkFileBasics(&$_formData, $IDtoAddToFileName='', $reqMimeType='message/rfc822')
6104 7251
 	{
6105
-		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data') return $_formData['file'];
7252
+		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data')
7253
+		{
7254
+			return $_formData['file'];
7255
+		}
6106 7256
 
6107 7257
 		//error_log(__METHOD__.__FILE__.array2string($_formData).' Id:'.$IDtoAddToFileName.' ReqMimeType:'.$reqMimeType);
6108 7258
 		$importfailed = $tmpFileName = false;
@@ -6151,8 +7301,15 @@  discard block
 block discarded – undo
6151 7301
 			{
6152 7302
 				$buff = explode('.',$_formData['name']);
6153 7303
 				$suffix = '';
6154
-				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
6155
-				if (!empty($suffix)) $sfxMimeType = mime_magic::ext2mime($suffix);
7304
+				if (is_array($buff))
7305
+				{
7306
+					$suffix = array_pop($buff);
7307
+				}
7308
+				// take the last extension to check with ext2mime
7309
+				if (!empty($suffix))
7310
+				{
7311
+					$sfxMimeType = mime_magic::ext2mime($suffix);
7312
+				}
6156 7313
 				if (!empty($suffix) && !empty($sfxMimeType) &&
6157 7314
 					(strlen(trim($_formData['type']))==0 || (strtolower(trim($_formData['type'])) != $sfxMimeType)))
6158 7315
 				{
@@ -6200,7 +7357,9 @@  discard block
 block discarded – undo
6200 7357
 			{
6201 7358
 				rename($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].SEP.$tmpFileName);
6202 7359
 			}
6203
-		} else {
7360
+		}
7361
+		else
7362
+		{
6204 7363
 			//error_log("Import of message ".$_formData['file']." failes to meet basic restrictions");
6205 7364
 			$importfailed = true;
6206 7365
 			$alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.",$_formData['name']);
@@ -6246,21 +7405,32 @@  discard block
 block discarded – undo
6246 7405
 				if (substr($url, 0, 5) !== 'data:')
6247 7406
 				{
6248 7407
 					$filename = basename($url);
6249
-					if (($directory = dirname($url)) == '.') $directory = '';
7408
+					if (($directory = dirname($url)) == '.')
7409
+					{
7410
+						$directory = '';
7411
+					}
6250 7412
 					$ext = pathinfo($filename, PATHINFO_EXTENSION);
6251 7413
 					$mimeType  = mime_magic::ext2mime($ext);
6252
-					if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
7414
+					if ( strlen($directory) > 1 && substr($directory,-1) != '/')
7415
+					{
7416
+$directory .= '/'; }
6253 7417
 					$myUrl = $directory.$filename;
6254
-					if ($myUrl[0]=='/') // local path -> we only allow path's that are available via http/https (or vfs)
7418
+					if ($myUrl[0]=='/')
7419
+					{
7420
+						// local path -> we only allow path's that are available via http/https (or vfs)
6255 7421
 					{
6256 7422
 						$basedir = ($_SERVER['HTTPS']?'https://':'http://'.$_SERVER['HTTP_HOST']);
6257 7423
 					}
7424
+					}
6258 7425
 					// use vfs instead of url containing webdav.php
6259 7426
 					// ToDo: we should test if the webdav url is of our own scope, as we cannot handle foreign
6260 7427
 					// webdav.php urls as vfs
6261
-					if (strpos($myUrl,'/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it.
7428
+					if (strpos($myUrl,'/webdav.php') !== false)
7429
+					{
7430
+						// we have a webdav link, so we build a vfs/sqlfs link of it.
6262 7431
 					{
6263 7432
 						egw_vfs::load_wrapper('vfs');
7433
+					}
6264 7434
 						list(,$myUrl) = explode('/webdav.php',$myUrl,2);
6265 7435
 						$basedir = 'vfs://default';
6266 7436
 						$needTempFile = false;
@@ -6289,8 +7459,13 @@  discard block
 block discarded – undo
6289 7459
 						}
6290 7460
 					}
6291 7461
 
6292
-					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/') { $basedir .= '/'; }
6293
-					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl));
7462
+					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/')
7463
+					{
7464
+$basedir .= '/'; }
7465
+					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http")
7466
+					{
7467
+						$data = file_get_contents($basedir.urldecode($myUrl));
7468
+					}
6294 7469
 				}
6295 7470
 				if (substr($url,0,strlen('data:'))=='data:')
6296 7471
 				{
@@ -6391,7 +7566,10 @@  discard block
 block discarded – undo
6391 7566
 				$_folder = $this->getSentFolder();
6392 7567
 			}
6393 7568
 			$delimiter = $this->getHierarchyDelimiter();
6394
-			if($_folder=='INBOX'.$delimiter) $_folder='INBOX';
7569
+			if($_folder=='INBOX'.$delimiter)
7570
+			{
7571
+				$_folder='INBOX';
7572
+			}
6395 7573
 			if ($importfailed === false)
6396 7574
 			{
6397 7575
 				$Subject = $mailObject->getHeader('Subject');
@@ -6420,7 +7598,9 @@  discard block
 block discarded – undo
6420 7598
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Id To Merge:'.$val);
6421 7599
 					if (/*$GLOBALS['egw_info']['flags']['currentapp'] == 'addressbook' &&*/
6422 7600
 						count($SendAndMergeTocontacts) > 1 && $val &&
6423
-						(is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))) // do the merge
7601
+						(is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)))
7602
+					{
7603
+						// do the merge
6424 7604
 					{
6425 7605
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6426 7606
 
@@ -6429,6 +7609,7 @@  discard block
 block discarded – undo
6429 7609
 						{
6430 7610
 							//error_log('ID ' . $val . ' ' .$type . ': ' . $mailObject->getHeader(egw_mailer::$type2header[$type]) . ' -> ' .$bo_merge->merge_string($mailObject->getHeader(egw_mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset));
6431 7611
 							$merged = $bo_merge->merge_string($mailObject->getHeader(egw_mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset);
7612
+					}
6432 7613
 							$mailObject->addAddress($merged,'',$type);
6433 7614
 							if($type == 'to')
6434 7615
 							{
@@ -6460,9 +7641,15 @@  discard block
 block discarded – undo
6460 7641
 						$mailObject->clearCustomHeaders();
6461 7642
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6462 7643
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6463
-						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));
7644
+						if($text_body)
7645
+						{
7646
+							$text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7647
+						}
6464 7648
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6465
-						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));
7649
+						if($html_body)
7650
+						{
7651
+							$html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7652
+						}
6466 7653
 
6467 7654
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6468 7655
 						// set a higher timeout for big messages
@@ -6477,9 +7664,12 @@  discard block
 block discarded – undo
6477 7664
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($errorInfo));
6478 7665
 						}
6479 7666
 					}
6480
-					elseif (!$k)	// 1. entry, further entries will fail for apps other then addressbook
7667
+					elseif (!$k)
7668
+					{
7669
+						// 1. entry, further entries will fail for apps other then addressbook
6481 7670
 					{
6482 7671
 						$openAsDraft = true;
7672
+					}
6483 7673
 						$mailObject->removeHeader('Message-ID');
6484 7674
 						$mailObject->removeHeader('Date');
6485 7675
 						$mailObject->clearCustomHeaders();
@@ -6493,9 +7683,12 @@  discard block
 block discarded – undo
6493 7683
 
6494 7684
 						// No addresses from placeholders?  Treat it as just a contact ID
6495 7685
 						if (count($mailObject->getAddresses('to',true)) == 0 &&
6496
-							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)) // do the merge
7686
+							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))
7687
+						{
7688
+							// do the merge
6497 7689
 						{
6498 7690
 							$contact = $bo_merge->contacts->read($val);
7691
+						}
6499 7692
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($contact));
6500 7693
 							$email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
6501 7694
 							$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
@@ -6506,9 +7699,15 @@  discard block
 block discarded – undo
6506 7699
 						}
6507 7700
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6508 7701
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6509
-						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));
7702
+						if (!empty($Body))
7703
+						{
7704
+							$text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7705
+						}
6510 7706
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6511
-						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));
7707
+						if (!empty($AltBody))
7708
+						{
7709
+							$html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7710
+						}
6512 7711
 						$_folder = $this->getDraftFolder();
6513 7712
 					}
6514 7713
 					if ($sendOK || $openAsDraft)
@@ -6516,11 +7715,15 @@  discard block
 block discarded – undo
6516 7715
 						if ($this->folderExists($_folder,true))
6517 7716
 						{
6518 7717
 						    if($this->isSentFolder($_folder))
6519
-							{
7718
+						    {
6520 7719
 						        $flags = '\\Seen';
6521
-						    } elseif($this->isDraftFolder($_folder)) {
7720
+						    }
7721
+						    elseif($this->isDraftFolder($_folder))
7722
+						    {
6522 7723
 						        $flags = '\\Draft';
6523
-						    } else {
7724
+						    }
7725
+						    else
7726
+						    {
6524 7727
 						        $flags = '';
6525 7728
 						    }
6526 7729
 							$savefailed = false;
@@ -6554,7 +7757,10 @@  discard block
 block discarded – undo
6554 7757
 						}
6555 7758
 						else
6556 7759
 						{
6557
-							if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
7760
+							if (!$openComposeWindow)
7761
+							{
7762
+								$processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
7763
+							}
6558 7764
 						}
6559 7765
 					}
6560 7766
 					if (!is_null($sendOK) && $sendOK===false && is_null($openComposeWindow))
@@ -6602,7 +7808,10 @@  discard block
 block discarded – undo
6602 7808
 				$tmpFileName = $GLOBALS['egw_info']['server']['temp_dir'].SEP.basename($tmpFileName);
6603 7809
 				break;
6604 7810
 		}
6605
-		if (!isset($message)) $message = fopen($tmpFileName, 'r');
7811
+		if (!isset($message))
7812
+		{
7813
+			$message = fopen($tmpFileName, 'r');
7814
+		}
6606 7815
 
6607 7816
 		if (!$message)
6608 7817
 		{
@@ -6633,7 +7842,10 @@  discard block
 block discarded – undo
6633 7842
 				(fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192));
6634 7843
 
6635 7844
 			$length = strpos($start, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
6636
-			if ($length===false) $length = strlen($start);
7845
+			if ($length===false)
7846
+			{
7847
+				$length = strlen($start);
7848
+			}
6637 7849
 			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0,$length));
6638 7850
 
6639 7851
 			foreach($headers->toArray(array('nowrap' => true)) as $header => $value)
@@ -6662,7 +7874,10 @@  discard block
 block discarded – undo
6662 7874
 		}
6663 7875
 		else
6664 7876
 		{
6665
-			if (($type = gettype($message)) == 'object') $type = get_class ($message);
7877
+			if (($type = gettype($message)) == 'object')
7878
+			{
7879
+				$type = get_class ($message);
7880
+			}
6666 7881
 			throw new egw_exception_wrong_parameter('Wrong parameter type for message: '.$type);
6667 7882
 		}
6668 7883
 	}
@@ -6686,7 +7901,9 @@  discard block
 block discarded – undo
6686 7901
 			$matches = array();
6687 7902
 			preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/",$addresses,$matches);
6688 7903
 			//error_log(__METHOD__.__LINE__.array2string($matches));
6689
-			foreach ($matches[0] as &$match) {$match = trim($match,', ');}
7904
+			foreach ($matches[0] as &$match)
7905
+			{
7906
+$match = trim($match,', ');}
6690 7907
 			$addresses = implode(',',$matches[0]);
6691 7908
 			//error_log(__METHOD__.__LINE__.array2string($addresses));
6692 7909
 			$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
@@ -6717,7 +7934,10 @@  discard block
 block discarded – undo
6717 7934
 			}
6718 7935
 			else
6719 7936
 			{
6720
-				if ($previousFailed && $remember) $adr->personal = $remember. ' ' . $adr->personal;
7937
+				if ($previousFailed && $remember)
7938
+				{
7939
+					$adr->personal = $remember. ' ' . $adr->personal;
7940
+				}
6721 7941
 				$remember = '';
6722 7942
 				$previousFailed=false;
6723 7943
 				//error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal");
@@ -6739,7 +7959,10 @@  discard block
 block discarded – undo
6739 7959
 	{
6740 7960
 		$acc = emailadmin_account::read($this->profileID);
6741 7961
 		$identity = emailadmin_account::read_identity($acc['ident_id'], true, null, $acc);
6742
-		if (self::$debug) error_log(__METHOD__.__LINE__.array2string($identity));
7962
+		if (self::$debug)
7963
+		{
7964
+			error_log(__METHOD__.__LINE__.array2string($identity));
7965
+		}
6743 7966
 		$headers = $this->getMessageHeader($uid, '', 'object', true, $_folder);
6744 7967
 
6745 7968
 		$mdn = new Horde_Mime_Mdn($headers);
Please login to merge, or discard this patch.
Spacing   +1066 added lines, -1067 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	 *
95 95
 	 * @array
96 96
 	 */
97
-	static $tidy_config = array('clean'=>false,'output-html'=>true,'join-classes'=>true,'join-styles'=>true,'show-body-only'=>"auto",'word-2000'=>true,'wrap'=>0);
97
+	static $tidy_config = array('clean'=>false, 'output-html'=>true, 'join-classes'=>true, 'join-styles'=>true, 'show-body-only'=>"auto", 'word-2000'=>true, 'wrap'=>0);
98 98
 
99 99
 	/**
100 100
 	 * static used to configure htmLawed, for use with emails
@@ -104,9 +104,9 @@  discard block
 block discarded – undo
104 104
 	static $htmLawed_config = array('comment'=>1, //remove comments
105 105
 		'make_tag_strict' => 3, // 3 is a new own config value, to indicate that transformation is to be performed, but don't transform font as size transformation of numeric sizes to keywords alters the intended result too much
106 106
 		'keep_bad'=>2, //remove tags but keep element content (4 and 6 keep element content only if text (pcdata) is valid in parent element as per specs, this may lead to textloss if balance is switched on)
107
-		'balance'=>1,//turn off tag-balancing (config['balance']=>0). That will not introduce any security risk; only standards-compliant tag nesting check/filtering will be turned off (basic tag-balance will remain; i.e., there won't be any unclosed tag, etc., after filtering)
107
+		'balance'=>1, //turn off tag-balancing (config['balance']=>0). That will not introduce any security risk; only standards-compliant tag nesting check/filtering will be turned off (basic tag-balance will remain; i.e., there won't be any unclosed tag, etc., after filtering)
108 108
 		'direct_list_nest' => 1,
109
-		'allow_for_inline' => array('table','div','li','p'),//block elements allowed for nesting when only inline is allowed; Example span does not allow block elements as table; table is the only element tested so far
109
+		'allow_for_inline' => array('table', 'div', 'li', 'p'), //block elements allowed for nesting when only inline is allowed; Example span does not allow block elements as table; table is the only element tested so far
110 110
 		// tidy eats away even some wanted whitespace, so we switch it off;
111 111
 		// we used it for its compacting and beautifying capabilities, which resulted in better html for further processing
112 112
 		'tidy'=>0,
@@ -121,13 +121,13 @@  discard block
 block discarded – undo
121 121
 	 *
122 122
 	 * @array
123 123
 	 */
124
-	static $aclShortCuts = array('' => array('label'=>'none','title'=>'The user has no rights whatsoever.'),
125
-		'lrs'		=> array('label'=>'readable','title'=>'Allows a user to read the contents of the mailbox.'),
126
-		'lprs'		=> array('label'=>'post','title'=>'Allows a user to read the mailbox and post to it through the delivery system by sending mail to the submission address of the mailbox.'),
127
-		'ilprs'		=> array('label'=>'append','title'=>'Allows a user to read the mailbox and append messages to it, either via IMAP or through the delivery system.'),
128
-		'cdilprsw'	=> array('label'=>'write','title'=>'Allows a user to read the maibox, post to it, append messages to it, and delete messages or the mailbox itself. The only right not given is the right to change the ACL of the mailbox.'),
129
-		'acdilprsw'	=> array('label'=>'all','title'=>'The user has all possible rights on the mailbox. This is usually granted to users only on the mailboxes they own.'),
130
-		'custom'	=> array('label'=>'custom','title'=>'User defined combination of rights for the ACL'),
124
+	static $aclShortCuts = array('' => array('label'=>'none', 'title'=>'The user has no rights whatsoever.'),
125
+		'lrs'		=> array('label'=>'readable', 'title'=>'Allows a user to read the contents of the mailbox.'),
126
+		'lprs'		=> array('label'=>'post', 'title'=>'Allows a user to read the mailbox and post to it through the delivery system by sending mail to the submission address of the mailbox.'),
127
+		'ilprs'		=> array('label'=>'append', 'title'=>'Allows a user to read the mailbox and append messages to it, either via IMAP or through the delivery system.'),
128
+		'cdilprsw'	=> array('label'=>'write', 'title'=>'Allows a user to read the maibox, post to it, append messages to it, and delete messages or the mailbox itself. The only right not given is the right to change the ACL of the mailbox.'),
129
+		'acdilprsw'	=> array('label'=>'all', 'title'=>'The user has all possible rights on the mailbox. This is usually granted to users only on the mailboxes they own.'),
130
+		'custom'	=> array('label'=>'custom', 'title'=>'User defined combination of rights for the ACL'),
131 131
 	);
132 132
 
133 133
 	/**
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 	 * @param boolean $_reuseCache = null if null it is set to the value of $_restoreSession
176 176
 	 * @return emailadmin_imapbase
177 177
 	 */
178
-	public static function getInstance($_restoreSession=true, &$_profileID=0, $_validate=true, $_oldImapServerObject=false, $_reuseCache=null)
178
+	public static function getInstance($_restoreSession = true, &$_profileID = 0, $_validate = true, $_oldImapServerObject = false, $_reuseCache = null)
179 179
 	{
180 180
 		//$_restoreSession=false;
181 181
 		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
@@ -185,13 +185,13 @@  discard block
 block discarded – undo
185 185
 		{
186 186
 			if (!is_object(self::$instances[$_profileID]))
187 187
 			{
188
-				self::$instances[$_profileID] = new emailadmin_imapbase('utf-8',false,$_profileID,false,$_reuseCache);
188
+				self::$instances[$_profileID] = new emailadmin_imapbase('utf-8', false, $_profileID, false, $_reuseCache);
189 189
 			}
190 190
 			self::$instances[$_profileID]->icServer = $_oldImapServerObject;
191
-			self::$instances[$_profileID]->accountid= $_oldImapServerObject->ImapServerId;
192
-			self::$instances[$_profileID]->profileID= $_oldImapServerObject->ImapServerId;
191
+			self::$instances[$_profileID]->accountid = $_oldImapServerObject->ImapServerId;
192
+			self::$instances[$_profileID]->profileID = $_oldImapServerObject->ImapServerId;
193 193
 			self::$instances[$_profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
194
-			self::$instances[$_profileID]->htmlOptions  = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
194
+			self::$instances[$_profileID]->htmlOptions = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
195 195
 			return self::$instances[$_profileID];
196 196
 		}
197 197
 		if ($_profileID == 0)
@@ -204,14 +204,14 @@  discard block
 block discarded – undo
204 204
 			{
205 205
 				$profileID = emailadmin_account::get_default_acc_id();
206 206
 			}
207
-			if ($profileID!=$_profileID) $_restoreSession==false;
208
-			$_profileID=$profileID;
207
+			if ($profileID != $_profileID) $_restoreSession == false;
208
+			$_profileID = $profileID;
209 209
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace());
210 210
 		}
211 211
 		// no validation or restoreSession for old ImapServer Object, just fetch it and return it
212
-		if ($_oldImapServerObject===true)
212
+		if ($_oldImapServerObject === true)
213 213
 		{
214
-			return new emailadmin_imapbase('utf-8',false,$_profileID,true,$_reuseCache);
214
+			return new emailadmin_imapbase('utf-8', false, $_profileID, true, $_reuseCache);
215 215
 		}
216 216
 		if ($_profileID != 0 && $_validate)
217 217
 		{
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
 			//egw_cache::setSession('mail','activeProfileID',$_profileID);
232 232
 		}
233 233
 		//error_log(__METHOD__.' ('.__LINE__.') '.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID.' called from:'.function_backtrace());
234
-		if ($_profileID && (!isset(self::$instances[$_profileID]) || $_restoreSession===false))
234
+		if ($_profileID && (!isset(self::$instances[$_profileID]) || $_restoreSession === false))
235 235
 		{
236
-			self::$instances[$_profileID] = new emailadmin_imapbase('utf-8',$_restoreSession,$_profileID,false,$_reuseCache);
236
+			self::$instances[$_profileID] = new emailadmin_imapbase('utf-8', $_restoreSession, $_profileID, false, $_reuseCache);
237 237
 		}
238 238
 		else
239 239
 		{
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 				self::$instances[$_profileID]->ogServer = emailadmin_account::read($_profileID)->smtpServer();
245 245
 				// TODO: merge mailprefs into userprefs, for easy treatment
246 246
 				self::$instances[$_profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
247
-				self::$instances[$_profileID]->htmlOptions  = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
247
+				self::$instances[$_profileID]->htmlOptions = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
248 248
 			} catch (egw_exception $e)
249 249
 			{
250 250
 				$newprofileID = emailadmin_account::get_default_acc_id();
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 				error_log(__METHOD__.' ('.__LINE__.') '." Loading the Profile for ProfileID ".$_profileID.' failed for icServer; '.$e->getMessage().' Trigger new instance for Default-Profile '.$newprofileID.'. called from:'.function_backtrace());
253 253
 				if ($newprofileID)
254 254
 				{
255
-					self::$instances[$newprofileID] = new emailadmin_imapbase('utf-8',false,$newprofileID,false,$_reuseCache);
255
+					self::$instances[$newprofileID] = new emailadmin_imapbase('utf-8', false, $newprofileID, false, $_reuseCache);
256 256
 					$_profileID = $newprofileID;
257 257
 				}
258 258
 				else
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 					throw $e;
261 261
 				}
262 262
 			}
263
-			self::storeActiveProfileIDToPref(self::$instances[$_profileID]->icServer, $_profileID, $_validate );
263
+			self::storeActiveProfileIDToPref(self::$instances[$_profileID]->icServer, $_profileID, $_validate);
264 264
 		}
265 265
 		self::$instances[$_profileID]->profileID = $_profileID;
266 266
 		if (!isset(self::$instances[$_profileID]->idna2)) self::$instances[$_profileID]->idna2 = new egw_idna;
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 	 * @param boolean $_testConnection = 0
277 277
 	 * @return mixed $_profileID or false on failed ConnectionTest
278 278
 	 */
279
-	public static function storeActiveProfileIDToPref($_icServerObject, $_profileID=0, $_testConnection=true)
279
+	public static function storeActiveProfileIDToPref($_icServerObject, $_profileID = 0, $_testConnection = true)
280 280
 	{
281 281
 		if (isset($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']) && !empty($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']))
282 282
 		{
@@ -297,12 +297,12 @@  discard block
 block discarded – undo
297 297
 		}
298 298
 		if ($oldProfileID != $_profileID)
299 299
 		{
300
-			if ($oldProfileID && $_profileID==0) $_profileID = $oldProfileID;
301
-			$GLOBALS['egw']->preferences->add('mail','ActiveProfileID',$_profileID,'user');
300
+			if ($oldProfileID && $_profileID == 0) $_profileID = $oldProfileID;
301
+			$GLOBALS['egw']->preferences->add('mail', 'ActiveProfileID', $_profileID, 'user');
302 302
 			// save prefs
303 303
 			$GLOBALS['egw']->preferences->save_repository(true);
304 304
 			$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $_profileID;
305
-			egw_cache::setSession('mail','activeProfileID',$_profileID);
305
+			egw_cache::setSession('mail', 'activeProfileID', $_profileID);
306 306
 		}
307 307
 		return $_profileID;
308 308
 	}
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 	 * @param int $_acc_id = 0
318 318
 	 * @return int validated acc_id -> either acc_id given, or first valid one
319 319
 	 */
320
-	public static function validateProfileID($_acc_id=0)
320
+	public static function validateProfileID($_acc_id = 0)
321 321
 	{
322 322
 		if ($_acc_id)
323 323
 		{
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 		}
337 337
 		// no account specified or specified account not found or not valid
338 338
 		// --> search existing account for first valid one and return that
339
-		foreach(emailadmin_account::search($only_current_user=true, 'acc_imap_host') as $acc_id => $imap_host)
339
+		foreach (emailadmin_account::search($only_current_user = true, 'acc_imap_host') as $acc_id => $imap_host)
340 340
 		{
341 341
 			if (!empty($imap_host) && ($account = emailadmin_account::read($acc_id)) && $account->is_imap())
342 342
 			{
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 	 * @param boolean $_oldImapServerObject = false
359 359
 	 * @param boolean $_reuseCache = null if null it is set to the value of $_restoreSession
360 360
 	 */
361
-	private function __construct($_displayCharset='utf-8',$_restoreSession=true, $_profileID=0, $_oldImapServerObject=false, $_reuseCache=null)
361
+	private function __construct($_displayCharset = 'utf-8', $_restoreSession = true, $_profileID = 0, $_oldImapServerObject = false, $_reuseCache = null)
362 362
 	{
363 363
 		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
364 364
 		if (!empty($_displayCharset)) self::$displayCharset = $_displayCharset;
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
 			$firstMessage = $this->sessionData['previewMessage'];
379 379
 			$this->sessionData = array();
380 380
 		}
381
-		if (!$_reuseCache) $this->forcePrefReload($_profileID,!$_reuseCache);
381
+		if (!$_reuseCache) $this->forcePrefReload($_profileID, !$_reuseCache);
382 382
 		try
383 383
 		{
384 384
 			$this->profileID = self::validateProfileID($_profileID);
@@ -389,14 +389,14 @@  discard block
 block discarded – undo
389 389
 		}
390 390
 		catch (Exception $e)
391 391
 		{
392
-			throw new egw_exception(__METHOD__." failed to instanciate emailadmin_imapbase for $_profileID / ".$this->profileID." with error:".$e->getMessage());;
392
+			throw new egw_exception(__METHOD__." failed to instanciate emailadmin_imapbase for $_profileID / ".$this->profileID." with error:".$e->getMessage()); ;
393 393
 		}
394 394
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($acc->imapServer()));
395
-		$this->icServer = ($_oldImapServerObject?$acc->oldImapServer():$acc->imapServer());
395
+		$this->icServer = ($_oldImapServerObject ? $acc->oldImapServer() : $acc->imapServer());
396 396
 		$this->ogServer = $acc->smtpServer();
397 397
 		// TODO: merge mailprefs into userprefs, for easy treatment
398 398
 		$this->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
399
-		$this->htmlOptions  = $this->mailPreferences['htmlOptions'];
399
+		$this->htmlOptions = $this->mailPreferences['htmlOptions'];
400 400
 		if (isset($this->icServer->ImapServerId) && !empty($this->icServer->ImapServerId))
401 401
 		{
402 402
 			$_profileID = $this->profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $this->icServer->ImapServerId;
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
 	public static function &forceEAProfileLoad($_profile_id)
416 416
 	{
417 417
 		self::unsetCachedObjects($_profile_id);
418
-		$mail = emailadmin_imapbase::getInstance(false, $_profile_id,false);
418
+		$mail = emailadmin_imapbase::getInstance(false, $_profile_id, false);
419 419
 		//_debug_array( $_profile_id);
420 420
 		$mail->icServer = emailadmin_account::read($_profile_id)->imapServer();
421 421
 		$mail->ogServer = emailadmin_account::read($_profile_id)->smtpServer();
@@ -427,11 +427,11 @@  discard block
 block discarded – undo
427 427
 	 * @param int $_profile_id
428 428
 	 * @param boolean $_resetFolderObjects
429 429
 	 */
430
-	public static function forcePrefReload($_profile_id=null,$_resetFolderObjects=true)
430
+	public static function forcePrefReload($_profile_id = null, $_resetFolderObjects = true)
431 431
 	{
432 432
 		// unset the mail_preferences session object, to force the reload/rebuild
433
-		$GLOBALS['egw']->session->appsession('mail_preferences','mail',serialize(array()));
434
-		$GLOBALS['egw']->session->appsession('session_data','emailadmin',serialize(array()));
433
+		$GLOBALS['egw']->session->appsession('mail_preferences', 'mail', serialize(array()));
434
+		$GLOBALS['egw']->session->appsession('session_data', 'emailadmin', serialize(array()));
435 435
 		if ($_resetFolderObjects) emailadmin_imapbase::resetFolderObjectCache($_profile_id);
436 436
 	}
437 437
 
@@ -440,8 +440,8 @@  discard block
 block discarded – undo
440 440
 	 */
441 441
 	function restoreSessionData()
442 442
 	{
443
-		$this->sessionData = array();//egw_cache::getCache(egw_cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1);
444
-		self::$activeFolderCache = egw_cache::getCache(egw_cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
443
+		$this->sessionData = array(); //egw_cache::getCache(egw_cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1);
444
+		self::$activeFolderCache = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 10);
445 445
 		if (!empty(self::$activeFolderCache[$this->profileID])) $this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID];
446 446
 	}
447 447
 
@@ -451,10 +451,10 @@  discard block
 block discarded – undo
451 451
 	function saveSessionData()
452 452
 	{
453 453
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($this->sessionData)));
454
-		if (!empty($this->sessionData['mailbox'])) self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox'];
454
+		if (!empty($this->sessionData['mailbox'])) self::$activeFolderCache[$this->profileID] = $this->sessionData['mailbox'];
455 455
 		if (isset(self::$activeFolderCache) && is_array(self::$activeFolderCache))
456 456
 		{
457
-			egw_cache::setCache(egw_cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),self::$activeFolderCache, 60*60*10);
457
+			egw_cache::setCache(egw_cache::INSTANCE, 'email', 'activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']), self::$activeFolderCache, 60 * 60 * 10);
458 458
 		}
459 459
 	}
460 460
 
@@ -470,40 +470,40 @@  discard block
 block discarded – undo
470 470
 	 * @param int $_profileID = null default profile of user as returned by getUserDefaultProfileID
471 471
 	 * @return void
472 472
 	 */
473
-	static function unsetCachedObjects($_profileID=null)
473
+	static function unsetCachedObjects($_profileID = null)
474 474
 	{
475 475
 		if (is_null($_profileID)) $_profileID = emailadmin_account::get_default_acc_id();
476 476
 		if (is_array($_profileID) && $_profileID['account_id']) $account_id = $_profileID['account_id'];
477 477
 		//error_log(__METHOD__.__LINE__.' called with ProfileID:'.array2string($_profileID).' from '.function_backtrace());
478
-		if (!is_array($_profileID) && (is_numeric($_profileID) || !(stripos($_profileID,'tracker_')===false)))
478
+		if (!is_array($_profileID) && (is_numeric($_profileID) || !(stripos($_profileID, 'tracker_') === false)))
479 479
 		{
480 480
 			self::resetConnectionErrorCache($_profileID);
481
-			$rawHeadersCache = egw_cache::getCache(egw_cache::INSTANCE,'email','rawHeadersCache'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*1);
481
+			$rawHeadersCache = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'rawHeadersCache'.trim($account_id), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 1);
482 482
 			if (isset($rawHeadersCache[$_profileID]))
483 483
 			{
484 484
 				unset($rawHeadersCache[$_profileID]);
485
-				egw_cache::setCache(egw_cache::INSTANCE,'email','rawHeadersCache'.trim($account_id),$rawHeadersCache, $expiration=60*60*1);
485
+				egw_cache::setCache(egw_cache::INSTANCE, 'email', 'rawHeadersCache'.trim($account_id), $rawHeadersCache, $expiration = 60 * 60 * 1);
486 486
 			}
487
-			$HierarchyDelimiterCache = egw_cache::getCache(egw_cache::INSTANCE,'email','HierarchyDelimiter'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*24*5);
487
+			$HierarchyDelimiterCache = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($account_id), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 24 * 5);
488 488
 			if (isset($HierarchyDelimiterCache[$_profileID]))
489 489
 			{
490 490
 				unset($HierarchyDelimiterCache[$_profileID]);
491
-				egw_cache::setCache(egw_cache::INSTANCE,'email','HierarchyDelimiter'.trim($account_id),$HierarchyDelimiterCache, $expiration=60*60*24*5);
491
+				egw_cache::setCache(egw_cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($account_id), $HierarchyDelimiterCache, $expiration = 60 * 60 * 24 * 5);
492 492
 			}
493 493
 			//reset folderObject cache, to trigger reload
494 494
 			self::resetFolderObjectCache($_profileID);
495 495
 			//reset counter of deleted messages per folder
496
-			$eMailListContainsDeletedMessages = egw_cache::getCache(egw_cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*1);
496
+			$eMailListContainsDeletedMessages = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($account_id), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 1);
497 497
 			if (isset($eMailListContainsDeletedMessages[$_profileID]))
498 498
 			{
499 499
 				unset($eMailListContainsDeletedMessages[$_profileID]);
500
-				egw_cache::setCache(egw_cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($account_id),$eMailListContainsDeletedMessages, $expiration=60*60*1);
500
+				egw_cache::setCache(egw_cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($account_id), $eMailListContainsDeletedMessages, $expiration = 60 * 60 * 1);
501 501
 			}
502
-			$vacationCached = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'vacationNotice'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*24*1);
502
+			$vacationCached = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'vacationNotice'.trim($account_id), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 24 * 1);
503 503
 			if (isset($vacationCached[$_profileID]))
504 504
 			{
505 505
 				unset($vacationCached[$_profileID]);
506
-				egw_cache::setCache(egw_cache::INSTANCE,'email','vacationNotice'.trim($account_id),$vacationCached, $expiration=60*60*24*1);
506
+				egw_cache::setCache(egw_cache::INSTANCE, 'email', 'vacationNotice'.trim($account_id), $vacationCached, $expiration = 60 * 60 * 24 * 1);
507 507
 			}
508 508
 
509 509
 			if (isset(self::$instances[$_profileID])) unset(self::$instances[$_profileID]);
@@ -511,17 +511,17 @@  discard block
 block discarded – undo
511 511
 		if (is_array($_profileID) && $_profileID['location'] == 'clear_cache')
512 512
 		{
513 513
 			// called via hook
514
-			foreach($GLOBALS['egw']->accounts->search(array('type' => 'accounts','order' => 'account_lid')) as $account)
514
+			foreach ($GLOBALS['egw']->accounts->search(array('type' => 'accounts', 'order' => 'account_lid')) as $account)
515 515
 			{
516 516
 				//error_log(__METHOD__.__LINE__.array2string($account));
517 517
 				$account_id = $account['account_id'];
518 518
 				$_profileID = null;
519
-				self::resetConnectionErrorCache($_profileID,$account_id);
520
-				self::resetFolderObjectCache($_profileID,$account_id);
521
-				egw_cache::setCache(egw_cache::INSTANCE,'email','rawHeadersCache'.trim($account_id),array(), 60*60*1);
522
-				egw_cache::setCache(egw_cache::INSTANCE,'email','HierarchyDelimiter'.trim($account_id),array(), 60*60*24*5);
523
-				egw_cache::setCache(egw_cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($account_id),array(), 60*60*1);
524
-				egw_cache::setCache(egw_cache::INSTANCE,'email','vacationNotice'.trim($account_id),array(), 60*60*24*1);
519
+				self::resetConnectionErrorCache($_profileID, $account_id);
520
+				self::resetFolderObjectCache($_profileID, $account_id);
521
+				egw_cache::setCache(egw_cache::INSTANCE, 'email', 'rawHeadersCache'.trim($account_id), array(), 60 * 60 * 1);
522
+				egw_cache::setCache(egw_cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($account_id), array(), 60 * 60 * 24 * 5);
523
+				egw_cache::setCache(egw_cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($account_id), array(), 60 * 60 * 1);
524
+				egw_cache::setCache(egw_cache::INSTANCE, 'email', 'vacationNotice'.trim($account_id), array(), 60 * 60 * 24 * 1);
525 525
 			}
526 526
 		}
527 527
 	}
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
 	 * @param int $_ImapServerId the profileID to look for
533 533
 	 * @param int $account_id the egw account to look for
534 534
 	 */
535
-	static function resetConnectionErrorCache($_ImapServerId=null,$account_id=null)
535
+	static function resetConnectionErrorCache($_ImapServerId = null, $account_id = null)
536 536
 	{
537 537
 		//error_log(__METHOD__.' ('.__LINE__.') '.' for Profile:'.array2string($_ImapServerId) .' for user:'.trim($account_id));
538 538
 		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
@@ -550,19 +550,19 @@  discard block
 block discarded – undo
550 550
 		}
551 551
 		else
552 552
 		{
553
-			$isConError = egw_cache::getCache(egw_cache::INSTANCE,'email','icServerSIEVE_connectionError'.trim($account_id));
553
+			$isConError = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'icServerSIEVE_connectionError'.trim($account_id));
554 554
 			if (isset($isConError[$_ImapServerId]))
555 555
 			{
556 556
 				unset($isConError[$_ImapServerId]);
557 557
 			}
558
-			$waitOnFailure = egw_cache::getCache(egw_cache::INSTANCE,'email','ActiveSyncWaitOnFailure'.trim($account_id),null,array(),60*60*2);
558
+			$waitOnFailure = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'ActiveSyncWaitOnFailure'.trim($account_id), null, array(), 60 * 60 * 2);
559 559
 			if (isset($waitOnFailure[$_ImapServerId]))
560 560
 			{
561 561
 				unset($waitOnFailure[$_ImapServerId]);
562 562
 			}
563 563
 		}
564
-		egw_cache::setCache(egw_cache::INSTANCE,'email','icServerSIEVE_connectionError'.trim($account_id),$isConError,60*15);
565
-		egw_cache::setCache(egw_cache::INSTANCE,'email','ActiveSyncWaitOnFailure'.trim($account_id),$waitOnFailure,60*60*2);
564
+		egw_cache::setCache(egw_cache::INSTANCE, 'email', 'icServerSIEVE_connectionError'.trim($account_id), $isConError, 60 * 15);
565
+		egw_cache::setCache(egw_cache::INSTANCE, 'email', 'ActiveSyncWaitOnFailure'.trim($account_id), $waitOnFailure, 60 * 60 * 2);
566 566
 	}
567 567
 
568 568
 	/**
@@ -571,13 +571,13 @@  discard block
 block discarded – undo
571 571
 	 * @param int $_ImapServerId the profileID to look for
572 572
 	 * @param int $account_id the egw account to look for
573 573
 	 */
574
-	static function resetFolderObjectCache($_ImapServerId=null,$account_id=null)
574
+	static function resetFolderObjectCache($_ImapServerId = null, $account_id = null)
575 575
 	{
576 576
 		//error_log(__METHOD__.' ('.__LINE__.') '.' called for Profile:'.array2string($_ImapServerId).'->'.function_backtrace());
577 577
 		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
578 578
 		// on [location] => verify_settings we coud either use [prefs] => Array([ActiveProfileID] => 9, .. as $_ImapServerId
579 579
 		// or treat it as not given. we try that path
580
-		if (is_null($_ImapServerId)||is_array($_ImapServerId))
580
+		if (is_null($_ImapServerId) || is_array($_ImapServerId))
581 581
 		{
582 582
 			$folders2return = array();
583 583
 			$folderInfo = array();
@@ -586,12 +586,12 @@  discard block
 block discarded – undo
586 586
 		}
587 587
 		else
588 588
 		{
589
-			$folders2return = egw_cache::getCache(egw_cache::INSTANCE,'email','folderObjects'.trim($account_id),null,array(),60*60*1);
589
+			$folders2return = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'folderObjects'.trim($account_id), null, array(), 60 * 60 * 1);
590 590
 			if (!empty($folders2return) && isset($folders2return[$_ImapServerId]))
591 591
 			{
592 592
 				unset($folders2return[$_ImapServerId]);
593 593
 			}
594
-			$folderInfo = egw_cache::getCache(egw_cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($account_id),null,array(),60*60*5);
594
+			$folderInfo = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($account_id), null, array(), 60 * 60 * 5);
595 595
 			if (!empty($folderInfo) && isset($folderInfo[$_ImapServerId]))
596 596
 			{
597 597
 				unset($folderInfo[$_ImapServerId]);
@@ -603,23 +603,23 @@  discard block
 block discarded – undo
603 603
 				unset($lastFolderUsedForMove[$_ImapServerId]);
604 604
 			}
605 605
 			*/
606
-			$folderBasicInfo = egw_cache::getCache(egw_cache::INSTANCE,'email','folderBasicInfo'.trim($account_id),null,array(),60*60*1);
606
+			$folderBasicInfo = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'folderBasicInfo'.trim($account_id), null, array(), 60 * 60 * 1);
607 607
 			if (!empty($folderBasicInfo) && isset($folderBasicInfo[$_ImapServerId]))
608 608
 			{
609 609
 				unset($folderBasicInfo[$_ImapServerId]);
610 610
 			}
611
-			$_specialUseFolders = egw_cache::getCache(egw_cache::INSTANCE,'email','specialUseFolders'.trim($account_id),null,array(),60*60*12);
611
+			$_specialUseFolders = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'specialUseFolders'.trim($account_id), null, array(), 60 * 60 * 12);
612 612
 			if (!empty($_specialUseFolders) && isset($_specialUseFolders[$_ImapServerId]))
613 613
 			{
614 614
 				unset($_specialUseFolders[$_ImapServerId]);
615
-				self::$specialUseFolders=null;
615
+				self::$specialUseFolders = null;
616 616
 			}
617 617
 		}
618
-		egw_cache::setCache(egw_cache::INSTANCE,'email','folderObjects'.trim($account_id),$folders2return, 60*60*1);
619
-		egw_cache::setCache(egw_cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($account_id),$folderInfo,60*60*5);
618
+		egw_cache::setCache(egw_cache::INSTANCE, 'email', 'folderObjects'.trim($account_id), $folders2return, 60 * 60 * 1);
619
+		egw_cache::setCache(egw_cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($account_id), $folderInfo, 60 * 60 * 5);
620 620
 		//egw_cache::setCache(egw_cache::INSTANCE,'email','lastFolderUsedForMove'.trim($account_id),$lastFolderUsedForMove,$expiration=60*60*1);
621
-		egw_cache::setCache(egw_cache::INSTANCE,'email','folderBasicInfo'.trim($account_id),$folderBasicInfo,60*60*1);
622
-		egw_cache::setCache(egw_cache::INSTANCE,'email','specialUseFolders'.trim($account_id),$_specialUseFolders,60*60*12);
621
+		egw_cache::setCache(egw_cache::INSTANCE, 'email', 'folderBasicInfo'.trim($account_id), $folderBasicInfo, 60 * 60 * 1);
622
+		egw_cache::setCache(egw_cache::INSTANCE, 'email', 'specialUseFolders'.trim($account_id), $_specialUseFolders, 60 * 60 * 12);
623 623
 	}
624 624
 
625 625
 	/**
@@ -640,14 +640,14 @@  discard block
 block discarded – undo
640 640
 	 * @param string $_profileID the ID of the mailaccount to check for identities, if null current mail-account is used
641 641
 	 * @return array - array(email=>realname)
642 642
 	 */
643
-	function getUserEMailAddresses($_profileID=null) {
644
-		$acc = emailadmin_account::read((!empty($_profileID)?$_profileID:$this->profileID));
643
+	function getUserEMailAddresses($_profileID = null) {
644
+		$acc = emailadmin_account::read((!empty($_profileID) ? $_profileID : $this->profileID));
645 645
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.array2string($acc));
646 646
 		$identities = $acc->identities();
647 647
 
648 648
 		$userEMailAdresses = array($acc['ident_email']=>$acc['ident_realname']);
649 649
 
650
-		foreach($identities as $ik => $ident) {
650
+		foreach ($identities as $ik => $ident) {
651 651
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
652 652
 			$identity = emailadmin_account::read_identity($ik);
653 653
 			if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']])) $userEMailAdresses[$identity['ident_email']] = $identity['ident_realname'];
@@ -662,19 +662,19 @@  discard block
 block discarded – undo
662 662
 	 * @param boolean $resolve_placeholders wether or not resolve possible placeholders in identities
663 663
 	 * @return array - array(email=>realname)
664 664
 	 */
665
-	static function getAllIdentities($_accountToSearch=null,$resolve_placeholders=false) {
665
+	static function getAllIdentities($_accountToSearch = null, $resolve_placeholders = false) {
666 666
 		$userEMailAdresses = array();
667
-		foreach(emailadmin_account::search($only_current_user=($_accountToSearch?$_accountToSearch:true), $just_name=true) as $acc_id => $identity_name)
667
+		foreach (emailadmin_account::search($only_current_user = ($_accountToSearch ? $_accountToSearch : true), $just_name = true) as $acc_id => $identity_name)
668 668
 		{
669
-			$acc = emailadmin_account::read($acc_id,($_accountToSearch?$_accountToSearch:null));
670
-			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']);
669
+			$acc = emailadmin_account::read($acc_id, ($_accountToSearch ? $_accountToSearch : null));
670
+			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']);
671 671
 			$identities = $acc->identities($acc_id);
672 672
 
673
-			foreach($identities as $ik => $ident) {
673
+			foreach ($identities as $ik => $ident) {
674 674
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
675
-				$identity = emailadmin_account::read_identity($ik,$resolve_placeholders);
675
+				$identity = emailadmin_account::read_identity($ik, $resolve_placeholders);
676 676
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
677
-				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']);
677
+				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']);
678 678
 			}
679 679
 		}
680 680
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses));
@@ -694,9 +694,9 @@  discard block
 block discarded – undo
694 694
 		}
695 695
 		$userEMailAdresses = array();
696 696
 		$identities = $account->identities(null, true, 'params');
697
-		foreach($identities as $ik => $ident) {
697
+		foreach ($identities as $ik => $ident) {
698 698
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
699
-			$identity = emailadmin_account::read_identity($ik,true,null,$account);
699
+			$identity = emailadmin_account::read_identity($ik, true, null, $account);
700 700
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
701 701
 			// standardIdentity has ident_id==acc_id (as it is done within account->identities)
702 702
 			if (empty($identity['ident_id'])) $identity['ident_id'] = $identity['acc_id'];
@@ -721,10 +721,10 @@  discard block
 block discarded – undo
721 721
 	 */
722 722
 	function getDefaultIdentity() {
723 723
 		// retrieve the signature accociated with the identity
724
-		$id = $this->getIdentitiesWithAccounts($_accountData=array());
724
+		$id = $this->getIdentitiesWithAccounts($_accountData = array());
725 725
 		$acc = emailadmin_account::read($this->profileID);
726
-		$accountDataIT = ($_accountData[$this->profileID]?$acc->identities($this->profileID,false,'ident_id'):$acc->identities($_accountData[$id],false,'ident_id'));
727
-		foreach($accountDataIT as $it => $accountData)
726
+		$accountDataIT = ($_accountData[$this->profileID] ? $acc->identities($this->profileID, false, 'ident_id') : $acc->identities($_accountData[$id], false, 'ident_id'));
727
+		foreach ($accountDataIT as $it => $accountData)
728 728
 		{
729 729
 			return $accountData;
730 730
 		}
@@ -740,13 +740,13 @@  discard block
 block discarded – undo
740 740
 	{
741 741
 		// account select box
742 742
 		$selectedID = $this->profileID;
743
-		$allAccountData = emailadmin_account::search($only_current_user=true, false, null);
743
+		$allAccountData = emailadmin_account::search($only_current_user = true, false, null);
744 744
 		if ($allAccountData) {
745
-			$rememberFirst=$selectedFound=null;
745
+			$rememberFirst = $selectedFound = null;
746 746
 			foreach ($allAccountData as $tmpkey => $icServers)
747 747
 			{
748 748
 				if (is_null($rememberFirst)) $rememberFirst = $tmpkey;
749
-				if ($tmpkey == $selectedID) $selectedFound=true;
749
+				if ($tmpkey == $selectedID) $selectedFound = true;
750 750
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($icServers->acc_imap_host));
751 751
 				$host = $icServers->acc_imap_host;
752 752
 				if (empty($host)) continue;
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($identities[$icServers->acc_id]));
755 755
 			}
756 756
 		}
757
-		return ($selectedFound?$selectedID:$rememberFirst);
757
+		return ($selectedFound ? $selectedID : $rememberFirst);
758 758
 	}
759 759
 
760 760
 	/**
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
 	 * @var boolean $fullString full or false=NamePart only is returned
765 765
 	 * @return string - constructed of identity object data as defined in mailConfig
766 766
 	 */
767
-	static function generateIdentityString($identity, $fullString=true)
767
+	static function generateIdentityString($identity, $fullString = true)
768 768
 	{
769 769
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($identity));
770 770
 		//if (is_null(self::$mailConfig)) self::$mailConfig = config::read('mail');
@@ -775,16 +775,16 @@  discard block
 block discarded – undo
775 775
 		{
776 776
 			case 'email';
777 777
 				//$retData = str_replace('@',' ',$identity->emailAddress).($fullString===true?' <'.$identity->emailAddress.'>':'');
778
-				$retData = $identity['ident_email'].($fullString===true?' <'.$identity['ident_email'].'>':'');
778
+				$retData = $identity['ident_email'].($fullString === true ? ' <'.$identity['ident_email'].'>' : '');
779 779
 				break;
780 780
 			case 'nameNemail';
781
-				$retData = (!empty($identity['ident_realname'])?$identity['ident_realname']:substr_replace($identity['ident_email'],'',strpos($identity['ident_email'],'@'))).($fullString===true?' <'.$identity['ident_email'].'>':'');
781
+				$retData = (!empty($identity['ident_realname']) ? $identity['ident_realname'] : substr_replace($identity['ident_email'], '', strpos($identity['ident_email'], '@'))).($fullString === true ? ' <'.$identity['ident_email'].'>' : '');
782 782
 				break;
783 783
 			case 'orgNemail';
784
-				$retData = (!empty($identity['ident_org'])?$identity['ident_org']:substr_replace($identity['ident_email'],'',0,strpos($identity['ident_email'],'@')+1)).($fullString===true?' <'.$identity['ident_email'].'>':'');
784
+				$retData = (!empty($identity['ident_org']) ? $identity['ident_org'] : substr_replace($identity['ident_email'], '', 0, strpos($identity['ident_email'], '@') + 1)).($fullString === true ? ' <'.$identity['ident_email'].'>' : '');
785 785
 				break;
786 786
 			default:
787
-				$retData = $identity['ident_realname'].(!empty($identity['ident_org'])?' '.$identity['ident_org']:'').($fullString===true?' <'.$identity['ident_email'].'>':'');
787
+				$retData = $identity['ident_realname'].(!empty($identity['ident_org']) ? ' '.$identity['ident_org'] : '').($fullString === true ? ' <'.$identity['ident_email'].'>' : '');
788 788
 		}
789 789
 		return $retData;
790 790
 	}
@@ -808,7 +808,7 @@  discard block
 block discarded – undo
808 808
 	 */
809 809
 	function reopen($_foldername)
810 810
 	{
811
-		if (self::$debugTimes) $starttime = microtime (true);
811
+		if (self::$debugTimes) $starttime = microtime(true);
812 812
 
813 813
 		//error_log(__METHOD__.' ('.__LINE__.') '."('$_foldername') ".function_backtrace());
814 814
 		// TODO: trying to reduce traffic to the IMAP Server here, introduces problems with fetching the bodies of
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
 			}
824 824
 			$folderOpened = $_foldername;
825 825
 		//}
826
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') ');
826
+		if (self::$debugTimes) self::logRunTimes($starttime, null, 'Folder:'.$_foldername, __METHOD__.' ('.__LINE__.') ');
827 827
 	}
828 828
 
829 829
 
@@ -834,15 +834,15 @@  discard block
 block discarded – undo
834 834
 	 * @throws Horde_Imap_Client_Exception on connection error or authentication failure
835 835
 	 * @throws InvalidArgumentException on missing credentials
836 836
 	 */
837
-	function openConnection($_icServerID=0)
837
+	function openConnection($_icServerID = 0)
838 838
 	{
839 839
 		//error_log( "-------------------------->open connection ".function_backtrace());
840 840
 		//error_log(__METHOD__.' ('.__LINE__.') '.' ->'.array2string($this->icServer));
841
-		if (self::$debugTimes) $starttime = microtime (true);
842
-		$mailbox=null;
841
+		if (self::$debugTimes) $starttime = microtime(true);
842
+		$mailbox = null;
843 843
 		try
844 844
 		{
845
-			if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox'])) $mailbox = $this->sessionData['mailbox'];
845
+			if (isset($this->sessionData['mailbox']) && $this->folderExists($this->sessionData['mailbox'])) $mailbox = $this->sessionData['mailbox'];
846 846
 			if (empty($mailbox)) $mailbox = $this->icServer->getCurrentMailbox();
847 847
 /*
848 848
 			if (isset(emailadmin_imap::$supports_keywords[$_icServerID]))
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
 			error_log(__METHOD__.' ('.__LINE__.') '."->open connection for Server with profileID:".$_icServerID." failed!".$e->getMessage());
870 870
 			throw new egw_exception(__METHOD__." failed to ".__METHOD__." on Profile to $_icServerID :".$e->getMessage());
871 871
 		}
872
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') ');
872
+		if (self::$debugTimes) self::logRunTimes($starttime, null, 'ProfileID:'.$_icServerID, __METHOD__.' ('.__LINE__.') ');
873 873
 	}
874 874
 
875 875
 	/**
@@ -883,13 +883,13 @@  discard block
 block discarded – undo
883 883
 		static $quota;
884 884
 		if (isset($quota)) return $quota;
885 885
 		$this->icServer->getCurrentMailbox();
886
-		if(!$this->icServer->hasCapability('QUOTA')) {
886
+		if (!$this->icServer->hasCapability('QUOTA')) {
887 887
 			$quota = false;
888 888
 			return false;
889 889
 		}
890 890
 		$quota = $this->icServer->getStorageQuotaRoot('INBOX');
891 891
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($quota));
892
-		if(is_array($quota)) {
892
+		if (is_array($quota)) {
893 893
 			$quota = array(
894 894
 				'usage'	=> $quota['USED'],
895 895
 				'limit'	=> $quota['QMAX'],
@@ -907,10 +907,10 @@  discard block
 block discarded – undo
907 907
 	 *
908 908
 	 * @return int - timeout (either set or default 20/10)
909 909
 	 */
910
-	static function getTimeOut($_use='IMAP')
910
+	static function getTimeOut($_use = 'IMAP')
911 911
 	{
912 912
 		$timeout = $GLOBALS['egw_info']['user']['preferences']['mail']['connectionTimeout'];
913
-		if (empty($timeout)) $timeout = ($_use=='SIEVE'?10:20); // this is the default value
913
+		if (empty($timeout)) $timeout = ($_use == 'SIEVE' ? 10 : 20); // this is the default value
914 914
 		return $timeout;
915 915
 	}
916 916
 
@@ -929,18 +929,18 @@  discard block
 block discarded – undo
929 929
 		if (is_null($nameSpace)) $nameSpace = $this->icServer->getNameSpaceArray();
930 930
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($nameSpace));
931 931
 		if (is_array($nameSpace)) {
932
-			foreach($nameSpace as $type => $singleNameSpaceArray)
932
+			foreach ($nameSpace as $type => $singleNameSpaceArray)
933 933
 			{
934 934
 				foreach ($singleNameSpaceArray as $k => $singleNameSpace)
935 935
 				{
936 936
 					$_foldersNameSpace = array();
937
-					if($type == 'personal' && $singleNameSpace['name'] == '#mh/' && ($this->folderExists('Mail')||$this->folderExists('INBOX')))
937
+					if ($type == 'personal' && $singleNameSpace['name'] == '#mh/' && ($this->folderExists('Mail') || $this->folderExists('INBOX')))
938 938
 					{
939 939
 						$_foldersNameSpace['prefix_present'] = 'forced';
940 940
 						// uw-imap server with mailbox prefix or dovecot maybe
941
-						$_foldersNameSpace['prefix'] = ($this->folderExists('Mail')?'Mail':(!empty($singleNameSpace['name'])?$singleNameSpace['name']:''));
941
+						$_foldersNameSpace['prefix'] = ($this->folderExists('Mail') ? 'Mail' : (!empty($singleNameSpace['name']) ? $singleNameSpace['name'] : ''));
942 942
 					}
943
-					elseif($type == 'personal' && ($singleNameSpace['name'] == '#mh/') && $this->folderExists('mail'))
943
+					elseif ($type == 'personal' && ($singleNameSpace['name'] == '#mh/') && $this->folderExists('mail'))
944 944
 					{
945 945
 						$_foldersNameSpace['prefix_present'] = 'forced';
946 946
 						// uw-imap server with mailbox prefix or dovecot maybe
@@ -949,9 +949,9 @@  discard block
 block discarded – undo
949 949
 						$_foldersNameSpace['prefix_present'] = !empty($singleNameSpace['name']);
950 950
 						$_foldersNameSpace['prefix'] = $singleNameSpace['name'];
951 951
 					}
952
-					$_foldersNameSpace['delimiter'] = ($singleNameSpace['delimiter']?$singleNameSpace['delimiter']:$delimiter);
952
+					$_foldersNameSpace['delimiter'] = ($singleNameSpace['delimiter'] ? $singleNameSpace['delimiter'] : $delimiter);
953 953
 					$_foldersNameSpace['type'] = $type;
954
-					$foldersNameSpace[] =$_foldersNameSpace;
954
+					$foldersNameSpace[] = $_foldersNameSpace;
955 955
 				}
956 956
 				//echo "############## $type->".print_r($foldersNameSpace[$type],true)." ###################<br>";
957 957
 			}
@@ -968,10 +968,10 @@  discard block
 block discarded – undo
968 968
 	 */
969 969
 	function getFolderPrefixFromNamespace($nameSpace, $folderName)
970 970
 	{
971
-		foreach($nameSpace as &$singleNameSpace)
971
+		foreach ($nameSpace as &$singleNameSpace)
972 972
 		{
973 973
 			//if (substr($singleNameSpace['prefix'],0,strlen($folderName))==$folderName) return $singleNameSpace['prefix'];
974
-			if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix']) return $singleNameSpace['prefix'];
974
+			if (substr($folderName, 0, strlen($singleNameSpace['prefix'])) == $singleNameSpace['prefix']) return $singleNameSpace['prefix'];
975 975
 		}
976 976
 		return "";
977 977
 	}
@@ -981,12 +981,12 @@  discard block
 block discarded – undo
981 981
 	 * @var boolean $_useCache
982 982
 	 * @return string the hierarchyDelimiter
983 983
 	 */
984
-	function getHierarchyDelimiter($_useCache=true)
984
+	function getHierarchyDelimiter($_useCache = true)
985 985
 	{
986 986
 		static $HierarchyDelimiter;
987
-		if (is_null($HierarchyDelimiter)) $HierarchyDelimiter = egw_cache::getCache(egw_cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
988
-		if ($_useCache===false) unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
989
-		if (isset($HierarchyDelimiter[$this->icServer->ImapServerId])&&!empty($HierarchyDelimiter[$this->icServer->ImapServerId]))
987
+		if (is_null($HierarchyDelimiter)) $HierarchyDelimiter = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 24 * 5);
988
+		if ($_useCache === false) unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
989
+		if (isset($HierarchyDelimiter[$this->icServer->ImapServerId]) && !empty($HierarchyDelimiter[$this->icServer->ImapServerId]))
990 990
 		{
991 991
 			return $HierarchyDelimiter[$this->icServer->ImapServerId];
992 992
 		}
@@ -996,11 +996,11 @@  discard block
 block discarded – undo
996 996
 			$this->icServer->getCurrentMailbox();
997 997
 			$HierarchyDelimiter[$this->icServer->ImapServerId] = $this->icServer->getDelimiter();
998 998
 		}
999
-		catch(Exception $e)
999
+		catch (Exception $e)
1000 1000
 		{
1001 1001
 			$HierarchyDelimiter[$this->icServer->ImapServerId] = '/';
1002 1002
 		}
1003
-		egw_cache::setCache(egw_cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),$HierarchyDelimiter, 60*60*24*5);
1003
+		egw_cache::setCache(egw_cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']), $HierarchyDelimiter, 60 * 60 * 24 * 5);
1004 1004
 		return $HierarchyDelimiter[$this->icServer->ImapServerId];
1005 1005
 	}
1006 1006
 
@@ -1013,7 +1013,7 @@  discard block
 block discarded – undo
1013 1013
 	{
1014 1014
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$this->icServer->ImapServerId.' Connected:'.$this->icServer->_connected);
1015 1015
 		static $_specialUseFolders;
1016
-		if (is_null($_specialUseFolders)||empty($_specialUseFolders)) $_specialUseFolders = egw_cache::getCache(egw_cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1016
+		if (is_null($_specialUseFolders) || empty($_specialUseFolders)) $_specialUseFolders = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 24 * 5);
1017 1017
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_trash));
1018 1018
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_sent));
1019 1019
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_draft));
@@ -1021,19 +1021,19 @@  discard block
 block discarded – undo
1021 1021
 		self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId];
1022 1022
 		if (isset($_specialUseFolders[$this->icServer->ImapServerId]) && !empty($_specialUseFolders[$this->icServer->ImapServerId]))
1023 1023
 			return $_specialUseFolders[$this->icServer->ImapServerId];
1024
-		$_specialUseFolders[$this->icServer->ImapServerId]=array();
1024
+		$_specialUseFolders[$this->icServer->ImapServerId] = array();
1025 1025
 		//if (!empty($this->icServer->acc_folder_trash) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]))
1026
-			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]='Trash';
1026
+			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash] = 'Trash';
1027 1027
 		//if (!empty($this->icServer->acc_folder_draft) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_draft]))
1028
-			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_draft]='Drafts';
1028
+			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_draft] = 'Drafts';
1029 1029
 		//if (!empty($this->icServer->acc_folder_sent) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_sent]))
1030
-			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_sent]='Sent';
1030
+			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_sent] = 'Sent';
1031 1031
 		//if (!empty($this->icServer->acc_folder_template) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_template]))
1032
-			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_template]='Templates';
1033
-		$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_junk]='Junk';
1032
+			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_template] = 'Templates';
1033
+		$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_junk] = 'Junk';
1034 1034
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_specialUseFolders));//.'<->'.array2string($this->icServer));
1035 1035
 		self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId];
1036
-		egw_cache::setCache(egw_cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),$_specialUseFolders, 60*60*24*5);
1036
+		egw_cache::setCache(egw_cache::INSTANCE, 'email', 'specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']), $_specialUseFolders, 60 * 60 * 24 * 5);
1037 1037
 		return $_specialUseFolders[$this->icServer->ImapServerId];
1038 1038
 	}
1039 1039
 
@@ -1049,8 +1049,8 @@  discard block
 block discarded – undo
1049 1049
 	function folderIsSelectable($folderToSelect)
1050 1050
 	{
1051 1051
 		$retval = true;
1052
-		if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true))) {
1053
-			if (!empty($folderStatus['attributes']) && stripos(array2string($folderStatus['attributes']),'noselect')!==false)
1052
+		if ($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect, false, true))) {
1053
+			if (!empty($folderStatus['attributes']) && stripos(array2string($folderStatus['attributes']), 'noselect') !== false)
1054 1054
 			{
1055 1055
 				$retval = false;
1056 1056
 			}
@@ -1070,7 +1070,7 @@  discard block
 block discarded – undo
1070 1070
 	 *
1071 1071
 	 * @throws egw_exception
1072 1072
 	 */
1073
-	function _getStatus($folderName,$ignoreStatusCache=false)
1073
+	function _getStatus($folderName, $ignoreStatusCache = false)
1074 1074
 	{
1075 1075
 		static $folderStatus;
1076 1076
 		if (!$ignoreStatusCache && isset($folderStatus[$this->icServer->ImapServerId][$folderName]))
@@ -1080,7 +1080,7 @@  discard block
 block discarded – undo
1080 1080
 		}
1081 1081
 		try
1082 1082
 		{
1083
-			$folderStatus[$this->icServer->ImapServerId][$folderName] = $this->icServer->getStatus($folderName,$ignoreStatusCache);
1083
+			$folderStatus[$this->icServer->ImapServerId][$folderName] = $this->icServer->getStatus($folderName, $ignoreStatusCache);
1084 1084
 		}
1085 1085
 		catch (Exception $e)
1086 1086
 		{
@@ -1100,7 +1100,7 @@  discard block
 block discarded – undo
1100 1100
 	 * @param fetchSubscribedInfo bool fetch Subscribed Info on folder
1101 1101
 	 * @return array
1102 1102
 	 */
1103
-	function getFolderStatus($_folderName,$ignoreStatusCache=false,$basicInfoOnly=false,$fetchSubscribedInfo=true)
1103
+	function getFolderStatus($_folderName, $ignoreStatusCache = false, $basicInfoOnly = false, $fetchSubscribedInfo = true)
1104 1104
 	{
1105 1105
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly");
1106 1106
 		if (!is_string($_folderName) || empty($_folderName)) // something is wrong. Do not proceed
@@ -1113,7 +1113,7 @@  discard block
 block discarded – undo
1113 1113
 		{
1114 1114
 			$folderInfoCache = $folderBasicInfo[$this->profileID];
1115 1115
 		}
1116
-		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly) return $folderInfoCache[$_folderName];
1116
+		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache == false && $basicInfoOnly) return $folderInfoCache[$_folderName];
1117 1117
 		$retValue = array();
1118 1118
 		$retValue['subscribed'] = false;
1119 1119
 /*
@@ -1131,28 +1131,28 @@  discard block
 block discarded – undo
1131 1131
 			if (is_array($ret))
1132 1132
 			{
1133 1133
 				$retkeys = array_keys($ret);
1134
-				if ($retkeys[0]==$_folderName) $folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1134
+				if ($retkeys[0] == $_folderName) $folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1135 1135
 			}
1136 1136
 			else
1137 1137
 			{
1138
-				$folderInfoCache[$_folderName]=false;
1138
+				$folderInfoCache[$_folderName] = false;
1139 1139
 			}
1140 1140
 		}
1141 1141
 		$folderInfo = $folderInfoCache[$_folderName];
1142 1142
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($folderInfo).'->'.function_backtrace());
1143
-		if(!$folderInfo|| !is_array($folderInfo)) {
1143
+		if (!$folderInfo || !is_array($folderInfo)) {
1144 1144
 			try
1145 1145
 			{
1146
-				$folderInfo = $this->_getStatus($_folderName,$ignoreStatusCache);
1146
+				$folderInfo = $this->_getStatus($_folderName, $ignoreStatusCache);
1147 1147
 			}
1148 1148
 			catch (Exception $e)
1149 1149
 			{
1150
-				$folderInfo=null;
1150
+				$folderInfo = null;
1151 1151
 			}
1152 1152
 			if (!is_array($folderInfo))
1153 1153
 			{
1154 1154
 				// no folder info, but there is a status returned for the folder: something is wrong, try to cope with it
1155
-				$folderInfo = is_array($folderInfo)?$folderInfo:array('HIERACHY_DELIMITER'=>$this->getHierarchyDelimiter(),
1155
+				$folderInfo = is_array($folderInfo) ? $folderInfo : array('HIERACHY_DELIMITER'=>$this->getHierarchyDelimiter(),
1156 1156
 					'ATTRIBUTES' => '');
1157 1157
 				if (!isset($folderInfo['HIERACHY_DELIMITER']) || empty($folderInfo['HIERACHY_DELIMITER']) || (isset($folderInfo['delimiter']) && empty($folderInfo['delimiter'])))
1158 1158
 				{
@@ -1164,24 +1164,24 @@  discard block
 block discarded – undo
1164 1164
 		#if(!is_array($folderInfo)) {
1165 1165
 		#	return false;
1166 1166
 		#}
1167
-		$retValue['delimiter']		= (isset($folderInfo['HIERACHY_DELIMITER']) && $folderInfo['HIERACHY_DELIMITER']?$folderInfo['HIERACHY_DELIMITER']:$folderInfo['delimiter']);
1168
-		$retValue['attributes']		= (isset($folderInfo['ATTRIBUTES']) && $folderInfo['ATTRIBUTES']?$folderInfo['ATTRIBUTES']:$folderInfo['attributes']);
1169
-		$shortNameParts			= explode($retValue['delimiter'], $_folderName);
1167
+		$retValue['delimiter']		= (isset($folderInfo['HIERACHY_DELIMITER']) && $folderInfo['HIERACHY_DELIMITER'] ? $folderInfo['HIERACHY_DELIMITER'] : $folderInfo['delimiter']);
1168
+		$retValue['attributes']		= (isset($folderInfo['ATTRIBUTES']) && $folderInfo['ATTRIBUTES'] ? $folderInfo['ATTRIBUTES'] : $folderInfo['attributes']);
1169
+		$shortNameParts = explode($retValue['delimiter'], $_folderName);
1170 1170
 		$retValue['shortName']		= array_pop($shortNameParts);
1171 1171
 		$retValue['displayName']	= $_folderName;
1172
-		$retValue['shortDisplayName']	= $retValue['shortName'];
1173
-		if(strtoupper($retValue['shortName']) == 'INBOX') {
1174
-			$retValue['displayName']	= lang('INBOX');
1175
-			$retValue['shortDisplayName']	= lang('INBOX');
1172
+		$retValue['shortDisplayName'] = $retValue['shortName'];
1173
+		if (strtoupper($retValue['shortName']) == 'INBOX') {
1174
+			$retValue['displayName'] = lang('INBOX');
1175
+			$retValue['shortDisplayName'] = lang('INBOX');
1176 1176
 		}
1177 1177
 		// translate the automatic Folders (Sent, Drafts, ...) like the INBOX
1178
-		elseif (in_array($retValue['shortName'],self::$autoFolders))
1178
+		elseif (in_array($retValue['shortName'], self::$autoFolders))
1179 1179
 		{
1180 1180
 			$retValue['displayName'] = $retValue['shortDisplayName'] = lang($retValue['shortName']);
1181 1181
 		}
1182
-		if ($folderInfo) $folderBasicInfo[$this->profileID][$_folderName]=$retValue;
1182
+		if ($folderInfo) $folderBasicInfo[$this->profileID][$_folderName] = $retValue;
1183 1183
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.$_folderName.array2string($retValue['attributes']));
1184
-		if ($basicInfoOnly || (isset($retValue['attributes']) && stripos(array2string($retValue['attributes']),'noselect')!==false))
1184
+		if ($basicInfoOnly || (isset($retValue['attributes']) && stripos(array2string($retValue['attributes']), 'noselect') !== false))
1185 1185
 		{
1186 1186
 			return $retValue;
1187 1187
 		}
@@ -1194,12 +1194,12 @@  discard block
 block discarded – undo
1194 1194
 		if (is_null($nameSpace) || empty($nameSpace[$this->profileID])) $nameSpace[$this->profileID] = $this->_getNameSpaces();
1195 1195
 		if (!empty($nameSpace[$this->profileID]))
1196 1196
 		{
1197
-			$nsNoPersonal=array();
1198
-			foreach($nameSpace[$this->profileID] as &$ns)
1197
+			$nsNoPersonal = array();
1198
+			foreach ($nameSpace[$this->profileID] as &$ns)
1199 1199
 			{
1200
-				if ($ns['type']!='personal') $nsNoPersonal[]=$ns;
1200
+				if ($ns['type'] != 'personal') $nsNoPersonal[] = $ns;
1201 1201
 			}
1202
-			$nameSpace[$this->profileID]=$nsNoPersonal;
1202
+			$nameSpace[$this->profileID] = $nsNoPersonal;
1203 1203
 		}
1204 1204
 		if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName])) $prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName);
1205 1205
 
@@ -1208,32 +1208,32 @@  discard block
 block discarded – undo
1208 1208
 			$subscribedFolders[$this->profileID] = $this->icServer->listSubscribedMailboxes();
1209 1209
 		}
1210 1210
 
1211
-		if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID])) {
1211
+		if ($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName, $subscribedFolders[$this->profileID])) {
1212 1212
 			$retValue['subscribed'] = true;
1213 1213
 		}
1214 1214
 
1215 1215
 		try
1216 1216
 		{
1217 1217
 			//$folderStatus = $this->_getStatus($_folderName,$ignoreStatusCache);
1218
-			$folderStatus = $this->getMailBoxCounters($_folderName,false);
1219
-			$retValue['messages']		= $folderStatus['MESSAGES'];
1218
+			$folderStatus = $this->getMailBoxCounters($_folderName, false);
1219
+			$retValue['messages'] = $folderStatus['MESSAGES'];
1220 1220
 			$retValue['recent']		= $folderStatus['RECENT'];
1221
-			$retValue['uidnext']		= $folderStatus['UIDNEXT'];
1222
-			$retValue['uidvalidity']	= $folderStatus['UIDVALIDITY'];
1221
+			$retValue['uidnext'] = $folderStatus['UIDNEXT'];
1222
+			$retValue['uidvalidity'] = $folderStatus['UIDVALIDITY'];
1223 1223
 			$retValue['unseen']		= $folderStatus['UNSEEN'];
1224 1224
 			if (//$retValue['unseen']==0 &&
1225 1225
 				(isset($this->mailPreferences['trustServersUnseenInfo']) && // some servers dont serve the UNSEEN information
1226
-				$this->mailPreferences['trustServersUnseenInfo']==false) ||
1226
+				$this->mailPreferences['trustServersUnseenInfo'] == false) ||
1227 1227
 				(isset($this->mailPreferences['trustServersUnseenInfo']) &&
1228
-				$this->mailPreferences['trustServersUnseenInfo']==2 &&
1229
-				$prefix[$this->profileID][$_folderName] != '' && stripos($_folderName,$prefix[$this->profileID][$_folderName]) !== false)
1228
+				$this->mailPreferences['trustServersUnseenInfo'] == 2 &&
1229
+				$prefix[$this->profileID][$_folderName] != '' && stripos($_folderName, $prefix[$this->profileID][$_folderName]) !== false)
1230 1230
 			)
1231 1231
 			{
1232 1232
 				//error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($prefix,true).' TS:'.$this->mailPreferences['trustServersUnseenInfo']);
1233 1233
 				// we filter for the combined status of unseen and undeleted, as this is what we show in list
1234 1234
 				try
1235 1235
 				{
1236
-					$sortResult = $this->getSortedList($_folderName, $_sort=0, $_reverse=1, array('status'=>array('UNSEEN','UNDELETED')),$byUid=true,false);
1236
+					$sortResult = $this->getSortedList($_folderName, $_sort = 0, $_reverse = 1, array('status'=>array('UNSEEN', 'UNDELETED')), $byUid = true, false);
1237 1237
 					$retValue['unseen'] = $sortResult['count'];
1238 1238
 				}
1239 1239
 				catch (Exception $ee)
@@ -1244,7 +1244,7 @@  discard block
 block discarded – undo
1244 1244
 		}
1245 1245
 		catch (Exception $e)
1246 1246
 		{
1247
-			if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1247
+			if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(), true));
1248 1248
 		}
1249 1249
 
1250 1250
 		return $retValue;
@@ -1265,7 +1265,7 @@  discard block
 block discarded – undo
1265 1265
 	 * @param boolean $_cacheResult = true try touse the cache of getSortedList
1266 1266
 	 * @return array result as array(header=>array,total=>int,first=>int,last=>int)
1267 1267
 	 */
1268
-	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true)
1268
+	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly = null, $_cacheResult = true)
1269 1269
 	{
1270 1270
 		//self::$debug=true;
1271 1271
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
@@ -1278,7 +1278,7 @@  discard block
 block discarded – undo
1278 1278
 		$rByUid = true; // try searching by uid. this var will be passed by reference to getSortedList, and may be set to false, if UID retrieval fails
1279 1279
 		#print "<pre>";
1280 1280
 		#$this->icServer->setDebug(true);
1281
-		$total=0;
1281
+		$total = 0;
1282 1282
 		if ($_thisUIDOnly === null)
1283 1283
 		{
1284 1284
 			if (($_startMessage || $_numberOfMessages) && !isset($_filter['range']))
@@ -1291,24 +1291,24 @@  discard block
 block discarded – undo
1291 1291
 				//$_filter['range'] ="$_startMessage:*";
1292 1292
 			}
1293 1293
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1294
-			if (self::$debug||self::$debugTimes) $starttime = microtime (true);
1294
+			if (self::$debug || self::$debugTimes) $starttime = microtime(true);
1295 1295
 			//see this example below for a 12 week datefilter (since)
1296 1296
 			//$_filter = array('status'=>array('UNDELETED'),'type'=>"SINCE",'string'=> date("d-M-Y", $starttime-(3600*24*7*12)));
1297 1297
 			$_sortResult = $this->getSortedList($_folderName, $_sort, $reverse, $_filter, $rByUid, $_cacheResult);
1298 1298
 			$sortResult = $_sortResult['match']->ids;
1299 1299
 			//$modseq = $_sortResult['modseq'];
1300 1300
 			//error_log(__METHOD__.' ('.__LINE__.') '.'Modsequence:'.$modseq);
1301
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1301
+			if (self::$debug || self::$debugTimes) self::logRunTimes($starttime, null, ' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly), __METHOD__.' ('.__LINE__.') ');
1302 1302
 
1303 1303
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1304 1304
 			#$this->icServer->setDebug(false);
1305 1305
 			#print "</pre>";
1306 1306
 			// nothing found
1307
-			if(!is_array($sortResult) || empty($sortResult)) {
1307
+			if (!is_array($sortResult) || empty($sortResult)) {
1308 1308
 				$retValue = array();
1309 1309
 				$retValue['info']['total']	= 0;
1310 1310
 				$retValue['info']['first']	= 0;
1311
-				$retValue['info']['last']	= 0;
1311
+				$retValue['info']['last'] = 0;
1312 1312
 				return $retValue;
1313 1313
 			}
1314 1314
 
@@ -1316,54 +1316,54 @@  discard block
 block discarded – undo
1316 1316
 			#_debug_array($sortResult);
1317 1317
 			#_debug_array(array_slice($sortResult, -5, -2));
1318 1318
 			//error_log("REVERSE: $reverse");
1319
-			if($reverse === true) {
1320
-				if  ($_startMessage<=$total)
1319
+			if ($reverse === true) {
1320
+				if ($_startMessage <= $total)
1321 1321
 				{
1322
-					$startMessage = $_startMessage-1;
1322
+					$startMessage = $_startMessage - 1;
1323 1323
 				}
1324 1324
 				else
1325 1325
 				{
1326 1326
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total);
1327
-					if ($_startMessage+$_numberOfMessages>$total)
1327
+					if ($_startMessage + $_numberOfMessages > $total)
1328 1328
 					{
1329
-						$numberOfMessages = $total%$_numberOfMessages;
1329
+						$numberOfMessages = $total % $_numberOfMessages;
1330 1330
 						//$numberOfMessages = abs($_startMessage-$total-1);
1331
-						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages) $_numberOfMessages = $numberOfMessages;
1331
+						if ($numberOfMessages > 0 && $numberOfMessages <= $_numberOfMessages) $_numberOfMessages = $numberOfMessages;
1332 1332
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total);
1333 1333
 					}
1334
-					$startMessage=($total-$_numberOfMessages)-1;
1334
+					$startMessage = ($total - $_numberOfMessages) - 1;
1335 1335
 					//$retValue['info']['first'] = $startMessage;
1336 1336
 					//$retValue['info']['last'] = $total;
1337 1337
 
1338 1338
 				}
1339
-				if ($startMessage+$_numberOfMessages>$total)
1339
+				if ($startMessage + $_numberOfMessages > $total)
1340 1340
 				{
1341
-					$_numberOfMessages = $_numberOfMessages-($total-($startMessage+$_numberOfMessages));
1341
+					$_numberOfMessages = $_numberOfMessages - ($total - ($startMessage + $_numberOfMessages));
1342 1342
 					//$retValue['info']['first'] = $startMessage;
1343 1343
 					//$retValue['info']['last'] = $total;
1344 1344
 				}
1345
-				if($startMessage > 0) {
1346
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1347
-					$sortResult = array_slice($sortResult, -($_numberOfMessages+$startMessage), -$startMessage);
1345
+				if ($startMessage > 0) {
1346
+					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages + $startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1347
+					$sortResult = array_slice($sortResult, -($_numberOfMessages + $startMessage), -$startMessage);
1348 1348
 				} else {
1349
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1350
-					$sortResult = array_slice($sortResult, -($_numberOfMessages+($_startMessage-1)));
1349
+					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages + ($_startMessage - 1))).', AllTheRest, Number of Messages:'.count($sortResult));
1350
+					$sortResult = array_slice($sortResult, -($_numberOfMessages + ($_startMessage - 1)));
1351 1351
 				}
1352 1352
 				$sortResult = array_reverse($sortResult);
1353 1353
 			} else {
1354
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1355
-				$sortResult = array_slice($sortResult, $_startMessage-1, $_numberOfMessages);
1354
+				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage - 1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1355
+				$sortResult = array_slice($sortResult, $_startMessage - 1, $_numberOfMessages);
1356 1356
 			}
1357 1357
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1358 1358
 		}
1359 1359
 		else
1360 1360
 		{
1361
-			$sortResult = (is_array($_thisUIDOnly) ? $_thisUIDOnly:(array)$_thisUIDOnly);
1361
+			$sortResult = (is_array($_thisUIDOnly) ? $_thisUIDOnly : (array)$_thisUIDOnly);
1362 1362
 		}
1363 1363
 
1364 1364
 
1365 1365
 		// fetch the data for the selected messages
1366
-		if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1366
+		if (self::$debug || self::$debugTimes) $starttime = microtime(true);
1367 1367
 		try
1368 1368
 		{
1369 1369
 			$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -1372,20 +1372,20 @@  discard block
 block discarded – undo
1372 1372
 			$fquery = new Horde_Imap_Client_Fetch_Query();
1373 1373
 
1374 1374
 			// Pre-cache the headers we want, 'fetchHeaders' is a label into the cache
1375
-			$fquery->headers('fetchHeaders',array(
1376
-				'DISPOSITION-NOTIFICATION-TO','RETURN-RECEIPT-TO','X-CONFIRM-READING-TO',
1377
-				'DATE','SUBJECT','FROM','TO','CC',
1375
+			$fquery->headers('fetchHeaders', array(
1376
+				'DISPOSITION-NOTIFICATION-TO', 'RETURN-RECEIPT-TO', 'X-CONFIRM-READING-TO',
1377
+				'DATE', 'SUBJECT', 'FROM', 'TO', 'CC',
1378 1378
 				'X-PRIORITY'
1379
-			),array(
1379
+			), array(
1380 1380
 				// Cache headers, we'll look at them below
1381
-				'cache' => true,//$_cacheResult,
1381
+				'cache' => true, //$_cacheResult,
1382 1382
 				// Set peek so messages are not flagged as read
1383 1383
 				'peek' => true
1384 1384
 			));
1385 1385
 			$fquery->size();
1386 1386
 			$fquery->structure();
1387 1387
 			$fquery->flags();
1388
-			$fquery->imapDate();// needed to ensure getImapDate fetches the internaldate, not the current time
1388
+			$fquery->imapDate(); // needed to ensure getImapDate fetches the internaldate, not the current time
1389 1389
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
1390 1390
 				'ids' => $uidsToFetch,
1391 1391
 			));
@@ -1396,9 +1396,9 @@  discard block
 block discarded – undo
1396 1396
 			$headersNew = array();
1397 1397
 			$sortResult = array();
1398 1398
 		}
1399
-		if (self::$debug||self::$debugTimes)
1399
+		if (self::$debug || self::$debugTimes)
1400 1400
 		{
1401
-			self::logRunTimes($starttime,null,'HordeFetch: for Folder:'.$_folderName.' Filter:'.array2string($_filter),__METHOD__.' ('.__LINE__.') ');
1401
+			self::logRunTimes($starttime, null, 'HordeFetch: for Folder:'.$_folderName.' Filter:'.array2string($_filter), __METHOD__.' ('.__LINE__.') ');
1402 1402
 			if (self::$debug)
1403 1403
 			{
1404 1404
 				$queryString = implode(',', $sortResult);
@@ -1408,28 +1408,28 @@  discard block
 block discarded – undo
1408 1408
 
1409 1409
 		$count = 0;
1410 1410
 
1411
-		foreach((array)$sortResult as $uid) {
1411
+		foreach ((array)$sortResult as $uid) {
1412 1412
 			$sortOrder[$uid] = $count++;
1413 1413
 		}
1414 1414
 
1415 1415
 		$count = 0;
1416 1416
 		if (is_object($headersNew)) {
1417
-			if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1418
-			foreach($headersNew->ids() as $id) {
1417
+			if (self::$debug || self::$debugTimes) $starttime = microtime(true);
1418
+			foreach ($headersNew->ids() as $id) {
1419 1419
 				$_headerObject = $headersNew->get($id);
1420 1420
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject));
1421 1421
 				$headerObject = array();
1422
-				$uid = $headerObject['UID']= ($_headerObject->getUid()?$_headerObject->getUid():$id);
1422
+				$uid = $headerObject['UID'] = ($_headerObject->getUid() ? $_headerObject->getUid() : $id);
1423 1423
 				$headerObject['MSG_NUM'] = $_headerObject->getSeq();
1424 1424
 				$headerObject['SIZE'] = $_headerObject->getSize();
1425 1425
 				$headerObject['INTERNALDATE'] = $_headerObject->getImapDate();
1426 1426
 
1427 1427
 				// Get already cached headers, 'fetchHeaders' is a label matchimg above
1428
-				$headerForPrio = array_change_key_case($_headerObject->getHeaders('fetchHeaders',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
1428
+				$headerForPrio = array_change_key_case($_headerObject->getHeaders('fetchHeaders', Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
1429 1429
 				// Try to fetch header with key='' as some servers might have no fetchHeaders index. e.g. yandex.com
1430
-				if (empty($headerForPrio)) $headerForPrio = array_change_key_case($_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
1430
+				if (empty($headerForPrio)) $headerForPrio = array_change_key_case($_headerObject->getHeaders('', Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
1431 1431
 				if (self::$debug) {
1432
-					error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject).'UID:'.$_headerObject->getUid().' Size:'.$_headerObject->getSize().' Date:'.$_headerObject->getImapDate().'/'.egw_time::to($_headerObject->getImapDate(),'Y-m-d H:i:s'));
1432
+					error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject).'UID:'.$_headerObject->getUid().' Size:'.$_headerObject->getSize().' Date:'.$_headerObject->getImapDate().'/'.egw_time::to($_headerObject->getImapDate(), 'Y-m-d H:i:s'));
1433 1433
 					error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerForPrio));
1434 1434
 				}
1435 1435
 
@@ -1439,24 +1439,24 @@  discard block
 block discarded – undo
1439 1439
 					$total--;
1440 1440
 					continue;
1441 1441
 				}
1442
-				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) ) {
1442
+				if (isset($headerForPrio['DISPOSITION-NOTIFICATION-TO'])) {
1443 1443
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['DISPOSITION-NOTIFICATION-TO']));
1444
-				} else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) ) {
1444
+				} else if (isset($headerForPrio['RETURN-RECEIPT-TO'])) {
1445 1445
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['RETURN-RECEIPT-TO']));
1446
-				} else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) ) {
1446
+				} else if (isset($headerForPrio['X-CONFIRM-READING-TO'])) {
1447 1447
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['X-CONFIRM-READING-TO']));
1448 1448
 				} /*else $sent_not = "";*/
1449 1449
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
1450 1450
 				$headerObject['DATE'] = $headerForPrio['DATE'];
1451
-				$headerObject['SUBJECT'] = (is_array($headerForPrio['SUBJECT'])?$headerForPrio['SUBJECT'][0]:$headerForPrio['SUBJECT']);
1452
-				$headerObject['FROM'] = (array)($headerForPrio['FROM']?$headerForPrio['FROM']:($headerForPrio['REPLY-TO']?$headerForPrio['REPLY-TO']:$headerForPrio['RETURN-PATH']));
1451
+				$headerObject['SUBJECT'] = (is_array($headerForPrio['SUBJECT']) ? $headerForPrio['SUBJECT'][0] : $headerForPrio['SUBJECT']);
1452
+				$headerObject['FROM'] = (array)($headerForPrio['FROM'] ? $headerForPrio['FROM'] : ($headerForPrio['REPLY-TO'] ? $headerForPrio['REPLY-TO'] : $headerForPrio['RETURN-PATH']));
1453 1453
 				$headerObject['TO'] = (array)$headerForPrio['TO'];
1454
-				$headerObject['CC'] = isset($headerForPrio['CC'])?(array)$headerForPrio['CC']:array();
1455
-				$headerObject['PRIORITY'] = isset($headerForPrio['X-PRIORITY'])?$headerForPrio['X-PRIORITY']:null;
1456
-				foreach (array('FROM','TO','CC') as $_k => $key)
1454
+				$headerObject['CC'] = isset($headerForPrio['CC']) ? (array)$headerForPrio['CC'] : array();
1455
+				$headerObject['PRIORITY'] = isset($headerForPrio['X-PRIORITY']) ? $headerForPrio['X-PRIORITY'] : null;
1456
+				foreach (array('FROM', 'TO', 'CC') as $_k => $key)
1457 1457
 				{
1458 1458
 					$address = array();
1459
-					$remember=null;
1459
+					$remember = null;
1460 1460
 					foreach ($headerObject[$key] as $k => $ad)
1461 1461
 					{
1462 1462
 						//the commented section below IS a simplified version of the section "make sure ..."
@@ -1476,7 +1476,7 @@  discard block
 block discarded – undo
1476 1476
 						foreach ($rfcAddr as $_rfcAddr)
1477 1477
 						{
1478 1478
 							if (!$_rfcAddr->valid)	continue; // skip. not a valid address
1479
-							$address[] = imap_rfc822_write_address($_rfcAddr->mailbox,$_rfcAddr->host,$_rfcAddr->personal);
1479
+							$address[] = imap_rfc822_write_address($_rfcAddr->mailbox, $_rfcAddr->host, $_rfcAddr->personal);
1480 1480
 						}
1481 1481
 					}
1482 1482
 					$headerObject[$key] = $address;
@@ -1486,12 +1486,12 @@  discard block
 block discarded – undo
1486 1486
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
1487 1487
 				//error_log(__METHOD__.' ('.__LINE__.') '.' MimeMap:'.array2string($mailStructureObject->contentTypeMap()));
1488 1488
 				//foreach ($_headerObject->getStructure()->getParts() as $p => $part)
1489
-				$headerObject['ATTACHMENTS']=null;
1490
-				$skipParts=array();
1491
-				$messageMimeType='';
1489
+				$headerObject['ATTACHMENTS'] = null;
1490
+				$skipParts = array();
1491
+				$messageMimeType = '';
1492 1492
 				foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
1493 1493
 				{
1494
-					if ($mime_id==0 || $messageMimeType==='') $messageMimeType = $mime_type;
1494
+					if ($mime_id == 0 || $messageMimeType === '') $messageMimeType = $mime_type;
1495 1495
 					$part = $mailStructureObject->getPart($mime_id);
1496 1496
 					$partdisposition = $part->getDisposition();
1497 1497
 					$partPrimaryType = $part->getPrimaryType();
@@ -1502,28 +1502,28 @@  discard block
 block discarded – undo
1502 1502
 						// the presence of an cid does not necessarily indicate its inline. it may lack the needed
1503 1503
 						// link to show the image. Considering this: we "list" everything that matches the above criteria
1504 1504
 						// as attachment in order to not loose/miss information on our data
1505
-						$partdisposition='attachment';//($partPrimaryType == 'image'&&!empty($cid)?'inline':'attachment');
1505
+						$partdisposition = 'attachment'; //($partPrimaryType == 'image'&&!empty($cid)?'inline':'attachment');
1506 1506
 					}
1507
-					if ($mime_type=='message/rfc822')
1507
+					if ($mime_type == 'message/rfc822')
1508 1508
 					{
1509 1509
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
1510
-						foreach($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
1510
+						foreach ($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type; }
1511 1511
 					}
1512 1512
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType.' Skip:'.array2string($skipParts));
1513
-					if (array_key_exists($mime_id,$skipParts)) continue;
1514
-					if ($partdisposition=='attachment' ||
1515
-						($partdisposition=='inline'&&$partPrimaryType == 'image'&&$mime_type=='image/tiff') || // as we are not able to display tiffs
1516
-						($partdisposition=='inline'&&$partPrimaryType == 'image'&&empty($cid)) ||
1517
-						($partdisposition=='inline' && $partPrimaryType != 'image' && $partPrimaryType != 'multipart' && $partPrimaryType != 'text'))
1513
+					if (array_key_exists($mime_id, $skipParts)) continue;
1514
+					if ($partdisposition == 'attachment' ||
1515
+						($partdisposition == 'inline' && $partPrimaryType == 'image' && $mime_type == 'image/tiff') || // as we are not able to display tiffs
1516
+						($partdisposition == 'inline' && $partPrimaryType == 'image' && empty($cid)) ||
1517
+						($partdisposition == 'inline' && $partPrimaryType != 'image' && $partPrimaryType != 'multipart' && $partPrimaryType != 'text'))
1518 1518
 					{
1519
-						$headerObject['ATTACHMENTS'][$mime_id]=$part->getAllDispositionParameters();
1520
-						$headerObject['ATTACHMENTS'][$mime_id]['mimeType']=$mime_type;
1521
-						$headerObject['ATTACHMENTS'][$mime_id]['uid']=$uid;
1519
+						$headerObject['ATTACHMENTS'][$mime_id] = $part->getAllDispositionParameters();
1520
+						$headerObject['ATTACHMENTS'][$mime_id]['mimeType'] = $mime_type;
1521
+						$headerObject['ATTACHMENTS'][$mime_id]['uid'] = $uid;
1522 1522
 						$headerObject['ATTACHMENTS'][$mime_id]['cid'] = $cid;
1523
-						$headerObject['ATTACHMENTS'][$mime_id]['partID']=$mime_id;
1524
-						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1525
-						if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'],'winmail.dat') ||
1526
-							$headerObject['ATTACHMENTS'][$mime_id]['mimeType']=='application/ms-tnef')
1523
+						$headerObject['ATTACHMENTS'][$mime_id]['partID'] = $mime_id;
1524
+						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name'] = $part->getName();
1525
+						if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'], 'winmail.dat') ||
1526
+							$headerObject['ATTACHMENTS'][$mime_id]['mimeType'] == 'application/ms-tnef')
1527 1527
 						{
1528 1528
 							$headerObject['ATTACHMENTS'][$mime_id]['is_winmail'] = true;
1529 1529
 						}
@@ -1538,53 +1538,53 @@  discard block
 block discarded – undo
1538 1538
 				if (empty($headerObject['UID'])) continue;
1539 1539
 				//$uid = ($rByUid ? $headerObject['UID'] : $headerObject['MSG_NUM']);
1540 1540
 				// make dates like "Mon, 23 Apr 2007 10:11:06 UT" working with strtotime
1541
-				if(substr($headerObject['DATE'],-2) === 'UT') {
1541
+				if (substr($headerObject['DATE'], -2) === 'UT') {
1542 1542
 					$headerObject['DATE'] .= 'C';
1543 1543
 				}
1544
-				if(substr($headerObject['INTERNALDATE'],-2) === 'UT') {
1544
+				if (substr($headerObject['INTERNALDATE'], -2) === 'UT') {
1545 1545
 					$headerObject['INTERNALDATE'] .= 'C';
1546 1546
 				}
1547 1547
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$headerObject['SUBJECT'].'->'.$headerObject['DATE'].'<->'.$headerObject['INTERNALDATE'] .'#');
1548 1548
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$this->decode_subject($headerObject['SUBJECT']).'->'.$headerObject['DATE']);
1549
-				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;}
1550
-				$retValue['header'][$sortOrder[$uid]]['subject']	= $this->decode_subject($headerObject['SUBJECT']);
1551
-				$retValue['header'][$sortOrder[$uid]]['size'] 		= $headerObject['SIZE'];
1552
-				$retValue['header'][$sortOrder[$uid]]['date']		= self::_strtotime(($headerObject['DATE']&&!($headerObject['DATE']=='NIL')?$headerObject['DATE']:$headerObject['INTERNALDATE']),'ts',true);
1553
-				$retValue['header'][$sortOrder[$uid]]['internaldate']= self::_strtotime($headerObject['INTERNALDATE'],'ts',true);
1554
-				$retValue['header'][$sortOrder[$uid]]['mimetype']	= $messageMimeType;
1555
-				$retValue['header'][$sortOrder[$uid]]['id']		= $headerObject['MSG_NUM'];
1556
-				$retValue['header'][$sortOrder[$uid]]['uid']		= $headerObject['UID'];
1557
-				$retValue['header'][$sortOrder[$uid]]['priority']		= ($headerObject['PRIORITY']?$headerObject['PRIORITY']:3);
1549
+				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][] = $a; }
1550
+				$retValue['header'][$sortOrder[$uid]]['subject'] = $this->decode_subject($headerObject['SUBJECT']);
1551
+				$retValue['header'][$sortOrder[$uid]]['size'] = $headerObject['SIZE'];
1552
+				$retValue['header'][$sortOrder[$uid]]['date'] = self::_strtotime(($headerObject['DATE'] && !($headerObject['DATE'] == 'NIL') ? $headerObject['DATE'] : $headerObject['INTERNALDATE']), 'ts', true);
1553
+				$retValue['header'][$sortOrder[$uid]]['internaldate'] = self::_strtotime($headerObject['INTERNALDATE'], 'ts', true);
1554
+				$retValue['header'][$sortOrder[$uid]]['mimetype'] = $messageMimeType;
1555
+				$retValue['header'][$sortOrder[$uid]]['id'] = $headerObject['MSG_NUM'];
1556
+				$retValue['header'][$sortOrder[$uid]]['uid'] = $headerObject['UID'];
1557
+				$retValue['header'][$sortOrder[$uid]]['priority'] = ($headerObject['PRIORITY'] ? $headerObject['PRIORITY'] : 3);
1558 1558
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.array2string($retValue['header'][$sortOrder[$uid]]));
1559 1559
 				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO'])) $retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1560 1560
 				if (is_array($headerObject['FLAGS'])) {
1561
-					$retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]],self::prepareFlagsArray($headerObject));
1561
+					$retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]], self::prepareFlagsArray($headerObject));
1562 1562
 				}
1563 1563
 				//error_log(__METHOD__.' ('.__LINE__.') '.$headerObject['SUBJECT'].'->'.array2string($_headerObject->getEnvelope()->__get('from')));
1564
-				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0]) {
1565
-					$retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0],true);
1564
+				if (is_array($headerObject['FROM']) && $headerObject['FROM'][0]) {
1565
+					$retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0], true);
1566 1566
 				}
1567
-				if(is_array($headerObject['TO']) && $headerObject['TO'][0]) {
1568
-					$retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0],true);
1569
-					if (count($headerObject['TO'])>1)
1567
+				if (is_array($headerObject['TO']) && $headerObject['TO'][0]) {
1568
+					$retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0], true);
1569
+					if (count($headerObject['TO']) > 1)
1570 1570
 					{
1571
-						$ki=0;
1572
-						foreach($headerObject['TO'] as $k => $add)
1571
+						$ki = 0;
1572
+						foreach ($headerObject['TO'] as $k => $add)
1573 1573
 						{
1574
-							if ($k==0) continue;
1574
+							if ($k == 0) continue;
1575 1575
 							//error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add));
1576
-							$retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add,true);
1576
+							$retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add, true);
1577 1577
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki]));
1578 1578
 							$ki++;
1579 1579
 						}
1580 1580
 					}
1581 1581
 				}
1582
-				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0) {
1583
-					$ki=0;
1584
-					foreach($headerObject['CC'] as $k => $add)
1582
+				if (is_array($headerObject['CC']) && count($headerObject['CC']) > 0) {
1583
+					$ki = 0;
1584
+					foreach ($headerObject['CC'] as $k => $add)
1585 1585
 					{
1586 1586
 						//error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add));
1587
-						$retValue['header'][$sortOrder[$uid]]['cc_addresses'][$ki] = self::decode_header($add,true);
1587
+						$retValue['header'][$sortOrder[$uid]]['cc_addresses'][$ki] = self::decode_header($add, true);
1588 1588
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki]));
1589 1589
 						$ki++;
1590 1590
 					}
@@ -1593,27 +1593,27 @@  discard block
 block discarded – undo
1593 1593
 
1594 1594
 				$count++;
1595 1595
 			}
1596
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
1596
+			if (self::$debug || self::$debugTimes) self::logRunTimes($starttime, null, ' fetching Headers and stuff for Folder:'.$_folderName, __METHOD__.' ('.__LINE__.') ');
1597 1597
 			//self::$debug=false;
1598 1598
 			// sort the messages to the requested displayorder
1599
-			if(is_array($retValue['header'])) {
1599
+			if (is_array($retValue['header'])) {
1600 1600
 				$countMessages = $total;
1601 1601
 				if (isset($_filter['range'])) $countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
1602 1602
 				ksort($retValue['header']);
1603 1603
 				$retValue['info']['total']	= $total;
1604 1604
 				//if ($_startMessage>$total) $_startMessage = $total-($count-1);
1605 1605
 				$retValue['info']['first']	= $_startMessage;
1606
-				$retValue['info']['last']	= $_startMessage + $count - 1 ;
1606
+				$retValue['info']['last'] = $_startMessage + $count - 1;
1607 1607
 				return $retValue;
1608 1608
 			} else {
1609 1609
 				$retValue = array();
1610 1610
 				$retValue['info']['total']	= 0;
1611 1611
 				$retValue['info']['first']	= 0;
1612
-				$retValue['info']['last']	= 0;
1612
+				$retValue['info']['last'] = 0;
1613 1613
 				return $retValue;
1614 1614
 			}
1615 1615
 		} else {
1616
-			if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
1616
+			if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew, TRUE));
1617 1617
 			$retValue = array();
1618 1618
 			$retValue['info']['total']  = 0;
1619 1619
 			$retValue['info']['first']  = 0;
@@ -1630,17 +1630,17 @@  discard block
 block discarded – undo
1630 1630
 	 */
1631 1631
 	static function prepareFlagsArray($headerObject)
1632 1632
 	{
1633
-		if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower',$headerObject['FLAGS']);
1633
+		if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower', $headerObject['FLAGS']);
1634 1634
 		$retValue = array();
1635 1635
 		$retValue['recent']		= in_array('\\recent', $headerFlags);
1636 1636
 		$retValue['flagged']	= in_array('\\flagged', $headerFlags);
1637
-		$retValue['answered']	= in_array('\\answered', $headerFlags);
1638
-		$retValue['forwarded']   = in_array('$forwarded', $headerFlags);
1637
+		$retValue['answered'] = in_array('\\answered', $headerFlags);
1638
+		$retValue['forwarded'] = in_array('$forwarded', $headerFlags);
1639 1639
 		$retValue['deleted']	= in_array('\\deleted', $headerFlags);
1640
-		$retValue['seen']		= in_array('\\seen', $headerFlags);
1641
-		$retValue['draft']		= in_array('\\draft', $headerFlags);
1642
-		$retValue['mdnsent']	= in_array('$mdnsent', $headerFlags)||in_array('mdnsent', $headerFlags);
1643
-		$retValue['mdnnotsent']	= in_array('$mdnnotsent', $headerFlags)||in_array('mdnnotsent', $headerFlags);
1640
+		$retValue['seen'] = in_array('\\seen', $headerFlags);
1641
+		$retValue['draft'] = in_array('\\draft', $headerFlags);
1642
+		$retValue['mdnsent']	= in_array('$mdnsent', $headerFlags) || in_array('mdnsent', $headerFlags);
1643
+		$retValue['mdnnotsent'] = in_array('$mdnnotsent', $headerFlags) || in_array('mdnnotsent', $headerFlags);
1644 1644
 		$retValue['label1']   = in_array('$label1', $headerFlags);
1645 1645
 		$retValue['label2']   = in_array('$label2', $headerFlags);
1646 1646
 		$retValue['label3']   = in_array('$label3', $headerFlags);
@@ -1664,12 +1664,12 @@  discard block
 block discarded – undo
1664 1664
 	 * @param bool $setSession if set to true the session will be populated with the result of the query
1665 1665
 	 * @return mixed bool/array false or array of ids
1666 1666
 	 */
1667
-	function getSortedList($_folderName, $_sort, &$_reverse, $_filter, &$resultByUid=true, $setSession=true)
1667
+	function getSortedList($_folderName, $_sort, &$_reverse, $_filter, &$resultByUid = true, $setSession = true)
1668 1668
 	{
1669 1669
 		static $cachedFolderStatus;
1670 1670
 		// in the past we needed examineMailbox to figure out if the server with the serverID support keywords
1671 1671
 		// this information is filled/provided by examineMailbox; but caching within one request seems o.k.
1672
-		if (is_null($cachedFolderStatus) || !isset($cachedFolderStatus[$this->profileID][$_folderName]) )
1672
+		if (is_null($cachedFolderStatus) || !isset($cachedFolderStatus[$this->profileID][$_folderName]))
1673 1673
 		{
1674 1674
 			$folderStatus = $cachedFolderStatus[$this->profileID][$_folderName] = $this->icServer->examineMailbox($_folderName);
1675 1675
 		}
@@ -1681,27 +1681,27 @@  discard block
 block discarded – undo
1681 1681
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Filter:'.array2string($_filter));
1682 1682
 		$try2useCache = true;
1683 1683
 		static $eMailListContainsDeletedMessages;
1684
-		if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = egw_cache::getCache(egw_cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
1684
+		if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
1685 1685
 		// this indicates, that there is no Filter set, and the returned set/subset should not contain DELETED Messages, nor filtered for UNDELETED
1686
-		if ($setSession==true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
1686
+		if ($setSession == true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
1687 1687
 		{
1688 1688
 			if (self::$debugTimes) $starttime = microtime(true);
1689
-			if (is_null($eMailListContainsDeletedMessages) || empty($eMailListContainsDeletedMessages[$this->profileID]) || empty($eMailListContainsDeletedMessages[$this->profileID][$_folderName])) $eMailListContainsDeletedMessages = egw_cache::getCache(egw_cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
1690
-			$deletedMessages = $this->getSortedList($_folderName, 0, $three=1, array('status'=>array('DELETED')),$five=true,false);
1689
+			if (is_null($eMailListContainsDeletedMessages) || empty($eMailListContainsDeletedMessages[$this->profileID]) || empty($eMailListContainsDeletedMessages[$this->profileID][$_folderName])) $eMailListContainsDeletedMessages = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
1690
+			$deletedMessages = $this->getSortedList($_folderName, 0, $three = 1, array('status'=>array('DELETED')), $five = true, false);
1691 1691
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
1692
-			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] =$deletedMessages['count'];
1693
-			egw_cache::setCache(egw_cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),$eMailListContainsDeletedMessages, 60*60*1);
1694
-			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']);
1692
+			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] = $deletedMessages['count'];
1693
+			egw_cache::setCache(egw_cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']), $eMailListContainsDeletedMessages, 60 * 60 * 1);
1694
+			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']);
1695 1695
 		}
1696 1696
 		$try2useCache = false;
1697 1697
 		//self::$supportsORinQuery[$this->profileID]=true;
1698 1698
 		if (is_null(self::$supportsORinQuery) || !isset(self::$supportsORinQuery[$this->profileID]))
1699 1699
 		{
1700
-			self::$supportsORinQuery = egw_cache::getCache(egw_cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
1701
-			if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID]=true;
1700
+			self::$supportsORinQuery = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 10);
1701
+			if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID] = true;
1702 1702
 		}
1703 1703
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_filter).' SupportsOrInQuery:'.self::$supportsORinQuery[$this->profileID]);
1704
-		$filter = $this->createIMAPFilter($_folderName, $_filter,self::$supportsORinQuery[$this->profileID]);
1704
+		$filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]);
1705 1705
 		if (self::$debug)
1706 1706
 		{
1707 1707
 			$query_str = $filter->build();
@@ -1709,14 +1709,14 @@  discard block
 block discarded – undo
1709 1709
 		}
1710 1710
 		//_debug_array($filter);
1711 1711
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($filter).'#'.array2string($this->icServer->capability()));
1712
-		if($this->icServer->hasCapability('SORT')) {
1712
+		if ($this->icServer->hasCapability('SORT')) {
1713 1713
 			// when using an orQuery and we sort by date. sort seems to fail on certain servers => ZIMBRA with Horde_Imap_Client
1714 1714
 			// thus we translate the search request from date to Horde_Imap_Client::SORT_SEQUENCE (which should be the same, if
1715 1715
 			// there is no messing with the dates)
1716 1716
 			//if (self::$supportsORinQuery[$this->profileID]&&$_sort=='date'&&$_filter['type']=='quick'&&!empty($_filter['string']))$_sort='INTERNALDATE';
1717 1717
 			if (self::$debug) error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
1718 1718
 			$sortOrder = $this->_getSortString($_sort, $_reverse);
1719
-			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder)) $_reverse=false; // as we reversed the result already
1719
+			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE, $sortOrder)) $_reverse = false; // as we reversed the result already
1720 1720
 			if (self::$debug) error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
1721 1721
 			try
1722 1722
 			{
@@ -1724,24 +1724,24 @@  discard block
 block discarded – undo
1724 1724
 					'sort' => $sortOrder,));
1725 1725
 			// if there is an Error, we assume that the server is not capable of sorting
1726 1726
 			}
1727
-			catch(Exception $e)
1727
+			catch (Exception $e)
1728 1728
 			{
1729 1729
 				//error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1730 1730
 				$resultByUid = false;
1731 1731
 				$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1732
-				if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
1732
+				if ($_reverse) array_unshift($sortOrder, Horde_Imap_Client::SORT_REVERSE);
1733 1733
 				try
1734 1734
 				{
1735 1735
 					$sortResult = $this->icServer->search($_folderName, $filter, array(
1736 1736
 						'sort' => $sortOrder));
1737 1737
 				}
1738
-				catch(Exception $e)
1738
+				catch (Exception $e)
1739 1739
 				{
1740 1740
 					error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1741 1741
 					$sortResult = self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'];
1742 1742
 				}
1743 1743
 			}
1744
-			if (self::$debug) error_log(__METHOD__.print_r($sortResult,true));
1744
+			if (self::$debug) error_log(__METHOD__.print_r($sortResult, true));
1745 1745
 		} else {
1746 1746
 			if (self::$debug) error_log(__METHOD__." Mailserver has NO SORT Capability");
1747 1747
 			//$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
@@ -1751,12 +1751,12 @@  discard block
 block discarded – undo
1751 1751
 				$sortResult = $this->icServer->search($_folderName, $filter, array()/*array(
1752 1752
 					'sort' => $sortOrder)*/);
1753 1753
 			}
1754
-			catch(Exception $e)
1754
+			catch (Exception $e)
1755 1755
 			{
1756 1756
 				//error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1757 1757
 				// possible error OR Query. But Horde gives no detailed Info :-(
1758
-				self::$supportsORinQuery[$this->profileID]=false;
1759
-				egw_cache::setCache(egw_cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),self::$supportsORinQuery,60*60*10);
1758
+				self::$supportsORinQuery[$this->profileID] = false;
1759
+				egw_cache::setCache(egw_cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), self::$supportsORinQuery, 60 * 60 * 10);
1760 1760
 				if (self::$debug) error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
1761 1761
 				$filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]);
1762 1762
 				try
@@ -1764,25 +1764,25 @@  discard block
 block discarded – undo
1764 1764
 					$sortResult = $this->icServer->search($_folderName, $filter, array()/*array(
1765 1765
 						'sort' => $sortOrder)*/);
1766 1766
 				}
1767
-				catch(Exception $e)
1767
+				catch (Exception $e)
1768 1768
 				{
1769 1769
 				}
1770 1770
 			}
1771
-			if(is_array($sortResult['match'])) {
1771
+			if (is_array($sortResult['match'])) {
1772 1772
 					// not sure that this is going so succeed as $sortResult['match'] is a hordeObject
1773 1773
 					sort($sortResult['match'], SORT_NUMERIC);
1774 1774
 			}
1775
-			if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
1775
+			if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter, true)." ->".print_r($sortResult, true));
1776 1776
 		}
1777 1777
 		if ($setSession)
1778 1778
 		{
1779 1779
 			self::$folderStatusCache[$this->profileID][$_folderName]['uidValidity'] = $folderStatus['UIDVALIDITY'];
1780
-			self::$folderStatusCache[$this->profileID][$_folderName]['messages']	= $folderStatus['MESSAGES'];
1780
+			self::$folderStatusCache[$this->profileID][$_folderName]['messages'] = $folderStatus['MESSAGES'];
1781 1781
 			self::$folderStatusCache[$this->profileID][$_folderName]['deleted']	= $eMailListContainsDeletedMessages[$this->profileID][$_folderName];
1782 1782
 			self::$folderStatusCache[$this->profileID][$_folderName]['uidnext']	= $folderStatus['UIDNEXT'];
1783
-			self::$folderStatusCache[$this->profileID][$_folderName]['filter']	= $_filter;
1783
+			self::$folderStatusCache[$this->profileID][$_folderName]['filter'] = $_filter;
1784 1784
 			self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'] = $sortResult;
1785
-			self::$folderStatusCache[$this->profileID][$_folderName]['sort']	= $_sort;
1785
+			self::$folderStatusCache[$this->profileID][$_folderName]['sort'] = $_sort;
1786 1786
 		}
1787 1787
 		//error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
1788 1788
 		//_debug_array($sortResult['match']->ids);
@@ -1796,12 +1796,12 @@  discard block
 block discarded – undo
1796 1796
 	 * @param bool _reverse wether to add REVERSE to the Sort String or not
1797 1797
 	 * @return the sort sequence for horde search
1798 1798
 	 */
1799
-	function _getSortString($_sort, $_reverse=false)
1799
+	function _getSortString($_sort, $_reverse = false)
1800 1800
 	{
1801
-		$_reverse=false;
1801
+		$_reverse = false;
1802 1802
 		if (is_numeric($_sort))
1803 1803
 		{
1804
-			switch($_sort) {
1804
+			switch ($_sort) {
1805 1805
 				case 2:
1806 1806
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1807 1807
 					break;
@@ -1823,7 +1823,7 @@  discard block
 block discarded – undo
1823 1823
 		}
1824 1824
 		else
1825 1825
 		{
1826
-			switch(strtoupper($_sort)) {
1826
+			switch (strtoupper($_sort)) {
1827 1827
 				case 'FROMADDRESS':
1828 1828
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1829 1829
 					break;
@@ -1849,7 +1849,7 @@  discard block
 block discarded – undo
1849 1849
 					break;
1850 1850
 			}
1851 1851
 		}
1852
-		if ($_reverse) array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
1852
+		if ($_reverse) array_unshift($retValue, Horde_Imap_Client::SORT_REVERSE);
1853 1853
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.($_reverse?'REVERSE ':'').$_sort.'->'.$retValue);
1854 1854
 		return $retValue;
1855 1855
 	}
@@ -1862,22 +1862,22 @@  discard block
 block discarded – undo
1862 1862
 	 * @param boolean $_supportsOrInQuery wether to use the OR Query on QuickSearch
1863 1863
 	 * @return Horde_Imap_Client_Search_Query the IMAP filter
1864 1864
 	 */
1865
-	function createIMAPFilter($_folder, $_criterias, $_supportsOrInQuery=true)
1865
+	function createIMAPFilter($_folder, $_criterias, $_supportsOrInQuery = true)
1866 1866
 	{
1867 1867
 		$imapFilter = new Horde_Imap_Client_Search_Query();
1868 1868
 		$imapFilter->charset('UTF-8');
1869 1869
 
1870 1870
 		//_debug_array($_criterias);
1871
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
1872
-		if((!is_array($_criterias) || $_criterias['status']=='any') && (!isset($_criterias['string']) || empty($_criterias['string']))) {
1873
-			$imapFilter->flag('DELETED', $set=false);
1871
+		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias) ? " none -> returning" : array2string($_criterias)));
1872
+		if ((!is_array($_criterias) || $_criterias['status'] == 'any') && (!isset($_criterias['string']) || empty($_criterias['string']))) {
1873
+			$imapFilter->flag('DELETED', $set = false);
1874 1874
 			return $imapFilter;
1875 1875
 		}
1876 1876
 		$queryValid = false;
1877 1877
 		// statusQuery MUST be placed first, as search for subject/mailbody and such is
1878 1878
 		// depending on charset. flagSearch is not BUT messes the charset if called afterwards
1879 1879
 		$statusQueryValid = false;
1880
-		foreach((array)$_criterias['status'] as $k => $criteria) {
1880
+		foreach ((array)$_criterias['status'] as $k => $criteria) {
1881 1881
 			$imapStatusFilter = new Horde_Imap_Client_Search_Query();
1882 1882
 			$imapStatusFilter->charset('UTF-8');
1883 1883
 			$criteria = strtoupper($criteria);
@@ -1887,12 +1887,12 @@  discard block
 block discarded – undo
1887 1887
 				case 'FLAGGED':
1888 1888
 				case 'RECENT':
1889 1889
 				case 'SEEN':
1890
-					$imapStatusFilter->flag($criteria, $set=true);
1891
-					$queryValid = $statusQueryValid =true;
1890
+					$imapStatusFilter->flag($criteria, $set = true);
1891
+					$queryValid = $statusQueryValid = true;
1892 1892
 					break;
1893 1893
 				case 'READ':
1894
-					$imapStatusFilter->flag('SEEN', $set=true);
1895
-					$queryValid = $statusQueryValid =true;
1894
+					$imapStatusFilter->flag('SEEN', $set = true);
1895
+					$queryValid = $statusQueryValid = true;
1896 1896
 					break;
1897 1897
 				case 'LABEL1':
1898 1898
 				case 'KEYWORD1':
@@ -1904,38 +1904,38 @@  discard block
 block discarded – undo
1904 1904
 				case 'KEYWORD4':
1905 1905
 				case 'LABEL5':
1906 1906
 				case 'KEYWORD5':
1907
-					$imapStatusFilter->flag(str_ireplace('KEYWORD','$LABEL',$criteria), $set=true);
1908
-					$queryValid = $statusQueryValid =true;
1907
+					$imapStatusFilter->flag(str_ireplace('KEYWORD', '$LABEL', $criteria), $set = true);
1908
+					$queryValid = $statusQueryValid = true;
1909 1909
 					break;
1910 1910
 				case 'NEW':
1911
-					$imapStatusFilter->flag('RECENT', $set=true);
1912
-					$imapStatusFilter->flag('SEEN', $set=false);
1913
-					$queryValid = $statusQueryValid =true;
1911
+					$imapStatusFilter->flag('RECENT', $set = true);
1912
+					$imapStatusFilter->flag('SEEN', $set = false);
1913
+					$queryValid = $statusQueryValid = true;
1914 1914
 					break;
1915 1915
 				case 'OLD':
1916
-					$imapStatusFilter->flag('RECENT', $set=false);
1917
-					$queryValid = $statusQueryValid =true;
1916
+					$imapStatusFilter->flag('RECENT', $set = false);
1917
+					$queryValid = $statusQueryValid = true;
1918 1918
 					break;
1919 1919
 // operate only on system flags
1920 1920
 //        $systemflags = array(
1921 1921
 //            'ANSWERED', 'DELETED', 'DRAFT', 'FLAGGED', 'RECENT', 'SEEN'
1922 1922
 //        );
1923 1923
 				case 'UNANSWERED':
1924
-					$imapStatusFilter->flag('ANSWERED', $set=false);
1925
-					$queryValid = $statusQueryValid =true;
1924
+					$imapStatusFilter->flag('ANSWERED', $set = false);
1925
+					$queryValid = $statusQueryValid = true;
1926 1926
 					break;
1927 1927
 				case 'UNDELETED':
1928
-					$imapFilter->flag('DELETED', $set=false);
1928
+					$imapFilter->flag('DELETED', $set = false);
1929 1929
 					$queryValid = true;
1930 1930
 					break;
1931 1931
 				case 'UNFLAGGED':
1932
-					$imapStatusFilter->flag('FLAGGED', $set=false);
1933
-					$queryValid = $statusQueryValid =true;
1932
+					$imapStatusFilter->flag('FLAGGED', $set = false);
1933
+					$queryValid = $statusQueryValid = true;
1934 1934
 					break;
1935 1935
 				case 'UNREAD':
1936 1936
 				case 'UNSEEN':
1937
-					$imapStatusFilter->flag('SEEN', $set=false);
1938
-					$queryValid = $statusQueryValid =true;
1937
+					$imapStatusFilter->flag('SEEN', $set = false);
1938
+					$queryValid = $statusQueryValid = true;
1939 1939
 					break;
1940 1940
 				case 'UNLABEL1':
1941 1941
 				case 'UNKEYWORD1':
@@ -1947,8 +1947,8 @@  discard block
 block discarded – undo
1947 1947
 				case 'UNKEYWORD4':
1948 1948
 				case 'UNLABEL5':
1949 1949
 				case 'UNKEYWORD5':
1950
-					$imapStatusFilter->flag(str_ireplace(array('UNKEYWORD','UNLABEL'),'$LABEL',$criteria), $set=false);
1951
-					$queryValid = $statusQueryValid =true;
1950
+					$imapStatusFilter->flag(str_ireplace(array('UNKEYWORD', 'UNLABEL'), '$LABEL', $criteria), $set = false);
1951
+					$queryValid = $statusQueryValid = true;
1952 1952
 					break;
1953 1953
 				default:
1954 1954
 					$statusQueryValid = false;
@@ -1964,18 +1964,18 @@  discard block
 block discarded – undo
1964 1964
 		$imapSearchFilter = new Horde_Imap_Client_Search_Query();
1965 1965
 		$imapSearchFilter->charset('UTF-8');
1966 1966
 
1967
-		if(!empty($_criterias['string'])) {
1967
+		if (!empty($_criterias['string'])) {
1968 1968
 			$criteria = strtoupper($_criterias['type']);
1969 1969
 			switch ($criteria) {
1970 1970
 				case 'QUICK':
1971
-					$imapSearchFilter->headerText('SUBJECT', $_criterias['string'], $not=false);
1971
+					$imapSearchFilter->headerText('SUBJECT', $_criterias['string'], $not = false);
1972 1972
 					//$imapSearchFilter->charset('UTF-8');
1973 1973
 					$imapFilter2 = new Horde_Imap_Client_Search_Query();
1974 1974
 					$imapFilter2->charset('UTF-8');
1975
-					if($this->isSentFolder($_folder)) {
1976
-						$imapFilter2->headerText('TO', $_criterias['string'], $not=false);
1975
+					if ($this->isSentFolder($_folder)) {
1976
+						$imapFilter2->headerText('TO', $_criterias['string'], $not = false);
1977 1977
 					} else {
1978
-						$imapFilter2->headerText('FROM', $_criterias['string'], $not=false);
1978
+						$imapFilter2->headerText('FROM', $_criterias['string'], $not = false);
1979 1979
 					}
1980 1980
 					if ($_supportsOrInQuery)
1981 1981
 					{
@@ -1992,31 +1992,31 @@  discard block
 block discarded – undo
1992 1992
 				case 'CC':
1993 1993
 				case 'BCC':
1994 1994
 				case 'SUBJECT':
1995
-					$imapSearchFilter->headerText($criteria, $_criterias['string'], $not=false);
1995
+					$imapSearchFilter->headerText($criteria, $_criterias['string'], $not = false);
1996 1996
 					//$imapSearchFilter->charset('UTF-8');
1997 1997
 					$queryValid = true;
1998 1998
 					break;
1999 1999
 				case 'BODY':
2000 2000
 				case 'TEXT':
2001
-					$imapSearchFilter->text($_criterias['string'],($criteria=='BODY'?true:false), $not=false);
2001
+					$imapSearchFilter->text($_criterias['string'], ($criteria == 'BODY' ? true : false), $not = false);
2002 2002
 					//$imapSearchFilter->charset('UTF-8');
2003 2003
 					$queryValid = true;
2004 2004
 					break;
2005 2005
 				case 'SINCE':
2006
-					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header=true, $not=false);
2006
+					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header = true, $not = false);
2007 2007
 					$queryValid = true;
2008 2008
 					break;
2009 2009
 				case 'BEFORE':
2010
-					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header=true, $not=false);
2010
+					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header = true, $not = false);
2011 2011
 					$queryValid = true;
2012 2012
 					break;
2013 2013
 				case 'ON':
2014
-					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_ON, $header=true, $not=false);
2014
+					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_ON, $header = true, $not = false);
2015 2015
 					$queryValid = true;
2016 2016
 					break;
2017 2017
 			}
2018 2018
 		}
2019
-		if ($statusQueryValid && !$queryValid) $queryValid=true;
2019
+		if ($statusQueryValid && !$queryValid) $queryValid = true;
2020 2020
 		if ($queryValid) $imapFilter->andSearch($imapSearchFilter);
2021 2021
 
2022 2022
 		if (isset($_criterias['range']) && !empty($_criterias['range']))
@@ -2029,8 +2029,8 @@  discard block
 block discarded – undo
2029 2029
 			$query_str = $imapFilter->build();
2030 2030
 			error_log(__METHOD__.' ('.__LINE__.') '.' '.$query_str['query']);
2031 2031
 		}
2032
-		if($queryValid==false) {
2033
-			$imapFilter->flag('DELETED', $set=false);
2032
+		if ($queryValid == false) {
2033
+			$imapFilter->flag('DELETED', $set = false);
2034 2034
 			return $imapFilter;
2035 2035
 		} else {
2036 2036
 			return $imapFilter;
@@ -2044,11 +2044,11 @@  discard block
 block discarded – undo
2044 2044
 	 * @param  mixed/boolean $_tryIDNConversion (true/false AND FORCE): try IDN Conversion on domainparts of emailADRESSES
2045 2045
 	 * @return mixed - based on the input type
2046 2046
 	 */
2047
-	static function decode_header($_string, $_tryIDNConversion=false)
2047
+	static function decode_header($_string, $_tryIDNConversion = false)
2048 2048
 	{
2049 2049
 		if (is_array($_string))
2050 2050
 		{
2051
-			foreach($_string as $k=>$v)
2051
+			foreach ($_string as $k=>$v)
2052 2052
 			{
2053 2053
 				$_string[$k] = self::decode_header($v, $_tryIDNConversion);
2054 2054
 			}
@@ -2056,18 +2056,18 @@  discard block
 block discarded – undo
2056 2056
 		}
2057 2057
 		else
2058 2058
 		{
2059
-			$_string = translation::decodeMailHeader($_string,self::$displayCharset);
2059
+			$_string = translation::decodeMailHeader($_string, self::$displayCharset);
2060 2060
 			$test = @json_encode($_string);
2061 2061
 			//error_log(__METHOD__.__LINE__.' ->'.strlen($singleBodyPart['body']).' Error:'.json_last_error().'<- BodyPart:#'.$test.'#');
2062
-			if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
2062
+			if (($test == "null" || $test === false || is_null($test)) && strlen($_string) > 0)
2063 2063
 			{
2064 2064
 				// try to fix broken utf8
2065 2065
 				$x = utf8_encode($_string);
2066 2066
 				$test = @json_encode($x);
2067
-				if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
2067
+				if (($test == "null" || $test === false || is_null($test)) && strlen($_string) > 0)
2068 2068
 				{
2069 2069
 					// this should not be needed, unless something fails with charset detection/ wrong charset passed
2070
-					$_string = (function_exists('mb_convert_encoding')?mb_convert_encoding($_string,'UTF-8','UTF-8'):(function_exists('iconv')?@iconv("UTF-8","UTF-8//IGNORE",$_string):$_string));
2070
+					$_string = (function_exists('mb_convert_encoding') ? mb_convert_encoding($_string, 'UTF-8', 'UTF-8') : (function_exists('iconv') ? @iconv("UTF-8", "UTF-8//IGNORE", $_string) : $_string));
2071 2071
 				}
2072 2072
 				else
2073 2073
 				{
@@ -2075,7 +2075,7 @@  discard block
 block discarded – undo
2075 2075
 				}
2076 2076
 			}
2077 2077
 
2078
-			if ($_tryIDNConversion===true && stripos($_string,'@')!==false)
2078
+			if ($_tryIDNConversion === true && stripos($_string, '@') !== false)
2079 2079
 			{
2080 2080
 				$rfcAddr = self::parseAddressList($_string);
2081 2081
 				if (!isset(self::$idna2)) self::$idna2 = new egw_idna;
@@ -2090,12 +2090,12 @@  discard block
 block discarded – undo
2090 2090
 							$stringA = array();
2091 2091
 							break; // skip idna conversion if we encounter an error here
2092 2092
 						}
2093
-						$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox,self::$idna2->decode($_rfcAddr->host),$_rfcAddr->personal);
2093
+						$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox, self::$idna2->decode($_rfcAddr->host), $_rfcAddr->personal);
2094 2094
 					}
2095
-					if (!empty($stringA)) $_string = implode(',',$stringA);
2095
+					if (!empty($stringA)) $_string = implode(',', $stringA);
2096 2096
 				}
2097 2097
 			}
2098
-			if ($_tryIDNConversion==='FORCE')
2098
+			if ($_tryIDNConversion === 'FORCE')
2099 2099
 			{
2100 2100
 				if (!isset(self::$idna2)) self::$idna2 = new egw_idna;
2101 2101
 				if (isset(self::$idna2))
@@ -2115,17 +2115,17 @@  discard block
 block discarded – undo
2115 2115
 	 * @param  boolean $decode try decoding
2116 2116
 	 * @return mixed - based on the input type
2117 2117
 	 */
2118
-	function decode_subject($_string,$decode=true)
2118
+	function decode_subject($_string, $decode = true)
2119 2119
 	{
2120 2120
 		#$string = $_string;
2121
-		if($_string=='NIL')
2121
+		if ($_string == 'NIL')
2122 2122
 		{
2123 2123
 			return 'No Subject';
2124 2124
 		}
2125 2125
 		if ($decode) $_string = self::decode_header($_string);
2126 2126
 		// make sure its utf-8
2127 2127
 		$test = @json_encode($_string);
2128
-		if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
2128
+		if (($test == "null" || $test === false || is_null($test)) && strlen($_string) > 0)
2129 2129
 		{
2130 2130
 			$_string = utf8_encode($_string);
2131 2131
 		}
@@ -2177,18 +2177,18 @@  discard block
 block discarded – undo
2177 2177
 	function createFolder($_parent, $_folderName, &$_error)
2178 2178
 	{
2179 2179
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2180
-		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2181
-		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2180
+		$parent = $_parent; //$this->_encodeFolderName($_parent);
2181
+		$folderName = $_folderName; //$this->_encodeFolderName($_folderName);
2182 2182
 
2183
-		if(empty($parent)) {
2183
+		if (empty($parent)) {
2184 2184
 			$newFolderName = $folderName;
2185 2185
 		} else {
2186 2186
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2187
-			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2187
+			$newFolderName = $parent.$HierarchyDelimiter.$folderName;
2188 2188
 		}
2189 2189
 		if (empty($newFolderName)) return false;
2190 2190
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2191
-		if ($this->folderExists($newFolderName,true))
2191
+		if ($this->folderExists($newFolderName, true))
2192 2192
 		{
2193 2193
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2194 2194
 			return $newFolderName;
@@ -2205,7 +2205,7 @@  discard block
 block discarded – undo
2205 2205
 		}
2206 2206
 		catch (Exception $e)
2207 2207
 		{
2208
-			$_error = lang('Could not create Folder %1 Reason: %2',$newFolderName,$e->getMessage());
2208
+			$_error = lang('Could not create Folder %1 Reason: %2', $newFolderName, $e->getMessage());
2209 2209
 			error_log(__METHOD__.' ('.__LINE__.') '.' create Folder '.$newFolderName.'->'.$e->getMessage().' ('.$e->details.') Namespace:'.array2string($this->icServer->getNameSpaces()).function_backtrace());
2210 2210
 			return false;
2211 2211
 		}
@@ -2234,15 +2234,15 @@  discard block
 block discarded – undo
2234 2234
 	 */
2235 2235
 	function renameFolder($_oldFolderName, $_parent, $_folderName)
2236 2236
 	{
2237
-		$oldFolderName	= $_oldFolderName;//$this->_encodeFolderName($_oldFolderName);
2238
-		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2239
-		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2237
+		$oldFolderName = $_oldFolderName; //$this->_encodeFolderName($_oldFolderName);
2238
+		$parent = $_parent; //$this->_encodeFolderName($_parent);
2239
+		$folderName = $_folderName; //$this->_encodeFolderName($_folderName);
2240 2240
 
2241
-		if(empty($parent)) {
2241
+		if (empty($parent)) {
2242 2242
 			$newFolderName = $folderName;
2243 2243
 		} else {
2244 2244
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2245
-			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2245
+			$newFolderName = $parent.$HierarchyDelimiter.$folderName;
2246 2246
 		}
2247 2247
 		if (self::$debug) error_log("create folder: $newFolderName");
2248 2248
 		try
@@ -2251,10 +2251,10 @@  discard block
 block discarded – undo
2251 2251
 		}
2252 2252
 		catch (Exception $e)
2253 2253
 		{
2254
-			throw new egw_exception(__METHOD__." failed for $oldFolderName (rename to: $newFolderName) with error:".$e->getMessage());;
2254
+			throw new egw_exception(__METHOD__." failed for $oldFolderName (rename to: $newFolderName) with error:".$e->getMessage()); ;
2255 2255
 		}
2256 2256
 		// clear FolderExistsInfoCache
2257
-		egw_cache::setCache(egw_cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderInfo,60*60*5);
2257
+		egw_cache::setCache(egw_cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderInfo, 60 * 60 * 5);
2258 2258
 
2259 2259
 		return $newFolderName;
2260 2260
 
@@ -2273,15 +2273,15 @@  discard block
 block discarded – undo
2273 2273
 		//$folderName = $this->_encodeFolderName($_folderName);
2274 2274
 		try
2275 2275
 		{
2276
-			$this->icServer->subscribeMailbox($_folderName,false);
2276
+			$this->icServer->subscribeMailbox($_folderName, false);
2277 2277
 			$this->icServer->deleteMailbox($_folderName);
2278 2278
 		}
2279 2279
 		catch (Exception $e)
2280 2280
 		{
2281
-			throw new egw_exception("Deleting Folder $_folderName failed! Error:".$e->getMessage());;
2281
+			throw new egw_exception("Deleting Folder $_folderName failed! Error:".$e->getMessage()); ;
2282 2282
 		}
2283 2283
 		// clear FolderExistsInfoCache
2284
-		egw_cache::setCache(egw_cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderInfo,60*60*5);
2284
+		egw_cache::setCache(egw_cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderInfo, 60 * 60 * 5);
2285 2285
 
2286 2286
 		return true;
2287 2287
 	}
@@ -2316,10 +2316,10 @@  discard block
 block discarded – undo
2316 2316
 	 *
2317 2317
 	 * @return array with folder objects. eg.: INBOX => {inbox object}
2318 2318
 	 */
2319
-	function getFolderObjects($_subscribedOnly=false, $_getCounters=false, $_alwaysGetDefaultFolders=false,$_useCacheIfPossible=true)
2319
+	function getFolderObjects($_subscribedOnly = false, $_getCounters = false, $_alwaysGetDefaultFolders = false, $_useCacheIfPossible = true)
2320 2320
 	{
2321 2321
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2322
-		if (self::$debugTimes) $starttime = microtime (true);
2322
+		if (self::$debugTimes) $starttime = microtime(true);
2323 2323
 		static $folders2return;
2324 2324
 		//$_subscribedOnly=false;
2325 2325
 		// always use static on single request if info is available;
@@ -2327,42 +2327,42 @@  discard block
 block discarded – undo
2327 2327
 		// set $_useCacheIfPossible to false !
2328 2328
 		if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2329 2329
 		{
2330
-			if (self::$debugTimes) self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2330
+			if (self::$debugTimes) self::logRunTimes($starttime, null, 'using static', __METHOD__.' ('.__LINE__.') ');
2331 2331
 			return $folders2return[$this->icServer->ImapServerId];
2332 2332
 		}
2333 2333
 
2334
-		if ($_subscribedOnly && $_getCounters===false)
2334
+		if ($_subscribedOnly && $_getCounters === false)
2335 2335
 		{
2336
-			if (is_null($folders2return)) $folders2return = egw_cache::getCache(egw_cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2336
+			if (is_null($folders2return)) $folders2return = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
2337 2337
 			if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2338 2338
 			{
2339 2339
 				//error_log(__METHOD__.' ('.__LINE__.') '.' using Cached folderObjects'.array2string($folders2return[$this->icServer->ImapServerId]));
2340
-				if (self::$debugTimes) self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
2340
+				if (self::$debugTimes) self::logRunTimes($starttime, null, 'from Cache', __METHOD__.' ('.__LINE__.') ');
2341 2341
 				return $folders2return[$this->icServer->ImapServerId];
2342 2342
 			}
2343 2343
 		}
2344 2344
 		// use $folderBasicInfo for holding attributes and other basic folderinfo $folderBasicInfo[$this->icServer->ImapServerId]
2345 2345
 		static $folderBasicInfo;
2346
-		if (is_null($folderBasicInfo)||!isset($folderBasicInfo[$this->icServer->ImapServerId])) $folderBasicInfo = egw_cache::getCache(egw_cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2346
+		if (is_null($folderBasicInfo) || !isset($folderBasicInfo[$this->icServer->ImapServerId])) $folderBasicInfo = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
2347 2347
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($folderBasicInfo[$this->icServer->ImapServerId])));
2348 2348
 
2349 2349
 		$delimiter = $this->getHierarchyDelimiter();
2350 2350
 
2351 2351
 		$inboxData = new stdClass;
2352
-		$inboxData->name 		= 'INBOX';
2352
+		$inboxData->name = 'INBOX';
2353 2353
 		$inboxData->folderName		= 'INBOX';
2354
-		$inboxData->displayName		= lang('INBOX');
2354
+		$inboxData->displayName = lang('INBOX');
2355 2355
 		$inboxData->delimiter 		= $delimiter;
2356
-		$inboxData->shortFolderName	= 'INBOX';
2357
-		$inboxData->shortDisplayName	= lang('INBOX');
2356
+		$inboxData->shortFolderName = 'INBOX';
2357
+		$inboxData->shortDisplayName = lang('INBOX');
2358 2358
 		$inboxData->subscribed = true;
2359
-		if($_getCounters == true) {
2359
+		if ($_getCounters == true) {
2360 2360
 			$inboxData->counter = $this->getMailBoxCounters('INBOX');
2361 2361
 		}
2362 2362
 		// force unsubscribed by preference showAllFoldersInFolderPane
2363 2363
 		if ($_subscribedOnly == true &&
2364 2364
 			isset($this->mailPreferences['showAllFoldersInFolderPane']) &&
2365
-			$this->mailPreferences['showAllFoldersInFolderPane']==1)
2365
+			$this->mailPreferences['showAllFoldersInFolderPane'] == 1)
2366 2366
 		{
2367 2367
 			$_subscribedOnly = false;
2368 2368
 		}
@@ -2375,12 +2375,12 @@  discard block
 block discarded – undo
2375 2375
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2376 2376
 		if (is_array($nameSpace))
2377 2377
 		{
2378
-			foreach($nameSpace as $k => $singleNameSpace) {
2378
+			foreach ($nameSpace as $k => $singleNameSpace) {
2379 2379
 				$type = $singleNameSpace['type'];
2380 2380
 				// the following line (assumption that for the same namespace the delimiter should be equal) may be wrong
2381
-				$foldersNameSpace[$type]['delimiter']  = $singleNameSpace['delimiter'];
2381
+				$foldersNameSpace[$type]['delimiter'] = $singleNameSpace['delimiter'];
2382 2382
 
2383
-				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false) {
2383
+				if (is_array($singleNameSpace) && $fetchedAllInOneGo == false) {
2384 2384
 					// fetch and sort the subscribed folders
2385 2385
 					// we alway fetch the subscribed, as this provides the only way to tell
2386 2386
 					// if a folder is subscribed or not
@@ -2388,22 +2388,22 @@  discard block
 block discarded – undo
2388 2388
 					{
2389 2389
 						try
2390 2390
 						{
2391
-							$subscribedMailboxes = $this->icServer->listSubscribedMailboxes('',0,true);
2391
+							$subscribedMailboxes = $this->icServer->listSubscribedMailboxes('', 0, true);
2392 2392
 							if (!empty($subscribedMailboxes))
2393 2393
 							{
2394 2394
 								$fetchedAllInOneGo = true;
2395 2395
 							}
2396 2396
 							else
2397 2397
 							{
2398
-								$subscribedMailboxes = $this->icServer->listSubscribedMailboxes($singleNameSpace['prefix'],0,true);
2398
+								$subscribedMailboxes = $this->icServer->listSubscribedMailboxes($singleNameSpace['prefix'], 0, true);
2399 2399
 							}
2400 2400
 						}
2401
-						catch(Exception $e)
2401
+						catch (Exception $e)
2402 2402
 						{
2403 2403
 							continue;
2404 2404
 						}
2405 2405
 						//echo "subscribedMailboxes";_debug_array($subscribedMailboxes);
2406
-						$subscribedFoldersPerNS = (!empty($subscribedMailboxes)?array_keys($subscribedMailboxes):array());
2406
+						$subscribedFoldersPerNS = (!empty($subscribedMailboxes) ? array_keys($subscribedMailboxes) : array());
2407 2407
 						//if (is_array($foldersNameSpace[$type]['subscribed'])) sort($foldersNameSpace[$type]['subscribed']);
2408 2408
 						//_debug_array($foldersNameSpace);
2409 2409
 						//error_log(__METHOD__.__LINE__.array2string($singleNameSpace).':#:'.array2string($subscribedFoldersPerNS));
@@ -2413,18 +2413,18 @@  discard block
 block discarded – undo
2413 2413
 							foreach ($subscribedMailboxes as $k => $finfo)
2414 2414
 							{
2415 2415
 								//error_log(__METHOD__.__LINE__.$k.':#:'.array2string($finfo));
2416
-								$subscribedFoldersForCache[$this->icServer->ImapServerId][$k]=
2417
-								$folderBasicInfo[$this->icServer->ImapServerId][$k]=array(
2416
+								$subscribedFoldersForCache[$this->icServer->ImapServerId][$k] =
2417
+								$folderBasicInfo[$this->icServer->ImapServerId][$k] = array(
2418 2418
 									'MAILBOX'=>$finfo['MAILBOX'],
2419 2419
 									'ATTRIBUTES'=>$finfo['ATTRIBUTES'],
2420
-									'delimiter'=>$finfo['delimiter'],//lowercase for some reason???
2421
-									'SUBSCRIBED'=>$finfo['SUBSCRIBED'],//seeded by getMailboxes
2420
+									'delimiter'=>$finfo['delimiter'], //lowercase for some reason???
2421
+									'SUBSCRIBED'=>$finfo['SUBSCRIBED'], //seeded by getMailboxes
2422 2422
 								);
2423
-								if (empty($foldersNameSpace[$type]['subscribed']) || !in_array($k,$foldersNameSpace[$type]['subscribed']))
2423
+								if (empty($foldersNameSpace[$type]['subscribed']) || !in_array($k, $foldersNameSpace[$type]['subscribed']))
2424 2424
 								{
2425 2425
 									$foldersNameSpace[$type]['subscribed'][] = $k;
2426 2426
 								}
2427
-								if (empty($foldersNameSpace[$type]['all']) || !in_array($k,$foldersNameSpace[$type]['all']))
2427
+								if (empty($foldersNameSpace[$type]['all']) || !in_array($k, $foldersNameSpace[$type]['all']))
2428 2428
 								{
2429 2429
 									$foldersNameSpace[$type]['all'][] = $k;
2430 2430
 								}
@@ -2447,7 +2447,7 @@  discard block
 block discarded – undo
2447 2447
 						// that may produce problems, when encountering recursions probably
2448 2448
 						// horde is handling that, so we do not; keep that in mind!
2449 2449
 						//$allMailboxesExt = $this->icServer->getMailboxes($singleNameSpace['prefix'],2,true);
2450
-						$allMailboxesExt = $this->icServer->getMailboxes($singleNameSpace['prefix'],0,true);
2450
+						$allMailboxesExt = $this->icServer->getMailboxes($singleNameSpace['prefix'], 0, true);
2451 2451
 					}
2452 2452
 					catch (Exception $e)
2453 2453
 					{
@@ -2465,26 +2465,26 @@  discard block
 block discarded – undo
2465 2465
 					foreach ($allMailboxesExt as $mbx) {
2466 2466
 						if (!isset($folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]))
2467 2467
 						{
2468
-							$folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]=array(
2468
+							$folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']] = array(
2469 2469
 								'MAILBOX'=>$mbx['MAILBOX'],
2470 2470
 								'ATTRIBUTES'=>$mbx['ATTRIBUTES'],
2471
-								'delimiter'=>$mbx['delimiter'],//lowercase for some reason???
2472
-								'SUBSCRIBED'=>$mbx['SUBSCRIBED'],//seeded by getMailboxes
2471
+								'delimiter'=>$mbx['delimiter'], //lowercase for some reason???
2472
+								'SUBSCRIBED'=>$mbx['SUBSCRIBED'], //seeded by getMailboxes
2473 2473
 							);
2474 2474
 							if ($mbx['SUBSCRIBED'] && !isset($subscribedFoldersForCache[$this->icServer->ImapServerId][$mbx['MAILBOX']]))
2475 2475
 							{
2476 2476
 								$subscribedFoldersForCache[$this->icServer->ImapServerId][$mbx['MAILBOX']] = $folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']];
2477 2477
 							}
2478 2478
 						}
2479
-						if ($mbx['SUBSCRIBED'] && (empty($foldersNameSpace[$type]['subscribed']) || !in_array($mbx['MAILBOX'],$foldersNameSpace[$type]['subscribed'])))
2479
+						if ($mbx['SUBSCRIBED'] && (empty($foldersNameSpace[$type]['subscribed']) || !in_array($mbx['MAILBOX'], $foldersNameSpace[$type]['subscribed'])))
2480 2480
 						{
2481 2481
 							$foldersNameSpace[$type]['subscribed'][] = $mbx['MAILBOX'];
2482 2482
 						}
2483 2483
 						//echo __METHOD__;_debug_array($mbx);
2484 2484
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx));
2485
-						if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']])||
2486
-							isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']])||
2487
-							(substr($mbx['MAILBOX'],-1)==$foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'],0,-1)]))
2485
+						if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']]) ||
2486
+							isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']]) ||
2487
+							(substr($mbx['MAILBOX'], -1) == $foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'], 0, -1)]))
2488 2488
 						) continue;
2489 2489
 
2490 2490
 						//echo '#'.$mbx['MAILBOX'].':'.array2string($mbx)."#<br>";
@@ -2494,7 +2494,7 @@  discard block
 block discarded – undo
2494 2494
 					//_debug_array(array_keys($allMailBoxesExtSorted));
2495 2495
 					$allMailboxes = array();
2496 2496
 					foreach ((array)$allMailBoxesExtSorted as $mbx) {
2497
-						if (!in_array($mbx['MAILBOX'],$allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
2497
+						if (!in_array($mbx['MAILBOX'], $allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
2498 2498
 						//echo "Result:";_debug_array($allMailboxes);
2499 2499
 					}
2500 2500
 					$foldersNameSpace[$type]['all'] = $allMailboxes;
@@ -2503,57 +2503,57 @@  discard block
 block discarded – undo
2503 2503
 			}
2504 2504
 		}
2505 2505
 		//subscribed folders may be used in getFolderStatus
2506
-		egw_cache::setCache(egw_cache::INSTANCE,'email','subscribedFolders'.trim($GLOBALS['egw_info']['user']['account_id']),$subscribedFoldersForCache,$expiration=60*60*1);
2506
+		egw_cache::setCache(egw_cache::INSTANCE, 'email', 'subscribedFolders'.trim($GLOBALS['egw_info']['user']['account_id']), $subscribedFoldersForCache, $expiration = 60 * 60 * 1);
2507 2507
 		//echo "<br>FolderNameSpace To Process:";_debug_array($foldersNameSpace);
2508 2508
 		$autoFolderObjects = $folders = array();
2509 2509
 		$autofolder_exists = array();
2510
-		foreach( array('personal', 'others', 'shared') as $type) {
2511
-			if(isset($foldersNameSpace[$type])) {
2512
-				if($_subscribedOnly) {
2513
-					if( !empty($foldersNameSpace[$type]['subscribed']) ) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
2510
+		foreach (array('personal', 'others', 'shared') as $type) {
2511
+			if (isset($foldersNameSpace[$type])) {
2512
+				if ($_subscribedOnly) {
2513
+					if (!empty($foldersNameSpace[$type]['subscribed'])) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
2514 2514
 				} else {
2515
-					if( !empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
2515
+					if (!empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
2516 2516
 				}
2517
-				foreach((array)$listOfFolders as $folderName) {
2517
+				foreach ((array)$listOfFolders as $folderName) {
2518 2518
 					//echo "<br>FolderToCheck:$folderName<br>";
2519 2519
 					//error_log(__METHOD__.__LINE__.'#Delimiter:'.$delimiter.':#'.$folderName);
2520
-					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue;//when subscribedonly, we fetch all folders in one go.
2521
-					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
2520
+					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue; //when subscribedonly, we fetch all folders in one go.
2521
+					if ($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all']) || in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
2522 2522
 						#echo "$folderName failed to be here <br>";
2523 2523
 						continue;
2524 2524
 					}
2525 2525
 					if (isset($folders[$folderName])) continue;
2526 2526
 					if (isset($autoFolderObjects[$folderName])) continue;
2527
-					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter'];
2527
+					if (empty($delimiter) || $delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter'];
2528 2528
 					$folderParts = explode($delimiter, $folderName);
2529 2529
 					$shortName = array_pop($folderParts);
2530 2530
 
2531 2531
 					$folderObject = new stdClass;
2532
-					$folderObject->delimiter	= $delimiter;
2533
-					$folderObject->folderName	= $folderName;
2534
-					$folderObject->shortFolderName	= $shortName;
2535
-					if(!$_subscribedOnly) {
2532
+					$folderObject->delimiter = $delimiter;
2533
+					$folderObject->folderName = $folderName;
2534
+					$folderObject->shortFolderName = $shortName;
2535
+					if (!$_subscribedOnly) {
2536 2536
 						#echo $folderName."->".$type."<br>";
2537 2537
 						#_debug_array($foldersNameSpace[$type]['subscribed']);
2538 2538
 						$folderObject->subscribed = in_array($folderName, (array)$foldersNameSpace[$type]['subscribed']);
2539 2539
 					}
2540 2540
 
2541
-					if($_getCounters == true) {
2541
+					if ($_getCounters == true) {
2542 2542
 						//error_log(__METHOD__.' ('.__LINE__.') '.' getCounter forFolder:'.$folderName);
2543 2543
 						$folderObject->counter = $this->getMailBoxCounters($folderName);
2544 2544
 					}
2545
-					if(strtoupper($folderName) == 'INBOX') {
2545
+					if (strtoupper($folderName) == 'INBOX') {
2546 2546
 						$folderName = 'INBOX';
2547
-						$folderObject->folderName	= 'INBOX';
2548
-						$folderObject->shortFolderName	= 'INBOX';
2549
-						$folderObject->displayName	= lang('INBOX');
2547
+						$folderObject->folderName = 'INBOX';
2548
+						$folderObject->shortFolderName = 'INBOX';
2549
+						$folderObject->displayName = lang('INBOX');
2550 2550
 						$folderObject->shortDisplayName = lang('INBOX');
2551
-						$folderObject->subscribed	= true;
2551
+						$folderObject->subscribed = true;
2552 2552
 					// translate the automatic Folders (Sent, Drafts, ...) like the INBOX
2553
-					} elseif (in_array($shortName,self::$autoFolders)) {
2554
-						$tmpfolderparts = explode($delimiter,$folderObject->folderName);
2553
+					} elseif (in_array($shortName, self::$autoFolders)) {
2554
+						$tmpfolderparts = explode($delimiter, $folderObject->folderName);
2555 2555
 						array_pop($tmpfolderparts);
2556
-						$folderObject->displayName = implode($delimiter,$tmpfolderparts).$delimiter.lang($shortName);
2556
+						$folderObject->displayName = implode($delimiter, $tmpfolderparts).$delimiter.lang($shortName);
2557 2557
 						$folderObject->shortDisplayName = lang($shortName);
2558 2558
 						unset($tmpfolderparts);
2559 2559
 					} else {
@@ -2561,13 +2561,13 @@  discard block
 block discarded – undo
2561 2561
 						$folderObject->shortDisplayName = $shortName;
2562 2562
 					}
2563 2563
 					//$folderName = $folderName;
2564
-					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false) {
2564
+					if (in_array($shortName, self::$autoFolders) && self::searchValueInFolderObjects($shortName, $autoFolderObjects) === false) {
2565 2565
 						$autoFolderObjects[$folderName] = $folderObject;
2566 2566
 					} else {
2567 2567
 						$folders[$folderName] = $folderObject;
2568 2568
 					}
2569 2569
 					//error_log(__METHOD__.' ('.__LINE__.') '.':'.$folderObject->folderName);
2570
-					if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders ();
2570
+					if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders();
2571 2571
 					if (isset(self::$specialUseFolders[$folderName]))
2572 2572
 					{
2573 2573
 						$autofolder_exists[$folderName] = self::$specialUseFolders[$folderName];
@@ -2576,27 +2576,27 @@  discard block
 block discarded – undo
2576 2576
 			}
2577 2577
 		}
2578 2578
 		if (is_array($autoFolderObjects) && !empty($autoFolderObjects)) {
2579
-			uasort($autoFolderObjects,array($this,"sortByAutoFolderPos"));
2579
+			uasort($autoFolderObjects, array($this, "sortByAutoFolderPos"));
2580 2580
 		}
2581 2581
 		// check if some standard folders are missing and need to be created
2582 2582
 		if (count($autofolder_exists) < count(self::$autoFolders) && $this->check_create_autofolders($autofolder_exists))
2583 2583
 		{
2584 2584
 			// if new folders have been created, re-read folders ignoring the cache
2585
-			return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false);	// false = do NOT use cache
2585
+			return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false); // false = do NOT use cache
2586 2586
 		}
2587
-		if (is_array($folders)) uasort($folders,array($this,"sortByDisplayName"));
2587
+		if (is_array($folders)) uasort($folders, array($this, "sortByDisplayName"));
2588 2588
 		//$folders2return = array_merge($autoFolderObjects,$folders);
2589 2589
 		//_debug_array($folders2return); #exit;
2590
-		$folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject,(array)$autoFolderObjects,(array)$folders);
2591
-		if (($_subscribedOnly && $_getCounters===false) ||
2592
-			($_subscribedOnly == false && $_getCounters===false &&
2590
+		$folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject, (array)$autoFolderObjects, (array)$folders);
2591
+		if (($_subscribedOnly && $_getCounters === false) ||
2592
+			($_subscribedOnly == false && $_getCounters === false &&
2593 2593
 			isset($this->mailPreferences['showAllFoldersInFolderPane']) &&
2594
-			$this->mailPreferences['showAllFoldersInFolderPane']==1))
2594
+			$this->mailPreferences['showAllFoldersInFolderPane'] == 1))
2595 2595
 		{
2596
-			egw_cache::setCache(egw_cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$folders2return,$expiration=60*60*1);
2596
+			egw_cache::setCache(egw_cache::INSTANCE, 'email', 'folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']), $folders2return, $expiration = 60 * 60 * 1);
2597 2597
 		}
2598
-		egw_cache::setCache(egw_cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderBasicInfo,$expiration=60*60*1);
2599
-		if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
2598
+		egw_cache::setCache(egw_cache::INSTANCE, 'email', 'folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderBasicInfo, $expiration = 60 * 60 * 1);
2599
+		if (self::$debugTimes) self::logRunTimes($starttime, null, function_backtrace(), __METHOD__.' ('.__LINE__.') ');
2600 2600
 		return $folders2return[$this->icServer->ImapServerId];
2601 2601
 	}
2602 2602
 
@@ -2617,21 +2617,21 @@  discard block
 block discarded – undo
2617 2617
 	 *
2618 2618
 	 * @return array arrays of folders
2619 2619
 	 */
2620
-	function getFolderArrays ($_nodePath = null, $_onlyTopLevel = false, $_search= 2, $_subscribedOnly = false, $_getCounter = false)
2620
+	function getFolderArrays($_nodePath = null, $_onlyTopLevel = false, $_search = 2, $_subscribedOnly = false, $_getCounter = false)
2621 2621
 	{
2622 2622
 		// delimiter
2623 2623
 		$delimiter = $this->getHierarchyDelimiter();
2624 2624
 
2625
-		$folders = $nameSpace =  array();
2625
+		$folders = $nameSpace = array();
2626 2626
 		$nameSpaceTmp = $this->_getNameSpaces();
2627
-		foreach($nameSpaceTmp as $k => $singleNameSpace) {
2628
-			$nameSpace[$singleNameSpace['type']]=$singleNameSpace;
2627
+		foreach ($nameSpaceTmp as $k => $singleNameSpace) {
2628
+			$nameSpace[$singleNameSpace['type']] = $singleNameSpace;
2629 2629
 		}
2630 2630
 		unset($nameSpaceTmp);
2631 2631
 
2632 2632
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2633 2633
 		// Get special use folders
2634
-		if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders (); // Set self::$specialUseFolders
2634
+		if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders(); // Set self::$specialUseFolders
2635 2635
 		// topLevelQueries generally ignore the $_search param. Except for Config::examineNamespace
2636 2636
 		if ($_onlyTopLevel) // top level leaves
2637 2637
 		{
@@ -2642,20 +2642,20 @@  discard block
 block discarded – undo
2642 2642
 			if (is_null(self::$mailConfig)) self::$mailConfig = config::read('mail');
2643 2643
 			if (self::$mailConfig['examineNamespace'])
2644 2644
 			{
2645
-				$prefixes=array();
2645
+				$prefixes = array();
2646 2646
 				if (is_array($nameSpace))
2647 2647
 				{
2648
-					foreach($nameSpace as $k => $singleNameSpace) {
2648
+					foreach ($nameSpace as $k => $singleNameSpace) {
2649 2649
 						$type = $singleNameSpace['type'];
2650 2650
 
2651
-						if(is_array($singleNameSpace) && $singleNameSpace['prefix']){
2651
+						if (is_array($singleNameSpace) && $singleNameSpace['prefix']) {
2652 2652
 							$prefixes[$type] = $singleNameSpace['prefix'];
2653 2653
 							//regard extra care for nameSpacequeries when configured AND respect $_search
2654
-							$result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search==0?0:2, true);
2654
+							$result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search == 0 ? 0 : 2, true);
2655 2655
 							if (is_array($result))
2656 2656
 							{
2657 2657
 								ksort($result);
2658
-								$topFolders = array_merge($topFolders,$result);
2658
+								$topFolders = array_merge($topFolders, $result);
2659 2659
 							}
2660 2660
 						}
2661 2661
 					}
@@ -2664,7 +2664,7 @@  discard block
 block discarded – undo
2664 2664
 
2665 2665
 			$autofolders = array();
2666 2666
 
2667
-			foreach(self::$specialUseFolders as $path => $folder)
2667
+			foreach (self::$specialUseFolders as $path => $folder)
2668 2668
 			{
2669 2669
 				if ($this->folderExists($path))
2670 2670
 				{
@@ -2672,9 +2672,9 @@  discard block
 block discarded – undo
2672 2672
 				}
2673 2673
 			}
2674 2674
 			// Check if the special use folders are there, otherwise try to create them
2675
-			if (count($autofolders) < count(self::$autoFolders) && $this->check_create_autofolders ($autofolders))
2675
+			if (count($autofolders) < count(self::$autoFolders) && $this->check_create_autofolders($autofolders))
2676 2676
 			{
2677
-				return $this->getFolderArrays ($_nodePath, $_onlyTopLevel, $_search, $_subscribedOnly, $_getCounter);
2677
+				return $this->getFolderArrays($_nodePath, $_onlyTopLevel, $_search, $_subscribedOnly, $_getCounter);
2678 2678
 			}
2679 2679
 
2680 2680
 			// now process topFolders for next level
@@ -2682,13 +2682,13 @@  discard block
 block discarded – undo
2682 2682
 			{
2683 2683
 				$pattern = "/\\".$delimiter."/";
2684 2684
 				$reference = preg_replace($pattern, '', $node['MAILBOX']);
2685
-				if(!empty($prefixes))
2685
+				if (!empty($prefixes))
2686 2686
 				{
2687 2687
 					$reference = '';
2688
-					$tmpArray = explode($delimiter,$node['MAILBOX']);
2689
-					foreach($tmpArray as $p)
2688
+					$tmpArray = explode($delimiter, $node['MAILBOX']);
2689
+					foreach ($tmpArray as $p)
2690 2690
 					{
2691
-						$reference = empty($reference)?$p:$reference.$delimiter.$p;
2691
+						$reference = empty($reference) ? $p : $reference.$delimiter.$p;
2692 2692
 					}
2693 2693
 				}
2694 2694
 				$mainFolder = $subFolders = array();
@@ -2724,19 +2724,19 @@  discard block
 block discarded – undo
2724 2724
 							$nFolders [$path] = $folder;
2725 2725
 						}
2726 2726
 					}
2727
-					if (is_array($aFolders)) uasort ($aFolders, array($this,'sortByAutofolder'));
2727
+					if (is_array($aFolders)) uasort($aFolders, array($this, 'sortByAutofolder'));
2728 2728
 					//ksort($aFolders);
2729 2729
 
2730 2730
 					// Sort none auto folders base on mailbox name
2731
-					uasort($nFolders,array($this,'sortByMailbox'));
2731
+					uasort($nFolders, array($this, 'sortByMailbox'));
2732 2732
 
2733
-					$subFolders = array_merge($aFolders,$nFolders);
2733
+					$subFolders = array_merge($aFolders, $nFolders);
2734 2734
 				}
2735 2735
 				else
2736 2736
 				{
2737 2737
 					if (is_array($subFolders)) ksort($subFolders);
2738 2738
 				}
2739
-				$folders = array_merge($folders,(array)$mainFolder, (array)$subFolders);
2739
+				$folders = array_merge($folders, (array)$mainFolder, (array)$subFolders);
2740 2740
 			}
2741 2741
 		}
2742 2742
 		elseif ($_nodePath) // single node
@@ -2763,9 +2763,9 @@  discard block
 block discarded – undo
2763 2763
 				$folders = $this->icServer->getMailboxes($path, $_search, true);
2764 2764
 			}
2765 2765
 
2766
-			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
2766
+			uasort($folders, array($this, 'sortByMailbox')); //ksort($folders);
2767 2767
 		}
2768
-		elseif(!$_nodePath) // all
2768
+		elseif (!$_nodePath) // all
2769 2769
 		{
2770 2770
 			if ($_subscribedOnly)
2771 2771
 			{
@@ -2781,98 +2781,98 @@  discard block
 block discarded – undo
2781 2781
 		{
2782 2782
 			// SORTING FOLDERS
2783 2783
 			//self::$debugTimes=true;
2784
-			if (self::$debugTimes) $starttime = microtime (true);
2784
+			if (self::$debugTimes) $starttime = microtime(true);
2785 2785
 			// Merge of all auto folders and specialusefolders
2786 2786
 			$autoFoldersTmp = array_unique((array_merge(self::$autoFolders, array_values(self::$specialUseFolders))));
2787
-			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
2787
+			uasort($folders, array($this, 'sortByMailbox')); //ksort($folders);
2788 2788
 			$tmpFolders = $folders;
2789
-			$inboxFolderObject=$inboxSubFolderObjects=$autoFolderObjects=$typeFolderObject=$mySpecialUseFolders=array();
2790
-			$googleMailFolderObject=$googleAutoFolderObjects=$googleSubFolderObjects=array();
2791
-			$isGoogleMail=false;
2792
-			foreach($autoFoldersTmp as $afk=>$aF)
2789
+			$inboxFolderObject = $inboxSubFolderObjects = $autoFolderObjects = $typeFolderObject = $mySpecialUseFolders = array();
2790
+			$googleMailFolderObject = $googleAutoFolderObjects = $googleSubFolderObjects = array();
2791
+			$isGoogleMail = false;
2792
+			foreach ($autoFoldersTmp as $afk=>$aF)
2793 2793
 			{
2794
-				if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
2794
+				if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF] = $this->getFolderByType($aF, false);
2795 2795
 				//error_log($afk.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
2796 2796
 			}
2797 2797
 			//error_log(array2string($mySpecialUseFolders));
2798 2798
 			foreach ($tmpFolders as $k => $f) {
2799
-				$sorted=false;
2800
-				if (strtoupper(substr($k,0,5))=='INBOX') {
2801
-					if (strtoupper($k)=='INBOX') {
2799
+				$sorted = false;
2800
+				if (strtoupper(substr($k, 0, 5)) == 'INBOX') {
2801
+					if (strtoupper($k) == 'INBOX') {
2802 2802
 						//error_log(__METHOD__.__LINE__.':'.strtoupper(substr($k,0,5)).':'.$k);
2803
-						$inboxFolderObject[$k]=$f;
2803
+						$inboxFolderObject[$k] = $f;
2804 2804
 						unset($folders[$k]);
2805
-						$sorted=true;
2805
+						$sorted = true;
2806 2806
 					} else {
2807
-						$isAutoFolder=false;
2808
-						foreach($autoFoldersTmp as $afk=>$aF)
2807
+						$isAutoFolder = false;
2808
+						foreach ($autoFoldersTmp as $afk=>$aF)
2809 2809
 						{
2810 2810
 							//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
2811
-							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
2812
-								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter))
2811
+							if ($aF && strlen($mySpecialUseFolders[$aF]) && /*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
2812
+								($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter))
2813 2813
 							{
2814 2814
 								//error_log($k.'->'.$mySpecialUseFolders[$aF]);
2815
-								$isAutoFolder=true;
2816
-								$autoFolderObjects[$k]=$f;
2815
+								$isAutoFolder = true;
2816
+								$autoFolderObjects[$k] = $f;
2817 2817
 								break;
2818 2818
 							}
2819 2819
 						}
2820
-						if ($isAutoFolder==false) $inboxSubFolderObjects[$k]=$f;
2820
+						if ($isAutoFolder == false) $inboxSubFolderObjects[$k] = $f;
2821 2821
 						unset($folders[$k]);
2822
-						$sorted=true;
2822
+						$sorted = true;
2823 2823
 					}
2824
-				} elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]') {
2825
-					$isGoogleMail=true;
2826
-					if (strtoupper($k)=='[GOOGLE MAIL]') {
2827
-						$googleMailFolderObject[$k]=$f;
2824
+				} elseif (strtoupper(substr($k, 0, 13)) == '[GOOGLE MAIL]') {
2825
+					$isGoogleMail = true;
2826
+					if (strtoupper($k) == '[GOOGLE MAIL]') {
2827
+						$googleMailFolderObject[$k] = $f;
2828 2828
 						unset($folders[$k]);
2829
-						$sorted=true;
2829
+						$sorted = true;
2830 2830
 					} else {
2831
-						$isAutoFolder=false;
2832
-						foreach($autoFoldersTmp as $afk=>$aF)
2831
+						$isAutoFolder = false;
2832
+						foreach ($autoFoldersTmp as $afk=>$aF)
2833 2833
 						{
2834 2834
 							//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
2835
-							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
2836
-								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter))
2835
+							if ($aF && strlen($mySpecialUseFolders[$aF]) && /*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
2836
+								($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter))
2837 2837
 							{
2838 2838
 								//error_log($k.'->'.$mySpecialUseFolders[$aF]);
2839
-								$isAutoFolder=true;
2840
-								$googleAutoFolderObjects[$k]=$f;
2839
+								$isAutoFolder = true;
2840
+								$googleAutoFolderObjects[$k] = $f;
2841 2841
 								break;
2842 2842
 							}
2843 2843
 						}
2844
-						if ($isAutoFolder==false) $googleSubFolderObjects[$k]=$f;
2844
+						if ($isAutoFolder == false) $googleSubFolderObjects[$k] = $f;
2845 2845
 						unset($folders[$k]);
2846
-						$sorted=true;
2846
+						$sorted = true;
2847 2847
 					}
2848 2848
 				} else {
2849
-					$isAutoFolder=false;
2850
-					foreach($autoFoldersTmp as $afk=>$aF)
2849
+					$isAutoFolder = false;
2850
+					foreach ($autoFoldersTmp as $afk=>$aF)
2851 2851
 					{
2852 2852
 						//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
2853
-						if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
2854
-								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter))
2853
+						if ($aF && strlen($mySpecialUseFolders[$aF]) && /*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
2854
+								($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter))
2855 2855
 						{
2856 2856
 							//error_log($k.'->'.$mySpecialUseFolders[$aF]);
2857
-							$isAutoFolder=true;
2858
-							$autoFolderObjects[$k]=$f;
2857
+							$isAutoFolder = true;
2858
+							$autoFolderObjects[$k] = $f;
2859 2859
 							unset($folders[$k]);
2860
-							$sorted=true;
2860
+							$sorted = true;
2861 2861
 							break;
2862 2862
 						}
2863 2863
 					}
2864 2864
 				}
2865 2865
 
2866
-				if ($sorted==false)
2866
+				if ($sorted == false)
2867 2867
 				{
2868
-					foreach(array('others','shared') as $type)
2868
+					foreach (array('others', 'shared') as $type)
2869 2869
 					{
2870
-						if ($nameSpace[$type]['prefix_present']&&$nameSpace[$type]['prefix'])
2870
+						if ($nameSpace[$type]['prefix_present'] && $nameSpace[$type]['prefix'])
2871 2871
 						{
2872
-							if (substr($k,0,strlen($nameSpace[$type]['prefix']))==$nameSpace[$type]['prefix']||
2873
-								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1)) {
2872
+							if (substr($k, 0, strlen($nameSpace[$type]['prefix'])) == $nameSpace[$type]['prefix'] ||
2873
+								substr($k, 0, strlen($nameSpace[$type]['prefix']) - strlen($nameSpace[$type]['delimiter'])) == substr($nameSpace[$type]['prefix'], 0, strlen($nameSpace[$type]['delimiter']) * -1)) {
2874 2874
 								//error_log(__METHOD__.__LINE__.':'.substr($k,0,strlen($nameSpace[$type]['prefix'])).':'.$k);
2875
-								$typeFolderObject[$type][$k]=$f;
2875
+								$typeFolderObject[$type][$k] = $f;
2876 2876
 								unset($folders[$k]);
2877 2877
 							}
2878 2878
 						}
@@ -2883,38 +2883,38 @@  discard block
 block discarded – undo
2883 2883
 			// avoid calling sortByAutoFolder as it is not regarding subfolders
2884 2884
 			$autoFolderObjectsTmp = $autoFolderObjects;
2885 2885
 			unset($autoFolderObjects);
2886
-			uasort($autoFolderObjectsTmp, array($this,'sortByMailbox'));
2887
-			foreach($autoFoldersTmp as $afk=>$aF)
2886
+			uasort($autoFolderObjectsTmp, array($this, 'sortByMailbox'));
2887
+			foreach ($autoFoldersTmp as $afk=>$aF)
2888 2888
 			{
2889
-				foreach($autoFolderObjectsTmp as $k => $f)
2889
+				foreach ($autoFolderObjectsTmp as $k => $f)
2890 2890
 				{
2891
-					if($aF && ($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter))
2891
+					if ($aF && ($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter))
2892 2892
 					{
2893
-						$autoFolderObjects[$k]=$f;
2893
+						$autoFolderObjects[$k] = $f;
2894 2894
 					}
2895 2895
 				}
2896 2896
 			}
2897 2897
 			//error_log(__METHOD__.__LINE__.array2string($autoFolderObjects));
2898 2898
 			if (!$isGoogleMail) {
2899
-				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$inboxSubFolderObjects,(array)$folders,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
2899
+				$folders = array_merge($inboxFolderObject, $autoFolderObjects, (array)$inboxSubFolderObjects, (array)$folders, (array)$typeFolderObject['others'], (array)$typeFolderObject['shared']);
2900 2900
 			} else {
2901 2901
 				// avoid calling sortByAutoFolder as it is not regarding subfolders
2902 2902
 				$gAutoFolderObjectsTmp = $googleAutoFolderObjects;
2903 2903
 				unset($googleAutoFolderObjects);
2904
-				uasort($gAutoFolderObjectsTmp, array($this,'sortByMailbox'));
2905
-				foreach($autoFoldersTmp as $afk=>$aF)
2904
+				uasort($gAutoFolderObjectsTmp, array($this, 'sortByMailbox'));
2905
+				foreach ($autoFoldersTmp as $afk=>$aF)
2906 2906
 				{
2907
-					foreach($gAutoFolderObjectsTmp as $k => $f)
2907
+					foreach ($gAutoFolderObjectsTmp as $k => $f)
2908 2908
 					{
2909
-						if($aF && ($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter))
2909
+						if ($aF && ($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter))
2910 2910
 						{
2911
-							$googleAutoFolderObjects[$k]=$f;
2911
+							$googleAutoFolderObjects[$k] = $f;
2912 2912
 						}
2913 2913
 					}
2914 2914
 				}
2915
-				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$folders,(array)$googleMailFolderObject,$googleAutoFolderObjects,$googleSubFolderObjects,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
2915
+				$folders = array_merge($inboxFolderObject, $autoFolderObjects, (array)$folders, (array)$googleMailFolderObject, $googleAutoFolderObjects, $googleSubFolderObjects, (array)$typeFolderObject['others'], (array)$typeFolderObject['shared']);
2916 2916
 			}
2917
-			if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
2917
+			if (self::$debugTimes) self::logRunTimes($starttime, null, function_backtrace(), __METHOD__.' ('.__LINE__.') Sorting:');
2918 2918
 			//self::$debugTimes=false;
2919 2919
 		}
2920 2920
 		// Get counter information and add them to each fetched folders array
@@ -2936,10 +2936,10 @@  discard block
 block discarded – undo
2936 2936
 	 * @param array $autofolders_exists existing folders, no need to check their existance again
2937 2937
 	 * @return int number of new folders created
2938 2938
 	 */
2939
-	function check_create_autofolders(array $autofolders_exists=array())
2939
+	function check_create_autofolders(array $autofolders_exists = array())
2940 2940
 	{
2941 2941
 		$num_created = 0;
2942
-		foreach(self::$autoFolders as $folder)
2942
+		foreach (self::$autoFolders as $folder)
2943 2943
 		{
2944 2944
 			$created = false;
2945 2945
 			if (!in_array($folder, $autofolders_exists) && $this->_getSpecialUseFolder($folder, true, $created) &&
@@ -2964,7 +2964,7 @@  discard block
 block discarded – undo
2964 2964
 		$rv = false;
2965 2965
 		foreach ($haystack as $k => $v)
2966 2966
 		{
2967
-			foreach($v as &$sv) {if (trim($sv)==trim($needle)) return $k;}
2967
+			foreach ($v as &$sv) {if (trim($sv) == trim($needle)) return $k; }
2968 2968
 		}
2969 2969
 		return $rv;
2970 2970
 	}
@@ -2977,9 +2977,9 @@  discard block
 block discarded – undo
2977 2977
 	 * @param array $b array of folders
2978 2978
 	 * @return int expect values (0, 1 or -1)
2979 2979
 	 */
2980
-	function sortByMailbox($a,$b)
2980
+	function sortByMailbox($a, $b)
2981 2981
 	{
2982
-		return strcasecmp($a['MAILBOX'],$b['MAILBOX']);
2982
+		return strcasecmp($a['MAILBOX'], $b['MAILBOX']);
2983 2983
 	}
2984 2984
 
2985 2985
 	/**
@@ -2990,13 +2990,13 @@  discard block
 block discarded – undo
2990 2990
 	 * @param array $b
2991 2991
 	 * @return int expect values (0, 1 or -1)
2992 2992
 	 */
2993
-	function sortByAutoFolder($a,$b)
2993
+	function sortByAutoFolder($a, $b)
2994 2994
 	{
2995 2995
 		// 0, 1 und -1
2996 2996
 		$a = mail_tree::pathToFolderData($a['MAILBOX'], $a['delimiter']);
2997 2997
 		$b = mail_tree::pathToFolderData($b['MAILBOX'], $b['delimiter']);
2998
-		$pos1 = array_search(trim($a['name']),self::$autoFolders);
2999
-		$pos2 = array_search(trim($b['name']),self::$autoFolders);
2998
+		$pos1 = array_search(trim($a['name']), self::$autoFolders);
2999
+		$pos2 = array_search(trim($b['name']), self::$autoFolders);
3000 3000
 		if ($pos1 == $pos2) return 0;
3001 3001
 		return ($pos1 < $pos2) ? -1 : 1;
3002 3002
 	}
@@ -3009,10 +3009,10 @@  discard block
 block discarded – undo
3009 3009
 	 * @param object $b array of folderobjects
3010 3010
 	 * @return int expect values (0, 1 or -1)
3011 3011
 	 */
3012
-	function sortByDisplayName($a,$b)
3012
+	function sortByDisplayName($a, $b)
3013 3013
 	{
3014 3014
 		// 0, 1 und -1
3015
-		return strcasecmp($a->displayName,$b->displayName);
3015
+		return strcasecmp($a->displayName, $b->displayName);
3016 3016
 	}
3017 3017
 
3018 3018
 	/**
@@ -3023,11 +3023,11 @@  discard block
 block discarded – undo
3023 3023
 	 * @param object $b array of folderobjects
3024 3024
 	 * @return int expect values (0, 1 or -1)
3025 3025
 	 */
3026
-	function sortByAutoFolderPos($a,$b)
3026
+	function sortByAutoFolderPos($a, $b)
3027 3027
 	{
3028 3028
 		// 0, 1 und -1
3029
-		$pos1 = array_search(trim($a->shortFolderName),self::$autoFolders);
3030
-		$pos2 = array_search(trim($b->shortFolderName),self::$autoFolders);
3029
+		$pos1 = array_search(trim($a->shortFolderName), self::$autoFolders);
3030
+		$pos2 = array_search(trim($b->shortFolderName), self::$autoFolders);
3031 3031
 		if ($pos1 == $pos2) return 0;
3032 3032
 		return ($pos1 < $pos2) ? -1 : 1;
3033 3033
 	}
@@ -3040,7 +3040,7 @@  discard block
 block discarded – undo
3040 3040
 	 * @param boolean $_returnObject return the counters as object rather than an array
3041 3041
 	 * @return mixed false or array of counters array(MESSAGES,UNSEEN,RECENT,UIDNEXT,UIDVALIDITY) or object
3042 3042
 	 */
3043
-	function getMailBoxCounters($folderName,$_returnObject=true)
3043
+	function getMailBoxCounters($folderName, $_returnObject = true)
3044 3044
 	{
3045 3045
 		try
3046 3046
 		{
@@ -3052,9 +3052,9 @@  discard block
 block discarded – undo
3052 3052
 			if (self::$debug) error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3053 3053
 			return false;
3054 3054
 		}
3055
-		if(is_array($folderStatus)) {
3056
-			if ($_returnObject===false) return $folderStatus;
3057
-			$status =  new stdClass;
3055
+		if (is_array($folderStatus)) {
3056
+			if ($_returnObject === false) return $folderStatus;
3057
+			$status = new stdClass;
3058 3058
 			$status->messages   = $folderStatus['MESSAGES'];
3059 3059
 			$status->unseen     = $folderStatus['UNSEEN'];
3060 3060
 			$status->recent     = $folderStatus['RECENT'];
@@ -3076,42 +3076,42 @@  discard block
 block discarded – undo
3076 3076
 	 * @param string $reclevel 0, counter to keep track of the current recursionlevel
3077 3077
 	 * @return array of mailboxes
3078 3078
 	 */
3079
-	function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel=0)
3079
+	function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel = 0)
3080 3080
 	{
3081 3081
 		#echo __METHOD__." retrieve SubFolders for $_mailbox$delimiter <br>";
3082
-		$maxreclevel=25;
3082
+		$maxreclevel = 25;
3083 3083
 		if ($reclevel > $maxreclevel) {
3084
-			error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
3084
+			error_log(__METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
3085 3085
 			return array();
3086 3086
 		}
3087 3087
 		$reclevel++;
3088 3088
 		// clean up double delimiters
3089
-		$_mailbox = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$_mailbox);
3089
+		$_mailbox = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter : $delimiter).'+~s', $delimiter, $_mailbox);
3090 3090
 		//get that mailbox in question
3091
-		$mbx = $this->icServer->getMailboxes($_mailbox,1,true);
3091
+		$mbx = $this->icServer->getMailboxes($_mailbox, 1, true);
3092 3092
 		$mbxkeys = array_keys($mbx);
3093 3093
 		#_debug_array($mbx);
3094 3094
 //error_log(__METHOD__.' ('.__LINE__.') '.' Delimiter:'.array2string($delimiter));
3095 3095
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx));
3096 3096
 		// Example: Array([INBOX/GaGa] => Array([MAILBOX] => INBOX/GaGa[ATTRIBUTES] => Array([0] => \\unmarked)[delimiter] => /))
3097
-		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"]))) {
3097
+		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"]))) {
3098 3098
 			// if there are children fetch them
3099 3099
 			//echo $mbx[$mbxkeys[0]]['MAILBOX']."<br>";
3100 3100
 
3101
-			$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'].($mbx[$mbxkeys[0]]['MAILBOX'] == $prefix ? '':$delimiter),2,false);
3101
+			$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'].($mbx[$mbxkeys[0]]['MAILBOX'] == $prefix ? '' : $delimiter), 2, false);
3102 3102
 			//$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'],2,false);
3103 3103
 			//_debug_array($buff);
3104 3104
 			$allMailboxes = array();
3105 3105
 			foreach ($buff as $mbxname) {
3106 3106
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbxname));
3107
-				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname['MAILBOX']);
3107
+				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter : $delimiter).'+~s', $delimiter, $mbxname['MAILBOX']);
3108 3108
 				#echo "About to recur in level $reclevel:".$mbxname."<br>";
3109
-				if ( $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'] && $mbxname != $prefix  && $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'].$delimiter)
3109
+				if ($mbxname != $mbx[$mbxkeys[0]]['MAILBOX'] && $mbxname != $prefix && $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'].$delimiter)
3110 3110
 				{
3111 3111
 					$allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel));
3112 3112
 				}
3113 3113
 			}
3114
-			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'];
3114
+			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'];
3115 3115
 			return $allMailboxes;
3116 3116
 		} else {
3117 3117
 			return array($_mailbox);
@@ -3126,17 +3126,17 @@  discard block
 block discarded – undo
3126 3126
 	 * @param boolean& $created =null on return true: if folder was just created, false if not
3127 3127
 	 * @return mixed string or false
3128 3128
 	 */
3129
-	function _getSpecialUseFolder($_type, $_checkexistance=TRUE, &$created=null)
3129
+	function _getSpecialUseFolder($_type, $_checkexistance = TRUE, &$created = null)
3130 3130
 	{
3131 3131
 		static $types = array(
3132
-			'Drafts'   => array('profileKey'=>'acc_folder_draft','autoFolderName'=>'Drafts'),
3133
-			'Template' => array('profileKey'=>'acc_folder_template','autoFolderName'=>'Templates'),
3134
-			'Trash'    => array('profileKey'=>'acc_folder_trash','autoFolderName'=>'Trash'),
3135
-			'Sent'     => array('profileKey'=>'acc_folder_sent','autoFolderName'=>'Sent'),
3136
-			'Junk'     => array('profileKey'=>'acc_folder_junk','autoFolderName'=>'Junk'),
3137
-			'Outbox'   => array('profileKey'=>'acc_folder_outbox','autoFolderName'=>'Outbox'),
3132
+			'Drafts'   => array('profileKey'=>'acc_folder_draft', 'autoFolderName'=>'Drafts'),
3133
+			'Template' => array('profileKey'=>'acc_folder_template', 'autoFolderName'=>'Templates'),
3134
+			'Trash'    => array('profileKey'=>'acc_folder_trash', 'autoFolderName'=>'Trash'),
3135
+			'Sent'     => array('profileKey'=>'acc_folder_sent', 'autoFolderName'=>'Sent'),
3136
+			'Junk'     => array('profileKey'=>'acc_folder_junk', 'autoFolderName'=>'Junk'),
3137
+			'Outbox'   => array('profileKey'=>'acc_folder_outbox', 'autoFolderName'=>'Outbox'),
3138 3138
 		);
3139
-		if ($_type == 'Templates') $_type = 'Template';	// for some reason self::$autofolders uses 'Templates'!
3139
+		if ($_type == 'Templates') $_type = 'Template'; // for some reason self::$autofolders uses 'Templates'!
3140 3140
 		$created = false;
3141 3141
 		if (!isset($types[$_type]))
3142 3142
 		{
@@ -3157,38 +3157,38 @@  discard block
 block discarded – undo
3157 3157
 			$_folderName = false;
3158 3158
 		}
3159 3159
 		// does the folder exist??? (is configured/preset, but non-existent)
3160
-		if ($_folderName && $_checkexistance && $_folderName !='none' && !$this->folderExists($_folderName,true)) {
3160
+		if ($_folderName && $_checkexistance && $_folderName != 'none' && !$this->folderExists($_folderName, true)) {
3161 3161
 			try
3162 3162
 			{
3163 3163
 				$error = null;
3164 3164
 				if (($_folderName = $this->createFolder('', $_folderName, $error))) $created = true;
3165 3165
 				if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
3166 3166
 			}
3167
-			catch(Exception $e)
3167
+			catch (Exception $e)
3168 3168
 			{
3169 3169
 				error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$e->getMessage().':'.function_backtrace());
3170 3170
 				$_folderName = false;
3171 3171
 			}
3172 3172
 		}
3173 3173
 		// not sure yet if false is the correct behavior on none
3174
-		if ($_folderName =='none') return 'none' ; //false;
3174
+		if ($_folderName == 'none') return 'none'; //false;
3175 3175
 		//no (valid) folder found yet; try specialUseFolders
3176
-		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders))) $_folderName = $f;
3176
+		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type, self::$specialUseFolders))) $_folderName = $f;
3177 3177
 		//no specialUseFolder; try some Defaults
3178 3178
 		if (empty($_folderName) && isset($types[$_type]))
3179 3179
 		{
3180 3180
 			$nameSpace = $this->_getNameSpaces();
3181
-			$prefix='';
3181
+			$prefix = '';
3182 3182
 			foreach ($nameSpace as $nSp)
3183 3183
 			{
3184
-				if ($nSp['type']=='personal')
3184
+				if ($nSp['type'] == 'personal')
3185 3185
 				{
3186 3186
 					//error_log(__METHOD__.__LINE__.array2string($nSp));
3187 3187
 					$prefix = $nSp['prefix'];
3188 3188
 					break;
3189 3189
 				}
3190 3190
 			}
3191
-			if ($this->folderExists($prefix.$types[$_type]['autoFolderName'],true))
3191
+			if ($this->folderExists($prefix.$types[$_type]['autoFolderName'], true))
3192 3192
 			{
3193 3193
 				$_folderName = $prefix.$types[$_type]['autoFolderName'];
3194 3194
 			}
@@ -3197,11 +3197,11 @@  discard block
 block discarded – undo
3197 3197
 				try
3198 3198
 				{
3199 3199
 					$error = null;
3200
-					$this->createFolder('', $prefix.$types[$_type]['autoFolderName'],$error);
3200
+					$this->createFolder('', $prefix.$types[$_type]['autoFolderName'], $error);
3201 3201
 					$_folderName = $prefix.$types[$_type]['autoFolderName'];
3202 3202
 					if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
3203 3203
 				}
3204
-				catch(Exception $e)
3204
+				catch (Exception $e)
3205 3205
 				{
3206 3206
 					error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$e->getMessage());
3207 3207
 					$_folderName = false;
@@ -3217,7 +3217,7 @@  discard block
 block discarded – undo
3217 3217
 	 * @param boolean $_checkexistance trigger check for existance
3218 3218
 	 * @return mixed string or false
3219 3219
 	 */
3220
-	function getFolderByType($type, $_checkexistance=false)
3220
+	function getFolderByType($type, $_checkexistance = false)
3221 3221
 	{
3222 3222
 		return $this->_getSpecialUseFolder($type, $_checkexistance);
3223 3223
 	}
@@ -3227,7 +3227,7 @@  discard block
 block discarded – undo
3227 3227
 	 * @param boolean $_checkexistance trigger check for existance
3228 3228
 	 * @return mixed string or false
3229 3229
 	 */
3230
-	function getJunkFolder($_checkexistance=TRUE)
3230
+	function getJunkFolder($_checkexistance = TRUE)
3231 3231
 	{
3232 3232
 		return $this->_getSpecialUseFolder('Junk', $_checkexistance);
3233 3233
 	}
@@ -3237,7 +3237,7 @@  discard block
 block discarded – undo
3237 3237
 	 * @param boolean $_checkexistance trigger check for existance
3238 3238
 	 * @return mixed string or false
3239 3239
 	 */
3240
-	function getDraftFolder($_checkexistance=TRUE)
3240
+	function getDraftFolder($_checkexistance = TRUE)
3241 3241
 	{
3242 3242
 		return $this->_getSpecialUseFolder('Drafts', $_checkexistance);
3243 3243
 	}
@@ -3247,7 +3247,7 @@  discard block
 block discarded – undo
3247 3247
 	 * @param boolean $_checkexistance trigger check for existance
3248 3248
 	 * @return mixed string or false
3249 3249
 	 */
3250
-	function getTemplateFolder($_checkexistance=TRUE)
3250
+	function getTemplateFolder($_checkexistance = TRUE)
3251 3251
 	{
3252 3252
 		return $this->_getSpecialUseFolder('Template', $_checkexistance);
3253 3253
 	}
@@ -3257,7 +3257,7 @@  discard block
 block discarded – undo
3257 3257
 	 * @param boolean $_checkexistance trigger check for existance
3258 3258
 	 * @return mixed string or false
3259 3259
 	 */
3260
-	function getTrashFolder($_checkexistance=TRUE)
3260
+	function getTrashFolder($_checkexistance = TRUE)
3261 3261
 	{
3262 3262
 		return $this->_getSpecialUseFolder('Trash', $_checkexistance);
3263 3263
 	}
@@ -3267,7 +3267,7 @@  discard block
 block discarded – undo
3267 3267
 	 * @param boolean $_checkexistance trigger check for existance
3268 3268
 	 * @return mixed string or false
3269 3269
 	 */
3270
-	function getSentFolder($_checkexistance=TRUE)
3270
+	function getSentFolder($_checkexistance = TRUE)
3271 3271
 	{
3272 3272
 		return $this->_getSpecialUseFolder('Sent', $_checkexistance);
3273 3273
 	}
@@ -3277,7 +3277,7 @@  discard block
 block discarded – undo
3277 3277
 	 * @param boolean $_checkexistance trigger check for existance
3278 3278
 	 * @return mixed string or false
3279 3279
 	 */
3280
-	function getOutboxFolder($_checkexistance=TRUE)
3280
+	function getOutboxFolder($_checkexistance = TRUE)
3281 3281
 	{
3282 3282
 		return $this->_getSpecialUseFolder('Outbox', $_checkexistance);
3283 3283
 	}
@@ -3288,10 +3288,10 @@  discard block
 block discarded – undo
3288 3288
 	 * @param boolean $_checkexistance trigger check for existance
3289 3289
 	 * @return boolean
3290 3290
 	 */
3291
-	function isSentFolder($_folderName, $_checkexistance=TRUE)
3291
+	function isSentFolder($_folderName, $_checkexistance = TRUE)
3292 3292
 	{
3293 3293
 		$sentFolder = $this->getSentFolder($_checkexistance);
3294
-		if(empty($sentFolder)) {
3294
+		if (empty($sentFolder)) {
3295 3295
 			return false;
3296 3296
 		}
3297 3297
 		// does the folder exist???
@@ -3299,7 +3299,7 @@  discard block
 block discarded – undo
3299 3299
 			return false;
3300 3300
 		}
3301 3301
 
3302
-		if(false !== stripos($_folderName, $sentFolder)) {
3302
+		if (false !== stripos($_folderName, $sentFolder)) {
3303 3303
 			return true;
3304 3304
 		} else {
3305 3305
 			return false;
@@ -3312,15 +3312,15 @@  discard block
 block discarded – undo
3312 3312
 	 * @param boolean $_checkexistance trigger check for existance
3313 3313
 	 * @return boolean
3314 3314
 	 */
3315
-	function isOutbox($_folderName, $_checkexistance=TRUE)
3315
+	function isOutbox($_folderName, $_checkexistance = TRUE)
3316 3316
 	{
3317
-		if (stripos($_folderName, 'Outbox')===false) {
3317
+		if (stripos($_folderName, 'Outbox') === false) {
3318 3318
 			return false;
3319 3319
 		}
3320 3320
 		// does the folder exist???
3321 3321
 		if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName)) {
3322 3322
 			$outboxFolder = $this->getOutboxFolder($_checkexistance);
3323
-			if(false !== stripos($_folderName, $outboxFolder)) {
3323
+			if (false !== stripos($_folderName, $outboxFolder)) {
3324 3324
 				return true;
3325 3325
 			} else {
3326 3326
 				return false;
@@ -3335,18 +3335,18 @@  discard block
 block discarded – undo
3335 3335
 	 * @param boolean $_checkexistance trigger check for existance
3336 3336
 	 * @return boolean
3337 3337
 	 */
3338
-	function isDraftFolder($_folderName, $_checkexistance=TRUE)
3338
+	function isDraftFolder($_folderName, $_checkexistance = TRUE)
3339 3339
 	{
3340 3340
 		$draftFolder = $this->getDraftFolder($_checkexistance);
3341
-		if(empty($draftFolder)) {
3341
+		if (empty($draftFolder)) {
3342 3342
 			return false;
3343 3343
 		}
3344 3344
 		// does the folder exist???
3345 3345
 		if ($_checkexistance && !$this->folderExists($_folderName)) {
3346 3346
 			return false;
3347 3347
 		}
3348
-		if (is_a($_folderName,"Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8;
3349
-		if(false !== stripos($_folderName, $draftFolder)) {
3348
+		if (is_a($_folderName, "Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8;
3349
+		if (false !== stripos($_folderName, $draftFolder)) {
3350 3350
 			return true;
3351 3351
 		} else {
3352 3352
 			return false;
@@ -3359,10 +3359,10 @@  discard block
 block discarded – undo
3359 3359
 	 * @param boolean $_checkexistance trigger check for existance
3360 3360
 	 * @return boolean
3361 3361
 	 */
3362
-	function isTrashFolder($_folderName, $_checkexistance=TRUE)
3362
+	function isTrashFolder($_folderName, $_checkexistance = TRUE)
3363 3363
 	{
3364 3364
 		$trashFolder = $this->getTrashFolder($_checkexistance);
3365
-		if(empty($trashFolder)) {
3365
+		if (empty($trashFolder)) {
3366 3366
 			return false;
3367 3367
 		}
3368 3368
 		// does the folder exist???
@@ -3370,7 +3370,7 @@  discard block
 block discarded – undo
3370 3370
 			return false;
3371 3371
 		}
3372 3372
 
3373
-		if(false !== stripos($_folderName, $trashFolder)) {
3373
+		if (false !== stripos($_folderName, $trashFolder)) {
3374 3374
 			return true;
3375 3375
 		} else {
3376 3376
 			return false;
@@ -3383,10 +3383,10 @@  discard block
 block discarded – undo
3383 3383
 	 * @param boolean $_checkexistance trigger check for existance
3384 3384
 	 * @return boolean
3385 3385
 	 */
3386
-	function isTemplateFolder($_folderName, $_checkexistance=TRUE)
3386
+	function isTemplateFolder($_folderName, $_checkexistance = TRUE)
3387 3387
 	{
3388 3388
 		$templateFolder = $this->getTemplateFolder($_checkexistance);
3389
-		if(empty($templateFolder)) {
3389
+		if (empty($templateFolder)) {
3390 3390
 			return false;
3391 3391
 		}
3392 3392
 		// does the folder exist???
@@ -3394,7 +3394,7 @@  discard block
 block discarded – undo
3394 3394
 			return false;
3395 3395
 		}
3396 3396
 
3397
-		if(false !== stripos($_folderName, $templateFolder)) {
3397
+		if (false !== stripos($_folderName, $templateFolder)) {
3398 3398
 			return true;
3399 3399
 		} else {
3400 3400
 			return false;
@@ -3407,24 +3407,24 @@  discard block
 block discarded – undo
3407 3407
 	 * @param boolean $_forceCheck trigger check for existance on icServer
3408 3408
 	 * @return mixed string or false
3409 3409
 	 */
3410
-	function folderExists($_folder, $_forceCheck=false)
3410
+	function folderExists($_folder, $_forceCheck = false)
3411 3411
 	{
3412 3412
 		static $folderInfo;
3413 3413
 		$forceCheck = $_forceCheck;
3414 3414
 		if (empty($_folder))
3415 3415
 		{
3416 3416
 			// this error is more or less without significance, unless we force the check
3417
-			if ($_forceCheck===true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
3417
+			if ($_forceCheck === true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
3418 3418
 			return false;
3419 3419
 		}
3420 3420
 		// when check is not enforced , we assume a folder represented as Horde_Imap_Client_Mailbox as existing folder
3421
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false) return true;
3422
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")) $_folder =  $_folder->utf8;
3421
+		if (is_a($_folder, "Horde_Imap_Client_Mailbox") && $_forceCheck === false) return true;
3422
+		if (is_a($_folder, "Horde_Imap_Client_Mailbox")) $_folder = $_folder->utf8;
3423 3423
 		// reduce traffic within the Instance per User; Expire every 5 hours
3424 3424
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Called with Folder:'.$_folder.function_backtrace());
3425
-		if (is_null($folderInfo)) $folderInfo = egw_cache::getCache(egw_cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
3425
+		if (is_null($folderInfo)) $folderInfo = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), $expiration = 60 * 60 * 5);
3426 3426
 		//error_log(__METHOD__.' ('.__LINE__.') '.'Cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID.($forceCheck?'(forcedCheck)':'').':'.array2string($folderInfo));
3427
-		if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck===false)
3427
+		if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck === false)
3428 3428
 		{
3429 3429
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Using cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID);
3430 3430
 			return $folderInfo[$this->profileID][$_folder];
@@ -3440,7 +3440,7 @@  discard block
 block discarded – undo
3440 3440
 
3441 3441
 		// does the folder exist???
3442 3442
 		//error_log(__METHOD__."->Connected?".$this->icServer->_connected.", ".$_folder.", ".($forceCheck?' forceCheck activated':'dont check on server'));
3443
-		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
3443
+		if ($forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
3444 3444
 			//error_log(__METHOD__."->NotConnected and forceCheck with profile:".$this->profileID);
3445 3445
 			//return false;
3446 3446
 			//try to connect
@@ -3456,12 +3456,12 @@  discard block
 block discarded – undo
3456 3456
 		}
3457 3457
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Folder Exists:'.$folderInfo[$this->profileID][$_folder].function_backtrace());
3458 3458
 
3459
-		if(!empty($folderInfo) && isset($folderInfo[$this->profileID][$_folder]) &&
3459
+		if (!empty($folderInfo) && isset($folderInfo[$this->profileID][$_folder]) &&
3460 3460
 			$folderInfo[$this->profileID][$_folder] !== true)
3461 3461
 		{
3462 3462
 			$folderInfo[$this->profileID][$_folder] = false; // set to false, whatever it was (to have a valid returnvalue for the static return)
3463 3463
 		}
3464
-		egw_cache::setCache(egw_cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderInfo,$expiration=60*60*5);
3464
+		egw_cache::setCache(egw_cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderInfo, $expiration = 60 * 60 * 5);
3465 3465
 		return (!empty($folderInfo) && isset($folderInfo[$this->profileID][$_folder]) ? $folderInfo[$this->profileID][$_folder] : false);
3466 3466
 	}
3467 3467
 
@@ -3474,14 +3474,14 @@  discard block
 block discarded – undo
3474 3474
 	 */
3475 3475
 	function compressFolder($_folderName = false)
3476 3476
 	{
3477
-		$folderName	= ($_folderName ? $_folderName : $this->sessionData['mailbox']);
3478
-		$deleteOptions	= $GLOBALS['egw_info']['user']['preferences']['mail']['deleteOptions'];
3479
-		$trashFolder	= $this->getTrashFolder();
3477
+		$folderName = ($_folderName ? $_folderName : $this->sessionData['mailbox']);
3478
+		$deleteOptions = $GLOBALS['egw_info']['user']['preferences']['mail']['deleteOptions'];
3479
+		$trashFolder = $this->getTrashFolder();
3480 3480
 
3481 3481
 		$this->icServer->openMailbox($folderName);
3482 3482
 
3483
-		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") {
3484
-			$this->deleteMessages('all',$folderName,'remove_immediately');
3483
+		if (strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") {
3484
+			$this->deleteMessages('all', $folderName, 'remove_immediately');
3485 3485
 		} else {
3486 3486
 			$this->icServer->expunge($folderName);
3487 3487
 		}
@@ -3497,19 +3497,19 @@  discard block
 block discarded – undo
3497 3497
 	 * @return bool true, as we do not handle return values yet
3498 3498
 	 * @throws egw_exception
3499 3499
 	 */
3500
-	function deleteMessages($_messageUID, $_folder=NULL, $_forceDeleteMethod='no')
3500
+	function deleteMessages($_messageUID, $_folder = NULL, $_forceDeleteMethod = 'no')
3501 3501
 	{
3502 3502
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.array2string($_folder).', '.$_forceDeleteMethod);
3503 3503
 		$oldMailbox = '';
3504 3504
 		if (is_null($_folder) || empty($_folder)) $_folder = $this->sessionData['mailbox'];
3505 3505
 		if (empty($_messageUID))
3506 3506
 		{
3507
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
3507
+			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',', $_messageUID));
3508 3508
 			return false;
3509 3509
 		}
3510
-		elseif ($_messageUID==='all')
3510
+		elseif ($_messageUID === 'all')
3511 3511
 		{
3512
-			$_messageUID= null;
3512
+			$_messageUID = null;
3513 3513
 		}
3514 3514
 		else
3515 3515
 		{
@@ -3518,32 +3518,32 @@  discard block
 block discarded – undo
3518 3518
 			$uidsToDelete->add($_messageUID);
3519 3519
 		}
3520 3520
 		$deleteOptions = $_forceDeleteMethod; // use forceDeleteMethod if not "no", or unknown method
3521
-		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");
3521
+		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");
3522 3522
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3523 3523
 		$trashFolder    = $this->getTrashFolder();
3524
-		$draftFolder	= $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder'];
3524
+		$draftFolder = $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder'];
3525 3525
 		$templateFolder = $this->getTemplateFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['templateFolder'];
3526
-		if((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") ||
3526
+		if ((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") ||
3527 3527
 		   (strtolower($_folder) == strtolower($draftFolder))) {
3528 3528
 			$deleteOptions = "remove_immediately";
3529 3529
 		}
3530
-		if($this->icServer->getCurrentMailbox() != $_folder) {
3530
+		if ($this->icServer->getCurrentMailbox() != $_folder) {
3531 3531
 			$oldMailbox = $this->icServer->getCurrentMailbox();
3532 3532
 			$this->icServer->openMailbox($_folder);
3533 3533
 		}
3534 3534
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3535 3535
 		$updateCache = false;
3536
-		switch($deleteOptions) {
3536
+		switch ($deleteOptions) {
3537 3537
 			case "move_to_trash":
3538 3538
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3539 3539
 				$updateCache = true;
3540
-				if(!empty($trashFolder)) {
3540
+				if (!empty($trashFolder)) {
3541 3541
 					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
3542
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
3542
+					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ".$this->sessionData['mailbox']);
3543 3543
 					// copy messages
3544 3544
 					try
3545 3545
 					{
3546
-						$this->icServer->copy($_folder, $trashFolder, array('ids'=>$uidsToDelete,'move'=>true));
3546
+						$this->icServer->copy($_folder, $trashFolder, array('ids'=>$uidsToDelete, 'move'=>true));
3547 3547
 					}
3548 3548
 					catch (Exception $e)
3549 3549
 					{
@@ -3555,18 +3555,18 @@  discard block
 block discarded – undo
3555 3555
 			case "mark_as_deleted":
3556 3556
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3557 3557
 				// mark messages as deleted
3558
-				if (is_null($_messageUID)) $_messageUID='all';
3559
-				foreach((array)$_messageUID as $key =>$uid)
3558
+				if (is_null($_messageUID)) $_messageUID = 'all';
3559
+				foreach ((array)$_messageUID as $key =>$uid)
3560 3560
 				{
3561 3561
 					//flag messages, that are flagged for deletion as seen too
3562 3562
 					$this->flagMessages('read', $uid, $_folder);
3563 3563
 					$flags = $this->getFlags($uid);
3564 3564
 					$this->flagMessages('delete', $uid, $_folder);
3565 3565
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
3566
-					if (strpos( array2string($flags),'Deleted')!==false) $undelete[] = $uid;
3566
+					if (strpos(array2string($flags), 'Deleted') !== false) $undelete[] = $uid;
3567 3567
 					unset($flags);
3568 3568
 				}
3569
-				foreach((array)$undelete as $key =>$uid)
3569
+				foreach ((array)$undelete as $key =>$uid)
3570 3570
 				{
3571 3571
 					$this->flagMessages('undelete', $uid, $_folder);
3572 3572
 				}
@@ -3575,14 +3575,14 @@  discard block
 block discarded – undo
3575 3575
 			case "remove_immediately":
3576 3576
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3577 3577
 				$updateCache = true;
3578
-				if (is_null($_messageUID)) $_messageUID='all';
3578
+				if (is_null($_messageUID)) $_messageUID = 'all';
3579 3579
 				if (is_object($_messageUID))
3580 3580
 				{
3581 3581
 					$this->flagMessages('delete', $_messageUID, $_folder);
3582 3582
 				}
3583 3583
 				else
3584 3584
 				{
3585
-					foreach((array)$_messageUID as $key =>$uid)
3585
+					foreach ((array)$_messageUID as $key =>$uid)
3586 3586
 					{
3587 3587
 						//flag messages, that are flagged for deletion as seen too
3588 3588
 						$this->flagMessages('delete', $uid, $_folder);
@@ -3592,7 +3592,7 @@  discard block
 block discarded – undo
3592 3592
 				$this->icServer->expunge($_folder);
3593 3593
 				break;
3594 3594
 		}
3595
-		if($oldMailbox != '') {
3595
+		if ($oldMailbox != '') {
3596 3596
 			$this->icServer->openMailbox($oldMailbox);
3597 3597
 		}
3598 3598
 
@@ -3606,7 +3606,7 @@  discard block
 block discarded – undo
3606 3606
 	 *
3607 3607
 	 * @return null/array flags
3608 3608
 	 */
3609
-	function getFlags ($_messageUID) {
3609
+	function getFlags($_messageUID) {
3610 3610
 		try
3611 3611
 		{
3612 3612
 			$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -3619,7 +3619,7 @@  discard block
 block discarded – undo
3619 3619
 				'ids' => $uidsToFetch,
3620 3620
 			));
3621 3621
 			if (is_object($headersNew)) {
3622
-				foreach($headersNew->ids() as $id) {
3622
+				foreach ($headersNew->ids() as $id) {
3623 3623
 					$_headerObject = $headersNew->get($id);
3624 3624
 					$flags = $_headerObject->getFlags();
3625 3625
 				}
@@ -3642,22 +3642,22 @@  discard block
 block discarded – undo
3642 3642
 	 *
3643 3643
 	 * @return null/boolean
3644 3644
 	 */
3645
-	function getNotifyFlags ($_messageUID, $flags=null)
3645
+	function getNotifyFlags($_messageUID, $flags = null)
3646 3646
 	{
3647 3647
 		if (self::$debug) error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
3648 3648
 		try
3649 3649
 		{
3650
-			if($flags===null) $flags =  $this->getFlags($_messageUID);
3650
+			if ($flags === null) $flags = $this->getFlags($_messageUID);
3651 3651
 		}
3652 3652
 		catch (Exception $e)
3653 3653
 		{
3654 3654
 			return null;
3655 3655
 		}
3656 3656
 
3657
-		if ( stripos( array2string($flags),'MDNSent')!==false)
3657
+		if (stripos(array2string($flags), 'MDNSent') !== false)
3658 3658
 			return true;
3659 3659
 
3660
-		if ( stripos( array2string($flags),'MDNnotSent')!==false)
3660
+		if (stripos(array2string($flags), 'MDNnotSent') !== false)
3661 3661
 			return false;
3662 3662
 
3663 3663
 		return null;
@@ -3674,45 +3674,45 @@  discard block
 block discarded – undo
3674 3674
 	 *
3675 3675
 	 * @return bool true, as we do not handle icserver->setFlags returnValue
3676 3676
 	 */
3677
-	function flagMessages($_flag, $_messageUID,$_folder=NULL)
3677
+	function flagMessages($_flag, $_messageUID, $_folder = NULL)
3678 3678
 	{
3679 3679
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",$_folder /".$this->sessionData['mailbox']);
3680 3680
 		if (empty($_messageUID))
3681 3681
 		{
3682
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
3682
+			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',', $_messageUID));
3683 3683
 			return false;
3684 3684
 		}
3685
-		$this->icServer->openMailbox(($_folder?$_folder:$this->sessionData['mailbox']));
3685
+		$this->icServer->openMailbox(($_folder ? $_folder : $this->sessionData['mailbox']));
3686 3686
 		$folder = $this->icServer->getCurrentMailbox();
3687
-		if (is_array($_messageUID)&& count($_messageUID)>50)
3687
+		if (is_array($_messageUID) && count($_messageUID) > 50)
3688 3688
 		{
3689
-			$count = $this->getMailBoxCounters($folder,true);
3690
-			if ($count->messages == count($_messageUID)) $_messageUID='all';
3689
+			$count = $this->getMailBoxCounters($folder, true);
3690
+			if ($count->messages == count($_messageUID)) $_messageUID = 'all';
3691 3691
 		}
3692 3692
 
3693
-		if ($_messageUID==='all')
3693
+		if ($_messageUID === 'all')
3694 3694
 		{
3695 3695
 			$messageUIDs = array('all');
3696 3696
 		}
3697 3697
 		else
3698 3698
 		{
3699 3699
 			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
3700
-			$messageUIDs = array_chunk($_messageUID,50,true);
3700
+			$messageUIDs = array_chunk($_messageUID, 50, true);
3701 3701
 		}
3702 3702
 		try
3703 3703
 		{
3704
-			foreach($messageUIDs as &$uids)
3704
+			foreach ($messageUIDs as &$uids)
3705 3705
 			{
3706
-				if ($uids==='all')
3706
+				if ($uids === 'all')
3707 3707
 				{
3708
-					$uidsToModify=null;
3708
+					$uidsToModify = null;
3709 3709
 				}
3710 3710
 				else
3711 3711
 				{
3712 3712
 					$uidsToModify = new Horde_Imap_Client_Ids();
3713 3713
 					$uidsToModify->add($uids);
3714 3714
 				}
3715
-				switch($_flag) {
3715
+				switch ($_flag) {
3716 3716
 					case "delete":
3717 3717
 						$ret = $this->icServer->store($folder, array('add'=>array('\\Deleted'), 'ids'=> $uidsToModify));
3718 3718
 						break;
@@ -3736,7 +3736,7 @@  discard block
 block discarded – undo
3736 3736
 						break;
3737 3737
 					case "unread":
3738 3738
 					case "unseen":
3739
-						$ret = $this->icServer->store($folder, array('remove'=>array('\\Seen','\\Answered','$Forwarded'), 'ids'=> $uidsToModify));
3739
+						$ret = $this->icServer->store($folder, array('remove'=>array('\\Seen', '\\Answered', '$Forwarded'), 'ids'=> $uidsToModify));
3740 3740
 						break;
3741 3741
 					case "mdnsent":
3742 3742
 						$ret = $this->icServer->store($folder, array('add'=>array('MDNSent'), 'ids'=> $uidsToModify));
@@ -3794,13 +3794,13 @@  discard block
 block discarded – undo
3794 3794
 				}
3795 3795
 			}
3796 3796
 		}
3797
-		catch(Exception $e)
3797
+		catch (Exception $e)
3798 3798
 		{
3799 3799
 			error_log(__METHOD__.__LINE__.' Error, could not flag messages in folder '.$folder.' Reason:'.$e->getMessage());
3800 3800
 		}
3801 3801
 		if ($folder instanceof Horde_Imap_Client_Mailbox) $_folder = $folder->utf8;
3802 3802
 		//error_log(__METHOD__.__LINE__.'#'.$this->icServer->ImapServerId.'#'.array2string($_folder).'#');
3803
-		self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])]['uidValidity'] = 0;
3803
+		self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder) ? $_folder : $this->sessionData['mailbox'])]['uidValidity'] = 0;
3804 3804
 
3805 3805
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",".($_folder?$_folder:$this->sessionData['mailbox']));
3806 3806
 		return true; // as we do not catch/examine setFlags returnValue
@@ -3821,19 +3821,19 @@  discard block
 block discarded – undo
3821 3821
 	 * @return mixed/bool true,false or new uid
3822 3822
 	 * @throws egw_exception
3823 3823
 	 */
3824
-	function moveMessages($_foldername, $_messageUID, $deleteAfterMove=true, $currentFolder = Null, $returnUIDs = false, $_sourceProfileID = Null, $_targetProfileID = Null)
3824
+	function moveMessages($_foldername, $_messageUID, $deleteAfterMove = true, $currentFolder = Null, $returnUIDs = false, $_sourceProfileID = Null, $_targetProfileID = Null)
3825 3825
 	{
3826
-		$source = emailadmin_account::read(($_sourceProfileID?$_sourceProfileID:$this->icServer->ImapServerId))->imapServer();
3826
+		$source = emailadmin_account::read(($_sourceProfileID ? $_sourceProfileID : $this->icServer->ImapServerId))->imapServer();
3827 3827
 		//$deleteOptions  = $GLOBALS['egw_info']["user"]["preferences"]["mail"]["deleteOptions"];
3828 3828
 		if (empty($_messageUID))
3829 3829
 		{
3830
-			if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
3830
+			if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',', $_messageUID));
3831 3831
 			return false;
3832 3832
 		}
3833
-		elseif ($_messageUID==='all')
3833
+		elseif ($_messageUID === 'all')
3834 3834
 		{
3835 3835
 			//error_log(__METHOD__." all Message(s): ".implode(',',$_messageUID));
3836
-			$uidsToMove= null;
3836
+			$uidsToMove = null;
3837 3837
 		}
3838 3838
 		else
3839 3839
 		{
@@ -3842,7 +3842,7 @@  discard block
 block discarded – undo
3842 3842
 			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
3843 3843
 			$uidsToMove->add($_messageUID);
3844 3844
 		}
3845
-		$sourceFolder = (!empty($currentFolder)?$currentFolder: $this->sessionData['mailbox']);
3845
+		$sourceFolder = (!empty($currentFolder) ? $currentFolder : $this->sessionData['mailbox']);
3846 3846
 		//error_log(__METHOD__.__LINE__."$_targetProfileID !== ".array2string($source->ImapServerId));
3847 3847
 		if (!is_null($_targetProfileID) && $_targetProfileID !== $source->ImapServerId)
3848 3848
 		{
@@ -3862,19 +3862,19 @@  discard block
 block discarded – undo
3862 3862
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' mailheaders:'.array2string($headersNew));
3863 3863
 
3864 3864
 			if (is_object($headersNew)) {
3865
-				$c=0;
3865
+				$c = 0;
3866 3866
 				$retUid = new Horde_Imap_Client_Ids();
3867 3867
 				// we copy chunks of 5 to avoid too much memory and/or server stress
3868 3868
 				// some servers seem not to allow/support the appendig of multiple messages. so we are down to one
3869
-				foreach($headersNew as &$_headerObject) {
3869
+				foreach ($headersNew as &$_headerObject) {
3870 3870
 					$c++;
3871 3871
 					$flags = $_headerObject->getFlags(); //unseen status seems to be lost when retrieving the full message
3872 3872
 					$date = $_headerObject->getImapDate();
3873
-					$currentDate =  new Horde_Imap_Client_DateTime();
3873
+					$currentDate = new Horde_Imap_Client_DateTime();
3874 3874
 					// if the internal Date of the message equals the current date; try using the header date
3875
-					if ($date==$currentDate)
3875
+					if ($date == $currentDate)
3876 3876
 					{
3877
-						$headerForPrio = array_change_key_case($_headerObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
3877
+						$headerForPrio = array_change_key_case($_headerObject->getHeaderText(0, Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
3878 3878
 						//error_log(__METHOD__.__LINE__.'#'.array2string($date).'#'.array2string($currentDate).'#'.$headerForPrio['DATE']);
3879 3879
 						$date = new Horde_Imap_Client_DateTime($headerForPrio['DATE']);
3880 3880
 						//error_log(__METHOD__.__LINE__.'#'.array2string($date).'#'.array2string($currentDate).'#');
@@ -3883,20 +3883,20 @@  discard block
 block discarded – undo
3883 3883
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
3884 3884
 					$body = $_headerObject->getFullMsg();
3885 3885
 					$dataNflags[] = array('data'=>$body, 'flags'=>$flags, 'internaldate'=>$date);
3886
-					if ($c==1)
3886
+					if ($c == 1)
3887 3887
 					{
3888 3888
 						$target = emailadmin_account::read($_targetProfileID)->imapServer();
3889 3889
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' TargetServer:'.$_targetProfileID.' TargetFolderObject:'.array2string($_foldername));
3890 3890
 						$foldername = $target->getMailbox($_foldername);
3891 3891
 						// make sure the target folder is open and ready
3892 3892
 						$target->openMailbox($foldername);
3893
-						$ret = $target->append($foldername,$dataNflags);
3893
+						$ret = $target->append($foldername, $dataNflags);
3894 3894
 						$retUid->add($ret);
3895 3895
 						unset($dataNflags);
3896 3896
 						// sleep 500 miliseconds; AS some sERVERs seem not to be capable of the load this is
3897 3897
 						// inflicting in them. they "reply" with an unspecific IMAP Error
3898
-						time_nanosleep(0,500000);
3899
-						$c=0;
3898
+						time_nanosleep(0, 500000);
3899
+						$c = 0;
3900 3900
 					}
3901 3901
 				}
3902 3902
 				if (isset($dataNflags))
@@ -3906,7 +3906,7 @@  discard block
 block discarded – undo
3906 3906
 					$foldername = $target->getMailbox($_foldername);
3907 3907
 					// make sure the target folder is open and ready
3908 3908
 					$target->openMailbox($foldername);
3909
-					$ret = $target->append($foldername,$dataNflags);
3909
+					$ret = $target->append($foldername, $dataNflags);
3910 3910
 					$retUid->add($ret);
3911 3911
 					unset($dataNflags);
3912 3912
 				}
@@ -3917,7 +3917,7 @@  discard block
 block discarded – undo
3917 3917
 				{
3918 3918
 					$remember = $this->icServer;
3919 3919
 					$this->icServer = $source;
3920
-					$this->deleteMessages($_messageUID, $sourceFolder, $_forceDeleteMethod='remove_immediately');
3920
+					$this->deleteMessages($_messageUID, $sourceFolder, $_forceDeleteMethod = 'remove_immediately');
3921 3921
 					$this->icServer = $remember;
3922 3922
 				}
3923 3923
 			}
@@ -3926,7 +3926,7 @@  discard block
 block discarded – undo
3926 3926
 		{
3927 3927
 			try
3928 3928
 			{
3929
-				$retUid = $source->copy($sourceFolder, $_foldername, array('ids'=>$uidsToMove,'move'=>$deleteAfterMove));
3929
+				$retUid = $source->copy($sourceFolder, $_foldername, array('ids'=>$uidsToMove, 'move'=>$deleteAfterMove));
3930 3930
 			}
3931 3931
 			catch (exception $e)
3932 3932
 			{
@@ -3946,19 +3946,19 @@  discard block
 block discarded – undo
3946 3946
 	 * @param string $format ='' if none is passed, use user prefs
3947 3947
 	 * @return string returns the date as it is parseable by strtotime, or current timestamp if everything fails
3948 3948
 	 */
3949
-	static function _strtotime($_date='', $format='', $convert2usertime=false)
3949
+	static function _strtotime($_date = '', $format = '', $convert2usertime = false)
3950 3950
 	{
3951 3951
 		try {
3952
-			$date = new egw_time($_date);	// parse date & time including timezone (throws exception, if not parsable)
3953
-			if ($convert2usertime) $date->setUser();	// convert to user-time
3952
+			$date = new egw_time($_date); // parse date & time including timezone (throws exception, if not parsable)
3953
+			if ($convert2usertime) $date->setUser(); // convert to user-time
3954 3954
 			$date2return = $date->format($format);
3955 3955
 		}
3956
-		catch(Exception $e)
3956
+		catch (Exception $e)
3957 3957
 		{
3958
-			unset($e);	// not used
3958
+			unset($e); // not used
3959 3959
 
3960 3960
 			// remove last space-separated part and retry
3961
-			$parts = explode(' ',$_date);
3961
+			$parts = explode(' ', $_date);
3962 3962
 			if (count($parts) > 1)
3963 3963
 			{
3964 3964
 				array_pop($parts);
@@ -3979,12 +3979,12 @@  discard block
 block discarded – undo
3979 3979
 	 * @param mixed $_charset false or string -> Target charset, if false emailadmin_imapbase displayCharset will be used
3980 3980
 	 * @return string
3981 3981
 	 */
3982
-	static function htmlentities($_string, $_charset=false)
3982
+	static function htmlentities($_string, $_charset = false)
3983 3983
 	{
3984 3984
 		//setting the charset (if not given)
3985
-		if ($_charset===false) $_charset = self::$displayCharset;
3985
+		if ($_charset === false) $_charset = self::$displayCharset;
3986 3986
 		$string = @htmlentities($_string, ENT_QUOTES, $_charset, false);
3987
-		if (empty($string) && !empty($_string)) $string = @htmlentities(translation::convert($_string,translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
3987
+		if (empty($string) && !empty($_string)) $string = @htmlentities(translation::convert($_string, translation::detect_encoding($_string), $_charset), ENT_QUOTES|ENT_IGNORE, $_charset, false);
3988 3988
 		return $string;
3989 3989
 	}
3990 3990
 
@@ -4001,21 +4001,21 @@  discard block
 block discarded – undo
4001 4001
 		//$_html = str_replace("\t",' ',$_html);
4002 4002
 		//error_log($_html);
4003 4003
 		//repair doubleencoded ampersands, and some stuff htmLawed stumbles upon with balancing switched on
4004
-		$_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>'),
4005
-							 array('&amp;',    '<BR>',           '<BR>',             '<BR>',             '</font></td>','<td>',    '',         '',           '',  ''),$_html);
4004
+		$_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>'),
4005
+							 array('&amp;', '<BR>', '<BR>', '<BR>', '</font></td>', '<td>', '', '', '', ''), $_html);
4006 4006
 		//$_html = str_replace(array('&amp;amp;'),array('&amp;'),$_html);
4007
-		if (stripos($_html,'style')!==false) translation::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags
4008
-		if (stripos($_html,'head')!==false) translation::replaceTagsCompletley($_html,'head'); // Strip out stuff in head
4007
+		if (stripos($_html, 'style') !== false) translation::replaceTagsCompletley($_html, 'style'); // clean out empty or pagewide style definitions / left over tags
4008
+		if (stripos($_html, 'head') !== false) translation::replaceTagsCompletley($_html, 'head'); // Strip out stuff in head
4009 4009
 		//if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false) translation::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false); // Strip out stuff in ifs
4010 4010
 		//if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false) translation::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false); // Strip out stuff in ifs
4011 4011
 		//error_log(__METHOD__.' ('.__LINE__.') '.$_html);
4012 4012
 
4013 4013
 		if (get_magic_quotes_gpc() === 1) $_html = stripslashes($_html);
4014 4014
 		// Strip out doctype in head, as htmlLawed cannot handle it TODO: Consider extracting it and adding it afterwards
4015
-		if (stripos($_html,'!doctype')!==false) translation::replaceTagsCompletley($_html,'!doctype');
4016
-		if (stripos($_html,'?xml:namespace')!==false) translation::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
4017
-		if (stripos($_html,'?xml version')!==false) translation::replaceTagsCompletley($_html,'\?xml version','\?>',false);
4018
-		if (strpos($_html,'!CURSOR')!==false) translation::replaceTagsCompletley($_html,'!CURSOR');
4015
+		if (stripos($_html, '!doctype') !== false) translation::replaceTagsCompletley($_html, '!doctype');
4016
+		if (stripos($_html, '?xml:namespace') !== false) translation::replaceTagsCompletley($_html, '\?xml:namespace', '/>', false);
4017
+		if (stripos($_html, '?xml version') !== false) translation::replaceTagsCompletley($_html, '\?xml version', '\?>', false);
4018
+		if (strpos($_html, '!CURSOR') !== false) translation::replaceTagsCompletley($_html, '!CURSOR');
4019 4019
 		// htmLawed filter only the 'body'
4020 4020
 		//preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $_html, $matches);
4021 4021
 		//if ($matches[2])
@@ -4026,16 +4026,16 @@  discard block
 block discarded – undo
4026 4026
 		// purify got switched to htmLawed
4027 4027
 		// some testcode to test purifying / htmlawed
4028 4028
 		//$_html = "<BLOCKQUOTE>hi <div> there </div> kram <br> </blockquote>".$_html;
4029
-		$_html = html::purify($_html,self::$htmLawed_config,array(),true);
4029
+		$_html = html::purify($_html, self::$htmLawed_config, array(), true);
4030 4030
 		//if ($hasOther) $_html = $matches[1]. $_html. $matches[3];
4031 4031
 		// clean out comments , should not be needed as purify should do the job.
4032 4032
 		$search = array(
4033
-			'@url\(http:\/\/[^\)].*?\)@si',  // url calls e.g. in style definitions
4034
-			'@<!--[\s\S]*?[ \t\n\r]*-->@',         // Strip multi-line comments including CDATA
4033
+			'@url\(http:\/\/[^\)].*?\)@si', // url calls e.g. in style definitions
4034
+			'@<!--[\s\S]*?[ \t\n\r]*-->@', // Strip multi-line comments including CDATA
4035 4035
 		);
4036
-		$_html = preg_replace($search,"",$_html);
4036
+		$_html = preg_replace($search, "", $_html);
4037 4037
 		// remove non printable chars
4038
-		$_html = preg_replace('/([\000-\011])/','',$_html);
4038
+		$_html = preg_replace('/([\000-\011])/', '', $_html);
4039 4039
 		//error_log(__METHOD__.':'.__LINE__.':'.$_html);
4040 4040
 	}
4041 4041
 
@@ -4052,12 +4052,12 @@  discard block
 block discarded – undo
4052 4052
 	function getMimePartCharset($_mimePartObject)
4053 4053
 	{
4054 4054
 		//$charSet = 'iso-8859-1';//self::$displayCharset; //'iso-8859-1'; // self::displayCharset seems to be asmarter fallback than iso-8859-1
4055
-		$CharsetFound=false;
4055
+		$CharsetFound = false;
4056 4056
 		//echo "#".$_mimePartObject->encoding.'#<br>';
4057
-		if(is_array($_mimePartObject->parameters)) {
4058
-			if(isset($_mimePartObject->parameters['CHARSET'])) {
4057
+		if (is_array($_mimePartObject->parameters)) {
4058
+			if (isset($_mimePartObject->parameters['CHARSET'])) {
4059 4059
 				$charSet = $_mimePartObject->parameters['CHARSET'];
4060
-				$CharsetFound=true;
4060
+				$CharsetFound = true;
4061 4061
 			}
4062 4062
 		}
4063 4063
 		// this one is dirty, but until I find something that does the trick of detecting the encoding, ....
@@ -4076,7 +4076,7 @@  discard block
 block discarded – undo
4076 4076
 	function decodeMimePart($_mimeMessage, $_encoding, $_charset = '')
4077 4077
 	{
4078 4078
 		// decode the part
4079
-		if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
4079
+		if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage, true));
4080 4080
 		switch (strtoupper($_encoding))
4081 4081
 		{
4082 4082
 			case 'BASE64':
@@ -4116,10 +4116,10 @@  discard block
 block discarded – undo
4116 4116
 		// sometimes there are 3 parts, when there is an ics/ical attached/included-> we want to show that
4117 4117
 		// as attachment AND as abstracted ical information (we use our notification style here).
4118 4118
 		$partText = $partCalendar = $partHTML = null;
4119
-		if (self::$debug) _debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
4119
+		if (self::$debug) _debug_array(array("METHOD"=>__METHOD__, "LINE"=>__LINE__, "STRUCTURE"=>$_structure));
4120 4120
 		//error_log(__METHOD__.' ('.__LINE__.') ');
4121 4121
 		$ignore_first_part = true;
4122
-		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4122
+		foreach ($_structure->contentTypeMap() as $mime_id => $mime_type)
4123 4123
 		{
4124 4124
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type"." ignoreFirstPart:".$ignore_first_part);
4125 4125
 			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
@@ -4127,15 +4127,15 @@  discard block
 block discarded – undo
4127 4127
 			if ($ignore_first_part)
4128 4128
 			{
4129 4129
 				$ignore_first_part = false;
4130
-				continue;	// ignore multipart/alternative itself
4130
+				continue; // ignore multipart/alternative itself
4131 4131
 			}
4132 4132
 
4133 4133
 			$mimePart = $_structure->getPart($mime_id);
4134 4134
 
4135
-			switch($mimePart->getPrimaryType())
4135
+			switch ($mimePart->getPrimaryType())
4136 4136
 			{
4137 4137
 				case 'text':
4138
-					switch($mimePart->getSubType())
4138
+					switch ($mimePart->getSubType())
4139 4139
 					{
4140 4140
 						case 'plain':
4141 4141
 							if ($mimePart->getBytes() > 0) $partText = $mimePart;
@@ -4148,7 +4148,7 @@  discard block
 block discarded – undo
4148 4148
 					break;
4149 4149
 
4150 4150
 				case 'multipart':
4151
-					switch($mimePart->getSubType())
4151
+					switch ($mimePart->getSubType())
4152 4152
 					{
4153 4153
 						case 'related':
4154 4154
 						case 'mixed':
@@ -4170,13 +4170,13 @@  discard block
 block discarded – undo
4170 4170
 			}
4171 4171
 		}
4172 4172
 
4173
-		switch($_htmlMode)
4173
+		switch ($_htmlMode)
4174 4174
 		{
4175 4175
 			case 'html_only':
4176 4176
 			case 'always_display':
4177 4177
 				if ($partHTML)
4178 4178
 				{
4179
-					switch($partHTML->getSubType())
4179
+					switch ($partHTML->getSubType())
4180 4180
 					{
4181 4181
 						case 'related':
4182 4182
 							return $this->getMultipartRelated($_uid, $partHTML, $_htmlMode, $_preserveSeen);
@@ -4188,7 +4188,7 @@  discard block
 block discarded – undo
4188 4188
 							return $this->getTextPart($_uid, $partHTML, $_htmlMode, $_preserveSeen);
4189 4189
 					}
4190 4190
 				}
4191
-				elseif ($partText && $_htmlMode=='always_display')
4191
+				elseif ($partText && $_htmlMode == 'always_display')
4192 4192
 				{
4193 4193
 					return $this->getTextPart($_uid, $partText, $_htmlMode, $_preserveSeen);
4194 4194
 				}
@@ -4234,7 +4234,7 @@  discard block
 block discarded – undo
4234 4234
 	 * @param array	&$skipParts - passed by reference to have control/knowledge which parts are already fetched
4235 4235
 	 * @return array containing the desired part
4236 4236
 	 */
4237
-	function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts=array())
4237
+	function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts = array())
4238 4238
 	{
4239 4239
 		if (self::$debug) echo __METHOD__."$_uid, $_htmlMode<br>";
4240 4240
 		$bodyPart = array();
@@ -4243,7 +4243,7 @@  discard block
 block discarded – undo
4243 4243
 		$ignore_first_part = true;
4244 4244
 		//$skipParts = array();
4245 4245
 		//error_log(__METHOD__.__LINE__.array2string($_structure->contentTypeMap()));
4246
-		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4246
+		foreach ($_structure->contentTypeMap() as $mime_id => $mime_type)
4247 4247
 		{
4248 4248
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type");
4249 4249
 			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
@@ -4251,9 +4251,9 @@  discard block
 block discarded – undo
4251 4251
 			{
4252 4252
 				$ignore_first_part = false;
4253 4253
 				//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") SKIPPED FirstPart $mime_id: $mime_type");
4254
-				continue;	// ignore multipart/mixed itself
4254
+				continue; // ignore multipart/mixed itself
4255 4255
 			}
4256
-			if (array_key_exists($mime_id,$skipParts))
4256
+			if (array_key_exists($mime_id, $skipParts))
4257 4257
 			{
4258 4258
 				//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") SKIPPED $mime_id: $mime_type");
4259 4259
 				continue;
@@ -4261,11 +4261,11 @@  discard block
 block discarded – undo
4261 4261
 
4262 4262
 			$part = $_structure->getPart($mime_id);
4263 4263
 
4264
-			switch($part->getPrimaryType())
4264
+			switch ($part->getPrimaryType())
4265 4265
 			{
4266 4266
 				case 'multipart':
4267 4267
 					if ($part->getDisposition() == 'attachment') continue;
4268
-					switch($part->getSubType())
4268
+					switch ($part->getSubType())
4269 4269
 					{
4270 4270
 						case 'alternative':
4271 4271
 							return array($this->getMultipartAlternative($_uid, $part, $_htmlMode, $_preserveSeen));
@@ -4281,15 +4281,15 @@  discard block
 block discarded – undo
4281 4281
 					}
4282 4282
 					break;
4283 4283
 				case 'application':
4284
-					switch($part->getSubType())
4284
+					switch ($part->getSubType())
4285 4285
 					{
4286 4286
 						case 'pgp-encrypted':
4287
-							if (($part = $_structure->getPart($mime_id+1)) &&
4287
+							if (($part = $_structure->getPart($mime_id + 1)) &&
4288 4288
 								$part->getType() == 'application/octet-stream')
4289 4289
 							{
4290 4290
 								$this->fetchPartContents($_uid, $part);
4291
-								$skipParts[$mime_id]=$mime_type;
4292
-								$skipParts[$mime_id+1]=$part->getType();
4291
+								$skipParts[$mime_id] = $mime_type;
4292
+								$skipParts[$mime_id + 1] = $part->getType();
4293 4293
 								$bodyPart[] = array(
4294 4294
 									'body'		=> $part->getContents(array(
4295 4295
 										'stream' => false,
@@ -4303,15 +4303,15 @@  discard block
 block discarded – undo
4303 4303
 					break;
4304 4304
 
4305 4305
 				case 'text':
4306
-					switch($part->getSubType())
4306
+					switch ($part->getSubType())
4307 4307
 					{
4308 4308
 						case 'plain':
4309 4309
 						case 'html':
4310 4310
 						case 'calendar': // inline ics/ical files
4311
-							if($part->getDisposition() != 'attachment')
4311
+							if ($part->getDisposition() != 'attachment')
4312 4312
 							{
4313 4313
 								$bodyPart[] = $this->getTextPart($_uid, $part, $_htmlMode, $_preserveSeen);
4314
-								$skipParts[$mime_id]=$mime_type;
4314
+								$skipParts[$mime_id] = $mime_type;
4315 4315
 							}
4316 4316
 							//error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$part->type."/".$part->subType.' -> BodyPart:'.array2string($bodyPart[count($bodyPart)-1]));
4317 4317
 							break;
@@ -4320,16 +4320,16 @@  discard block
 block discarded – undo
4320 4320
 
4321 4321
 				case 'message':
4322 4322
 					//skip attachments
4323
-					if($part->getSubType() == 'delivery-status' && $part->getDisposition() != 'attachment')
4323
+					if ($part->getSubType() == 'delivery-status' && $part->getDisposition() != 'attachment')
4324 4324
 					{
4325 4325
 						$bodyPart[] = $this->getTextPart($_uid, $part, $_htmlMode, $_preserveSeen);
4326
-						$skipParts[$mime_id]=$mime_type;
4326
+						$skipParts[$mime_id] = $mime_type;
4327 4327
 					}
4328 4328
 					// do not descend into attached Messages
4329
-					if($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment')
4329
+					if ($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment')
4330 4330
 					{
4331 4331
 						$skipParts[$mime_id.'.0'] = $mime_type;
4332
-						foreach($part->contentTypeMap() as $sub_id => $sub_type){ $skipParts[$sub_id] = $sub_type;}
4332
+						foreach ($part->contentTypeMap() as $sub_id => $sub_type) { $skipParts[$sub_id] = $sub_type; }
4333 4333
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$_uid.' Part:'.$mime_id.':'.array2string($skipParts));
4334 4334
 						//break 2;
4335 4335
 					}
@@ -4370,13 +4370,13 @@  discard block
 block discarded – undo
4370 4370
 	 * @param boolean $_tryDecodingServerside = true; wether to try to fetch Data with BINARY instead of BODY
4371 4371
 	 * @return string|resource
4372 4372
 	 */
4373
-	function getBodyPart($_uid, $_partID=null, $_folder=null, $_preserveSeen=false, $_stream=false, &$_encoding=null, $_tryDecodingServerside=true)
4373
+	function getBodyPart($_uid, $_partID = null, $_folder = null, $_preserveSeen = false, $_stream = false, &$_encoding = null, $_tryDecodingServerside = true)
4374 4374
 	{
4375
-		if (self::$debug) error_log( __METHOD__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen)");
4375
+		if (self::$debug) error_log(__METHOD__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen)");
4376 4376
 
4377 4377
 		if (empty($_folder))
4378 4378
 		{
4379
-			$_folder = (isset($this->sessionData['mailbox'])&&$this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
4379
+			$_folder = (isset($this->sessionData['mailbox']) && $this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
4380 4380
 		}
4381 4381
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_folder).'/'.$this->icServer->getCurrentMailbox().'/'. $this->sessionData['mailbox']);
4382 4382
 		// querying contents of body part
@@ -4387,11 +4387,11 @@  discard block
 block discarded – undo
4387 4387
 		$fquery = new Horde_Imap_Client_Fetch_Query();
4388 4388
 		$fetchParams = array(
4389 4389
 			'peek' => $_preserveSeen,
4390
-			'decode' => true,	// try decode on server, does NOT neccessary work
4390
+			'decode' => true, // try decode on server, does NOT neccessary work
4391 4391
 		);
4392
-		if ($_tryDecodingServerside===false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
4392
+		if ($_tryDecodingServerside === false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
4393 4393
 		{
4394
-			$_tryDecodingServerside=false;
4394
+			$_tryDecodingServerside = false;
4395 4395
 			$fetchParams = array(
4396 4396
 				'peek' => $_preserveSeen,
4397 4397
 			);
@@ -4411,12 +4411,12 @@  discard block
 block discarded – undo
4411 4411
 		}
4412 4412
 		// if we get an empty result, server may have trouble fetching data with UID FETCH $_uid (BINARY.PEEK[$_partID])
4413 4413
 		// thus we trigger a second go with UID FETCH $_uid (BODY.PEEK[$_partID])
4414
-		if (empty($partToReturn)&&$_tryDecodingServerside===true)
4414
+		if (empty($partToReturn) && $_tryDecodingServerside === true)
4415 4415
 		{
4416 4416
 			error_log(__METHOD__.__LINE__.' failed to fetch bodyPart in  BINARY. Try BODY');
4417 4417
 			$partToReturn = $this->getBodyPart($_uid, $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, false);
4418 4418
 		}
4419
-		return ($partToReturn?$partToReturn:null);
4419
+		return ($partToReturn ? $partToReturn : null);
4420 4420
 	}
4421 4421
 
4422 4422
 	/**
@@ -4429,13 +4429,13 @@  discard block
 block discarded – undo
4429 4429
 	 * @param boolean $_stream = false true return a stream, false return string
4430 4430
 	 * @return array containing the desired text part, mimeType and charset
4431 4431
 	 */
4432
-	function getTextPart($_uid, Horde_Mime_Part $_structure, $_htmlMode='', $_preserveSeen=false, $_stream=false)
4432
+	function getTextPart($_uid, Horde_Mime_Part $_structure, $_htmlMode = '', $_preserveSeen = false, $_stream = false)
4433 4433
 	{
4434 4434
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_uid.':'.array2string($_structure).' '.function_backtrace());
4435 4435
 		$bodyPart = array();
4436
-		if (self::$debug) _debug_array(array($_structure,function_backtrace()));
4436
+		if (self::$debug) _debug_array(array($_structure, function_backtrace()));
4437 4437
 
4438
-		if($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text')))
4438
+		if ($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text')))
4439 4439
 		{
4440 4440
 			$bodyPart = array(
4441 4441
 				'error'		=> 1,
@@ -4481,10 +4481,10 @@  discard block
 block discarded – undo
4481 4481
 	 * @param string $_folder folder to work on
4482 4482
 	 * @return array containing the message body, mimeType and charset
4483 4483
 	 */
4484
-	function getMessageBody($_uid, $_htmlOptions='', $_partID=null, Horde_Mime_Part $_structure=null, $_preserveSeen = false, $_folder = '')
4484
+	function getMessageBody($_uid, $_htmlOptions = '', $_partID = null, Horde_Mime_Part $_structure = null, $_preserveSeen = false, $_folder = '')
4485 4485
 	{
4486 4486
 		if (self::$debug) echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
4487
-		if($_htmlOptions != '') {
4487
+		if ($_htmlOptions != '') {
4488 4488
 			$this->htmlOptions = $_htmlOptions;
4489 4489
 		}
4490 4490
 		if (empty($_folder))
@@ -4505,7 +4505,7 @@  discard block
 block discarded – undo
4505 4505
 			return array(
4506 4506
 				array(
4507 4507
 					'error'		=> 1,
4508
-					'body'		=> 'Error: Could not fetch structure on mail:'.$_uid." as $_htmlOptions". 'for Mailprofile'.$this->icServer->ImapServerId.' User:'.$GLOBALS['egw_info']['user']['account_lid'],
4508
+					'body'		=> 'Error: Could not fetch structure on mail:'.$_uid." as $_htmlOptions".'for Mailprofile'.$this->icServer->ImapServerId.' User:'.$GLOBALS['egw_info']['user']['account_lid'],
4509 4509
 					'mimeType'	=> 'text/plain',
4510 4510
 					'charSet'	=> self::$displayCharset,
4511 4511
 				)
@@ -4518,7 +4518,7 @@  discard block
 block discarded – undo
4518 4518
 			//_debug_array($_structure->getMimeId()); exit;
4519 4519
 		}
4520 4520
 
4521
-		switch($_structure->getPrimaryType())
4521
+		switch ($_structure->getPrimaryType())
4522 4522
 		{
4523 4523
 			case 'application':
4524 4524
 				return array(
@@ -4530,7 +4530,7 @@  discard block
 block discarded – undo
4530 4530
 				);
4531 4531
 
4532 4532
 			case 'multipart':
4533
-				switch($_structure->getSubType())
4533
+				switch ($_structure->getSubType())
4534 4534
 				{
4535 4535
 					case 'alternative':
4536 4536
 						$bodyParts = array($this->getMultipartAlternative($_uid, $_structure, $this->htmlOptions, $_preserveSeen));
@@ -4564,7 +4564,7 @@  discard block
 block discarded – undo
4564 4564
 				$bodyPart = array();
4565 4565
 				if ($_structure->getDisposition() != 'attachment')
4566 4566
 				{
4567
-					switch($_structure->getSubType())
4567
+					switch ($_structure->getSubType())
4568 4568
 					{
4569 4569
 						case 'calendar':
4570 4570
 							// this is handeled in getTextPart
@@ -4580,11 +4580,11 @@  discard block
 block discarded – undo
4580 4580
 
4581 4581
 			case 'attachment':
4582 4582
 			case 'message':
4583
-				switch($_structure->getSubType())
4583
+				switch ($_structure->getSubType())
4584 4584
 				{
4585 4585
 					case 'rfc822':
4586 4586
 						$newStructure = $_structure->getParts();
4587
-						if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
4587
+						if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]); }
4588 4588
 						return self::normalizeBodyParts($this->getMessageBody($_uid, $_htmlOptions, $newStructure[0]->getMimeId(), $newStructure[0], $_preserveSeen, $_folder));
4589 4589
 				}
4590 4590
 				break;
@@ -4612,11 +4612,11 @@  discard block
 block discarded – undo
4612 4612
 	{
4613 4613
 		if (is_array($_bodyParts))
4614 4614
 		{
4615
-			foreach($_bodyParts as $singleBodyPart)
4615
+			foreach ($_bodyParts as $singleBodyPart)
4616 4616
 			{
4617 4617
 				if (!isset($singleBodyPart['body'])) {
4618 4618
 					$buff = self::normalizeBodyParts($singleBodyPart);
4619
-					foreach ((array)$buff as $val) { $body2return[] = $val;}
4619
+					foreach ((array)$buff as $val) { $body2return[] = $val; }
4620 4620
 					continue;
4621 4621
 				}
4622 4622
 				$body2return[] = $singleBodyPart;
@@ -4637,14 +4637,14 @@  discard block
 block discarded – undo
4637 4637
 	 * @param boolean $useTidy  switch to use tidy
4638 4638
 	 * @return string a preformatted string with the mails converted to text
4639 4639
 	 */
4640
-	static function &getdisplayableBody(&$mailClass, $bodyParts, $preserveHTML = false,  $useTidy = true)
4640
+	static function &getdisplayableBody(&$mailClass, $bodyParts, $preserveHTML = false, $useTidy = true)
4641 4641
 	{
4642
-		$message='';
4643
-		for($i=0; $i<count($bodyParts); $i++)
4642
+		$message = '';
4643
+		for ($i = 0; $i < count($bodyParts); $i++)
4644 4644
 		{
4645 4645
 			if (!isset($bodyParts[$i]['body'])) {
4646 4646
 				$bodyParts[$i]['body'] = self::getdisplayableBody($mailClass, $bodyParts[$i], $preserveHTML, $useTidy);
4647
-				$message .= empty($bodyParts[$i]['body'])?'':$bodyParts[$i]['body'];
4647
+				$message .= empty($bodyParts[$i]['body']) ? '' : $bodyParts[$i]['body'];
4648 4648
 				continue;
4649 4649
 			}
4650 4650
 			if (isset($bodyParts[$i]['error'])) continue;
@@ -4669,32 +4669,32 @@  discard block
 block discarded – undo
4669 4669
 				'(R)',
4670 4670
 			);
4671 4671
 
4672
-			if(($bodyParts[$i]['mimeType'] == 'text/html' || $bodyParts[$i]['mimeType'] == 'text/plain') &&
4672
+			if (($bodyParts[$i]['mimeType'] == 'text/html' || $bodyParts[$i]['mimeType'] == 'text/plain') &&
4673 4673
 				strtoupper($bodyParts[$i]['charSet']) != 'UTF-8')
4674 4674
 			{
4675
-				$bodyParts[$i]['body'] = preg_replace($sar,$rar,$bodyParts[$i]['body']);
4675
+				$bodyParts[$i]['body'] = preg_replace($sar, $rar, $bodyParts[$i]['body']);
4676 4676
 			}
4677 4677
 
4678
-			if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = translation::detect_encoding($bodyParts[$i]['body']);
4678
+			if ($bodyParts[$i]['charSet'] === false) $bodyParts[$i]['charSet'] = translation::detect_encoding($bodyParts[$i]['body']);
4679 4679
 			// add line breaks to $bodyParts
4680 4680
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
4681
-			$newBody  = translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
4681
+			$newBody = translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
4682 4682
 			//error_log(__METHOD__.' ('.__LINE__.') '.' MimeType:'.$bodyParts[$i]['mimeType'].'->'.$newBody);
4683 4683
 			$mailClass->activeMimeType = 'text/plain';
4684 4684
 			if ($bodyParts[$i]['mimeType'] == 'text/html') {
4685 4685
 				$mailClass->activeMimeType = $bodyParts[$i]['mimeType'];
4686 4686
 				if (!$preserveHTML)
4687 4687
 				{
4688
-					$alreadyHtmlLawed=false;
4688
+					$alreadyHtmlLawed = false;
4689 4689
 					// as translation::convert reduces \r\n to \n and purifier eats \n -> peplace it with a single space
4690
-					$newBody = str_replace("\n"," ",$newBody);
4690
+					$newBody = str_replace("\n", " ", $newBody);
4691 4691
 					// convert HTML to text, as we dont want HTML in infologs
4692 4692
 					if ($useTidy && extension_loaded('tidy'))
4693 4693
 					{
4694 4694
 						$tidy = new tidy();
4695
-						$cleaned = $tidy->repairString($newBody, self::$tidy_config,'utf8');
4695
+						$cleaned = $tidy->repairString($newBody, self::$tidy_config, 'utf8');
4696 4696
 						// Found errors. Strip it all so there's some output
4697
-						if($tidy->getStatus() == 2)
4697
+						if ($tidy->getStatus() == 2)
4698 4698
 						{
4699 4699
 							error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$tidy->errorBuffer);
4700 4700
 						}
@@ -4705,7 +4705,7 @@  discard block
 block discarded – undo
4705 4705
 						if (!$preserveHTML)
4706 4706
 						{
4707 4707
 							// filter only the 'body', as we only want that part, if we throw away the html
4708
-							preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
4708
+							preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches = array());
4709 4709
 							if ($matches[2])
4710 4710
 							{
4711 4711
 								$hasOther = true;
@@ -4716,7 +4716,7 @@  discard block
 block discarded – undo
4716 4716
 					else
4717 4717
 					{
4718 4718
 						// htmLawed filter only the 'body'
4719
-						preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
4719
+						preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches = array());
4720 4720
 						if ($matches[2])
4721 4721
 						{
4722 4722
 							$hasOther = true;
@@ -4725,17 +4725,17 @@  discard block
 block discarded – undo
4725 4725
 						$htmLawed = new egw_htmLawed();
4726 4726
 						// the next line should not be needed, but produces better results on HTML 2 Text conversion,
4727 4727
 						// as we switched off HTMLaweds tidy functionality
4728
-						$newBody = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<BR>','<BR>','<BR>'),$newBody);
4729
-						$newBody = $htmLawed->egw_htmLawed($newBody,self::$htmLawed_config);
4730
-						if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3];
4731
-						$alreadyHtmlLawed=true;
4728
+						$newBody = str_replace(array('&amp;amp;', '<DIV><BR></DIV>', "<DIV>&nbsp;</DIV>", '<div>&nbsp;</div>'), array('&amp;', '<BR>', '<BR>', '<BR>'), $newBody);
4729
+						$newBody = $htmLawed->egw_htmLawed($newBody, self::$htmLawed_config);
4730
+						if ($hasOther && $preserveHTML) $newBody = $matches[1].$newBody.$matches[3];
4731
+						$alreadyHtmlLawed = true;
4732 4732
 					}
4733 4733
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after purify:'.$newBody);
4734
-					if ($preserveHTML==false) $newBody = translation::convertHTMLToText($newBody,self::$displayCharset,true,true);
4734
+					if ($preserveHTML == false) $newBody = translation::convertHTMLToText($newBody, self::$displayCharset, true, true);
4735 4735
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after convertHTMLToText:'.$newBody);
4736
-					if ($preserveHTML==false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n
4736
+					if ($preserveHTML == false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n
4737 4737
 					/*if (!$alreadyHtmlLawed) */ $mailClass->getCleanHTML($newBody); // remove stuff we regard as unwanted
4738
-					if ($preserveHTML==false) $newBody = str_replace("<br />","\r\n",$newBody);
4738
+					if ($preserveHTML == false) $newBody = str_replace("<br />", "\r\n", $newBody);
4739 4739
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after getClean:'.$newBody);
4740 4740
 				}
4741 4741
 				$message .= $newBody;
@@ -4744,9 +4744,9 @@  discard block
 block discarded – undo
4744 4744
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Body(after specialchars):'.$newBody);
4745 4745
 			//use translation::convertHTMLToText instead of strip_tags, (even message is plain text) as strip_tags eats away too much
4746 4746
 			//$newBody = strip_tags($newBody); //we need to fix broken tags (or just stuff like "<800 USD/p" )
4747
-			$newBody = translation::convertHTMLToText($newBody,self::$displayCharset,false,false);
4747
+			$newBody = translation::convertHTMLToText($newBody, self::$displayCharset, false, false);
4748 4748
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Body(after strip tags):'.$newBody);
4749
-			$newBody = htmlspecialchars_decode($newBody,ENT_QUOTES);
4749
+			$newBody = htmlspecialchars_decode($newBody, ENT_QUOTES);
4750 4750
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Body (after hmlspc_decode):'.$newBody);
4751 4751
 			$message .= $newBody;
4752 4752
 			//continue;
@@ -4754,27 +4754,27 @@  discard block
 block discarded – undo
4754 4754
 		return $message;
4755 4755
 	}
4756 4756
 
4757
-	static function wordwrap($str, $cols, $cut, $dontbreaklinesstartingwith=false)
4757
+	static function wordwrap($str, $cols, $cut, $dontbreaklinesstartingwith = false)
4758 4758
 	{
4759 4759
 		$lines = explode("\n", $str);
4760 4760
 		$newStr = '';
4761
-		foreach($lines as $line)
4761
+		foreach ($lines as $line)
4762 4762
 		{
4763 4763
 			// replace tabs by 8 space chars, or any tab only counts one char
4764 4764
 			//$line = str_replace("\t","        ",$line);
4765 4765
 			//$newStr .= wordwrap($line, $cols, $cut);
4766
-			$allowedLength = $cols-strlen($cut);
4766
+			$allowedLength = $cols - strlen($cut);
4767 4767
 			//dont try to break lines with links, chance is we mess up the text is way too big
4768
-			if (strlen($line) > $allowedLength && stripos($line,'href=')===false &&
4769
-				($dontbreaklinesstartingwith==false ||
4768
+			if (strlen($line) > $allowedLength && stripos($line, 'href=') === false &&
4769
+				($dontbreaklinesstartingwith == false ||
4770 4770
 				 ($dontbreaklinesstartingwith &&
4771
-				  strlen($dontbreaklinesstartingwith)>=1 &&
4772
-				  substr($line,0,strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
4771
+				  strlen($dontbreaklinesstartingwith) >= 1 &&
4772
+				  substr($line, 0, strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
4773 4773
 				 )
4774 4774
 				)
4775 4775
 			   )
4776 4776
 			{
4777
-				$s=explode(" ", $line);
4777
+				$s = explode(" ", $line);
4778 4778
 				$line = "";
4779 4779
 				$linecnt = 0;
4780 4780
 				foreach ($s as &$v) {
@@ -4782,22 +4782,22 @@  discard block
 block discarded – undo
4782 4782
 					// only break long words within the wordboundaries,
4783 4783
 					// but it may destroy links, so we check for href and dont do it if we find one
4784 4784
 					// we check for any html within the word, because we do not want to break html by accident
4785
-					if($cnt > $allowedLength && stripos($v,'href=')===false && stripos($v,'onclick=')===false && $cnt == strlen(html_entity_decode($v)))
4785
+					if ($cnt > $allowedLength && stripos($v, 'href=') === false && stripos($v, 'onclick=') === false && $cnt == strlen(html_entity_decode($v)))
4786 4786
 					{
4787
-						$v=wordwrap($v, $allowedLength, $cut, true);
4787
+						$v = wordwrap($v, $allowedLength, $cut, true);
4788 4788
 					}
4789 4789
 					// the rest should be broken at the start of the new word that exceeds the limit
4790
-					if ($linecnt+$cnt > $allowedLength) {
4791
-						$v=$cut.$v;
4790
+					if ($linecnt + $cnt > $allowedLength) {
4791
+						$v = $cut.$v;
4792 4792
 						#$linecnt = 0;
4793
-						$linecnt =strlen($v)-strlen($cut);
4793
+						$linecnt = strlen($v) - strlen($cut);
4794 4794
 					} else {
4795 4795
 						$linecnt += $cnt;
4796 4796
 					}
4797 4797
 					if (strlen($v)) $line .= (strlen($line) ? " " : "").$v;
4798 4798
 				}
4799 4799
 			}
4800
-			$newStr .= $line . "\n";
4800
+			$newStr .= $line."\n";
4801 4801
 		}
4802 4802
 		return $newStr;
4803 4803
 	}
@@ -4812,12 +4812,12 @@  discard block
 block discarded – undo
4812 4812
 	 * @param boolean $_useHeaderInsteadOfEnvelope - force getMessageHeader method to be used for fetching Envelope Information
4813 4813
 	 * @return array the message header
4814 4814
 	 */
4815
-	function getMessageEnvelope($_uid, $_partID = '',$decode=false, $_folder='', $_useHeaderInsteadOfEnvelope=false)
4815
+	function getMessageEnvelope($_uid, $_partID = '', $decode = false, $_folder = '', $_useHeaderInsteadOfEnvelope = false)
4816 4816
 	{
4817 4817
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder".function_backtrace());
4818
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
4818
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
4819 4819
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder");
4820
-		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false) {
4820
+		if ((empty($_partID) || $_partID == 'null') && $_useHeaderInsteadOfEnvelope === false) {
4821 4821
 			$uidsToFetch = new Horde_Imap_Client_Ids();
4822 4822
 			if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
4823 4823
 			$uidsToFetch->add($_uid);
@@ -4829,7 +4829,7 @@  discard block
 block discarded – undo
4829 4829
 				'ids' => $uidsToFetch,
4830 4830
 			));
4831 4831
 			if (is_object($headersNew)) {
4832
-				foreach($headersNew as &$_headerObject) {
4832
+				foreach ($headersNew as &$_headerObject) {
4833 4833
 					$env = $_headerObject->getEnvelope();
4834 4834
 					//_debug_array($envFields->singleFields());
4835 4835
 					$singleFields = $envFields->singleFields();
@@ -4844,33 +4844,33 @@  discard block
 block discarded – undo
4844 4844
 							case 'bcc':
4845 4845
 							case 'sender':
4846 4846
 								//error_log(__METHOD__.' ('.__LINE__.') '.$v.'->'.array2string($env->$v->addresses));
4847
-								$envelope[$v]=$env->$v->addresses;
4847
+								$envelope[$v] = $env->$v->addresses;
4848 4848
 								$address = array();
4849 4849
 								if (!is_array($envelope[$v])) break;
4850 4850
 								foreach ($envelope[$v] as $k => $ad)
4851 4851
 								{
4852
-									if (stripos($ad,'@')===false)
4852
+									if (stripos($ad, '@') === false)
4853 4853
 									{
4854
-										$remember=$k;
4854
+										$remember = $k;
4855 4855
 									}
4856 4856
 									else
4857 4857
 									{
4858
-										$address[] = (!is_null($remember)?$envelope[$v][$remember].' ':'').$ad;
4859
-										$remember=null;
4858
+										$address[] = (!is_null($remember) ? $envelope[$v][$remember].' ' : '').$ad;
4859
+										$remember = null;
4860 4860
 									}
4861 4861
 								}
4862 4862
 								$envelope[$v] = $address;
4863 4863
 								break;
4864 4864
 							case 'date':
4865
-								$envelope[$v]=egw_time::to($env->$v);
4865
+								$envelope[$v] = egw_time::to($env->$v);
4866 4866
 								break;
4867 4867
 							default:
4868
-								$envelope[$v]=$env->$v;
4868
+								$envelope[$v] = $env->$v;
4869 4869
 						}
4870 4870
 					}
4871 4871
 				}
4872 4872
 			}
4873
-			$envelope = array_change_key_case($envelope,CASE_UPPER);
4873
+			$envelope = array_change_key_case($envelope, CASE_UPPER);
4874 4874
 			//if ($decode) _debug_array($envelope);
4875 4875
 			//error_log(__METHOD__.' ('.__LINE__.') '.array2string($envelope));
4876 4876
 			if ($decode)
@@ -4878,19 +4878,19 @@  discard block
 block discarded – undo
4878 4878
 				foreach ($envelope as $key => $rvV)
4879 4879
 				{
4880 4880
 					//try idn conversion only on 'FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO'
4881
-					$envelope[$key]=self::decode_header($rvV,in_array($key,array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
4881
+					$envelope[$key] = self::decode_header($rvV, in_array($key, array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
4882 4882
 				}
4883 4883
 			}
4884 4884
 			return $envelope;
4885 4885
 		} else {
4886 4886
 
4887
-			$headers = $this->getMessageHeader($_uid, $_partID, true,true,$_folder);
4887
+			$headers = $this->getMessageHeader($_uid, $_partID, true, true, $_folder);
4888 4888
 
4889 4889
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.array2string($headers));
4890 4890
 			//_debug_array($headers);
4891 4891
 			$newData = array(
4892 4892
 				'DATE'		=> $headers['DATE'],
4893
-				'SUBJECT'	=> ($decode ? self::decode_header($headers['SUBJECT']):$headers['SUBJECT']),
4893
+				'SUBJECT'	=> ($decode ? self::decode_header($headers['SUBJECT']) : $headers['SUBJECT']),
4894 4894
 				'MESSAGE_ID'	=> $headers['MESSAGE-ID']
4895 4895
 			);
4896 4896
 			if (isset($headers['IN-REPLY-TO'])) $newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
@@ -4900,11 +4900,11 @@  discard block
 block discarded – undo
4900 4900
 			if (isset($headers['LIST-ID'])) $newData['LIST-ID'] = $headers['LIST-ID'];
4901 4901
 			//_debug_array($newData);
4902 4902
 			$recepientList = array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO');
4903
-			foreach($recepientList as $recepientType) {
4904
-				if(isset($headers[$recepientType])) {
4905
-					if ($decode) $headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
4903
+			foreach ($recepientList as $recepientType) {
4904
+				if (isset($headers[$recepientType])) {
4905
+					if ($decode) $headers[$recepientType] = self::decode_header($headers[$recepientType], true);
4906 4906
 					//error_log(__METHOD__.__LINE__." ".$recepientType."->".array2string($headers[$recepientType]));
4907
-					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress) {
4907
+					foreach (self::parseAddressList($headers[$recepientType]) as $singleAddress) {
4908 4908
 						$addressData = array(
4909 4909
 							'PERSONAL_NAME'		=> $singleAddress->personal ? $singleAddress->personal : 'NIL',
4910 4910
 							'AT_DOMAIN_LIST'	=> $singleAddress->adl ? $singleAddress->adl : 'NIL',
@@ -4912,15 +4912,15 @@  discard block
 block discarded – undo
4912 4912
 							'HOST_NAME'		=> $singleAddress->host ? $singleAddress->host : 'NIL',
4913 4913
 							'EMAIL'			=> $singleAddress->host ? $singleAddress->mailbox.'@'.$singleAddress->host : $singleAddress->mailbox,
4914 4914
 						);
4915
-						if($addressData['PERSONAL_NAME'] != 'NIL') {
4915
+						if ($addressData['PERSONAL_NAME'] != 'NIL') {
4916 4916
 							$addressData['RFC822_EMAIL'] = imap_rfc822_write_address($singleAddress->mailbox, $singleAddress->host, $singleAddress->personal);
4917 4917
 						} else {
4918 4918
 							$addressData['RFC822_EMAIL'] = 'NIL';
4919 4919
 						}
4920
-						$newData[$recepientType][] = ($addressData['RFC822_EMAIL']!='NIL'?$addressData['RFC822_EMAIL']:$addressData['EMAIL']);//$addressData;
4920
+						$newData[$recepientType][] = ($addressData['RFC822_EMAIL'] != 'NIL' ? $addressData['RFC822_EMAIL'] : $addressData['EMAIL']); //$addressData;
4921 4921
 					}
4922 4922
 				} else {
4923
-					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') {
4923
+					if ($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') {
4924 4924
 						$newData[$recepientType] = $newData['FROM'];
4925 4925
 					} else {
4926 4926
 						$newData[$recepientType] = array();
@@ -4942,10 +4942,10 @@  discard block
 block discarded – undo
4942 4942
 	 * @param string $_folder folder to work on
4943 4943
 	 * @return array|Horde_Mime_Headers message header as array or object
4944 4944
 	 */
4945
-	function getMessageHeader($_uid, $_partID = '',$decode=false, $preserveUnSeen=false, $_folder='')
4945
+	function getMessageHeader($_uid, $_partID = '', $decode = false, $preserveUnSeen = false, $_folder = '')
4946 4946
 	{
4947 4947
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$_uid.', '.$_partID.', '.$decode.', '.$preserveUnSeen.', '.$_folder);
4948
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
4948
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
4949 4949
 		$uidsToFetch = new Horde_Imap_Client_Ids();
4950 4950
 		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
4951 4951
 		$uidsToFetch->add($_uid);
@@ -4953,7 +4953,7 @@  discard block
 block discarded – undo
4953 4953
 		$fquery = new Horde_Imap_Client_Fetch_Query();
4954 4954
 		if ($_partID != '')
4955 4955
 		{
4956
-			$fquery->headerText(array('id'=>$_partID,'peek'=>$preserveUnSeen));
4956
+			$fquery->headerText(array('id'=>$_partID, 'peek'=>$preserveUnSeen));
4957 4957
 			$fquery->structure();
4958 4958
 		}
4959 4959
 		else
@@ -4964,18 +4964,18 @@  discard block
 block discarded – undo
4964 4964
 			'ids' => $uidsToFetch,
4965 4965
 		));
4966 4966
 		if (is_object($headersNew)) {
4967
-			foreach($headersNew as $_fetchObject)
4967
+			foreach ($headersNew as $_fetchObject)
4968 4968
 			{
4969
-				$headers = $_fetchObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
4969
+				$headers = $_fetchObject->getHeaderText(0, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
4970 4970
 				if ($_partID != '')
4971 4971
 				{
4972 4972
 					$mailStructureObject = $_fetchObject->getStructure();
4973 4973
 					foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
4974 4974
 					{
4975
-						if ($mime_id==$_partID)
4975
+						if ($mime_id == $_partID)
4976 4976
 						{
4977 4977
 							//error_log(__METHOD__.' ('.__LINE__.') '."$mime_id == $_partID".array2string($_headerObject->getHeaderText($mime_id,Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray()));
4978
-							$headers = $_fetchObject->getHeaderText($mime_id,Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
4978
+							$headers = $_fetchObject->getHeaderText($mime_id, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
4979 4979
 							break;
4980 4980
 						}
4981 4981
 					}
@@ -4986,14 +4986,14 @@  discard block
 block discarded – undo
4986 4986
 				if (is_object($headers)) $headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
4987 4987
 				return $headers;
4988 4988
 			}
4989
-			$retValue = is_object($headers) ? $headers->toArray():array();
4989
+			$retValue = is_object($headers) ? $headers->toArray() : array();
4990 4990
 		}
4991
-		$retValue = array_change_key_case($retValue,CASE_UPPER);
4991
+		$retValue = array_change_key_case($retValue, CASE_UPPER);
4992 4992
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue));
4993 4993
 		// if SUBJECT is an array, use thelast one, as we assume something with the unfolding for the subject did not work
4994 4994
 		if (is_array($retValue['SUBJECT']))
4995 4995
 		{
4996
-			$retValue['SUBJECT'] = $retValue['SUBJECT'][count($retValue['SUBJECT'])-1];
4996
+			$retValue['SUBJECT'] = $retValue['SUBJECT'][count($retValue['SUBJECT']) - 1];
4997 4997
 		}
4998 4998
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.array2string($decode ? self::decode_header($retValue,true):$retValue));
4999 4999
 		if ($decode)
@@ -5001,7 +5001,7 @@  discard block
 block discarded – undo
5001 5001
 			foreach ($retValue as $key => $rvV)
5002 5002
 			{
5003 5003
 				//try idn conversion only on 'FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO'
5004
-				$retValue[$key]=self::decode_header($rvV,in_array($key,array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5004
+				$retValue[$key] = self::decode_header($rvV, in_array($key, array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5005 5005
 			}
5006 5006
 		}
5007 5007
 		return $retValue;
@@ -5018,14 +5018,14 @@  discard block
 block discarded – undo
5018 5018
 	function getMessageRawHeader($_uid, $_partID = '', $_folder = '')
5019 5019
 	{
5020 5020
 		static $rawHeaders;
5021
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5021
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5022 5022
 		//error_log(__METHOD__.' ('.__LINE__.') '." Try Using Cache for raw Header $_uid, $_partID in Folder $_folder");
5023 5023
 
5024
-		if (is_null($rawHeaders)||!is_array($rawHeaders)) $rawHeaders = egw_cache::getCache(egw_cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
5025
-		if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5024
+		if (is_null($rawHeaders) || !is_array($rawHeaders)) $rawHeaders = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
5025
+		if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)]))
5026 5026
 		{
5027 5027
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Header $_uid, $_partID in Folder $_folder");
5028
-			return $rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)];
5028
+			return $rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)];
5029 5029
 		}
5030 5030
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5031 5031
 		$uid = $_uid;
@@ -5035,7 +5035,7 @@  discard block
 block discarded – undo
5035 5035
 		$fquery = new Horde_Imap_Client_Fetch_Query();
5036 5036
 		if ($_partID != '')
5037 5037
 		{
5038
-			$fquery->headerText(array('id'=>$_partID,'peek'=>true));
5038
+			$fquery->headerText(array('id'=>$_partID, 'peek'=>true));
5039 5039
 			$fquery->structure();
5040 5040
 		}
5041 5041
 		else
@@ -5046,14 +5046,14 @@  discard block
 block discarded – undo
5046 5046
 			'ids' => $uidsToFetch,
5047 5047
 		));
5048 5048
 		if (is_object($headersNew)) {
5049
-			foreach($headersNew as &$_headerObject) {
5049
+			foreach ($headersNew as &$_headerObject) {
5050 5050
 				$retValue = $_headerObject->getHeaderText();
5051 5051
 				if ($_partID != '')
5052 5052
 				{
5053 5053
 					$mailStructureObject = $_headerObject->getStructure();
5054 5054
 					foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
5055 5055
 					{
5056
-						if ($mime_id==$_partID)
5056
+						if ($mime_id == $_partID)
5057 5057
 						{
5058 5058
 							$retValue = $_headerObject->getHeaderText($mime_id);
5059 5059
 						}
@@ -5061,8 +5061,8 @@  discard block
 block discarded – undo
5061 5061
 				}
5062 5062
 			}
5063 5063
 		}
5064
-		$rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]=$retValue;
5065
-		egw_cache::setCache(egw_cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),$rawHeaders,60*60*1);
5064
+		$rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)] = $retValue;
5065
+		egw_cache::setCache(egw_cache::INSTANCE, 'email', 'rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']), $rawHeaders, 60 * 60 * 1);
5066 5066
 		return $retValue;
5067 5067
 	}
5068 5068
 
@@ -5075,25 +5075,25 @@  discard block
 block discarded – undo
5075 5075
 	{
5076 5076
 		$style = '';
5077 5077
 		if (empty($_bodyParts)) return "";
5078
-		foreach((array)$_bodyParts as $singleBodyPart) {
5078
+		foreach ((array)$_bodyParts as $singleBodyPart) {
5079 5079
 			if (!isset($singleBodyPart['body'])) {
5080 5080
 				$singleBodyPart['body'] = self::getStyles($singleBodyPart);
5081 5081
 				$style .= $singleBodyPart['body'];
5082 5082
 				continue;
5083 5083
 			}
5084 5084
 
5085
-			if ($singleBodyPart['charSet']===false) $singleBodyPart['charSet'] = translation::detect_encoding($singleBodyPart['body']);
5085
+			if ($singleBodyPart['charSet'] === false) $singleBodyPart['charSet'] = translation::detect_encoding($singleBodyPart['body']);
5086 5086
 			$singleBodyPart['body'] = translation::convert(
5087 5087
 				$singleBodyPart['body'],
5088 5088
 				strtolower($singleBodyPart['charSet'])
5089 5089
 			);
5090 5090
 			$ct = 0;
5091
-			$newStyle=array();
5092
-			if (stripos($singleBodyPart['body'],'<style')!==false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
5093
-			if ($ct>0)
5091
+			$newStyle = array();
5092
+			if (stripos($singleBodyPart['body'], '<style') !== false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
5093
+			if ($ct > 0)
5094 5094
 			{
5095 5095
 				//error_log(__METHOD__.' ('.__LINE__.') '.'#'.$ct.'#'.array2string($newStyle));
5096
-				$style2buffer = implode('',$newStyle[0]);
5096
+				$style2buffer = implode('', $newStyle[0]);
5097 5097
 			}
5098 5098
 			if ($style2buffer && strtoupper(self::$displayCharset) == 'UTF-8')
5099 5099
 			{
@@ -5101,7 +5101,7 @@  discard block
 block discarded – undo
5101 5101
 				$test = json_encode($style2buffer);
5102 5102
 				//error_log(__METHOD__.' ('.__LINE__.') '.'#'.$test.'# ->'.strlen($style2buffer).' Error:'.json_last_error());
5103 5103
 				//if (json_last_error() != JSON_ERROR_NONE && strlen($style2buffer)>0)
5104
-				if ($test=="null" && strlen($style2buffer)>0)
5104
+				if ($test == "null" && strlen($style2buffer) > 0)
5105 5105
 				{
5106 5106
 					// this should not be needed, unless something fails with charset detection/ wrong charset passed
5107 5107
 					error_log(__METHOD__.' ('.__LINE__.') '.' Found Invalid sequence for utf-8 in CSS:'.$style2buffer.' Charset Reported:'.$singleBodyPart['charSet'].' Carset Detected:'.translation::detect_encoding($style2buffer));
@@ -5112,19 +5112,19 @@  discard block
 block discarded – undo
5112 5112
 		}
5113 5113
 		// clean out comments and stuff
5114 5114
 		$search = array(
5115
-			'@url\(http:\/\/[^\)].*?\)@si',  // url calls e.g. in style definitions
5115
+			'@url\(http:\/\/[^\)].*?\)@si', // url calls e.g. in style definitions
5116 5116
 //			'@<!--[\s\S]*?[ \t\n\r]*-->@',   // Strip multi-line comments including CDATA
5117 5117
 //			'@<!--[\s\S]*?[ \t\n\r]*--@',    // Strip broken multi-line comments including CDATA
5118 5118
 		);
5119
-		$style = preg_replace($search,"",$style);
5119
+		$style = preg_replace($search, "", $style);
5120 5120
 
5121 5121
 		// CSS Security
5122 5122
 		// http://code.google.com/p/browsersec/wiki/Part1#Cascading_stylesheets
5123
-		$css = preg_replace('/(javascript|expression|-moz-binding)/i','',$style);
5124
-		if (stripos($css,'script')!==false) translation::replaceTagsCompletley($css,'script'); // Strip out script that may be included
5123
+		$css = preg_replace('/(javascript|expression|-moz-binding)/i', '', $style);
5124
+		if (stripos($css, 'script') !== false) translation::replaceTagsCompletley($css, 'script'); // Strip out script that may be included
5125 5125
 		// 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
5126 5126
 		// as the comments as <!-- styledefinition --> in stylesheet are outdated, and ck-editor does not understand it, we remove it
5127
-		$css = str_replace(array(':','<!--','-->'),array(': ','',''),$css);
5127
+		$css = str_replace(array(':', '<!--', '-->'), array(': ', '', ''), $css);
5128 5128
 		//error_log(__METHOD__.' ('.__LINE__.') '.$css);
5129 5129
 		// TODO: we may have to strip urls and maybe comments and ifs
5130 5130
 		return $css;
@@ -5138,16 +5138,16 @@  discard block
 block discarded – undo
5138 5138
 	 * @param string $_folder folder to work on
5139 5139
 	 * @return string the message body
5140 5140
 	 */
5141
-	function getMessageRawBody($_uid, $_partID = '', $_folder='')
5141
+	function getMessageRawBody($_uid, $_partID = '', $_folder = '')
5142 5142
 	{
5143 5143
 		//TODO: caching einbauen static!
5144 5144
 		static $rawBody;
5145 5145
 		if (is_null($rawBody)) $rawBody = array();
5146
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5147
-		if (isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5146
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5147
+		if (isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)]))
5148 5148
 		{
5149 5149
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Body $_uid, $_partID in Folder $_folder");
5150
-			return $rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)];
5150
+			return $rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)];
5151 5151
 		}
5152 5152
 
5153 5153
 		$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -5160,13 +5160,13 @@  discard block
 block discarded – undo
5160 5160
 		if ($_partID != '')
5161 5161
 		{
5162 5162
 			$fquery->structure();
5163
-			$fquery->bodyPart($_partID,array('peek'=>true));
5163
+			$fquery->bodyPart($_partID, array('peek'=>true));
5164 5164
 		}
5165 5165
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5166 5166
 			'ids' => $uidsToFetch,
5167 5167
 		));
5168 5168
 		if (is_object($headersNew)) {
5169
-			foreach($headersNew as &$_headerObject) {
5169
+			foreach ($headersNew as &$_headerObject) {
5170 5170
 				$body = $_headerObject->getFullMsg();
5171 5171
 				if ($_partID != '')
5172 5172
 				{
@@ -5174,7 +5174,7 @@  discard block
 block discarded – undo
5174 5174
 					//_debug_array($mailStructureObject->contentTypeMap());
5175 5175
 					foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
5176 5176
 					{
5177
-						if ($mime_id==$_partID)
5177
+						if ($mime_id == $_partID)
5178 5178
 						{
5179 5179
 							$body = $_headerObject->getBodyPart($mime_id);
5180 5180
 						}
@@ -5183,7 +5183,7 @@  discard block
 block discarded – undo
5183 5183
 			}
5184 5184
 		}
5185 5185
 		//error_log(__METHOD__.' ('.__LINE__.') '."[$this->icServer->ImapServerId][$_folder][$_uid][".(empty($_partID)?'NIL':$_partID)."]");
5186
-		$rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)] = $body;
5186
+		$rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)] = $body;
5187 5187
 		return $body;
5188 5188
 	}
5189 5189
 
@@ -5197,13 +5197,13 @@  discard block
 block discarded – undo
5197 5197
 	 * @param Horde_Imap_Client_Fetch_Query $fquery=null default query just structure
5198 5198
 	 * @return Horde_Mime_Part
5199 5199
 	 */
5200
-	function getStructure($_uid, $_partID=null, $_folder=null, $_preserveSeen=false)
5200
+	function getStructure($_uid, $_partID = null, $_folder = null, $_preserveSeen = false)
5201 5201
 	{
5202
-		if (self::$debug) error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
5202
+		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
5203 5203
 
5204 5204
 		if (empty($_folder))
5205 5205
 		{
5206
-			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5206
+			$_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5207 5207
 		}
5208 5208
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5209 5209
 		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
@@ -5221,7 +5221,7 @@  discard block
 block discarded – undo
5221 5221
 				'ids' => $uidsToFetch,
5222 5222
 			))->first();
5223 5223
 
5224
-			return is_object($mail)?$mail->getStructure():null;
5224
+			return is_object($mail) ? $mail->getStructure() : null;
5225 5225
 		}
5226 5226
 		catch (Exception $e)
5227 5227
 		{
@@ -5244,14 +5244,14 @@  discard block
 block discarded – undo
5244 5244
 	 * @param string $_folder folder to work on
5245 5245
 	 * @return array  an array of information about the attachment: array of array(name, size, mimeType, partID, encoding)
5246 5246
 	 */
5247
-	function getMessageAttachments($_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folder='')
5247
+	function getMessageAttachments($_uid, $_partID = null, Horde_Mime_Part $_structure = null, $fetchEmbeddedImages = true, $fetchTextCalendar = false, $resolveTNEF = true, $_folder = '')
5248 5248
 	{
5249
-		if (self::$debug) error_log( __METHOD__.":$_uid, $_partID");
5250
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5249
+		if (self::$debug) error_log(__METHOD__.":$_uid, $_partID");
5250
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5251 5251
 		$attachments = array();
5252 5252
 		if (!isset($_structure))
5253 5253
 		{
5254
-			$_structure = $this->getStructure($_uid, $_partID,$_folder,true);
5254
+			$_structure = $this->getStructure($_uid, $_partID, $_folder, true);
5255 5255
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.print_r($_structure->contentTypeMap(),true));
5256 5256
 		}
5257 5257
 		if (!$_structure || !$_structure->contentTypeMap()) return array();
@@ -5259,7 +5259,7 @@  discard block
 block discarded – undo
5259 5259
 		$skipParts = array();
5260 5260
 		$tnefParts = array();
5261 5261
 		$skip = 0;
5262
-		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
5262
+		foreach ($_structure->contentTypeMap() as $mime_id => $mime_type)
5263 5263
 		{
5264 5264
 			$part = $_structure->getPart($mime_id);
5265 5265
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.' Uid:'.$uid.' Part:'.$_partID.'->'.array2string($part->getMimeId()));
@@ -5270,10 +5270,10 @@  discard block
 block discarded – undo
5270 5270
 			$partPrimaryType = $part->getPrimaryType();
5271 5271
 			// we only want to retrieve the attachments of the current mail, not those of possible
5272 5272
 			// attached mails
5273
-			if ($mime_type=='message/rfc822' && $_partID!=$mime_id)
5273
+			if ($mime_type == 'message/rfc822' && $_partID != $mime_id)
5274 5274
 			{
5275 5275
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
5276
-				foreach($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
5276
+				foreach ($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type; }
5277 5277
 			}
5278 5278
 			if (empty($partDisposition) && $partPrimaryType != 'multipart' && $partPrimaryType != 'text')
5279 5279
 			{
@@ -5281,27 +5281,27 @@  discard block
 block discarded – undo
5281 5281
 				// attachment with no link to show the attachment inline.
5282 5282
 				// Considering this: we "list" everything that matches the above criteria
5283 5283
 				// as attachment in order to not loose/miss information on our data
5284
-				$partDisposition='attachment';
5284
+				$partDisposition = 'attachment';
5285 5285
 			}
5286 5286
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($skipParts));
5287
-			if (array_key_exists($mime_id,$skipParts)) continue;
5287
+			if (array_key_exists($mime_id, $skipParts)) continue;
5288 5288
 
5289 5289
 			if ($partDisposition == 'attachment' ||
5290
-				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId()=='') ||
5290
+				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId() == '') ||
5291 5291
 				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType != 'image' && $partPrimaryType != 'text' && $partPrimaryType != 'multipart') ||
5292
-				($mime_type=='image/tiff') || //always fetch. even if $fetchEmbeddedImages is false. as we cannot display tiffs
5292
+				($mime_type == 'image/tiff') || //always fetch. even if $fetchEmbeddedImages is false. as we cannot display tiffs
5293 5293
 				($fetchEmbeddedImages && ($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image') ||
5294 5294
 				($fetchTextCalendar && $partPrimaryType == 'text' && $part->getSubType() == 'calendar'))
5295 5295
 			{
5296 5296
 				// if type is message/rfc822 and _partID is given, and MimeID equals partID
5297 5297
 				// we attempt to fetch "ourselves"
5298
-				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message') continue;
5298
+				if ($_partID == $part->getMimeId() && $part->getPrimaryType() == 'message') continue;
5299 5299
 				$attachment = $part->getAllDispositionParameters();
5300 5300
 
5301 5301
 				$attachment['mimeType'] = $mime_type;
5302 5302
 				$attachment['uid'] = $_uid;
5303 5303
 				$attachment['partID'] = $mime_id;
5304
-				if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
5304
+				if (!isset($attachment['name']) || empty($attachment['name'])) $attachment['name'] = $part->getName();
5305 5305
 				if ($fetchTextCalendar)
5306 5306
 				{
5307 5307
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part->getAllContentTypeParameters()));
@@ -5311,11 +5311,11 @@  discard block
 block discarded – undo
5311 5311
 				}
5312 5312
 				$attachment['size'] = $part->getBytes();
5313 5313
 				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5314
-				if (empty($attachment['name'])) $attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.mime_magic::mime2ext($mime_type);
5314
+				if (empty($attachment['name'])) $attachment['name'] = (isset($attachment['cid']) && !empty($attachment['cid']) ? $attachment['cid'] : lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.mime_magic::mime2ext($mime_type);
5315 5315
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($attachment));
5316 5316
 				//typical winmail.dat attachment is
5317 5317
 				//Array([size] => 1462762[filename] => winmail.dat[mimeType] => application/ms-tnef[uid] => 100[partID] => 2[name] => winmail.dat)
5318
-				if ($resolveTNEF && ($attachment['mimeType']=='application/ms-tnef' || !strcasecmp($attachment['name'],'winmail.dat')))
5318
+				if ($resolveTNEF && ($attachment['mimeType'] == 'application/ms-tnef' || !strcasecmp($attachment['name'], 'winmail.dat')))
5319 5319
 				{
5320 5320
 					$tnefParts[] = $attachment;
5321 5321
 				}
@@ -5330,31 +5330,31 @@  discard block
 block discarded – undo
5330 5330
 			//error_log(__METHOD__.__LINE__.array2string($tnefParts));
5331 5331
 			foreach ($tnefParts as $k => $tnp)
5332 5332
 			{
5333
-				$tnefResolved=false;
5334
-				$tnef_data = $this->getAttachment($tnp['uid'],$tnp['partID'],$k,false);
5333
+				$tnefResolved = false;
5334
+				$tnef_data = $this->getAttachment($tnp['uid'], $tnp['partID'], $k, false);
5335 5335
 				$myTnef = $this->tnef_decoder($tnef_data['attachment']);
5336 5336
 				//error_log(__METHOD__.__LINE__.array2string($myTnef->getParts()));
5337 5337
 				// Note: MimeId starts with 0, almost always, we cannot use that as winmail_id
5338 5338
 				// we need to build Something that meets the needs
5339 5339
 				if ($myTnef)
5340 5340
 				{
5341
-					foreach($myTnef->getParts() as $mime_id => $part)
5341
+					foreach ($myTnef->getParts() as $mime_id => $part)
5342 5342
 					{
5343
-						$tnefResolved=true;
5343
+						$tnefResolved = true;
5344 5344
 						$attachment = $part->getAllDispositionParameters();
5345 5345
 
5346 5346
 						$attachment['mimeType'] = $part->getType();
5347 5347
 						$attachment['uid'] = $tnp['uid'];
5348 5348
 						$attachment['partID'] = $tnp['partID'];
5349 5349
 						$attachment['is_winmail'] = $tnp['uid'].'@'.$tnp['partID'].'@'.$mime_id;
5350
-						if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
5350
+						if (!isset($attachment['name']) || empty($attachment['name'])) $attachment['name'] = $part->getName();
5351 5351
 						$attachment['size'] = $part->getBytes();
5352 5352
 						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5353
-						if (empty($attachment['name'])) $attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.mime_magic::mime2ext($attachment['mimeType']);
5353
+						if (empty($attachment['name'])) $attachment['name'] = (isset($attachment['cid']) && !empty($attachment['cid']) ? $attachment['cid'] : lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.mime_magic::mime2ext($attachment['mimeType']);
5354 5354
 						$attachments[] = $attachment;
5355 5355
 					}
5356 5356
 				}
5357
-				if ($tnefResolved===false) $attachments[]=$tnp;
5357
+				if ($tnefResolved === false) $attachments[] = $tnp;
5358 5358
 			}
5359 5359
 		}
5360 5360
 		//error_log(__METHOD__.__LINE__.array2string($attachments));
@@ -5369,9 +5369,9 @@  discard block
 block discarded – undo
5369 5369
 	 * @return boolean|Horde_Mime_part Multipart/Mixed part decoded attachments |
5370 5370
 	 *	return false if there's no attachments or failure
5371 5371
 	 */
5372
-	public function tnef_decoder( $data )
5372
+	public function tnef_decoder($data)
5373 5373
 	{
5374
-		foreach(array('Horde_Compress', 'Horde_Icalendar', 'Horde_Mapi') as $class)
5374
+		foreach (array('Horde_Compress', 'Horde_Icalendar', 'Horde_Mapi') as $class)
5375 5375
 		{
5376 5376
 			if (!class_exists($class))
5377 5377
 			{
@@ -5402,7 +5402,7 @@  discard block
 block discarded – undo
5402 5402
 				$tmp_part->setContents($data['stream']);
5403 5403
 				$tmp_part->setDescription($data['name']);
5404 5404
 
5405
-				$type = $data['type'] . '/' . $data['subtype'];
5405
+				$type = $data['type'].'/'.$data['subtype'];
5406 5406
 				if (in_array($type, array('application/octet-stream', 'application/base64')))
5407 5407
 				{
5408 5408
 					$type = Horde_Mime_Magic::filenameToMIME($data['name']);
@@ -5445,24 +5445,24 @@  discard block
 block discarded – undo
5445 5445
 	 *
5446 5446
 	 * @return array returns an array of all resolved embeded attachments from winmail.dat
5447 5447
 	 */
5448
-	function getTnefAttachments ($_uid, $_partID, $_stream=false)
5448
+	function getTnefAttachments($_uid, $_partID, $_stream = false)
5449 5449
 	{
5450
-		$tnef_data = $this->getAttachment($_uid, $_partID,0,false);
5450
+		$tnef_data = $this->getAttachment($_uid, $_partID, 0, false);
5451 5451
 		$tnef_parts = $this->tnef_decoder($tnef_data['attachment']);
5452 5452
 		$attachments = array();
5453 5453
 		if ($tnef_parts)
5454 5454
 		{
5455
-			foreach($tnef_parts->getParts() as $mime_id => $part)
5455
+			foreach ($tnef_parts->getParts() as $mime_id => $part)
5456 5456
 			{
5457 5457
 
5458 5458
 				$attachment = $part->getAllDispositionParameters();
5459 5459
 				$attachment['mimeType'] = $part->getType();
5460
-				if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5460
+				if (!isset($attachment['filename']) || empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5461 5461
 				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5462 5462
 				if (empty($attachment['filename']))
5463 5463
 				{
5464
-					$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?
5465
-						$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.mime_magic::mime2ext($attachment['mimeType']);
5464
+					$attachment['filename'] = (isset($attachment['cid']) && !empty($attachment['cid']) ?
5465
+						$attachment['cid'] : lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.mime_magic::mime2ext($attachment['mimeType']);
5466 5466
 				}
5467 5467
 
5468 5468
 				$attachment['attachment'] = $part->getContents(array('stream'=>$_stream));
@@ -5486,10 +5486,10 @@  discard block
 block discarded – undo
5486 5486
 	 *
5487 5487
 	 * @return array
5488 5488
 	 */
5489
-	function getAttachment($_uid, $_partID, $_winmail_nr=0, $_returnPart=true, $_stream=false, $_folder=null)
5489
+	function getAttachment($_uid, $_partID, $_winmail_nr = 0, $_returnPart = true, $_stream = false, $_folder = null)
5490 5490
 	{
5491 5491
 		//error_log(__METHOD__.__LINE__."Uid:$_uid, PartId:$_partID, WinMailNr:$_winmail_nr, ReturnPart:$_returnPart, Stream:$_stream, Folder:$_folder".function_backtrace());
5492
-		if (!isset($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5492
+		if (!isset($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5493 5493
 
5494 5494
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5495 5495
 		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
@@ -5502,36 +5502,36 @@  discard block
 block discarded – undo
5502 5502
 			'ids' => $uidsToFetch,
5503 5503
 		));
5504 5504
 		if (is_object($headersNew)) {
5505
-			foreach($headersNew as $id=>$_headerObject) {
5505
+			foreach ($headersNew as $id=>$_headerObject) {
5506 5506
 				$body = $_headerObject->getFullMsg();
5507 5507
 				if ($_partID != '')
5508 5508
 				{
5509 5509
 					$mailStructureObject = $_headerObject->getStructure();
5510 5510
 					$mailStructureObject->contentTypeMap();
5511 5511
 					$part = $mailStructureObject->getPart($_partID);
5512
-					$partDisposition = ($part?$part->getDisposition():'failed');
5513
-					if ($partDisposition=='failed')
5512
+					$partDisposition = ($part ? $part->getDisposition() : 'failed');
5513
+					if ($partDisposition == 'failed')
5514 5514
 					{
5515 5515
 						error_log(__METHOD__.'('.__LINE__.'):'.array2string($_uid).','.$_partID.' ID:'.$id.' HObject:'.array2string($_headerObject).' StructureObject:'.array2string($mailStructureObject->contentTypeMap()).'->'.function_backtrace());
5516 5516
 					}
5517 5517
 					// if $partDisposition is empty, we assume attachment, and hope that the function
5518 5518
 					// itself is only triggered to fetch attachments
5519
-					if (empty($partDisposition)) $partDisposition='attachment';
5520
-					if ($part && ($partDisposition=='attachment' || $partDisposition=='inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar')))
5519
+					if (empty($partDisposition)) $partDisposition = 'attachment';
5520
+					if ($part && ($partDisposition == 'attachment' || $partDisposition == 'inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar')))
5521 5521
 					{
5522 5522
 						//$headerObject=$part->getAllDispositionParameters();//not used anywhere around here
5523 5523
 						$structure_mime = $part->getType();
5524 5524
 						$filename = $part->getName();
5525 5525
 						$charset = $part->getContentTypeParameter('charset');
5526 5526
 						//$structure_bytes = $part->getBytes(); $structure_partID=$part->getMimeId(); error_log(__METHOD__.__LINE__." fetchPartContents(".array2string($_uid).", $structure_partID, $_stream, $_preserveSeen,$structure_mime)" );
5527
-						$this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen=true,$structure_mime);
5527
+						$this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen = true, $structure_mime);
5528 5528
 						if ($_returnPart) return $part;
5529 5529
 					}
5530 5530
 				}
5531 5531
 			}
5532 5532
 		}
5533 5533
 		$ext = mime_magic::mime2ext($structure_mime);
5534
-		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false) $filename = trim($filename).'.'.$ext;
5534
+		if ($ext && stripos($filename, '.') === false && stripos($filename, $ext) === false) $filename = trim($filename).'.'.$ext;
5535 5535
 		if (!$part)
5536 5536
 		{
5537 5537
 			throw new egw_exception_wrong_parameter("Error: Could not fetch attachment for Uid=".array2string($_uid).", PartId=$_partID, WinMailNr=$_winmail_nr, folder=$_folder");
@@ -5549,20 +5549,20 @@  discard block
 block discarded – undo
5549 5549
 		// try guessing the mimetype, if we get the application/octet-stream
5550 5550
 		if (strtolower($attachmentData['type']) == 'application/octet-stream') $attachmentData['type'] = mime_magic::filename2mime($attachmentData['filename']);
5551 5551
 		# if the attachment holds a winmail number and is a winmail.dat then we have to handle that.
5552
-		if ( $filename == 'winmail.dat' && $_winmail_nr)
5552
+		if ($filename == 'winmail.dat' && $_winmail_nr)
5553 5553
 		{
5554 5554
 			//by now _uid is of type array
5555
-			$tnefResolved=false;
5556
-			$wantedPart=$_uid[0].'@'.$_partID;
5555
+			$tnefResolved = false;
5556
+			$wantedPart = $_uid[0].'@'.$_partID;
5557 5557
 			$myTnef = $this->tnef_decoder($attachmentData['attachment']);
5558 5558
 			//error_log(__METHOD__.__LINE__.array2string($myTnef->getParts()));
5559 5559
 			// Note: MimeId starts with 0, almost always, we cannot use that as winmail_id
5560 5560
 			// we need to build Something that meets the needs
5561 5561
 			if ($myTnef)
5562 5562
 			{
5563
-				foreach($myTnef->getParts() as $mime_id => $part)
5563
+				foreach ($myTnef->getParts() as $mime_id => $part)
5564 5564
 				{
5565
-					$tnefResolved=true;
5565
+					$tnefResolved = true;
5566 5566
 					$attachment = $part->getAllDispositionParameters();
5567 5567
 					$attachment['mimeType'] = $part->getType();
5568 5568
 					//error_log(__METHOD__.__LINE__.'#'.$mime_id.'#'.$filename.'#'.array2string($attachment));
@@ -5570,9 +5570,9 @@  discard block
 block discarded – undo
5570 5570
 					if ($_winmail_nr == $wantedPart.'@'.$mime_id)
5571 5571
 					{
5572 5572
 						//error_log(__METHOD__.__LINE__.'#'.$structure_mime.'#'.$filename.'#'.array2string($attachment));
5573
-						if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5573
+						if (!isset($attachment['filename']) || empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5574 5574
 						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5575
-						if (empty($attachment['filename'])) $attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.mime_magic::mime2ext($attachment['mimeType']);
5575
+						if (empty($attachment['filename'])) $attachment['filename'] = (isset($attachment['cid']) && !empty($attachment['cid']) ? $attachment['cid'] : lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.mime_magic::mime2ext($attachment['mimeType']);
5576 5576
 						$wmattach = $attachment;
5577 5577
 						$wmattach['attachment'] = $part->getContents(array('stream'=>$_stream));
5578 5578
 
@@ -5582,7 +5582,7 @@  discard block
 block discarded – undo
5582 5582
 			if ($tnefResolved)
5583 5583
 			{
5584 5584
 				$ext = mime_magic::mime2ext($wmattach['mimeType']);
5585
-				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
5585
+				if ($ext && stripos($wmattach['filename'], '.') === false && stripos($wmattach['filename'], $ext) === false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
5586 5586
 				$attachmentData = array(
5587 5587
 					'type'       => $wmattach['mimeType'],
5588 5588
 					'filename'   => $wmattach['filename'],
@@ -5606,21 +5606,21 @@  discard block
 block discarded – undo
5606 5606
 	 *	true:
5607 5607
 	 * @return Horde_Mime_Part
5608 5608
 	 */
5609
-	function getAttachmentByCID($_uid, $_cid, $_part, $_stream=null)
5609
+	function getAttachmentByCID($_uid, $_cid, $_part, $_stream = null)
5610 5610
 	{
5611 5611
 		// some static variables to avoid fetching the same mail multiple times
5612
-		static $uid=null, $part=null, $structure=null;
5612
+		static $uid = null, $part = null, $structure = null;
5613 5613
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_cid, $_part");
5614 5614
 
5615
-		if(empty($_cid)) return false;
5615
+		if (empty($_cid)) return false;
5616 5616
 
5617 5617
 		if ($_uid != $uid || $_part != $part)
5618 5618
 		{
5619
-			$structure = $this->getStructure($uid=$_uid, $part=$_part);
5619
+			$structure = $this->getStructure($uid = $_uid, $part = $_part);
5620 5620
 		}
5621 5621
 		/** @var Horde_Mime_Part */
5622 5622
 		$attachment = null;
5623
-		foreach($structure->contentTypeMap() as $mime_id => $mime_type)
5623
+		foreach ($structure->contentTypeMap() as $mime_id => $mime_type)
5624 5624
 		{
5625 5625
 			$part = $structure->getPart($mime_id);
5626 5626
 
@@ -5672,16 +5672,16 @@  discard block
 block discarded – undo
5672 5672
 	 * @param string  $_mimetype to decide wether to try to fetch part as binary or not
5673 5673
 	 * @return Horde_Mime_Part
5674 5674
 	 */
5675
-	public function fetchPartContents($_uid, Horde_Mime_Part $part=null, $_stream=false, $_preserveSeen=false, $_mimetype=null)
5675
+	public function fetchPartContents($_uid, Horde_Mime_Part $part = null, $_stream = false, $_preserveSeen = false, $_mimetype = null)
5676 5676
 	{
5677
-		if (is_null($part)) return null;//new Horde_Mime_Part;
5677
+		if (is_null($part)) return null; //new Horde_Mime_Part;
5678 5678
 		$encoding = null;
5679 5679
 		$fetchAsBinary = true;
5680
-		if ($_mimetype && strtolower($_mimetype)=='message/rfc822') $fetchAsBinary = false;
5680
+		if ($_mimetype && strtolower($_mimetype) == 'message/rfc822') $fetchAsBinary = false;
5681 5681
 		// we need to set content on structure to decode transfer encoding
5682 5682
 		$part->setContents(
5683 5683
 			$this->getBodyPart($_uid, $part->getMimeId(), null, $_preserveSeen, $_stream, $encoding, $fetchAsBinary),
5684
-			array('encoding' => (!$fetchAsBinary&&!$encoding?'8bit':$encoding)));
5684
+			array('encoding' => (!$fetchAsBinary && !$encoding ? '8bit' : $encoding)));
5685 5685
 
5686 5686
 		return $part;
5687 5687
 	}
@@ -5699,17 +5699,17 @@  discard block
 block discarded – undo
5699 5699
 	 * @return the id of the message appended or exception
5700 5700
 	 * @throws egw_exception_wrong_userinput
5701 5701
 	 */
5702
-	function appendMessage($_folderName, $_header, $_body, $_flags='\\Recent')
5702
+	function appendMessage($_folderName, $_header, $_body, $_flags = '\\Recent')
5703 5703
 	{
5704 5704
 		if (!is_resource($_header))
5705 5705
 		{
5706
-			if (stripos($_header,'message-id:')===false)
5706
+			if (stripos($_header, 'message-id:') === false)
5707 5707
 			{
5708 5708
 				$_header = 'Message-ID: <'.self::getRandomString().'@localhost>'."\n".$_header;
5709 5709
 			}
5710 5710
 			//error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_header, $_body, $_flags");
5711
-			$_header = ltrim(str_replace("\n","\r\n",$_header));
5712
-			$_header .= str_replace("\n","\r\n",$_body);
5711
+			$_header = ltrim(str_replace("\n", "\r\n", $_header));
5712
+			$_header .= str_replace("\n", "\r\n", $_body);
5713 5713
 		}
5714 5714
 		// the recent flag is the default enforced here ; as we assume the _flags is always set,
5715 5715
 		// we default it to hordes default (Recent) (, other wise we should not pass the parameter
@@ -5727,7 +5727,7 @@  discard block
 block discarded – undo
5727 5727
 			// searched for the message-id then returning the uid found
5728 5728
 			//$dataNflags[] = array('data'=>array(array('t'=>'text','v'=>"$header"."$body")), 'flags'=>array($_flags));
5729 5729
 			$dataNflags[] = array('data' => $_header, 'flags'=>array($_flags));
5730
-			$messageid = $this->icServer->append($_folderName,$dataNflags);
5730
+			$messageid = $this->icServer->append($_folderName, $dataNflags);
5731 5731
 		}
5732 5732
 		catch (Exception $e)
5733 5733
 		{
@@ -5739,7 +5739,7 @@  discard block
 block discarded – undo
5739 5739
 		//$messageid = true; // for debug reasons only
5740 5740
 		if ($messageid === true || empty($messageid)) // try to figure out the message uid
5741 5741
 		{
5742
-			$list = $this->getHeaders($_folderName, $_startMessage=1, 1, 'INTERNALDATE', true, array(),null, false);
5742
+			$list = $this->getHeaders($_folderName, $_startMessage = 1, 1, 'INTERNALDATE', true, array(), null, false);
5743 5743
 			if ($list)
5744 5744
 			{
5745 5745
 				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
@@ -5779,27 +5779,27 @@  discard block
 block discarded – undo
5779 5779
 	 *				'attachments'=>$attachments,
5780 5780
 	 *				'headers'=>$headers,; boolean false on failure
5781 5781
 	 */
5782
-	static function get_mailcontent(&$mailClass,$uid,$partid='',$mailbox='', $preserveHTML = false, $addHeaderSection=true, $includeAttachments=true)
5782
+	static function get_mailcontent(&$mailClass, $uid, $partid = '', $mailbox = '', $preserveHTML = false, $addHeaderSection = true, $includeAttachments = true)
5783 5783
 	{
5784 5784
 			//echo __METHOD__." called for $uid,$partid <br>";
5785
-			$headers = $mailClass->getMessageHeader($uid,$partid,true,false,$mailbox);
5785
+			$headers = $mailClass->getMessageHeader($uid, $partid, true, false, $mailbox);
5786 5786
 			if (empty($headers)) return false;
5787 5787
 			// dont force retrieval of the textpart, let mailClass preferences decide
5788
-			$bodyParts = $mailClass->getMessageBody($uid,($preserveHTML?'always_display':'only_if_no_text'),$partid,null,false,$mailbox);
5788
+			$bodyParts = $mailClass->getMessageBody($uid, ($preserveHTML ? 'always_display' : 'only_if_no_text'), $partid, null, false, $mailbox);
5789 5789
 			// if we do not want HTML but there is no TextRepresentation with the message itself, try converting
5790
-			if ( !$preserveHTML && $bodyParts[0]['mimeType']=='text/html')
5790
+			if (!$preserveHTML && $bodyParts[0]['mimeType'] == 'text/html')
5791 5791
 			{
5792
-				foreach($bodyParts as $i => $part)
5792
+				foreach ($bodyParts as $i => $part)
5793 5793
 				{
5794
-					if ($bodyParts[$i]['mimeType']=='text/html')
5794
+					if ($bodyParts[$i]['mimeType'] == 'text/html')
5795 5795
 					{
5796
-						$bodyParts[$i]['body'] = translation::convertHTMLToText($bodyParts[$i]['body'],$bodyParts[$i]['charSet'],true,$stripalltags=true);
5797
-						$bodyParts[$i]['mimeType']='text/plain';
5796
+						$bodyParts[$i]['body'] = translation::convertHTMLToText($bodyParts[$i]['body'], $bodyParts[$i]['charSet'], true, $stripalltags = true);
5797
+						$bodyParts[$i]['mimeType'] = 'text/plain';
5798 5798
 					}
5799 5799
 				}
5800 5800
 			}
5801 5801
 			//error_log(array2string($bodyParts));
5802
-			$attachments = $includeAttachments?$mailClass->getMessageAttachments($uid,$partid,null,true,false,true,$mailbox):array();
5802
+			$attachments = $includeAttachments ? $mailClass->getMessageAttachments($uid, $partid, null, true, false, true, $mailbox) : array();
5803 5803
 
5804 5804
 			if ($mailClass->isSentFolder($mailbox)) $mailaddress = $headers['TO'];
5805 5805
 			elseif (isset($headers['FROM'])) $mailaddress = $headers['FROM'];
@@ -5810,7 +5810,7 @@  discard block
 block discarded – undo
5810 5810
 
5811 5811
 			$message = self::getdisplayableBody($mailClass, $bodyParts, $preserveHTML);
5812 5812
 			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain') $message = '<pre>'.$message.'</pre>';
5813
-			$headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '',$preserveHTML) : '');
5813
+			$headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '', $preserveHTML) : '');
5814 5814
 			$message = $headdata.$message;
5815 5815
 			//echo __METHOD__.'<br>';
5816 5816
 			//_debug_array($attachments);
@@ -5826,25 +5826,25 @@  discard block
 block discarded – undo
5826 5826
 						//_debug_array($mailClass->getMessageHeader($uid, $attachment['partID']));
5827 5827
 						//_debug_array($mailClass->getMessageBody($uid,'', $attachment['partID']));
5828 5828
 						//_debug_array($mailClass->getMessageAttachments($uid, $attachment['partID']));
5829
-						$mailcontent = self::get_mailcontent($mailClass,$uid,$attachment['partID'],$mailbox);
5830
-						$headdata ='';
5829
+						$mailcontent = self::get_mailcontent($mailClass, $uid, $attachment['partID'], $mailbox);
5830
+						$headdata = '';
5831 5831
 						if ($mailcontent['headers'])
5832 5832
 						{
5833
-							$headdata = self::createHeaderInfoSection($mailcontent['headers'],'',$preserveHTML);
5833
+							$headdata = self::createHeaderInfoSection($mailcontent['headers'], '', $preserveHTML);
5834 5834
 						}
5835 5835
 						if ($mailcontent['message'])
5836 5836
 						{
5837
-							$tempname =tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
5837
+							$tempname = tempnam($GLOBALS['egw_info']['server']['temp_dir'], $GLOBALS['egw_info']['flags']['currentapp']."_");
5838 5838
 							$attachedMessages[] = array(
5839 5839
 								'type' => 'TEXT/PLAIN',
5840 5840
 								'name' => $mailcontent['subject'].'.txt',
5841 5841
 								'tmp_name' => $tempname,
5842 5842
 							);
5843
-							$tmpfile = fopen($tempname,'w');
5844
-							fwrite($tmpfile,$headdata.$mailcontent['message']);
5843
+							$tmpfile = fopen($tempname, 'w');
5844
+							fwrite($tmpfile, $headdata.$mailcontent['message']);
5845 5845
 							fclose($tmpfile);
5846 5846
 						}
5847
-						foreach($mailcontent['attachments'] as &$tmpval)
5847
+						foreach ($mailcontent['attachments'] as &$tmpval)
5848 5848
 						{
5849 5849
 							$attachedMessages[] = $tmpval;
5850 5850
 						}
@@ -5852,36 +5852,36 @@  discard block
 block discarded – undo
5852 5852
 					}
5853 5853
 					else
5854 5854
 					{
5855
-						$attachments[$num] = array_merge($attachments[$num],$mailClass->getAttachment($uid, $attachment['partID'],0,false,false));
5855
+						$attachments[$num] = array_merge($attachments[$num], $mailClass->getAttachment($uid, $attachment['partID'], 0, false, false));
5856 5856
 
5857
-						if (empty($attachments[$num]['attachment'])&&$attachments[$num]['cid'])
5857
+						if (empty($attachments[$num]['attachment']) && $attachments[$num]['cid'])
5858 5858
 						{
5859
-							$c = $mailClass->getAttachmentByCID($uid, $attachment['cid'], $attachment['partID'],true);
5859
+							$c = $mailClass->getAttachmentByCID($uid, $attachment['cid'], $attachment['partID'], true);
5860 5860
 							$attachments[$num]['attachment'] = $c->getContents();
5861 5861
 						}
5862 5862
 						// no attempt to convert, if we dont know about the charset
5863
-						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset'])) {
5863
+						if (isset($attachments[$num]['charset']) && !empty($attachments[$num]['charset'])) {
5864 5864
 							// we do not try guessing the charset, if it is not set
5865 5865
 							//if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = translation::detect_encoding($attachments[$num]['attachment']);
5866
-							translation::convert($attachments[$num]['attachment'],$attachments[$num]['charset']);
5866
+							translation::convert($attachments[$num]['attachment'], $attachments[$num]['charset']);
5867 5867
 						}
5868
-						if(in_array($attachments[$num]['name'], $file_list))
5868
+						if (in_array($attachments[$num]['name'], $file_list))
5869 5869
 						{
5870 5870
 							$dupe_count[$attachments[$num]['name']]++;
5871
-							$attachments[$num]['name'] = pathinfo($attachments[$num]['name'], PATHINFO_FILENAME) .
5872
-								' ('.($dupe_count[$attachments[$num]['name']] + 1).')' . '.' .
5871
+							$attachments[$num]['name'] = pathinfo($attachments[$num]['name'], PATHINFO_FILENAME).
5872
+								' ('.($dupe_count[$attachments[$num]['name']] + 1).')'.'.'.
5873 5873
 								pathinfo($attachments[$num]['name'], PATHINFO_EXTENSION);
5874 5874
 						}
5875 5875
 						$attachments[$num]['type'] = $attachments[$num]['mimeType'];
5876
-						$attachments[$num]['tmp_name'] = tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
5877
-						$tmpfile = fopen($attachments[$num]['tmp_name'],'w');
5878
-						fwrite($tmpfile,$attachments[$num]['attachment']);
5876
+						$attachments[$num]['tmp_name'] = tempnam($GLOBALS['egw_info']['server']['temp_dir'], $GLOBALS['egw_info']['flags']['currentapp']."_");
5877
+						$tmpfile = fopen($attachments[$num]['tmp_name'], 'w');
5878
+						fwrite($tmpfile, $attachments[$num]['attachment']);
5879 5879
 						fclose($tmpfile);
5880 5880
 						$file_list[] = $attachments[$num]['name'];
5881 5881
 						unset($attachments[$num]['attachment']);
5882 5882
 					}
5883 5883
 				}
5884
-				if (is_array($attachedMessages)) $attachments = array_merge($attachments,$attachedMessages);
5884
+				if (is_array($attachedMessages)) $attachments = array_merge($attachments, $attachedMessages);
5885 5885
 			}
5886 5886
 			return array(
5887 5887
 					'mailaddress'=>$mailaddress,
@@ -5903,10 +5903,10 @@  discard block
 block discarded – undo
5903 5903
 	{
5904 5904
 		$c = 0;
5905 5905
 		// use the standardIdentity
5906
-		foreach($_identities as $key => $acc) {
5907
-			if ($c==0) $identity = $acc;
5906
+		foreach ($_identities as $key => $acc) {
5907
+			if ($c == 0) $identity = $acc;
5908 5908
 			//error_log(__METHOD__.__LINE__." $key == $_profile_id ");
5909
-			if ($key==$_profile_id) $identity = $acc;
5909
+			if ($key == $_profile_id) $identity = $acc;
5910 5910
 			$c++;
5911 5911
 		}
5912 5912
 		return $identity;
@@ -5918,29 +5918,29 @@  discard block
 block discarded – undo
5918 5918
 	 * @param bool createHTML do it with HTML breaks
5919 5919
 	 * @return string a preformatted string with the information of the header worked into it
5920 5920
 	 */
5921
-	static function createHeaderInfoSection($header,$headline='', $createHTML = false)
5921
+	static function createHeaderInfoSection($header, $headline = '', $createHTML = false)
5922 5922
 	{
5923 5923
 		$headdata = null;
5924 5924
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($header).function_backtrace());
5925
-		if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
5926
-		if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
5927
-		if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
5928
-		if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
5929
-		if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
5930
-		if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
5931
-		if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
5932
-		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
5933
-		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
5925
+		if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML ? "<br />" : "\n");
5926
+		if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML ? "<br />" : "\n");
5927
+		if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML ? "<br />" : "\n");
5928
+		if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML ? "<br />" : "\n");
5929
+		if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML ? "<br />" : "\n");
5930
+		if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML ? "<br />" : "\n");
5931
+		if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML ? "<br />" : "\n");
5932
+		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML ? "<br />" : "\n");
5933
+		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] != 'normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML ? "<br />" : "\n");
5934 5934
 		//if ($mailcontent['headers']['ORGANIZATION']) $headdata .= lang('organization').': '.$mailcontent['headers']['ORGANIZATION']."\
5935 5935
 		if (!empty($headdata))
5936 5936
 		{
5937
-			if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
5938
-			if (empty($headline)) $headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
5939
-			$headdata .= ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'');
5937
+			if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML ? "<br />" : "\n").$headdata;
5938
+			if (empty($headline)) $headdata = ($headline != 'SUPPRESS' ? "--------------------------------------------------------".($createHTML ? "<br />" : "\n") : '').$headdata;
5939
+			$headdata .= ($headline != 'SUPPRESS' ? "--------------------------------------------------------".($createHTML ? "<br />" : "\n") : '');
5940 5940
 		}
5941 5941
 		else
5942 5942
 		{
5943
-			$headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'');
5943
+			$headdata = ($headline != 'SUPPRESS' ? "--------------------------------------------------------".($createHTML ? "<br />" : "\n") : '');
5944 5944
 		}
5945 5945
 		return $headdata;
5946 5946
 	}
@@ -5953,8 +5953,8 @@  discard block
 block discarded – undo
5953 5953
 	 */
5954 5954
 	static function adaptSubjectForImport($subject)
5955 5955
 	{
5956
-		$subject = str_replace('$$','__',($subject?$subject:lang('(no subject)')));
5957
-		$subject = str_ireplace(array('[FWD]','[',']','{','}','<','>'),array('Fwd:',' ',' ',' ',' ',' ',' '),trim($subject));
5956
+		$subject = str_replace('$$', '__', ($subject ? $subject : lang('(no subject)')));
5957
+		$subject = str_ireplace(array('[FWD]', '[', ']', '{', '}', '<', '>'), array('Fwd:', ' ', ' ', ' ', ' ', ' ', ' '), trim($subject));
5958 5958
 		return $subject;
5959 5959
 	}
5960 5960
 
@@ -5966,15 +5966,15 @@  discard block
 block discarded – undo
5966 5966
 	static function convertAddressArrayToString($rfcAddressArray)
5967 5967
 	{
5968 5968
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($rfcAddressArray));
5969
-		$returnAddr ='';
5969
+		$returnAddr = '';
5970 5970
 		if (is_array($rfcAddressArray))
5971 5971
 		{
5972
-			foreach((array)$rfcAddressArray as $addressData) {
5972
+			foreach ((array)$rfcAddressArray as $addressData) {
5973 5973
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressData));
5974
-				if($addressData['MAILBOX_NAME'] == 'NIL') {
5974
+				if ($addressData['MAILBOX_NAME'] == 'NIL') {
5975 5975
 					continue;
5976 5976
 				}
5977
-				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') {
5977
+				if (strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') {
5978 5978
 					continue;
5979 5979
 				}
5980 5980
 				if ($addressData['RFC822_EMAIL'])
@@ -5983,7 +5983,7 @@  discard block
 block discarded – undo
5983 5983
 				}
5984 5984
 				else
5985 5985
 				{
5986
-					$emailaddress = ($addressData['PERSONAL_NAME']?$addressData['PERSONAL_NAME'].' <'.$addressData['EMAIL'].'>':$addressData['EMAIL']);
5986
+					$emailaddress = ($addressData['PERSONAL_NAME'] ? $addressData['PERSONAL_NAME'].' <'.$addressData['EMAIL'].'>' : $addressData['EMAIL']);
5987 5987
 					$addressObjectA = self::parseAddressList($emailaddress);
5988 5988
 				}
5989 5989
 				$addressObject = $addressObjectA[0];
@@ -5992,10 +5992,10 @@  discard block
 block discarded – undo
5992 5992
 				//$mb =(string)$addressObject->mailbox;
5993 5993
 				//$h = (string)$addressObject->host;
5994 5994
 				//$p = (string)$addressObject->personal;
5995
-				$returnAddr .= (strlen($returnAddr)>0?',':'');
5995
+				$returnAddr .= (strlen($returnAddr) > 0 ? ',' : '');
5996 5996
 				//error_log(__METHOD__.' ('.__LINE__.') '.$p.' <'.$mb.'@'.$h.'>');
5997 5997
 				$buff = imap_rfc822_write_address($addressObject->mailbox, self::$idna2->decode($addressObject->host), $addressObject->personal);
5998
-				$buff = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$buff);
5998
+				$buff = str_replace(array('<', '>', '"\'', '\'"'), array('[', ']', '"', '"'), $buff);
5999 5999
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Address: '.$returnAddr);
6000 6000
 				$returnAddr .= $buff;
6001 6001
 			}
@@ -6003,8 +6003,8 @@  discard block
 block discarded – undo
6003 6003
 		else
6004 6004
 		{
6005 6005
 			// do not mess with strings, return them untouched /* ToDo: validate string as Address */
6006
-			$rfcAddressArray = self::decode_header($rfcAddressArray,true);
6007
-			$rfcAddressArray = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$rfcAddressArray);
6006
+			$rfcAddressArray = self::decode_header($rfcAddressArray, true);
6007
+			$rfcAddressArray = str_replace(array('<', '>', '"\'', '\'"'), array('[', ']', '"', '"'), $rfcAddressArray);
6008 6008
 			if (is_string($rfcAddressArray)) return $rfcAddressArray;
6009 6009
 		}
6010 6010
 		return $returnAddr;
@@ -6018,12 +6018,12 @@  discard block
 block discarded – undo
6018 6018
 	 * @param string &$err error-message on error
6019 6019
 	 * @return string/boolean merged content or false on error
6020 6020
 	 */
6021
-	static function merge($content,$ids,$mimetype='')
6021
+	static function merge($content, $ids, $mimetype = '')
6022 6022
 	{
6023 6023
 		$mergeobj = new addressbook_merge();
6024 6024
 
6025
-		if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
6026
-		$rv = $mergeobj->merge_string($content,$ids,$err='',$mimetype, array(), self::$displayCharset);
6025
+		if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ? 'text/plain' : 'text/html');
6026
+		$rv = $mergeobj->merge_string($content, $ids, $err = '', $mimetype, array(), self::$displayCharset);
6027 6027
 		if (empty($rv) && !empty($content) && !empty($err)) $rv = $content;
6028 6028
 		if (!empty($err) && !empty($content) && !empty($ids)) error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
6029 6029
 		return $rv;
@@ -6065,12 +6065,12 @@  discard block
 block discarded – undo
6065 6065
 		else
6066 6066
 			settype($bytes, 'integer');
6067 6067
 
6068
-		return $bytes . ' ' . $type ;
6068
+		return $bytes.' '.$type;
6069 6069
 	}
6070 6070
 
6071 6071
 	static function detect_qp(&$sting) {
6072 6072
 		$needle = '/(=[0-9][A-F])|(=[A-F][0-9])|(=[A-F][A-F])|(=[0-9][0-9])/';
6073
-		return preg_match("$needle",$string);
6073
+		return preg_match("$needle", $string);
6074 6074
 	}
6075 6075
 
6076 6076
 	/**
@@ -6083,11 +6083,11 @@  discard block
 block discarded – undo
6083 6083
 	 * @param string $_methodNline - Information where the log was taken
6084 6084
 	 * @return void
6085 6085
 	 */
6086
-	static function logRunTimes($_starttime,$_endtime=null,$_message='',$_methodNline='')
6086
+	static function logRunTimes($_starttime, $_endtime = null, $_message = '', $_methodNline = '')
6087 6087
 	{
6088 6088
 		if (is_null($_endtime)) $_endtime = microtime(true);
6089 6089
 		$usagetime = microtime(true) - $_starttime;
6090
-		if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
6090
+		if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime, 5).'(s) '.($_message ? 'Details:'.$_message : ''));
6091 6091
 	}
6092 6092
 
6093 6093
 	/**
@@ -6100,9 +6100,9 @@  discard block
 block discarded – undo
6100 6100
 	 *
6101 6101
 	 * @throws egw_exception_wrong_userinput
6102 6102
 	 */
6103
-	static function checkFileBasics(&$_formData, $IDtoAddToFileName='', $reqMimeType='message/rfc822')
6103
+	static function checkFileBasics(&$_formData, $IDtoAddToFileName = '', $reqMimeType = 'message/rfc822')
6104 6104
 	{
6105
-		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data') return $_formData['file'];
6105
+		if (parse_url($_formData['file'], PHP_URL_SCHEME) == 'egw-data') return $_formData['file'];
6106 6106
 
6107 6107
 		//error_log(__METHOD__.__FILE__.array2string($_formData).' Id:'.$IDtoAddToFileName.' ReqMimeType:'.$reqMimeType);
6108 6108
 		$importfailed = $tmpFileName = false;
@@ -6112,7 +6112,7 @@  discard block
 block discarded – undo
6112 6112
 			$importfailed = true;
6113 6113
 			$alert_msg .= lang("Empty file %1 ignored.", $_formData['name']);
6114 6114
 		}
6115
-		elseif (parse_url($_formData['file'],PHP_URL_SCHEME) == 'vfs' || is_uploaded_file($_formData['file']) ||
6115
+		elseif (parse_url($_formData['file'], PHP_URL_SCHEME) == 'vfs' || is_uploaded_file($_formData['file']) ||
6116 6116
 			realpath(dirname($_formData['file'])) == realpath($GLOBALS['egw_info']['server']['temp_dir']))
6117 6117
 		{
6118 6118
 			// ensure existance of eGW temp dir
@@ -6120,7 +6120,7 @@  discard block
 block discarded – undo
6120 6120
 			// and different from any other temp file location set in php.ini
6121 6121
 			if (!file_exists($GLOBALS['egw_info']['server']['temp_dir']))
6122 6122
 			{
6123
-				@mkdir($GLOBALS['egw_info']['server']['temp_dir'],0700);
6123
+				@mkdir($GLOBALS['egw_info']['server']['temp_dir'], 0700);
6124 6124
 			}
6125 6125
 
6126 6126
 			// if we were NOT able to create this temp directory, then make an ERROR report
@@ -6147,14 +6147,14 @@  discard block
 block discarded – undo
6147 6147
 			// maybe its application/octet-stream -> this may mean that we could not determine the type
6148 6148
 			// so we check for the suffix too
6149 6149
 			// trust vfs mime-types, trust the mimetype if it contains a method
6150
-			if ((substr($_formData['file'],0,6) !== 'vfs://' || $_formData['type'] == 'application/octet-stream') && stripos($_formData['type'],'method=')===false)
6150
+			if ((substr($_formData['file'], 0, 6) !== 'vfs://' || $_formData['type'] == 'application/octet-stream') && stripos($_formData['type'], 'method=') === false)
6151 6151
 			{
6152
-				$buff = explode('.',$_formData['name']);
6152
+				$buff = explode('.', $_formData['name']);
6153 6153
 				$suffix = '';
6154 6154
 				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
6155 6155
 				if (!empty($suffix)) $sfxMimeType = mime_magic::ext2mime($suffix);
6156 6156
 				if (!empty($suffix) && !empty($sfxMimeType) &&
6157
-					(strlen(trim($_formData['type']))==0 || (strtolower(trim($_formData['type'])) != $sfxMimeType)))
6157
+					(strlen(trim($_formData['type'])) == 0 || (strtolower(trim($_formData['type'])) != $sfxMimeType)))
6158 6158
 				{
6159 6159
 					error_log(__METHOD__.' ('.__LINE__.') '.' Data:'.array2string($_formData));
6160 6160
 					error_log(__METHOD__.' ('.__LINE__.') '.' Form reported Mimetype:'.$_formData['type'].' but seems to be:'.$sfxMimeType);
@@ -6169,13 +6169,13 @@  discard block
 block discarded – undo
6169 6169
 			if ($reqMimeType)
6170 6170
 			{
6171 6171
 				// so if PHP did not pass any file_type info, then substitute the rfc default value
6172
-				if (substr(strtolower(trim($_formData['type'])),0,strlen($mime_type_default)) != $mime_type_default)
6172
+				if (substr(strtolower(trim($_formData['type'])), 0, strlen($mime_type_default)) != $mime_type_default)
6173 6173
 				{
6174 6174
 					if (!(strtolower(trim($_formData['type'])) == "application/octet-stream" && $sfxMimeType == $reqMimeType))
6175 6175
 					{
6176 6176
 						//error_log("Message rejected, no message/rfc. Is:".$_formData['type']);
6177 6177
 						$importfailed = true;
6178
-						$alert_msg .= lang("File rejected, no %2. Is:%1",$_formData['type'],$reqMimeType);
6178
+						$alert_msg .= lang("File rejected, no %2. Is:%1", $_formData['type'], $reqMimeType);
6179 6179
 					}
6180 6180
 					if ((strtolower(trim($_formData['type'])) != $reqMimeType && $sfxMimeType == $reqMimeType))
6181 6181
 					{
@@ -6184,17 +6184,17 @@  discard block
 block discarded – undo
6184 6184
 				}
6185 6185
 			}
6186 6186
 			// as FreeBSD seems to have problems with the generated temp names we append some more random stuff
6187
-			$randomString = chr(rand(65,90)).chr(rand(48,57)).chr(rand(65,90)).chr(rand(48,57)).chr(rand(65,90));
6187
+			$randomString = chr(rand(65, 90)).chr(rand(48, 57)).chr(rand(65, 90)).chr(rand(48, 57)).chr(rand(65, 90));
6188 6188
 			$tmpFileName = $GLOBALS['egw_info']['user']['account_id'].
6189 6189
 				trim($IDtoAddToFileName).basename($_formData['file']).'_'.$randomString;
6190 6190
 
6191
-			if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'vfs')
6191
+			if (parse_url($_formData['file'], PHP_URL_SCHEME) == 'vfs')
6192 6192
 			{
6193
-				$tmpFileName = $_formData['file'];	// no need to store it somewhere
6193
+				$tmpFileName = $_formData['file']; // no need to store it somewhere
6194 6194
 			}
6195 6195
 			elseif (is_uploaded_file($_formData['file']))
6196 6196
 			{
6197
-				move_uploaded_file($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].SEP.$tmpFileName);	// requirement for safe_mode!
6197
+				move_uploaded_file($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].SEP.$tmpFileName); // requirement for safe_mode!
6198 6198
 			}
6199 6199
 			else
6200 6200
 			{
@@ -6203,7 +6203,7 @@  discard block
 block discarded – undo
6203 6203
 		} else {
6204 6204
 			//error_log("Import of message ".$_formData['file']." failes to meet basic restrictions");
6205 6205
 			$importfailed = true;
6206
-			$alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.",$_formData['name']);
6206
+			$alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.", $_formData['name']);
6207 6207
 		}
6208 6208
 		if ($importfailed == true)
6209 6209
 		{
@@ -6211,7 +6211,7 @@  discard block
 block discarded – undo
6211 6211
 		}
6212 6212
 		else
6213 6213
 		{
6214
-			if (parse_url($tmpFileName,PHP_URL_SCHEME) == 'vfs')
6214
+			if (parse_url($tmpFileName, PHP_URL_SCHEME) == 'vfs')
6215 6215
 			{
6216 6216
 				egw_vfs::load_wrapper('vfs');
6217 6217
 			}
@@ -6236,7 +6236,7 @@  discard block
 block discarded – undo
6236 6236
 		$images = null;
6237 6237
 		if (preg_match_all("/(src|background)=\"(.*)\"/Ui", $_html2parse, $images) && isset($images[2]))
6238 6238
 		{
6239
-			foreach($images[2] as $i => $url)
6239
+			foreach ($images[2] as $i => $url)
6240 6240
 			{
6241 6241
 				//$isData = false;
6242 6242
 				$basedir = $data = '';
@@ -6248,20 +6248,20 @@  discard block
 block discarded – undo
6248 6248
 					$filename = basename($url);
6249 6249
 					if (($directory = dirname($url)) == '.') $directory = '';
6250 6250
 					$ext = pathinfo($filename, PATHINFO_EXTENSION);
6251
-					$mimeType  = mime_magic::ext2mime($ext);
6252
-					if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
6251
+					$mimeType = mime_magic::ext2mime($ext);
6252
+					if (strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; }
6253 6253
 					$myUrl = $directory.$filename;
6254
-					if ($myUrl[0]=='/') // local path -> we only allow path's that are available via http/https (or vfs)
6254
+					if ($myUrl[0] == '/') // local path -> we only allow path's that are available via http/https (or vfs)
6255 6255
 					{
6256
-						$basedir = ($_SERVER['HTTPS']?'https://':'http://'.$_SERVER['HTTP_HOST']);
6256
+						$basedir = ($_SERVER['HTTPS'] ? 'https://' : 'http://'.$_SERVER['HTTP_HOST']);
6257 6257
 					}
6258 6258
 					// use vfs instead of url containing webdav.php
6259 6259
 					// ToDo: we should test if the webdav url is of our own scope, as we cannot handle foreign
6260 6260
 					// webdav.php urls as vfs
6261
-					if (strpos($myUrl,'/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it.
6261
+					if (strpos($myUrl, '/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it.
6262 6262
 					{
6263 6263
 						egw_vfs::load_wrapper('vfs');
6264
-						list(,$myUrl) = explode('/webdav.php',$myUrl,2);
6264
+						list(,$myUrl) = explode('/webdav.php', $myUrl, 2);
6265 6265
 						$basedir = 'vfs://default';
6266 6266
 						$needTempFile = false;
6267 6267
 					}
@@ -6274,11 +6274,11 @@  discard block
 block discarded – undo
6274 6274
 						// Strips the url and store it into a temp for further procss
6275 6275
 						$tmp_url = html_entity_decode($myUrl);
6276 6276
 
6277
-						parse_str(parse_url($tmp_url, PHP_URL_QUERY),$URI_params);
6277
+						parse_str(parse_url($tmp_url, PHP_URL_QUERY), $URI_params);
6278 6278
 						if ($URI_params['mailbox'] && $URI_params['uid'] && $URI_params['cid'])
6279 6279
 						{
6280 6280
 							$mail_bo->reopen(base64_decode($URI_params['mailbox']));
6281
-							$attachment = $mail_bo->getAttachmentByCID($URI_params['uid'], base64_decode($URI_params['cid']),base64_decode($URI_params['partID']),true);
6281
+							$attachment = $mail_bo->getAttachmentByCID($URI_params['uid'], base64_decode($URI_params['cid']), base64_decode($URI_params['partID']), true);
6282 6282
 							$mail_bo->closeConnection();
6283 6283
 							if ($attachment)
6284 6284
 							{
@@ -6289,32 +6289,32 @@  discard block
 block discarded – undo
6289 6289
 						}
6290 6290
 					}
6291 6291
 
6292
-					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/') { $basedir .= '/'; }
6293
-					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl));
6292
+					if (strlen($basedir) > 1 && substr($basedir, -1) != '/' && $myUrl[0] != '/') { $basedir .= '/'; }
6293
+					if ($needTempFile && !$attachment && substr($myUrl, 0, 4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl));
6294 6294
 				}
6295
-				if (substr($url,0,strlen('data:'))=='data:')
6295
+				if (substr($url, 0, strlen('data:')) == 'data:')
6296 6296
 				{
6297 6297
 					//error_log(__METHOD__.' ('.__LINE__.') '.' -> '.$i.': '.array2string($images[$i]));
6298 6298
 					// we only support base64 encoded data
6299
-					$tmp = substr($url,strlen('data:'));
6300
-					list($mimeType,$data_base64) = explode(';base64,',$tmp);
6299
+					$tmp = substr($url, strlen('data:'));
6300
+					list($mimeType, $data_base64) = explode(';base64,', $tmp);
6301 6301
 					$data = base64_decode($data_base64);
6302 6302
 					// FF currently does NOT add any mime-type
6303 6303
 					if (strtolower(substr($mimeType, 0, 6)) != 'image/')
6304 6304
 					{
6305 6305
 						$mimeType = mime_magic::analyze_data($data);
6306 6306
 					}
6307
-					list($what,$exactly) = explode('/',$mimeType);
6307
+					list($what, $exactly) = explode('/', $mimeType);
6308 6308
 					$needTempFile = true;
6309
-					$filename = ($what?$what:'data').$imageC++.'.'.$exactly;
6309
+					$filename = ($what ? $what : 'data').$imageC++.'.'.$exactly;
6310 6310
 				}
6311 6311
 				if ($data || $needTempFile === false)
6312 6312
 				{
6313 6313
 					if ($needTempFile)
6314 6314
 					{
6315
-						$attachment_file =tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
6316
-						$tmpfile = fopen($attachment_file,'w');
6317
-						fwrite($tmpfile,$data);
6315
+						$attachment_file = tempnam($GLOBALS['egw_info']['server']['temp_dir'], $GLOBALS['egw_info']['flags']['currentapp']."_");
6316
+						$tmpfile = fopen($attachment_file, 'w');
6317
+						fwrite($tmpfile, $data);
6318 6318
 						fclose($tmpfile);
6319 6319
 					}
6320 6320
 					else
@@ -6325,7 +6325,7 @@  discard block
 block discarded – undo
6325 6325
 					// (or similar) in all cases (when cut&paste). This may lead to more attached files, in case
6326 6326
 					// we use the same image multiple times, but, if we do this, we should try to detect that
6327 6327
 					// on upload. filename itself is not sufficient to determine the sameness of images
6328
-					$cid = 'cid:' . md5($attachment_file);
6328
+					$cid = 'cid:'.md5($attachment_file);
6329 6329
 					if ($_mailObject->AddEmbeddedImage($attachment_file, substr($cid, 4), $filename, $mimeType) !== null)
6330 6330
 					{
6331 6331
 						//$_html2parse = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $_html2parse);
@@ -6347,14 +6347,14 @@  discard block
 block discarded – undo
6347 6347
 	 * @param string $importID ID for the imported message, used by attachments to identify them unambiguously
6348 6348
 	 * @return mixed array of messages with success and failed messages or exception
6349 6349
 	 */
6350
-	function importMessageToMergeAndSend(bo_merge $bo_merge, $document, $SendAndMergeTocontacts, &$_folder, &$importID='')
6350
+	function importMessageToMergeAndSend(bo_merge $bo_merge, $document, $SendAndMergeTocontacts, &$_folder, &$importID = '')
6351 6351
 	{
6352 6352
 		$importfailed = false;
6353
-		$processStats = array('success'=>array(),'failed'=>array());
6353
+		$processStats = array('success'=>array(), 'failed'=>array());
6354 6354
 		if (empty($SendAndMergeTocontacts))
6355 6355
 		{
6356 6356
 			$importfailed = true;
6357
-			$alert_msg .= lang("Import of message %1 failed. No Contacts to merge and send to specified.",$_formData['name']);
6357
+			$alert_msg .= lang("Import of message %1 failed. No Contacts to merge and send to specified.", $_formData['name']);
6358 6358
 		}
6359 6359
 
6360 6360
 		// check if formdata meets basic restrictions (in tmp dir, or vfs, mimetype, etc.)
@@ -6391,7 +6391,7 @@  discard block
 block discarded – undo
6391 6391
 				$_folder = $this->getSentFolder();
6392 6392
 			}
6393 6393
 			$delimiter = $this->getHierarchyDelimiter();
6394
-			if($_folder=='INBOX'.$delimiter) $_folder='INBOX';
6394
+			if ($_folder == 'INBOX'.$delimiter) $_folder = 'INBOX';
6395 6395
 			if ($importfailed === false)
6396 6396
 			{
6397 6397
 				$Subject = $mailObject->getHeader('Subject');
@@ -6409,9 +6409,9 @@  discard block
 block discarded – undo
6409 6409
 				{
6410 6410
 					$mailObject->clearReplyTos();
6411 6411
 					$activeMailProfiles = $this->mail->getAccountIdentities($this->profileID);
6412
-					$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles,$this->profileID);
6412
+					$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles, $this->profileID);
6413 6413
 
6414
-					$mailObject->addReplyTo(self::$idna2->encode($activeMailProfile['ident_email']),emailadmin_imapbase::generateIdentityString($activeMailProfile,false));
6414
+					$mailObject->addReplyTo(self::$idna2->encode($activeMailProfile['ident_email']), emailadmin_imapbase::generateIdentityString($activeMailProfile, false));
6415 6415
 				}
6416 6416
 				foreach ($SendAndMergeTocontacts as $k => $val)
6417 6417
 				{
@@ -6425,12 +6425,12 @@  discard block
 block discarded – undo
6425 6425
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6426 6426
 
6427 6427
 						// Parse destinations for placeholders
6428
-						foreach(egw_mailer::$type2header as $type => $h)
6428
+						foreach (egw_mailer::$type2header as $type => $h)
6429 6429
 						{
6430 6430
 							//error_log('ID ' . $val . ' ' .$type . ': ' . $mailObject->getHeader(egw_mailer::$type2header[$type]) . ' -> ' .$bo_merge->merge_string($mailObject->getHeader(egw_mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset));
6431
-							$merged = $bo_merge->merge_string($mailObject->getHeader(egw_mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset);
6432
-							$mailObject->addAddress($merged,'',$type);
6433
-							if($type == 'to')
6431
+							$merged = $bo_merge->merge_string($mailObject->getHeader(egw_mailer::$type2header[$type]), $val, $e, 'text/plain', array(), self::$displayCharset);
6432
+							$mailObject->addAddress($merged, '', $type);
6433
+							if ($type == 'to')
6434 6434
 							{
6435 6435
 								$email = $merged;
6436 6436
 							}
@@ -6443,26 +6443,26 @@  discard block
 block discarded – undo
6443 6443
 							//error_log(__METHOD__.' ('.__LINE__.') '.' ID:'.$val.' Data:'.array2string($contact));
6444 6444
 							$email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
6445 6445
 							$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
6446
-							if($email)
6446
+							if ($email)
6447 6447
 							{
6448
-								$mailObject->addAddress(self::$idna2->encode($email),$mailObject->EncodeHeader($nfn));
6448
+								$mailObject->addAddress(self::$idna2->encode($email), $mailObject->EncodeHeader($nfn));
6449 6449
 							}
6450 6450
 						}
6451 6451
 
6452 6452
 						$activeMailProfiles = $this->getAccountIdentities($this->profileID);
6453
-						$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles,$this->profileID);
6453
+						$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles, $this->profileID);
6454 6454
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($activeMailProfile));
6455 6455
 						$mailObject->setFrom($activeMailProfile['ident_email'],
6456
-							self::generateIdentityString($activeMailProfile,false));
6456
+							self::generateIdentityString($activeMailProfile, false));
6457 6457
 
6458 6458
 						$mailObject->removeHeader('Message-ID');
6459 6459
 						$mailObject->removeHeader('Date');
6460 6460
 						$mailObject->clearCustomHeaders();
6461 6461
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6462 6462
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6463
-						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));
6463
+						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));
6464 6464
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6465
-						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));
6465
+						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));
6466 6466
 
6467 6467
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6468 6468
 						// set a higher timeout for big messages
@@ -6471,7 +6471,7 @@  discard block
 block discarded – undo
6471 6471
 						try {
6472 6472
 							$mailObject->send();
6473 6473
 						}
6474
-						catch(Exception $e) {
6474
+						catch (Exception $e) {
6475 6475
 							$sendOK = false;
6476 6476
 							$errorInfo = $e->getMessage();
6477 6477
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($errorInfo));
@@ -6485,42 +6485,42 @@  discard block
 block discarded – undo
6485 6485
 						$mailObject->clearCustomHeaders();
6486 6486
 
6487 6487
 						// Parse destinations for placeholders
6488
-						foreach(egw_mailer::$type2header as $type => $h)
6488
+						foreach (egw_mailer::$type2header as $type => $h)
6489 6489
 						{
6490 6490
 							// Parse destinations for placeholders
6491
-							$merged = $bo_merge->merge_string($mailObject->getHeader(egw_mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset);
6491
+							$merged = $bo_merge->merge_string($mailObject->getHeader(egw_mailer::$type2header[$type]), $val, $e, 'text/plain', array(), self::$displayCharset);
6492 6492
 							//error_log($type . ': ' . $mailObject->getHeader(Mailer::$type2header[$type]) . ' -> ' .$merged);
6493
-							$mailObject->addAddress(trim($merged,'"'),'',$type);
6493
+							$mailObject->addAddress(trim($merged, '"'), '', $type);
6494 6494
 						}
6495 6495
 
6496 6496
 						// No addresses from placeholders?  Treat it as just a contact ID
6497
-						if (count($mailObject->getAddresses('to',true)) == 0 &&
6497
+						if (count($mailObject->getAddresses('to', true)) == 0 &&
6498 6498
 							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)) // do the merge
6499 6499
 						{
6500 6500
 							$contact = $bo_merge->contacts->read($val);
6501 6501
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($contact));
6502 6502
 							$email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
6503 6503
 							$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
6504
-							if($email)
6504
+							if ($email)
6505 6505
 							{
6506
-								$mailObject->addAddress(self::$idna2->encode($email),$mailObject->EncodeHeader($nfn));
6506
+								$mailObject->addAddress(self::$idna2->encode($email), $mailObject->EncodeHeader($nfn));
6507 6507
 							}
6508 6508
 						}
6509 6509
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6510 6510
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6511
-						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));
6511
+						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));
6512 6512
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6513
-						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));
6513
+						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));
6514 6514
 						$_folder = $this->getDraftFolder();
6515 6515
 					}
6516 6516
 					if ($sendOK || $openAsDraft)
6517 6517
 					{
6518
-						if ($this->folderExists($_folder,true))
6518
+						if ($this->folderExists($_folder, true))
6519 6519
 						{
6520
-						    if($this->isSentFolder($_folder))
6520
+						    if ($this->isSentFolder($_folder))
6521 6521
 							{
6522 6522
 						        $flags = '\\Seen';
6523
-						    } elseif($this->isDraftFolder($_folder)) {
6523
+						    } elseif ($this->isDraftFolder($_folder)) {
6524 6524
 						        $flags = '\\Draft';
6525 6525
 						    } else {
6526 6526
 						        $flags = '';
@@ -6528,7 +6528,7 @@  discard block
 block discarded – undo
6528 6528
 							$savefailed = false;
6529 6529
 							try
6530 6530
 							{
6531
-								$messageUid =$this->appendMessage($_folder,
6531
+								$messageUid = $this->appendMessage($_folder,
6532 6532
 									$mailObject->getRaw(),
6533 6533
 									null,
6534 6534
 									$flags);
@@ -6536,10 +6536,10 @@  discard block
 block discarded – undo
6536 6536
 							catch (egw_exception_wrong_userinput $e)
6537 6537
 							{
6538 6538
 								$savefailed = true;
6539
-								$alert_msg .= lang("Save of message %1 failed. Could not save message to folder %2 due to: %3",$Subject,$_folder,$e->getMessage());
6539
+								$alert_msg .= lang("Save of message %1 failed. Could not save message to folder %2 due to: %3", $Subject, $_folder, $e->getMessage());
6540 6540
 							}
6541 6541
 							// no send, save successful, and message_uid present
6542
-							if ($savefailed===false && $messageUid && is_null($sendOK))
6542
+							if ($savefailed === false && $messageUid && is_null($sendOK))
6543 6543
 							{
6544 6544
 								$importID = $messageUid;
6545 6545
 								$openComposeWindow = true;
@@ -6548,20 +6548,20 @@  discard block
 block discarded – undo
6548 6548
 						else
6549 6549
 						{
6550 6550
 							$savefailed = true;
6551
-							$alert_msg .= lang("Saving of message %1 failed. Destination Folder %2 does not exist.",$Subject,$_folder);
6551
+							$alert_msg .= lang("Saving of message %1 failed. Destination Folder %2 does not exist.", $Subject, $_folder);
6552 6552
 						}
6553 6553
 						if ($sendOK)
6554 6554
 						{
6555
-							$processStats['success'][$val] = 'Send succeeded to '.$nfn.'<'.$email.'>'.($savefailed?' but failed to store to Folder:'.$_folder:'');
6555
+							$processStats['success'][$val] = 'Send succeeded to '.$nfn.'<'.$email.'>'.($savefailed ? ' but failed to store to Folder:'.$_folder : '');
6556 6556
 						}
6557 6557
 						else
6558 6558
 						{
6559
-							if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6559
+							if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo ? $errorInfo : 'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6560 6560
 						}
6561 6561
 					}
6562
-					if (!is_null($sendOK) && $sendOK===false && is_null($openComposeWindow))
6562
+					if (!is_null($sendOK) && $sendOK === false && is_null($openComposeWindow))
6563 6563
 					{
6564
-						$processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6564
+						$processStats['failed'][$val] = $errorInfo ? $errorInfo : 'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6565 6565
 					}
6566 6566
 				}
6567 6567
 			}
@@ -6631,19 +6631,18 @@  discard block
 block discarded – undo
6631 6631
 			//error_log(__METHOD__.__LINE__.':'.array2string($structure));
6632 6632
 
6633 6633
 			// unfortunately parseMessage does NOT return parsed headers (we assume header is shorter then 8k)
6634
-			$start = is_string($message) ? substr($message, 0, 8192) :
6635
-				(fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192));
6634
+			$start = is_string($message) ? substr($message, 0, 8192) : (fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192));
6636 6635
 
6637 6636
 			$length = strpos($start, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
6638
-			if ($length===false) $length = strlen($start);
6639
-			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0,$length));
6637
+			if ($length === false) $length = strlen($start);
6638
+			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0, $length));
6640 6639
 
6641
-			foreach($headers->toArray(array('nowrap' => true)) as $header => $value)
6640
+			foreach ($headers->toArray(array('nowrap' => true)) as $header => $value)
6642 6641
 			{
6643
-				foreach((array)$value as $n => $val)
6642
+				foreach ((array)$value as $n => $val)
6644 6643
 				{
6645 6644
 					$overwrite = !$n;
6646
-					switch($header)
6645
+					switch ($header)
6647 6646
 					{
6648 6647
 						case 'Content-Transfer-Encoding':
6649 6648
 							//as we parse the message and this sets the part with a Content-Transfer-Encoding, we
@@ -6664,7 +6663,7 @@  discard block
 block discarded – undo
6664 6663
 		}
6665 6664
 		else
6666 6665
 		{
6667
-			if (($type = gettype($message)) == 'object') $type = get_class ($message);
6666
+			if (($type = gettype($message)) == 'object') $type = get_class($message);
6668 6667
 			throw new egw_exception_wrong_parameter('Wrong parameter type for message: '.$type);
6669 6668
 		}
6670 6669
 	}
@@ -6678,50 +6677,50 @@  discard block
 block discarded – undo
6678 6677
 	 * @param string $default_domain
6679 6678
 	 * @return Horde_Mail_Rfc822_List iteratable Horde_Mail_Rfc822_Address objects with attributes mailbox, host, personal and valid
6680 6679
 	 */
6681
-	public static function parseAddressList($addresses, $default_domain=null)
6680
+	public static function parseAddressList($addresses, $default_domain = null)
6682 6681
 	{
6683 6682
 		$rfc822 = new Horde_Mail_Rfc822();
6684 6683
 		$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
6685 6684
 		//error_log(__METHOD__.__LINE__.'#'.array2string($addresses).'#'.array2string($ret).'#'.$ret->count().'#'.$ret->count.function_backtrace());
6686
-		if ((empty($ret) || $ret->count()==0)&& is_string($addresses) && strlen($addresses)>0)
6685
+		if ((empty($ret) || $ret->count() == 0) && is_string($addresses) && strlen($addresses) > 0)
6687 6686
 		{
6688 6687
 			$matches = array();
6689
-			preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/",$addresses,$matches);
6688
+			preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/", $addresses, $matches);
6690 6689
 			//error_log(__METHOD__.__LINE__.array2string($matches));
6691
-			foreach ($matches[0] as &$match) {$match = trim($match,', ');}
6692
-			$addresses = implode(',',$matches[0]);
6690
+			foreach ($matches[0] as &$match) {$match = trim($match, ', '); }
6691
+			$addresses = implode(',', $matches[0]);
6693 6692
 			//error_log(__METHOD__.__LINE__.array2string($addresses));
6694 6693
 			$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
6695 6694
 			//error_log(__METHOD__.__LINE__.'#'.array2string($addresses).'#'.array2string($ret).'#'.$ret->count().'#'.$ret->count);
6696 6695
 		}
6697
-		$previousFailed=false;
6696
+		$previousFailed = false;
6698 6697
 		$ret2 = new Horde_Mail_Rfc822_List();
6699 6698
 		// handle known problems on emailaddresses
6700
-		foreach($ret as $i => $adr)
6699
+		foreach ($ret as $i => $adr)
6701 6700
 		{
6702 6701
 			//mailaddresses enclosed in single quotes like '[email protected]' show up as 'me as mailbox and you.com' as host
6703
-			if ($adr->mailbox && stripos($adr->mailbox,"'")== 0 &&
6704
-					$adr->host && stripos($adr->host,"'")== (strlen($adr->host) -1))
6702
+			if ($adr->mailbox && stripos($adr->mailbox, "'") == 0 &&
6703
+					$adr->host && stripos($adr->host, "'") == (strlen($adr->host) - 1))
6705 6704
 			{
6706
-				$adr->mailbox = str_replace("'","",$adr->mailbox);
6707
-				$adr->host = str_replace("'","",$adr->host);
6705
+				$adr->mailbox = str_replace("'", "", $adr->mailbox);
6706
+				$adr->host = str_replace("'", "", $adr->host);
6708 6707
 			}
6709 6708
 			// no mailbox or host part as 'Xr\xc3\xa4hlyz, User <[email protected]>' is parsed as 2 addresses separated by ','
6710 6709
 			//#'Xr\xc3\xa4hlyz, User <[email protected]>'
6711 6710
 			//#Horde_Mail_Rfc822_List Object([_data:protected] => Array(
6712 6711
 			//[0] => Horde_Mail_Rfc822_Address Object([comment] => Array()[mailbox] => Xr\xc3\xa4hlyz[_host:protected] => [_personal:protected] => )
6713 6712
 			//[1] => Horde_Mail_Rfc822_Address Object([comment] => Array()[mailbox] => mailboxpart1.mailboxpart2[_host:protected] => youthost.com[_personal:protected] => User))[_filter:protected] => Array()[_ptr:protected] => )#2#,
6714
-			if (strlen($adr->mailbox)==0||strlen($adr->host)==0)
6713
+			if (strlen($adr->mailbox) == 0 || strlen($adr->host) == 0)
6715 6714
 			{
6716
-				$remember = ($adr->mailbox?$adr->mailbox:($adr->host?$adr->host:''));
6717
-				$previousFailed=true;
6715
+				$remember = ($adr->mailbox ? $adr->mailbox : ($adr->host ? $adr->host : ''));
6716
+				$previousFailed = true;
6718 6717
 				//error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal");
6719 6718
 			}
6720 6719
 			else
6721 6720
 			{
6722
-				if ($previousFailed && $remember) $adr->personal = $remember. ' ' . $adr->personal;
6721
+				if ($previousFailed && $remember) $adr->personal = $remember.' '.$adr->personal;
6723 6722
 				$remember = '';
6724
-				$previousFailed=false;
6723
+				$previousFailed = false;
6725 6724
 				//error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal");
6726 6725
 				$ret2->add($adr);
6727 6726
 			}
@@ -6737,7 +6736,7 @@  discard block
 block discarded – undo
6737 6736
 	 * @param string $_folder
6738 6737
 	 * @return boolean
6739 6738
 	 */
6740
-	function sendMDN($uid,$_folder)
6739
+	function sendMDN($uid, $_folder)
6741 6740
 	{
6742 6741
 		$acc = emailadmin_account::read($this->profileID);
6743 6742
 		$identity = emailadmin_account::read_identity($acc['ident_id'], true, null, $acc);
@@ -6767,7 +6766,7 @@  discard block
 block discarded – undo
6767 6766
 	 */
6768 6767
 	function addAccount($_hookValues)
6769 6768
 	{
6770
-		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!' . ' hookValue = '. $_hookValues);
6769
+		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!'.' hookValue = '.$_hookValues);
6771 6770
 
6772 6771
 	}
6773 6772
 
@@ -6781,7 +6780,7 @@  discard block
 block discarded – undo
6781 6780
 	 */
6782 6781
 	function deleteAccount($_hookValues)
6783 6782
 	{
6784
-		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!' . ' hookValue = '. $_hookValues);
6783
+		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!'.' hookValue = '.$_hookValues);
6785 6784
 
6786 6785
 	}
6787 6786
 
@@ -6795,7 +6794,7 @@  discard block
 block discarded – undo
6795 6794
 	 */
6796 6795
 	function updateAccount($_hookValues)
6797 6796
 	{
6798
-		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!' . ' hookValue = '. $_hookValues);
6797
+		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!'.' hookValue = '.$_hookValues);
6799 6798
 
6800 6799
 	}
6801 6800
 }
Please login to merge, or discard this patch.
emailadmin/inc/class.emailadmin_script.inc.php 3 patches
Doc Comments   +5 added lines, -1 removed lines patch added patch discarded remove patch
@@ -52,6 +52,10 @@  discard block
 block discarded – undo
52 52
 	var $debug=false;
53 53
 
54 54
 	// class constructor
55
+
56
+	/**
57
+	 * @param string $scriptname
58
+	 */
55 59
 	function __construct ($scriptname) {
56 60
 		$this->name = $scriptname;
57 61
 		$this->script = '';
@@ -69,7 +73,7 @@  discard block
 block discarded – undo
69 73
 	/**
70 74
 	 * Retrieve the rules
71 75
 	 *
72
-	 * @param bosieve $connection
76
+	 * @param emailadmin_sieve $connection
73 77
 	 * @return boolean true, if script written successfull
74 78
 	 */
75 79
 	function retrieveRules ($connection) {
Please login to merge, or discard this patch.
Spacing   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -18,17 +18,17 @@  discard block
 block discarded – undo
18 18
  */
19 19
 class emailadmin_script {
20 20
 
21
-	var $name;         /* filename of script. */
22
-	var $script;       /* full ascii text of script from server. */
23
-	var $size;         /* size of script in bytes. */
24
-	var $so;           /* boolean: is it safe to overwrite script?
21
+	var $name; /* filename of script. */
22
+	var $script; /* full ascii text of script from server. */
23
+	var $size; /* size of script in bytes. */
24
+	var $so; /* boolean: is it safe to overwrite script?
25 25
 											* only safe if we recognise encoding. */
26
-	var $mode;         /* basic or advanced. Smartsieve can only read/write basic. */
27
-	var $rules;        /* array of sieve rules. */
28
-	var $vacation;     /* vacation settings. */
26
+	var $mode; /* basic or advanced. Smartsieve can only read/write basic. */
27
+	var $rules; /* array of sieve rules. */
28
+	var $vacation; /* vacation settings. */
29 29
 	var $emailNotification; /* email notification settings. */
30
-	var $pcount;       /* highest priority value in ruleset. */
31
-	var $errstr;       /* error text. */
30
+	var $pcount; /* highest priority value in ruleset. */
31
+	var $errstr; /* error text. */
32 32
 	/**
33 33
 	 * Body transform content types
34 34
 	 *
@@ -49,10 +49,10 @@  discard block
 block discarded – undo
49 49
 	 *
50 50
 	 * @var boolean
51 51
 	 */
52
-	var $debug=false;
52
+	var $debug = false;
53 53
 
54 54
 	// class constructor
55
-	function __construct ($scriptname) {
55
+	function __construct($scriptname) {
56 56
 		$this->name = $scriptname;
57 57
 		$this->script = '';
58 58
 		$this->size = 0;
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	 * @param bosieve $connection
73 73
 	 * @return boolean true, if script written successfull
74 74
 	 */
75
-	function retrieveRules ($connection) {
75
+	function retrieveRules($connection) {
76 76
 		#global $_SESSION;
77 77
 		$continuebit = 1;
78 78
 		$sizebit = 2;
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 		$keepbit = 8;
81 81
 		$regexbit = 128;
82 82
 
83
-		if (!isset($this->name)){
83
+		if (!isset($this->name)) {
84 84
 			$this->errstr = 'retrieveRules: no script name specified';
85 85
 			if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.": no script name specified");
86 86
 			return false;
@@ -99,13 +99,13 @@  discard block
 block discarded – undo
99 99
 			$this->updateScript($connection);
100 100
 		}
101 101
 
102
-		if(self::isError($script = $connection->getScript($this->name))) {
102
+		if (self::isError($script = $connection->getScript($this->name))) {
103 103
 			if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.": error retrieving script: ".$script->getMessage());
104 104
 			return $script;
105 105
 		}
106 106
 		#print "<br>AAA: Script is ". htmlentities($script) ."<br>";
107 107
 
108
-		$lines = preg_split("/\n/",$script); //,PREG_SPLIT_NO_EMPTY);
108
+		$lines = preg_split("/\n/", $script); //,PREG_SPLIT_NO_EMPTY);
109 109
 
110 110
 		$rules = array();
111 111
 		$vacation = array();
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 		/* next line should be the recognised encoded head. if not, the script
124 124
 		 * is of an unrecognised format, and we should not overwrite it. */
125 125
 		$line1 = array_shift($lines);
126
-		if (!preg_match("/^# ?Mail(.*)rules for/", $line1)){
126
+		if (!preg_match("/^# ?Mail(.*)rules for/", $line1)) {
127 127
 				$this->errstr = 'retrieveRules: encoding not recognised';
128 128
 				$this->so = false;
129 129
 				if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.": encoding not recognised");
@@ -136,62 +136,62 @@  discard block
 block discarded – undo
136 136
 		while (isset($line))
137 137
 		{
138 138
 			$matches = null;
139
-			if (preg_match("/^ *#(#PSEUDO|rule|vacation|mode|notify)/i",$line,$matches)){
139
+			if (preg_match("/^ *#(#PSEUDO|rule|vacation|mode|notify)/i", $line, $matches)) {
140 140
 				$line = rtrim($line);
141
-				switch ($matches[1]){
141
+				switch ($matches[1]) {
142 142
 					case "rule":
143
-						$bits = explode("&&",  $line);
143
+						$bits = explode("&&", $line);
144 144
 						$rule = array();
145
-						$rule['priority']	= $bits[1];
145
+						$rule['priority'] = $bits[1];
146 146
 						$rule['status']		= $bits[2];
147
-						$rule['from']		= stripslashes($bits[3]);
148
-						$rule['to']		= stripslashes($bits[4]);
147
+						$rule['from'] = stripslashes($bits[3]);
148
+						$rule['to'] = stripslashes($bits[4]);
149 149
 						$rule['subject']	= stripslashes($bits[5]);
150 150
 						$rule['action']		= $bits[6];
151 151
 						$rule['action_arg']	= $bits[7];
152 152
 						// <crnl>s will be encoded as \\n. undo this.
153
-						$rule['action_arg']	= preg_replace("/\\\\n/","\r\n",$rule['action_arg']);
153
+						$rule['action_arg']	= preg_replace("/\\\\n/", "\r\n", $rule['action_arg']);
154 154
 						$rule['action_arg']	= stripslashes($rule['action_arg']);
155
-						$rule['flg']		= $bits[8];   // bitwise flag
156
-						$rule['field']		= stripslashes($bits[9]);
157
-						$rule['field_val']	= stripslashes($bits[10]);
158
-						$rule['size']		= $bits[11];
159
-						$rule['continue']	= ($bits[8] & $continuebit);
160
-						$rule['gthan']		= ($bits[8] & $sizebit); // use 'greater than'
161
-						$rule['anyof']		= ($bits[8] & $anyofbit);
162
-						$rule['keep']		= ($bits[8] & $keepbit);
163
-						$rule['regexp']		= ($bits[8] & $regexbit);
155
+						$rule['flg'] = $bits[8]; // bitwise flag
156
+						$rule['field'] = stripslashes($bits[9]);
157
+						$rule['field_val'] = stripslashes($bits[10]);
158
+						$rule['size'] = $bits[11];
159
+						$rule['continue'] = ($bits[8]&$continuebit);
160
+						$rule['gthan']		= ($bits[8]&$sizebit); // use 'greater than'
161
+						$rule['anyof']		= ($bits[8]&$anyofbit);
162
+						$rule['keep'] = ($bits[8]&$keepbit);
163
+						$rule['regexp'] = ($bits[8]&$regexbit);
164 164
 						$rule['bodytransform'] = ($bits[12]);
165 165
 						$rule['field_bodytransform'] = ($bits[13]);
166 166
 						$rule['ctype'] = ($bits[14]);
167 167
 						$rule['field_ctype_val'] = ($bits[15]);
168
-						$rule['unconditional']	= 0;
168
+						$rule['unconditional'] = 0;
169 169
 						if (!$rule['from'] && !$rule['to'] && !$rule['subject'] &&
170 170
 							!$rule['field'] && !$rule['size'] && $rule['action']) {
171 171
 							$rule['unconditional'] = 1;
172 172
 						}
173 173
 
174
-						array_push($rules,$rule);
174
+						array_push($rules, $rule);
175 175
 
176 176
 						if ($rule['priority'] > $this->pcount) {
177 177
 							$this->pcount = $rule['priority'];
178 178
 						}
179 179
 						break;
180 180
 					case "vacation" :
181
-						if (preg_match("/^ *#vacation&&(.*)&&(.*)&&(.*)&&(.*)&&(.*)/i",$line,$bits) ||
182
-							preg_match("/^ *#vacation&&(.*)&&(.*)&&(.*)&&(.*)/i",$line,$bits)) {
181
+						if (preg_match("/^ *#vacation&&(.*)&&(.*)&&(.*)&&(.*)&&(.*)/i", $line, $bits) ||
182
+							preg_match("/^ *#vacation&&(.*)&&(.*)&&(.*)&&(.*)/i", $line, $bits)) {
183 183
 							$vacation['days'] = $bits[1];
184
-							$vaddresslist = preg_replace("/\"|\s/","",$bits[2]);
185
-							$vaddresses = preg_split("/,/",$vaddresslist);
184
+							$vaddresslist = preg_replace("/\"|\s/", "", $bits[2]);
185
+							$vaddresses = preg_split("/,/", $vaddresslist);
186 186
 							$vacation['text'] = $bits[3];
187 187
 
188 188
 						// <crnl>s will be encoded as \\n. undo this.
189
-							$vacation['text'] = preg_replace("/\\\\n/","\r\n",$vacation['text']);
189
+							$vacation['text'] = preg_replace("/\\\\n/", "\r\n", $vacation['text']);
190 190
 
191
-							if (strpos($bits[4],'-')!== false)
191
+							if (strpos($bits[4], '-') !== false)
192 192
 							{
193 193
 								$vacation['status'] = 'by_date';
194
-								list($vacation['start_date'],$vacation['end_date']) = explode('-',$bits[4]);
194
+								list($vacation['start_date'], $vacation['end_date']) = explode('-', $bits[4]);
195 195
 							}
196 196
 							else
197 197
 							{
@@ -203,14 +203,14 @@  discard block
 block discarded – undo
203 203
 						}
204 204
 						break;
205 205
 					case "notify":
206
-						if (preg_match("/^ *#notify&&(.*)&&(.*)&&(.*)/i",$line,$bits)) {
206
+						if (preg_match("/^ *#notify&&(.*)&&(.*)&&(.*)/i", $line, $bits)) {
207 207
 							$emailNotification['status'] = $bits[1];
208 208
 							$emailNotification['externalEmail'] = $bits[2];
209 209
 							$emailNotification['displaySubject'] = $bits[3];
210 210
 						}
211 211
 						break;
212 212
 					case "mode" :
213
-						if (preg_match("/^ *#mode&&(.*)/i",$line,$bits)){
213
+						if (preg_match("/^ *#mode&&(.*)/i", $line, $bits)) {
214 214
 							if ($bits[1] == 'basic')
215 215
 								$this->mode = 'basic';
216 216
 							elseif ($bits[1] == 'advanced')
@@ -226,9 +226,9 @@  discard block
 block discarded – undo
226 226
 		$this->script = $script;
227 227
 		$this->rules = $rules;
228 228
 		$this->vacation = $vacation;
229
-		if (!(in_array('vacation',$connection->_capability['extensions'])|| in_array('VACATION', $connection->_capability['extensions']))) $this->vacation = false;
229
+		if (!(in_array('vacation', $connection->_capability['extensions']) || in_array('VACATION', $connection->_capability['extensions']))) $this->vacation = false;
230 230
 		$this->emailNotification = $emailNotification; // Added email notifications
231
-		if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.": Script succesful retrieved: ".print_r($vacation,true));
231
+		if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.": Script succesful retrieved: ".print_r($vacation, true));
232 232
 
233 233
 		return true;
234 234
 	}
@@ -240,10 +240,10 @@  discard block
 block discarded – undo
240 240
 	 * @param emailadmin_imap $connection
241 241
 	 * @param boolean $utf7imap_fileinto =false true: encode foldernames with utf7imap, default utf8
242 242
 	 */
243
-	function updateScript ($connection, $utf7imap_fileinto=false)
243
+	function updateScript($connection, $utf7imap_fileinto = false)
244 244
 	{
245 245
 		#global $_SESSION,$default,$sieve;
246
-		global $default,$sieve;
246
+		global $default, $sieve;
247 247
 
248 248
 		$activerules = 0;
249 249
 		$regexused = 0;
@@ -251,8 +251,8 @@  discard block
 block discarded – undo
251 251
 		$rejectused = 0;
252 252
 		$vacation_active = false;
253 253
 
254
-		$username	= $GLOBALS['egw_info']['user']['account_lid'];
255
-		$version	= $GLOBALS['egw_info']['apps']['mail']['version'];
254
+		$username = $GLOBALS['egw_info']['user']['account_lid'];
255
+		$version = $GLOBALS['egw_info']['apps']['mail']['version'];
256 256
 
257 257
 		//include "$default->lib_dir/version.php";
258 258
 
@@ -271,12 +271,12 @@  discard block
 block discarded – undo
271 271
 
272 272
 		// lets generate the main body of the script from our rules
273 273
 		//error_log(__METHOD__.__LINE__.array2string($connection->_capability));
274
-		$enotify = $variables= $supportsbody = false;
275
-		if (in_array('enotify',$connection->_capability['extensions'])|| in_array('ENOTIFY', $connection->_capability['extensions'])) $enotify = true;
276
-		if (in_array('variables',$connection->_capability['extensions'])|| in_array('VARIABLES', $connection->_capability['extensions'])) $variables = true;
274
+		$enotify = $variables = $supportsbody = false;
275
+		if (in_array('enotify', $connection->_capability['extensions']) || in_array('ENOTIFY', $connection->_capability['extensions'])) $enotify = true;
276
+		if (in_array('variables', $connection->_capability['extensions']) || in_array('VARIABLES', $connection->_capability['extensions'])) $variables = true;
277 277
 		if (in_array('body', $connection->_capability['extensions']) || in_array('BODY', $connection->_capability['extensions'])) $supportsbody = true;
278
-		if (!(in_array('vacation',$connection->_capability['extensions'])|| in_array('VACATION', $connection->_capability['extensions']))) $this->vacation = false;
279
-		if (!(in_array('regex',$connection->_capability['extensions'])|| in_array('REGEX', $connection->_capability['extensions']))) $regexsupported = false;
278
+		if (!(in_array('vacation', $connection->_capability['extensions']) || in_array('VACATION', $connection->_capability['extensions']))) $this->vacation = false;
279
+		if (!(in_array('regex', $connection->_capability['extensions']) || in_array('REGEX', $connection->_capability['extensions']))) $regexsupported = false;
280 280
 
281 281
 		$newscriptbody = "";
282 282
 		$continue = 1;
@@ -300,83 +300,83 @@  discard block
 block discarded – undo
300 300
 
301 301
 				if (!$rule['unconditional']) {
302 302
 						if (!$continue) $newruletext .= "els";
303
-						$newruletext .= "if " . $anyall . " (";
303
+						$newruletext .= "if ".$anyall." (";
304 304
 						if ($rule['from']) {
305
-								if (preg_match("/^\s*!/", $rule['from'])){
305
+								if (preg_match("/^\s*!/", $rule['from'])) {
306 306
 										$newruletext .= 'not ';
307
-										$rule['from'] = preg_replace("/^\s*!/","",$rule['from']);
307
+										$rule['from'] = preg_replace("/^\s*!/", "", $rule['from']);
308 308
 								}
309 309
 								$match = ':contains';
310 310
 								if (preg_match("/\*|\?/", $rule['from'])) $match = ':matches';
311 311
 								if ($rule['regexp']) $match = ':regex';
312
-								$newruletext .= "address " . $match . " [\"From\"]";
313
-								$newruletext .= " \"" . addslashes($rule['from']) . "\"";
312
+								$newruletext .= "address ".$match." [\"From\"]";
313
+								$newruletext .= " \"".addslashes($rule['from'])."\"";
314 314
 								$started = 1;
315 315
 						}
316 316
 						if ($rule['to']) {
317 317
 								if ($started) $newruletext .= ", ";
318
-								if (preg_match("/^\s*!/", $rule['to'])){
318
+								if (preg_match("/^\s*!/", $rule['to'])) {
319 319
 										$newruletext .= 'not ';
320
-										$rule['to'] = preg_replace("/^\s*!/","",$rule['to']);
320
+										$rule['to'] = preg_replace("/^\s*!/", "", $rule['to']);
321 321
 								}
322 322
 								$match = ':contains';
323 323
 								if (preg_match("/\*|\?/", $rule['to'])) $match = ':matches';
324 324
 								if ($rule['regexp']) $match = ':regex';
325
-								$newruletext .= "address " . $match . " [\"To\",\"TO\",\"Cc\",\"CC\"]";
326
-								$newruletext .= " \"" . addslashes($rule['to']) . "\"";
325
+								$newruletext .= "address ".$match." [\"To\",\"TO\",\"Cc\",\"CC\"]";
326
+								$newruletext .= " \"".addslashes($rule['to'])."\"";
327 327
 								$started = 1;
328 328
 						}
329 329
 						if ($rule['subject']) {
330 330
 								if ($started) $newruletext .= ", ";
331
-								if (preg_match("/^\s*!/", $rule['subject'])){
331
+								if (preg_match("/^\s*!/", $rule['subject'])) {
332 332
 										$newruletext .= 'not ';
333
-										$rule['subject'] = preg_replace("/^\s*!/","",$rule['subject']);
333
+										$rule['subject'] = preg_replace("/^\s*!/", "", $rule['subject']);
334 334
 								}
335 335
 								$match = ':contains';
336 336
 								if (preg_match("/\*|\?/", $rule['subject'])) $match = ':matches';
337 337
 								if ($rule['regexp']) $match = ':regex';
338
-								$newruletext .= "header " . $match . " \"subject\"";
339
-								$newruletext .= " \"" . addslashes($rule['subject']) . "\"";
338
+								$newruletext .= "header ".$match." \"subject\"";
339
+								$newruletext .= " \"".addslashes($rule['subject'])."\"";
340 340
 								$started = 1;
341 341
 						}
342 342
 						if ($rule['field'] && $rule['field_val']) {
343 343
 								if ($started) $newruletext .= ", ";
344
-								if (preg_match("/^\s*!/", $rule['field_val'])){
344
+								if (preg_match("/^\s*!/", $rule['field_val'])) {
345 345
 										$newruletext .= 'not ';
346
-										$rule['field_val'] = preg_replace("/^\s*!/","",$rule['field_val']);
346
+										$rule['field_val'] = preg_replace("/^\s*!/", "", $rule['field_val']);
347 347
 								}
348 348
 								$match = ':contains';
349 349
 								if (preg_match("/\*|\?/", $rule['field_val'])) $match = ':matches';
350 350
 								if ($rule['regexp']) $match = ':regex';
351
-								$newruletext .= "header " . $match . " \"" . addslashes($rule['field']) . "\"";
352
-								$newruletext .= " \"" . addslashes($rule['field_val']) . "\"";
351
+								$newruletext .= "header ".$match." \"".addslashes($rule['field'])."\"";
352
+								$newruletext .= " \"".addslashes($rule['field_val'])."\"";
353 353
 								$started = 1;
354 354
 						}
355 355
 						if ($rule['size']) {
356 356
 								$xthan = " :under ";
357 357
 								if ($rule['gthan']) $xthan = " :over ";
358 358
 								if ($started) $newruletext .= ", ";
359
-								$newruletext .= "size " . $xthan . $rule['size'] . "K";
359
+								$newruletext .= "size ".$xthan.$rule['size']."K";
360 360
 								$started = 1;
361 361
 						}
362
-						if ($supportsbody){
363
-							if (!empty($rule['field_bodytransform'])){
362
+						if ($supportsbody) {
363
+							if (!empty($rule['field_bodytransform'])) {
364 364
 								if ($started) $newruletext .= ", ";
365
-								$btransform	= " :raw ";
365
+								$btransform = " :raw ";
366 366
 								$match = ' :contains';
367 367
 								if ($rule['bodytransform'])	$btransform = " :text ";
368 368
 								if (preg_match("/\*|\?/", $rule['field_bodytransform'])) $match = ':matches';
369 369
 								if ($rule['regexp']) $match = ':regex';
370
-								$newruletext .= "body " . $btransform . $match . " \"" . $rule['field_bodytransform'] . "\"";
370
+								$newruletext .= "body ".$btransform.$match." \"".$rule['field_bodytransform']."\"";
371 371
 								$started = 1;
372 372
 
373 373
 							}
374
-							if ($rule['ctype']!= '0' && !empty($rule['ctype'])){
374
+							if ($rule['ctype'] != '0' && !empty($rule['ctype'])) {
375 375
 								if ($started) $newruletext .= ", ";
376 376
 								$btransform_ctype = emailadmin_script::$btransform_ctype_array[$rule['ctype']];
377 377
 								$ctype_subtype = "";
378 378
 								if ($rule['field_ctype_val']) $ctype_subtype = "/";
379
-								$newruletext .= "body :content " . " \"" . $btransform_ctype . $ctype_subtype . $rule['field_ctype_val'] . "\"" . " :contains \"\"";
379
+								$newruletext .= "body :content "." \"".$btransform_ctype.$ctype_subtype.$rule['field_ctype_val']."\""." :contains \"\"";
380 380
 								$started = 1;
381 381
 								//error_log(__CLASS__."::".__METHOD__.array2string(emailadmin_script::$btransform_ctype_array));
382 382
 							}
@@ -387,21 +387,21 @@  discard block
 block discarded – undo
387 387
 
388 388
 				if (!$rule['unconditional']) $newruletext .= ") {\n\t";
389 389
 
390
-				if (preg_match("/folder/i",$rule['action'])) {
391
-						$newruletext .= "fileinto \"" . ($utf7imap_fileinto ?
392
-							translation::convert($rule['action_arg'],'utf-8', 'utf7-imap') : $rule['action_arg']) . "\";";
390
+				if (preg_match("/folder/i", $rule['action'])) {
391
+						$newruletext .= "fileinto \"".($utf7imap_fileinto ?
392
+							translation::convert($rule['action_arg'], 'utf-8', 'utf7-imap') : $rule['action_arg'])."\";";
393 393
 				}
394
-				if (preg_match("/reject/i",$rule['action'])) {
395
-						$newruletext .= "reject text: \n" . $rule['action_arg'] . "\n.\n;";
394
+				if (preg_match("/reject/i", $rule['action'])) {
395
+						$newruletext .= "reject text: \n".$rule['action_arg']."\n.\n;";
396 396
 						$rejectused = 1;
397 397
 				}
398
-				if (preg_match("/address/i",$rule['action'])) {
399
-						foreach(preg_split('/, ?/',$rule['action_arg']) as $addr)
398
+				if (preg_match("/address/i", $rule['action'])) {
399
+						foreach (preg_split('/, ?/', $rule['action_arg']) as $addr)
400 400
 						{
401 401
 							$newruletext .= "\tredirect \"".trim($addr)."\";\n";
402 402
 						}
403 403
 				}
404
-				if (preg_match("/discard/i",$rule['action'])) {
404
+				if (preg_match("/discard/i", $rule['action'])) {
405 405
 						$newruletext .= "discard;";
406 406
 				}
407 407
 				if ($rule['keep']) $newruletext .= "\n\tkeep;";
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
 				if ($rule['continue']) $continue = 1;
412 412
 				if ($rule['unconditional']) $continue = 1;
413 413
 
414
-				$newscriptbody .= $newruletext . "\n\n";
414
+				$newscriptbody .= $newruletext."\n\n";
415 415
 
416 416
 			} // end 'if ! ENABLED'
417 417
 		}
@@ -420,32 +420,32 @@  discard block
 block discarded – undo
420 420
 
421 421
 		if ($this->vacation) {
422 422
 			$vacation = $this->vacation;
423
-			if (!$vacation['days']) $vacation['days'] = ($default->vacation_days ? $default->vacation_days:'');
424
-			if (!$vacation['text']) $vacation['text'] = ($default->vacation_text ? $default->vacation_text:'');
423
+			if (!$vacation['days']) $vacation['days'] = ($default->vacation_days ? $default->vacation_days : '');
424
+			if (!$vacation['text']) $vacation['text'] = ($default->vacation_text ? $default->vacation_text : '');
425 425
 			if (!$vacation['status']) $vacation['status'] = 'on';
426 426
 
427 427
 			// filter out invalid addresses.
428 428
 			$ok_vaddrs = array();
429
-			foreach($vacation['addresses'] as $addr){
430
-				if ($addr != '' && preg_match("/\@/",$addr))
431
-				array_push($ok_vaddrs,$addr);
429
+			foreach ($vacation['addresses'] as $addr) {
430
+				if ($addr != '' && preg_match("/\@/", $addr))
431
+				array_push($ok_vaddrs, $addr);
432 432
 			}
433 433
 			$vacation['addresses'] = $ok_vaddrs;
434 434
 
435
-			if (!$vacation['addresses'][0]){
436
-				$defaultaddr = $sieve->user . '@' . $sieve->maildomain;
437
-				array_push($vacation['addresses'],$defaultaddr);
435
+			if (!$vacation['addresses'][0]) {
436
+				$defaultaddr = $sieve->user.'@'.$sieve->maildomain;
437
+				array_push($vacation['addresses'], $defaultaddr);
438 438
 			}
439
-			if (($vacation['status'] == 'on' && strlen(trim($vacation['text']))>0)|| $vacation['status'] == 'by_date' &&
440
-				$vacation['start_date'] <= time() && time() < $vacation['end_date']+24*3600)	// +24*3600 to include the end_date day
439
+			if (($vacation['status'] == 'on' && strlen(trim($vacation['text'])) > 0) || $vacation['status'] == 'by_date' &&
440
+				$vacation['start_date'] <= time() && time() < $vacation['end_date'] + 24 * 3600)	// +24*3600 to include the end_date day
441 441
 			{
442 442
 				if (trim($vacation['forwards'])) {
443 443
 					$if = array();
444
-					foreach($vacation['addresses'] as $addr) {
444
+					foreach ($vacation['addresses'] as $addr) {
445 445
 						$if[] = 'address :contains ["To","TO","Cc","CC"] "'.trim($addr).'"';
446 446
 					}
447
-					$newscriptbody .= 'if anyof ('.implode(', ',$if).") {\n";
448
-					foreach(preg_split('/, ?/',$vacation['forwards']) as $addr) {
447
+					$newscriptbody .= 'if anyof ('.implode(', ', $if).") {\n";
448
+					foreach (preg_split('/, ?/', $vacation['forwards']) as $addr) {
449 449
 						$newscriptbody .= "\tredirect \"".trim($addr)."\";\n";
450 450
 					}
451 451
 					$newscriptbody .= "\tkeep;\n}\n";
@@ -466,11 +466,11 @@  discard block
 block discarded – undo
466 466
 						$newscriptbody .= "if header :contains ".'"X-Spam-Status" '.'"YES"'."{\n\tstop;\n}\n"; //stop vacation reply if it is spam
467 467
 					}
468 468
 				}
469
-				$newscriptbody .= "vacation :days " . $vacation['days'] . " :addresses [";
469
+				$newscriptbody .= "vacation :days ".$vacation['days']." :addresses [";
470 470
 				$first = 1;
471 471
 				foreach ($vacation['addresses'] as $vaddress) {
472 472
 						if (!$first) $newscriptbody .= ", ";
473
-						$newscriptbody .= "\"" . trim($vaddress) . "\"";
473
+						$newscriptbody .= "\"".trim($vaddress)."\"";
474 474
 						$first = 0;
475 475
 				}
476 476
 				$message = $vacation['text'];
@@ -478,12 +478,12 @@  discard block
 block discarded – undo
478 478
 				{
479 479
 					$format_date = 'd M Y'; // see to it, that there is always a format, because if it is missing - no date will be output
480 480
 					if (!empty($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'])) $format_date = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'];
481
-					$message = str_replace(array('$$start$$','$$end$$'),array(
482
-							date($format_date,$vacation['start_date']),
483
-							date($format_date,$vacation['end_date']),
484
-						),$message);
481
+					$message = str_replace(array('$$start$$', '$$end$$'), array(
482
+							date($format_date, $vacation['start_date']),
483
+							date($format_date, $vacation['end_date']),
484
+						), $message);
485 485
 				}
486
-				$newscriptbody .= "] text:\n" . $message . "\n.\n;\n\n";
486
+				$newscriptbody .= "] text:\n".$message."\n.\n;\n\n";
487 487
 			}
488 488
 
489 489
 			// update with any changes.
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
 
497 497
 			// format notification body
498 498
 			$egw_site_title = $GLOBALS['egw_info']['server']['site_title'];
499
-			if ($enotify==true)
499
+			if ($enotify == true)
500 500
 			{
501 501
 				$notification_body = lang("You have received a new message on the")." {$egw_site_title}";
502 502
 				if ($variables)
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
 				}
513 513
 				else
514 514
 				{
515
-					$notification_body ="[SIEVE] ".$notification_body;
515
+					$notification_body = "[SIEVE] ".$notification_body;
516 516
 				}
517 517
 				$newscriptbody .= 'notify :message "'.$notification_body.'"'."\n\t".'"mailto:'.$notification_email.'";'."\n";
518 518
 				//$newscriptbody .= 'notify :message "'.$notification_body.'" :method "mailto" :options "'.$notification_email.'?subject='.$notification_subject.'";'."\n";
@@ -536,8 +536,8 @@  discard block
 block discarded – undo
536 536
 		// generate the script head
537 537
 
538 538
 		$newscripthead = "";
539
-		$newscripthead .= "#Mail filter rules for " . $username . "\n";
540
-		$newscripthead .= '#Generated by ' . $username . ' using Mail ' . $version . ' ' . date($default->script_date_format);
539
+		$newscripthead .= "#Mail filter rules for ".$username."\n";
540
+		$newscripthead .= '#Generated by '.$username.' using Mail '.$version.' '.date($default->script_date_format);
541 541
 		$newscripthead .= "\n";
542 542
 
543 543
 		if ($activerules) {
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
 				$newscripthead .= ",\"vacation\"";
549 549
 			}
550 550
 			if ($supportsbody) $newscripthead .= ",\"body\"";
551
-			if ($this->emailNotification && $this->emailNotification['status'] == 'on') $newscripthead .= ',"'.($enotify?'e':'').'notify"'.($variables?',"variables"':''); // Added email notifications
551
+			if ($this->emailNotification && $this->emailNotification['status'] == 'on') $newscripthead .= ',"'.($enotify ? 'e' : '').'notify"'.($variables ? ',"variables"' : ''); // Added email notifications
552 552
 			$newscripthead .= "];\n\n";
553 553
 		} else {
554 554
 			// no active rules, but might still have an active vacation rule
@@ -557,17 +557,17 @@  discard block
 block discarded – undo
557 557
 			{
558 558
 				$newscripthead .= "require [\"vacation\"";
559 559
 				if ($regexsupported && $regexused) $newscripthead .= ",\"regex\"";
560
-				$closeRequired=true;
560
+				$closeRequired = true;
561 561
 			}
562 562
 			if ($this->emailNotification && $this->emailNotification['status'] == 'on')
563 563
 			{
564 564
 				if ($this->vacation && $vacation_active)
565 565
 				{
566
-					$newscripthead .= ",\"".($enotify?'e':'')."notify\"".($variables?',"variables"':'')."];\n\n"; // Added email notifications
566
+					$newscripthead .= ",\"".($enotify ? 'e' : '')."notify\"".($variables ? ',"variables"' : '')."];\n\n"; // Added email notifications
567 567
 				}
568 568
 				else
569 569
 				{
570
-					$newscripthead .= "require [\"".($enotify?'e':'')."notify\"".($variables?',"variables"':'')."];\n\n"; // Added email notifications
570
+					$newscripthead .= "require [\"".($enotify ? 'e' : '')."notify\"".($variables ? ',"variables"' : '')."];\n\n"; // Added email notifications
571 571
 				}
572 572
 			}
573 573
 			if ($closeRequired) $newscripthead .= "];\n\n";
@@ -583,16 +583,16 @@  discard block
 block discarded – undo
583 583
 			if ($rule['status'] != 'DELETED') {
584 584
 				$rule['action_arg'] = addslashes($rule['action_arg']);
585 585
 				// we need to handle \r\n here.
586
-				$rule['action_arg'] = preg_replace("/\r?\n/","\\n",$rule['action_arg']);
586
+				$rule['action_arg'] = preg_replace("/\r?\n/", "\\n", $rule['action_arg']);
587 587
 				/* reset priority value. note: we only do this
588 588
 				* for compatibility with Websieve. */
589 589
 				$rule['priority'] = $pcount;
590
-				$newscriptfoot .= "#rule&&" . $rule['priority'] . "&&" . $rule['status'] . "&&" .
591
-				addslashes($rule['from']) . "&&" . addslashes($rule['to']) . "&&" . addslashes($rule['subject']) . "&&" . $rule['action'] . "&&" .
592
-				$rule['action_arg'] . "&&" . $rule['flg'] . "&&" . addslashes($rule['field']) . "&&" . addslashes($rule['field_val']) . "&&" . $rule['size'];
593
-				if ($supportsbody && (!empty($rule['field_bodytransform']) || ($rule['ctype']!= '0' && !empty($rule['ctype'])))) $newscriptfoot .= "&&" . $rule['bodytransform'] . "&&" . $rule['field_bodytransform']. "&&" . $rule['ctype'] . "&&" . $rule['field_ctype_val'];
590
+				$newscriptfoot .= "#rule&&".$rule['priority']."&&".$rule['status']."&&".
591
+				addslashes($rule['from'])."&&".addslashes($rule['to'])."&&".addslashes($rule['subject'])."&&".$rule['action']."&&".
592
+				$rule['action_arg']."&&".$rule['flg']."&&".addslashes($rule['field'])."&&".addslashes($rule['field_val'])."&&".$rule['size'];
593
+				if ($supportsbody && (!empty($rule['field_bodytransform']) || ($rule['ctype'] != '0' && !empty($rule['ctype'])))) $newscriptfoot .= "&&".$rule['bodytransform']."&&".$rule['field_bodytransform']."&&".$rule['ctype']."&&".$rule['field_ctype_val'];
594 594
 				$newscriptfoot .= "\n";
595
-				$pcount = $pcount+2;
595
+				$pcount = $pcount + 2;
596 596
 				//error_log(__CLASS__."::".__METHOD__.__LINE__.array2string($newscriptfoot));
597 597
 			}
598 598
 		}
@@ -600,36 +600,36 @@  discard block
 block discarded – undo
600 600
 		if ($this->vacation)
601 601
 		{
602 602
 			$vacation = $this->vacation;
603
-			$newscriptfoot .= "#vacation&&" . $vacation['days'] . "&&";
603
+			$newscriptfoot .= "#vacation&&".$vacation['days']."&&";
604 604
 			$first = 1;
605 605
 			foreach ($vacation['addresses'] as $address) {
606 606
 				if (!$first) $newscriptfoot .= ", ";
607
-				$newscriptfoot .= "\"" . trim($address) . "\"";
607
+				$newscriptfoot .= "\"".trim($address)."\"";
608 608
 				$first = 0;
609 609
 			}
610 610
 
611
-			$vacation['text'] = preg_replace("/\r?\n/","\\n",$vacation['text']);
612
-			$newscriptfoot .= "&&" . $vacation['text'] . "&&" .
613
-				($vacation['status']=='by_date' ? $vacation['start_date'].'-'.$vacation['end_date'] : $vacation['status']);
614
-			if ($vacation['forwards']) $newscriptfoot .= '&&' . $vacation['forwards'];
611
+			$vacation['text'] = preg_replace("/\r?\n/", "\\n", $vacation['text']);
612
+			$newscriptfoot .= "&&".$vacation['text']."&&".
613
+				($vacation['status'] == 'by_date' ? $vacation['start_date'].'-'.$vacation['end_date'] : $vacation['status']);
614
+			if ($vacation['forwards']) $newscriptfoot .= '&&'.$vacation['forwards'];
615 615
 			$newscriptfoot .= "\n";
616 616
 		}
617 617
 		if ($this->emailNotification) {
618 618
 			$emailNotification = $this->emailNotification;
619
-			$newscriptfoot .= "#notify&&" . $emailNotification['status'] . "&&" . $emailNotification['externalEmail'] . "&&" . $emailNotification['displaySubject'] . "\n";
619
+			$newscriptfoot .= "#notify&&".$emailNotification['status']."&&".$emailNotification['externalEmail']."&&".$emailNotification['displaySubject']."\n";
620 620
 		}
621 621
 
622 622
 		$newscriptfoot .= "#mode&&basic\n";
623 623
 
624
-		$newscript = $newscripthead . $newscriptbody . $newscriptfoot;
624
+		$newscript = $newscripthead.$newscriptbody.$newscriptfoot;
625 625
 		$this->script = $newscript;
626 626
 		//error_log(__METHOD__.__LINE__.array2string($newscript));
627 627
 		//print "<pre>$newscript</pre>"; exit;
628 628
 		//print "<hr><pre>".htmlentities($newscript)."</pre><hr>";
629 629
 		$ret = $connection->installScript($this->name, $newscript, true);
630 630
 		if (!$ret || self::isError($ret)) {
631
-			$this->errstr = 'updateScript: putscript failed: ' . (self::isError($ret)?$ret->message:$connection->errstr);
632
-			if ($regexused&&!$regexsupported) $this->errstr .= " REGEX is not an supported CAPABILITY";
631
+			$this->errstr = 'updateScript: putscript failed: '.(self::isError($ret) ? $ret->message : $connection->errstr);
632
+			if ($regexused && !$regexsupported) $this->errstr .= " REGEX is not an supported CAPABILITY";
633 633
 			error_log(__METHOD__.__LINE__.' # Error: ->'.$this->errstr);
634 634
 			error_log(__METHOD__.__LINE__.' # ScriptName:'.$this->name.' Script:'.$newscript);
635 635
 			error_log(__METHOD__.__LINE__.' # Instance='.$GLOBALS['egw_info']['user']['domain'].', User='.$GLOBALS['egw_info']['user']['account_lid']);
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 	 */
655 655
 	protected static function isError($data, $code = null)
656 656
 	{
657
-		static $pear=null;
657
+		static $pear = null;
658 658
 		if (!isset($pear)) $pear = new PEAR();
659 659
 
660 660
 		return $pear->isError($data, $code);
Please login to merge, or discard this patch.
Braces   +335 added lines, -111 removed lines patch added patch discarded remove patch
@@ -16,7 +16,8 @@  discard block
 block discarded – undo
16 16
 /**
17 17
  * Support for Sieve scripts
18 18
  */
19
-class emailadmin_script {
19
+class emailadmin_script
20
+{
20 21
 
21 22
 	var $name;         /* filename of script. */
22 23
 	var $script;       /* full ascii text of script from server. */
@@ -52,7 +53,8 @@  discard block
 block discarded – undo
52 53
 	var $debug=false;
53 54
 
54 55
 	// class constructor
55
-	function __construct ($scriptname) {
56
+	function __construct ($scriptname)
57
+	{
56 58
 		$this->name = $scriptname;
57 59
 		$this->script = '';
58 60
 		$this->size = 0;
@@ -72,7 +74,8 @@  discard block
 block discarded – undo
72 74
 	 * @param bosieve $connection
73 75
 	 * @return boolean true, if script written successfull
74 76
 	 */
75
-	function retrieveRules ($connection) {
77
+	function retrieveRules ($connection)
78
+	{
76 79
 		#global $_SESSION;
77 80
 		$continuebit = 1;
78 81
 		$sizebit = 2;
@@ -80,15 +83,23 @@  discard block
 block discarded – undo
80 83
 		$keepbit = 8;
81 84
 		$regexbit = 128;
82 85
 
83
-		if (!isset($this->name)){
86
+		if (!isset($this->name))
87
+		{
84 88
 			$this->errstr = 'retrieveRules: no script name specified';
85
-			if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.": no script name specified");
89
+			if ($this->debug)
90
+			{
91
+				error_log(__CLASS__.'::'.__METHOD__.": no script name specified");
92
+			}
86 93
 			return false;
87 94
 		}
88 95
 
89
-		if (!is_object($connection)) {
96
+		if (!is_object($connection))
97
+		{
90 98
 			$this->errstr = "retrieveRules: no sieve session open";
91
-			if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.": no sieve session open");
99
+			if ($this->debug)
100
+			{
101
+				error_log(__CLASS__.'::'.__METHOD__.": no sieve session open");
102
+			}
92 103
 			return false;
93 104
 		}
94 105
 
@@ -99,8 +110,12 @@  discard block
 block discarded – undo
99 110
 			$this->updateScript($connection);
100 111
 		}
101 112
 
102
-		if(self::isError($script = $connection->getScript($this->name))) {
103
-			if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.": error retrieving script: ".$script->getMessage());
113
+		if(self::isError($script = $connection->getScript($this->name)))
114
+		{
115
+			if ($this->debug)
116
+			{
117
+				error_log(__CLASS__.'::'.__METHOD__.": error retrieving script: ".$script->getMessage());
118
+			}
104 119
 			return $script;
105 120
 		}
106 121
 		#print "<br>AAA: Script is ". htmlentities($script) ."<br>";
@@ -123,10 +138,14 @@  discard block
 block discarded – undo
123 138
 		/* next line should be the recognised encoded head. if not, the script
124 139
 		 * is of an unrecognised format, and we should not overwrite it. */
125 140
 		$line1 = array_shift($lines);
126
-		if (!preg_match("/^# ?Mail(.*)rules for/", $line1)){
141
+		if (!preg_match("/^# ?Mail(.*)rules for/", $line1))
142
+		{
127 143
 				$this->errstr = 'retrieveRules: encoding not recognised';
128 144
 				$this->so = false;
129
-				if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.": encoding not recognised");
145
+				if ($this->debug)
146
+				{
147
+					error_log(__CLASS__.'::'.__METHOD__.": encoding not recognised");
148
+				}
130 149
 				return false;
131 150
 		}
132 151
 		$this->so = true;
@@ -136,9 +155,11 @@  discard block
 block discarded – undo
136 155
 		while (isset($line))
137 156
 		{
138 157
 			$matches = null;
139
-			if (preg_match("/^ *#(#PSEUDO|rule|vacation|mode|notify)/i",$line,$matches)){
158
+			if (preg_match("/^ *#(#PSEUDO|rule|vacation|mode|notify)/i",$line,$matches))
159
+			{
140 160
 				$line = rtrim($line);
141
-				switch ($matches[1]){
161
+				switch ($matches[1])
162
+				{
142 163
 					case "rule":
143 164
 						$bits = explode("&&",  $line);
144 165
 						$rule = array();
@@ -167,19 +188,22 @@  discard block
 block discarded – undo
167 188
 						$rule['field_ctype_val'] = ($bits[15]);
168 189
 						$rule['unconditional']	= 0;
169 190
 						if (!$rule['from'] && !$rule['to'] && !$rule['subject'] &&
170
-							!$rule['field'] && !$rule['size'] && $rule['action']) {
191
+							!$rule['field'] && !$rule['size'] && $rule['action'])
192
+						{
171 193
 							$rule['unconditional'] = 1;
172 194
 						}
173 195
 
174 196
 						array_push($rules,$rule);
175 197
 
176
-						if ($rule['priority'] > $this->pcount) {
198
+						if ($rule['priority'] > $this->pcount)
199
+						{
177 200
 							$this->pcount = $rule['priority'];
178 201
 						}
179 202
 						break;
180 203
 					case "vacation" :
181 204
 						if (preg_match("/^ *#vacation&&(.*)&&(.*)&&(.*)&&(.*)&&(.*)/i",$line,$bits) ||
182
-							preg_match("/^ *#vacation&&(.*)&&(.*)&&(.*)&&(.*)/i",$line,$bits)) {
205
+							preg_match("/^ *#vacation&&(.*)&&(.*)&&(.*)&&(.*)/i",$line,$bits))
206
+						{
183 207
 							$vacation['days'] = $bits[1];
184 208
 							$vaddresslist = preg_replace("/\"|\s/","",$bits[2]);
185 209
 							$vaddresses = preg_split("/,/",$vaddresslist);
@@ -203,20 +227,27 @@  discard block
 block discarded – undo
203 227
 						}
204 228
 						break;
205 229
 					case "notify":
206
-						if (preg_match("/^ *#notify&&(.*)&&(.*)&&(.*)/i",$line,$bits)) {
230
+						if (preg_match("/^ *#notify&&(.*)&&(.*)&&(.*)/i",$line,$bits))
231
+						{
207 232
 							$emailNotification['status'] = $bits[1];
208 233
 							$emailNotification['externalEmail'] = $bits[2];
209 234
 							$emailNotification['displaySubject'] = $bits[3];
210 235
 						}
211 236
 						break;
212 237
 					case "mode" :
213
-						if (preg_match("/^ *#mode&&(.*)/i",$line,$bits)){
238
+						if (preg_match("/^ *#mode&&(.*)/i",$line,$bits))
239
+						{
214 240
 							if ($bits[1] == 'basic')
215
-								$this->mode = 'basic';
241
+							{
242
+															$this->mode = 'basic';
243
+							}
216 244
 							elseif ($bits[1] == 'advanced')
217
-								$this->mode = 'advanced';
218
-							else
219
-								$this->mode = 'unknown';
245
+							{
246
+															$this->mode = 'advanced';
247
+							}
248
+							else {
249
+															$this->mode = 'unknown';
250
+							}
220 251
 						}
221 252
 				}
222 253
 			}
@@ -226,9 +257,15 @@  discard block
 block discarded – undo
226 257
 		$this->script = $script;
227 258
 		$this->rules = $rules;
228 259
 		$this->vacation = $vacation;
229
-		if (!(in_array('vacation',$connection->_capability['extensions'])|| in_array('VACATION', $connection->_capability['extensions']))) $this->vacation = false;
260
+		if (!(in_array('vacation',$connection->_capability['extensions'])|| in_array('VACATION', $connection->_capability['extensions'])))
261
+		{
262
+			$this->vacation = false;
263
+		}
230 264
 		$this->emailNotification = $emailNotification; // Added email notifications
231
-		if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.": Script succesful retrieved: ".print_r($vacation,true));
265
+		if ($this->debug)
266
+		{
267
+			error_log(__CLASS__.'::'.__METHOD__.": Script succesful retrieved: ".print_r($vacation,true));
268
+		}
232 269
 
233 270
 		return true;
234 271
 	}
@@ -272,110 +309,206 @@  discard block
 block discarded – undo
272 309
 		// lets generate the main body of the script from our rules
273 310
 		//error_log(__METHOD__.__LINE__.array2string($connection->_capability));
274 311
 		$enotify = $variables= $supportsbody = false;
275
-		if (in_array('enotify',$connection->_capability['extensions'])|| in_array('ENOTIFY', $connection->_capability['extensions'])) $enotify = true;
276
-		if (in_array('variables',$connection->_capability['extensions'])|| in_array('VARIABLES', $connection->_capability['extensions'])) $variables = true;
277
-		if (in_array('body', $connection->_capability['extensions']) || in_array('BODY', $connection->_capability['extensions'])) $supportsbody = true;
278
-		if (!(in_array('vacation',$connection->_capability['extensions'])|| in_array('VACATION', $connection->_capability['extensions']))) $this->vacation = false;
279
-		if (!(in_array('regex',$connection->_capability['extensions'])|| in_array('REGEX', $connection->_capability['extensions']))) $regexsupported = false;
312
+		if (in_array('enotify',$connection->_capability['extensions'])|| in_array('ENOTIFY', $connection->_capability['extensions']))
313
+		{
314
+			$enotify = true;
315
+		}
316
+		if (in_array('variables',$connection->_capability['extensions'])|| in_array('VARIABLES', $connection->_capability['extensions']))
317
+		{
318
+			$variables = true;
319
+		}
320
+		if (in_array('body', $connection->_capability['extensions']) || in_array('BODY', $connection->_capability['extensions']))
321
+		{
322
+			$supportsbody = true;
323
+		}
324
+		if (!(in_array('vacation',$connection->_capability['extensions'])|| in_array('VACATION', $connection->_capability['extensions'])))
325
+		{
326
+			$this->vacation = false;
327
+		}
328
+		if (!(in_array('regex',$connection->_capability['extensions'])|| in_array('REGEX', $connection->_capability['extensions'])))
329
+		{
330
+			$regexsupported = false;
331
+		}
280 332
 
281 333
 		$newscriptbody = "";
282 334
 		$continue = 1;
283 335
 
284
-		foreach ($this->rules as $rule) {
336
+		foreach ($this->rules as $rule)
337
+		{
285 338
 			$newruletext = "";
286 339
 
287 340
 			// don't print this rule if disabled.
288
-			if ($rule['status'] != 'ENABLED') {
289
-			} else {
341
+			if ($rule['status'] != 'ENABLED')
342
+			{
343
+			}
344
+			else
345
+			{
290 346
 				$activerules = 1;
291 347
 
292 348
 				// conditions
293 349
 
294 350
 				$anyall = "allof";
295
-				if ($rule['anyof']) $anyall = "anyof";
296
-				if ($rule['regexp']) {
351
+				if ($rule['anyof'])
352
+				{
353
+					$anyall = "anyof";
354
+				}
355
+				if ($rule['regexp'])
356
+				{
297 357
 						$regexused = 1;
298 358
 				}
299 359
 				$started = 0;
300 360
 
301
-				if (!$rule['unconditional']) {
302
-						if (!$continue) $newruletext .= "els";
361
+				if (!$rule['unconditional'])
362
+				{
363
+						if (!$continue)
364
+						{
365
+							$newruletext .= "els";
366
+						}
303 367
 						$newruletext .= "if " . $anyall . " (";
304
-						if ($rule['from']) {
305
-								if (preg_match("/^\s*!/", $rule['from'])){
368
+						if ($rule['from'])
369
+						{
370
+								if (preg_match("/^\s*!/", $rule['from']))
371
+								{
306 372
 										$newruletext .= 'not ';
307 373
 										$rule['from'] = preg_replace("/^\s*!/","",$rule['from']);
308 374
 								}
309 375
 								$match = ':contains';
310
-								if (preg_match("/\*|\?/", $rule['from'])) $match = ':matches';
311
-								if ($rule['regexp']) $match = ':regex';
376
+								if (preg_match("/\*|\?/", $rule['from']))
377
+								{
378
+									$match = ':matches';
379
+								}
380
+								if ($rule['regexp'])
381
+								{
382
+									$match = ':regex';
383
+								}
312 384
 								$newruletext .= "address " . $match . " [\"From\"]";
313 385
 								$newruletext .= " \"" . addslashes($rule['from']) . "\"";
314 386
 								$started = 1;
315 387
 						}
316
-						if ($rule['to']) {
317
-								if ($started) $newruletext .= ", ";
318
-								if (preg_match("/^\s*!/", $rule['to'])){
388
+						if ($rule['to'])
389
+						{
390
+								if ($started)
391
+								{
392
+									$newruletext .= ", ";
393
+								}
394
+								if (preg_match("/^\s*!/", $rule['to']))
395
+								{
319 396
 										$newruletext .= 'not ';
320 397
 										$rule['to'] = preg_replace("/^\s*!/","",$rule['to']);
321 398
 								}
322 399
 								$match = ':contains';
323
-								if (preg_match("/\*|\?/", $rule['to'])) $match = ':matches';
324
-								if ($rule['regexp']) $match = ':regex';
400
+								if (preg_match("/\*|\?/", $rule['to']))
401
+								{
402
+									$match = ':matches';
403
+								}
404
+								if ($rule['regexp'])
405
+								{
406
+									$match = ':regex';
407
+								}
325 408
 								$newruletext .= "address " . $match . " [\"To\",\"TO\",\"Cc\",\"CC\"]";
326 409
 								$newruletext .= " \"" . addslashes($rule['to']) . "\"";
327 410
 								$started = 1;
328 411
 						}
329
-						if ($rule['subject']) {
330
-								if ($started) $newruletext .= ", ";
331
-								if (preg_match("/^\s*!/", $rule['subject'])){
412
+						if ($rule['subject'])
413
+						{
414
+								if ($started)
415
+								{
416
+									$newruletext .= ", ";
417
+								}
418
+								if (preg_match("/^\s*!/", $rule['subject']))
419
+								{
332 420
 										$newruletext .= 'not ';
333 421
 										$rule['subject'] = preg_replace("/^\s*!/","",$rule['subject']);
334 422
 								}
335 423
 								$match = ':contains';
336
-								if (preg_match("/\*|\?/", $rule['subject'])) $match = ':matches';
337
-								if ($rule['regexp']) $match = ':regex';
424
+								if (preg_match("/\*|\?/", $rule['subject']))
425
+								{
426
+									$match = ':matches';
427
+								}
428
+								if ($rule['regexp'])
429
+								{
430
+									$match = ':regex';
431
+								}
338 432
 								$newruletext .= "header " . $match . " \"subject\"";
339 433
 								$newruletext .= " \"" . addslashes($rule['subject']) . "\"";
340 434
 								$started = 1;
341 435
 						}
342
-						if ($rule['field'] && $rule['field_val']) {
343
-								if ($started) $newruletext .= ", ";
344
-								if (preg_match("/^\s*!/", $rule['field_val'])){
436
+						if ($rule['field'] && $rule['field_val'])
437
+						{
438
+								if ($started)
439
+								{
440
+									$newruletext .= ", ";
441
+								}
442
+								if (preg_match("/^\s*!/", $rule['field_val']))
443
+								{
345 444
 										$newruletext .= 'not ';
346 445
 										$rule['field_val'] = preg_replace("/^\s*!/","",$rule['field_val']);
347 446
 								}
348 447
 								$match = ':contains';
349
-								if (preg_match("/\*|\?/", $rule['field_val'])) $match = ':matches';
350
-								if ($rule['regexp']) $match = ':regex';
448
+								if (preg_match("/\*|\?/", $rule['field_val']))
449
+								{
450
+									$match = ':matches';
451
+								}
452
+								if ($rule['regexp'])
453
+								{
454
+									$match = ':regex';
455
+								}
351 456
 								$newruletext .= "header " . $match . " \"" . addslashes($rule['field']) . "\"";
352 457
 								$newruletext .= " \"" . addslashes($rule['field_val']) . "\"";
353 458
 								$started = 1;
354 459
 						}
355
-						if ($rule['size']) {
460
+						if ($rule['size'])
461
+						{
356 462
 								$xthan = " :under ";
357
-								if ($rule['gthan']) $xthan = " :over ";
358
-								if ($started) $newruletext .= ", ";
463
+								if ($rule['gthan'])
464
+								{
465
+									$xthan = " :over ";
466
+								}
467
+								if ($started)
468
+								{
469
+									$newruletext .= ", ";
470
+								}
359 471
 								$newruletext .= "size " . $xthan . $rule['size'] . "K";
360 472
 								$started = 1;
361 473
 						}
362
-						if ($supportsbody){
363
-							if (!empty($rule['field_bodytransform'])){
364
-								if ($started) $newruletext .= ", ";
474
+						if ($supportsbody)
475
+						{
476
+							if (!empty($rule['field_bodytransform']))
477
+							{
478
+								if ($started)
479
+								{
480
+									$newruletext .= ", ";
481
+								}
365 482
 								$btransform	= " :raw ";
366 483
 								$match = ' :contains';
367
-								if ($rule['bodytransform'])	$btransform = " :text ";
368
-								if (preg_match("/\*|\?/", $rule['field_bodytransform'])) $match = ':matches';
369
-								if ($rule['regexp']) $match = ':regex';
484
+								if ($rule['bodytransform'])
485
+								{
486
+									$btransform = " :text ";
487
+								}
488
+								if (preg_match("/\*|\?/", $rule['field_bodytransform']))
489
+								{
490
+									$match = ':matches';
491
+								}
492
+								if ($rule['regexp'])
493
+								{
494
+									$match = ':regex';
495
+								}
370 496
 								$newruletext .= "body " . $btransform . $match . " \"" . $rule['field_bodytransform'] . "\"";
371 497
 								$started = 1;
372 498
 
373 499
 							}
374
-							if ($rule['ctype']!= '0' && !empty($rule['ctype'])){
375
-								if ($started) $newruletext .= ", ";
500
+							if ($rule['ctype']!= '0' && !empty($rule['ctype']))
501
+							{
502
+								if ($started)
503
+								{
504
+									$newruletext .= ", ";
505
+								}
376 506
 								$btransform_ctype = emailadmin_script::$btransform_ctype_array[$rule['ctype']];
377 507
 								$ctype_subtype = "";
378
-								if ($rule['field_ctype_val']) $ctype_subtype = "/";
508
+								if ($rule['field_ctype_val'])
509
+								{
510
+									$ctype_subtype = "/";
511
+								}
379 512
 								$newruletext .= "body :content " . " \"" . $btransform_ctype . $ctype_subtype . $rule['field_ctype_val'] . "\"" . " :contains \"\"";
380 513
 								$started = 1;
381 514
 								//error_log(__CLASS__."::".__METHOD__.array2string(emailadmin_script::$btransform_ctype_array));
@@ -385,31 +518,50 @@  discard block
 block discarded – undo
385 518
 
386 519
 				// actions
387 520
 
388
-				if (!$rule['unconditional']) $newruletext .= ") {\n\t";
521
+				if (!$rule['unconditional'])
522
+				{
523
+					$newruletext .= ") {\n\t";
524
+				}
389 525
 
390
-				if (preg_match("/folder/i",$rule['action'])) {
526
+				if (preg_match("/folder/i",$rule['action']))
527
+				{
391 528
 						$newruletext .= "fileinto \"" . ($utf7imap_fileinto ?
392 529
 							translation::convert($rule['action_arg'],'utf-8', 'utf7-imap') : $rule['action_arg']) . "\";";
393 530
 				}
394
-				if (preg_match("/reject/i",$rule['action'])) {
531
+				if (preg_match("/reject/i",$rule['action']))
532
+				{
395 533
 						$newruletext .= "reject text: \n" . $rule['action_arg'] . "\n.\n;";
396 534
 						$rejectused = 1;
397 535
 				}
398
-				if (preg_match("/address/i",$rule['action'])) {
536
+				if (preg_match("/address/i",$rule['action']))
537
+				{
399 538
 						foreach(preg_split('/, ?/',$rule['action_arg']) as $addr)
400 539
 						{
401 540
 							$newruletext .= "\tredirect \"".trim($addr)."\";\n";
402 541
 						}
403 542
 				}
404
-				if (preg_match("/discard/i",$rule['action'])) {
543
+				if (preg_match("/discard/i",$rule['action']))
544
+				{
405 545
 						$newruletext .= "discard;";
406 546
 				}
407
-				if ($rule['keep']) $newruletext .= "\n\tkeep;";
408
-				if (!$rule['unconditional']) $newruletext .= "\n}";
547
+				if ($rule['keep'])
548
+				{
549
+					$newruletext .= "\n\tkeep;";
550
+				}
551
+				if (!$rule['unconditional'])
552
+				{
553
+					$newruletext .= "\n}";
554
+				}
409 555
 
410 556
 				$continue = 0;
411
-				if ($rule['continue']) $continue = 1;
412
-				if ($rule['unconditional']) $continue = 1;
557
+				if ($rule['continue'])
558
+				{
559
+					$continue = 1;
560
+				}
561
+				if ($rule['unconditional'])
562
+				{
563
+					$continue = 1;
564
+				}
413 565
 
414 566
 				$newscriptbody .= $newruletext . "\n\n";
415 567
 
@@ -418,34 +570,53 @@  discard block
 block discarded – undo
418 570
 
419 571
 		// vacation rule
420 572
 
421
-		if ($this->vacation) {
573
+		if ($this->vacation)
574
+		{
422 575
 			$vacation = $this->vacation;
423
-			if (!$vacation['days']) $vacation['days'] = ($default->vacation_days ? $default->vacation_days:'');
424
-			if (!$vacation['text']) $vacation['text'] = ($default->vacation_text ? $default->vacation_text:'');
425
-			if (!$vacation['status']) $vacation['status'] = 'on';
576
+			if (!$vacation['days'])
577
+			{
578
+				$vacation['days'] = ($default->vacation_days ? $default->vacation_days:'');
579
+			}
580
+			if (!$vacation['text'])
581
+			{
582
+				$vacation['text'] = ($default->vacation_text ? $default->vacation_text:'');
583
+			}
584
+			if (!$vacation['status'])
585
+			{
586
+				$vacation['status'] = 'on';
587
+			}
426 588
 
427 589
 			// filter out invalid addresses.
428 590
 			$ok_vaddrs = array();
429
-			foreach($vacation['addresses'] as $addr){
591
+			foreach($vacation['addresses'] as $addr)
592
+			{
430 593
 				if ($addr != '' && preg_match("/\@/",$addr))
431
-				array_push($ok_vaddrs,$addr);
594
+				{
595
+								array_push($ok_vaddrs,$addr);
596
+				}
432 597
 			}
433 598
 			$vacation['addresses'] = $ok_vaddrs;
434 599
 
435
-			if (!$vacation['addresses'][0]){
600
+			if (!$vacation['addresses'][0])
601
+			{
436 602
 				$defaultaddr = $sieve->user . '@' . $sieve->maildomain;
437 603
 				array_push($vacation['addresses'],$defaultaddr);
438 604
 			}
439 605
 			if (($vacation['status'] == 'on' && strlen(trim($vacation['text']))>0)|| $vacation['status'] == 'by_date' &&
440
-				$vacation['start_date'] <= time() && time() < $vacation['end_date']+24*3600)	// +24*3600 to include the end_date day
606
+				$vacation['start_date'] <= time() && time() < $vacation['end_date']+24*3600)
607
+			{
608
+				// +24*3600 to include the end_date day
441 609
 			{
442 610
 				if (trim($vacation['forwards'])) {
443 611
 					$if = array();
444
-					foreach($vacation['addresses'] as $addr) {
612
+			}
613
+					foreach($vacation['addresses'] as $addr)
614
+					{
445 615
 						$if[] = 'address :contains ["To","TO","Cc","CC"] "'.trim($addr).'"';
446 616
 					}
447 617
 					$newscriptbody .= 'if anyof ('.implode(', ',$if).") {\n";
448
-					foreach(preg_split('/, ?/',$vacation['forwards']) as $addr) {
618
+					foreach(preg_split('/, ?/',$vacation['forwards']) as $addr)
619
+					{
449 620
 						$newscriptbody .= "\tredirect \"".trim($addr)."\";\n";
450 621
 					}
451 622
 					$newscriptbody .= "\tkeep;\n}\n";
@@ -468,8 +639,12 @@  discard block
 block discarded – undo
468 639
 				}
469 640
 				$newscriptbody .= "vacation :days " . $vacation['days'] . " :addresses [";
470 641
 				$first = 1;
471
-				foreach ($vacation['addresses'] as $vaddress) {
472
-						if (!$first) $newscriptbody .= ", ";
642
+				foreach ($vacation['addresses'] as $vaddress)
643
+				{
644
+						if (!$first)
645
+						{
646
+							$newscriptbody .= ", ";
647
+						}
473 648
 						$newscriptbody .= "\"" . trim($vaddress) . "\"";
474 649
 						$first = 0;
475 650
 				}
@@ -477,7 +652,10 @@  discard block
 block discarded – undo
477 652
 				if ($vacation['start_date'] || $vacation['end_date'])
478 653
 				{
479 654
 					$format_date = 'd M Y'; // see to it, that there is always a format, because if it is missing - no date will be output
480
-					if (!empty($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'])) $format_date = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'];
655
+					if (!empty($GLOBALS['egw_info']['user']['preferences']['common']['dateformat']))
656
+					{
657
+						$format_date = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'];
658
+					}
481 659
 					$message = str_replace(array('$$start$$','$$end$$'),array(
482 660
 							date($format_date,$vacation['start_date']),
483 661
 							date($format_date,$vacation['end_date']),
@@ -490,7 +668,8 @@  discard block
 block discarded – undo
490 668
 			$this->vacation = $vacation;
491 669
 		}
492 670
 
493
-		if ($this->emailNotification && $this->emailNotification['status'] == 'on') {
671
+		if ($this->emailNotification && $this->emailNotification['status'] == 'on')
672
+		{
494 673
 			// format notification email header components
495 674
 			$notification_email = $this->emailNotification['externalEmail'];
496 675
 
@@ -503,7 +682,8 @@  discard block
 block discarded – undo
503 682
 				{
504 683
 					$notification_body .= ", ";
505 684
 					$notification_body .= 'From: ${from}';
506
-					if ($this->emailNotification['displaySubject']) {
685
+					if ($this->emailNotification['displaySubject'])
686
+					{
507 687
 						$notification_body .= ', Subject: ${subject}';
508 688
 					}
509 689
 					//$notification_body .= 'Size: $size$'."\n";
@@ -522,7 +702,8 @@  discard block
 block discarded – undo
522 702
 				$notification_body = lang("You have received a new message on the")." {$egw_site_title}"."\n";
523 703
 				$notification_body .= "\n";
524 704
 				$notification_body .= 'From: $from$'."\n";
525
-				if ($this->emailNotification['displaySubject']) {
705
+				if ($this->emailNotification['displaySubject'])
706
+				{
526 707
 					$notification_body .= 'Subject: $subject$'."\n";
527 708
 				}
528 709
 				//$notification_body .= 'Size: $size$'."\n";
@@ -540,23 +721,43 @@  discard block
 block discarded – undo
540 721
 		$newscripthead .= '#Generated by ' . $username . ' using Mail ' . $version . ' ' . date($default->script_date_format);
541 722
 		$newscripthead .= "\n";
542 723
 
543
-		if ($activerules) {
724
+		if ($activerules)
725
+		{
544 726
 			$newscripthead .= "require [\"fileinto\"";
545
-			if ($regexsupported && $regexused) $newscripthead .= ",\"regex\"";
546
-			if ($rejectused) $newscripthead .= ",\"reject\"";
547
-			if ($this->vacation && $vacation_active) {
727
+			if ($regexsupported && $regexused)
728
+			{
729
+				$newscripthead .= ",\"regex\"";
730
+			}
731
+			if ($rejectused)
732
+			{
733
+				$newscripthead .= ",\"reject\"";
734
+			}
735
+			if ($this->vacation && $vacation_active)
736
+			{
548 737
 				$newscripthead .= ",\"vacation\"";
549 738
 			}
550
-			if ($supportsbody) $newscripthead .= ",\"body\"";
551
-			if ($this->emailNotification && $this->emailNotification['status'] == 'on') $newscripthead .= ',"'.($enotify?'e':'').'notify"'.($variables?',"variables"':''); // Added email notifications
739
+			if ($supportsbody)
740
+			{
741
+				$newscripthead .= ",\"body\"";
742
+			}
743
+			if ($this->emailNotification && $this->emailNotification['status'] == 'on')
744
+			{
745
+				$newscripthead .= ',"'.($enotify?'e':'').'notify"'.($variables?',"variables"':'');
746
+			}
747
+			// Added email notifications
552 748
 			$newscripthead .= "];\n\n";
553
-		} else {
749
+		}
750
+		else
751
+		{
554 752
 			// no active rules, but might still have an active vacation rule
555 753
 			$closeRequired = false;
556 754
 			if ($this->vacation && $vacation_active)
557 755
 			{
558 756
 				$newscripthead .= "require [\"vacation\"";
559
-				if ($regexsupported && $regexused) $newscripthead .= ",\"regex\"";
757
+				if ($regexsupported && $regexused)
758
+				{
759
+					$newscripthead .= ",\"regex\"";
760
+				}
560 761
 				$closeRequired=true;
561 762
 			}
562 763
 			if ($this->emailNotification && $this->emailNotification['status'] == 'on')
@@ -570,7 +771,10 @@  discard block
 block discarded – undo
570 771
 					$newscripthead .= "require [\"".($enotify?'e':'')."notify\"".($variables?',"variables"':'')."];\n\n"; // Added email notifications
571 772
 				}
572 773
 			}
573
-			if ($closeRequired) $newscripthead .= "];\n\n";
774
+			if ($closeRequired)
775
+			{
776
+				$newscripthead .= "];\n\n";
777
+			}
574 778
 		}
575 779
 
576 780
 		// generate the encoded script foot
@@ -578,9 +782,11 @@  discard block
 block discarded – undo
578 782
 		$newscriptfoot = "";
579 783
 		$pcount = 1;
580 784
 		$newscriptfoot .= "##PSEUDO script start\n";
581
-		foreach ($this->rules as $rule) {
785
+		foreach ($this->rules as $rule)
786
+		{
582 787
 			// only add rule to foot if status != deleted. this is how we delete a rule.
583
-			if ($rule['status'] != 'DELETED') {
788
+			if ($rule['status'] != 'DELETED')
789
+			{
584 790
 				$rule['action_arg'] = addslashes($rule['action_arg']);
585 791
 				// we need to handle \r\n here.
586 792
 				$rule['action_arg'] = preg_replace("/\r?\n/","\\n",$rule['action_arg']);
@@ -590,7 +796,10 @@  discard block
 block discarded – undo
590 796
 				$newscriptfoot .= "#rule&&" . $rule['priority'] . "&&" . $rule['status'] . "&&" .
591 797
 				addslashes($rule['from']) . "&&" . addslashes($rule['to']) . "&&" . addslashes($rule['subject']) . "&&" . $rule['action'] . "&&" .
592 798
 				$rule['action_arg'] . "&&" . $rule['flg'] . "&&" . addslashes($rule['field']) . "&&" . addslashes($rule['field_val']) . "&&" . $rule['size'];
593
-				if ($supportsbody && (!empty($rule['field_bodytransform']) || ($rule['ctype']!= '0' && !empty($rule['ctype'])))) $newscriptfoot .= "&&" . $rule['bodytransform'] . "&&" . $rule['field_bodytransform']. "&&" . $rule['ctype'] . "&&" . $rule['field_ctype_val'];
799
+				if ($supportsbody && (!empty($rule['field_bodytransform']) || ($rule['ctype']!= '0' && !empty($rule['ctype']))))
800
+				{
801
+					$newscriptfoot .= "&&" . $rule['bodytransform'] . "&&" . $rule['field_bodytransform']. "&&" . $rule['ctype'] . "&&" . $rule['field_ctype_val'];
802
+				}
594 803
 				$newscriptfoot .= "\n";
595 804
 				$pcount = $pcount+2;
596 805
 				//error_log(__CLASS__."::".__METHOD__.__LINE__.array2string($newscriptfoot));
@@ -602,8 +811,12 @@  discard block
 block discarded – undo
602 811
 			$vacation = $this->vacation;
603 812
 			$newscriptfoot .= "#vacation&&" . $vacation['days'] . "&&";
604 813
 			$first = 1;
605
-			foreach ($vacation['addresses'] as $address) {
606
-				if (!$first) $newscriptfoot .= ", ";
814
+			foreach ($vacation['addresses'] as $address)
815
+			{
816
+				if (!$first)
817
+				{
818
+					$newscriptfoot .= ", ";
819
+				}
607 820
 				$newscriptfoot .= "\"" . trim($address) . "\"";
608 821
 				$first = 0;
609 822
 			}
@@ -611,10 +824,14 @@  discard block
 block discarded – undo
611 824
 			$vacation['text'] = preg_replace("/\r?\n/","\\n",$vacation['text']);
612 825
 			$newscriptfoot .= "&&" . $vacation['text'] . "&&" .
613 826
 				($vacation['status']=='by_date' ? $vacation['start_date'].'-'.$vacation['end_date'] : $vacation['status']);
614
-			if ($vacation['forwards']) $newscriptfoot .= '&&' . $vacation['forwards'];
827
+			if ($vacation['forwards'])
828
+			{
829
+				$newscriptfoot .= '&&' . $vacation['forwards'];
830
+			}
615 831
 			$newscriptfoot .= "\n";
616 832
 		}
617
-		if ($this->emailNotification) {
833
+		if ($this->emailNotification)
834
+		{
618 835
 			$emailNotification = $this->emailNotification;
619 836
 			$newscriptfoot .= "#notify&&" . $emailNotification['status'] . "&&" . $emailNotification['externalEmail'] . "&&" . $emailNotification['displaySubject'] . "\n";
620 837
 		}
@@ -627,9 +844,13 @@  discard block
 block discarded – undo
627 844
 		//print "<pre>$newscript</pre>"; exit;
628 845
 		//print "<hr><pre>".htmlentities($newscript)."</pre><hr>";
629 846
 		$ret = $connection->installScript($this->name, $newscript, true);
630
-		if (!$ret || self::isError($ret)) {
847
+		if (!$ret || self::isError($ret))
848
+		{
631 849
 			$this->errstr = 'updateScript: putscript failed: ' . (self::isError($ret)?$ret->message:$connection->errstr);
632
-			if ($regexused&&!$regexsupported) $this->errstr .= " REGEX is not an supported CAPABILITY";
850
+			if ($regexused&&!$regexsupported)
851
+			{
852
+				$this->errstr .= " REGEX is not an supported CAPABILITY";
853
+			}
633 854
 			error_log(__METHOD__.__LINE__.' # Error: ->'.$this->errstr);
634 855
 			error_log(__METHOD__.__LINE__.' # ScriptName:'.$this->name.' Script:'.$newscript);
635 856
 			error_log(__METHOD__.__LINE__.' # Instance='.$GLOBALS['egw_info']['user']['domain'].', User='.$GLOBALS['egw_info']['user']['account_lid']);
@@ -655,7 +876,10 @@  discard block
 block discarded – undo
655 876
 	protected static function isError($data, $code = null)
656 877
 	{
657 878
 		static $pear=null;
658
-		if (!isset($pear)) $pear = new PEAR();
879
+		if (!isset($pear))
880
+		{
881
+			$pear = new PEAR();
882
+		}
659 883
 
660 884
 		return $pear->isError($data, $code);
661 885
 	}
Please login to merge, or discard this patch.
emailadmin/inc/class.emailadmin_sieve.inc.php 4 patches
Doc Comments   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 	 *
117 117
 	 * @param emailadmin_imap $_icServer
118 118
 	 * @param string $euser effictive user, if given the Cyrus admin account is used to login on behalf of $euser
119
-	 * @return mixed 'die' = sieve not enabled, false=connect or login failure, true=success
119
+	 * @return string|boolean 'die' = sieve not enabled, false=connect or login failure, true=success
120 120
 	 */
121 121
 	function _connect(emailadmin_imap $_icServer, $euser='')
122 122
 	{
@@ -314,6 +314,7 @@  discard block
 block discarded – undo
314 314
 	*
315 315
 	* @param string if !=null,check this one first if reported as serverMethod.
316 316
 	*                  if so, return as bestauthmethod
317
+	* @param string $userMethod
317 318
 	* @return mixed    Returns a string containing the name of the best
318 319
 	*                  supported authentication method or a PEAR_Error object
319 320
 	*                  if a failure condition is encountered.
@@ -606,7 +607,7 @@  discard block
 block discarded – undo
606 607
 	 *
607 608
 	 * @param array $_emailNotification
608 609
 	 * @param string $_scriptName
609
-	 * @return emailadmin_script
610
+	 * @return boolean
610 611
 	 */
611 612
 	function setEmailNotification(array $_emailNotification, $_scriptName=null)
612 613
 	{
Please login to merge, or discard this patch.
Indentation   +252 added lines, -252 removed lines patch added patch discarded remove patch
@@ -37,28 +37,28 @@  discard block
 block discarded – undo
37 37
 	var $icServer;
38 38
 
39 39
 	/**
40
-	* @var string name of active script queried from Sieve server
41
-	*/
40
+	 * @var string name of active script queried from Sieve server
41
+	 */
42 42
 	var $scriptName;
43 43
 
44 44
 	/**
45
-	* @var $rules containing the rules
46
-	*/
45
+	 * @var $rules containing the rules
46
+	 */
47 47
 	var $rules;
48 48
 
49 49
 	/**
50
-	* @var $vacation containing the vacation
51
-	*/
50
+	 * @var $vacation containing the vacation
51
+	 */
52 52
 	var $vacation;
53 53
 
54 54
 	/**
55
-	* @var $emailNotification containing the emailNotification
56
-	*/
55
+	 * @var $emailNotification containing the emailNotification
56
+	 */
57 57
 	var $emailNotification;
58 58
 
59 59
 	/**
60
-	* @var object $error the last PEAR error object
61
-	*/
60
+	 * @var object $error the last PEAR error object
61
+	 */
62 62
 	var $error;
63 63
 
64 64
 	/**
@@ -245,79 +245,79 @@  discard block
 block discarded – undo
245 245
 		return true;
246 246
 	}
247 247
 
248
-    /**
249
-     * Handles connecting to the server and checks the response validity.
250
-     * overwritten function from Net_Sieve to respect timeout
251
-     *
252
-     * @param string  $host    Hostname of server.
253
-     * @param string  $port    Port of server.
254
-     * @param array   $options List of options to pass to
255
-     *                         stream_context_create().
256
-     * @param boolean $useTLS  Use TLS if available.
257
-     *
258
-     * @return boolean  True on success, PEAR_Error otherwise.
259
-     */
260
-    function connect($host, $port, $options = null, $useTLS = true)
261
-    {
262
-        if ($this->debug)
248
+	/**
249
+	 * Handles connecting to the server and checks the response validity.
250
+	 * overwritten function from Net_Sieve to respect timeout
251
+	 *
252
+	 * @param string  $host    Hostname of server.
253
+	 * @param string  $port    Port of server.
254
+	 * @param array   $options List of options to pass to
255
+	 *                         stream_context_create().
256
+	 * @param boolean $useTLS  Use TLS if available.
257
+	 *
258
+	 * @return boolean  True on success, PEAR_Error otherwise.
259
+	 */
260
+	function connect($host, $port, $options = null, $useTLS = true)
261
+	{
262
+		if ($this->debug)
263 263
 		{
264 264
 			error_log(__METHOD__ . __LINE__ . "$host, $port, " . array2string($options) . ", $useTLS");
265 265
 		}
266 266
 		$this->_data['host'] = $host;
267
-        $this->_data['port'] = $port;
268
-        $this->_useTLS       = $useTLS;
269
-        if (is_array($options)) {
270
-            $this->_options = array_merge((array)$this->_options, $options);
271
-        }
267
+		$this->_data['port'] = $port;
268
+		$this->_useTLS       = $useTLS;
269
+		if (is_array($options)) {
270
+			$this->_options = array_merge((array)$this->_options, $options);
271
+		}
272 272
 
273
-        if (NET_SIEVE_STATE_DISCONNECTED != $this->_state) {
274
-            return PEAR::raiseError('Not currently in DISCONNECTED state', 1);
275
-        }
273
+		if (NET_SIEVE_STATE_DISCONNECTED != $this->_state) {
274
+			return PEAR::raiseError('Not currently in DISCONNECTED state', 1);
275
+		}
276 276
 
277 277
 		if (self::isError($res = $this->_sock->connect($host, $port, false, ($this->_timeout?$this->_timeout:10), $options))) {
278
-            return $res;
279
-        }
280
-
281
-        if ($this->_bypassAuth) {
282
-            $this->_state = NET_SIEVE_STATE_TRANSACTION;
283
-        } else {
284
-            $this->_state = NET_SIEVE_STATE_AUTHORISATION;
285
-            if (self::isError($res = $this->_doCmd())) {
286
-                return $res;
287
-            }
288
-        }
289
-
290
-        // Explicitly ask for the capabilities in case the connection is
291
-        // picked up from an existing connection.
292
-        if (self::isError($res = $this->_cmdCapability())) {
293
-            return PEAR::raiseError(
294
-                'Failed to connect, server said: ' . $res->getMessage(), 2
295
-            );
296
-        }
297
-
298
-        // Check if we can enable TLS via STARTTLS.
299
-        if ($useTLS && !empty($this->_capability['starttls'])
300
-            && function_exists('stream_socket_enable_crypto')
301
-        ) {
302
-            if (self::isError($res = $this->_startTLS())) {
303
-                return $res;
304
-            }
305
-        }
306
-
307
-        return true;
308
-    }
278
+			return $res;
279
+		}
280
+
281
+		if ($this->_bypassAuth) {
282
+			$this->_state = NET_SIEVE_STATE_TRANSACTION;
283
+		} else {
284
+			$this->_state = NET_SIEVE_STATE_AUTHORISATION;
285
+			if (self::isError($res = $this->_doCmd())) {
286
+				return $res;
287
+			}
288
+		}
289
+
290
+		// Explicitly ask for the capabilities in case the connection is
291
+		// picked up from an existing connection.
292
+		if (self::isError($res = $this->_cmdCapability())) {
293
+			return PEAR::raiseError(
294
+				'Failed to connect, server said: ' . $res->getMessage(), 2
295
+			);
296
+		}
297
+
298
+		// Check if we can enable TLS via STARTTLS.
299
+		if ($useTLS && !empty($this->_capability['starttls'])
300
+			&& function_exists('stream_socket_enable_crypto')
301
+		) {
302
+			if (self::isError($res = $this->_startTLS())) {
303
+				return $res;
304
+			}
305
+		}
306
+
307
+		return true;
308
+	}
309 309
 
310 310
 	/**
311
-	* Own _getBestAuthMethod as Net/Sieve.php assumes SASLMethods to be working
312
-	* Returns the name of the best authentication method that the server
313
-	* has advertised.
314
-	*
315
-	* @param string if !=null,check this one first if reported as serverMethod.
316
-	*                  if so, return as bestauthmethod
317
-	* @return mixed    Returns a string containing the name of the best
318
-	*                  supported authentication method or a PEAR_Error object
319
-	*                  if a failure condition is encountered.
320
-	*/
311
+	 * Own _getBestAuthMethod as Net/Sieve.php assumes SASLMethods to be working
312
+	 * Returns the name of the best authentication method that the server
313
+	 * has advertised.
314
+	 *
315
+	 * @param string if !=null,check this one first if reported as serverMethod.
316
+	 *                  if so, return as bestauthmethod
317
+	 * @return mixed    Returns a string containing the name of the best
318
+	 *                  supported authentication method or a PEAR_Error object
319
+	 *                  if a failure condition is encountered.
320
+	 */
321 321
 	function _getBestAuthMethod($userMethod = null)
322 322
 	{
323 323
 		//error_log(__METHOD__.__LINE__.'->'.$userMethod.'<->'.array2string($this->_capability['sasl']));
@@ -352,196 +352,196 @@  discard block
 block discarded – undo
352 352
 		}
353 353
 	}
354 354
 
355
-    /**
356
-     * Handles the authentication using any known method
357
-     * overwritten function from Net_Sieve to support fallback
358
-     *
359
-     * @param string $uid The userid to authenticate as.
360
-     * @param string $pwd The password to authenticate with.
361
-     * @param string $userMethod The method to use ( if $userMethod == '' then the class chooses the best method (the stronger is the best ) )
362
-     * @param string $euser The effective uid to authenticate as.
363
-     *
364
-     * @return mixed  string or PEAR_Error
365
-     *
366
-     * @access private
367
-     * @since  1.0
368
-     */
369
-    function _cmdAuthenticate($uid , $pwd , $userMethod = null , $euser = '' )
370
-    {
371
-        if ( self::isError( $method = $this->_getBestAuthMethod($userMethod) ) ) {
372
-            return $method;
373
-        }
374
-        //error_log(__METHOD__.__LINE__.' using AuthMethod: '.$method);
375
-        switch ($method) {
376
-            case 'DIGEST-MD5':
377
-                $result = $this->_authDigestMD5( $uid , $pwd , $euser );
378
-                if (!self::isError($result))
355
+	/**
356
+	 * Handles the authentication using any known method
357
+	 * overwritten function from Net_Sieve to support fallback
358
+	 *
359
+	 * @param string $uid The userid to authenticate as.
360
+	 * @param string $pwd The password to authenticate with.
361
+	 * @param string $userMethod The method to use ( if $userMethod == '' then the class chooses the best method (the stronger is the best ) )
362
+	 * @param string $euser The effective uid to authenticate as.
363
+	 *
364
+	 * @return mixed  string or PEAR_Error
365
+	 *
366
+	 * @access private
367
+	 * @since  1.0
368
+	 */
369
+	function _cmdAuthenticate($uid , $pwd , $userMethod = null , $euser = '' )
370
+	{
371
+		if ( self::isError( $method = $this->_getBestAuthMethod($userMethod) ) ) {
372
+			return $method;
373
+		}
374
+		//error_log(__METHOD__.__LINE__.' using AuthMethod: '.$method);
375
+		switch ($method) {
376
+			case 'DIGEST-MD5':
377
+				$result = $this->_authDigestMD5( $uid , $pwd , $euser );
378
+				if (!self::isError($result))
379 379
 				{
380 380
 					break;
381 381
 				}
382 382
 				$res = $this->_doCmd();
383
-                unset($this->_error);
384
-                $this->supportedAuthMethods = array_diff($this->supportedAuthMethods,array($method,'CRAM-MD5'));
385
-                return $this->_cmdAuthenticate($uid , $pwd, null, $euser);
386
-            case 'CRAM-MD5':
387
-                $result = $this->_authCRAMMD5( $uid , $pwd, $euser);
388
-                if (!self::isError($result))
383
+				unset($this->_error);
384
+				$this->supportedAuthMethods = array_diff($this->supportedAuthMethods,array($method,'CRAM-MD5'));
385
+				return $this->_cmdAuthenticate($uid , $pwd, null, $euser);
386
+			case 'CRAM-MD5':
387
+				$result = $this->_authCRAMMD5( $uid , $pwd, $euser);
388
+				if (!self::isError($result))
389 389
 				{
390 390
 					break;
391 391
 				}
392 392
 				$res = $this->_doCmd();
393
-                unset($this->_error);
394
-                $this->supportedAuthMethods = array_diff($this->supportedAuthMethods,array($method,'DIGEST-MD5'));
395
-                return $this->_cmdAuthenticate($uid , $pwd, null, $euser);
396
-            case 'LOGIN':
397
-                $result = $this->_authLOGIN( $uid , $pwd , $euser );
398
-                if (!self::isError($result))
393
+				unset($this->_error);
394
+				$this->supportedAuthMethods = array_diff($this->supportedAuthMethods,array($method,'DIGEST-MD5'));
395
+				return $this->_cmdAuthenticate($uid , $pwd, null, $euser);
396
+			case 'LOGIN':
397
+				$result = $this->_authLOGIN( $uid , $pwd , $euser );
398
+				if (!self::isError($result))
399 399
 				{
400 400
 					break;
401 401
 				}
402 402
 				$res = $this->_doCmd();
403
-                unset($this->_error);
404
-                $this->supportedAuthMethods = array_diff($this->supportedAuthMethods,array($method));
405
-                return $this->_cmdAuthenticate($uid , $pwd, null, $euser);
406
-            case 'PLAIN':
407
-                $result = $this->_authPLAIN( $uid , $pwd , $euser );
408
-                break;
409
-            default :
410
-                $result = new PEAR_Error( "$method is not a supported authentication method" );
411
-                break;
412
-        }
413
-        if (self::isError($result))
403
+				unset($this->_error);
404
+				$this->supportedAuthMethods = array_diff($this->supportedAuthMethods,array($method));
405
+				return $this->_cmdAuthenticate($uid , $pwd, null, $euser);
406
+			case 'PLAIN':
407
+				$result = $this->_authPLAIN( $uid , $pwd , $euser );
408
+				break;
409
+			default :
410
+				$result = new PEAR_Error( "$method is not a supported authentication method" );
411
+				break;
412
+		}
413
+		if (self::isError($result))
414 414
 		{
415 415
 			return $result;
416 416
 		}
417 417
 		if (self::isError($res = $this->_doCmd())) {
418
-            return $res;
419
-        }
420
-
421
-        // Query the server capabilities again now that we are authenticated.
422
-        if (self::isError($res = $this->_cmdCapability())) {
423
-            return PEAR::raiseError(
424
-                'Failed to connect, server said: ' . $res->getMessage(), 2
425
-            );
426
-        }
427
-
428
-        return $result;
429
-    }
430
-
431
-    /**
432
-     * Send a command and retrieves a response from the server.
433
-     *
434
-     * @param string $cmd   The command to send.
435
-     * @param boolean $auth Whether this is an authentication command.
436
-     *
437
-     * @return string|PEAR_Error  Reponse string if an OK response, PEAR_Error
438
-     *                            if a NO response.
439
-     */
440
-    function _doCmd($cmd = '', $auth = false)
441
-    {
442
-        $referralCount = 0;
443
-        while ($referralCount < $this->_maxReferralCount) {
444
-            if (strlen($cmd)) {
445
-                $error = $this->_sendCmd($cmd);
446
-                if (is_a($error, 'PEAR_Error')) {
447
-                    return $error;
448
-                }
449
-            }
450
-
451
-            $response = '';
452
-            while (true) {
453
-                $line = $this->_recvLn();
454
-
455
-                if (is_a($line, 'PEAR_Error')) {
456
-                    return $line;
457
-                }
458
-
459
-                if (preg_match('/^(OK|NO)/i', $line, $tag)) {
460
-                    // Check for string literal message.
461
-                    // ServerResponse may send {nm} (nm representing a number)
462
-                    // dbmail (in some versions) sends: {nm+} thus breaking RFC5804 rules (Section 4 Formal Syntax)
463
-                    // {nm+} may only be used in communicating from client TO server; (not Server to Client)
464
-                    // we work around this bug (allowing +) using a patch introduced with roundcube 2 years ago.
465
-                    //if (preg_match('/{([0-9]+)}$/', $line, $matches)) { //original
466
-                    if (preg_match('/{([0-9]+)\+?}$/', $line, $matches)) { //patched to cope with dbmail
467
-                        $line = substr($line, 0, -(strlen($matches[1]) + 2))
468
-                            . str_replace(
469
-                                "\r\n", ' ', $this->_recvBytes($matches[1] + 2)
470
-                            );
471
-                    }
472
-
473
-                    if ('OK' == $this->_toUpper($tag[1])) {
474
-                        $response .= $line;
475
-                        return rtrim($response);
476
-                    }
477
-
478
-                    return $this->_pear->raiseError(trim($response . substr($line, 2)), 3);
479
-                }
480
-
481
-                if (preg_match('/^BYE/i', $line)) {
482
-                    $error = $this->disconnect(false);
483
-                    if (is_a($error, 'PEAR_Error')) {
484
-                        return $this->_pear->raiseError(
485
-                            'Cannot handle BYE, the error was: '
486
-                            . $error->getMessage(),
487
-                            4
488
-                        );
489
-                    }
490
-                    // Check for referral, then follow it.  Otherwise, carp an
491
-                    // error.
492
-                    if (preg_match('/^bye \(referral "(sieve:\/\/)?([^"]+)/i', $line, $matches)) {
493
-                        // Replace the old host with the referral host
494
-                        // preserving any protocol prefix.
495
-                        $this->_data['host'] = preg_replace(
496
-                            '/\w+(?!(\w|\:\/\/)).*/', $matches[2],
497
-                            $this->_data['host']
498
-                        );
499
-                        $error = $this->_handleConnectAndLogin();
500
-                        if (is_a($error, 'PEAR_Error')) {
501
-                            return $this->_pear->raiseError(
502
-                                'Cannot follow referral to '
503
-                                . $this->_data['host'] . ', the error was: '
504
-                                . $error->getMessage(),
505
-                                5
506
-                            );
507
-                        }
508
-                        break;
509
-                    }
510
-                    return $this->_pear->raiseError(trim($response . $line), 6);
511
-                }
512
-
513
-                // ServerResponse may send {nm} (nm representing a number)
514
-                // dbmail (in some versions) sends: {nm+} thus breaking RFC5804 rules (Section 4 Formal Syntax)
515
-                // {nm+} may only be used in communicating from client TO server; (not Server to Client)
516
-                // we work around this bug (allowing +) using a patch introduced with roundcube 2 years ago.
517
-                // although roundcube suggested only the change in line
518
-                //if (preg_match('/^{([0-9]+)}/', $line, $matches)) { //original
519
-                if (preg_match('/^{([0-9]+)\+?}/', $line, $matches)) { //patched to cope with dbmail
520
-                    // Matches literal string responses.
521
-                    $line = $this->_recvBytes($matches[1] + 2);
522
-                    if (!$auth) {
523
-                        // Receive the pending OK only if we aren't
524
-                        // authenticating since string responses during
525
-                        // authentication don't need an OK.
526
-                        $this->_recvLn();
527
-                    }
528
-                    return $line;
529
-                }
530
-
531
-                if ($auth) {
532
-                    // String responses during authentication don't need an
533
-                    // OK.
534
-                    $response .= $line;
535
-                    return rtrim($response);
536
-                }
537
-
538
-                $response .= $line . "\r\n";
539
-                $referralCount++;
540
-            }
541
-        }
542
-
543
-        return $this->_pear->raiseError('Max referral count (' . $referralCount . ') reached. Cyrus murder loop error?', 7);
544
-    }
418
+			return $res;
419
+		}
420
+
421
+		// Query the server capabilities again now that we are authenticated.
422
+		if (self::isError($res = $this->_cmdCapability())) {
423
+			return PEAR::raiseError(
424
+				'Failed to connect, server said: ' . $res->getMessage(), 2
425
+			);
426
+		}
427
+
428
+		return $result;
429
+	}
430
+
431
+	/**
432
+	 * Send a command and retrieves a response from the server.
433
+	 *
434
+	 * @param string $cmd   The command to send.
435
+	 * @param boolean $auth Whether this is an authentication command.
436
+	 *
437
+	 * @return string|PEAR_Error  Reponse string if an OK response, PEAR_Error
438
+	 *                            if a NO response.
439
+	 */
440
+	function _doCmd($cmd = '', $auth = false)
441
+	{
442
+		$referralCount = 0;
443
+		while ($referralCount < $this->_maxReferralCount) {
444
+			if (strlen($cmd)) {
445
+				$error = $this->_sendCmd($cmd);
446
+				if (is_a($error, 'PEAR_Error')) {
447
+					return $error;
448
+				}
449
+			}
450
+
451
+			$response = '';
452
+			while (true) {
453
+				$line = $this->_recvLn();
454
+
455
+				if (is_a($line, 'PEAR_Error')) {
456
+					return $line;
457
+				}
458
+
459
+				if (preg_match('/^(OK|NO)/i', $line, $tag)) {
460
+					// Check for string literal message.
461
+					// ServerResponse may send {nm} (nm representing a number)
462
+					// dbmail (in some versions) sends: {nm+} thus breaking RFC5804 rules (Section 4 Formal Syntax)
463
+					// {nm+} may only be used in communicating from client TO server; (not Server to Client)
464
+					// we work around this bug (allowing +) using a patch introduced with roundcube 2 years ago.
465
+					//if (preg_match('/{([0-9]+)}$/', $line, $matches)) { //original
466
+					if (preg_match('/{([0-9]+)\+?}$/', $line, $matches)) { //patched to cope with dbmail
467
+						$line = substr($line, 0, -(strlen($matches[1]) + 2))
468
+							. str_replace(
469
+								"\r\n", ' ', $this->_recvBytes($matches[1] + 2)
470
+							);
471
+					}
472
+
473
+					if ('OK' == $this->_toUpper($tag[1])) {
474
+						$response .= $line;
475
+						return rtrim($response);
476
+					}
477
+
478
+					return $this->_pear->raiseError(trim($response . substr($line, 2)), 3);
479
+				}
480
+
481
+				if (preg_match('/^BYE/i', $line)) {
482
+					$error = $this->disconnect(false);
483
+					if (is_a($error, 'PEAR_Error')) {
484
+						return $this->_pear->raiseError(
485
+							'Cannot handle BYE, the error was: '
486
+							. $error->getMessage(),
487
+							4
488
+						);
489
+					}
490
+					// Check for referral, then follow it.  Otherwise, carp an
491
+					// error.
492
+					if (preg_match('/^bye \(referral "(sieve:\/\/)?([^"]+)/i', $line, $matches)) {
493
+						// Replace the old host with the referral host
494
+						// preserving any protocol prefix.
495
+						$this->_data['host'] = preg_replace(
496
+							'/\w+(?!(\w|\:\/\/)).*/', $matches[2],
497
+							$this->_data['host']
498
+						);
499
+						$error = $this->_handleConnectAndLogin();
500
+						if (is_a($error, 'PEAR_Error')) {
501
+							return $this->_pear->raiseError(
502
+								'Cannot follow referral to '
503
+								. $this->_data['host'] . ', the error was: '
504
+								. $error->getMessage(),
505
+								5
506
+							);
507
+						}
508
+						break;
509
+					}
510
+					return $this->_pear->raiseError(trim($response . $line), 6);
511
+				}
512
+
513
+				// ServerResponse may send {nm} (nm representing a number)
514
+				// dbmail (in some versions) sends: {nm+} thus breaking RFC5804 rules (Section 4 Formal Syntax)
515
+				// {nm+} may only be used in communicating from client TO server; (not Server to Client)
516
+				// we work around this bug (allowing +) using a patch introduced with roundcube 2 years ago.
517
+				// although roundcube suggested only the change in line
518
+				//if (preg_match('/^{([0-9]+)}/', $line, $matches)) { //original
519
+				if (preg_match('/^{([0-9]+)\+?}/', $line, $matches)) { //patched to cope with dbmail
520
+					// Matches literal string responses.
521
+					$line = $this->_recvBytes($matches[1] + 2);
522
+					if (!$auth) {
523
+						// Receive the pending OK only if we aren't
524
+						// authenticating since string responses during
525
+						// authentication don't need an OK.
526
+						$this->_recvLn();
527
+					}
528
+					return $line;
529
+				}
530
+
531
+				if ($auth) {
532
+					// String responses during authentication don't need an
533
+					// OK.
534
+					$response .= $line;
535
+					return rtrim($response);
536
+				}
537
+
538
+				$response .= $line . "\r\n";
539
+				$referralCount++;
540
+			}
541
+		}
542
+
543
+		return $this->_pear->raiseError('Max referral count (' . $referralCount . ') reached. Cyrus murder loop error?', 7);
544
+	}
545 545
 
546 546
 	function getRules()
547 547
 	{
@@ -611,11 +611,11 @@  discard block
 block discarded – undo
611 611
 	function setEmailNotification(array $_emailNotification, $_scriptName=null)
612 612
 	{
613 613
 		if ($_emailNotification['externalEmail'] == '' || !preg_match("/\@/",$_emailNotification['externalEmail'])) {
614
-    		$_emailNotification['status'] = 'off';
615
-    		$_emailNotification['externalEmail'] = '';
616
-    	}
614
+			$_emailNotification['status'] = 'off';
615
+			$_emailNotification['externalEmail'] = '';
616
+		}
617 617
 
618
-    	$script = $this->retrieveRules($_scriptName);
618
+		$script = $this->retrieveRules($_scriptName);
619 619
    		$script->emailNotification = $_emailNotification;
620 620
 		$ret = $script->updateScript($this);
621 621
 		$this->error = $script->errstr;
Please login to merge, or discard this patch.
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 	 * @param string $_euser effictive user, if given the Cyrus admin account is used to login on behalf of $euser
87 87
 	 * @param string $_scriptName
88 88
 	 */
89
-	function __construct(emailadmin_imap $_icServer=null, $_euser='', $_scriptName=null)
89
+	function __construct(emailadmin_imap $_icServer = null, $_euser = '', $_scriptName = null)
90 90
 	{
91 91
 		parent::Net_Sieve();
92 92
 
@@ -95,16 +95,16 @@  discard block
 block discarded – undo
95 95
 		// TODO: since we seem to have major problems authenticating via DIGEST-MD5 and CRAM-MD5 in SIEVE, we skip MD5-METHODS for now
96 96
 		if (!is_null($_icServer))
97 97
 		{
98
-			$_icServer->supportedAuthMethods = array('PLAIN' , 'LOGIN');
99
-			$_icServer->supportedSASLAuthMethods=array();
98
+			$_icServer->supportedAuthMethods = array('PLAIN', 'LOGIN');
99
+			$_icServer->supportedSASLAuthMethods = array();
100 100
 		}
101 101
 		else
102 102
 		{
103
-			$this->supportedAuthMethods = array('PLAIN' , 'LOGIN');
104
-			$this->supportedSASLAuthMethods=array();
103
+			$this->supportedAuthMethods = array('PLAIN', 'LOGIN');
104
+			$this->supportedSASLAuthMethods = array();
105 105
 		}
106 106
 
107
-		$this->displayCharset	= translation::charset();
107
+		$this->displayCharset = translation::charset();
108 108
 
109 109
 		if (!is_null($_icServer) && $this->_connect($_icServer, $_euser) === 'die') {
110 110
 			die('Sieve not activated');
@@ -118,16 +118,16 @@  discard block
 block discarded – undo
118 118
 	 * @param string $euser effictive user, if given the Cyrus admin account is used to login on behalf of $euser
119 119
 	 * @return mixed 'die' = sieve not enabled, false=connect or login failure, true=success
120 120
 	 */
121
-	function _connect(emailadmin_imap $_icServer, $euser='')
121
+	function _connect(emailadmin_imap $_icServer, $euser = '')
122 122
 	{
123 123
 		static $isConError = null;
124 124
 		static $sieveAuthMethods = null;
125 125
 		$_icServerID = $_icServer->acc_id;
126 126
 		if (is_null($isConError))
127 127
 		{
128
-			$isConError =  egw_cache::getCache(egw_cache::INSTANCE, 'email', 'icServerSIEVE_connectionError' . trim($GLOBALS['egw_info']['user']['account_id']));
128
+			$isConError = egw_cache::getCache(egw_cache::INSTANCE, 'email', 'icServerSIEVE_connectionError'.trim($GLOBALS['egw_info']['user']['account_id']));
129 129
 		}
130
-		if ( isset($isConError[$_icServerID]) )
130
+		if (isset($isConError[$_icServerID]))
131 131
 		{
132 132
 			$this->error = new PEAR_Error($isConError[$_icServerID]);
133 133
 			return false;
@@ -135,9 +135,9 @@  discard block
 block discarded – undo
135 135
 
136 136
 		if ($this->debug)
137 137
 		{
138
-			error_log(__METHOD__ . array2string($euser));
138
+			error_log(__METHOD__.array2string($euser));
139 139
 		}
140
-		if($_icServer->acc_sieve_enabled)
140
+		if ($_icServer->acc_sieve_enabled)
141 141
 		{
142 142
 			if ($_icServer->acc_sieve_host)
143 143
 			{
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 
153 153
 			$useTLS = false;
154 154
 
155
-			switch($_icServer->acc_sieve_ssl & ~emailadmin_account::SSL_VERIFY)
155
+			switch ($_icServer->acc_sieve_ssl&~emailadmin_account::SSL_VERIFY)
156 156
 			{
157 157
 				case emailadmin_account::SSL_SSL:
158 158
 					$sieveHost = 'ssl://'.$sieveHost;
@@ -166,8 +166,8 @@  discard block
 block discarded – undo
166 166
 			// disable certificate validation, if not explicitly enabled (not possible in current UI, as not supported by Horde_Imap_Client)
167 167
 			$options = array(
168 168
 				'ssl' => array(
169
-					'verify_peer' => (bool)($_icServer->acc_sieve_ssl & emailadmin_account::SSL_VERIFY),
170
-					'verify_peer_name' => (bool)($_icServer->acc_sieve_ssl & emailadmin_account::SSL_VERIFY),
169
+					'verify_peer' => (bool)($_icServer->acc_sieve_ssl&emailadmin_account::SSL_VERIFY),
170
+					'verify_peer_name' => (bool)($_icServer->acc_sieve_ssl&emailadmin_account::SSL_VERIFY),
171 171
 				),
172 172
 			);
173 173
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 		}
186 186
 		else
187 187
 		{
188
-			egw_cache::setCache(egw_cache::INSTANCE,'email','icServerSIEVE_connectionError'.trim($GLOBALS['egw_info']['user']['account_id']),$isConError,$expiration=60*15);
188
+			egw_cache::setCache(egw_cache::INSTANCE, 'email', 'icServerSIEVE_connectionError'.trim($GLOBALS['egw_info']['user']['account_id']), $isConError, $expiration = 60 * 15);
189 189
 			return 'die';
190 190
 		}
191 191
 		$this->_timeout = 10; // socket::connect sets the/this timeout on connection
@@ -195,14 +195,14 @@  discard block
 block discarded – undo
195 195
 			$this->_timeout = $timeout;
196 196
 		}
197 197
 
198
-		if(self::isError($this->error = $this->connect($sieveHost , $sievePort, $options, $useTLS) ) )
198
+		if (self::isError($this->error = $this->connect($sieveHost, $sievePort, $options, $useTLS)))
199 199
 		{
200 200
 			if ($this->debug)
201 201
 			{
202
-				error_log(__METHOD__ . ": error in connect($sieveHost,$sievePort, " . array2string($options) . ", $useTLS): " . $this->error->getMessage());
202
+				error_log(__METHOD__.": error in connect($sieveHost,$sievePort, ".array2string($options).", $useTLS): ".$this->error->getMessage());
203 203
 			}
204 204
 			$isConError[$_icServerID] = $this->error->getMessage();
205
-			egw_cache::setCache(egw_cache::INSTANCE,'email','icServerSIEVE_connectionError'.trim($GLOBALS['egw_info']['user']['account_id']),$isConError,$expiration=60*15);
205
+			egw_cache::setCache(egw_cache::INSTANCE, 'email', 'icServerSIEVE_connectionError'.trim($GLOBALS['egw_info']['user']['account_id']), $isConError, $expiration = 60 * 15);
206 206
 			return false;
207 207
 		}
208 208
 		// we cache the supported AuthMethods during session, to be able to speed up login.
@@ -215,14 +215,14 @@  discard block
 block discarded – undo
215 215
 			$this->supportedAuthMethods = $sieveAuthMethods[$_icServerID];
216 216
 		}
217 217
 		// pear net_sieve _authLOGIN does not support euser. so use plain, when trying to act on behalf of another user (effective user = euser)
218
-		if(self::isError($this->error = $this->login($username, $password, ($euser?'PLAIN':'LOGIN'), $euser) ) )
218
+		if (self::isError($this->error = $this->login($username, $password, ($euser ? 'PLAIN' : 'LOGIN'), $euser)))
219 219
 		{
220 220
 			if ($this->debug)
221 221
 			{
222
-				error_log(__METHOD__ . ": error in login($username,$password,null,$euser): " . $this->error->getMessage());
222
+				error_log(__METHOD__.": error in login($username,$password,null,$euser): ".$this->error->getMessage());
223 223
 			}
224 224
 			$isConError[$_icServerID] = $this->error->getMessage();
225
-			egw_cache::setCache(egw_cache::INSTANCE,'email','icServerSIEVE_connectionError'.trim($GLOBALS['egw_info']['user']['account_id']),$isConError,$expiration=60*15);
225
+			egw_cache::setCache(egw_cache::INSTANCE, 'email', 'icServerSIEVE_connectionError'.trim($GLOBALS['egw_info']['user']['account_id']), $isConError, $expiration = 60 * 15);
226 226
 			return false;
227 227
 		}
228 228
 
@@ -232,8 +232,8 @@  discard block
 block discarded – undo
232 232
 			try {
233 233
 				$this->scriptName = $this->getActive();
234 234
 			}
235
-			catch(Exception $e) {
236
-				unset($e);	// ignore NOTEXISTS exception
235
+			catch (Exception $e) {
236
+				unset($e); // ignore NOTEXISTS exception
237 237
 			}
238 238
 			if (empty($this->scriptName))
239 239
 			{
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
     {
262 262
         if ($this->debug)
263 263
 		{
264
-			error_log(__METHOD__ . __LINE__ . "$host, $port, " . array2string($options) . ", $useTLS");
264
+			error_log(__METHOD__.__LINE__."$host, $port, ".array2string($options).", $useTLS");
265 265
 		}
266 266
 		$this->_data['host'] = $host;
267 267
         $this->_data['port'] = $port;
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
             return PEAR::raiseError('Not currently in DISCONNECTED state', 1);
275 275
         }
276 276
 
277
-		if (self::isError($res = $this->_sock->connect($host, $port, false, ($this->_timeout?$this->_timeout:10), $options))) {
277
+		if (self::isError($res = $this->_sock->connect($host, $port, false, ($this->_timeout ? $this->_timeout : 10), $options))) {
278 278
             return $res;
279 279
         }
280 280
 
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
         // picked up from an existing connection.
292 292
         if (self::isError($res = $this->_cmdCapability())) {
293 293
             return PEAR::raiseError(
294
-                'Failed to connect, server said: ' . $res->getMessage(), 2
294
+                'Failed to connect, server said: '.$res->getMessage(), 2
295 295
             );
296 296
         }
297 297
 
@@ -321,33 +321,33 @@  discard block
 block discarded – undo
321 321
 	function _getBestAuthMethod($userMethod = null)
322 322
 	{
323 323
 		//error_log(__METHOD__.__LINE__.'->'.$userMethod.'<->'.array2string($this->_capability['sasl']));
324
-		if( isset($this->_capability['sasl']) ){
325
-			$serverMethods=$this->_capability['sasl'];
326
-		}else{
324
+		if (isset($this->_capability['sasl'])) {
325
+			$serverMethods = $this->_capability['sasl'];
326
+		} else {
327 327
 			// if the server don't send an sasl capability fallback to login auth
328 328
 			//return 'LOGIN';
329 329
 			return PEAR::raiseError("This server don't support any Auth methods SASL problem?");
330 330
 		}
331 331
 		$methods = array();
332
-		if($userMethod != null ){
332
+		if ($userMethod != null) {
333 333
 			$methods[] = $userMethod;
334
-			foreach ( $this->supportedAuthMethods as $method ) {
335
-				$methods[]=$method;
334
+			foreach ($this->supportedAuthMethods as $method) {
335
+				$methods[] = $method;
336 336
 			}
337
-		}else{
337
+		} else {
338 338
 			$methods = $this->supportedAuthMethods;
339 339
 		}
340
-		if( ($methods != null) && ($serverMethods != null)){
341
-			foreach ( $methods as $method ) {
342
-				if ( in_array( $method , $serverMethods ) ) {
340
+		if (($methods != null) && ($serverMethods != null)) {
341
+			foreach ($methods as $method) {
342
+				if (in_array($method, $serverMethods)) {
343 343
 					return $method;
344 344
 				}
345 345
 			}
346
-			$serverMethods=implode(',' , $serverMethods );
347
-			$myMethods=implode(',' ,$this->supportedAuthMethods);
348
-			return PEAR::raiseError("$method NOT supported authentication method!. This server " .
346
+			$serverMethods = implode(',', $serverMethods);
347
+			$myMethods = implode(',', $this->supportedAuthMethods);
348
+			return PEAR::raiseError("$method NOT supported authentication method!. This server ".
349 349
 				"supports these methods= $serverMethods, but I support $myMethods");
350
-		}else{
350
+		} else {
351 351
 			return PEAR::raiseError("This server don't support any Auth methods");
352 352
 		}
353 353
 	}
@@ -366,48 +366,48 @@  discard block
 block discarded – undo
366 366
      * @access private
367 367
      * @since  1.0
368 368
      */
369
-    function _cmdAuthenticate($uid , $pwd , $userMethod = null , $euser = '' )
369
+    function _cmdAuthenticate($uid, $pwd, $userMethod = null, $euser = '')
370 370
     {
371
-        if ( self::isError( $method = $this->_getBestAuthMethod($userMethod) ) ) {
371
+        if (self::isError($method = $this->_getBestAuthMethod($userMethod))) {
372 372
             return $method;
373 373
         }
374 374
         //error_log(__METHOD__.__LINE__.' using AuthMethod: '.$method);
375 375
         switch ($method) {
376 376
             case 'DIGEST-MD5':
377
-                $result = $this->_authDigestMD5( $uid , $pwd , $euser );
377
+                $result = $this->_authDigestMD5($uid, $pwd, $euser);
378 378
                 if (!self::isError($result))
379 379
 				{
380 380
 					break;
381 381
 				}
382 382
 				$res = $this->_doCmd();
383 383
                 unset($this->_error);
384
-                $this->supportedAuthMethods = array_diff($this->supportedAuthMethods,array($method,'CRAM-MD5'));
385
-                return $this->_cmdAuthenticate($uid , $pwd, null, $euser);
384
+                $this->supportedAuthMethods = array_diff($this->supportedAuthMethods, array($method, 'CRAM-MD5'));
385
+                return $this->_cmdAuthenticate($uid, $pwd, null, $euser);
386 386
             case 'CRAM-MD5':
387
-                $result = $this->_authCRAMMD5( $uid , $pwd, $euser);
387
+                $result = $this->_authCRAMMD5($uid, $pwd, $euser);
388 388
                 if (!self::isError($result))
389 389
 				{
390 390
 					break;
391 391
 				}
392 392
 				$res = $this->_doCmd();
393 393
                 unset($this->_error);
394
-                $this->supportedAuthMethods = array_diff($this->supportedAuthMethods,array($method,'DIGEST-MD5'));
395
-                return $this->_cmdAuthenticate($uid , $pwd, null, $euser);
394
+                $this->supportedAuthMethods = array_diff($this->supportedAuthMethods, array($method, 'DIGEST-MD5'));
395
+                return $this->_cmdAuthenticate($uid, $pwd, null, $euser);
396 396
             case 'LOGIN':
397
-                $result = $this->_authLOGIN( $uid , $pwd , $euser );
397
+                $result = $this->_authLOGIN($uid, $pwd, $euser);
398 398
                 if (!self::isError($result))
399 399
 				{
400 400
 					break;
401 401
 				}
402 402
 				$res = $this->_doCmd();
403 403
                 unset($this->_error);
404
-                $this->supportedAuthMethods = array_diff($this->supportedAuthMethods,array($method));
405
-                return $this->_cmdAuthenticate($uid , $pwd, null, $euser);
404
+                $this->supportedAuthMethods = array_diff($this->supportedAuthMethods, array($method));
405
+                return $this->_cmdAuthenticate($uid, $pwd, null, $euser);
406 406
             case 'PLAIN':
407
-                $result = $this->_authPLAIN( $uid , $pwd , $euser );
407
+                $result = $this->_authPLAIN($uid, $pwd, $euser);
408 408
                 break;
409 409
             default :
410
-                $result = new PEAR_Error( "$method is not a supported authentication method" );
410
+                $result = new PEAR_Error("$method is not a supported authentication method");
411 411
                 break;
412 412
         }
413 413
         if (self::isError($result))
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
         // Query the server capabilities again now that we are authenticated.
422 422
         if (self::isError($res = $this->_cmdCapability())) {
423 423
             return PEAR::raiseError(
424
-                'Failed to connect, server said: ' . $res->getMessage(), 2
424
+                'Failed to connect, server said: '.$res->getMessage(), 2
425 425
             );
426 426
         }
427 427
 
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
                         return rtrim($response);
476 476
                     }
477 477
 
478
-                    return $this->_pear->raiseError(trim($response . substr($line, 2)), 3);
478
+                    return $this->_pear->raiseError(trim($response.substr($line, 2)), 3);
479 479
                 }
480 480
 
481 481
                 if (preg_match('/^BYE/i', $line)) {
@@ -500,14 +500,14 @@  discard block
 block discarded – undo
500 500
                         if (is_a($error, 'PEAR_Error')) {
501 501
                             return $this->_pear->raiseError(
502 502
                                 'Cannot follow referral to '
503
-                                . $this->_data['host'] . ', the error was: '
503
+                                . $this->_data['host'].', the error was: '
504 504
                                 . $error->getMessage(),
505 505
                                 5
506 506
                             );
507 507
                         }
508 508
                         break;
509 509
                     }
510
-                    return $this->_pear->raiseError(trim($response . $line), 6);
510
+                    return $this->_pear->raiseError(trim($response.$line), 6);
511 511
                 }
512 512
 
513 513
                 // ServerResponse may send {nm} (nm representing a number)
@@ -535,12 +535,12 @@  discard block
 block discarded – undo
535 535
                     return rtrim($response);
536 536
                 }
537 537
 
538
-                $response .= $line . "\r\n";
538
+                $response .= $line."\r\n";
539 539
                 $referralCount++;
540 540
             }
541 541
         }
542 542
 
543
-        return $this->_pear->raiseError('Max referral count (' . $referralCount . ') reached. Cyrus murder loop error?', 7);
543
+        return $this->_pear->raiseError('Max referral count ('.$referralCount.') reached. Cyrus murder loop error?', 7);
544 544
     }
545 545
 
546 546
 	function getRules()
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
 	 * @param string $_scriptName
572 572
 	 * @param boolean $utf7imap_fileinto =false true: encode foldernames with utf7imap, default utf8
573 573
 	 */
574
-	function setRules(array $_rules, $_scriptName=null, $utf7imap_fileinto=false)
574
+	function setRules(array $_rules, $_scriptName = null, $utf7imap_fileinto = false)
575 575
 	{
576 576
 		$script = $this->retrieveRules($_scriptName);
577 577
 		$script->debug = $this->debug;
@@ -587,11 +587,11 @@  discard block
 block discarded – undo
587 587
 	 * @param array $_vacation
588 588
 	 * @param string $_scriptName
589 589
 	 */
590
-	function setVacation(array $_vacation, $_scriptName=null)
590
+	function setVacation(array $_vacation, $_scriptName = null)
591 591
 	{
592 592
 		if ($this->debug)
593 593
 		{
594
-			error_log(__METHOD__ . "($_scriptName," . print_r($_vacation, true) . ')');
594
+			error_log(__METHOD__."($_scriptName,".print_r($_vacation, true).')');
595 595
 		}
596 596
 		$script = $this->retrieveRules($_scriptName);
597 597
 		$script->debug = $this->debug;
@@ -608,9 +608,9 @@  discard block
 block discarded – undo
608 608
 	 * @param string $_scriptName
609 609
 	 * @return emailadmin_script
610 610
 	 */
611
-	function setEmailNotification(array $_emailNotification, $_scriptName=null)
611
+	function setEmailNotification(array $_emailNotification, $_scriptName = null)
612 612
 	{
613
-		if ($_emailNotification['externalEmail'] == '' || !preg_match("/\@/",$_emailNotification['externalEmail'])) {
613
+		if ($_emailNotification['externalEmail'] == '' || !preg_match("/\@/", $_emailNotification['externalEmail'])) {
614 614
     		$_emailNotification['status'] = 'off';
615 615
     		$_emailNotification['externalEmail'] = '';
616 616
     	}
@@ -628,7 +628,7 @@  discard block
 block discarded – undo
628 628
 	 * @param string $_scriptName
629 629
 	 * @return emailadmin_script
630 630
 	 */
631
-	function retrieveRules($_scriptName=null)
631
+	function retrieveRules($_scriptName = null)
632 632
 	{
633 633
 		if (!$_scriptName)
634 634
 		{
@@ -640,11 +640,11 @@  discard block
 block discarded – undo
640 640
 			$script->retrieveRules($this);
641 641
 		}
642 642
 		catch (Exception $e) {
643
-			unset($e);	// ignore not found script exception
643
+			unset($e); // ignore not found script exception
644 644
 		}
645
-		$this->rules =& $script->rules;
646
-		$this->vacation =& $script->vacation;
647
-		$this->emailNotification =& $script->emailNotification; // Added email notifications
645
+		$this->rules = & $script->rules;
646
+		$this->vacation = & $script->vacation;
647
+		$this->emailNotification = & $script->emailNotification; // Added email notifications
648 648
 
649 649
 		return $script;
650 650
 	}
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
 	 */
665 665
 	protected static function isError($data, $code = null)
666 666
 	{
667
-		static $pear=null;
667
+		static $pear = null;
668 668
 		if (!isset($pear)) $pear = new PEAR();
669 669
 
670 670
 		return $pear->isError($data, $code);
Please login to merge, or discard this patch.
Braces   +107 added lines, -48 removed lines patch added patch discarded remove patch
@@ -90,7 +90,10 @@  discard block
 block discarded – undo
90 90
 	{
91 91
 		parent::Net_Sieve();
92 92
 
93
-		if ($_scriptName) $this->scriptName = $_scriptName;
93
+		if ($_scriptName)
94
+		{
95
+			$this->scriptName = $_scriptName;
96
+		}
94 97
 
95 98
 		// TODO: since we seem to have major problems authenticating via DIGEST-MD5 and CRAM-MD5 in SIEVE, we skip MD5-METHODS for now
96 99
 		if (!is_null($_icServer))
@@ -106,7 +109,8 @@  discard block
 block discarded – undo
106 109
 
107 110
 		$this->displayCharset	= translation::charset();
108 111
 
109
-		if (!is_null($_icServer) && $this->_connect($_icServer, $_euser) === 'die') {
112
+		if (!is_null($_icServer) && $this->_connect($_icServer, $_euser) === 'die')
113
+		{
110 114
 			die('Sieve not activated');
111 115
 		}
112 116
 	}
@@ -260,36 +264,44 @@  discard block
 block discarded – undo
260 264
     function connect($host, $port, $options = null, $useTLS = true)
261 265
     {
262 266
         if ($this->debug)
263
-		{
267
+        {
264 268
 			error_log(__METHOD__ . __LINE__ . "$host, $port, " . array2string($options) . ", $useTLS");
265 269
 		}
266 270
 		$this->_data['host'] = $host;
267 271
         $this->_data['port'] = $port;
268 272
         $this->_useTLS       = $useTLS;
269
-        if (is_array($options)) {
273
+        if (is_array($options))
274
+        {
270 275
             $this->_options = array_merge((array)$this->_options, $options);
271 276
         }
272 277
 
273
-        if (NET_SIEVE_STATE_DISCONNECTED != $this->_state) {
278
+        if (NET_SIEVE_STATE_DISCONNECTED != $this->_state)
279
+        {
274 280
             return PEAR::raiseError('Not currently in DISCONNECTED state', 1);
275 281
         }
276 282
 
277
-		if (self::isError($res = $this->_sock->connect($host, $port, false, ($this->_timeout?$this->_timeout:10), $options))) {
283
+		if (self::isError($res = $this->_sock->connect($host, $port, false, ($this->_timeout?$this->_timeout:10), $options)))
284
+		{
278 285
             return $res;
279 286
         }
280 287
 
281
-        if ($this->_bypassAuth) {
288
+        if ($this->_bypassAuth)
289
+        {
282 290
             $this->_state = NET_SIEVE_STATE_TRANSACTION;
283
-        } else {
291
+        }
292
+        else
293
+        {
284 294
             $this->_state = NET_SIEVE_STATE_AUTHORISATION;
285
-            if (self::isError($res = $this->_doCmd())) {
295
+            if (self::isError($res = $this->_doCmd()))
296
+            {
286 297
                 return $res;
287 298
             }
288 299
         }
289 300
 
290 301
         // Explicitly ask for the capabilities in case the connection is
291 302
         // picked up from an existing connection.
292
-        if (self::isError($res = $this->_cmdCapability())) {
303
+        if (self::isError($res = $this->_cmdCapability()))
304
+        {
293 305
             return PEAR::raiseError(
294 306
                 'Failed to connect, server said: ' . $res->getMessage(), 2
295 307
             );
@@ -299,7 +311,8 @@  discard block
 block discarded – undo
299 311
         if ($useTLS && !empty($this->_capability['starttls'])
300 312
             && function_exists('stream_socket_enable_crypto')
301 313
         ) {
302
-            if (self::isError($res = $this->_startTLS())) {
314
+            if (self::isError($res = $this->_startTLS()))
315
+            {
303 316
                 return $res;
304 317
             }
305 318
         }
@@ -321,25 +334,35 @@  discard block
 block discarded – undo
321 334
 	function _getBestAuthMethod($userMethod = null)
322 335
 	{
323 336
 		//error_log(__METHOD__.__LINE__.'->'.$userMethod.'<->'.array2string($this->_capability['sasl']));
324
-		if( isset($this->_capability['sasl']) ){
337
+		if( isset($this->_capability['sasl']) )
338
+		{
325 339
 			$serverMethods=$this->_capability['sasl'];
326
-		}else{
340
+		}
341
+		else
342
+		{
327 343
 			// if the server don't send an sasl capability fallback to login auth
328 344
 			//return 'LOGIN';
329 345
 			return PEAR::raiseError("This server don't support any Auth methods SASL problem?");
330 346
 		}
331 347
 		$methods = array();
332
-		if($userMethod != null ){
348
+		if($userMethod != null )
349
+		{
333 350
 			$methods[] = $userMethod;
334
-			foreach ( $this->supportedAuthMethods as $method ) {
351
+			foreach ( $this->supportedAuthMethods as $method )
352
+			{
335 353
 				$methods[]=$method;
336 354
 			}
337
-		}else{
355
+		}
356
+		else
357
+		{
338 358
 			$methods = $this->supportedAuthMethods;
339 359
 		}
340
-		if( ($methods != null) && ($serverMethods != null)){
341
-			foreach ( $methods as $method ) {
342
-				if ( in_array( $method , $serverMethods ) ) {
360
+		if( ($methods != null) && ($serverMethods != null))
361
+		{
362
+			foreach ( $methods as $method )
363
+			{
364
+				if ( in_array( $method , $serverMethods ) )
365
+				{
343 366
 					return $method;
344 367
 				}
345 368
 			}
@@ -347,7 +370,9 @@  discard block
 block discarded – undo
347 370
 			$myMethods=implode(',' ,$this->supportedAuthMethods);
348 371
 			return PEAR::raiseError("$method NOT supported authentication method!. This server " .
349 372
 				"supports these methods= $serverMethods, but I support $myMethods");
350
-		}else{
373
+		}
374
+		else
375
+		{
351 376
 			return PEAR::raiseError("This server don't support any Auth methods");
352 377
 		}
353 378
 	}
@@ -368,15 +393,17 @@  discard block
 block discarded – undo
368 393
      */
369 394
     function _cmdAuthenticate($uid , $pwd , $userMethod = null , $euser = '' )
370 395
     {
371
-        if ( self::isError( $method = $this->_getBestAuthMethod($userMethod) ) ) {
396
+        if ( self::isError( $method = $this->_getBestAuthMethod($userMethod) ) )
397
+        {
372 398
             return $method;
373 399
         }
374 400
         //error_log(__METHOD__.__LINE__.' using AuthMethod: '.$method);
375
-        switch ($method) {
401
+        switch ($method)
402
+        {
376 403
             case 'DIGEST-MD5':
377 404
                 $result = $this->_authDigestMD5( $uid , $pwd , $euser );
378 405
                 if (!self::isError($result))
379
-				{
406
+                {
380 407
 					break;
381 408
 				}
382 409
 				$res = $this->_doCmd();
@@ -386,7 +413,7 @@  discard block
 block discarded – undo
386 413
             case 'CRAM-MD5':
387 414
                 $result = $this->_authCRAMMD5( $uid , $pwd, $euser);
388 415
                 if (!self::isError($result))
389
-				{
416
+                {
390 417
 					break;
391 418
 				}
392 419
 				$res = $this->_doCmd();
@@ -396,7 +423,7 @@  discard block
 block discarded – undo
396 423
             case 'LOGIN':
397 424
                 $result = $this->_authLOGIN( $uid , $pwd , $euser );
398 425
                 if (!self::isError($result))
399
-				{
426
+                {
400 427
 					break;
401 428
 				}
402 429
 				$res = $this->_doCmd();
@@ -411,15 +438,17 @@  discard block
 block discarded – undo
411 438
                 break;
412 439
         }
413 440
         if (self::isError($result))
414
-		{
441
+        {
415 442
 			return $result;
416 443
 		}
417
-		if (self::isError($res = $this->_doCmd())) {
444
+		if (self::isError($res = $this->_doCmd()))
445
+		{
418 446
             return $res;
419 447
         }
420 448
 
421 449
         // Query the server capabilities again now that we are authenticated.
422
-        if (self::isError($res = $this->_cmdCapability())) {
450
+        if (self::isError($res = $this->_cmdCapability()))
451
+        {
423 452
             return PEAR::raiseError(
424 453
                 'Failed to connect, server said: ' . $res->getMessage(), 2
425 454
             );
@@ -440,37 +469,46 @@  discard block
 block discarded – undo
440 469
     function _doCmd($cmd = '', $auth = false)
441 470
     {
442 471
         $referralCount = 0;
443
-        while ($referralCount < $this->_maxReferralCount) {
444
-            if (strlen($cmd)) {
472
+        while ($referralCount < $this->_maxReferralCount)
473
+        {
474
+            if (strlen($cmd))
475
+            {
445 476
                 $error = $this->_sendCmd($cmd);
446
-                if (is_a($error, 'PEAR_Error')) {
477
+                if (is_a($error, 'PEAR_Error'))
478
+                {
447 479
                     return $error;
448 480
                 }
449 481
             }
450 482
 
451 483
             $response = '';
452
-            while (true) {
484
+            while (true)
485
+            {
453 486
                 $line = $this->_recvLn();
454 487
 
455
-                if (is_a($line, 'PEAR_Error')) {
488
+                if (is_a($line, 'PEAR_Error'))
489
+                {
456 490
                     return $line;
457 491
                 }
458 492
 
459
-                if (preg_match('/^(OK|NO)/i', $line, $tag)) {
493
+                if (preg_match('/^(OK|NO)/i', $line, $tag))
494
+                {
460 495
                     // Check for string literal message.
461 496
                     // ServerResponse may send {nm} (nm representing a number)
462 497
                     // dbmail (in some versions) sends: {nm+} thus breaking RFC5804 rules (Section 4 Formal Syntax)
463 498
                     // {nm+} may only be used in communicating from client TO server; (not Server to Client)
464 499
                     // we work around this bug (allowing +) using a patch introduced with roundcube 2 years ago.
465 500
                     //if (preg_match('/{([0-9]+)}$/', $line, $matches)) { //original
466
-                    if (preg_match('/{([0-9]+)\+?}$/', $line, $matches)) { //patched to cope with dbmail
501
+                    if (preg_match('/{([0-9]+)\+?}$/', $line, $matches))
502
+                    {
503
+//patched to cope with dbmail
467 504
                         $line = substr($line, 0, -(strlen($matches[1]) + 2))
468 505
                             . str_replace(
469 506
                                 "\r\n", ' ', $this->_recvBytes($matches[1] + 2)
470 507
                             );
471 508
                     }
472 509
 
473
-                    if ('OK' == $this->_toUpper($tag[1])) {
510
+                    if ('OK' == $this->_toUpper($tag[1]))
511
+                    {
474 512
                         $response .= $line;
475 513
                         return rtrim($response);
476 514
                     }
@@ -478,9 +516,11 @@  discard block
 block discarded – undo
478 516
                     return $this->_pear->raiseError(trim($response . substr($line, 2)), 3);
479 517
                 }
480 518
 
481
-                if (preg_match('/^BYE/i', $line)) {
519
+                if (preg_match('/^BYE/i', $line))
520
+                {
482 521
                     $error = $this->disconnect(false);
483
-                    if (is_a($error, 'PEAR_Error')) {
522
+                    if (is_a($error, 'PEAR_Error'))
523
+                    {
484 524
                         return $this->_pear->raiseError(
485 525
                             'Cannot handle BYE, the error was: '
486 526
                             . $error->getMessage(),
@@ -489,7 +529,8 @@  discard block
 block discarded – undo
489 529
                     }
490 530
                     // Check for referral, then follow it.  Otherwise, carp an
491 531
                     // error.
492
-                    if (preg_match('/^bye \(referral "(sieve:\/\/)?([^"]+)/i', $line, $matches)) {
532
+                    if (preg_match('/^bye \(referral "(sieve:\/\/)?([^"]+)/i', $line, $matches))
533
+                    {
493 534
                         // Replace the old host with the referral host
494 535
                         // preserving any protocol prefix.
495 536
                         $this->_data['host'] = preg_replace(
@@ -497,7 +538,8 @@  discard block
 block discarded – undo
497 538
                             $this->_data['host']
498 539
                         );
499 540
                         $error = $this->_handleConnectAndLogin();
500
-                        if (is_a($error, 'PEAR_Error')) {
541
+                        if (is_a($error, 'PEAR_Error'))
542
+                        {
501 543
                             return $this->_pear->raiseError(
502 544
                                 'Cannot follow referral to '
503 545
                                 . $this->_data['host'] . ', the error was: '
@@ -516,10 +558,13 @@  discard block
 block discarded – undo
516 558
                 // we work around this bug (allowing +) using a patch introduced with roundcube 2 years ago.
517 559
                 // although roundcube suggested only the change in line
518 560
                 //if (preg_match('/^{([0-9]+)}/', $line, $matches)) { //original
519
-                if (preg_match('/^{([0-9]+)\+?}/', $line, $matches)) { //patched to cope with dbmail
561
+                if (preg_match('/^{([0-9]+)\+?}/', $line, $matches))
562
+                {
563
+//patched to cope with dbmail
520 564
                     // Matches literal string responses.
521 565
                     $line = $this->_recvBytes($matches[1] + 2);
522
-                    if (!$auth) {
566
+                    if (!$auth)
567
+                    {
523 568
                         // Receive the pending OK only if we aren't
524 569
                         // authenticating since string responses during
525 570
                         // authentication don't need an OK.
@@ -528,7 +573,8 @@  discard block
 block discarded – undo
528 573
                     return $line;
529 574
                 }
530 575
 
531
-                if ($auth) {
576
+                if ($auth)
577
+                {
532 578
                     // String responses during authentication don't need an
533 579
                     // OK.
534 580
                     $response .= $line;
@@ -545,21 +591,30 @@  discard block
 block discarded – undo
545 591
 
546 592
 	function getRules()
547 593
 	{
548
-		if (!isset($this->rules)) $this->retrieveRules();
594
+		if (!isset($this->rules))
595
+		{
596
+			$this->retrieveRules();
597
+		}
549 598
 
550 599
 		return $this->rules;
551 600
 	}
552 601
 
553 602
 	function getVacation()
554 603
 	{
555
-		if (!isset($this->rules)) $this->retrieveRules();
604
+		if (!isset($this->rules))
605
+		{
606
+			$this->retrieveRules();
607
+		}
556 608
 
557 609
 		return $this->vacation;
558 610
 	}
559 611
 
560 612
 	function getEmailNotification()
561 613
 	{
562
-		if (!isset($this->rules)) $this->retrieveRules();
614
+		if (!isset($this->rules))
615
+		{
616
+			$this->retrieveRules();
617
+		}
563 618
 
564 619
 		return $this->emailNotification;
565 620
 	}
@@ -610,7 +665,8 @@  discard block
 block discarded – undo
610 665
 	 */
611 666
 	function setEmailNotification(array $_emailNotification, $_scriptName=null)
612 667
 	{
613
-		if ($_emailNotification['externalEmail'] == '' || !preg_match("/\@/",$_emailNotification['externalEmail'])) {
668
+		if ($_emailNotification['externalEmail'] == '' || !preg_match("/\@/",$_emailNotification['externalEmail']))
669
+		{
614 670
     		$_emailNotification['status'] = 'off';
615 671
     		$_emailNotification['externalEmail'] = '';
616 672
     	}
@@ -665,7 +721,10 @@  discard block
 block discarded – undo
665 721
 	protected static function isError($data, $code = null)
666 722
 	{
667 723
 		static $pear=null;
668
-		if (!isset($pear)) $pear = new PEAR();
724
+		if (!isset($pear))
725
+		{
726
+			$pear = new PEAR();
727
+		}
669 728
 
670 729
 		return $pear->isError($data, $code);
671 730
 	}
Please login to merge, or discard this patch.
emailadmin/inc/class.emailadmin_smtp.inc.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	/**
73 73
 	 * Constructor
74 74
 	 *
75
-	 * @param string $defaultDomain=null
75
+	 * @param string $defaultDomain
76 76
 	 */
77 77
 	function __construct($defaultDomain=null)
78 78
 	{
@@ -149,8 +149,8 @@  discard block
 block discarded – undo
149 149
 	/**
150 150
 	 * Get the data of a given user
151 151
 	 *
152
-	 * @param int|string $user numerical account-id, account-name or email address
153
-	 * @param boolean $match_uid_at_domain=true true: uid@domain matches, false only an email or alias address matches
152
+	 * @param integer $user numerical account-id, account-name or email address
153
+	 * @param boolean $match_uid_at_domain true: uid@domain matches, false only an email or alias address matches
154 154
 	 * @return array with values for keys 'mailLocalAddress', 'mailAlternateAddress' (array), 'mailForwardingAddress' (array),
155 155
 	 * 	'accountStatus' ("active"), 'quotaLimit' and 'deliveryMode' ("forwardOnly")
156 156
 	 */
@@ -187,8 +187,8 @@  discard block
 block discarded – undo
187 187
 	 * @param string $_accountStatus
188 188
 	 * @param string $_mailLocalAddress
189 189
 	 * @param int $_quota in MB
190
-	 * @param boolean $_forwarding_only=false true: store only forwarding info, used internally by saveSMTPForwarding
191
-	 * @param string $_setMailbox=null used only for account migration
190
+	 * @param boolean $_forwarding_only true: store only forwarding info, used internally by saveSMTPForwarding
191
+	 * @param string $_setMailbox used only for account migration
192 192
 	 * @return boolean true on success, false on error writing to ldap
193 193
 	 */
194 194
 	function setUserData($_uidnumber, array $_mailAlternateAddress, array $_mailForwardingAddress, $_deliveryMode,
Please login to merge, or discard this patch.
Spacing   +12 added lines, -14 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	 *
75 75
 	 * @param string $defaultDomain=null
76 76
 	 */
77
-	function __construct($defaultDomain=null)
77
+	function __construct($defaultDomain = null)
78 78
 	{
79 79
 		$this->defaultDomain = $defaultDomain ? $defaultDomain : $GLOBALS['egw_info']['server']['mail_suffix'];
80 80
 
@@ -99,12 +99,10 @@  discard block
 block discarded – undo
99 99
 	 */
100 100
 	function addAccount($_hookValues)
101 101
 	{
102
-		$mailLocalAddress = $_hookValues['account_email'] ? $_hookValues['account_email'] :
103
-			common::email_address($_hookValues['account_firstname'],
104
-				$_hookValues['account_lastname'],$_hookValues['account_lid'],$this->defaultDomain);
102
+		$mailLocalAddress = $_hookValues['account_email'] ? $_hookValues['account_email'] : common::email_address($_hookValues['account_firstname'],
103
+				$_hookValues['account_lastname'], $_hookValues['account_lid'], $this->defaultDomain);
105 104
 
106
-		$account_id = !empty($_hookValues['account_id']) ? $_hookValues['account_id'] :
107
-			$this->accounts->name2id($_hookValues['account_lid'], 'account_lid', 'u');
105
+		$account_id = !empty($_hookValues['account_id']) ? $_hookValues['account_id'] : $this->accounts->name2id($_hookValues['account_lid'], 'account_lid', 'u');
108 106
 
109 107
 		if ($this->accounts->exists($account_id) != 1)
110 108
 		{
@@ -132,12 +130,12 @@  discard block
 block discarded – undo
132 130
 	 */
133 131
 	function getAccountEmailAddress($_accountName)
134 132
 	{
135
-		$emailAddresses	= array();
133
+		$emailAddresses = array();
136 134
 
137 135
 		if (($account_id = $this->accounts->name2id($_accountName, 'account_lid', 'u')))
138 136
 		{
139
-			$realName = trim($GLOBALS['egw_info']['user']['account_firstname'] . (!empty($GLOBALS['egw_info']['user']['account_firstname']) ? ' ' : '') . $GLOBALS['egw_info']['user']['account_lastname']);
140
-			$emailAddresses[] = array (
137
+			$realName = trim($GLOBALS['egw_info']['user']['account_firstname'].(!empty($GLOBALS['egw_info']['user']['account_firstname']) ? ' ' : '').$GLOBALS['egw_info']['user']['account_lastname']);
138
+			$emailAddresses[] = array(
141 139
 				'name'		=> $realName,
142 140
 				'address'	=> $this->accounts->id2name($account_id, 'account_email'),
143 141
 				'type'		=> 'default',
@@ -154,7 +152,7 @@  discard block
 block discarded – undo
154 152
 	 * @return array with values for keys 'mailLocalAddress', 'mailAlternateAddress' (array), 'mailForwardingAddress' (array),
155 153
 	 * 	'accountStatus' ("active"), 'quotaLimit' and 'deliveryMode' ("forwardOnly")
156 154
 	 */
157
-	function getUserData($user, $match_uid_at_domain=false)
155
+	function getUserData($user, $match_uid_at_domain = false)
158 156
 	{
159 157
 		$userData = array();
160 158
 
@@ -192,7 +190,7 @@  discard block
 block discarded – undo
192 190
 	 * @return boolean true on success, false on error writing to ldap
193 191
 	 */
194 192
 	function setUserData($_uidnumber, array $_mailAlternateAddress, array $_mailForwardingAddress, $_deliveryMode,
195
-		$_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only=false, $_setMailbox=null)
193
+		$_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only = false, $_setMailbox = null)
196 194
 	{
197 195
 		return true;
198 196
 	}
@@ -219,15 +217,15 @@  discard block
 block discarded – undo
219 217
 	 * 	default use $this->loginType
220 218
 	 * @return string
221 219
 	 */
222
-	/*static*/ public function mailbox_addr($account,$domain=null,$mail_login_type=null)
220
+	/*static*/ public function mailbox_addr($account, $domain = null, $mail_login_type = null)
223 221
 	{
224 222
 		if (is_null($domain)) $domain = $this->defaultDomain;
225 223
 		if (is_null($mail_login_type)) $mail_login_type = $this->loginType;
226 224
 
227
-		switch($mail_login_type)
225
+		switch ($mail_login_type)
228 226
 		{
229 227
 			case 'email':
230
-				$mbox = is_array($account) ? $account['account_email'] : $GLOBALS['egw']->accounts->id2name($account,'account_email');
228
+				$mbox = is_array($account) ? $account['account_email'] : $GLOBALS['egw']->accounts->id2name($account, 'account_email');
231 229
 				break;
232 230
 
233 231
 			case 'uidNumber':
Please login to merge, or discard this patch.
Braces   +12 added lines, -3 removed lines patch added patch discarded remove patch
@@ -235,8 +235,14 @@  discard block
 block discarded – undo
235 235
 	 */
236 236
 	/*static*/ public function mailbox_addr($account,$domain=null,$mail_login_type=null)
237 237
 	{
238
-		if (is_null($domain)) $domain = $this->defaultDomain;
239
-		if (is_null($mail_login_type)) $mail_login_type = $this->loginType;
238
+		if (is_null($domain))
239
+		{
240
+			$domain = $this->defaultDomain;
241
+		}
242
+		if (is_null($mail_login_type))
243
+		{
244
+			$mail_login_type = $this->loginType;
245
+		}
240 246
 
241 247
 		switch($mail_login_type)
242 248
 		{
@@ -245,7 +251,10 @@  discard block
 block discarded – undo
245 251
 				break;
246 252
 
247 253
 			case 'uidNumber':
248
-				if (is_array($account)) $account = $account['account_id'];
254
+				if (is_array($account))
255
+				{
256
+					$account = $account['account_id'];
257
+				}
249 258
 				$mbox = 'u'.$account.'@'.$domain;
250 259
 				break;
251 260
 
Please login to merge, or discard this patch.
emailadmin/inc/class.emailadmin_smtp_ads.inc.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -146,7 +146,7 @@
 block discarded – undo
146 146
 	/**
147 147
 	 * Constructor
148 148
 	 *
149
-	 * @param string $defaultDomain=null
149
+	 * @param string $defaultDomain
150 150
 	 */
151 151
 	function __construct($defaultDomain=null)
152 152
 	{
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -148,7 +148,7 @@
 block discarded – undo
148 148
 	 *
149 149
 	 * @param string $defaultDomain=null
150 150
 	 */
151
-	function __construct($defaultDomain=null)
151
+	function __construct($defaultDomain = null)
152 152
 	{
153 153
 		parent::__construct($defaultDomain);
154 154
 
Please login to merge, or discard this patch.
emailadmin/inc/class.emailadmin_smtp_ldap.inc.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -628,7 +628,7 @@
 block discarded – undo
628 628
 	 * @param int $_accountID
629 629
 	 * @param string $_forwardingAddress
630 630
 	 * @param string $_keepLocalCopy 'yes'
631
-	 * @return boolean true on success, false on error writing to ldap
631
+	 * @return boolean|null true on success, false on error writing to ldap
632 632
 	 */
633 633
 	function saveSMTPForwarding($_accountID, $_forwardingAddress, $_keepLocalCopy)
634 634
 	{
Please login to merge, or discard this patch.
Spacing   +44 added lines, -45 removed lines patch added patch discarded remove patch
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	 *
152 152
 	 * @param string $defaultDomain =null
153 153
 	 */
154
-	function __construct($defaultDomain=null)
154
+	function __construct($defaultDomain = null)
155 155
 	{
156 156
 		parent::__construct($defaultDomain);
157 157
 
@@ -199,9 +199,8 @@  discard block
 block discarded – undo
199 199
 	 */
200 200
 	function addAccount($_hookValues)
201 201
 	{
202
-		$mailLocalAddress = $_hookValues['account_email'] ? $_hookValues['account_email'] :
203
-			common::email_address($_hookValues['account_firstname'],
204
-				$_hookValues['account_lastname'],$_hookValues['account_lid'],$this->defaultDomain);
202
+		$mailLocalAddress = $_hookValues['account_email'] ? $_hookValues['account_email'] : common::email_address($_hookValues['account_firstname'],
203
+				$_hookValues['account_lastname'], $_hookValues['account_lid'], $this->defaultDomain);
205 204
 
206 205
 		$ds = $this->getLdapConnection();
207 206
 
@@ -213,13 +212,13 @@  discard block
 block discarded – undo
213 212
 		}
214 213
 		$allValues 	= ldap_get_entries($ds, $sri);
215 214
 		$accountDN 	= $allValues[0]['dn'];
216
-		$objectClasses	= $allValues[0]['objectclass'];
215
+		$objectClasses = $allValues[0]['objectclass'];
217 216
 		unset($objectClasses['count']);
218 217
 
219 218
 		// add our mail schema, if not already set
220
-		if(!in_array(static::SCHEMA,$objectClasses) && !in_array(strtolower(static::SCHEMA),$objectClasses))
219
+		if (!in_array(static::SCHEMA, $objectClasses) && !in_array(strtolower(static::SCHEMA), $objectClasses))
221 220
 		{
222
-			$objectClasses[]	= static::SCHEMA;
221
+			$objectClasses[] = static::SCHEMA;
223 222
 		}
224 223
 		// the new code for postfix+cyrus+ldap
225 224
 		$newData = array(
@@ -250,7 +249,7 @@  discard block
 block discarded – undo
250 249
 		{
251 250
 			error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'$accountDN',".
252 251
 				array2string($newData).') returning '.array2string($ret).
253
-				(!$ret?' ('.ldap_error($ds).')':''));
252
+				(!$ret ? ' ('.ldap_error($ds).')' : ''));
254 253
 		}
255 254
 		return $ret;
256 255
 	}
@@ -264,7 +263,7 @@  discard block
 block discarded – undo
264 263
 	 */
265 264
 	function addAccountExtra(array $_hookValues, array $allValues, array &$newData)
266 265
 	{
267
-		unset($_hookValues, $allValues, $newData);	// not used, but required by function signature
266
+		unset($_hookValues, $allValues, $newData); // not used, but required by function signature
268 267
 	}
269 268
 
270 269
 	/**
@@ -275,24 +274,24 @@  discard block
 block discarded – undo
275 274
 	 */
276 275
 	function getAccountEmailAddress($_accountName)
277 276
 	{
278
-		$emailAddresses	= array();
277
+		$emailAddresses = array();
279 278
 		$ds = $this->getLdapConnection();
280 279
 		$filter = '(&'.static::USER_FILTER.'('.static::USER_ATTR.'='.ldap::quote($_accountName).'))';
281
-		$attributes	= array('dn', static::MAIL_ATTR, static::ALIAS_ATTR);
280
+		$attributes = array('dn', static::MAIL_ATTR, static::ALIAS_ATTR);
282 281
 		$sri = @ldap_search($ds, $this->search_base, $filter, $attributes);
283 282
 
284 283
 		if ($sri)
285 284
 		{
286
-			$realName = trim($GLOBALS['egw_info']['user']['account_firstname'] . (!empty($GLOBALS['egw_info']['user']['account_firstname']) ? ' ' : '') . $GLOBALS['egw_info']['user']['account_lastname']);
285
+			$realName = trim($GLOBALS['egw_info']['user']['account_firstname'].(!empty($GLOBALS['egw_info']['user']['account_firstname']) ? ' ' : '').$GLOBALS['egw_info']['user']['account_lastname']);
287 286
 			$allValues = ldap_get_entries($ds, $sri);
288 287
 
289
-			if(isset($allValues[0][static::MAIL_ATTR]))
288
+			if (isset($allValues[0][static::MAIL_ATTR]))
290 289
 			{
291
-				foreach($allValues[0][static::MAIL_ATTR] as $key => $value)
290
+				foreach ($allValues[0][static::MAIL_ATTR] as $key => $value)
292 291
 				{
293 292
 					if ($key === 'count') continue;
294 293
 
295
-					$emailAddresses[] = array (
294
+					$emailAddresses[] = array(
296 295
 						'name'		=> $realName,
297 296
 						'address'	=> $value,
298 297
 						'type'		=> !$key ? 'default' : 'alternate',
@@ -301,7 +300,7 @@  discard block
 block discarded – undo
301 300
 			}
302 301
 			if (static::ALIAS_ATTR && isset($allValues[0][static::ALIAS_ATTR]))
303 302
 			{
304
-				foreach(self::getAttributePrefix($allValues[0][static::ALIAS_ATTR], static::ALIAS_PREFIX) as $value)
303
+				foreach (self::getAttributePrefix($allValues[0][static::ALIAS_ATTR], static::ALIAS_PREFIX) as $value)
305 304
 				{
306 305
 					$emailAddresses[] = array(
307 306
 						'name'		=> $realName,
@@ -328,7 +327,7 @@  discard block
 block discarded – undo
328 327
 	 * @return array with values for keys 'mailLocalAddress', 'mailAlternateAddress' (array), 'mailForwardingAddress' (array),
329 328
 	 * 	'accountStatus' ("active"), 'quotaLimit' and 'deliveryMode' ("forwardOnly")
330 329
 	 */
331
-	function getUserData($user, $match_uid_at_domain=false)
330
+	function getUserData($user, $match_uid_at_domain = false)
332 331
 	{
333 332
 		$userData = array(
334 333
 			'mailbox' => array(),
@@ -388,7 +387,7 @@  discard block
 block discarded – undo
388 387
 			$allValues = ldap_get_entries($ldap, $sri);
389 388
 			if ($this->debug) error_log(__METHOD__."('$user') --> ldap_search(, '$this->search_base', '$filter') --> ldap_get_entries=".array2string($allValues[0]));
390 389
 
391
-			foreach($allValues as $key => $values)
390
+			foreach ($allValues as $key => $values)
392 391
 			{
393 392
 				if ($key === 'count') continue;
394 393
 
@@ -471,16 +470,16 @@  discard block
 block discarded – undo
471 470
 
472 471
 				if (static::FORWARD_ATTR)
473 472
 				{
474
-					$userData['mailForwardingAddress']	= self::getAttributePrefix($values[static::FORWARD_ATTR], static::FORWARD_PREFIX);
473
+					$userData['mailForwardingAddress'] = self::getAttributePrefix($values[static::FORWARD_ATTR], static::FORWARD_PREFIX);
475 474
 				}
476 475
 
477
-				if (static::MAILBOX_ATTR) $userData['mailMessageStore']	= $values[static::MAILBOX_ATTR][0];
476
+				if (static::MAILBOX_ATTR) $userData['mailMessageStore'] = $values[static::MAILBOX_ATTR][0];
478 477
 
479 478
 				$userData['deliveryMode'] = $deliveryMode;
480 479
 
481 480
 				// eg. suse stores all email addresses as aliases
482 481
 				if (static::REQUIRE_MAIL_AS_ALIAS &&
483
-					($k = array_search($userData['mailLocalAddress'],$userData['mailAlternateAddress'])) !== false)
482
+					($k = array_search($userData['mailLocalAddress'], $userData['mailAlternateAddress'])) !== false)
484 483
 				{
485 484
 					unset($userData['mailAlternateAddress'][$k]);
486 485
 				}
@@ -513,9 +512,9 @@  discard block
 block discarded – undo
513 512
 	 * @return boolean true on success, false on error writing to ldap
514 513
 	 */
515 514
 	function setUserData($_uidnumber, array $_mailAlternateAddress, array $_mailForwardingAddress, $_deliveryMode,
516
-		$_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only=false, $_setMailbox=null)
515
+		$_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only = false, $_setMailbox = null)
517 516
 	{
518
-		unset($_forwarding_only);	// not used
517
+		unset($_forwarding_only); // not used
519 518
 
520 519
 		if (static::USERID_ATTR)
521 520
 		{
@@ -535,15 +534,15 @@  discard block
 block discarded – undo
535 534
 		$allValues 	= ldap_get_entries($ldap, $sri);
536 535
 
537 536
 		$accountDN 	= $allValues[0]['dn'];
538
-		$uid	   	= $allValues[0][static::USER_ATTR][0];
539
-		$objectClasses	= $allValues[0]['objectclass'];
537
+		$uid = $allValues[0][static::USER_ATTR][0];
538
+		$objectClasses = $allValues[0]['objectclass'];
540 539
 
541 540
 		unset($objectClasses['count']);
542 541
 
543
-		if(!in_array(static::SCHEMA,$objectClasses) && !in_array(strtolower(static::SCHEMA),$objectClasses))
542
+		if (!in_array(static::SCHEMA, $objectClasses) && !in_array(strtolower(static::SCHEMA), $objectClasses))
544 543
 		{
545
-			$objectClasses[]	= static::SCHEMA;
546
-			$newData['objectclass']	= $objectClasses;
544
+			$objectClasses[] = static::SCHEMA;
545
+			$newData['objectclass'] = $objectClasses;
547 546
 		}
548 547
 
549 548
 		sort($_mailAlternateAddress);
@@ -556,7 +555,7 @@  discard block
 block discarded – undo
556 555
 			self::setAttributePrefix($newData[static::ALIAS_ATTR], $_mailAlternateAddress, static::ALIAS_PREFIX);
557 556
 
558 557
 			// all email must be stored as alias for suse
559
-			if (static::REQUIRE_MAIL_AS_ALIAS && !in_array($_mailLocalAddress,(array)$_mailAlternateAddress))
558
+			if (static::REQUIRE_MAIL_AS_ALIAS && !in_array($_mailLocalAddress, (array)$_mailAlternateAddress))
560 559
 			{
561 560
 				self::setAttributePrefix($newData[static::ALIAS_ATTR], $_mailLocalAddress, static::ALIAS_PREFIX);
562 561
 			}
@@ -589,12 +588,12 @@  discard block
 block discarded – undo
589 588
 		if (static::QUOTA_ATTR)
590 589
 		{
591 590
 			self::setAttributePrefix($newData[static::QUOTA_ATTR],
592
-				(int)$_quota > 0 ? (int)$_quota*static::QUOTA_FACTOR : array(), static::QUOTA_PREFIX);
591
+				(int)$_quota > 0 ? (int)$_quota * static::QUOTA_FACTOR : array(), static::QUOTA_PREFIX);
593 592
 		}
594 593
 		// does schema support enabling/disabling mail via attribute
595 594
 		if (static::MAIL_ENABLE_ATTR)
596 595
 		{
597
-			$newData[static::MAIL_ENABLE_ATTR]	= $_accountStatus ?
596
+			$newData[static::MAIL_ENABLE_ATTR] = $_accountStatus ?
598 597
 				(static::MAIL_ENABLED == self::MAIL_ENABLED_USE_MAIL ? $_mailLocalAddress : static::MAIL_ENABLED) : array();
599 598
 		}
600 599
 		// if we have no mail-enabled attribute, but require primary mail in aliases-attr
@@ -636,7 +635,7 @@  discard block
 block discarded – undo
636 635
 			$uid = $GLOBALS['egw']->accounts->id2name($_accountID);
637 636
 			$filter = '(&'.static::USER_FILTER.'('.static::USER_ATTR.'='.ldap::quote($uid).'))';
638 637
 		}
639
-		$attributes	= array('dn', static::FORWARD_ATTR, 'objectclass');
638
+		$attributes = array('dn', static::FORWARD_ATTR, 'objectclass');
640 639
 		if (static::FORWARD_ONLY_ATTR)
641 640
 		{
642 641
 			$attributes[] = static::FORWARD_ONLY_ATTR;
@@ -647,12 +646,12 @@  discard block
 block discarded – undo
647 646
 		{
648 647
 			$newData = array();
649 648
 			$allValues = ldap_get_entries($ds, $sri);
650
-			$objectClasses  = $allValues[0]['objectclass'];
651
-			$newData['objectclass']	= $allValues[0]['objectclass'];
649
+			$objectClasses = $allValues[0]['objectclass'];
650
+			$newData['objectclass'] = $allValues[0]['objectclass'];
652 651
 
653 652
 			unset($newData['objectclass']['count']);
654 653
 
655
-			if(!in_array(static::SCHEMA,$objectClasses))
654
+			if (!in_array(static::SCHEMA, $objectClasses))
656 655
 			{
657 656
 				$newData['objectclass'][] = static::SCHEMA;
658 657
 			}
@@ -662,9 +661,9 @@  discard block
 block discarded – undo
662 661
 				$newData[static::FORWARD_ATTR] = $allValues[0][static::FORWARD_ATTR];
663 662
 				$forwards = self::getAttributePrefix($newData[static::FORWARD_ATTR], static::FORWARD_PREFIX);
664 663
 
665
-				if(!empty($_forwardingAddress))
664
+				if (!empty($_forwardingAddress))
666 665
 				{
667
-					if($forwards)
666
+					if ($forwards)
668 667
 					{
669 668
 						if (!is_array($_forwardingAddress))
670 669
 						{
@@ -696,7 +695,7 @@  discard block
 block discarded – undo
696 695
 			}
697 696
 			if ($this->debug) error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'{$allValues[0]['dn']}',".array2string($newData).')');
698 697
 
699
-			return ldap_modify ($ds, $allValues[0]['dn'], $newData);
698
+			return ldap_modify($ds, $allValues[0]['dn'], $newData);
700 699
 		}
701 700
 	}
702 701
 
@@ -738,9 +737,9 @@  discard block
 block discarded – undo
738 737
 		unset($entries['count']);
739 738
 
740 739
 		$mailboxes = array();
741
-		foreach($entries as $entry)
740
+		foreach ($entries as $entry)
742 741
 		{
743
-			if ($entry[static::USER_ATTR][0] == 'anonymous') continue;	// anonymous is never a mail-user!
742
+			if ($entry[static::USER_ATTR][0] == 'anonymous') continue; // anonymous is never a mail-user!
744 743
 			list($mailbox) = explode('@', $entry[static::MAILBOX_ATTR ? static::MAILBOX_ATTR : static::MAIL_ATTR][0]);
745 744
 			$mailboxes[$entry[static::USER_ATTR][0]] = $mailbox;
746 745
 		}
@@ -754,13 +753,13 @@  discard block
 block discarded – undo
754 753
 	 * @param string|array $values value(s) to set
755 754
 	 * @param string $prefix ='' prefix to use or ''
756 755
 	 */
757
-	protected static function setAttributePrefix(&$attribute, $values, $prefix='')
756
+	protected static function setAttributePrefix(&$attribute, $values, $prefix = '')
758 757
 	{
759 758
 		//$attribute_in = $attribute;
760 759
 		if (empty($attribute)) $attribute = array();
761 760
 		if (!is_array($attribute)) $attribute = (array)$attribute;
762 761
 
763
-		foreach((array)$values as $value)
762
+		foreach ((array)$values as $value)
764 763
 		{
765 764
 			$attribute[] = $prefix.$value;
766 765
 		}
@@ -775,7 +774,7 @@  discard block
 block discarded – undo
775 774
 	 * @param boolean $remove =true remove returned values from $attribute
776 775
 	 * @return array with values (prefix removed) or array() if nothing found
777 776
 	 */
778
-	protected static function getAttributePrefix(&$attribute, $prefix='', $remove=true)
777
+	protected static function getAttributePrefix(&$attribute, $prefix = '', $remove = true)
779 778
 	{
780 779
 		//$attribute_in = $attribute;
781 780
 		$values = array();
@@ -784,7 +783,7 @@  discard block
 block discarded – undo
784 783
 		{
785 784
 			unset($attribute['count']);
786 785
 
787
-			foreach($attribute as $key => $value)
786
+			foreach ($attribute as $key => $value)
788 787
 			{
789 788
 				if (!$prefix || stripos($value, $prefix) === 0)
790 789
 				{
@@ -804,7 +803,7 @@  discard block
 block discarded – undo
804 803
 	 */
805 804
 	protected function getLdapConnection()
806 805
 	{
807
-		static $ldap=null;
806
+		static $ldap = null;
808 807
 
809 808
 		if (is_null($ldap)) $ldap = $GLOBALS['egw']->ldap->ldapConnect();
810 809
 
Please login to merge, or discard this patch.
Braces   +73 added lines, -18 removed lines patch added patch discarded remove patch
@@ -290,7 +290,10 @@  discard block
 block discarded – undo
290 290
 			{
291 291
 				foreach($allValues[0][static::MAIL_ATTR] as $key => $value)
292 292
 				{
293
-					if ($key === 'count') continue;
293
+					if ($key === 'count')
294
+					{
295
+						continue;
296
+					}
294 297
 
295 298
 					$emailAddresses[] = array (
296 299
 						'name'		=> $realName,
@@ -311,7 +314,10 @@  discard block
 block discarded – undo
311 314
 				}
312 315
 			}
313 316
 		}
314
-		if ($this->debug) error_log(__METHOD__."('$_accountName') returning ".array2string($emailAddresses));
317
+		if ($this->debug)
318
+		{
319
+			error_log(__METHOD__."('$_accountName') returning ".array2string($emailAddresses));
320
+		}
315 321
 
316 322
 		return $emailAddresses;
317 323
 	}
@@ -344,7 +350,10 @@  discard block
 block discarded – undo
344 350
 		}
345 351
 		elseif (strpos($user, '@') === false)
346 352
 		{
347
-			if (is_numeric($user)) $user = $GLOBALS['egw']->accounts->id2name($user);
353
+			if (is_numeric($user))
354
+			{
355
+				$user = $GLOBALS['egw']->accounts->id2name($user);
356
+			}
348 357
 			$filter = '(&'.static::USER_FILTER.'('.static::USER_ATTR.'='.ldap::quote($user).'))';
349 358
 		}
350 359
 		else	// email address --> build filter by attributes defined in config
@@ -361,7 +370,10 @@  discard block
 block discarded – undo
361 370
 			else
362 371
 			{
363 372
 				$to_or = array('('.static::MAIL_ATTR.'='.ldap::quote($user).')');
364
-				if ($match_uid_at_domain) $to_or[] = '('.static::USER_ATTR.'='.ldap::quote($namepart).')';
373
+				if ($match_uid_at_domain)
374
+				{
375
+					$to_or[] = '('.static::USER_ATTR.'='.ldap::quote($namepart).')';
376
+				}
365 377
 				if (static::ALIAS_ATTR)
366 378
 				{
367 379
 					$to_or[] = '('.static::ALIAS_ATTR.'='.static::ALIAS_PREFIX.ldap::quote($user).')';
@@ -386,11 +398,17 @@  discard block
 block discarded – undo
386 398
 		if ($sri)
387 399
 		{
388 400
 			$allValues = ldap_get_entries($ldap, $sri);
389
-			if ($this->debug) error_log(__METHOD__."('$user') --> ldap_search(, '$this->search_base', '$filter') --> ldap_get_entries=".array2string($allValues[0]));
401
+			if ($this->debug)
402
+			{
403
+				error_log(__METHOD__."('$user') --> ldap_search(, '$this->search_base', '$filter') --> ldap_get_entries=".array2string($allValues[0]));
404
+			}
390 405
 
391 406
 			foreach($allValues as $key => $values)
392 407
 			{
393
-				if ($key === 'count') continue;
408
+				if ($key === 'count')
409
+				{
410
+					continue;
411
+				}
394 412
 
395 413
 				// groups are always active (if they have an email) and allways forwardOnly
396 414
 				if (in_array(static::GROUP_SCHEMA, $values['objectclass']))
@@ -415,11 +433,14 @@  discard block
 block discarded – undo
415 433
 					}
416 434
 					if (static::FORWARD_ONLY_ATTR)
417 435
 					{
418
-						if (static::FORWARD_ONLY)	// check caseinsensitiv for existence of that value
436
+						if (static::FORWARD_ONLY)
437
+						{
438
+							// check caseinsensitiv for existence of that value
419 439
 						{
420 440
 							$deliveryMode = self::getAttributePrefix($values[static::FORWARD_ONLY_ATTR], static::FORWARD_ONLY) ?
421 441
 								emailadmin_smtp::FORWARD_ONLY : '';
422 442
 						}
443
+						}
423 444
 						else	// check for existence of any value
424 445
 						{
425 446
 							$deliveryMode = $values[static::FORWARD_ONLY_ATTR]['count'] > 0 ?
@@ -452,7 +473,10 @@  discard block
 block discarded – undo
452 473
 				}
453 474
 
454 475
 				// regular user-data can only be from users, NOT groups
455
-				if (in_array(static::GROUP_SCHEMA, $values['objectclass'])) continue;
476
+				if (in_array(static::GROUP_SCHEMA, $values['objectclass']))
477
+				{
478
+					continue;
479
+				}
456 480
 
457 481
 				$userData['mailLocalAddress'] = $values[static::MAIL_ATTR][0];
458 482
 				$userData['accountStatus'] = $accountStatus;
@@ -474,7 +498,10 @@  discard block
 block discarded – undo
474 498
 					$userData['mailForwardingAddress']	= self::getAttributePrefix($values[static::FORWARD_ATTR], static::FORWARD_PREFIX);
475 499
 				}
476 500
 
477
-				if (static::MAILBOX_ATTR) $userData['mailMessageStore']	= $values[static::MAILBOX_ATTR][0];
501
+				if (static::MAILBOX_ATTR)
502
+				{
503
+					$userData['mailMessageStore']	= $values[static::MAILBOX_ATTR][0];
504
+				}
478 505
 
479 506
 				$userData['deliveryMode'] = $deliveryMode;
480 507
 
@@ -493,7 +520,10 @@  discard block
 block discarded – undo
493 520
 				}
494 521
 			}
495 522
 		}
496
-		if ($this->debug) error_log(__METHOD__."('$user') returning ".array2string($userData));
523
+		if ($this->debug)
524
+		{
525
+			error_log(__METHOD__."('$user') returning ".array2string($userData));
526
+		}
497 527
 
498 528
 		return $userData;
499 529
 	}
@@ -611,7 +641,10 @@  discard block
 block discarded – undo
611 641
 
612 642
 		$this->addAccountExtra(array('location' => 'setUserData'), $allValues[0], $newData);
613 643
 
614
-		if ($this->debug) error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'$accountDN',".array2string($newData).')');
644
+		if ($this->debug)
645
+		{
646
+			error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'$accountDN',".array2string($newData).')');
647
+		}
615 648
 
616 649
 		return ldap_mod_replace($ldap, $accountDN, $newData);
617 650
 	}
@@ -694,7 +727,10 @@  discard block
 block discarded – undo
694 727
 				// merge in again all new set forwards incl. opt. prefix
695 728
 				self::setAttributePrefix($newData[static::FORWARD_ATTR], $forwards, static::FORWARD_PREFIX);
696 729
 			}
697
-			if ($this->debug) error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'{$allValues[0]['dn']}',".array2string($newData).')');
730
+			if ($this->debug)
731
+			{
732
+				error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'{$allValues[0]['dn']}',".array2string($newData).')');
733
+			}
698 734
 
699 735
 			return ldap_modify ($ds, $allValues[0]['dn'], $newData);
700 736
 		}
@@ -740,7 +776,11 @@  discard block
 block discarded – undo
740 776
 		$mailboxes = array();
741 777
 		foreach($entries as $entry)
742 778
 		{
743
-			if ($entry[static::USER_ATTR][0] == 'anonymous') continue;	// anonymous is never a mail-user!
779
+			if ($entry[static::USER_ATTR][0] == 'anonymous')
780
+			{
781
+				continue;
782
+			}
783
+			// anonymous is never a mail-user!
744 784
 			list($mailbox) = explode('@', $entry[static::MAILBOX_ATTR ? static::MAILBOX_ATTR : static::MAIL_ATTR][0]);
745 785
 			$mailboxes[$entry[static::USER_ATTR][0]] = $mailbox;
746 786
 		}
@@ -757,8 +797,14 @@  discard block
 block discarded – undo
757 797
 	protected static function setAttributePrefix(&$attribute, $values, $prefix='')
758 798
 	{
759 799
 		//$attribute_in = $attribute;
760
-		if (empty($attribute)) $attribute = array();
761
-		if (!is_array($attribute)) $attribute = (array)$attribute;
800
+		if (empty($attribute))
801
+		{
802
+			$attribute = array();
803
+		}
804
+		if (!is_array($attribute))
805
+		{
806
+			$attribute = (array)$attribute;
807
+		}
762 808
 
763 809
 		foreach((array)$values as $value)
764 810
 		{
@@ -788,12 +834,18 @@  discard block
 block discarded – undo
788 834
 			{
789 835
 				if (!$prefix || stripos($value, $prefix) === 0)
790 836
 				{
791
-					if ($remove) unset($attribute[$key]);
837
+					if ($remove)
838
+					{
839
+						unset($attribute[$key]);
840
+					}
792 841
 					$values[] = substr($value, strlen($prefix));
793 842
 				}
794 843
 			}
795 844
 			// reindex $attribute, if neccessary
796
-			if ($values && $attribute) $attribute = array_values($attribute);
845
+			if ($values && $attribute)
846
+			{
847
+				$attribute = array_values($attribute);
848
+			}
797 849
 		}
798 850
 		//error_log(__METHOD__."(".array2string($attribute_in).", '$prefix', $remove) attribute=".array2string($attribute).' returning '.array2string($values));
799 851
 		return $values;
@@ -806,7 +858,10 @@  discard block
 block discarded – undo
806 858
 	{
807 859
 		static $ldap=null;
808 860
 
809
-		if (is_null($ldap)) $ldap = $GLOBALS['egw']->ldap->ldapConnect();
861
+		if (is_null($ldap))
862
+		{
863
+			$ldap = $GLOBALS['egw']->ldap->ldapConnect();
864
+		}
810 865
 
811 866
 		return $ldap;
812 867
 	}
Please login to merge, or discard this patch.
emailadmin/inc/class.emailadmin_smtp_sql.inc.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	/**
56 56
 	 * Constructor
57 57
 	 *
58
-	 * @param string $defaultDomain=null
58
+	 * @param string $defaultDomain
59 59
 	 */
60 60
 	function __construct($defaultDomain=null)
61 61
 	{
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 	 * from all accounts!
102 102
 	 *
103 103
 	 * @param int|string $user numerical account-id, account-name or email address
104
-	 * @param boolean $match_uid_at_domain=true true: uid@domain matches, false only an email or alias address matches
104
+	 * @param boolean $match_uid_at_domain true: uid@domain matches, false only an email or alias address matches
105 105
 	 * @return array with values for keys 'mailLocalAddress', 'mailAlternateAddress' (array), 'mailForwardingAddress' (array),
106 106
 	 * 	'accountStatus' ("active"), 'quotaLimit' and 'deliveryMode' ("forwardOnly")
107 107
 	 */
@@ -227,8 +227,8 @@  discard block
 block discarded – undo
227 227
 	 * @param string $_accountStatus
228 228
 	 * @param string $_mailLocalAddress
229 229
 	 * @param int $_quota in MB
230
-	 * @param boolean $_forwarding_only=false true: store only forwarding info, used internally by saveSMTPForwarding
231
-	 * @param string $_setMailbox=null used only for account migration
230
+	 * @param boolean $_forwarding_only true: store only forwarding info, used internally by saveSMTPForwarding
231
+	 * @param string $_setMailbox used only for account migration
232 232
 	 * @return boolean true on success, false on error writing to ldap
233 233
 	 */
234 234
 	function setUserData($_uidnumber, array $_mailAlternateAddress, array $_mailForwardingAddress, $_deliveryMode,
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	 *
64 64
 	 * @param string $defaultDomain =null
65 65
 	 */
66
-	function __construct($defaultDomain=null)
66
+	function __construct($defaultDomain = null)
67 67
 	{
68 68
 		parent::__construct($defaultDomain);
69 69
 
@@ -78,16 +78,16 @@  discard block
 block discarded – undo
78 78
 	 */
79 79
 	function getAccountEmailAddress($_accountName)
80 80
 	{
81
-		$emailAddresses	= parent::getAccountEmailAddress($_accountName);
81
+		$emailAddresses = parent::getAccountEmailAddress($_accountName);
82 82
 
83 83
 		if (($account_id = $this->accounts->name2id($_accountName, 'account_lid', 'u')))
84 84
 		{
85
-			foreach($this->db->select(self::TABLE, 'mail_value', array(
85
+			foreach ($this->db->select(self::TABLE, 'mail_value', array(
86 86
 				'account_id' => $account_id,
87 87
 				'mail_type' => self::TYPE_ALIAS,
88 88
 			), __LINE__, __FILE__, false, 'ORDER BY mail_value', self::APP) as $row)
89 89
 			{
90
-				$emailAddresses[] = array (
90
+				$emailAddresses[] = array(
91 91
 					'name'		=> $emailAddresses[0]['name'],
92 92
 					'address'	=> $row['mail_value'],
93 93
 					'type'		=> 'alternate',
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 	 * @return array with values for keys 'mailLocalAddress', 'mailAlternateAddress' (array), 'mailForwardingAddress' (array),
112 112
 	 * 	'accountStatus' ("active"), 'quotaLimit' and 'deliveryMode' ("forwardOnly")
113 113
 	 */
114
-	function getUserData($user, $match_uid_at_domain=false)
114
+	function getUserData($user, $match_uid_at_domain = false)
115 115
 	{
116 116
 		$userData = array();
117 117
 
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 			{
141 141
 				$account_id[] = $id;
142 142
 			}
143
-			foreach($this->db->select(self::TABLE, 'account_id', array(
143
+			foreach ($this->db->select(self::TABLE, 'account_id', array(
144 144
 				'mail_type' => self::TYPE_ALIAS,
145 145
 				'mail_value' => $user,
146 146
 			), __LINE__, __FILE__, false, '', self::APP) as $row)
@@ -156,11 +156,11 @@  discard block
 block discarded – undo
156 156
 				$userData['mailLocalAddress'] = $this->accounts->id2name($account_id, 'account_email');
157 157
 			}
158 158
 			$enabled = $forwardOnly = array();
159
-			foreach($this->db->select(self::TABLE, '*', array(
159
+			foreach ($this->db->select(self::TABLE, '*', array(
160 160
 				'account_id' => $account_id,
161 161
 			), __LINE__, __FILE__, false, 'ORDER BY mail_type,mail_value', self::APP) as $row)
162 162
 			{
163
-				switch($row['mail_type'])
163
+				switch ($row['mail_type'])
164 164
 				{
165 165
 					case self::TYPE_ENABLED:
166 166
 						$userData['accountStatus'] = $row['mail_value'];
@@ -203,11 +203,11 @@  discard block
 block discarded – undo
203 203
 			if (is_array($account_id))
204 204
 			{
205 205
 				// add group-members for groups as forward (that way we dont need to store&update them)
206
-				foreach($account_id as $id)
206
+				foreach ($account_id as $id)
207 207
 				{
208 208
 					if ($id < 0 && ($members = $this->accounts->members($id, true)))
209 209
 					{
210
-						foreach($members as $member)
210
+						foreach ($members as $member)
211 211
 						{
212 212
 							if (($email = $this->accounts->id2name($member, 'account_email')) && !in_array($email, (array)$userData['forward']))
213 213
 							{
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 	 * @return boolean true on success, false on error writing to ldap
239 239
 	 */
240 240
 	function setUserData($_uidnumber, array $_mailAlternateAddress, array $_mailForwardingAddress, $_deliveryMode,
241
-		$_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only=false, $_setMailbox=null)
241
+		$_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only = false, $_setMailbox = null)
242 242
 	{
243 243
 		if ($this->debug) error_log(__METHOD__."($_uidnumber, ".array2string($_mailAlternateAddress).', '.array2string($_mailForwardingAddress).", '$_deliveryMode', '$_accountStatus', '$_mailLocalAddress', $_quota, forwarding_only=".array2string($_forwarding_only).') '.function_backtrace());
244 244
 
@@ -257,22 +257,22 @@  discard block
 block discarded – undo
257 257
 		if ($_forwarding_only) $where['mail_type'] = array(self::TYPE_FORWARD, self::TYPE_DELIVERY);
258 258
 		// find all invalid values: either delete or update them
259 259
 		$delete_ids = array();
260
-		foreach($this->db->select(self::TABLE, '*', $where, __LINE__, __FILE__, false, '', self::APP) as $row)
260
+		foreach ($this->db->select(self::TABLE, '*', $where, __LINE__, __FILE__, false, '', self::APP) as $row)
261 261
 		{
262
-			switch($row['mail_type'])
262
+			switch ($row['mail_type'])
263 263
 			{
264 264
 				case self::TYPE_ALIAS:
265
-					$new_addresses =& $_mailAlternateAddress;
265
+					$new_addresses = & $_mailAlternateAddress;
266 266
 					// fall-throught
267 267
 				case self::TYPE_FORWARD:
268
-					if ($row['mail_type'] == self::TYPE_FORWARD) $new_addresses =& $_mailForwardingAddress;
268
+					if ($row['mail_type'] == self::TYPE_FORWARD) $new_addresses = & $_mailForwardingAddress;
269 269
 					if (($key = array_search($row['mail_value'], $new_addresses)) === false)
270 270
 					{
271 271
 						$delete_ids[] = $row['mail_id'];
272 272
 					}
273 273
 					else
274 274
 					{
275
-						unset($new_addresses[$key]);	// no need to store
275
+						unset($new_addresses[$key]); // no need to store
276 276
 					}
277 277
 					break;
278 278
 
@@ -322,14 +322,14 @@  discard block
 block discarded – undo
322 322
 			));
323 323
 		}
324 324
 		// store all new values
325
-		foreach($flags+array(
325
+		foreach ($flags + array(
326 326
 			self::TYPE_ALIAS => $_mailAlternateAddress,
327 327
 			self::TYPE_FORWARD => $_mailForwardingAddress,
328 328
 		) as $type => $values)
329 329
 		{
330 330
 			if ($values && (!$_forwarding_only || in_array($type, array(self::TYPE_FORWARD, self::TYPE_DELIVERY))))
331 331
 			{
332
-				foreach((array)$values as $value)
332
+				foreach ((array)$values as $value)
333 333
 				{
334 334
 					$this->db->insert(self::TABLE, array(
335 335
 						'account_id' => $_uidnumber,
@@ -363,11 +363,11 @@  discard block
 block discarded – undo
363 363
 			$join .= ' JOIN '.self::TABLE.' active ON active.account_id='.self::TABLE.'.account_id AND active.mail_type='.self::TYPE_ENABLED;
364 364
 		}
365 365
 		$mailboxes = array();
366
-		foreach($this->db->select(self::TABLE, 'account_lid AS uid,'.self::TABLE.'.mail_value AS mailbox',
366
+		foreach ($this->db->select(self::TABLE, 'account_lid AS uid,'.self::TABLE.'.mail_value AS mailbox',
367 367
 			self::TABLE.'.mail_type='.self::TYPE_MAILBOX,
368 368
 			__LINE__, __FILE__, false, 'ORDER BY account_lid', self::APP, 0, $join) as $row)
369 369
 		{
370
-			if ($row['uid'] == 'anonymous') continue;	// anonymous is never a mail-user!
370
+			if ($row['uid'] == 'anonymous') continue; // anonymous is never a mail-user!
371 371
 			list($mailbox) = explode('@', $row['mailbox']);
372 372
 			$mailboxes[$row['uid']] = $mailbox;
373 373
 		}
Please login to merge, or discard this patch.
Braces   +29 added lines, -7 removed lines patch added patch discarded remove patch
@@ -94,7 +94,10 @@  discard block
 block discarded – undo
94 94
 				);
95 95
 			}
96 96
 		}
97
-		if ($this->debug) error_log(__METHOD__."('$_accountName') returning ".array2string($emailAddresses));
97
+		if ($this->debug)
98
+		{
99
+			error_log(__METHOD__."('$_accountName') returning ".array2string($emailAddresses));
100
+		}
98 101
 
99 102
 		return $emailAddresses;
100 103
 	}
@@ -145,7 +148,10 @@  discard block
 block discarded – undo
145 148
 				'mail_value' => $user,
146 149
 			), __LINE__, __FILE__, false, '', self::APP) as $row)
147 150
 			{
148
-				if (!in_array($row['account_id'], $account_id)) $account_id[] = $row['account_id'];
151
+				if (!in_array($row['account_id'], $account_id))
152
+				{
153
+					$account_id[] = $row['account_id'];
154
+				}
149 155
 			}
150 156
 			//error_log(__METHOD__."('$user') account_id=".array2string($account_id));
151 157
 		}
@@ -218,7 +224,10 @@  discard block
 block discarded – undo
218 224
 				}
219 225
 			}
220 226
 		}
221
-		if ($this->debug) error_log(__METHOD__."('$user') returning ".array2string($userData));
227
+		if ($this->debug)
228
+		{
229
+			error_log(__METHOD__."('$user') returning ".array2string($userData));
230
+		}
222 231
 
223 232
 		return $userData;
224 233
 	}
@@ -240,7 +249,10 @@  discard block
 block discarded – undo
240 249
 	function setUserData($_uidnumber, array $_mailAlternateAddress, array $_mailForwardingAddress, $_deliveryMode,
241 250
 		$_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only=false, $_setMailbox=null)
242 251
 	{
243
-		if ($this->debug) error_log(__METHOD__."($_uidnumber, ".array2string($_mailAlternateAddress).', '.array2string($_mailForwardingAddress).", '$_deliveryMode', '$_accountStatus', '$_mailLocalAddress', $_quota, forwarding_only=".array2string($_forwarding_only).') '.function_backtrace());
252
+		if ($this->debug)
253
+		{
254
+			error_log(__METHOD__."($_uidnumber, ".array2string($_mailAlternateAddress).', '.array2string($_mailForwardingAddress).", '$_deliveryMode', '$_accountStatus', '$_mailLocalAddress', $_quota, forwarding_only=".array2string($_forwarding_only).') '.function_backtrace());
255
+		}
244 256
 
245 257
 		if (!$_forwarding_only && $this->accounts->id2name($_uidnumber, 'account_email') !== $_mailLocalAddress)
246 258
 		{
@@ -254,7 +266,10 @@  discard block
 block discarded – undo
254 266
 			self::TYPE_QUOTA => $_quota,
255 267
 		);
256 268
 		$where = array('account_id' => $_uidnumber);
257
-		if ($_forwarding_only) $where['mail_type'] = array(self::TYPE_FORWARD, self::TYPE_DELIVERY);
269
+		if ($_forwarding_only)
270
+		{
271
+			$where['mail_type'] = array(self::TYPE_FORWARD, self::TYPE_DELIVERY);
272
+		}
258 273
 		// find all invalid values: either delete or update them
259 274
 		$delete_ids = array();
260 275
 		foreach($this->db->select(self::TABLE, '*', $where, __LINE__, __FILE__, false, '', self::APP) as $row)
@@ -265,7 +280,10 @@  discard block
 block discarded – undo
265 280
 					$new_addresses =& $_mailAlternateAddress;
266 281
 					// fall-throught
267 282
 				case self::TYPE_FORWARD:
268
-					if ($row['mail_type'] == self::TYPE_FORWARD) $new_addresses =& $_mailForwardingAddress;
283
+					if ($row['mail_type'] == self::TYPE_FORWARD)
284
+					{
285
+						$new_addresses =& $_mailForwardingAddress;
286
+					}
269 287
 					if (($key = array_search($row['mail_value'], $new_addresses)) === false)
270 288
 					{
271 289
 						$delete_ids[] = $row['mail_id'];
@@ -367,7 +385,11 @@  discard block
 block discarded – undo
367 385
 			self::TABLE.'.mail_type='.self::TYPE_MAILBOX,
368 386
 			__LINE__, __FILE__, false, 'ORDER BY account_lid', self::APP, 0, $join) as $row)
369 387
 		{
370
-			if ($row['uid'] == 'anonymous') continue;	// anonymous is never a mail-user!
388
+			if ($row['uid'] == 'anonymous')
389
+			{
390
+				continue;
391
+			}
392
+			// anonymous is never a mail-user!
371 393
 			list($mailbox) = explode('@', $row['mailbox']);
372 394
 			$mailboxes[$row['uid']] = $mailbox;
373 395
 		}
Please login to merge, or discard this patch.
etemplate/doc/et_media/inc/class.ui_et_media.inc.php 3 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -127,8 +127,7 @@
 block discarded – undo
127 127
 	/**
128 128
 	 * Show files shared
129 129
 	 *
130
-	 * @param array $content=null
131
-	 * @param string $msg=''
130
+	 * @param array $content
132 131
 	 */
133 132
 	public function index(array $content=null)
134 133
 	{
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @version $Id$ 
11 11
  */
12 12
 
13
-include_once(EGW_INCLUDE_ROOT . '/et_media/inc/class.bo_et_media.inc.php');
13
+include_once(EGW_INCLUDE_ROOT.'/et_media/inc/class.bo_et_media.inc.php');
14 14
 
15 15
 class ui_et_media extends bo_et_media
16 16
 {
@@ -31,9 +31,9 @@  discard block
 block discarded – undo
31 31
 	 */
32 32
 	function ui_et_media()
33 33
 	{
34
-		$this->bo_et_media();	// calling the constructor of the extended bo object
34
+		$this->bo_et_media(); // calling the constructor of the extended bo object
35 35
 
36
-		$this->tmpl =& CreateObject('etemplate.etemplate','et_media.edit');
36
+		$this->tmpl = & CreateObject('etemplate.etemplate', 'et_media.edit');
37 37
 	}
38 38
 
39 39
 	/**
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 * @param array $content=null
43 43
 	 * @param string $msg=''
44 44
 	 */
45
-	function edit($content=null,$msg = '')
45
+	function edit($content = null, $msg = '')
46 46
 	{
47 47
 		if (is_array($content))	// not first call from index
48 48
 		{
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 			{
63 63
 				unset($content['id']);
64 64
 				unset($content['read']);
65
-				$found = $this->search($content,False,'name,author');
65
+				$found = $this->search($content, False, 'name,author');
66 66
 
67 67
 				if (!$found)
68 68
 				{
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 		$no_button = array(
109 109
 			'delete' => !$this->data[$this->db_key_cols[$this->autoinc_id]]
110 110
 		);
111
-		$this->tmpl->exec('et_media.ui_et_media.edit',$content,$sel_options,$no_button,array(
111
+		$this->tmpl->exec('et_media.ui_et_media.edit', $content, $sel_options, $no_button, array(
112 112
 			'id' => $this->data['id']
113 113
 		));
114 114
 	}
@@ -118,20 +118,20 @@  discard block
 block discarded – undo
118 118
 	 *
119 119
 	 * @param array $found
120 120
 	 */
121
-	function show($found=null)
121
+	function show($found = null)
122 122
 	{
123 123
 		if (!is_array($found) || !count($found))
124 124
 		{
125 125
 			$this->edit();
126 126
 			return;
127 127
 		}
128
-		array_unshift($found,false);	// change the array to start with index 1
128
+		array_unshift($found, false); // change the array to start with index 1
129 129
 		$content = array(
130
-			'msg' => lang('%1 matches on search criteria',count($found)),
130
+			'msg' => lang('%1 matches on search criteria', count($found)),
131 131
 			'entry' => $found,
132 132
 		);
133 133
 		$this->tmpl->read('et_media.show');
134 134
 
135
-		$this->tmpl->exec('et_media.ui_et_media.edit',$content);
135
+		$this->tmpl->exec('et_media.ui_et_media.edit', $content);
136 136
 	}
137 137
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,11 +44,14 @@
 block discarded – undo
44 44
 	 */
45 45
 	function edit($content=null,$msg = '')
46 46
 	{
47
-		if (is_array($content))	// not first call from index
47
+		if (is_array($content))
48
+		{
49
+			// not first call from index
48 50
 		{
49 51
 			if ($content['id'] > 0)
50 52
 			{
51 53
 				$this->read($content);
54
+		}
52 55
 			}
53 56
 			//echo "<p>edit: content ="; _debug_array($content);
54 57
 			$this->data_merge($content);
Please login to merge, or discard this patch.