Completed
Push — master ( 0bd975...40d1e5 )
by Klaus
19:57
created
api/src/Mail.php 2 patches
Spacing   +1134 added lines, -1135 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 *
122 122
 	 * @array
123 123
 	 */
124
-	static $tidy_config = array('clean'=>false,'output-html'=>true,'join-classes'=>true,'join-styles'=>true,'show-body-only'=>"auto",'word-2000'=>true,'wrap'=>0);
124
+	static $tidy_config = array('clean'=>false, 'output-html'=>true, 'join-classes'=>true, 'join-styles'=>true, 'show-body-only'=>"auto", 'word-2000'=>true, 'wrap'=>0);
125 125
 
126 126
 	/**
127 127
 	 * static used to configure htmLawed, for use with emails
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
 	static $htmLawed_config = array('comment'=>1, //remove comments
132 132
 		'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
133 133
 		'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)
134
-		'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)
134
+		'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)
135 135
 		'direct_list_nest' => 1,
136
-		'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
136
+		'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
137 137
 		// tidy eats away even some wanted whitespace, so we switch it off;
138 138
 		// we used it for its compacting and beautifying capabilities, which resulted in better html for further processing
139 139
 		'tidy'=>0,
@@ -148,13 +148,13 @@  discard block
 block discarded – undo
148 148
 	 *
149 149
 	 * @array
150 150
 	 */
151
-	static $aclShortCuts = array('' => array('label'=>'none','title'=>'The user has no rights whatsoever.'),
152
-		'lrs'		=> array('label'=>'readable','title'=>'Allows a user to read the contents of the mailbox.'),
153
-		'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.'),
154
-		'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.'),
155
-		'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.'),
156
-		'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.'),
157
-		'custom'	=> array('label'=>'custom','title'=>'User defined combination of rights for the ACL'),
151
+	static $aclShortCuts = array('' => array('label'=>'none', 'title'=>'The user has no rights whatsoever.'),
152
+		'lrs'		=> array('label'=>'readable', 'title'=>'Allows a user to read the contents of the mailbox.'),
153
+		'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.'),
154
+		'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.'),
155
+		'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.'),
156
+		'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.'),
157
+		'custom'	=> array('label'=>'custom', 'title'=>'User defined combination of rights for the ACL'),
158 158
 	);
159 159
 
160 160
 	/**
@@ -196,27 +196,27 @@  discard block
 block discarded – undo
196 196
 	 * @param boolean $_reuseCache = null if null it is set to the value of $_restoreSession
197 197
 	 * @return Mail
198 198
 	 */
199
-	public static function getInstance($_restoreSession=true, &$_profileID=0, $_validate=true, $_oldImapServerObject=false, $_reuseCache=null)
199
+	public static function getInstance($_restoreSession = true, &$_profileID = 0, $_validate = true, $_oldImapServerObject = false, $_reuseCache = null)
200 200
 	{
201 201
 		//$_restoreSession=false;
202 202
 		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
203 203
 		//error_log(__METHOD__.' ('.__LINE__.') '.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID.'/'.Mail\Account::get_default_acc_id().' for user:'.$GLOBALS['egw_info']['user']['account_lid'].' called from:'.function_backtrace());
204 204
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_oldImapServerObject));
205
-		if (isset(self::$profileDefunct[$_profileID]) && self::$profileDefunct[$_profileID]===true)
205
+		if (isset(self::$profileDefunct[$_profileID]) && self::$profileDefunct[$_profileID] === true)
206 206
 		{
207
-			throw new Exception(__METHOD__." failed to instanciate Mail for $_profileID / ".$this->profileID." with error:".$e->getMessage().($e->details?', '.$e->details:''));
207
+			throw new Exception(__METHOD__." failed to instanciate Mail for $_profileID / ".$this->profileID." with error:".$e->getMessage().($e->details ? ', '.$e->details : ''));
208 208
 		}
209 209
 		if ($_oldImapServerObject instanceof Mail\Imap)
210 210
 		{
211 211
 			if (!is_object(self::$instances[$_profileID]))
212 212
 			{
213
-				self::$instances[$_profileID] = new Mail('utf-8',false,$_profileID,false,$_reuseCache);
213
+				self::$instances[$_profileID] = new Mail('utf-8', false, $_profileID, false, $_reuseCache);
214 214
 			}
215 215
 			self::$instances[$_profileID]->icServer = $_oldImapServerObject;
216
-			self::$instances[$_profileID]->accountid= $_oldImapServerObject->ImapServerId;
217
-			self::$instances[$_profileID]->profileID= $_oldImapServerObject->ImapServerId;
216
+			self::$instances[$_profileID]->accountid = $_oldImapServerObject->ImapServerId;
217
+			self::$instances[$_profileID]->profileID = $_oldImapServerObject->ImapServerId;
218 218
 			self::$instances[$_profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
219
-			self::$instances[$_profileID]->htmlOptions  = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
219
+			self::$instances[$_profileID]->htmlOptions = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
220 220
 			return self::$instances[$_profileID];
221 221
 		}
222 222
 		if ($_profileID == 0)
@@ -229,14 +229,14 @@  discard block
 block discarded – undo
229 229
 			{
230 230
 				$profileID = Mail\Account::get_default_acc_id();
231 231
 			}
232
-			if ($profileID!=$_profileID) $_restoreSession==false;
233
-			$_profileID=$profileID;
232
+			if ($profileID != $_profileID) $_restoreSession == false;
233
+			$_profileID = $profileID;
234 234
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace());
235 235
 		}
236 236
 		// no validation or restoreSession for old ImapServer Object, just fetch it and return it
237
-		if ($_oldImapServerObject===true)
237
+		if ($_oldImapServerObject === true)
238 238
 		{
239
-			return new Mail('utf-8',false,$_profileID,true,$_reuseCache);
239
+			return new Mail('utf-8', false, $_profileID, true, $_reuseCache);
240 240
 		}
241 241
 		if ($_profileID != 0 && $_validate)
242 242
 		{
@@ -256,9 +256,9 @@  discard block
 block discarded – undo
256 256
 			//Cache::setSession('mail','activeProfileID',$_profileID);
257 257
 		}
258 258
 		//error_log(__METHOD__.' ('.__LINE__.') '.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID.' called from:'.function_backtrace());
259
-		if ($_profileID && (!isset(self::$instances[$_profileID]) || $_restoreSession===false))
259
+		if ($_profileID && (!isset(self::$instances[$_profileID]) || $_restoreSession === false))
260 260
 		{
261
-			self::$instances[$_profileID] = new Mail('utf-8',$_restoreSession,$_profileID,false,$_reuseCache);
261
+			self::$instances[$_profileID] = new Mail('utf-8', $_restoreSession, $_profileID, false, $_reuseCache);
262 262
 		}
263 263
 		else
264 264
 		{
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 				self::$instances[$_profileID]->ogServer = Mail\Account::read($_profileID)->smtpServer();
270 270
 				// TODO: merge mailprefs into userprefs, for easy treatment
271 271
 				self::$instances[$_profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
272
-				self::$instances[$_profileID]->htmlOptions  = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
272
+				self::$instances[$_profileID]->htmlOptions = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
273 273
 			} catch (\Exception $e)
274 274
 			{
275 275
 				$newprofileID = Mail\Account::get_default_acc_id();
@@ -277,15 +277,15 @@  discard block
 block discarded – undo
277 277
 				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());
278 278
 				if ($newprofileID)
279 279
 				{
280
-					self::$instances[$newprofileID] = new Mail('utf-8',false,$newprofileID,false,$_reuseCache);
280
+					self::$instances[$newprofileID] = new Mail('utf-8', false, $newprofileID, false, $_reuseCache);
281 281
 					$_profileID = $newprofileID;
282 282
 				}
283 283
 				else
284 284
 				{
285
-					throw new Exception(__METHOD__." failed to load the Profile for ProfileID for $_profileID / ".$this->profileID." with error:".$e->getMessage().($e->details?', '.$e->details:''));
285
+					throw new Exception(__METHOD__." failed to load the Profile for ProfileID for $_profileID / ".$this->profileID." with error:".$e->getMessage().($e->details ? ', '.$e->details : ''));
286 286
 				}
287 287
 			}
288
-			self::storeActiveProfileIDToPref(self::$instances[$_profileID]->icServer, $_profileID, $_validate );
288
+			self::storeActiveProfileIDToPref(self::$instances[$_profileID]->icServer, $_profileID, $_validate);
289 289
 		}
290 290
 		self::$instances[$_profileID]->profileID = $_profileID;
291 291
 		if (!isset(self::$instances[$_profileID]->idna2)) self::$instances[$_profileID]->idna2 = new Horde_Idna;
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 	 * @param boolean $_testConnection = 0
302 302
 	 * @return mixed $_profileID or false on failed ConnectionTest
303 303
 	 */
304
-	public static function storeActiveProfileIDToPref($_icServerObject, $_profileID=0, $_testConnection=true)
304
+	public static function storeActiveProfileIDToPref($_icServerObject, $_profileID = 0, $_testConnection = true)
305 305
 	{
306 306
 		if (isset($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']) && !empty($GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID']))
307 307
 		{
@@ -322,12 +322,12 @@  discard block
 block discarded – undo
322 322
 		}
323 323
 		if ($oldProfileID != $_profileID)
324 324
 		{
325
-			if ($oldProfileID && $_profileID==0) $_profileID = $oldProfileID;
326
-			$GLOBALS['egw']->preferences->add('mail','ActiveProfileID',$_profileID,'user');
325
+			if ($oldProfileID && $_profileID == 0) $_profileID = $oldProfileID;
326
+			$GLOBALS['egw']->preferences->add('mail', 'ActiveProfileID', $_profileID, 'user');
327 327
 			// save prefs
328 328
 			$GLOBALS['egw']->preferences->save_repository(true);
329 329
 			$GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $_profileID;
330
-			Cache::setSession('mail','activeProfileID',$_profileID);
330
+			Cache::setSession('mail', 'activeProfileID', $_profileID);
331 331
 		}
332 332
 		return $_profileID;
333 333
 	}
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 	 * @param int $_acc_id = 0
343 343
 	 * @return int validated acc_id -> either acc_id given, or first valid one
344 344
 	 */
345
-	public static function validateProfileID($_acc_id=0)
345
+	public static function validateProfileID($_acc_id = 0)
346 346
 	{
347 347
 		if ($_acc_id)
348 348
 		{
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 		}
362 362
 		// no account specified or specified account not found or not valid
363 363
 		// --> search existing account for first valid one and return that
364
-		foreach(Mail\Account::search($only_current_user=true, 'acc_imap_host') as $acc_id => $imap_host)
364
+		foreach (Mail\Account::search($only_current_user = true, 'acc_imap_host') as $acc_id => $imap_host)
365 365
 		{
366 366
 			if (!empty($imap_host) && ($account = Mail\Account::read($acc_id)) && $account->is_imap())
367 367
 			{
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 	 * @param boolean $_oldImapServerObject = false
384 384
 	 * @param boolean $_reuseCache = null if null it is set to the value of $_restoreSession
385 385
 	 */
386
-	private function __construct($_displayCharset='utf-8',$_restoreSession=true, $_profileID=0, $_oldImapServerObject=false, $_reuseCache=null)
386
+	private function __construct($_displayCharset = 'utf-8', $_restoreSession = true, $_profileID = 0, $_oldImapServerObject = false, $_reuseCache = null)
387 387
 	{
388 388
 		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
389 389
 		if (!empty($_displayCharset)) self::$displayCharset = $_displayCharset;
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
 			$firstMessage = $this->sessionData['previewMessage'];
404 404
 			$this->sessionData = array();
405 405
 		}
406
-		if (!$_reuseCache) $this->forcePrefReload($_profileID,!$_reuseCache);
406
+		if (!$_reuseCache) $this->forcePrefReload($_profileID, !$_reuseCache);
407 407
 		try
408 408
 		{
409 409
 			$this->profileID = self::validateProfileID($_profileID);
@@ -417,11 +417,11 @@  discard block
 block discarded – undo
417 417
 			throw new Exception(__METHOD__." failed to instanciate Mail for $_profileID / ".$this->profileID." with error:".$e->getMessage());
418 418
 		}
419 419
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($acc->imapServer()));
420
-		$this->icServer = ($_oldImapServerObject?$acc->oldImapServer():$acc->imapServer());
420
+		$this->icServer = ($_oldImapServerObject ? $acc->oldImapServer() : $acc->imapServer());
421 421
 		$this->ogServer = $acc->smtpServer();
422 422
 		// TODO: merge mailprefs into userprefs, for easy treatment
423 423
 		$this->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
424
-		$this->htmlOptions  = $this->mailPreferences['htmlOptions'];
424
+		$this->htmlOptions = $this->mailPreferences['htmlOptions'];
425 425
 		if (isset($this->icServer->ImapServerId) && !empty($this->icServer->ImapServerId))
426 426
 		{
427 427
 			$_profileID = $this->profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $this->icServer->ImapServerId;
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
 	public static function &forceEAProfileLoad($_profile_id)
440 440
 	{
441 441
 		self::unsetCachedObjects($_profile_id);
442
-		$mail = self::getInstance(false, $_profile_id,false);
442
+		$mail = self::getInstance(false, $_profile_id, false);
443 443
 		//_debug_array( $_profile_id);
444 444
 		$mail->icServer = Mail\Account::read($_profile_id)->imapServer();
445 445
 		$mail->ogServer = Mail\Account::read($_profile_id)->smtpServer();
@@ -451,11 +451,11 @@  discard block
 block discarded – undo
451 451
 	 * @param int $_profile_id
452 452
 	 * @param boolean $_resetFolderObjects
453 453
 	 */
454
-	public static function forcePrefReload($_profile_id=null,$_resetFolderObjects=true)
454
+	public static function forcePrefReload($_profile_id = null, $_resetFolderObjects = true)
455 455
 	{
456 456
 		// unset the mail_preferences session object, to force the reload/rebuild
457
-		Cache::setSession('mail','mail_preferences',serialize(array()));
458
-		Cache::setSession('emailadmin','session_data',serialize(array()));
457
+		Cache::setSession('mail', 'mail_preferences', serialize(array()));
458
+		Cache::setSession('emailadmin', 'session_data', serialize(array()));
459 459
 		if ($_resetFolderObjects) self::resetFolderObjectCache($_profile_id);
460 460
 	}
461 461
 
@@ -464,8 +464,8 @@  discard block
 block discarded – undo
464 464
 	 */
465 465
 	function restoreSessionData()
466 466
 	{
467
-		$this->sessionData = array();//Cache::getCache(Cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1);
468
-		self::$activeFolderCache = Cache::getCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
467
+		$this->sessionData = array(); //Cache::getCache(Cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1);
468
+		self::$activeFolderCache = Cache::getCache(Cache::INSTANCE, 'email', 'activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 10);
469 469
 		if (!empty(self::$activeFolderCache[$this->profileID])) $this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID];
470 470
 	}
471 471
 
@@ -475,10 +475,10 @@  discard block
 block discarded – undo
475 475
 	function saveSessionData()
476 476
 	{
477 477
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($this->sessionData)));
478
-		if (!empty($this->sessionData['mailbox'])) self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox'];
478
+		if (!empty($this->sessionData['mailbox'])) self::$activeFolderCache[$this->profileID] = $this->sessionData['mailbox'];
479 479
 		if (isset(self::$activeFolderCache) && is_array(self::$activeFolderCache))
480 480
 		{
481
-			Cache::setCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),self::$activeFolderCache, 60*60*10);
481
+			Cache::setCache(Cache::INSTANCE, 'email', 'activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']), self::$activeFolderCache, 60 * 60 * 10);
482 482
 		}
483 483
 	}
484 484
 
@@ -494,40 +494,40 @@  discard block
 block discarded – undo
494 494
 	 * @param int $_profileID = null default profile of user as returned by getUserDefaultProfileID
495 495
 	 * @return void
496 496
 	 */
497
-	static function unsetCachedObjects($_profileID=null)
497
+	static function unsetCachedObjects($_profileID = null)
498 498
 	{
499 499
 		if (is_null($_profileID)) $_profileID = Mail\Account::get_default_acc_id();
500 500
 		if (is_array($_profileID) && $_profileID['account_id']) $account_id = $_profileID['account_id'];
501 501
 		//error_log(__METHOD__.__LINE__.' called with ProfileID:'.array2string($_profileID).' from '.function_backtrace());
502
-		if (!is_array($_profileID) && (is_numeric($_profileID) || !(stripos($_profileID,'tracker_')===false)))
502
+		if (!is_array($_profileID) && (is_numeric($_profileID) || !(stripos($_profileID, 'tracker_') === false)))
503 503
 		{
504 504
 			self::resetConnectionErrorCache($_profileID);
505
-			$rawHeadersCache = Cache::getCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*1);
505
+			$rawHeadersCache = Cache::getCache(Cache::INSTANCE, 'email', 'rawHeadersCache'.trim($account_id), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 1);
506 506
 			if (isset($rawHeadersCache[$_profileID]))
507 507
 			{
508 508
 				unset($rawHeadersCache[$_profileID]);
509
-				Cache::setCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($account_id),$rawHeadersCache, $expiration=60*60*1);
509
+				Cache::setCache(Cache::INSTANCE, 'email', 'rawHeadersCache'.trim($account_id), $rawHeadersCache, $expiration = 60 * 60 * 1);
510 510
 			}
511
-			$HierarchyDelimiterCache = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*24*5);
511
+			$HierarchyDelimiterCache = Cache::getCache(Cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($account_id), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 24 * 5);
512 512
 			if (isset($HierarchyDelimiterCache[$_profileID]))
513 513
 			{
514 514
 				unset($HierarchyDelimiterCache[$_profileID]);
515
-				Cache::setCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($account_id),$HierarchyDelimiterCache, $expiration=60*60*24*5);
515
+				Cache::setCache(Cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($account_id), $HierarchyDelimiterCache, $expiration = 60 * 60 * 24 * 5);
516 516
 			}
517 517
 			//reset folderObject cache, to trigger reload
518 518
 			self::resetFolderObjectCache($_profileID);
519 519
 			//reset counter of deleted messages per folder
520
-			$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*1);
520
+			$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($account_id), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 1);
521 521
 			if (isset($eMailListContainsDeletedMessages[$_profileID]))
522 522
 			{
523 523
 				unset($eMailListContainsDeletedMessages[$_profileID]);
524
-				Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($account_id),$eMailListContainsDeletedMessages, $expiration=60*60*1);
524
+				Cache::setCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($account_id), $eMailListContainsDeletedMessages, $expiration = 60 * 60 * 1);
525 525
 			}
526
-			$vacationCached = Cache::getCache(Cache::INSTANCE, 'email', 'vacationNotice'.trim($account_id),$callback=null,$callback_params=array(),$expiration=60*60*24*1);
526
+			$vacationCached = Cache::getCache(Cache::INSTANCE, 'email', 'vacationNotice'.trim($account_id), $callback = null, $callback_params = array(), $expiration = 60 * 60 * 24 * 1);
527 527
 			if (isset($vacationCached[$_profileID]))
528 528
 			{
529 529
 				unset($vacationCached[$_profileID]);
530
-				Cache::setCache(Cache::INSTANCE,'email','vacationNotice'.trim($account_id),$vacationCached, $expiration=60*60*24*1);
530
+				Cache::setCache(Cache::INSTANCE, 'email', 'vacationNotice'.trim($account_id), $vacationCached, $expiration = 60 * 60 * 24 * 1);
531 531
 			}
532 532
 
533 533
 			if (isset(self::$instances[$_profileID])) unset(self::$instances[$_profileID]);
@@ -535,17 +535,17 @@  discard block
 block discarded – undo
535 535
 		if (is_array($_profileID) && $_profileID['location'] == 'clear_cache')
536 536
 		{
537 537
 			// called via hook
538
-			foreach($GLOBALS['egw']->accounts->search(array('type' => 'accounts','order' => 'account_lid')) as $account)
538
+			foreach ($GLOBALS['egw']->accounts->search(array('type' => 'accounts', 'order' => 'account_lid')) as $account)
539 539
 			{
540 540
 				//error_log(__METHOD__.__LINE__.array2string($account));
541 541
 				$account_id = $account['account_id'];
542 542
 				$_profileID = null;
543
-				self::resetConnectionErrorCache($_profileID,$account_id);
544
-				self::resetFolderObjectCache($_profileID,$account_id);
545
-				Cache::setCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($account_id),array(), 60*60*1);
546
-				Cache::setCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($account_id),array(), 60*60*24*5);
547
-				Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($account_id),array(), 60*60*1);
548
-				Cache::setCache(Cache::INSTANCE,'email','vacationNotice'.trim($account_id),array(), 60*60*24*1);
543
+				self::resetConnectionErrorCache($_profileID, $account_id);
544
+				self::resetFolderObjectCache($_profileID, $account_id);
545
+				Cache::setCache(Cache::INSTANCE, 'email', 'rawHeadersCache'.trim($account_id), array(), 60 * 60 * 1);
546
+				Cache::setCache(Cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($account_id), array(), 60 * 60 * 24 * 5);
547
+				Cache::setCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($account_id), array(), 60 * 60 * 1);
548
+				Cache::setCache(Cache::INSTANCE, 'email', 'vacationNotice'.trim($account_id), array(), 60 * 60 * 24 * 1);
549 549
 			}
550 550
 		}
551 551
 	}
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
 	 * @param int $_ImapServerId the profileID to look for
557 557
 	 * @param int $account_id the egw account to look for
558 558
 	 */
559
-	static function resetConnectionErrorCache($_ImapServerId=null,$account_id=null)
559
+	static function resetConnectionErrorCache($_ImapServerId = null, $account_id = null)
560 560
 	{
561 561
 		//error_log(__METHOD__.' ('.__LINE__.') '.' for Profile:'.array2string($_ImapServerId) .' for user:'.trim($account_id));
562 562
 		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
@@ -574,19 +574,19 @@  discard block
 block discarded – undo
574 574
 		}
575 575
 		else
576 576
 		{
577
-			$isConError = Cache::getCache(Cache::INSTANCE,'email','icServerSIEVE_connectionError'.trim($account_id));
577
+			$isConError = Cache::getCache(Cache::INSTANCE, 'email', 'icServerSIEVE_connectionError'.trim($account_id));
578 578
 			if (isset($isConError[$_ImapServerId]))
579 579
 			{
580 580
 				unset($isConError[$_ImapServerId]);
581 581
 			}
582
-			$waitOnFailure = Cache::getCache(Cache::INSTANCE,'email','ActiveSyncWaitOnFailure'.trim($account_id),null,array(),60*60*2);
582
+			$waitOnFailure = Cache::getCache(Cache::INSTANCE, 'email', 'ActiveSyncWaitOnFailure'.trim($account_id), null, array(), 60 * 60 * 2);
583 583
 			if (isset($waitOnFailure[$_ImapServerId]))
584 584
 			{
585 585
 				unset($waitOnFailure[$_ImapServerId]);
586 586
 			}
587 587
 		}
588
-		Cache::setCache(Cache::INSTANCE,'email','icServerSIEVE_connectionError'.trim($account_id),$isConError,60*15);
589
-		Cache::setCache(Cache::INSTANCE,'email','ActiveSyncWaitOnFailure'.trim($account_id),$waitOnFailure,60*60*2);
588
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerSIEVE_connectionError'.trim($account_id), $isConError, 60 * 15);
589
+		Cache::setCache(Cache::INSTANCE, 'email', 'ActiveSyncWaitOnFailure'.trim($account_id), $waitOnFailure, 60 * 60 * 2);
590 590
 	}
591 591
 
592 592
 	/**
@@ -595,13 +595,13 @@  discard block
 block discarded – undo
595 595
 	 * @param int $_ImapServerId the profileID to look for
596 596
 	 * @param int $account_id the egw account to look for
597 597
 	 */
598
-	static function resetFolderObjectCache($_ImapServerId=null,$account_id=null)
598
+	static function resetFolderObjectCache($_ImapServerId = null, $account_id = null)
599 599
 	{
600 600
 		//error_log(__METHOD__.' ('.__LINE__.') '.' called for Profile:'.array2string($_ImapServerId).'->'.function_backtrace());
601 601
 		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
602 602
 		// on [location] => verify_settings we coud either use [prefs] => Array([ActiveProfileID] => 9, .. as $_ImapServerId
603 603
 		// or treat it as not given. we try that path
604
-		if (is_null($_ImapServerId)||is_array($_ImapServerId))
604
+		if (is_null($_ImapServerId) || is_array($_ImapServerId))
605 605
 		{
606 606
 			$folders2return = array();
607 607
 			$folderInfo = array();
@@ -610,12 +610,12 @@  discard block
 block discarded – undo
610 610
 		}
611 611
 		else
612 612
 		{
613
-			$folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($account_id),null,array(),60*60*1);
613
+			$folders2return = Cache::getCache(Cache::INSTANCE, 'email', 'folderObjects'.trim($account_id), null, array(), 60 * 60 * 1);
614 614
 			if (!empty($folders2return) && isset($folders2return[$_ImapServerId]))
615 615
 			{
616 616
 				unset($folders2return[$_ImapServerId]);
617 617
 			}
618
-			$folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($account_id),null,array(),60*60*5);
618
+			$folderInfo = Cache::getCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($account_id), null, array(), 60 * 60 * 5);
619 619
 			if (!empty($folderInfo) && isset($folderInfo[$_ImapServerId]))
620 620
 			{
621 621
 				unset($folderInfo[$_ImapServerId]);
@@ -627,23 +627,23 @@  discard block
 block discarded – undo
627 627
 				unset($lastFolderUsedForMove[$_ImapServerId]);
628 628
 			}
629 629
 			*/
630
-			$folderBasicInfo = Cache::getCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($account_id),null,array(),60*60*1);
630
+			$folderBasicInfo = Cache::getCache(Cache::INSTANCE, 'email', 'folderBasicInfo'.trim($account_id), null, array(), 60 * 60 * 1);
631 631
 			if (!empty($folderBasicInfo) && isset($folderBasicInfo[$_ImapServerId]))
632 632
 			{
633 633
 				unset($folderBasicInfo[$_ImapServerId]);
634 634
 			}
635
-			$_specialUseFolders = Cache::getCache(Cache::INSTANCE,'email','specialUseFolders'.trim($account_id),null,array(),60*60*12);
635
+			$_specialUseFolders = Cache::getCache(Cache::INSTANCE, 'email', 'specialUseFolders'.trim($account_id), null, array(), 60 * 60 * 12);
636 636
 			if (!empty($_specialUseFolders) && isset($_specialUseFolders[$_ImapServerId]))
637 637
 			{
638 638
 				unset($_specialUseFolders[$_ImapServerId]);
639
-				self::$specialUseFolders=null;
639
+				self::$specialUseFolders = null;
640 640
 			}
641 641
 		}
642
-		Cache::setCache(Cache::INSTANCE,'email','folderObjects'.trim($account_id),$folders2return, 60*60*1);
643
-		Cache::setCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($account_id),$folderInfo,60*60*5);
642
+		Cache::setCache(Cache::INSTANCE, 'email', 'folderObjects'.trim($account_id), $folders2return, 60 * 60 * 1);
643
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($account_id), $folderInfo, 60 * 60 * 5);
644 644
 		//Cache::setCache(Cache::INSTANCE,'email','lastFolderUsedForMove'.trim($account_id),$lastFolderUsedForMove,$expiration=60*60*1);
645
-		Cache::setCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($account_id),$folderBasicInfo,60*60*1);
646
-		Cache::setCache(Cache::INSTANCE,'email','specialUseFolders'.trim($account_id),$_specialUseFolders,60*60*12);
645
+		Cache::setCache(Cache::INSTANCE, 'email', 'folderBasicInfo'.trim($account_id), $folderBasicInfo, 60 * 60 * 1);
646
+		Cache::setCache(Cache::INSTANCE, 'email', 'specialUseFolders'.trim($account_id), $_specialUseFolders, 60 * 60 * 12);
647 647
 	}
648 648
 
649 649
 	/**
@@ -664,15 +664,15 @@  discard block
 block discarded – undo
664 664
 	 * @param string $_profileID the ID of the mailaccount to check for identities, if null current mail-account is used
665 665
 	 * @return array - array(email=>realname)
666 666
 	 */
667
-	function getUserEMailAddresses($_profileID=null)
667
+	function getUserEMailAddresses($_profileID = null)
668 668
 	{
669
-		$acc = Mail\Account::read((!empty($_profileID)?$_profileID:$this->profileID));
669
+		$acc = Mail\Account::read((!empty($_profileID) ? $_profileID : $this->profileID));
670 670
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.array2string($acc));
671 671
 		$identities = Mail\Account::identities($acc);
672 672
 
673 673
 		$userEMailAdresses = array($acc['ident_email']=>$acc['ident_realname']);
674 674
 
675
-		foreach($identities as $ik => $ident) {
675
+		foreach ($identities as $ik => $ident) {
676 676
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
677 677
 			$identity = Mail\Account::read_identity($ik);
678 678
 			if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']])) $userEMailAdresses[$identity['ident_email']] = $identity['ident_realname'];
@@ -687,19 +687,19 @@  discard block
 block discarded – undo
687 687
 	 * @param boolean $resolve_placeholders wether or not resolve possible placeholders in identities
688 688
 	 * @return array - array(email=>realname)
689 689
 	 */
690
-	static function getAllIdentities($_accountToSearch=null,$resolve_placeholders=false)
690
+	static function getAllIdentities($_accountToSearch = null, $resolve_placeholders = false)
691 691
 	{
692 692
 		$userEMailAdresses = array();
693
-		foreach(Mail\Account::search($only_current_user=($_accountToSearch?$_accountToSearch:true), $just_name=true) as $acc_id => $identity_name)
693
+		foreach (Mail\Account::search($only_current_user = ($_accountToSearch ? $_accountToSearch : true), $just_name = true) as $acc_id => $identity_name)
694 694
 		{
695
-			$acc = Mail\Account::read($acc_id,($_accountToSearch?$_accountToSearch:null));
696
-			if (!$resolve_placeholders) $userEMailAdresses[$acc['ident_id']] = array('acc_id'=>$acc_id,'ident_id'=>$acc['ident_id'],'ident_email'=>$acc['ident_email'],'ident_org'=>$acc['ident_org'],'ident_realname'=>$acc['ident_realname'],'ident_signature'=>$acc['ident_signature'],'ident_name'=>$acc['ident_name']);
695
+			$acc = Mail\Account::read($acc_id, ($_accountToSearch ? $_accountToSearch : null));
696
+			if (!$resolve_placeholders) $userEMailAdresses[$acc['ident_id']] = array('acc_id'=>$acc_id, 'ident_id'=>$acc['ident_id'], 'ident_email'=>$acc['ident_email'], 'ident_org'=>$acc['ident_org'], 'ident_realname'=>$acc['ident_realname'], 'ident_signature'=>$acc['ident_signature'], 'ident_name'=>$acc['ident_name']);
697 697
 
698
-			foreach(Mail\Account::identities($acc) as $ik => $ident) {
698
+			foreach (Mail\Account::identities($acc) as $ik => $ident) {
699 699
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
700
-				$identity = Mail\Account::read_identity($ik,$resolve_placeholders);
700
+				$identity = Mail\Account::read_identity($ik, $resolve_placeholders);
701 701
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
702
-				if (!isset($userEMailAdresses[$identity['ident_id']])) $userEMailAdresses[$identity['ident_id']] = array('acc_id'=>$acc_id,'ident_id'=>$identity['ident_id'],'ident_email'=>$identity['ident_email'],'ident_org'=>$identity['ident_org'],'ident_realname'=>$identity['ident_realname'],'ident_signature'=>$identity['ident_signature'],'ident_name'=>$identity['ident_name']);
702
+				if (!isset($userEMailAdresses[$identity['ident_id']])) $userEMailAdresses[$identity['ident_id']] = array('acc_id'=>$acc_id, 'ident_id'=>$identity['ident_id'], 'ident_email'=>$identity['ident_email'], 'ident_org'=>$identity['ident_org'], 'ident_realname'=>$identity['ident_realname'], 'ident_signature'=>$identity['ident_signature'], 'ident_name'=>$identity['ident_name']);
703 703
 			}
704 704
 		}
705 705
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses));
@@ -719,9 +719,9 @@  discard block
 block discarded – undo
719 719
 			$account = Mail\Account::read($account);
720 720
 		}
721 721
 		$userEMailAdresses = array();
722
-		foreach(Mail\Account::identities($account, true, 'params') as $ik => $ident) {
722
+		foreach (Mail\Account::identities($account, true, 'params') as $ik => $ident) {
723 723
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
724
-			$identity = Mail\Account::read_identity($ik,true,null,$account);
724
+			$identity = Mail\Account::read_identity($ik, true, null, $account);
725 725
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
726 726
 			// standardIdentity has ident_id==acc_id (as it is done within account->identities)
727 727
 			if (empty($identity['ident_id'])) $identity['ident_id'] = $identity['acc_id'];
@@ -748,9 +748,9 @@  discard block
 block discarded – undo
748 748
 	function getDefaultIdentity()
749 749
 	{
750 750
 		// retrieve the signature accociated with the identity
751
-		$id = $this->getIdentitiesWithAccounts($_accountData=array());
752
-		foreach(Mail\Account::identities($_accountData[$this->profileID] ?
753
-			$this->profileID : $_accountData[$id],false,'ident_id') as $accountData)
751
+		$id = $this->getIdentitiesWithAccounts($_accountData = array());
752
+		foreach (Mail\Account::identities($_accountData[$this->profileID] ?
753
+			$this->profileID : $_accountData[$id], false, 'ident_id') as $accountData)
754 754
 		{
755 755
 			return $accountData;
756 756
 		}
@@ -766,13 +766,13 @@  discard block
 block discarded – undo
766 766
 	{
767 767
 		// account select box
768 768
 		$selectedID = $this->profileID;
769
-		$allAccountData = Mail\Account::search($only_current_user=true, false, null);
769
+		$allAccountData = Mail\Account::search($only_current_user = true, false, null);
770 770
 		if ($allAccountData) {
771
-			$rememberFirst=$selectedFound=null;
771
+			$rememberFirst = $selectedFound = null;
772 772
 			foreach ($allAccountData as $tmpkey => $icServers)
773 773
 			{
774 774
 				if (is_null($rememberFirst)) $rememberFirst = $tmpkey;
775
-				if ($tmpkey == $selectedID) $selectedFound=true;
775
+				if ($tmpkey == $selectedID) $selectedFound = true;
776 776
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($icServers->acc_imap_host));
777 777
 				$host = $icServers->acc_imap_host;
778 778
 				if (empty($host)) continue;
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($identities[$icServers->acc_id]));
781 781
 			}
782 782
 		}
783
-		return ($selectedFound?$selectedID:$rememberFirst);
783
+		return ($selectedFound ? $selectedID : $rememberFirst);
784 784
 	}
785 785
 
786 786
 	/**
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
 	 * @var boolean $fullString full or false=NamePart only is returned
791 791
 	 * @return string - constructed of identity object data as defined in mailConfig
792 792
 	 */
793
-	static function generateIdentityString($identity, $fullString=true)
793
+	static function generateIdentityString($identity, $fullString = true)
794 794
 	{
795 795
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($identity));
796 796
 		//if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
@@ -801,16 +801,16 @@  discard block
 block discarded – undo
801 801
 		{
802 802
 			case 'email';
803 803
 				//$retData = str_replace('@',' ',$identity->emailAddress).($fullString===true?' <'.$identity->emailAddress.'>':'');
804
-				$retData = $identity['ident_email'].($fullString===true?' <'.$identity['ident_email'].'>':'');
804
+				$retData = $identity['ident_email'].($fullString === true ? ' <'.$identity['ident_email'].'>' : '');
805 805
 				break;
806 806
 			case 'nameNemail';
807
-				$retData = (!empty($identity['ident_realname'])?$identity['ident_realname']:substr_replace($identity['ident_email'],'',strpos($identity['ident_email'],'@'))).($fullString===true?' <'.$identity['ident_email'].'>':'');
807
+				$retData = (!empty($identity['ident_realname']) ? $identity['ident_realname'] : substr_replace($identity['ident_email'], '', strpos($identity['ident_email'], '@'))).($fullString === true ? ' <'.$identity['ident_email'].'>' : '');
808 808
 				break;
809 809
 			case 'orgNemail';
810
-				$retData = (!empty($identity['ident_org'])?$identity['ident_org']:substr_replace($identity['ident_email'],'',0,strpos($identity['ident_email'],'@')+1)).($fullString===true?' <'.$identity['ident_email'].'>':'');
810
+				$retData = (!empty($identity['ident_org']) ? $identity['ident_org'] : substr_replace($identity['ident_email'], '', 0, strpos($identity['ident_email'], '@') + 1)).($fullString === true ? ' <'.$identity['ident_email'].'>' : '');
811 811
 				break;
812 812
 			default:
813
-				$retData = $identity['ident_realname'].(!empty($identity['ident_org'])?' '.$identity['ident_org']:'').($fullString===true?' <'.$identity['ident_email'].'>':'');
813
+				$retData = $identity['ident_realname'].(!empty($identity['ident_org']) ? ' '.$identity['ident_org'] : '').($fullString === true ? ' <'.$identity['ident_email'].'>' : '');
814 814
 		}
815 815
 		return $retData;
816 816
 	}
@@ -835,7 +835,7 @@  discard block
 block discarded – undo
835 835
 	 */
836 836
 	function reopen($_foldername)
837 837
 	{
838
-		if (self::$debugTimes) $starttime = microtime (true);
838
+		if (self::$debugTimes) $starttime = microtime(true);
839 839
 
840 840
 		//error_log(__METHOD__.' ('.__LINE__.') '."('$_foldername') ".function_backtrace());
841 841
 		// TODO: trying to reduce traffic to the IMAP Server here, introduces problems with fetching the bodies of
@@ -850,7 +850,7 @@  discard block
 block discarded – undo
850 850
 			}
851 851
 			$folderOpened = $_foldername;
852 852
 		//}
853
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') ');
853
+		if (self::$debugTimes) self::logRunTimes($starttime, null, 'Folder:'.$_foldername, __METHOD__.' ('.__LINE__.') ');
854 854
 	}
855 855
 
856 856
 
@@ -861,15 +861,15 @@  discard block
 block discarded – undo
861 861
 	 * @throws Horde_Imap_Client_Exception on connection error or authentication failure
862 862
 	 * @throws InvalidArgumentException on missing credentials
863 863
 	 */
864
-	function openConnection($_icServerID=0)
864
+	function openConnection($_icServerID = 0)
865 865
 	{
866 866
 		//error_log( "-------------------------->open connection ".function_backtrace());
867 867
 		//error_log(__METHOD__.' ('.__LINE__.') '.' ->'.array2string($this->icServer));
868
-		if (self::$debugTimes) $starttime = microtime (true);
869
-		$mailbox=null;
868
+		if (self::$debugTimes) $starttime = microtime(true);
869
+		$mailbox = null;
870 870
 		try
871 871
 		{
872
-			if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox'])) $mailbox = $this->sessionData['mailbox'];
872
+			if (isset($this->sessionData['mailbox']) && $this->folderExists($this->sessionData['mailbox'])) $mailbox = $this->sessionData['mailbox'];
873 873
 			if (empty($mailbox)) $mailbox = $this->icServer->getCurrentMailbox();
874 874
 /*
875 875
 			if (isset(Mail\Imap::$supports_keywords[$_icServerID]))
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
 			error_log(__METHOD__.' ('.__LINE__.') '."->open connection for Server with profileID:".$_icServerID." trying to examine ($mailbox) failed!".$e->getMessage());
897 897
 			throw new Exception(__METHOD__." failed to ".__METHOD__." on Profile to $_icServerID while trying to examine $mailbox:".$e->getMessage());
898 898
 		}
899
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') ');
899
+		if (self::$debugTimes) self::logRunTimes($starttime, null, 'ProfileID:'.$_icServerID, __METHOD__.' ('.__LINE__.') ');
900 900
 	}
901 901
 
902 902
 	/**
@@ -909,7 +909,7 @@  discard block
 block discarded – undo
909 909
 	{
910 910
 		static $quota;
911 911
 		if (isset($quota)) return $quota;
912
-		if (isset(self::$profileDefunct[$this->profileID]) && self::$profileDefunct[$this->profileID]===true)
912
+		if (isset(self::$profileDefunct[$this->profileID]) && self::$profileDefunct[$this->profileID] === true)
913 913
 		{
914 914
 			// something is wrong. Do not proceed. either no folder or profile is marked as defunct for this request
915 915
 			return false;
@@ -917,7 +917,7 @@  discard block
 block discarded – undo
917 917
 		try
918 918
 		{
919 919
 			$this->icServer->getCurrentMailbox();
920
-			if(!$this->icServer->hasCapability('QUOTA')) {
920
+			if (!$this->icServer->hasCapability('QUOTA')) {
921 921
 				$quota = false;
922 922
 				return false;
923 923
 			}
@@ -927,14 +927,14 @@  discard block
 block discarded – undo
927 927
 		{
928 928
 			//error_log(__METHOD__.array2string($e));
929 929
 			//error_log(__METHOD__." failed to fetch quota on ".$this->profileID.' Reason:'.$e->getMessage().($e->details?', '.$e->details:'')/*.function_backtrace()*/);
930
-			if ($e->getCode()==102)
930
+			if ($e->getCode() == 102)
931 931
 			{
932
-				self::$profileDefunct[$this->profileID]=true;
933
-				throw new Exception(__METHOD__." failed to fetch quota on ".$this->profileID.' Reason:'.$e->getMessage().($e->details?', '.$e->details:''));
932
+				self::$profileDefunct[$this->profileID] = true;
933
+				throw new Exception(__METHOD__." failed to fetch quota on ".$this->profileID.' Reason:'.$e->getMessage().($e->details ? ', '.$e->details : ''));
934 934
 			}
935 935
 		}
936 936
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($quota));
937
-		if(is_array($quota)) {
937
+		if (is_array($quota)) {
938 938
 			$quota = array(
939 939
 				'usage'	=> $quota['USED'],
940 940
 				'limit'	=> $quota['QMAX'],
@@ -952,10 +952,10 @@  discard block
 block discarded – undo
952 952
 	 *
953 953
 	 * @return int - timeout (either set or default 20/10)
954 954
 	 */
955
-	static function getTimeOut($_use='IMAP')
955
+	static function getTimeOut($_use = 'IMAP')
956 956
 	{
957 957
 		$timeout = $GLOBALS['egw_info']['user']['preferences']['mail']['connectionTimeout'];
958
-		if (empty($timeout)) $timeout = ($_use=='SIEVE'?10:20); // this is the default value
958
+		if (empty($timeout)) $timeout = ($_use == 'SIEVE' ? 10 : 20); // this is the default value
959 959
 		return $timeout;
960 960
 	}
961 961
 
@@ -976,18 +976,18 @@  discard block
 block discarded – undo
976 976
 		if (is_null($nameSpace)) $nameSpace = $this->icServer->getNameSpaceArray();
977 977
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($nameSpace));
978 978
 		if (is_array($nameSpace)) {
979
-			foreach($nameSpace as $type => $singleNameSpaceArray)
979
+			foreach ($nameSpace as $type => $singleNameSpaceArray)
980 980
 			{
981 981
 				foreach ($singleNameSpaceArray as $singleNameSpace)
982 982
 				{
983 983
 					$_foldersNameSpace = array();
984
-					if($type == 'personal' && $singleNameSpace['name'] == '#mh/' && ($this->folderExists('Mail')||$this->folderExists('INBOX')))
984
+					if ($type == 'personal' && $singleNameSpace['name'] == '#mh/' && ($this->folderExists('Mail') || $this->folderExists('INBOX')))
985 985
 					{
986 986
 						$_foldersNameSpace['prefix_present'] = 'forced';
987 987
 						// uw-imap server with mailbox prefix or dovecot maybe
988
-						$_foldersNameSpace['prefix'] = ($this->folderExists('Mail')?'Mail':(!empty($singleNameSpace['name'])?$singleNameSpace['name']:''));
988
+						$_foldersNameSpace['prefix'] = ($this->folderExists('Mail') ? 'Mail' : (!empty($singleNameSpace['name']) ? $singleNameSpace['name'] : ''));
989 989
 					}
990
-					elseif($type == 'personal' && ($singleNameSpace['name'] == '#mh/') && $this->folderExists('mail'))
990
+					elseif ($type == 'personal' && ($singleNameSpace['name'] == '#mh/') && $this->folderExists('mail'))
991 991
 					{
992 992
 						$_foldersNameSpace['prefix_present'] = 'forced';
993 993
 						// uw-imap server with mailbox prefix or dovecot maybe
@@ -996,9 +996,9 @@  discard block
 block discarded – undo
996 996
 						$_foldersNameSpace['prefix_present'] = !empty($singleNameSpace['name']);
997 997
 						$_foldersNameSpace['prefix'] = $singleNameSpace['name'];
998 998
 					}
999
-					$_foldersNameSpace['delimiter'] = ($singleNameSpace['delimiter']?$singleNameSpace['delimiter']:$delimiter);
999
+					$_foldersNameSpace['delimiter'] = ($singleNameSpace['delimiter'] ? $singleNameSpace['delimiter'] : $delimiter);
1000 1000
 					$_foldersNameSpace['type'] = $type;
1001
-					$foldersNameSpace[] =$_foldersNameSpace;
1001
+					$foldersNameSpace[] = $_foldersNameSpace;
1002 1002
 				}
1003 1003
 				//echo "############## $type->".print_r($foldersNameSpace[$type],true)." ###################<br>";
1004 1004
 			}
@@ -1016,10 +1016,10 @@  discard block
 block discarded – undo
1016 1016
 	 */
1017 1017
 	function getFolderPrefixFromNamespace($nameSpace, $folderName)
1018 1018
 	{
1019
-		foreach($nameSpace as &$singleNameSpace)
1019
+		foreach ($nameSpace as &$singleNameSpace)
1020 1020
 		{
1021 1021
 			//if (substr($singleNameSpace['prefix'],0,strlen($folderName))==$folderName) return $singleNameSpace['prefix'];
1022
-			if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix']) return $singleNameSpace['prefix'];
1022
+			if (substr($folderName, 0, strlen($singleNameSpace['prefix'])) == $singleNameSpace['prefix']) return $singleNameSpace['prefix'];
1023 1023
 		}
1024 1024
 		return "";
1025 1025
 	}
@@ -1030,12 +1030,12 @@  discard block
 block discarded – undo
1030 1030
 	 * @var boolean $_useCache
1031 1031
 	 * @return string the hierarchyDelimiter
1032 1032
 	 */
1033
-	function getHierarchyDelimiter($_useCache=true)
1033
+	function getHierarchyDelimiter($_useCache = true)
1034 1034
 	{
1035 1035
 		static $HierarchyDelimiter = null;
1036
-		if (is_null($HierarchyDelimiter)) $HierarchyDelimiter = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1037
-		if ($_useCache===false) unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1038
-		if (isset($HierarchyDelimiter[$this->icServer->ImapServerId])&&!empty($HierarchyDelimiter[$this->icServer->ImapServerId]))
1036
+		if (is_null($HierarchyDelimiter)) $HierarchyDelimiter = Cache::getCache(Cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 24 * 5);
1037
+		if ($_useCache === false) unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1038
+		if (isset($HierarchyDelimiter[$this->icServer->ImapServerId]) && !empty($HierarchyDelimiter[$this->icServer->ImapServerId]))
1039 1039
 		{
1040 1040
 			return $HierarchyDelimiter[$this->icServer->ImapServerId];
1041 1041
 		}
@@ -1045,13 +1045,13 @@  discard block
 block discarded – undo
1045 1045
 			$this->icServer->getCurrentMailbox();
1046 1046
 			$HierarchyDelimiter[$this->icServer->ImapServerId] = $this->icServer->getDelimiter();
1047 1047
 		}
1048
-		catch(\Exception $e)
1048
+		catch (\Exception $e)
1049 1049
 		{
1050
-			if ($e->getCode()==102) self::$profileDefunct[$this->profileID]=true;
1050
+			if ($e->getCode() == 102) self::$profileDefunct[$this->profileID] = true;
1051 1051
 			unset($e);
1052 1052
 			$HierarchyDelimiter[$this->icServer->ImapServerId] = '/';
1053 1053
 		}
1054
-		Cache::setCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),$HierarchyDelimiter, 60*60*24*5);
1054
+		Cache::setCache(Cache::INSTANCE, 'email', 'HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']), $HierarchyDelimiter, 60 * 60 * 24 * 5);
1055 1055
 		return $HierarchyDelimiter[$this->icServer->ImapServerId];
1056 1056
 	}
1057 1057
 
@@ -1064,7 +1064,7 @@  discard block
 block discarded – undo
1064 1064
 	{
1065 1065
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$this->icServer->ImapServerId.' Connected:'.$this->icServer->_connected);
1066 1066
 		static $_specialUseFolders = null;
1067
-		if (is_null($_specialUseFolders)||empty($_specialUseFolders)) $_specialUseFolders = Cache::getCache(Cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1067
+		if (is_null($_specialUseFolders) || empty($_specialUseFolders)) $_specialUseFolders = Cache::getCache(Cache::INSTANCE, 'email', 'specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 24 * 5);
1068 1068
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_trash));
1069 1069
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_sent));
1070 1070
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_draft));
@@ -1072,20 +1072,20 @@  discard block
 block discarded – undo
1072 1072
 		self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId];
1073 1073
 		if (isset($_specialUseFolders[$this->icServer->ImapServerId]) && !empty($_specialUseFolders[$this->icServer->ImapServerId]))
1074 1074
 			return $_specialUseFolders[$this->icServer->ImapServerId];
1075
-		$_specialUseFolders[$this->icServer->ImapServerId]=array();
1075
+		$_specialUseFolders[$this->icServer->ImapServerId] = array();
1076 1076
 		//if (!empty($this->icServer->acc_folder_trash) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]))
1077
-			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]='Trash';
1077
+			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash] = 'Trash';
1078 1078
 		//if (!empty($this->icServer->acc_folder_draft) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_draft]))
1079
-			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_draft]='Drafts';
1079
+			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_draft] = 'Drafts';
1080 1080
 		//if (!empty($this->icServer->acc_folder_sent) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_sent]))
1081
-			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_sent]='Sent';
1081
+			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_sent] = 'Sent';
1082 1082
 		//if (!empty($this->icServer->acc_folder_template) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_template]))
1083
-			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_template]='Templates';
1084
-		$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_junk]='Junk';
1085
-		$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_archive]='Archive';
1083
+			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_template] = 'Templates';
1084
+		$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_junk] = 'Junk';
1085
+		$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_archive] = 'Archive';
1086 1086
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_specialUseFolders));//.'<->'.array2string($this->icServer));
1087 1087
 		self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId];
1088
-		Cache::setCache(Cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),$_specialUseFolders, 60*60*24*5);
1088
+		Cache::setCache(Cache::INSTANCE, 'email', 'specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']), $_specialUseFolders, 60 * 60 * 24 * 5);
1089 1089
 		return $_specialUseFolders[$this->icServer->ImapServerId];
1090 1090
 	}
1091 1091
 
@@ -1099,8 +1099,8 @@  discard block
 block discarded – undo
1099 1099
 	function folderIsSelectable($folderToSelect)
1100 1100
 	{
1101 1101
 		$retval = true;
1102
-		if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true))) {
1103
-			if (!empty($folderStatus['attributes']) && stripos(array2string($folderStatus['attributes']),'noselect')!==false)
1102
+		if ($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect, false, true))) {
1103
+			if (!empty($folderStatus['attributes']) && stripos(array2string($folderStatus['attributes']), 'noselect') !== false)
1104 1104
 			{
1105 1105
 				$retval = false;
1106 1106
 			}
@@ -1120,7 +1120,7 @@  discard block
 block discarded – undo
1120 1120
 	 *
1121 1121
 	 * @throws Exception
1122 1122
 	 */
1123
-	function _getStatus($folderName,$ignoreStatusCache=false)
1123
+	function _getStatus($folderName, $ignoreStatusCache = false)
1124 1124
 	{
1125 1125
 		static $folderStatus = null;
1126 1126
 		if (!$ignoreStatusCache && isset($folderStatus[$this->icServer->ImapServerId][$folderName]))
@@ -1130,11 +1130,11 @@  discard block
 block discarded – undo
1130 1130
 		}
1131 1131
 		try
1132 1132
 		{
1133
-			$folderStatus[$this->icServer->ImapServerId][$folderName] = $this->icServer->getStatus($folderName,$ignoreStatusCache);
1133
+			$folderStatus[$this->icServer->ImapServerId][$folderName] = $this->icServer->getStatus($folderName, $ignoreStatusCache);
1134 1134
 		}
1135 1135
 		catch (\Exception $e)
1136 1136
 		{
1137
-			throw new Exception(__METHOD__.' ('.__LINE__.') '." failed for $folderName with error:".$e->getMessage().($e->details?', '.$e->details:''));
1137
+			throw new Exception(__METHOD__.' ('.__LINE__.') '." failed for $folderName with error:".$e->getMessage().($e->details ? ', '.$e->details : ''));
1138 1138
 		}
1139 1139
 		return $folderStatus[$this->icServer->ImapServerId][$folderName];
1140 1140
 	}
@@ -1150,10 +1150,10 @@  discard block
 block discarded – undo
1150 1150
 	 * @param fetchSubscribedInfo bool fetch Subscribed Info on folder
1151 1151
 	 * @return array
1152 1152
 	 */
1153
-	function getFolderStatus($_folderName,$ignoreStatusCache=false,$basicInfoOnly=false,$fetchSubscribedInfo=true)
1153
+	function getFolderStatus($_folderName, $ignoreStatusCache = false, $basicInfoOnly = false, $fetchSubscribedInfo = true)
1154 1154
 	{
1155 1155
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly");
1156
-		if (!is_string($_folderName) || empty($_folderName)||(isset(self::$profileDefunct[$this->profileID]) && self::$profileDefunct[$this->profileID]===true))
1156
+		if (!is_string($_folderName) || empty($_folderName) || (isset(self::$profileDefunct[$this->profileID]) && self::$profileDefunct[$this->profileID] === true))
1157 1157
 		{
1158 1158
 			// something is wrong. Do not proceed. either no folder or profile is marked as defunct for this request
1159 1159
 			return false;
@@ -1164,7 +1164,7 @@  discard block
 block discarded – undo
1164 1164
 		{
1165 1165
 			$folderInfoCache = $folderBasicInfo[$this->profileID];
1166 1166
 		}
1167
-		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly) return $folderInfoCache[$_folderName];
1167
+		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache == false && $basicInfoOnly) return $folderInfoCache[$_folderName];
1168 1168
 		$retValue = array();
1169 1169
 		$retValue['subscribed'] = false;
1170 1170
 /*
@@ -1185,39 +1185,39 @@  discard block
 block discarded – undo
1185 1185
 			{
1186 1186
 				//error_log(__METHOD__.array2string($e));
1187 1187
 				//error_log(__METHOD__." failed to fetch Mailbox $_folderName on ".$this->profileID.' Reason:'.$e->getMessage().($e->details?', '.$e->details:'')/*.function_backtrace()*/);
1188
-				self::$profileDefunct[$this->profileID]=true;
1189
-				throw new Exception(__METHOD__." failed to fetch Mailbox $_folderName on ".$this->profileID.' Reason:'.$e->getMessage().($e->details?', '.$e->details:''));
1188
+				self::$profileDefunct[$this->profileID] = true;
1189
+				throw new Exception(__METHOD__." failed to fetch Mailbox $_folderName on ".$this->profileID.' Reason:'.$e->getMessage().($e->details ? ', '.$e->details : ''));
1190 1190
 			}
1191 1191
 			//error_log(__METHOD__.' ('.__LINE__.') '.$_folderName.' '.array2string($ret));
1192 1192
 			if (is_array($ret))
1193 1193
 			{
1194 1194
 				$retkeys = array_keys($ret);
1195
-				if ($retkeys[0]==$_folderName) $folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1195
+				if ($retkeys[0] == $_folderName) $folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1196 1196
 			}
1197 1197
 			else
1198 1198
 			{
1199
-				$folderInfoCache[$_folderName]=false;
1199
+				$folderInfoCache[$_folderName] = false;
1200 1200
 			}
1201 1201
 		}
1202 1202
 		$folderInfo = $folderInfoCache[$_folderName];
1203 1203
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($folderInfo).'->'.function_backtrace());
1204
-		if($ignoreStatusCache||!$folderInfo|| !is_array($folderInfo)) {
1204
+		if ($ignoreStatusCache || !$folderInfo || !is_array($folderInfo)) {
1205 1205
 			try
1206 1206
 			{
1207
-				$folderInfo = $this->_getStatus($_folderName,$ignoreStatusCache);
1207
+				$folderInfo = $this->_getStatus($_folderName, $ignoreStatusCache);
1208 1208
 			}
1209 1209
 			catch (\Exception $e)
1210 1210
 			{
1211 1211
 				//error_log(__METHOD__.array2string($e));
1212
-				error_log(__METHOD__." failed to fetch status for $_folderName on ".$this->profileID.' Reason:'.$e->getMessage().($e->details?', '.$e->details:'')/*.function_backtrace()*/);
1213
-				self::$profileDefunct[$this->profileID]=true;
1212
+				error_log(__METHOD__." failed to fetch status for $_folderName on ".$this->profileID.' Reason:'.$e->getMessage().($e->details ? ', '.$e->details : '')/*.function_backtrace()*/);
1213
+				self::$profileDefunct[$this->profileID] = true;
1214 1214
 				//throw new Exception(__METHOD__." failed to fetch status for $_folderName on ".$this->profileID.' Reason:'.$e->getMessage().($e->details?', '.$e->details:''));
1215
-				$folderInfo=null;
1215
+				$folderInfo = null;
1216 1216
 			}
1217 1217
 			if (!is_array($folderInfo))
1218 1218
 			{
1219 1219
 				// no folder info, but there is a status returned for the folder: something is wrong, try to cope with it
1220
-				$folderInfo = is_array($folderInfo)?$folderInfo:array('HIERACHY_DELIMITER'=>$this->getHierarchyDelimiter(),
1220
+				$folderInfo = is_array($folderInfo) ? $folderInfo : array('HIERACHY_DELIMITER'=>$this->getHierarchyDelimiter(),
1221 1221
 					'ATTRIBUTES' => '');
1222 1222
 				if (!isset($folderInfo['HIERACHY_DELIMITER']) || empty($folderInfo['HIERACHY_DELIMITER']) || (isset($folderInfo['delimiter']) && empty($folderInfo['delimiter'])))
1223 1223
 				{
@@ -1229,24 +1229,24 @@  discard block
 block discarded – undo
1229 1229
 		#if(!is_array($folderInfo)) {
1230 1230
 		#	return false;
1231 1231
 		#}
1232
-		$retValue['delimiter']		= (isset($folderInfo['HIERACHY_DELIMITER']) && $folderInfo['HIERACHY_DELIMITER']?$folderInfo['HIERACHY_DELIMITER']:$folderInfo['delimiter']);
1233
-		$retValue['attributes']		= (isset($folderInfo['ATTRIBUTES']) && $folderInfo['ATTRIBUTES']?$folderInfo['ATTRIBUTES']:$folderInfo['attributes']);
1234
-		$shortNameParts			= explode($retValue['delimiter'], $_folderName);
1232
+		$retValue['delimiter']		= (isset($folderInfo['HIERACHY_DELIMITER']) && $folderInfo['HIERACHY_DELIMITER'] ? $folderInfo['HIERACHY_DELIMITER'] : $folderInfo['delimiter']);
1233
+		$retValue['attributes']		= (isset($folderInfo['ATTRIBUTES']) && $folderInfo['ATTRIBUTES'] ? $folderInfo['ATTRIBUTES'] : $folderInfo['attributes']);
1234
+		$shortNameParts = explode($retValue['delimiter'], $_folderName);
1235 1235
 		$retValue['shortName']		= array_pop($shortNameParts);
1236 1236
 		$retValue['displayName']	= $_folderName;
1237
-		$retValue['shortDisplayName']	= $retValue['shortName'];
1238
-		if(strtoupper($retValue['shortName']) == 'INBOX') {
1239
-			$retValue['displayName']	= lang('INBOX');
1240
-			$retValue['shortDisplayName']	= lang('INBOX');
1237
+		$retValue['shortDisplayName'] = $retValue['shortName'];
1238
+		if (strtoupper($retValue['shortName']) == 'INBOX') {
1239
+			$retValue['displayName'] = lang('INBOX');
1240
+			$retValue['shortDisplayName'] = lang('INBOX');
1241 1241
 		}
1242 1242
 		// translate the automatic Folders (Sent, Drafts, ...) like the INBOX
1243
-		elseif (in_array($retValue['shortName'],self::$autoFolders))
1243
+		elseif (in_array($retValue['shortName'], self::$autoFolders))
1244 1244
 		{
1245 1245
 			$retValue['displayName'] = $retValue['shortDisplayName'] = lang($retValue['shortName']);
1246 1246
 		}
1247
-		if ($folderInfo) $folderBasicInfo[$this->profileID][$_folderName]=$retValue;
1247
+		if ($folderInfo) $folderBasicInfo[$this->profileID][$_folderName] = $retValue;
1248 1248
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.$_folderName.array2string($retValue['attributes']));
1249
-		if ($basicInfoOnly || (isset($retValue['attributes']) && stripos(array2string($retValue['attributes']),'noselect')!==false))
1249
+		if ($basicInfoOnly || (isset($retValue['attributes']) && stripos(array2string($retValue['attributes']), 'noselect') !== false))
1250 1250
 		{
1251 1251
 			return $retValue;
1252 1252
 		}
@@ -1259,12 +1259,12 @@  discard block
 block discarded – undo
1259 1259
 		if (is_null($nameSpace) || empty($nameSpace[$this->profileID])) $nameSpace[$this->profileID] = $this->_getNameSpaces();
1260 1260
 		if (!empty($nameSpace[$this->profileID]))
1261 1261
 		{
1262
-			$nsNoPersonal=array();
1263
-			foreach($nameSpace[$this->profileID] as &$ns)
1262
+			$nsNoPersonal = array();
1263
+			foreach ($nameSpace[$this->profileID] as &$ns)
1264 1264
 			{
1265
-				if ($ns['type']!='personal') $nsNoPersonal[]=$ns;
1265
+				if ($ns['type'] != 'personal') $nsNoPersonal[] = $ns;
1266 1266
 			}
1267
-			$nameSpace[$this->profileID]=$nsNoPersonal;
1267
+			$nameSpace[$this->profileID] = $nsNoPersonal;
1268 1268
 		}
1269 1269
 		if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName])) $prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName);
1270 1270
 
@@ -1273,33 +1273,33 @@  discard block
 block discarded – undo
1273 1273
 			$subscribedFolders[$this->profileID] = $this->icServer->listSubscribedMailboxes();
1274 1274
 		}
1275 1275
 
1276
-		if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID])) {
1276
+		if ($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName, $subscribedFolders[$this->profileID])) {
1277 1277
 			$retValue['subscribed'] = true;
1278 1278
 		}
1279 1279
 
1280 1280
 		try
1281 1281
 		{
1282 1282
 			//$folderStatus = $this->_getStatus($_folderName,$ignoreStatusCache);
1283
-			$folderStatus = $this->getMailBoxCounters($_folderName,false);
1284
-			$retValue['messages']		= $folderStatus['MESSAGES'];
1283
+			$folderStatus = $this->getMailBoxCounters($_folderName, false);
1284
+			$retValue['messages'] = $folderStatus['MESSAGES'];
1285 1285
 			$retValue['recent']		= $folderStatus['RECENT'];
1286
-			$retValue['uidnext']		= $folderStatus['UIDNEXT'];
1287
-			$retValue['uidvalidity']	= $folderStatus['UIDVALIDITY'];
1286
+			$retValue['uidnext'] = $folderStatus['UIDNEXT'];
1287
+			$retValue['uidvalidity'] = $folderStatus['UIDVALIDITY'];
1288 1288
 			$retValue['unseen']		= $folderStatus['UNSEEN'];
1289 1289
 			if (//$retValue['unseen']==0 &&
1290 1290
 				(isset($this->mailPreferences['trustServersUnseenInfo']) && // some servers dont serve the UNSEEN information
1291
-				$this->mailPreferences['trustServersUnseenInfo']==false) ||
1291
+				$this->mailPreferences['trustServersUnseenInfo'] == false) ||
1292 1292
 				(isset($this->mailPreferences['trustServersUnseenInfo']) &&
1293
-				$this->mailPreferences['trustServersUnseenInfo']==2 &&
1294
-				$prefix[$this->profileID][$_folderName] != '' && stripos($_folderName,$prefix[$this->profileID][$_folderName]) !== false)
1293
+				$this->mailPreferences['trustServersUnseenInfo'] == 2 &&
1294
+				$prefix[$this->profileID][$_folderName] != '' && stripos($_folderName, $prefix[$this->profileID][$_folderName]) !== false)
1295 1295
 			)
1296 1296
 			{
1297 1297
 				//error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($prefix,true).' TS:'.$this->mailPreferences['trustServersUnseenInfo']);
1298 1298
 				// we filter for the combined status of unseen and undeleted, as this is what we show in list
1299 1299
 				try
1300 1300
 				{
1301
-					$byUid=true;
1302
-					$sortResult = $this->getSortedList($_folderName, $_sort=0, $_reverse=1, array('status'=>array('UNSEEN','UNDELETED')),$byUid,false);
1301
+					$byUid = true;
1302
+					$sortResult = $this->getSortedList($_folderName, $_sort = 0, $_reverse = 1, array('status'=>array('UNSEEN', 'UNDELETED')), $byUid, false);
1303 1303
 					$retValue['unseen'] = $sortResult['count'];
1304 1304
 				}
1305 1305
 				catch (\Exception $ee)
@@ -1310,7 +1310,7 @@  discard block
 block discarded – undo
1310 1310
 		}
1311 1311
 		catch (\Exception $e)
1312 1312
 		{
1313
-			if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1313
+			if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(), true));
1314 1314
 		}
1315 1315
 
1316 1316
 		return $retValue;
@@ -1332,7 +1332,7 @@  discard block
 block discarded – undo
1332 1332
 	 * @param mixed $_fetchPreviews = false (boolean/int) fetch part of the body of the messages requested (if integer the number is assumed to be the number of chars to be returned for preview; if set to true 300 chars are returned (when available))
1333 1333
 	 * @return array result as array(header=>array,total=>int,first=>int,last=>int)
1334 1334
 	 */
1335
-	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true, $_fetchPreviews=false)
1335
+	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly = null, $_cacheResult = true, $_fetchPreviews = false)
1336 1336
 	{
1337 1337
 		//self::$debug=true;
1338 1338
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
@@ -1345,7 +1345,7 @@  discard block
 block discarded – undo
1345 1345
 		$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
1346 1346
 		#print "<pre>";
1347 1347
 		#$this->icServer->setDebug(true);
1348
-		$total=0;
1348
+		$total = 0;
1349 1349
 		if ($_thisUIDOnly === null)
1350 1350
 		{
1351 1351
 			if (($_startMessage || $_numberOfMessages) && !isset($_filter['range']))
@@ -1358,24 +1358,24 @@  discard block
 block discarded – undo
1358 1358
 				//$_filter['range'] ="$_startMessage:*";
1359 1359
 			}
1360 1360
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1361
-			if (self::$debug||self::$debugTimes) $starttime = microtime (true);
1361
+			if (self::$debug || self::$debugTimes) $starttime = microtime(true);
1362 1362
 			//see this example below for a 12 week datefilter (since)
1363 1363
 			//$_filter = array('status'=>array('UNDELETED'),'type'=>"SINCE",'string'=> date("d-M-Y", $starttime-(3600*24*7*12)));
1364 1364
 			$_sortResult = $this->getSortedList($_folderName, $_sort, $reverse, $_filter, $rByUid, $_cacheResult);
1365 1365
 			$sortResult = $_sortResult['match']->ids;
1366 1366
 			//$modseq = $_sortResult['modseq'];
1367 1367
 			//error_log(__METHOD__.' ('.__LINE__.') '.'Modsequence:'.$modseq);
1368
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1368
+			if (self::$debug || self::$debugTimes) self::logRunTimes($starttime, null, ' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly), __METHOD__.' ('.__LINE__.') ');
1369 1369
 
1370 1370
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1371 1371
 			#$this->icServer->setDebug(false);
1372 1372
 			#print "</pre>";
1373 1373
 			// nothing found
1374
-			if(!is_array($sortResult) || empty($sortResult)) {
1374
+			if (!is_array($sortResult) || empty($sortResult)) {
1375 1375
 				$retValue = array();
1376 1376
 				$retValue['info']['total']	= 0;
1377 1377
 				$retValue['info']['first']	= 0;
1378
-				$retValue['info']['last']	= 0;
1378
+				$retValue['info']['last'] = 0;
1379 1379
 				return $retValue;
1380 1380
 			}
1381 1381
 
@@ -1383,54 +1383,54 @@  discard block
 block discarded – undo
1383 1383
 			#_debug_array($sortResult);
1384 1384
 			#_debug_array(array_slice($sortResult, -5, -2));
1385 1385
 			//error_log("REVERSE: $reverse");
1386
-			if($reverse === true) {
1387
-				if  ($_startMessage<=$total)
1386
+			if ($reverse === true) {
1387
+				if ($_startMessage <= $total)
1388 1388
 				{
1389
-					$startMessage = $_startMessage-1;
1389
+					$startMessage = $_startMessage - 1;
1390 1390
 				}
1391 1391
 				else
1392 1392
 				{
1393 1393
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total);
1394
-					if ($_startMessage+$_numberOfMessages>$total)
1394
+					if ($_startMessage + $_numberOfMessages > $total)
1395 1395
 					{
1396
-						$numberOfMessages = $total%$_numberOfMessages;
1396
+						$numberOfMessages = $total % $_numberOfMessages;
1397 1397
 						//$numberOfMessages = abs($_startMessage-$total-1);
1398
-						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages) $_numberOfMessages = $numberOfMessages;
1398
+						if ($numberOfMessages > 0 && $numberOfMessages <= $_numberOfMessages) $_numberOfMessages = $numberOfMessages;
1399 1399
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total);
1400 1400
 					}
1401
-					$startMessage=($total-$_numberOfMessages)-1;
1401
+					$startMessage = ($total - $_numberOfMessages) - 1;
1402 1402
 					//$retValue['info']['first'] = $startMessage;
1403 1403
 					//$retValue['info']['last'] = $total;
1404 1404
 
1405 1405
 				}
1406
-				if ($startMessage+$_numberOfMessages>$total)
1406
+				if ($startMessage + $_numberOfMessages > $total)
1407 1407
 				{
1408
-					$_numberOfMessages = $_numberOfMessages-($total-($startMessage+$_numberOfMessages));
1408
+					$_numberOfMessages = $_numberOfMessages - ($total - ($startMessage + $_numberOfMessages));
1409 1409
 					//$retValue['info']['first'] = $startMessage;
1410 1410
 					//$retValue['info']['last'] = $total;
1411 1411
 				}
1412
-				if($startMessage > 0) {
1413
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1414
-					$sortResult = array_slice($sortResult, -($_numberOfMessages+$startMessage), -$startMessage);
1412
+				if ($startMessage > 0) {
1413
+					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages + $startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1414
+					$sortResult = array_slice($sortResult, -($_numberOfMessages + $startMessage), -$startMessage);
1415 1415
 				} else {
1416
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1417
-					$sortResult = array_slice($sortResult, -($_numberOfMessages+($_startMessage-1)));
1416
+					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages + ($_startMessage - 1))).', AllTheRest, Number of Messages:'.count($sortResult));
1417
+					$sortResult = array_slice($sortResult, -($_numberOfMessages + ($_startMessage - 1)));
1418 1418
 				}
1419 1419
 				$sortResult = array_reverse($sortResult);
1420 1420
 			} else {
1421
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1422
-				$sortResult = array_slice($sortResult, $_startMessage-1, $_numberOfMessages);
1421
+				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage - 1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1422
+				$sortResult = array_slice($sortResult, $_startMessage - 1, $_numberOfMessages);
1423 1423
 			}
1424 1424
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1425 1425
 		}
1426 1426
 		else
1427 1427
 		{
1428
-			$sortResult = (is_array($_thisUIDOnly) ? $_thisUIDOnly:(array)$_thisUIDOnly);
1428
+			$sortResult = (is_array($_thisUIDOnly) ? $_thisUIDOnly : (array)$_thisUIDOnly);
1429 1429
 		}
1430 1430
 
1431 1431
 
1432 1432
 		// fetch the data for the selected messages
1433
-		if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1433
+		if (self::$debug || self::$debugTimes) $starttime = microtime(true);
1434 1434
 		try
1435 1435
 		{
1436 1436
 			$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -1439,22 +1439,22 @@  discard block
 block discarded – undo
1439 1439
 			$fquery = new Horde_Imap_Client_Fetch_Query();
1440 1440
 
1441 1441
 			// Pre-cache the headers we want, 'fetchHeaders' is a label into the cache
1442
-			$fquery->headers('fetchHeaders',array(
1443
-				'DISPOSITION-NOTIFICATION-TO','RETURN-RECEIPT-TO','X-CONFIRM-READING-TO',
1444
-				'DATE','SUBJECT','FROM','TO','CC',
1442
+			$fquery->headers('fetchHeaders', array(
1443
+				'DISPOSITION-NOTIFICATION-TO', 'RETURN-RECEIPT-TO', 'X-CONFIRM-READING-TO',
1444
+				'DATE', 'SUBJECT', 'FROM', 'TO', 'CC',
1445 1445
 				'X-PRIORITY'
1446
-			),array(
1446
+			), array(
1447 1447
 				// Cache headers, we'll look at them below
1448
-				'cache' => true,//$_cacheResult,
1448
+				'cache' => true, //$_cacheResult,
1449 1449
 				// Set peek so messages are not flagged as read
1450 1450
 				'peek' => true
1451 1451
 			));
1452 1452
 			$fquery->size();
1453 1453
 			$fquery->structure();
1454 1454
 			$fquery->flags();
1455
-			$fquery->imapDate();// needed to ensure getImapDate fetches the internaldate, not the current time
1455
+			$fquery->imapDate(); // needed to ensure getImapDate fetches the internaldate, not the current time
1456 1456
 			// if $_fetchPreviews is activated fetch part of the messages too
1457
-			if ($_fetchPreviews) $fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0));
1457
+			if ($_fetchPreviews) $fquery->fullText(array('peek'=>true, 'length'=>((int)$_fetchPreviews < 5000 ? 5000 : $_fetchPreviews), 'start'=>0));
1458 1458
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
1459 1459
 				'ids' => $uidsToFetch,
1460 1460
 			));
@@ -1465,9 +1465,9 @@  discard block
 block discarded – undo
1465 1465
 			$headersNew = array();
1466 1466
 			$sortResult = array();
1467 1467
 		}
1468
-		if (self::$debug||self::$debugTimes)
1468
+		if (self::$debug || self::$debugTimes)
1469 1469
 		{
1470
-			self::logRunTimes($starttime,null,'HordeFetch: for Folder:'.$_folderName.' Filter:'.array2string($_filter),__METHOD__.' ('.__LINE__.') ');
1470
+			self::logRunTimes($starttime, null, 'HordeFetch: for Folder:'.$_folderName.' Filter:'.array2string($_filter), __METHOD__.' ('.__LINE__.') ');
1471 1471
 			if (self::$debug)
1472 1472
 			{
1473 1473
 				$queryString = implode(',', $sortResult);
@@ -1477,27 +1477,27 @@  discard block
 block discarded – undo
1477 1477
 
1478 1478
 		$cnt = 0;
1479 1479
 
1480
-		foreach((array)$sortResult as $uid) {
1480
+		foreach ((array)$sortResult as $uid) {
1481 1481
 			$sortOrder[$uid] = $cnt++;
1482 1482
 		}
1483 1483
 
1484 1484
 		$count = 0;
1485 1485
 		if (is_object($headersNew)) {
1486
-			if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1487
-			foreach($headersNew->ids() as $id) {
1486
+			if (self::$debug || self::$debugTimes) $starttime = microtime(true);
1487
+			foreach ($headersNew->ids() as $id) {
1488 1488
 				$_headerObject = $headersNew->get($id);
1489 1489
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject));
1490 1490
 				$headerObject = array();
1491 1491
 				$bodyPreview = null;
1492
-				$uid = $headerObject['UID']= ($_headerObject->getUid()?$_headerObject->getUid():$id);
1492
+				$uid = $headerObject['UID'] = ($_headerObject->getUid() ? $_headerObject->getUid() : $id);
1493 1493
 				$headerObject['MSG_NUM'] = $_headerObject->getSeq();
1494 1494
 				$headerObject['SIZE'] = $_headerObject->getSize();
1495 1495
 				$headerObject['INTERNALDATE'] = $_headerObject->getImapDate();
1496 1496
 
1497 1497
 				// Get already cached headers, 'fetchHeaders' is a label matchimg above
1498
-				$headerForPrio = $_headerObject->getHeaders('fetchHeaders',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1498
+				$headerForPrio = $_headerObject->getHeaders('fetchHeaders', Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1499 1499
 				// Try to fetch header with key='' as some servers might have no fetchHeaders index. e.g. yandex.com
1500
-				if (empty($headerForPrio)) $headerForPrio = $_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1500
+				if (empty($headerForPrio)) $headerForPrio = $_headerObject->getHeaders('', Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1501 1501
 				//fetch the fullMsg part if all conditions match to be available in case $_headerObject->getHeaders returns
1502 1502
 				//nothing worthwhile (as it does for googlemail accounts, when preview is switched on
1503 1503
 				if ($_fetchPreviews)
@@ -1505,16 +1505,16 @@  discard block
 block discarded – undo
1505 1505
 					// on enabled preview $bodyPreview is needed lateron. fetched here, for fallback-reasons
1506 1506
 					// in case of failed Header-Retrieval
1507 1507
 					$bodyPreview = $_headerObject->getFullMsg();
1508
-					if (empty($headerForPrio)||(is_array($headerForPrio)&&count($headerForPrio)===1&&$headerForPrio['']))
1508
+					if (empty($headerForPrio) || (is_array($headerForPrio) && count($headerForPrio) === 1 && $headerForPrio['']))
1509 1509
 					{
1510 1510
 						$length = strpos($bodyPreview, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
1511
-						if ($length===false) $length = strlen($bodyPreview);
1512
-						$headerForPrio =  Horde_Mime_Headers::parseHeaders(substr($bodyPreview, 0,$length))->toArray();
1511
+						if ($length === false) $length = strlen($bodyPreview);
1512
+						$headerForPrio = Horde_Mime_Headers::parseHeaders(substr($bodyPreview, 0, $length))->toArray();
1513 1513
 					}
1514 1514
 				}
1515 1515
 				$headerForPrio = array_change_key_case($headerForPrio, CASE_UPPER);
1516 1516
 				if (self::$debug) {
1517
-					error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject).'UID:'.$_headerObject->getUid().' Size:'.$_headerObject->getSize().' Date:'.$_headerObject->getImapDate().'/'.DateTime::to($_headerObject->getImapDate(),'Y-m-d H:i:s'));
1517
+					error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject).'UID:'.$_headerObject->getUid().' Size:'.$_headerObject->getSize().' Date:'.$_headerObject->getImapDate().'/'.DateTime::to($_headerObject->getImapDate(), 'Y-m-d H:i:s'));
1518 1518
 					error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerForPrio));
1519 1519
 				}
1520 1520
 				// message deleted from server but cache still reporting its existence ; may happen on QRESYNC with No permanent modsequences
@@ -1523,21 +1523,21 @@  discard block
 block discarded – undo
1523 1523
 					$total--;
1524 1524
 					continue;
1525 1525
 				}
1526
-				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) ) {
1526
+				if (isset($headerForPrio['DISPOSITION-NOTIFICATION-TO'])) {
1527 1527
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['DISPOSITION-NOTIFICATION-TO']));
1528
-				} else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) ) {
1528
+				} else if (isset($headerForPrio['RETURN-RECEIPT-TO'])) {
1529 1529
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['RETURN-RECEIPT-TO']));
1530
-				} else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) ) {
1530
+				} else if (isset($headerForPrio['X-CONFIRM-READING-TO'])) {
1531 1531
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['X-CONFIRM-READING-TO']));
1532 1532
 				} /*else $sent_not = "";*/
1533 1533
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
1534 1534
 				$headerObject['DATE'] = $headerForPrio['DATE'];
1535
-				$headerObject['SUBJECT'] = (is_array($headerForPrio['SUBJECT'])?$headerForPrio['SUBJECT'][0]:$headerForPrio['SUBJECT']);
1536
-				$headerObject['FROM'] = (array)($headerForPrio['FROM']?$headerForPrio['FROM']:($headerForPrio['REPLY-TO']?$headerForPrio['REPLY-TO']:$headerForPrio['RETURN-PATH']));
1535
+				$headerObject['SUBJECT'] = (is_array($headerForPrio['SUBJECT']) ? $headerForPrio['SUBJECT'][0] : $headerForPrio['SUBJECT']);
1536
+				$headerObject['FROM'] = (array)($headerForPrio['FROM'] ? $headerForPrio['FROM'] : ($headerForPrio['REPLY-TO'] ? $headerForPrio['REPLY-TO'] : $headerForPrio['RETURN-PATH']));
1537 1537
 				$headerObject['TO'] = (array)$headerForPrio['TO'];
1538
-				$headerObject['CC'] = isset($headerForPrio['CC'])?(array)$headerForPrio['CC']:array();
1539
-				$headerObject['PRIORITY'] = isset($headerForPrio['X-PRIORITY'])?$headerForPrio['X-PRIORITY']:null;
1540
-				foreach (array('FROM','TO','CC') as $key)
1538
+				$headerObject['CC'] = isset($headerForPrio['CC']) ? (array)$headerForPrio['CC'] : array();
1539
+				$headerObject['PRIORITY'] = isset($headerForPrio['X-PRIORITY']) ? $headerForPrio['X-PRIORITY'] : null;
1540
+				foreach (array('FROM', 'TO', 'CC') as $key)
1541 1541
 				{
1542 1542
 					$address = array();
1543 1543
 					foreach ($headerObject[$key] as $k => $ad)
@@ -1559,13 +1559,13 @@  discard block
 block discarded – undo
1559 1559
 						foreach ($rfcAddr as $_rfcAddr)
1560 1560
 						{
1561 1561
 							if (!$_rfcAddr->valid)	continue; // skip. not a valid address
1562
-							$address[] = imap_rfc822_write_address($_rfcAddr->mailbox,$_rfcAddr->host,$_rfcAddr->personal);
1562
+							$address[] = imap_rfc822_write_address($_rfcAddr->mailbox, $_rfcAddr->host, $_rfcAddr->personal);
1563 1563
 						}
1564 1564
 					}
1565 1565
 					$headerObject[$key] = $address;
1566 1566
 				}
1567 1567
 				$headerObject['FLAGS'] = $_headerObject->getFlags();
1568
-				$headerObject['BODYPREVIEW']=null;
1568
+				$headerObject['BODYPREVIEW'] = null;
1569 1569
 				// this section fetches part of the message-body (if enabled) for some kind of preview
1570 1570
 				// if we fail to succeed, we fall back to the retrieval of the message-body with
1571 1571
 				// fetchPartContents (see below, when we iterate over the structure to determine the
@@ -1577,17 +1577,17 @@  discard block
 block discarded – undo
1577 1577
 					if (empty($bodyPreview)) $bodyPreview = $_headerObject->getFullMsg();
1578 1578
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($bodyPreview));
1579 1579
 					$base = Horde_Mime_Part::parseMessage($bodyPreview);
1580
-					foreach($base->partIterator() as $part)
1580
+					foreach ($base->partIterator() as $part)
1581 1581
 					{
1582 1582
 						//error_log(__METHOD__.__LINE__.'Part:'.$part->getPrimaryType());
1583
-						if (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'text')
1583
+						if (empty($headerObject['BODYPREVIEW']) && $part->getPrimaryType() == 'text')
1584 1584
 						{
1585 1585
 							$charset = $part->getContentTypeParameter('charset');
1586 1586
 							$buffer = Mail\Html::convertHTMLToText($part->toString(array(
1587
-												'encode' => Horde_Mime_Part::ENCODE_BINARY,	// otherwise we cant recode charset
1587
+												'encode' => Horde_Mime_Part::ENCODE_BINARY, // otherwise we cant recode charset
1588 1588
 											)), $charset, 'utf-8');
1589
-							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Translation::convert_jsonsafe($buffer),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
1590
-						} elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart')
1589
+							$headerObject['BODYPREVIEW'] = trim(str_replace(array("\r\n", "\r", "\n"), ' ', mb_substr(Translation::convert_jsonsafe($buffer), 0, ((int)$_fetchPreviews < 300 ? 300 : $_fetchPreviews))));
1590
+						} elseif (empty($headerObject['BODYPREVIEW']) && $part->getPrimaryType() == 'multipart')
1591 1591
 						{
1592 1592
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part));
1593 1593
 						}
@@ -1598,12 +1598,12 @@  discard block
 block discarded – undo
1598 1598
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
1599 1599
 				//error_log(__METHOD__.' ('.__LINE__.') '.' MimeMap:'.array2string($mailStructureObject->contentTypeMap()));
1600 1600
 				//foreach ($_headerObject->getStructure()->getParts() as $p => $part)
1601
-				$headerObject['ATTACHMENTS']=null;
1602
-				$skipParts=array();
1603
-				$messageMimeType='';
1601
+				$headerObject['ATTACHMENTS'] = null;
1602
+				$skipParts = array();
1603
+				$messageMimeType = '';
1604 1604
 				foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
1605 1605
 				{
1606
-					if ($mime_id==0 || $messageMimeType==='') $messageMimeType = $mime_type;
1606
+					if ($mime_id == 0 || $messageMimeType === '') $messageMimeType = $mime_type;
1607 1607
 					$part = $mailStructureObject->getPart($mime_id);
1608 1608
 					$partdisposition = $part->getDisposition();
1609 1609
 					$partPrimaryType = $part->getPrimaryType();
@@ -1611,16 +1611,16 @@  discard block
 block discarded – undo
1611 1611
 					// drawback here it is talking to the mailserver for each mail thus consuming
1612 1612
 					// more time than expected; so we call this section only when there is no
1613 1613
 					// bodypreview could be found (multipart/....)
1614
-					if ($_fetchPreviews && empty($headerObject['BODYPREVIEW'])&&($partPrimaryType == 'text') &&
1614
+					if ($_fetchPreviews && empty($headerObject['BODYPREVIEW']) && ($partPrimaryType == 'text') &&
1615 1615
 						((intval($mime_id) === 1) || !$mime_id) &&
1616 1616
 						($partdisposition !== 'attachment')) {
1617
-							$_structure=$part;
1618
-							$this->fetchPartContents($uid, $_structure, false,true);
1619
-							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
1620
-							$charSet=Translation::detect_encoding($headerObject['BODYPREVIEW']);
1617
+							$_structure = $part;
1618
+							$this->fetchPartContents($uid, $_structure, false, true);
1619
+							$headerObject['BODYPREVIEW'] = trim(str_replace(array("\r\n", "\r", "\n"), ' ', mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()), 0, ((int)$_fetchPreviews < 300 ? 300 : $_fetchPreviews))));
1620
+							$charSet = Translation::detect_encoding($headerObject['BODYPREVIEW']);
1621 1621
 							// add line breaks to $bodyParts
1622 1622
 							//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
1623
-							$headerObject['BODYPREVIEW']  = Translation::convert_jsonsafe($headerObject['BODYPREVIEW'], $charSet);
1623
+							$headerObject['BODYPREVIEW'] = Translation::convert_jsonsafe($headerObject['BODYPREVIEW'], $charSet);
1624 1624
 							//error_log(__METHOD__.__LINE__.$headerObject['BODYPREVIEW']);
1625 1625
 					}
1626 1626
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType);
@@ -1630,28 +1630,28 @@  discard block
 block discarded – undo
1630 1630
 						// the presence of an cid does not necessarily indicate its inline. it may lack the needed
1631 1631
 						// link to show the image. Considering this: we "list" everything that matches the above criteria
1632 1632
 						// as attachment in order to not loose/miss information on our data
1633
-						$partdisposition='attachment';//($partPrimaryType == 'image'&&!empty($cid)?'inline':'attachment');
1633
+						$partdisposition = 'attachment'; //($partPrimaryType == 'image'&&!empty($cid)?'inline':'attachment');
1634 1634
 					}
1635
-					if ($mime_type=='message/rfc822')
1635
+					if ($mime_type == 'message/rfc822')
1636 1636
 					{
1637 1637
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
1638
-						foreach($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
1638
+						foreach ($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type; }
1639 1639
 					}
1640 1640
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType.' Skip:'.array2string($skipParts));
1641
-					if (array_key_exists($mime_id,$skipParts)) continue;
1642
-					if ($partdisposition=='attachment' ||
1643
-						($partdisposition=='inline'&&$partPrimaryType == 'image'&&$mime_type=='image/tiff') || // as we are not able to display tiffs
1644
-						($partdisposition=='inline'&&$partPrimaryType == 'image'&&empty($cid)) ||
1645
-						($partdisposition=='inline' && $partPrimaryType != 'image' && $partPrimaryType != 'multipart' && $partPrimaryType != 'text'))
1641
+					if (array_key_exists($mime_id, $skipParts)) continue;
1642
+					if ($partdisposition == 'attachment' ||
1643
+						($partdisposition == 'inline' && $partPrimaryType == 'image' && $mime_type == 'image/tiff') || // as we are not able to display tiffs
1644
+						($partdisposition == 'inline' && $partPrimaryType == 'image' && empty($cid)) ||
1645
+						($partdisposition == 'inline' && $partPrimaryType != 'image' && $partPrimaryType != 'multipart' && $partPrimaryType != 'text'))
1646 1646
 					{
1647
-						$headerObject['ATTACHMENTS'][$mime_id]=$part->getAllDispositionParameters();
1648
-						$headerObject['ATTACHMENTS'][$mime_id]['mimeType']=$mime_type;
1649
-						$headerObject['ATTACHMENTS'][$mime_id]['uid']=$uid;
1647
+						$headerObject['ATTACHMENTS'][$mime_id] = $part->getAllDispositionParameters();
1648
+						$headerObject['ATTACHMENTS'][$mime_id]['mimeType'] = $mime_type;
1649
+						$headerObject['ATTACHMENTS'][$mime_id]['uid'] = $uid;
1650 1650
 						$headerObject['ATTACHMENTS'][$mime_id]['cid'] = $cid;
1651
-						$headerObject['ATTACHMENTS'][$mime_id]['partID']=$mime_id;
1652
-						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1653
-						if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'],'winmail.dat') ||
1654
-							$headerObject['ATTACHMENTS'][$mime_id]['mimeType']=='application/ms-tnef')
1651
+						$headerObject['ATTACHMENTS'][$mime_id]['partID'] = $mime_id;
1652
+						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name'] = $part->getName();
1653
+						if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'], 'winmail.dat') ||
1654
+							$headerObject['ATTACHMENTS'][$mime_id]['mimeType'] == 'application/ms-tnef')
1655 1655
 						{
1656 1656
 							$headerObject['ATTACHMENTS'][$mime_id]['is_winmail'] = true;
1657 1657
 						}
@@ -1666,54 +1666,54 @@  discard block
 block discarded – undo
1666 1666
 				if (empty($headerObject['UID'])) continue;
1667 1667
 				//$uid = ($rByUid ? $headerObject['UID'] : $headerObject['MSG_NUM']);
1668 1668
 				// make dates like "Mon, 23 Apr 2007 10:11:06 UT" working with strtotime
1669
-				if(substr($headerObject['DATE'],-2) === 'UT') {
1669
+				if (substr($headerObject['DATE'], -2) === 'UT') {
1670 1670
 					$headerObject['DATE'] .= 'C';
1671 1671
 				}
1672
-				if(substr($headerObject['INTERNALDATE'],-2) === 'UT') {
1672
+				if (substr($headerObject['INTERNALDATE'], -2) === 'UT') {
1673 1673
 					$headerObject['INTERNALDATE'] .= 'C';
1674 1674
 				}
1675 1675
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$headerObject['SUBJECT'].'->'.$headerObject['DATE'].'<->'.$headerObject['INTERNALDATE'] .'#');
1676 1676
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$this->decode_subject($headerObject['SUBJECT']).'->'.$headerObject['DATE']);
1677
-				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;}
1678
-				$retValue['header'][$sortOrder[$uid]]['subject']	= $this->decode_subject($headerObject['SUBJECT']);
1679
-				$retValue['header'][$sortOrder[$uid]]['size'] 		= $headerObject['SIZE'];
1680
-				$retValue['header'][$sortOrder[$uid]]['date']		= self::_strtotime(($headerObject['DATE']&&!($headerObject['DATE']=='NIL')?$headerObject['DATE']:$headerObject['INTERNALDATE']),'ts',true);
1681
-				$retValue['header'][$sortOrder[$uid]]['internaldate']= self::_strtotime($headerObject['INTERNALDATE'],'ts',true);
1682
-				$retValue['header'][$sortOrder[$uid]]['mimetype']	= $messageMimeType;
1683
-				$retValue['header'][$sortOrder[$uid]]['id']		= $headerObject['MSG_NUM'];
1684
-				$retValue['header'][$sortOrder[$uid]]['uid']		= $headerObject['UID'];
1685
-				$retValue['header'][$sortOrder[$uid]]['bodypreview']		= $headerObject['BODYPREVIEW'];
1686
-				$retValue['header'][$sortOrder[$uid]]['priority']		= ($headerObject['PRIORITY']?$headerObject['PRIORITY']:3);
1677
+				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][] = $a; }
1678
+				$retValue['header'][$sortOrder[$uid]]['subject'] = $this->decode_subject($headerObject['SUBJECT']);
1679
+				$retValue['header'][$sortOrder[$uid]]['size'] = $headerObject['SIZE'];
1680
+				$retValue['header'][$sortOrder[$uid]]['date'] = self::_strtotime(($headerObject['DATE'] && !($headerObject['DATE'] == 'NIL') ? $headerObject['DATE'] : $headerObject['INTERNALDATE']), 'ts', true);
1681
+				$retValue['header'][$sortOrder[$uid]]['internaldate'] = self::_strtotime($headerObject['INTERNALDATE'], 'ts', true);
1682
+				$retValue['header'][$sortOrder[$uid]]['mimetype'] = $messageMimeType;
1683
+				$retValue['header'][$sortOrder[$uid]]['id'] = $headerObject['MSG_NUM'];
1684
+				$retValue['header'][$sortOrder[$uid]]['uid'] = $headerObject['UID'];
1685
+				$retValue['header'][$sortOrder[$uid]]['bodypreview'] = $headerObject['BODYPREVIEW'];
1686
+				$retValue['header'][$sortOrder[$uid]]['priority'] = ($headerObject['PRIORITY'] ? $headerObject['PRIORITY'] : 3);
1687 1687
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.array2string($retValue['header'][$sortOrder[$uid]]));
1688 1688
 				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO'])) $retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1689 1689
 				if (is_array($headerObject['FLAGS'])) {
1690
-					$retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]],self::prepareFlagsArray($headerObject));
1690
+					$retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]], self::prepareFlagsArray($headerObject));
1691 1691
 				}
1692 1692
 				//error_log(__METHOD__.' ('.__LINE__.') '.$headerObject['SUBJECT'].'->'.array2string($_headerObject->getEnvelope()->__get('from')));
1693
-				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0]) {
1694
-					$retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0],true);
1693
+				if (is_array($headerObject['FROM']) && $headerObject['FROM'][0]) {
1694
+					$retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0], true);
1695 1695
 				}
1696
-				if(is_array($headerObject['TO']) && $headerObject['TO'][0]) {
1697
-					$retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0],true);
1698
-					if (count($headerObject['TO'])>1)
1696
+				if (is_array($headerObject['TO']) && $headerObject['TO'][0]) {
1697
+					$retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0], true);
1698
+					if (count($headerObject['TO']) > 1)
1699 1699
 					{
1700
-						$ki=0;
1701
-						foreach($headerObject['TO'] as $k => $add)
1700
+						$ki = 0;
1701
+						foreach ($headerObject['TO'] as $k => $add)
1702 1702
 						{
1703
-							if ($k==0) continue;
1703
+							if ($k == 0) continue;
1704 1704
 							//error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add));
1705
-							$retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add,true);
1705
+							$retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add, true);
1706 1706
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki]));
1707 1707
 							$ki++;
1708 1708
 						}
1709 1709
 					}
1710 1710
 				}
1711
-				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0) {
1712
-					$ki=0;
1713
-					foreach($headerObject['CC'] as $k => $add)
1711
+				if (is_array($headerObject['CC']) && count($headerObject['CC']) > 0) {
1712
+					$ki = 0;
1713
+					foreach ($headerObject['CC'] as $k => $add)
1714 1714
 					{
1715 1715
 						//error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add));
1716
-						$retValue['header'][$sortOrder[$uid]]['cc_addresses'][$ki] = self::decode_header($add,true);
1716
+						$retValue['header'][$sortOrder[$uid]]['cc_addresses'][$ki] = self::decode_header($add, true);
1717 1717
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki]));
1718 1718
 						$ki++;
1719 1719
 					}
@@ -1722,27 +1722,27 @@  discard block
 block discarded – undo
1722 1722
 
1723 1723
 				$count++;
1724 1724
 			}
1725
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
1725
+			if (self::$debug || self::$debugTimes) self::logRunTimes($starttime, null, ' fetching Headers and stuff for Folder:'.$_folderName, __METHOD__.' ('.__LINE__.') ');
1726 1726
 			//self::$debug=false;
1727 1727
 			// sort the messages to the requested displayorder
1728
-			if(is_array($retValue['header'])) {
1728
+			if (is_array($retValue['header'])) {
1729 1729
 				$countMessages = $total;
1730 1730
 				if (isset($_filter['range'])) $countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
1731 1731
 				ksort($retValue['header']);
1732 1732
 				$retValue['info']['total']	= $total;
1733 1733
 				//if ($_startMessage>$total) $_startMessage = $total-($count-1);
1734 1734
 				$retValue['info']['first']	= $_startMessage;
1735
-				$retValue['info']['last']	= $_startMessage + $count - 1 ;
1735
+				$retValue['info']['last'] = $_startMessage + $count - 1;
1736 1736
 				return $retValue;
1737 1737
 			} else {
1738 1738
 				$retValue = array();
1739 1739
 				$retValue['info']['total']	= 0;
1740 1740
 				$retValue['info']['first']	= 0;
1741
-				$retValue['info']['last']	= 0;
1741
+				$retValue['info']['last'] = 0;
1742 1742
 				return $retValue;
1743 1743
 			}
1744 1744
 		} else {
1745
-			if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
1745
+			if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew, TRUE));
1746 1746
 			$retValue = array();
1747 1747
 			$retValue['info']['total']  = 0;
1748 1748
 			$retValue['info']['first']  = 0;
@@ -1759,17 +1759,17 @@  discard block
 block discarded – undo
1759 1759
 	 */
1760 1760
 	static function prepareFlagsArray($headerObject)
1761 1761
 	{
1762
-		if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower',$headerObject['FLAGS']);
1762
+		if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower', $headerObject['FLAGS']);
1763 1763
 		$retValue = array();
1764 1764
 		$retValue['recent']		= in_array('\\recent', $headerFlags);
1765 1765
 		$retValue['flagged']	= in_array('\\flagged', $headerFlags);
1766
-		$retValue['answered']	= in_array('\\answered', $headerFlags);
1767
-		$retValue['forwarded']   = in_array('$forwarded', $headerFlags);
1766
+		$retValue['answered'] = in_array('\\answered', $headerFlags);
1767
+		$retValue['forwarded'] = in_array('$forwarded', $headerFlags);
1768 1768
 		$retValue['deleted']	= in_array('\\deleted', $headerFlags);
1769
-		$retValue['seen']		= in_array('\\seen', $headerFlags);
1770
-		$retValue['draft']		= in_array('\\draft', $headerFlags);
1771
-		$retValue['mdnsent']	= in_array('$mdnsent', $headerFlags)||in_array('mdnsent', $headerFlags);
1772
-		$retValue['mdnnotsent']	= in_array('$mdnnotsent', $headerFlags)||in_array('mdnnotsent', $headerFlags);
1769
+		$retValue['seen'] = in_array('\\seen', $headerFlags);
1770
+		$retValue['draft'] = in_array('\\draft', $headerFlags);
1771
+		$retValue['mdnsent']	= in_array('$mdnsent', $headerFlags) || in_array('mdnsent', $headerFlags);
1772
+		$retValue['mdnnotsent'] = in_array('$mdnnotsent', $headerFlags) || in_array('mdnnotsent', $headerFlags);
1773 1773
 		$retValue['label1']   = in_array('$label1', $headerFlags);
1774 1774
 		$retValue['label2']   = in_array('$label2', $headerFlags);
1775 1775
 		$retValue['label3']   = in_array('$label3', $headerFlags);
@@ -1793,12 +1793,12 @@  discard block
 block discarded – undo
1793 1793
 	 * @param bool $setSession if set to true the session will be populated with the result of the query
1794 1794
 	 * @return mixed bool/array false or array of ids
1795 1795
 	 */
1796
-	function getSortedList($_folderName, $_sort, &$_reverse, $_filter, &$resultByUid=true, $setSession=true)
1796
+	function getSortedList($_folderName, $_sort, &$_reverse, $_filter, &$resultByUid = true, $setSession = true)
1797 1797
 	{
1798 1798
 		static $cachedFolderStatus = null;
1799 1799
 		// in the past we needed examineMailbox to figure out if the server with the serverID support keywords
1800 1800
 		// this information is filled/provided by examineMailbox; but caching within one request seems o.k.
1801
-		if (is_null($cachedFolderStatus) || !isset($cachedFolderStatus[$this->profileID][$_folderName]) )
1801
+		if (is_null($cachedFolderStatus) || !isset($cachedFolderStatus[$this->profileID][$_folderName]))
1802 1802
 		{
1803 1803
 			$folderStatus = $cachedFolderStatus[$this->profileID][$_folderName] = $this->icServer->examineMailbox($_folderName);
1804 1804
 		}
@@ -1810,28 +1810,28 @@  discard block
 block discarded – undo
1810 1810
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Filter:'.array2string($_filter));
1811 1811
 		$try2useCache = true;
1812 1812
 		static $eMailListContainsDeletedMessages = null;
1813
-		if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
1813
+		if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
1814 1814
 		// this indicates, that there is no Filter set, and the returned set/subset should not contain DELETED Messages, nor filtered for UNDELETED
1815
-		if ($setSession==true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
1815
+		if ($setSession == true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
1816 1816
 		{
1817 1817
 			if (self::$debugTimes) $starttime = microtime(true);
1818
-			if (is_null($eMailListContainsDeletedMessages) || empty($eMailListContainsDeletedMessages[$this->profileID]) || empty($eMailListContainsDeletedMessages[$this->profileID][$_folderName])) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
1819
-			$five=true;
1820
-			$deletedMessages = $this->getSortedList($_folderName, 0, $three=1, array('status'=>array('DELETED')),$five,false);
1818
+			if (is_null($eMailListContainsDeletedMessages) || empty($eMailListContainsDeletedMessages[$this->profileID]) || empty($eMailListContainsDeletedMessages[$this->profileID][$_folderName])) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
1819
+			$five = true;
1820
+			$deletedMessages = $this->getSortedList($_folderName, 0, $three = 1, array('status'=>array('DELETED')), $five, false);
1821 1821
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
1822
-			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] =$deletedMessages['count'];
1823
-			Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),$eMailListContainsDeletedMessages, 60*60*1);
1824
-			if (self::$debugTimes) self::logRunTimes($starttime,null,'setting eMailListContainsDeletedMessages for Profile:'.$this->profileID.' Folder:'.$_folderName.' to '.$eMailListContainsDeletedMessages[$this->profileID][$_folderName],__METHOD__.' ('.__LINE__.') ');			//error_log(__METHOD__.' ('.__LINE__.') '.' Profile:'.$this->profileID.' Folder:'.$_folderName.' -> EXISTS/SessStat:'.array2string($folderStatus['MESSAGES']).'/'.self::$folderStatusCache[$this->profileID][$_folderName]['messages'].' ListContDelMsg/SessDeleted:'.$eMailListContainsDeletedMessages[$this->profileID][$_folderName].'/'.self::$folderStatusCache[$this->profileID][$_folderName]['deleted']);
1822
+			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] = $deletedMessages['count'];
1823
+			Cache::setCache(Cache::INSTANCE, 'email', 'eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']), $eMailListContainsDeletedMessages, 60 * 60 * 1);
1824
+			if (self::$debugTimes) self::logRunTimes($starttime, null, 'setting eMailListContainsDeletedMessages for Profile:'.$this->profileID.' Folder:'.$_folderName.' to '.$eMailListContainsDeletedMessages[$this->profileID][$_folderName], __METHOD__.' ('.__LINE__.') '); //error_log(__METHOD__.' ('.__LINE__.') '.' Profile:'.$this->profileID.' Folder:'.$_folderName.' -> EXISTS/SessStat:'.array2string($folderStatus['MESSAGES']).'/'.self::$folderStatusCache[$this->profileID][$_folderName]['messages'].' ListContDelMsg/SessDeleted:'.$eMailListContainsDeletedMessages[$this->profileID][$_folderName].'/'.self::$folderStatusCache[$this->profileID][$_folderName]['deleted']);
1825 1825
 		}
1826 1826
 		$try2useCache = false;
1827 1827
 		//self::$supportsORinQuery[$this->profileID]=true;
1828 1828
 		if (is_null(self::$supportsORinQuery) || !isset(self::$supportsORinQuery[$this->profileID]))
1829 1829
 		{
1830
-			self::$supportsORinQuery = Cache::getCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
1831
-			if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID]=true;
1830
+			self::$supportsORinQuery = Cache::getCache(Cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 10);
1831
+			if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID] = true;
1832 1832
 		}
1833 1833
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_filter).' SupportsOrInQuery:'.self::$supportsORinQuery[$this->profileID]);
1834
-		$filter = $this->createIMAPFilter($_folderName, $_filter,self::$supportsORinQuery[$this->profileID]);
1834
+		$filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]);
1835 1835
 		if (self::$debug)
1836 1836
 		{
1837 1837
 			$query_str = $filter->build();
@@ -1839,14 +1839,14 @@  discard block
 block discarded – undo
1839 1839
 		}
1840 1840
 		//_debug_array($filter);
1841 1841
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($filter).'#'.array2string($this->icServer->capability()));
1842
-		if($this->icServer->hasCapability('SORT')) {
1842
+		if ($this->icServer->hasCapability('SORT')) {
1843 1843
 			// when using an orQuery and we sort by date. sort seems to fail on certain servers => ZIMBRA with Horde_Imap_Client
1844 1844
 			// thus we translate the search request from date to Horde_Imap_Client::SORT_SEQUENCE (which should be the same, if
1845 1845
 			// there is no messing with the dates)
1846 1846
 			//if (self::$supportsORinQuery[$this->profileID]&&$_sort=='date'&&$_filter['type']=='quick'&&!empty($_filter['string']))$_sort='INTERNALDATE';
1847 1847
 			if (self::$debug) error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
1848 1848
 			$sortOrder = $this->_getSortString($_sort, $_reverse);
1849
-			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder)) $_reverse=false; // as we reversed the result already
1849
+			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE, $sortOrder)) $_reverse = false; // as we reversed the result already
1850 1850
 			if (self::$debug) error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
1851 1851
 			try
1852 1852
 			{
@@ -1854,24 +1854,24 @@  discard block
 block discarded – undo
1854 1854
 					'sort' => $sortOrder,));
1855 1855
 			// if there is an Error, we assume that the server is not capable of sorting
1856 1856
 			}
1857
-			catch(\Exception $e)
1857
+			catch (\Exception $e)
1858 1858
 			{
1859 1859
 				//error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1860 1860
 				$resultByUid = false;
1861 1861
 				$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1862
-				if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
1862
+				if ($_reverse) array_unshift($sortOrder, Horde_Imap_Client::SORT_REVERSE);
1863 1863
 				try
1864 1864
 				{
1865 1865
 					$sortResult = $this->icServer->search($_folderName, $filter, array(
1866 1866
 						'sort' => $sortOrder));
1867 1867
 				}
1868
-				catch(\Exception $e)
1868
+				catch (\Exception $e)
1869 1869
 				{
1870 1870
 					error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1871 1871
 					$sortResult = self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'];
1872 1872
 				}
1873 1873
 			}
1874
-			if (self::$debug) error_log(__METHOD__.print_r($sortResult,true));
1874
+			if (self::$debug) error_log(__METHOD__.print_r($sortResult, true));
1875 1875
 		} else {
1876 1876
 			if (self::$debug) error_log(__METHOD__." Mailserver has NO SORT Capability");
1877 1877
 			//$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
@@ -1881,12 +1881,12 @@  discard block
 block discarded – undo
1881 1881
 				$sortResult = $this->icServer->search($_folderName, $filter, array()/*array(
1882 1882
 					'sort' => $sortOrder)*/);
1883 1883
 			}
1884
-			catch(\Exception $e)
1884
+			catch (\Exception $e)
1885 1885
 			{
1886 1886
 				//error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1887 1887
 				// possible error OR Query. But Horde gives no detailed Info :-(
1888
-				self::$supportsORinQuery[$this->profileID]=false;
1889
-				Cache::setCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),self::$supportsORinQuery,60*60*10);
1888
+				self::$supportsORinQuery[$this->profileID] = false;
1889
+				Cache::setCache(Cache::INSTANCE, 'email', 'supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']), self::$supportsORinQuery, 60 * 60 * 10);
1890 1890
 				if (self::$debug) error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
1891 1891
 				$filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]);
1892 1892
 				try
@@ -1894,25 +1894,25 @@  discard block
 block discarded – undo
1894 1894
 					$sortResult = $this->icServer->search($_folderName, $filter, array()/*array(
1895 1895
 						'sort' => $sortOrder)*/);
1896 1896
 				}
1897
-				catch(\Exception $e)
1897
+				catch (\Exception $e)
1898 1898
 				{
1899 1899
 				}
1900 1900
 			}
1901
-			if(is_array($sortResult['match'])) {
1901
+			if (is_array($sortResult['match'])) {
1902 1902
 					// not sure that this is going so succeed as $sortResult['match'] is a hordeObject
1903 1903
 					sort($sortResult['match'], SORT_NUMERIC);
1904 1904
 			}
1905
-			if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
1905
+			if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter, true)." ->".print_r($sortResult, true));
1906 1906
 		}
1907 1907
 		if ($setSession)
1908 1908
 		{
1909 1909
 			self::$folderStatusCache[$this->profileID][$_folderName]['uidValidity'] = $folderStatus['UIDVALIDITY'];
1910
-			self::$folderStatusCache[$this->profileID][$_folderName]['messages']	= $folderStatus['MESSAGES'];
1910
+			self::$folderStatusCache[$this->profileID][$_folderName]['messages'] = $folderStatus['MESSAGES'];
1911 1911
 			self::$folderStatusCache[$this->profileID][$_folderName]['deleted']	= $eMailListContainsDeletedMessages[$this->profileID][$_folderName];
1912 1912
 			self::$folderStatusCache[$this->profileID][$_folderName]['uidnext']	= $folderStatus['UIDNEXT'];
1913
-			self::$folderStatusCache[$this->profileID][$_folderName]['filter']	= $_filter;
1913
+			self::$folderStatusCache[$this->profileID][$_folderName]['filter'] = $_filter;
1914 1914
 			self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'] = $sortResult;
1915
-			self::$folderStatusCache[$this->profileID][$_folderName]['sort']	= $_sort;
1915
+			self::$folderStatusCache[$this->profileID][$_folderName]['sort'] = $_sort;
1916 1916
 		}
1917 1917
 		//error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
1918 1918
 		//_debug_array($sortResult['match']->ids);
@@ -1926,12 +1926,12 @@  discard block
 block discarded – undo
1926 1926
 	 * @param bool _reverse wether to add REVERSE to the Sort String or not
1927 1927
 	 * @return the sort sequence for horde search
1928 1928
 	 */
1929
-	function _getSortString($_sort, $_reverse=false)
1929
+	function _getSortString($_sort, $_reverse = false)
1930 1930
 	{
1931
-		$_reverse=false;
1931
+		$_reverse = false;
1932 1932
 		if (is_numeric($_sort))
1933 1933
 		{
1934
-			switch($_sort) {
1934
+			switch ($_sort) {
1935 1935
 				case 2:
1936 1936
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1937 1937
 					break;
@@ -1953,7 +1953,7 @@  discard block
 block discarded – undo
1953 1953
 		}
1954 1954
 		else
1955 1955
 		{
1956
-			switch(strtoupper($_sort)) {
1956
+			switch (strtoupper($_sort)) {
1957 1957
 				case 'FROMADDRESS':
1958 1958
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1959 1959
 					break;
@@ -1979,7 +1979,7 @@  discard block
 block discarded – undo
1979 1979
 					break;
1980 1980
 			}
1981 1981
 		}
1982
-		if ($_reverse) array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
1982
+		if ($_reverse) array_unshift($retValue, Horde_Imap_Client::SORT_REVERSE);
1983 1983
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.($_reverse?'REVERSE ':'').$_sort.'->'.$retValue);
1984 1984
 		return $retValue;
1985 1985
 	}
@@ -1992,28 +1992,28 @@  discard block
 block discarded – undo
1992 1992
 	 * @param boolean $_supportsOrInQuery wether to use the OR Query on QuickSearch
1993 1993
 	 * @return Horde_Imap_Client_Search_Query the IMAP filter
1994 1994
 	 */
1995
-	function createIMAPFilter($_folder, $_criterias, $_supportsOrInQuery=true)
1995
+	function createIMAPFilter($_folder, $_criterias, $_supportsOrInQuery = true)
1996 1996
 	{
1997 1997
 		$imapFilter = new Horde_Imap_Client_Search_Query();
1998 1998
 		$imapFilter->charset('UTF-8');
1999 1999
 
2000 2000
 		//_debug_array($_criterias);
2001
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2002
-		if((!is_array($_criterias) || $_criterias['status']=='any') &&
2001
+		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias) ? " none -> returning" : array2string($_criterias)));
2002
+		if ((!is_array($_criterias) || $_criterias['status'] == 'any') &&
2003 2003
 			(!isset($_criterias['string']) || empty($_criterias['string'])) &&
2004
-			(!isset($_criterias['range'])|| empty($_criterias['range']) ||
2005
-			( !empty($_criterias['range'])&& ($_criterias['range']!='BETWEEN' && empty($_criterias['date'])||
2006
-			($_criterias['range']=='BETWEEN' && empty($_criterias['since'])&& empty($_criterias['before']))))))
2004
+			(!isset($_criterias['range']) || empty($_criterias['range']) ||
2005
+			(!empty($_criterias['range']) && ($_criterias['range'] != 'BETWEEN' && empty($_criterias['date']) ||
2006
+			($_criterias['range'] == 'BETWEEN' && empty($_criterias['since']) && empty($_criterias['before']))))))
2007 2007
 		{
2008 2008
 			//error_log(__METHOD__.' ('.__LINE__.') returning early Criterias:'.print_r($_criterias, true));
2009
-			$imapFilter->flag('DELETED', $set=false);
2009
+			$imapFilter->flag('DELETED', $set = false);
2010 2010
 			return $imapFilter;
2011 2011
 		}
2012 2012
 		$queryValid = false;
2013 2013
 		// statusQuery MUST be placed first, as search for subject/mailbody and such is
2014 2014
 		// depending on charset. flagSearch is not BUT messes the charset if called afterwards
2015 2015
 		$statusQueryValid = false;
2016
-		foreach((array)$_criterias['status'] as $k => $criteria) {
2016
+		foreach ((array)$_criterias['status'] as $k => $criteria) {
2017 2017
 			$imapStatusFilter = new Horde_Imap_Client_Search_Query();
2018 2018
 			$imapStatusFilter->charset('UTF-8');
2019 2019
 			$criteria = strtoupper($criteria);
@@ -2023,12 +2023,12 @@  discard block
 block discarded – undo
2023 2023
 				case 'FLAGGED':
2024 2024
 				case 'RECENT':
2025 2025
 				case 'SEEN':
2026
-					$imapStatusFilter->flag($criteria, $set=true);
2027
-					$queryValid = $statusQueryValid =true;
2026
+					$imapStatusFilter->flag($criteria, $set = true);
2027
+					$queryValid = $statusQueryValid = true;
2028 2028
 					break;
2029 2029
 				case 'READ':
2030
-					$imapStatusFilter->flag('SEEN', $set=true);
2031
-					$queryValid = $statusQueryValid =true;
2030
+					$imapStatusFilter->flag('SEEN', $set = true);
2031
+					$queryValid = $statusQueryValid = true;
2032 2032
 					break;
2033 2033
 				case 'LABEL1':
2034 2034
 				case 'KEYWORD1':
@@ -2040,38 +2040,38 @@  discard block
 block discarded – undo
2040 2040
 				case 'KEYWORD4':
2041 2041
 				case 'LABEL5':
2042 2042
 				case 'KEYWORD5':
2043
-					$imapStatusFilter->flag(str_ireplace('KEYWORD','$LABEL',$criteria), $set=true);
2044
-					$queryValid = $statusQueryValid =true;
2043
+					$imapStatusFilter->flag(str_ireplace('KEYWORD', '$LABEL', $criteria), $set = true);
2044
+					$queryValid = $statusQueryValid = true;
2045 2045
 					break;
2046 2046
 				case 'NEW':
2047
-					$imapStatusFilter->flag('RECENT', $set=true);
2048
-					$imapStatusFilter->flag('SEEN', $set=false);
2049
-					$queryValid = $statusQueryValid =true;
2047
+					$imapStatusFilter->flag('RECENT', $set = true);
2048
+					$imapStatusFilter->flag('SEEN', $set = false);
2049
+					$queryValid = $statusQueryValid = true;
2050 2050
 					break;
2051 2051
 				case 'OLD':
2052
-					$imapStatusFilter->flag('RECENT', $set=false);
2053
-					$queryValid = $statusQueryValid =true;
2052
+					$imapStatusFilter->flag('RECENT', $set = false);
2053
+					$queryValid = $statusQueryValid = true;
2054 2054
 					break;
2055 2055
 // operate only on system flags
2056 2056
 //        $systemflags = array(
2057 2057
 //            'ANSWERED', 'DELETED', 'DRAFT', 'FLAGGED', 'RECENT', 'SEEN'
2058 2058
 //        );
2059 2059
 				case 'UNANSWERED':
2060
-					$imapStatusFilter->flag('ANSWERED', $set=false);
2061
-					$queryValid = $statusQueryValid =true;
2060
+					$imapStatusFilter->flag('ANSWERED', $set = false);
2061
+					$queryValid = $statusQueryValid = true;
2062 2062
 					break;
2063 2063
 				case 'UNDELETED':
2064
-					$imapFilter->flag('DELETED', $set=false);
2064
+					$imapFilter->flag('DELETED', $set = false);
2065 2065
 					$queryValid = true;
2066 2066
 					break;
2067 2067
 				case 'UNFLAGGED':
2068
-					$imapStatusFilter->flag('FLAGGED', $set=false);
2069
-					$queryValid = $statusQueryValid =true;
2068
+					$imapStatusFilter->flag('FLAGGED', $set = false);
2069
+					$queryValid = $statusQueryValid = true;
2070 2070
 					break;
2071 2071
 				case 'UNREAD':
2072 2072
 				case 'UNSEEN':
2073
-					$imapStatusFilter->flag('SEEN', $set=false);
2074
-					$queryValid = $statusQueryValid =true;
2073
+					$imapStatusFilter->flag('SEEN', $set = false);
2074
+					$queryValid = $statusQueryValid = true;
2075 2075
 					break;
2076 2076
 				case 'UNLABEL1':
2077 2077
 				case 'UNKEYWORD1':
@@ -2083,8 +2083,8 @@  discard block
 block discarded – undo
2083 2083
 				case 'UNKEYWORD4':
2084 2084
 				case 'UNLABEL5':
2085 2085
 				case 'UNKEYWORD5':
2086
-					$imapStatusFilter->flag(str_ireplace(array('UNKEYWORD','UNLABEL'),'$LABEL',$criteria), $set=false);
2087
-					$queryValid = $statusQueryValid =true;
2086
+					$imapStatusFilter->flag(str_ireplace(array('UNKEYWORD', 'UNLABEL'), '$LABEL', $criteria), $set = false);
2087
+					$queryValid = $statusQueryValid = true;
2088 2088
 					break;
2089 2089
 				default:
2090 2090
 					$statusQueryValid = false;
@@ -2100,20 +2100,20 @@  discard block
 block discarded – undo
2100 2100
 		$imapSearchFilter = new Horde_Imap_Client_Search_Query();
2101 2101
 		$imapSearchFilter->charset('UTF-8');
2102 2102
 
2103
-		if(!empty($_criterias['string'])) {
2103
+		if (!empty($_criterias['string'])) {
2104 2104
 			$criteria = strtoupper($_criterias['type']);
2105 2105
 			switch ($criteria) {
2106 2106
 				case 'BYDATE':
2107 2107
 				case 'QUICK':
2108 2108
 				case 'QUICKWITHCC':
2109
-					$imapSearchFilter->headerText('SUBJECT', $_criterias['string'], $not=false);
2109
+					$imapSearchFilter->headerText('SUBJECT', $_criterias['string'], $not = false);
2110 2110
 					//$imapSearchFilter->charset('UTF-8');
2111 2111
 					$imapFilter2 = new Horde_Imap_Client_Search_Query();
2112 2112
 					$imapFilter2->charset('UTF-8');
2113
-					if($this->isSentFolder($_folder)) {
2114
-						$imapFilter2->headerText('TO', $_criterias['string'], $not=false);
2113
+					if ($this->isSentFolder($_folder)) {
2114
+						$imapFilter2->headerText('TO', $_criterias['string'], $not = false);
2115 2115
 					} else {
2116
-						$imapFilter2->headerText('FROM', $_criterias['string'], $not=false);
2116
+						$imapFilter2->headerText('FROM', $_criterias['string'], $not = false);
2117 2117
 					}
2118 2118
 					if ($_supportsOrInQuery)
2119 2119
 					{
@@ -2123,31 +2123,31 @@  discard block
 block discarded – undo
2123 2123
 					{
2124 2124
 						$imapSearchFilter->andSearch($imapFilter2);
2125 2125
 					}
2126
-					if ($_supportsOrInQuery && $criteria=='QUICKWITHCC')
2126
+					if ($_supportsOrInQuery && $criteria == 'QUICKWITHCC')
2127 2127
 					{
2128 2128
 						$imapFilter3 = new Horde_Imap_Client_Search_Query();
2129 2129
 						$imapFilter3->charset('UTF-8');
2130
-						$imapFilter3->headerText('CC', $_criterias['string'], $not=false);
2130
+						$imapFilter3->headerText('CC', $_criterias['string'], $not = false);
2131 2131
 						$imapSearchFilter->orSearch($imapFilter3);
2132 2132
 					}
2133 2133
 					$queryValid = true;
2134 2134
 					break;
2135 2135
 				case 'LARGER':
2136 2136
 				case 'SMALLER':
2137
-					if (strlen(trim($_criterias['string'])) != strlen((float) trim($_criterias['string'])))
2137
+					if (strlen(trim($_criterias['string'])) != strlen((float)trim($_criterias['string'])))
2138 2138
 					{
2139 2139
 						//examine string to evaluate size
2140
-						$unit = strtoupper(trim(substr(trim($_criterias['string']),strlen((float) trim($_criterias['string'])))));
2141
-						$multipleBy = array('KB'=>1024,'K'=>1024,
2142
-											'MB'=>1024*1000,'M'=>1024*1000,
2143
-											'GB'=>1024*1000*1000,'G'=>1024*1000*1000,
2144
-											'TB'=>1024*1000*1000*1000,'T'=>1024*1000*1000*1000);
2145
-						$numberinBytes=(float)$_criterias['string'];
2146
-						if (isset($multipleBy[$unit])) $numberinBytes=(float)$_criterias['string']*$multipleBy[$unit];
2140
+						$unit = strtoupper(trim(substr(trim($_criterias['string']), strlen((float)trim($_criterias['string'])))));
2141
+						$multipleBy = array('KB'=>1024, 'K'=>1024,
2142
+											'MB'=>1024 * 1000, 'M'=>1024 * 1000,
2143
+											'GB'=>1024 * 1000 * 1000, 'G'=>1024 * 1000 * 1000,
2144
+											'TB'=>1024 * 1000 * 1000 * 1000, 'T'=>1024 * 1000 * 1000 * 1000);
2145
+						$numberinBytes = (float)$_criterias['string'];
2146
+						if (isset($multipleBy[$unit])) $numberinBytes = (float)$_criterias['string'] * $multipleBy[$unit];
2147 2147
 						//error_log(__METHOD__.__LINE__.'#'.$_criterias['string'].'->'.(float)$_criterias['string'].'#'.$unit.' ='.$numberinBytes);
2148
-						$_criterias['string']=$numberinBytes;
2148
+						$_criterias['string'] = $numberinBytes;
2149 2149
 					}
2150
-					$imapSearchFilter->size( $_criterias['string'], ($criteria=='LARGER'?true:false), $not=false);
2150
+					$imapSearchFilter->size($_criterias['string'], ($criteria == 'LARGER' ? true : false), $not = false);
2151 2151
 					//$imapSearchFilter->charset('UTF-8');
2152 2152
 					$queryValid = true;
2153 2153
 					break;
@@ -2156,31 +2156,31 @@  discard block
 block discarded – undo
2156 2156
 				case 'CC':
2157 2157
 				case 'BCC':
2158 2158
 				case 'SUBJECT':
2159
-					$imapSearchFilter->headerText($criteria, $_criterias['string'], $not=false);
2159
+					$imapSearchFilter->headerText($criteria, $_criterias['string'], $not = false);
2160 2160
 					//$imapSearchFilter->charset('UTF-8');
2161 2161
 					$queryValid = true;
2162 2162
 					break;
2163 2163
 				case 'BODY':
2164 2164
 				case 'TEXT':
2165
-					$imapSearchFilter->text($_criterias['string'],($criteria=='BODY'?true:false), $not=false);
2165
+					$imapSearchFilter->text($_criterias['string'], ($criteria == 'BODY' ? true : false), $not = false);
2166 2166
 					//$imapSearchFilter->charset('UTF-8');
2167 2167
 					$queryValid = true;
2168 2168
 					break;
2169 2169
 				case 'SINCE':
2170
-					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header=true, $not=false);
2170
+					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header = true, $not = false);
2171 2171
 					$queryValid = true;
2172 2172
 					break;
2173 2173
 				case 'BEFORE':
2174
-					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header=true, $not=false);
2174
+					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header = true, $not = false);
2175 2175
 					$queryValid = true;
2176 2176
 					break;
2177 2177
 				case 'ON':
2178
-					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_ON, $header=true, $not=false);
2178
+					$imapSearchFilter->dateSearch(new DateTime($_criterias['string']), Horde_Imap_Client_Search_Query::DATE_ON, $header = true, $not = false);
2179 2179
 					$queryValid = true;
2180 2180
 					break;
2181 2181
 			}
2182 2182
 		}
2183
-		if ($statusQueryValid && !$queryValid) $queryValid=true;
2183
+		if ($statusQueryValid && !$queryValid) $queryValid = true;
2184 2184
 		if ($queryValid) $imapFilter->andSearch($imapSearchFilter);
2185 2185
 
2186 2186
 		if (isset($_criterias['range']) && !empty($_criterias['range']))
@@ -2189,12 +2189,12 @@  discard block
 block discarded – undo
2189 2189
 			$imapRangeFilter = new Horde_Imap_Client_Search_Query();
2190 2190
 			$imapRangeFilter->charset('UTF-8');
2191 2191
 			$criteria = strtoupper($_criterias['range']);
2192
-			if ($_criterias['range'] == "BETWEEN" && isset($_criterias['since']) && isset($_criterias['before']) && $_criterias['since']==$_criterias['before'])
2192
+			if ($_criterias['range'] == "BETWEEN" && isset($_criterias['since']) && isset($_criterias['before']) && $_criterias['since'] == $_criterias['before'])
2193 2193
 			{
2194
-				$_criterias['date']=$_criterias['since'];
2194
+				$_criterias['date'] = $_criterias['since'];
2195 2195
 				unset($_criterias['since']);
2196 2196
 				unset($_criterias['before']);
2197
-				$criteria=$_criterias['range']='ON';
2197
+				$criteria = $_criterias['range'] = 'ON';
2198 2198
 			}
2199 2199
 			switch ($criteria) {
2200 2200
 				case 'BETWEEN':
@@ -2202,7 +2202,7 @@  discard block
 block discarded – undo
2202 2202
 					//enddate
2203 2203
 					if ($_criterias['since'])
2204 2204
 					{
2205
-						$imapRangeFilter->dateSearch(new DateTime($_criterias['since']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header=true, $not=false);
2205
+						$imapRangeFilter->dateSearch(new DateTime($_criterias['since']), Horde_Imap_Client_Search_Query::DATE_SINCE, $header = true, $not = false);
2206 2206
 						$rangeValid = true;
2207 2207
 					}
2208 2208
 					//startdate
@@ -2211,28 +2211,28 @@  discard block
 block discarded – undo
2211 2211
 						$imapRangeFilter2 = new Horde_Imap_Client_Search_Query();
2212 2212
 						$imapRangeFilter2->charset('UTF-8');
2213 2213
 						//our before (startdate) is inklusive, as we work with "d-M-Y", we must add a day
2214
-						$_criterias['before'] = date("d-M-Y",DateTime::to($_criterias['before'],'ts')+(3600*24));
2215
-						$imapRangeFilter2->dateSearch(new DateTime($_criterias['before']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header=true, $not=false);
2214
+						$_criterias['before'] = date("d-M-Y", DateTime::to($_criterias['before'], 'ts') + (3600 * 24));
2215
+						$imapRangeFilter2->dateSearch(new DateTime($_criterias['before']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header = true, $not = false);
2216 2216
 						$imapRangeFilter->andSearch($imapRangeFilter2);
2217 2217
 						$rangeValid = true;
2218 2218
 					}
2219 2219
 					break;
2220 2220
 				case 'SINCE'://enddate
2221
-					$imapRangeFilter->dateSearch(new DateTime(($_criterias['since']?$_criterias['since']:$_criterias['date'])), Horde_Imap_Client_Search_Query::DATE_SINCE, $header=true, $not=false);
2221
+					$imapRangeFilter->dateSearch(new DateTime(($_criterias['since'] ? $_criterias['since'] : $_criterias['date'])), Horde_Imap_Client_Search_Query::DATE_SINCE, $header = true, $not = false);
2222 2222
 					$rangeValid = true;
2223 2223
 					break;
2224 2224
 				case 'BEFORE'://startdate
2225 2225
 					//our before (startdate) is inklusive, as we work with "d-M-Y", we must add a day
2226
-					$_criterias['before'] = date("d-M-Y",DateTime::to(($_criterias['before']?$_criterias['before']:$_criterias['date']),'ts')+(3600*24));
2227
-					$imapRangeFilter->dateSearch(new DateTime($_criterias['before']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header=true, $not=false);
2226
+					$_criterias['before'] = date("d-M-Y", DateTime::to(($_criterias['before'] ? $_criterias['before'] : $_criterias['date']), 'ts') + (3600 * 24));
2227
+					$imapRangeFilter->dateSearch(new DateTime($_criterias['before']), Horde_Imap_Client_Search_Query::DATE_BEFORE, $header = true, $not = false);
2228 2228
 					$rangeValid = true;
2229 2229
 					break;
2230 2230
 				case 'ON':
2231
-					$imapRangeFilter->dateSearch(new DateTime($_criterias['date']), Horde_Imap_Client_Search_Query::DATE_ON, $header=true, $not=false);
2231
+					$imapRangeFilter->dateSearch(new DateTime($_criterias['date']), Horde_Imap_Client_Search_Query::DATE_ON, $header = true, $not = false);
2232 2232
 					$rangeValid = true;
2233 2233
 					break;
2234 2234
 			}
2235
-			if ($rangeValid && !$queryValid) $queryValid=true;
2235
+			if ($rangeValid && !$queryValid) $queryValid = true;
2236 2236
 			if ($rangeValid) $imapFilter->andSearch($imapRangeFilter);
2237 2237
 		}
2238 2238
 		if (self::$debug)
@@ -2241,8 +2241,8 @@  discard block
 block discarded – undo
2241 2241
 			$query_str = $imapFilter->build();
2242 2242
 			//error_log(__METHOD__.' ('.__LINE__.') '.' '.$query_str['query'].' created by Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2243 2243
 		}
2244
-		if($queryValid==false) {
2245
-			$imapFilter->flag('DELETED', $set=false);
2244
+		if ($queryValid == false) {
2245
+			$imapFilter->flag('DELETED', $set = false);
2246 2246
 			return $imapFilter;
2247 2247
 		} else {
2248 2248
 			return $imapFilter;
@@ -2256,11 +2256,11 @@  discard block
 block discarded – undo
2256 2256
 	 * @param  mixed/boolean $_tryIDNConversion (true/false AND FORCE): try IDN Conversion on domainparts of emailADRESSES
2257 2257
 	 * @return mixed - based on the input type
2258 2258
 	 */
2259
-	static function decode_header($_string, $_tryIDNConversion=false)
2259
+	static function decode_header($_string, $_tryIDNConversion = false)
2260 2260
 	{
2261 2261
 		if (is_array($_string))
2262 2262
 		{
2263
-			foreach($_string as $k=>$v)
2263
+			foreach ($_string as $k=>$v)
2264 2264
 			{
2265 2265
 				$_string[$k] = self::decode_header($v, $_tryIDNConversion);
2266 2266
 			}
@@ -2268,18 +2268,18 @@  discard block
 block discarded – undo
2268 2268
 		}
2269 2269
 		else
2270 2270
 		{
2271
-			$_string = Mail\Html::decodeMailHeader($_string,self::$displayCharset);
2271
+			$_string = Mail\Html::decodeMailHeader($_string, self::$displayCharset);
2272 2272
 			$test = @json_encode($_string);
2273 2273
 			//error_log(__METHOD__.__LINE__.' ->'.strlen($singleBodyPart['body']).' Error:'.json_last_error().'<- BodyPart:#'.$test.'#');
2274
-			if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
2274
+			if (($test == "null" || $test === false || is_null($test)) && strlen($_string) > 0)
2275 2275
 			{
2276 2276
 				// try to fix broken utf8
2277 2277
 				$x = utf8_encode($_string);
2278 2278
 				$test = @json_encode($x);
2279
-				if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
2279
+				if (($test == "null" || $test === false || is_null($test)) && strlen($_string) > 0)
2280 2280
 				{
2281 2281
 					// this should not be needed, unless something fails with charset detection/ wrong charset passed
2282
-					$_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));
2282
+					$_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));
2283 2283
 				}
2284 2284
 				else
2285 2285
 				{
@@ -2287,7 +2287,7 @@  discard block
 block discarded – undo
2287 2287
 				}
2288 2288
 			}
2289 2289
 
2290
-			if ($_tryIDNConversion===true && stripos($_string,'@')!==false)
2290
+			if ($_tryIDNConversion === true && stripos($_string, '@') !== false)
2291 2291
 			{
2292 2292
 				$rfcAddr = self::parseAddressList($_string);
2293 2293
 				$stringA = array();
@@ -2299,11 +2299,11 @@  discard block
 block discarded – undo
2299 2299
 						$stringA = array();
2300 2300
 						break; // skip idna conversion if we encounter an error here
2301 2301
 					}
2302
-					$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox,Horde_Idna::decode($_rfcAddr->host),$_rfcAddr->personal);
2302
+					$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox, Horde_Idna::decode($_rfcAddr->host), $_rfcAddr->personal);
2303 2303
 				}
2304
-				if (!empty($stringA)) $_string = implode(',',$stringA);
2304
+				if (!empty($stringA)) $_string = implode(',', $stringA);
2305 2305
 			}
2306
-			if ($_tryIDNConversion==='FORCE')
2306
+			if ($_tryIDNConversion === 'FORCE')
2307 2307
 			{
2308 2308
 				//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_string.'='.Horde_Idna::decode($_string));
2309 2309
 				$_string = Horde_Idna::decode($_string);
@@ -2319,17 +2319,17 @@  discard block
 block discarded – undo
2319 2319
 	 * @param  boolean $decode try decoding
2320 2320
 	 * @return mixed - based on the input type
2321 2321
 	 */
2322
-	function decode_subject($_string,$decode=true)
2322
+	function decode_subject($_string, $decode = true)
2323 2323
 	{
2324 2324
 		#$string = $_string;
2325
-		if($_string=='NIL')
2325
+		if ($_string == 'NIL')
2326 2326
 		{
2327 2327
 			return 'No Subject';
2328 2328
 		}
2329 2329
 		if ($decode) $_string = self::decode_header($_string);
2330 2330
 		// make sure its utf-8
2331 2331
 		$test = @json_encode($_string);
2332
-		if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
2332
+		if (($test == "null" || $test === false || is_null($test)) && strlen($_string) > 0)
2333 2333
 		{
2334 2334
 			$_string = utf8_encode($_string);
2335 2335
 		}
@@ -2381,18 +2381,18 @@  discard block
 block discarded – undo
2381 2381
 	function createFolder($_parent, $_folderName, &$_error)
2382 2382
 	{
2383 2383
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2384
-		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2385
-		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2384
+		$parent = $_parent; //$this->_encodeFolderName($_parent);
2385
+		$folderName = $_folderName; //$this->_encodeFolderName($_folderName);
2386 2386
 
2387
-		if(empty($parent)) {
2387
+		if (empty($parent)) {
2388 2388
 			$newFolderName = $folderName;
2389 2389
 		} else {
2390 2390
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2391
-			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2391
+			$newFolderName = $parent.$HierarchyDelimiter.$folderName;
2392 2392
 		}
2393 2393
 		if (empty($newFolderName)) return false;
2394 2394
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2395
-		if ($this->folderExists($newFolderName,true))
2395
+		if ($this->folderExists($newFolderName, true))
2396 2396
 		{
2397 2397
 			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2398 2398
 			return $newFolderName;
@@ -2409,7 +2409,7 @@  discard block
 block discarded – undo
2409 2409
 		}
2410 2410
 		catch (\Exception $e)
2411 2411
 		{
2412
-			$_error = lang('Could not create Folder %1 Reason: %2',$newFolderName,$e->getMessage());
2412
+			$_error = lang('Could not create Folder %1 Reason: %2', $newFolderName, $e->getMessage());
2413 2413
 			error_log(__METHOD__.' ('.__LINE__.') '.' create Folder '.$newFolderName.'->'.$e->getMessage().' ('.$e->details.') Namespace:'.array2string($this->icServer->getNameSpaces()).function_backtrace());
2414 2414
 			return false;
2415 2415
 		}
@@ -2438,15 +2438,15 @@  discard block
 block discarded – undo
2438 2438
 	 */
2439 2439
 	function renameFolder($_oldFolderName, $_parent, $_folderName)
2440 2440
 	{
2441
-		$oldFolderName	= $_oldFolderName;//$this->_encodeFolderName($_oldFolderName);
2442
-		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2443
-		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2441
+		$oldFolderName = $_oldFolderName; //$this->_encodeFolderName($_oldFolderName);
2442
+		$parent = $_parent; //$this->_encodeFolderName($_parent);
2443
+		$folderName = $_folderName; //$this->_encodeFolderName($_folderName);
2444 2444
 
2445
-		if(empty($parent)) {
2445
+		if (empty($parent)) {
2446 2446
 			$newFolderName = $folderName;
2447 2447
 		} else {
2448 2448
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2449
-			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2449
+			$newFolderName = $parent.$HierarchyDelimiter.$folderName;
2450 2450
 		}
2451 2451
 		if (self::$debug) error_log("create folder: $newFolderName");
2452 2452
 		try
@@ -2455,10 +2455,10 @@  discard block
 block discarded – undo
2455 2455
 		}
2456 2456
 		catch (\Exception $e)
2457 2457
 		{
2458
-			throw new Exception(__METHOD__." failed for $oldFolderName (rename to: $newFolderName) with error:".$e->getMessage());;
2458
+			throw new Exception(__METHOD__." failed for $oldFolderName (rename to: $newFolderName) with error:".$e->getMessage()); ;
2459 2459
 		}
2460 2460
 		// clear FolderExistsInfoCache
2461
-		Cache::setCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderInfo,60*60*5);
2461
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderInfo, 60 * 60 * 5);
2462 2462
 
2463 2463
 		return $newFolderName;
2464 2464
 
@@ -2477,15 +2477,15 @@  discard block
 block discarded – undo
2477 2477
 		//$folderName = $this->_encodeFolderName($_folderName);
2478 2478
 		try
2479 2479
 		{
2480
-			$this->icServer->subscribeMailbox($_folderName,false);
2480
+			$this->icServer->subscribeMailbox($_folderName, false);
2481 2481
 			$this->icServer->deleteMailbox($_folderName);
2482 2482
 		}
2483 2483
 		catch (\Exception $e)
2484 2484
 		{
2485
-			throw new Exception("Deleting Folder $_folderName failed! Error:".$e->getMessage());;
2485
+			throw new Exception("Deleting Folder $_folderName failed! Error:".$e->getMessage()); ;
2486 2486
 		}
2487 2487
 		// clear FolderExistsInfoCache
2488
-		Cache::setCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderInfo,60*60*5);
2488
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderInfo, 60 * 60 * 5);
2489 2489
 
2490 2490
 		return true;
2491 2491
 	}
@@ -2520,10 +2520,10 @@  discard block
 block discarded – undo
2520 2520
 	 *
2521 2521
 	 * @return array with folder objects. eg.: INBOX => {inbox object}
2522 2522
 	 */
2523
-	function getFolderObjects($_subscribedOnly=false, $_getCounters=false, $_alwaysGetDefaultFolders=false,$_useCacheIfPossible=true)
2523
+	function getFolderObjects($_subscribedOnly = false, $_getCounters = false, $_alwaysGetDefaultFolders = false, $_useCacheIfPossible = true)
2524 2524
 	{
2525 2525
 		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2526
-		if (self::$debugTimes) $starttime = microtime (true);
2526
+		if (self::$debugTimes) $starttime = microtime(true);
2527 2527
 		static $folders2return;
2528 2528
 		//$_subscribedOnly=false;
2529 2529
 		// always use static on single request if info is available;
@@ -2531,42 +2531,42 @@  discard block
 block discarded – undo
2531 2531
 		// set $_useCacheIfPossible to false !
2532 2532
 		if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2533 2533
 		{
2534
-			if (self::$debugTimes) self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2534
+			if (self::$debugTimes) self::logRunTimes($starttime, null, 'using static', __METHOD__.' ('.__LINE__.') ');
2535 2535
 			return $folders2return[$this->icServer->ImapServerId];
2536 2536
 		}
2537 2537
 
2538
-		if ($_subscribedOnly && $_getCounters===false)
2538
+		if ($_subscribedOnly && $_getCounters === false)
2539 2539
 		{
2540
-			if (is_null($folders2return)) $folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2540
+			if (is_null($folders2return)) $folders2return = Cache::getCache(Cache::INSTANCE, 'email', 'folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
2541 2541
 			if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2542 2542
 			{
2543 2543
 				//error_log(__METHOD__.' ('.__LINE__.') '.' using Cached folderObjects'.array2string($folders2return[$this->icServer->ImapServerId]));
2544
-				if (self::$debugTimes) self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
2544
+				if (self::$debugTimes) self::logRunTimes($starttime, null, 'from Cache', __METHOD__.' ('.__LINE__.') ');
2545 2545
 				return $folders2return[$this->icServer->ImapServerId];
2546 2546
 			}
2547 2547
 		}
2548 2548
 		// use $folderBasicInfo for holding attributes and other basic folderinfo $folderBasicInfo[$this->icServer->ImapServerId]
2549 2549
 		static $folderBasicInfo;
2550
-		if (is_null($folderBasicInfo)||!isset($folderBasicInfo[$this->icServer->ImapServerId])) $folderBasicInfo = Cache::getCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2550
+		if (is_null($folderBasicInfo) || !isset($folderBasicInfo[$this->icServer->ImapServerId])) $folderBasicInfo = Cache::getCache(Cache::INSTANCE, 'email', 'folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
2551 2551
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($folderBasicInfo[$this->icServer->ImapServerId])));
2552 2552
 
2553 2553
 		$delimiter = $this->getHierarchyDelimiter();
2554 2554
 
2555 2555
 		$inboxData = new \stdClass;
2556
-		$inboxData->name 		= 'INBOX';
2556
+		$inboxData->name = 'INBOX';
2557 2557
 		$inboxData->folderName		= 'INBOX';
2558
-		$inboxData->displayName		= lang('INBOX');
2558
+		$inboxData->displayName = lang('INBOX');
2559 2559
 		$inboxData->delimiter 		= $delimiter;
2560
-		$inboxData->shortFolderName	= 'INBOX';
2561
-		$inboxData->shortDisplayName	= lang('INBOX');
2560
+		$inboxData->shortFolderName = 'INBOX';
2561
+		$inboxData->shortDisplayName = lang('INBOX');
2562 2562
 		$inboxData->subscribed = true;
2563
-		if($_getCounters == true) {
2563
+		if ($_getCounters == true) {
2564 2564
 			$inboxData->counter = $this->getMailBoxCounters('INBOX');
2565 2565
 		}
2566 2566
 		// force unsubscribed by preference showAllFoldersInFolderPane
2567 2567
 		if ($_subscribedOnly == true &&
2568 2568
 			isset($this->mailPreferences['showAllFoldersInFolderPane']) &&
2569
-			$this->mailPreferences['showAllFoldersInFolderPane']==1)
2569
+			$this->mailPreferences['showAllFoldersInFolderPane'] == 1)
2570 2570
 		{
2571 2571
 			$_subscribedOnly = false;
2572 2572
 		}
@@ -2579,12 +2579,12 @@  discard block
 block discarded – undo
2579 2579
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2580 2580
 		if (is_array($nameSpace))
2581 2581
 		{
2582
-			foreach($nameSpace as $k => $singleNameSpace) {
2582
+			foreach ($nameSpace as $k => $singleNameSpace) {
2583 2583
 				$type = $singleNameSpace['type'];
2584 2584
 				// the following line (assumption that for the same namespace the delimiter should be equal) may be wrong
2585
-				$foldersNameSpace[$type]['delimiter']  = $singleNameSpace['delimiter'];
2585
+				$foldersNameSpace[$type]['delimiter'] = $singleNameSpace['delimiter'];
2586 2586
 
2587
-				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false) {
2587
+				if (is_array($singleNameSpace) && $fetchedAllInOneGo == false) {
2588 2588
 					// fetch and sort the subscribed folders
2589 2589
 					// we alway fetch the subscribed, as this provides the only way to tell
2590 2590
 					// if a folder is subscribed or not
@@ -2592,22 +2592,22 @@  discard block
 block discarded – undo
2592 2592
 					{
2593 2593
 						try
2594 2594
 						{
2595
-							$subscribedMailboxes = $this->icServer->listSubscribedMailboxes('',0,true);
2595
+							$subscribedMailboxes = $this->icServer->listSubscribedMailboxes('', 0, true);
2596 2596
 							if (!empty($subscribedMailboxes))
2597 2597
 							{
2598 2598
 								$fetchedAllInOneGo = true;
2599 2599
 							}
2600 2600
 							else
2601 2601
 							{
2602
-								$subscribedMailboxes = $this->icServer->listSubscribedMailboxes($singleNameSpace['prefix'],0,true);
2602
+								$subscribedMailboxes = $this->icServer->listSubscribedMailboxes($singleNameSpace['prefix'], 0, true);
2603 2603
 							}
2604 2604
 						}
2605
-						catch(Exception $e)
2605
+						catch (Exception $e)
2606 2606
 						{
2607 2607
 							continue;
2608 2608
 						}
2609 2609
 						//echo "subscribedMailboxes";_debug_array($subscribedMailboxes);
2610
-						$subscribedFoldersPerNS = (!empty($subscribedMailboxes)?array_keys($subscribedMailboxes):array());
2610
+						$subscribedFoldersPerNS = (!empty($subscribedMailboxes) ? array_keys($subscribedMailboxes) : array());
2611 2611
 						//if (is_array($foldersNameSpace[$type]['subscribed'])) sort($foldersNameSpace[$type]['subscribed']);
2612 2612
 						//_debug_array($foldersNameSpace);
2613 2613
 						//error_log(__METHOD__.__LINE__.array2string($singleNameSpace).':#:'.array2string($subscribedFoldersPerNS));
@@ -2617,18 +2617,18 @@  discard block
 block discarded – undo
2617 2617
 							foreach ($subscribedMailboxes as $k => $finfo)
2618 2618
 							{
2619 2619
 								//error_log(__METHOD__.__LINE__.$k.':#:'.array2string($finfo));
2620
-								$subscribedFoldersForCache[$this->icServer->ImapServerId][$k]=
2621
-								$folderBasicInfo[$this->icServer->ImapServerId][$k]=array(
2620
+								$subscribedFoldersForCache[$this->icServer->ImapServerId][$k] =
2621
+								$folderBasicInfo[$this->icServer->ImapServerId][$k] = array(
2622 2622
 									'MAILBOX'=>$finfo['MAILBOX'],
2623 2623
 									'ATTRIBUTES'=>$finfo['ATTRIBUTES'],
2624
-									'delimiter'=>$finfo['delimiter'],//lowercase for some reason???
2625
-									'SUBSCRIBED'=>$finfo['SUBSCRIBED'],//seeded by getMailboxes
2624
+									'delimiter'=>$finfo['delimiter'], //lowercase for some reason???
2625
+									'SUBSCRIBED'=>$finfo['SUBSCRIBED'], //seeded by getMailboxes
2626 2626
 								);
2627
-								if (empty($foldersNameSpace[$type]['subscribed']) || !in_array($k,$foldersNameSpace[$type]['subscribed']))
2627
+								if (empty($foldersNameSpace[$type]['subscribed']) || !in_array($k, $foldersNameSpace[$type]['subscribed']))
2628 2628
 								{
2629 2629
 									$foldersNameSpace[$type]['subscribed'][] = $k;
2630 2630
 								}
2631
-								if (empty($foldersNameSpace[$type]['all']) || !in_array($k,$foldersNameSpace[$type]['all']))
2631
+								if (empty($foldersNameSpace[$type]['all']) || !in_array($k, $foldersNameSpace[$type]['all']))
2632 2632
 								{
2633 2633
 									$foldersNameSpace[$type]['all'][] = $k;
2634 2634
 								}
@@ -2651,7 +2651,7 @@  discard block
 block discarded – undo
2651 2651
 						// that may produce problems, when encountering recursions probably
2652 2652
 						// horde is handling that, so we do not; keep that in mind!
2653 2653
 						//$allMailboxesExt = $this->icServer->getMailboxes($singleNameSpace['prefix'],2,true);
2654
-						$allMailboxesExt = $this->icServer->getMailboxes($singleNameSpace['prefix'],0,true);
2654
+						$allMailboxesExt = $this->icServer->getMailboxes($singleNameSpace['prefix'], 0, true);
2655 2655
 					}
2656 2656
 					catch (\Exception $e)
2657 2657
 					{
@@ -2669,26 +2669,26 @@  discard block
 block discarded – undo
2669 2669
 					foreach ($allMailboxesExt as $mbx) {
2670 2670
 						if (!isset($folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]))
2671 2671
 						{
2672
-							$folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]=array(
2672
+							$folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']] = array(
2673 2673
 								'MAILBOX'=>$mbx['MAILBOX'],
2674 2674
 								'ATTRIBUTES'=>$mbx['ATTRIBUTES'],
2675
-								'delimiter'=>$mbx['delimiter'],//lowercase for some reason???
2676
-								'SUBSCRIBED'=>$mbx['SUBSCRIBED'],//seeded by getMailboxes
2675
+								'delimiter'=>$mbx['delimiter'], //lowercase for some reason???
2676
+								'SUBSCRIBED'=>$mbx['SUBSCRIBED'], //seeded by getMailboxes
2677 2677
 							);
2678 2678
 							if ($mbx['SUBSCRIBED'] && !isset($subscribedFoldersForCache[$this->icServer->ImapServerId][$mbx['MAILBOX']]))
2679 2679
 							{
2680 2680
 								$subscribedFoldersForCache[$this->icServer->ImapServerId][$mbx['MAILBOX']] = $folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']];
2681 2681
 							}
2682 2682
 						}
2683
-						if ($mbx['SUBSCRIBED'] && (empty($foldersNameSpace[$type]['subscribed']) || !in_array($mbx['MAILBOX'],$foldersNameSpace[$type]['subscribed'])))
2683
+						if ($mbx['SUBSCRIBED'] && (empty($foldersNameSpace[$type]['subscribed']) || !in_array($mbx['MAILBOX'], $foldersNameSpace[$type]['subscribed'])))
2684 2684
 						{
2685 2685
 							$foldersNameSpace[$type]['subscribed'][] = $mbx['MAILBOX'];
2686 2686
 						}
2687 2687
 						//echo __METHOD__;_debug_array($mbx);
2688 2688
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx));
2689
-						if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']])||
2690
-							isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']])||
2691
-							(substr($mbx['MAILBOX'],-1)==$foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'],0,-1)]))
2689
+						if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']]) ||
2690
+							isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']]) ||
2691
+							(substr($mbx['MAILBOX'], -1) == $foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'], 0, -1)]))
2692 2692
 						) continue;
2693 2693
 
2694 2694
 						//echo '#'.$mbx['MAILBOX'].':'.array2string($mbx)."#<br>";
@@ -2698,7 +2698,7 @@  discard block
 block discarded – undo
2698 2698
 					//_debug_array(array_keys($allMailBoxesExtSorted));
2699 2699
 					$allMailboxes = array();
2700 2700
 					foreach ((array)$allMailBoxesExtSorted as $mbx) {
2701
-						if (!in_array($mbx['MAILBOX'],$allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
2701
+						if (!in_array($mbx['MAILBOX'], $allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
2702 2702
 						//echo "Result:";_debug_array($allMailboxes);
2703 2703
 					}
2704 2704
 					$foldersNameSpace[$type]['all'] = $allMailboxes;
@@ -2707,57 +2707,57 @@  discard block
 block discarded – undo
2707 2707
 			}
2708 2708
 		}
2709 2709
 		//subscribed folders may be used in getFolderStatus
2710
-		Cache::setCache(Cache::INSTANCE,'email','subscribedFolders'.trim($GLOBALS['egw_info']['user']['account_id']),$subscribedFoldersForCache,$expiration=60*60*1);
2710
+		Cache::setCache(Cache::INSTANCE, 'email', 'subscribedFolders'.trim($GLOBALS['egw_info']['user']['account_id']), $subscribedFoldersForCache, $expiration = 60 * 60 * 1);
2711 2711
 		//echo "<br>FolderNameSpace To Process:";_debug_array($foldersNameSpace);
2712 2712
 		$autoFolderObjects = $folders = array();
2713 2713
 		$autofolder_exists = array();
2714
-		foreach( array('personal', 'others', 'shared') as $type) {
2715
-			if(isset($foldersNameSpace[$type])) {
2716
-				if($_subscribedOnly) {
2717
-					if( !empty($foldersNameSpace[$type]['subscribed']) ) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
2714
+		foreach (array('personal', 'others', 'shared') as $type) {
2715
+			if (isset($foldersNameSpace[$type])) {
2716
+				if ($_subscribedOnly) {
2717
+					if (!empty($foldersNameSpace[$type]['subscribed'])) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
2718 2718
 				} else {
2719
-					if( !empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
2719
+					if (!empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
2720 2720
 				}
2721
-				foreach((array)$listOfFolders as $folderName) {
2721
+				foreach ((array)$listOfFolders as $folderName) {
2722 2722
 					//echo "<br>FolderToCheck:$folderName<br>";
2723 2723
 					//error_log(__METHOD__.__LINE__.'#Delimiter:'.$delimiter.':#'.$folderName);
2724
-					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue;//when subscribedonly, we fetch all folders in one go.
2725
-					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
2724
+					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue; //when subscribedonly, we fetch all folders in one go.
2725
+					if ($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all']) || in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
2726 2726
 						#echo "$folderName failed to be here <br>";
2727 2727
 						continue;
2728 2728
 					}
2729 2729
 					if (isset($folders[$folderName])) continue;
2730 2730
 					if (isset($autoFolderObjects[$folderName])) continue;
2731
-					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter'];
2731
+					if (empty($delimiter) || $delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter'];
2732 2732
 					$folderParts = explode($delimiter, $folderName);
2733 2733
 					$shortName = array_pop($folderParts);
2734 2734
 
2735 2735
 					$folderObject = new \stdClass;
2736
-					$folderObject->delimiter	= $delimiter;
2737
-					$folderObject->folderName	= $folderName;
2738
-					$folderObject->shortFolderName	= $shortName;
2739
-					if(!$_subscribedOnly) {
2736
+					$folderObject->delimiter = $delimiter;
2737
+					$folderObject->folderName = $folderName;
2738
+					$folderObject->shortFolderName = $shortName;
2739
+					if (!$_subscribedOnly) {
2740 2740
 						#echo $folderName."->".$type."<br>";
2741 2741
 						#_debug_array($foldersNameSpace[$type]['subscribed']);
2742 2742
 						$folderObject->subscribed = in_array($folderName, (array)$foldersNameSpace[$type]['subscribed']);
2743 2743
 					}
2744 2744
 
2745
-					if($_getCounters == true) {
2745
+					if ($_getCounters == true) {
2746 2746
 						//error_log(__METHOD__.' ('.__LINE__.') '.' getCounter forFolder:'.$folderName);
2747 2747
 						$folderObject->counter = $this->getMailBoxCounters($folderName);
2748 2748
 					}
2749
-					if(strtoupper($folderName) == 'INBOX') {
2749
+					if (strtoupper($folderName) == 'INBOX') {
2750 2750
 						$folderName = 'INBOX';
2751
-						$folderObject->folderName	= 'INBOX';
2752
-						$folderObject->shortFolderName	= 'INBOX';
2753
-						$folderObject->displayName	= lang('INBOX');
2751
+						$folderObject->folderName = 'INBOX';
2752
+						$folderObject->shortFolderName = 'INBOX';
2753
+						$folderObject->displayName = lang('INBOX');
2754 2754
 						$folderObject->shortDisplayName = lang('INBOX');
2755
-						$folderObject->subscribed	= true;
2755
+						$folderObject->subscribed = true;
2756 2756
 					// translate the automatic Folders (Sent, Drafts, ...) like the INBOX
2757
-					} elseif (in_array($shortName,self::$autoFolders)) {
2758
-						$tmpfolderparts = explode($delimiter,$folderObject->folderName);
2757
+					} elseif (in_array($shortName, self::$autoFolders)) {
2758
+						$tmpfolderparts = explode($delimiter, $folderObject->folderName);
2759 2759
 						array_pop($tmpfolderparts);
2760
-						$folderObject->displayName = implode($delimiter,$tmpfolderparts).$delimiter.lang($shortName);
2760
+						$folderObject->displayName = implode($delimiter, $tmpfolderparts).$delimiter.lang($shortName);
2761 2761
 						$folderObject->shortDisplayName = lang($shortName);
2762 2762
 						unset($tmpfolderparts);
2763 2763
 					} else {
@@ -2765,13 +2765,13 @@  discard block
 block discarded – undo
2765 2765
 						$folderObject->shortDisplayName = $shortName;
2766 2766
 					}
2767 2767
 					//$folderName = $folderName;
2768
-					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false) {
2768
+					if (in_array($shortName, self::$autoFolders) && self::searchValueInFolderObjects($shortName, $autoFolderObjects) === false) {
2769 2769
 						$autoFolderObjects[$folderName] = $folderObject;
2770 2770
 					} else {
2771 2771
 						$folders[$folderName] = $folderObject;
2772 2772
 					}
2773 2773
 					//error_log(__METHOD__.' ('.__LINE__.') '.':'.$folderObject->folderName);
2774
-					if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders ();
2774
+					if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders();
2775 2775
 					if (isset(self::$specialUseFolders[$folderName]))
2776 2776
 					{
2777 2777
 						$autofolder_exists[$folderName] = self::$specialUseFolders[$folderName];
@@ -2780,27 +2780,27 @@  discard block
 block discarded – undo
2780 2780
 			}
2781 2781
 		}
2782 2782
 		if (is_array($autoFolderObjects) && !empty($autoFolderObjects)) {
2783
-			uasort($autoFolderObjects,array($this,"sortByAutoFolderPos"));
2783
+			uasort($autoFolderObjects, array($this, "sortByAutoFolderPos"));
2784 2784
 		}
2785 2785
 		// check if some standard folders are missing and need to be created
2786 2786
 		if (count($autofolder_exists) < count(self::$autoFolders) && $this->check_create_autofolders($autofolder_exists))
2787 2787
 		{
2788 2788
 			// if new folders have been created, re-read folders ignoring the cache
2789
-			return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false);	// false = do NOT use cache
2789
+			return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false); // false = do NOT use cache
2790 2790
 		}
2791
-		if (is_array($folders)) uasort($folders,array($this,"sortByDisplayName"));
2791
+		if (is_array($folders)) uasort($folders, array($this, "sortByDisplayName"));
2792 2792
 		//$folders2return = array_merge($autoFolderObjects,$folders);
2793 2793
 		//_debug_array($folders2return); #exit;
2794
-		$folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject,(array)$autoFolderObjects,(array)$folders);
2795
-		if (($_subscribedOnly && $_getCounters===false) ||
2796
-			($_subscribedOnly == false && $_getCounters===false &&
2794
+		$folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject, (array)$autoFolderObjects, (array)$folders);
2795
+		if (($_subscribedOnly && $_getCounters === false) ||
2796
+			($_subscribedOnly == false && $_getCounters === false &&
2797 2797
 			isset($this->mailPreferences['showAllFoldersInFolderPane']) &&
2798
-			$this->mailPreferences['showAllFoldersInFolderPane']==1))
2798
+			$this->mailPreferences['showAllFoldersInFolderPane'] == 1))
2799 2799
 		{
2800
-			Cache::setCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$folders2return,$expiration=60*60*1);
2800
+			Cache::setCache(Cache::INSTANCE, 'email', 'folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']), $folders2return, $expiration = 60 * 60 * 1);
2801 2801
 		}
2802
-		Cache::setCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderBasicInfo,$expiration=60*60*1);
2803
-		if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
2802
+		Cache::setCache(Cache::INSTANCE, 'email', 'folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderBasicInfo, $expiration = 60 * 60 * 1);
2803
+		if (self::$debugTimes) self::logRunTimes($starttime, null, function_backtrace(), __METHOD__.' ('.__LINE__.') ');
2804 2804
 		return $folders2return[$this->icServer->ImapServerId];
2805 2805
 	}
2806 2806
 
@@ -2821,21 +2821,21 @@  discard block
 block discarded – undo
2821 2821
 	 *
2822 2822
 	 * @return array arrays of folders
2823 2823
 	 */
2824
-	function getFolderArrays ($_nodePath = null, $_onlyTopLevel = false, $_search= 2, $_subscribedOnly = false, $_getCounter = false)
2824
+	function getFolderArrays($_nodePath = null, $_onlyTopLevel = false, $_search = 2, $_subscribedOnly = false, $_getCounter = false)
2825 2825
 	{
2826 2826
 		// delimiter
2827 2827
 		$delimiter = $this->getHierarchyDelimiter();
2828 2828
 
2829
-		$folders = $nameSpace =  array();
2829
+		$folders = $nameSpace = array();
2830 2830
 		$nameSpaceTmp = $this->_getNameSpaces();
2831
-		foreach($nameSpaceTmp as $k => $singleNameSpace) {
2832
-			$nameSpace[$singleNameSpace['type']]=$singleNameSpace;
2831
+		foreach ($nameSpaceTmp as $k => $singleNameSpace) {
2832
+			$nameSpace[$singleNameSpace['type']] = $singleNameSpace;
2833 2833
 		}
2834 2834
 		unset($nameSpaceTmp);
2835 2835
 
2836 2836
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2837 2837
 		// Get special use folders
2838
-		if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders (); // Set self::$specialUseFolders
2838
+		if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders(); // Set self::$specialUseFolders
2839 2839
 		// topLevelQueries generally ignore the $_search param. Except for Config::examineNamespace
2840 2840
 		if ($_onlyTopLevel) // top level leaves
2841 2841
 		{
@@ -2846,20 +2846,20 @@  discard block
 block discarded – undo
2846 2846
 			if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
2847 2847
 			if (self::$mailConfig['examineNamespace'])
2848 2848
 			{
2849
-				$prefixes=array();
2849
+				$prefixes = array();
2850 2850
 				if (is_array($nameSpace))
2851 2851
 				{
2852
-					foreach($nameSpace as $k => $singleNameSpace) {
2852
+					foreach ($nameSpace as $k => $singleNameSpace) {
2853 2853
 						$type = $singleNameSpace['type'];
2854 2854
 
2855
-						if(is_array($singleNameSpace) && $singleNameSpace['prefix']){
2855
+						if (is_array($singleNameSpace) && $singleNameSpace['prefix']) {
2856 2856
 							$prefixes[$type] = $singleNameSpace['prefix'];
2857 2857
 							//regard extra care for nameSpacequeries when configured AND respect $_search
2858
-							$result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search==0?0:2, true);
2858
+							$result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search == 0 ? 0 : 2, true);
2859 2859
 							if (is_array($result))
2860 2860
 							{
2861 2861
 								ksort($result);
2862
-								$topFolders = array_merge($topFolders,$result);
2862
+								$topFolders = array_merge($topFolders, $result);
2863 2863
 							}
2864 2864
 						}
2865 2865
 					}
@@ -2868,7 +2868,7 @@  discard block
 block discarded – undo
2868 2868
 
2869 2869
 			$autofolders = array();
2870 2870
 
2871
-			foreach(self::$specialUseFolders as $path => $folder)
2871
+			foreach (self::$specialUseFolders as $path => $folder)
2872 2872
 			{
2873 2873
 				if ($this->folderExists($path))
2874 2874
 				{
@@ -2876,9 +2876,9 @@  discard block
 block discarded – undo
2876 2876
 				}
2877 2877
 			}
2878 2878
 			// Check if the special use folders are there, otherwise try to create them
2879
-			if (count($autofolders) < count(self::$autoFolders) && $this->check_create_autofolders ($autofolders))
2879
+			if (count($autofolders) < count(self::$autoFolders) && $this->check_create_autofolders($autofolders))
2880 2880
 			{
2881
-				return $this->getFolderArrays ($_nodePath, $_onlyTopLevel, $_search, $_subscribedOnly, $_getCounter);
2881
+				return $this->getFolderArrays($_nodePath, $_onlyTopLevel, $_search, $_subscribedOnly, $_getCounter);
2882 2882
 			}
2883 2883
 
2884 2884
 			// now process topFolders for next level
@@ -2886,13 +2886,13 @@  discard block
 block discarded – undo
2886 2886
 			{
2887 2887
 				$pattern = "/\\".$delimiter."/";
2888 2888
 				$reference = preg_replace($pattern, '', $node['MAILBOX']);
2889
-				if(!empty($prefixes))
2889
+				if (!empty($prefixes))
2890 2890
 				{
2891 2891
 					$reference = '';
2892
-					$tmpArray = explode($delimiter,$node['MAILBOX']);
2893
-					foreach($tmpArray as $p)
2892
+					$tmpArray = explode($delimiter, $node['MAILBOX']);
2893
+					foreach ($tmpArray as $p)
2894 2894
 					{
2895
-						$reference = empty($reference)?$p:$reference.$delimiter.$p;
2895
+						$reference = empty($reference) ? $p : $reference.$delimiter.$p;
2896 2896
 					}
2897 2897
 				}
2898 2898
 				$mainFolder = $subFolders = array();
@@ -2928,19 +2928,19 @@  discard block
 block discarded – undo
2928 2928
 							$nFolders [$path] = $folder;
2929 2929
 						}
2930 2930
 					}
2931
-					if (is_array($aFolders)) uasort ($aFolders, array($this,'sortByAutofolder'));
2931
+					if (is_array($aFolders)) uasort($aFolders, array($this, 'sortByAutofolder'));
2932 2932
 					//ksort($aFolders);
2933 2933
 
2934 2934
 					// Sort none auto folders base on mailbox name
2935
-					uasort($nFolders,array($this,'sortByMailbox'));
2935
+					uasort($nFolders, array($this, 'sortByMailbox'));
2936 2936
 
2937
-					$subFolders = array_merge($aFolders,$nFolders);
2937
+					$subFolders = array_merge($aFolders, $nFolders);
2938 2938
 				}
2939 2939
 				else
2940 2940
 				{
2941 2941
 					if (is_array($subFolders)) ksort($subFolders);
2942 2942
 				}
2943
-				$folders = array_merge($folders,(array)$mainFolder, (array)$subFolders);
2943
+				$folders = array_merge($folders, (array)$mainFolder, (array)$subFolders);
2944 2944
 			}
2945 2945
 		}
2946 2946
 		elseif ($_nodePath) // single node
@@ -2967,9 +2967,9 @@  discard block
 block discarded – undo
2967 2967
 				$folders = $this->icServer->getMailboxes($path, $_search, true);
2968 2968
 			}
2969 2969
 
2970
-			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
2970
+			uasort($folders, array($this, 'sortByMailbox')); //ksort($folders);
2971 2971
 		}
2972
-		elseif(!$_nodePath) // all
2972
+		elseif (!$_nodePath) // all
2973 2973
 		{
2974 2974
 			if ($_subscribedOnly)
2975 2975
 			{
@@ -2985,101 +2985,101 @@  discard block
 block discarded – undo
2985 2985
 		{
2986 2986
 			// SORTING FOLDERS
2987 2987
 			//self::$debugTimes=true;
2988
-			if (self::$debugTimes) $starttime = microtime (true);
2988
+			if (self::$debugTimes) $starttime = microtime(true);
2989 2989
 			// Merge of all auto folders and specialusefolders
2990 2990
 			$autoFoldersTmp = array_unique((array_merge(self::$autoFolders, array_values(self::$specialUseFolders))));
2991
-			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
2991
+			uasort($folders, array($this, 'sortByMailbox')); //ksort($folders);
2992 2992
 			$tmpFolders = $folders;
2993
-			$inboxFolderObject=$inboxSubFolderObjects=$autoFolderObjects=$typeFolderObject=$mySpecialUseFolders=array();
2994
-			$googleMailFolderObject=$googleAutoFolderObjects=$googleSubFolderObjects=array();
2995
-			$isGoogleMail=false;
2996
-			foreach($autoFoldersTmp as $afk=>$aF)
2993
+			$inboxFolderObject = $inboxSubFolderObjects = $autoFolderObjects = $typeFolderObject = $mySpecialUseFolders = array();
2994
+			$googleMailFolderObject = $googleAutoFolderObjects = $googleSubFolderObjects = array();
2995
+			$isGoogleMail = false;
2996
+			foreach ($autoFoldersTmp as $afk=>$aF)
2997 2997
 			{
2998
-				if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
2998
+				if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF] = $this->getFolderByType($aF, false);
2999 2999
 				//error_log($afk.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3000 3000
 			}
3001 3001
 			//error_log(array2string($mySpecialUseFolders));
3002 3002
 			foreach ($tmpFolders as $k => $f) {
3003
-				$sorted=false;
3004
-				if (strtoupper(substr($k,0,5))=='INBOX') {
3005
-					if (strtoupper($k)=='INBOX') {
3003
+				$sorted = false;
3004
+				if (strtoupper(substr($k, 0, 5)) == 'INBOX') {
3005
+					if (strtoupper($k) == 'INBOX') {
3006 3006
 						//error_log(__METHOD__.__LINE__.':'.strtoupper(substr($k,0,5)).':'.$k);
3007
-						$inboxFolderObject[$k]=$f;
3007
+						$inboxFolderObject[$k] = $f;
3008 3008
 						unset($folders[$k]);
3009
-						$sorted=true;
3009
+						$sorted = true;
3010 3010
 					} else {
3011
-						$isAutoFolder=false;
3012
-						foreach($autoFoldersTmp as $afk=>$aF)
3011
+						$isAutoFolder = false;
3012
+						foreach ($autoFoldersTmp as $afk=>$aF)
3013 3013
 						{
3014 3014
 							//error_log(__METHOD__.__LINE__.$k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3015
-							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3016
-								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3017
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3015
+							if ($aF && strlen($mySpecialUseFolders[$aF]) && /*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3016
+								($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3017
+								stristr($mySpecialUseFolders[$aF], $k.$delimiter) !== false)) // k is parent of an autofolder
3018 3018
 							{
3019 3019
 								//error_log(__METHOD__.__LINE__.$k.'->'.$mySpecialUseFolders[$aF]);
3020
-								$isAutoFolder=true;
3021
-								$autoFolderObjects[$k]=$f;
3020
+								$isAutoFolder = true;
3021
+								$autoFolderObjects[$k] = $f;
3022 3022
 								break;
3023 3023
 							}
3024 3024
 						}
3025
-						if ($isAutoFolder==false) $inboxSubFolderObjects[$k]=$f;
3025
+						if ($isAutoFolder == false) $inboxSubFolderObjects[$k] = $f;
3026 3026
 						unset($folders[$k]);
3027
-						$sorted=true;
3027
+						$sorted = true;
3028 3028
 					}
3029
-				} elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]') {
3030
-					$isGoogleMail=true;
3031
-					if (strtoupper($k)=='[GOOGLE MAIL]') {
3032
-						$googleMailFolderObject[$k]=$f;
3029
+				} elseif (strtoupper(substr($k, 0, 13)) == '[GOOGLE MAIL]') {
3030
+					$isGoogleMail = true;
3031
+					if (strtoupper($k) == '[GOOGLE MAIL]') {
3032
+						$googleMailFolderObject[$k] = $f;
3033 3033
 						unset($folders[$k]);
3034
-						$sorted=true;
3034
+						$sorted = true;
3035 3035
 					} else {
3036
-						$isAutoFolder=false;
3037
-						foreach($autoFoldersTmp as $afk=>$aF)
3036
+						$isAutoFolder = false;
3037
+						foreach ($autoFoldersTmp as $afk=>$aF)
3038 3038
 						{
3039 3039
 							//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3040
-							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3041
-								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3042
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3040
+							if ($aF && strlen($mySpecialUseFolders[$aF]) && /*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3041
+								($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3042
+								stristr($mySpecialUseFolders[$aF], $k.$delimiter) !== false)) // k is parent of an autofolder
3043 3043
 							{
3044 3044
 								//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3045
-								$isAutoFolder=true;
3046
-								$googleAutoFolderObjects[$k]=$f;
3045
+								$isAutoFolder = true;
3046
+								$googleAutoFolderObjects[$k] = $f;
3047 3047
 								break;
3048 3048
 							}
3049 3049
 						}
3050
-						if ($isAutoFolder==false) $googleSubFolderObjects[$k]=$f;
3050
+						if ($isAutoFolder == false) $googleSubFolderObjects[$k] = $f;
3051 3051
 						unset($folders[$k]);
3052
-						$sorted=true;
3052
+						$sorted = true;
3053 3053
 					}
3054 3054
 				} else {
3055
-					$isAutoFolder=false;
3056
-					foreach($autoFoldersTmp as $afk=>$aF)
3055
+					$isAutoFolder = false;
3056
+					foreach ($autoFoldersTmp as $afk=>$aF)
3057 3057
 					{
3058 3058
 						//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3059
-						if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3060
-								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3061
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3059
+						if ($aF && strlen($mySpecialUseFolders[$aF]) && /*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3060
+								($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3061
+								stristr($mySpecialUseFolders[$aF], $k.$delimiter) !== false)) // k is parent of an autofolder
3062 3062
 						{
3063 3063
 							//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3064
-							$isAutoFolder=true;
3065
-							$autoFolderObjects[$k]=$f;
3064
+							$isAutoFolder = true;
3065
+							$autoFolderObjects[$k] = $f;
3066 3066
 							unset($folders[$k]);
3067
-							$sorted=true;
3067
+							$sorted = true;
3068 3068
 							break;
3069 3069
 						}
3070 3070
 					}
3071 3071
 				}
3072 3072
 
3073
-				if ($sorted==false)
3073
+				if ($sorted == false)
3074 3074
 				{
3075
-					foreach(array('others','shared') as $type)
3075
+					foreach (array('others', 'shared') as $type)
3076 3076
 					{
3077
-						if ($nameSpace[$type]['prefix_present']&&$nameSpace[$type]['prefix'])
3077
+						if ($nameSpace[$type]['prefix_present'] && $nameSpace[$type]['prefix'])
3078 3078
 						{
3079
-							if (substr($k,0,strlen($nameSpace[$type]['prefix']))==$nameSpace[$type]['prefix']||
3080
-								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1)) {
3079
+							if (substr($k, 0, strlen($nameSpace[$type]['prefix'])) == $nameSpace[$type]['prefix'] ||
3080
+								substr($k, 0, strlen($nameSpace[$type]['prefix']) - strlen($nameSpace[$type]['delimiter'])) == substr($nameSpace[$type]['prefix'], 0, strlen($nameSpace[$type]['delimiter']) * -1)) {
3081 3081
 								//error_log(__METHOD__.__LINE__.':'.substr($k,0,strlen($nameSpace[$type]['prefix'])).':'.$k);
3082
-								$typeFolderObject[$type][$k]=$f;
3082
+								$typeFolderObject[$type][$k] = $f;
3083 3083
 								unset($folders[$k]);
3084 3084
 							}
3085 3085
 						}
@@ -3090,40 +3090,40 @@  discard block
 block discarded – undo
3090 3090
 			// avoid calling sortByAutoFolder as it is not regarding subfolders
3091 3091
 			$autoFolderObjectsTmp = $autoFolderObjects;
3092 3092
 			unset($autoFolderObjects);
3093
-			uasort($autoFolderObjectsTmp, array($this,'sortByMailbox'));
3094
-			foreach($autoFoldersTmp as $afk=>$aF)
3093
+			uasort($autoFolderObjectsTmp, array($this, 'sortByMailbox'));
3094
+			foreach ($autoFoldersTmp as $afk=>$aF)
3095 3095
 			{
3096
-				foreach($autoFolderObjectsTmp as $k => $f)
3096
+				foreach ($autoFolderObjectsTmp as $k => $f)
3097 3097
 				{
3098
-					if($aF && ($mySpecialUseFolders[$aF]==$k ||
3099
-						substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter ||
3100
-						stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3098
+					if ($aF && ($mySpecialUseFolders[$aF] == $k ||
3099
+						substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter ||
3100
+						stristr($mySpecialUseFolders[$aF], $k.$delimiter) !== false))
3101 3101
 					{
3102
-						$autoFolderObjects[$k]=$f;
3102
+						$autoFolderObjects[$k] = $f;
3103 3103
 					}
3104 3104
 				}
3105 3105
 			}
3106 3106
 			//error_log(__METHOD__.__LINE__.array2string($autoFolderObjects));
3107 3107
 			if (!$isGoogleMail) {
3108
-				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$inboxSubFolderObjects,(array)$folders,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3108
+				$folders = array_merge($inboxFolderObject, $autoFolderObjects, (array)$inboxSubFolderObjects, (array)$folders, (array)$typeFolderObject['others'], (array)$typeFolderObject['shared']);
3109 3109
 			} else {
3110 3110
 				// avoid calling sortByAutoFolder as it is not regarding subfolders
3111 3111
 				$gAutoFolderObjectsTmp = $googleAutoFolderObjects;
3112 3112
 				unset($googleAutoFolderObjects);
3113
-				uasort($gAutoFolderObjectsTmp, array($this,'sortByMailbox'));
3114
-				foreach($autoFoldersTmp as $afk=>$aF)
3113
+				uasort($gAutoFolderObjectsTmp, array($this, 'sortByMailbox'));
3114
+				foreach ($autoFoldersTmp as $afk=>$aF)
3115 3115
 				{
3116
-					foreach($gAutoFolderObjectsTmp as $k => $f)
3116
+					foreach ($gAutoFolderObjectsTmp as $k => $f)
3117 3117
 					{
3118
-						if($aF && ($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter))
3118
+						if ($aF && ($mySpecialUseFolders[$aF] == $k || substr($k, 0, strlen($mySpecialUseFolders[$aF].$delimiter)) == $mySpecialUseFolders[$aF].$delimiter))
3119 3119
 						{
3120
-							$googleAutoFolderObjects[$k]=$f;
3120
+							$googleAutoFolderObjects[$k] = $f;
3121 3121
 						}
3122 3122
 					}
3123 3123
 				}
3124
-				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$folders,(array)$googleMailFolderObject,$googleAutoFolderObjects,$googleSubFolderObjects,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3124
+				$folders = array_merge($inboxFolderObject, $autoFolderObjects, (array)$folders, (array)$googleMailFolderObject, $googleAutoFolderObjects, $googleSubFolderObjects, (array)$typeFolderObject['others'], (array)$typeFolderObject['shared']);
3125 3125
 			}
3126
-			if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3126
+			if (self::$debugTimes) self::logRunTimes($starttime, null, function_backtrace(), __METHOD__.' ('.__LINE__.') Sorting:');
3127 3127
 			//self::$debugTimes=false;
3128 3128
 		}
3129 3129
 		// Get counter information and add them to each fetched folders array
@@ -3145,10 +3145,10 @@  discard block
 block discarded – undo
3145 3145
 	 * @param array $autofolders_exists existing folders, no need to check their existance again
3146 3146
 	 * @return int number of new folders created
3147 3147
 	 */
3148
-	function check_create_autofolders(array $autofolders_exists=array())
3148
+	function check_create_autofolders(array $autofolders_exists = array())
3149 3149
 	{
3150 3150
 		$num_created = 0;
3151
-		foreach(self::$autoFolders as $folder)
3151
+		foreach (self::$autoFolders as $folder)
3152 3152
 		{
3153 3153
 			$created = false;
3154 3154
 			if (!in_array($folder, $autofolders_exists) && $this->_getSpecialUseFolder($folder, true, $created) &&
@@ -3173,7 +3173,7 @@  discard block
 block discarded – undo
3173 3173
 		$rv = false;
3174 3174
 		foreach ($haystack as $k => $v)
3175 3175
 		{
3176
-			foreach($v as &$sv) {if (trim($sv)==trim($needle)) return $k;}
3176
+			foreach ($v as &$sv) {if (trim($sv) == trim($needle)) return $k; }
3177 3177
 		}
3178 3178
 		return $rv;
3179 3179
 	}
@@ -3186,9 +3186,9 @@  discard block
 block discarded – undo
3186 3186
 	 * @param array $b array of folders
3187 3187
 	 * @return int expect values (0, 1 or -1)
3188 3188
 	 */
3189
-	function sortByMailbox($a,$b)
3189
+	function sortByMailbox($a, $b)
3190 3190
 	{
3191
-		return strcasecmp($a['MAILBOX'],$b['MAILBOX']);
3191
+		return strcasecmp($a['MAILBOX'], $b['MAILBOX']);
3192 3192
 	}
3193 3193
 
3194 3194
 	/**
@@ -3198,13 +3198,13 @@  discard block
 block discarded – undo
3198 3198
 	 * @param string $_hDelimiter hierarchy delimiter
3199 3199
 	 * @return array returns an array of data extracted from given node path
3200 3200
 	 */
3201
-	static function pathToFolderData ($_path, $_hDelimiter)
3201
+	static function pathToFolderData($_path, $_hDelimiter)
3202 3202
 	{
3203 3203
 		if (!strpos($_path, self::DELIMITER)) $_path = self::DELIMITER.$_path;
3204 3204
 		list(,$path) = explode(self::DELIMITER, $_path);
3205 3205
 		$path_chain = $parts = explode($_hDelimiter, $path);
3206 3206
 		$name = array_pop($parts);
3207
-		return array (
3207
+		return array(
3208 3208
 			'name' => $name,
3209 3209
 			'mailbox' => $path,
3210 3210
 			'parent' => implode($_hDelimiter, $parts),
@@ -3227,8 +3227,8 @@  discard block
 block discarded – undo
3227 3227
 		// 0, 1 und -1
3228 3228
 		$a = self::pathToFolderData($_a['MAILBOX'], $_a['delimiter']);
3229 3229
 		$b = self::pathToFolderData($_b['MAILBOX'], $_b['delimiter']);
3230
-		$pos1 = array_search(trim($a['name']),self::$autoFolders);
3231
-		$pos2 = array_search(trim($b['name']),self::$autoFolders);
3230
+		$pos1 = array_search(trim($a['name']), self::$autoFolders);
3231
+		$pos2 = array_search(trim($b['name']), self::$autoFolders);
3232 3232
 		if ($pos1 == $pos2) return 0;
3233 3233
 		return ($pos1 < $pos2) ? -1 : 1;
3234 3234
 	}
@@ -3241,10 +3241,10 @@  discard block
 block discarded – undo
3241 3241
 	 * @param object $b array of folderobjects
3242 3242
 	 * @return int expect values (0, 1 or -1)
3243 3243
 	 */
3244
-	function sortByDisplayName($a,$b)
3244
+	function sortByDisplayName($a, $b)
3245 3245
 	{
3246 3246
 		// 0, 1 und -1
3247
-		return strcasecmp($a->displayName,$b->displayName);
3247
+		return strcasecmp($a->displayName, $b->displayName);
3248 3248
 	}
3249 3249
 
3250 3250
 	/**
@@ -3255,11 +3255,11 @@  discard block
 block discarded – undo
3255 3255
 	 * @param object $b array of folderobjects
3256 3256
 	 * @return int expect values (0, 1 or -1)
3257 3257
 	 */
3258
-	function sortByAutoFolderPos($a,$b)
3258
+	function sortByAutoFolderPos($a, $b)
3259 3259
 	{
3260 3260
 		// 0, 1 und -1
3261
-		$pos1 = array_search(trim($a->shortFolderName),self::$autoFolders);
3262
-		$pos2 = array_search(trim($b->shortFolderName),self::$autoFolders);
3261
+		$pos1 = array_search(trim($a->shortFolderName), self::$autoFolders);
3262
+		$pos2 = array_search(trim($b->shortFolderName), self::$autoFolders);
3263 3263
 		if ($pos1 == $pos2) return 0;
3264 3264
 		return ($pos1 < $pos2) ? -1 : 1;
3265 3265
 	}
@@ -3272,7 +3272,7 @@  discard block
 block discarded – undo
3272 3272
 	 * @param boolean $_returnObject return the counters as object rather than an array
3273 3273
 	 * @return mixed false or array of counters array(MESSAGES,UNSEEN,RECENT,UIDNEXT,UIDVALIDITY) or object
3274 3274
 	 */
3275
-	function getMailBoxCounters($folderName,$_returnObject=true)
3275
+	function getMailBoxCounters($folderName, $_returnObject = true)
3276 3276
 	{
3277 3277
 		try
3278 3278
 		{
@@ -3284,9 +3284,9 @@  discard block
 block discarded – undo
3284 3284
 			if (self::$debug) error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3285 3285
 			return false;
3286 3286
 		}
3287
-		if(is_array($folderStatus)) {
3288
-			if ($_returnObject===false) return $folderStatus;
3289
-			$status =  new \stdClass;
3287
+		if (is_array($folderStatus)) {
3288
+			if ($_returnObject === false) return $folderStatus;
3289
+			$status = new \stdClass;
3290 3290
 			$status->messages   = $folderStatus['MESSAGES'];
3291 3291
 			$status->unseen     = $folderStatus['UNSEEN'];
3292 3292
 			$status->recent     = $folderStatus['RECENT'];
@@ -3308,42 +3308,42 @@  discard block
 block discarded – undo
3308 3308
 	 * @param string $reclevel 0, counter to keep track of the current recursionlevel
3309 3309
 	 * @return array of mailboxes
3310 3310
 	 */
3311
-	function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel=0)
3311
+	function getMailBoxesRecursive($_mailbox, $delimiter, $prefix, $reclevel = 0)
3312 3312
 	{
3313 3313
 		#echo __METHOD__." retrieve SubFolders for $_mailbox$delimiter <br>";
3314
-		$maxreclevel=25;
3314
+		$maxreclevel = 25;
3315 3315
 		if ($reclevel > $maxreclevel) {
3316
-			error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
3316
+			error_log(__METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
3317 3317
 			return array();
3318 3318
 		}
3319 3319
 		$reclevel++;
3320 3320
 		// clean up double delimiters
3321
-		$_mailbox = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$_mailbox);
3321
+		$_mailbox = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter : $delimiter).'+~s', $delimiter, $_mailbox);
3322 3322
 		//get that mailbox in question
3323
-		$mbx = $this->icServer->getMailboxes($_mailbox,1,true);
3323
+		$mbx = $this->icServer->getMailboxes($_mailbox, 1, true);
3324 3324
 		$mbxkeys = array_keys($mbx);
3325 3325
 		#_debug_array($mbx);
3326 3326
 //error_log(__METHOD__.' ('.__LINE__.') '.' Delimiter:'.array2string($delimiter));
3327 3327
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx));
3328 3328
 		// Example: Array([INBOX/GaGa] => Array([MAILBOX] => INBOX/GaGa[ATTRIBUTES] => Array([0] => \\unmarked)[delimiter] => /))
3329
-		if (is_array($mbx[$mbxkeys[0]]["ATTRIBUTES"]) && (in_array('\HasChildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Haschildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\haschildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]))) {
3329
+		if (is_array($mbx[$mbxkeys[0]]["ATTRIBUTES"]) && (in_array('\HasChildren', $mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Haschildren', $mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\haschildren', $mbx[$mbxkeys[0]]["ATTRIBUTES"]))) {
3330 3330
 			// if there are children fetch them
3331 3331
 			//echo $mbx[$mbxkeys[0]]['MAILBOX']."<br>";
3332 3332
 
3333
-			$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'].($mbx[$mbxkeys[0]]['MAILBOX'] == $prefix ? '':$delimiter),2,false);
3333
+			$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'].($mbx[$mbxkeys[0]]['MAILBOX'] == $prefix ? '' : $delimiter), 2, false);
3334 3334
 			//$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'],2,false);
3335 3335
 			//_debug_array($buff);
3336 3336
 			$allMailboxes = array();
3337 3337
 			foreach ($buff as $mbxname) {
3338 3338
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbxname));
3339
-				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname['MAILBOX']);
3339
+				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter : $delimiter).'+~s', $delimiter, $mbxname['MAILBOX']);
3340 3340
 				#echo "About to recur in level $reclevel:".$mbxname."<br>";
3341
-				if ( $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'] && $mbxname != $prefix  && $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'].$delimiter)
3341
+				if ($mbxname != $mbx[$mbxkeys[0]]['MAILBOX'] && $mbxname != $prefix && $mbxname != $mbx[$mbxkeys[0]]['MAILBOX'].$delimiter)
3342 3342
 				{
3343 3343
 					$allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel));
3344 3344
 				}
3345 3345
 			}
3346
-			if (!(in_array('\NoSelect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]))) $allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX'];
3346
+			if (!(in_array('\NoSelect', $mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect', $mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect', $mbx[$mbxkeys[0]]["ATTRIBUTES"]))) $allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX'];
3347 3347
 			return $allMailboxes;
3348 3348
 		} else {
3349 3349
 			return array($_mailbox);
@@ -3358,18 +3358,18 @@  discard block
 block discarded – undo
3358 3358
 	 * @param boolean& $created =null on return true: if folder was just created, false if not
3359 3359
 	 * @return mixed string or false
3360 3360
 	 */
3361
-	function _getSpecialUseFolder($_type, $_checkexistance=TRUE, &$created=null)
3361
+	function _getSpecialUseFolder($_type, $_checkexistance = TRUE, &$created = null)
3362 3362
 	{
3363 3363
 		static $types = array(
3364
-			'Drafts'   => array('profileKey'=>'acc_folder_draft','autoFolderName'=>'Drafts'),
3365
-			'Template' => array('profileKey'=>'acc_folder_template','autoFolderName'=>'Templates'),
3366
-			'Trash'    => array('profileKey'=>'acc_folder_trash','autoFolderName'=>'Trash'),
3367
-			'Sent'     => array('profileKey'=>'acc_folder_sent','autoFolderName'=>'Sent'),
3368
-			'Junk'     => array('profileKey'=>'acc_folder_junk','autoFolderName'=>'Junk'),
3369
-			'Outbox'   => array('profileKey'=>'acc_folder_outbox','autoFolderName'=>'Outbox'),
3370
-			'Archive'   => array('profileKey'=>'acc_folder_archive','autoFolderName'=>'Archive'),
3364
+			'Drafts'   => array('profileKey'=>'acc_folder_draft', 'autoFolderName'=>'Drafts'),
3365
+			'Template' => array('profileKey'=>'acc_folder_template', 'autoFolderName'=>'Templates'),
3366
+			'Trash'    => array('profileKey'=>'acc_folder_trash', 'autoFolderName'=>'Trash'),
3367
+			'Sent'     => array('profileKey'=>'acc_folder_sent', 'autoFolderName'=>'Sent'),
3368
+			'Junk'     => array('profileKey'=>'acc_folder_junk', 'autoFolderName'=>'Junk'),
3369
+			'Outbox'   => array('profileKey'=>'acc_folder_outbox', 'autoFolderName'=>'Outbox'),
3370
+			'Archive'   => array('profileKey'=>'acc_folder_archive', 'autoFolderName'=>'Archive'),
3371 3371
 		);
3372
-		if ($_type == 'Templates') $_type = 'Template';	// for some reason self::$autofolders uses 'Templates'!
3372
+		if ($_type == 'Templates') $_type = 'Template'; // for some reason self::$autofolders uses 'Templates'!
3373 3373
 		$created = false;
3374 3374
 		if (!isset($types[$_type]))
3375 3375
 		{
@@ -3391,7 +3391,7 @@  discard block
 block discarded – undo
3391 3391
 		}
3392 3392
 		// do not try to autocreate configured Archive-Folder. Return false if configured folder does not exist
3393 3393
 		if ($_type == 'Archive') {
3394
-			if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
3394
+			if ($_folderName && $_checkexistance && strtolower($_folderName) != 'none' && !$this->folderExists($_folderName, true)) {
3395 3395
 				return false;
3396 3396
 			} else {
3397 3397
 				return $_folderName;
@@ -3399,38 +3399,38 @@  discard block
 block discarded – undo
3399 3399
 
3400 3400
 		}
3401 3401
 		// does the folder exist??? (is configured/preset, but non-existent)
3402
-		if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
3402
+		if ($_folderName && $_checkexistance && strtolower($_folderName) != 'none' && !$this->folderExists($_folderName, true)) {
3403 3403
 			try
3404 3404
 			{
3405 3405
 				$error = null;
3406 3406
 				if (($_folderName = $this->createFolder('', $_folderName, $error))) $created = true;
3407 3407
 				if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
3408 3408
 			}
3409
-			catch(Exception $e)
3409
+			catch (Exception $e)
3410 3410
 			{
3411 3411
 				error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$e->getMessage().':'.function_backtrace());
3412 3412
 				$_folderName = false;
3413 3413
 			}
3414 3414
 		}
3415 3415
 		// not sure yet if false is the correct behavior on none
3416
-		if ($_folderName =='none') return 'none' ; //false;
3416
+		if ($_folderName == 'none') return 'none'; //false;
3417 3417
 		//no (valid) folder found yet; try specialUseFolders
3418
-		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders))) $_folderName = $f;
3418
+		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type, self::$specialUseFolders))) $_folderName = $f;
3419 3419
 		//no specialUseFolder; try some Defaults
3420 3420
 		if (empty($_folderName) && isset($types[$_type]))
3421 3421
 		{
3422 3422
 			$nameSpace = $this->_getNameSpaces();
3423
-			$prefix='';
3423
+			$prefix = '';
3424 3424
 			foreach ($nameSpace as $nSp)
3425 3425
 			{
3426
-				if ($nSp['type']=='personal')
3426
+				if ($nSp['type'] == 'personal')
3427 3427
 				{
3428 3428
 					//error_log(__METHOD__.__LINE__.array2string($nSp));
3429 3429
 					$prefix = $nSp['prefix'];
3430 3430
 					break;
3431 3431
 				}
3432 3432
 			}
3433
-			if ($this->folderExists($prefix.$types[$_type]['autoFolderName'],true))
3433
+			if ($this->folderExists($prefix.$types[$_type]['autoFolderName'], true))
3434 3434
 			{
3435 3435
 				$_folderName = $prefix.$types[$_type]['autoFolderName'];
3436 3436
 			}
@@ -3439,11 +3439,11 @@  discard block
 block discarded – undo
3439 3439
 				try
3440 3440
 				{
3441 3441
 					$error = null;
3442
-					$this->createFolder('', $prefix.$types[$_type]['autoFolderName'],$error);
3442
+					$this->createFolder('', $prefix.$types[$_type]['autoFolderName'], $error);
3443 3443
 					$_folderName = $prefix.$types[$_type]['autoFolderName'];
3444 3444
 					if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
3445 3445
 				}
3446
-				catch(Exception $e)
3446
+				catch (Exception $e)
3447 3447
 				{
3448 3448
 					error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$e->getMessage());
3449 3449
 					$_folderName = false;
@@ -3459,7 +3459,7 @@  discard block
 block discarded – undo
3459 3459
 	 * @param boolean $_checkexistance trigger check for existance
3460 3460
 	 * @return mixed string or false
3461 3461
 	 */
3462
-	function getFolderByType($type, $_checkexistance=false)
3462
+	function getFolderByType($type, $_checkexistance = false)
3463 3463
 	{
3464 3464
 		return $this->_getSpecialUseFolder($type, $_checkexistance);
3465 3465
 	}
@@ -3469,7 +3469,7 @@  discard block
 block discarded – undo
3469 3469
 	 * @param boolean $_checkexistance trigger check for existance
3470 3470
 	 * @return mixed string or false
3471 3471
 	 */
3472
-	function getJunkFolder($_checkexistance=TRUE)
3472
+	function getJunkFolder($_checkexistance = TRUE)
3473 3473
 	{
3474 3474
 		return $this->_getSpecialUseFolder('Junk', $_checkexistance);
3475 3475
 	}
@@ -3479,7 +3479,7 @@  discard block
 block discarded – undo
3479 3479
 	 * @param boolean $_checkexistance trigger check for existance
3480 3480
 	 * @return mixed string or false
3481 3481
 	 */
3482
-	function getDraftFolder($_checkexistance=TRUE)
3482
+	function getDraftFolder($_checkexistance = TRUE)
3483 3483
 	{
3484 3484
 		return $this->_getSpecialUseFolder('Drafts', $_checkexistance);
3485 3485
 	}
@@ -3489,7 +3489,7 @@  discard block
 block discarded – undo
3489 3489
 	 * @param boolean $_checkexistance trigger check for existance
3490 3490
 	 * @return mixed string or false
3491 3491
 	 */
3492
-	function getTemplateFolder($_checkexistance=TRUE)
3492
+	function getTemplateFolder($_checkexistance = TRUE)
3493 3493
 	{
3494 3494
 		return $this->_getSpecialUseFolder('Template', $_checkexistance);
3495 3495
 	}
@@ -3499,7 +3499,7 @@  discard block
 block discarded – undo
3499 3499
 	 * @param boolean $_checkexistance trigger check for existance
3500 3500
 	 * @return mixed string or false
3501 3501
 	 */
3502
-	function getTrashFolder($_checkexistance=TRUE)
3502
+	function getTrashFolder($_checkexistance = TRUE)
3503 3503
 	{
3504 3504
 		return $this->_getSpecialUseFolder('Trash', $_checkexistance);
3505 3505
 	}
@@ -3509,7 +3509,7 @@  discard block
 block discarded – undo
3509 3509
 	 * @param boolean $_checkexistance trigger check for existance
3510 3510
 	 * @return mixed string or false
3511 3511
 	 */
3512
-	function getSentFolder($_checkexistance=TRUE)
3512
+	function getSentFolder($_checkexistance = TRUE)
3513 3513
 	{
3514 3514
 		return $this->_getSpecialUseFolder('Sent', $_checkexistance);
3515 3515
 	}
@@ -3519,7 +3519,7 @@  discard block
 block discarded – undo
3519 3519
 	 * @param boolean $_checkexistance trigger check for existance
3520 3520
 	 * @return mixed string or false
3521 3521
 	 */
3522
-	function getOutboxFolder($_checkexistance=TRUE)
3522
+	function getOutboxFolder($_checkexistance = TRUE)
3523 3523
 	{
3524 3524
 		return $this->_getSpecialUseFolder('Outbox', $_checkexistance);
3525 3525
 	}
@@ -3529,7 +3529,7 @@  discard block
 block discarded – undo
3529 3529
 	 * @param boolean $_checkexistance trigger check for existance . We do no autocreation for configured Archive folder
3530 3530
 	 * @return mixed string or false
3531 3531
 	 */
3532
-	function getArchiveFolder($_checkexistance=TRUE)
3532
+	function getArchiveFolder($_checkexistance = TRUE)
3533 3533
 	{
3534 3534
 		return $this->_getSpecialUseFolder('Archive', $_checkexistance);
3535 3535
 	}
@@ -3540,10 +3540,10 @@  discard block
 block discarded – undo
3540 3540
 	 * @param boolean $_checkexistance trigger check for existance
3541 3541
 	 * @return boolean
3542 3542
 	 */
3543
-	function isSentFolder($_folderName, $_checkexistance=TRUE)
3543
+	function isSentFolder($_folderName, $_checkexistance = TRUE)
3544 3544
 	{
3545 3545
 		$sentFolder = $this->getSentFolder($_checkexistance);
3546
-		if(empty($sentFolder)) {
3546
+		if (empty($sentFolder)) {
3547 3547
 			return false;
3548 3548
 		}
3549 3549
 		// does the folder exist???
@@ -3551,7 +3551,7 @@  discard block
 block discarded – undo
3551 3551
 			return false;
3552 3552
 		}
3553 3553
 
3554
-		if(false !== stripos($_folderName, $sentFolder)) {
3554
+		if (false !== stripos($_folderName, $sentFolder)) {
3555 3555
 			return true;
3556 3556
 		} else {
3557 3557
 			return false;
@@ -3564,15 +3564,15 @@  discard block
 block discarded – undo
3564 3564
 	 * @param boolean $_checkexistance trigger check for existance
3565 3565
 	 * @return boolean
3566 3566
 	 */
3567
-	function isOutbox($_folderName, $_checkexistance=TRUE)
3567
+	function isOutbox($_folderName, $_checkexistance = TRUE)
3568 3568
 	{
3569
-		if (stripos($_folderName, 'Outbox')===false) {
3569
+		if (stripos($_folderName, 'Outbox') === false) {
3570 3570
 			return false;
3571 3571
 		}
3572 3572
 		// does the folder exist???
3573 3573
 		if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName)) {
3574 3574
 			$outboxFolder = $this->getOutboxFolder($_checkexistance);
3575
-			if(false !== stripos($_folderName, $outboxFolder)) {
3575
+			if (false !== stripos($_folderName, $outboxFolder)) {
3576 3576
 				return true;
3577 3577
 			} else {
3578 3578
 				return false;
@@ -3587,18 +3587,18 @@  discard block
 block discarded – undo
3587 3587
 	 * @param boolean $_checkexistance trigger check for existance
3588 3588
 	 * @return boolean
3589 3589
 	 */
3590
-	function isDraftFolder($_folderName, $_checkexistance=TRUE)
3590
+	function isDraftFolder($_folderName, $_checkexistance = TRUE)
3591 3591
 	{
3592 3592
 		$draftFolder = $this->getDraftFolder($_checkexistance);
3593
-		if(empty($draftFolder)) {
3593
+		if (empty($draftFolder)) {
3594 3594
 			return false;
3595 3595
 		}
3596 3596
 		// does the folder exist???
3597 3597
 		if ($_checkexistance && !$this->folderExists($_folderName)) {
3598 3598
 			return false;
3599 3599
 		}
3600
-		if (is_a($_folderName,"Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8;
3601
-		if(false !== stripos($_folderName, $draftFolder)) {
3600
+		if (is_a($_folderName, "Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8;
3601
+		if (false !== stripos($_folderName, $draftFolder)) {
3602 3602
 			return true;
3603 3603
 		} else {
3604 3604
 			return false;
@@ -3611,10 +3611,10 @@  discard block
 block discarded – undo
3611 3611
 	 * @param boolean $_checkexistance trigger check for existance
3612 3612
 	 * @return boolean
3613 3613
 	 */
3614
-	function isTrashFolder($_folderName, $_checkexistance=TRUE)
3614
+	function isTrashFolder($_folderName, $_checkexistance = TRUE)
3615 3615
 	{
3616 3616
 		$trashFolder = $this->getTrashFolder($_checkexistance);
3617
-		if(empty($trashFolder)) {
3617
+		if (empty($trashFolder)) {
3618 3618
 			return false;
3619 3619
 		}
3620 3620
 		// does the folder exist???
@@ -3622,7 +3622,7 @@  discard block
 block discarded – undo
3622 3622
 			return false;
3623 3623
 		}
3624 3624
 
3625
-		if(false !== stripos($_folderName, $trashFolder)) {
3625
+		if (false !== stripos($_folderName, $trashFolder)) {
3626 3626
 			return true;
3627 3627
 		} else {
3628 3628
 			return false;
@@ -3635,10 +3635,10 @@  discard block
 block discarded – undo
3635 3635
 	 * @param boolean $_checkexistance trigger check for existance
3636 3636
 	 * @return boolean
3637 3637
 	 */
3638
-	function isTemplateFolder($_folderName, $_checkexistance=TRUE)
3638
+	function isTemplateFolder($_folderName, $_checkexistance = TRUE)
3639 3639
 	{
3640 3640
 		$templateFolder = $this->getTemplateFolder($_checkexistance);
3641
-		if(empty($templateFolder)) {
3641
+		if (empty($templateFolder)) {
3642 3642
 			return false;
3643 3643
 		}
3644 3644
 		// does the folder exist???
@@ -3646,7 +3646,7 @@  discard block
 block discarded – undo
3646 3646
 			return false;
3647 3647
 		}
3648 3648
 
3649
-		if(false !== stripos($_folderName, $templateFolder)) {
3649
+		if (false !== stripos($_folderName, $templateFolder)) {
3650 3650
 			return true;
3651 3651
 		} else {
3652 3652
 			return false;
@@ -3659,24 +3659,24 @@  discard block
 block discarded – undo
3659 3659
 	 * @param boolean $_forceCheck trigger check for existance on icServer
3660 3660
 	 * @return mixed string or false
3661 3661
 	 */
3662
-	function folderExists($_folder, $_forceCheck=false)
3662
+	function folderExists($_folder, $_forceCheck = false)
3663 3663
 	{
3664 3664
 		static $folderInfo;
3665 3665
 		$forceCheck = $_forceCheck;
3666 3666
 		if (empty($_folder))
3667 3667
 		{
3668 3668
 			// this error is more or less without significance, unless we force the check
3669
-			if ($_forceCheck===true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
3669
+			if ($_forceCheck === true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
3670 3670
 			return false;
3671 3671
 		}
3672 3672
 		// when check is not enforced , we assume a folder represented as Horde_Imap_Client_Mailbox as existing folder
3673
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false) return true;
3674
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")) $_folder =  $_folder->utf8;
3673
+		if (is_a($_folder, "Horde_Imap_Client_Mailbox") && $_forceCheck === false) return true;
3674
+		if (is_a($_folder, "Horde_Imap_Client_Mailbox")) $_folder = $_folder->utf8;
3675 3675
 		// reduce traffic within the Instance per User; Expire every 5 hours
3676 3676
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Called with Folder:'.$_folder.function_backtrace());
3677
-		if (is_null($folderInfo)) $folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
3677
+		if (is_null($folderInfo)) $folderInfo = Cache::getCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), $expiration = 60 * 60 * 5);
3678 3678
 		//error_log(__METHOD__.' ('.__LINE__.') '.'Cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID.($forceCheck?'(forcedCheck)':'').':'.array2string($folderInfo));
3679
-		if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck===false)
3679
+		if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck === false)
3680 3680
 		{
3681 3681
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Using cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID);
3682 3682
 			return $folderInfo[$this->profileID][$_folder];
@@ -3692,7 +3692,7 @@  discard block
 block discarded – undo
3692 3692
 
3693 3693
 		// does the folder exist???
3694 3694
 		//error_log(__METHOD__."->Connected?".$this->icServer->_connected.", ".$_folder.", ".($forceCheck?' forceCheck activated':'dont check on server'));
3695
-		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
3695
+		if ($forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
3696 3696
 			//error_log(__METHOD__."->NotConnected and forceCheck with profile:".$this->profileID);
3697 3697
 			//return false;
3698 3698
 			//try to connect
@@ -3703,18 +3703,18 @@  discard block
 block discarded – undo
3703 3703
 		}
3704 3704
 		catch (\Exception $e)
3705 3705
 		{
3706
-			error_log(__METHOD__.__LINE__.$e->getMessage().($e->details?', '.$e->details:''));
3707
-			self::$profileDefunct[$this->profileID]=true;
3706
+			error_log(__METHOD__.__LINE__.$e->getMessage().($e->details ? ', '.$e->details : ''));
3707
+			self::$profileDefunct[$this->profileID] = true;
3708 3708
 			$folderInfo[$this->profileID][$_folder] = false;
3709 3709
 		}
3710 3710
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Folder Exists:'.$folderInfo[$this->profileID][$_folder].function_backtrace());
3711 3711
 
3712
-		if(!empty($folderInfo) && isset($folderInfo[$this->profileID][$_folder]) &&
3712
+		if (!empty($folderInfo) && isset($folderInfo[$this->profileID][$_folder]) &&
3713 3713
 			$folderInfo[$this->profileID][$_folder] !== true)
3714 3714
 		{
3715 3715
 			$folderInfo[$this->profileID][$_folder] = false; // set to false, whatever it was (to have a valid returnvalue for the static return)
3716 3716
 		}
3717
-		Cache::setCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderInfo,$expiration=60*60*5);
3717
+		Cache::setCache(Cache::INSTANCE, 'email', 'icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']), $folderInfo, $expiration = 60 * 60 * 5);
3718 3718
 		return (!empty($folderInfo) && isset($folderInfo[$this->profileID][$_folder]) ? $folderInfo[$this->profileID][$_folder] : false);
3719 3719
 	}
3720 3720
 
@@ -3727,14 +3727,14 @@  discard block
 block discarded – undo
3727 3727
 	 */
3728 3728
 	function compressFolder($_folderName = false)
3729 3729
 	{
3730
-		$folderName	= ($_folderName ? $_folderName : $this->sessionData['mailbox']);
3731
-		$deleteOptions	= $GLOBALS['egw_info']['user']['preferences']['mail']['deleteOptions'];
3732
-		$trashFolder	= $this->getTrashFolder();
3730
+		$folderName = ($_folderName ? $_folderName : $this->sessionData['mailbox']);
3731
+		$deleteOptions = $GLOBALS['egw_info']['user']['preferences']['mail']['deleteOptions'];
3732
+		$trashFolder = $this->getTrashFolder();
3733 3733
 
3734 3734
 		$this->icServer->openMailbox($folderName);
3735 3735
 
3736
-		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") {
3737
-			$this->deleteMessages('all',$folderName,'remove_immediately');
3736
+		if (strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") {
3737
+			$this->deleteMessages('all', $folderName, 'remove_immediately');
3738 3738
 		} else {
3739 3739
 			$this->icServer->expunge($folderName);
3740 3740
 		}
@@ -3750,19 +3750,19 @@  discard block
 block discarded – undo
3750 3750
 	 * @return bool true, as we do not handle return values yet
3751 3751
 	 * @throws Exception
3752 3752
 	 */
3753
-	function deleteMessages($_messageUID, $_folder=NULL, $_forceDeleteMethod='no')
3753
+	function deleteMessages($_messageUID, $_folder = NULL, $_forceDeleteMethod = 'no')
3754 3754
 	{
3755 3755
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.array2string($_folder).', '.$_forceDeleteMethod);
3756 3756
 		$oldMailbox = '';
3757 3757
 		if (is_null($_folder) || empty($_folder)) $_folder = $this->sessionData['mailbox'];
3758 3758
 		if (empty($_messageUID))
3759 3759
 		{
3760
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
3760
+			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',', $_messageUID));
3761 3761
 			return false;
3762 3762
 		}
3763
-		elseif ($_messageUID==='all')
3763
+		elseif ($_messageUID === 'all')
3764 3764
 		{
3765
-			$_messageUID= null;
3765
+			$_messageUID = null;
3766 3766
 		}
3767 3767
 		else
3768 3768
 		{
@@ -3771,32 +3771,32 @@  discard block
 block discarded – undo
3771 3771
 			$uidsToDelete->add($_messageUID);
3772 3772
 		}
3773 3773
 		$deleteOptions = $_forceDeleteMethod; // use forceDeleteMethod if not "no", or unknown method
3774
-		if ($_forceDeleteMethod === 'no' || !in_array($_forceDeleteMethod,array('move_to_trash',"mark_as_deleted","remove_immediately"))) $deleteOptions  = ($this->mailPreferences['deleteOptions']?$this->mailPreferences['deleteOptions']:"mark_as_deleted");
3774
+		if ($_forceDeleteMethod === 'no' || !in_array($_forceDeleteMethod, array('move_to_trash', "mark_as_deleted", "remove_immediately"))) $deleteOptions = ($this->mailPreferences['deleteOptions'] ? $this->mailPreferences['deleteOptions'] : "mark_as_deleted");
3775 3775
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3776 3776
 		$trashFolder    = $this->getTrashFolder();
3777
-		$draftFolder	= $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder'];
3777
+		$draftFolder = $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder'];
3778 3778
 		$templateFolder = $this->getTemplateFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['templateFolder'];
3779
-		if((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") ||
3779
+		if ((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") ||
3780 3780
 		   (strtolower($_folder) == strtolower($draftFolder))) {
3781 3781
 			$deleteOptions = "remove_immediately";
3782 3782
 		}
3783
-		if($this->icServer->getCurrentMailbox() != $_folder) {
3783
+		if ($this->icServer->getCurrentMailbox() != $_folder) {
3784 3784
 			$oldMailbox = $this->icServer->getCurrentMailbox();
3785 3785
 			$this->icServer->openMailbox($_folder);
3786 3786
 		}
3787 3787
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3788 3788
 		$updateCache = false;
3789
-		switch($deleteOptions) {
3789
+		switch ($deleteOptions) {
3790 3790
 			case "move_to_trash":
3791 3791
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3792 3792
 				$updateCache = true;
3793
-				if(!empty($trashFolder)) {
3793
+				if (!empty($trashFolder)) {
3794 3794
 					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
3795
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
3795
+					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ".$this->sessionData['mailbox']);
3796 3796
 					// copy messages
3797 3797
 					try
3798 3798
 					{
3799
-						$this->icServer->copy($_folder, $trashFolder, array('ids'=>$uidsToDelete,'move'=>true));
3799
+						$this->icServer->copy($_folder, $trashFolder, array('ids'=>$uidsToDelete, 'move'=>true));
3800 3800
 					}
3801 3801
 					catch (\Exception $e)
3802 3802
 					{
@@ -3808,18 +3808,18 @@  discard block
 block discarded – undo
3808 3808
 			case "mark_as_deleted":
3809 3809
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3810 3810
 				// mark messages as deleted
3811
-				if (is_null($_messageUID)) $_messageUID='all';
3812
-				foreach((array)$_messageUID as $key =>$uid)
3811
+				if (is_null($_messageUID)) $_messageUID = 'all';
3812
+				foreach ((array)$_messageUID as $key =>$uid)
3813 3813
 				{
3814 3814
 					//flag messages, that are flagged for deletion as seen too
3815 3815
 					$this->flagMessages('read', $uid, $_folder);
3816 3816
 					$flags = $this->getFlags($uid);
3817 3817
 					$this->flagMessages('delete', $uid, $_folder);
3818 3818
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
3819
-					if (strpos( array2string($flags),'Deleted')!==false) $undelete[] = $uid;
3819
+					if (strpos(array2string($flags), 'Deleted') !== false) $undelete[] = $uid;
3820 3820
 					unset($flags);
3821 3821
 				}
3822
-				foreach((array)$undelete as $key =>$uid)
3822
+				foreach ((array)$undelete as $key =>$uid)
3823 3823
 				{
3824 3824
 					$this->flagMessages('undelete', $uid, $_folder);
3825 3825
 				}
@@ -3828,14 +3828,14 @@  discard block
 block discarded – undo
3828 3828
 			case "remove_immediately":
3829 3829
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3830 3830
 				$updateCache = true;
3831
-				if (is_null($_messageUID)) $_messageUID='all';
3831
+				if (is_null($_messageUID)) $_messageUID = 'all';
3832 3832
 				if (is_object($_messageUID))
3833 3833
 				{
3834 3834
 					$this->flagMessages('delete', $_messageUID, $_folder);
3835 3835
 				}
3836 3836
 				else
3837 3837
 				{
3838
-					foreach((array)$_messageUID as $key =>$uid)
3838
+					foreach ((array)$_messageUID as $key =>$uid)
3839 3839
 					{
3840 3840
 						//flag messages, that are flagged for deletion as seen too
3841 3841
 						$this->flagMessages('delete', $uid, $_folder);
@@ -3845,7 +3845,7 @@  discard block
 block discarded – undo
3845 3845
 				$this->icServer->expunge($_folder);
3846 3846
 				break;
3847 3847
 		}
3848
-		if($oldMailbox != '') {
3848
+		if ($oldMailbox != '') {
3849 3849
 			$this->icServer->openMailbox($oldMailbox);
3850 3850
 		}
3851 3851
 
@@ -3859,7 +3859,7 @@  discard block
 block discarded – undo
3859 3859
 	 *
3860 3860
 	 * @return null/array flags
3861 3861
 	 */
3862
-	function getFlags ($_messageUID) {
3862
+	function getFlags($_messageUID) {
3863 3863
 		try
3864 3864
 		{
3865 3865
 			$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -3872,7 +3872,7 @@  discard block
 block discarded – undo
3872 3872
 				'ids' => $uidsToFetch,
3873 3873
 			));
3874 3874
 			if (is_object($headersNew)) {
3875
-				foreach($headersNew->ids() as $id) {
3875
+				foreach ($headersNew->ids() as $id) {
3876 3876
 					$_headerObject = $headersNew->get($id);
3877 3877
 					$flags = $_headerObject->getFlags();
3878 3878
 				}
@@ -3895,22 +3895,22 @@  discard block
 block discarded – undo
3895 3895
 	 *
3896 3896
 	 * @return null/boolean
3897 3897
 	 */
3898
-	function getNotifyFlags ($_messageUID, $flags=null)
3898
+	function getNotifyFlags($_messageUID, $flags = null)
3899 3899
 	{
3900 3900
 		if (self::$debug) error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
3901 3901
 		try
3902 3902
 		{
3903
-			if($flags===null) $flags =  $this->getFlags($_messageUID);
3903
+			if ($flags === null) $flags = $this->getFlags($_messageUID);
3904 3904
 		}
3905 3905
 		catch (\Exception $e)
3906 3906
 		{
3907 3907
 			return null;
3908 3908
 		}
3909 3909
 
3910
-		if ( stripos( array2string($flags),'MDNSent')!==false)
3910
+		if (stripos(array2string($flags), 'MDNSent') !== false)
3911 3911
 			return true;
3912 3912
 
3913
-		if ( stripos( array2string($flags),'MDNnotSent')!==false)
3913
+		if (stripos(array2string($flags), 'MDNnotSent') !== false)
3914 3914
 			return false;
3915 3915
 
3916 3916
 		return null;
@@ -3927,45 +3927,45 @@  discard block
 block discarded – undo
3927 3927
 	 *
3928 3928
 	 * @return bool true, as we do not handle icserver->setFlags returnValue
3929 3929
 	 */
3930
-	function flagMessages($_flag, $_messageUID,$_folder=NULL)
3930
+	function flagMessages($_flag, $_messageUID, $_folder = NULL)
3931 3931
 	{
3932 3932
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",$_folder /".$this->sessionData['mailbox']);
3933 3933
 		if (empty($_messageUID))
3934 3934
 		{
3935
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
3935
+			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',', $_messageUID));
3936 3936
 			return false;
3937 3937
 		}
3938
-		$this->icServer->openMailbox(($_folder?$_folder:$this->sessionData['mailbox']));
3938
+		$this->icServer->openMailbox(($_folder ? $_folder : $this->sessionData['mailbox']));
3939 3939
 		$folder = $this->icServer->getCurrentMailbox();
3940
-		if (is_array($_messageUID)&& count($_messageUID)>50)
3940
+		if (is_array($_messageUID) && count($_messageUID) > 50)
3941 3941
 		{
3942
-			$count = $this->getMailBoxCounters($folder,true);
3943
-			if ($count->messages == count($_messageUID)) $_messageUID='all';
3942
+			$count = $this->getMailBoxCounters($folder, true);
3943
+			if ($count->messages == count($_messageUID)) $_messageUID = 'all';
3944 3944
 		}
3945 3945
 
3946
-		if ($_messageUID==='all')
3946
+		if ($_messageUID === 'all')
3947 3947
 		{
3948 3948
 			$messageUIDs = array('all');
3949 3949
 		}
3950 3950
 		else
3951 3951
 		{
3952 3952
 			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
3953
-			$messageUIDs = array_chunk($_messageUID,50,true);
3953
+			$messageUIDs = array_chunk($_messageUID, 50, true);
3954 3954
 		}
3955 3955
 		try
3956 3956
 		{
3957
-			foreach($messageUIDs as &$uids)
3957
+			foreach ($messageUIDs as &$uids)
3958 3958
 			{
3959
-				if ($uids==='all')
3959
+				if ($uids === 'all')
3960 3960
 				{
3961
-					$uidsToModify=null;
3961
+					$uidsToModify = null;
3962 3962
 				}
3963 3963
 				else
3964 3964
 				{
3965 3965
 					$uidsToModify = new Horde_Imap_Client_Ids();
3966 3966
 					$uidsToModify->add($uids);
3967 3967
 				}
3968
-				switch($_flag) {
3968
+				switch ($_flag) {
3969 3969
 					case "delete":
3970 3970
 						$ret = $this->icServer->store($folder, array('add'=>array('\\Deleted'), 'ids'=> $uidsToModify));
3971 3971
 						break;
@@ -3989,7 +3989,7 @@  discard block
 block discarded – undo
3989 3989
 						break;
3990 3990
 					case "unread":
3991 3991
 					case "unseen":
3992
-						$ret = $this->icServer->store($folder, array('remove'=>array('\\Seen','\\Answered','$Forwarded'), 'ids'=> $uidsToModify));
3992
+						$ret = $this->icServer->store($folder, array('remove'=>array('\\Seen', '\\Answered', '$Forwarded'), 'ids'=> $uidsToModify));
3993 3993
 						break;
3994 3994
 					case "mdnsent":
3995 3995
 						$ret = $this->icServer->store($folder, array('add'=>array('MDNSent'), 'ids'=> $uidsToModify));
@@ -4047,13 +4047,13 @@  discard block
 block discarded – undo
4047 4047
 				}
4048 4048
 			}
4049 4049
 		}
4050
-		catch(Exception $e)
4050
+		catch (Exception $e)
4051 4051
 		{
4052 4052
 			error_log(__METHOD__.__LINE__.' Error, could not flag messages in folder '.$folder.' Reason:'.$e->getMessage());
4053 4053
 		}
4054 4054
 		if ($folder instanceof Horde_Imap_Client_Mailbox) $_folder = $folder->utf8;
4055 4055
 		//error_log(__METHOD__.__LINE__.'#'.$this->icServer->ImapServerId.'#'.array2string($_folder).'#');
4056
-		self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])]['uidValidity'] = 0;
4056
+		self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder) ? $_folder : $this->sessionData['mailbox'])]['uidValidity'] = 0;
4057 4057
 
4058 4058
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",".($_folder?$_folder:$this->sessionData['mailbox']));
4059 4059
 		return true; // as we do not catch/examine setFlags returnValue
@@ -4074,19 +4074,19 @@  discard block
 block discarded – undo
4074 4074
 	 * @return mixed/bool true,false or new uid
4075 4075
 	 * @throws Exception
4076 4076
 	 */
4077
-	function moveMessages($_foldername, $_messageUID, $deleteAfterMove=true, $currentFolder = Null, $returnUIDs = false, $_sourceProfileID = Null, $_targetProfileID = Null)
4077
+	function moveMessages($_foldername, $_messageUID, $deleteAfterMove = true, $currentFolder = Null, $returnUIDs = false, $_sourceProfileID = Null, $_targetProfileID = Null)
4078 4078
 	{
4079
-		$source = Mail\Account::read(($_sourceProfileID?$_sourceProfileID:$this->icServer->ImapServerId))->imapServer();
4079
+		$source = Mail\Account::read(($_sourceProfileID ? $_sourceProfileID : $this->icServer->ImapServerId))->imapServer();
4080 4080
 		//$deleteOptions  = $GLOBALS['egw_info']["user"]["preferences"]["mail"]["deleteOptions"];
4081 4081
 		if (empty($_messageUID))
4082 4082
 		{
4083
-			if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4083
+			if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',', $_messageUID));
4084 4084
 			return false;
4085 4085
 		}
4086
-		elseif ($_messageUID==='all')
4086
+		elseif ($_messageUID === 'all')
4087 4087
 		{
4088 4088
 			//error_log(__METHOD__." all Message(s): ".implode(',',$_messageUID));
4089
-			$uidsToMove= null;
4089
+			$uidsToMove = null;
4090 4090
 		}
4091 4091
 		else
4092 4092
 		{
@@ -4095,7 +4095,7 @@  discard block
 block discarded – undo
4095 4095
 			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4096 4096
 			$uidsToMove->add($_messageUID);
4097 4097
 		}
4098
-		$sourceFolder = (!empty($currentFolder)?$currentFolder: $this->sessionData['mailbox']);
4098
+		$sourceFolder = (!empty($currentFolder) ? $currentFolder : $this->sessionData['mailbox']);
4099 4099
 		//error_log(__METHOD__.__LINE__."$_targetProfileID !== ".array2string($source->ImapServerId));
4100 4100
 		if (!is_null($_targetProfileID) && $_targetProfileID !== $source->ImapServerId)
4101 4101
 		{
@@ -4115,19 +4115,19 @@  discard block
 block discarded – undo
4115 4115
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' mailheaders:'.array2string($headersNew));
4116 4116
 
4117 4117
 			if (is_object($headersNew)) {
4118
-				$c=0;
4118
+				$c = 0;
4119 4119
 				$retUid = new Horde_Imap_Client_Ids();
4120 4120
 				// we copy chunks of 5 to avoid too much memory and/or server stress
4121 4121
 				// some servers seem not to allow/support the appendig of multiple messages. so we are down to one
4122
-				foreach($headersNew as &$_headerObject) {
4122
+				foreach ($headersNew as &$_headerObject) {
4123 4123
 					$c++;
4124 4124
 					$flags = $_headerObject->getFlags(); //unseen status seems to be lost when retrieving the full message
4125 4125
 					$date = $_headerObject->getImapDate();
4126
-					$currentDate =  new Horde_Imap_Client_DateTime();
4126
+					$currentDate = new Horde_Imap_Client_DateTime();
4127 4127
 					// if the internal Date of the message equals the current date; try using the header date
4128
-					if ($date==$currentDate)
4128
+					if ($date == $currentDate)
4129 4129
 					{
4130
-						$headerForPrio = array_change_key_case($_headerObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
4130
+						$headerForPrio = array_change_key_case($_headerObject->getHeaderText(0, Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray(), CASE_UPPER);
4131 4131
 						//error_log(__METHOD__.__LINE__.'#'.array2string($date).'#'.array2string($currentDate).'#'.$headerForPrio['DATE']);
4132 4132
 						$date = new Horde_Imap_Client_DateTime($headerForPrio['DATE']);
4133 4133
 						//error_log(__METHOD__.__LINE__.'#'.array2string($date).'#'.array2string($currentDate).'#');
@@ -4136,20 +4136,20 @@  discard block
 block discarded – undo
4136 4136
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
4137 4137
 					$body = $_headerObject->getFullMsg();
4138 4138
 					$dataNflags[] = array('data'=>$body, 'flags'=>$flags, 'internaldate'=>$date);
4139
-					if ($c==1)
4139
+					if ($c == 1)
4140 4140
 					{
4141 4141
 						$target = Mail\Account::read($_targetProfileID)->imapServer();
4142 4142
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' TargetServer:'.$_targetProfileID.' TargetFolderObject:'.array2string($_foldername));
4143 4143
 						$foldername = $target->getMailbox($_foldername);
4144 4144
 						// make sure the target folder is open and ready
4145 4145
 						$target->openMailbox($foldername);
4146
-						$ret = $target->append($foldername,$dataNflags);
4146
+						$ret = $target->append($foldername, $dataNflags);
4147 4147
 						$retUid->add($ret);
4148 4148
 						unset($dataNflags);
4149 4149
 						// sleep 500 miliseconds; AS some sERVERs seem not to be capable of the load this is
4150 4150
 						// inflicting in them. they "reply" with an unspecific IMAP Error
4151
-						time_nanosleep(0,500000);
4152
-						$c=0;
4151
+						time_nanosleep(0, 500000);
4152
+						$c = 0;
4153 4153
 					}
4154 4154
 				}
4155 4155
 				if (isset($dataNflags))
@@ -4159,7 +4159,7 @@  discard block
 block discarded – undo
4159 4159
 					$foldername = $target->getMailbox($_foldername);
4160 4160
 					// make sure the target folder is open and ready
4161 4161
 					$target->openMailbox($foldername);
4162
-					$ret = $target->append($foldername,$dataNflags);
4162
+					$ret = $target->append($foldername, $dataNflags);
4163 4163
 					$retUid->add($ret);
4164 4164
 					unset($dataNflags);
4165 4165
 				}
@@ -4170,7 +4170,7 @@  discard block
 block discarded – undo
4170 4170
 				{
4171 4171
 					$remember = $this->icServer;
4172 4172
 					$this->icServer = $source;
4173
-					$this->deleteMessages($_messageUID, $sourceFolder, $_forceDeleteMethod='remove_immediately');
4173
+					$this->deleteMessages($_messageUID, $sourceFolder, $_forceDeleteMethod = 'remove_immediately');
4174 4174
 					$this->icServer = $remember;
4175 4175
 				}
4176 4176
 			}
@@ -4179,7 +4179,7 @@  discard block
 block discarded – undo
4179 4179
 		{
4180 4180
 			try
4181 4181
 			{
4182
-				$retUid = $source->copy($sourceFolder, $_foldername, array('ids'=>$uidsToMove,'move'=>$deleteAfterMove));
4182
+				$retUid = $source->copy($sourceFolder, $_foldername, array('ids'=>$uidsToMove, 'move'=>$deleteAfterMove));
4183 4183
 			}
4184 4184
 			catch (exception $e)
4185 4185
 			{
@@ -4199,19 +4199,19 @@  discard block
 block discarded – undo
4199 4199
 	 * @param string $format ='' if none is passed, use user prefs
4200 4200
 	 * @return string returns the date as it is parseable by strtotime, or current timestamp if everything fails
4201 4201
 	 */
4202
-	static function _strtotime($_date='', $format='', $convert2usertime=false)
4202
+	static function _strtotime($_date = '', $format = '', $convert2usertime = false)
4203 4203
 	{
4204 4204
 		try {
4205
-			$date = new DateTime($_date);	// parse date & time including timezone (throws exception, if not parsable)
4206
-			if ($convert2usertime) $date->setUser();	// convert to user-time
4205
+			$date = new DateTime($_date); // parse date & time including timezone (throws exception, if not parsable)
4206
+			if ($convert2usertime) $date->setUser(); // convert to user-time
4207 4207
 			$date2return = $date->format($format);
4208 4208
 		}
4209
-		catch(\Exception $e)
4209
+		catch (\Exception $e)
4210 4210
 		{
4211
-			unset($e);	// not used
4211
+			unset($e); // not used
4212 4212
 
4213 4213
 			// remove last space-separated part and retry
4214
-			$parts = explode(' ',$_date);
4214
+			$parts = explode(' ', $_date);
4215 4215
 			if (count($parts) > 1)
4216 4216
 			{
4217 4217
 				array_pop($parts);
@@ -4232,12 +4232,12 @@  discard block
 block discarded – undo
4232 4232
 	 * @param mixed $_charset false or string -> Target charset, if false Mail displayCharset will be used
4233 4233
 	 * @return string
4234 4234
 	 */
4235
-	static function htmlentities($_string, $_charset=false)
4235
+	static function htmlentities($_string, $_charset = false)
4236 4236
 	{
4237 4237
 		//setting the charset (if not given)
4238
-		if ($_charset===false) $_charset = self::$displayCharset;
4238
+		if ($_charset === false) $_charset = self::$displayCharset;
4239 4239
 		$string = @htmlentities($_string, ENT_QUOTES, $_charset, false);
4240
-		if (empty($string) && !empty($_string)) $string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
4240
+		if (empty($string) && !empty($_string)) $string = @htmlentities(Translation::convert($_string, Translation::detect_encoding($_string), $_charset), ENT_QUOTES|ENT_IGNORE, $_charset, false);
4241 4241
 		return $string;
4242 4242
 	}
4243 4243
 
@@ -4254,21 +4254,21 @@  discard block
 block discarded – undo
4254 4254
 		//$_html = str_replace("\t",' ',$_html);
4255 4255
 		//error_log(__METHOD__.__LINE__.':'.$_html);
4256 4256
 		//repair doubleencoded ampersands, and some stuff htmLawed stumbles upon with balancing switched on
4257
-		$_html = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>','</td></font>','<br><td>','<tr></tr>','<o:p></o:p>','<o:p>','</o:p>'),
4258
-							 array('&amp;',    '<BR>',           '<BR>',             '<BR>',             '</font></td>','<td>',    '',         '',           '',  ''),$_html);
4257
+		$_html = str_replace(array('&amp;amp;', '<DIV><BR></DIV>', "<DIV>&nbsp;</DIV>", '<div>&nbsp;</div>', '</td></font>', '<br><td>', '<tr></tr>', '<o:p></o:p>', '<o:p>', '</o:p>'),
4258
+							 array('&amp;', '<BR>', '<BR>', '<BR>', '</font></td>', '<td>', '', '', '', ''), $_html);
4259 4259
 		//$_html = str_replace(array('&amp;amp;'),array('&amp;'),$_html);
4260
-		if (stripos($_html,'style')!==false) Mail\Html::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags
4261
-		if (stripos($_html,'head')!==false) Mail\Html::replaceTagsCompletley($_html,'head'); // Strip out stuff in head
4260
+		if (stripos($_html, 'style') !== false) Mail\Html::replaceTagsCompletley($_html, 'style'); // clean out empty or pagewide style definitions / left over tags
4261
+		if (stripos($_html, 'head') !== false) Mail\Html::replaceTagsCompletley($_html, 'head'); // Strip out stuff in head
4262 4262
 		//if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false) Mail\Html::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false); // Strip out stuff in ifs
4263 4263
 		//if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false) Mail\Html::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false); // Strip out stuff in ifs
4264 4264
 		//error_log(__METHOD__.' ('.__LINE__.') '.$_html);
4265 4265
 
4266 4266
 		if (get_magic_quotes_gpc() === 1) $_html = stripslashes($_html);
4267 4267
 		// Strip out doctype in head, as htmlLawed cannot handle it TODO: Consider extracting it and adding it afterwards
4268
-		if (stripos($_html,'!doctype')!==false) Mail\Html::replaceTagsCompletley($_html,'!doctype');
4269
-		if (stripos($_html,'?xml:namespace')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
4270
-		if (stripos($_html,'?xml version')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false);
4271
-		if (strpos($_html,'!CURSOR')!==false) Mail\Html::replaceTagsCompletley($_html,'!CURSOR');
4268
+		if (stripos($_html, '!doctype') !== false) Mail\Html::replaceTagsCompletley($_html, '!doctype');
4269
+		if (stripos($_html, '?xml:namespace') !== false) Mail\Html::replaceTagsCompletley($_html, '\?xml:namespace', '/>', false);
4270
+		if (stripos($_html, '?xml version') !== false) Mail\Html::replaceTagsCompletley($_html, '\?xml version', '\?>', false);
4271
+		if (strpos($_html, '!CURSOR') !== false) Mail\Html::replaceTagsCompletley($_html, '!CURSOR');
4272 4272
 		// htmLawed filter only the 'body'
4273 4273
 		//preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $_html, $matches);
4274 4274
 		//if ($matches[2])
@@ -4279,16 +4279,16 @@  discard block
 block discarded – undo
4279 4279
 		// purify got switched to htmLawed
4280 4280
 		// some testcode to test purifying / htmlawed
4281 4281
 		//$_html = "<BLOCKQUOTE>hi <div> there </div> kram <br> </blockquote>".$_html;
4282
-		$_html = Html\HtmLawed::purify($_html,self::$htmLawed_config,array(),true);
4282
+		$_html = Html\HtmLawed::purify($_html, self::$htmLawed_config, array(), true);
4283 4283
 		//if ($hasOther) $_html = $matches[1]. $_html. $matches[3];
4284 4284
 		// clean out comments , should not be needed as purify should do the job.
4285 4285
 		$search = array(
4286
-			'@url\(http:\/\/[^\)].*?\)@si',  // url calls e.g. in style definitions
4287
-			'@<!--[\s\S]*?[ \t\n\r]*-->@',         // Strip multi-line comments including CDATA
4286
+			'@url\(http:\/\/[^\)].*?\)@si', // url calls e.g. in style definitions
4287
+			'@<!--[\s\S]*?[ \t\n\r]*-->@', // Strip multi-line comments including CDATA
4288 4288
 		);
4289
-		$_html = preg_replace($search,"",$_html);
4289
+		$_html = preg_replace($search, "", $_html);
4290 4290
 		// remove non printable chars
4291
-		$_html = preg_replace('/([\000-\011])/','',$_html);
4291
+		$_html = preg_replace('/([\000-\011])/', '', $_html);
4292 4292
 		//error_log(__METHOD__.':'.__LINE__.':'.$_html);
4293 4293
 	}
4294 4294
 
@@ -4305,12 +4305,12 @@  discard block
 block discarded – undo
4305 4305
 	function getMimePartCharset($_mimePartObject)
4306 4306
 	{
4307 4307
 		//$charSet = 'iso-8859-1';//self::$displayCharset; //'iso-8859-1'; // self::displayCharset seems to be asmarter fallback than iso-8859-1
4308
-		$CharsetFound=false;
4308
+		$CharsetFound = false;
4309 4309
 		//echo "#".$_mimePartObject->encoding.'#<br>';
4310
-		if(is_array($_mimePartObject->parameters)) {
4311
-			if(isset($_mimePartObject->parameters['CHARSET'])) {
4310
+		if (is_array($_mimePartObject->parameters)) {
4311
+			if (isset($_mimePartObject->parameters['CHARSET'])) {
4312 4312
 				$charSet = $_mimePartObject->parameters['CHARSET'];
4313
-				$CharsetFound=true;
4313
+				$CharsetFound = true;
4314 4314
 			}
4315 4315
 		}
4316 4316
 		// this one is dirty, but until I find something that does the trick of detecting the encoding, ....
@@ -4329,7 +4329,7 @@  discard block
 block discarded – undo
4329 4329
 	function decodeMimePart($_mimeMessage, $_encoding, $_charset = '')
4330 4330
 	{
4331 4331
 		// decode the part
4332
-		if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
4332
+		if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage, true));
4333 4333
 		switch (strtoupper($_encoding))
4334 4334
 		{
4335 4335
 			case 'BASE64':
@@ -4369,10 +4369,10 @@  discard block
 block discarded – undo
4369 4369
 		// sometimes there are 3 parts, when there is an ics/ical attached/included-> we want to show that
4370 4370
 		// as attachment AND as abstracted ical information (we use our notification style here).
4371 4371
 		$partText = $partCalendar = $partHTML = null;
4372
-		if (self::$debug) _debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
4372
+		if (self::$debug) _debug_array(array("METHOD"=>__METHOD__, "LINE"=>__LINE__, "STRUCTURE"=>$_structure));
4373 4373
 		//error_log(__METHOD__.' ('.__LINE__.') ');
4374 4374
 		$ignore_first_part = true;
4375
-		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4375
+		foreach ($_structure->contentTypeMap() as $mime_id => $mime_type)
4376 4376
 		{
4377 4377
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type"." ignoreFirstPart:".$ignore_first_part);
4378 4378
 			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
@@ -4380,15 +4380,15 @@  discard block
 block discarded – undo
4380 4380
 			if ($ignore_first_part)
4381 4381
 			{
4382 4382
 				$ignore_first_part = false;
4383
-				continue;	// ignore multipart/alternative itself
4383
+				continue; // ignore multipart/alternative itself
4384 4384
 			}
4385 4385
 
4386 4386
 			$mimePart = $_structure->getPart($mime_id);
4387 4387
 
4388
-			switch($mimePart->getPrimaryType())
4388
+			switch ($mimePart->getPrimaryType())
4389 4389
 			{
4390 4390
 				case 'text':
4391
-					switch($mimePart->getSubType())
4391
+					switch ($mimePart->getSubType())
4392 4392
 					{
4393 4393
 						case 'plain':
4394 4394
 							if ($mimePart->getBytes() > 0) $partText = $mimePart;
@@ -4401,7 +4401,7 @@  discard block
 block discarded – undo
4401 4401
 					break;
4402 4402
 
4403 4403
 				case 'multipart':
4404
-					switch($mimePart->getSubType())
4404
+					switch ($mimePart->getSubType())
4405 4405
 					{
4406 4406
 						case 'related':
4407 4407
 						case 'mixed':
@@ -4423,13 +4423,13 @@  discard block
 block discarded – undo
4423 4423
 			}
4424 4424
 		}
4425 4425
 
4426
-		switch($_htmlMode)
4426
+		switch ($_htmlMode)
4427 4427
 		{
4428 4428
 			case 'html_only':
4429 4429
 			case 'always_display':
4430 4430
 				if ($partHTML)
4431 4431
 				{
4432
-					switch($partHTML->getSubType())
4432
+					switch ($partHTML->getSubType())
4433 4433
 					{
4434 4434
 						case 'related':
4435 4435
 							return $this->getMultipartRelated($_uid, $partHTML, $_htmlMode, $_preserveSeen);
@@ -4441,7 +4441,7 @@  discard block
 block discarded – undo
4441 4441
 							return $this->getTextPart($_uid, $partHTML, $_htmlMode, $_preserveSeen);
4442 4442
 					}
4443 4443
 				}
4444
-				elseif ($partText && $_htmlMode=='always_display')
4444
+				elseif ($partText && $_htmlMode == 'always_display')
4445 4445
 				{
4446 4446
 					return $this->getTextPart($_uid, $partText, $_htmlMode, $_preserveSeen);
4447 4447
 				}
@@ -4487,7 +4487,7 @@  discard block
 block discarded – undo
4487 4487
 	 * @param array	&$skipParts - passed by reference to have control/knowledge which parts are already fetched
4488 4488
 	 * @return array containing the desired part
4489 4489
 	 */
4490
-	function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts=array())
4490
+	function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts = array())
4491 4491
 	{
4492 4492
 		if (self::$debug) echo __METHOD__."$_uid, $_htmlMode<br>";
4493 4493
 		$bodyPart = array();
@@ -4496,7 +4496,7 @@  discard block
 block discarded – undo
4496 4496
 		$ignore_first_part = true;
4497 4497
 		//$skipParts = array();
4498 4498
 		//error_log(__METHOD__.__LINE__.array2string($_structure->contentTypeMap()));
4499
-		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4499
+		foreach ($_structure->contentTypeMap() as $mime_id => $mime_type)
4500 4500
 		{
4501 4501
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type");
4502 4502
 			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
@@ -4504,9 +4504,9 @@  discard block
 block discarded – undo
4504 4504
 			{
4505 4505
 				$ignore_first_part = false;
4506 4506
 				//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") SKIPPED FirstPart $mime_id: $mime_type");
4507
-				continue;	// ignore multipart/mixed itself
4507
+				continue; // ignore multipart/mixed itself
4508 4508
 			}
4509
-			if (array_key_exists($mime_id,$skipParts))
4509
+			if (array_key_exists($mime_id, $skipParts))
4510 4510
 			{
4511 4511
 				//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") SKIPPED $mime_id: $mime_type");
4512 4512
 				continue;
@@ -4514,11 +4514,11 @@  discard block
 block discarded – undo
4514 4514
 
4515 4515
 			$part = $_structure->getPart($mime_id);
4516 4516
 
4517
-			switch($part->getPrimaryType())
4517
+			switch ($part->getPrimaryType())
4518 4518
 			{
4519 4519
 				case 'multipart':
4520 4520
 					if ($part->getDisposition() == 'attachment') continue;
4521
-					switch($part->getSubType())
4521
+					switch ($part->getSubType())
4522 4522
 					{
4523 4523
 						case 'alternative':
4524 4524
 							return array($this->getMultipartAlternative($_uid, $part, $_htmlMode, $_preserveSeen));
@@ -4534,15 +4534,15 @@  discard block
 block discarded – undo
4534 4534
 					}
4535 4535
 					break;
4536 4536
 				case 'application':
4537
-					switch($part->getSubType())
4537
+					switch ($part->getSubType())
4538 4538
 					{
4539 4539
 						case 'pgp-encrypted':
4540
-							if (($part = $_structure->getPart($mime_id+1)) &&
4540
+							if (($part = $_structure->getPart($mime_id + 1)) &&
4541 4541
 								$part->getType() == 'application/octet-stream')
4542 4542
 							{
4543 4543
 								$this->fetchPartContents($_uid, $part);
4544
-								$skipParts[$mime_id]=$mime_type;
4545
-								$skipParts[$mime_id+1]=$part->getType();
4544
+								$skipParts[$mime_id] = $mime_type;
4545
+								$skipParts[$mime_id + 1] = $part->getType();
4546 4546
 								$bodyPart[] = array(
4547 4547
 									'body'		=> $part->getContents(array(
4548 4548
 										'stream' => false,
@@ -4556,15 +4556,15 @@  discard block
 block discarded – undo
4556 4556
 					break;
4557 4557
 
4558 4558
 				case 'text':
4559
-					switch($part->getSubType())
4559
+					switch ($part->getSubType())
4560 4560
 					{
4561 4561
 						case 'plain':
4562 4562
 						case 'html':
4563 4563
 						case 'calendar': // inline ics/ical files
4564
-							if($part->getDisposition() != 'attachment')
4564
+							if ($part->getDisposition() != 'attachment')
4565 4565
 							{
4566 4566
 								$bodyPart[] = $this->getTextPart($_uid, $part, $_htmlMode, $_preserveSeen);
4567
-								$skipParts[$mime_id]=$mime_type;
4567
+								$skipParts[$mime_id] = $mime_type;
4568 4568
 							}
4569 4569
 							//error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$part->type."/".$part->subType.' -> BodyPart:'.array2string($bodyPart[count($bodyPart)-1]));
4570 4570
 							break;
@@ -4573,16 +4573,16 @@  discard block
 block discarded – undo
4573 4573
 
4574 4574
 				case 'message':
4575 4575
 					//skip attachments
4576
-					if($part->getSubType() == 'delivery-status' && $part->getDisposition() != 'attachment')
4576
+					if ($part->getSubType() == 'delivery-status' && $part->getDisposition() != 'attachment')
4577 4577
 					{
4578 4578
 						$bodyPart[] = $this->getTextPart($_uid, $part, $_htmlMode, $_preserveSeen);
4579
-						$skipParts[$mime_id]=$mime_type;
4579
+						$skipParts[$mime_id] = $mime_type;
4580 4580
 					}
4581 4581
 					// do not descend into attached Messages
4582
-					if($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment')
4582
+					if ($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment')
4583 4583
 					{
4584 4584
 						$skipParts[$mime_id.'.0'] = $mime_type;
4585
-						foreach($part->contentTypeMap() as $sub_id => $sub_type){ $skipParts[$sub_id] = $sub_type;}
4585
+						foreach ($part->contentTypeMap() as $sub_id => $sub_type) { $skipParts[$sub_id] = $sub_type; }
4586 4586
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$_uid.' Part:'.$mime_id.':'.array2string($skipParts));
4587 4587
 						//break 2;
4588 4588
 					}
@@ -4623,13 +4623,13 @@  discard block
 block discarded – undo
4623 4623
 	 * @param boolean $_tryDecodingServerside = true; wether to try to fetch Data with BINARY instead of BODY
4624 4624
 	 * @return string|resource
4625 4625
 	 */
4626
-	function getBodyPart($_uid, $_partID=null, $_folder=null, $_preserveSeen=false, $_stream=false, &$_encoding=null, $_tryDecodingServerside=true)
4626
+	function getBodyPart($_uid, $_partID = null, $_folder = null, $_preserveSeen = false, $_stream = false, &$_encoding = null, $_tryDecodingServerside = true)
4627 4627
 	{
4628
-		if (self::$debug) error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
4628
+		if (self::$debug) error_log(__METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
4629 4629
 
4630 4630
 		if (empty($_folder))
4631 4631
 		{
4632
-			$_folder = (isset($this->sessionData['mailbox'])&&$this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
4632
+			$_folder = (isset($this->sessionData['mailbox']) && $this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
4633 4633
 		}
4634 4634
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_folder).'/'.$this->icServer->getCurrentMailbox().'/'. $this->sessionData['mailbox']);
4635 4635
 		// querying contents of body part
@@ -4640,11 +4640,11 @@  discard block
 block discarded – undo
4640 4640
 		$fquery = new Horde_Imap_Client_Fetch_Query();
4641 4641
 		$fetchParams = array(
4642 4642
 			'peek' => $_preserveSeen,
4643
-			'decode' => true,	// try decode on server, does NOT neccessary work
4643
+			'decode' => true, // try decode on server, does NOT neccessary work
4644 4644
 		);
4645
-		if ($_tryDecodingServerside===false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
4645
+		if ($_tryDecodingServerside === false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
4646 4646
 		{
4647
-			$_tryDecodingServerside=false;
4647
+			$_tryDecodingServerside = false;
4648 4648
 			$fetchParams = array(
4649 4649
 				'peek' => $_preserveSeen,
4650 4650
 			);
@@ -4664,12 +4664,12 @@  discard block
 block discarded – undo
4664 4664
 		}
4665 4665
 		// if we get an empty result, server may have trouble fetching data with UID FETCH $_uid (BINARY.PEEK[$_partID])
4666 4666
 		// thus we trigger a second go with UID FETCH $_uid (BODY.PEEK[$_partID])
4667
-		if (empty($partToReturn)&&$_tryDecodingServerside===true)
4667
+		if (empty($partToReturn) && $_tryDecodingServerside === true)
4668 4668
 		{
4669 4669
 			error_log(__METHOD__.__LINE__.' failed to fetch bodyPart in  BINARY. Try BODY');
4670 4670
 			$partToReturn = $this->getBodyPart($_uid, $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, false);
4671 4671
 		}
4672
-		return ($partToReturn?$partToReturn:null);
4672
+		return ($partToReturn ? $partToReturn : null);
4673 4673
 	}
4674 4674
 
4675 4675
 	/**
@@ -4682,13 +4682,13 @@  discard block
 block discarded – undo
4682 4682
 	 * @param boolean $_stream = false true return a stream, false return string
4683 4683
 	 * @return array containing the desired text part, mimeType and charset
4684 4684
 	 */
4685
-	function getTextPart($_uid, Horde_Mime_Part $_structure, $_htmlMode='', $_preserveSeen=false, $_stream=false)
4685
+	function getTextPart($_uid, Horde_Mime_Part $_structure, $_htmlMode = '', $_preserveSeen = false, $_stream = false)
4686 4686
 	{
4687 4687
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_uid.':'.array2string($_structure).' '.function_backtrace());
4688 4688
 		$bodyPart = array();
4689
-		if (self::$debug) _debug_array(array($_structure,function_backtrace()));
4689
+		if (self::$debug) _debug_array(array($_structure, function_backtrace()));
4690 4690
 
4691
-		if($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text')))
4691
+		if ($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text')))
4692 4692
 		{
4693 4693
 			$bodyPart = array(
4694 4694
 				'error'		=> 1,
@@ -4734,10 +4734,10 @@  discard block
 block discarded – undo
4734 4734
 	 * @param string $_folder folder to work on
4735 4735
 	 * @return array containing the message body, mimeType and charset
4736 4736
 	 */
4737
-	function getMessageBody($_uid, $_htmlOptions='', $_partID=null, Horde_Mime_Part $_structure=null, $_preserveSeen = false, $_folder = '')
4737
+	function getMessageBody($_uid, $_htmlOptions = '', $_partID = null, Horde_Mime_Part $_structure = null, $_preserveSeen = false, $_folder = '')
4738 4738
 	{
4739 4739
 		if (self::$debug) echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
4740
-		if($_htmlOptions != '') {
4740
+		if ($_htmlOptions != '') {
4741 4741
 			$this->htmlOptions = $_htmlOptions;
4742 4742
 		}
4743 4743
 		if (empty($_folder))
@@ -4758,7 +4758,7 @@  discard block
 block discarded – undo
4758 4758
 			return array(
4759 4759
 				array(
4760 4760
 					'error'		=> 1,
4761
-					'body'		=> 'Error: Could not fetch structure on mail:'.$_uid." as $_htmlOptions". 'for Mailprofile'.$this->icServer->ImapServerId.' User:'.$GLOBALS['egw_info']['user']['account_lid'],
4761
+					'body'		=> 'Error: Could not fetch structure on mail:'.$_uid." as $_htmlOptions".'for Mailprofile'.$this->icServer->ImapServerId.' User:'.$GLOBALS['egw_info']['user']['account_lid'],
4762 4762
 					'mimeType'	=> 'text/plain',
4763 4763
 					'charSet'	=> self::$displayCharset,
4764 4764
 				)
@@ -4771,7 +4771,7 @@  discard block
 block discarded – undo
4771 4771
 			//_debug_array($_structure->getMimeId()); exit;
4772 4772
 		}
4773 4773
 
4774
-		switch($_structure->getPrimaryType())
4774
+		switch ($_structure->getPrimaryType())
4775 4775
 		{
4776 4776
 			case 'application':
4777 4777
 				return array(
@@ -4783,7 +4783,7 @@  discard block
 block discarded – undo
4783 4783
 				);
4784 4784
 
4785 4785
 			case 'multipart':
4786
-				switch($_structure->getSubType())
4786
+				switch ($_structure->getSubType())
4787 4787
 				{
4788 4788
 					case 'alternative':
4789 4789
 						$bodyParts = array($this->getMultipartAlternative($_uid, $_structure, $this->htmlOptions, $_preserveSeen));
@@ -4817,7 +4817,7 @@  discard block
 block discarded – undo
4817 4817
 				$bodyPart = array();
4818 4818
 				if ($_structure->getDisposition() != 'attachment')
4819 4819
 				{
4820
-					switch($_structure->getSubType())
4820
+					switch ($_structure->getSubType())
4821 4821
 					{
4822 4822
 						case 'calendar':
4823 4823
 							// this is handeled in getTextPart
@@ -4833,11 +4833,11 @@  discard block
 block discarded – undo
4833 4833
 
4834 4834
 			case 'attachment':
4835 4835
 			case 'message':
4836
-				switch($_structure->getSubType())
4836
+				switch ($_structure->getSubType())
4837 4837
 				{
4838 4838
 					case 'rfc822':
4839 4839
 						$newStructure = $_structure->getParts();
4840
-						if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
4840
+						if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]); }
4841 4841
 						return self::normalizeBodyParts($this->getMessageBody($_uid, $_htmlOptions, $newStructure[0]->getMimeId(), $newStructure[0], $_preserveSeen, $_folder));
4842 4842
 				}
4843 4843
 				break;
@@ -4865,11 +4865,11 @@  discard block
 block discarded – undo
4865 4865
 	{
4866 4866
 		if (is_array($_bodyParts))
4867 4867
 		{
4868
-			foreach($_bodyParts as $singleBodyPart)
4868
+			foreach ($_bodyParts as $singleBodyPart)
4869 4869
 			{
4870 4870
 				if (!isset($singleBodyPart['body'])) {
4871 4871
 					$buff = self::normalizeBodyParts($singleBodyPart);
4872
-					foreach ((array)$buff as $val) { $body2return[] = $val;}
4872
+					foreach ((array)$buff as $val) { $body2return[] = $val; }
4873 4873
 					continue;
4874 4874
 				}
4875 4875
 				$body2return[] = $singleBodyPart;
@@ -4890,14 +4890,14 @@  discard block
 block discarded – undo
4890 4890
 	 * @param boolean $useTidy  switch to use tidy
4891 4891
 	 * @return string a preformatted string with the mails converted to text
4892 4892
 	 */
4893
-	static function &getdisplayableBody(&$mailClass, $bodyParts, $preserveHTML = false,  $useTidy = true)
4893
+	static function &getdisplayableBody(&$mailClass, $bodyParts, $preserveHTML = false, $useTidy = true)
4894 4894
 	{
4895
-		$message='';
4896
-		for($i=0; $i<count($bodyParts); $i++)
4895
+		$message = '';
4896
+		for ($i = 0; $i < count($bodyParts); $i++)
4897 4897
 		{
4898 4898
 			if (!isset($bodyParts[$i]['body'])) {
4899 4899
 				$bodyParts[$i]['body'] = self::getdisplayableBody($mailClass, $bodyParts[$i], $preserveHTML, $useTidy);
4900
-				$message .= empty($bodyParts[$i]['body'])?'':$bodyParts[$i]['body'];
4900
+				$message .= empty($bodyParts[$i]['body']) ? '' : $bodyParts[$i]['body'];
4901 4901
 				continue;
4902 4902
 			}
4903 4903
 			if (isset($bodyParts[$i]['error'])) continue;
@@ -4922,32 +4922,32 @@  discard block
 block discarded – undo
4922 4922
 				'(R)',
4923 4923
 			);
4924 4924
 
4925
-			if(($bodyParts[$i]['mimeType'] == 'text/html' || $bodyParts[$i]['mimeType'] == 'text/plain') &&
4925
+			if (($bodyParts[$i]['mimeType'] == 'text/html' || $bodyParts[$i]['mimeType'] == 'text/plain') &&
4926 4926
 				strtoupper($bodyParts[$i]['charSet']) != 'UTF-8')
4927 4927
 			{
4928
-				$bodyParts[$i]['body'] = preg_replace($sar,$rar,$bodyParts[$i]['body']);
4928
+				$bodyParts[$i]['body'] = preg_replace($sar, $rar, $bodyParts[$i]['body']);
4929 4929
 			}
4930 4930
 
4931
-			if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
4931
+			if ($bodyParts[$i]['charSet'] === false) $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
4932 4932
 			// add line breaks to $bodyParts
4933 4933
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
4934
-			$newBody  = Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
4934
+			$newBody = Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
4935 4935
 			//error_log(__METHOD__.' ('.__LINE__.') '.' MimeType:'.$bodyParts[$i]['mimeType'].'->'.$newBody);
4936 4936
 			$mailClass->activeMimeType = 'text/plain';
4937 4937
 			if ($bodyParts[$i]['mimeType'] == 'text/html') {
4938 4938
 				$mailClass->activeMimeType = $bodyParts[$i]['mimeType'];
4939 4939
 				if (!$preserveHTML)
4940 4940
 				{
4941
-					$alreadyHtmlLawed=false;
4941
+					$alreadyHtmlLawed = false;
4942 4942
 					// as Translation::convert reduces \r\n to \n and purifier eats \n -> peplace it with a single space
4943
-					$newBody = str_replace("\n"," ",$newBody);
4943
+					$newBody = str_replace("\n", " ", $newBody);
4944 4944
 					// convert HTML to text, as we dont want HTML in infologs
4945 4945
 					if ($useTidy && extension_loaded('tidy'))
4946 4946
 					{
4947 4947
 						$tidy = new tidy();
4948
-						$cleaned = $tidy->repairString($newBody, self::$tidy_config,'utf8');
4948
+						$cleaned = $tidy->repairString($newBody, self::$tidy_config, 'utf8');
4949 4949
 						// Found errors. Strip it all so there's some output
4950
-						if($tidy->getStatus() == 2)
4950
+						if ($tidy->getStatus() == 2)
4951 4951
 						{
4952 4952
 							error_log(__METHOD__.' ('.__LINE__.') '.' ->'.$tidy->errorBuffer);
4953 4953
 						}
@@ -4958,7 +4958,7 @@  discard block
 block discarded – undo
4958 4958
 						if (!$preserveHTML)
4959 4959
 						{
4960 4960
 							// filter only the 'body', as we only want that part, if we throw away the html
4961
-							preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
4961
+							preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches = array());
4962 4962
 							if ($matches[2])
4963 4963
 							{
4964 4964
 								$hasOther = true;
@@ -4969,7 +4969,7 @@  discard block
 block discarded – undo
4969 4969
 					else
4970 4970
 					{
4971 4971
 						// htmLawed filter only the 'body'
4972
-						preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches=array());
4972
+						preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $newBody, $matches = array());
4973 4973
 						if ($matches[2])
4974 4974
 						{
4975 4975
 							$hasOther = true;
@@ -4978,17 +4978,17 @@  discard block
 block discarded – undo
4978 4978
 						$htmLawed = new Html\HtmLawed();
4979 4979
 						// the next line should not be needed, but produces better results on HTML 2 Text conversion,
4980 4980
 						// as we switched off HTMLaweds tidy functionality
4981
-						$newBody = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<BR>','<BR>','<BR>'),$newBody);
4982
-						$newBody = $htmLawed->run($newBody,self::$htmLawed_config);
4983
-						if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3];
4984
-						$alreadyHtmlLawed=true;
4981
+						$newBody = str_replace(array('&amp;amp;', '<DIV><BR></DIV>', "<DIV>&nbsp;</DIV>", '<div>&nbsp;</div>'), array('&amp;', '<BR>', '<BR>', '<BR>'), $newBody);
4982
+						$newBody = $htmLawed->run($newBody, self::$htmLawed_config);
4983
+						if ($hasOther && $preserveHTML) $newBody = $matches[1].$newBody.$matches[3];
4984
+						$alreadyHtmlLawed = true;
4985 4985
 					}
4986 4986
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after purify:'.$newBody);
4987
-					if ($preserveHTML==false) $newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true);
4987
+					if ($preserveHTML == false) $newBody = Mail\Html::convertHTMLToText($newBody, self::$displayCharset, true, true);
4988 4988
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after convertHTMLToText:'.$newBody);
4989
-					if ($preserveHTML==false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n
4989
+					if ($preserveHTML == false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n
4990 4990
 					/*if (!$alreadyHtmlLawed) */ $mailClass->getCleanHTML($newBody); // remove stuff we regard as unwanted
4991
-					if ($preserveHTML==false) $newBody = str_replace("<br />","\r\n",$newBody);
4991
+					if ($preserveHTML == false) $newBody = str_replace("<br />", "\r\n", $newBody);
4992 4992
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after getClean:'.$newBody);
4993 4993
 				}
4994 4994
 				$message .= $newBody;
@@ -4997,9 +4997,9 @@  discard block
 block discarded – undo
4997 4997
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Body(after specialchars):'.$newBody);
4998 4998
 			//use Mail\Html::convertHTMLToText instead of strip_tags, (even message is plain text) as strip_tags eats away too much
4999 4999
 			//$newBody = strip_tags($newBody); //we need to fix broken tags (or just stuff like "<800 USD/p" )
5000
-			$newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,false,false);
5000
+			$newBody = Mail\Html::convertHTMLToText($newBody, self::$displayCharset, false, false);
5001 5001
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Body(after strip tags):'.$newBody);
5002
-			$newBody = htmlspecialchars_decode($newBody,ENT_QUOTES);
5002
+			$newBody = htmlspecialchars_decode($newBody, ENT_QUOTES);
5003 5003
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Body (after hmlspc_decode):'.$newBody);
5004 5004
 			$message .= $newBody;
5005 5005
 			//continue;
@@ -5007,27 +5007,27 @@  discard block
 block discarded – undo
5007 5007
 		return $message;
5008 5008
 	}
5009 5009
 
5010
-	static function wordwrap($str, $cols, $cut, $dontbreaklinesstartingwith=false)
5010
+	static function wordwrap($str, $cols, $cut, $dontbreaklinesstartingwith = false)
5011 5011
 	{
5012 5012
 		$lines = explode("\n", $str);
5013 5013
 		$newStr = '';
5014
-		foreach($lines as $line)
5014
+		foreach ($lines as $line)
5015 5015
 		{
5016 5016
 			// replace tabs by 8 space chars, or any tab only counts one char
5017 5017
 			//$line = str_replace("\t","        ",$line);
5018 5018
 			//$newStr .= wordwrap($line, $cols, $cut);
5019
-			$allowedLength = $cols-strlen($cut);
5019
+			$allowedLength = $cols - strlen($cut);
5020 5020
 			//dont try to break lines with links, chance is we mess up the text is way too big
5021
-			if (strlen($line) > $allowedLength && stripos($line,'href=')===false &&
5022
-				($dontbreaklinesstartingwith==false ||
5021
+			if (strlen($line) > $allowedLength && stripos($line, 'href=') === false &&
5022
+				($dontbreaklinesstartingwith == false ||
5023 5023
 				 ($dontbreaklinesstartingwith &&
5024
-				  strlen($dontbreaklinesstartingwith)>=1 &&
5025
-				  substr($line,0,strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
5024
+				  strlen($dontbreaklinesstartingwith) >= 1 &&
5025
+				  substr($line, 0, strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
5026 5026
 				 )
5027 5027
 				)
5028 5028
 			   )
5029 5029
 			{
5030
-				$s=explode(" ", $line);
5030
+				$s = explode(" ", $line);
5031 5031
 				$line = "";
5032 5032
 				$linecnt = 0;
5033 5033
 				foreach ($s as &$v) {
@@ -5035,22 +5035,22 @@  discard block
 block discarded – undo
5035 5035
 					// only break long words within the wordboundaries,
5036 5036
 					// but it may destroy links, so we check for href and dont do it if we find one
5037 5037
 					// we check for any html within the word, because we do not want to break html by accident
5038
-					if($cnt > $allowedLength && stripos($v,'href=')===false && stripos($v,'onclick=')===false && $cnt == strlen(html_entity_decode($v)))
5038
+					if ($cnt > $allowedLength && stripos($v, 'href=') === false && stripos($v, 'onclick=') === false && $cnt == strlen(html_entity_decode($v)))
5039 5039
 					{
5040
-						$v=wordwrap($v, $allowedLength, $cut, true);
5040
+						$v = wordwrap($v, $allowedLength, $cut, true);
5041 5041
 					}
5042 5042
 					// the rest should be broken at the start of the new word that exceeds the limit
5043
-					if ($linecnt+$cnt > $allowedLength) {
5044
-						$v=$cut.$v;
5043
+					if ($linecnt + $cnt > $allowedLength) {
5044
+						$v = $cut.$v;
5045 5045
 						#$linecnt = 0;
5046
-						$linecnt =strlen($v)-strlen($cut);
5046
+						$linecnt = strlen($v) - strlen($cut);
5047 5047
 					} else {
5048 5048
 						$linecnt += $cnt;
5049 5049
 					}
5050 5050
 					if (strlen($v)) $line .= (strlen($line) ? " " : "").$v;
5051 5051
 				}
5052 5052
 			}
5053
-			$newStr .= $line . "\n";
5053
+			$newStr .= $line."\n";
5054 5054
 		}
5055 5055
 		return $newStr;
5056 5056
 	}
@@ -5065,12 +5065,12 @@  discard block
 block discarded – undo
5065 5065
 	 * @param boolean $_useHeaderInsteadOfEnvelope - force getMessageHeader method to be used for fetching Envelope Information
5066 5066
 	 * @return array the message header
5067 5067
 	 */
5068
-	function getMessageEnvelope($_uid, $_partID = '',$decode=false, $_folder='', $_useHeaderInsteadOfEnvelope=false)
5068
+	function getMessageEnvelope($_uid, $_partID = '', $decode = false, $_folder = '', $_useHeaderInsteadOfEnvelope = false)
5069 5069
 	{
5070 5070
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder".function_backtrace());
5071
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5071
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5072 5072
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder");
5073
-		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false) {
5073
+		if ((empty($_partID) || $_partID == 'null') && $_useHeaderInsteadOfEnvelope === false) {
5074 5074
 			$uidsToFetch = new Horde_Imap_Client_Ids();
5075 5075
 			if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5076 5076
 			$uidsToFetch->add($_uid);
@@ -5083,7 +5083,7 @@  discard block
 block discarded – undo
5083 5083
 				'ids' => $uidsToFetch,
5084 5084
 			));
5085 5085
 			if (is_object($headersNew)) {
5086
-				foreach($headersNew as &$_headerObject) {
5086
+				foreach ($headersNew as &$_headerObject) {
5087 5087
 					$env = $_headerObject->getEnvelope();
5088 5088
 					//_debug_array($envFields->singleFields());
5089 5089
 					$singleFields = $envFields->singleFields();
@@ -5098,34 +5098,34 @@  discard block
 block discarded – undo
5098 5098
 							case 'bcc':
5099 5099
 							case 'sender':
5100 5100
 								//error_log(__METHOD__.' ('.__LINE__.') '.$v.'->'.array2string($env->$v->addresses));
5101
-								$envelope[$v]=$env->$v->addresses;
5101
+								$envelope[$v] = $env->$v->addresses;
5102 5102
 								$address = array();
5103 5103
 								if (!is_array($envelope[$v])) break;
5104 5104
 								foreach ($envelope[$v] as $k => $ad)
5105 5105
 								{
5106
-									if (stripos($ad,'@')===false)
5106
+									if (stripos($ad, '@') === false)
5107 5107
 									{
5108
-										$remember=$k;
5108
+										$remember = $k;
5109 5109
 									}
5110 5110
 									else
5111 5111
 									{
5112
-										$address[] = (!is_null($remember)?$envelope[$v][$remember].' ':'').$ad;
5113
-										$remember=null;
5112
+										$address[] = (!is_null($remember) ? $envelope[$v][$remember].' ' : '').$ad;
5113
+										$remember = null;
5114 5114
 									}
5115 5115
 								}
5116 5116
 								$envelope[$v] = $address;
5117 5117
 								break;
5118 5118
 							case 'date':
5119
-								$envelope[$v]=DateTime::to($env->$v);
5119
+								$envelope[$v] = DateTime::to($env->$v);
5120 5120
 								break;
5121 5121
 							default:
5122
-								$envelope[$v]=$env->$v;
5122
+								$envelope[$v] = $env->$v;
5123 5123
 						}
5124 5124
 					}
5125
-					$envelope['size']=$_headerObject->getSize();
5125
+					$envelope['size'] = $_headerObject->getSize();
5126 5126
 				}
5127 5127
 			}
5128
-			$envelope = array_change_key_case($envelope,CASE_UPPER);
5128
+			$envelope = array_change_key_case($envelope, CASE_UPPER);
5129 5129
 			//if ($decode) _debug_array($envelope);
5130 5130
 			//error_log(__METHOD__.' ('.__LINE__.') '.array2string($envelope));
5131 5131
 			if ($decode)
@@ -5133,19 +5133,19 @@  discard block
 block discarded – undo
5133 5133
 				foreach ($envelope as $key => $rvV)
5134 5134
 				{
5135 5135
 					//try idn conversion only on 'FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO'
5136
-					$envelope[$key]=self::decode_header($rvV,in_array($key,array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5136
+					$envelope[$key] = self::decode_header($rvV, in_array($key, array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5137 5137
 				}
5138 5138
 			}
5139 5139
 			return $envelope;
5140 5140
 		} else {
5141 5141
 
5142
-			$headers = $this->getMessageHeader($_uid, $_partID, true,true,$_folder);
5142
+			$headers = $this->getMessageHeader($_uid, $_partID, true, true, $_folder);
5143 5143
 
5144 5144
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.array2string($headers));
5145 5145
 			//_debug_array($headers);
5146 5146
 			$newData = array(
5147 5147
 				'DATE'		=> $headers['DATE'],
5148
-				'SUBJECT'	=> ($decode ? self::decode_header($headers['SUBJECT']):$headers['SUBJECT']),
5148
+				'SUBJECT'	=> ($decode ? self::decode_header($headers['SUBJECT']) : $headers['SUBJECT']),
5149 5149
 				'MESSAGE_ID'	=> $headers['MESSAGE-ID']
5150 5150
 			);
5151 5151
 			if (isset($headers['IN-REPLY-TO'])) $newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
@@ -5156,11 +5156,11 @@  discard block
 block discarded – undo
5156 5156
 			if (isset($headers['SIZE'])) $newData['SIZE'] = $headers['SIZE'];
5157 5157
 			//_debug_array($newData);
5158 5158
 			$recepientList = array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO');
5159
-			foreach($recepientList as $recepientType) {
5160
-				if(isset($headers[$recepientType])) {
5161
-					if ($decode) $headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
5159
+			foreach ($recepientList as $recepientType) {
5160
+				if (isset($headers[$recepientType])) {
5161
+					if ($decode) $headers[$recepientType] = self::decode_header($headers[$recepientType], true);
5162 5162
 					//error_log(__METHOD__.__LINE__." ".$recepientType."->".array2string($headers[$recepientType]));
5163
-					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress) {
5163
+					foreach (self::parseAddressList($headers[$recepientType]) as $singleAddress) {
5164 5164
 						$addressData = array(
5165 5165
 							'PERSONAL_NAME'		=> $singleAddress->personal ? $singleAddress->personal : 'NIL',
5166 5166
 							'AT_DOMAIN_LIST'	=> $singleAddress->adl ? $singleAddress->adl : 'NIL',
@@ -5168,15 +5168,15 @@  discard block
 block discarded – undo
5168 5168
 							'HOST_NAME'		=> $singleAddress->host ? $singleAddress->host : 'NIL',
5169 5169
 							'EMAIL'			=> $singleAddress->host ? $singleAddress->mailbox.'@'.$singleAddress->host : $singleAddress->mailbox,
5170 5170
 						);
5171
-						if($addressData['PERSONAL_NAME'] != 'NIL') {
5171
+						if ($addressData['PERSONAL_NAME'] != 'NIL') {
5172 5172
 							$addressData['RFC822_EMAIL'] = imap_rfc822_write_address($singleAddress->mailbox, $singleAddress->host, $singleAddress->personal);
5173 5173
 						} else {
5174 5174
 							$addressData['RFC822_EMAIL'] = 'NIL';
5175 5175
 						}
5176
-						$newData[$recepientType][] = ($addressData['RFC822_EMAIL']!='NIL'?$addressData['RFC822_EMAIL']:$addressData['EMAIL']);//$addressData;
5176
+						$newData[$recepientType][] = ($addressData['RFC822_EMAIL'] != 'NIL' ? $addressData['RFC822_EMAIL'] : $addressData['EMAIL']); //$addressData;
5177 5177
 					}
5178 5178
 				} else {
5179
-					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') {
5179
+					if ($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') {
5180 5180
 						$newData[$recepientType] = $newData['FROM'];
5181 5181
 					} else {
5182 5182
 						$newData[$recepientType] = array();
@@ -5198,10 +5198,10 @@  discard block
 block discarded – undo
5198 5198
 	 * @param string $_folder folder to work on
5199 5199
 	 * @return array|Horde_Mime_Headers message header as array or object
5200 5200
 	 */
5201
-	function getMessageHeader($_uid, $_partID = '',$decode=false, $preserveUnSeen=false, $_folder='')
5201
+	function getMessageHeader($_uid, $_partID = '', $decode = false, $preserveUnSeen = false, $_folder = '')
5202 5202
 	{
5203 5203
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$_uid.', '.$_partID.', '.$decode.', '.$preserveUnSeen.', '.$_folder);
5204
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5204
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5205 5205
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5206 5206
 		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5207 5207
 		$uidsToFetch->add($_uid);
@@ -5209,7 +5209,7 @@  discard block
 block discarded – undo
5209 5209
 		$fquery = new Horde_Imap_Client_Fetch_Query();
5210 5210
 		if ($_partID != '')
5211 5211
 		{
5212
-			$fquery->headerText(array('id'=>$_partID,'peek'=>$preserveUnSeen));
5212
+			$fquery->headerText(array('id'=>$_partID, 'peek'=>$preserveUnSeen));
5213 5213
 			$fquery->structure();
5214 5214
 		}
5215 5215
 		else
@@ -5222,18 +5222,18 @@  discard block
 block discarded – undo
5222 5222
 			'ids' => $uidsToFetch,
5223 5223
 		));
5224 5224
 		if (is_object($headersNew)) {
5225
-			foreach($headersNew as $_fetchObject)
5225
+			foreach ($headersNew as $_fetchObject)
5226 5226
 			{
5227
-				$headers = $_fetchObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
5227
+				$headers = $_fetchObject->getHeaderText(0, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
5228 5228
 				if ($_partID != '')
5229 5229
 				{
5230 5230
 					$mailStructureObject = $_fetchObject->getStructure();
5231 5231
 					foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
5232 5232
 					{
5233
-						if ($mime_id==$_partID)
5233
+						if ($mime_id == $_partID)
5234 5234
 						{
5235 5235
 							//error_log(__METHOD__.' ('.__LINE__.') '."$mime_id == $_partID".array2string($_headerObject->getHeaderText($mime_id,Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray()));
5236
-							$headers = $_fetchObject->getHeaderText($mime_id,Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
5236
+							$headers = $_fetchObject->getHeaderText($mime_id, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
5237 5237
 							break;
5238 5238
 						}
5239 5239
 					}
@@ -5246,15 +5246,15 @@  discard block
 block discarded – undo
5246 5246
 				if (is_object($headers)) $headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
5247 5247
 				return $headers;
5248 5248
 			}
5249
-			$retValue = is_object($headers) ? $headers->toArray():array();
5249
+			$retValue = is_object($headers) ? $headers->toArray() : array();
5250 5250
 			if ($size) $retValue['size'] = $size;
5251 5251
 		}
5252
-		$retValue = array_change_key_case($retValue,CASE_UPPER);
5252
+		$retValue = array_change_key_case($retValue, CASE_UPPER);
5253 5253
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue));
5254 5254
 		// if SUBJECT is an array, use thelast one, as we assume something with the unfolding for the subject did not work
5255 5255
 		if (is_array($retValue['SUBJECT']))
5256 5256
 		{
5257
-			$retValue['SUBJECT'] = $retValue['SUBJECT'][count($retValue['SUBJECT'])-1];
5257
+			$retValue['SUBJECT'] = $retValue['SUBJECT'][count($retValue['SUBJECT']) - 1];
5258 5258
 		}
5259 5259
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.array2string($decode ? self::decode_header($retValue,true):$retValue));
5260 5260
 		if ($decode)
@@ -5262,7 +5262,7 @@  discard block
 block discarded – undo
5262 5262
 			foreach ($retValue as $key => $rvV)
5263 5263
 			{
5264 5264
 				//try idn conversion only on 'FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO'
5265
-				$retValue[$key]=self::decode_header($rvV,in_array($key,array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5265
+				$retValue[$key] = self::decode_header($rvV, in_array($key, array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO')));
5266 5266
 			}
5267 5267
 		}
5268 5268
 		return $retValue;
@@ -5279,14 +5279,14 @@  discard block
 block discarded – undo
5279 5279
 	function getMessageRawHeader($_uid, $_partID = '', $_folder = '')
5280 5280
 	{
5281 5281
 		static $rawHeaders;
5282
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5282
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5283 5283
 		//error_log(__METHOD__.' ('.__LINE__.') '." Try Using Cache for raw Header $_uid, $_partID in Folder $_folder");
5284 5284
 
5285
-		if (is_null($rawHeaders)||!is_array($rawHeaders)) $rawHeaders = Cache::getCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
5286
-		if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5285
+		if (is_null($rawHeaders) || !is_array($rawHeaders)) $rawHeaders = Cache::getCache(Cache::INSTANCE, 'email', 'rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']), null, array(), 60 * 60 * 1);
5286
+		if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)]))
5287 5287
 		{
5288 5288
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Header $_uid, $_partID in Folder $_folder");
5289
-			return $rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)];
5289
+			return $rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)];
5290 5290
 		}
5291 5291
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5292 5292
 		$uid = $_uid;
@@ -5296,7 +5296,7 @@  discard block
 block discarded – undo
5296 5296
 		$fquery = new Horde_Imap_Client_Fetch_Query();
5297 5297
 		if ($_partID != '')
5298 5298
 		{
5299
-			$fquery->headerText(array('id'=>$_partID,'peek'=>true));
5299
+			$fquery->headerText(array('id'=>$_partID, 'peek'=>true));
5300 5300
 			$fquery->structure();
5301 5301
 		}
5302 5302
 		else
@@ -5307,14 +5307,14 @@  discard block
 block discarded – undo
5307 5307
 			'ids' => $uidsToFetch,
5308 5308
 		));
5309 5309
 		if (is_object($headersNew)) {
5310
-			foreach($headersNew as &$_headerObject) {
5310
+			foreach ($headersNew as &$_headerObject) {
5311 5311
 				$retValue = $_headerObject->getHeaderText();
5312 5312
 				if ($_partID != '')
5313 5313
 				{
5314 5314
 					$mailStructureObject = $_headerObject->getStructure();
5315 5315
 					foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
5316 5316
 					{
5317
-						if ($mime_id==$_partID)
5317
+						if ($mime_id == $_partID)
5318 5318
 						{
5319 5319
 							$retValue = $_headerObject->getHeaderText($mime_id);
5320 5320
 						}
@@ -5322,8 +5322,8 @@  discard block
 block discarded – undo
5322 5322
 				}
5323 5323
 			}
5324 5324
 		}
5325
-		$rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]=$retValue;
5326
-		Cache::setCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),$rawHeaders,60*60*1);
5325
+		$rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)] = $retValue;
5326
+		Cache::setCache(Cache::INSTANCE, 'email', 'rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']), $rawHeaders, 60 * 60 * 1);
5327 5327
 		return $retValue;
5328 5328
 	}
5329 5329
 
@@ -5336,25 +5336,25 @@  discard block
 block discarded – undo
5336 5336
 	{
5337 5337
 		$style = '';
5338 5338
 		if (empty($_bodyParts)) return "";
5339
-		foreach((array)$_bodyParts as $singleBodyPart) {
5339
+		foreach ((array)$_bodyParts as $singleBodyPart) {
5340 5340
 			if (!isset($singleBodyPart['body'])) {
5341 5341
 				$singleBodyPart['body'] = self::getStyles($singleBodyPart);
5342 5342
 				$style .= $singleBodyPart['body'];
5343 5343
 				continue;
5344 5344
 			}
5345 5345
 
5346
-			if ($singleBodyPart['charSet']===false) $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
5346
+			if ($singleBodyPart['charSet'] === false) $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
5347 5347
 			$singleBodyPart['body'] = Translation::convert(
5348 5348
 				$singleBodyPart['body'],
5349 5349
 				strtolower($singleBodyPart['charSet'])
5350 5350
 			);
5351 5351
 			$ct = 0;
5352
-			$newStyle=array();
5353
-			if (stripos($singleBodyPart['body'],'<style')!==false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
5354
-			if ($ct>0)
5352
+			$newStyle = array();
5353
+			if (stripos($singleBodyPart['body'], '<style') !== false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
5354
+			if ($ct > 0)
5355 5355
 			{
5356 5356
 				//error_log(__METHOD__.' ('.__LINE__.') '.'#'.$ct.'#'.array2string($newStyle));
5357
-				$style2buffer = implode('',$newStyle[0]);
5357
+				$style2buffer = implode('', $newStyle[0]);
5358 5358
 			}
5359 5359
 			if ($style2buffer && strtoupper(self::$displayCharset) == 'UTF-8')
5360 5360
 			{
@@ -5362,7 +5362,7 @@  discard block
 block discarded – undo
5362 5362
 				$test = json_encode($style2buffer);
5363 5363
 				//error_log(__METHOD__.' ('.__LINE__.') '.'#'.$test.'# ->'.strlen($style2buffer).' Error:'.json_last_error());
5364 5364
 				//if (json_last_error() != JSON_ERROR_NONE && strlen($style2buffer)>0)
5365
-				if ($test=="null" && strlen($style2buffer)>0)
5365
+				if ($test == "null" && strlen($style2buffer) > 0)
5366 5366
 				{
5367 5367
 					// this should not be needed, unless something fails with charset detection/ wrong charset passed
5368 5368
 					error_log(__METHOD__.' ('.__LINE__.') '.' Found Invalid sequence for utf-8 in CSS:'.$style2buffer.' Charset Reported:'.$singleBodyPart['charSet'].' Carset Detected:'.Translation::detect_encoding($style2buffer));
@@ -5373,19 +5373,19 @@  discard block
 block discarded – undo
5373 5373
 		}
5374 5374
 		// clean out comments and stuff
5375 5375
 		$search = array(
5376
-			'@url\(http:\/\/[^\)].*?\)@si',  // url calls e.g. in style definitions
5376
+			'@url\(http:\/\/[^\)].*?\)@si', // url calls e.g. in style definitions
5377 5377
 //			'@<!--[\s\S]*?[ \t\n\r]*-->@',   // Strip multi-line comments including CDATA
5378 5378
 //			'@<!--[\s\S]*?[ \t\n\r]*--@',    // Strip broken multi-line comments including CDATA
5379 5379
 		);
5380
-		$style = preg_replace($search,"",$style);
5380
+		$style = preg_replace($search, "", $style);
5381 5381
 
5382 5382
 		// CSS Security
5383 5383
 		// http://code.google.com/p/browsersec/wiki/Part1#Cascading_stylesheets
5384
-		$css = preg_replace('/(javascript|expression|-moz-binding)/i','',$style);
5385
-		if (stripos($css,'script')!==false) Mail\Html::replaceTagsCompletley($css,'script'); // Strip out script that may be included
5384
+		$css = preg_replace('/(javascript|expression|-moz-binding)/i', '', $style);
5385
+		if (stripos($css, 'script') !== false) Mail\Html::replaceTagsCompletley($css, 'script'); // Strip out script that may be included
5386 5386
 		// we need this, as styledefinitions are enclosed with curly brackets; and template stuff tries to replace everything between curly brackets that is having no horizontal whitespace
5387 5387
 		// as the comments as <!-- styledefinition --> in stylesheet are outdated, and ck-editor does not understand it, we remove it
5388
-		$css = str_replace(array(':','<!--','-->'),array(': ','',''),$css);
5388
+		$css = str_replace(array(':', '<!--', '-->'), array(': ', '', ''), $css);
5389 5389
 		//error_log(__METHOD__.' ('.__LINE__.') '.$css);
5390 5390
 		// TODO: we may have to strip urls and maybe comments and ifs
5391 5391
 		return $css;
@@ -5399,16 +5399,16 @@  discard block
 block discarded – undo
5399 5399
 	 * @param string $_folder folder to work on
5400 5400
 	 * @return string the message body
5401 5401
 	 */
5402
-	function getMessageRawBody($_uid, $_partID = '', $_folder='')
5402
+	function getMessageRawBody($_uid, $_partID = '', $_folder = '')
5403 5403
 	{
5404 5404
 		//TODO: caching einbauen static!
5405 5405
 		static $rawBody;
5406 5406
 		if (is_null($rawBody)) $rawBody = array();
5407
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5408
-		if (isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5407
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5408
+		if (isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)]))
5409 5409
 		{
5410 5410
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Body $_uid, $_partID in Folder $_folder");
5411
-			return $rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)];
5411
+			return $rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)];
5412 5412
 		}
5413 5413
 
5414 5414
 		$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -5421,13 +5421,13 @@  discard block
 block discarded – undo
5421 5421
 		if ($_partID != '')
5422 5422
 		{
5423 5423
 			$fquery->structure();
5424
-			$fquery->bodyPart($_partID,array('peek'=>true));
5424
+			$fquery->bodyPart($_partID, array('peek'=>true));
5425 5425
 		}
5426 5426
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5427 5427
 			'ids' => $uidsToFetch,
5428 5428
 		));
5429 5429
 		if (is_object($headersNew)) {
5430
-			foreach($headersNew as &$_headerObject) {
5430
+			foreach ($headersNew as &$_headerObject) {
5431 5431
 				$body = $_headerObject->getFullMsg();
5432 5432
 				if ($_partID != '')
5433 5433
 				{
@@ -5435,7 +5435,7 @@  discard block
 block discarded – undo
5435 5435
 					//_debug_array($mailStructureObject->contentTypeMap());
5436 5436
 					foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
5437 5437
 					{
5438
-						if ($mime_id==$_partID)
5438
+						if ($mime_id == $_partID)
5439 5439
 						{
5440 5440
 							$body = $_headerObject->getBodyPart($mime_id);
5441 5441
 						}
@@ -5444,7 +5444,7 @@  discard block
 block discarded – undo
5444 5444
 			}
5445 5445
 		}
5446 5446
 		//error_log(__METHOD__.' ('.__LINE__.') '."[$this->icServer->ImapServerId][$_folder][$_uid][".(empty($_partID)?'NIL':$_partID)."]");
5447
-		$rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)] = $body;
5447
+		$rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID) ? 'NIL' : $_partID)] = $body;
5448 5448
 		return $body;
5449 5449
 	}
5450 5450
 
@@ -5458,13 +5458,13 @@  discard block
 block discarded – undo
5458 5458
 	 * @param Horde_Imap_Client_Fetch_Query $fquery=null default query just structure
5459 5459
 	 * @return Horde_Mime_Part
5460 5460
 	 */
5461
-	function getStructure($_uid, $_partID=null, $_folder=null, $_preserveSeen=false)
5461
+	function getStructure($_uid, $_partID = null, $_folder = null, $_preserveSeen = false)
5462 5462
 	{
5463
-		if (self::$debug) error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
5463
+		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
5464 5464
 
5465 5465
 		if (empty($_folder))
5466 5466
 		{
5467
-			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5467
+			$_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5468 5468
 		}
5469 5469
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5470 5470
 		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
@@ -5482,7 +5482,7 @@  discard block
 block discarded – undo
5482 5482
 				'ids' => $uidsToFetch,
5483 5483
 			))->first();
5484 5484
 
5485
-			return is_object($mail)?$mail->getStructure():null;
5485
+			return is_object($mail) ? $mail->getStructure() : null;
5486 5486
 		}
5487 5487
 		catch (\Exception $e)
5488 5488
 		{
@@ -5505,14 +5505,14 @@  discard block
 block discarded – undo
5505 5505
 	 * @param string $_folder folder to work on
5506 5506
 	 * @return array  an array of information about the attachment: array of array(name, size, mimeType, partID, encoding)
5507 5507
 	 */
5508
-	function getMessageAttachments($_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folder='')
5508
+	function getMessageAttachments($_uid, $_partID = null, Horde_Mime_Part $_structure = null, $fetchEmbeddedImages = true, $fetchTextCalendar = false, $resolveTNEF = true, $_folder = '')
5509 5509
 	{
5510
-		if (self::$debug) error_log( __METHOD__.":$_uid, $_partID");
5511
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5510
+		if (self::$debug) error_log(__METHOD__.":$_uid, $_partID");
5511
+		if (empty($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5512 5512
 		$attachments = array();
5513 5513
 		if (!isset($_structure))
5514 5514
 		{
5515
-			$_structure = $this->getStructure($_uid, $_partID,$_folder,true);
5515
+			$_structure = $this->getStructure($_uid, $_partID, $_folder, true);
5516 5516
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.print_r($_structure->contentTypeMap(),true));
5517 5517
 		}
5518 5518
 		if (!$_structure || !$_structure->contentTypeMap()) return array();
@@ -5520,7 +5520,7 @@  discard block
 block discarded – undo
5520 5520
 		$skipParts = array();
5521 5521
 		$tnefParts = array();
5522 5522
 		$skip = 0;
5523
-		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
5523
+		foreach ($_structure->contentTypeMap() as $mime_id => $mime_type)
5524 5524
 		{
5525 5525
 			// skip multipart/encrypted incl. its two sub-parts, as we show 2. sub-part as body to be decrypted client-side
5526 5526
 			if ($mime_type == 'multipart/encrypted')
@@ -5528,7 +5528,7 @@  discard block
 block discarded – undo
5528 5528
 				$skip = 2;
5529 5529
 				continue;
5530 5530
 			}
5531
-			elseif($skip)
5531
+			elseif ($skip)
5532 5532
 			{
5533 5533
 				$skip--;
5534 5534
 				continue;
@@ -5542,10 +5542,10 @@  discard block
 block discarded – undo
5542 5542
 			$partPrimaryType = $part->getPrimaryType();
5543 5543
 			// we only want to retrieve the attachments of the current mail, not those of possible
5544 5544
 			// attached mails
5545
-			if ($mime_type=='message/rfc822' && $_partID!=$mime_id)
5545
+			if ($mime_type == 'message/rfc822' && $_partID != $mime_id)
5546 5546
 			{
5547 5547
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
5548
-				foreach($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
5548
+				foreach ($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type; }
5549 5549
 			}
5550 5550
 			if (empty($partDisposition) && $partPrimaryType != 'multipart' && $partPrimaryType != 'text')
5551 5551
 			{
@@ -5553,27 +5553,27 @@  discard block
 block discarded – undo
5553 5553
 				// attachment with no link to show the attachment inline.
5554 5554
 				// Considering this: we "list" everything that matches the above criteria
5555 5555
 				// as attachment in order to not loose/miss information on our data
5556
-				$partDisposition='attachment';
5556
+				$partDisposition = 'attachment';
5557 5557
 			}
5558 5558
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($skipParts));
5559
-			if (array_key_exists($mime_id,$skipParts)) continue;
5559
+			if (array_key_exists($mime_id, $skipParts)) continue;
5560 5560
 
5561 5561
 			if ($partDisposition == 'attachment' ||
5562
-				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId()=='') ||
5562
+				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId() == '') ||
5563 5563
 				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType != 'image' && $partPrimaryType != 'text' && $partPrimaryType != 'multipart') ||
5564
-				($mime_type=='image/tiff') || //always fetch. even if $fetchEmbeddedImages is false. as we cannot display tiffs
5564
+				($mime_type == 'image/tiff') || //always fetch. even if $fetchEmbeddedImages is false. as we cannot display tiffs
5565 5565
 				($fetchEmbeddedImages && ($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image') ||
5566 5566
 				($fetchTextCalendar && $partPrimaryType == 'text' && $part->getSubType() == 'calendar'))
5567 5567
 			{
5568 5568
 				// if type is message/rfc822 and _partID is given, and MimeID equals partID
5569 5569
 				// we attempt to fetch "ourselves"
5570
-				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message') continue;
5570
+				if ($_partID == $part->getMimeId() && $part->getPrimaryType() == 'message') continue;
5571 5571
 				$attachment = $part->getAllDispositionParameters();
5572 5572
 				$attachment['disposition'] = $part->getDisposition();
5573 5573
 				$attachment['mimeType'] = $mime_type;
5574 5574
 				$attachment['uid'] = $_uid;
5575 5575
 				$attachment['partID'] = $mime_id;
5576
-				if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
5576
+				if (!isset($attachment['name']) || empty($attachment['name'])) $attachment['name'] = $part->getName();
5577 5577
 				if ($fetchTextCalendar)
5578 5578
 				{
5579 5579
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part->getAllContentTypeParameters()));
@@ -5583,11 +5583,11 @@  discard block
 block discarded – undo
5583 5583
 				}
5584 5584
 				$attachment['size'] = $part->getBytes();
5585 5585
 				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5586
-				if (empty($attachment['name'])) $attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($mime_type);
5586
+				if (empty($attachment['name'])) $attachment['name'] = (isset($attachment['cid']) && !empty($attachment['cid']) ? $attachment['cid'] : lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($mime_type);
5587 5587
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($attachment));
5588 5588
 				//typical winmail.dat attachment is
5589 5589
 				//Array([size] => 1462762[filename] => winmail.dat[mimeType] => application/ms-tnef[uid] => 100[partID] => 2[name] => winmail.dat)
5590
-				if ($resolveTNEF && ($attachment['mimeType']=='application/ms-tnef' || !strcasecmp($attachment['name'],'winmail.dat')))
5590
+				if ($resolveTNEF && ($attachment['mimeType'] == 'application/ms-tnef' || !strcasecmp($attachment['name'], 'winmail.dat')))
5591 5591
 				{
5592 5592
 					$tnefParts[] = $attachment;
5593 5593
 				}
@@ -5602,31 +5602,31 @@  discard block
 block discarded – undo
5602 5602
 			//error_log(__METHOD__.__LINE__.array2string($tnefParts));
5603 5603
 			foreach ($tnefParts as $k => $tnp)
5604 5604
 			{
5605
-				$tnefResolved=false;
5606
-				$tnef_data = $this->getAttachment($tnp['uid'],$tnp['partID'],$k,false);
5605
+				$tnefResolved = false;
5606
+				$tnef_data = $this->getAttachment($tnp['uid'], $tnp['partID'], $k, false);
5607 5607
 				$myTnef = $this->tnef_decoder($tnef_data['attachment']);
5608 5608
 				//error_log(__METHOD__.__LINE__.array2string($myTnef->getParts()));
5609 5609
 				// Note: MimeId starts with 0, almost always, we cannot use that as winmail_id
5610 5610
 				// we need to build Something that meets the needs
5611 5611
 				if ($myTnef)
5612 5612
 				{
5613
-					foreach($myTnef->getParts() as $mime_id => $part)
5613
+					foreach ($myTnef->getParts() as $mime_id => $part)
5614 5614
 					{
5615
-						$tnefResolved=true;
5615
+						$tnefResolved = true;
5616 5616
 						$attachment = $part->getAllDispositionParameters();
5617 5617
 						$attachment['disposition'] = $part->getDisposition();
5618 5618
 						$attachment['mimeType'] = $part->getType();
5619 5619
 						$attachment['uid'] = $tnp['uid'];
5620 5620
 						$attachment['partID'] = $tnp['partID'];
5621 5621
 						$attachment['is_winmail'] = $tnp['uid'].'@'.$tnp['partID'].'@'.$mime_id;
5622
-						if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
5622
+						if (!isset($attachment['name']) || empty($attachment['name'])) $attachment['name'] = $part->getName();
5623 5623
 						$attachment['size'] = $part->getBytes();
5624 5624
 						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5625
-						if (empty($attachment['name'])) $attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
5625
+						if (empty($attachment['name'])) $attachment['name'] = (isset($attachment['cid']) && !empty($attachment['cid']) ? $attachment['cid'] : lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
5626 5626
 						$attachments[] = $attachment;
5627 5627
 					}
5628 5628
 				}
5629
-				if ($tnefResolved===false) $attachments[]=$tnp;
5629
+				if ($tnefResolved === false) $attachments[] = $tnp;
5630 5630
 			}
5631 5631
 		}
5632 5632
 		//error_log(__METHOD__.__LINE__.array2string($attachments));
@@ -5641,9 +5641,9 @@  discard block
 block discarded – undo
5641 5641
 	 * @return boolean|Horde_Mime_part Multipart/Mixed part decoded attachments |
5642 5642
 	 *	return false if there's no attachments or failure
5643 5643
 	 */
5644
-	public function tnef_decoder( $data )
5644
+	public function tnef_decoder($data)
5645 5645
 	{
5646
-		foreach(array('Horde_Compress', 'Horde_Icalendar', 'Horde_Mapi') as $class)
5646
+		foreach (array('Horde_Compress', 'Horde_Icalendar', 'Horde_Mapi') as $class)
5647 5647
 		{
5648 5648
 			if (!class_exists($class))
5649 5649
 			{
@@ -5675,7 +5675,7 @@  discard block
 block discarded – undo
5675 5675
 				$tmp_part->setContents($data['stream']);
5676 5676
 				$tmp_part->setDescription($data['name']);
5677 5677
 
5678
-				$type = $data['type'] . '/' . $data['subtype'];
5678
+				$type = $data['type'].'/'.$data['subtype'];
5679 5679
 				if (in_array($type, array('application/octet-stream', 'application/base64')))
5680 5680
 				{
5681 5681
 					$type = Horde_Mime_Magic::filenameToMIME($data['name']);
@@ -5718,24 +5718,24 @@  discard block
 block discarded – undo
5718 5718
 	 *
5719 5719
 	 * @return array returns an array of all resolved embeded attachments from winmail.dat
5720 5720
 	 */
5721
-	function getTnefAttachments ($_uid, $_partID, $_stream=false)
5721
+	function getTnefAttachments($_uid, $_partID, $_stream = false)
5722 5722
 	{
5723
-		$tnef_data = $this->getAttachment($_uid, $_partID,0,false);
5723
+		$tnef_data = $this->getAttachment($_uid, $_partID, 0, false);
5724 5724
 		$tnef_parts = $this->tnef_decoder($tnef_data['attachment']);
5725 5725
 		$attachments = array();
5726 5726
 		if ($tnef_parts)
5727 5727
 		{
5728
-			foreach($tnef_parts->getParts() as $mime_id => $part)
5728
+			foreach ($tnef_parts->getParts() as $mime_id => $part)
5729 5729
 			{
5730 5730
 
5731 5731
 				$attachment = $part->getAllDispositionParameters();
5732 5732
 				$attachment['mimeType'] = $part->getType();
5733
-				if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5733
+				if (!isset($attachment['filename']) || empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5734 5734
 				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5735 5735
 				if (empty($attachment['filename']))
5736 5736
 				{
5737
-					$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?
5738
-						$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
5737
+					$attachment['filename'] = (isset($attachment['cid']) && !empty($attachment['cid']) ?
5738
+						$attachment['cid'] : lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
5739 5739
 				}
5740 5740
 
5741 5741
 				$attachment['attachment'] = $part->getContents(array('stream'=>$_stream));
@@ -5759,10 +5759,10 @@  discard block
 block discarded – undo
5759 5759
 	 *
5760 5760
 	 * @return array
5761 5761
 	 */
5762
-	function getAttachment($_uid, $_partID, $_winmail_nr=0, $_returnPart=true, $_stream=false, $_folder=null)
5762
+	function getAttachment($_uid, $_partID, $_winmail_nr = 0, $_returnPart = true, $_stream = false, $_folder = null)
5763 5763
 	{
5764 5764
 		//error_log(__METHOD__.__LINE__."Uid:$_uid, PartId:$_partID, WinMailNr:$_winmail_nr, ReturnPart:$_returnPart, Stream:$_stream, Folder:$_folder".function_backtrace());
5765
-		if (!isset($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5765
+		if (!isset($_folder)) $_folder = ($this->sessionData['mailbox'] ? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5766 5766
 
5767 5767
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5768 5768
 		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
@@ -5775,36 +5775,36 @@  discard block
 block discarded – undo
5775 5775
 			'ids' => $uidsToFetch,
5776 5776
 		));
5777 5777
 		if (is_object($headersNew)) {
5778
-			foreach($headersNew as $id=>$_headerObject) {
5778
+			foreach ($headersNew as $id=>$_headerObject) {
5779 5779
 				$body = $_headerObject->getFullMsg();
5780 5780
 				if ($_partID != '')
5781 5781
 				{
5782 5782
 					$mailStructureObject = $_headerObject->getStructure();
5783 5783
 					$mailStructureObject->contentTypeMap();
5784 5784
 					$part = $mailStructureObject->getPart($_partID);
5785
-					$partDisposition = ($part?$part->getDisposition():'failed');
5786
-					if ($partDisposition=='failed')
5785
+					$partDisposition = ($part ? $part->getDisposition() : 'failed');
5786
+					if ($partDisposition == 'failed')
5787 5787
 					{
5788 5788
 						error_log(__METHOD__.'('.__LINE__.'):'.array2string($_uid).','.$_partID.' ID:'.$id.' HObject:'.array2string($_headerObject).' StructureObject:'.array2string($mailStructureObject->contentTypeMap()).'->'.function_backtrace());
5789 5789
 					}
5790 5790
 					// if $partDisposition is empty, we assume attachment, and hope that the function
5791 5791
 					// itself is only triggered to fetch attachments
5792
-					if (empty($partDisposition)) $partDisposition='attachment';
5793
-					if ($part && ($partDisposition=='attachment' || $partDisposition=='inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar')))
5792
+					if (empty($partDisposition)) $partDisposition = 'attachment';
5793
+					if ($part && ($partDisposition == 'attachment' || $partDisposition == 'inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar')))
5794 5794
 					{
5795 5795
 						//$headerObject=$part->getAllDispositionParameters();//not used anywhere around here
5796 5796
 						$structure_mime = $part->getType();
5797 5797
 						$filename = $part->getName();
5798 5798
 						$charset = $part->getContentTypeParameter('charset');
5799 5799
 						//$structure_bytes = $part->getBytes(); $structure_partID=$part->getMimeId(); error_log(__METHOD__.__LINE__." fetchPartContents(".array2string($_uid).", $structure_partID, $_stream, $_preserveSeen,$structure_mime)" );
5800
-						$this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen=true,$structure_mime);
5800
+						$this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen = true, $structure_mime);
5801 5801
 						if ($_returnPart) return $part;
5802 5802
 					}
5803 5803
 				}
5804 5804
 			}
5805 5805
 		}
5806 5806
 		$ext = MimeMagic::mime2ext($structure_mime);
5807
-		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false) $filename = trim($filename).'.'.$ext;
5807
+		if ($ext && stripos($filename, '.') === false && stripos($filename, $ext) === false) $filename = trim($filename).'.'.$ext;
5808 5808
 		if (!$part)
5809 5809
 		{
5810 5810
 			throw new Exception\WrongParameter("Error: Could not fetch attachment for Uid=".array2string($_uid).", PartId=$_partID, WinMailNr=$_winmail_nr, folder=$_folder");
@@ -5822,20 +5822,20 @@  discard block
 block discarded – undo
5822 5822
 		// try guessing the mimetype, if we get the application/octet-stream
5823 5823
 		if (strtolower($attachmentData['type']) == 'application/octet-stream') $attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']);
5824 5824
 		# if the attachment holds a winmail number and is a winmail.dat then we have to handle that.
5825
-		if ( $filename == 'winmail.dat' && $_winmail_nr)
5825
+		if ($filename == 'winmail.dat' && $_winmail_nr)
5826 5826
 		{
5827 5827
 			//by now _uid is of type array
5828
-			$tnefResolved=false;
5829
-			$wantedPart=$_uid[0].'@'.$_partID;
5828
+			$tnefResolved = false;
5829
+			$wantedPart = $_uid[0].'@'.$_partID;
5830 5830
 			$myTnef = $this->tnef_decoder($attachmentData['attachment']);
5831 5831
 			//error_log(__METHOD__.__LINE__.array2string($myTnef->getParts()));
5832 5832
 			// Note: MimeId starts with 0, almost always, we cannot use that as winmail_id
5833 5833
 			// we need to build Something that meets the needs
5834 5834
 			if ($myTnef)
5835 5835
 			{
5836
-				foreach($myTnef->getParts() as $mime_id => $part)
5836
+				foreach ($myTnef->getParts() as $mime_id => $part)
5837 5837
 				{
5838
-					$tnefResolved=true;
5838
+					$tnefResolved = true;
5839 5839
 					$attachment = $part->getAllDispositionParameters();
5840 5840
 					$attachment['mimeType'] = $part->getType();
5841 5841
 					//error_log(__METHOD__.__LINE__.'#'.$mime_id.'#'.$filename.'#'.array2string($attachment));
@@ -5843,9 +5843,9 @@  discard block
 block discarded – undo
5843 5843
 					if ($_winmail_nr == $wantedPart.'@'.$mime_id)
5844 5844
 					{
5845 5845
 						//error_log(__METHOD__.__LINE__.'#'.$structure_mime.'#'.$filename.'#'.array2string($attachment));
5846
-						if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5846
+						if (!isset($attachment['filename']) || empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5847 5847
 						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5848
-						if (empty($attachment['filename'])) $attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
5848
+						if (empty($attachment['filename'])) $attachment['filename'] = (isset($attachment['cid']) && !empty($attachment['cid']) ? $attachment['cid'] : lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
5849 5849
 						$wmattach = $attachment;
5850 5850
 						$wmattach['attachment'] = $part->getContents(array('stream'=>$_stream));
5851 5851
 
@@ -5855,7 +5855,7 @@  discard block
 block discarded – undo
5855 5855
 			if ($tnefResolved)
5856 5856
 			{
5857 5857
 				$ext = MimeMagic::mime2ext($wmattach['mimeType']);
5858
-				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
5858
+				if ($ext && stripos($wmattach['filename'], '.') === false && stripos($wmattach['filename'], $ext) === false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
5859 5859
 				$attachmentData = array(
5860 5860
 					'type'       => $wmattach['mimeType'],
5861 5861
 					'filename'   => $wmattach['filename'],
@@ -5879,21 +5879,21 @@  discard block
 block discarded – undo
5879 5879
 	 *	true:
5880 5880
 	 * @return Horde_Mime_Part
5881 5881
 	 */
5882
-	function getAttachmentByCID($_uid, $_cid, $_part, $_stream=null)
5882
+	function getAttachmentByCID($_uid, $_cid, $_part, $_stream = null)
5883 5883
 	{
5884 5884
 		// some static variables to avoid fetching the same mail multiple times
5885
-		static $uid=null, $part=null, $structure=null;
5885
+		static $uid = null, $part = null, $structure = null;
5886 5886
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_cid, $_part");
5887 5887
 
5888
-		if(empty($_cid)) return false;
5888
+		if (empty($_cid)) return false;
5889 5889
 
5890 5890
 		if ($_uid != $uid || $_part != $part)
5891 5891
 		{
5892
-			$structure = $this->getStructure($uid=$_uid, $part=$_part);
5892
+			$structure = $this->getStructure($uid = $_uid, $part = $_part);
5893 5893
 		}
5894 5894
 		/** @var Horde_Mime_Part */
5895 5895
 		$attachment = null;
5896
-		foreach($structure->contentTypeMap() as $mime_id => $mime_type)
5896
+		foreach ($structure->contentTypeMap() as $mime_id => $mime_type)
5897 5897
 		{
5898 5898
 			$part = $structure->getPart($mime_id);
5899 5899
 
@@ -5945,16 +5945,16 @@  discard block
 block discarded – undo
5945 5945
 	 * @param string  $_mimetype to decide wether to try to fetch part as binary or not
5946 5946
 	 * @return Horde_Mime_Part
5947 5947
 	 */
5948
-	public function fetchPartContents($_uid, Horde_Mime_Part $part=null, $_stream=false, $_preserveSeen=false, $_mimetype=null)
5948
+	public function fetchPartContents($_uid, Horde_Mime_Part $part = null, $_stream = false, $_preserveSeen = false, $_mimetype = null)
5949 5949
 	{
5950
-		if (is_null($part)) return null;//new Horde_Mime_Part;
5950
+		if (is_null($part)) return null; //new Horde_Mime_Part;
5951 5951
 		$encoding = null;
5952 5952
 		$fetchAsBinary = true;
5953
-		if ($_mimetype && strtolower($_mimetype)=='message/rfc822') $fetchAsBinary = false;
5953
+		if ($_mimetype && strtolower($_mimetype) == 'message/rfc822') $fetchAsBinary = false;
5954 5954
 		// we need to set content on structure to decode transfer encoding
5955 5955
 		$part->setContents(
5956 5956
 			$this->getBodyPart($_uid, $part->getMimeId(), null, $_preserveSeen, $_stream, $encoding, $fetchAsBinary),
5957
-			array('encoding' => (!$fetchAsBinary&&!$encoding?'8bit':$encoding)));
5957
+			array('encoding' => (!$fetchAsBinary && !$encoding ? '8bit' : $encoding)));
5958 5958
 
5959 5959
 		return $part;
5960 5960
 	}
@@ -5972,17 +5972,17 @@  discard block
 block discarded – undo
5972 5972
 	 * @return the id of the message appended or exception
5973 5973
 	 * @throws Exception\WrongUserinput
5974 5974
 	 */
5975
-	function appendMessage($_folderName, $_header, $_body, $_flags='\\Recent')
5975
+	function appendMessage($_folderName, $_header, $_body, $_flags = '\\Recent')
5976 5976
 	{
5977 5977
 		if (!is_resource($_header))
5978 5978
 		{
5979
-			if (stripos($_header,'message-id:')===false)
5979
+			if (stripos($_header, 'message-id:') === false)
5980 5980
 			{
5981 5981
 				$_header = 'Message-ID: <'.self::getRandomString().'@localhost>'."\n".$_header;
5982 5982
 			}
5983 5983
 			//error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_header, $_body, $_flags");
5984
-			$_header = ltrim(str_replace("\n","\r\n",$_header));
5985
-			$_header .= str_replace("\n","\r\n",$_body);
5984
+			$_header = ltrim(str_replace("\n", "\r\n", $_header));
5985
+			$_header .= str_replace("\n", "\r\n", $_body);
5986 5986
 		}
5987 5987
 		// the recent flag is the default enforced here ; as we assume the _flags is always set,
5988 5988
 		// we default it to hordes default (Recent) (, other wise we should not pass the parameter
@@ -6000,7 +6000,7 @@  discard block
 block discarded – undo
6000 6000
 			// searched for the message-id then returning the uid found
6001 6001
 			//$dataNflags[] = array('data'=>array(array('t'=>'text','v'=>"$header"."$body")), 'flags'=>array($_flags));
6002 6002
 			$dataNflags[] = array('data' => $_header, 'flags'=>array($_flags));
6003
-			$messageid = $this->icServer->append($_folderName,$dataNflags);
6003
+			$messageid = $this->icServer->append($_folderName, $dataNflags);
6004 6004
 		}
6005 6005
 		catch (\Exception $e)
6006 6006
 		{
@@ -6012,7 +6012,7 @@  discard block
 block discarded – undo
6012 6012
 		//$messageid = true; // for debug reasons only
6013 6013
 		if ($messageid === true || empty($messageid)) // try to figure out the message uid
6014 6014
 		{
6015
-			$list = $this->getHeaders($_folderName, $_startMessage=1, 1, 'INTERNALDATE', true, array(),null, false);
6015
+			$list = $this->getHeaders($_folderName, $_startMessage = 1, 1, 'INTERNALDATE', true, array(), null, false);
6016 6016
 			if ($list)
6017 6017
 			{
6018 6018
 				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
@@ -6052,27 +6052,27 @@  discard block
 block discarded – undo
6052 6052
 	 *				'attachments'=>$attachments,
6053 6053
 	 *				'headers'=>$headers,; boolean false on failure
6054 6054
 	 */
6055
-	static function get_mailcontent(&$mailClass,$uid,$partid='',$mailbox='', $preserveHTML = false, $addHeaderSection=true, $includeAttachments=true)
6055
+	static function get_mailcontent(&$mailClass, $uid, $partid = '', $mailbox = '', $preserveHTML = false, $addHeaderSection = true, $includeAttachments = true)
6056 6056
 	{
6057 6057
 			//echo __METHOD__." called for $uid,$partid <br>";
6058
-			$headers = $mailClass->getMessageHeader($uid,$partid,true,false,$mailbox);
6058
+			$headers = $mailClass->getMessageHeader($uid, $partid, true, false, $mailbox);
6059 6059
 			if (empty($headers)) return false;
6060 6060
 			// dont force retrieval of the textpart, let mailClass preferences decide
6061
-			$bodyParts = $mailClass->getMessageBody($uid,($preserveHTML?'always_display':'only_if_no_text'),$partid,null,false,$mailbox);
6061
+			$bodyParts = $mailClass->getMessageBody($uid, ($preserveHTML ? 'always_display' : 'only_if_no_text'), $partid, null, false, $mailbox);
6062 6062
 			// if we do not want HTML but there is no TextRepresentation with the message itself, try converting
6063
-			if ( !$preserveHTML && $bodyParts[0]['mimeType']=='text/html')
6063
+			if (!$preserveHTML && $bodyParts[0]['mimeType'] == 'text/html')
6064 6064
 			{
6065
-				foreach($bodyParts as $i => $part)
6065
+				foreach ($bodyParts as $i => $part)
6066 6066
 				{
6067
-					if ($bodyParts[$i]['mimeType']=='text/html')
6067
+					if ($bodyParts[$i]['mimeType'] == 'text/html')
6068 6068
 					{
6069
-						$bodyParts[$i]['body'] = Mail\Html::convertHTMLToText($bodyParts[$i]['body'],$bodyParts[$i]['charSet'],true,$stripalltags=true);
6070
-						$bodyParts[$i]['mimeType']='text/plain';
6069
+						$bodyParts[$i]['body'] = Mail\Html::convertHTMLToText($bodyParts[$i]['body'], $bodyParts[$i]['charSet'], true, $stripalltags = true);
6070
+						$bodyParts[$i]['mimeType'] = 'text/plain';
6071 6071
 					}
6072 6072
 				}
6073 6073
 			}
6074 6074
 			//error_log(array2string($bodyParts));
6075
-			$attachments = $includeAttachments?$mailClass->getMessageAttachments($uid,$partid,null,true,false,true,$mailbox):array();
6075
+			$attachments = $includeAttachments ? $mailClass->getMessageAttachments($uid, $partid, null, true, false, true, $mailbox) : array();
6076 6076
 
6077 6077
 			if ($mailClass->isSentFolder($mailbox)) $mailaddress = $headers['TO'];
6078 6078
 			elseif (isset($headers['FROM'])) $mailaddress = $headers['FROM'];
@@ -6083,7 +6083,7 @@  discard block
 block discarded – undo
6083 6083
 
6084 6084
 			$message = self::getdisplayableBody($mailClass, $bodyParts, $preserveHTML);
6085 6085
 			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain') $message = '<pre>'.$message.'</pre>';
6086
-			$headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '',$preserveHTML) : '');
6086
+			$headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '', $preserveHTML) : '');
6087 6087
 			$message = $headdata.$message;
6088 6088
 			//echo __METHOD__.'<br>';
6089 6089
 			//_debug_array($attachments);
@@ -6099,25 +6099,25 @@  discard block
 block discarded – undo
6099 6099
 						//_debug_array($mailClass->getMessageHeader($uid, $attachment['partID']));
6100 6100
 						//_debug_array($mailClass->getMessageBody($uid,'', $attachment['partID']));
6101 6101
 						//_debug_array($mailClass->getMessageAttachments($uid, $attachment['partID']));
6102
-						$mailcontent = self::get_mailcontent($mailClass,$uid,$attachment['partID'],$mailbox);
6103
-						$headdata ='';
6102
+						$mailcontent = self::get_mailcontent($mailClass, $uid, $attachment['partID'], $mailbox);
6103
+						$headdata = '';
6104 6104
 						if ($mailcontent['headers'])
6105 6105
 						{
6106
-							$headdata = self::createHeaderInfoSection($mailcontent['headers'],'',$preserveHTML);
6106
+							$headdata = self::createHeaderInfoSection($mailcontent['headers'], '', $preserveHTML);
6107 6107
 						}
6108 6108
 						if ($mailcontent['message'])
6109 6109
 						{
6110
-							$tempname =tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
6110
+							$tempname = tempnam($GLOBALS['egw_info']['server']['temp_dir'], $GLOBALS['egw_info']['flags']['currentapp']."_");
6111 6111
 							$attachedMessages[] = array(
6112 6112
 								'type' => 'TEXT/PLAIN',
6113 6113
 								'name' => $mailcontent['subject'].'.txt',
6114 6114
 								'tmp_name' => $tempname,
6115 6115
 							);
6116
-							$tmpfile = fopen($tempname,'w');
6117
-							fwrite($tmpfile,$headdata.$mailcontent['message']);
6116
+							$tmpfile = fopen($tempname, 'w');
6117
+							fwrite($tmpfile, $headdata.$mailcontent['message']);
6118 6118
 							fclose($tmpfile);
6119 6119
 						}
6120
-						foreach($mailcontent['attachments'] as &$tmpval)
6120
+						foreach ($mailcontent['attachments'] as &$tmpval)
6121 6121
 						{
6122 6122
 							$attachedMessages[] = $tmpval;
6123 6123
 						}
@@ -6125,36 +6125,36 @@  discard block
 block discarded – undo
6125 6125
 					}
6126 6126
 					else
6127 6127
 					{
6128
-						$attachments[$num] = array_merge($attachments[$num],$mailClass->getAttachment($uid, $attachment['partID'],0,false,false));
6128
+						$attachments[$num] = array_merge($attachments[$num], $mailClass->getAttachment($uid, $attachment['partID'], 0, false, false));
6129 6129
 
6130
-						if (empty($attachments[$num]['attachment'])&&$attachments[$num]['cid'])
6130
+						if (empty($attachments[$num]['attachment']) && $attachments[$num]['cid'])
6131 6131
 						{
6132
-							$c = $mailClass->getAttachmentByCID($uid, $attachment['cid'], $attachment['partID'],true);
6132
+							$c = $mailClass->getAttachmentByCID($uid, $attachment['cid'], $attachment['partID'], true);
6133 6133
 							$attachments[$num]['attachment'] = $c->getContents();
6134 6134
 						}
6135 6135
 						// no attempt to convert, if we dont know about the charset
6136
-						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset'])) {
6136
+						if (isset($attachments[$num]['charset']) && !empty($attachments[$num]['charset'])) {
6137 6137
 							// we do not try guessing the charset, if it is not set
6138 6138
 							//if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = Translation::detect_encoding($attachments[$num]['attachment']);
6139
-							Translation::convert($attachments[$num]['attachment'],$attachments[$num]['charset']);
6139
+							Translation::convert($attachments[$num]['attachment'], $attachments[$num]['charset']);
6140 6140
 						}
6141
-						if(in_array($attachments[$num]['name'], $file_list))
6141
+						if (in_array($attachments[$num]['name'], $file_list))
6142 6142
 						{
6143 6143
 							$dupe_count[$attachments[$num]['name']]++;
6144
-							$attachments[$num]['name'] = pathinfo($attachments[$num]['name'], PATHINFO_FILENAME) .
6145
-								' ('.($dupe_count[$attachments[$num]['name']] + 1).')' . '.' .
6144
+							$attachments[$num]['name'] = pathinfo($attachments[$num]['name'], PATHINFO_FILENAME).
6145
+								' ('.($dupe_count[$attachments[$num]['name']] + 1).')'.'.'.
6146 6146
 								pathinfo($attachments[$num]['name'], PATHINFO_EXTENSION);
6147 6147
 						}
6148 6148
 						$attachments[$num]['type'] = $attachments[$num]['mimeType'];
6149
-						$attachments[$num]['tmp_name'] = tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
6150
-						$tmpfile = fopen($attachments[$num]['tmp_name'],'w');
6151
-						fwrite($tmpfile,$attachments[$num]['attachment']);
6149
+						$attachments[$num]['tmp_name'] = tempnam($GLOBALS['egw_info']['server']['temp_dir'], $GLOBALS['egw_info']['flags']['currentapp']."_");
6150
+						$tmpfile = fopen($attachments[$num]['tmp_name'], 'w');
6151
+						fwrite($tmpfile, $attachments[$num]['attachment']);
6152 6152
 						fclose($tmpfile);
6153 6153
 						$file_list[] = $attachments[$num]['name'];
6154 6154
 						unset($attachments[$num]['attachment']);
6155 6155
 					}
6156 6156
 				}
6157
-				if (is_array($attachedMessages)) $attachments = array_merge($attachments,$attachedMessages);
6157
+				if (is_array($attachedMessages)) $attachments = array_merge($attachments, $attachedMessages);
6158 6158
 			}
6159 6159
 			return array(
6160 6160
 					'mailaddress'=>$mailaddress,
@@ -6176,10 +6176,10 @@  discard block
 block discarded – undo
6176 6176
 	{
6177 6177
 		$c = 0;
6178 6178
 		// use the standardIdentity
6179
-		foreach($_identities as $key => $acc) {
6180
-			if ($c==0) $identity = $acc;
6179
+		foreach ($_identities as $key => $acc) {
6180
+			if ($c == 0) $identity = $acc;
6181 6181
 			//error_log(__METHOD__.__LINE__." $key == $_profile_id ");
6182
-			if ($key==$_profile_id) $identity = $acc;
6182
+			if ($key == $_profile_id) $identity = $acc;
6183 6183
 			$c++;
6184 6184
 		}
6185 6185
 		return $identity;
@@ -6191,29 +6191,29 @@  discard block
 block discarded – undo
6191 6191
 	 * @param bool createHTML do it with HTML breaks
6192 6192
 	 * @return string a preformatted string with the information of the header worked into it
6193 6193
 	 */
6194
-	static function createHeaderInfoSection($header,$headline='', $createHTML = false)
6194
+	static function createHeaderInfoSection($header, $headline = '', $createHTML = false)
6195 6195
 	{
6196 6196
 		$headdata = null;
6197 6197
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($header).function_backtrace());
6198
-		if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
6199
-		if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
6200
-		if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
6201
-		if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
6202
-		if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
6203
-		if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
6204
-		if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
6205
-		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
6206
-		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
6198
+		if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML ? "<br />" : "\n");
6199
+		if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML ? "<br />" : "\n");
6200
+		if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML ? "<br />" : "\n");
6201
+		if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML ? "<br />" : "\n");
6202
+		if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML ? "<br />" : "\n");
6203
+		if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML ? "<br />" : "\n");
6204
+		if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML ? "<br />" : "\n");
6205
+		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML ? "<br />" : "\n");
6206
+		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] != 'normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML ? "<br />" : "\n");
6207 6207
 		//if ($mailcontent['headers']['ORGANIZATION']) $headdata .= lang('organization').': '.$mailcontent['headers']['ORGANIZATION']."\
6208 6208
 		if (!empty($headdata))
6209 6209
 		{
6210
-			if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
6211
-			if (empty($headline)) $headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
6212
-			$headdata .= ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'');
6210
+			if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML ? "<br />" : "\n").$headdata;
6211
+			if (empty($headline)) $headdata = ($headline != 'SUPPRESS' ? "--------------------------------------------------------".($createHTML ? "<br />" : "\n") : '').$headdata;
6212
+			$headdata .= ($headline != 'SUPPRESS' ? "--------------------------------------------------------".($createHTML ? "<br />" : "\n") : '');
6213 6213
 		}
6214 6214
 		else
6215 6215
 		{
6216
-			$headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'');
6216
+			$headdata = ($headline != 'SUPPRESS' ? "--------------------------------------------------------".($createHTML ? "<br />" : "\n") : '');
6217 6217
 		}
6218 6218
 		return $headdata;
6219 6219
 	}
@@ -6226,8 +6226,8 @@  discard block
 block discarded – undo
6226 6226
 	 */
6227 6227
 	static function adaptSubjectForImport($subject)
6228 6228
 	{
6229
-		$subject = str_replace('$$','__',($subject?$subject:lang('(no subject)')));
6230
-		$subject = str_ireplace(array('[FWD]','[',']','{','}','<','>'),array('Fwd:',' ',' ',' ',' ',' ',' '),trim($subject));
6229
+		$subject = str_replace('$$', '__', ($subject ? $subject : lang('(no subject)')));
6230
+		$subject = str_ireplace(array('[FWD]', '[', ']', '{', '}', '<', '>'), array('Fwd:', ' ', ' ', ' ', ' ', ' ', ' '), trim($subject));
6231 6231
 		return $subject;
6232 6232
 	}
6233 6233
 
@@ -6239,15 +6239,15 @@  discard block
 block discarded – undo
6239 6239
 	static function convertAddressArrayToString($rfcAddressArray)
6240 6240
 	{
6241 6241
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($rfcAddressArray));
6242
-		$returnAddr ='';
6242
+		$returnAddr = '';
6243 6243
 		if (is_array($rfcAddressArray))
6244 6244
 		{
6245
-			foreach((array)$rfcAddressArray as $addressData) {
6245
+			foreach ((array)$rfcAddressArray as $addressData) {
6246 6246
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressData));
6247
-				if($addressData['MAILBOX_NAME'] == 'NIL') {
6247
+				if ($addressData['MAILBOX_NAME'] == 'NIL') {
6248 6248
 					continue;
6249 6249
 				}
6250
-				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') {
6250
+				if (strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') {
6251 6251
 					continue;
6252 6252
 				}
6253 6253
 				if ($addressData['RFC822_EMAIL'])
@@ -6256,7 +6256,7 @@  discard block
 block discarded – undo
6256 6256
 				}
6257 6257
 				else
6258 6258
 				{
6259
-					$emailaddress = ($addressData['PERSONAL_NAME']?$addressData['PERSONAL_NAME'].' <'.$addressData['EMAIL'].'>':$addressData['EMAIL']);
6259
+					$emailaddress = ($addressData['PERSONAL_NAME'] ? $addressData['PERSONAL_NAME'].' <'.$addressData['EMAIL'].'>' : $addressData['EMAIL']);
6260 6260
 					$addressObjectA = self::parseAddressList($emailaddress);
6261 6261
 				}
6262 6262
 				$addressObject = $addressObjectA[0];
@@ -6265,10 +6265,10 @@  discard block
 block discarded – undo
6265 6265
 				//$mb =(string)$addressObject->mailbox;
6266 6266
 				//$h = (string)$addressObject->host;
6267 6267
 				//$p = (string)$addressObject->personal;
6268
-				$returnAddr .= (strlen($returnAddr)>0?',':'');
6268
+				$returnAddr .= (strlen($returnAddr) > 0 ? ',' : '');
6269 6269
 				//error_log(__METHOD__.' ('.__LINE__.') '.$p.' <'.$mb.'@'.$h.'>');
6270 6270
 				$buff = imap_rfc822_write_address($addressObject->mailbox, Horde_Idna::decode($addressObject->host), $addressObject->personal);
6271
-				$buff = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$buff);
6271
+				$buff = str_replace(array('<', '>', '"\'', '\'"'), array('[', ']', '"', '"'), $buff);
6272 6272
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Address: '.$returnAddr);
6273 6273
 				$returnAddr .= $buff;
6274 6274
 			}
@@ -6276,8 +6276,8 @@  discard block
 block discarded – undo
6276 6276
 		else
6277 6277
 		{
6278 6278
 			// do not mess with strings, return them untouched /* ToDo: validate string as Address */
6279
-			$rfcAddressArray = self::decode_header($rfcAddressArray,true);
6280
-			$rfcAddressArray = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$rfcAddressArray);
6279
+			$rfcAddressArray = self::decode_header($rfcAddressArray, true);
6280
+			$rfcAddressArray = str_replace(array('<', '>', '"\'', '\'"'), array('[', ']', '"', '"'), $rfcAddressArray);
6281 6281
 			if (is_string($rfcAddressArray)) return $rfcAddressArray;
6282 6282
 		}
6283 6283
 		return $returnAddr;
@@ -6291,12 +6291,12 @@  discard block
 block discarded – undo
6291 6291
 	 * @param string &$err error-message on error
6292 6292
 	 * @return string/boolean merged content or false on error
6293 6293
 	 */
6294
-	static function merge($content,$ids,$mimetype='')
6294
+	static function merge($content, $ids, $mimetype = '')
6295 6295
 	{
6296 6296
 		$mergeobj = new Contacts\Merge();
6297 6297
 
6298
-		if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
6299
-		$rv = $mergeobj->merge_string($content,$ids,$err='',$mimetype, array(), self::$displayCharset);
6298
+		if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ? 'text/plain' : 'text/html');
6299
+		$rv = $mergeobj->merge_string($content, $ids, $err = '', $mimetype, array(), self::$displayCharset);
6300 6300
 		if (empty($rv) && !empty($content) && !empty($err)) $rv = $content;
6301 6301
 		if (!empty($err) && !empty($content) && !empty($ids)) error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
6302 6302
 		return $rv;
@@ -6338,12 +6338,12 @@  discard block
 block discarded – undo
6338 6338
 		else
6339 6339
 			settype($bytes, 'integer');
6340 6340
 
6341
-		return $bytes . ' ' . $type ;
6341
+		return $bytes.' '.$type;
6342 6342
 	}
6343 6343
 
6344 6344
 	static function detect_qp(&$sting) {
6345 6345
 		$needle = '/(=[0-9][A-F])|(=[A-F][0-9])|(=[A-F][A-F])|(=[0-9][0-9])/';
6346
-		return preg_match("$needle",$string);
6346
+		return preg_match("$needle", $string);
6347 6347
 	}
6348 6348
 
6349 6349
 	/**
@@ -6356,11 +6356,11 @@  discard block
 block discarded – undo
6356 6356
 	 * @param string $_methodNline - Information where the log was taken
6357 6357
 	 * @return void
6358 6358
 	 */
6359
-	static function logRunTimes($_starttime,$_endtime=null,$_message='',$_methodNline='')
6359
+	static function logRunTimes($_starttime, $_endtime = null, $_message = '', $_methodNline = '')
6360 6360
 	{
6361 6361
 		if (is_null($_endtime)) $_endtime = microtime(true);
6362 6362
 		$usagetime = microtime(true) - $_starttime;
6363
-		if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
6363
+		if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime, 5).'(s) '.($_message ? 'Details:'.$_message : ''));
6364 6364
 	}
6365 6365
 
6366 6366
 	/**
@@ -6373,9 +6373,9 @@  discard block
 block discarded – undo
6373 6373
 	 *
6374 6374
 	 * @throws Exception\WrongUserinput
6375 6375
 	 */
6376
-	static function checkFileBasics(&$_formData, $IDtoAddToFileName='', $reqMimeType='message/rfc822')
6376
+	static function checkFileBasics(&$_formData, $IDtoAddToFileName = '', $reqMimeType = 'message/rfc822')
6377 6377
 	{
6378
-		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data') return $_formData['file'];
6378
+		if (parse_url($_formData['file'], PHP_URL_SCHEME) == 'egw-data') return $_formData['file'];
6379 6379
 
6380 6380
 		//error_log(__METHOD__.__FILE__.array2string($_formData).' Id:'.$IDtoAddToFileName.' ReqMimeType:'.$reqMimeType);
6381 6381
 		$importfailed = $tmpFileName = false;
@@ -6385,7 +6385,7 @@  discard block
 block discarded – undo
6385 6385
 			$importfailed = true;
6386 6386
 			$alert_msg .= lang("Empty file %1 ignored.", $_formData['name']);
6387 6387
 		}
6388
-		elseif (parse_url($_formData['file'],PHP_URL_SCHEME) == 'vfs' || is_uploaded_file($_formData['file']) ||
6388
+		elseif (parse_url($_formData['file'], PHP_URL_SCHEME) == 'vfs' || is_uploaded_file($_formData['file']) ||
6389 6389
 			realpath(dirname($_formData['file'])) == realpath($GLOBALS['egw_info']['server']['temp_dir']))
6390 6390
 		{
6391 6391
 			// ensure existance of eGW temp dir
@@ -6393,7 +6393,7 @@  discard block
 block discarded – undo
6393 6393
 			// and different from any other temp file location set in php.ini
6394 6394
 			if (!file_exists($GLOBALS['egw_info']['server']['temp_dir']))
6395 6395
 			{
6396
-				@mkdir($GLOBALS['egw_info']['server']['temp_dir'],0700);
6396
+				@mkdir($GLOBALS['egw_info']['server']['temp_dir'], 0700);
6397 6397
 			}
6398 6398
 
6399 6399
 			// if we were NOT able to create this temp directory, then make an ERROR report
@@ -6420,14 +6420,14 @@  discard block
 block discarded – undo
6420 6420
 			// maybe its application/octet-stream -> this may mean that we could not determine the type
6421 6421
 			// so we check for the suffix too
6422 6422
 			// trust vfs mime-types, trust the mimetype if it contains a method
6423
-			if ((substr($_formData['file'],0,6) !== 'vfs://' || $_formData['type'] == 'application/octet-stream') && stripos($_formData['type'],'method=')===false)
6423
+			if ((substr($_formData['file'], 0, 6) !== 'vfs://' || $_formData['type'] == 'application/octet-stream') && stripos($_formData['type'], 'method=') === false)
6424 6424
 			{
6425
-				$buff = explode('.',$_formData['name']);
6425
+				$buff = explode('.', $_formData['name']);
6426 6426
 				$suffix = '';
6427 6427
 				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
6428 6428
 				if (!empty($suffix)) $sfxMimeType = MimeMagic::ext2mime($suffix);
6429 6429
 				if (!empty($suffix) && !empty($sfxMimeType) &&
6430
-					(strlen(trim($_formData['type']))==0 || (strtolower(trim($_formData['type'])) != $sfxMimeType)))
6430
+					(strlen(trim($_formData['type'])) == 0 || (strtolower(trim($_formData['type'])) != $sfxMimeType)))
6431 6431
 				{
6432 6432
 					error_log(__METHOD__.' ('.__LINE__.') '.' Data:'.array2string($_formData));
6433 6433
 					error_log(__METHOD__.' ('.__LINE__.') '.' Form reported Mimetype:'.$_formData['type'].' but seems to be:'.$sfxMimeType);
@@ -6442,13 +6442,13 @@  discard block
 block discarded – undo
6442 6442
 			if ($reqMimeType)
6443 6443
 			{
6444 6444
 				// so if PHP did not pass any file_type info, then substitute the rfc default value
6445
-				if (substr(strtolower(trim($_formData['type'])),0,strlen($mime_type_default)) != $mime_type_default)
6445
+				if (substr(strtolower(trim($_formData['type'])), 0, strlen($mime_type_default)) != $mime_type_default)
6446 6446
 				{
6447 6447
 					if (!(strtolower(trim($_formData['type'])) == "application/octet-stream" && $sfxMimeType == $reqMimeType))
6448 6448
 					{
6449 6449
 						//error_log("Message rejected, no message/rfc. Is:".$_formData['type']);
6450 6450
 						$importfailed = true;
6451
-						$alert_msg .= lang("File rejected, no %2. Is:%1",$_formData['type'],$reqMimeType);
6451
+						$alert_msg .= lang("File rejected, no %2. Is:%1", $_formData['type'], $reqMimeType);
6452 6452
 					}
6453 6453
 					if ((strtolower(trim($_formData['type'])) != $reqMimeType && $sfxMimeType == $reqMimeType))
6454 6454
 					{
@@ -6457,17 +6457,17 @@  discard block
 block discarded – undo
6457 6457
 				}
6458 6458
 			}
6459 6459
 			// as FreeBSD seems to have problems with the generated temp names we append some more random stuff
6460
-			$randomString = chr(rand(65,90)).chr(rand(48,57)).chr(rand(65,90)).chr(rand(48,57)).chr(rand(65,90));
6460
+			$randomString = chr(rand(65, 90)).chr(rand(48, 57)).chr(rand(65, 90)).chr(rand(48, 57)).chr(rand(65, 90));
6461 6461
 			$tmpFileName = $GLOBALS['egw_info']['user']['account_id'].
6462 6462
 				trim($IDtoAddToFileName).basename($_formData['file']).'_'.$randomString;
6463 6463
 
6464
-			if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'vfs')
6464
+			if (parse_url($_formData['file'], PHP_URL_SCHEME) == 'vfs')
6465 6465
 			{
6466
-				$tmpFileName = $_formData['file'];	// no need to store it somewhere
6466
+				$tmpFileName = $_formData['file']; // no need to store it somewhere
6467 6467
 			}
6468 6468
 			elseif (is_uploaded_file($_formData['file']))
6469 6469
 			{
6470
-				move_uploaded_file($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmpFileName);	// requirement for safe_mode!
6470
+				move_uploaded_file($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmpFileName); // requirement for safe_mode!
6471 6471
 			}
6472 6472
 			else
6473 6473
 			{
@@ -6476,7 +6476,7 @@  discard block
 block discarded – undo
6476 6476
 		} else {
6477 6477
 			//error_log("Import of message ".$_formData['file']." failes to meet basic restrictions");
6478 6478
 			$importfailed = true;
6479
-			$alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.",$_formData['name']);
6479
+			$alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.", $_formData['name']);
6480 6480
 		}
6481 6481
 		if ($importfailed == true)
6482 6482
 		{
@@ -6484,7 +6484,7 @@  discard block
 block discarded – undo
6484 6484
 		}
6485 6485
 		else
6486 6486
 		{
6487
-			if (parse_url($tmpFileName,PHP_URL_SCHEME) == 'vfs')
6487
+			if (parse_url($tmpFileName, PHP_URL_SCHEME) == 'vfs')
6488 6488
 			{
6489 6489
 				Vfs::load_wrapper('vfs');
6490 6490
 			}
@@ -6509,7 +6509,7 @@  discard block
 block discarded – undo
6509 6509
 		$images = null;
6510 6510
 		if (preg_match_all("/(src|background)=\"(.*)\"/Ui", $_html2parse, $images) && isset($images[2]))
6511 6511
 		{
6512
-			foreach($images[2] as $i => $url)
6512
+			foreach ($images[2] as $i => $url)
6513 6513
 			{
6514 6514
 				//$isData = false;
6515 6515
 				$basedir = $data = '';
@@ -6521,20 +6521,20 @@  discard block
 block discarded – undo
6521 6521
 					$filename = basename($url);
6522 6522
 					if (($directory = dirname($url)) == '.') $directory = '';
6523 6523
 					$ext = pathinfo($filename, PATHINFO_EXTENSION);
6524
-					$mimeType  = MimeMagic::ext2mime($ext);
6525
-					if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
6524
+					$mimeType = MimeMagic::ext2mime($ext);
6525
+					if (strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; }
6526 6526
 					$myUrl = $directory.$filename;
6527
-					if ($myUrl[0]=='/') // local path -> we only allow path's that are available via http/https (or vfs)
6527
+					if ($myUrl[0] == '/') // local path -> we only allow path's that are available via http/https (or vfs)
6528 6528
 					{
6529
-						$basedir = ($_SERVER['HTTPS']?'https://':'http://'.$_SERVER['HTTP_HOST']);
6529
+						$basedir = ($_SERVER['HTTPS'] ? 'https://' : 'http://'.$_SERVER['HTTP_HOST']);
6530 6530
 					}
6531 6531
 					// use vfs instead of url containing webdav.php
6532 6532
 					// ToDo: we should test if the webdav url is of our own scope, as we cannot handle foreign
6533 6533
 					// webdav.php urls as vfs
6534
-					if (strpos($myUrl,'/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it.
6534
+					if (strpos($myUrl, '/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it.
6535 6535
 					{
6536 6536
 						Vfs::load_wrapper('vfs');
6537
-						list(,$myUrl) = explode('/webdav.php',$myUrl,2);
6537
+						list(,$myUrl) = explode('/webdav.php', $myUrl, 2);
6538 6538
 						$basedir = 'vfs://default';
6539 6539
 						$needTempFile = false;
6540 6540
 					}
@@ -6547,11 +6547,11 @@  discard block
 block discarded – undo
6547 6547
 						// Strips the url and store it into a temp for further procss
6548 6548
 						$tmp_url = html_entity_decode($myUrl);
6549 6549
 
6550
-						parse_str(parse_url($tmp_url, PHP_URL_QUERY),$URI_params);
6550
+						parse_str(parse_url($tmp_url, PHP_URL_QUERY), $URI_params);
6551 6551
 						if ($URI_params['mailbox'] && $URI_params['uid'] && $URI_params['cid'])
6552 6552
 						{
6553 6553
 							$mail_bo->reopen(base64_decode($URI_params['mailbox']));
6554
-							$attachment = $mail_bo->getAttachmentByCID($URI_params['uid'], base64_decode($URI_params['cid']),base64_decode($URI_params['partID']),true);
6554
+							$attachment = $mail_bo->getAttachmentByCID($URI_params['uid'], base64_decode($URI_params['cid']), base64_decode($URI_params['partID']), true);
6555 6555
 							$mail_bo->closeConnection();
6556 6556
 							if ($attachment)
6557 6557
 							{
@@ -6562,32 +6562,32 @@  discard block
 block discarded – undo
6562 6562
 						}
6563 6563
 					}
6564 6564
 
6565
-					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/') { $basedir .= '/'; }
6566
-					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl));
6565
+					if (strlen($basedir) > 1 && substr($basedir, -1) != '/' && $myUrl[0] != '/') { $basedir .= '/'; }
6566
+					if ($needTempFile && !$attachment && substr($myUrl, 0, 4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl));
6567 6567
 				}
6568
-				if (substr($url,0,strlen('data:'))=='data:')
6568
+				if (substr($url, 0, strlen('data:')) == 'data:')
6569 6569
 				{
6570 6570
 					//error_log(__METHOD__.' ('.__LINE__.') '.' -> '.$i.': '.array2string($images[$i]));
6571 6571
 					// we only support base64 encoded data
6572
-					$tmp = substr($url,strlen('data:'));
6573
-					list($mimeType,$data_base64) = explode(';base64,',$tmp);
6572
+					$tmp = substr($url, strlen('data:'));
6573
+					list($mimeType, $data_base64) = explode(';base64,', $tmp);
6574 6574
 					$data = base64_decode($data_base64);
6575 6575
 					// FF currently does NOT add any mime-type
6576 6576
 					if (strtolower(substr($mimeType, 0, 6)) != 'image/')
6577 6577
 					{
6578 6578
 						$mimeType = MimeMagic::analyze_data($data);
6579 6579
 					}
6580
-					list($what,$exactly) = explode('/',$mimeType);
6580
+					list($what, $exactly) = explode('/', $mimeType);
6581 6581
 					$needTempFile = true;
6582
-					$filename = ($what?$what:'data').$imageC++.'.'.$exactly;
6582
+					$filename = ($what ? $what : 'data').$imageC++.'.'.$exactly;
6583 6583
 				}
6584 6584
 				if ($data || $needTempFile === false)
6585 6585
 				{
6586 6586
 					if ($needTempFile)
6587 6587
 					{
6588
-						$attachment_file =tempnam($GLOBALS['egw_info']['server']['temp_dir'],$GLOBALS['egw_info']['flags']['currentapp']."_");
6589
-						$tmpfile = fopen($attachment_file,'w');
6590
-						fwrite($tmpfile,$data);
6588
+						$attachment_file = tempnam($GLOBALS['egw_info']['server']['temp_dir'], $GLOBALS['egw_info']['flags']['currentapp']."_");
6589
+						$tmpfile = fopen($attachment_file, 'w');
6590
+						fwrite($tmpfile, $data);
6591 6591
 						fclose($tmpfile);
6592 6592
 					}
6593 6593
 					else
@@ -6598,7 +6598,7 @@  discard block
 block discarded – undo
6598 6598
 					// (or similar) in all cases (when cut&paste). This may lead to more attached files, in case
6599 6599
 					// we use the same image multiple times, but, if we do this, we should try to detect that
6600 6600
 					// on upload. filename itself is not sufficient to determine the sameness of images
6601
-					$cid = 'cid:' . md5($attachment_file);
6601
+					$cid = 'cid:'.md5($attachment_file);
6602 6602
 					if ($_mailObject->AddEmbeddedImage($attachment_file, substr($cid, 4), urldecode($filename), $mimeType) !== null)
6603 6603
 					{
6604 6604
 						//$_html2parse = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $_html2parse);
@@ -6620,10 +6620,10 @@  discard block
 block discarded – undo
6620 6620
 	 * @param string& $importID ID for the imported message, used by attachments to identify them unambiguously
6621 6621
 	 * @return mixed array of messages with success and failed messages or exception
6622 6622
 	 */
6623
-	function importMessageToMergeAndSend(Storage\Merge $bo_merge, $document, $SendAndMergeTocontacts, &$_folder, &$importID='')
6623
+	function importMessageToMergeAndSend(Storage\Merge $bo_merge, $document, $SendAndMergeTocontacts, &$_folder, &$importID = '')
6624 6624
 	{
6625 6625
 		$importfailed = false;
6626
-		$processStats = array('success'=>array(),'failed'=>array());
6626
+		$processStats = array('success'=>array(), 'failed'=>array());
6627 6627
 		if (empty($SendAndMergeTocontacts))
6628 6628
 		{
6629 6629
 			$importfailed = true;
@@ -6664,7 +6664,7 @@  discard block
 block discarded – undo
6664 6664
 				$_folder = $this->getSentFolder();
6665 6665
 			}
6666 6666
 			$delimiter = $this->getHierarchyDelimiter();
6667
-			if($_folder=='INBOX'.$delimiter) $_folder='INBOX';
6667
+			if ($_folder == 'INBOX'.$delimiter) $_folder = 'INBOX';
6668 6668
 			if ($importfailed === false)
6669 6669
 			{
6670 6670
 				$Subject = $mailObject->getHeader('Subject');
@@ -6682,9 +6682,9 @@  discard block
 block discarded – undo
6682 6682
 				{
6683 6683
 					$mailObject->clearReplyTos();
6684 6684
 					$activeMailProfiles = $this->mail->getAccountIdentities($this->profileID);
6685
-					$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles,$this->profileID);
6685
+					$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles, $this->profileID);
6686 6686
 
6687
-					$mailObject->addReplyTo(Horde_Idna::encode($activeMailProfile['ident_email']),Mail::generateIdentityString($activeMailProfile,false));
6687
+					$mailObject->addReplyTo(Horde_Idna::encode($activeMailProfile['ident_email']), Mail::generateIdentityString($activeMailProfile, false));
6688 6688
 				}
6689 6689
 				foreach ($SendAndMergeTocontacts as $k => $val)
6690 6690
 				{
@@ -6698,12 +6698,12 @@  discard block
 block discarded – undo
6698 6698
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6699 6699
 
6700 6700
 						// Parse destinations for placeholders
6701
-						foreach(Mailer::$type2header as $type => $h)
6701
+						foreach (Mailer::$type2header as $type => $h)
6702 6702
 						{
6703 6703
 							//error_log('ID ' . $val . ' ' .$type . ': ' . $mailObject->getHeader(Mailer::$type2header[$type]) . ' -> ' .$bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset));
6704
-							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset);
6705
-							$mailObject->addAddress($merged,'',$type);
6706
-							if($type == 'to')
6704
+							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]), $val, $e, 'text/plain', array(), self::$displayCharset);
6705
+							$mailObject->addAddress($merged, '', $type);
6706
+							if ($type == 'to')
6707 6707
 							{
6708 6708
 								$email = $merged;
6709 6709
 							}
@@ -6716,26 +6716,26 @@  discard block
 block discarded – undo
6716 6716
 							//error_log(__METHOD__.' ('.__LINE__.') '.' ID:'.$val.' Data:'.array2string($contact));
6717 6717
 							$email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
6718 6718
 							$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
6719
-							if($email)
6719
+							if ($email)
6720 6720
 							{
6721 6721
 								$mailObject->addAddress(Horde_Idna::encode($email), $nfn);
6722 6722
 							}
6723 6723
 						}
6724 6724
 
6725 6725
 						$activeMailProfiles = $this->getAccountIdentities($this->profileID);
6726
-						$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles,$this->profileID);
6726
+						$activeMailProfile = self::getStandardIdentityForProfile($activeMailProfiles, $this->profileID);
6727 6727
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($activeMailProfile));
6728 6728
 						$mailObject->setFrom($activeMailProfile['ident_email'],
6729
-							self::generateIdentityString($activeMailProfile,false));
6729
+							self::generateIdentityString($activeMailProfile, false));
6730 6730
 
6731 6731
 						$mailObject->removeHeader('Message-ID');
6732 6732
 						$mailObject->removeHeader('Date');
6733 6733
 						$mailObject->clearCustomHeaders();
6734 6734
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6735 6735
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6736
-						if($text_body) $text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
6736
+						if ($text_body) $text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset), array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
6737 6737
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6738
-						if($html_body) $html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
6738
+						if ($html_body) $html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset), array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
6739 6739
 
6740 6740
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6741 6741
 						// set a higher timeout for big messages
@@ -6744,7 +6744,7 @@  discard block
 block discarded – undo
6744 6744
 						try {
6745 6745
 							$mailObject->send();
6746 6746
 						}
6747
-						catch(Exception $e) {
6747
+						catch (Exception $e) {
6748 6748
 							$sendOK = false;
6749 6749
 							$errorInfo = $e->getMessage();
6750 6750
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($errorInfo));
@@ -6758,41 +6758,41 @@  discard block
 block discarded – undo
6758 6758
 						$mailObject->clearCustomHeaders();
6759 6759
 
6760 6760
 						// Parse destinations for placeholders
6761
-						foreach(Mailer::$type2header as $type => $h)
6761
+						foreach (Mailer::$type2header as $type => $h)
6762 6762
 						{
6763
-							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset);
6763
+							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]), $val, $e, 'text/plain', array(), self::$displayCharset);
6764 6764
 							//error_log($type . ': ' . $mailObject->getHeader(Mailer::$type2header[$type]) . ' -> ' .$merged);
6765
-							$mailObject->addAddress(trim($merged,'"'),'',$type);
6765
+							$mailObject->addAddress(trim($merged, '"'), '', $type);
6766 6766
 						}
6767 6767
 
6768 6768
 						// No addresses from placeholders?  Treat it as just a contact ID
6769
-						if (count($mailObject->getAddresses('to',true)) == 0 &&
6769
+						if (count($mailObject->getAddresses('to', true)) == 0 &&
6770 6770
 							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)) // do the merge
6771 6771
 						{
6772 6772
 							$contact = $bo_merge->contacts->read($val);
6773 6773
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($contact));
6774 6774
 							$email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
6775 6775
 							$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
6776
-							if($email)
6776
+							if ($email)
6777 6777
 							{
6778 6778
 								$mailObject->addAddress(Horde_Idna::encode($email), $nfn);
6779 6779
 							}
6780 6780
 						}
6781 6781
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6782 6782
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6783
-						if (!empty($Body)) $text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
6783
+						if (!empty($Body)) $text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset), array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
6784 6784
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6785
-						if (!empty($AltBody)) $html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
6785
+						if (!empty($AltBody)) $html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset), array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
6786 6786
 						$_folder = $this->getDraftFolder();
6787 6787
 					}
6788 6788
 					if ($sendOK || $openAsDraft)
6789 6789
 					{
6790
-						if ($this->folderExists($_folder,true))
6790
+						if ($this->folderExists($_folder, true))
6791 6791
 						{
6792
-						    if($this->isSentFolder($_folder))
6792
+						    if ($this->isSentFolder($_folder))
6793 6793
 							{
6794 6794
 						        $flags = '\\Seen';
6795
-						    } elseif($this->isDraftFolder($_folder)) {
6795
+						    } elseif ($this->isDraftFolder($_folder)) {
6796 6796
 						        $flags = '\\Draft';
6797 6797
 						    } else {
6798 6798
 						        $flags = '';
@@ -6800,7 +6800,7 @@  discard block
 block discarded – undo
6800 6800
 							$savefailed = false;
6801 6801
 							try
6802 6802
 							{
6803
-								$messageUid =$this->appendMessage($_folder,
6803
+								$messageUid = $this->appendMessage($_folder,
6804 6804
 									$mailObject->getRaw(),
6805 6805
 									null,
6806 6806
 									$flags);
@@ -6808,10 +6808,10 @@  discard block
 block discarded – undo
6808 6808
 							catch (\Exception\WrongUserinput $e)
6809 6809
 							{
6810 6810
 								$savefailed = true;
6811
-								$alert_msg .= lang("Save of message %1 failed. Could not save message to folder %2 due to: %3",$Subject,$_folder,$e->getMessage());
6811
+								$alert_msg .= lang("Save of message %1 failed. Could not save message to folder %2 due to: %3", $Subject, $_folder, $e->getMessage());
6812 6812
 							}
6813 6813
 							// no send, save successful, and message_uid present
6814
-							if ($savefailed===false && $messageUid && is_null($sendOK))
6814
+							if ($savefailed === false && $messageUid && is_null($sendOK))
6815 6815
 							{
6816 6816
 								$importID = $messageUid;
6817 6817
 								$openComposeWindow = true;
@@ -6820,20 +6820,20 @@  discard block
 block discarded – undo
6820 6820
 						else
6821 6821
 						{
6822 6822
 							$savefailed = true;
6823
-							$alert_msg .= lang("Saving of message %1 failed. Destination Folder %2 does not exist.",$Subject,$_folder);
6823
+							$alert_msg .= lang("Saving of message %1 failed. Destination Folder %2 does not exist.", $Subject, $_folder);
6824 6824
 						}
6825 6825
 						if ($sendOK)
6826 6826
 						{
6827
-							$processStats['success'][$val] = 'Send succeeded to '.$nfn.'<'.$email.'>'.($savefailed?' but failed to store to Folder:'.$_folder:'');
6827
+							$processStats['success'][$val] = 'Send succeeded to '.$nfn.'<'.$email.'>'.($savefailed ? ' but failed to store to Folder:'.$_folder : '');
6828 6828
 						}
6829 6829
 						else
6830 6830
 						{
6831
-							if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6831
+							if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo ? $errorInfo : 'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6832 6832
 						}
6833 6833
 					}
6834
-					if (!is_null($sendOK) && $sendOK===false && is_null($openComposeWindow))
6834
+					if (!is_null($sendOK) && $sendOK === false && is_null($openComposeWindow))
6835 6835
 					{
6836
-						$processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6836
+						$processStats['failed'][$val] = $errorInfo ? $errorInfo : 'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
6837 6837
 					}
6838 6838
 				}
6839 6839
 			}
@@ -6903,19 +6903,18 @@  discard block
 block discarded – undo
6903 6903
 			//error_log(__METHOD__.__LINE__.':'.array2string($structure));
6904 6904
 
6905 6905
 			// unfortunately parseMessage does NOT return parsed headers (we assume header is shorter then 8k)
6906
-			$start = is_string($message) ? substr($message, 0, 8192) :
6907
-				(fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192));
6906
+			$start = is_string($message) ? substr($message, 0, 8192) : (fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192));
6908 6907
 
6909 6908
 			$length = strpos($start, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
6910
-			if ($length===false) $length = strlen($start);
6911
-			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0,$length));
6909
+			if ($length === false) $length = strlen($start);
6910
+			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0, $length));
6912 6911
 
6913
-			foreach($headers->toArray(array('nowrap' => true)) as $header => $value)
6912
+			foreach ($headers->toArray(array('nowrap' => true)) as $header => $value)
6914 6913
 			{
6915
-				foreach((array)$value as $n => $val)
6914
+				foreach ((array)$value as $n => $val)
6916 6915
 				{
6917 6916
 					$overwrite = !$n;
6918
-					switch($header)
6917
+					switch ($header)
6919 6918
 					{
6920 6919
 						case 'Content-Transfer-Encoding':
6921 6920
 							//as we parse the message and this sets the part with a Content-Transfer-Encoding, we
@@ -6936,7 +6935,7 @@  discard block
 block discarded – undo
6936 6935
 		}
6937 6936
 		else
6938 6937
 		{
6939
-			if (($type = gettype($message)) == 'object') $type = get_class ($message);
6938
+			if (($type = gettype($message)) == 'object') $type = get_class($message);
6940 6939
 			throw new Exception\WrongParameter('Wrong parameter type for message: '.$type);
6941 6940
 		}
6942 6941
 	}
@@ -6950,50 +6949,50 @@  discard block
 block discarded – undo
6950 6949
 	 * @param string $default_domain
6951 6950
 	 * @return Horde_Mail_Rfc822_List iteratable Horde_Mail_Rfc822_Address objects with attributes mailbox, host, personal and valid
6952 6951
 	 */
6953
-	public static function parseAddressList($addresses, $default_domain=null)
6952
+	public static function parseAddressList($addresses, $default_domain = null)
6954 6953
 	{
6955 6954
 		$rfc822 = new Horde_Mail_Rfc822();
6956 6955
 		$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
6957 6956
 		//error_log(__METHOD__.__LINE__.'#'.array2string($addresses).'#'.array2string($ret).'#'.$ret->count().'#'.$ret->count.function_backtrace());
6958
-		if ((empty($ret) || $ret->count()==0)&& is_string($addresses) && strlen($addresses)>0)
6957
+		if ((empty($ret) || $ret->count() == 0) && is_string($addresses) && strlen($addresses) > 0)
6959 6958
 		{
6960 6959
 			$matches = array();
6961
-			preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/",$addresses,$matches);
6960
+			preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/", $addresses, $matches);
6962 6961
 			//error_log(__METHOD__.__LINE__.array2string($matches));
6963
-			foreach ($matches[0] as &$match) {$match = trim($match,', ');}
6964
-			$addresses = implode(',',$matches[0]);
6962
+			foreach ($matches[0] as &$match) {$match = trim($match, ', '); }
6963
+			$addresses = implode(',', $matches[0]);
6965 6964
 			//error_log(__METHOD__.__LINE__.array2string($addresses));
6966 6965
 			$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
6967 6966
 			//error_log(__METHOD__.__LINE__.'#'.array2string($addresses).'#'.array2string($ret).'#'.$ret->count().'#'.$ret->count);
6968 6967
 		}
6969
-		$previousFailed=false;
6968
+		$previousFailed = false;
6970 6969
 		$ret2 = new Horde_Mail_Rfc822_List();
6971 6970
 		// handle known problems on emailaddresses
6972
-		foreach($ret as $i => $adr)
6971
+		foreach ($ret as $i => $adr)
6973 6972
 		{
6974 6973
 			//mailaddresses enclosed in single quotes like '[email protected]' show up as 'me as mailbox and you.com' as host
6975
-			if ($adr->mailbox && stripos($adr->mailbox,"'")== 0 &&
6976
-					$adr->host && stripos($adr->host,"'")== (strlen($adr->host) -1))
6974
+			if ($adr->mailbox && stripos($adr->mailbox, "'") == 0 &&
6975
+					$adr->host && stripos($adr->host, "'") == (strlen($adr->host) - 1))
6977 6976
 			{
6978
-				$adr->mailbox = str_replace("'","",$adr->mailbox);
6979
-				$adr->host = str_replace("'","",$adr->host);
6977
+				$adr->mailbox = str_replace("'", "", $adr->mailbox);
6978
+				$adr->host = str_replace("'", "", $adr->host);
6980 6979
 			}
6981 6980
 			// no mailbox or host part as 'Xr\xc3\xa4hlyz, User <[email protected]>' is parsed as 2 addresses separated by ','
6982 6981
 			//#'Xr\xc3\xa4hlyz, User <[email protected]>'
6983 6982
 			//#Horde_Mail_Rfc822_List Object([_data:protected] => Array(
6984 6983
 			//[0] => Horde_Mail_Rfc822_Address Object([comment] => Array()[mailbox] => Xr\xc3\xa4hlyz[_host:protected] => [_personal:protected] => )
6985 6984
 			//[1] => Horde_Mail_Rfc822_Address Object([comment] => Array()[mailbox] => mailboxpart1.mailboxpart2[_host:protected] => youthost.com[_personal:protected] => User))[_filter:protected] => Array()[_ptr:protected] => )#2#,
6986
-			if (strlen($adr->mailbox)==0||strlen($adr->host)==0)
6985
+			if (strlen($adr->mailbox) == 0 || strlen($adr->host) == 0)
6987 6986
 			{
6988
-				$remember = ($adr->mailbox?$adr->mailbox:($adr->host?$adr->host:''));
6989
-				$previousFailed=true;
6987
+				$remember = ($adr->mailbox ? $adr->mailbox : ($adr->host ? $adr->host : ''));
6988
+				$previousFailed = true;
6990 6989
 				//error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal");
6991 6990
 			}
6992 6991
 			else
6993 6992
 			{
6994
-				if ($previousFailed && $remember) $adr->personal = $remember. ' ' . $adr->personal;
6993
+				if ($previousFailed && $remember) $adr->personal = $remember.' '.$adr->personal;
6995 6994
 				$remember = '';
6996
-				$previousFailed=false;
6995
+				$previousFailed = false;
6997 6996
 				//error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal");
6998 6997
 				$ret2->add($adr);
6999 6998
 			}
@@ -7009,7 +7008,7 @@  discard block
 block discarded – undo
7009 7008
 	 * @param string $_folder
7010 7009
 	 * @return boolean
7011 7010
 	 */
7012
-	function sendMDN($uid,$_folder)
7011
+	function sendMDN($uid, $_folder)
7013 7012
 	{
7014 7013
 		$acc = Mail\Account::read($this->profileID);
7015 7014
 		$identity = Mail\Account::read_identity($acc['ident_id'], true, null, $acc);
@@ -7039,7 +7038,7 @@  discard block
 block discarded – undo
7039 7038
 	 */
7040 7039
 	function addAccount($_hookValues)
7041 7040
 	{
7042
-		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!' . ' hookValue = '. $_hookValues);
7041
+		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!'.' hookValue = '.$_hookValues);
7043 7042
 
7044 7043
 	}
7045 7044
 
@@ -7053,7 +7052,7 @@  discard block
 block discarded – undo
7053 7052
 	 */
7054 7053
 	function deleteAccount($_hookValues)
7055 7054
 	{
7056
-		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!' . ' hookValue = '. $_hookValues);
7055
+		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!'.' hookValue = '.$_hookValues);
7057 7056
 
7058 7057
 	}
7059 7058
 
@@ -7067,7 +7066,7 @@  discard block
 block discarded – undo
7067 7066
 	 */
7068 7067
 	function updateAccount($_hookValues)
7069 7068
 	{
7070
-		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!' . ' hookValue = '. $_hookValues);
7069
+		error_log(__METHOD__.' ('.__LINE__.') '.' NOT DONE YET!'.' hookValue = '.$_hookValues);
7071 7070
 
7072 7071
 	}
7073 7072
 }
Please login to merge, or discard this patch.
Braces   +1778 added lines, -527 removed lines patch added patch discarded remove patch
@@ -199,7 +199,10 @@  discard block
 block discarded – undo
199 199
 	public static function getInstance($_restoreSession=true, &$_profileID=0, $_validate=true, $_oldImapServerObject=false, $_reuseCache=null)
200 200
 	{
201 201
 		//$_restoreSession=false;
202
-		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
202
+		if (is_null($_reuseCache))
203
+		{
204
+			$_reuseCache = $_restoreSession;
205
+		}
203 206
 		//error_log(__METHOD__.' ('.__LINE__.') '.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID.'/'.Mail\Account::get_default_acc_id().' for user:'.$GLOBALS['egw_info']['user']['account_lid'].' called from:'.function_backtrace());
204 207
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_oldImapServerObject));
205 208
 		if (isset(self::$profileDefunct[$_profileID]) && self::$profileDefunct[$_profileID]===true)
@@ -229,9 +232,15 @@  discard block
 block discarded – undo
229 232
 			{
230 233
 				$profileID = Mail\Account::get_default_acc_id();
231 234
 			}
232
-			if ($profileID!=$_profileID) $_restoreSession==false;
235
+			if ($profileID!=$_profileID)
236
+			{
237
+				$_restoreSession==false;
238
+			}
233 239
 			$_profileID=$profileID;
234
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace());
240
+			if (self::$debug)
241
+			{
242
+				error_log(__METHOD__.' ('.__LINE__.') '.' called with profileID==0 using '.$profileID.' instead->'.function_backtrace());
243
+			}
235 244
 		}
236 245
 		// no validation or restoreSession for old ImapServer Object, just fetch it and return it
237 246
 		if ($_oldImapServerObject===true)
@@ -270,7 +279,8 @@  discard block
 block discarded – undo
270 279
 				// TODO: merge mailprefs into userprefs, for easy treatment
271 280
 				self::$instances[$_profileID]->mailPreferences = $GLOBALS['egw_info']['user']['preferences']['mail'];
272 281
 				self::$instances[$_profileID]->htmlOptions  = self::$instances[$_profileID]->mailPreferences['htmlOptions'];
273
-			} catch (\Exception $e)
282
+			}
283
+			catch (\Exception $e)
274 284
 			{
275 285
 				$newprofileID = Mail\Account::get_default_acc_id();
276 286
 				// try loading the default profile for the user
@@ -288,9 +298,15 @@  discard block
 block discarded – undo
288 298
 			self::storeActiveProfileIDToPref(self::$instances[$_profileID]->icServer, $_profileID, $_validate );
289 299
 		}
290 300
 		self::$instances[$_profileID]->profileID = $_profileID;
291
-		if (!isset(self::$instances[$_profileID]->idna2)) self::$instances[$_profileID]->idna2 = new Horde_Idna;
301
+		if (!isset(self::$instances[$_profileID]->idna2))
302
+		{
303
+			self::$instances[$_profileID]->idna2 = new Horde_Idna;
304
+		}
292 305
 		//if ($_profileID==0); error_log(__METHOD__.' ('.__LINE__.') '.' RestoreSession:'.$_restoreSession.' ProfileId:'.$_profileID);
293
-		if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
306
+		if (is_null(self::$mailConfig))
307
+		{
308
+			self::$mailConfig = Config::read('mail');
309
+		}
294 310
 		return self::$instances[$_profileID];
295 311
 	}
296 312
 
@@ -315,14 +331,20 @@  discard block
 block discarded – undo
315 331
 			}
316 332
 			catch (\Exception $e)
317 333
 			{
318
-				if ($_profileID != Mail\Account::get_default_acc_id()) $_profileID = Mail\Account::get_default_acc_id();
334
+				if ($_profileID != Mail\Account::get_default_acc_id())
335
+				{
336
+					$_profileID = Mail\Account::get_default_acc_id();
337
+				}
319 338
 				error_log(__METHOD__.__LINE__.' '.$e->getMessage());
320 339
 				return false;
321 340
 			}
322 341
 		}
323 342
 		if ($oldProfileID != $_profileID)
324 343
 		{
325
-			if ($oldProfileID && $_profileID==0) $_profileID = $oldProfileID;
344
+			if ($oldProfileID && $_profileID==0)
345
+			{
346
+				$_profileID = $oldProfileID;
347
+			}
326 348
 			$GLOBALS['egw']->preferences->add('mail','ActiveProfileID',$_profileID,'user');
327 349
 			// save prefs
328 350
 			$GLOBALS['egw']->preferences->save_repository(true);
@@ -352,11 +374,17 @@  discard block
 block discarded – undo
352 374
 				{
353 375
 					return $_acc_id;
354 376
 				}
355
-				if (self::$debug) error_log(__METHOD__."($_acc_id) account NOT valid, no imap-host!");
377
+				if (self::$debug)
378
+				{
379
+					error_log(__METHOD__."($_acc_id) account NOT valid, no imap-host!");
380
+				}
356 381
 			}
357 382
 			catch (\Exception $e) {
358 383
 				unset($e);
359
-				if (self::$debug) error_log(__METHOD__."($_acc_id) account NOT found!");
384
+				if (self::$debug)
385
+				{
386
+					error_log(__METHOD__."($_acc_id) account NOT found!");
387
+				}
360 388
 			}
361 389
 		}
362 390
 		// no account specified or specified account not found or not valid
@@ -365,11 +393,17 @@  discard block
 block discarded – undo
365 393
 		{
366 394
 			if (!empty($imap_host) && ($account = Mail\Account::read($acc_id)) && $account->is_imap())
367 395
 			{
368
-				if (self::$debug && $_acc_id) error_log(__METHOD__."($_acc_id) using $acc_id instead");
396
+				if (self::$debug && $_acc_id)
397
+				{
398
+					error_log(__METHOD__."($_acc_id) using $acc_id instead");
399
+				}
369 400
 				return $acc_id;
370 401
 			}
371 402
 		}
372
-		if (self::$debug) error_log(__METHOD__."($_acc_id) NO valid account found!");
403
+		if (self::$debug)
404
+		{
405
+			error_log(__METHOD__."($_acc_id) NO valid account found!");
406
+		}
373 407
 		return 0;
374 408
 	}
375 409
 
@@ -385,10 +419,19 @@  discard block
 block discarded – undo
385 419
 	 */
386 420
 	private function __construct($_displayCharset='utf-8',$_restoreSession=true, $_profileID=0, $_oldImapServerObject=false, $_reuseCache=null)
387 421
 	{
388
-		if (is_null($_reuseCache)) $_reuseCache = $_restoreSession;
389
-		if (!empty($_displayCharset)) self::$displayCharset = $_displayCharset;
422
+		if (is_null($_reuseCache))
423
+		{
424
+			$_reuseCache = $_restoreSession;
425
+		}
426
+		if (!empty($_displayCharset))
427
+		{
428
+			self::$displayCharset = $_displayCharset;
429
+		}
390 430
 		// not nummeric, we assume we only want an empty class object
391
-		if (!is_numeric($_profileID)) return true;
431
+		if (!is_numeric($_profileID))
432
+		{
433
+			return true;
434
+		}
392 435
 		if ($_restoreSession)
393 436
 		{
394 437
 			//error_log(__METHOD__." Session restore ".function_backtrace());
@@ -403,7 +446,10 @@  discard block
 block discarded – undo
403 446
 			$firstMessage = $this->sessionData['previewMessage'];
404 447
 			$this->sessionData = array();
405 448
 		}
406
-		if (!$_reuseCache) $this->forcePrefReload($_profileID,!$_reuseCache);
449
+		if (!$_reuseCache)
450
+		{
451
+			$this->forcePrefReload($_profileID,!$_reuseCache);
452
+		}
407 453
 		try
408 454
 		{
409 455
 			$this->profileID = self::validateProfileID($_profileID);
@@ -427,7 +473,10 @@  discard block
 block discarded – undo
427 473
 			$_profileID = $this->profileID = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] = $this->icServer->ImapServerId;
428 474
 		}
429 475
 
430
-		if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
476
+		if (is_null(self::$mailConfig))
477
+		{
478
+			self::$mailConfig = Config::read('mail');
479
+		}
431 480
 	}
432 481
 
433 482
 	/**
@@ -456,7 +505,10 @@  discard block
 block discarded – undo
456 505
 		// unset the mail_preferences session object, to force the reload/rebuild
457 506
 		Cache::setSession('mail','mail_preferences',serialize(array()));
458 507
 		Cache::setSession('emailadmin','session_data',serialize(array()));
459
-		if ($_resetFolderObjects) self::resetFolderObjectCache($_profile_id);
508
+		if ($_resetFolderObjects)
509
+		{
510
+			self::resetFolderObjectCache($_profile_id);
511
+		}
460 512
 	}
461 513
 
462 514
 	/**
@@ -466,7 +518,10 @@  discard block
 block discarded – undo
466 518
 	{
467 519
 		$this->sessionData = array();//Cache::getCache(Cache::SESSION,'mail','session_data',$callback=null,$callback_params=array(),$expiration=60*60*1);
468 520
 		self::$activeFolderCache = Cache::getCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
469
-		if (!empty(self::$activeFolderCache[$this->profileID])) $this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID];
521
+		if (!empty(self::$activeFolderCache[$this->profileID]))
522
+		{
523
+			$this->sessionData['mailbox'] = self::$activeFolderCache[$this->profileID];
524
+		}
470 525
 	}
471 526
 
472 527
 	/**
@@ -475,7 +530,10 @@  discard block
 block discarded – undo
475 530
 	function saveSessionData()
476 531
 	{
477 532
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($this->sessionData)));
478
-		if (!empty($this->sessionData['mailbox'])) self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox'];
533
+		if (!empty($this->sessionData['mailbox']))
534
+		{
535
+			self::$activeFolderCache[$this->profileID]=$this->sessionData['mailbox'];
536
+		}
479 537
 		if (isset(self::$activeFolderCache) && is_array(self::$activeFolderCache))
480 538
 		{
481 539
 			Cache::setCache(Cache::INSTANCE,'email','activeMailbox'.trim($GLOBALS['egw_info']['user']['account_id']),self::$activeFolderCache, 60*60*10);
@@ -496,8 +554,14 @@  discard block
 block discarded – undo
496 554
 	 */
497 555
 	static function unsetCachedObjects($_profileID=null)
498 556
 	{
499
-		if (is_null($_profileID)) $_profileID = Mail\Account::get_default_acc_id();
500
-		if (is_array($_profileID) && $_profileID['account_id']) $account_id = $_profileID['account_id'];
557
+		if (is_null($_profileID))
558
+		{
559
+			$_profileID = Mail\Account::get_default_acc_id();
560
+		}
561
+		if (is_array($_profileID) && $_profileID['account_id'])
562
+		{
563
+			$account_id = $_profileID['account_id'];
564
+		}
501 565
 		//error_log(__METHOD__.__LINE__.' called with ProfileID:'.array2string($_profileID).' from '.function_backtrace());
502 566
 		if (!is_array($_profileID) && (is_numeric($_profileID) || !(stripos($_profileID,'tracker_')===false)))
503 567
 		{
@@ -530,7 +594,10 @@  discard block
 block discarded – undo
530 594
 				Cache::setCache(Cache::INSTANCE,'email','vacationNotice'.trim($account_id),$vacationCached, $expiration=60*60*24*1);
531 595
 			}
532 596
 
533
-			if (isset(self::$instances[$_profileID])) unset(self::$instances[$_profileID]);
597
+			if (isset(self::$instances[$_profileID]))
598
+			{
599
+				unset(self::$instances[$_profileID]);
600
+			}
534 601
 		}
535 602
 		if (is_array($_profileID) && $_profileID['location'] == 'clear_cache')
536 603
 		{
@@ -559,7 +626,10 @@  discard block
 block discarded – undo
559 626
 	static function resetConnectionErrorCache($_ImapServerId=null,$account_id=null)
560 627
 	{
561 628
 		//error_log(__METHOD__.' ('.__LINE__.') '.' for Profile:'.array2string($_ImapServerId) .' for user:'.trim($account_id));
562
-		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
629
+		if (is_null($account_id))
630
+		{
631
+			$account_id = $GLOBALS['egw_info']['user']['account_id'];
632
+		}
563 633
 		if (is_array($_ImapServerId))
564 634
 		{
565 635
 			// called via hook
@@ -598,7 +668,10 @@  discard block
 block discarded – undo
598 668
 	static function resetFolderObjectCache($_ImapServerId=null,$account_id=null)
599 669
 	{
600 670
 		//error_log(__METHOD__.' ('.__LINE__.') '.' called for Profile:'.array2string($_ImapServerId).'->'.function_backtrace());
601
-		if (is_null($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
671
+		if (is_null($account_id))
672
+		{
673
+			$account_id = $GLOBALS['egw_info']['user']['account_id'];
674
+		}
602 675
 		// on [location] => verify_settings we coud either use [prefs] => Array([ActiveProfileID] => 9, .. as $_ImapServerId
603 676
 		// or treat it as not given. we try that path
604 677
 		if (is_null($_ImapServerId)||is_array($_ImapServerId))
@@ -672,10 +745,14 @@  discard block
 block discarded – undo
672 745
 
673 746
 		$userEMailAdresses = array($acc['ident_email']=>$acc['ident_realname']);
674 747
 
675
-		foreach($identities as $ik => $ident) {
748
+		foreach($identities as $ik => $ident)
749
+		{
676 750
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
677 751
 			$identity = Mail\Account::read_identity($ik);
678
-			if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']])) $userEMailAdresses[$identity['ident_email']] = $identity['ident_realname'];
752
+			if (!empty($identity['ident_email']) && !isset($userEMailAdresses[$identity['ident_email']]))
753
+			{
754
+				$userEMailAdresses[$identity['ident_email']] = $identity['ident_realname'];
755
+			}
679 756
 		}
680 757
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses));
681 758
 		return $userEMailAdresses;
@@ -693,13 +770,20 @@  discard block
 block discarded – undo
693 770
 		foreach(Mail\Account::search($only_current_user=($_accountToSearch?$_accountToSearch:true), $just_name=true) as $acc_id => $identity_name)
694 771
 		{
695 772
 			$acc = Mail\Account::read($acc_id,($_accountToSearch?$_accountToSearch:null));
696
-			if (!$resolve_placeholders) $userEMailAdresses[$acc['ident_id']] = array('acc_id'=>$acc_id,'ident_id'=>$acc['ident_id'],'ident_email'=>$acc['ident_email'],'ident_org'=>$acc['ident_org'],'ident_realname'=>$acc['ident_realname'],'ident_signature'=>$acc['ident_signature'],'ident_name'=>$acc['ident_name']);
773
+			if (!$resolve_placeholders)
774
+			{
775
+				$userEMailAdresses[$acc['ident_id']] = array('acc_id'=>$acc_id,'ident_id'=>$acc['ident_id'],'ident_email'=>$acc['ident_email'],'ident_org'=>$acc['ident_org'],'ident_realname'=>$acc['ident_realname'],'ident_signature'=>$acc['ident_signature'],'ident_name'=>$acc['ident_name']);
776
+			}
697 777
 
698
-			foreach(Mail\Account::identities($acc) as $ik => $ident) {
778
+			foreach(Mail\Account::identities($acc) as $ik => $ident)
779
+			{
699 780
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
700 781
 				$identity = Mail\Account::read_identity($ik,$resolve_placeholders);
701 782
 				//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
702
-				if (!isset($userEMailAdresses[$identity['ident_id']])) $userEMailAdresses[$identity['ident_id']] = array('acc_id'=>$acc_id,'ident_id'=>$identity['ident_id'],'ident_email'=>$identity['ident_email'],'ident_org'=>$identity['ident_org'],'ident_realname'=>$identity['ident_realname'],'ident_signature'=>$identity['ident_signature'],'ident_name'=>$identity['ident_name']);
783
+				if (!isset($userEMailAdresses[$identity['ident_id']]))
784
+				{
785
+					$userEMailAdresses[$identity['ident_id']] = array('acc_id'=>$acc_id,'ident_id'=>$identity['ident_id'],'ident_email'=>$identity['ident_email'],'ident_org'=>$identity['ident_org'],'ident_realname'=>$identity['ident_realname'],'ident_signature'=>$identity['ident_signature'],'ident_name'=>$identity['ident_name']);
786
+				}
703 787
 			}
704 788
 		}
705 789
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($userEMailAdresses));
@@ -719,12 +803,16 @@  discard block
 block discarded – undo
719 803
 			$account = Mail\Account::read($account);
720 804
 		}
721 805
 		$userEMailAdresses = array();
722
-		foreach(Mail\Account::identities($account, true, 'params') as $ik => $ident) {
806
+		foreach(Mail\Account::identities($account, true, 'params') as $ik => $ident)
807
+		{
723 808
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($ident));
724 809
 			$identity = Mail\Account::read_identity($ik,true,null,$account);
725 810
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.$ik.'->'.array2string($identity));
726 811
 			// standardIdentity has ident_id==acc_id (as it is done within account->identities)
727
-			if (empty($identity['ident_id'])) $identity['ident_id'] = $identity['acc_id'];
812
+			if (empty($identity['ident_id']))
813
+			{
814
+				$identity['ident_id'] = $identity['acc_id'];
815
+			}
728 816
 			if (!isset($userEMailAdresses[$identity['ident_id']]))
729 817
 			{
730 818
 				$userEMailAdresses[$identity['ident_id']] = array('acc_id'=>$identity['acc_id'],
@@ -767,15 +855,25 @@  discard block
 block discarded – undo
767 855
 		// account select box
768 856
 		$selectedID = $this->profileID;
769 857
 		$allAccountData = Mail\Account::search($only_current_user=true, false, null);
770
-		if ($allAccountData) {
858
+		if ($allAccountData)
859
+		{
771 860
 			$rememberFirst=$selectedFound=null;
772 861
 			foreach ($allAccountData as $tmpkey => $icServers)
773 862
 			{
774
-				if (is_null($rememberFirst)) $rememberFirst = $tmpkey;
775
-				if ($tmpkey == $selectedID) $selectedFound=true;
863
+				if (is_null($rememberFirst))
864
+				{
865
+					$rememberFirst = $tmpkey;
866
+				}
867
+				if ($tmpkey == $selectedID)
868
+				{
869
+					$selectedFound=true;
870
+				}
776 871
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($icServers->acc_imap_host));
777 872
 				$host = $icServers->acc_imap_host;
778
-				if (empty($host)) continue;
873
+				if (empty($host))
874
+				{
875
+					continue;
876
+				}
779 877
 				$identities[$icServers->acc_id] = $icServers['ident_realname'].' '.$icServers['ident_org'].' <'.$icServers['ident_email'].'>';
780 878
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Key:'.$tmpkey.'->'.array2string($identities[$icServers->acc_id]));
781 879
 			}
@@ -835,7 +933,10 @@  discard block
 block discarded – undo
835 933
 	 */
836 934
 	function reopen($_foldername)
837 935
 	{
838
-		if (self::$debugTimes) $starttime = microtime (true);
936
+		if (self::$debugTimes)
937
+		{
938
+			$starttime = microtime (true);
939
+		}
839 940
 
840 941
 		//error_log(__METHOD__.' ('.__LINE__.') '."('$_foldername') ".function_backtrace());
841 942
 		// TODO: trying to reduce traffic to the IMAP Server here, introduces problems with fetching the bodies of
@@ -845,12 +946,16 @@  discard block
 block discarded – undo
845 946
 		//{
846 947
 			//error_log( __METHOD__.' ('.__LINE__.') '." $_foldername ".function_backtrace());
847 948
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Connected with icServer for Profile:'.$this->profileID.'?'.print_r($this->icServer->_connected,true));
848
-			if ($this->folderIsSelectable($_foldername)) {
949
+			if ($this->folderIsSelectable($_foldername))
950
+			{
849 951
 				$this->icServer->openMailbox($_foldername);
850 952
 			}
851 953
 			$folderOpened = $_foldername;
852 954
 		//}
853
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') ');
955
+		if (self::$debugTimes)
956
+		{
957
+			self::logRunTimes($starttime,null,'Folder:'.$_foldername,__METHOD__.' ('.__LINE__.') ');
958
+		}
854 959
 	}
855 960
 
856 961
 
@@ -865,13 +970,22 @@  discard block
 block discarded – undo
865 970
 	{
866 971
 		//error_log( "-------------------------->open connection ".function_backtrace());
867 972
 		//error_log(__METHOD__.' ('.__LINE__.') '.' ->'.array2string($this->icServer));
868
-		if (self::$debugTimes) $starttime = microtime (true);
973
+		if (self::$debugTimes)
974
+		{
975
+			$starttime = microtime (true);
976
+		}
869 977
 		$mailbox=null;
870 978
 		try
871 979
 		{
872
-			if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox'])) $mailbox = $this->sessionData['mailbox'];
873
-			if (empty($mailbox)) $mailbox = $this->icServer->getCurrentMailbox();
874
-/*
980
+			if(isset($this->sessionData['mailbox'])&&$this->folderExists($this->sessionData['mailbox']))
981
+			{
982
+				$mailbox = $this->sessionData['mailbox'];
983
+			}
984
+			if (empty($mailbox))
985
+			{
986
+				$mailbox = $this->icServer->getCurrentMailbox();
987
+			}
988
+			/*
875 989
 			if (isset(Mail\Imap::$supports_keywords[$_icServerID]))
876 990
 			{
877 991
 				$this->icServer->openMailbox($mailbox);
@@ -896,7 +1010,10 @@  discard block
 block discarded – undo
896 1010
 			error_log(__METHOD__.' ('.__LINE__.') '."->open connection for Server with profileID:".$_icServerID." trying to examine ($mailbox) failed!".$e->getMessage());
897 1011
 			throw new Exception(__METHOD__." failed to ".__METHOD__." on Profile to $_icServerID while trying to examine $mailbox:".$e->getMessage());
898 1012
 		}
899
-		if (self::$debugTimes) self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') ');
1013
+		if (self::$debugTimes)
1014
+		{
1015
+			self::logRunTimes($starttime,null,'ProfileID:'.$_icServerID,__METHOD__.' ('.__LINE__.') ');
1016
+		}
900 1017
 	}
901 1018
 
902 1019
 	/**
@@ -908,7 +1025,10 @@  discard block
 block discarded – undo
908 1025
 	function getQuotaRoot()
909 1026
 	{
910 1027
 		static $quota;
911
-		if (isset($quota)) return $quota;
1028
+		if (isset($quota))
1029
+		{
1030
+			return $quota;
1031
+		}
912 1032
 		if (isset(self::$profileDefunct[$this->profileID]) && self::$profileDefunct[$this->profileID]===true)
913 1033
 		{
914 1034
 			// something is wrong. Do not proceed. either no folder or profile is marked as defunct for this request
@@ -917,7 +1037,8 @@  discard block
 block discarded – undo
917 1037
 		try
918 1038
 		{
919 1039
 			$this->icServer->getCurrentMailbox();
920
-			if(!$this->icServer->hasCapability('QUOTA')) {
1040
+			if(!$this->icServer->hasCapability('QUOTA'))
1041
+			{
921 1042
 				$quota = false;
922 1043
 				return false;
923 1044
 			}
@@ -934,12 +1055,15 @@  discard block
 block discarded – undo
934 1055
 			}
935 1056
 		}
936 1057
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($quota));
937
-		if(is_array($quota)) {
1058
+		if(is_array($quota))
1059
+		{
938 1060
 			$quota = array(
939 1061
 				'usage'	=> $quota['USED'],
940 1062
 				'limit'	=> $quota['QMAX'],
941 1063
 			);
942
-		} else {
1064
+		}
1065
+		else
1066
+		{
943 1067
 			$quota = false;
944 1068
 		}
945 1069
 		return $quota;
@@ -955,7 +1079,11 @@  discard block
 block discarded – undo
955 1079
 	static function getTimeOut($_use='IMAP')
956 1080
 	{
957 1081
 		$timeout = $GLOBALS['egw_info']['user']['preferences']['mail']['connectionTimeout'];
958
-		if (empty($timeout)) $timeout = ($_use=='SIEVE'?10:20); // this is the default value
1082
+		if (empty($timeout))
1083
+		{
1084
+			$timeout = ($_use=='SIEVE'?10:20);
1085
+		}
1086
+		// this is the default value
959 1087
 		return $timeout;
960 1088
 	}
961 1089
 
@@ -973,9 +1101,13 @@  discard block
 block discarded – undo
973 1101
 		$foldersNameSpace = array();
974 1102
 		$delimiter = $this->getHierarchyDelimiter();
975 1103
 		// TODO: cache by $this->icServer->ImapServerId
976
-		if (is_null($nameSpace)) $nameSpace = $this->icServer->getNameSpaceArray();
1104
+		if (is_null($nameSpace))
1105
+		{
1106
+			$nameSpace = $this->icServer->getNameSpaceArray();
1107
+		}
977 1108
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($nameSpace));
978
-		if (is_array($nameSpace)) {
1109
+		if (is_array($nameSpace))
1110
+		{
979 1111
 			foreach($nameSpace as $type => $singleNameSpaceArray)
980 1112
 			{
981 1113
 				foreach ($singleNameSpaceArray as $singleNameSpace)
@@ -992,7 +1124,9 @@  discard block
 block discarded – undo
992 1124
 						$_foldersNameSpace['prefix_present'] = 'forced';
993 1125
 						// uw-imap server with mailbox prefix or dovecot maybe
994 1126
 						$_foldersNameSpace['prefix'] = 'mail';
995
-					} else {
1127
+					}
1128
+					else
1129
+					{
996 1130
 						$_foldersNameSpace['prefix_present'] = !empty($singleNameSpace['name']);
997 1131
 						$_foldersNameSpace['prefix'] = $singleNameSpace['name'];
998 1132
 					}
@@ -1019,7 +1153,10 @@  discard block
 block discarded – undo
1019 1153
 		foreach($nameSpace as &$singleNameSpace)
1020 1154
 		{
1021 1155
 			//if (substr($singleNameSpace['prefix'],0,strlen($folderName))==$folderName) return $singleNameSpace['prefix'];
1022
-			if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix']) return $singleNameSpace['prefix'];
1156
+			if (substr($folderName,0,strlen($singleNameSpace['prefix']))==$singleNameSpace['prefix'])
1157
+			{
1158
+				return $singleNameSpace['prefix'];
1159
+			}
1023 1160
 		}
1024 1161
 		return "";
1025 1162
 	}
@@ -1033,8 +1170,14 @@  discard block
 block discarded – undo
1033 1170
 	function getHierarchyDelimiter($_useCache=true)
1034 1171
 	{
1035 1172
 		static $HierarchyDelimiter = null;
1036
-		if (is_null($HierarchyDelimiter)) $HierarchyDelimiter = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1037
-		if ($_useCache===false) unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1173
+		if (is_null($HierarchyDelimiter))
1174
+		{
1175
+			$HierarchyDelimiter = Cache::getCache(Cache::INSTANCE,'email','HierarchyDelimiter'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1176
+		}
1177
+		if ($_useCache===false)
1178
+		{
1179
+			unset($HierarchyDelimiter[$this->icServer->ImapServerId]);
1180
+		}
1038 1181
 		if (isset($HierarchyDelimiter[$this->icServer->ImapServerId])&&!empty($HierarchyDelimiter[$this->icServer->ImapServerId]))
1039 1182
 		{
1040 1183
 			return $HierarchyDelimiter[$this->icServer->ImapServerId];
@@ -1047,7 +1190,10 @@  discard block
 block discarded – undo
1047 1190
 		}
1048 1191
 		catch(\Exception $e)
1049 1192
 		{
1050
-			if ($e->getCode()==102) self::$profileDefunct[$this->profileID]=true;
1193
+			if ($e->getCode()==102)
1194
+			{
1195
+				self::$profileDefunct[$this->profileID]=true;
1196
+			}
1051 1197
 			unset($e);
1052 1198
 			$HierarchyDelimiter[$this->icServer->ImapServerId] = '/';
1053 1199
 		}
@@ -1064,14 +1210,19 @@  discard block
 block discarded – undo
1064 1210
 	{
1065 1211
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$this->icServer->ImapServerId.' Connected:'.$this->icServer->_connected);
1066 1212
 		static $_specialUseFolders = null;
1067
-		if (is_null($_specialUseFolders)||empty($_specialUseFolders)) $_specialUseFolders = Cache::getCache(Cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1213
+		if (is_null($_specialUseFolders)||empty($_specialUseFolders))
1214
+		{
1215
+			$_specialUseFolders = Cache::getCache(Cache::INSTANCE,'email','specialUseFolders'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*24*5);
1216
+		}
1068 1217
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_trash));
1069 1218
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_sent));
1070 1219
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_draft));
1071 1220
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($this->icServer->acc_folder_template));
1072 1221
 		self::$specialUseFolders = $_specialUseFolders[$this->icServer->ImapServerId];
1073 1222
 		if (isset($_specialUseFolders[$this->icServer->ImapServerId]) && !empty($_specialUseFolders[$this->icServer->ImapServerId]))
1074
-			return $_specialUseFolders[$this->icServer->ImapServerId];
1223
+		{
1224
+					return $_specialUseFolders[$this->icServer->ImapServerId];
1225
+		}
1075 1226
 		$_specialUseFolders[$this->icServer->ImapServerId]=array();
1076 1227
 		//if (!empty($this->icServer->acc_folder_trash) && !isset($_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]))
1077 1228
 			$_specialUseFolders[$this->icServer->ImapServerId][$this->icServer->acc_folder_trash]='Trash';
@@ -1099,7 +1250,8 @@  discard block
 block discarded – undo
1099 1250
 	function folderIsSelectable($folderToSelect)
1100 1251
 	{
1101 1252
 		$retval = true;
1102
-		if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true))) {
1253
+		if($folderToSelect && ($folderStatus = $this->getFolderStatus($folderToSelect,false,true)))
1254
+		{
1103 1255
 			if (!empty($folderStatus['attributes']) && stripos(array2string($folderStatus['attributes']),'noselect')!==false)
1104 1256
 			{
1105 1257
 				$retval = false;
@@ -1152,7 +1304,10 @@  discard block
 block discarded – undo
1152 1304
 	 */
1153 1305
 	function getFolderStatus($_folderName,$ignoreStatusCache=false,$basicInfoOnly=false,$fetchSubscribedInfo=true)
1154 1306
 	{
1155
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly");
1307
+		if (self::$debug)
1308
+		{
1309
+			error_log(__METHOD__.' ('.__LINE__.') '." called with:$_folderName,$ignoreStatusCache,$basicInfoOnly");
1310
+		}
1156 1311
 		if (!is_string($_folderName) || empty($_folderName)||(isset(self::$profileDefunct[$this->profileID]) && self::$profileDefunct[$this->profileID]===true))
1157 1312
 		{
1158 1313
 			// something is wrong. Do not proceed. either no folder or profile is marked as defunct for this request
@@ -1164,7 +1319,10 @@  discard block
 block discarded – undo
1164 1319
 		{
1165 1320
 			$folderInfoCache = $folderBasicInfo[$this->profileID];
1166 1321
 		}
1167
-		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly) return $folderInfoCache[$_folderName];
1322
+		if (isset($folderInfoCache[$_folderName]) && $ignoreStatusCache==false && $basicInfoOnly)
1323
+		{
1324
+			return $folderInfoCache[$_folderName];
1325
+		}
1168 1326
 		$retValue = array();
1169 1327
 		$retValue['subscribed'] = false;
1170 1328
 /*
@@ -1192,7 +1350,10 @@  discard block
 block discarded – undo
1192 1350
 			if (is_array($ret))
1193 1351
 			{
1194 1352
 				$retkeys = array_keys($ret);
1195
-				if ($retkeys[0]==$_folderName) $folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1353
+				if ($retkeys[0]==$_folderName)
1354
+				{
1355
+					$folderInfoCache[$_folderName] = $ret[$retkeys[0]];
1356
+				}
1196 1357
 			}
1197 1358
 			else
1198 1359
 			{
@@ -1201,7 +1362,8 @@  discard block
 block discarded – undo
1201 1362
 		}
1202 1363
 		$folderInfo = $folderInfoCache[$_folderName];
1203 1364
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($folderInfo).'->'.function_backtrace());
1204
-		if($ignoreStatusCache||!$folderInfo|| !is_array($folderInfo)) {
1365
+		if($ignoreStatusCache||!$folderInfo|| !is_array($folderInfo))
1366
+		{
1205 1367
 			try
1206 1368
 			{
1207 1369
 				$folderInfo = $this->_getStatus($_folderName,$ignoreStatusCache);
@@ -1235,7 +1397,8 @@  discard block
 block discarded – undo
1235 1397
 		$retValue['shortName']		= array_pop($shortNameParts);
1236 1398
 		$retValue['displayName']	= $_folderName;
1237 1399
 		$retValue['shortDisplayName']	= $retValue['shortName'];
1238
-		if(strtoupper($retValue['shortName']) == 'INBOX') {
1400
+		if(strtoupper($retValue['shortName']) == 'INBOX')
1401
+		{
1239 1402
 			$retValue['displayName']	= lang('INBOX');
1240 1403
 			$retValue['shortDisplayName']	= lang('INBOX');
1241 1404
 		}
@@ -1244,7 +1407,10 @@  discard block
 block discarded – undo
1244 1407
 		{
1245 1408
 			$retValue['displayName'] = $retValue['shortDisplayName'] = lang($retValue['shortName']);
1246 1409
 		}
1247
-		if ($folderInfo) $folderBasicInfo[$this->profileID][$_folderName]=$retValue;
1410
+		if ($folderInfo)
1411
+		{
1412
+			$folderBasicInfo[$this->profileID][$_folderName]=$retValue;
1413
+		}
1248 1414
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.$_folderName.array2string($retValue['attributes']));
1249 1415
 		if ($basicInfoOnly || (isset($retValue['attributes']) && stripos(array2string($retValue['attributes']),'noselect')!==false))
1250 1416
 		{
@@ -1256,24 +1422,34 @@  discard block
 block discarded – undo
1256 1422
 		static $subscribedFolders = null;
1257 1423
 		static $nameSpace = null;
1258 1424
 		static $prefix = null;
1259
-		if (is_null($nameSpace) || empty($nameSpace[$this->profileID])) $nameSpace[$this->profileID] = $this->_getNameSpaces();
1425
+		if (is_null($nameSpace) || empty($nameSpace[$this->profileID]))
1426
+		{
1427
+			$nameSpace[$this->profileID] = $this->_getNameSpaces();
1428
+		}
1260 1429
 		if (!empty($nameSpace[$this->profileID]))
1261 1430
 		{
1262 1431
 			$nsNoPersonal=array();
1263 1432
 			foreach($nameSpace[$this->profileID] as &$ns)
1264 1433
 			{
1265
-				if ($ns['type']!='personal') $nsNoPersonal[]=$ns;
1434
+				if ($ns['type']!='personal')
1435
+				{
1436
+					$nsNoPersonal[]=$ns;
1437
+				}
1266 1438
 			}
1267 1439
 			$nameSpace[$this->profileID]=$nsNoPersonal;
1268 1440
 		}
1269
-		if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName])) $prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName);
1441
+		if (is_null($prefix) || empty($prefix[$this->profileID]) || empty($prefix[$this->profileID][$_folderName]))
1442
+		{
1443
+			$prefix[$this->profileID][$_folderName] = $this->getFolderPrefixFromNamespace($nameSpace[$this->profileID], $_folderName);
1444
+		}
1270 1445
 
1271 1446
 		if ($fetchSubscribedInfo && is_null($subscribedFolders) || empty($subscribedFolders[$this->profileID]))
1272 1447
 		{
1273 1448
 			$subscribedFolders[$this->profileID] = $this->icServer->listSubscribedMailboxes();
1274 1449
 		}
1275 1450
 
1276
-		if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID])) {
1451
+		if($fetchSubscribedInfo && is_array($subscribedFolders[$this->profileID]) && in_array($_folderName,$subscribedFolders[$this->profileID]))
1452
+		{
1277 1453
 			$retValue['subscribed'] = true;
1278 1454
 		}
1279 1455
 
@@ -1292,8 +1468,7 @@  discard block
 block discarded – undo
1292 1468
 				(isset($this->mailPreferences['trustServersUnseenInfo']) &&
1293 1469
 				$this->mailPreferences['trustServersUnseenInfo']==2 &&
1294 1470
 				$prefix[$this->profileID][$_folderName] != '' && stripos($_folderName,$prefix[$this->profileID][$_folderName]) !== false)
1295
-			)
1296
-			{
1471
+			) {
1297 1472
 				//error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($prefix,true).' TS:'.$this->mailPreferences['trustServersUnseenInfo']);
1298 1473
 				// we filter for the combined status of unseen and undeleted, as this is what we show in list
1299 1474
 				try
@@ -1304,13 +1479,19 @@  discard block
 block discarded – undo
1304 1479
 				}
1305 1480
 				catch (\Exception $ee)
1306 1481
 				{
1307
-					if (self::$debug) error_log(__METHOD__." could not fetch/calculate unseen counter for $_folderName Reason:'".$ee->getMessage()."' but requested.");
1482
+					if (self::$debug)
1483
+					{
1484
+						error_log(__METHOD__." could not fetch/calculate unseen counter for $_folderName Reason:'".$ee->getMessage()."' but requested.");
1485
+					}
1308 1486
 				}
1309 1487
 			}
1310 1488
 		}
1311 1489
 		catch (\Exception $e)
1312 1490
 		{
1313
-			if (self::$debug) error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1491
+			if (self::$debug)
1492
+			{
1493
+				error_log(__METHOD__." returned folderStatus for Folder $_folderName:".print_r($e->getMessage(),true));
1494
+			}
1314 1495
 		}
1315 1496
 
1316 1497
 		return $retValue;
@@ -1335,8 +1516,14 @@  discard block
 block discarded – undo
1335 1516
 	function getHeaders($_folderName, $_startMessage, $_numberOfMessages, $_sort, $_reverse, $_filter, $_thisUIDOnly=null, $_cacheResult=true, $_fetchPreviews=false)
1336 1517
 	{
1337 1518
 		//self::$debug=true;
1338
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
1339
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName,$_startMessage, $_numberOfMessages, $_sort, $_reverse, ".array2string($_filter).", $_thisUIDOnly");
1519
+		if (self::$debug)
1520
+		{
1521
+			error_log(__METHOD__.' ('.__LINE__.') '.function_backtrace());
1522
+		}
1523
+		if (self::$debug)
1524
+		{
1525
+			error_log(__METHOD__.' ('.__LINE__.') '."$_folderName,$_startMessage, $_numberOfMessages, $_sort, $_reverse, ".array2string($_filter).", $_thisUIDOnly");
1526
+		}
1340 1527
 		$reverse = (bool)$_reverse;
1341 1528
 		// get the list of messages to fetch
1342 1529
 		$this->reopen($_folderName);
@@ -1357,21 +1544,34 @@  discard block
 block discarded – undo
1357 1544
 				//$_filter['range'] ="$start:$end";
1358 1545
 				//$_filter['range'] ="$_startMessage:*";
1359 1546
 			}
1360
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1361
-			if (self::$debug||self::$debugTimes) $starttime = microtime (true);
1547
+			if (self::$debug)
1548
+			{
1549
+				error_log(__METHOD__.' ('.__LINE__.') '."$_folderName, $_sort, $reverse, ".array2string($_filter).", $rByUid");
1550
+			}
1551
+			if (self::$debug||self::$debugTimes)
1552
+			{
1553
+				$starttime = microtime (true);
1554
+			}
1362 1555
 			//see this example below for a 12 week datefilter (since)
1363 1556
 			//$_filter = array('status'=>array('UNDELETED'),'type'=>"SINCE",'string'=> date("d-M-Y", $starttime-(3600*24*7*12)));
1364 1557
 			$_sortResult = $this->getSortedList($_folderName, $_sort, $reverse, $_filter, $rByUid, $_cacheResult);
1365 1558
 			$sortResult = $_sortResult['match']->ids;
1366 1559
 			//$modseq = $_sortResult['modseq'];
1367 1560
 			//error_log(__METHOD__.' ('.__LINE__.') '.'Modsequence:'.$modseq);
1368
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1561
+			if (self::$debug||self::$debugTimes)
1562
+			{
1563
+				self::logRunTimes($starttime,null,' call getSortedList for Folder:'.$_folderName.' Filter:'.array2string($_filter).' Ids:'.array2string($_thisUIDOnly),__METHOD__.' ('.__LINE__.') ');
1564
+			}
1369 1565
 
1370
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1566
+			if (self::$debug)
1567
+			{
1568
+				error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1569
+			}
1371 1570
 			#$this->icServer->setDebug(false);
1372 1571
 			#print "</pre>";
1373 1572
 			// nothing found
1374
-			if(!is_array($sortResult) || empty($sortResult)) {
1573
+			if(!is_array($sortResult) || empty($sortResult))
1574
+			{
1375 1575
 				$retValue = array();
1376 1576
 				$retValue['info']['total']	= 0;
1377 1577
 				$retValue['info']['first']	= 0;
@@ -1383,7 +1583,8 @@  discard block
 block discarded – undo
1383 1583
 			#_debug_array($sortResult);
1384 1584
 			#_debug_array(array_slice($sortResult, -5, -2));
1385 1585
 			//error_log("REVERSE: $reverse");
1386
-			if($reverse === true) {
1586
+			if($reverse === true)
1587
+			{
1387 1588
 				if  ($_startMessage<=$total)
1388 1589
 				{
1389 1590
 					$startMessage = $_startMessage-1;
@@ -1395,7 +1596,10 @@  discard block
 block discarded – undo
1395 1596
 					{
1396 1597
 						$numberOfMessages = $total%$_numberOfMessages;
1397 1598
 						//$numberOfMessages = abs($_startMessage-$total-1);
1398
-						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages) $_numberOfMessages = $numberOfMessages;
1599
+						if ($numberOfMessages>0 && $numberOfMessages<=$_numberOfMessages)
1600
+						{
1601
+							$_numberOfMessages = $numberOfMessages;
1602
+						}
1399 1603
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Start:'.$_startMessage.' NumberOfMessages:'.$_numberOfMessages.' Total:'.$total);
1400 1604
 					}
1401 1605
 					$startMessage=($total-$_numberOfMessages)-1;
@@ -1409,19 +1613,36 @@  discard block
 block discarded – undo
1409 1613
 					//$retValue['info']['first'] = $startMessage;
1410 1614
 					//$retValue['info']['last'] = $total;
1411 1615
 				}
1412
-				if($startMessage > 0) {
1413
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1616
+				if($startMessage > 0)
1617
+				{
1618
+					if (self::$debug)
1619
+					{
1620
+						error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+$startMessage)).', '.-$startMessage.' Number of Messages:'.count($sortResult));
1621
+					}
1414 1622
 					$sortResult = array_slice($sortResult, -($_numberOfMessages+$startMessage), -$startMessage);
1415
-				} else {
1416
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1623
+				}
1624
+				else
1625
+				{
1626
+					if (self::$debug)
1627
+					{
1628
+						error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.(-($_numberOfMessages+($_startMessage-1))).', AllTheRest, Number of Messages:'.count($sortResult));
1629
+					}
1417 1630
 					$sortResult = array_slice($sortResult, -($_numberOfMessages+($_startMessage-1)));
1418 1631
 				}
1419 1632
 				$sortResult = array_reverse($sortResult);
1420
-			} else {
1421
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1633
+			}
1634
+			else
1635
+			{
1636
+				if (self::$debug)
1637
+				{
1638
+					error_log(__METHOD__.' ('.__LINE__.') '.' StartMessage:'.($_startMessage-1).', '.$_numberOfMessages.' Number of Messages:'.count($sortResult));
1639
+				}
1422 1640
 				$sortResult = array_slice($sortResult, $_startMessage-1, $_numberOfMessages);
1423 1641
 			}
1424
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1642
+			if (self::$debug)
1643
+			{
1644
+				error_log(__METHOD__.' ('.__LINE__.') '.array2string($sortResult));
1645
+			}
1425 1646
 		}
1426 1647
 		else
1427 1648
 		{
@@ -1430,7 +1651,10 @@  discard block
 block discarded – undo
1430 1651
 
1431 1652
 
1432 1653
 		// fetch the data for the selected messages
1433
-		if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1654
+		if (self::$debug||self::$debugTimes)
1655
+		{
1656
+			$starttime = microtime(true);
1657
+		}
1434 1658
 		try
1435 1659
 		{
1436 1660
 			$uidsToFetch = new Horde_Imap_Client_Ids();
@@ -1454,7 +1678,10 @@  discard block
 block discarded – undo
1454 1678
 			$fquery->flags();
1455 1679
 			$fquery->imapDate();// needed to ensure getImapDate fetches the internaldate, not the current time
1456 1680
 			// if $_fetchPreviews is activated fetch part of the messages too
1457
-			if ($_fetchPreviews) $fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0));
1681
+			if ($_fetchPreviews)
1682
+			{
1683
+				$fquery->fullText(array('peek'=>true,'length'=>((int)$_fetchPreviews<5000?5000:$_fetchPreviews),'start'=>0));
1684
+			}
1458 1685
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
1459 1686
 				'ids' => $uidsToFetch,
1460 1687
 			));
@@ -1477,14 +1704,20 @@  discard block
 block discarded – undo
1477 1704
 
1478 1705
 		$cnt = 0;
1479 1706
 
1480
-		foreach((array)$sortResult as $uid) {
1707
+		foreach((array)$sortResult as $uid)
1708
+		{
1481 1709
 			$sortOrder[$uid] = $cnt++;
1482 1710
 		}
1483 1711
 
1484 1712
 		$count = 0;
1485
-		if (is_object($headersNew)) {
1486
-			if (self::$debug||self::$debugTimes) $starttime = microtime(true);
1487
-			foreach($headersNew->ids() as $id) {
1713
+		if (is_object($headersNew))
1714
+		{
1715
+			if (self::$debug||self::$debugTimes)
1716
+			{
1717
+				$starttime = microtime(true);
1718
+			}
1719
+			foreach($headersNew->ids() as $id)
1720
+			{
1488 1721
 				$_headerObject = $headersNew->get($id);
1489 1722
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject));
1490 1723
 				$headerObject = array();
@@ -1497,7 +1730,10 @@  discard block
 block discarded – undo
1497 1730
 				// Get already cached headers, 'fetchHeaders' is a label matchimg above
1498 1731
 				$headerForPrio = $_headerObject->getHeaders('fetchHeaders',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1499 1732
 				// Try to fetch header with key='' as some servers might have no fetchHeaders index. e.g. yandex.com
1500
-				if (empty($headerForPrio)) $headerForPrio = $_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1733
+				if (empty($headerForPrio))
1734
+				{
1735
+					$headerForPrio = $_headerObject->getHeaders('',Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->toArray();
1736
+				}
1501 1737
 				//fetch the fullMsg part if all conditions match to be available in case $_headerObject->getHeaders returns
1502 1738
 				//nothing worthwhile (as it does for googlemail accounts, when preview is switched on
1503 1739
 				if ($_fetchPreviews)
@@ -1508,12 +1744,16 @@  discard block
 block discarded – undo
1508 1744
 					if (empty($headerForPrio)||(is_array($headerForPrio)&&count($headerForPrio)===1&&$headerForPrio['']))
1509 1745
 					{
1510 1746
 						$length = strpos($bodyPreview, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
1511
-						if ($length===false) $length = strlen($bodyPreview);
1747
+						if ($length===false)
1748
+						{
1749
+							$length = strlen($bodyPreview);
1750
+						}
1512 1751
 						$headerForPrio =  Horde_Mime_Headers::parseHeaders(substr($bodyPreview, 0,$length))->toArray();
1513 1752
 					}
1514 1753
 				}
1515 1754
 				$headerForPrio = array_change_key_case($headerForPrio, CASE_UPPER);
1516
-				if (self::$debug) {
1755
+				if (self::$debug)
1756
+				{
1517 1757
 					error_log(__METHOD__.' ('.__LINE__.') '.array2string($_headerObject).'UID:'.$_headerObject->getUid().' Size:'.$_headerObject->getSize().' Date:'.$_headerObject->getImapDate().'/'.DateTime::to($_headerObject->getImapDate(),'Y-m-d H:i:s'));
1518 1758
 					error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerForPrio));
1519 1759
 				}
@@ -1523,11 +1763,16 @@  discard block
 block discarded – undo
1523 1763
 					$total--;
1524 1764
 					continue;
1525 1765
 				}
1526
-				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) ) {
1766
+				if ( isset($headerForPrio['DISPOSITION-NOTIFICATION-TO']) )
1767
+				{
1527 1768
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['DISPOSITION-NOTIFICATION-TO']));
1528
-				} else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) ) {
1769
+				}
1770
+				else if ( isset($headerForPrio['RETURN-RECEIPT-TO']) )
1771
+				{
1529 1772
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['RETURN-RECEIPT-TO']));
1530
-				} else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) ) {
1773
+				}
1774
+				else if ( isset($headerForPrio['X-CONFIRM-READING-TO']) )
1775
+				{
1531 1776
 					$headerObject['DISPOSITION-NOTIFICATION-TO'] = self::decode_header(trim($headerForPrio['X-CONFIRM-READING-TO']));
1532 1777
 				} /*else $sent_not = "";*/
1533 1778
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($headerObject));
@@ -1558,7 +1803,11 @@  discard block
 block discarded – undo
1558 1803
 						$rfcAddr = self::parseAddressList($ad); // does some fixing of known problems too
1559 1804
 						foreach ($rfcAddr as $_rfcAddr)
1560 1805
 						{
1561
-							if (!$_rfcAddr->valid)	continue; // skip. not a valid address
1806
+							if (!$_rfcAddr->valid)
1807
+							{
1808
+								continue;
1809
+							}
1810
+							// skip. not a valid address
1562 1811
 							$address[] = imap_rfc822_write_address($_rfcAddr->mailbox,$_rfcAddr->host,$_rfcAddr->personal);
1563 1812
 						}
1564 1813
 					}
@@ -1574,7 +1823,10 @@  discard block
 block discarded – undo
1574 1823
 				{
1575 1824
 					// $bodyPreview is populated at the beginning of the loop, as it may be
1576 1825
 					// needed to parse the Headers of the Message
1577
-					if (empty($bodyPreview)) $bodyPreview = $_headerObject->getFullMsg();
1826
+					if (empty($bodyPreview))
1827
+					{
1828
+						$bodyPreview = $_headerObject->getFullMsg();
1829
+					}
1578 1830
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($bodyPreview));
1579 1831
 					$base = Horde_Mime_Part::parseMessage($bodyPreview);
1580 1832
 					foreach($base->partIterator() as $part)
@@ -1587,7 +1839,8 @@  discard block
 block discarded – undo
1587 1839
 												'encode' => Horde_Mime_Part::ENCODE_BINARY,	// otherwise we cant recode charset
1588 1840
 											)), $charset, 'utf-8');
1589 1841
 							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Translation::convert_jsonsafe($buffer),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
1590
-						} elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart')
1842
+						}
1843
+						elseif (empty($headerObject['BODYPREVIEW'])&&$part->getPrimaryType()== 'multipart')
1591 1844
 						{
1592 1845
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part));
1593 1846
 						}
@@ -1603,7 +1856,10 @@  discard block
 block discarded – undo
1603 1856
 				$messageMimeType='';
1604 1857
 				foreach ($mailStructureObject->contentTypeMap() as $mime_id => $mime_type)
1605 1858
 				{
1606
-					if ($mime_id==0 || $messageMimeType==='') $messageMimeType = $mime_type;
1859
+					if ($mime_id==0 || $messageMimeType==='')
1860
+					{
1861
+						$messageMimeType = $mime_type;
1862
+					}
1607 1863
 					$part = $mailStructureObject->getPart($mime_id);
1608 1864
 					$partdisposition = $part->getDisposition();
1609 1865
 					$partPrimaryType = $part->getPrimaryType();
@@ -1613,7 +1869,8 @@  discard block
 block discarded – undo
1613 1869
 					// bodypreview could be found (multipart/....)
1614 1870
 					if ($_fetchPreviews && empty($headerObject['BODYPREVIEW'])&&($partPrimaryType == 'text') &&
1615 1871
 						((intval($mime_id) === 1) || !$mime_id) &&
1616
-						($partdisposition !== 'attachment')) {
1872
+						($partdisposition !== 'attachment'))
1873
+					{
1617 1874
 							$_structure=$part;
1618 1875
 							$this->fetchPartContents($uid, $_structure, false,true);
1619 1876
 							$headerObject['BODYPREVIEW']=trim(str_replace(array("\r\n","\r","\n"),' ',mb_substr(Mail\Html::convertHTMLToText($_structure->getContents()),0,((int)$_fetchPreviews<300?300:$_fetchPreviews))));
@@ -1635,10 +1892,19 @@  discard block
 block discarded – undo
1635 1892
 					if ($mime_type=='message/rfc822')
1636 1893
 					{
1637 1894
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
1638
-						foreach($part->contentTypeMap() as $sub_id => $sub_type) { if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
1895
+						foreach($part->contentTypeMap() as $sub_id => $sub_type)
1896
+						{
1897
+if ($sub_id != $mime_id)
1898
+						{
1899
+							$skipParts[$sub_id] = $sub_type;
1900
+						}
1901
+						}
1639 1902
 					}
1640 1903
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.' Disp:'.$partdisposition.' Type:'.$partPrimaryType.' Skip:'.array2string($skipParts));
1641
-					if (array_key_exists($mime_id,$skipParts)) continue;
1904
+					if (array_key_exists($mime_id,$skipParts))
1905
+					{
1906
+						continue;
1907
+					}
1642 1908
 					if ($partdisposition=='attachment' ||
1643 1909
 						($partdisposition=='inline'&&$partPrimaryType == 'image'&&$mime_type=='image/tiff') || // as we are not able to display tiffs
1644 1910
 						($partdisposition=='inline'&&$partPrimaryType == 'image'&&empty($cid)) ||
@@ -1649,7 +1915,10 @@  discard block
 block discarded – undo
1649 1915
 						$headerObject['ATTACHMENTS'][$mime_id]['uid']=$uid;
1650 1916
 						$headerObject['ATTACHMENTS'][$mime_id]['cid'] = $cid;
1651 1917
 						$headerObject['ATTACHMENTS'][$mime_id]['partID']=$mime_id;
1652
-						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1918
+						if (!isset($headerObject['ATTACHMENTS'][$mime_id]['name']))
1919
+						{
1920
+							$headerObject['ATTACHMENTS'][$mime_id]['name']=$part->getName();
1921
+						}
1653 1922
 						if (!strcasecmp($headerObject['ATTACHMENTS'][$mime_id]['name'],'winmail.dat') ||
1654 1923
 							$headerObject['ATTACHMENTS'][$mime_id]['mimeType']=='application/ms-tnef')
1655 1924
 						{
@@ -1663,18 +1932,27 @@  discard block
 block discarded – undo
1663 1932
 				//error_log(__METHOD__.' ('.__LINE__.') '.' FindBody (plain):'.array2string($mailStructureObject->findBody('plain')));
1664 1933
 				//error_log(__METHOD__.' ('.__LINE__.') '.' FindBody (html):'.array2string($mailStructureObject->findBody('html')));
1665 1934
 				//if($count == 0) error_log(__METHOD__.array2string($headerObject));
1666
-				if (empty($headerObject['UID'])) continue;
1935
+				if (empty($headerObject['UID']))
1936
+				{
1937
+					continue;
1938
+				}
1667 1939
 				//$uid = ($rByUid ? $headerObject['UID'] : $headerObject['MSG_NUM']);
1668 1940
 				// make dates like "Mon, 23 Apr 2007 10:11:06 UT" working with strtotime
1669
-				if(substr($headerObject['DATE'],-2) === 'UT') {
1941
+				if(substr($headerObject['DATE'],-2) === 'UT')
1942
+				{
1670 1943
 					$headerObject['DATE'] .= 'C';
1671 1944
 				}
1672
-				if(substr($headerObject['INTERNALDATE'],-2) === 'UT') {
1945
+				if(substr($headerObject['INTERNALDATE'],-2) === 'UT')
1946
+				{
1673 1947
 					$headerObject['INTERNALDATE'] .= 'C';
1674 1948
 				}
1675 1949
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$headerObject['SUBJECT'].'->'.$headerObject['DATE'].'<->'.$headerObject['INTERNALDATE'] .'#');
1676 1950
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.$this->decode_subject($headerObject['SUBJECT']).'->'.$headerObject['DATE']);
1677
-				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS'])) foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;}
1951
+				if (isset($headerObject['ATTACHMENTS']) && count($headerObject['ATTACHMENTS']))
1952
+				{
1953
+					foreach ($headerObject['ATTACHMENTS'] as &$a) { $retValue['header'][$sortOrder[$uid]]['attachments'][]=$a;
1954
+				}
1955
+				}
1678 1956
 				$retValue['header'][$sortOrder[$uid]]['subject']	= $this->decode_subject($headerObject['SUBJECT']);
1679 1957
 				$retValue['header'][$sortOrder[$uid]]['size'] 		= $headerObject['SIZE'];
1680 1958
 				$retValue['header'][$sortOrder[$uid]]['date']		= self::_strtotime(($headerObject['DATE']&&!($headerObject['DATE']=='NIL')?$headerObject['DATE']:$headerObject['INTERNALDATE']),'ts',true);
@@ -1685,22 +1963,31 @@  discard block
 block discarded – undo
1685 1963
 				$retValue['header'][$sortOrder[$uid]]['bodypreview']		= $headerObject['BODYPREVIEW'];
1686 1964
 				$retValue['header'][$sortOrder[$uid]]['priority']		= ($headerObject['PRIORITY']?$headerObject['PRIORITY']:3);
1687 1965
 				//error_log(__METHOD__.' ('.__LINE__.') '.' '.array2string($retValue['header'][$sortOrder[$uid]]));
1688
-				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO'])) $retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1689
-				if (is_array($headerObject['FLAGS'])) {
1966
+				if (isset($headerObject['DISPOSITION-NOTIFICATION-TO']))
1967
+				{
1968
+					$retValue['header'][$sortOrder[$uid]]['disposition-notification-to'] = $headerObject['DISPOSITION-NOTIFICATION-TO'];
1969
+				}
1970
+				if (is_array($headerObject['FLAGS']))
1971
+				{
1690 1972
 					$retValue['header'][$sortOrder[$uid]] = array_merge($retValue['header'][$sortOrder[$uid]],self::prepareFlagsArray($headerObject));
1691 1973
 				}
1692 1974
 				//error_log(__METHOD__.' ('.__LINE__.') '.$headerObject['SUBJECT'].'->'.array2string($_headerObject->getEnvelope()->__get('from')));
1693
-				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0]) {
1975
+				if(is_array($headerObject['FROM']) && $headerObject['FROM'][0])
1976
+				{
1694 1977
 					$retValue['header'][$sortOrder[$uid]]['sender_address'] = self::decode_header($headerObject['FROM'][0],true);
1695 1978
 				}
1696
-				if(is_array($headerObject['TO']) && $headerObject['TO'][0]) {
1979
+				if(is_array($headerObject['TO']) && $headerObject['TO'][0])
1980
+				{
1697 1981
 					$retValue['header'][$sortOrder[$uid]]['to_address'] = self::decode_header($headerObject['TO'][0],true);
1698 1982
 					if (count($headerObject['TO'])>1)
1699 1983
 					{
1700 1984
 						$ki=0;
1701 1985
 						foreach($headerObject['TO'] as $k => $add)
1702 1986
 						{
1703
-							if ($k==0) continue;
1987
+							if ($k==0)
1988
+							{
1989
+								continue;
1990
+							}
1704 1991
 							//error_log(__METHOD__.' ('.__LINE__.') '."-> $k:".array2string($add));
1705 1992
 							$retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki] = self::decode_header($add,true);
1706 1993
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue['header'][$sortOrder[$uid]]['additional_to_addresses'][$ki]));
@@ -1708,7 +1995,8 @@  discard block
 block discarded – undo
1708 1995
 						}
1709 1996
 					}
1710 1997
 				}
1711
-				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0) {
1998
+				if(is_array($headerObject['CC']) && count($headerObject['CC'])>0)
1999
+				{
1712 2000
 					$ki=0;
1713 2001
 					foreach($headerObject['CC'] as $k => $add)
1714 2002
 					{
@@ -1722,27 +2010,41 @@  discard block
 block discarded – undo
1722 2010
 
1723 2011
 				$count++;
1724 2012
 			}
1725
-			if (self::$debug||self::$debugTimes) self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
2013
+			if (self::$debug||self::$debugTimes)
2014
+			{
2015
+				self::logRunTimes($starttime,null,' fetching Headers and stuff for Folder:'.$_folderName,__METHOD__.' ('.__LINE__.') ');
2016
+			}
1726 2017
 			//self::$debug=false;
1727 2018
 			// sort the messages to the requested displayorder
1728
-			if(is_array($retValue['header'])) {
2019
+			if(is_array($retValue['header']))
2020
+			{
1729 2021
 				$countMessages = $total;
1730
-				if (isset($_filter['range'])) $countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
2022
+				if (isset($_filter['range']))
2023
+				{
2024
+					$countMessages = self::$folderStatusCache[$this->profileID][$_folderName]['messages'];
2025
+				}
1731 2026
 				ksort($retValue['header']);
1732 2027
 				$retValue['info']['total']	= $total;
1733 2028
 				//if ($_startMessage>$total) $_startMessage = $total-($count-1);
1734 2029
 				$retValue['info']['first']	= $_startMessage;
1735 2030
 				$retValue['info']['last']	= $_startMessage + $count - 1 ;
1736 2031
 				return $retValue;
1737
-			} else {
2032
+			}
2033
+			else
2034
+			{
1738 2035
 				$retValue = array();
1739 2036
 				$retValue['info']['total']	= 0;
1740 2037
 				$retValue['info']['first']	= 0;
1741 2038
 				$retValue['info']['last']	= 0;
1742 2039
 				return $retValue;
1743 2040
 			}
1744
-		} else {
1745
-			if ($headersNew == null && empty($_thisUIDOnly)) error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
2041
+		}
2042
+		else
2043
+		{
2044
+			if ($headersNew == null && empty($_thisUIDOnly))
2045
+			{
2046
+				error_log(__METHOD__." -> retrieval of Message Details to Query $queryString failed: ".print_r($headersNew,TRUE));
2047
+			}
1746 2048
 			$retValue = array();
1747 2049
 			$retValue['info']['total']  = 0;
1748 2050
 			$retValue['info']['first']  = 0;
@@ -1759,7 +2061,10 @@  discard block
 block discarded – undo
1759 2061
 	 */
1760 2062
 	static function prepareFlagsArray($headerObject)
1761 2063
 	{
1762
-		if (is_array($headerObject['FLAGS'])) $headerFlags = array_map('strtolower',$headerObject['FLAGS']);
2064
+		if (is_array($headerObject['FLAGS']))
2065
+		{
2066
+			$headerFlags = array_map('strtolower',$headerObject['FLAGS']);
2067
+		}
1763 2068
 		$retValue = array();
1764 2069
 		$retValue['recent']		= in_array('\\recent', $headerFlags);
1765 2070
 		$retValue['flagged']	= in_array('\\flagged', $headerFlags);
@@ -1810,25 +2115,44 @@  discard block
 block discarded – undo
1810 2115
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Filter:'.array2string($_filter));
1811 2116
 		$try2useCache = true;
1812 2117
 		static $eMailListContainsDeletedMessages = null;
1813
-		if (is_null($eMailListContainsDeletedMessages)) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2118
+		if (is_null($eMailListContainsDeletedMessages))
2119
+		{
2120
+			$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2121
+		}
1814 2122
 		// this indicates, that there is no Filter set, and the returned set/subset should not contain DELETED Messages, nor filtered for UNDELETED
1815 2123
 		if ($setSession==true && ((strpos(array2string($_filter), 'UNDELETED') === false && strpos(array2string($_filter), 'DELETED') === false)))
1816 2124
 		{
1817
-			if (self::$debugTimes) $starttime = microtime(true);
1818
-			if (is_null($eMailListContainsDeletedMessages) || empty($eMailListContainsDeletedMessages[$this->profileID]) || empty($eMailListContainsDeletedMessages[$this->profileID][$_folderName])) $eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
1819
-			$five=true;
1820
-			$deletedMessages = $this->getSortedList($_folderName, 0, $three=1, array('status'=>array('DELETED')),$five,false);
1821
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
1822
-			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] =$deletedMessages['count'];
2125
+			if (self::$debugTimes)
2126
+			{
2127
+				$starttime = microtime(true);
2128
+			}
2129
+			if (is_null($eMailListContainsDeletedMessages) || empty($eMailListContainsDeletedMessages[$this->profileID]) || empty($eMailListContainsDeletedMessages[$this->profileID][$_folderName]))
2130
+			{
2131
+				$eMailListContainsDeletedMessages = Cache::getCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2132
+			}
2133
+			$five=true;
2134
+			$deletedMessages = $this->getSortedList($_folderName, 0, $three=1, array('status'=>array('DELETED')),$five,false);
2135
+			if (self::$debug)
2136
+			{
2137
+				error_log(__METHOD__.' ('.__LINE__.') Found DeletedMessages:'.array2string($eMailListContainsDeletedMessages));
2138
+			}
2139
+			$eMailListContainsDeletedMessages[$this->profileID][$_folderName] =$deletedMessages['count'];
1823 2140
 			Cache::setCache(Cache::INSTANCE,'email','eMailListContainsDeletedMessages'.trim($GLOBALS['egw_info']['user']['account_id']),$eMailListContainsDeletedMessages, 60*60*1);
1824
-			if (self::$debugTimes) self::logRunTimes($starttime,null,'setting eMailListContainsDeletedMessages for Profile:'.$this->profileID.' Folder:'.$_folderName.' to '.$eMailListContainsDeletedMessages[$this->profileID][$_folderName],__METHOD__.' ('.__LINE__.') ');			//error_log(__METHOD__.' ('.__LINE__.') '.' Profile:'.$this->profileID.' Folder:'.$_folderName.' -> EXISTS/SessStat:'.array2string($folderStatus['MESSAGES']).'/'.self::$folderStatusCache[$this->profileID][$_folderName]['messages'].' ListContDelMsg/SessDeleted:'.$eMailListContainsDeletedMessages[$this->profileID][$_folderName].'/'.self::$folderStatusCache[$this->profileID][$_folderName]['deleted']);
2141
+			if (self::$debugTimes)
2142
+			{
2143
+				self::logRunTimes($starttime,null,'setting eMailListContainsDeletedMessages for Profile:'.$this->profileID.' Folder:'.$_folderName.' to '.$eMailListContainsDeletedMessages[$this->profileID][$_folderName],__METHOD__.' ('.__LINE__.') ');
2144
+			}
2145
+			//error_log(__METHOD__.' ('.__LINE__.') '.' Profile:'.$this->profileID.' Folder:'.$_folderName.' -> EXISTS/SessStat:'.array2string($folderStatus['MESSAGES']).'/'.self::$folderStatusCache[$this->profileID][$_folderName]['messages'].' ListContDelMsg/SessDeleted:'.$eMailListContainsDeletedMessages[$this->profileID][$_folderName].'/'.self::$folderStatusCache[$this->profileID][$_folderName]['deleted']);
1825 2146
 		}
1826 2147
 		$try2useCache = false;
1827 2148
 		//self::$supportsORinQuery[$this->profileID]=true;
1828 2149
 		if (is_null(self::$supportsORinQuery) || !isset(self::$supportsORinQuery[$this->profileID]))
1829 2150
 		{
1830 2151
 			self::$supportsORinQuery = Cache::getCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*10);
1831
-			if (!isset(self::$supportsORinQuery[$this->profileID])) self::$supportsORinQuery[$this->profileID]=true;
2152
+			if (!isset(self::$supportsORinQuery[$this->profileID]))
2153
+			{
2154
+				self::$supportsORinQuery[$this->profileID]=true;
2155
+			}
1832 2156
 		}
1833 2157
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_filter).' SupportsOrInQuery:'.self::$supportsORinQuery[$this->profileID]);
1834 2158
 		$filter = $this->createIMAPFilter($_folderName, $_filter,self::$supportsORinQuery[$this->profileID]);
@@ -1839,15 +2163,26 @@  discard block
 block discarded – undo
1839 2163
 		}
1840 2164
 		//_debug_array($filter);
1841 2165
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($filter).'#'.array2string($this->icServer->capability()));
1842
-		if($this->icServer->hasCapability('SORT')) {
2166
+		if($this->icServer->hasCapability('SORT'))
2167
+		{
1843 2168
 			// when using an orQuery and we sort by date. sort seems to fail on certain servers => ZIMBRA with Horde_Imap_Client
1844 2169
 			// thus we translate the search request from date to Horde_Imap_Client::SORT_SEQUENCE (which should be the same, if
1845 2170
 			// there is no messing with the dates)
1846 2171
 			//if (self::$supportsORinQuery[$this->profileID]&&$_sort=='date'&&$_filter['type']=='quick'&&!empty($_filter['string']))$_sort='INTERNALDATE';
1847
-			if (self::$debug) error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
2172
+			if (self::$debug)
2173
+			{
2174
+				error_log(__METHOD__." Mailserver has SORT Capability, SortBy: ".array2string($_sort)." Reverse: $_reverse");
2175
+			}
1848 2176
 			$sortOrder = $this->_getSortString($_sort, $_reverse);
1849
-			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder)) $_reverse=false; // as we reversed the result already
1850
-			if (self::$debug) error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
2177
+			if ($_reverse && in_array(Horde_Imap_Client::SORT_REVERSE,$sortOrder))
2178
+			{
2179
+				$_reverse=false;
2180
+			}
2181
+			// as we reversed the result already
2182
+			if (self::$debug)
2183
+			{
2184
+				error_log(__METHOD__." Mailserver runs SORT: SortBy:".array2string($_sort)."->".array2string($sortOrder)." Filter: ".array2string($filter));
2185
+			}
1851 2186
 			try
1852 2187
 			{
1853 2188
 				$sortResult = $this->icServer->search($_folderName, $filter, array(
@@ -1859,7 +2194,10 @@  discard block
 block discarded – undo
1859 2194
 				//error_log(__METHOD__.'('.__LINE__.'):'.$e->getMessage());
1860 2195
 				$resultByUid = false;
1861 2196
 				$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1862
-				if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
2197
+				if ($_reverse)
2198
+				{
2199
+					array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
2200
+				}
1863 2201
 				try
1864 2202
 				{
1865 2203
 					$sortResult = $this->icServer->search($_folderName, $filter, array(
@@ -1871,9 +2209,17 @@  discard block
 block discarded – undo
1871 2209
 					$sortResult = self::$folderStatusCache[$this->profileID][$_folderName]['sortResult'];
1872 2210
 				}
1873 2211
 			}
1874
-			if (self::$debug) error_log(__METHOD__.print_r($sortResult,true));
1875
-		} else {
1876
-			if (self::$debug) error_log(__METHOD__." Mailserver has NO SORT Capability");
2212
+			if (self::$debug)
2213
+			{
2214
+				error_log(__METHOD__.print_r($sortResult,true));
2215
+			}
2216
+		}
2217
+		else
2218
+		{
2219
+			if (self::$debug)
2220
+			{
2221
+				error_log(__METHOD__." Mailserver has NO SORT Capability");
2222
+			}
1877 2223
 			//$sortOrder = array(Horde_Imap_Client::SORT_SEQUENCE);
1878 2224
 			//if ($_reverse) array_unshift($sortOrder,Horde_Imap_Client::SORT_REVERSE);
1879 2225
 			try
@@ -1887,7 +2233,10 @@  discard block
 block discarded – undo
1887 2233
 				// possible error OR Query. But Horde gives no detailed Info :-(
1888 2234
 				self::$supportsORinQuery[$this->profileID]=false;
1889 2235
 				Cache::setCache(Cache::INSTANCE,'email','supportsORinQuery'.trim($GLOBALS['egw_info']['user']['account_id']),self::$supportsORinQuery,60*60*10);
1890
-				if (self::$debug) error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
2236
+				if (self::$debug)
2237
+				{
2238
+					error_log(__METHOD__.__LINE__." Mailserver seems to have NO OR Capability for Search:".$sortResult->message);
2239
+				}
1891 2240
 				$filter = $this->createIMAPFilter($_folderName, $_filter, self::$supportsORinQuery[$this->profileID]);
1892 2241
 				try
1893 2242
 				{
@@ -1898,11 +2247,15 @@  discard block
 block discarded – undo
1898 2247
 				{
1899 2248
 				}
1900 2249
 			}
1901
-			if(is_array($sortResult['match'])) {
2250
+			if(is_array($sortResult['match']))
2251
+			{
1902 2252
 					// not sure that this is going so succeed as $sortResult['match'] is a hordeObject
1903 2253
 					sort($sortResult['match'], SORT_NUMERIC);
1904 2254
 			}
1905
-			if (self::$debug) error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
2255
+			if (self::$debug)
2256
+			{
2257
+				error_log(__METHOD__." using Filter:".print_r($filter,true)." ->".print_r($sortResult,true));
2258
+			}
1906 2259
 		}
1907 2260
 		if ($setSession)
1908 2261
 		{
@@ -1931,7 +2284,8 @@  discard block
 block discarded – undo
1931 2284
 		$_reverse=false;
1932 2285
 		if (is_numeric($_sort))
1933 2286
 		{
1934
-			switch($_sort) {
2287
+			switch($_sort)
2288
+			{
1935 2289
 				case 2:
1936 2290
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1937 2291
 					break;
@@ -1953,7 +2307,8 @@  discard block
 block discarded – undo
1953 2307
 		}
1954 2308
 		else
1955 2309
 		{
1956
-			switch(strtoupper($_sort)) {
2310
+			switch(strtoupper($_sort))
2311
+			{
1957 2312
 				case 'FROMADDRESS':
1958 2313
 					$retValue = array(Horde_Imap_Client::SORT_FROM);
1959 2314
 					break;
@@ -1979,7 +2334,10 @@  discard block
 block discarded – undo
1979 2334
 					break;
1980 2335
 			}
1981 2336
 		}
1982
-		if ($_reverse) array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
2337
+		if ($_reverse)
2338
+		{
2339
+			array_unshift($retValue,Horde_Imap_Client::SORT_REVERSE);
2340
+		}
1983 2341
 		//error_log(__METHOD__.' ('.__LINE__.') '.' '.($_reverse?'REVERSE ':'').$_sort.'->'.$retValue);
1984 2342
 		return $retValue;
1985 2343
 	}
@@ -1998,7 +2356,10 @@  discard block
 block discarded – undo
1998 2356
 		$imapFilter->charset('UTF-8');
1999 2357
 
2000 2358
 		//_debug_array($_criterias);
2001
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2359
+		if (self::$debug)
2360
+		{
2361
+			error_log(__METHOD__.' ('.__LINE__.') '.' Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2362
+		}
2002 2363
 		if((!is_array($_criterias) || $_criterias['status']=='any') &&
2003 2364
 			(!isset($_criterias['string']) || empty($_criterias['string'])) &&
2004 2365
 			(!isset($_criterias['range'])|| empty($_criterias['range']) ||
@@ -2013,11 +2374,13 @@  discard block
 block discarded – undo
2013 2374
 		// statusQuery MUST be placed first, as search for subject/mailbody and such is
2014 2375
 		// depending on charset. flagSearch is not BUT messes the charset if called afterwards
2015 2376
 		$statusQueryValid = false;
2016
-		foreach((array)$_criterias['status'] as $k => $criteria) {
2377
+		foreach((array)$_criterias['status'] as $k => $criteria)
2378
+		{
2017 2379
 			$imapStatusFilter = new Horde_Imap_Client_Search_Query();
2018 2380
 			$imapStatusFilter->charset('UTF-8');
2019 2381
 			$criteria = strtoupper($criteria);
2020
-			switch ($criteria) {
2382
+			switch ($criteria)
2383
+			{
2021 2384
 				case 'ANSWERED':
2022 2385
 				case 'DELETED':
2023 2386
 				case 'FLAGGED':
@@ -2100,9 +2463,11 @@  discard block
 block discarded – undo
2100 2463
 		$imapSearchFilter = new Horde_Imap_Client_Search_Query();
2101 2464
 		$imapSearchFilter->charset('UTF-8');
2102 2465
 
2103
-		if(!empty($_criterias['string'])) {
2466
+		if(!empty($_criterias['string']))
2467
+		{
2104 2468
 			$criteria = strtoupper($_criterias['type']);
2105
-			switch ($criteria) {
2469
+			switch ($criteria)
2470
+			{
2106 2471
 				case 'BYDATE':
2107 2472
 				case 'QUICK':
2108 2473
 				case 'QUICKWITHCC':
@@ -2110,9 +2475,12 @@  discard block
 block discarded – undo
2110 2475
 					//$imapSearchFilter->charset('UTF-8');
2111 2476
 					$imapFilter2 = new Horde_Imap_Client_Search_Query();
2112 2477
 					$imapFilter2->charset('UTF-8');
2113
-					if($this->isSentFolder($_folder)) {
2478
+					if($this->isSentFolder($_folder))
2479
+					{
2114 2480
 						$imapFilter2->headerText('TO', $_criterias['string'], $not=false);
2115
-					} else {
2481
+					}
2482
+					else
2483
+					{
2116 2484
 						$imapFilter2->headerText('FROM', $_criterias['string'], $not=false);
2117 2485
 					}
2118 2486
 					if ($_supportsOrInQuery)
@@ -2143,7 +2511,10 @@  discard block
 block discarded – undo
2143 2511
 											'GB'=>1024*1000*1000,'G'=>1024*1000*1000,
2144 2512
 											'TB'=>1024*1000*1000*1000,'T'=>1024*1000*1000*1000);
2145 2513
 						$numberinBytes=(float)$_criterias['string'];
2146
-						if (isset($multipleBy[$unit])) $numberinBytes=(float)$_criterias['string']*$multipleBy[$unit];
2514
+						if (isset($multipleBy[$unit]))
2515
+						{
2516
+							$numberinBytes=(float)$_criterias['string']*$multipleBy[$unit];
2517
+						}
2147 2518
 						//error_log(__METHOD__.__LINE__.'#'.$_criterias['string'].'->'.(float)$_criterias['string'].'#'.$unit.' ='.$numberinBytes);
2148 2519
 						$_criterias['string']=$numberinBytes;
2149 2520
 					}
@@ -2180,8 +2551,14 @@  discard block
 block discarded – undo
2180 2551
 					break;
2181 2552
 			}
2182 2553
 		}
2183
-		if ($statusQueryValid && !$queryValid) $queryValid=true;
2184
-		if ($queryValid) $imapFilter->andSearch($imapSearchFilter);
2554
+		if ($statusQueryValid && !$queryValid)
2555
+		{
2556
+			$queryValid=true;
2557
+		}
2558
+		if ($queryValid)
2559
+		{
2560
+			$imapFilter->andSearch($imapSearchFilter);
2561
+		}
2185 2562
 
2186 2563
 		if (isset($_criterias['range']) && !empty($_criterias['range']))
2187 2564
 		{
@@ -2196,7 +2573,8 @@  discard block
 block discarded – undo
2196 2573
 				unset($_criterias['before']);
2197 2574
 				$criteria=$_criterias['range']='ON';
2198 2575
 			}
2199
-			switch ($criteria) {
2576
+			switch ($criteria)
2577
+			{
2200 2578
 				case 'BETWEEN':
2201 2579
 					//try to be smart about missing
2202 2580
 					//enddate
@@ -2232,8 +2610,14 @@  discard block
 block discarded – undo
2232 2610
 					$rangeValid = true;
2233 2611
 					break;
2234 2612
 			}
2235
-			if ($rangeValid && !$queryValid) $queryValid=true;
2236
-			if ($rangeValid) $imapFilter->andSearch($imapRangeFilter);
2613
+			if ($rangeValid && !$queryValid)
2614
+			{
2615
+				$queryValid=true;
2616
+			}
2617
+			if ($rangeValid)
2618
+			{
2619
+				$imapFilter->andSearch($imapRangeFilter);
2620
+			}
2237 2621
 		}
2238 2622
 		if (self::$debug)
2239 2623
 		{
@@ -2241,10 +2625,13 @@  discard block
 block discarded – undo
2241 2625
 			$query_str = $imapFilter->build();
2242 2626
 			//error_log(__METHOD__.' ('.__LINE__.') '.' '.$query_str['query'].' created by Criterias:'.(!is_array($_criterias)?" none -> returning":array2string($_criterias)));
2243 2627
 		}
2244
-		if($queryValid==false) {
2628
+		if($queryValid==false)
2629
+		{
2245 2630
 			$imapFilter->flag('DELETED', $set=false);
2246 2631
 			return $imapFilter;
2247
-		} else {
2632
+		}
2633
+		else
2634
+		{
2248 2635
 			return $imapFilter;
2249 2636
 		}
2250 2637
 	}
@@ -2301,7 +2688,10 @@  discard block
 block discarded – undo
2301 2688
 					}
2302 2689
 					$stringA[] = imap_rfc822_write_address($_rfcAddr->mailbox,Horde_Idna::decode($_rfcAddr->host),$_rfcAddr->personal);
2303 2690
 				}
2304
-				if (!empty($stringA)) $_string = implode(',',$stringA);
2691
+				if (!empty($stringA))
2692
+				{
2693
+					$_string = implode(',',$stringA);
2694
+				}
2305 2695
 			}
2306 2696
 			if ($_tryIDNConversion==='FORCE')
2307 2697
 			{
@@ -2326,7 +2716,10 @@  discard block
 block discarded – undo
2326 2716
 		{
2327 2717
 			return 'No Subject';
2328 2718
 		}
2329
-		if ($decode) $_string = self::decode_header($_string);
2719
+		if ($decode)
2720
+		{
2721
+			$_string = self::decode_header($_string);
2722
+		}
2330 2723
 		// make sure its utf-8
2331 2724
 		$test = @json_encode($_string);
2332 2725
 		if (($test=="null" || $test === false || is_null($test)) && strlen($_string)>0)
@@ -2364,7 +2757,8 @@  discard block
 block discarded – undo
2364 2757
 	 * @param string _parent the parent foldername
2365 2758
 	 * @return ISO-8859-1 / UTF7-IMAP encoded string
2366 2759
 	 */
2367
-	function _encodeFolderName($_folderName) {
2760
+	function _encodeFolderName($_folderName)
2761
+	{
2368 2762
 		return Translation::convert($_folderName, self::$displayCharset, 'ISO-8859-1');
2369 2763
 		#return Translation::convert($_folderName, self::$displayCharset, 'UTF7-IMAP');
2370 2764
 	}
@@ -2380,21 +2774,36 @@  discard block
 block discarded – undo
2380 2774
 	 */
2381 2775
 	function createFolder($_parent, $_folderName, &$_error)
2382 2776
 	{
2383
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2777
+		if (self::$debug)
2778
+		{
2779
+			error_log(__METHOD__.' ('.__LINE__.') '."->"."$_parent, $_folderName called from:".function_backtrace());
2780
+		}
2384 2781
 		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2385 2782
 		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2386 2783
 
2387
-		if(empty($parent)) {
2784
+		if(empty($parent))
2785
+		{
2388 2786
 			$newFolderName = $folderName;
2389
-		} else {
2787
+		}
2788
+		else
2789
+		{
2390 2790
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2391 2791
 			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2392 2792
 		}
2393
-		if (empty($newFolderName)) return false;
2394
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2793
+		if (empty($newFolderName))
2794
+		{
2795
+			return false;
2796
+		}
2797
+		if (self::$debug)
2798
+		{
2799
+			error_log(__METHOD__.' ('.__LINE__.') '.'->'.$newFolderName);
2800
+		}
2395 2801
 		if ($this->folderExists($newFolderName,true))
2396 2802
 		{
2397
-			if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2803
+			if (self::$debug)
2804
+			{
2805
+				error_log(__METHOD__.' ('.__LINE__.') '." Folder $newFolderName already exists.");
2806
+			}
2398 2807
 			return $newFolderName;
2399 2808
 		}
2400 2809
 		try
@@ -2442,13 +2851,19 @@  discard block
 block discarded – undo
2442 2851
 		$parent		= $_parent;//$this->_encodeFolderName($_parent);
2443 2852
 		$folderName	= $_folderName;//$this->_encodeFolderName($_folderName);
2444 2853
 
2445
-		if(empty($parent)) {
2854
+		if(empty($parent))
2855
+		{
2446 2856
 			$newFolderName = $folderName;
2447
-		} else {
2857
+		}
2858
+		else
2859
+		{
2448 2860
 			$HierarchyDelimiter = $this->getHierarchyDelimiter();
2449 2861
 			$newFolderName = $parent . $HierarchyDelimiter . $folderName;
2450 2862
 		}
2451
-		if (self::$debug) error_log("create folder: $newFolderName");
2863
+		if (self::$debug)
2864
+		{
2865
+			error_log("create folder: $newFolderName");
2866
+		}
2452 2867
 		try
2453 2868
 		{
2454 2869
 			$this->icServer->renameMailbox($oldFolderName, $newFolderName);
@@ -2522,8 +2937,14 @@  discard block
 block discarded – undo
2522 2937
 	 */
2523 2938
 	function getFolderObjects($_subscribedOnly=false, $_getCounters=false, $_alwaysGetDefaultFolders=false,$_useCacheIfPossible=true)
2524 2939
 	{
2525
-		if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2526
-		if (self::$debugTimes) $starttime = microtime (true);
2940
+		if (self::$debug)
2941
+		{
2942
+			error_log(__METHOD__.' ('.__LINE__.') '.' ServerID:'.$this->icServer->ImapServerId.", subscribedOnly:$_subscribedOnly, getCounters:$_getCounters, alwaysGetDefaultFolders:$_alwaysGetDefaultFolders, _useCacheIfPossible:$_useCacheIfPossible");
2943
+		}
2944
+		if (self::$debugTimes)
2945
+		{
2946
+			$starttime = microtime (true);
2947
+		}
2527 2948
 		static $folders2return;
2528 2949
 		//$_subscribedOnly=false;
2529 2950
 		// always use static on single request if info is available;
@@ -2531,23 +2952,35 @@  discard block
 block discarded – undo
2531 2952
 		// set $_useCacheIfPossible to false !
2532 2953
 		if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2533 2954
 		{
2534
-			if (self::$debugTimes) self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2955
+			if (self::$debugTimes)
2956
+			{
2957
+				self::logRunTimes($starttime,null,'using static',__METHOD__.' ('.__LINE__.') ');
2958
+			}
2535 2959
 			return $folders2return[$this->icServer->ImapServerId];
2536 2960
 		}
2537 2961
 
2538 2962
 		if ($_subscribedOnly && $_getCounters===false)
2539 2963
 		{
2540
-			if (is_null($folders2return)) $folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2964
+			if (is_null($folders2return))
2965
+			{
2966
+				$folders2return = Cache::getCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2967
+			}
2541 2968
 			if ($_useCacheIfPossible && isset($folders2return[$this->icServer->ImapServerId]) && !empty($folders2return[$this->icServer->ImapServerId]))
2542 2969
 			{
2543 2970
 				//error_log(__METHOD__.' ('.__LINE__.') '.' using Cached folderObjects'.array2string($folders2return[$this->icServer->ImapServerId]));
2544
-				if (self::$debugTimes) self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
2971
+				if (self::$debugTimes)
2972
+				{
2973
+					self::logRunTimes($starttime,null,'from Cache',__METHOD__.' ('.__LINE__.') ');
2974
+				}
2545 2975
 				return $folders2return[$this->icServer->ImapServerId];
2546 2976
 			}
2547 2977
 		}
2548 2978
 		// use $folderBasicInfo for holding attributes and other basic folderinfo $folderBasicInfo[$this->icServer->ImapServerId]
2549 2979
 		static $folderBasicInfo;
2550
-		if (is_null($folderBasicInfo)||!isset($folderBasicInfo[$this->icServer->ImapServerId])) $folderBasicInfo = Cache::getCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2980
+		if (is_null($folderBasicInfo)||!isset($folderBasicInfo[$this->icServer->ImapServerId]))
2981
+		{
2982
+			$folderBasicInfo = Cache::getCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
2983
+		}
2551 2984
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string(array_keys($folderBasicInfo[$this->icServer->ImapServerId])));
2552 2985
 
2553 2986
 		$delimiter = $this->getHierarchyDelimiter();
@@ -2560,7 +2993,8 @@  discard block
 block discarded – undo
2560 2993
 		$inboxData->shortFolderName	= 'INBOX';
2561 2994
 		$inboxData->shortDisplayName	= lang('INBOX');
2562 2995
 		$inboxData->subscribed = true;
2563
-		if($_getCounters == true) {
2996
+		if($_getCounters == true)
2997
+		{
2564 2998
 			$inboxData->counter = $this->getMailBoxCounters('INBOX');
2565 2999
 		}
2566 3000
 		// force unsubscribed by preference showAllFoldersInFolderPane
@@ -2579,12 +3013,14 @@  discard block
 block discarded – undo
2579 3013
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2580 3014
 		if (is_array($nameSpace))
2581 3015
 		{
2582
-			foreach($nameSpace as $k => $singleNameSpace) {
3016
+			foreach($nameSpace as $k => $singleNameSpace)
3017
+			{
2583 3018
 				$type = $singleNameSpace['type'];
2584 3019
 				// the following line (assumption that for the same namespace the delimiter should be equal) may be wrong
2585 3020
 				$foldersNameSpace[$type]['delimiter']  = $singleNameSpace['delimiter'];
2586 3021
 
2587
-				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false) {
3022
+				if(is_array($singleNameSpace)&&$fetchedAllInOneGo==false)
3023
+				{
2588 3024
 					// fetch and sort the subscribed folders
2589 3025
 					// we alway fetch the subscribed, as this provides the only way to tell
2590 3026
 					// if a folder is subscribed or not
@@ -2635,8 +3071,12 @@  discard block
 block discarded – undo
2635 3071
 							}
2636 3072
 						}
2637 3073
 						//error_log(__METHOD__.' ('.__LINE__.') '.' '.$type.'->'.array2string($foldersNameSpace[$type]['subscribed']));
2638
-						if (!is_array($foldersNameSpace[$type]['all'])) $foldersNameSpace[$type]['all'] = array();
2639
-						if ($_subscribedOnly == true && !empty($foldersNameSpace[$type]['subscribed'])) {
3074
+						if (!is_array($foldersNameSpace[$type]['all']))
3075
+						{
3076
+							$foldersNameSpace[$type]['all'] = array();
3077
+						}
3078
+						if ($_subscribedOnly == true && !empty($foldersNameSpace[$type]['subscribed']))
3079
+						{
2640 3080
 							continue;
2641 3081
 						}
2642 3082
 
@@ -2666,7 +3106,8 @@  discard block
 block discarded – undo
2666 3106
 					}
2667 3107
 
2668 3108
 					//error_log(__METHOD__.' ('.__LINE__.') '.' '.$type.'->'.array2string($allMailboxesExt));
2669
-					foreach ($allMailboxesExt as $mbx) {
3109
+					foreach ($allMailboxesExt as $mbx)
3110
+					{
2670 3111
 						if (!isset($folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]))
2671 3112
 						{
2672 3113
 							$folderBasicInfo[$this->icServer->ImapServerId][$mbx['MAILBOX']]=array(
@@ -2689,20 +3130,33 @@  discard block
 block discarded – undo
2689 3130
 						if (isset($allMailBoxesExtSorted[$mbx['MAILBOX']])||
2690 3131
 							isset($allMailBoxesExtSorted[$mbx['MAILBOX'].$foldersNameSpace[$type]['delimiter']])||
2691 3132
 							(substr($mbx['MAILBOX'],-1)==$foldersNameSpace[$type]['delimiter'] && isset($allMailBoxesExtSorted[substr($mbx['MAILBOX'],0,-1)]))
2692
-						) continue;
3133
+						)
3134
+						{
3135
+							continue;
3136
+						}
2693 3137
 
2694 3138
 						//echo '#'.$mbx['MAILBOX'].':'.array2string($mbx)."#<br>";
2695 3139
 						$allMailBoxesExtSorted[$mbx['MAILBOX']] = $mbx;
2696 3140
 					}
2697
-					if (is_array($allMailBoxesExtSorted)) ksort($allMailBoxesExtSorted);
3141
+					if (is_array($allMailBoxesExtSorted))
3142
+					{
3143
+						ksort($allMailBoxesExtSorted);
3144
+					}
2698 3145
 					//_debug_array(array_keys($allMailBoxesExtSorted));
2699 3146
 					$allMailboxes = array();
2700
-					foreach ((array)$allMailBoxesExtSorted as $mbx) {
2701
-						if (!in_array($mbx['MAILBOX'],$allMailboxes)) $allMailboxes[] = $mbx['MAILBOX'];
3147
+					foreach ((array)$allMailBoxesExtSorted as $mbx)
3148
+					{
3149
+						if (!in_array($mbx['MAILBOX'],$allMailboxes))
3150
+						{
3151
+							$allMailboxes[] = $mbx['MAILBOX'];
3152
+						}
2702 3153
 						//echo "Result:";_debug_array($allMailboxes);
2703 3154
 					}
2704 3155
 					$foldersNameSpace[$type]['all'] = $allMailboxes;
2705
-					if (is_array($foldersNameSpace[$type]['all'])) sort($foldersNameSpace[$type]['all']);
3156
+					if (is_array($foldersNameSpace[$type]['all']))
3157
+					{
3158
+						sort($foldersNameSpace[$type]['all']);
3159
+					}
2706 3160
 				}
2707 3161
 			}
2708 3162
 		}
@@ -2711,24 +3165,50 @@  discard block
 block discarded – undo
2711 3165
 		//echo "<br>FolderNameSpace To Process:";_debug_array($foldersNameSpace);
2712 3166
 		$autoFolderObjects = $folders = array();
2713 3167
 		$autofolder_exists = array();
2714
-		foreach( array('personal', 'others', 'shared') as $type) {
2715
-			if(isset($foldersNameSpace[$type])) {
2716
-				if($_subscribedOnly) {
2717
-					if( !empty($foldersNameSpace[$type]['subscribed']) ) $listOfFolders = $foldersNameSpace[$type]['subscribed'];
2718
-				} else {
2719
-					if( !empty($foldersNameSpace[$type]['all'])) $listOfFolders = $foldersNameSpace[$type]['all'];
2720
-				}
2721
-				foreach((array)$listOfFolders as $folderName) {
3168
+		foreach( array('personal', 'others', 'shared') as $type)
3169
+		{
3170
+			if(isset($foldersNameSpace[$type]))
3171
+			{
3172
+				if($_subscribedOnly)
3173
+				{
3174
+					if( !empty($foldersNameSpace[$type]['subscribed']) )
3175
+					{
3176
+						$listOfFolders = $foldersNameSpace[$type]['subscribed'];
3177
+					}
3178
+				}
3179
+				else
3180
+				{
3181
+					if( !empty($foldersNameSpace[$type]['all']))
3182
+					{
3183
+						$listOfFolders = $foldersNameSpace[$type]['all'];
3184
+					}
3185
+				}
3186
+				foreach((array)$listOfFolders as $folderName)
3187
+				{
2722 3188
 					//echo "<br>FolderToCheck:$folderName<br>";
2723 3189
 					//error_log(__METHOD__.__LINE__.'#Delimiter:'.$delimiter.':#'.$folderName);
2724
-					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all'])) continue;//when subscribedonly, we fetch all folders in one go.
2725
-					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all']))) {
3190
+					if ($_subscribedOnly && empty($foldersNameSpace[$type]['all']))
3191
+					{
3192
+						continue;
3193
+					}
3194
+					//when subscribedonly, we fetch all folders in one go.
3195
+					if($_subscribedOnly && !(in_array($folderName, $foldersNameSpace[$type]['all'])||in_array($folderName.$foldersNameSpace[$type]['delimiter'], $foldersNameSpace[$type]['all'])))
3196
+					{
2726 3197
 						#echo "$folderName failed to be here <br>";
2727 3198
 						continue;
2728 3199
 					}
2729
-					if (isset($folders[$folderName])) continue;
2730
-					if (isset($autoFolderObjects[$folderName])) continue;
2731
-					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter']) $delimiter = $foldersNameSpace[$type]['delimiter'];
3200
+					if (isset($folders[$folderName]))
3201
+					{
3202
+						continue;
3203
+					}
3204
+					if (isset($autoFolderObjects[$folderName]))
3205
+					{
3206
+						continue;
3207
+					}
3208
+					if (empty($delimiter)||$delimiter != $foldersNameSpace[$type]['delimiter'])
3209
+					{
3210
+						$delimiter = $foldersNameSpace[$type]['delimiter'];
3211
+					}
2732 3212
 					$folderParts = explode($delimiter, $folderName);
2733 3213
 					$shortName = array_pop($folderParts);
2734 3214
 
@@ -2736,17 +3216,20 @@  discard block
 block discarded – undo
2736 3216
 					$folderObject->delimiter	= $delimiter;
2737 3217
 					$folderObject->folderName	= $folderName;
2738 3218
 					$folderObject->shortFolderName	= $shortName;
2739
-					if(!$_subscribedOnly) {
3219
+					if(!$_subscribedOnly)
3220
+					{
2740 3221
 						#echo $folderName."->".$type."<br>";
2741 3222
 						#_debug_array($foldersNameSpace[$type]['subscribed']);
2742 3223
 						$folderObject->subscribed = in_array($folderName, (array)$foldersNameSpace[$type]['subscribed']);
2743 3224
 					}
2744 3225
 
2745
-					if($_getCounters == true) {
3226
+					if($_getCounters == true)
3227
+					{
2746 3228
 						//error_log(__METHOD__.' ('.__LINE__.') '.' getCounter forFolder:'.$folderName);
2747 3229
 						$folderObject->counter = $this->getMailBoxCounters($folderName);
2748 3230
 					}
2749
-					if(strtoupper($folderName) == 'INBOX') {
3231
+					if(strtoupper($folderName) == 'INBOX')
3232
+					{
2750 3233
 						$folderName = 'INBOX';
2751 3234
 						$folderObject->folderName	= 'INBOX';
2752 3235
 						$folderObject->shortFolderName	= 'INBOX';
@@ -2754,24 +3237,34 @@  discard block
 block discarded – undo
2754 3237
 						$folderObject->shortDisplayName = lang('INBOX');
2755 3238
 						$folderObject->subscribed	= true;
2756 3239
 					// translate the automatic Folders (Sent, Drafts, ...) like the INBOX
2757
-					} elseif (in_array($shortName,self::$autoFolders)) {
3240
+					}
3241
+					elseif (in_array($shortName,self::$autoFolders))
3242
+					{
2758 3243
 						$tmpfolderparts = explode($delimiter,$folderObject->folderName);
2759 3244
 						array_pop($tmpfolderparts);
2760 3245
 						$folderObject->displayName = implode($delimiter,$tmpfolderparts).$delimiter.lang($shortName);
2761 3246
 						$folderObject->shortDisplayName = lang($shortName);
2762 3247
 						unset($tmpfolderparts);
2763
-					} else {
3248
+					}
3249
+					else
3250
+					{
2764 3251
 						$folderObject->displayName = $folderObject->folderName;
2765 3252
 						$folderObject->shortDisplayName = $shortName;
2766 3253
 					}
2767 3254
 					//$folderName = $folderName;
2768
-					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false) {
3255
+					if (in_array($shortName,self::$autoFolders)&&self::searchValueInFolderObjects($shortName,$autoFolderObjects)===false)
3256
+					{
2769 3257
 						$autoFolderObjects[$folderName] = $folderObject;
2770
-					} else {
3258
+					}
3259
+					else
3260
+					{
2771 3261
 						$folders[$folderName] = $folderObject;
2772 3262
 					}
2773 3263
 					//error_log(__METHOD__.' ('.__LINE__.') '.':'.$folderObject->folderName);
2774
-					if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders ();
3264
+					if (!isset(self::$specialUseFolders))
3265
+					{
3266
+						$this->getSpecialUseFolders ();
3267
+					}
2775 3268
 					if (isset(self::$specialUseFolders[$folderName]))
2776 3269
 					{
2777 3270
 						$autofolder_exists[$folderName] = self::$specialUseFolders[$folderName];
@@ -2779,7 +3272,8 @@  discard block
 block discarded – undo
2779 3272
 				}
2780 3273
 			}
2781 3274
 		}
2782
-		if (is_array($autoFolderObjects) && !empty($autoFolderObjects)) {
3275
+		if (is_array($autoFolderObjects) && !empty($autoFolderObjects))
3276
+		{
2783 3277
 			uasort($autoFolderObjects,array($this,"sortByAutoFolderPos"));
2784 3278
 		}
2785 3279
 		// check if some standard folders are missing and need to be created
@@ -2788,7 +3282,10 @@  discard block
 block discarded – undo
2788 3282
 			// if new folders have been created, re-read folders ignoring the cache
2789 3283
 			return $this->getFolderObjects($_subscribedOnly, $_getCounters, $_alwaysGetDefaultFolders, false);	// false = do NOT use cache
2790 3284
 		}
2791
-		if (is_array($folders)) uasort($folders,array($this,"sortByDisplayName"));
3285
+		if (is_array($folders))
3286
+		{
3287
+			uasort($folders,array($this,"sortByDisplayName"));
3288
+		}
2792 3289
 		//$folders2return = array_merge($autoFolderObjects,$folders);
2793 3290
 		//_debug_array($folders2return); #exit;
2794 3291
 		$folders2return[$this->icServer->ImapServerId] = array_merge((array)$inboxFolderObject,(array)$autoFolderObjects,(array)$folders);
@@ -2800,7 +3297,10 @@  discard block
 block discarded – undo
2800 3297
 			Cache::setCache(Cache::INSTANCE,'email','folderObjects'.trim($GLOBALS['egw_info']['user']['account_id']),$folders2return,$expiration=60*60*1);
2801 3298
 		}
2802 3299
 		Cache::setCache(Cache::INSTANCE,'email','folderBasicInfo'.trim($GLOBALS['egw_info']['user']['account_id']),$folderBasicInfo,$expiration=60*60*1);
2803
-		if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
3300
+		if (self::$debugTimes)
3301
+		{
3302
+			self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') ');
3303
+		}
2804 3304
 		return $folders2return[$this->icServer->ImapServerId];
2805 3305
 	}
2806 3306
 
@@ -2828,31 +3328,44 @@  discard block
 block discarded – undo
2828 3328
 
2829 3329
 		$folders = $nameSpace =  array();
2830 3330
 		$nameSpaceTmp = $this->_getNameSpaces();
2831
-		foreach($nameSpaceTmp as $k => $singleNameSpace) {
3331
+		foreach($nameSpaceTmp as $k => $singleNameSpace)
3332
+		{
2832 3333
 			$nameSpace[$singleNameSpace['type']]=$singleNameSpace;
2833 3334
 		}
2834 3335
 		unset($nameSpaceTmp);
2835 3336
 
2836 3337
 		//error_log(__METHOD__.__LINE__.array2string($nameSpace));
2837 3338
 		// Get special use folders
2838
-		if (!isset(self::$specialUseFolders)) $this->getSpecialUseFolders (); // Set self::$specialUseFolders
3339
+		if (!isset(self::$specialUseFolders))
3340
+		{
3341
+			$this->getSpecialUseFolders ();
3342
+		}
3343
+		// Set self::$specialUseFolders
2839 3344
 		// topLevelQueries generally ignore the $_search param. Except for Config::examineNamespace
2840
-		if ($_onlyTopLevel) // top level leaves
3345
+		if ($_onlyTopLevel)
3346
+		{
3347
+			// top level leaves
2841 3348
 		{
2842 3349
 			// Get top mailboxes of icServer
2843 3350
 			$topFolders = $this->icServer->getMailboxes("", 2, true);
3351
+		}
2844 3352
 			// Trigger examination of namespace to retrieve
2845 3353
 			// folders located in other and shared; needed only for some servers
2846
-			if (is_null(self::$mailConfig)) self::$mailConfig = Config::read('mail');
3354
+			if (is_null(self::$mailConfig))
3355
+			{
3356
+				self::$mailConfig = Config::read('mail');
3357
+			}
2847 3358
 			if (self::$mailConfig['examineNamespace'])
2848 3359
 			{
2849 3360
 				$prefixes=array();
2850 3361
 				if (is_array($nameSpace))
2851 3362
 				{
2852
-					foreach($nameSpace as $k => $singleNameSpace) {
3363
+					foreach($nameSpace as $k => $singleNameSpace)
3364
+					{
2853 3365
 						$type = $singleNameSpace['type'];
2854 3366
 
2855
-						if(is_array($singleNameSpace) && $singleNameSpace['prefix']){
3367
+						if(is_array($singleNameSpace) && $singleNameSpace['prefix'])
3368
+						{
2856 3369
 							$prefixes[$type] = $singleNameSpace['prefix'];
2857 3370
 							//regard extra care for nameSpacequeries when configured AND respect $_search
2858 3371
 							$result = $this->icServer->getMailboxes($singleNameSpace['prefix'], $_search==0?0:2, true);
@@ -2928,7 +3441,10 @@  discard block
 block discarded – undo
2928 3441
 							$nFolders [$path] = $folder;
2929 3442
 						}
2930 3443
 					}
2931
-					if (is_array($aFolders)) uasort ($aFolders, array($this,'sortByAutofolder'));
3444
+					if (is_array($aFolders))
3445
+					{
3446
+						uasort ($aFolders, array($this,'sortByAutofolder'));
3447
+					}
2932 3448
 					//ksort($aFolders);
2933 3449
 
2934 3450
 					// Sort none auto folders base on mailbox name
@@ -2938,12 +3454,17 @@  discard block
 block discarded – undo
2938 3454
 				}
2939 3455
 				else
2940 3456
 				{
2941
-					if (is_array($subFolders)) ksort($subFolders);
3457
+					if (is_array($subFolders))
3458
+					{
3459
+						ksort($subFolders);
3460
+					}
2942 3461
 				}
2943 3462
 				$folders = array_merge($folders,(array)$mainFolder, (array)$subFolders);
2944 3463
 			}
2945 3464
 		}
2946
-		elseif ($_nodePath) // single node
3465
+		elseif ($_nodePath)
3466
+		{
3467
+			// single node
2947 3468
 		{
2948 3469
 			switch ($_search)
2949 3470
 			{
@@ -2951,6 +3472,7 @@  discard block
 block discarded – undo
2951 3472
 				case 0:
2952 3473
 				case 2:
2953 3474
 					$path = $_nodePath.''.$delimiter;
3475
+		}
2954 3476
 					break;
2955 3477
 				// Node itself
2956 3478
 				// shouldn't contain next level delimiter
@@ -2969,11 +3491,14 @@  discard block
 block discarded – undo
2969 3491
 
2970 3492
 			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
2971 3493
 		}
2972
-		elseif(!$_nodePath) // all
3494
+		elseif(!$_nodePath)
3495
+		{
3496
+			// all
2973 3497
 		{
2974 3498
 			if ($_subscribedOnly)
2975 3499
 			{
2976 3500
 				$folders = $this->icServer->listSubscribedMailboxes('', 0, true);
3501
+		}
2977 3502
 			}
2978 3503
 			else
2979 3504
 			{
@@ -2985,7 +3510,10 @@  discard block
 block discarded – undo
2985 3510
 		{
2986 3511
 			// SORTING FOLDERS
2987 3512
 			//self::$debugTimes=true;
2988
-			if (self::$debugTimes) $starttime = microtime (true);
3513
+			if (self::$debugTimes)
3514
+			{
3515
+				$starttime = microtime (true);
3516
+			}
2989 3517
 			// Merge of all auto folders and specialusefolders
2990 3518
 			$autoFoldersTmp = array_unique((array_merge(self::$autoFolders, array_values(self::$specialUseFolders))));
2991 3519
 			uasort($folders,array($this,'sortByMailbox'));//ksort($folders);
@@ -2995,73 +3523,103 @@  discard block
 block discarded – undo
2995 3523
 			$isGoogleMail=false;
2996 3524
 			foreach($autoFoldersTmp as $afk=>$aF)
2997 3525
 			{
2998
-				if (!isset($mySpecialUseFolders[$aF]) && $aF) $mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
3526
+				if (!isset($mySpecialUseFolders[$aF]) && $aF)
3527
+				{
3528
+					$mySpecialUseFolders[$aF]=$this->getFolderByType($aF,false);
3529
+				}
2999 3530
 				//error_log($afk.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3000 3531
 			}
3001 3532
 			//error_log(array2string($mySpecialUseFolders));
3002
-			foreach ($tmpFolders as $k => $f) {
3533
+			foreach ($tmpFolders as $k => $f)
3534
+			{
3003 3535
 				$sorted=false;
3004
-				if (strtoupper(substr($k,0,5))=='INBOX') {
3005
-					if (strtoupper($k)=='INBOX') {
3536
+				if (strtoupper(substr($k,0,5))=='INBOX')
3537
+				{
3538
+					if (strtoupper($k)=='INBOX')
3539
+					{
3006 3540
 						//error_log(__METHOD__.__LINE__.':'.strtoupper(substr($k,0,5)).':'.$k);
3007 3541
 						$inboxFolderObject[$k]=$f;
3008 3542
 						unset($folders[$k]);
3009 3543
 						$sorted=true;
3010
-					} else {
3544
+					}
3545
+					else
3546
+					{
3011 3547
 						$isAutoFolder=false;
3012 3548
 						foreach($autoFoldersTmp as $afk=>$aF)
3013 3549
 						{
3014 3550
 							//error_log(__METHOD__.__LINE__.$k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3015 3551
 							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3016 3552
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter || //k may be child of an autofolder
3017
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3553
+								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3554
+							{
3555
+								// k is parent of an autofolder
3018 3556
 							{
3019 3557
 								//error_log(__METHOD__.__LINE__.$k.'->'.$mySpecialUseFolders[$aF]);
3020 3558
 								$isAutoFolder=true;
3559
+							}
3021 3560
 								$autoFolderObjects[$k]=$f;
3022 3561
 								break;
3023 3562
 							}
3024 3563
 						}
3025
-						if ($isAutoFolder==false) $inboxSubFolderObjects[$k]=$f;
3564
+						if ($isAutoFolder==false)
3565
+						{
3566
+							$inboxSubFolderObjects[$k]=$f;
3567
+						}
3026 3568
 						unset($folders[$k]);
3027 3569
 						$sorted=true;
3028 3570
 					}
3029
-				} elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]') {
3571
+				}
3572
+				elseif (strtoupper(substr($k,0,13))=='[GOOGLE MAIL]')
3573
+				{
3030 3574
 					$isGoogleMail=true;
3031
-					if (strtoupper($k)=='[GOOGLE MAIL]') {
3575
+					if (strtoupper($k)=='[GOOGLE MAIL]')
3576
+					{
3032 3577
 						$googleMailFolderObject[$k]=$f;
3033 3578
 						unset($folders[$k]);
3034 3579
 						$sorted=true;
3035
-					} else {
3580
+					}
3581
+					else
3582
+					{
3036 3583
 						$isAutoFolder=false;
3037 3584
 						foreach($autoFoldersTmp as $afk=>$aF)
3038 3585
 						{
3039 3586
 							//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3040 3587
 							if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3041 3588
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3042
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3589
+								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3590
+							{
3591
+								// k is parent of an autofolder
3043 3592
 							{
3044 3593
 								//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3045 3594
 								$isAutoFolder=true;
3595
+							}
3046 3596
 								$googleAutoFolderObjects[$k]=$f;
3047 3597
 								break;
3048 3598
 							}
3049 3599
 						}
3050
-						if ($isAutoFolder==false) $googleSubFolderObjects[$k]=$f;
3600
+						if ($isAutoFolder==false)
3601
+						{
3602
+							$googleSubFolderObjects[$k]=$f;
3603
+						}
3051 3604
 						unset($folders[$k]);
3052 3605
 						$sorted=true;
3053 3606
 					}
3054
-				} else {
3607
+				}
3608
+				else
3609
+				{
3055 3610
 					$isAutoFolder=false;
3056 3611
 					foreach($autoFoldersTmp as $afk=>$aF)
3057 3612
 					{
3058 3613
 						//error_log($k.':'.$aF.'->'.$mySpecialUseFolders[$aF]);
3059 3614
 						if($aF && strlen($mySpecialUseFolders[$aF])&&/*strlen($k)>=strlen($mySpecialUseFolders[$aF])&&*/
3060 3615
 								($mySpecialUseFolders[$aF]==$k || substr($k,0,strlen($mySpecialUseFolders[$aF].$delimiter))==$mySpecialUseFolders[$aF].$delimiter|| //k may be child of an autofolder
3061
-								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false)) // k is parent of an autofolder
3616
+								stristr($mySpecialUseFolders[$aF],$k.$delimiter)!==false))
3617
+						{
3618
+							// k is parent of an autofolder
3062 3619
 						{
3063 3620
 							//error_log($k.'->'.$mySpecialUseFolders[$aF]);
3064 3621
 							$isAutoFolder=true;
3622
+						}
3065 3623
 							$autoFolderObjects[$k]=$f;
3066 3624
 							unset($folders[$k]);
3067 3625
 							$sorted=true;
@@ -3077,7 +3635,8 @@  discard block
 block discarded – undo
3077 3635
 						if ($nameSpace[$type]['prefix_present']&&$nameSpace[$type]['prefix'])
3078 3636
 						{
3079 3637
 							if (substr($k,0,strlen($nameSpace[$type]['prefix']))==$nameSpace[$type]['prefix']||
3080
-								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1)) {
3638
+								substr($k,0,strlen($nameSpace[$type]['prefix'])-strlen($nameSpace[$type]['delimiter']))==substr($nameSpace[$type]['prefix'],0,strlen($nameSpace[$type]['delimiter'])*-1))
3639
+							{
3081 3640
 								//error_log(__METHOD__.__LINE__.':'.substr($k,0,strlen($nameSpace[$type]['prefix'])).':'.$k);
3082 3641
 								$typeFolderObject[$type][$k]=$f;
3083 3642
 								unset($folders[$k]);
@@ -3104,9 +3663,12 @@  discard block
 block discarded – undo
3104 3663
 				}
3105 3664
 			}
3106 3665
 			//error_log(__METHOD__.__LINE__.array2string($autoFolderObjects));
3107
-			if (!$isGoogleMail) {
3666
+			if (!$isGoogleMail)
3667
+			{
3108 3668
 				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$inboxSubFolderObjects,(array)$folders,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3109
-			} else {
3669
+			}
3670
+			else
3671
+			{
3110 3672
 				// avoid calling sortByAutoFolder as it is not regarding subfolders
3111 3673
 				$gAutoFolderObjectsTmp = $googleAutoFolderObjects;
3112 3674
 				unset($googleAutoFolderObjects);
@@ -3123,7 +3685,10 @@  discard block
 block discarded – undo
3123 3685
 				}
3124 3686
 				$folders = array_merge($inboxFolderObject,$autoFolderObjects,(array)$folders,(array)$googleMailFolderObject,$googleAutoFolderObjects,$googleSubFolderObjects,(array)$typeFolderObject['others'],(array)$typeFolderObject['shared']);
3125 3687
 			}
3126
-			if (self::$debugTimes) self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3688
+			if (self::$debugTimes)
3689
+			{
3690
+				self::logRunTimes($starttime,null,function_backtrace(),__METHOD__.' ('.__LINE__.') Sorting:');
3691
+			}
3127 3692
 			//self::$debugTimes=false;
3128 3693
 		}
3129 3694
 		// Get counter information and add them to each fetched folders array
@@ -3173,7 +3738,13 @@  discard block
 block discarded – undo
3173 3738
 		$rv = false;
3174 3739
 		foreach ($haystack as $k => $v)
3175 3740
 		{
3176
-			foreach($v as &$sv) {if (trim($sv)==trim($needle)) return $k;}
3741
+			foreach($v as &$sv)
3742
+			{
3743
+if (trim($sv)==trim($needle))
3744
+			{
3745
+				return $k;
3746
+			}
3747
+			}
3177 3748
 		}
3178 3749
 		return $rv;
3179 3750
 	}
@@ -3200,7 +3771,10 @@  discard block
 block discarded – undo
3200 3771
 	 */
3201 3772
 	static function pathToFolderData ($_path, $_hDelimiter)
3202 3773
 	{
3203
-		if (!strpos($_path, self::DELIMITER)) $_path = self::DELIMITER.$_path;
3774
+		if (!strpos($_path, self::DELIMITER))
3775
+		{
3776
+			$_path = self::DELIMITER.$_path;
3777
+		}
3204 3778
 		list(,$path) = explode(self::DELIMITER, $_path);
3205 3779
 		$path_chain = $parts = explode($_hDelimiter, $path);
3206 3780
 		$name = array_pop($parts);
@@ -3229,7 +3803,10 @@  discard block
 block discarded – undo
3229 3803
 		$b = self::pathToFolderData($_b['MAILBOX'], $_b['delimiter']);
3230 3804
 		$pos1 = array_search(trim($a['name']),self::$autoFolders);
3231 3805
 		$pos2 = array_search(trim($b['name']),self::$autoFolders);
3232
-		if ($pos1 == $pos2) return 0;
3806
+		if ($pos1 == $pos2)
3807
+		{
3808
+			return 0;
3809
+		}
3233 3810
 		return ($pos1 < $pos2) ? -1 : 1;
3234 3811
 	}
3235 3812
 
@@ -3260,7 +3837,10 @@  discard block
 block discarded – undo
3260 3837
 		// 0, 1 und -1
3261 3838
 		$pos1 = array_search(trim($a->shortFolderName),self::$autoFolders);
3262 3839
 		$pos2 = array_search(trim($b->shortFolderName),self::$autoFolders);
3263
-		if ($pos1 == $pos2) return 0;
3840
+		if ($pos1 == $pos2)
3841
+		{
3842
+			return 0;
3843
+		}
3264 3844
 		return ($pos1 < $pos2) ? -1 : 1;
3265 3845
 	}
3266 3846
 
@@ -3281,11 +3861,18 @@  discard block
 block discarded – undo
3281 3861
 		}
3282 3862
 		catch (\Exception $e)
3283 3863
 		{
3284
-			if (self::$debug) error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3864
+			if (self::$debug)
3865
+			{
3866
+				error_log(__METHOD__." returned FolderStatus for Folder $folderName:".$e->getMessage());
3867
+			}
3285 3868
 			return false;
3286 3869
 		}
3287
-		if(is_array($folderStatus)) {
3288
-			if ($_returnObject===false) return $folderStatus;
3870
+		if(is_array($folderStatus))
3871
+		{
3872
+			if ($_returnObject===false)
3873
+			{
3874
+				return $folderStatus;
3875
+			}
3289 3876
 			$status =  new \stdClass;
3290 3877
 			$status->messages   = $folderStatus['MESSAGES'];
3291 3878
 			$status->unseen     = $folderStatus['UNSEEN'];
@@ -3312,7 +3899,8 @@  discard block
 block discarded – undo
3312 3899
 	{
3313 3900
 		#echo __METHOD__." retrieve SubFolders for $_mailbox$delimiter <br>";
3314 3901
 		$maxreclevel=25;
3315
-		if ($reclevel > $maxreclevel) {
3902
+		if ($reclevel > $maxreclevel)
3903
+		{
3316 3904
 			error_log( __METHOD__." Recursion Level Exeeded ($reclevel) while looking up $_mailbox$delimiter ");
3317 3905
 			return array();
3318 3906
 		}
@@ -3326,7 +3914,8 @@  discard block
 block discarded – undo
3326 3914
 //error_log(__METHOD__.' ('.__LINE__.') '.' Delimiter:'.array2string($delimiter));
3327 3915
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbx));
3328 3916
 		// Example: Array([INBOX/GaGa] => Array([MAILBOX] => INBOX/GaGa[ATTRIBUTES] => Array([0] => \\unmarked)[delimiter] => /))
3329
-		if (is_array($mbx[$mbxkeys[0]]["ATTRIBUTES"]) && (in_array('\HasChildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Haschildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\haschildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]))) {
3917
+		if (is_array($mbx[$mbxkeys[0]]["ATTRIBUTES"]) && (in_array('\HasChildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Haschildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\haschildren',$mbx[$mbxkeys[0]]["ATTRIBUTES"])))
3918
+		{
3330 3919
 			// if there are children fetch them
3331 3920
 			//echo $mbx[$mbxkeys[0]]['MAILBOX']."<br>";
3332 3921
 
@@ -3334,7 +3923,8 @@  discard block
 block discarded – undo
3334 3923
 			//$buff = $this->icServer->getMailboxes($mbx[$mbxkeys[0]]['MAILBOX'],2,false);
3335 3924
 			//_debug_array($buff);
3336 3925
 			$allMailboxes = array();
3337
-			foreach ($buff as $mbxname) {
3926
+			foreach ($buff as $mbxname)
3927
+			{
3338 3928
 //error_log(__METHOD__.' ('.__LINE__.') '.array2string($mbxname));
3339 3929
 				$mbxname = preg_replace('~'.($delimiter == '.' ? "\\".$delimiter:$delimiter).'+~s',$delimiter,$mbxname['MAILBOX']);
3340 3930
 				#echo "About to recur in level $reclevel:".$mbxname."<br>";
@@ -3343,9 +3933,14 @@  discard block
 block discarded – undo
3343 3933
 					$allMailboxes = array_merge($allMailboxes, self::getMailBoxesRecursive($mbxname, $delimiter, $prefix, $reclevel));
3344 3934
 				}
3345 3935
 			}
3346
-			if (!(in_array('\NoSelect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]))) $allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX'];
3936
+			if (!(in_array('\NoSelect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\Noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"]) || in_array('\noselect',$mbx[$mbxkeys[0]]["ATTRIBUTES"])))
3937
+			{
3938
+				$allMailboxes[] = $mbx[$mbxkeys[0]]['MAILBOX'];
3939
+			}
3347 3940
 			return $allMailboxes;
3348
-		} else {
3941
+		}
3942
+		else
3943
+		{
3349 3944
 			return array($_mailbox);
3350 3945
 		}
3351 3946
 	}
@@ -3369,14 +3964,21 @@  discard block
 block discarded – undo
3369 3964
 			'Outbox'   => array('profileKey'=>'acc_folder_outbox','autoFolderName'=>'Outbox'),
3370 3965
 			'Archive'   => array('profileKey'=>'acc_folder_archive','autoFolderName'=>'Archive'),
3371 3966
 		);
3372
-		if ($_type == 'Templates') $_type = 'Template';	// for some reason self::$autofolders uses 'Templates'!
3967
+		if ($_type == 'Templates')
3968
+		{
3969
+			$_type = 'Template';
3970
+		}
3971
+		// for some reason self::$autofolders uses 'Templates'!
3373 3972
 		$created = false;
3374 3973
 		if (!isset($types[$_type]))
3375 3974
 		{
3376 3975
 			error_log(__METHOD__.' ('.__LINE__.') '.' '.$_type.' not supported for '.__METHOD__);
3377 3976
 			return false;
3378 3977
 		}
3379
-		if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders)) self::$specialUseFolders = $this->getSpecialUseFolders();
3978
+		if (is_null(self::$specialUseFolders) || empty(self::$specialUseFolders))
3979
+		{
3980
+			self::$specialUseFolders = $this->getSpecialUseFolders();
3981
+		}
3380 3982
 
3381 3983
 		//highest precedence
3382 3984
 		try
@@ -3386,25 +3988,39 @@  discard block
 block discarded – undo
3386 3988
 		catch (\Exception $e)
3387 3989
 		{
3388 3990
 			// we know that outbox is not supported, but we use this here, as we autocreate expected SpecialUseFolders in this function
3389
-			if ($_type != 'Outbox') error_log(__METHOD__.' ('.__LINE__.') '.' Failed to retrieve Folder'.$_folderName." for ".array2string($types[$_type]).":".$e->getMessage());
3991
+			if ($_type != 'Outbox')
3992
+			{
3993
+				error_log(__METHOD__.' ('.__LINE__.') '.' Failed to retrieve Folder'.$_folderName." for ".array2string($types[$_type]).":".$e->getMessage());
3994
+			}
3390 3995
 			$_folderName = false;
3391 3996
 		}
3392 3997
 		// do not try to autocreate configured Archive-Folder. Return false if configured folder does not exist
3393
-		if ($_type == 'Archive') {
3394
-			if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
3998
+		if ($_type == 'Archive')
3999
+		{
4000
+			if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true))
4001
+			{
3395 4002
 				return false;
3396
-			} else {
4003
+			}
4004
+			else
4005
+			{
3397 4006
 				return $_folderName;
3398 4007
 			}
3399 4008
 
3400 4009
 		}
3401 4010
 		// does the folder exist??? (is configured/preset, but non-existent)
3402
-		if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true)) {
4011
+		if ($_folderName && $_checkexistance && strtolower($_folderName) !='none' && !$this->folderExists($_folderName,true))
4012
+		{
3403 4013
 			try
3404 4014
 			{
3405 4015
 				$error = null;
3406
-				if (($_folderName = $this->createFolder('', $_folderName, $error))) $created = true;
3407
-				if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4016
+				if (($_folderName = $this->createFolder('', $_folderName, $error)))
4017
+				{
4018
+					$created = true;
4019
+				}
4020
+				if ($error)
4021
+				{
4022
+					error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4023
+				}
3408 4024
 			}
3409 4025
 			catch(Exception $e)
3410 4026
 			{
@@ -3413,9 +4029,16 @@  discard block
 block discarded – undo
3413 4029
 			}
3414 4030
 		}
3415 4031
 		// not sure yet if false is the correct behavior on none
3416
-		if ($_folderName =='none') return 'none' ; //false;
4032
+		if ($_folderName =='none')
4033
+		{
4034
+			return 'none' ;
4035
+		}
4036
+		//false;
3417 4037
 		//no (valid) folder found yet; try specialUseFolders
3418
-		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders))) $_folderName = $f;
4038
+		if (empty($_folderName) && is_array(self::$specialUseFolders) && ($f = array_search($_type,self::$specialUseFolders)))
4039
+		{
4040
+			$_folderName = $f;
4041
+		}
3419 4042
 		//no specialUseFolder; try some Defaults
3420 4043
 		if (empty($_folderName) && isset($types[$_type]))
3421 4044
 		{
@@ -3441,7 +4064,10 @@  discard block
 block discarded – undo
3441 4064
 					$error = null;
3442 4065
 					$this->createFolder('', $prefix.$types[$_type]['autoFolderName'],$error);
3443 4066
 					$_folderName = $prefix.$types[$_type]['autoFolderName'];
3444
-					if ($error) error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4067
+					if ($error)
4068
+					{
4069
+						error_log(__METHOD__.' ('.__LINE__.') '.' Failed to create Folder '.$_folderName." for $_type:".$error);
4070
+					}
3445 4071
 				}
3446 4072
 				catch(Exception $e)
3447 4073
 				{
@@ -3543,17 +4169,22 @@  discard block
 block discarded – undo
3543 4169
 	function isSentFolder($_folderName, $_checkexistance=TRUE)
3544 4170
 	{
3545 4171
 		$sentFolder = $this->getSentFolder($_checkexistance);
3546
-		if(empty($sentFolder)) {
4172
+		if(empty($sentFolder))
4173
+		{
3547 4174
 			return false;
3548 4175
 		}
3549 4176
 		// does the folder exist???
3550
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4177
+		if ($_checkexistance && !$this->folderExists($_folderName))
4178
+		{
3551 4179
 			return false;
3552 4180
 		}
3553 4181
 
3554
-		if(false !== stripos($_folderName, $sentFolder)) {
4182
+		if(false !== stripos($_folderName, $sentFolder))
4183
+		{
3555 4184
 			return true;
3556
-		} else {
4185
+		}
4186
+		else
4187
+		{
3557 4188
 			return false;
3558 4189
 		}
3559 4190
 	}
@@ -3566,15 +4197,20 @@  discard block
 block discarded – undo
3566 4197
 	 */
3567 4198
 	function isOutbox($_folderName, $_checkexistance=TRUE)
3568 4199
 	{
3569
-		if (stripos($_folderName, 'Outbox')===false) {
4200
+		if (stripos($_folderName, 'Outbox')===false)
4201
+		{
3570 4202
 			return false;
3571 4203
 		}
3572 4204
 		// does the folder exist???
3573
-		if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName)) {
4205
+		if ($_checkexistance && $GLOBALS['egw_info']['user']['apps']['activesync'] && !$this->folderExists($_folderName))
4206
+		{
3574 4207
 			$outboxFolder = $this->getOutboxFolder($_checkexistance);
3575
-			if(false !== stripos($_folderName, $outboxFolder)) {
4208
+			if(false !== stripos($_folderName, $outboxFolder))
4209
+			{
3576 4210
 				return true;
3577
-			} else {
4211
+			}
4212
+			else
4213
+			{
3578 4214
 				return false;
3579 4215
 			}
3580 4216
 		}
@@ -3590,17 +4226,25 @@  discard block
 block discarded – undo
3590 4226
 	function isDraftFolder($_folderName, $_checkexistance=TRUE)
3591 4227
 	{
3592 4228
 		$draftFolder = $this->getDraftFolder($_checkexistance);
3593
-		if(empty($draftFolder)) {
4229
+		if(empty($draftFolder))
4230
+		{
3594 4231
 			return false;
3595 4232
 		}
3596 4233
 		// does the folder exist???
3597
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4234
+		if ($_checkexistance && !$this->folderExists($_folderName))
4235
+		{
3598 4236
 			return false;
3599 4237
 		}
3600
-		if (is_a($_folderName,"Horde_Imap_Client_Mailbox")) $_folderName = $_folderName->utf8;
3601
-		if(false !== stripos($_folderName, $draftFolder)) {
4238
+		if (is_a($_folderName,"Horde_Imap_Client_Mailbox"))
4239
+		{
4240
+			$_folderName = $_folderName->utf8;
4241
+		}
4242
+		if(false !== stripos($_folderName, $draftFolder))
4243
+		{
3602 4244
 			return true;
3603
-		} else {
4245
+		}
4246
+		else
4247
+		{
3604 4248
 			return false;
3605 4249
 		}
3606 4250
 	}
@@ -3614,17 +4258,22 @@  discard block
 block discarded – undo
3614 4258
 	function isTrashFolder($_folderName, $_checkexistance=TRUE)
3615 4259
 	{
3616 4260
 		$trashFolder = $this->getTrashFolder($_checkexistance);
3617
-		if(empty($trashFolder)) {
4261
+		if(empty($trashFolder))
4262
+		{
3618 4263
 			return false;
3619 4264
 		}
3620 4265
 		// does the folder exist???
3621
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4266
+		if ($_checkexistance && !$this->folderExists($_folderName))
4267
+		{
3622 4268
 			return false;
3623 4269
 		}
3624 4270
 
3625
-		if(false !== stripos($_folderName, $trashFolder)) {
4271
+		if(false !== stripos($_folderName, $trashFolder))
4272
+		{
3626 4273
 			return true;
3627
-		} else {
4274
+		}
4275
+		else
4276
+		{
3628 4277
 			return false;
3629 4278
 		}
3630 4279
 	}
@@ -3638,17 +4287,22 @@  discard block
 block discarded – undo
3638 4287
 	function isTemplateFolder($_folderName, $_checkexistance=TRUE)
3639 4288
 	{
3640 4289
 		$templateFolder = $this->getTemplateFolder($_checkexistance);
3641
-		if(empty($templateFolder)) {
4290
+		if(empty($templateFolder))
4291
+		{
3642 4292
 			return false;
3643 4293
 		}
3644 4294
 		// does the folder exist???
3645
-		if ($_checkexistance && !$this->folderExists($_folderName)) {
4295
+		if ($_checkexistance && !$this->folderExists($_folderName))
4296
+		{
3646 4297
 			return false;
3647 4298
 		}
3648 4299
 
3649
-		if(false !== stripos($_folderName, $templateFolder)) {
4300
+		if(false !== stripos($_folderName, $templateFolder))
4301
+		{
3650 4302
 			return true;
3651
-		} else {
4303
+		}
4304
+		else
4305
+		{
3652 4306
 			return false;
3653 4307
 		}
3654 4308
 	}
@@ -3666,15 +4320,27 @@  discard block
 block discarded – undo
3666 4320
 		if (empty($_folder))
3667 4321
 		{
3668 4322
 			// this error is more or less without significance, unless we force the check
3669
-			if ($_forceCheck===true) error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
4323
+			if ($_forceCheck===true)
4324
+			{
4325
+				error_log(__METHOD__.' ('.__LINE__.') '.' Called with empty Folder:'.$_folder.function_backtrace());
4326
+			}
3670 4327
 			return false;
3671 4328
 		}
3672 4329
 		// when check is not enforced , we assume a folder represented as Horde_Imap_Client_Mailbox as existing folder
3673
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false) return true;
3674
-		if (is_a($_folder,"Horde_Imap_Client_Mailbox")) $_folder =  $_folder->utf8;
4330
+		if (is_a($_folder,"Horde_Imap_Client_Mailbox")&&$_forceCheck===false)
4331
+		{
4332
+			return true;
4333
+		}
4334
+		if (is_a($_folder,"Horde_Imap_Client_Mailbox"))
4335
+		{
4336
+			$_folder =  $_folder->utf8;
4337
+		}
3675 4338
 		// reduce traffic within the Instance per User; Expire every 5 hours
3676 4339
 		//error_log(__METHOD__.' ('.__LINE__.') '.' Called with Folder:'.$_folder.function_backtrace());
3677
-		if (is_null($folderInfo)) $folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
4340
+		if (is_null($folderInfo))
4341
+		{
4342
+			$folderInfo = Cache::getCache(Cache::INSTANCE,'email','icServerFolderExistsInfo'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),$expiration=60*60*5);
4343
+		}
3678 4344
 		//error_log(__METHOD__.' ('.__LINE__.') '.'Cached Info on Folder:'.$_folder.' for Profile:'.$this->profileID.($forceCheck?'(forcedCheck)':'').':'.array2string($folderInfo));
3679 4345
 		if (!empty($folderInfo) && isset($folderInfo[$this->profileID]) && isset($folderInfo[$this->profileID][$_folder]) && $forceCheck===false)
3680 4346
 		{
@@ -3692,7 +4358,8 @@  discard block
 block discarded – undo
3692 4358
 
3693 4359
 		// does the folder exist???
3694 4360
 		//error_log(__METHOD__."->Connected?".$this->icServer->_connected.", ".$_folder.", ".($forceCheck?' forceCheck activated':'dont check on server'));
3695
-		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder])) {
4361
+		if ( $forceCheck || empty($folderInfo) || !isset($folderInfo[$this->profileID]) || !isset($folderInfo[$this->profileID][$_folder]))
4362
+		{
3696 4363
 			//error_log(__METHOD__."->NotConnected and forceCheck with profile:".$this->profileID);
3697 4364
 			//return false;
3698 4365
 			//try to connect
@@ -3733,9 +4400,12 @@  discard block
 block discarded – undo
3733 4400
 
3734 4401
 		$this->icServer->openMailbox($folderName);
3735 4402
 
3736
-		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") {
4403
+		if(strtolower($folderName) == strtolower($trashFolder) && $deleteOptions == "move_to_trash")
4404
+		{
3737 4405
 			$this->deleteMessages('all',$folderName,'remove_immediately');
3738
-		} else {
4406
+		}
4407
+		else
4408
+		{
3739 4409
 			$this->icServer->expunge($folderName);
3740 4410
 		}
3741 4411
 	}
@@ -3754,10 +4424,16 @@  discard block
 block discarded – undo
3754 4424
 	{
3755 4425
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.array2string($_folder).', '.$_forceDeleteMethod);
3756 4426
 		$oldMailbox = '';
3757
-		if (is_null($_folder) || empty($_folder)) $_folder = $this->sessionData['mailbox'];
4427
+		if (is_null($_folder) || empty($_folder))
4428
+		{
4429
+			$_folder = $this->sessionData['mailbox'];
4430
+		}
3758 4431
 		if (empty($_messageUID))
3759 4432
 		{
3760
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4433
+			if (self::$debug)
4434
+			{
4435
+				error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4436
+			}
3761 4437
 			return false;
3762 4438
 		}
3763 4439
 		elseif ($_messageUID==='all')
@@ -3767,32 +4443,48 @@  discard block
 block discarded – undo
3767 4443
 		else
3768 4444
 		{
3769 4445
 			$uidsToDelete = new Horde_Imap_Client_Ids();
3770
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4446
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4447
+			{
4448
+				$_messageUID = (array)$_messageUID;
4449
+			}
3771 4450
 			$uidsToDelete->add($_messageUID);
3772 4451
 		}
3773 4452
 		$deleteOptions = $_forceDeleteMethod; // use forceDeleteMethod if not "no", or unknown method
3774
-		if ($_forceDeleteMethod === 'no' || !in_array($_forceDeleteMethod,array('move_to_trash',"mark_as_deleted","remove_immediately"))) $deleteOptions  = ($this->mailPreferences['deleteOptions']?$this->mailPreferences['deleteOptions']:"mark_as_deleted");
4453
+		if ($_forceDeleteMethod === 'no' || !in_array($_forceDeleteMethod,array('move_to_trash',"mark_as_deleted","remove_immediately")))
4454
+		{
4455
+			$deleteOptions  = ($this->mailPreferences['deleteOptions']?$this->mailPreferences['deleteOptions']:"mark_as_deleted");
4456
+		}
3775 4457
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3776 4458
 		$trashFolder    = $this->getTrashFolder();
3777 4459
 		$draftFolder	= $this->getDraftFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['draftFolder'];
3778 4460
 		$templateFolder = $this->getTemplateFolder(); //$GLOBALS['egw_info']['user']['preferences']['mail']['templateFolder'];
3779 4461
 		if((strtolower($_folder) == strtolower($trashFolder) && $deleteOptions == "move_to_trash") ||
3780
-		   (strtolower($_folder) == strtolower($draftFolder))) {
4462
+		   (strtolower($_folder) == strtolower($draftFolder)))
4463
+		{
3781 4464
 			$deleteOptions = "remove_immediately";
3782 4465
 		}
3783
-		if($this->icServer->getCurrentMailbox() != $_folder) {
4466
+		if($this->icServer->getCurrentMailbox() != $_folder)
4467
+		{
3784 4468
 			$oldMailbox = $this->icServer->getCurrentMailbox();
3785 4469
 			$this->icServer->openMailbox($_folder);
3786 4470
 		}
3787 4471
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.array2string($_messageUID).','.$_folder.'/'.$this->sessionData['mailbox'].' Option:'.$deleteOptions);
3788 4472
 		$updateCache = false;
3789
-		switch($deleteOptions) {
4473
+		switch($deleteOptions)
4474
+		{
3790 4475
 			case "move_to_trash":
3791 4476
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3792 4477
 				$updateCache = true;
3793
-				if(!empty($trashFolder)) {
3794
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
3795
-					if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
4478
+				if(!empty($trashFolder))
4479
+				{
4480
+					if (self::$debug)
4481
+					{
4482
+						error_log(__METHOD__.' ('.__LINE__.') '.implode(' : ', $_messageUID));
4483
+					}
4484
+					if (self::$debug)
4485
+					{
4486
+						error_log(__METHOD__.' ('.__LINE__.') '."$trashFolder <= $_folder / ". $this->sessionData['mailbox']);
4487
+					}
3796 4488
 					// copy messages
3797 4489
 					try
3798 4490
 					{
@@ -3808,7 +4500,10 @@  discard block
 block discarded – undo
3808 4500
 			case "mark_as_deleted":
3809 4501
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3810 4502
 				// mark messages as deleted
3811
-				if (is_null($_messageUID)) $_messageUID='all';
4503
+				if (is_null($_messageUID))
4504
+				{
4505
+					$_messageUID='all';
4506
+				}
3812 4507
 				foreach((array)$_messageUID as $key =>$uid)
3813 4508
 				{
3814 4509
 					//flag messages, that are flagged for deletion as seen too
@@ -3816,7 +4511,10 @@  discard block
 block discarded – undo
3816 4511
 					$flags = $this->getFlags($uid);
3817 4512
 					$this->flagMessages('delete', $uid, $_folder);
3818 4513
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
3819
-					if (strpos( array2string($flags),'Deleted')!==false) $undelete[] = $uid;
4514
+					if (strpos( array2string($flags),'Deleted')!==false)
4515
+					{
4516
+						$undelete[] = $uid;
4517
+					}
3820 4518
 					unset($flags);
3821 4519
 				}
3822 4520
 				foreach((array)$undelete as $key =>$uid)
@@ -3828,7 +4526,10 @@  discard block
 block discarded – undo
3828 4526
 			case "remove_immediately":
3829 4527
 				//error_log(__METHOD__.' ('.__LINE__.') ');
3830 4528
 				$updateCache = true;
3831
-				if (is_null($_messageUID)) $_messageUID='all';
4529
+				if (is_null($_messageUID))
4530
+				{
4531
+					$_messageUID='all';
4532
+				}
3832 4533
 				if (is_object($_messageUID))
3833 4534
 				{
3834 4535
 					$this->flagMessages('delete', $_messageUID, $_folder);
@@ -3845,7 +4546,8 @@  discard block
 block discarded – undo
3845 4546
 				$this->icServer->expunge($_folder);
3846 4547
 				break;
3847 4548
 		}
3848
-		if($oldMailbox != '') {
4549
+		if($oldMailbox != '')
4550
+		{
3849 4551
 			$this->icServer->openMailbox($oldMailbox);
3850 4552
 		}
3851 4553
 
@@ -3859,11 +4561,15 @@  discard block
 block discarded – undo
3859 4561
 	 *
3860 4562
 	 * @return null/array flags
3861 4563
 	 */
3862
-	function getFlags ($_messageUID) {
4564
+	function getFlags ($_messageUID)
4565
+	{
3863 4566
 		try
3864 4567
 		{
3865 4568
 			$uidsToFetch = new Horde_Imap_Client_Ids();
3866
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4569
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4570
+			{
4571
+				$_messageUID = (array)$_messageUID;
4572
+			}
3867 4573
 			$uidsToFetch->add($_messageUID);
3868 4574
 			$_folderName = $this->icServer->getCurrentMailbox();
3869 4575
 			$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -3871,8 +4577,10 @@  discard block
 block discarded – undo
3871 4577
 			$headersNew = $this->icServer->fetch($_folderName, $fquery, array(
3872 4578
 				'ids' => $uidsToFetch,
3873 4579
 			));
3874
-			if (is_object($headersNew)) {
3875
-				foreach($headersNew->ids() as $id) {
4580
+			if (is_object($headersNew))
4581
+			{
4582
+				foreach($headersNew->ids() as $id)
4583
+				{
3876 4584
 					$_headerObject = $headersNew->get($id);
3877 4585
 					$flags = $_headerObject->getFlags();
3878 4586
 				}
@@ -3897,10 +4605,16 @@  discard block
 block discarded – undo
3897 4605
 	 */
3898 4606
 	function getNotifyFlags ($_messageUID, $flags=null)
3899 4607
 	{
3900
-		if (self::$debug) error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
4608
+		if (self::$debug)
4609
+		{
4610
+			error_log(__METHOD__.$_messageUID.' Flags:'.array2string($flags));
4611
+		}
3901 4612
 		try
3902 4613
 		{
3903
-			if($flags===null) $flags =  $this->getFlags($_messageUID);
4614
+			if($flags===null)
4615
+			{
4616
+				$flags =  $this->getFlags($_messageUID);
4617
+			}
3904 4618
 		}
3905 4619
 		catch (\Exception $e)
3906 4620
 		{
@@ -3908,10 +4622,14 @@  discard block
 block discarded – undo
3908 4622
 		}
3909 4623
 
3910 4624
 		if ( stripos( array2string($flags),'MDNSent')!==false)
3911
-			return true;
4625
+		{
4626
+					return true;
4627
+		}
3912 4628
 
3913 4629
 		if ( stripos( array2string($flags),'MDNnotSent')!==false)
3914
-			return false;
4630
+		{
4631
+					return false;
4632
+		}
3915 4633
 
3916 4634
 		return null;
3917 4635
 	}
@@ -3932,7 +4650,10 @@  discard block
 block discarded – undo
3932 4650
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",$_folder /".$this->sessionData['mailbox']);
3933 4651
 		if (empty($_messageUID))
3934 4652
 		{
3935
-			if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4653
+			if (self::$debug)
4654
+			{
4655
+				error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
4656
+			}
3936 4657
 			return false;
3937 4658
 		}
3938 4659
 		$this->icServer->openMailbox(($_folder?$_folder:$this->sessionData['mailbox']));
@@ -3940,7 +4661,10 @@  discard block
 block discarded – undo
3940 4661
 		if (is_array($_messageUID)&& count($_messageUID)>50)
3941 4662
 		{
3942 4663
 			$count = $this->getMailBoxCounters($folder,true);
3943
-			if ($count->messages == count($_messageUID)) $_messageUID='all';
4664
+			if ($count->messages == count($_messageUID))
4665
+			{
4666
+				$_messageUID='all';
4667
+			}
3944 4668
 		}
3945 4669
 
3946 4670
 		if ($_messageUID==='all')
@@ -3949,7 +4673,10 @@  discard block
 block discarded – undo
3949 4673
 		}
3950 4674
 		else
3951 4675
 		{
3952
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4676
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4677
+			{
4678
+				$_messageUID = (array)$_messageUID;
4679
+			}
3953 4680
 			$messageUIDs = array_chunk($_messageUID,50,true);
3954 4681
 		}
3955 4682
 		try
@@ -3965,7 +4692,8 @@  discard block
 block discarded – undo
3965 4692
 					$uidsToModify = new Horde_Imap_Client_Ids();
3966 4693
 					$uidsToModify->add($uids);
3967 4694
 				}
3968
-				switch($_flag) {
4695
+				switch($_flag)
4696
+				{
3969 4697
 					case "delete":
3970 4698
 						$ret = $this->icServer->store($folder, array('add'=>array('\\Deleted'), 'ids'=> $uidsToModify));
3971 4699
 						break;
@@ -4051,7 +4779,10 @@  discard block
 block discarded – undo
4051 4779
 		{
4052 4780
 			error_log(__METHOD__.__LINE__.' Error, could not flag messages in folder '.$folder.' Reason:'.$e->getMessage());
4053 4781
 		}
4054
-		if ($folder instanceof Horde_Imap_Client_Mailbox) $_folder = $folder->utf8;
4782
+		if ($folder instanceof Horde_Imap_Client_Mailbox)
4783
+		{
4784
+			$_folder = $folder->utf8;
4785
+		}
4055 4786
 		//error_log(__METHOD__.__LINE__.'#'.$this->icServer->ImapServerId.'#'.array2string($_folder).'#');
4056 4787
 		self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])]['uidValidity'] = 0;
4057 4788
 
@@ -4080,7 +4811,10 @@  discard block
 block discarded – undo
4080 4811
 		//$deleteOptions  = $GLOBALS['egw_info']["user"]["preferences"]["mail"]["deleteOptions"];
4081 4812
 		if (empty($_messageUID))
4082 4813
 		{
4083
-			if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4814
+			if (self::$debug)
4815
+			{
4816
+				error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
4817
+			}
4084 4818
 			return false;
4085 4819
 		}
4086 4820
 		elseif ($_messageUID==='all')
@@ -4092,7 +4826,10 @@  discard block
 block discarded – undo
4092 4826
 		{
4093 4827
 			//error_log(__METHOD__." Message(s): ".implode(',',$_messageUID));
4094 4828
 			$uidsToMove = new Horde_Imap_Client_Ids();
4095
-			if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
4829
+			if (!(is_object($_messageUID) || is_array($_messageUID)))
4830
+			{
4831
+				$_messageUID = (array)$_messageUID;
4832
+			}
4096 4833
 			$uidsToMove->add($_messageUID);
4097 4834
 		}
4098 4835
 		$sourceFolder = (!empty($currentFolder)?$currentFolder: $this->sessionData['mailbox']);
@@ -4114,12 +4851,14 @@  discard block
 block discarded – undo
4114 4851
 
4115 4852
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' mailheaders:'.array2string($headersNew));
4116 4853
 
4117
-			if (is_object($headersNew)) {
4854
+			if (is_object($headersNew))
4855
+			{
4118 4856
 				$c=0;
4119 4857
 				$retUid = new Horde_Imap_Client_Ids();
4120 4858
 				// we copy chunks of 5 to avoid too much memory and/or server stress
4121 4859
 				// some servers seem not to allow/support the appendig of multiple messages. so we are down to one
4122
-				foreach($headersNew as &$_headerObject) {
4860
+				foreach($headersNew as &$_headerObject)
4861
+				{
4123 4862
 					$c++;
4124 4863
 					$flags = $_headerObject->getFlags(); //unseen status seems to be lost when retrieving the full message
4125 4864
 					$date = $_headerObject->getImapDate();
@@ -4203,7 +4942,11 @@  discard block
 block discarded – undo
4203 4942
 	{
4204 4943
 		try {
4205 4944
 			$date = new DateTime($_date);	// parse date & time including timezone (throws exception, if not parsable)
4206
-			if ($convert2usertime) $date->setUser();	// convert to user-time
4945
+			if ($convert2usertime)
4946
+			{
4947
+				$date->setUser();
4948
+			}
4949
+			// convert to user-time
4207 4950
 			$date2return = $date->format($format);
4208 4951
 		}
4209 4952
 		catch(\Exception $e)
@@ -4235,9 +4978,15 @@  discard block
 block discarded – undo
4235 4978
 	static function htmlentities($_string, $_charset=false)
4236 4979
 	{
4237 4980
 		//setting the charset (if not given)
4238
-		if ($_charset===false) $_charset = self::$displayCharset;
4981
+		if ($_charset===false)
4982
+		{
4983
+			$_charset = self::$displayCharset;
4984
+		}
4239 4985
 		$string = @htmlentities($_string, ENT_QUOTES, $_charset, false);
4240
-		if (empty($string) && !empty($_string)) $string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
4986
+		if (empty($string) && !empty($_string))
4987
+		{
4988
+			$string = @htmlentities(Translation::convert($_string,Translation::detect_encoding($_string),$_charset),ENT_QUOTES | ENT_IGNORE,$_charset, false);
4989
+		}
4241 4990
 		return $string;
4242 4991
 	}
4243 4992
 
@@ -4257,18 +5006,41 @@  discard block
 block discarded – undo
4257 5006
 		$_html = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>','</td></font>','<br><td>','<tr></tr>','<o:p></o:p>','<o:p>','</o:p>'),
4258 5007
 							 array('&amp;',    '<BR>',           '<BR>',             '<BR>',             '</font></td>','<td>',    '',         '',           '',  ''),$_html);
4259 5008
 		//$_html = str_replace(array('&amp;amp;'),array('&amp;'),$_html);
4260
-		if (stripos($_html,'style')!==false) Mail\Html::replaceTagsCompletley($_html,'style'); // clean out empty or pagewide style definitions / left over tags
4261
-		if (stripos($_html,'head')!==false) Mail\Html::replaceTagsCompletley($_html,'head'); // Strip out stuff in head
5009
+		if (stripos($_html,'style')!==false)
5010
+		{
5011
+			Mail\Html::replaceTagsCompletley($_html,'style');
5012
+		}
5013
+		// clean out empty or pagewide style definitions / left over tags
5014
+		if (stripos($_html,'head')!==false)
5015
+		{
5016
+			Mail\Html::replaceTagsCompletley($_html,'head');
5017
+		}
5018
+		// Strip out stuff in head
4262 5019
 		//if (stripos($_html,'![if')!==false && stripos($_html,'<![endif]>')!==false) Mail\Html::replaceTagsCompletley($_html,'!\[if','<!\[endif\]>',false); // Strip out stuff in ifs
4263 5020
 		//if (stripos($_html,'!--[if')!==false && stripos($_html,'<![endif]-->')!==false) Mail\Html::replaceTagsCompletley($_html,'!--\[if','<!\[endif\]-->',false); // Strip out stuff in ifs
4264 5021
 		//error_log(__METHOD__.' ('.__LINE__.') '.$_html);
4265 5022
 
4266
-		if (get_magic_quotes_gpc() === 1) $_html = stripslashes($_html);
5023
+		if (get_magic_quotes_gpc() === 1)
5024
+		{
5025
+			$_html = stripslashes($_html);
5026
+		}
4267 5027
 		// Strip out doctype in head, as htmlLawed cannot handle it TODO: Consider extracting it and adding it afterwards
4268
-		if (stripos($_html,'!doctype')!==false) Mail\Html::replaceTagsCompletley($_html,'!doctype');
4269
-		if (stripos($_html,'?xml:namespace')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
4270
-		if (stripos($_html,'?xml version')!==false) Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false);
4271
-		if (strpos($_html,'!CURSOR')!==false) Mail\Html::replaceTagsCompletley($_html,'!CURSOR');
5028
+		if (stripos($_html,'!doctype')!==false)
5029
+		{
5030
+			Mail\Html::replaceTagsCompletley($_html,'!doctype');
5031
+		}
5032
+		if (stripos($_html,'?xml:namespace')!==false)
5033
+		{
5034
+			Mail\Html::replaceTagsCompletley($_html,'\?xml:namespace','/>',false);
5035
+		}
5036
+		if (stripos($_html,'?xml version')!==false)
5037
+		{
5038
+			Mail\Html::replaceTagsCompletley($_html,'\?xml version','\?>',false);
5039
+		}
5040
+		if (strpos($_html,'!CURSOR')!==false)
5041
+		{
5042
+			Mail\Html::replaceTagsCompletley($_html,'!CURSOR');
5043
+		}
4272 5044
 		// htmLawed filter only the 'body'
4273 5045
 		//preg_match('`(<htm.+?<body[^>]*>)(.+?)(</body>.*?</html>)`ims', $_html, $matches);
4274 5046
 		//if ($matches[2])
@@ -4307,8 +5079,10 @@  discard block
 block discarded – undo
4307 5079
 		//$charSet = 'iso-8859-1';//self::$displayCharset; //'iso-8859-1'; // self::displayCharset seems to be asmarter fallback than iso-8859-1
4308 5080
 		$CharsetFound=false;
4309 5081
 		//echo "#".$_mimePartObject->encoding.'#<br>';
4310
-		if(is_array($_mimePartObject->parameters)) {
4311
-			if(isset($_mimePartObject->parameters['CHARSET'])) {
5082
+		if(is_array($_mimePartObject->parameters))
5083
+		{
5084
+			if(isset($_mimePartObject->parameters['CHARSET']))
5085
+			{
4312 5086
 				$charSet = $_mimePartObject->parameters['CHARSET'];
4313 5087
 				$CharsetFound=true;
4314 5088
 			}
@@ -4329,7 +5103,10 @@  discard block
 block discarded – undo
4329 5103
 	function decodeMimePart($_mimeMessage, $_encoding, $_charset = '')
4330 5104
 	{
4331 5105
 		// decode the part
4332
-		if (self::$debug) error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
5106
+		if (self::$debug)
5107
+		{
5108
+			error_log(__METHOD__."() with $_encoding and $_charset:".print_r($_mimeMessage,true));
5109
+		}
4333 5110
 		switch (strtoupper($_encoding))
4334 5111
 		{
4335 5112
 			case 'BASE64':
@@ -4369,13 +5146,19 @@  discard block
 block discarded – undo
4369 5146
 		// sometimes there are 3 parts, when there is an ics/ical attached/included-> we want to show that
4370 5147
 		// as attachment AND as abstracted ical information (we use our notification style here).
4371 5148
 		$partText = $partCalendar = $partHTML = null;
4372
-		if (self::$debug) _debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
5149
+		if (self::$debug)
5150
+		{
5151
+			_debug_array(array("METHOD"=>__METHOD__,"LINE"=>__LINE__,"STRUCTURE"=>$_structure));
5152
+		}
4373 5153
 		//error_log(__METHOD__.' ('.__LINE__.') ');
4374 5154
 		$ignore_first_part = true;
4375 5155
 		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4376 5156
 		{
4377 5157
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type"." ignoreFirstPart:".$ignore_first_part);
4378
-			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5158
+			if (self::$debug)
5159
+			{
5160
+				echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5161
+			}
4379 5162
 
4380 5163
 			if ($ignore_first_part)
4381 5164
 			{
@@ -4391,11 +5174,17 @@  discard block
 block discarded – undo
4391 5174
 					switch($mimePart->getSubType())
4392 5175
 					{
4393 5176
 						case 'plain':
4394
-							if ($mimePart->getBytes() > 0) $partText = $mimePart;
5177
+							if ($mimePart->getBytes() > 0)
5178
+							{
5179
+								$partText = $mimePart;
5180
+							}
4395 5181
 							break;
4396 5182
 
4397 5183
 						case 'html':
4398
-							if ($mimePart->getBytes() > 0)  $partHTML = $mimePart;
5184
+							if ($mimePart->getBytes() > 0)
5185
+							{
5186
+								$partHTML = $mimePart;
5187
+							}
4399 5188
 							break;
4400 5189
 					}
4401 5190
 					break;
@@ -4408,7 +5197,10 @@  discard block
 block discarded – undo
4408 5197
 							if (count($mimePart->getParts()) > 1)
4409 5198
 							{
4410 5199
 								// in a multipart alternative we treat the multipart/related as html part
4411
-								if (self::$debug) error_log(__METHOD__." process MULTIPART/".$mimePart->getSubType()." with array as subparts");
5200
+								if (self::$debug)
5201
+								{
5202
+									error_log(__METHOD__." process MULTIPART/".$mimePart->getSubType()." with array as subparts");
5203
+								}
4412 5204
 								$partHTML = $mimePart;
4413 5205
 								break 3; // GET OUT OF LOOP, will be processed according to type
4414 5206
 							}
@@ -4489,9 +5281,15 @@  discard block
 block discarded – undo
4489 5281
 	 */
4490 5282
 	function getMultipartMixed($_uid, Horde_Mime_Part $_structure, $_htmlMode, $_preserveSeen = false, &$skipParts=array())
4491 5283
 	{
4492
-		if (self::$debug) echo __METHOD__."$_uid, $_htmlMode<br>";
5284
+		if (self::$debug)
5285
+		{
5286
+			echo __METHOD__."$_uid, $_htmlMode<br>";
5287
+		}
4493 5288
 		$bodyPart = array();
4494
-		if (self::$debug) _debug_array($_structure);
5289
+		if (self::$debug)
5290
+		{
5291
+			_debug_array($_structure);
5292
+		}
4495 5293
 
4496 5294
 		$ignore_first_part = true;
4497 5295
 		//$skipParts = array();
@@ -4499,7 +5297,10 @@  discard block
 block discarded – undo
4499 5297
 		foreach($_structure->contentTypeMap() as $mime_id => $mime_type)
4500 5298
 		{
4501 5299
 			//error_log(__METHOD__."($_uid, ".$_structure->getMimeId().") $mime_id: $mime_type");
4502
-			if (self::$debug) echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5300
+			if (self::$debug)
5301
+			{
5302
+				echo __METHOD__."($_uid, partID=".$_structure->getMimeId().") $mime_id: $mime_type<br>";
5303
+			}
4503 5304
 			if ($ignore_first_part)
4504 5305
 			{
4505 5306
 				$ignore_first_part = false;
@@ -4517,7 +5318,10 @@  discard block
 block discarded – undo
4517 5318
 			switch($part->getPrimaryType())
4518 5319
 			{
4519 5320
 				case 'multipart':
4520
-					if ($part->getDisposition() == 'attachment') continue;
5321
+					if ($part->getDisposition() == 'attachment')
5322
+					{
5323
+						continue;
5324
+					}
4521 5325
 					switch($part->getSubType())
4522 5326
 					{
4523 5327
 						case 'alternative':
@@ -4582,7 +5386,9 @@  discard block
 block discarded – undo
4582 5386
 					if($part->getSubType() == 'rfc822' || $part->getDisposition() == 'attachment')
4583 5387
 					{
4584 5388
 						$skipParts[$mime_id.'.0'] = $mime_type;
4585
-						foreach($part->contentTypeMap() as $sub_id => $sub_type){ $skipParts[$sub_id] = $sub_type;}
5389
+						foreach($part->contentTypeMap() as $sub_id => $sub_type)
5390
+						{
5391
+$skipParts[$sub_id] = $sub_type;}
4586 5392
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$_uid.' Part:'.$mime_id.':'.array2string($skipParts));
4587 5393
 						//break 2;
4588 5394
 					}
@@ -4625,7 +5431,10 @@  discard block
 block discarded – undo
4625 5431
 	 */
4626 5432
 	function getBodyPart($_uid, $_partID=null, $_folder=null, $_preserveSeen=false, $_stream=false, &$_encoding=null, $_tryDecodingServerside=true)
4627 5433
 	{
4628
-		if (self::$debug) error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
5434
+		if (self::$debug)
5435
+		{
5436
+			error_log( __METHOD__.__LINE__."(".array2string($_uid).", $_partID, $_folder, $_preserveSeen, $_stream, $_encoding, $_tryDecodingServerside)");
5437
+		}
4629 5438
 
4630 5439
 		if (empty($_folder))
4631 5440
 		{
@@ -4634,7 +5443,10 @@  discard block
 block discarded – undo
4634 5443
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($_folder).'/'.$this->icServer->getCurrentMailbox().'/'. $this->sessionData['mailbox']);
4635 5444
 		// querying contents of body part
4636 5445
 		$uidsToFetch = new Horde_Imap_Client_Ids();
4637
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5446
+		if (!(is_object($_uid) || is_array($_uid)))
5447
+		{
5448
+			$_uid = (array)$_uid;
5449
+		}
4638 5450
 		$uidsToFetch->add($_uid);
4639 5451
 
4640 5452
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -4642,9 +5454,12 @@  discard block
 block discarded – undo
4642 5454
 			'peek' => $_preserveSeen,
4643 5455
 			'decode' => true,	// try decode on server, does NOT neccessary work
4644 5456
 		);
4645
-		if ($_tryDecodingServerside===false)// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
5457
+		if ($_tryDecodingServerside===false)
5458
+		{
5459
+			// || ($_tryDecodingServerside&&$this->isDraftFolder($_folder)))
4646 5460
 		{
4647 5461
 			$_tryDecodingServerside=false;
5462
+		}
4648 5463
 			$fetchParams = array(
4649 5464
 				'peek' => $_preserveSeen,
4650 5465
 			);
@@ -4686,7 +5501,10 @@  discard block
 block discarded – undo
4686 5501
 	{
4687 5502
 		//error_log(__METHOD__.' ('.__LINE__.') '.'->'.$_uid.':'.array2string($_structure).' '.function_backtrace());
4688 5503
 		$bodyPart = array();
4689
-		if (self::$debug) _debug_array(array($_structure,function_backtrace()));
5504
+		if (self::$debug)
5505
+		{
5506
+			_debug_array(array($_structure,function_backtrace()));
5507
+		}
4690 5508
 
4691 5509
 		if($_structure->getSubType() == 'html' && !in_array($_htmlMode, array('html_only', 'always_display', 'only_if_no_text')))
4692 5510
 		{
@@ -4736,8 +5554,12 @@  discard block
 block discarded – undo
4736 5554
 	 */
4737 5555
 	function getMessageBody($_uid, $_htmlOptions='', $_partID=null, Horde_Mime_Part $_structure=null, $_preserveSeen = false, $_folder = '')
4738 5556
 	{
4739
-		if (self::$debug) echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
4740
-		if($_htmlOptions != '') {
5557
+		if (self::$debug)
5558
+		{
5559
+			echo __METHOD__."$_uid, $_htmlOptions, $_partID<br>";
5560
+		}
5561
+		if($_htmlOptions != '')
5562
+		{
4741 5563
 			$this->htmlOptions = $_htmlOptions;
4742 5564
 		}
4743 5565
 		if (empty($_folder))
@@ -4826,7 +5648,9 @@  discard block
 block discarded – undo
4826 5648
 						default:
4827 5649
 							$bodyPart = array($this->getTextPart($_uid, $_structure, $this->htmlOptions, $_preserveSeen));
4828 5650
 					}
4829
-				} else {
5651
+				}
5652
+				else
5653
+				{
4830 5654
 					// what if the structure->disposition is attachment ,...
4831 5655
 				}
4832 5656
 				return self::normalizeBodyParts($bodyPart);
@@ -4837,13 +5661,18 @@  discard block
 block discarded – undo
4837 5661
 				{
4838 5662
 					case 'rfc822':
4839 5663
 						$newStructure = $_structure->getParts();
4840
-						if (self::$debug) {echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
5664
+						if (self::$debug)
5665
+						{
5666
+echo __METHOD__." Message -> RFC -> NewStructure:"; _debug_array($newStructure[0]);}
4841 5667
 						return self::normalizeBodyParts($this->getMessageBody($_uid, $_htmlOptions, $newStructure[0]->getMimeId(), $newStructure[0], $_preserveSeen, $_folder));
4842 5668
 				}
4843 5669
 				break;
4844 5670
 
4845 5671
 			default:
4846
-				if (self::$debug) _debug_array($_structure);
5672
+				if (self::$debug)
5673
+				{
5674
+					_debug_array($_structure);
5675
+				}
4847 5676
 				return array(
4848 5677
 					array(
4849 5678
 						'body'		=> lang('The mimeparser can not parse this message.').$_structure->getType(),
@@ -4867,9 +5696,12 @@  discard block
 block discarded – undo
4867 5696
 		{
4868 5697
 			foreach($_bodyParts as $singleBodyPart)
4869 5698
 			{
4870
-				if (!isset($singleBodyPart['body'])) {
5699
+				if (!isset($singleBodyPart['body']))
5700
+				{
4871 5701
 					$buff = self::normalizeBodyParts($singleBodyPart);
4872
-					foreach ((array)$buff as $val) { $body2return[] = $val;}
5702
+					foreach ((array)$buff as $val)
5703
+					{
5704
+$body2return[] = $val;}
4873 5705
 					continue;
4874 5706
 				}
4875 5707
 				$body2return[] = $singleBodyPart;
@@ -4895,13 +5727,20 @@  discard block
 block discarded – undo
4895 5727
 		$message='';
4896 5728
 		for($i=0; $i<count($bodyParts); $i++)
4897 5729
 		{
4898
-			if (!isset($bodyParts[$i]['body'])) {
5730
+			if (!isset($bodyParts[$i]['body']))
5731
+			{
4899 5732
 				$bodyParts[$i]['body'] = self::getdisplayableBody($mailClass, $bodyParts[$i], $preserveHTML, $useTidy);
4900 5733
 				$message .= empty($bodyParts[$i]['body'])?'':$bodyParts[$i]['body'];
4901 5734
 				continue;
4902 5735
 			}
4903
-			if (isset($bodyParts[$i]['error'])) continue;
4904
-			if (empty($bodyParts[$i]['body'])) continue;
5736
+			if (isset($bodyParts[$i]['error']))
5737
+			{
5738
+				continue;
5739
+			}
5740
+			if (empty($bodyParts[$i]['body']))
5741
+			{
5742
+				continue;
5743
+			}
4905 5744
 			// some characterreplacements, as they fail to translate
4906 5745
 			$sar = array(
4907 5746
 				'@(\x84|\x93|\x94)@',
@@ -4928,13 +5767,17 @@  discard block
 block discarded – undo
4928 5767
 				$bodyParts[$i]['body'] = preg_replace($sar,$rar,$bodyParts[$i]['body']);
4929 5768
 			}
4930 5769
 
4931
-			if ($bodyParts[$i]['charSet']===false) $bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
5770
+			if ($bodyParts[$i]['charSet']===false)
5771
+			{
5772
+				$bodyParts[$i]['charSet'] = Translation::detect_encoding($bodyParts[$i]['body']);
5773
+			}
4932 5774
 			// add line breaks to $bodyParts
4933 5775
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Charset:'.$bodyParts[$i]['charSet'].'->'.$bodyParts[$i]['body']);
4934 5776
 			$newBody  = Translation::convert_jsonsafe($bodyParts[$i]['body'], $bodyParts[$i]['charSet']);
4935 5777
 			//error_log(__METHOD__.' ('.__LINE__.') '.' MimeType:'.$bodyParts[$i]['mimeType'].'->'.$newBody);
4936 5778
 			$mailClass->activeMimeType = 'text/plain';
4937
-			if ($bodyParts[$i]['mimeType'] == 'text/html') {
5779
+			if ($bodyParts[$i]['mimeType'] == 'text/html')
5780
+			{
4938 5781
 				$mailClass->activeMimeType = $bodyParts[$i]['mimeType'];
4939 5782
 				if (!$preserveHTML)
4940 5783
 				{
@@ -4980,15 +5823,28 @@  discard block
 block discarded – undo
4980 5823
 						// as we switched off HTMLaweds tidy functionality
4981 5824
 						$newBody = str_replace(array('&amp;amp;','<DIV><BR></DIV>',"<DIV>&nbsp;</DIV>",'<div>&nbsp;</div>'),array('&amp;','<BR>','<BR>','<BR>'),$newBody);
4982 5825
 						$newBody = $htmLawed->run($newBody,self::$htmLawed_config);
4983
-						if ($hasOther && $preserveHTML) $newBody = $matches[1]. $newBody. $matches[3];
5826
+						if ($hasOther && $preserveHTML)
5827
+						{
5828
+							$newBody = $matches[1]. $newBody. $matches[3];
5829
+						}
4984 5830
 						$alreadyHtmlLawed=true;
4985 5831
 					}
4986 5832
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after purify:'.$newBody);
4987
-					if ($preserveHTML==false) $newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true);
5833
+					if ($preserveHTML==false)
5834
+					{
5835
+						$newBody = Mail\Html::convertHTMLToText($newBody,self::$displayCharset,true,true);
5836
+					}
4988 5837
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after convertHTMLToText:'.$newBody);
4989
-					if ($preserveHTML==false) $newBody = nl2br($newBody); // we need this, as htmLawed removes \r\n
5838
+					if ($preserveHTML==false)
5839
+					{
5840
+						$newBody = nl2br($newBody);
5841
+					}
5842
+					// we need this, as htmLawed removes \r\n
4990 5843
 					/*if (!$alreadyHtmlLawed) */ $mailClass->getCleanHTML($newBody); // remove stuff we regard as unwanted
4991
-					if ($preserveHTML==false) $newBody = str_replace("<br />","\r\n",$newBody);
5844
+					if ($preserveHTML==false)
5845
+					{
5846
+						$newBody = str_replace("<br />","\r\n",$newBody);
5847
+					}
4992 5848
 					//error_log(__METHOD__.' ('.__LINE__.') '.' after getClean:'.$newBody);
4993 5849
 				}
4994 5850
 				$message .= $newBody;
@@ -5025,12 +5881,12 @@  discard block
 block discarded – undo
5025 5881
 				  substr($line,0,strlen($dontbreaklinesstartingwith)) != $dontbreaklinesstartingwith
5026 5882
 				 )
5027 5883
 				)
5028
-			   )
5029
-			{
5884
+			   ) {
5030 5885
 				$s=explode(" ", $line);
5031 5886
 				$line = "";
5032 5887
 				$linecnt = 0;
5033
-				foreach ($s as &$v) {
5888
+				foreach ($s as &$v)
5889
+				{
5034 5890
 					$cnt = strlen($v);
5035 5891
 					// only break long words within the wordboundaries,
5036 5892
 					// but it may destroy links, so we check for href and dont do it if we find one
@@ -5040,14 +5896,20 @@  discard block
 block discarded – undo
5040 5896
 						$v=wordwrap($v, $allowedLength, $cut, true);
5041 5897
 					}
5042 5898
 					// the rest should be broken at the start of the new word that exceeds the limit
5043
-					if ($linecnt+$cnt > $allowedLength) {
5899
+					if ($linecnt+$cnt > $allowedLength)
5900
+					{
5044 5901
 						$v=$cut.$v;
5045 5902
 						#$linecnt = 0;
5046 5903
 						$linecnt =strlen($v)-strlen($cut);
5047
-					} else {
5904
+					}
5905
+					else
5906
+					{
5048 5907
 						$linecnt += $cnt;
5049 5908
 					}
5050
-					if (strlen($v)) $line .= (strlen($line) ? " " : "").$v;
5909
+					if (strlen($v))
5910
+					{
5911
+						$line .= (strlen($line) ? " " : "").$v;
5912
+					}
5051 5913
 				}
5052 5914
 			}
5053 5915
 			$newStr .= $line . "\n";
@@ -5068,11 +5930,18 @@  discard block
 block discarded – undo
5068 5930
 	function getMessageEnvelope($_uid, $_partID = '',$decode=false, $_folder='', $_useHeaderInsteadOfEnvelope=false)
5069 5931
 	{
5070 5932
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder".function_backtrace());
5071
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5933
+		if (empty($_folder))
5934
+		{
5935
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5936
+		}
5072 5937
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid,$_partID,$decode,$_folder");
5073
-		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false) {
5938
+		if((empty($_partID)||$_partID=='null')&&$_useHeaderInsteadOfEnvelope===false)
5939
+		{
5074 5940
 			$uidsToFetch = new Horde_Imap_Client_Ids();
5075
-			if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
5941
+			if (!(is_object($_uid) || is_array($_uid)))
5942
+			{
5943
+				$_uid = (array)$_uid;
5944
+			}
5076 5945
 			$uidsToFetch->add($_uid);
5077 5946
 
5078 5947
 			$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5082,8 +5951,10 @@  discard block
 block discarded – undo
5082 5951
 			$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5083 5952
 				'ids' => $uidsToFetch,
5084 5953
 			));
5085
-			if (is_object($headersNew)) {
5086
-				foreach($headersNew as &$_headerObject) {
5954
+			if (is_object($headersNew))
5955
+			{
5956
+				foreach($headersNew as &$_headerObject)
5957
+				{
5087 5958
 					$env = $_headerObject->getEnvelope();
5088 5959
 					//_debug_array($envFields->singleFields());
5089 5960
 					$singleFields = $envFields->singleFields();
@@ -5100,7 +5971,10 @@  discard block
 block discarded – undo
5100 5971
 								//error_log(__METHOD__.' ('.__LINE__.') '.$v.'->'.array2string($env->$v->addresses));
5101 5972
 								$envelope[$v]=$env->$v->addresses;
5102 5973
 								$address = array();
5103
-								if (!is_array($envelope[$v])) break;
5974
+								if (!is_array($envelope[$v]))
5975
+								{
5976
+									break;
5977
+								}
5104 5978
 								foreach ($envelope[$v] as $k => $ad)
5105 5979
 								{
5106 5980
 									if (stripos($ad,'@')===false)
@@ -5137,7 +6011,9 @@  discard block
 block discarded – undo
5137 6011
 				}
5138 6012
 			}
5139 6013
 			return $envelope;
5140
-		} else {
6014
+		}
6015
+		else
6016
+		{
5141 6017
 
5142 6018
 			$headers = $this->getMessageHeader($_uid, $_partID, true,true,$_folder);
5143 6019
 
@@ -5148,19 +6024,43 @@  discard block
 block discarded – undo
5148 6024
 				'SUBJECT'	=> ($decode ? self::decode_header($headers['SUBJECT']):$headers['SUBJECT']),
5149 6025
 				'MESSAGE_ID'	=> $headers['MESSAGE-ID']
5150 6026
 			);
5151
-			if (isset($headers['IN-REPLY-TO'])) $newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
5152
-			if (isset($headers['REFERENCES'])) $newData['REFERENCES'] = $headers['REFERENCES'];
5153
-			if (isset($headers['THREAD-TOPIC'])) $newData['THREAD-TOPIC'] = $headers['THREAD-TOPIC'];
5154
-			if (isset($headers['THREAD-INDEX'])) $newData['THREAD-INDEX'] = $headers['THREAD-INDEX'];
5155
-			if (isset($headers['LIST-ID'])) $newData['LIST-ID'] = $headers['LIST-ID'];
5156
-			if (isset($headers['SIZE'])) $newData['SIZE'] = $headers['SIZE'];
6027
+			if (isset($headers['IN-REPLY-TO']))
6028
+			{
6029
+				$newData['IN-REPLY-TO'] = $headers['IN-REPLY-TO'];
6030
+			}
6031
+			if (isset($headers['REFERENCES']))
6032
+			{
6033
+				$newData['REFERENCES'] = $headers['REFERENCES'];
6034
+			}
6035
+			if (isset($headers['THREAD-TOPIC']))
6036
+			{
6037
+				$newData['THREAD-TOPIC'] = $headers['THREAD-TOPIC'];
6038
+			}
6039
+			if (isset($headers['THREAD-INDEX']))
6040
+			{
6041
+				$newData['THREAD-INDEX'] = $headers['THREAD-INDEX'];
6042
+			}
6043
+			if (isset($headers['LIST-ID']))
6044
+			{
6045
+				$newData['LIST-ID'] = $headers['LIST-ID'];
6046
+			}
6047
+			if (isset($headers['SIZE']))
6048
+			{
6049
+				$newData['SIZE'] = $headers['SIZE'];
6050
+			}
5157 6051
 			//_debug_array($newData);
5158 6052
 			$recepientList = array('FROM', 'TO', 'CC', 'BCC', 'SENDER', 'REPLY-TO');
5159
-			foreach($recepientList as $recepientType) {
5160
-				if(isset($headers[$recepientType])) {
5161
-					if ($decode) $headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
6053
+			foreach($recepientList as $recepientType)
6054
+			{
6055
+				if(isset($headers[$recepientType]))
6056
+				{
6057
+					if ($decode)
6058
+					{
6059
+						$headers[$recepientType] =  self::decode_header($headers[$recepientType],true);
6060
+					}
5162 6061
 					//error_log(__METHOD__.__LINE__." ".$recepientType."->".array2string($headers[$recepientType]));
5163
-					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress) {
6062
+					foreach(self::parseAddressList($headers[$recepientType]) as $singleAddress)
6063
+					{
5164 6064
 						$addressData = array(
5165 6065
 							'PERSONAL_NAME'		=> $singleAddress->personal ? $singleAddress->personal : 'NIL',
5166 6066
 							'AT_DOMAIN_LIST'	=> $singleAddress->adl ? $singleAddress->adl : 'NIL',
@@ -5168,17 +6068,25 @@  discard block
 block discarded – undo
5168 6068
 							'HOST_NAME'		=> $singleAddress->host ? $singleAddress->host : 'NIL',
5169 6069
 							'EMAIL'			=> $singleAddress->host ? $singleAddress->mailbox.'@'.$singleAddress->host : $singleAddress->mailbox,
5170 6070
 						);
5171
-						if($addressData['PERSONAL_NAME'] != 'NIL') {
6071
+						if($addressData['PERSONAL_NAME'] != 'NIL')
6072
+						{
5172 6073
 							$addressData['RFC822_EMAIL'] = imap_rfc822_write_address($singleAddress->mailbox, $singleAddress->host, $singleAddress->personal);
5173
-						} else {
6074
+						}
6075
+						else
6076
+						{
5174 6077
 							$addressData['RFC822_EMAIL'] = 'NIL';
5175 6078
 						}
5176 6079
 						$newData[$recepientType][] = ($addressData['RFC822_EMAIL']!='NIL'?$addressData['RFC822_EMAIL']:$addressData['EMAIL']);//$addressData;
5177 6080
 					}
5178
-				} else {
5179
-					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO') {
6081
+				}
6082
+				else
6083
+				{
6084
+					if($recepientType == 'SENDER' || $recepientType == 'REPLY-TO')
6085
+					{
5180 6086
 						$newData[$recepientType] = $newData['FROM'];
5181
-					} else {
6087
+					}
6088
+					else
6089
+					{
5182 6090
 						$newData[$recepientType] = array();
5183 6091
 					}
5184 6092
 				}
@@ -5201,9 +6109,15 @@  discard block
 block discarded – undo
5201 6109
 	function getMessageHeader($_uid, $_partID = '',$decode=false, $preserveUnSeen=false, $_folder='')
5202 6110
 	{
5203 6111
 		//error_log(__METHOD__.' ('.__LINE__.') '.':'.$_uid.', '.$_partID.', '.$decode.', '.$preserveUnSeen.', '.$_folder);
5204
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6112
+		if (empty($_folder))
6113
+		{
6114
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6115
+		}
5205 6116
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5206
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6117
+		if (!(is_object($_uid) || is_array($_uid)))
6118
+		{
6119
+			$_uid = (array)$_uid;
6120
+		}
5207 6121
 		$uidsToFetch->add($_uid);
5208 6122
 
5209 6123
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5221,7 +6135,8 @@  discard block
 block discarded – undo
5221 6135
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5222 6136
 			'ids' => $uidsToFetch,
5223 6137
 		));
5224
-		if (is_object($headersNew)) {
6138
+		if (is_object($headersNew))
6139
+		{
5225 6140
 			foreach($headersNew as $_fetchObject)
5226 6141
 			{
5227 6142
 				$headers = $_fetchObject->getHeaderText(0,Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
@@ -5243,11 +6158,17 @@  discard block
 block discarded – undo
5243 6158
 			}
5244 6159
 			if ($decode === 'object')
5245 6160
 			{
5246
-				if (is_object($headers)) $headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
6161
+				if (is_object($headers))
6162
+				{
6163
+					$headers->setUserAgent('EGroupware API '.$GLOBALS['egw_info']['server']['versions']['phpgwapi']);
6164
+				}
5247 6165
 				return $headers;
5248 6166
 			}
5249 6167
 			$retValue = is_object($headers) ? $headers->toArray():array();
5250
-			if ($size) $retValue['size'] = $size;
6168
+			if ($size)
6169
+			{
6170
+				$retValue['size'] = $size;
6171
+			}
5251 6172
 		}
5252 6173
 		$retValue = array_change_key_case($retValue,CASE_UPPER);
5253 6174
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retValue));
@@ -5279,10 +6200,16 @@  discard block
 block discarded – undo
5279 6200
 	function getMessageRawHeader($_uid, $_partID = '', $_folder = '')
5280 6201
 	{
5281 6202
 		static $rawHeaders;
5282
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6203
+		if (empty($_folder))
6204
+		{
6205
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6206
+		}
5283 6207
 		//error_log(__METHOD__.' ('.__LINE__.') '." Try Using Cache for raw Header $_uid, $_partID in Folder $_folder");
5284 6208
 
5285
-		if (is_null($rawHeaders)||!is_array($rawHeaders)) $rawHeaders = Cache::getCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
6209
+		if (is_null($rawHeaders)||!is_array($rawHeaders))
6210
+		{
6211
+			$rawHeaders = Cache::getCache(Cache::INSTANCE,'email','rawHeadersCache'.trim($GLOBALS['egw_info']['user']['account_id']),null,array(),60*60*1);
6212
+		}
5286 6213
 		if (isset($rawHeaders[$this->icServer->ImapServerId][(string)$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5287 6214
 		{
5288 6215
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Header $_uid, $_partID in Folder $_folder");
@@ -5290,7 +6217,10 @@  discard block
 block discarded – undo
5290 6217
 		}
5291 6218
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5292 6219
 		$uid = $_uid;
5293
-		if (!(is_object($_uid) || is_array($_uid))) $uid = (array)$_uid;
6220
+		if (!(is_object($_uid) || is_array($_uid)))
6221
+		{
6222
+			$uid = (array)$_uid;
6223
+		}
5294 6224
 		$uidsToFetch->add($uid);
5295 6225
 
5296 6226
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5306,8 +6236,10 @@  discard block
 block discarded – undo
5306 6236
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5307 6237
 			'ids' => $uidsToFetch,
5308 6238
 		));
5309
-		if (is_object($headersNew)) {
5310
-			foreach($headersNew as &$_headerObject) {
6239
+		if (is_object($headersNew))
6240
+		{
6241
+			foreach($headersNew as &$_headerObject)
6242
+			{
5311 6243
 				$retValue = $_headerObject->getHeaderText();
5312 6244
 				if ($_partID != '')
5313 6245
 				{
@@ -5335,22 +6267,33 @@  discard block
 block discarded – undo
5335 6267
 	static function &getStyles($_bodyParts)
5336 6268
 	{
5337 6269
 		$style = '';
5338
-		if (empty($_bodyParts)) return "";
5339
-		foreach((array)$_bodyParts as $singleBodyPart) {
5340
-			if (!isset($singleBodyPart['body'])) {
6270
+		if (empty($_bodyParts))
6271
+		{
6272
+			return "";
6273
+		}
6274
+		foreach((array)$_bodyParts as $singleBodyPart)
6275
+		{
6276
+			if (!isset($singleBodyPart['body']))
6277
+			{
5341 6278
 				$singleBodyPart['body'] = self::getStyles($singleBodyPart);
5342 6279
 				$style .= $singleBodyPart['body'];
5343 6280
 				continue;
5344 6281
 			}
5345 6282
 
5346
-			if ($singleBodyPart['charSet']===false) $singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
6283
+			if ($singleBodyPart['charSet']===false)
6284
+			{
6285
+				$singleBodyPart['charSet'] = Translation::detect_encoding($singleBodyPart['body']);
6286
+			}
5347 6287
 			$singleBodyPart['body'] = Translation::convert(
5348 6288
 				$singleBodyPart['body'],
5349 6289
 				strtolower($singleBodyPart['charSet'])
5350 6290
 			);
5351 6291
 			$ct = 0;
5352 6292
 			$newStyle=array();
5353
-			if (stripos($singleBodyPart['body'],'<style')!==false)  $ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
6293
+			if (stripos($singleBodyPart['body'],'<style')!==false)
6294
+			{
6295
+				$ct = preg_match_all('#<style(?:\s.*)?>(.+)</style>#isU', $singleBodyPart['body'], $newStyle);
6296
+			}
5354 6297
 			if ($ct>0)
5355 6298
 			{
5356 6299
 				//error_log(__METHOD__.' ('.__LINE__.') '.'#'.$ct.'#'.array2string($newStyle));
@@ -5382,7 +6325,11 @@  discard block
 block discarded – undo
5382 6325
 		// CSS Security
5383 6326
 		// http://code.google.com/p/browsersec/wiki/Part1#Cascading_stylesheets
5384 6327
 		$css = preg_replace('/(javascript|expression|-moz-binding)/i','',$style);
5385
-		if (stripos($css,'script')!==false) Mail\Html::replaceTagsCompletley($css,'script'); // Strip out script that may be included
6328
+		if (stripos($css,'script')!==false)
6329
+		{
6330
+			Mail\Html::replaceTagsCompletley($css,'script');
6331
+		}
6332
+		// Strip out script that may be included
5386 6333
 		// we need this, as styledefinitions are enclosed with curly brackets; and template stuff tries to replace everything between curly brackets that is having no horizontal whitespace
5387 6334
 		// as the comments as <!-- styledefinition --> in stylesheet are outdated, and ck-editor does not understand it, we remove it
5388 6335
 		$css = str_replace(array(':','<!--','-->'),array(': ','',''),$css);
@@ -5403,8 +6350,14 @@  discard block
 block discarded – undo
5403 6350
 	{
5404 6351
 		//TODO: caching einbauen static!
5405 6352
 		static $rawBody;
5406
-		if (is_null($rawBody)) $rawBody = array();
5407
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6353
+		if (is_null($rawBody))
6354
+		{
6355
+			$rawBody = array();
6356
+		}
6357
+		if (empty($_folder))
6358
+		{
6359
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6360
+		}
5408 6361
 		if (isset($rawBody[$this->icServer->ImapServerId][$_folder][$_uid][(empty($_partID)?'NIL':$_partID)]))
5409 6362
 		{
5410 6363
 			//error_log(__METHOD__.' ('.__LINE__.') '." Using Cache for raw Body $_uid, $_partID in Folder $_folder");
@@ -5413,7 +6366,10 @@  discard block
 block discarded – undo
5413 6366
 
5414 6367
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5415 6368
 		$uid = $_uid;
5416
-		if (!(is_object($_uid) || is_array($_uid))) $uid = (array)$_uid;
6369
+		if (!(is_object($_uid) || is_array($_uid)))
6370
+		{
6371
+			$uid = (array)$_uid;
6372
+		}
5417 6373
 		$uidsToFetch->add($uid);
5418 6374
 
5419 6375
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5426,8 +6382,10 @@  discard block
 block discarded – undo
5426 6382
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5427 6383
 			'ids' => $uidsToFetch,
5428 6384
 		));
5429
-		if (is_object($headersNew)) {
5430
-			foreach($headersNew as &$_headerObject) {
6385
+		if (is_object($headersNew))
6386
+		{
6387
+			foreach($headersNew as &$_headerObject)
6388
+			{
5431 6389
 				$body = $_headerObject->getFullMsg();
5432 6390
 				if ($_partID != '')
5433 6391
 				{
@@ -5460,14 +6418,20 @@  discard block
 block discarded – undo
5460 6418
 	 */
5461 6419
 	function getStructure($_uid, $_partID=null, $_folder=null, $_preserveSeen=false)
5462 6420
 	{
5463
-		if (self::$debug) error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
6421
+		if (self::$debug)
6422
+		{
6423
+			error_log( __METHOD__.' ('.__LINE__.') '.":$_uid, $_partID");
6424
+		}
5464 6425
 
5465 6426
 		if (empty($_folder))
5466 6427
 		{
5467 6428
 			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
5468 6429
 		}
5469 6430
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5470
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6431
+		if (!(is_object($_uid) || is_array($_uid)))
6432
+		{
6433
+			$_uid = (array)$_uid;
6434
+		}
5471 6435
 		$uidsToFetch->add($_uid);
5472 6436
 		try
5473 6437
 		{
@@ -5476,7 +6440,10 @@  discard block
 block discarded – undo
5476 6440
 	//		$fquery->envelope();
5477 6441
 	//		$fquery->size();
5478 6442
 			$_fquery->structure();
5479
-			if ($_partID) $_fquery->bodyPart($_partID, array('peek' => $_preserveSeen));
6443
+			if ($_partID)
6444
+			{
6445
+				$_fquery->bodyPart($_partID, array('peek' => $_preserveSeen));
6446
+			}
5480 6447
 
5481 6448
 			$mail = $this->icServer->fetch($_folder, $_fquery, array(
5482 6449
 				'ids' => $uidsToFetch,
@@ -5507,16 +6474,28 @@  discard block
 block discarded – undo
5507 6474
 	 */
5508 6475
 	function getMessageAttachments($_uid, $_partID=null, Horde_Mime_Part $_structure=null, $fetchEmbeddedImages=true, $fetchTextCalendar=false, $resolveTNEF=true, $_folder='')
5509 6476
 	{
5510
-		if (self::$debug) error_log( __METHOD__.":$_uid, $_partID");
5511
-		if (empty($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6477
+		if (self::$debug)
6478
+		{
6479
+			error_log( __METHOD__.":$_uid, $_partID");
6480
+		}
6481
+		if (empty($_folder))
6482
+		{
6483
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6484
+		}
5512 6485
 		$attachments = array();
5513 6486
 		if (!isset($_structure))
5514 6487
 		{
5515 6488
 			$_structure = $this->getStructure($_uid, $_partID,$_folder,true);
5516 6489
 			//error_log(__METHOD__.' ('.__LINE__.') '.':'.print_r($_structure->contentTypeMap(),true));
5517 6490
 		}
5518
-		if (!$_structure || !$_structure->contentTypeMap()) return array();
5519
-		if (!empty($_partID)) $_structure = $_structure->getPart($_partID);
6491
+		if (!$_structure || !$_structure->contentTypeMap())
6492
+		{
6493
+			return array();
6494
+		}
6495
+		if (!empty($_partID))
6496
+		{
6497
+			$_structure = $_structure->getPart($_partID);
6498
+		}
5520 6499
 		$skipParts = array();
5521 6500
 		$tnefParts = array();
5522 6501
 		$skip = 0;
@@ -5545,7 +6524,13 @@  discard block
 block discarded – undo
5545 6524
 			if ($mime_type=='message/rfc822' && $_partID!=$mime_id)
5546 6525
 			{
5547 6526
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.'->'.$mime_id.':'.array2string($part->contentTypeMap()));
5548
-				foreach($part->contentTypeMap() as $sub_id => $sub_type) {if ($sub_id != $mime_id) $skipParts[$sub_id] = $sub_type;}
6527
+				foreach($part->contentTypeMap() as $sub_id => $sub_type)
6528
+				{
6529
+if ($sub_id != $mime_id)
6530
+				{
6531
+					$skipParts[$sub_id] = $sub_type;
6532
+				}
6533
+				}
5549 6534
 			}
5550 6535
 			if (empty($partDisposition) && $partPrimaryType != 'multipart' && $partPrimaryType != 'text')
5551 6536
 			{
@@ -5556,7 +6541,10 @@  discard block
 block discarded – undo
5556 6541
 				$partDisposition='attachment';
5557 6542
 			}
5558 6543
 			//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($skipParts));
5559
-			if (array_key_exists($mime_id,$skipParts)) continue;
6544
+			if (array_key_exists($mime_id,$skipParts))
6545
+			{
6546
+				continue;
6547
+			}
5560 6548
 
5561 6549
 			if ($partDisposition == 'attachment' ||
5562 6550
 				(($partDisposition == 'inline' || empty($partDisposition)) && $partPrimaryType == 'image' && $part->getContentId()=='') ||
@@ -5567,23 +6555,41 @@  discard block
 block discarded – undo
5567 6555
 			{
5568 6556
 				// if type is message/rfc822 and _partID is given, and MimeID equals partID
5569 6557
 				// we attempt to fetch "ourselves"
5570
-				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message') continue;
6558
+				if ($_partID==$part->getMimeId() && $part->getPrimaryType()=='message')
6559
+				{
6560
+					continue;
6561
+				}
5571 6562
 				$attachment = $part->getAllDispositionParameters();
5572 6563
 				$attachment['disposition'] = $part->getDisposition();
5573 6564
 				$attachment['mimeType'] = $mime_type;
5574 6565
 				$attachment['uid'] = $_uid;
5575 6566
 				$attachment['partID'] = $mime_id;
5576
-				if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
6567
+				if (!isset($attachment['name'])||empty($attachment['name']))
6568
+				{
6569
+					$attachment['name'] = $part->getName();
6570
+				}
5577 6571
 				if ($fetchTextCalendar)
5578 6572
 				{
5579 6573
 					//error_log(__METHOD__.' ('.__LINE__.') '.array2string($part->getAllContentTypeParameters()));
5580 6574
 					$method = $part->getContentTypeParameter('method');
5581
-					if ($method) $attachment['method'] = $method;
5582
-					if (!isset($attachment['name'])) $attachment['name'] = 'event.ics';
6575
+					if ($method)
6576
+					{
6577
+						$attachment['method'] = $method;
6578
+					}
6579
+					if (!isset($attachment['name']))
6580
+					{
6581
+						$attachment['name'] = 'event.ics';
6582
+					}
5583 6583
 				}
5584 6584
 				$attachment['size'] = $part->getBytes();
5585
-				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5586
-				if (empty($attachment['name'])) $attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($mime_type);
6585
+				if (($cid = $part->getContentId()))
6586
+				{
6587
+					$attachment['cid'] = $cid;
6588
+				}
6589
+				if (empty($attachment['name']))
6590
+				{
6591
+					$attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($mime_type);
6592
+				}
5587 6593
 				//error_log(__METHOD__.' ('.__LINE__.') '.' Uid:'.$uid.' Part:'.$_partID.'->'.$mime_id.':'.array2string($attachment));
5588 6594
 				//typical winmail.dat attachment is
5589 6595
 				//Array([size] => 1462762[filename] => winmail.dat[mimeType] => application/ms-tnef[uid] => 100[partID] => 2[name] => winmail.dat)
@@ -5619,14 +6625,26 @@  discard block
 block discarded – undo
5619 6625
 						$attachment['uid'] = $tnp['uid'];
5620 6626
 						$attachment['partID'] = $tnp['partID'];
5621 6627
 						$attachment['is_winmail'] = $tnp['uid'].'@'.$tnp['partID'].'@'.$mime_id;
5622
-						if (!isset($attachment['name'])||empty($attachment['name'])) $attachment['name'] = $part->getName();
6628
+						if (!isset($attachment['name'])||empty($attachment['name']))
6629
+						{
6630
+							$attachment['name'] = $part->getName();
6631
+						}
5623 6632
 						$attachment['size'] = $part->getBytes();
5624
-						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5625
-						if (empty($attachment['name'])) $attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
6633
+						if (($cid = $part->getContentId()))
6634
+						{
6635
+							$attachment['cid'] = $cid;
6636
+						}
6637
+						if (empty($attachment['name']))
6638
+						{
6639
+							$attachment['name'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
6640
+						}
5626 6641
 						$attachments[] = $attachment;
5627 6642
 					}
5628 6643
 				}
5629
-				if ($tnefResolved===false) $attachments[]=$tnp;
6644
+				if ($tnefResolved===false)
6645
+				{
6646
+					$attachments[]=$tnp;
6647
+				}
5630 6648
 			}
5631 6649
 		}
5632 6650
 		//error_log(__METHOD__.__LINE__.array2string($attachments));
@@ -5730,8 +6748,14 @@  discard block
 block discarded – undo
5730 6748
 
5731 6749
 				$attachment = $part->getAllDispositionParameters();
5732 6750
 				$attachment['mimeType'] = $part->getType();
5733
-				if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5734
-				if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
6751
+				if (!isset($attachment['filename'])||empty($attachment['filename']))
6752
+				{
6753
+					$attachment['filename'] = $part->getName();
6754
+				}
6755
+				if (($cid = $part->getContentId()))
6756
+				{
6757
+					$attachment['cid'] = $cid;
6758
+				}
5735 6759
 				if (empty($attachment['filename']))
5736 6760
 				{
5737 6761
 					$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?
@@ -5743,7 +6767,10 @@  discard block
 block discarded – undo
5743 6767
 				$attachments[$_uid.'@'.$_partID.'@'.$mime_id] = $attachment;
5744 6768
 			}
5745 6769
 		}
5746
-		if (!is_array($attachments)) return false;
6770
+		if (!is_array($attachments))
6771
+		{
6772
+			return false;
6773
+		}
5747 6774
 		return $attachments;
5748 6775
 	}
5749 6776
 
@@ -5762,10 +6789,16 @@  discard block
 block discarded – undo
5762 6789
 	function getAttachment($_uid, $_partID, $_winmail_nr=0, $_returnPart=true, $_stream=false, $_folder=null)
5763 6790
 	{
5764 6791
 		//error_log(__METHOD__.__LINE__."Uid:$_uid, PartId:$_partID, WinMailNr:$_winmail_nr, ReturnPart:$_returnPart, Stream:$_stream, Folder:$_folder".function_backtrace());
5765
-		if (!isset($_folder)) $_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6792
+		if (!isset($_folder))
6793
+		{
6794
+			$_folder = ($this->sessionData['mailbox']? $this->sessionData['mailbox'] : $this->icServer->getCurrentMailbox());
6795
+		}
5766 6796
 
5767 6797
 		$uidsToFetch = new Horde_Imap_Client_Ids();
5768
-		if (!(is_object($_uid) || is_array($_uid))) $_uid = (array)$_uid;
6798
+		if (!(is_object($_uid) || is_array($_uid)))
6799
+		{
6800
+			$_uid = (array)$_uid;
6801
+		}
5769 6802
 		$uidsToFetch->add($_uid);
5770 6803
 
5771 6804
 		$fquery = new Horde_Imap_Client_Fetch_Query();
@@ -5774,8 +6807,10 @@  discard block
 block discarded – undo
5774 6807
 		$headersNew = $this->icServer->fetch($_folder, $fquery, array(
5775 6808
 			'ids' => $uidsToFetch,
5776 6809
 		));
5777
-		if (is_object($headersNew)) {
5778
-			foreach($headersNew as $id=>$_headerObject) {
6810
+		if (is_object($headersNew))
6811
+		{
6812
+			foreach($headersNew as $id=>$_headerObject)
6813
+			{
5779 6814
 				$body = $_headerObject->getFullMsg();
5780 6815
 				if ($_partID != '')
5781 6816
 				{
@@ -5789,7 +6824,10 @@  discard block
 block discarded – undo
5789 6824
 					}
5790 6825
 					// if $partDisposition is empty, we assume attachment, and hope that the function
5791 6826
 					// itself is only triggered to fetch attachments
5792
-					if (empty($partDisposition)) $partDisposition='attachment';
6827
+					if (empty($partDisposition))
6828
+					{
6829
+						$partDisposition='attachment';
6830
+					}
5793 6831
 					if ($part && ($partDisposition=='attachment' || $partDisposition=='inline' || ($part->getPrimaryType() == 'text' && $part->getSubType() == 'calendar')))
5794 6832
 					{
5795 6833
 						//$headerObject=$part->getAllDispositionParameters();//not used anywhere around here
@@ -5798,13 +6836,19 @@  discard block
 block discarded – undo
5798 6836
 						$charset = $part->getContentTypeParameter('charset');
5799 6837
 						//$structure_bytes = $part->getBytes(); $structure_partID=$part->getMimeId(); error_log(__METHOD__.__LINE__." fetchPartContents(".array2string($_uid).", $structure_partID, $_stream, $_preserveSeen,$structure_mime)" );
5800 6838
 						$this->fetchPartContents($_uid, $part, $_stream, $_preserveSeen=true,$structure_mime);
5801
-						if ($_returnPart) return $part;
6839
+						if ($_returnPart)
6840
+						{
6841
+							return $part;
6842
+						}
5802 6843
 					}
5803 6844
 				}
5804 6845
 			}
5805 6846
 		}
5806 6847
 		$ext = MimeMagic::mime2ext($structure_mime);
5807
-		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false) $filename = trim($filename).'.'.$ext;
6848
+		if ($ext && stripos($filename,'.')===false && stripos($filename,$ext)===false)
6849
+		{
6850
+			$filename = trim($filename).'.'.$ext;
6851
+		}
5808 6852
 		if (!$part)
5809 6853
 		{
5810 6854
 			throw new Exception\WrongParameter("Error: Could not fetch attachment for Uid=".array2string($_uid).", PartId=$_partID, WinMailNr=$_winmail_nr, folder=$_folder");
@@ -5820,7 +6864,10 @@  discard block
 block discarded – undo
5820 6864
 		);
5821 6865
 
5822 6866
 		// try guessing the mimetype, if we get the application/octet-stream
5823
-		if (strtolower($attachmentData['type']) == 'application/octet-stream') $attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']);
6867
+		if (strtolower($attachmentData['type']) == 'application/octet-stream')
6868
+		{
6869
+			$attachmentData['type'] = MimeMagic::filename2mime($attachmentData['filename']);
6870
+		}
5824 6871
 		# if the attachment holds a winmail number and is a winmail.dat then we have to handle that.
5825 6872
 		if ( $filename == 'winmail.dat' && $_winmail_nr)
5826 6873
 		{
@@ -5843,9 +6890,18 @@  discard block
 block discarded – undo
5843 6890
 					if ($_winmail_nr == $wantedPart.'@'.$mime_id)
5844 6891
 					{
5845 6892
 						//error_log(__METHOD__.__LINE__.'#'.$structure_mime.'#'.$filename.'#'.array2string($attachment));
5846
-						if (!isset($attachment['filename'])||empty($attachment['filename'])) $attachment['filename'] = $part->getName();
5847
-						if (($cid = $part->getContentId())) $attachment['cid'] = $cid;
5848
-						if (empty($attachment['filename'])) $attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
6893
+						if (!isset($attachment['filename'])||empty($attachment['filename']))
6894
+						{
6895
+							$attachment['filename'] = $part->getName();
6896
+						}
6897
+						if (($cid = $part->getContentId()))
6898
+						{
6899
+							$attachment['cid'] = $cid;
6900
+						}
6901
+						if (empty($attachment['filename']))
6902
+						{
6903
+							$attachment['filename'] = (isset($attachment['cid'])&&!empty($attachment['cid'])?$attachment['cid']:lang("unknown").'_Uid'.$_uid.'_Part'.$mime_id).'.'.MimeMagic::mime2ext($attachment['mimeType']);
6904
+						}
5849 6905
 						$wmattach = $attachment;
5850 6906
 						$wmattach['attachment'] = $part->getContents(array('stream'=>$_stream));
5851 6907
 
@@ -5855,7 +6911,10 @@  discard block
 block discarded – undo
5855 6911
 			if ($tnefResolved)
5856 6912
 			{
5857 6913
 				$ext = MimeMagic::mime2ext($wmattach['mimeType']);
5858
-				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false) $wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
6914
+				if ($ext && stripos($wmattach['filename'],'.')===false && stripos($wmattach['filename'],$ext)===false)
6915
+				{
6916
+					$wmattach['filename'] = trim($wmattach['filename']).'.'.$ext;
6917
+				}
5859 6918
 				$attachmentData = array(
5860 6919
 					'type'       => $wmattach['mimeType'],
5861 6920
 					'filename'   => $wmattach['filename'],
@@ -5885,7 +6944,10 @@  discard block
 block discarded – undo
5885 6944
 		static $uid=null, $part=null, $structure=null;
5886 6945
 		//error_log(__METHOD__.' ('.__LINE__.') '.":$_uid, $_cid, $_part");
5887 6946
 
5888
-		if(empty($_cid)) return false;
6947
+		if(empty($_cid))
6948
+		{
6949
+			return false;
6950
+		}
5889 6951
 
5890 6952
 		if ($_uid != $uid || $_part != $part)
5891 6953
 		{
@@ -5910,13 +6972,19 @@  discard block
 block discarded – undo
5910 6972
 					$attachment = $part;
5911 6973
 				}
5912 6974
 				// everything else we only consider after we checked all
5913
-				if (!isset($attachment)) $attachment = $part;
6975
+				if (!isset($attachment))
6976
+				{
6977
+					$attachment = $part;
6978
+				}
5914 6979
 				// do we want content fetched, can be done later, if not needed
5915 6980
 				if (isset($_stream))
5916 6981
 				{
5917 6982
 					$this->fetchPartContents($_uid, $attachment, $_stream);
5918 6983
 				}
5919
-				if (isset($attachment)) break;
6984
+				if (isset($attachment))
6985
+				{
6986
+					break;
6987
+				}
5920 6988
 			}
5921 6989
 		}
5922 6990
 		// set name as filename, if not set
@@ -5947,10 +7015,17 @@  discard block
 block discarded – undo
5947 7015
 	 */
5948 7016
 	public function fetchPartContents($_uid, Horde_Mime_Part $part=null, $_stream=false, $_preserveSeen=false, $_mimetype=null)
5949 7017
 	{
5950
-		if (is_null($part)) return null;//new Horde_Mime_Part;
7018
+		if (is_null($part))
7019
+		{
7020
+			return null;
7021
+		}
7022
+		//new Horde_Mime_Part;
5951 7023
 		$encoding = null;
5952 7024
 		$fetchAsBinary = true;
5953
-		if ($_mimetype && strtolower($_mimetype)=='message/rfc822') $fetchAsBinary = false;
7025
+		if ($_mimetype && strtolower($_mimetype)=='message/rfc822')
7026
+		{
7027
+			$fetchAsBinary = false;
7028
+		}
5954 7029
 		// we need to set content on structure to decode transfer encoding
5955 7030
 		$part->setContents(
5956 7031
 			$this->getBodyPart($_uid, $part->getMimeId(), null, $_preserveSeen, $_stream, $encoding, $fetchAsBinary),
@@ -5987,7 +7062,10 @@  discard block
 block discarded – undo
5987 7062
 		// the recent flag is the default enforced here ; as we assume the _flags is always set,
5988 7063
 		// we default it to hordes default (Recent) (, other wise we should not pass the parameter
5989 7064
 		// for flags at all)
5990
-		if (empty($_flags)) $_flags = '\\Recent';
7065
+		if (empty($_flags))
7066
+		{
7067
+			$_flags = '\\Recent';
7068
+		}
5991 7069
 		//if (!is_array($_flags) && stripos($_flags,',')!==false) $_flags=explode(',',$_flags);
5992 7070
 		//if (!is_array($_flags)) $_flags = (array) $_flags;
5993 7071
 		try
@@ -6004,18 +7082,27 @@  discard block
 block discarded – undo
6004 7082
 		}
6005 7083
 		catch (\Exception $e)
6006 7084
 		{
6007
-			if (self::$debug) error_log("Could not append Message: ".$e->getMessage());
7085
+			if (self::$debug)
7086
+			{
7087
+				error_log("Could not append Message: ".$e->getMessage());
7088
+			}
6008 7089
 			throw new Exception\WrongUserinput(lang("Could not append Message:").' '.$e->getMessage().': '.$e->details);
6009 7090
 			//return false;
6010 7091
 		}
6011 7092
 		//error_log(__METHOD__.' ('.__LINE__.') '.' appended UID:'.$messageid);
6012 7093
 		//$messageid = true; // for debug reasons only
6013
-		if ($messageid === true || empty($messageid)) // try to figure out the message uid
7094
+		if ($messageid === true || empty($messageid))
7095
+		{
7096
+			// try to figure out the message uid
6014 7097
 		{
6015 7098
 			$list = $this->getHeaders($_folderName, $_startMessage=1, 1, 'INTERNALDATE', true, array(),null, false);
7099
+		}
6016 7100
 			if ($list)
6017 7101
 			{
6018
-				if (self::$debug) error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
7102
+				if (self::$debug)
7103
+				{
7104
+					error_log(__METHOD__.' ('.__LINE__.') '.' MessageUid:'.$messageid.' but found:'.array2string($list));
7105
+				}
6019 7106
 				$messageid = $list['header'][0]['uid'];
6020 7107
 			}
6021 7108
 		}
@@ -6056,7 +7143,10 @@  discard block
 block discarded – undo
6056 7143
 	{
6057 7144
 			//echo __METHOD__." called for $uid,$partid <br>";
6058 7145
 			$headers = $mailClass->getMessageHeader($uid,$partid,true,false,$mailbox);
6059
-			if (empty($headers)) return false;
7146
+			if (empty($headers))
7147
+			{
7148
+				return false;
7149
+			}
6060 7150
 			// dont force retrieval of the textpart, let mailClass preferences decide
6061 7151
 			$bodyParts = $mailClass->getMessageBody($uid,($preserveHTML?'always_display':'only_if_no_text'),$partid,null,false,$mailbox);
6062 7152
 			// if we do not want HTML but there is no TextRepresentation with the message itself, try converting
@@ -6074,15 +7164,30 @@  discard block
 block discarded – undo
6074 7164
 			//error_log(array2string($bodyParts));
6075 7165
 			$attachments = $includeAttachments?$mailClass->getMessageAttachments($uid,$partid,null,true,false,true,$mailbox):array();
6076 7166
 
6077
-			if ($mailClass->isSentFolder($mailbox)) $mailaddress = $headers['TO'];
6078
-			elseif (isset($headers['FROM'])) $mailaddress = $headers['FROM'];
6079
-			elseif (isset($headers['SENDER'])) $mailaddress = $headers['SENDER'];
6080
-			if (isset($headers['CC'])) $mailaddress .= ','.$headers['CC'];
7167
+			if ($mailClass->isSentFolder($mailbox))
7168
+			{
7169
+				$mailaddress = $headers['TO'];
7170
+			}
7171
+			elseif (isset($headers['FROM']))
7172
+			{
7173
+				$mailaddress = $headers['FROM'];
7174
+			}
7175
+			elseif (isset($headers['SENDER']))
7176
+			{
7177
+				$mailaddress = $headers['SENDER'];
7178
+			}
7179
+			if (isset($headers['CC']))
7180
+			{
7181
+				$mailaddress .= ','.$headers['CC'];
7182
+			}
6081 7183
 			//_debug_array(array($headers,$mailaddress));
6082 7184
 			$subject = $headers['SUBJECT'];
6083 7185
 
6084 7186
 			$message = self::getdisplayableBody($mailClass, $bodyParts, $preserveHTML);
6085
-			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain') $message = '<pre>'.$message.'</pre>';
7187
+			if ($preserveHTML && $mailClass->activeMimeType == 'text/plain')
7188
+			{
7189
+				$message = '<pre>'.$message.'</pre>';
7190
+			}
6086 7191
 			$headdata = ($addHeaderSection ? self::createHeaderInfoSection($headers, '',$preserveHTML) : '');
6087 7192
 			$message = $headdata.$message;
6088 7193
 			//echo __METHOD__.'<br>';
@@ -6133,7 +7238,8 @@  discard block
 block discarded – undo
6133 7238
 							$attachments[$num]['attachment'] = $c->getContents();
6134 7239
 						}
6135 7240
 						// no attempt to convert, if we dont know about the charset
6136
-						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset'])) {
7241
+						if (isset($attachments[$num]['charset'])&&!empty($attachments[$num]['charset']))
7242
+						{
6137 7243
 							// we do not try guessing the charset, if it is not set
6138 7244
 							//if ($attachments[$num]['charset']===false) $attachments[$num]['charset'] = Translation::detect_encoding($attachments[$num]['attachment']);
6139 7245
 							Translation::convert($attachments[$num]['attachment'],$attachments[$num]['charset']);
@@ -6154,7 +7260,10 @@  discard block
 block discarded – undo
6154 7260
 						unset($attachments[$num]['attachment']);
6155 7261
 					}
6156 7262
 				}
6157
-				if (is_array($attachedMessages)) $attachments = array_merge($attachments,$attachedMessages);
7263
+				if (is_array($attachedMessages))
7264
+				{
7265
+					$attachments = array_merge($attachments,$attachedMessages);
7266
+				}
6158 7267
 			}
6159 7268
 			return array(
6160 7269
 					'mailaddress'=>$mailaddress,
@@ -6176,10 +7285,17 @@  discard block
 block discarded – undo
6176 7285
 	{
6177 7286
 		$c = 0;
6178 7287
 		// use the standardIdentity
6179
-		foreach($_identities as $key => $acc) {
6180
-			if ($c==0) $identity = $acc;
7288
+		foreach($_identities as $key => $acc)
7289
+		{
7290
+			if ($c==0)
7291
+			{
7292
+				$identity = $acc;
7293
+			}
6181 7294
 			//error_log(__METHOD__.__LINE__." $key == $_profile_id ");
6182
-			if ($key==$_profile_id) $identity = $acc;
7295
+			if ($key==$_profile_id)
7296
+			{
7297
+				$identity = $acc;
7298
+			}
6183 7299
 			$c++;
6184 7300
 		}
6185 7301
 		return $identity;
@@ -6195,20 +7311,53 @@  discard block
 block discarded – undo
6195 7311
 	{
6196 7312
 		$headdata = null;
6197 7313
 		//error_log(__METHOD__.' ('.__LINE__.') '.array2string($header).function_backtrace());
6198
-		if ($header['SUBJECT']) $headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
6199
-		if ($header['FROM']) $headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
6200
-		if ($header['SENDER']) $headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
6201
-		if ($header['TO']) $headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
6202
-		if ($header['CC']) $headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
6203
-		if ($header['BCC']) $headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
6204
-		if ($header['DATE']) $headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
6205
-		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal') $headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
6206
-		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal') $headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
7314
+		if ($header['SUBJECT'])
7315
+		{
7316
+			$headdata = lang('subject').': '.$header['SUBJECT'].($createHTML?"<br />":"\n");
7317
+		}
7318
+		if ($header['FROM'])
7319
+		{
7320
+			$headdata .= lang('from').': '.self::convertAddressArrayToString($header['FROM'], $createHTML).($createHTML?"<br />":"\n");
7321
+		}
7322
+		if ($header['SENDER'])
7323
+		{
7324
+			$headdata .= lang('sender').': '.self::convertAddressArrayToString($header['SENDER'], $createHTML).($createHTML?"<br />":"\n");
7325
+		}
7326
+		if ($header['TO'])
7327
+		{
7328
+			$headdata .= lang('to').': '.self::convertAddressArrayToString($header['TO'], $createHTML).($createHTML?"<br />":"\n");
7329
+		}
7330
+		if ($header['CC'])
7331
+		{
7332
+			$headdata .= lang('cc').': '.self::convertAddressArrayToString($header['CC'], $createHTML).($createHTML?"<br />":"\n");
7333
+		}
7334
+		if ($header['BCC'])
7335
+		{
7336
+			$headdata .= lang('bcc').': '.self::convertAddressArrayToString($header['BCC'], $createHTML).($createHTML?"<br />":"\n");
7337
+		}
7338
+		if ($header['DATE'])
7339
+		{
7340
+			$headdata .= lang('date').': '.$header['DATE'].($createHTML?"<br />":"\n");
7341
+		}
7342
+		if ($header['PRIORITY'] && $header['PRIORITY'] != 'normal')
7343
+		{
7344
+			$headdata .= lang('priority').': '.$header['PRIORITY'].($createHTML?"<br />":"\n");
7345
+		}
7346
+		if ($header['IMPORTANCE'] && $header['IMPORTANCE'] !='normal')
7347
+		{
7348
+			$headdata .= lang('importance').': '.$header['IMPORTANCE'].($createHTML?"<br />":"\n");
7349
+		}
6207 7350
 		//if ($mailcontent['headers']['ORGANIZATION']) $headdata .= lang('organization').': '.$mailcontent['headers']['ORGANIZATION']."\
6208 7351
 		if (!empty($headdata))
6209 7352
 		{
6210
-			if (!empty($headline) && $headline != 'SUPPRESS') $headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
6211
-			if (empty($headline)) $headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
7353
+			if (!empty($headline) && $headline != 'SUPPRESS')
7354
+			{
7355
+				$headdata = "---------------------------- $headline ----------------------------".($createHTML?"<br />":"\n").$headdata;
7356
+			}
7357
+			if (empty($headline))
7358
+			{
7359
+				$headdata = ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'').$headdata;
7360
+			}
6212 7361
 			$headdata .= ($headline != 'SUPPRESS'?"--------------------------------------------------------".($createHTML?"<br />":"\n"):'');
6213 7362
 		}
6214 7363
 		else
@@ -6242,12 +7391,15 @@  discard block
 block discarded – undo
6242 7391
 		$returnAddr ='';
6243 7392
 		if (is_array($rfcAddressArray))
6244 7393
 		{
6245
-			foreach((array)$rfcAddressArray as $addressData) {
7394
+			foreach((array)$rfcAddressArray as $addressData)
7395
+			{
6246 7396
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressData));
6247
-				if($addressData['MAILBOX_NAME'] == 'NIL') {
7397
+				if($addressData['MAILBOX_NAME'] == 'NIL')
7398
+				{
6248 7399
 					continue;
6249 7400
 				}
6250
-				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients') {
7401
+				if(strtolower($addressData['MAILBOX_NAME']) == 'undisclosed-recipients')
7402
+				{
6251 7403
 					continue;
6252 7404
 				}
6253 7405
 				if ($addressData['RFC822_EMAIL'])
@@ -6261,7 +7413,10 @@  discard block
 block discarded – undo
6261 7413
 				}
6262 7414
 				$addressObject = $addressObjectA[0];
6263 7415
 				//error_log(__METHOD__.' ('.__LINE__.') '.array2string($addressObject));
6264
-				if (!$addressObject->valid) continue;
7416
+				if (!$addressObject->valid)
7417
+				{
7418
+					continue;
7419
+				}
6265 7420
 				//$mb =(string)$addressObject->mailbox;
6266 7421
 				//$h = (string)$addressObject->host;
6267 7422
 				//$p = (string)$addressObject->personal;
@@ -6278,7 +7433,10 @@  discard block
 block discarded – undo
6278 7433
 			// do not mess with strings, return them untouched /* ToDo: validate string as Address */
6279 7434
 			$rfcAddressArray = self::decode_header($rfcAddressArray,true);
6280 7435
 			$rfcAddressArray = str_replace(array('<','>','"\'','\'"'),array('[',']','"','"'),$rfcAddressArray);
6281
-			if (is_string($rfcAddressArray)) return $rfcAddressArray;
7436
+			if (is_string($rfcAddressArray))
7437
+			{
7438
+				return $rfcAddressArray;
7439
+			}
6282 7440
 		}
6283 7441
 		return $returnAddr;
6284 7442
 	}
@@ -6295,10 +7453,19 @@  discard block
 block discarded – undo
6295 7453
 	{
6296 7454
 		$mergeobj = new Contacts\Merge();
6297 7455
 
6298
-		if (empty($mimetype)) $mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
7456
+		if (empty($mimetype))
7457
+		{
7458
+			$mimetype = (strlen(strip_tags($content)) == strlen($content) ?'text/plain':'text/html');
7459
+		}
6299 7460
 		$rv = $mergeobj->merge_string($content,$ids,$err='',$mimetype, array(), self::$displayCharset);
6300
-		if (empty($rv) && !empty($content) && !empty($err)) $rv = $content;
6301
-		if (!empty($err) && !empty($content) && !empty($ids)) error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
7461
+		if (empty($rv) && !empty($content) && !empty($err))
7462
+		{
7463
+			$rv = $content;
7464
+		}
7465
+		if (!empty($err) && !empty($content) && !empty($ids))
7466
+		{
7467
+			error_log(__METHOD__.' ('.__LINE__.') '.' Merge failed for Ids:'.array2string($ids).' ContentType:'.$mimetype.' Content:'.$content.' Reason:'.array2string($err));
7468
+		}
6302 7469
 		return $rv;
6303 7470
 	}
6304 7471
 
@@ -6335,13 +7502,15 @@  discard block
 block discarded – undo
6335 7502
 			settype($bytes, 'integer');
6336 7503
 			$bytes /= 10;
6337 7504
 		}
6338
-		else
6339
-			settype($bytes, 'integer');
7505
+		else {
7506
+					settype($bytes, 'integer');
7507
+		}
6340 7508
 
6341 7509
 		return $bytes . ' ' . $type ;
6342 7510
 	}
6343 7511
 
6344
-	static function detect_qp(&$sting) {
7512
+	static function detect_qp(&$sting)
7513
+	{
6345 7514
 		$needle = '/(=[0-9][A-F])|(=[A-F][0-9])|(=[A-F][A-F])|(=[0-9][0-9])/';
6346 7515
 		return preg_match("$needle",$string);
6347 7516
 	}
@@ -6358,9 +7527,15 @@  discard block
 block discarded – undo
6358 7527
 	 */
6359 7528
 	static function logRunTimes($_starttime,$_endtime=null,$_message='',$_methodNline='')
6360 7529
 	{
6361
-		if (is_null($_endtime)) $_endtime = microtime(true);
7530
+		if (is_null($_endtime))
7531
+		{
7532
+			$_endtime = microtime(true);
7533
+		}
6362 7534
 		$usagetime = microtime(true) - $_starttime;
6363
-		if (self::$debugTimes) error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
7535
+		if (self::$debugTimes)
7536
+		{
7537
+			error_log($_methodNline.' took:'.number_format($usagetime,5).'(s) '.($_message?'Details:'.$_message:''));
7538
+		}
6364 7539
 	}
6365 7540
 
6366 7541
 	/**
@@ -6375,7 +7550,10 @@  discard block
 block discarded – undo
6375 7550
 	 */
6376 7551
 	static function checkFileBasics(&$_formData, $IDtoAddToFileName='', $reqMimeType='message/rfc822')
6377 7552
 	{
6378
-		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data') return $_formData['file'];
7553
+		if (parse_url($_formData['file'],PHP_URL_SCHEME) == 'egw-data')
7554
+		{
7555
+			return $_formData['file'];
7556
+		}
6379 7557
 
6380 7558
 		//error_log(__METHOD__.__FILE__.array2string($_formData).' Id:'.$IDtoAddToFileName.' ReqMimeType:'.$reqMimeType);
6381 7559
 		$importfailed = $tmpFileName = false;
@@ -6424,8 +7602,15 @@  discard block
 block discarded – undo
6424 7602
 			{
6425 7603
 				$buff = explode('.',$_formData['name']);
6426 7604
 				$suffix = '';
6427
-				if (is_array($buff)) $suffix = array_pop($buff); // take the last extension to check with ext2mime
6428
-				if (!empty($suffix)) $sfxMimeType = MimeMagic::ext2mime($suffix);
7605
+				if (is_array($buff))
7606
+				{
7607
+					$suffix = array_pop($buff);
7608
+				}
7609
+				// take the last extension to check with ext2mime
7610
+				if (!empty($suffix))
7611
+				{
7612
+					$sfxMimeType = MimeMagic::ext2mime($suffix);
7613
+				}
6429 7614
 				if (!empty($suffix) && !empty($sfxMimeType) &&
6430 7615
 					(strlen(trim($_formData['type']))==0 || (strtolower(trim($_formData['type'])) != $sfxMimeType)))
6431 7616
 				{
@@ -6473,7 +7658,9 @@  discard block
 block discarded – undo
6473 7658
 			{
6474 7659
 				rename($_formData['file'], $GLOBALS['egw_info']['server']['temp_dir'].'/'.$tmpFileName);
6475 7660
 			}
6476
-		} else {
7661
+		}
7662
+		else
7663
+		{
6477 7664
 			//error_log("Import of message ".$_formData['file']." failes to meet basic restrictions");
6478 7665
 			$importfailed = true;
6479 7666
 			$alert_msg .= lang("Processing of file %1 failed. Failed to meet basic restrictions.",$_formData['name']);
@@ -6519,21 +7706,32 @@  discard block
 block discarded – undo
6519 7706
 				if (substr($url, 0, 5) !== 'data:')
6520 7707
 				{
6521 7708
 					$filename = basename($url);
6522
-					if (($directory = dirname($url)) == '.') $directory = '';
7709
+					if (($directory = dirname($url)) == '.')
7710
+					{
7711
+						$directory = '';
7712
+					}
6523 7713
 					$ext = pathinfo($filename, PATHINFO_EXTENSION);
6524 7714
 					$mimeType  = MimeMagic::ext2mime($ext);
6525
-					if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
7715
+					if ( strlen($directory) > 1 && substr($directory,-1) != '/')
7716
+					{
7717
+$directory .= '/'; }
6526 7718
 					$myUrl = $directory.$filename;
6527
-					if ($myUrl[0]=='/') // local path -> we only allow path's that are available via http/https (or vfs)
7719
+					if ($myUrl[0]=='/')
7720
+					{
7721
+						// local path -> we only allow path's that are available via http/https (or vfs)
6528 7722
 					{
6529 7723
 						$basedir = ($_SERVER['HTTPS']?'https://':'http://'.$_SERVER['HTTP_HOST']);
6530 7724
 					}
7725
+					}
6531 7726
 					// use vfs instead of url containing webdav.php
6532 7727
 					// ToDo: we should test if the webdav url is of our own scope, as we cannot handle foreign
6533 7728
 					// webdav.php urls as vfs
6534
-					if (strpos($myUrl,'/webdav.php') !== false) // we have a webdav link, so we build a vfs/sqlfs link of it.
7729
+					if (strpos($myUrl,'/webdav.php') !== false)
7730
+					{
7731
+						// we have a webdav link, so we build a vfs/sqlfs link of it.
6535 7732
 					{
6536 7733
 						Vfs::load_wrapper('vfs');
7734
+					}
6537 7735
 						list(,$myUrl) = explode('/webdav.php',$myUrl,2);
6538 7736
 						$basedir = 'vfs://default';
6539 7737
 						$needTempFile = false;
@@ -6562,8 +7760,13 @@  discard block
 block discarded – undo
6562 7760
 						}
6563 7761
 					}
6564 7762
 
6565
-					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/') { $basedir .= '/'; }
6566
-					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http") $data = file_get_contents($basedir.urldecode($myUrl));
7763
+					if ( strlen($basedir) > 1 && substr($basedir,-1) != '/' && $myUrl[0]!='/')
7764
+					{
7765
+$basedir .= '/'; }
7766
+					if ($needTempFile && !$attachment && substr($myUrl,0,4) !== "http")
7767
+					{
7768
+						$data = file_get_contents($basedir.urldecode($myUrl));
7769
+					}
6567 7770
 				}
6568 7771
 				if (substr($url,0,strlen('data:'))=='data:')
6569 7772
 				{
@@ -6664,7 +7867,10 @@  discard block
 block discarded – undo
6664 7867
 				$_folder = $this->getSentFolder();
6665 7868
 			}
6666 7869
 			$delimiter = $this->getHierarchyDelimiter();
6667
-			if($_folder=='INBOX'.$delimiter) $_folder='INBOX';
7870
+			if($_folder=='INBOX'.$delimiter)
7871
+			{
7872
+				$_folder='INBOX';
7873
+			}
6668 7874
 			if ($importfailed === false)
6669 7875
 			{
6670 7876
 				$Subject = $mailObject->getHeader('Subject');
@@ -6693,7 +7899,9 @@  discard block
 block discarded – undo
6693 7899
 					//error_log(__METHOD__.' ('.__LINE__.') '.' Id To Merge:'.$val);
6694 7900
 					if (/*$GLOBALS['egw_info']['flags']['currentapp'] == 'addressbook' &&*/
6695 7901
 						count($SendAndMergeTocontacts) > 1 && $val &&
6696
-						(is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))) // do the merge
7902
+						(is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)))
7903
+					{
7904
+						// do the merge
6697 7905
 					{
6698 7906
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6699 7907
 
@@ -6702,6 +7910,7 @@  discard block
 block discarded – undo
6702 7910
 						{
6703 7911
 							//error_log('ID ' . $val . ' ' .$type . ': ' . $mailObject->getHeader(Mailer::$type2header[$type]) . ' -> ' .$bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset));
6704 7912
 							$merged = $bo_merge->merge_string($mailObject->getHeader(Mailer::$type2header[$type]),$val,$e,'text/plain',array(),self::$displayCharset);
7913
+					}
6705 7914
 							$mailObject->addAddress($merged,'',$type);
6706 7915
 							if($type == 'to')
6707 7916
 							{
@@ -6733,9 +7942,15 @@  discard block
 block discarded – undo
6733 7942
 						$mailObject->clearCustomHeaders();
6734 7943
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6735 7944
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6736
-						if($text_body) $text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7945
+						if($text_body)
7946
+						{
7947
+							$text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7948
+						}
6737 7949
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6738
-						if($html_body) $html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7950
+						if($html_body)
7951
+						{
7952
+							$html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
7953
+						}
6739 7954
 
6740 7955
 						//error_log(__METHOD__.' ('.__LINE__.') '.array2string($mailObject));
6741 7956
 						// set a higher timeout for big messages
@@ -6750,9 +7965,12 @@  discard block
 block discarded – undo
6750 7965
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($errorInfo));
6751 7966
 						}
6752 7967
 					}
6753
-					elseif (!$k)	// 1. entry, further entries will fail for apps other then addressbook
7968
+					elseif (!$k)
7969
+					{
7970
+						// 1. entry, further entries will fail for apps other then addressbook
6754 7971
 					{
6755 7972
 						$openAsDraft = true;
7973
+					}
6756 7974
 						$mailObject->removeHeader('Message-ID');
6757 7975
 						$mailObject->removeHeader('Date');
6758 7976
 						$mailObject->clearCustomHeaders();
@@ -6767,9 +7985,12 @@  discard block
 block discarded – undo
6767 7985
 
6768 7986
 						// No addresses from placeholders?  Treat it as just a contact ID
6769 7987
 						if (count($mailObject->getAddresses('to',true)) == 0 &&
6770
-							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val)) // do the merge
7988
+							is_numeric($val) || $GLOBALS['egw']->accounts->name2id($val))
7989
+						{
7990
+							// do the merge
6771 7991
 						{
6772 7992
 							$contact = $bo_merge->contacts->read($val);
7993
+						}
6773 7994
 							//error_log(__METHOD__.' ('.__LINE__.') '.array2string($contact));
6774 7995
 							$email = ($contact['email'] ? $contact['email'] : $contact['email_home']);
6775 7996
 							$nfn = ($contact['n_fn'] ? $contact['n_fn'] : $contact['n_given'].' '.$contact['n_family']);
@@ -6780,9 +8001,15 @@  discard block
 block discarded – undo
6780 8001
 						}
6781 8002
 						$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
6782 8003
 						//error_log(__METHOD__.' ('.__LINE__.') '.' ContentType:'.$mailObject->BodyContentType);
6783
-						if (!empty($Body)) $text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
8004
+						if (!empty($Body))
8005
+						{
8006
+							$text_body->setContents($bo_merge->merge_string($Body, $val, $e, 'text/plain', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
8007
+						}
6784 8008
 						//error_log(__METHOD__.' ('.__LINE__.') '.' Result:'.$mailObject->Body.' error:'.array2string($e));
6785
-						if (!empty($AltBody)) $html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
8009
+						if (!empty($AltBody))
8010
+						{
8011
+							$html_body->setContents($bo_merge->merge_string($AltBody, $val, $e, 'text/html', array(), self::$displayCharset),array('encoding'=>Horde_Mime_Part::DEFAULT_ENCODING));
8012
+						}
6786 8013
 						$_folder = $this->getDraftFolder();
6787 8014
 					}
6788 8015
 					if ($sendOK || $openAsDraft)
@@ -6790,11 +8017,15 @@  discard block
 block discarded – undo
6790 8017
 						if ($this->folderExists($_folder,true))
6791 8018
 						{
6792 8019
 						    if($this->isSentFolder($_folder))
6793
-							{
8020
+						    {
6794 8021
 						        $flags = '\\Seen';
6795
-						    } elseif($this->isDraftFolder($_folder)) {
8022
+						    }
8023
+						    elseif($this->isDraftFolder($_folder))
8024
+						    {
6796 8025
 						        $flags = '\\Draft';
6797
-						    } else {
8026
+						    }
8027
+						    else
8028
+						    {
6798 8029
 						        $flags = '';
6799 8030
 						    }
6800 8031
 							$savefailed = false;
@@ -6828,7 +8059,10 @@  discard block
 block discarded – undo
6828 8059
 						}
6829 8060
 						else
6830 8061
 						{
6831
-							if (!$openComposeWindow) $processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
8062
+							if (!$openComposeWindow)
8063
+							{
8064
+								$processStats['failed'][$val] = $errorInfo?$errorInfo:'Send failed to '.$nfn.'<'.$email.'> See error_log for details';
8065
+							}
6832 8066
 						}
6833 8067
 					}
6834 8068
 					if (!is_null($sendOK) && $sendOK===false && is_null($openComposeWindow))
@@ -6876,7 +8110,10 @@  discard block
 block discarded – undo
6876 8110
 				$tmpFileName = $GLOBALS['egw_info']['server']['temp_dir'].'/'.basename($tmpFileName);
6877 8111
 				break;
6878 8112
 		}
6879
-		if (!isset($message)) $message = fopen($tmpFileName, 'r');
8113
+		if (!isset($message))
8114
+		{
8115
+			$message = fopen($tmpFileName, 'r');
8116
+		}
6880 8117
 
6881 8118
 		if (!$message)
6882 8119
 		{
@@ -6907,7 +8144,10 @@  discard block
 block discarded – undo
6907 8144
 				(fseek($message, 0, SEEK_SET) == -1 ? '' : fread($message, 8192));
6908 8145
 
6909 8146
 			$length = strpos($start, Horde_Mime_Part::RFC_EOL.Horde_Mime_Part::RFC_EOL);
6910
-			if ($length===false) $length = strlen($start);
8147
+			if ($length===false)
8148
+			{
8149
+				$length = strlen($start);
8150
+			}
6911 8151
 			$headers = Horde_Mime_Headers::parseHeaders(substr($start, 0,$length));
6912 8152
 
6913 8153
 			foreach($headers->toArray(array('nowrap' => true)) as $header => $value)
@@ -6936,7 +8176,10 @@  discard block
 block discarded – undo
6936 8176
 		}
6937 8177
 		else
6938 8178
 		{
6939
-			if (($type = gettype($message)) == 'object') $type = get_class ($message);
8179
+			if (($type = gettype($message)) == 'object')
8180
+			{
8181
+				$type = get_class ($message);
8182
+			}
6940 8183
 			throw new Exception\WrongParameter('Wrong parameter type for message: '.$type);
6941 8184
 		}
6942 8185
 	}
@@ -6960,7 +8203,9 @@  discard block
 block discarded – undo
6960 8203
 			$matches = array();
6961 8204
 			preg_match_all("/[\w\.,-.,_.,0-9.]+@[\w\.,-.,_.,0-9.]+/",$addresses,$matches);
6962 8205
 			//error_log(__METHOD__.__LINE__.array2string($matches));
6963
-			foreach ($matches[0] as &$match) {$match = trim($match,', ');}
8206
+			foreach ($matches[0] as &$match)
8207
+			{
8208
+$match = trim($match,', ');}
6964 8209
 			$addresses = implode(',',$matches[0]);
6965 8210
 			//error_log(__METHOD__.__LINE__.array2string($addresses));
6966 8211
 			$ret = $rfc822->parseAddressList($addresses, $default_domain ? array('default_domain' => $default_domain) : array());
@@ -6991,7 +8236,10 @@  discard block
 block discarded – undo
6991 8236
 			}
6992 8237
 			else
6993 8238
 			{
6994
-				if ($previousFailed && $remember) $adr->personal = $remember. ' ' . $adr->personal;
8239
+				if ($previousFailed && $remember)
8240
+				{
8241
+					$adr->personal = $remember. ' ' . $adr->personal;
8242
+				}
6995 8243
 				$remember = '';
6996 8244
 				$previousFailed=false;
6997 8245
 				//error_log(__METHOD__.__LINE__."('$addresses', $default_domain) parsed $i: mailbox=$adr->mailbox, host=$adr->host, personal=$adr->personal");
@@ -7013,7 +8261,10 @@  discard block
 block discarded – undo
7013 8261
 	{
7014 8262
 		$acc = Mail\Account::read($this->profileID);
7015 8263
 		$identity = Mail\Account::read_identity($acc['ident_id'], true, null, $acc);
7016
-		if (self::$debug) error_log(__METHOD__.__LINE__.array2string($identity));
8264
+		if (self::$debug)
8265
+		{
8266
+			error_log(__METHOD__.__LINE__.array2string($identity));
8267
+		}
7017 8268
 		$headers = $this->getMessageHeader($uid, '', 'object', true, $_folder);
7018 8269
 
7019 8270
 		$mdn = new Horde_Mime_Mdn($headers);
Please login to merge, or discard this patch.