Completed
Push — 16.1 ( bf28e4...647407 )
by Ralf
44:12 queued 29:51
created
api/src/Mail/Smtp/Ldap.php 1 patch
Spacing   +43 added lines, -44 removed lines patch added patch discarded remove patch
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 	 *
165 165
 	 * @param string $defaultDomain =null
166 166
 	 */
167
-	function __construct($defaultDomain=null)
167
+	function __construct($defaultDomain = null)
168 168
 	{
169 169
 		parent::__construct($defaultDomain);
170 170
 
@@ -212,9 +212,8 @@  discard block
 block discarded – undo
212 212
 	 */
213 213
 	function addAccount($_hookValues)
214 214
 	{
215
-		$mailLocalAddress = $_hookValues['account_email'] ? $_hookValues['account_email'] :
216
-			Api\Accounts::email($_hookValues['account_firstname'],
217
-				$_hookValues['account_lastname'],$_hookValues['account_lid'],$this->defaultDomain);
215
+		$mailLocalAddress = $_hookValues['account_email'] ? $_hookValues['account_email'] : Api\Accounts::email($_hookValues['account_firstname'],
216
+				$_hookValues['account_lastname'], $_hookValues['account_lid'], $this->defaultDomain);
218 217
 
219 218
 		$ds = $this->getLdapConnection();
220 219
 
@@ -226,13 +225,13 @@  discard block
 block discarded – undo
226 225
 		}
227 226
 		$allValues 	= ldap_get_entries($ds, $sri);
228 227
 		$accountDN 	= $allValues[0]['dn'];
229
-		$objectClasses	= $allValues[0]['objectclass'];
228
+		$objectClasses = $allValues[0]['objectclass'];
230 229
 		unset($objectClasses['count']);
231 230
 
232 231
 		// add our mail schema, if not already set
233
-		if(!in_array(static::SCHEMA,$objectClasses) && !in_array(strtolower(static::SCHEMA),$objectClasses))
232
+		if (!in_array(static::SCHEMA, $objectClasses) && !in_array(strtolower(static::SCHEMA), $objectClasses))
234 233
 		{
235
-			$objectClasses[]	= static::SCHEMA;
234
+			$objectClasses[] = static::SCHEMA;
236 235
 		}
237 236
 		// the new code for postfix+cyrus+ldap
238 237
 		$newData = array(
@@ -263,7 +262,7 @@  discard block
 block discarded – undo
263 262
 		{
264 263
 			error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'$accountDN',".
265 264
 				array2string($newData).') returning '.array2string($ret).
266
-				(!$ret?' ('.ldap_error($ds).')':''));
265
+				(!$ret ? ' ('.ldap_error($ds).')' : ''));
267 266
 		}
268 267
 		return $ret;
269 268
 	}
@@ -277,7 +276,7 @@  discard block
 block discarded – undo
277 276
 	 */
278 277
 	function addAccountExtra(array $_hookValues, array $allValues, array &$newData)
279 278
 	{
280
-		unset($_hookValues, $allValues, $newData);	// not used, but required by function signature
279
+		unset($_hookValues, $allValues, $newData); // not used, but required by function signature
281 280
 	}
282 281
 
283 282
 	/**
@@ -288,24 +287,24 @@  discard block
 block discarded – undo
288 287
 	 */
289 288
 	function getAccountEmailAddress($_accountName)
290 289
 	{
291
-		$emailAddresses	= array();
290
+		$emailAddresses = array();
292 291
 		$ds = $this->getLdapConnection();
293 292
 		$filter = '(&'.static::USER_FILTER.'('.static::USER_ATTR.'='.Api\Ldap::quote($_accountName).'))';
294
-		$attributes	= array('dn', static::MAIL_ATTR, static::ALIAS_ATTR);
293
+		$attributes = array('dn', static::MAIL_ATTR, static::ALIAS_ATTR);
295 294
 		$sri = @ldap_search($ds, $this->search_base, $filter, $attributes);
296 295
 
297 296
 		if ($sri)
298 297
 		{
299
-			$realName = trim($GLOBALS['egw_info']['user']['account_firstname'] . (!empty($GLOBALS['egw_info']['user']['account_firstname']) ? ' ' : '') . $GLOBALS['egw_info']['user']['account_lastname']);
298
+			$realName = trim($GLOBALS['egw_info']['user']['account_firstname'].(!empty($GLOBALS['egw_info']['user']['account_firstname']) ? ' ' : '').$GLOBALS['egw_info']['user']['account_lastname']);
300 299
 			$allValues = ldap_get_entries($ds, $sri);
301 300
 
302
-			if(isset($allValues[0][static::MAIL_ATTR]))
301
+			if (isset($allValues[0][static::MAIL_ATTR]))
303 302
 			{
304
-				foreach($allValues[0][static::MAIL_ATTR] as $key => $value)
303
+				foreach ($allValues[0][static::MAIL_ATTR] as $key => $value)
305 304
 				{
306 305
 					if ($key === 'count') continue;
307 306
 
308
-					$emailAddresses[] = array (
307
+					$emailAddresses[] = array(
309 308
 						'name'		=> $realName,
310 309
 						'address'	=> $value,
311 310
 						'type'		=> !$key ? 'default' : 'alternate',
@@ -314,7 +313,7 @@  discard block
 block discarded – undo
314 313
 			}
315 314
 			if (static::ALIAS_ATTR && isset($allValues[0][static::ALIAS_ATTR]))
316 315
 			{
317
-				foreach(self::getAttributePrefix($allValues[0][static::ALIAS_ATTR], static::ALIAS_PREFIX) as $value)
316
+				foreach (self::getAttributePrefix($allValues[0][static::ALIAS_ATTR], static::ALIAS_PREFIX) as $value)
318 317
 				{
319 318
 					$emailAddresses[] = array(
320 319
 						'name'		=> $realName,
@@ -341,7 +340,7 @@  discard block
 block discarded – undo
341 340
 	 * @return array with values for keys 'mailLocalAddress', 'mailAlternateAddress' (array), 'mailForwardingAddress' (array),
342 341
 	 * 	'accountStatus' ("active"), 'quotaLimit' and 'deliveryMode' ("forwardOnly")
343 342
 	 */
344
-	function getUserData($user, $match_uid_at_domain=false)
343
+	function getUserData($user, $match_uid_at_domain = false)
345 344
 	{
346 345
 		$userData = array(
347 346
 			'mailbox' => array(),
@@ -401,7 +400,7 @@  discard block
 block discarded – undo
401 400
 			$allValues = ldap_get_entries($ldap, $sri);
402 401
 			if ($this->debug) error_log(__METHOD__."('$user') --> ldap_search(, '$this->search_base', '$filter') --> ldap_get_entries=".array2string($allValues[0]));
403 402
 
404
-			foreach($allValues as $key => $values)
403
+			foreach ($allValues as $key => $values)
405 404
 			{
406 405
 				if ($key === 'count') continue;
407 406
 
@@ -504,16 +503,16 @@  discard block
 block discarded – undo
504 503
 					// remember if server returned forward-attribute
505 504
 					$this->forward_attr_returned = isset($values[static::FORWARD_ATTR]);
506 505
 
507
-					$userData['mailForwardingAddress']	= self::getAttributePrefix($values[static::FORWARD_ATTR], static::FORWARD_PREFIX);
506
+					$userData['mailForwardingAddress'] = self::getAttributePrefix($values[static::FORWARD_ATTR], static::FORWARD_PREFIX);
508 507
 				}
509 508
 
510
-				if (static::MAILBOX_ATTR) $userData['mailMessageStore']	= $values[static::MAILBOX_ATTR][0];
509
+				if (static::MAILBOX_ATTR) $userData['mailMessageStore'] = $values[static::MAILBOX_ATTR][0];
511 510
 
512 511
 				$userData['deliveryMode'] = $deliveryMode;
513 512
 
514 513
 				// eg. suse stores all email addresses as aliases
515 514
 				if (static::REQUIRE_MAIL_AS_ALIAS &&
516
-					($k = array_search($userData['mailLocalAddress'],$userData['mailAlternateAddress'])) !== false)
515
+					($k = array_search($userData['mailLocalAddress'], $userData['mailAlternateAddress'])) !== false)
517 516
 				{
518 517
 					unset($userData['mailAlternateAddress'][$k]);
519 518
 					$userData['mailAlternateAddress'] = array_values($userData['mailAlternateAddress']);
@@ -547,9 +546,9 @@  discard block
 block discarded – undo
547 546
 	 * @return boolean true on success, false on error writing to ldap
548 547
 	 */
549 548
 	function setUserData($_uidnumber, array $_mailAlternateAddress, array $_mailForwardingAddress, $_deliveryMode,
550
-		$_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only=false, $_setMailbox=null)
549
+		$_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only = false, $_setMailbox = null)
551 550
 	{
552
-		unset($_forwarding_only);	// not used
551
+		unset($_forwarding_only); // not used
553 552
 
554 553
 		if (static::USERID_ATTR)
555 554
 		{
@@ -569,15 +568,15 @@  discard block
 block discarded – undo
569 568
 		$allValues 	= ldap_get_entries($ldap, $sri);
570 569
 
571 570
 		$accountDN 	= $allValues[0]['dn'];
572
-		$uid	   	= $allValues[0][static::USER_ATTR][0];
573
-		$objectClasses	= $allValues[0]['objectclass'];
571
+		$uid = $allValues[0][static::USER_ATTR][0];
572
+		$objectClasses = $allValues[0]['objectclass'];
574 573
 
575 574
 		unset($objectClasses['count']);
576 575
 
577
-		if(!in_array(static::SCHEMA,$objectClasses) && !in_array(strtolower(static::SCHEMA),$objectClasses))
576
+		if (!in_array(static::SCHEMA, $objectClasses) && !in_array(strtolower(static::SCHEMA), $objectClasses))
578 577
 		{
579
-			$objectClasses[]	= static::SCHEMA;
580
-			$newData['objectclass']	= $objectClasses;
578
+			$objectClasses[] = static::SCHEMA;
579
+			$newData['objectclass'] = $objectClasses;
581 580
 		}
582 581
 
583 582
 		sort($_mailAlternateAddress);
@@ -590,7 +589,7 @@  discard block
 block discarded – undo
590 589
 			self::setAttributePrefix($newData[static::ALIAS_ATTR], $_mailAlternateAddress, static::ALIAS_PREFIX);
591 590
 
592 591
 			// all email must be stored as alias for suse
593
-			if (static::REQUIRE_MAIL_AS_ALIAS && !in_array($_mailLocalAddress,(array)$_mailAlternateAddress))
592
+			if (static::REQUIRE_MAIL_AS_ALIAS && !in_array($_mailLocalAddress, (array)$_mailAlternateAddress))
594 593
 			{
595 594
 				self::setAttributePrefix($newData[static::ALIAS_ATTR], $_mailLocalAddress, static::ALIAS_PREFIX);
596 595
 			}
@@ -628,12 +627,12 @@  discard block
 block discarded – undo
628 627
 		if (static::QUOTA_ATTR)
629 628
 		{
630 629
 			self::setAttributePrefix($newData[static::QUOTA_ATTR],
631
-				(int)$_quota > 0 ? (int)$_quota*static::QUOTA_FACTOR : array(), static::QUOTA_PREFIX);
630
+				(int)$_quota > 0 ? (int)$_quota * static::QUOTA_FACTOR : array(), static::QUOTA_PREFIX);
632 631
 		}
633 632
 		// does schema support enabling/disabling mail via attribute
634 633
 		if (static::MAIL_ENABLE_ATTR)
635 634
 		{
636
-			$newData[static::MAIL_ENABLE_ATTR]	= $_accountStatus ?
635
+			$newData[static::MAIL_ENABLE_ATTR] = $_accountStatus ?
637 636
 				(static::MAIL_ENABLED == self::MAIL_ENABLED_USE_MAIL ? $_mailLocalAddress : static::MAIL_ENABLED) : array();
638 637
 		}
639 638
 		// if we have no mail-enabled attribute, but require primary mail in aliases-attr
@@ -681,7 +680,7 @@  discard block
 block discarded – undo
681 680
 			$uid = $GLOBALS['egw']->accounts->id2name($_accountID);
682 681
 			$filter = '(&'.static::USER_FILTER.'('.static::USER_ATTR.'='.Api\Ldap::quote($uid).'))';
683 682
 		}
684
-		$attributes	= array('dn', static::MAIL_ATTR, static::FORWARD_ATTR, 'objectclass');
683
+		$attributes = array('dn', static::MAIL_ATTR, static::FORWARD_ATTR, 'objectclass');
685 684
 		if (static::FORWARD_ONLY_ATTR)
686 685
 		{
687 686
 			$attributes[] = static::FORWARD_ONLY_ATTR;
@@ -692,12 +691,12 @@  discard block
 block discarded – undo
692 691
 		{
693 692
 			$newData = array();
694 693
 			$allValues = ldap_get_entries($ds, $sri);
695
-			$objectClasses  = $allValues[0]['objectclass'];
696
-			$newData['objectclass']	= $allValues[0]['objectclass'];
694
+			$objectClasses = $allValues[0]['objectclass'];
695
+			$newData['objectclass'] = $allValues[0]['objectclass'];
697 696
 
698 697
 			unset($newData['objectclass']['count']);
699 698
 
700
-			if(!in_array(static::SCHEMA,$objectClasses))
699
+			if (!in_array(static::SCHEMA, $objectClasses))
701 700
 			{
702 701
 				$newData['objectclass'][] = static::SCHEMA;
703 702
 			}
@@ -707,9 +706,9 @@  discard block
 block discarded – undo
707 706
 				$newData[static::FORWARD_ATTR] = $allValues[0][static::FORWARD_ATTR];
708 707
 				$forwards = self::getAttributePrefix($newData[static::FORWARD_ATTR], static::FORWARD_PREFIX);
709 708
 
710
-				if(!empty($_forwardingAddress))
709
+				if (!empty($_forwardingAddress))
711 710
 				{
712
-					if($forwards)
711
+					if ($forwards)
713 712
 					{
714 713
 						if (!is_array($_forwardingAddress))
715 714
 						{
@@ -752,7 +751,7 @@  discard block
 block discarded – undo
752 751
 			}
753 752
 			if ($this->debug) error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'{$allValues[0]['dn']}',".array2string($newData).')');
754 753
 
755
-			return ldap_modify ($ds, $allValues[0]['dn'], $newData);
754
+			return ldap_modify($ds, $allValues[0]['dn'], $newData);
756 755
 		}
757 756
 	}
758 757
 
@@ -794,9 +793,9 @@  discard block
 block discarded – undo
794 793
 		unset($entries['count']);
795 794
 
796 795
 		$mailboxes = array();
797
-		foreach($entries as $entry)
796
+		foreach ($entries as $entry)
798 797
 		{
799
-			if ($entry[static::USER_ATTR][0] == 'anonymous') continue;	// anonymous is never a mail-user!
798
+			if ($entry[static::USER_ATTR][0] == 'anonymous') continue; // anonymous is never a mail-user!
800 799
 			list($mailbox) = explode('@', $entry[static::MAILBOX_ATTR ? static::MAILBOX_ATTR : static::MAIL_ATTR][0]);
801 800
 			$mailboxes[$entry[static::USER_ATTR][0]] = $mailbox;
802 801
 		}
@@ -810,13 +809,13 @@  discard block
 block discarded – undo
810 809
 	 * @param string|array $values value(s) to set
811 810
 	 * @param string $prefix ='' prefix to use or ''
812 811
 	 */
813
-	protected static function setAttributePrefix(&$attribute, $values, $prefix='')
812
+	protected static function setAttributePrefix(&$attribute, $values, $prefix = '')
814 813
 	{
815 814
 		//$attribute_in = $attribute;
816 815
 		if (empty($attribute)) $attribute = array();
817 816
 		if (!is_array($attribute)) $attribute = (array)$attribute;
818 817
 
819
-		foreach((array)$values as $value)
818
+		foreach ((array)$values as $value)
820 819
 		{
821 820
 			$attribute[] = $prefix.$value;
822 821
 		}
@@ -831,7 +830,7 @@  discard block
 block discarded – undo
831 830
 	 * @param boolean $remove =true remove returned values from $attribute
832 831
 	 * @return array with values (prefix removed) or array() if nothing found
833 832
 	 */
834
-	protected static function getAttributePrefix(&$attribute, $prefix='', $remove=true)
833
+	protected static function getAttributePrefix(&$attribute, $prefix = '', $remove = true)
835 834
 	{
836 835
 		//$attribute_in = $attribute;
837 836
 		$values = array();
@@ -840,7 +839,7 @@  discard block
 block discarded – undo
840 839
 		{
841 840
 			unset($attribute['count']);
842 841
 
843
-			foreach($attribute as $key => $value)
842
+			foreach ($attribute as $key => $value)
844 843
 			{
845 844
 				if (!$prefix || stripos($value, $prefix) === 0)
846 845
 				{
Please login to merge, or discard this patch.