Completed
Push — 14.2 ( bb1aaa...cd00e9 )
by Klaus
28:13
created
emailadmin/inc/class.emailadmin_wizard.inc.php 1 patch
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 * @var array
84 84
 	 */
85 85
 	public static $ssl_types = array(
86
-		self::SSL_TLS => 'TLS',	// SSL with minimum TLS (no SSL v.2 or v.3), requires Horde_Imap_Client-2.16.0/Horde_Socket_Client-1.1.0
86
+		self::SSL_TLS => 'TLS', // SSL with minimum TLS (no SSL v.2 or v.3), requires Horde_Imap_Client-2.16.0/Horde_Socket_Client-1.1.0
87 87
 		self::SSL_SSL => 'SSL',
88 88
 		self::SSL_STARTTLS => 'STARTTLS',
89 89
 		'no' => 'no',
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	public static $ssl2secure = array(
97 97
 		'SSL' => 'ssl',
98 98
 		'STARTTLS' => 'tls',
99
-		'TLS' => 'tlsv1',	// SSL with minimum TLS (no SSL v.2 or v.3), requires Horde_Imap_Client-2.16.0/Horde_Socket_Client-1.1.0
99
+		'TLS' => 'tlsv1', // SSL with minimum TLS (no SSL v.2 or v.3), requires Horde_Imap_Client-2.16.0/Horde_Socket_Client-1.1.0
100 100
 	);
101 101
 	/**
102 102
 	 * Convert ssl-type to eMailAdmin acc_(imap|sieve|smtp)_ssl integer value
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	 * @param array $content
163 163
 	 * @param type $msg
164 164
 	 */
165
-	public function add(array $content=array(), $msg='', $msg_type='success')
165
+	public function add(array $content = array(), $msg = '', $msg_type = 'success')
166 166
 	{
167 167
 		// otherwise we cant switch to ckeditor in edit
168 168
 		egw_ckeditor_config::set_csp_script_src_attrs();
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 		if ($content['button'] && key($content['button']) == 'skip_imap')
203 203
 		{
204 204
 			unset($content['button']);
205
-			if (!isset($content['acc_smtp_host'])) $content['acc_smtp_host'] = '';	// do manual mode right away
205
+			if (!isset($content['acc_smtp_host'])) $content['acc_smtp_host'] = ''; // do manual mode right away
206 206
 			return $this->smtp($content, lang('Skipping IMAP configuration!'));
207 207
 		}
208 208
 		$content['output'] = '';
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 		if (!empty($content['acc_imap_host']))
217 217
 		{
218 218
 			$hosts = array($content['acc_imap_host'] => true);
219
-			if ($content['acc_imap_port'] > 0 && !in_array($content['acc_imap_port'], array(143,993)))
219
+			if ($content['acc_imap_port'] > 0 && !in_array($content['acc_imap_port'], array(143, 993)))
220 220
 			{
221 221
 				$ssl_type = (string)array_search($content['acc_imap_ssl'], self::$ssl2type);
222 222
 				if ($ssl_type === '') $ssl_type = 'insecure';
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 			$content['ispdb'] = $ispdb;
231 231
 			$content['output'] .= lang('Using data from Mozilla ISPDB for provider %1', $ispdb['displayName'])."\n";
232 232
 			$hosts = array();
233
-			foreach($ispdb['imap'] as $server)
233
+			foreach ($ispdb['imap'] as $server)
234 234
 			{
235 235
 				if (!isset($hosts[$server['hostname']]))
236 236
 				{
@@ -254,13 +254,13 @@  discard block
 block discarded – undo
254 254
 		}
255 255
 
256 256
 		// iterate over all hosts and try to connect
257
-		foreach($hosts as $host => $data)
257
+		foreach ($hosts as $host => $data)
258 258
 		{
259 259
 			$content['acc_imap_host'] = $host;
260 260
 			// by default we check SSL, STARTTLS and at last an insecure connection
261 261
 			if (!is_array($data)) $data = array('TLS' => 993, 'SSL' => 993, 'STARTTLS' => 143, 'insecure' => 143);
262 262
 
263
-			foreach($data as $ssl => $port)
263
+			foreach ($data as $ssl => $port)
264 264
 			{
265 265
 				if ($ssl === 'username') continue;
266 266
 
@@ -285,17 +285,17 @@  discard block
 block discarded – undo
285 285
 					$content['connected'] = $connected = true;
286 286
 					break 2;
287 287
 				}
288
-				catch(Horde_Imap_Client_Exception $e)
288
+				catch (Horde_Imap_Client_Exception $e)
289 289
 				{
290
-					switch($e->getCode())
290
+					switch ($e->getCode())
291 291
 					{
292 292
 						case Horde_Imap_Client_Exception::LOGIN_AUTHENTICATIONFAILED:
293 293
 							$content['output'] .= "\n".$e->getMessage()."\n";
294
-							break 3;	// no need to try other SSL or non-SSL connections, if auth failed
294
+							break 3; // no need to try other SSL or non-SSL connections, if auth failed
295 295
 
296 296
 						case Horde_Imap_Client_Exception::SERVER_CONNECT:
297 297
 							$content['output'] .= "\n".$e->getMessage()."\n";
298
-							if ($ssl == 'STARTTLS') break 2;	// no need to try insecure connection on same port
298
+							if ($ssl == 'STARTTLS') break 2; // no need to try insecure connection on same port
299 299
 							break;
300 300
 
301 301
 						default:
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 					}
305 305
 					if (self::$debug) _egw_log_exception($e);
306 306
 				}
307
-				catch(Exception $e) {
307
+				catch (Exception $e) {
308 308
 					$content['output'] .= "\n".get_class($e).': '.$e->getMessage().' ('.$e->getCode().')'."\n";
309 309
 					//$content['output'] .= $e->getTraceAsString()."\n";
310 310
 					if (self::$debug) _egw_log_exception($e);
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 		// add validation error, if we can identify a field
321 321
 		if (!$connected && $e instanceof Horde_Imap_Client_Exception)
322 322
 		{
323
-			switch($e->getCode())
323
+			switch ($e->getCode())
324 324
 			{
325 325
 				case Horde_Imap_Client_Exception::LOGIN_AUTHENTICATIONFAILED:
326 326
 					etemplate_new::set_validation_error('acc_imap_username', lang($e->getMessage()));
@@ -346,13 +346,13 @@  discard block
 block discarded – undo
346 346
 	 * @param string $msg =''
347 347
 	 * @param Horde_Imap_Client_Socket $imap =null
348 348
 	 */
349
-	public function folder(array $content, $msg='', Horde_Imap_Client_Socket $imap=null)
349
+	public function folder(array $content, $msg = '', Horde_Imap_Client_Socket $imap = null)
350 350
 	{
351 351
 		if (isset($content['button']))
352 352
 		{
353 353
 			list($button) = each($content['button']);
354 354
 			unset($content['button']);
355
-			switch($button)
355
+			switch ($button)
356 356
 			{
357 357
 				case 'back':
358 358
 					return $this->add($content);
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 			}
363 363
 		}
364 364
 		$content['msg'] = $msg;
365
-		if (!isset($imap)) $imap = self::imap_client ($content);
365
+		if (!isset($imap)) $imap = self::imap_client($content);
366 366
 
367 367
 		try {
368 368
 			//_debug_array($content);
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 				$sel_options['acc_folder_draft'] = $sel_options['acc_folder_template'] =
371 371
 					$sel_options['acc_folder_junk'] = self::mailboxes($imap, $content);
372 372
 		}
373
-		catch(Exception $e) {
373
+		catch (Exception $e) {
374 374
 			$content['msg'] = $e->getMessage();
375 375
 			if (self::$debug) _egw_log_exception($e);
376 376
 		}
@@ -387,27 +387,27 @@  discard block
 block discarded – undo
387 387
 	 * @return array with folders as key AND value
388 388
 	 * @throws Horde_Imap_Client_Exception
389 389
 	 */
390
-	public static function mailboxes(Horde_Imap_Client_Socket $imap, array &$content=null)
390
+	public static function mailboxes(Horde_Imap_Client_Socket $imap, array &$content = null)
391 391
 	{
392 392
 		// query all subscribed mailboxes
393 393
 		$mailboxes = $imap->listMailboxes('*', Horde_Imap_Client::MBOX_SUBSCRIBED, array(
394 394
 			'special_use' => true,
395
-			'attributes' => true,	// otherwise special_use is only queried, but not returned ;-)
395
+			'attributes' => true, // otherwise special_use is only queried, but not returned ;-)
396 396
 			'delimiter' => true,
397 397
 		));
398 398
 		//_debug_array($mailboxes);
399 399
 		// list mailboxes by special-use attributes
400 400
 		$folders = $attributes = $all = array();
401
-		foreach($mailboxes as $mailbox => $data)
401
+		foreach ($mailboxes as $mailbox => $data)
402 402
 		{
403
-			foreach($data['attributes'] as $attribute)
403
+			foreach ($data['attributes'] as $attribute)
404 404
 			{
405 405
 				$attributes[$attribute][] = $mailbox;
406 406
 			}
407 407
 			$folders[$mailbox] = $mailbox.': '.implode(', ', $data['attributes']);
408 408
 		}
409 409
 		// pre-select send, trash, ... folder for user, by checking special-use attributes or common name(s)
410
-		foreach(array(
410
+		foreach (array(
411 411
 			'acc_folder_sent'  => array('\\sent', 'sent'),
412 412
 			'acc_folder_trash' => array('\\trash', 'trash'),
413 413
 			'acc_folder_draft' => array('\\drafts', 'drafts'),
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
 			// first check special-use attributes
419 419
 			if (($special_use = array_shift($common_names)))
420 420
 			{
421
-				foreach((array)$attributes[$special_use] as $mailbox)
421
+				foreach ((array)$attributes[$special_use] as $mailbox)
422 422
 				{
423 423
 					if (empty($content[$name]) || strlen($mailbox) < strlen($content[$name]))
424 424
 					{
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
 			// no special use folder found, try common names
430 430
 			if (empty($content[$name]))
431 431
 			{
432
-				foreach($mailboxes as $mailbox => $data)
432
+				foreach ($mailboxes as $mailbox => $data)
433 433
 				{
434 434
 					$delimiter = !empty($data['delimiter']) ? $data['delimiter'] : '.';
435 435
 					$name_parts = explode($delimiter, strtolower($mailbox));
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
 	 * @param array $content
457 457
 	 * @param string $msg =''
458 458
 	 */
459
-	public function sieve(array $content, $msg='')
459
+	public function sieve(array $content, $msg = '')
460 460
 	{
461 461
 		static $sieve_ssl2port = array(
462 462
 			self::SSL_TLS => 5190,
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
 		{
471 471
 			list($button) = each($content['button']);
472 472
 			unset($content['button']);
473
-			switch($button)
473
+			switch ($button)
474 474
 			{
475 475
 				case 'back':
476 476
 					return $this->folder($content);
@@ -519,9 +519,9 @@  discard block
 block discarded – undo
519 519
 			{
520 520
 				$data = $sieve_ssl2port;
521 521
 			}
522
-			foreach($data as $ssl => $ports)
522
+			foreach ($data as $ssl => $ports)
523 523
 			{
524
-				foreach((array)$ports as $port)
524
+				foreach ((array)$ports as $port)
525 525
 				{
526 526
 					$content['acc_sieve_ssl'] = $ssl;
527 527
 					$ssl_label = self::$ssl_types[$ssl];
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
 						$content['acc_sieve_port'] = $port;
533 533
 						$useTLS = false;
534 534
 						$host = $content['acc_sieve_host'];
535
-						switch($content['acc_sieve_ssl'])
535
+						switch ($content['acc_sieve_ssl'])
536 536
 						{
537 537
 							case self::SSL_SSL:
538 538
 								$host = 'ssl://'.$host;
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
 						{
551 551
 							$sieve->setDebug(true, function($sieve, $_msg) //use (&$content)
552 552
 							{
553
-								unset($sieve);	// not used here
553
+								unset($sieve); // not used here
554 554
 								//$content['sieve_output'] .= "\n".$_msg;
555 555
 								if (($fp = fopen(self::DEBUG_LOG, 'a')))
556 556
 								{
@@ -560,8 +560,8 @@  discard block
 block discarded – undo
560 560
 							});
561 561
 						}
562 562
 						// connect to sieve server
563
-						$sieve->connect($host, $port, $options=null, $useTLS);
564
-						$content['sieve_output'] .= "\n".lang('Successful connected to %1 server%2.', 'Sieve','');
563
+						$sieve->connect($host, $port, $options = null, $useTLS);
564
+						$content['sieve_output'] .= "\n".lang('Successful connected to %1 server%2.', 'Sieve', '');
565 565
 						// and log in
566 566
 						$sieve->login($content['acc_imap_username'], $content['acc_imap_password']);
567 567
 						$content['sieve_output'] .= ' '.lang('and logged in')."\n";
@@ -572,8 +572,8 @@  discard block
 block discarded – undo
572 572
 							' '.lang('and logged in')));
573 573
 					}
574 574
 					// PEAR::setErrorHandling(PEAR_ERROR_EXCEPTION) throws just Exception
575
-					catch(Exception $e) {
576
-						switch($e->getCode())
575
+					catch (Exception $e) {
576
+						switch ($e->getCode())
577 577
 						{
578 578
 							case 61:	// connection refused
579 579
 							case 60:	// connection timed out
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
 		// add validation error, if we can identify a field
600 600
 		if (!$content['sieve_connected'] && $e instanceof Exception)
601 601
 		{
602
-			switch($e->getCode())
602
+			switch ($e->getCode())
603 603
 			{
604 604
 				case 61:	// connection refused
605 605
 				case 60:	// connection timed out (imap.googlemail.com returns that for none-ssl/4190/2000)
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
 	 * @param array $content
623 623
 	 * @param string $msg =''
624 624
 	 */
625
-	public function smtp(array $content, $msg='')
625
+	public function smtp(array $content, $msg = '')
626 626
 	{
627 627
 		static $smtp_ssl2port = array(
628 628
 			self::SSL_NONE => 25,
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
 		{
637 637
 			list($button) = each($content['button']);
638 638
 			unset($content['button']);
639
-			switch($button)
639
+			switch ($button)
640 640
 			{
641 641
 				case 'back':
642 642
 					return $this->sieve($content);
@@ -677,11 +677,11 @@  discard block
 block discarded – undo
677 677
 					);
678 678
 				}
679 679
 			}
680
-			elseif($content['ispdb'] && !empty($content['ispdb']['smtp']))
680
+			elseif ($content['ispdb'] && !empty($content['ispdb']['smtp']))
681 681
 			{
682 682
 				$content['smtp_output'] .= lang('Using data from Mozilla ISPDB for provider %1', $content['ispdb']['displayName'])."\n";
683 683
 				$hosts = array();
684
-				foreach($content['ispdb']['smtp'] as $server)
684
+				foreach ($content['ispdb']['smtp'] as $server)
685 685
 				{
686 686
 					if (!isset($hosts[$server['hostname']]))
687 687
 					{
@@ -703,14 +703,14 @@  discard block
 block discarded – undo
703 703
 			{
704 704
 				$hosts = $this->guess_hosts($content['ident_email'], 'smtp');
705 705
 			}
706
-			foreach($hosts as $host => $data)
706
+			foreach ($hosts as $host => $data)
707 707
 			{
708 708
 				$content['acc_smtp_host'] = $host;
709 709
 				if (!is_array($data))
710 710
 				{
711 711
 					$data = array('TLS' => 465, 'SSL' => 465, 'STARTTLS' => 587, '' => 25);
712 712
 				}
713
-				foreach($data as $ssl => $port)
713
+				foreach ($data as $ssl => $port)
714 714
 				{
715 715
 					if ($ssl === 'username') continue;
716 716
 
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
 						$content['smtp_output'] .= "\n".egw_time::to('now', 'H:i:s').": Trying $ssl connection to $host:$port ...\n";
722 722
 						$content['acc_smtp_port'] = $port;
723 723
 
724
-						$mail = new Horde_Mail_Transport_Smtphorde($params=array(
724
+						$mail = new Horde_Mail_Transport_Smtphorde($params = array(
725 725
 							'username' => $content['acc_smtp_username'],
726 726
 							'password' => $content['acc_smtp_password'],
727 727
 							'host' => $content['acc_smtp_host'],
@@ -761,9 +761,9 @@  discard block
 block discarded – undo
761 761
 					}
762 762
 					// unfortunately LOGIN_AUTHENTICATIONFAILED and SERVER_CONNECT are thrown as Horde_Mail_Exception
763 763
 					// while others are thrown as Horde_Smtp_Exception --> using common base Horde_Exception_Wrapped
764
-					catch(Horde_Exception_Wrapped $e)
764
+					catch (Horde_Exception_Wrapped $e)
765 765
 					{
766
-						switch($e->getCode())
766
+						switch ($e->getCode())
767 767
 						{
768 768
 							case Horde_Smtp_Exception::LOGIN_AUTHENTICATIONFAILED:
769 769
 							case Horde_Smtp_Exception::LOGIN_REQUIREAUTHENTICATION:
@@ -779,14 +779,14 @@  discard block
 block discarded – undo
779 779
 						}
780 780
 						if (self::$debug) _egw_log_exception($e);
781 781
 					}
782
-					catch(Horde_Smtp_Exception $e)
782
+					catch (Horde_Smtp_Exception $e)
783 783
 					{
784 784
 						// prever $e->details over $e->getMessage() as it contains original message from SMTP server (eg. relay access denied)
785 785
 						$content['smtp_output'] .= "\n".(empty($e->details) ? $e->getMessage().' ('.$e->getCode().')' : $e->details)."\n";
786 786
 						//$content['smtp_output'] .= $e->getTraceAsString()."\n";
787 787
 						if (self::$debug) _egw_log_exception($e);
788 788
 					}
789
-					catch(Exception $e) {
789
+					catch (Exception $e) {
790 790
 						$content['smtp_output'] .= "\n".get_class($e).': '.$e->getMessage().' ('.$e->getCode().')'."\n";
791 791
 						//$content['smtp_output'] .= $e->getTraceAsString()."\n";
792 792
 						if (self::$debug) _egw_log_exception($e);
@@ -797,7 +797,7 @@  discard block
 block discarded – undo
797 797
 		// add validation error, if we can identify a field
798 798
 		if (!$content['smtp_connected'] && $e instanceof Horde_Exception_Wrapped)
799 799
 		{
800
-			switch($e->getCode())
800
+			switch ($e->getCode())
801 801
 			{
802 802
 				case Horde_Smtp_Exception::LOGIN_AUTHENTICATIONFAILED:
803 803
 				case Horde_Smtp_Exception::LOGIN_REQUIREAUTHENTICATION:
@@ -831,14 +831,14 @@  discard block
 block discarded – undo
831 831
 	 * @param string $msg =''
832 832
 	 * @param string $msg_type ='success'
833 833
 	 */
834
-	public function edit(array $content=null, $msg='', $msg_type='success')
834
+	public function edit(array $content = null, $msg = '', $msg_type = 'success')
835 835
 	{
836 836
 		// app is trying to tell something, while redirecting to wizard
837
-		if (empty($content) && $_GET['acc_id'] && empty($msg) && !empty( $_GET['msg']))
837
+		if (empty($content) && $_GET['acc_id'] && empty($msg) && !empty($_GET['msg']))
838 838
 		{
839
-			if (stripos($_GET['msg'],'fatal error:')!==false || $_GET['msg_type'] == 'error') $msg_type = 'error';
839
+			if (stripos($_GET['msg'], 'fatal error:') !== false || $_GET['msg_type'] == 'error') $msg_type = 'error';
840 840
 		}
841
-		if ($content['acc_id'] || (isset($_GET['acc_id']) && (int)$_GET['acc_id'] > 0) ) emailadmin_imapbase::unsetCachedObjects($content['acc_id']?$content['acc_id']:$_GET['acc_id']);
841
+		if ($content['acc_id'] || (isset($_GET['acc_id']) && (int)$_GET['acc_id'] > 0)) emailadmin_imapbase::unsetCachedObjects($content['acc_id'] ? $content['acc_id'] : $_GET['acc_id']);
842 842
 		$tpl = new etemplate_new('emailadmin.account');
843 843
 
844 844
 		if (!is_array($content) || !empty($content['acc_id']) && isset($content['old_acc_id']) && $content['acc_id'] != $content['old_acc_id'])
@@ -853,7 +853,7 @@  discard block
 block discarded – undo
853 853
 					list($content['acc_id']) = each($content['accounts']);
854 854
 					//error_log(__METHOD__.__LINE__.'.'.array2string($content['acc_id']));
855 855
 					// test if the "to be selected" acccount is imap or not
856
-					if (count($content['accounts'])>1 && emailadmin_account::is_multiple($content['acc_id']))
856
+					if (count($content['accounts']) > 1 && emailadmin_account::is_multiple($content['acc_id']))
857 857
 					{
858 858
 						try {
859 859
 							$account = emailadmin_account::read($content['acc_id'], $content['called_for']);
@@ -864,7 +864,7 @@  discard block
 block discarded – undo
864 864
 								//error_log(__METHOD__.__LINE__.'.'.array2string($content['acc_id']));
865 865
 							}
866 866
 						}
867
-						catch(egw_exception_not_found $e) {
867
+						catch (egw_exception_not_found $e) {
868 868
 							if (self::$debug) _egw_log_exception($e);
869 869
 						}
870 870
 					}
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
 				try {
888 888
 					$account = emailadmin_account::read($content['acc_id'], $this->is_admin && $content['called_for'] ?
889 889
 						$content['called_for'] : $GLOBALS['egw_info']['user']['account_id']);
890
-					$account->getUserData();	// quota, aliases, forwards etc.
890
+					$account->getUserData(); // quota, aliases, forwards etc.
891 891
 					$content += $account->params;
892 892
 					$content['acc_sieve_enabled'] = (string)($content['acc_sieve_enabled']);
893 893
 					$content['notify_use_default'] = !$content['notify_account_id'];
@@ -898,16 +898,16 @@  discard block
 block discarded – undo
898 898
 					$content['std_ident_id'] = $content['ident_id'];
899 899
 					$content['identities'][$content['std_ident_id']] = lang('Standard identity');
900 900
 					// change self::SSL_NONE (=0) to "no" used in sel_options
901
-					foreach(array('imap','smtp','sieve') as $type)
901
+					foreach (array('imap', 'smtp', 'sieve') as $type)
902 902
 					{
903 903
 						if (!$content['acc_'.$type.'_ssl']) $content['acc_'.$type.'_ssl'] = 'no';
904 904
 					}
905 905
 				}
906
-				catch(egw_exception_not_found $e) {
906
+				catch (egw_exception_not_found $e) {
907 907
 					if (self::$debug) _egw_log_exception($e);
908 908
 					egw_framework::window_close(lang('Account not found!'));
909 909
 				}
910
-				catch(Exception $e) {
910
+				catch (Exception $e) {
911 911
 					if (self::$debug) _egw_log_exception($e);
912 912
 					egw_framework::window_close($e->getMessage().' ('.get_class($e).': '.$e->getCode().')');
913 913
 				}
@@ -915,7 +915,7 @@  discard block
 block discarded – undo
915 915
 			elseif ($content['acc_id'] === 'new')
916 916
 			{
917 917
 				$content['account_id'] = $content['called_for'];
918
-				$content['old_acc_id'] = $content['acc_id'];	// to not call add/wizard, if we return from to
918
+				$content['old_acc_id'] = $content['acc_id']; // to not call add/wizard, if we return from to
919 919
 				unset($content['tabs']);
920 920
 				return $this->add($content);
921 921
 			}
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
 		{
926 926
 			if (!isset($content['account_id'])) $content['account_id'] = array($GLOBALS['egw_info']['user']['account_id']);
927 927
 			$content['acc_user_editable'] = $content['acc_further_identities'] = true;
928
-			$readonlys['ident_id'] = true;	// need to create standard identity first
928
+			$readonlys['ident_id'] = true; // need to create standard identity first
929 929
 		}
930 930
 		if (empty($content['acc_name']))
931 931
 		{
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
 		{
962 962
 			list($button) = each($content['button']);
963 963
 			unset($content['button']);
964
-			switch($button)
964
+			switch ($button)
965 965
 			{
966 966
 				case 'wizard':
967 967
 					// if we just came from wizard, go back to last page/step
@@ -994,7 +994,7 @@  discard block
 block discarded – undo
994 994
 						{
995 995
 							$content['ident_id'] = emailadmin_account::save_identity(array(
996 996
 								'account_id' => $content['called_for'] ? $content['called_for'] : $GLOBALS['egw_info']['user']['account_id'],
997
-							)+$content);
997
+							) + $content);
998 998
 							$content['identities'][$content['ident_id']] = emailadmin_account::identity_name($content);
999 999
 							$msg = lang('Identity saved.');
1000 1000
 							if ($edit_access) $msg .= ' '.lang('Switch back to standard identity to save account.');
@@ -1098,17 +1098,17 @@  discard block
 block discarded – undo
1098 1098
 					catch (Horde_Imap_Client_Exception $e)
1099 1099
 					{
1100 1100
 						_egw_log_exception($e);
1101
-						$tpl->set_validation_error('acc_imap_admin_username', $msg=lang($e->getMessage()).($e->details?', '.lang($e->details):''));
1101
+						$tpl->set_validation_error('acc_imap_admin_username', $msg = lang($e->getMessage()).($e->details ? ', '.lang($e->details) : ''));
1102 1102
 						$msg_type = 'error';
1103
-						$content['tabs'] = 'emailadmin.account.imap';	// should happen automatic
1103
+						$content['tabs'] = 'emailadmin.account.imap'; // should happen automatic
1104 1104
 						break;
1105 1105
 					}
1106 1106
 					catch (PEAR_Exception $e)
1107 1107
 					{
1108 1108
 						_egw_log_exception($e);
1109
-						$tpl->set_validation_error('acc_sieve_port', $msg=lang($e->getMessage()));
1109
+						$tpl->set_validation_error('acc_sieve_port', $msg = lang($e->getMessage()));
1110 1110
 						$msg_type = 'error';
1111
-						$content['tabs'] = 'emailadmin.account.sieve';	// should happen automatic
1111
+						$content['tabs'] = 'emailadmin.account.sieve'; // should happen automatic
1112 1112
 						break;
1113 1113
 					}
1114 1114
 					catch (Exception $e) {
@@ -1117,7 +1117,7 @@  discard block
 block discarded – undo
1117 1117
 						$msg_type = 'error';
1118 1118
 					}
1119 1119
 					if ($content['acc_id']) emailadmin_imapbase::unsetCachedObjects($content['acc_id']);
1120
-					if (stripos($msg,'fatal error:')!==false) $msg_type = 'error';
1120
+					if (stripos($msg, 'fatal error:') !== false) $msg_type = 'error';
1121 1121
 					egw_framework::refresh_opener($msg, 'emailadmin', $content['acc_id'], $new_account ? 'add' : 'update', null, null, null, $msg_type);
1122 1122
 					if ($button == 'save') egw_framework::window_close();
1123 1123
 					break;
@@ -1170,7 +1170,7 @@  discard block
 block discarded – undo
1170 1170
 		if ($this->is_admin && (empty($content['acc_imap_username']) || empty($content['acc_imap_host']) || $content['called_for']))
1171 1171
 		{
1172 1172
 			// cant connection to imap --> allow free entries in taglists
1173
-			foreach(array('acc_folder_sent', 'acc_folder_trash', 'acc_folder_draft', 'acc_folder_template', 'acc_folder_junk') as $folder)
1173
+			foreach (array('acc_folder_sent', 'acc_folder_trash', 'acc_folder_draft', 'acc_folder_template', 'acc_folder_junk') as $folder)
1174 1174
 			{
1175 1175
 				$tpl->setElementAttribute($folder, 'allowFreeEntries', true);
1176 1176
 			}
@@ -1181,15 +1181,15 @@  discard block
 block discarded – undo
1181 1181
 				$sel_options['acc_folder_sent'] = $sel_options['acc_folder_trash'] =
1182 1182
 					$sel_options['acc_folder_draft'] = $sel_options['acc_folder_template'] =
1183 1183
 					$sel_options['acc_folder_junk'] = $sel_options['notify_folders'] =
1184
-						self::mailboxes(self::imap_client ($content));
1184
+						self::mailboxes(self::imap_client($content));
1185 1185
 			}
1186
-			catch(Exception $e) {
1186
+			catch (Exception $e) {
1187 1187
 				if (self::$debug) _egw_log_exception($e);
1188 1188
 				// let user know what the problem is and that he can fix it using wizard or deleting
1189 1189
 				$msg = lang($e->getMessage())."\n\n".lang('You can use wizard to fix account settings or delete account.');
1190 1190
 				$msg_type = 'error';
1191 1191
 				// cant connection to imap --> allow free entries in taglists
1192
-				foreach(array('acc_folder_sent', 'acc_folder_trash', 'acc_folder_draft', 'acc_folder_template', 'acc_folder_junk') as $folder)
1192
+				foreach (array('acc_folder_sent', 'acc_folder_trash', 'acc_folder_draft', 'acc_folder_template', 'acc_folder_junk') as $folder)
1193 1193
 				{
1194 1194
 					$tpl->setElementAttribute($folder, 'allowFreeEntries', true);
1195 1195
 				}
@@ -1286,7 +1286,7 @@  discard block
 block discarded – undo
1286 1286
 		if ($content['called_for'] && $content['acc_id'] > 0)
1287 1287
 		{
1288 1288
 			$admin_actions = array();
1289
-			foreach($GLOBALS['egw']->hooks->process(array(
1289
+			foreach ($GLOBALS['egw']->hooks->process(array(
1290 1290
 				'location' => 'emailadmin_edit',
1291 1291
 				'account_id' => $content['called_for'],
1292 1292
 				'acc_id' => $content['acc_id'],
@@ -1307,7 +1307,7 @@  discard block
 block discarded – undo
1307 1307
 	 * @param string|array &$account_id on return always array
1308 1308
 	 * @param boolean $back =false
1309 1309
 	 */
1310
-	private static function fix_account_id_0(&$account_id=null, $back=false)
1310
+	private static function fix_account_id_0(&$account_id = null, $back = false)
1311 1311
 	{
1312 1312
 		if (!isset($account_id)) return;
1313 1313
 
@@ -1315,7 +1315,7 @@  discard block
 block discarded – undo
1315 1315
 		{
1316 1316
 			$account_id = explode(',', $account_id);
1317 1317
 		}
1318
-		if (($k = array_search($back?'':'0', $account_id)) !== false)
1318
+		if (($k = array_search($back ? '' : '0', $account_id)) !== false)
1319 1319
 		{
1320 1320
 			$account_id[$k] = $back ? '0' : '';
1321 1321
 		}
@@ -1328,7 +1328,7 @@  discard block
 block discarded – undo
1328 1328
 	 * @param int $timeout =null default use value returned by emailadmin_imap::getTimeOut()
1329 1329
 	 * @return Horde_Imap_Client_Socket
1330 1330
 	 */
1331
-	protected static function imap_client(array $content, $timeout=null)
1331
+	protected static function imap_client(array $content, $timeout = null)
1332 1332
 	{
1333 1333
 		return new Horde_Imap_Client_Socket(array(
1334 1334
 			'username' => $content['acc_imap_username'],
@@ -1350,7 +1350,7 @@  discard block
 block discarded – undo
1350 1350
 	protected static function fix_ssl_order($data)
1351 1351
 	{
1352 1352
 		$ordered = array();
1353
-		foreach(array_merge(array('TLS', 'SSL', 'STARTTLS'), array_keys($data)) as $key)
1353
+		foreach (array_merge(array('TLS', 'SSL', 'STARTTLS'), array_keys($data)) as $key)
1354 1354
 		{
1355 1355
 			if (array_key_exists($key, $data)) $ordered[$key] = $data[$key];
1356 1356
 		}
@@ -1368,7 +1368,7 @@  discard block
 block discarded – undo
1368 1368
 	 * @return array with values for keys 'displayName', 'imap', 'smtp', 'pop3', which each contain
1369 1369
 	 *	array of arrays with values for keys 'hostname', 'port', 'socketType'=(SSL|STARTTLS), 'username'=%EMAILADDRESS%
1370 1370
 	 */
1371
-	protected static function mozilla_ispdb($domain, $try_mx=true)
1371
+	protected static function mozilla_ispdb($domain, $try_mx = true)
1372 1372
 	{
1373 1373
 		if (strpos($domain, '@') !== false) list(,$domain) = explode('@', $domain);
1374 1374
 
@@ -1379,17 +1379,17 @@  discard block
 block discarded – undo
1379 1379
 			$provider = array(
1380 1380
 				'displayName' => (string)$xml->emailProvider->displayName,
1381 1381
 			);
1382
-			foreach($xml->emailProvider->children() as $tag => $server)
1382
+			foreach ($xml->emailProvider->children() as $tag => $server)
1383 1383
 			{
1384 1384
 				if (!in_array($tag, array('incomingServer', 'outgoingServer'))) continue;
1385
-				foreach($server->attributes() as $name => $value)
1385
+				foreach ($server->attributes() as $name => $value)
1386 1386
 				{
1387 1387
 					if ($name == 'type') $type = (string)$value;
1388 1388
 				}
1389 1389
 				$data = array();
1390
-				foreach($server as $name => $value)
1390
+				foreach ($server as $name => $value)
1391 1391
 				{
1392
-					foreach($value->children() as $tag => $val)
1392
+					foreach ($value->children() as $tag => $val)
1393 1393
 					{
1394 1394
 						$data[$name][$tag] = (string)$val;
1395 1395
 					}
@@ -1398,7 +1398,7 @@  discard block
 block discarded – undo
1398 1398
 				$provider[$type][] = $data;
1399 1399
 			}
1400 1400
 		}
1401
-		catch(Exception $e) {
1401
+		catch (Exception $e) {
1402 1402
 			// ignore own not-found exception or xml parsing execptions
1403 1403
 			unset($e);
1404 1404
 
@@ -1430,7 +1430,7 @@  discard block
 block discarded – undo
1430 1430
 	 * @param string $type ='imap' 'imap' or 'smtp', used as hostname beside 'mail'
1431 1431
 	 * @return array of hostname => true pairs
1432 1432
 	 */
1433
-	protected function guess_hosts($email, $type='imap')
1433
+	protected function guess_hosts($email, $type = 'imap')
1434 1434
 	{
1435 1435
 		list(,$domain) = explode('@', $email);
1436 1436
 
@@ -1456,7 +1456,7 @@  discard block
 block discarded – undo
1456 1456
 		}
1457 1457
 
1458 1458
 		// verify hosts in dns
1459
-		foreach(array_keys($hosts) as $host)
1459
+		foreach (array_keys($hosts) as $host)
1460 1460
 		{
1461 1461
 			if (!dns_get_record($host, DNS_A)) unset($hosts[$host]);
1462 1462
 		}
@@ -1494,12 +1494,12 @@  discard block
 block discarded – undo
1494 1494
 				}
1495 1495
 
1496 1496
 				$ea_account = emailadmin_account::read($emailadmin->acc_id, $_data['id']);				
1497
-				if (($userData = $ea_account->getUserData ()))
1497
+				if (($userData = $ea_account->getUserData()))
1498 1498
 				{
1499 1499
 					$userData = array(
1500 1500
 						'acc_smtp_type' => $ea_account->acc_smtp_type,
1501 1501
 						'accountStatus' => $_data['status'],
1502
-						'quotaLimit' => $_data['qouta']? $_data['qouta']: $userData['qoutaLimit'],
1502
+						'quotaLimit' => $_data['qouta'] ? $_data['qouta'] : $userData['qoutaLimit'],
1503 1503
 						'mailLocalAddress' => $userData['mailLocalAddress']
1504 1504
 					);
1505 1505
 					
@@ -1507,7 +1507,7 @@  discard block
 block discarded – undo
1507 1507
 					{
1508 1508
 						$userData['mailLocalAddress'] = preg_replace('/@'.preg_quote($ea_account->acc_domain).'$/', '@'.$_data['domain'], $userData['mailLocalAddress']);
1509 1509
 
1510
-						foreach($userData['mailAlternateAddress'] as &$alias)
1510
+						foreach ($userData['mailAlternateAddress'] as &$alias)
1511 1511
 						{
1512 1512
 							$alias = preg_replace('/@'.preg_quote($ea_account->acc_domain).'$/', '@'.$_data['domain'], $alias);
1513 1513
 						}
@@ -1515,7 +1515,7 @@  discard block
 block discarded – undo
1515 1515
 					// fullfill the saveUserData requirements
1516 1516
 					$userData += $ea_account->params;
1517 1517
 					$ea_account->saveUserData($_data['id'], $userData);
1518
-					$msg = '#'.$_data['id'].' '.$account['account_fullname']. ' '.($userData['accountStatus'] == 'active'? lang('activated'):lang('deactivated'));
1518
+					$msg = '#'.$_data['id'].' '.$account['account_fullname'].' '.($userData['accountStatus'] == 'active' ? lang('activated') : lang('deactivated'));
1519 1519
 				}
1520 1520
 				else
1521 1521
 				{
Please login to merge, or discard this patch.